]> Creatis software - bbtk.git/blob - kernel/src/bbtkWidgetBlackBox.h
Disclaimers
[bbtk.git] / kernel / src / bbtkWidgetBlackBox.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWidgetBlackBox.h,v $
4   Language:  C++
5   Date:      $Date: 2010/01/14 13:17:27 $
6   Version:   $Revision: 1.7 $
7 ========================================================================*/
8
9
10 /* ---------------------------------------------------------------------
11
12 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
13 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 *
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.
21 *
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
26 *  liability. 
27 *
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 * ------------------------------------------------------------------------ */                                                                         
31
32 /**
33  * \brief Short description in one line
34  * 
35  * Long description which 
36  * can span multiple lines
37  */
38 /**
39  * \file 
40  * \brief 
41  */
42 /**
43  * \class bbtk::
44  * \brief 
45  */
46 #ifndef __bbtkWidgetBlackBox_h_INCLUDED__
47 #define __bbtkWidgetBlackBox_h_INCLUDED__
48
49 #include "bbtkAtomicBlackBox.h"
50
51 namespace bbtk
52 {
53
54
55
56
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
62
63 //JCP 09JUIN2009 BBTK_EXPORT
64   template <class W>
65           
66   class /*BBTK_EXPORT*/ WidgetBlackBox : public bbtk::AtomicBlackBox  
67   { 
68   public:
69     //    typedef WidgetTraits Traits;
70     typedef W Widget;
71     typedef Widget* WidgetPointer;
72     
73     
74     BBTK_BLACK_BOX_INTERFACE(WidgetBlackBox,bbtk::AtomicBlackBox);
75     BBTK_DECLARE_INPUT(WinTitle,std::string);
76     BBTK_DECLARE_INPUT(WinWidth,int);
77     BBTK_DECLARE_INPUT(WinHeight,int);
78     BBTK_DECLARE_INPUT(WinDialog,bool);
79     BBTK_DECLARE_INPUT(WinHide,Void);
80     BBTK_DECLARE_INPUT(WinClose,Void);
81     BBTK_DECLARE_OUTPUT(Widget,Widget*);
82
83     //==================================================================
84     /// Overloaded bbCreateWindow method for WidgetBlackBoxes which handles 
85     /// the window creation if needed
86     virtual void bbCreateWindow();
87     virtual bool bbWindowIsCreated() { return false; }
88     //==================================================================
89     
90     //==================================================================
91     /// Overloaded bbShowWindow method for WidgetBlackBoxes which handles 
92     /// the window creation if needed
93     virtual void bbShowWindow() {}
94     //==================================================================    
95
96  
97     /// Convenient method which returns true iff the output Widget is connected
98     bool bbIsOutputWidgetConnected();
99
100     //==================================================================    
101     bool bbIsShown();
102     //==================================================================    
103  
104    
105     //==================================================================    
106     /// User callback for creating the widget associated to the box
107     /// ** Must be defined ** in user classes
108     virtual void bbUserCreateWidget(Widget* parent) 
109     {
110       bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbUserCreateWidget methods is not overloaded : is it a feature or a bug ?!?");
111     }
112     //==================================================================    
113
114           
115   protected:
116     
117     void bbSetShown(bool);
118
119     //==================================================================
120     /// Convenient method for layout widgets which creates and returns
121     /// (calls bbUserCreateWidget) 
122     /// the widget of the box connected to the input in.
123     /// Returns NULL if the input is not connected
124     Widget* bbCreateWidgetOfInput(const std::string& in, 
125                                   Widget* parent);
126     //==================================================================
127
128    //==================================================================    
129     /// Callback for creating a Dialog window (modal)
130     /// ** Must be defined ** in toolkit specific descendants 
131     virtual void bbCreateDialogWindow()
132     {
133       bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbCreateDialogWindow method is not overloaded ?!?");
134     }
135     //==================================================================    
136
137  //==================================================================    
138     /// Callback for creating a Frame window 
139     /// ** Must be defined ** in toolkit specific descendants 
140     virtual void bbCreateFrameWindow()
141     {
142       bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbCreateFrameWindow method is not overloaded ?!?");
143     }
144     //==================================================================    
145     //==================================================================
146     /// Overloaded processing method for WidgetBlackBoxes
147     virtual void bbProcess();
148     //==================================================================
149
150     //==================================================================
151     /// Destroys the WidgetBlackBoxWindow associated to the box (if exists)
152     virtual void bbDestroyWindow() {}
153     //==================================================================
154
155    
156
157   private:
158    
159     /// Set to true when the 
160     /// window containing the widget is shown
161     bool bbmShown;
162     /// Contains the "nested" WidgetBlackBoxes, 
163     /// i.e. if this WidgetBox is a Layout the ones
164     /// which are inserted into the layout 
165     /// The list is updated by the method bbCreateWidgetOfInput
166     /// It is emptied when ?
167     std::vector<BlackBox::WeakPointer> bbmNestedWidgetBoxes;
168   };
169   //=================================================================
170  
171
172   //======================================================================
173   /// Defines the bbUserCreateWidget method
174 #define BBTK_CREATE_WIDGET(CALLBACK)                                    \
175   public:                                                               \
176   inline void bbUserCreateWidget(Widget* parent)                        \
177   {                                                                     \
178     bbtkBlackBoxDebugMessage("widget",1,"**> Creating widget"           \
179                              <<std::endl);                              \
180     CALLBACK(parent);                                                   \
181   }
182   
183   //======================================================================
184
185   //======================================================================
186   /// Defines the bbUserOnShow method
187 #define BBTK_ON_SHOW_WIDGET(CALLBACK)                                   \
188   public:                                                               \
189   inline void bbUserOnShow()                                            \
190   {                                                                     \
191     bbtkBlackBoxDebugMessage("widget",1,"**> Showing"                   \
192                              <<std::endl);                              \
193     CALLBACK();                                                         \
194   }
195   
196   //======================================================================
197
198   //=================================================================
199   // WidgetBlackBoxDescriptor declaration
200   BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(WidgetBlackBox,bbtk::AtomicBlackBox);
201   BBTK_NAME("WidgetBlackBox_"+HumanTypeName<T>());
202   // BBTK_DESCRIPTION("Widget box. The inputs marked with (*) are only used if the widget is not inserted in another widget.\n");
203   BBTK_CATEGORY("widget");
204   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinTitle,
205              "Title of the window (*)",
206              std::string);
207   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinWidth,
208              "Width of the window (* : only used if the widget is not connected to a Layout box)",int);
209   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinHeight,
210              "Height of the window (*)",int);
211   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinDialog,
212              "Set to 'true' to create a dialog window, i.e. which blocks the pipeline until it is closed (modal) (*)",bool);
213   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinHide,
214              "Any signal received hides the window (*)",Void);
215   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinClose,
216              "Any signal received closes the window (*)",Void);
217   typedef typename WidgetBlackBox<T>::WidgetPointer WidgetPointer;
218   BBTK_TEMPLATE_OUTPUT(WidgetBlackBox,Widget,"Output widget",WidgetPointer);
219   BBTK_END_DESCRIBE_BLACK_BOX(WidgetBlackBox);
220   //=================================================================
221
222
223
224
225
226
227
228
229
230 } //namespace bbtk
231
232 // template code inclusion
233 #include "bbtkWidgetBlackBox.txx"
234
235 // WidgetBlackBoxWindow interface + code inclusion
236 #include "bbtkWidgetBlackBoxWindow.h"
237
238 #endif  //__bbtkWidgetBlackBox_h__