1 /*=========================================================================
3 Module: $RCSfile: bbtkWidgetBlackBox.h,v $
5 Date: $Date: 2009/06/08 14:50:04 $
6 Version: $Revision: 1.5 $
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"
56 //==================================================================
57 /// Generic (template) Widget black box from which all
58 /// widget black boxes for a specific GUI toolkit inherit with
59 /// apropriate traits.
60 /// Declares the common inputs / outputs and interface to all widget boxes
62 class /*BBTK_EXPORT*/ WidgetBlackBox : public bbtk::AtomicBlackBox
65 // typedef WidgetTraits Traits;
67 typedef Widget* WidgetPointer;
70 BBTK_BLACK_BOX_INTERFACE(WidgetBlackBox,bbtk::AtomicBlackBox);
71 BBTK_DECLARE_INPUT(WinTitle,std::string);
72 BBTK_DECLARE_INPUT(WinWidth,int);
73 BBTK_DECLARE_INPUT(WinHeight,int);
74 BBTK_DECLARE_INPUT(WinDialog,bool);
75 BBTK_DECLARE_INPUT(WinHide,Void);
76 BBTK_DECLARE_INPUT(WinClose,Void);
77 BBTK_DECLARE_OUTPUT(Widget,Widget*);
79 //==================================================================
80 /// Overloaded bbCreateWindow method for WidgetBlackBoxes which handles
81 /// the window creation if needed
82 virtual void bbCreateWindow();
83 virtual bool bbWindowIsCreated() { return false; }
84 //==================================================================
86 //==================================================================
87 /// Overloaded bbShowWindow method for WidgetBlackBoxes which handles
88 /// the window creation if needed
89 virtual void bbShowWindow() {}
90 //==================================================================
93 /// Convenient method which returns true iff the output Widget is connected
94 bool bbIsOutputWidgetConnected();
96 //==================================================================
98 //==================================================================
101 //==================================================================
102 /// User callback for creating the widget associated to the box
103 /// ** Must be defined ** in user classes
104 virtual void bbUserCreateWidget(Widget* parent)
106 bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbUserCreateWidget methods is not overloaded : is it a feature or a bug ?!?");
108 //==================================================================
113 void bbSetShown(bool);
115 //==================================================================
116 /// Convenient method for layout widgets which creates and returns
117 /// (calls bbUserCreateWidget)
118 /// the widget of the box connected to the input in.
119 /// Returns NULL if the input is not connected
120 Widget* bbCreateWidgetOfInput(const std::string& in,
122 //==================================================================
124 //==================================================================
125 /// Callback for creating a Dialog window (modal)
126 /// ** Must be defined ** in toolkit specific descendants
127 virtual void bbCreateDialogWindow()
129 bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbCreateDialogWindow method is not overloaded ?!?");
131 //==================================================================
133 //==================================================================
134 /// Callback for creating a Frame window
135 /// ** Must be defined ** in toolkit specific descendants
136 virtual void bbCreateFrameWindow()
138 bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbCreateFrameWindow method is not overloaded ?!?");
140 //==================================================================
141 //==================================================================
142 /// Overloaded processing method for WidgetBlackBoxes
143 virtual void bbProcess();
144 //==================================================================
146 //==================================================================
147 /// Destroys the WidgetBlackBoxWindow associated to the box (if exists)
148 virtual void bbDestroyWindow() {}
149 //==================================================================
155 /// Set to true when the
156 /// window containing the widget is shown
158 /// Contains the "nested" WidgetBlackBoxes,
159 /// i.e. if this WidgetBox is a Layout the ones
160 /// which are inserted into the layout
161 /// The list is updated by the method bbCreateWidgetOfInput
162 /// It is emptied when ?
163 std::vector<BlackBox::WeakPointer> bbmNestedWidgetBoxes;
165 //=================================================================
168 //======================================================================
169 /// Defines the bbUserCreateWidget method
170 #define BBTK_CREATE_WIDGET(CALLBACK) \
172 inline void bbUserCreateWidget(Widget* parent) \
174 bbtkBlackBoxDebugMessage("widget",1,"**> Creating widget" \
179 //======================================================================
181 //======================================================================
182 /// Defines the bbUserOnShow method
183 #define BBTK_ON_SHOW_WIDGET(CALLBACK) \
185 inline void bbUserOnShow() \
187 bbtkBlackBoxDebugMessage("widget",1,"**> Showing" \
192 //======================================================================
194 //=================================================================
195 // WidgetBlackBoxDescriptor declaration
196 BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(WidgetBlackBox,bbtk::AtomicBlackBox);
197 BBTK_NAME("WidgetBlackBox_"+HumanTypeName<T>());
198 // BBTK_DESCRIPTION("Widget box. The inputs marked with (*) are only used if the widget is not inserted in another widget.\n");
199 BBTK_CATEGORY("widget");
200 BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinTitle,
201 "Title of the window (*)",
203 BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinWidth,
204 "Width of the window (* : only used if the widget is not connected to a Layout box)",int);
205 BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinHeight,
206 "Height of the window (*)",int);
207 BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinDialog,
208 "Set to 'true' to create a dialog window, i.e. which blocks the pipeline until it is closed (modal) (*)",bool);
209 BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinHide,
210 "Any signal received hides the window (*)",Void);
211 BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinClose,
212 "Any signal received closes the window (*)",Void);
213 typedef typename WidgetBlackBox<T>::WidgetPointer WidgetPointer;
214 BBTK_TEMPLATE_OUTPUT(WidgetBlackBox,Widget,"Output widget",WidgetPointer);
215 BBTK_END_DESCRIBE_BLACK_BOX(WidgetBlackBox);
216 //=================================================================
228 // template code inclusion
229 #include "bbtkWidgetBlackBox.txx"
231 // WidgetBlackBoxWindow interface + code inclusion
232 #include "bbtkWidgetBlackBoxWindow.h"
234 #endif //__bbtkWidgetBlackBox_h__