]> Creatis software - bbtk.git/blob - kernel/src/bbtkWidgetBlackBox.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkWidgetBlackBox.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWidgetBlackBox.h,v $
4   Language:  C++
5   Date:      $Date: 2009/06/10 11:36:51 $
6   Version:   $Revision: 1.6 $
7 ========================================================================*/
8
9
10 /* ---------------------------------------------------------------------
11
12 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
13 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 *
15 *  This software is governed by the CeCILL-B license under French law and 
16 *  abiding by the rules of distribution of free software. You can  use, 
17 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
18 *  license as circulated by CEA, CNRS and INRIA at the following URL 
19 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
20 *  or in the file LICENSE.txt.
21 *
22 *  As a counterpart to the access to the source code and  rights to copy,
23 *  modify and redistribute granted by the license, users are provided only
24 *  with a limited warranty  and the software's author,  the holder of the
25 *  economic rights,  and the successive licensors  have only  limited
26 *  liability. 
27 *
28 *  The fact that you are presently reading this means that you have had
29 *  knowledge of the CeCILL-B license and that you accept its terms.
30 * ------------------------------------------------------------------------ */                                                                         
31 /**
32  * \brief Short description in one line
33  * 
34  * Long description which 
35  * can span multiple lines
36  */
37 /**
38  * \file 
39  * \brief 
40  */
41 /**
42  * \class bbtk::
43  * \brief 
44  */
45 #ifndef __bbtkWidgetBlackBox_h_INCLUDED__
46 #define __bbtkWidgetBlackBox_h_INCLUDED__
47
48 #include "bbtkAtomicBlackBox.h"
49
50 namespace bbtk
51 {
52
53
54
55
56   //==================================================================
57   /// Generic (template) Widget black box from which all 
58   /// widget black boxes for a specific GUI toolkit inherit with 
59   /// apropriate traits.
60   /// Declares the common inputs / outputs and interface to all widget boxes
61
62 //JCP 09JUIN2009 BBTK_EXPORT
63   template <class W>
64           
65   class /*BBTK_EXPORT*/ WidgetBlackBox : public bbtk::AtomicBlackBox  
66   { 
67   public:
68     //    typedef WidgetTraits Traits;
69     typedef W Widget;
70     typedef Widget* WidgetPointer;
71     
72     
73     BBTK_BLACK_BOX_INTERFACE(WidgetBlackBox,bbtk::AtomicBlackBox);
74     BBTK_DECLARE_INPUT(WinTitle,std::string);
75     BBTK_DECLARE_INPUT(WinWidth,int);
76     BBTK_DECLARE_INPUT(WinHeight,int);
77     BBTK_DECLARE_INPUT(WinDialog,bool);
78     BBTK_DECLARE_INPUT(WinHide,Void);
79     BBTK_DECLARE_INPUT(WinClose,Void);
80     BBTK_DECLARE_OUTPUT(Widget,Widget*);
81
82     //==================================================================
83     /// Overloaded bbCreateWindow method for WidgetBlackBoxes which handles 
84     /// the window creation if needed
85     virtual void bbCreateWindow();
86     virtual bool bbWindowIsCreated() { return false; }
87     //==================================================================
88     
89     //==================================================================
90     /// Overloaded bbShowWindow method for WidgetBlackBoxes which handles 
91     /// the window creation if needed
92     virtual void bbShowWindow() {}
93     //==================================================================    
94
95  
96     /// Convenient method which returns true iff the output Widget is connected
97     bool bbIsOutputWidgetConnected();
98
99     //==================================================================    
100     bool bbIsShown();
101     //==================================================================    
102  
103    
104     //==================================================================    
105     /// User callback for creating the widget associated to the box
106     /// ** Must be defined ** in user classes
107     virtual void bbUserCreateWidget(Widget* parent) 
108     {
109       bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbUserCreateWidget methods is not overloaded : is it a feature or a bug ?!?");
110     }
111     //==================================================================    
112
113           
114   protected:
115     
116     void bbSetShown(bool);
117
118     //==================================================================
119     /// Convenient method for layout widgets which creates and returns
120     /// (calls bbUserCreateWidget) 
121     /// the widget of the box connected to the input in.
122     /// Returns NULL if the input is not connected
123     Widget* bbCreateWidgetOfInput(const std::string& in, 
124                                   Widget* parent);
125     //==================================================================
126
127    //==================================================================    
128     /// Callback for creating a Dialog window (modal)
129     /// ** Must be defined ** in toolkit specific descendants 
130     virtual void bbCreateDialogWindow()
131     {
132       bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbCreateDialogWindow method is not overloaded ?!?");
133     }
134     //==================================================================    
135
136  //==================================================================    
137     /// Callback for creating a Frame window 
138     /// ** Must be defined ** in toolkit specific descendants 
139     virtual void bbCreateFrameWindow()
140     {
141       bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbCreateFrameWindow method is not overloaded ?!?");
142     }
143     //==================================================================    
144     //==================================================================
145     /// Overloaded processing method for WidgetBlackBoxes
146     virtual void bbProcess();
147     //==================================================================
148
149     //==================================================================
150     /// Destroys the WidgetBlackBoxWindow associated to the box (if exists)
151     virtual void bbDestroyWindow() {}
152     //==================================================================
153
154    
155
156   private:
157    
158     /// Set to true when the 
159     /// window containing the widget is shown
160     bool bbmShown;
161     /// Contains the "nested" WidgetBlackBoxes, 
162     /// i.e. if this WidgetBox is a Layout the ones
163     /// which are inserted into the layout 
164     /// The list is updated by the method bbCreateWidgetOfInput
165     /// It is emptied when ?
166     std::vector<BlackBox::WeakPointer> bbmNestedWidgetBoxes;
167   };
168   //=================================================================
169  
170
171   //======================================================================
172   /// Defines the bbUserCreateWidget method
173 #define BBTK_CREATE_WIDGET(CALLBACK)                                    \
174   public:                                                               \
175   inline void bbUserCreateWidget(Widget* parent)                        \
176   {                                                                     \
177     bbtkBlackBoxDebugMessage("widget",1,"**> Creating widget"           \
178                              <<std::endl);                              \
179     CALLBACK(parent);                                                   \
180   }
181   
182   //======================================================================
183
184   //======================================================================
185   /// Defines the bbUserOnShow method
186 #define BBTK_ON_SHOW_WIDGET(CALLBACK)                                   \
187   public:                                                               \
188   inline void bbUserOnShow()                                            \
189   {                                                                     \
190     bbtkBlackBoxDebugMessage("widget",1,"**> Showing"                   \
191                              <<std::endl);                              \
192     CALLBACK();                                                         \
193   }
194   
195   //======================================================================
196
197   //=================================================================
198   // WidgetBlackBoxDescriptor declaration
199   BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(WidgetBlackBox,bbtk::AtomicBlackBox);
200   BBTK_NAME("WidgetBlackBox_"+HumanTypeName<T>());
201   // BBTK_DESCRIPTION("Widget box. The inputs marked with (*) are only used if the widget is not inserted in another widget.\n");
202   BBTK_CATEGORY("widget");
203   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinTitle,
204              "Title of the window (*)",
205              std::string);
206   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinWidth,
207              "Width of the window (* : only used if the widget is not connected to a Layout box)",int);
208   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinHeight,
209              "Height of the window (*)",int);
210   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinDialog,
211              "Set to 'true' to create a dialog window, i.e. which blocks the pipeline until it is closed (modal) (*)",bool);
212   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinHide,
213              "Any signal received hides the window (*)",Void);
214   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinClose,
215              "Any signal received closes the window (*)",Void);
216   typedef typename WidgetBlackBox<T>::WidgetPointer WidgetPointer;
217   BBTK_TEMPLATE_OUTPUT(WidgetBlackBox,Widget,"Output widget",WidgetPointer);
218   BBTK_END_DESCRIBE_BLACK_BOX(WidgetBlackBox);
219   //=================================================================
220
221
222
223
224
225
226
227
228
229 } //namespace bbtk
230
231 // template code inclusion
232 #include "bbtkWidgetBlackBox.txx"
233
234 // WidgetBlackBoxWindow interface + code inclusion
235 #include "bbtkWidgetBlackBoxWindow.h"
236
237 #endif  //__bbtkWidgetBlackBox_h__