1 /*=========================================================================
3 Module: $RCSfile: bbtkWidgetBlackBox.h,v $
5 Date: $Date: 2009/05/14 14:43:34 $
6 Version: $Revision: 1.3 $
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
45 #ifndef __bbtkWidgetBlackBox_h_INCLUDED__
46 #define __bbtkWidgetBlackBox_h_INCLUDED__
48 #include "bbtkAtomicBlackBox.h"
54 template <class T> class WidgetBlackBoxWindow;
57 //==================================================================
58 /// Generic (template) Widget black box from which all
59 /// widget black boxes for a specific GUI toolkit inherit with
60 /// apropriate traits.
61 /// Declares the common inputs / outputs and interface to all widget boxes
63 class /*BBTK_EXPORT*/ WidgetBlackBox : public bbtk::AtomicBlackBox
66 // typedef WidgetTraits Traits;
68 typedef Widget* WidgetPointer;
69 typedef WidgetBlackBoxWindow<W> Window;
72 BBTK_BLACK_BOX_INTERFACE(WidgetBlackBox,bbtk::AtomicBlackBox);
73 BBTK_DECLARE_INPUT(WinTitle,std::string);
74 BBTK_DECLARE_INPUT(WinWidth,int);
75 BBTK_DECLARE_INPUT(WinHeight,int);
76 BBTK_DECLARE_INPUT(WinDialog,bool);
77 BBTK_DECLARE_INPUT(WinHide,Void);
78 BBTK_DECLARE_INPUT(WinClose,Void);
79 BBTK_DECLARE_OUTPUT(Widget,Widget*);
81 //==================================================================
82 /// Overloaded bbCreateWindow method for WidgetBlackBoxes which handles
83 /// the window creation if needed
84 virtual void bbCreateWindow();
85 //==================================================================
87 //==================================================================
88 /// Overloaded bbShowWindow method for WidgetBlackBoxes which handles
89 /// the window creation if needed
90 virtual void bbShowWindow();
91 //==================================================================
93 //==================================================================
94 /// Returns the **OWN** window associated to the box
95 /// If 0 returned = no window
96 Window* bbGetWindow() { return bbmWindow; }
97 /// Returns the window containing the widget associated to the box
98 /// Which can be the own window of **ANOTHER** box in case of
99 /// a hierarchy of widgets (layouts)
101 /// If bbGetWindow() != 0 then returns bbGetWindow()
102 /// Else if the output 'Widget' is connected
103 /// then returns bbGetContainingWindow() of the box connected to 'Widget'
105 Window* bbGetContainingWindow();
108 /// Returns true iff the 'containing window' exists and is shown
109 /// (see bbGetContainingWindow).
112 /// Convenient method which returns true iff the output Widget is connected
113 bool bbIsOutputWidgetConnected();
115 //==================================================================
116 /// User callback invoked when the containing window is shown
117 virtual void bbUserOnShow() {}
118 //==================================================================
120 //==================================================================
121 /// User callback invoked when the containing window is hidden
122 virtual void bbUserOnHide() {}
123 //==================================================================
126 inline void bbSetWindow(Window* w) { bbmWindow=w; }
128 //==================================================================
129 /// User callback for creating the widget associated to the box
130 /// ** Must be defined ** in user classes
131 virtual void bbUserCreateWidget(Widget* parent)
133 bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbUserCreateWidget methods is not overloaded : is it a feature or a bug ?!?");
135 //==================================================================
142 //==================================================================
143 /// Convenient method for layout widgets which creates and returns
144 /// (calls bbUserCreateWidget)
145 /// the widget of the box connected to the input in.
146 /// Returns NULL if the input is not connected
147 Widget* bbCreateWidgetOfInput(const std::string& in,
149 //==================================================================
151 //==================================================================
152 /// Callback for creating a Dialog window (modal)
153 /// ** Must be defined ** in toolkit specific descendants
154 virtual void bbCreateDialogWindow()
156 bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbCreateDialogWindow method is not overloaded ?!?");
158 //==================================================================
160 //==================================================================
161 /// Callback for creating a Frame window
162 /// ** Must be defined ** in toolkit specific descendants
163 virtual void bbCreateFrameWindow()
165 bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbCreateFrameWindow method is not overloaded ?!?");
167 //==================================================================
168 //==================================================================
169 /// Overloaded processing method for WidgetBlackBoxes
170 virtual void bbProcess();
171 //==================================================================
173 //==================================================================
174 /// Hides the WidgetBlackBoxWindow associated to the box (if exists)
176 /// Closes (destroys) the WidgetBlackBoxWindow associated to the box
178 void bbCloseWindow();
179 //==================================================================
182 //==================================================================
183 // virtual void InitWindowManagerIfNeeded();
184 virtual void IncNbWindowsAlive() {}
185 virtual void DecNbWindowsAlive() {}
186 virtual int GetNbWindowsAlive() { return 0; }
187 virtual bool IsSomeWindowAlive() { return false; }
189 virtual void IncNbWindowsShown() {}
190 virtual void DecNbWindowsShown() {}
191 virtual int GetNbWindowsShown() { return 0; }
192 virtual bool IsSomeWindowShown() { return false; }
193 //==================================================================
198 friend class WidgetBlackBoxWindow<W>;
199 // friend class WidgetBlackBoxWidgetEventHandler;
201 /// The WidgetBlackBoxWindow associated to the box
207 //=================================================================
210 //======================================================================
211 /// Defines the bbUserCreateWidget method
212 #define BBTK_CREATE_WIDGET(CALLBACK) \
214 inline void bbUserCreateWidget(Widget* parent) \
216 bbtkDebugMessageInc("kw",1,"**> Creating widget for [" \
217 <<bbGetFullName()<<"]"<<std::endl); \
219 bbtkDebugMessageInc("kw",1,"<** Creating widget for [" \
220 <<bbGetFullName()<<"]"<<std::endl); \
223 //======================================================================
225 //======================================================================
226 /// Defines the bbUserOnShow method
227 #define BBTK_ON_SHOW_WIDGET(CALLBACK) \
229 inline void bbUserOnShow() \
231 bbtkDebugMessageInc("wx",1,"**> Showing [" \
232 <<bbGetFullName()<<"]"<<std::endl); \
234 bbtkDebugMessageInc("wx",1,"<** Showing [" \
235 <<bbGetFullName()<<"]"<<std::endl); \
238 //======================================================================
240 //=================================================================
241 // WidgetBlackBoxDescriptor declaration
242 BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(WidgetBlackBox,bbtk::AtomicBlackBox);
243 BBTK_NAME("WidgetBlackBox_"+HumanTypeName<T>());
244 // BBTK_DESCRIPTION("Widget box. The inputs marked with (*) are only used if the widget is not inserted in another widget.\n");
245 BBTK_CATEGORY("widget");
246 BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinTitle,
247 "Title of the window (*)",
249 BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinWidth,
250 "Width of the window (* : only used if the widget is not connected to a Layout box)",int);
251 BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinHeight,
252 "Height of the window (*)",int);
253 BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinDialog,
254 "Set to 'true' to create a dialog window, i.e. which blocks the pipeline until it is closed (modal) (*)",bool);
255 BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinHide,
256 "Any signal received hides the window (*)",Void);
257 BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinClose,
258 "Any signal received closes the window (*)",Void);
259 typedef typename WidgetBlackBox<T>::WidgetPointer WidgetPointer;
260 BBTK_TEMPLATE_OUTPUT(WidgetBlackBox,Widget,"Output widget",WidgetPointer);
261 BBTK_END_DESCRIBE_BLACK_BOX(WidgetBlackBox);
262 //=================================================================
274 // template code inclusion
275 #include "bbtkWidgetBlackBox.txx"
277 // WidgetBlackBoxWindow interface + code inclusion
278 #include "bbtkWidgetBlackBoxWindow.h"
280 #endif //__bbtkWidgetBlackBox_h__