1 /*=========================================================================
3 Module: $RCSfile: bbtkKWBlackBox.h,v $
5 Date: $Date: 2008/12/11 09:50:35 $
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 __bbtkKWBlackBox_h_INCLUDED__
46 #define __bbtkKWBlackBox_h_INCLUDED__
51 #include "bbtkAtomicBlackBox.h"
57 //==================================================================
58 // Forward declaration of the class of window associated to a KWBlackBox
59 class vtkKWBlackBoxWindow;
60 class vtkKWBlackBoxDialog;
62 //==================================================================
72 //==================================================================
73 /// Widget black boxes
74 class BBTK_EXPORT KWBlackBox : public bbtk::AtomicBlackBox
76 BBTK_BLACK_BOX_INTERFACE(KWBlackBox,bbtk::AtomicBlackBox);
77 BBTK_DECLARE_INPUT(WinTitle,std::string);
78 BBTK_DECLARE_INPUT(WinWidth,int);
79 BBTK_DECLARE_INPUT(WinHeight,int);
80 BBTK_DECLARE_INPUT(WinDialog,bool);
81 BBTK_DECLARE_INPUT(WinHide,Void);
82 BBTK_DECLARE_INPUT(WinClose,Void);
83 BBTK_DECLARE_OUTPUT(Widget, vtkKWWidget*);
87 typedef vtkKWBlackBoxDialog Window;
89 /// Returns the **OWN** window associated to the box
90 /// If 0 returned = no window
91 Window* bbGetWindow() { return bbmWindow; }
93 /// Returns the window containing the widget associated to the box
94 /// Which can be the own window of **ANOTHER** box in case of
95 /// a hierarchy of widgets.
97 /// If bbGetWindow() != 0 then returns bbGetWindow()
98 /// Else if the output 'Widget' is connected
99 /// then returns bbGetContainingWindow() of the box connected to 'Widget'
101 Window* bbGetContainingWindow();
104 /// Returns true iff the 'containing window' exists and is shown
105 /// (see bbGetContainingWindow).
108 //==================================================================
109 /// User callback invoked when the containing window is shown
110 virtual void bbUserOnShow() {}
111 //==================================================================
113 //==================================================================
114 /// User callback invoked when the containing window is hidden
115 virtual void bbUserOnHide() {}
116 //==================================================================
119 inline void bbSetWindow(Window* w) { bbmWindow=w; }
125 //==================================================================
126 /// User callback called in the box contructor
127 virtual void bbUserConstructor();
128 /// User callback called in the box copy constructor
129 virtual void bbUserCopyConstructor(bbtk::BlackBox::Pointer);
130 /// User callback called in the box destructor
131 virtual void bbUserDestructor();
132 //==================================================================
134 //==================================================================
135 /// User callback for creating the widget associated to the box
136 /// ** Must be defined **
137 // LG 24/11/08 : New widget pipeline
138 virtual void bbUserCreateWidget(vtkKWFrame* parent)
140 bbtkError(bbGetTypeName()<<" is a KWBlackBox whose bbUserCreateWidget methods is not overloaded : is it a feature or a bug ?!?");
142 //==================================================================
145 //==================================================================
146 vtkKWWidget* bbCreateWidgetOfInput(const std::string& in,
148 //==================================================================
151 //==================================================================
152 /// Overloaded processing method for KWBlackBoxes
153 virtual void bbProcess();
154 //==================================================================
156 //==================================================================
157 /// If necessary creates the KWBlackBoxWindow associated to the box
159 /// (does nothing if the box output 'Widget' is connected which
160 /// means that the box does not have its own window but is contained
161 /// into another window)
163 /// Hides the KWBlackBoxWindow associated to the box (if exists)
165 /// Closes (destroys) the KWBlackBoxWindow associated to the box (if exists)
166 void bbCloseWindow();
167 //==================================================================
171 friend class vtkKWBlackBoxWindow;
172 // friend class KWBlackBoxWidgetEventHandler;
174 /// The KWBlackBoxWindow associated to the box
178 void bbInitAttributes();
181 //=================================================================
184 //======================================================================
185 /// Defines the bbUserCreateWidget method
186 #define BBTK_CREATE_KWWIDGET(CALLBACK) \
188 inline void bbUserCreateWidget(vtkKWFrame* parent) \
190 bbtkDebugMessageInc("kw",1,"**> Creating widget for [" \
191 <<bbGetFullName()<<"]"<<std::endl); \
193 bbtkDebugMessageInc("kw",1,"<** Creating widget for [" \
194 <<bbGetFullName()<<"]"<<std::endl); \
197 //======================================================================
199 //======================================================================
200 /// Defines the bbUserOnShow method
201 #define BBTK_ON_SHOW_WIDGET(CALLBACK) \
203 inline void bbUserOnShow() \
205 bbtkDebugMessageInc("wx",1,"**> Showing [" \
206 <<bbGetFullName()<<"]"<<std::endl); \
208 bbtkDebugMessageInc("wx",1,"<** Showing [" \
209 <<bbGetFullName()<<"]"<<std::endl); \
212 //======================================================================
214 //=================================================================
215 // KWBlackBoxDescriptor declaration
216 BBTK_BEGIN_DESCRIBE_BLACK_BOX(KWBlackBox,bbtk::AtomicBlackBox);
217 BBTK_NAME("KWBlackBox");
218 // BBTK_DESCRIPTION("Widget box. The inputs marked with (*) are only used if the widget is not inserted in another widget.\n");
219 BBTK_CATEGORY("widget");
220 BBTK_INPUT(KWBlackBox,WinTitle,
221 "Title of the window (*)",
223 BBTK_INPUT(KWBlackBox,WinWidth,
224 "Width of the window (* : only used if the widget is not connected to a Layout box)",int,"");
225 BBTK_INPUT(KWBlackBox,WinHeight,
226 "Height of the window (*)",int,"");
227 BBTK_INPUT(KWBlackBox,WinDialog,
228 "Set to 'true' to create a dialog window, i.e. which blocks the pipeline until it is closed (modal) (*)",bool,"");
229 BBTK_INPUT(KWBlackBox,WinHide,
230 "Any signal received hides the window (*)",Void,"signal");
231 BBTK_INPUT(KWBlackBox,WinClose,
232 "Any signal received closes the window (*)",Void,"signal");
233 BBTK_OUTPUT(KWBlackBox,Widget,"Output widget",vtkKWWidget*,"");
234 BBTK_END_DESCRIBE_BLACK_BOX(KWBlackBox);
235 //=================================================================
245 //=================================================================
246 // Handles the destroy events of a widget associated to a KWBlackBox
247 // in order to signal the widget death to its associated box
248 class BBTK_EXPORT KWBlackBoxWidgetEventHandler : public wxEvtHandler
251 /// Ctor with the box and widget
252 KWBlackBoxWidgetEventHandler( KWBlackBox::Pointer box, wxWindow *widget );
254 ~KWBlackBoxWidgetEventHandler();
255 /// Returns true iff is the handler for that window
256 bool IsHandlerOf( wxWindow* w ) { return mWindow == w; }
257 // wxWindow* GetKWWindow() { return mWindow; }
258 /// Method processing the destroy event of the widget
259 void OnWindowDestroy(wxWindowDestroyEvent&);
261 //bool IsDead() { return mDead; }
264 KWBlackBox::WeakPointer mBox;
268 //=================================================================
276 #endif // USE_KWWIDGETS
277 #endif //__bbtkKWBlackBox_h__