]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxBlackBox.h
Recreated the complete cvs tree because the project architecture deeply changed
[bbtk.git] / kernel / src / bbtkWxBlackBox.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkWxBlackBox.h,v $
5   Language:  C++
6   Date:      $Date: 2008/01/22 15:02:00 $
7   Version:   $Revision: 1.1.1.1 $
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     BBTK_PROCESS(Process);
74
75   public:
76     typedef WxBlackBoxWindow Window;
77     
78     /// Returns the window associated to the box
79     /// If 0 returned = no window
80     Window* bbGetWindow() { return bbmWindow; }
81
82     /// Returns the Parent Window that must be used to create the widget 
83     wxWindow* bbGetWxParent() { return bbGlobalGetTopWindow(); }
84
85
86     /// Returns the global parent of all bbtk windows
87     static wxWindow* bbGlobalGetTopWindow();
88     /// Sets the global parent of all bbtk windows
89     static void bbGlobalSetTopWindow(wxWindow*);
90
91     static void bbGlobalIncNbWindowsAlive() { bbmgNbWindowsAlive++; }
92     static void bbGlobalDecNbWindowsAlive();
93     static int  bbGlobalGetNbWindowsAlive() { return bbmgNbWindowsAlive; }
94     static bool bbGlobalIsSomeWindowAlive() { return (bbmgNbWindowsAlive>0);}
95
96     static void bbGlobalDecNbWindowsShown();
97     static void bbGlobalIncNbWindowsShown() { bbmgNbWindowsShown++; }
98     static int  bbGlobalGetNbWindowsShown() { return bbmgNbWindowsShown; }
99     static bool bbGlobalIsSomeWindowShown() { return (bbmgNbWindowsShown>0);}
100
101
102   private:
103     static wxWindow* bbmgTopWindow;
104     static int bbmgNbWindowsAlive;
105     static int bbmgNbWindowsShown;
106
107   protected:
108     
109   
110     //==================================================================
111     /// User callback called in the box contructor
112     virtual void bbUserConstructor();
113     /// User callback called in the box copy constructor
114     virtual void bbUserCopyConstructor();
115     /// User callback called in the box destructor
116     virtual void bbUserDestructor();
117     //==================================================================    
118
119     /*
120
121     //==================================================================    
122     /// User callback for creating the window associated to the box
123     /// Can be overloaded in order to impose your own window to show,
124     /// Typically if your widget is already a dialog that cannot 
125     /// be inserted into a parent.
126     /// WARNING : If you use it then your widget will not be inserted 
127     /// in the parent window, if any 
128     /// (i.e. even if the Parent-Child connection is set)
129     virtual Window* bbUserCreateWindow()
130     {
131       return 0;
132     }
133     //==================================================================    
134
135     //==================================================================    
136     /// User callback for creating the widget associated to the box
137     /// Must be defined if bbUserCreateWindow is not 
138     virtual Widget* bbUserCreateWidget(wxWindow *parent) 
139     {
140       bbtkError(bbGetTypeName()<<" is a WxBlackBox whose bbUserCreateWindow and bbUserCreateWidget methods are both undefined : cannot work !!");
141       return 0;
142     }
143     //==================================================================    
144     */
145
146     //==================================================================
147     /// Specific methods for windows creation during pipeline execution
148     //void bbCreateWindow();
149     void bbShowWindow(Connection* caller);
150     void bbHideWindow();
151     //==================================================================
152
153     void Process() { } 
154
155   private:
156     /// friendship
157     friend class WxBlackBoxWindow;
158     friend class WxBlackBoxWidgetEventHandler;
159
160     /// Sets the window
161     inline void bbSetWindow(Window* w) { bbmWindow=w; }
162
163     /// Sets the Widget Event Handler
164     inline void bbSetWidgetEventHandler(WxBlackBoxWidgetEventHandler* w) 
165     { bbmWidgetEventHandler = w; }
166     /// Gets the Widget Event Handler
167     inline WxBlackBoxWidgetEventHandler* bbGetWidgetEventHandler()
168     { return bbmWidgetEventHandler; }
169
170
171     /// The WxBlackBoxWindow associated to the box
172     Window* bbmWindow;
173     /// The WxBlackBoxWidgetEventHandler associated to the box
174     WxBlackBoxWidgetEventHandler* bbmWidgetEventHandler;
175
176
177     void bbInitAttributes();
178
179
180   };
181   //=================================================================
182  
183
184   //=================================================================
185   // UserBlackBox description
186   BBTK_BEGIN_DESCRIBE_BLACK_BOX(WxBlackBox,bbtk::UserBlackBox);
187   BBTK_NAME("WxBlackBox");
188   //  BBTK_INPUT_NOCOPY(WxBlackBox,WinParent,"Parent widget box",
189   //                WxParentToChildData*);
190   BBTK_INPUT(WxBlackBox,WinTitle,
191              "Title of the window (only used if the box is the top window of a Parent-Child hierarchy)",
192              std::string);
193   BBTK_INPUT(WxBlackBox,WinWidth,
194              "Width of the window (only used if the box is the top window of a Parent-Child hierarchy)",int);
195   BBTK_INPUT(WxBlackBox,WinHeight,
196              "Height of the window (only used if the box is the top window of a Parent-Child hierarchy)",int);
197   BBTK_INPUT(WxBlackBox,WinDialog,
198              "Set to 'true' to have a dialog window, i.e. which is modal (steals the focus until closed) (only used if the box is the top window of a Parent-Child hierarchy)",bool);
199   BBTK_INPUT(WxBlackBox,WinHide,
200              "Any signal received hides the window (only active if the box is the top window of a Parent-Child hierarchy)",Void);
201   BBTK_OUTPUT(WxBlackBox,Widget,"Output widget",wxWindow*);
202   BBTK_END_DESCRIBE_BLACK_BOX(WxBlackBox);
203   //=================================================================
204
205
206
207
208
209
210
211
212
213   //==================================================================
214   // The base of the hierarchy of windows associated to a WxBlackBox
215   class BBTK_EXPORT WxBlackBoxWindow //: public wxWindow
216   {
217   public:
218     WxBlackBoxWindow(WxBlackBox* box);
219     virtual ~WxBlackBoxWindow();
220     virtual void bbShow();
221     virtual void bbHide();
222     bool bbIsShown() { return mShown; }
223     virtual WxBlackBox* bbGetBlackBox() { return mBox; }
224     virtual wxDialog* bbGetDialog() { return 0; } 
225     virtual wxFrame* bbGetFrame() { return 0; } 
226   private:
227     WxBlackBox* mBox;
228     bool mShown;
229   };
230   //==================================================================
231
232   //==================================================================
233   // Dialog window which is modal
234   class BBTK_EXPORT  WxBlackBoxDialog : public wxDialog, public WxBlackBoxWindow
235   {
236   public:
237     WxBlackBoxDialog(WxBlackBox* box, 
238                      wxWindow *parent, wxString title, wxSize size);
239     ~WxBlackBoxDialog();
240     void bbShow();  
241     void bbHide();
242     wxDialog* bbGetDialog() { return this; } 
243   };
244   //==================================================================
245
246   //==================================================================
247   // Frame window which is not modal
248   class BBTK_EXPORT  WxBlackBoxFrame : public wxFrame, public WxBlackBoxWindow
249   {
250   public:
251     WxBlackBoxFrame(WxBlackBox* box,
252                     wxWindow *parent, wxString title, wxSize size);
253     ~WxBlackBoxFrame();
254     void bbShow();
255     void bbHide();
256     wxFrame* bbGetFrame() { return this; } 
257   };
258   //==================================================================
259
260
261   /*
262  //=================================================================
263   /// Class from which a user defined widget associated to a WxBlackBox 
264   /// should inherit
265   class BBTK_EXPORT  WxBlackBoxWidget
266   {
267   public:
268     /// Ctor with the WxBlackBox which created it 
269     WxBlackBoxWidget( WxBlackBox* box);
270     /// Dtor
271     virtual ~WxBlackBoxWidget();
272
273     /// Returns the WxBlackBox which created it
274     WxBlackBox* GetBlackBox() { return mBox; }
275     /// Returns the WxBlackBox which created it (const)
276     const WxBlackBox* GetBlackBox() const { return mBox; }
277
278     /// Returns the wxWindow associated to the widget
279     virtual wxWindow* GetWxWindow() { return 0; }
280
281     virtual bool IsDead() { return false; }
282
283   private:
284     WxBlackBox* mBox;
285   };  
286   //=================================================================
287   */
288
289   //=================================================================
290   // Handles the destroy events of a widget associated to a WxBlackBox 
291   // in order to signal the widget death to its associated box
292   class BBTK_EXPORT WxBlackBoxWidgetEventHandler : public wxEvtHandler
293   {
294   public:
295     /// Ctor with the box and widget 
296     WxBlackBoxWidgetEventHandler( WxBlackBox* box, wxWindow *widget );
297     /// Dtor
298     ~WxBlackBoxWidgetEventHandler();
299     /// Returns true iff is the handler for that window  
300     bool IsHandlerOf( wxWindow* w ) { return mWindow == w; }
301     // wxWindow* GetWxWindow() { return mWindow; }
302     /// Method processing the destroy event of the widget
303     void OnWindowDestroy(wxWindowDestroyEvent&);
304     //
305     //bool IsDead() { return mDead; }
306
307   private:
308     WxBlackBox* mBox;
309     wxWindow* mWindow;
310     //bool mDead;
311   };  
312   //=================================================================
313
314   /*
315   //=================================================================
316   /// A WxBlackBoxWidget which is a wxPanel also
317   class BBTK_EXPORT  WxBlackBoxWidgetPanel :      
318                                 public wxPanel,
319                                 public WxBlackBoxWidget
320 //                              public WxBlackBoxWidget,
321 //                              public wxPanel
322   {
323   public:
324     /// Ctor with the parent and the WxBlackBox which created it 
325     WxBlackBoxWidgetPanel(WxBlackBox* box,  wxWindow *parent)
326       :
327       wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
328       WxBlackBoxWidget(box)
329     {}
330     
331     /// Returns the top panel of the widget    
332     wxWindow* GetWxWindow() { return (wxWindow*)(wxPanel*)(this); }
333     /// Returns the top panel of the widget    
334     wxPanel* GetPanel() { return (wxPanel*)(this); }
335
336   };  
337   //=================================================================
338   */
339
340
341 } //namespace bbtk
342
343 #endif  //__bbtkWxBlackBox_h__
344
345 #endif  //_USE_WXWIDGETS_