1 /*=========================================================================
4 Module: $RCSfile: bbtkWxBlackBox.h,v $
6 Date: $Date: 2008/07/24 14:37:06 $
7 Version: $Revision: 1.17 $
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_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_INPUT(WinClose,Void);
73 BBTK_DECLARE_OUTPUT(Widget, wxWindow*);//WxBlackBoxWidget*);
76 /// 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)
77 virtual void bbExecute(bool force = false);
80 typedef WxBlackBoxWindow Window;
82 /// Returns the **OWN** window associated to the box
83 /// If 0 returned = no window
84 Window* bbGetWindow() { return bbmWindow; }
86 /// Returns the window containing the widget associated to the box
87 /// Which can be the own window of **ANOTHER** box in case of
88 /// a hierarchy of widgets.
90 /// If bbGetWindow() != 0 then returns bbGetWindow()
91 /// Else if the output 'Widget' is connected
92 /// then returns bbGetContainingWindow() of the box connected to 'Widget'
94 Window* bbGetContainingWindow();
96 /// Returns the parent wxWindow that must be used to create the widget
97 wxWindow* bbGetWxParent();
99 /// Returns true iff the 'containing window' exists and is shown
100 /// (see bbGetContainingWindow).
103 //==================================================================
104 /// User callback invoked when the containing window is shown
105 virtual void bbUserOnShow() {}
106 //==================================================================
108 //==================================================================
109 /// User callback invoked when the containing window is hidden
110 virtual void bbUserOnHide() {}
111 //==================================================================
116 //==================================================================
117 /// User callback called in the box contructor
118 virtual void bbUserConstructor();
119 /// User callback called in the box copy constructor
120 virtual void bbUserCopyConstructor();
121 /// User callback called in the box destructor
122 virtual void bbUserDestructor();
123 //==================================================================
125 //==================================================================
126 /// User callback for creating the widget associated to the box
127 /// ** Must be defined **
128 virtual void bbUserCreateWidget()
130 bbtkError(bbGetTypeName()<<" is a WxBlackBox whose bbUserCreateWidget methods is not overloaded : is it a feature or a bug ?!?");
132 //==================================================================
137 //==================================================================
138 /// Main processing method of the box.
139 virtual IOStatus bbBackwardUpdate( Connection::Pointer caller );
140 //==================================================================
144 //==================================================================
145 /// Overloaded processing method for WxBlackBoxes :
146 /// 1) if the widget is null then
147 /// calls the user defined widget creation method : bbUserCreateWidget()
148 /// 2) calls the user defined processing method : bbUserProcess()
149 /// 3) displays the window : bbShowWindow();
150 virtual void bbProcess();
151 //==================================================================
153 //==================================================================
154 /// If necessary creates the WxBlackBoxWindow associated to the box
156 /// (does nothing if the box output 'Widget' is connected which
157 /// means that the box does not have its own window but is contained
158 /// into another window)
160 /// Hides the WxBlackBoxWindow associated to the box (if exists)
162 /// Closes (destroys) the WxBlackBoxWindow associated to the box (if exists)
163 void bbCloseWindow();
164 //==================================================================
168 friend class WxBlackBoxWindow;
169 friend class WxBlackBoxWidgetEventHandler;
172 inline void bbSetWindow(Window* w) { bbmWindow=w; }
174 /// Sets the Widget Event Handler
175 inline void bbSetWidgetEventHandler(WxBlackBoxWidgetEventHandler* w)
176 { bbmWidgetEventHandler = w; }
177 /// Gets the Widget Event Handler
178 inline WxBlackBoxWidgetEventHandler* bbGetWidgetEventHandler()
179 { return bbmWidgetEventHandler; }
182 /// The WxBlackBoxWindow associated to the box
184 /// The WxBlackBoxWidgetEventHandler associated to the box
185 WxBlackBoxWidgetEventHandler* bbmWidgetEventHandler;
188 void bbInitAttributes();
193 /// For Forward update mechanism when execution is called
194 /// on a contained window
195 /// Is set to true before transfering update to parent
196 /// in order to not re-transfer a second time...
197 bool bbmUpdateTransferedToParent;
199 bool bbGetUpdateTransferedToParent() const { return bbmUpdateTransferedToParent; }
200 void bbSetUpdateTransferedToParent(bool b)
201 { bbmUpdateTransferedToParent = b; }
204 //=================================================================
207 //======================================================================
208 /// Defines the bbUserCreateWidget method
209 #define BBTK_CREATE_WIDGET(CALLBACK) \
211 inline void bbUserCreateWidget() \
213 bbtkDebugMessageInc("process",1,"**> Creating widget for [" \
214 <<bbGetFullName()<<"]"<<std::endl); \
216 bbtkDebugMessageInc("process",2,"<** Creating widget for [" \
217 <<bbGetFullName()<<"]"<<std::endl); \
220 //======================================================================
222 //=================================================================
223 // WxBlackBoxDescriptor declaration
224 BBTK_BEGIN_DESCRIBE_BLACK_BOX(WxBlackBox,bbtk::AtomicBlackBox);
225 BBTK_NAME("WxBlackBox");
226 // BBTK_DESCRIPTION("Widget box. The inputs marked with (*) are only used if the widget is not inserted in another widget.\n");
227 BBTK_CATEGORY("widget");
228 BBTK_INPUT(WxBlackBox,WinTitle,
229 "Title of the window (*)",
231 BBTK_INPUT(WxBlackBox,WinWidth,
232 "Width of the window (* : only used if the widget is not connected to a Layout box)",int,"");
233 BBTK_INPUT(WxBlackBox,WinHeight,
234 "Height of the window (*)",int,"");
235 BBTK_INPUT(WxBlackBox,WinDialog,
236 "Set to 'true' to create a dialog window, i.e. which blocks the pipeline until it is closed (modal) (*)",bool,"");
237 BBTK_INPUT(WxBlackBox,WinHide,
238 "Any signal received hides the window (*)",Void,"signal");
239 BBTK_INPUT(WxBlackBox,WinClose,
240 "Any signal received closes the window (*)",Void,"signal");
241 BBTK_OUTPUT(WxBlackBox,Widget,"Output widget",wxWindow*,"");
242 BBTK_END_DESCRIBE_BLACK_BOX(WxBlackBox);
243 //=================================================================
253 //==================================================================
254 // The base of the hierarchy of windows associated to a WxBlackBox
255 class BBTK_EXPORT WxBlackBoxWindow //: public wxWindow
258 WxBlackBoxWindow(WxBlackBox::Pointer box);
259 virtual ~WxBlackBoxWindow();
260 virtual void bbShow();
261 virtual void bbHide();
262 virtual void bbClose();
263 bool bbIsShown() { return mShown; }
264 virtual WxBlackBox::Pointer bbGetBlackBox() { return mBox.lock(); }
265 virtual wxDialog* bbGetDialog() { return 0; }
266 virtual wxFrame* bbGetFrame() { return 0; }
268 WxBlackBox::WeakPointer mBox;
271 //==================================================================
273 //==================================================================
274 // Dialog window which is modal
275 class BBTK_EXPORT WxBlackBoxDialog : public wxDialog, public WxBlackBoxWindow
278 WxBlackBoxDialog(WxBlackBox::Pointer box,
279 wxWindow *parent, wxString title, wxSize size);
284 wxDialog* bbGetDialog() { return this; }
286 //==================================================================
288 //==================================================================
289 // Frame window which is not modal
290 class BBTK_EXPORT WxBlackBoxFrame : public wxFrame, public WxBlackBoxWindow
293 WxBlackBoxFrame(WxBlackBox::Pointer box,
294 wxWindow *parent, wxString title, wxSize size);
299 wxFrame* bbGetFrame() { return this; }
301 //==================================================================
305 //=================================================================
306 // Handles the destroy events of a widget associated to a WxBlackBox
307 // in order to signal the widget death to its associated box
308 class BBTK_EXPORT WxBlackBoxWidgetEventHandler : public wxEvtHandler
311 /// Ctor with the box and widget
312 WxBlackBoxWidgetEventHandler( WxBlackBox::Pointer box, wxWindow *widget );
314 ~WxBlackBoxWidgetEventHandler();
315 /// Returns true iff is the handler for that window
316 bool IsHandlerOf( wxWindow* w ) { return mWindow == w; }
317 // wxWindow* GetWxWindow() { return mWindow; }
318 /// Method processing the destroy event of the widget
319 void OnWindowDestroy(wxWindowDestroyEvent&);
321 //bool IsDead() { return mDead; }
324 WxBlackBox::WeakPointer mBox;
328 //=================================================================
334 #endif //__bbtkWxBlackBox_h__
336 #endif //_USE_WXWIDGETS_