1 /*=========================================================================
4 Module: $RCSfile: bbtkWxBlackBox.h,v $
6 Date: $Date: 2008/02/08 10:05:38 $
7 Version: $Revision: 1.7 $
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 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 Wx::GetTopWindow(); }
89 //==================================================================
90 /// User callback called in the box contructor
91 virtual void bbUserConstructor();
92 /// User callback called in the box copy constructor
93 virtual void bbUserCopyConstructor();
94 /// User callback called in the box destructor
95 virtual void bbUserDestructor();
96 //==================================================================
98 //==================================================================
99 /// User callback for creating the widget associated to the box
100 /// ** Must be defined **
101 virtual void bbUserCreateWidget()
103 bbtkError(bbGetTypeName()<<" is a WxBlackBox whose bbUserCreateWidget methods is undefined : cannot work !!");
105 //==================================================================
107 //==================================================================
108 /// Calls the user defined widget creation method
109 /// and the user processing method and then displays the window
110 virtual void bbProcess()
112 if (bbGetOutputWidget()==0) this->bbUserCreateWidget();
113 this->bbUserProcess();
116 //==================================================================
118 //==================================================================
119 /// Specific methods for windows creation during pipeline execution
122 //==================================================================
126 friend class WxBlackBoxWindow;
127 friend class WxBlackBoxWidgetEventHandler;
130 inline void bbSetWindow(Window* w) { bbmWindow=w; }
132 /// Sets the Widget Event Handler
133 inline void bbSetWidgetEventHandler(WxBlackBoxWidgetEventHandler* w)
134 { bbmWidgetEventHandler = w; }
135 /// Gets the Widget Event Handler
136 inline WxBlackBoxWidgetEventHandler* bbGetWidgetEventHandler()
137 { return bbmWidgetEventHandler; }
140 /// The WxBlackBoxWindow associated to the box
142 /// The WxBlackBoxWidgetEventHandler associated to the box
143 WxBlackBoxWidgetEventHandler* bbmWidgetEventHandler;
146 void bbInitAttributes();
150 //=================================================================
153 //======================================================================
154 /// Defines the bbUserCreateWidget method
155 #define BBTK_CREATE_WIDGET(CALLBACK) \
157 inline void bbUserCreateWidget() \
159 bbtkDebugMessageInc("Process",1,"=> "<<bbGetTypeName()<<"::bbUserCreateWidget() [" \
160 <<bbGetFullName()<<"]"<<std::endl); \
162 bbtkDebugMessageDec("Process",1,"<= "<<bbGetTypeName()<<"::bbUserCreateWidget() [" \
163 <<bbGetFullName()<<"]"<<std::endl); \
166 //======================================================================
168 //=================================================================
169 // WxBlackBoxDescriptor declaration
170 BBTK_BEGIN_DESCRIBE_BLACK_BOX(WxBlackBox,bbtk::AtomicBlackBox);
171 BBTK_NAME("WxBlackBox");
172 // BBTK_DESCRIPTION("Widget box. The inputs marked with (*) are only used if the widget is not inserted in another widget.\n");
173 BBTK_CATEGORY("widget");
174 BBTK_INPUT(WxBlackBox,WinTitle,
175 "Title of the window (*)",
177 BBTK_INPUT(WxBlackBox,WinWidth,
178 "Width of the window (* : only used if the widget is not inserted in another widget)",int);
179 BBTK_INPUT(WxBlackBox,WinHeight,
180 "Height of the window (*)",int);
181 BBTK_INPUT(WxBlackBox,WinDialog,
182 "Set to 'true' to create a dialog window, i.e. which blocks the pipeline until it is closed (modal) (*)",bool);
183 BBTK_INPUT(WxBlackBox,WinHide,
184 "Any signal received hides the window (*)",Void);
185 BBTK_OUTPUT(WxBlackBox,Widget,"Output widget",wxWindow*);
186 BBTK_END_DESCRIBE_BLACK_BOX(WxBlackBox);
187 //=================================================================
197 //==================================================================
198 // The base of the hierarchy of windows associated to a WxBlackBox
199 class BBTK_EXPORT WxBlackBoxWindow //: public wxWindow
202 WxBlackBoxWindow(WxBlackBox* box);
203 virtual ~WxBlackBoxWindow();
204 virtual void bbShow();
205 virtual void bbHide();
206 bool bbIsShown() { return mShown; }
207 virtual WxBlackBox* bbGetBlackBox() { return mBox; }
208 virtual wxDialog* bbGetDialog() { return 0; }
209 virtual wxFrame* bbGetFrame() { return 0; }
214 //==================================================================
216 //==================================================================
217 // Dialog window which is modal
218 class BBTK_EXPORT WxBlackBoxDialog : public wxDialog, public WxBlackBoxWindow
221 WxBlackBoxDialog(WxBlackBox* box,
222 wxWindow *parent, wxString title, wxSize size);
226 wxDialog* bbGetDialog() { return this; }
228 //==================================================================
230 //==================================================================
231 // Frame window which is not modal
232 class BBTK_EXPORT WxBlackBoxFrame : public wxFrame, public WxBlackBoxWindow
235 WxBlackBoxFrame(WxBlackBox* box,
236 wxWindow *parent, wxString title, wxSize size);
240 wxFrame* bbGetFrame() { return this; }
242 //==================================================================
246 //=================================================================
247 /// Class from which a user defined widget associated to a WxBlackBox
249 class BBTK_EXPORT WxBlackBoxWidget
252 /// Ctor with the WxBlackBox which created it
253 WxBlackBoxWidget( WxBlackBox* box);
255 virtual ~WxBlackBoxWidget();
257 /// Returns the WxBlackBox which created it
258 WxBlackBox* GetBlackBox() { return mBox; }
259 /// Returns the WxBlackBox which created it (const)
260 const WxBlackBox* GetBlackBox() const { return mBox; }
262 /// Returns the wxWindow associated to the widget
263 virtual wxWindow* GetWxWindow() { return 0; }
265 virtual bool IsDead() { return false; }
270 //=================================================================
273 //=================================================================
274 // Handles the destroy events of a widget associated to a WxBlackBox
275 // in order to signal the widget death to its associated box
276 class BBTK_EXPORT WxBlackBoxWidgetEventHandler : public wxEvtHandler
279 /// Ctor with the box and widget
280 WxBlackBoxWidgetEventHandler( WxBlackBox* box, wxWindow *widget );
282 ~WxBlackBoxWidgetEventHandler();
283 /// Returns true iff is the handler for that window
284 bool IsHandlerOf( wxWindow* w ) { return mWindow == w; }
285 // wxWindow* GetWxWindow() { return mWindow; }
286 /// Method processing the destroy event of the widget
287 void OnWindowDestroy(wxWindowDestroyEvent&);
289 //bool IsDead() { return mDead; }
296 //=================================================================
299 //=================================================================
300 /// A WxBlackBoxWidget which is a wxPanel also
301 class BBTK_EXPORT WxBlackBoxWidgetPanel :
303 public WxBlackBoxWidget
304 // public WxBlackBoxWidget,
308 /// Ctor with the parent and the WxBlackBox which created it
309 WxBlackBoxWidgetPanel(WxBlackBox* box, wxWindow *parent)
311 wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
312 WxBlackBoxWidget(box)
315 /// Returns the top panel of the widget
316 wxWindow* GetWxWindow() { return (wxWindow*)(wxPanel*)(this); }
317 /// Returns the top panel of the widget
318 wxPanel* GetPanel() { return (wxPanel*)(this); }
321 //=================================================================
327 #endif //__bbtkWxBlackBox_h__
329 #endif //_USE_WXWIDGETS_