1 /*=========================================================================
4 Module: $RCSfile: bbtkWxBlackBox.h,v $
6 Date: $Date: 2008/01/28 14:32:54 $
7 Version: $Revision: 1.3 $
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.
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.
17 =========================================================================*//**
18 * \brief Short description in one line
20 * Long description which
21 * can span multiple lines
33 #ifdef _USE_WXWIDGETS_
36 #ifndef __bbtkWxBlackBox_h__
37 #define __bbtkWxBlackBox_h__
41 #include "bbtkUserBlackBox.h"
50 //==================================================================
51 // Forward declaration of the class of window associated to a WxBlackBox
52 class WxBlackBoxWindow;
53 //==================================================================
55 //==================================================================
56 // Forward declaration of the widget event handler class
57 class WxBlackBoxWidgetEventHandler;
58 //==================================================================
61 //==================================================================
62 /// Widget black boxes
63 class BBTK_EXPORT WxBlackBox : public bbtk::UserBlackBox
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*);
75 typedef WxBlackBoxWindow Window;
77 /// Returns the window associated to the box
78 /// If 0 returned = no window
79 Window* bbGetWindow() { return bbmWindow; }
81 /// Returns the Parent Window that must be used to create the widget
82 wxWindow* bbGetWxParent() { return bbGlobalGetTopWindow(); }
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*);
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);}
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);}
102 static wxWindow* bbmgTopWindow;
103 static int bbmgNbWindowsAlive;
104 static int bbmgNbWindowsShown;
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 //==================================================================
118 //==================================================================
119 /// User callback for creating the widget associated to the box
120 /// ** Must be defined **
121 virtual void bbUserCreateWidget()
123 bbtkError(bbGetTypeName()<<" is a WxBlackBox whose bbUserCreateWidget methods is undefined : cannot work !!");
125 //==================================================================
127 //==================================================================
128 /// Calls the user defined widget creation method
129 /// and the user processing method and then displays the window
130 virtual void bbProcess()
132 if (bbGetOutputWidget()==0) this->bbUserCreateWidget();
133 this->bbUserProcess();
136 //==================================================================
138 //==================================================================
139 /// Specific methods for windows creation during pipeline execution
142 //==================================================================
146 friend class WxBlackBoxWindow;
147 friend class WxBlackBoxWidgetEventHandler;
150 inline void bbSetWindow(Window* w) { bbmWindow=w; }
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; }
160 /// The WxBlackBoxWindow associated to the box
162 /// The WxBlackBoxWidgetEventHandler associated to the box
163 WxBlackBoxWidgetEventHandler* bbmWidgetEventHandler;
166 void bbInitAttributes();
170 //=================================================================
173 //======================================================================
174 /// Defines the bbUserCreateWidget method
175 #define BBTK_CREATE_WIDGET(CALLBACK) \
177 inline void bbUserCreateWidget() \
179 bbtkDebugMessageInc("Process",1,"=> "<<bbGetTypeName()<<"::bbUserCreateWidget() [" \
180 <<bbGetFullName()<<"]"<<std::endl); \
182 bbtkDebugMessageDec("Process",1,"<= "<<bbGetTypeName()<<"::bbUserCreateWidget() [" \
183 <<bbGetFullName()<<"]"<<std::endl); \
186 //======================================================================
188 //=================================================================
189 // UserBlackBox description
190 BBTK_BEGIN_DESCRIBE_BLACK_BOX(WxBlackBox,bbtk::UserBlackBox);
191 BBTK_NAME("WxBlackBox");
192 // BBTK_INPUT_NOCOPY(WxBlackBox,WinParent,"Parent widget box",
193 // WxParentToChildData*);
194 BBTK_INPUT(WxBlackBox,WinTitle,
195 "Title of the window (only used if the box is the top window of a Parent-Child hierarchy)",
197 BBTK_INPUT(WxBlackBox,WinWidth,
198 "Width of the window (only used if the box is the top window of a Parent-Child hierarchy)",int);
199 BBTK_INPUT(WxBlackBox,WinHeight,
200 "Height of the window (only used if the box is the top window of a Parent-Child hierarchy)",int);
201 BBTK_INPUT(WxBlackBox,WinDialog,
202 "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);
203 BBTK_INPUT(WxBlackBox,WinHide,
204 "Any signal received hides the window (only active if the box is the top window of a Parent-Child hierarchy)",Void);
205 BBTK_OUTPUT(WxBlackBox,Widget,"Output widget",wxWindow*);
206 BBTK_END_DESCRIBE_BLACK_BOX(WxBlackBox);
207 //=================================================================
217 //==================================================================
218 // The base of the hierarchy of windows associated to a WxBlackBox
219 class BBTK_EXPORT WxBlackBoxWindow //: public wxWindow
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; }
234 //==================================================================
236 //==================================================================
237 // Dialog window which is modal
238 class BBTK_EXPORT WxBlackBoxDialog : public wxDialog, public WxBlackBoxWindow
241 WxBlackBoxDialog(WxBlackBox* box,
242 wxWindow *parent, wxString title, wxSize size);
246 wxDialog* bbGetDialog() { return this; }
248 //==================================================================
250 //==================================================================
251 // Frame window which is not modal
252 class BBTK_EXPORT WxBlackBoxFrame : public wxFrame, public WxBlackBoxWindow
255 WxBlackBoxFrame(WxBlackBox* box,
256 wxWindow *parent, wxString title, wxSize size);
260 wxFrame* bbGetFrame() { return this; }
262 //==================================================================
266 //=================================================================
267 /// Class from which a user defined widget associated to a WxBlackBox
269 class BBTK_EXPORT WxBlackBoxWidget
272 /// Ctor with the WxBlackBox which created it
273 WxBlackBoxWidget( WxBlackBox* box);
275 virtual ~WxBlackBoxWidget();
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; }
282 /// Returns the wxWindow associated to the widget
283 virtual wxWindow* GetWxWindow() { return 0; }
285 virtual bool IsDead() { return false; }
290 //=================================================================
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
299 /// Ctor with the box and widget
300 WxBlackBoxWidgetEventHandler( WxBlackBox* box, wxWindow *widget );
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&);
309 //bool IsDead() { return mDead; }
316 //=================================================================
319 //=================================================================
320 /// A WxBlackBoxWidget which is a wxPanel also
321 class BBTK_EXPORT WxBlackBoxWidgetPanel :
323 public WxBlackBoxWidget
324 // public WxBlackBoxWidget,
328 /// Ctor with the parent and the WxBlackBox which created it
329 WxBlackBoxWidgetPanel(WxBlackBox* box, wxWindow *parent)
331 wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
332 WxBlackBoxWidget(box)
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); }
341 //=================================================================
347 #endif //__bbtkWxBlackBox_h__
349 #endif //_USE_WXWIDGETS_