]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxBlackBox.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkWxBlackBox.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkWxBlackBox.h,v $
5   Language:  C++
6   Date:      $Date: 2008/02/06 14:58:41 $
7   Version:   $Revision: 1.5 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*//**
18  * \brief Short description in one line
19  * 
20  * Long description which 
21  * can span multiple lines
22  */
23 /**
24  * \file 
25  * \brief 
26  */
27 /**
28  * \class bbtk::
29  * \brief 
30  */
31
32
33 #ifdef _USE_WXWIDGETS_
34
35
36 #ifndef __bbtkWxBlackBox_h__
37 #define __bbtkWxBlackBox_h__
38
39
40 #include "bbtkWx.h"
41 #include "bbtkUserBlackBox.h"
42
43
44 namespace bbtk
45 {
46
47
48
49
50   //==================================================================
51   // Forward declaration of the class of window associated to a WxBlackBox
52   class WxBlackBoxWindow;
53   //==================================================================
54
55   //==================================================================
56   // Forward declaration of the widget event handler class
57   class WxBlackBoxWidgetEventHandler;
58   //==================================================================
59
60
61   //==================================================================
62   /// Widget black boxes
63   class BBTK_EXPORT WxBlackBox : public bbtk::UserBlackBox  
64   {
65     BBTK_USER_BLACK_BOX_INTERFACE(WxBlackBox,bbtk::UserBlackBox);
66     //   BBTK_DECLARE_INPUT(WinParent,WxParentToChildData*);
67     BBTK_DECLARE_INPUT(WinTitle,std::string);
68     BBTK_DECLARE_INPUT(WinWidth,int);
69     BBTK_DECLARE_INPUT(WinHeight,int);
70     BBTK_DECLARE_INPUT(WinDialog,bool);
71     BBTK_DECLARE_INPUT(WinHide,Void);
72     BBTK_DECLARE_OUTPUT(Widget, wxWindow*);//WxBlackBoxWidget*);
73
74   public:
75     typedef WxBlackBoxWindow Window;
76     
77     /// Returns the window associated to the box
78     /// If 0 returned = no window
79     Window* bbGetWindow() { return bbmWindow; }
80
81     /// Returns the Parent Window that must be used to create the widget 
82     wxWindow* bbGetWxParent() { return bbGlobalGetTopWindow(); }
83
84
85     /// Returns the global parent of all bbtk windows
86     static wxWindow* bbGlobalGetTopWindow();
87     /// Sets the global parent of all bbtk windows
88     static void bbGlobalSetTopWindow(wxWindow*);
89
90         static void bbGlobalIncNbWindowsAlive() { WxBlackBox::bbmgNbWindowsAlive++; }
91     static void bbGlobalDecNbWindowsAlive();
92     static int  bbGlobalGetNbWindowsAlive() { return WxBlackBox::bbmgNbWindowsAlive; }
93     static bool bbGlobalIsSomeWindowAlive() { return (WxBlackBox::bbmgNbWindowsAlive>0);}
94
95     static void bbGlobalDecNbWindowsShown();
96     static void bbGlobalIncNbWindowsShown() { WxBlackBox::bbmgNbWindowsShown++; }
97         static int  bbGlobalGetNbWindowsShown() { return WxBlackBox::bbmgNbWindowsShown; }
98         static bool bbGlobalIsSomeWindowShown() { return (WxBlackBox::bbmgNbWindowsShown>0);}
99
100
101   private:
102     static wxWindow* bbmgTopWindow;
103     static int bbmgNbWindowsAlive;
104     static int bbmgNbWindowsShown;
105
106   protected:
107     
108   
109     //==================================================================
110     /// User callback called in the box contructor
111     virtual void bbUserConstructor();
112     /// User callback called in the box copy constructor
113     virtual void bbUserCopyConstructor();
114     /// User callback called in the box destructor
115     virtual void bbUserDestructor();
116     //==================================================================    
117
118     //==================================================================    
119     /// User callback for creating the widget associated to the box
120     /// ** Must be defined **
121     virtual void bbUserCreateWidget() 
122     {
123       bbtkError(bbGetTypeName()<<" is a WxBlackBox whose bbUserCreateWidget methods is undefined : cannot work !!");
124     }
125     //==================================================================    
126     
127     //==================================================================
128     /// Calls the user defined widget creation method 
129     /// and the user processing method and then displays the window
130     virtual void bbProcess() 
131     { 
132       if (bbGetOutputWidget()==0) this->bbUserCreateWidget();
133       this->bbUserProcess(); 
134       bbShowWindow();
135     }
136     //==================================================================
137
138     //==================================================================
139     /// Specific methods for windows creation during pipeline execution
140     void bbShowWindow();
141     void bbHideWindow();
142     //==================================================================
143
144   private:
145     /// friendship
146     friend class WxBlackBoxWindow;
147     friend class WxBlackBoxWidgetEventHandler;
148
149     /// Sets the window
150     inline void bbSetWindow(Window* w) { bbmWindow=w; }
151
152     /// Sets the Widget Event Handler
153     inline void bbSetWidgetEventHandler(WxBlackBoxWidgetEventHandler* w) 
154     { bbmWidgetEventHandler = w; }
155     /// Gets the Widget Event Handler
156     inline WxBlackBoxWidgetEventHandler* bbGetWidgetEventHandler()
157     { return bbmWidgetEventHandler; }
158
159
160     /// The WxBlackBoxWindow associated to the box
161     Window* bbmWindow;
162     /// The WxBlackBoxWidgetEventHandler associated to the box
163     WxBlackBoxWidgetEventHandler* bbmWidgetEventHandler;
164
165
166     void bbInitAttributes();
167
168
169   };
170   //=================================================================
171  
172
173   //======================================================================
174   /// Defines the bbUserCreateWidget method
175 #define BBTK_CREATE_WIDGET(CALLBACK)                                    \
176   public:                                                               \
177   inline void bbUserCreateWidget()                                      \
178   {                                                                     \
179     bbtkDebugMessageInc("Process",1,"=> "<<bbGetTypeName()<<"::bbUserCreateWidget() [" \
180                         <<bbGetFullName()<<"]"<<std::endl);             \
181     CALLBACK();                                                         \
182     bbtkDebugMessageDec("Process",1,"<= "<<bbGetTypeName()<<"::bbUserCreateWidget() [" \
183                         <<bbGetFullName()<<"]"<<std::endl);             \
184   }
185   
186   //======================================================================
187
188   //=================================================================
189   // UserBlackBox description
190   BBTK_BEGIN_DESCRIBE_BLACK_BOX(WxBlackBox,bbtk::UserBlackBox);
191   BBTK_NAME("WxBlackBox");
192   // BBTK_DESCRIPTION("Widget box. The inputs marked with (*) are only used if the widget is not inserted in another widget.\n");
193   BBTK_CATEGORY("widget");
194   BBTK_INPUT(WxBlackBox,WinTitle,
195              "Title of the window (*)",
196              std::string);
197   BBTK_INPUT(WxBlackBox,WinWidth,
198              "Width of the window (* : only used if the widget is not inserted in another widget)",int);
199   BBTK_INPUT(WxBlackBox,WinHeight,
200              "Height of the window (*)",int);
201   BBTK_INPUT(WxBlackBox,WinDialog,
202              "Set to 'true' to create a dialog window, i.e. which blocks the pipeline until it is closed (modal) (*)",bool);
203   BBTK_INPUT(WxBlackBox,WinHide,
204              "Any signal received hides the window (*)",Void);
205   BBTK_OUTPUT(WxBlackBox,Widget,"Output widget",wxWindow*);
206   BBTK_END_DESCRIBE_BLACK_BOX(WxBlackBox);
207   //=================================================================
208
209
210
211
212
213
214
215
216
217   //==================================================================
218   // The base of the hierarchy of windows associated to a WxBlackBox
219   class BBTK_EXPORT WxBlackBoxWindow //: public wxWindow
220   {
221   public:
222     WxBlackBoxWindow(WxBlackBox* box);
223     virtual ~WxBlackBoxWindow();
224     virtual void bbShow();
225     virtual void bbHide();
226     bool bbIsShown() { return mShown; }
227     virtual WxBlackBox* bbGetBlackBox() { return mBox; }
228     virtual wxDialog* bbGetDialog() { return 0; } 
229     virtual wxFrame* bbGetFrame() { return 0; } 
230   private:
231     WxBlackBox* mBox;
232     bool mShown;
233   };
234   //==================================================================
235
236   //==================================================================
237   // Dialog window which is modal
238   class BBTK_EXPORT  WxBlackBoxDialog : public wxDialog, public WxBlackBoxWindow
239   {
240   public:
241     WxBlackBoxDialog(WxBlackBox* box, 
242                      wxWindow *parent, wxString title, wxSize size);
243     ~WxBlackBoxDialog();
244     void bbShow();  
245     void bbHide();
246     wxDialog* bbGetDialog() { return this; } 
247   };
248   //==================================================================
249
250   //==================================================================
251   // Frame window which is not modal
252   class BBTK_EXPORT  WxBlackBoxFrame : public wxFrame, public WxBlackBoxWindow
253   {
254   public:
255     WxBlackBoxFrame(WxBlackBox* box,
256                     wxWindow *parent, wxString title, wxSize size);
257     ~WxBlackBoxFrame();
258     void bbShow();
259     void bbHide();
260     wxFrame* bbGetFrame() { return this; } 
261   };
262   //==================================================================
263
264
265   /*
266  //=================================================================
267   /// Class from which a user defined widget associated to a WxBlackBox 
268   /// should inherit
269   class BBTK_EXPORT  WxBlackBoxWidget
270   {
271   public:
272     /// Ctor with the WxBlackBox which created it 
273     WxBlackBoxWidget( WxBlackBox* box);
274     /// Dtor
275     virtual ~WxBlackBoxWidget();
276
277     /// Returns the WxBlackBox which created it
278     WxBlackBox* GetBlackBox() { return mBox; }
279     /// Returns the WxBlackBox which created it (const)
280     const WxBlackBox* GetBlackBox() const { return mBox; }
281
282     /// Returns the wxWindow associated to the widget
283     virtual wxWindow* GetWxWindow() { return 0; }
284
285     virtual bool IsDead() { return false; }
286
287   private:
288     WxBlackBox* mBox;
289   };  
290   //=================================================================
291   */
292
293   //=================================================================
294   // Handles the destroy events of a widget associated to a WxBlackBox 
295   // in order to signal the widget death to its associated box
296   class BBTK_EXPORT WxBlackBoxWidgetEventHandler : public wxEvtHandler
297   {
298   public:
299     /// Ctor with the box and widget 
300     WxBlackBoxWidgetEventHandler( WxBlackBox* box, wxWindow *widget );
301     /// Dtor
302     ~WxBlackBoxWidgetEventHandler();
303     /// Returns true iff is the handler for that window  
304     bool IsHandlerOf( wxWindow* w ) { return mWindow == w; }
305     // wxWindow* GetWxWindow() { return mWindow; }
306     /// Method processing the destroy event of the widget
307     void OnWindowDestroy(wxWindowDestroyEvent&);
308     //
309     //bool IsDead() { return mDead; }
310
311   private:
312     WxBlackBox* mBox;
313     wxWindow* mWindow;
314     //bool mDead;
315   };  
316   //=================================================================
317
318   /*
319   //=================================================================
320   /// A WxBlackBoxWidget which is a wxPanel also
321   class BBTK_EXPORT  WxBlackBoxWidgetPanel :      
322                                 public wxPanel,
323                                 public WxBlackBoxWidget
324 //                              public WxBlackBoxWidget,
325 //                              public wxPanel
326   {
327   public:
328     /// Ctor with the parent and the WxBlackBox which created it 
329     WxBlackBoxWidgetPanel(WxBlackBox* box,  wxWindow *parent)
330       :
331       wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
332       WxBlackBoxWidget(box)
333     {}
334     
335     /// Returns the top panel of the widget    
336     wxWindow* GetWxWindow() { return (wxWindow*)(wxPanel*)(this); }
337     /// Returns the top panel of the widget    
338     wxPanel* GetPanel() { return (wxPanel*)(this); }
339
340   };  
341   //=================================================================
342   */
343
344
345 } //namespace bbtk
346
347 #endif  //__bbtkWxBlackBox_h__
348
349 #endif  //_USE_WXWIDGETS_