2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkWxBlackBox.cxx,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.45 $
34 =========================================================================*/
38 #ifdef _USE_WXWIDGETS_
45 #include "bbtkWxBlackBox.h"
46 #include "bbtkBlackBoxOutputConnector.h"
48 //#include "bbtkWxContainerBlackBox.h"
49 #include <wx/dialog.h>
51 //#include "bbtkData.h"
52 //#include "bbtkFactory.h"
56 //=========================================================================
58 //=========================================================================
60 //==================================================================
61 class WxFrame : public wxFrame
64 WxFrame(WxBlackBox::Pointer b,
69 void OnCloseWindow(wxCloseEvent& event);
72 WxBlackBox::WeakPointer mBox;
73 DECLARE_EVENT_TABLE();
77 BEGIN_EVENT_TABLE(WxFrame, wxFrame)
78 // EVT_CLOSE(WxFrame::OnCloseWindow)
80 //==================================================================
82 //==================================================================
83 WxFrame::WxFrame(WxBlackBox::Pointer b,
102 std::cout<<"Creando Widget DELETE ME bbtkWxBlackBox.cxx--"<<std::endl;
103 std::cout<<"NAME : "<<bbtk::wx2std(title);
105 std::cout<<"PARENT : "<<bbtk::wx2std(parent->GetName())<<std::endl;
107 std::cout<<" SIN PADRE "<<std::endl;
108 bbtkDebugMessage("widget",9,"["<<b->bbGetName()<<"] WxFrame()"
110 Wx::IncNbWindowsAlive();
111 b->bbSetWindow(this);
112 // Insert the widget into the window
113 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
114 b->bbUserCreateWidget(this);
115 wxWindow* widget = b->bbGetOutputWidget();
116 sizer->Add( widget, 1, wxALL|wxGROW, 2);
120 //==================================================================
121 //==================================================================
125 bbtkDebugMessage("widget",9,"["<<mBox.lock()->bbGetName()
126 <<"] $$$$$$$$$$$$$$$$$$$ ~WxFrame()"
129 bbtkDebugMessage("widget",9,"[DEAD] $$$$$$$$$$$$$$$$$$$$$ ~WxFrame()"<<std::endl);
130 //bbtkDebugMessage("widget",9,"WxFrame::~WxFrame()"<<std::endl);
131 if (mBox.lock()) mBox.lock()->bbSetWindow(0);
132 Wx::DecNbWindowsAlive();
134 //==================================================================
135 //==================================================================
136 void WxFrame::OnCloseWindow(wxCloseEvent& event)
139 bbtkDebugMessage("widget",9,"["<<mBox.lock()->bbGetName()
140 <<"] $$$$$$$$$$$$$$$ WxFrame::OnCloseWindow()"<<std::endl);
142 bbtkDebugMessage("widget",9,"[DEAD] WxFrame::OnCloseWindow()"
144 if (mBox.lock()) mBox.lock()->bbSetWindow(0);
145 Wx::DecNbWindowsAlive();
147 bbtkDebugMessage("widget",9,
148 "$$$$$$$$$$$$$$$ Destroy !!!"<<std::endl);
151 //==================================================================
153 //=========================================================================
155 //=========================================================================
157 //==================================================================
158 // Dialog window which is modal
159 class BBTK_EXPORT WxDialog : public wxDialog
162 WxDialog(WxBlackBox::Pointer box,
167 void OnCloseWindow(wxCloseEvent& event);
170 WxBlackBox::WeakPointer mBox;
171 DECLARE_EVENT_TABLE();
175 BEGIN_EVENT_TABLE(WxDialog, wxDialog)
176 EVT_CLOSE(WxDialog::OnCloseWindow)
178 //=========================================================================
180 //=========================================================================
181 WxDialog::WxDialog(WxBlackBox::Pointer b,
201 bbtkDebugMessage("widget",9,"WxDialog::WxDialog ["<<b->bbGetName()<<"]"
203 Wx::IncNbWindowsAlive();
204 b->bbSetWindow(this);
205 // Insert the widget into the window
206 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
207 b->bbUserCreateWidget(this);
208 wxWindow* widget = b->bbGetOutputWidget();
209 sizer->Add( widget, 1, wxALL|wxGROW, 2);
213 //==================================================================
214 //==================================================================
215 WxDialog::~WxDialog()
217 bbtkDebugMessage("widget",9,"WxDialog::~WxDialog()"<<std::endl);
218 //bbtkDebugMessage("widget",9,"WxFrame::~WxFrame()"<<std::endl);
219 // if (mBox.lock()) mBox.lock()->bbSetWindow(0);
220 // Wx::DecNbWindowsAlive();
222 //==================================================================
223 //==================================================================
224 void WxDialog::OnCloseWindow(wxCloseEvent& event)
226 bbtkDebugMessage("widget",9,"WxDialog::OnCloseWindow()"<<std::endl);
227 if (mBox.lock()) mBox.lock()->bbSetWindow(0);
228 Wx::DecNbWindowsAlive();
231 //==================================================================
234 //=========================================================================
236 //=========================================================================
238 //=========================================================================
239 //=========================================================================
240 //=========================================================================
241 //=========================================================================
242 BBTK_BLACK_BOX_IMPLEMENTATION(WxBlackBox,WidgetBlackBox<wxWindow>);
243 //=========================================================================
245 //=========================================================================
246 void WxBlackBox::bbUserSetDefaultValues()
248 bbtkBlackBoxDebugMessage("widget",5,"WxBlackBox::bbUserSetDefaultValues()"<<std::endl);
251 //=========================================================================
253 //=========================================================================
254 void WxBlackBox::bbUserInitializeProcessing()
257 //==================================================================
259 //=========================================================================
260 void WxBlackBox::bbUserFinalizeProcessing()
262 bbtkBlackBoxDebugMessage("widget",5,"==> WxBlackBox::bbUserFinalizeProcessing()"<<std::endl);
264 bbtkBlackBoxDebugMessage("widget",5,"<== WxBlackBox::bbUserFinalizeProcessing()"<<std::endl);
266 //==================================================================
268 //==================================================================
269 /// Callback for creating a Dialog window (modal)
270 void WxBlackBox::bbCreateDialogWindow()
272 bbtkBlackBoxDebugMessage("widget",3,
273 "==> WxBlackBox::bbCreateDialogWindow() - parent = "
277 w = new WxDialog( GetThisPointer<WxBlackBox>(),
279 std2wx( bbGetInputWinTitle()
280 + " - bbtk (c) CREATIS"),
281 wxSize( bbGetInputWinWidth() ,
282 bbGetInputWinHeight() ) );
286 //=========================================================================
288 //==================================================================
290 //==================================================================
291 /// Callback for creating a Frame window
292 void WxBlackBox::bbCreateFrameWindow()
294 bbtkBlackBoxDebugMessage("widget",3,
295 "==> WxBlackBox::bbCreateFrameWindow() - parent = "
299 w = new WxFrame( GetThisPointer<WxBlackBox>(),
301 std2wx( bbGetInputWinTitle()
302 + " - bbtk (c) CREATIS"),
303 wxSize( bbGetInputWinWidth() ,
304 bbGetInputWinHeight() ) );
305 std::cout<<"--!!--JFGA Testing bbCreateFrameWindow "<<bbGetInputWinTitle()<<"......!! D E L E T M E !! bbtkWxBlackBox.cxx"<<std::endl;
309 //==================================================================
311 //==================================================================
312 void WxBlackBox::bbSetWindow(wxWindow* w)
314 bbtkBlackBoxDebugMessage("widget",9,"==> WxBlackBox::bbSetWindow("<<w<<")"<<std::endl);
315 if ((bbmWindow != 0)&&(w!=0))
317 std::cout << "ERRRRRRRROOOOR"<<std::endl;
319 std::cout<<"SetWindow DELETE ME bbtkWxBlackBox.cxx ------"<<std::endl;
320 std::cout<<"WINDOW : "<<bbtk::wx2std(w->GetName())<<std::endl;
323 //==================================================================
325 //==================================================================
326 void WxBlackBox::bbShowWindow()
328 std::cout<<"--!!--JFGA Testing bbShowWindow PRE IF "<<bbGetInputWinTitle()<<"......!! D E L E T M E !! bbtkWxBlackBox.cxx"<<std::endl;
329 if ((bbmWindow) && (!bbIsShown()))
331 bbtkBlackBoxDebugMessage("widget",3,"==> WxBlackBox::bbShowWindow()"
333 if (bbGetInputWinDialog())
335 ((WxDialog*)bbmWindow)->ShowModal();
339 std::cout<<"--!!--JFGA Testing bbShowWindow "<<bbGetInputWinTitle()<<"......!! D E L E T M E !! bbtkWxBlackBox.cxx"<<std::endl;
340 bbGetWindow()->Show();
345 //==================================================================
347 //==================================================================
348 void WxBlackBox::bbDestroyWindow()
350 bbtkBlackBoxDebugMessage("widget",3,"==> WxBlackBox::bbDestroyWindow("<<bbmWindow<<")"<<std::endl);
351 if (bbGetWindow()!=NULL)
353 // wxWindow* w = bbGetWindow();
355 // WE SHOULD DESTROY THE WINDOW WITH THE Close METHOD
359 delete bbGetWindow();
362 bbtkBlackBoxDebugMessage("widget",3,"<== WxBlackBox::bbDestroyWindow("<<bbmWindow<<")"<<std::endl);
365 //==================================================================