]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxBlackBox.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkWxBlackBox.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWxBlackBox.h,v $
4   Language:  C++
5   Date:      $Date: 2009/04/08 07:56:11 $
6   Version:   $Revision: 1.26 $
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  * \brief Short description in one line
33  * 
34  * Long description which 
35  * can span multiple lines
36  */
37 /**
38  * \file 
39  * \brief 
40  */
41 /**
42  * \class bbtk::
43  * \brief 
44  */
45
46
47 #ifdef USE_WXWIDGETS
48
49
50 #ifndef __bbtkWxBlackBox_h__
51 #define __bbtkWxBlackBox_h__
52
53
54 #include "bbtkWx.h"
55 #include "bbtkWidgetBlackBox.h"
56
57
58 namespace bbtk
59 {
60
61
62
63
64
65   //==================================================================
66   // Forward declaration of the widget event handler class
67   class WxBlackBoxWidgetEventHandler;
68   //==================================================================
69
70
71   //==================================================================
72   /// Widget black boxes
73   class BBTK_EXPORT WxBlackBox : public bbtk::WidgetBlackBox<wxWindow>
74   { 
75   public:
76     BBTK_BLACK_BOX_INTERFACE(WxBlackBox,bbtk::WidgetBlackBox<wxWindow>);
77
78           
79     //  protected:
80     
81   public:
82   
83    //==================================================================    
84     /// Callback for creating a Dialog window (modal)
85     /// ** Must be defined ** in toolkit specific descendants 
86     virtual void bbCreateDialogWindow();
87     //==================================================================    
88
89     //==================================================================    
90     /// Callback for creating a Frame window 
91     /// ** Must be defined ** in toolkit specific descendants 
92     virtual void bbCreateFrameWindow();
93     //==================================================================    
94
95     //==================================================================
96     /// User callback called in the box contructor
97     virtual void bbUserConstructor();
98     /// User callback called in the box copy constructor
99     virtual void bbUserCopyConstructor(bbtk::BlackBox::Pointer);
100     //==================================================================    
101
102   
103     //==================================================================
104     //    virtual void InitWindowManagerIfNeeded();
105     virtual void IncNbWindowsAlive();
106     virtual void DecNbWindowsAlive();
107     virtual int  GetNbWindowsAlive();
108     virtual bool IsSomeWindowAlive();
109     
110     virtual void IncNbWindowsShown();
111     virtual void DecNbWindowsShown();
112     virtual int  GetNbWindowsShown();
113     virtual bool IsSomeWindowShown();
114     //==================================================================
115
116
117           
118     //==================================================================    
119     void bbCreateWidgetAndEventHandler(wxWindow* parent); 
120     //==================================================================    
121     
122     //==================================================================    
123
124   private:
125     /// friendship
126     friend class WxBlackBoxWidgetEventHandler;
127     /// Sets the Widget Event Handler
128     inline void bbSetWidgetEventHandler(WxBlackBoxWidgetEventHandler* w) 
129     { bbmWidgetEventHandler = w; }
130     /// Gets the Widget Event Handler
131     inline WxBlackBoxWidgetEventHandler* bbGetWidgetEventHandler()
132     { return bbmWidgetEventHandler; }
133     /// The WxBlackBoxWidgetEventHandler associated to the box
134     WxBlackBoxWidgetEventHandler* bbmWidgetEventHandler;
135     /// Init the attributes 
136     void bbInitAttributes();
137   };
138   //=================================================================
139  
140
141   //=================================================================
142   // WxBlackBoxDescriptor declaration
143   //
144   class WxBlackBoxDescriptor : public WidgetBlackBoxDescriptor<wxWindow>
145   BBTK_BEGIN_DESCRIBE_BLACK_BOX_BODY(WxBlackBox);
146   BBTK_NAME("WxBlackBox");
147   BBTK_END_DESCRIBE_BLACK_BOX(WxBlackBox);
148   //=================================================================
149
150
151
152
153
154
155
156
157
158
159   //==================================================================
160   // Dialog window which is modal
161   class BBTK_EXPORT  WxBlackBoxDialog : public wxDialog, 
162                                         public WidgetBlackBoxWindow<wxWindow>
163   {
164   public:
165     typedef WidgetBlackBoxWindow<wxWindow> Parent;
166     WxBlackBoxDialog(WxBlackBox::Pointer box, 
167                      wxWindow *parent, wxString title, wxSize size);
168     ~WxBlackBoxDialog();
169     void bbShow();  
170     void bbHide();
171     void bbClose();
172     bool IsDialog() { return true; }
173     bool IsFrame() { return false; }
174     wxDialog* bbGetDialog() { return this; } 
175   };
176   //==================================================================
177
178   //==================================================================
179   // Frame window which is not modal
180   class BBTK_EXPORT  WxBlackBoxFrame : public wxFrame, 
181                                        public WidgetBlackBoxWindow<wxWindow>
182   {
183   public:
184     typedef WidgetBlackBoxWindow<wxWindow> Parent;
185     WxBlackBoxFrame(WxBlackBox::Pointer box,
186                     wxWindow *parent, wxString title, wxSize size);
187     ~WxBlackBoxFrame();
188     void bbShow();
189     void bbHide();
190     void bbClose();
191     bool IsDialog() { return false; }
192     bool IsFrame() { return true; }
193     wxFrame* bbGetFrame() { return this; } 
194   };
195   //==================================================================
196
197
198
199   //=================================================================
200   // Handles the destroy events of a widget associated to a WxBlackBox 
201   // in order to signal the widget death to its associated box
202   class BBTK_EXPORT WxBlackBoxWidgetEventHandler : public wxEvtHandler
203   {
204   public:
205     /// Ctor with the box and widget 
206     WxBlackBoxWidgetEventHandler( WxBlackBox::Pointer box, wxWindow *widget );
207     /// Dtor
208     ~WxBlackBoxWidgetEventHandler();
209     /// Returns true iff is the handler for that window  
210     bool IsHandlerOf( wxWindow* w ) { return mWindow == w; }
211     // wxWindow* GetWxWindow() { return mWindow; }
212     /// Method processing the destroy event of the widget
213     void OnWindowDestroy(wxWindowDestroyEvent&);
214     //
215     //bool IsDead() { return mDead; }
216
217   private:
218     WxBlackBox::WeakPointer mBox;
219     wxWindow* mWindow;
220     //bool mDead;
221   };  
222   //=================================================================
223
224
225
226 } //namespace bbtk
227
228 #endif  //__bbtkWxBlackBox_h__
229
230 #endif  //USE_WXWIDGETS