]> Creatis software - bbtk.git/blob - kernel/src/bbtkWidgetBlackBox.h
Changes under win32
[bbtk.git] / kernel / src / bbtkWidgetBlackBox.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWidgetBlackBox.h,v $
4   Language:  C++
5   Date:      $Date: 2009/04/21 14:36:51 $
6   Version:   $Revision: 1.2 $
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   template <class T> class WidgetBlackBoxWindow;
55
56
57   //==================================================================
58   /// Generic (template) Widget black box from which all 
59   /// widget black boxes for a specific GUI toolkit inherit with 
60   /// apropriate traits.
61   /// Declares the common inputs / outputs and interface to all widget boxes
62   template <class W>
63   class /*BBTK_EXPORT*/ WidgetBlackBox : public bbtk::AtomicBlackBox  
64   { 
65   public:
66     //    typedef WidgetTraits Traits;
67     typedef W Widget;
68     typedef Widget* WidgetPointer;
69     typedef WidgetBlackBoxWindow<W> Window;
70     
71     
72     BBTK_BLACK_BOX_INTERFACE(WidgetBlackBox,bbtk::AtomicBlackBox);
73     BBTK_DECLARE_INPUT(WinTitle,std::string);
74     BBTK_DECLARE_INPUT(WinWidth,int);
75     BBTK_DECLARE_INPUT(WinHeight,int);
76     BBTK_DECLARE_INPUT(WinDialog,bool);
77     BBTK_DECLARE_INPUT(WinHide,Void);
78     BBTK_DECLARE_INPUT(WinClose,Void);
79     BBTK_DECLARE_OUTPUT(Widget,Widget*);
80
81     //==================================================================
82     /// Overloaded bbCreateWindow method for WidgetBlackBoxes which handles 
83     /// the window creation if needed
84     virtual void bbCreateWindow();
85     //==================================================================
86     
87     //==================================================================
88     /// Overloaded bbShowWindow method for WidgetBlackBoxes which handles 
89     /// the window creation if needed
90     virtual void bbShowWindow();
91     //==================================================================    
92
93     //==================================================================
94     /// Returns the **OWN** window associated to the box
95     /// If 0 returned = no window
96     Window* bbGetWindow() { return bbmWindow; }
97     /// Returns the window containing the widget associated to the box
98     /// Which can be the own window of **ANOTHER** box in case of 
99     /// a hierarchy of widgets (layouts)
100     /// More precisely :
101     /// If bbGetWindow() != 0 then returns bbGetWindow()
102     /// Else if the output 'Widget' is connected 
103     ///  then returns bbGetContainingWindow() of the box connected to 'Widget'
104     /// Else returns 0;
105     Window* bbGetContainingWindow();
106
107
108     /// Returns true iff the 'containing window' exists and is shown 
109     /// (see bbGetContainingWindow).
110     bool bbIsShown();
111
112     /// Convenient method which returns true iff the output Widget is connected
113     bool bbIsOutputWidgetConnected();
114
115     //==================================================================    
116     /// User callback invoked when the containing window is shown
117     virtual void bbUserOnShow() {}
118     //==================================================================    
119  
120     //==================================================================    
121     /// User callback invoked when the containing window is hidden
122     virtual void bbUserOnHide() {}
123     //==================================================================    
124
125     /// Sets the window
126     inline void bbSetWindow(Window* w) { bbmWindow=w; }
127
128     //==================================================================    
129     /// User callback for creating the widget associated to the box
130     /// ** Must be defined ** in user classes
131     virtual void bbUserCreateWidget(Widget* parent) 
132     {
133       bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbUserCreateWidget methods is not overloaded : is it a feature or a bug ?!?");
134     }
135     //==================================================================    
136
137           
138   protected:
139     
140   
141     //==================================================================
142     /// User callback called in the box contructor
143     virtual void bbUserConstructor();
144     /// User callback called in the box copy constructor
145     virtual void bbUserCopyConstructor(bbtk::BlackBox::Pointer);
146     /// User callback called in the box destructor
147     virtual void bbUserDestructor();
148     //==================================================================    
149
150  
151
152
153     //==================================================================
154     /// Convenient method for layout widgets which creates and returns
155     /// (calls bbUserCreateWidget) 
156     /// the widget of the box connected to the input in.
157     /// Returns NULL if the input is not connected
158     Widget* bbCreateWidgetOfInput(const std::string& in, 
159                                   Widget* parent);
160     //==================================================================
161
162    //==================================================================    
163     /// Callback for creating a Dialog window (modal)
164     /// ** Must be defined ** in toolkit specific descendants 
165     virtual void bbCreateDialogWindow()
166     {
167       bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbCreateDialogWindow method is not overloaded ?!?");
168     }
169     //==================================================================    
170
171  //==================================================================    
172     /// Callback for creating a Frame window 
173     /// ** Must be defined ** in toolkit specific descendants 
174     virtual void bbCreateFrameWindow()
175     {
176       bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbCreateFrameWindow method is not overloaded ?!?");
177     }
178     //==================================================================    
179     //==================================================================
180     /// Overloaded processing method for WidgetBlackBoxes
181     virtual void bbProcess();
182     //==================================================================
183
184     //==================================================================
185     /// Hides the WidgetBlackBoxWindow associated to the box (if exists)
186     void bbHideWindow();
187     /// Closes (destroys) the WidgetBlackBoxWindow associated to the box 
188     /// (if exists)
189     void bbCloseWindow();
190     //==================================================================
191
192     
193     //==================================================================
194     //   virtual void InitWindowManagerIfNeeded();
195     virtual void IncNbWindowsAlive() {}
196     virtual void DecNbWindowsAlive() {}
197     virtual int  GetNbWindowsAlive() { return 0; }
198     virtual bool IsSomeWindowAlive() { return false; }
199     
200     virtual void IncNbWindowsShown() {}
201     virtual void DecNbWindowsShown() {}
202     virtual int  GetNbWindowsShown() { return 0; }
203     virtual bool IsSomeWindowShown() { return false; }
204     //==================================================================
205
206
207   private:
208     /// friendship
209     friend class WidgetBlackBoxWindow<W>;
210     //    friend class WidgetBlackBoxWidgetEventHandler;
211
212     /// The WidgetBlackBoxWindow associated to the box
213     Window* bbmWindow;
214
215
216     void bbInitAttributes();
217
218   };
219   //=================================================================
220  
221
222   //======================================================================
223   /// Defines the bbUserCreateWidget method
224 #define BBTK_CREATE_WIDGET(CALLBACK)                                    \
225   public:                                                               \
226   inline void bbUserCreateWidget(Widget* parent)                        \
227   {                                                                     \
228     bbtkDebugMessageInc("kw",1,"**> Creating widget for ["              \
229                         <<bbGetFullName()<<"]"<<std::endl);             \
230     CALLBACK(parent);                                                   \
231     bbtkDebugMessageInc("kw",1,"<** Creating widget for ["              \
232                         <<bbGetFullName()<<"]"<<std::endl);             \
233   }
234   
235   //======================================================================
236
237   //======================================================================
238   /// Defines the bbUserOnShow method
239 #define BBTK_ON_SHOW_WIDGET(CALLBACK)                                   \
240   public:                                                               \
241   inline void bbUserOnShow()                                    \
242   {                                                                     \
243     bbtkDebugMessageInc("wx",1,"**> Showing ["          \
244                         <<bbGetFullName()<<"]"<<std::endl);             \
245     CALLBACK();                                                         \
246     bbtkDebugMessageInc("wx",1,"<** Showing ["          \
247                         <<bbGetFullName()<<"]"<<std::endl);             \
248   }
249   
250   //======================================================================
251
252   //=================================================================
253   // WidgetBlackBoxDescriptor declaration
254   BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(WidgetBlackBox,bbtk::AtomicBlackBox);
255   BBTK_NAME("WidgetBlackBox_"+HumanTypeName<T>());
256   // BBTK_DESCRIPTION("Widget box. The inputs marked with (*) are only used if the widget is not inserted in another widget.\n");
257   BBTK_CATEGORY("widget");
258   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinTitle,
259              "Title of the window (*)",
260              std::string);
261   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinWidth,
262              "Width of the window (* : only used if the widget is not connected to a Layout box)",int);
263   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinHeight,
264              "Height of the window (*)",int);
265   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinDialog,
266              "Set to 'true' to create a dialog window, i.e. which blocks the pipeline until it is closed (modal) (*)",bool);
267   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinHide,
268              "Any signal received hides the window (*)",Void);
269   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinClose,
270              "Any signal received closes the window (*)",Void);
271   typedef typename WidgetBlackBox<T>::WidgetPointer WidgetPointer;
272   BBTK_TEMPLATE_OUTPUT(WidgetBlackBox,Widget,"Output widget",WidgetPointer);
273   BBTK_END_DESCRIBE_BLACK_BOX(WidgetBlackBox);
274   //=================================================================
275
276
277
278
279
280
281
282
283
284 } //namespace bbtk
285
286 // template code inclusion
287 #include "bbtkWidgetBlackBox.txx"
288
289 // WidgetBlackBoxWindow interface + code inclusion
290 #include "bbtkWidgetBlackBoxWindow.h"
291
292 #endif  //__bbtkWidgetBlackBox_h__