1 /*=========================================================================
4 Module: $RCSfile: bbtkWxBlackBox.h,v $
6 Date: $Date: 2008/01/22 15:02:00 $
7 Version: $Revision: 1.1.1.1 $
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*);
73 BBTK_PROCESS(Process);
76 typedef WxBlackBoxWindow Window;
78 /// Returns the window associated to the box
79 /// If 0 returned = no window
80 Window* bbGetWindow() { return bbmWindow; }
82 /// Returns the Parent Window that must be used to create the widget
83 wxWindow* bbGetWxParent() { return bbGlobalGetTopWindow(); }
86 /// Returns the global parent of all bbtk windows
87 static wxWindow* bbGlobalGetTopWindow();
88 /// Sets the global parent of all bbtk windows
89 static void bbGlobalSetTopWindow(wxWindow*);
91 static void bbGlobalIncNbWindowsAlive() { bbmgNbWindowsAlive++; }
92 static void bbGlobalDecNbWindowsAlive();
93 static int bbGlobalGetNbWindowsAlive() { return bbmgNbWindowsAlive; }
94 static bool bbGlobalIsSomeWindowAlive() { return (bbmgNbWindowsAlive>0);}
96 static void bbGlobalDecNbWindowsShown();
97 static void bbGlobalIncNbWindowsShown() { bbmgNbWindowsShown++; }
98 static int bbGlobalGetNbWindowsShown() { return bbmgNbWindowsShown; }
99 static bool bbGlobalIsSomeWindowShown() { return (bbmgNbWindowsShown>0);}
103 static wxWindow* bbmgTopWindow;
104 static int bbmgNbWindowsAlive;
105 static int bbmgNbWindowsShown;
110 //==================================================================
111 /// User callback called in the box contructor
112 virtual void bbUserConstructor();
113 /// User callback called in the box copy constructor
114 virtual void bbUserCopyConstructor();
115 /// User callback called in the box destructor
116 virtual void bbUserDestructor();
117 //==================================================================
121 //==================================================================
122 /// User callback for creating the window associated to the box
123 /// Can be overloaded in order to impose your own window to show,
124 /// Typically if your widget is already a dialog that cannot
125 /// be inserted into a parent.
126 /// WARNING : If you use it then your widget will not be inserted
127 /// in the parent window, if any
128 /// (i.e. even if the Parent-Child connection is set)
129 virtual Window* bbUserCreateWindow()
133 //==================================================================
135 //==================================================================
136 /// User callback for creating the widget associated to the box
137 /// Must be defined if bbUserCreateWindow is not
138 virtual Widget* bbUserCreateWidget(wxWindow *parent)
140 bbtkError(bbGetTypeName()<<" is a WxBlackBox whose bbUserCreateWindow and bbUserCreateWidget methods are both undefined : cannot work !!");
143 //==================================================================
146 //==================================================================
147 /// Specific methods for windows creation during pipeline execution
148 //void bbCreateWindow();
149 void bbShowWindow(Connection* caller);
151 //==================================================================
157 friend class WxBlackBoxWindow;
158 friend class WxBlackBoxWidgetEventHandler;
161 inline void bbSetWindow(Window* w) { bbmWindow=w; }
163 /// Sets the Widget Event Handler
164 inline void bbSetWidgetEventHandler(WxBlackBoxWidgetEventHandler* w)
165 { bbmWidgetEventHandler = w; }
166 /// Gets the Widget Event Handler
167 inline WxBlackBoxWidgetEventHandler* bbGetWidgetEventHandler()
168 { return bbmWidgetEventHandler; }
171 /// The WxBlackBoxWindow associated to the box
173 /// The WxBlackBoxWidgetEventHandler associated to the box
174 WxBlackBoxWidgetEventHandler* bbmWidgetEventHandler;
177 void bbInitAttributes();
181 //=================================================================
184 //=================================================================
185 // UserBlackBox description
186 BBTK_BEGIN_DESCRIBE_BLACK_BOX(WxBlackBox,bbtk::UserBlackBox);
187 BBTK_NAME("WxBlackBox");
188 // BBTK_INPUT_NOCOPY(WxBlackBox,WinParent,"Parent widget box",
189 // WxParentToChildData*);
190 BBTK_INPUT(WxBlackBox,WinTitle,
191 "Title of the window (only used if the box is the top window of a Parent-Child hierarchy)",
193 BBTK_INPUT(WxBlackBox,WinWidth,
194 "Width of the window (only used if the box is the top window of a Parent-Child hierarchy)",int);
195 BBTK_INPUT(WxBlackBox,WinHeight,
196 "Height of the window (only used if the box is the top window of a Parent-Child hierarchy)",int);
197 BBTK_INPUT(WxBlackBox,WinDialog,
198 "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);
199 BBTK_INPUT(WxBlackBox,WinHide,
200 "Any signal received hides the window (only active if the box is the top window of a Parent-Child hierarchy)",Void);
201 BBTK_OUTPUT(WxBlackBox,Widget,"Output widget",wxWindow*);
202 BBTK_END_DESCRIBE_BLACK_BOX(WxBlackBox);
203 //=================================================================
213 //==================================================================
214 // The base of the hierarchy of windows associated to a WxBlackBox
215 class BBTK_EXPORT WxBlackBoxWindow //: public wxWindow
218 WxBlackBoxWindow(WxBlackBox* box);
219 virtual ~WxBlackBoxWindow();
220 virtual void bbShow();
221 virtual void bbHide();
222 bool bbIsShown() { return mShown; }
223 virtual WxBlackBox* bbGetBlackBox() { return mBox; }
224 virtual wxDialog* bbGetDialog() { return 0; }
225 virtual wxFrame* bbGetFrame() { return 0; }
230 //==================================================================
232 //==================================================================
233 // Dialog window which is modal
234 class BBTK_EXPORT WxBlackBoxDialog : public wxDialog, public WxBlackBoxWindow
237 WxBlackBoxDialog(WxBlackBox* box,
238 wxWindow *parent, wxString title, wxSize size);
242 wxDialog* bbGetDialog() { return this; }
244 //==================================================================
246 //==================================================================
247 // Frame window which is not modal
248 class BBTK_EXPORT WxBlackBoxFrame : public wxFrame, public WxBlackBoxWindow
251 WxBlackBoxFrame(WxBlackBox* box,
252 wxWindow *parent, wxString title, wxSize size);
256 wxFrame* bbGetFrame() { return this; }
258 //==================================================================
262 //=================================================================
263 /// Class from which a user defined widget associated to a WxBlackBox
265 class BBTK_EXPORT WxBlackBoxWidget
268 /// Ctor with the WxBlackBox which created it
269 WxBlackBoxWidget( WxBlackBox* box);
271 virtual ~WxBlackBoxWidget();
273 /// Returns the WxBlackBox which created it
274 WxBlackBox* GetBlackBox() { return mBox; }
275 /// Returns the WxBlackBox which created it (const)
276 const WxBlackBox* GetBlackBox() const { return mBox; }
278 /// Returns the wxWindow associated to the widget
279 virtual wxWindow* GetWxWindow() { return 0; }
281 virtual bool IsDead() { return false; }
286 //=================================================================
289 //=================================================================
290 // Handles the destroy events of a widget associated to a WxBlackBox
291 // in order to signal the widget death to its associated box
292 class BBTK_EXPORT WxBlackBoxWidgetEventHandler : public wxEvtHandler
295 /// Ctor with the box and widget
296 WxBlackBoxWidgetEventHandler( WxBlackBox* box, wxWindow *widget );
298 ~WxBlackBoxWidgetEventHandler();
299 /// Returns true iff is the handler for that window
300 bool IsHandlerOf( wxWindow* w ) { return mWindow == w; }
301 // wxWindow* GetWxWindow() { return mWindow; }
302 /// Method processing the destroy event of the widget
303 void OnWindowDestroy(wxWindowDestroyEvent&);
305 //bool IsDead() { return mDead; }
312 //=================================================================
315 //=================================================================
316 /// A WxBlackBoxWidget which is a wxPanel also
317 class BBTK_EXPORT WxBlackBoxWidgetPanel :
319 public WxBlackBoxWidget
320 // public WxBlackBoxWidget,
324 /// Ctor with the parent and the WxBlackBox which created it
325 WxBlackBoxWidgetPanel(WxBlackBox* box, wxWindow *parent)
327 wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
328 WxBlackBoxWidget(box)
331 /// Returns the top panel of the widget
332 wxWindow* GetWxWindow() { return (wxWindow*)(wxPanel*)(this); }
333 /// Returns the top panel of the widget
334 wxPanel* GetPanel() { return (wxPanel*)(this); }
337 //=================================================================
343 #endif //__bbtkWxBlackBox_h__
345 #endif //_USE_WXWIDGETS_