1 /*=========================================================================
3 Module: $RCSfile: bbtkWxBlackBox.h,v $
5 Date: $Date: 2008/10/17 08:18:15 $
6 Version: $Revision: 1.18 $
7 ========================================================================*/
10 /* ---------------------------------------------------------------------
12 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
13 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
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.
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
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 * ------------------------------------------------------------------------ */
32 * \brief Short description in one line
34 * Long description which
35 * can span multiple lines
47 #ifdef _USE_WXWIDGETS_
50 #ifndef __bbtkWxBlackBox_h__
51 #define __bbtkWxBlackBox_h__
55 #include "bbtkAtomicBlackBox.h"
64 //==================================================================
65 // Forward declaration of the class of window associated to a WxBlackBox
66 class WxBlackBoxWindow;
67 //==================================================================
69 //==================================================================
70 // Forward declaration of the widget event handler class
71 class WxBlackBoxWidgetEventHandler;
72 //==================================================================
75 //==================================================================
76 /// Widget black boxes
77 class BBTK_EXPORT WxBlackBox : public bbtk::AtomicBlackBox
79 BBTK_BLACK_BOX_INTERFACE(WxBlackBox,bbtk::AtomicBlackBox);
80 // BBTK_DECLARE_INPUT(WinParent,WxParentToChildData*);
81 BBTK_DECLARE_INPUT(WinTitle,std::string);
82 BBTK_DECLARE_INPUT(WinWidth,int);
83 BBTK_DECLARE_INPUT(WinHeight,int);
84 BBTK_DECLARE_INPUT(WinDialog,bool);
85 BBTK_DECLARE_INPUT(WinHide,Void);
86 BBTK_DECLARE_INPUT(WinClose,Void);
87 BBTK_DECLARE_OUTPUT(Widget, wxWindow*);//WxBlackBoxWidget*);
90 /// 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)
91 virtual void bbExecute(bool force = false);
94 typedef WxBlackBoxWindow Window;
96 /// Returns the **OWN** window associated to the box
97 /// If 0 returned = no window
98 Window* bbGetWindow() { return bbmWindow; }
100 /// Returns the window containing the widget associated to the box
101 /// Which can be the own window of **ANOTHER** box in case of
102 /// a hierarchy of widgets.
104 /// If bbGetWindow() != 0 then returns bbGetWindow()
105 /// Else if the output 'Widget' is connected
106 /// then returns bbGetContainingWindow() of the box connected to 'Widget'
108 Window* bbGetContainingWindow();
110 /// Returns the parent wxWindow that must be used to create the widget
111 wxWindow* bbGetWxParent();
113 /// Returns true iff the 'containing window' exists and is shown
114 /// (see bbGetContainingWindow).
117 //==================================================================
118 /// User callback invoked when the containing window is shown
119 virtual void bbUserOnShow() {}
120 //==================================================================
122 //==================================================================
123 /// User callback invoked when the containing window is hidden
124 virtual void bbUserOnHide() {}
125 //==================================================================
130 //==================================================================
131 /// User callback called in the box contructor
132 virtual void bbUserConstructor();
133 /// User callback called in the box copy constructor
134 virtual void bbUserCopyConstructor();
135 /// User callback called in the box destructor
136 virtual void bbUserDestructor();
137 //==================================================================
139 //==================================================================
140 /// User callback for creating the widget associated to the box
141 /// ** Must be defined **
142 virtual void bbUserCreateWidget()
144 bbtkError(bbGetTypeName()<<" is a WxBlackBox whose bbUserCreateWidget methods is not overloaded : is it a feature or a bug ?!?");
146 //==================================================================
151 //==================================================================
152 /// Main processing method of the box.
153 virtual IOStatus bbBackwardUpdate( Connection::Pointer caller );
154 //==================================================================
158 //==================================================================
159 /// Overloaded processing method for WxBlackBoxes :
160 /// 1) if the widget is null then
161 /// calls the user defined widget creation method : bbUserCreateWidget()
162 /// 2) calls the user defined processing method : bbUserProcess()
163 /// 3) displays the window : bbShowWindow();
164 virtual void bbProcess();
165 //==================================================================
167 //==================================================================
168 /// If necessary creates the WxBlackBoxWindow associated to the box
170 /// (does nothing if the box output 'Widget' is connected which
171 /// means that the box does not have its own window but is contained
172 /// into another window)
174 /// Hides the WxBlackBoxWindow associated to the box (if exists)
176 /// Closes (destroys) the WxBlackBoxWindow associated to the box (if exists)
177 void bbCloseWindow();
178 //==================================================================
182 friend class WxBlackBoxWindow;
183 friend class WxBlackBoxWidgetEventHandler;
186 inline void bbSetWindow(Window* w) { bbmWindow=w; }
188 /// Sets the Widget Event Handler
189 inline void bbSetWidgetEventHandler(WxBlackBoxWidgetEventHandler* w)
190 { bbmWidgetEventHandler = w; }
191 /// Gets the Widget Event Handler
192 inline WxBlackBoxWidgetEventHandler* bbGetWidgetEventHandler()
193 { return bbmWidgetEventHandler; }
196 /// The WxBlackBoxWindow associated to the box
198 /// The WxBlackBoxWidgetEventHandler associated to the box
199 WxBlackBoxWidgetEventHandler* bbmWidgetEventHandler;
202 void bbInitAttributes();
207 /// For Forward update mechanism when execution is called
208 /// on a contained window
209 /// Is set to true before transfering update to parent
210 /// in order to not re-transfer a second time...
211 bool bbmUpdateTransferedToParent;
213 bool bbGetUpdateTransferedToParent() const { return bbmUpdateTransferedToParent; }
214 void bbSetUpdateTransferedToParent(bool b)
215 { bbmUpdateTransferedToParent = b; }
218 //=================================================================
221 //======================================================================
222 /// Defines the bbUserCreateWidget method
223 #define BBTK_CREATE_WIDGET(CALLBACK) \
225 inline void bbUserCreateWidget() \
227 bbtkDebugMessageInc("process",1,"**> Creating widget for [" \
228 <<bbGetFullName()<<"]"<<std::endl); \
230 bbtkDebugMessageInc("process",2,"<** Creating widget for [" \
231 <<bbGetFullName()<<"]"<<std::endl); \
234 //======================================================================
236 //=================================================================
237 // WxBlackBoxDescriptor declaration
238 BBTK_BEGIN_DESCRIBE_BLACK_BOX(WxBlackBox,bbtk::AtomicBlackBox);
239 BBTK_NAME("WxBlackBox");
240 // BBTK_DESCRIPTION("Widget box. The inputs marked with (*) are only used if the widget is not inserted in another widget.\n");
241 BBTK_CATEGORY("widget");
242 BBTK_INPUT(WxBlackBox,WinTitle,
243 "Title of the window (*)",
245 BBTK_INPUT(WxBlackBox,WinWidth,
246 "Width of the window (* : only used if the widget is not connected to a Layout box)",int,"");
247 BBTK_INPUT(WxBlackBox,WinHeight,
248 "Height of the window (*)",int,"");
249 BBTK_INPUT(WxBlackBox,WinDialog,
250 "Set to 'true' to create a dialog window, i.e. which blocks the pipeline until it is closed (modal) (*)",bool,"");
251 BBTK_INPUT(WxBlackBox,WinHide,
252 "Any signal received hides the window (*)",Void,"signal");
253 BBTK_INPUT(WxBlackBox,WinClose,
254 "Any signal received closes the window (*)",Void,"signal");
255 BBTK_OUTPUT(WxBlackBox,Widget,"Output widget",wxWindow*,"");
256 BBTK_END_DESCRIBE_BLACK_BOX(WxBlackBox);
257 //=================================================================
267 //==================================================================
268 // The base of the hierarchy of windows associated to a WxBlackBox
269 class BBTK_EXPORT WxBlackBoxWindow //: public wxWindow
272 WxBlackBoxWindow(WxBlackBox::Pointer box);
273 virtual ~WxBlackBoxWindow();
274 virtual void bbShow();
275 virtual void bbHide();
276 virtual void bbClose();
277 bool bbIsShown() { return mShown; }
278 virtual WxBlackBox::Pointer bbGetBlackBox() { return mBox.lock(); }
279 virtual wxDialog* bbGetDialog() { return 0; }
280 virtual wxFrame* bbGetFrame() { return 0; }
282 WxBlackBox::WeakPointer mBox;
285 //==================================================================
287 //==================================================================
288 // Dialog window which is modal
289 class BBTK_EXPORT WxBlackBoxDialog : public wxDialog, public WxBlackBoxWindow
292 WxBlackBoxDialog(WxBlackBox::Pointer box,
293 wxWindow *parent, wxString title, wxSize size);
298 wxDialog* bbGetDialog() { return this; }
300 //==================================================================
302 //==================================================================
303 // Frame window which is not modal
304 class BBTK_EXPORT WxBlackBoxFrame : public wxFrame, public WxBlackBoxWindow
307 WxBlackBoxFrame(WxBlackBox::Pointer box,
308 wxWindow *parent, wxString title, wxSize size);
313 wxFrame* bbGetFrame() { return this; }
315 //==================================================================
319 //=================================================================
320 // Handles the destroy events of a widget associated to a WxBlackBox
321 // in order to signal the widget death to its associated box
322 class BBTK_EXPORT WxBlackBoxWidgetEventHandler : public wxEvtHandler
325 /// Ctor with the box and widget
326 WxBlackBoxWidgetEventHandler( WxBlackBox::Pointer box, wxWindow *widget );
328 ~WxBlackBoxWidgetEventHandler();
329 /// Returns true iff is the handler for that window
330 bool IsHandlerOf( wxWindow* w ) { return mWindow == w; }
331 // wxWindow* GetWxWindow() { return mWindow; }
332 /// Method processing the destroy event of the widget
333 void OnWindowDestroy(wxWindowDestroyEvent&);
335 //bool IsDead() { return mDead; }
338 WxBlackBox::WeakPointer mBox;
342 //=================================================================
348 #endif //__bbtkWxBlackBox_h__
350 #endif //_USE_WXWIDGETS_