1 /*=========================================================================
4 Module: $RCSfile: bbtkWxBlackBox.h,v $
6 Date: $Date: 2008/04/08 06:59:30 $
7 Version: $Revision: 1.10 $
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 "bbtkAtomicBlackBox.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::AtomicBlackBox
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*);
75 typedef WxBlackBoxWindow Window;
77 /// Returns the **OWN** window associated to the box
78 /// If 0 returned = no window
79 Window* bbGetWindow() { return bbmWindow; }
81 /// Returns the window containing the widget associated to the box
82 /// Which can be the own window of **ANOTHER** box in case of
83 /// a hierarchy of widgets.
85 /// If bbGetWindow() != 0 then returns bbGetWindow()
86 /// Else if the output 'Widget' is connected
87 /// then returns bbGetContainingWindow() of the box connected to 'Widget'
89 Window* bbGetContainingWindow();
91 /// Returns the parent wxWindow that must be used to create the widget
92 wxWindow* bbGetWxParent();
94 /// Returns true iff the 'containing window' exists and is shown
95 /// (see bbGetContainingWindow).
98 //==================================================================
99 /// User callback invoked when the containing window is shown
100 virtual void bbUserOnShow() {}
101 //==================================================================
103 //==================================================================
104 /// User callback invoked when the containing window is hidden
105 virtual void bbUserOnHide() {}
106 //==================================================================
111 //==================================================================
112 /// User callback called in the box contructor
113 virtual void bbUserConstructor();
114 /// User callback called in the box copy constructor
115 virtual void bbUserCopyConstructor();
116 /// User callback called in the box destructor
117 virtual void bbUserDestructor();
118 //==================================================================
120 //==================================================================
121 /// User callback for creating the widget associated to the box
122 /// ** Must be defined **
123 virtual void bbUserCreateWidget()
125 bbtkError(bbGetTypeName()<<" is a WxBlackBox whose bbUserCreateWidget methods is not overloaded : is it a feature or a bug ?!?");
127 //==================================================================
132 //==================================================================
133 /// Main processing method of the box.
134 virtual IOStatus bbBackwardUpdate( Connection* caller );
135 //==================================================================
139 //==================================================================
140 /// Overloaded processing method for WxBlackBoxes :
141 /// 1) if the widget is null then
142 /// calls the user defined widget creation method : bbUserCreateWidget()
143 /// 2) calls the user defined processing method : bbUserProcess()
144 /// 3) displays the window : bbShowWindow();
145 virtual void bbProcess();
146 //==================================================================
148 //==================================================================
149 /// If necessary creates the WxBlackBoxWindow associated to the box
151 /// (does nothing if the box output 'Widget' is connected which
152 /// means that the box does not have its own window but is contained
153 /// into another window)
155 /// Hides the WxBlackBoxWindow associated to the box (if exists)
157 //==================================================================
161 friend class WxBlackBoxWindow;
162 friend class WxBlackBoxWidgetEventHandler;
165 inline void bbSetWindow(Window* w) { bbmWindow=w; }
167 /// Sets the Widget Event Handler
168 inline void bbSetWidgetEventHandler(WxBlackBoxWidgetEventHandler* w)
169 { bbmWidgetEventHandler = w; }
170 /// Gets the Widget Event Handler
171 inline WxBlackBoxWidgetEventHandler* bbGetWidgetEventHandler()
172 { return bbmWidgetEventHandler; }
175 /// The WxBlackBoxWindow associated to the box
177 /// The WxBlackBoxWidgetEventHandler associated to the box
178 WxBlackBoxWidgetEventHandler* bbmWidgetEventHandler;
181 void bbInitAttributes();
184 /// 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)
185 virtual void bbExecute(bool force = false);
188 //=================================================================
191 //======================================================================
192 /// Defines the bbUserCreateWidget method
193 #define BBTK_CREATE_WIDGET(CALLBACK) \
195 inline void bbUserCreateWidget() \
197 bbtkDebugMessageInc("Process",1,"=> "<<bbGetTypeName()<<"::bbUserCreateWidget() [" \
198 <<bbGetFullName()<<"]"<<std::endl); \
200 bbtkDebugMessageDec("Process",1,"<= "<<bbGetTypeName()<<"::bbUserCreateWidget() [" \
201 <<bbGetFullName()<<"]"<<std::endl); \
204 //======================================================================
206 //=================================================================
207 // WxBlackBoxDescriptor declaration
208 BBTK_BEGIN_DESCRIBE_BLACK_BOX(WxBlackBox,bbtk::AtomicBlackBox);
209 BBTK_NAME("WxBlackBox");
210 // BBTK_DESCRIPTION("Widget box. The inputs marked with (*) are only used if the widget is not inserted in another widget.\n");
211 BBTK_CATEGORY("widget");
212 BBTK_INPUT(WxBlackBox,WinTitle,
213 "Title of the window (*)",
215 BBTK_INPUT(WxBlackBox,WinWidth,
216 "Width of the window (* : only used if the widget is not inserted in another widget)",int,"");
217 BBTK_INPUT(WxBlackBox,WinHeight,
218 "Height of the window (*)",int,"");
219 BBTK_INPUT(WxBlackBox,WinDialog,
220 "Set to 'true' to create a dialog window, i.e. which blocks the pipeline until it is closed (modal) (*)",bool,"");
221 BBTK_INPUT(WxBlackBox,WinHide,
222 "Any signal received hides the window (*)",Void,"");
223 BBTK_OUTPUT(WxBlackBox,Widget,"Output widget",wxWindow*,"");
224 BBTK_END_DESCRIBE_BLACK_BOX(WxBlackBox);
225 //=================================================================
235 //==================================================================
236 // The base of the hierarchy of windows associated to a WxBlackBox
237 class BBTK_EXPORT WxBlackBoxWindow //: public wxWindow
240 WxBlackBoxWindow(WxBlackBox* box);
241 virtual ~WxBlackBoxWindow();
242 virtual void bbShow();
243 virtual void bbHide();
244 bool bbIsShown() { return mShown; }
245 virtual WxBlackBox* bbGetBlackBox() { return mBox; }
246 virtual wxDialog* bbGetDialog() { return 0; }
247 virtual wxFrame* bbGetFrame() { return 0; }
252 //==================================================================
254 //==================================================================
255 // Dialog window which is modal
256 class BBTK_EXPORT WxBlackBoxDialog : public wxDialog, public WxBlackBoxWindow
259 WxBlackBoxDialog(WxBlackBox* box,
260 wxWindow *parent, wxString title, wxSize size);
264 wxDialog* bbGetDialog() { return this; }
266 //==================================================================
268 //==================================================================
269 // Frame window which is not modal
270 class BBTK_EXPORT WxBlackBoxFrame : public wxFrame, public WxBlackBoxWindow
273 WxBlackBoxFrame(WxBlackBox* box,
274 wxWindow *parent, wxString title, wxSize size);
278 wxFrame* bbGetFrame() { return this; }
280 //==================================================================
284 //=================================================================
285 /// Class from which a user defined widget associated to a WxBlackBox
287 class BBTK_EXPORT WxBlackBoxWidget
290 /// Ctor with the WxBlackBox which created it
291 WxBlackBoxWidget( WxBlackBox* box);
293 virtual ~WxBlackBoxWidget();
295 /// Returns the WxBlackBox which created it
296 WxBlackBox* GetBlackBox() { return mBox; }
297 /// Returns the WxBlackBox which created it (const)
298 const WxBlackBox* GetBlackBox() const { return mBox; }
300 /// Returns the wxWindow associated to the widget
301 virtual wxWindow* GetWxWindow() { return 0; }
303 virtual bool IsDead() { return false; }
308 //=================================================================
311 //=================================================================
312 // Handles the destroy events of a widget associated to a WxBlackBox
313 // in order to signal the widget death to its associated box
314 class BBTK_EXPORT WxBlackBoxWidgetEventHandler : public wxEvtHandler
317 /// Ctor with the box and widget
318 WxBlackBoxWidgetEventHandler( WxBlackBox* box, wxWindow *widget );
320 ~WxBlackBoxWidgetEventHandler();
321 /// Returns true iff is the handler for that window
322 bool IsHandlerOf( wxWindow* w ) { return mWindow == w; }
323 // wxWindow* GetWxWindow() { return mWindow; }
324 /// Method processing the destroy event of the widget
325 void OnWindowDestroy(wxWindowDestroyEvent&);
327 //bool IsDead() { return mDead; }
334 //=================================================================
337 //=================================================================
338 /// A WxBlackBoxWidget which is a wxPanel also
339 class BBTK_EXPORT WxBlackBoxWidgetPanel :
341 public WxBlackBoxWidget
342 // public WxBlackBoxWidget,
346 /// Ctor with the parent and the WxBlackBox which created it
347 WxBlackBoxWidgetPanel(WxBlackBox* box, wxWindow *parent)
349 wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
350 WxBlackBoxWidget(box)
353 /// Returns the top panel of the widget
354 wxWindow* GetWxWindow() { return (wxWindow*)(wxPanel*)(this); }
355 /// Returns the top panel of the widget
356 wxPanel* GetPanel() { return (wxPanel*)(this); }
359 //=================================================================
365 #endif //__bbtkWxBlackBox_h__
367 #endif //_USE_WXWIDGETS_