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