]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxBlackBox.h
MACOS configure
[bbtk.git] / kernel / src / bbtkWxBlackBox.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWxBlackBox.h,v $
4   Language:  C++
5   Date:      $Date: 2009/03/23 13:06:41 $
6   Version:   $Revision: 1.25 $
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
46
47 #ifdef USE_WXWIDGETS
48
49
50 #ifndef __bbtkWxBlackBox_h__
51 #define __bbtkWxBlackBox_h__
52
53
54 #include "bbtkWx.h"
55 #include "bbtkAtomicBlackBox.h"
56
57
58 namespace bbtk
59 {
60
61
62
63
64   //==================================================================
65   // Forward declaration of the class of window associated to a WxBlackBox
66   class WxBlackBoxWindow;
67   //==================================================================
68
69   //==================================================================
70   // Forward declaration of the widget event handler class
71   class WxBlackBoxWidgetEventHandler;
72   //==================================================================
73
74
75   //==================================================================
76   /// Widget black boxes
77   class BBTK_EXPORT WxBlackBox : public bbtk::AtomicBlackBox  
78   { 
79     BBTK_BLACK_BOX_INTERFACE(WxBlackBox,bbtk::AtomicBlackBox);
80     BBTK_DECLARE_INPUT(WinTitle,std::string);
81     BBTK_DECLARE_INPUT(WinWidth,int);
82     BBTK_DECLARE_INPUT(WinHeight,int);
83     BBTK_DECLARE_INPUT(WinDialog,bool);
84     BBTK_DECLARE_INPUT(WinHide,Void);
85     BBTK_DECLARE_INPUT(WinClose,Void);
86     BBTK_DECLARE_OUTPUT(Widget, wxWindow*);
87
88   public:
89     /// 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 (as the container window must be created and displayed - this box will be executed by the normal pipeline recursion mechanism)
90     //   virtual void bbExecute(bool force = false);
91
92
93     typedef WxBlackBoxWindow Window;
94     
95     /// Returns the **OWN** window associated to the box
96     /// If 0 returned = no window
97     Window* bbGetWindow() { return bbmWindow; }
98
99     /// Returns the window containing the widget associated to the box
100     /// Which can be the own window of **ANOTHER** box in case of 
101     /// a hierarchy of widgets.
102     /// More precisely :
103     /// If bbGetWindow() != 0 then returns bbGetWindow()
104     /// Else if the output 'Widget' is connected 
105     ///  then returns bbGetContainingWindow() of the box connected to 'Widget'
106     /// Else returns 0;
107     Window* bbGetContainingWindow();
108
109     /// Returns true iff the 'containing window' exists and is shown 
110     /// (see bbGetContainingWindow).
111     bool bbIsShown();
112
113     //==================================================================    
114     /// User callback invoked when the containing window is shown
115     virtual void bbUserOnShow() {}
116     //==================================================================    
117  
118     //==================================================================    
119     /// User callback invoked when the containing window is hidden
120     virtual void bbUserOnHide() {}
121     //==================================================================    
122
123
124     //==================================================================    
125     void bbCreateWidgetAndEventHandler(wxWindow* parent); 
126     //==================================================================    
127           
128   protected:
129     
130   
131     //==================================================================
132     /// User callback called in the box contructor
133     virtual void bbUserConstructor();
134     /// User callback called in the box copy constructor
135     virtual void bbUserCopyConstructor(bbtk::BlackBox::Pointer);
136     /// User callback called in the box destructor
137     virtual void bbUserDestructor();
138     //==================================================================    
139
140     //==================================================================    
141     /// User callback for creating the widget associated to the box
142     /// ** Must be defined **
143     virtual void bbUserCreateWidget(wxWindow* parent) 
144     {
145       bbtkError(bbGetTypeName()<<" is a WxBlackBox whose bbUserCreateWidget methods is not overloaded : is it a feature or a bug ?!?");
146     }
147     //==================================================================    
148
149
150     //==================================================================    
151     // For layout widgets : creates and returns the widget 
152     // of the box connected to input in
153     wxWindow* bbCreateWidgetOfInput(const std::string& in, wxWindow* parent);
154     //==================================================================    
155
156  
157
158           //==================================================================
159           /// Overloaded bbCreateWidget method for WxBlackBoxes which handles 
160           /// the window creation if needed
161           virtual void bbCreateWidget();
162           //==================================================================
163           
164           //==================================================================
165           /// Overloaded bbShowWidget method for WxBlackBoxes which handles 
166           /// the window creation if needed
167           virtual void bbShowWidget();
168           //==================================================================
169           
170           //==================================================================
171     /// Overloaded processing method for WxBlackBoxes which handles 
172     /// the window creation if needed
173     virtual void bbProcess();
174     //==================================================================
175           
176           
177           
178           
179           
180     //==================================================================
181     /// If necessary creates the WxBlackBoxWindow associated to the box
182     /// and shows it 
183     /// (does nothing if the box output 'Widget' is connected which 
184     /// means that the box does not have its own window but is contained 
185     /// into another window)
186     //    void bbShowWindow();
187     /// Hides the WxBlackBoxWindow associated to the box (if exists)
188     void bbHideWindow();
189     /// Closes (destroys) the WxBlackBoxWindow associated to the box (if exists)
190     void bbCloseWindow();
191     //==================================================================
192
193   private:
194     /// friendship
195     friend class WxBlackBoxWindow;
196     friend class WxBlackBoxWidgetEventHandler;
197
198     /// Sets the window
199     inline void bbSetWindow(Window* w) { bbmWindow=w; }
200
201     /// Sets the Widget Event Handler
202     inline void bbSetWidgetEventHandler(WxBlackBoxWidgetEventHandler* w) 
203     { bbmWidgetEventHandler = w; }
204     /// Gets the Widget Event Handler
205     inline WxBlackBoxWidgetEventHandler* bbGetWidgetEventHandler()
206     { return bbmWidgetEventHandler; }
207
208
209     /// The WxBlackBoxWindow associated to the box
210     Window* bbmWindow;
211           
212     /// The WxBlackBoxWidgetEventHandler associated to the box
213     WxBlackBoxWidgetEventHandler* bbmWidgetEventHandler;
214
215
216     void bbInitAttributes();
217
218   protected :
219
220
221     /// For Forward update mechanism when execution is called 
222     /// on a contained window
223     /// Is set to true before transfering update to parent 
224     /// in order to not re-transfer a second time...
225     /*
226     bool bbmUpdateTransferedToParent;
227
228     bool bbGetUpdateTransferedToParent() const { return bbmUpdateTransferedToParent; }
229     void bbSetUpdateTransferedToParent(bool b) 
230     { bbmUpdateTransferedToParent = b; }
231     */
232   };
233   //=================================================================
234  
235
236   //======================================================================
237   /// Defines the bbUserCreateWidget method
238 #define BBTK_CREATE_WIDGET(CALLBACK)                                    \
239   public:                                                               \
240   inline void bbUserCreateWidget(wxWindow* parent)                                      \
241   {                                                                     \
242     bbtkDebugMessageInc("wx",1,"**> Creating widget for ["              \
243                         <<bbGetFullName()<<"]"<<std::endl);             \
244     CALLBACK(parent);                                                           \
245     bbtkDebugMessageInc("wx",1,"<** Creating widget for ["              \
246                         <<bbGetFullName()<<"]"<<std::endl);             \
247   }
248   
249   //======================================================================
250
251   //======================================================================
252   /// Defines the bbUserOnShow method
253 #define BBTK_ON_SHOW_WIDGET(CALLBACK)                                   \
254   public:                                                               \
255   inline void bbUserOnShow()                                    \
256   {                                                                     \
257     bbtkDebugMessageInc("wx",1,"**> Showing ["          \
258                         <<bbGetFullName()<<"]"<<std::endl);             \
259     CALLBACK();                                                         \
260     bbtkDebugMessageInc("wx",1,"<** Showing ["          \
261                         <<bbGetFullName()<<"]"<<std::endl);             \
262   }
263   
264   //======================================================================
265
266   //=================================================================
267   // WxBlackBoxDescriptor declaration
268   BBTK_BEGIN_DESCRIBE_BLACK_BOX(WxBlackBox,bbtk::AtomicBlackBox);
269   BBTK_NAME("WxBlackBox");
270   // BBTK_DESCRIPTION("Widget box. The inputs marked with (*) are only used if the widget is not inserted in another widget.\n");
271   BBTK_CATEGORY("widget");
272   BBTK_INPUT(WxBlackBox,WinTitle,
273              "Title of the window (*)",
274              std::string,"");
275   BBTK_INPUT(WxBlackBox,WinWidth,
276              "Width of the window (* : only used if the widget is not connected to a Layout box)",int,"");
277   BBTK_INPUT(WxBlackBox,WinHeight,
278              "Height of the window (*)",int,"");
279   BBTK_INPUT(WxBlackBox,WinDialog,
280              "Set to 'true' to create a dialog window, i.e. which blocks the pipeline until it is closed (modal) (*)",bool,"");
281   BBTK_INPUT(WxBlackBox,WinHide,
282              "Any signal received hides the window (*)",Void,"signal");
283   BBTK_INPUT(WxBlackBox,WinClose,
284              "Any signal received closes the window (*)",Void,"signal");
285   BBTK_OUTPUT(WxBlackBox,Widget,"Output widget",wxWindow*,"");
286   BBTK_END_DESCRIBE_BLACK_BOX(WxBlackBox);
287   //=================================================================
288
289
290
291
292
293
294
295
296
297   //==================================================================
298   // The base of the hierarchy of windows associated to a WxBlackBox
299   class BBTK_EXPORT WxBlackBoxWindow //: public wxWindow
300   {
301   public:
302     WxBlackBoxWindow(WxBlackBox::Pointer box);
303     virtual ~WxBlackBoxWindow();
304     virtual void bbShow();
305     virtual void bbHide();
306     virtual void bbClose();
307     bool bbIsShown() { return mShown; }
308     virtual WxBlackBox::Pointer bbGetBlackBox() { return mBox.lock(); }
309     virtual wxDialog* bbGetDialog() { return 0; } 
310     virtual wxFrame* bbGetFrame() { return 0; } 
311   private:
312     WxBlackBox::WeakPointer mBox;
313     bool mShown;
314   };
315   //==================================================================
316
317   //==================================================================
318   // Dialog window which is modal
319   class BBTK_EXPORT  WxBlackBoxDialog : public wxDialog, public WxBlackBoxWindow
320   {
321   public:
322     WxBlackBoxDialog(WxBlackBox::Pointer box, 
323                      wxWindow *parent, wxString title, wxSize size);
324     ~WxBlackBoxDialog();
325     void bbShow();  
326     void bbHide();
327     void bbClose();
328     wxDialog* bbGetDialog() { return this; } 
329   };
330   //==================================================================
331
332   //==================================================================
333   // Frame window which is not modal
334   class BBTK_EXPORT  WxBlackBoxFrame : public wxFrame, public WxBlackBoxWindow
335   {
336   public:
337     WxBlackBoxFrame(WxBlackBox::Pointer box,
338                     wxWindow *parent, wxString title, wxSize size);
339     ~WxBlackBoxFrame();
340     void bbShow();
341     void bbHide();
342     void bbClose();
343     wxFrame* bbGetFrame() { return this; } 
344   };
345   //==================================================================
346
347
348
349   //=================================================================
350   // Handles the destroy events of a widget associated to a WxBlackBox 
351   // in order to signal the widget death to its associated box
352   class BBTK_EXPORT WxBlackBoxWidgetEventHandler : public wxEvtHandler
353   {
354   public:
355     /// Ctor with the box and widget 
356     WxBlackBoxWidgetEventHandler( WxBlackBox::Pointer box, wxWindow *widget );
357     /// Dtor
358     ~WxBlackBoxWidgetEventHandler();
359     /// Returns true iff is the handler for that window  
360     bool IsHandlerOf( wxWindow* w ) { return mWindow == w; }
361     // wxWindow* GetWxWindow() { return mWindow; }
362     /// Method processing the destroy event of the widget
363     void OnWindowDestroy(wxWindowDestroyEvent&);
364     //
365     //bool IsDead() { return mDead; }
366
367   private:
368     WxBlackBox::WeakPointer mBox;
369     wxWindow* mWindow;
370     //bool mDead;
371   };  
372   //=================================================================
373
374
375
376 } //namespace bbtk
377
378 #endif  //__bbtkWxBlackBox_h__
379
380 #endif  //USE_WXWIDGETS