]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxBlackBox.cxx
#3073 BBTK Bug New Normal - message documentation in boxes
[bbtk.git] / kernel / src / bbtkWxBlackBox.cxx
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: bbtkWxBlackBox.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:49:01 $
33   Version:   $Revision: 1.45 $
34 =========================================================================*/
35
36
37
38 #ifdef _USE_WXWIDGETS_
39
40 /**
41  *  \file 
42  *  \brief 
43  */
44  
45 #include "bbtkWxBlackBox.h"
46 #include "bbtkBlackBoxOutputConnector.h"
47
48 //#include "bbtkWxContainerBlackBox.h"
49 #include <wx/dialog.h>
50
51 //#include "bbtkData.h"
52 //#include "bbtkFactory.h"
53
54 namespace bbtk
55 {
56   //=========================================================================
57   // WxFrame
58   //=========================================================================
59
60   //==================================================================
61   class WxFrame : public wxFrame
62   {
63   public:
64     WxFrame(WxBlackBox::Pointer b,
65             wxWindow *parent,
66             wxString title,
67             wxSize size);
68     ~WxFrame();
69     void OnCloseWindow(wxCloseEvent& event);
70
71
72     WxBlackBox::WeakPointer mBox;      
73     DECLARE_EVENT_TABLE();
74     
75   };
76   
77   BEGIN_EVENT_TABLE(WxFrame, wxFrame)
78   //  EVT_CLOSE(WxFrame::OnCloseWindow)
79     END_EVENT_TABLE();
80      //==========================================Window  ========================
81   
82      //==================================================================
83   WxFrame::WxFrame(WxBlackBox::Pointer b,
84                    wxWindow *parent,
85                    wxString title,
86                    wxSize size) 
87     : 
88     wxFrame( parent, 
89              -1, 
90              title,
91              wxDefaultPosition,
92              size,
93              wxRESIZE_BORDER | 
94              wxSYSTEM_MENU  |
95              wxCLOSE_BOX |
96              wxMAXIMIZE_BOX | 
97              wxMINIMIZE_BOX | 
98              wxCAPTION  
99              ),
100     mBox(b)
101   {   
102     bbtkDebugMessage("widget",9,"["<<b->bbGetName()<<"] WxFrame()"
103                      <<std::endl);
104     Wx::IncNbWindowsAlive();
105     b->bbSetWindow(this);
106     // Insert the widget into the window
107     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
108     b->bbUserCreateWidget(this);
109     wxWindow* widget = b->bbGetOutputWidget();
110     sizer->Add( widget, 1, wxALL|wxGROW, 2);
111     SetSizer(sizer);
112     Layout();
113   }
114   //==================================================================
115   //==================================================================
116   WxFrame::~WxFrame() 
117     { 
118       if (mBox.lock())
119         bbtkDebugMessage("widget",9,"["<<mBox.lock()->bbGetName()
120                          <<"] $$$$$$$$$$$$$$$$$$$ ~WxFrame()"
121                          <<std::endl);
122       else 
123         bbtkDebugMessage("widget",9,"[DEAD] $$$$$$$$$$$$$$$$$$$$$ ~WxFrame()"<<std::endl);
124       //bbtkDebugMessage("widget",9,"WxFrame::~WxFrame()"<<std::endl);
125       if (mBox.lock()) mBox.lock()->bbSetWindow(0); 
126       Wx::DecNbWindowsAlive();
127     }
128    //==================================================================
129    //==================================================================
130   void WxFrame::OnCloseWindow(wxCloseEvent& event)
131     {
132       if (mBox.lock())
133         bbtkDebugMessage("widget",9,"["<<mBox.lock()->bbGetName()
134                          <<"] $$$$$$$$$$$$$$$ WxFrame::OnCloseWindow()"<<std::endl);
135       else
136         bbtkDebugMessage("widget",9,"[DEAD] WxFrame::OnCloseWindow()"
137                          <<std::endl);
138       if (mBox.lock()) mBox.lock()->bbSetWindow(0); 
139       Wx::DecNbWindowsAlive();
140       
141         bbtkDebugMessage("widget",9,
142                          "$$$$$$$$$$$$$$$ Destroy !!!"<<std::endl);
143         //      this->Destroy();
144     }
145    //==================================================================
146
147   //====================================================SetWin=====================
148   // WxDialog
149   //=========================================================================
150
151    //==================================================================
152   // Dialog window which is modal
153   class BBTK_EXPORT  WxDialog : public wxDialog
154   {
155   public:
156     WxDialog(WxBlackBox::Pointer box, 
157                      wxWindow *parent, 
158                      wxString title, 
159                      wxSize size);
160     ~WxDialog();
161     void OnCloseWindow(wxCloseEvent& event);
162
163
164     WxBlackBox::WeakPointer mBox;      
165     DECLARE_EVENT_TABLE();
166     
167   };
168   
169   BEGIN_EVENT_TABLE(WxDialog, wxDialog)
170     EVT_CLOSE(WxDialog::OnCloseWindow)
171     END_EVENT_TABLE();
172   //=========================================================================
173
174   //=========================================================================
175   WxDialog::WxDialog(WxBlackBox::Pointer b,
176                      wxWindow *parent,
177                      wxString title,
178                      wxSize size)
179     :
180     wxDialog( parent, 
181                 -1, 
182                 title,
183                 wxDefaultPosition,
184                 size,
185                 wxRESIZE_BORDER | 
186                 wxSYSTEM_MENU  |
187                 wxCLOSE_BOX |
188                 wxMAXIMIZE_BOX | 
189                 wxMINIMIZE_BOX | 
190                 wxCAPTION  
191               ),
192     mBox(b)
193   {
194                 
195     bbtkDebugMessage("widget",9,"WxDialog::WxDialog ["<<b->bbGetName()<<"]"
196                      <<std::endl);
197     Wx::IncNbWindowsAlive();
198     b->bbSetWindow(this);
199     // Insert the widget into the window
200     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
201     b->bbUserCreateWidget(this);
202     wxWindow* widget = b->bbGetOutputWidget();
203     sizer->Add( widget, 1, wxALL|wxGROW, 2);
204     SetSizer(sizer);
205     Layout();
206   }
207   //==================================================================
208   //==================================================================
209   WxDialog::~WxDialog() 
210     { 
211       bbtkDebugMessage("widget",9,"WxDialog::~WxDialog()"<<std::endl);
212       //bbtkDebugMessage("widget",9,"WxFrame::~WxFrame()"<<std::endl);
213       //      if (mBox.lock()) mBox.lock()->bbSetWindow(0); 
214       //      Wx::DecNbWindowsAlive();
215     }
216    //==================================================================
217    //==================================================================
218   void WxDialog::OnCloseWindow(wxCloseEvent& event)
219     {
220       bbtkDebugMessage("widget",9,"WxDialog::OnCloseWindow()"<<std::endl);
221       if (mBox.lock()) mBox.lock()->bbSetWindow(0); 
222       Wx::DecNbWindowsAlive();
223       this->Destroy();
224     }
225    //==================================================================
226
227
228  //=========================================================================
229   // WxBlackBox
230   //=========================================================================
231
232   //=========================================================================
233   //=========================================================================
234   //=========================================================================
235   //=========================================================================
236   BBTK_BLACK_BOX_IMPLEMENTATION(WxBlackBox,WidgetBlackBox<wxWindow>);
237   //=========================================================================
238   
239   //=========================================================================
240   void WxBlackBox::bbUserSetDefaultValues()
241   {
242     bbtkBlackBoxDebugMessage("widget",5,"WxBlackBox::bbUserSetDefaultValues()"<<std::endl);
243     bbmWindow = 0;  
244   }
245   //=========================================================================
246
247   //=========================================================================
248   void WxBlackBox::bbUserInitializeProcessing()
249   {
250   }
251   //==================================================================    
252
253   //=========================================================================
254   void WxBlackBox::bbUserFinalizeProcessing()
255   {
256     bbtkBlackBoxDebugMessage("widget",5,"==> WxBlackBox::bbUserFinalizeProcessing()"<<std::endl);
257     bbDestroyWindow();
258     bbtkBlackBoxDebugMessage("widget",5,"<== WxBlackBox::bbUserFinalizeProcessing()"<<std::endl);
259   }
260   //==================================================================    
261
262   //==================================================================    
263   /// Callback for creating a Dialog window (modal)
264   void WxBlackBox::bbCreateDialogWindow()
265   {
266   bbtkBlackBoxDebugMessage("widget",3,
267                      "==> WxBlackBox::bbCreateDialogWindow() - parent = "
268                      <<Wx::GetTopWindow()
269                      <<std::endl);
270     WxDialog* w = 0;  
271     w = new WxDialog( GetThisPointer<WxBlackBox>(),
272                       Wx::GetTopWindow(),
273 //                    std2wx( bbGetInputWinTitle() + " - bbtk (c) CREATIS"),
274                       std2wx( ConstructWinTitle() ),
275                       wxSize( bbGetInputWinWidth() , 
276                               bbGetInputWinHeight() ) );
277     w->Show(false);
278     //    w->ShowModal();
279   } 
280   //=========================================================================
281
282   //==================================================================    
283
284   //==================================================================    
285   /// Callback for creating a Frame window 
286   void WxBlackBox::bbCreateFrameWindow()
287   {
288     bbtkBlackBoxDebugMessage("widget",3,
289                      "==> WxBlackBox::bbCreateFrameWindow() - parent = "
290                      <<Wx::GetTopWindow()
291                      <<std::endl);
292     WxFrame* w = 0;  
293     w = new WxFrame( GetThisPointer<WxBlackBox>(),
294                      Wx::GetTopWindow(),
295 //                   std2wx( bbGetInputWinTitle() + " - bbtk (c) CREATIS"),
296                      std2wx( ConstructWinTitle() ),
297                      wxSize( bbGetInputWinWidth() , 
298                              bbGetInputWinHeight() ) );
299     w->Show();
300
301
302    }
303
304   //==================================================================    
305
306   //==================================================================    
307   void WxBlackBox::bbSetWindow(wxWindow* w) 
308   {
309     bbtkBlackBoxDebugMessage("widget",9,"==> WxBlackBox::bbSetWindow("<<w<<")"<<std::endl);
310     if ((bbmWindow != 0)&&(w!=0)) 
311         { 
312                 std::cout << "WxBlackBox::bbSetWindow   ?? EED ?? ERRRRRRRROOOOR"<<std::endl; 
313         }
314     bbmWindow = w;
315   }
316   //==================================================================    
317
318   //==================================================================    
319   void WxBlackBox::bbShowWindow()
320   {
321     if ((bbmWindow) && (!bbIsShown()))
322       {
323         bbtkBlackBoxDebugMessage("widget",3,"==> WxBlackBox::bbShowWindow()"
324                          <<std::endl);
325         if (bbGetInputWinDialog()) 
326           {
327             ((WxDialog*)bbmWindow)->ShowModal();
328           }
329         else    
330           {
331             bbGetWindow()->Show();
332             bbSetShown(true);
333           } 
334       } // if
335
336
337   }
338   //==================================================================    
339
340   //==================================================================    
341   void WxBlackBox::bbDestroyWindow()
342   {
343     bbtkBlackBoxDebugMessage("widget",3,"==> WxBlackBox::bbDestroyWindow("<<bbmWindow<<")"<<std::endl);
344     if (bbGetWindow()!=NULL) 
345       {
346         //       wxWindow* w = bbGetWindow();
347         //bbSetWindow(0);
348         // WE SHOULD DESTROY THE WINDOW WITH THE Close METHOD
349         // HOWEVER I
350         //w->Close(true);
351         //
352         delete bbGetWindow();
353         bbSetShown(false);
354       }
355     bbtkBlackBoxDebugMessage("widget",3,"<== WxBlackBox::bbDestroyWindow("<<bbmWindow<<")"<<std::endl);
356
357   }
358   //==================================================================    
359   
360   //==================================================================    
361   void WxBlackBox::PutWinTitle()
362   {
363         if ( ! bbIsOutputWidgetConnected() )
364     {
365                 wxTopLevelWindow* wParent = (wxTopLevelWindow*)( bbGetOutputWidget()->GetParent() );
366                 wParent->SetTitle( std2wx( ConstructWinTitle() ) );
367         } // if
368   }
369   //==================================================================    
370
371   //==================================================================    
372   std::string WxBlackBox::ConstructWinTitle()
373   {
374         std::string title( bbGetInputWinTitle() + " - bbtk (c) CREATIS");
375         return title;
376   }
377   //==================================================================    
378
379
380
381 }//namespace bbtk
382
383 #endif
384