]> Creatis software - bbtk.git/blob - kernel/src/bbtkWidgetBlackBox.h
#3073 BBTK Bug New Normal - message documentation in boxes
[bbtk.git] / kernel / src / bbtkWidgetBlackBox.h
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbtkWidgetBlackBox.h,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:49:01 $
33   Version:   $Revision: 1.8 $
34 ========================================================================*/
35
36
37
38 /**
39  * \brief Short description in one line
40  * 
41  * Long description which 
42  * can span multiple lines
43  */
44 /**
45  * \file 
46  * \brief 
47  */
48 /**
49  * \class bbtk::
50  * \brief 
51  */
52 #ifndef __bbtkWidgetBlackBox_h_INCLUDED__
53 #define __bbtkWidgetBlackBox_h_INCLUDED__
54
55 #include "bbtkAtomicBlackBox.h"
56
57 namespace bbtk
58 {
59
60
61
62
63   //==================================================================
64   /// Generic (template) Widget black box from which all 
65   /// widget black boxes for a specific GUI toolkit inherit with 
66   /// apropriate traits.
67   /// Declares the common inputs / outputs and interface to all widget boxes
68
69 //JCP 09JUIN2009 BBTK_EXPORT
70   template <class W>
71           
72   class /*BBTK_EXPORT*/ WidgetBlackBox : public bbtk::AtomicBlackBox  
73   { 
74   public:
75     //    typedef WidgetTraits Traits;
76     typedef W Widget;
77     typedef Widget* WidgetPointer;
78     
79     
80     BBTK_BLACK_BOX_INTERFACE(WidgetBlackBox,bbtk::AtomicBlackBox);
81     BBTK_DECLARE_INPUT(WinTitle,std::string);
82     BBTK_DECLARE_INPUT(WinWidth,int);
83     BBTK_DECLARE_INPUT(WinHeight,int);
84     BBTK_DECLARE_INPUT(WinDialog,bool);
85     BBTK_DECLARE_INPUT(WinHide,Void);
86     BBTK_DECLARE_INPUT(WinClose,Void);
87     BBTK_DECLARE_OUTPUT(Widget,Widget*);
88
89     //==================================================================
90     /// Overloaded bbCreateWindow method for WidgetBlackBoxes which handles 
91     /// the window creation if needed
92     virtual void bbCreateWindow();
93     virtual bool bbWindowIsCreated() { return false; }
94     //==================================================================
95     
96     //==================================================================
97     /// Overloaded bbShowWindow method for WidgetBlackBoxes which handles 
98     /// the window creation if needed
99     virtual void bbShowWindow() {}
100     //==================================================================    
101
102  
103     /// Convenient method which returns true iff the output Widget is connected
104     bool bbIsOutputWidgetConnected();
105
106     //==================================================================    
107     bool bbIsShown();
108     //==================================================================    
109  
110    
111     //==================================================================    
112     /// User callback for creating the widget associated to the box
113     /// ** Must be defined ** in user classes
114     virtual void bbUserCreateWidget(Widget* parent) 
115     {
116       bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbUserCreateWidget methods is not overloaded : is it a feature or a bug ?!?");
117     }
118     //==================================================================    
119
120           
121   protected:
122     
123     void bbSetShown(bool);
124
125     //==================================================================
126     /// Convenient method for layout widgets which creates and returns
127     /// (calls bbUserCreateWidget) 
128     /// the widget of the box connected to the input in.
129     /// Returns NULL if the input is not connected
130     Widget* bbCreateWidgetOfInput(const std::string& in, 
131                                   Widget* parent);
132     //==================================================================
133
134    //==================================================================    
135     /// Callback for creating a Dialog window (modal)
136     /// ** Must be defined ** in toolkit specific descendants 
137     virtual void bbCreateDialogWindow()
138     {
139       bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbCreateDialogWindow method is not overloaded ?!?");
140     }
141     //==================================================================    
142
143  //==================================================================    
144     /// Callback for creating a Frame window 
145     /// ** Must be defined ** in toolkit specific descendants 
146     virtual void bbCreateFrameWindow()
147     {
148       bbtkError(bbGetTypeName()<<" is a WidgetBlackBox whose bbCreateFrameWindow method is not overloaded ?!?");
149     }
150     //==================================================================    
151     //==================================================================
152     /// Overloaded processing method for WidgetBlackBoxes
153     virtual void bbProcess();
154     //==================================================================
155
156     //==================================================================
157     /// Destroys the WidgetBlackBoxWindow associated to the box (if exists)
158     virtual void bbDestroyWindow() {}
159     //==================================================================
160
161     //==================================================================
162         // method to be added in the proces of a window
163         virtual void PutWinTitle() {}
164     //==================================================================
165    
166
167   private:
168    
169     /// Set to true when the 
170     /// window containing the widget is shown
171     bool bbmShown;
172     /// Contains the "nested" WidgetBlackBoxes, 
173     /// i.e. if this WidgetBox is a Layout the ones
174     /// which are inserted into the layout 
175     /// The list is updated by the method bbCreateWidgetOfInput
176     /// It is emptied when ?
177     std::vector<BlackBox::WeakPointer> bbmNestedWidgetBoxes;
178   };
179   //=================================================================
180  
181
182   //======================================================================
183   /// Defines the bbUserCreateWidget method
184 #define BBTK_CREATE_WIDGET(CALLBACK)                                    \
185   public:                                                               \
186   inline void bbUserCreateWidget(Widget* parent)                        \
187   {                                                                     \
188     bbtkBlackBoxDebugMessage("widget",1,"**> Creating widget"           \
189                              <<std::endl);                              \
190     CALLBACK(parent);                                                   \
191   }
192   
193   //======================================================================
194
195   //======================================================================
196   /// Defines the bbUserOnShow method
197 #define BBTK_ON_SHOW_WIDGET(CALLBACK)                                   \
198   public:                                                               \
199   inline void bbUserOnShow()                                            \
200   {                                                                     \
201     bbtkBlackBoxDebugMessage("widget",1,"**> Showing"                   \
202                              <<std::endl);                              \
203     CALLBACK();                                                         \
204   }
205   
206   //======================================================================
207
208   //=================================================================
209   // WidgetBlackBoxDescriptor declaration
210   BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(WidgetBlackBox,bbtk::AtomicBlackBox);
211   BBTK_NAME("WidgetBlackBox_"+HumanTypeName<T>());
212   // BBTK_DESCRIPTION("Widget box. The inputs marked with (*) are only used if the widget is not inserted in another widget.\n");
213   BBTK_CATEGORY("widget");
214   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinTitle,
215              "Title of the window (*)",
216              std::string);
217   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinWidth,
218              "Width of the window (* : only used if the widget is not connected to a Layout box)",int);
219   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinHeight,
220              "Height of the window (*)",int);
221   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinDialog,
222              "Set to 'true' to create a dialog window, i.e. which blocks the pipeline until it is closed (modal) (*)",bool);
223   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinHide,
224              "Any signal received hides the window (*)",Void);
225   BBTK_TEMPLATE_INPUT(WidgetBlackBox,WinClose,
226              "Any signal received closes the window (*)",Void);
227   typedef typename WidgetBlackBox<T>::WidgetPointer WidgetPointer;
228   BBTK_TEMPLATE_OUTPUT(WidgetBlackBox,Widget,"Output widget",WidgetPointer);
229   BBTK_END_DESCRIBE_BLACK_BOX(WidgetBlackBox);
230   //=================================================================
231
232
233
234
235
236
237
238
239
240 } //namespace bbtk
241
242 // template code inclusion
243 #include "bbtkWidgetBlackBox.txx"
244
245 // WidgetBlackBoxWindow interface + code inclusion
246 #include "bbtkWidgetBlackBoxWindow.h"
247
248 #endif  //__bbtkWidgetBlackBox_h__