]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxBlackBox.h
Fix a big bug. Consider the script :
[bbtk.git] / kernel / src / bbtkWxBlackBox.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkWxBlackBox.h,v $
5   Language:  C++
6   Date:      $Date: 2008/03/06 09:23:43 $
7   Version:   $Revision: 1.8 $
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 "bbtkAtomicBlackBox.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::AtomicBlackBox  
64   {
65     BBTK_USER_BLACK_BOX_INTERFACE(WxBlackBox,bbtk::AtomicBlackBox);
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 Wx::GetTopWindow(); }
83
84
85  
86   protected:
87     
88   
89     //==================================================================
90     /// User callback called in the box contructor
91     virtual void bbUserConstructor();
92     /// User callback called in the box copy constructor
93     virtual void bbUserCopyConstructor();
94     /// User callback called in the box destructor
95     virtual void bbUserDestructor();
96     //==================================================================    
97
98     //==================================================================    
99     /// User callback for creating the widget associated to the box
100     /// ** Must be defined **
101     virtual void bbUserCreateWidget() 
102     {
103       bbtkError(bbGetTypeName()<<" is a WxBlackBox whose bbUserCreateWidget methods is undefined : cannot work !!");
104     }
105     //==================================================================    
106     
107     //==================================================================
108     /// Calls the user defined widget creation method 
109     /// and the user processing method and then displays the window
110     virtual void bbProcess() 
111     { 
112       if (bbGetOutputWidget()==0) this->bbUserCreateWidget();
113       this->bbUserProcess(); 
114       bbShowWindow();
115     }
116     //==================================================================
117
118     //==================================================================
119     /// Specific methods for windows creation during pipeline execution
120     void bbShowWindow();
121     void bbHideWindow();
122     //==================================================================
123
124   private:
125     /// friendship
126     friend class WxBlackBoxWindow;
127     friend class WxBlackBoxWidgetEventHandler;
128
129     /// Sets the window
130     inline void bbSetWindow(Window* w) { bbmWindow=w; }
131
132     /// Sets the Widget Event Handler
133     inline void bbSetWidgetEventHandler(WxBlackBoxWidgetEventHandler* w) 
134     { bbmWidgetEventHandler = w; }
135     /// Gets the Widget Event Handler
136     inline WxBlackBoxWidgetEventHandler* bbGetWidgetEventHandler()
137     { return bbmWidgetEventHandler; }
138
139
140     /// The WxBlackBoxWindow associated to the box
141     Window* bbmWindow;
142     /// The WxBlackBoxWidgetEventHandler associated to the box
143     WxBlackBoxWidgetEventHandler* bbmWidgetEventHandler;
144
145
146     void bbInitAttributes();
147
148   protected :
149     /// Main processing method of the box. Overloaded to handle windows inclusion : if the output Widget is connected then the execution is transfered to the box to which it is connected (the container window must be created and displayed - this box will be also executed by the normal pipeline recursion mechanism)
150     virtual void bbExecute(bool force = false);
151
152   };
153   //=================================================================
154  
155
156   //======================================================================
157   /// Defines the bbUserCreateWidget method
158 #define BBTK_CREATE_WIDGET(CALLBACK)                                    \
159   public:                                                               \
160   inline void bbUserCreateWidget()                                      \
161   {                                                                     \
162     bbtkDebugMessageInc("Process",1,"=> "<<bbGetTypeName()<<"::bbUserCreateWidget() [" \
163                         <<bbGetFullName()<<"]"<<std::endl);             \
164     CALLBACK();                                                         \
165     bbtkDebugMessageDec("Process",1,"<= "<<bbGetTypeName()<<"::bbUserCreateWidget() [" \
166                         <<bbGetFullName()<<"]"<<std::endl);             \
167   }
168   
169   //======================================================================
170
171   //=================================================================
172   // WxBlackBoxDescriptor declaration
173   BBTK_BEGIN_DESCRIBE_BLACK_BOX(WxBlackBox,bbtk::AtomicBlackBox);
174   BBTK_NAME("WxBlackBox");
175   // BBTK_DESCRIPTION("Widget box. The inputs marked with (*) are only used if the widget is not inserted in another widget.\n");
176   BBTK_CATEGORY("widget");
177   BBTK_INPUT(WxBlackBox,WinTitle,
178              "Title of the window (*)",
179              std::string);
180   BBTK_INPUT(WxBlackBox,WinWidth,
181              "Width of the window (* : only used if the widget is not inserted in another widget)",int);
182   BBTK_INPUT(WxBlackBox,WinHeight,
183              "Height of the window (*)",int);
184   BBTK_INPUT(WxBlackBox,WinDialog,
185              "Set to 'true' to create a dialog window, i.e. which blocks the pipeline until it is closed (modal) (*)",bool);
186   BBTK_INPUT(WxBlackBox,WinHide,
187              "Any signal received hides the window (*)",Void);
188   BBTK_OUTPUT(WxBlackBox,Widget,"Output widget",wxWindow*);
189   BBTK_END_DESCRIBE_BLACK_BOX(WxBlackBox);
190   //=================================================================
191
192
193
194
195
196
197
198
199
200   //==================================================================
201   // The base of the hierarchy of windows associated to a WxBlackBox
202   class BBTK_EXPORT WxBlackBoxWindow //: public wxWindow
203   {
204   public:
205     WxBlackBoxWindow(WxBlackBox* box);
206     virtual ~WxBlackBoxWindow();
207     virtual void bbShow();
208     virtual void bbHide();
209     bool bbIsShown() { return mShown; }
210     virtual WxBlackBox* bbGetBlackBox() { return mBox; }
211     virtual wxDialog* bbGetDialog() { return 0; } 
212     virtual wxFrame* bbGetFrame() { return 0; } 
213   private:
214     WxBlackBox* mBox;
215     bool mShown;
216   };
217   //==================================================================
218
219   //==================================================================
220   // Dialog window which is modal
221   class BBTK_EXPORT  WxBlackBoxDialog : public wxDialog, public WxBlackBoxWindow
222   {
223   public:
224     WxBlackBoxDialog(WxBlackBox* box, 
225                      wxWindow *parent, wxString title, wxSize size);
226     ~WxBlackBoxDialog();
227     void bbShow();  
228     void bbHide();
229     wxDialog* bbGetDialog() { return this; } 
230   };
231   //==================================================================
232
233   //==================================================================
234   // Frame window which is not modal
235   class BBTK_EXPORT  WxBlackBoxFrame : public wxFrame, public WxBlackBoxWindow
236   {
237   public:
238     WxBlackBoxFrame(WxBlackBox* box,
239                     wxWindow *parent, wxString title, wxSize size);
240     ~WxBlackBoxFrame();
241     void bbShow();
242     void bbHide();
243     wxFrame* bbGetFrame() { return this; } 
244   };
245   //==================================================================
246
247
248   /*
249  //=================================================================
250   /// Class from which a user defined widget associated to a WxBlackBox 
251   /// should inherit
252   class BBTK_EXPORT  WxBlackBoxWidget
253   {
254   public:
255     /// Ctor with the WxBlackBox which created it 
256     WxBlackBoxWidget( WxBlackBox* box);
257     /// Dtor
258     virtual ~WxBlackBoxWidget();
259
260     /// Returns the WxBlackBox which created it
261     WxBlackBox* GetBlackBox() { return mBox; }
262     /// Returns the WxBlackBox which created it (const)
263     const WxBlackBox* GetBlackBox() const { return mBox; }
264
265     /// Returns the wxWindow associated to the widget
266     virtual wxWindow* GetWxWindow() { return 0; }
267
268     virtual bool IsDead() { return false; }
269
270   private:
271     WxBlackBox* mBox;
272   };  
273   //=================================================================
274   */
275
276   //=================================================================
277   // Handles the destroy events of a widget associated to a WxBlackBox 
278   // in order to signal the widget death to its associated box
279   class BBTK_EXPORT WxBlackBoxWidgetEventHandler : public wxEvtHandler
280   {
281   public:
282     /// Ctor with the box and widget 
283     WxBlackBoxWidgetEventHandler( WxBlackBox* box, wxWindow *widget );
284     /// Dtor
285     ~WxBlackBoxWidgetEventHandler();
286     /// Returns true iff is the handler for that window  
287     bool IsHandlerOf( wxWindow* w ) { return mWindow == w; }
288     // wxWindow* GetWxWindow() { return mWindow; }
289     /// Method processing the destroy event of the widget
290     void OnWindowDestroy(wxWindowDestroyEvent&);
291     //
292     //bool IsDead() { return mDead; }
293
294   private:
295     WxBlackBox* mBox;
296     wxWindow* mWindow;
297     //bool mDead;
298   };  
299   //=================================================================
300
301   /*
302   //=================================================================
303   /// A WxBlackBoxWidget which is a wxPanel also
304   class BBTK_EXPORT  WxBlackBoxWidgetPanel :      
305                                 public wxPanel,
306                                 public WxBlackBoxWidget
307 //                              public WxBlackBoxWidget,
308 //                              public wxPanel
309   {
310   public:
311     /// Ctor with the parent and the WxBlackBox which created it 
312     WxBlackBoxWidgetPanel(WxBlackBox* box,  wxWindow *parent)
313       :
314       wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
315       WxBlackBoxWidget(box)
316     {}
317     
318     /// Returns the top panel of the widget    
319     wxWindow* GetWxWindow() { return (wxWindow*)(wxPanel*)(this); }
320     /// Returns the top panel of the widget    
321     wxPanel* GetPanel() { return (wxPanel*)(this); }
322
323   };  
324   //=================================================================
325   */
326
327
328 } //namespace bbtk
329
330 #endif  //__bbtkWxBlackBox_h__
331
332 #endif  //_USE_WXWIDGETS_