1 /*=========================================================================
3 Module: $RCSfile: bbtkWxBlackBox.cxx,v $
5 Date: $Date: 2009/04/08 07:56:11 $
6 Version: $Revision: 1.38 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
32 #ifdef _USE_WXWIDGETS_
41 #include "bbtkWxBlackBox.h"
42 #include "bbtkBlackBoxOutputConnector.h"
44 //#include "bbtkWxContainerBlackBox.h"
45 #include <wx/dialog.h>
47 //#include "bbtkData.h"
48 //#include "bbtkFactory.h"
60 //=========================================================================
62 //=========================================================================
64 //=========================================================================
65 WxBlackBoxDialog::WxBlackBoxDialog(WxBlackBox::Pointer box,
84 bbtkDebugMessage("wx",9,"WxBlackBoxDialog::WxBlackBoxDialog("<<
85 bbGetBlackBox()->bbGetFullName()<<","<<parent<<","
86 <<title<<",size)"<<std::endl);
87 // Insert the widget into the window
88 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
90 box->bbCreateWidgetAndEventHandler(this);
91 wxWindow* widget = bbGetBlackBox()->bbGetOutputWidget();
92 sizer->Add( widget, 1, wxALL|wxEXPAND, 2);
93 //SetAutoLayout(true);
97 //=========================================================================
99 //=========================================================================
100 void WxBlackBoxDialog::bbShow()
102 if (bbIsShown()) return;
103 bbtkDebugMessage("wx",5,"WxBlackBoxDialog::bbShow() ["
104 <<bbGetBlackBox()->bbGetFullName()<<"]"<<std::endl);
107 SetReturnCode( wxDialog::ShowModal() );
110 //=========================================================================
112 //=========================================================================
113 void WxBlackBoxDialog::bbHide()
115 bbtkDebugMessage("wx",9,"WxBlackBoxDialog::bbHide()"<<std::endl);
119 //=========================================================================
121 //=========================================================================
122 void WxBlackBoxDialog::bbClose()
124 bbtkDebugMessage("wx",9,"WxBlackBoxDialog::bbClose()"<<std::endl);
127 //=========================================================================
129 //=========================================================================
130 WxBlackBoxDialog::~WxBlackBoxDialog()
133 //=========================================================================
139 //=========================================================================
141 //=========================================================================
143 //=========================================================================
144 WxBlackBoxFrame::WxBlackBoxFrame(WxBlackBox::Pointer box,
162 bbtkDebugMessage("wx",9,"WxBlackBoxFrame::WxBlackBoxFrame("<<
163 bbGetBlackBox()->bbGetFullName()<<","<<parent<<","
164 <<title<<",size)"<<std::endl);
165 // Insert the widget into the window
166 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
167 box->bbCreateWidgetAndEventHandler(this);
168 wxWindow* widget = bbGetBlackBox()->bbGetOutputWidget();
169 wxFrame* frame = (wxFrame*)this;
170 sizer->Add( widget, 1, wxALL|wxGROW, 2);
171 // frame->SetAutoLayout(true);
172 frame->SetSizer(sizer);
176 //=========================================================================
178 //=========================================================================
179 WxBlackBoxFrame::~WxBlackBoxFrame()
182 //=========================================================================
184 //=========================================================================
185 void WxBlackBoxFrame::bbShow()
187 if (bbIsShown()) return;
188 bbtkDebugMessage("wx",5,"WxBlackBoxFrame::bbShow("
189 <<bbGetBlackBox()->bbGetFullName()<<")"<<std::endl);
192 // This Update is ** MANDATORY **
193 // to synchronize wxvtkRenderWindowInteractor objects
194 // (force wx objects creation **NOW**)
203 // if (bbGetBlackBox()) bbGetBlackBox()->bbUserOnShow();
205 //=========================================================================
207 //=========================================================================
208 void WxBlackBoxFrame::bbHide()
210 bbtkDebugMessage("wx",9,"WxBlackBoxFrame::bbHide()"<<std::endl);
213 if (bbGetBlackBox()) bbGetBlackBox()->bbUserOnHide();
215 //=========================================================================
217 //=========================================================================
218 void WxBlackBoxFrame::bbClose()
220 bbtkDebugMessage("wx",9,"WxBlackBoxFrame::bbClose()"<<std::endl);
223 //=========================================================================
227 //=========================================================================
228 // WxBlackBoxWidgetEventHandler
229 //=========================================================================
231 //=========================================================================
232 WxBlackBoxWidgetEventHandler::
233 WxBlackBoxWidgetEventHandler( WxBlackBox::Pointer box,
239 bbtkDebugMessage("wx",9,"WxBlackBoxWidgetEventHandler::WxBlackBoxWidgetEventHandler("<<mBox.lock()->bbGetFullName()<<")"<<std::endl);
241 mBox.lock()->bbSetWidgetEventHandler(this);
243 Connect ( mWindow->GetId(),
245 (wxObjectEventFunction)
246 (void (wxEvtHandler::*)(wxWindowDestroyEvent& c))
247 &WxBlackBoxWidgetEventHandler::OnWindowDestroy );
249 mWindow->PushEventHandler(this);
252 //=========================================================================
254 //=========================================================================
255 WxBlackBoxWidgetEventHandler::~WxBlackBoxWidgetEventHandler()
257 if (mBox.expired()) return;
258 bbtkDebugMessage("wx",9,
259 "WxBlackBoxWidgetEventHandler::~WxBlackBoxWidgetEventHandler() ["
260 <<mBox.lock()->bbGetFullName()<<"]"<<std::endl);
261 mBox.lock()->bbSetWidgetEventHandler(0);
263 //=========================================================================
265 //=========================================================================
266 void WxBlackBoxWidgetEventHandler::OnWindowDestroy(wxWindowDestroyEvent&)
268 if (mBox.expired()) return;
269 bbtkDebugMessage("wx",9,"WxBlackBoxWidgetEventHandler::OnWindowDestroy() ["
270 <<mBox.lock()->bbGetFullName()<<"]"<<std::endl);
271 mBox.lock()->bbSetOutputWidget(0);
273 // mBox.lock()->bbSetModifiedStatus();
275 //=========================================================================
283 //=========================================================================
285 //=========================================================================
287 //=========================================================================
288 //=========================================================================
289 //=========================================================================
290 //=========================================================================
291 BBTK_BLACK_BOX_IMPLEMENTATION(WxBlackBox,WidgetBlackBox<wxWindow>);
292 //=========================================================================
294 //=========================================================================
295 void WxBlackBox::bbUserConstructor()
297 bbtkDebugMessage("Kernel",9,"WxBlackBox::bbUserConstructor()"<<std::endl);
300 //=========================================================================
302 //=========================================================================
303 void WxBlackBox::bbUserCopyConstructor(bbtk::BlackBox::Pointer)
305 bbtkDebugMessage("Kernel",9,"WxBlackBox::bbUserCopyConstructor()"
309 //=========================================================================
313 //=========================================================================
314 /// Initialize the attributes of the class
315 void WxBlackBox::bbInitAttributes()
317 bbSetWidgetEventHandler(0);
319 //=========================================================================
321 //==================================================================
322 /// Callback for creating a Dialog window (modal)
323 void WxBlackBox::bbCreateDialogWindow()
325 WxBlackBoxDialog* w = 0;
326 w = new WxBlackBoxDialog( GetThisPointer<WxBlackBox>(),
328 std2wx( bbGetInputWinTitle()
329 + " - bbtk (c) CREATIS LRMN"),
330 wxSize( bbGetInputWinWidth() ,
331 bbGetInputWinHeight() ));
334 //==================================================================
336 //==================================================================
337 /// Callback for creating a Frame window
338 void WxBlackBox::bbCreateFrameWindow()
340 WxBlackBoxFrame* w = 0;
341 w = new WxBlackBoxFrame( GetThisPointer<WxBlackBox>(),
343 std2wx( bbGetInputWinTitle()
344 + " - bbtk (c) CREATIS LRMN"),
345 wxSize( bbGetInputWinWidth() ,
346 bbGetInputWinHeight() ) );
349 //==================================================================
354 //=========================================================================
355 void WxBlackBox::bbCreateWidgetAndEventHandler(wxWindow* parent)
357 if (bbGetOutputWidget()==0)
359 this->bbUserCreateWidget(parent);
361 // If Event Handler for the widget does not exist or is obsolete:
363 if (bbGetOutputWidget()!=0)
365 if (bbGetWidgetEventHandler()==0)
367 bbtkDebugMessage("wx",3,
368 "-> No widget event handler : creating one"
370 new WxBlackBoxWidgetEventHandler(GetThisPointer<WxBlackBox>(),
371 bbGetOutputWidget());
373 else if ( ! bbGetWidgetEventHandler()->IsHandlerOf
374 ( bbGetOutputWidget() ) )
376 bbtkDebugMessage("wx",3,
377 "-> Obsolete widget event handler : re-creating one"
379 delete bbGetWidgetEventHandler();
380 new WxBlackBoxWidgetEventHandler(GetThisPointer<WxBlackBox>(),
381 bbGetOutputWidget());
383 // Sets the name of the wxWindow to the input WinTitle
384 bbGetOutputWidget()->SetName(bbtk::std2wx(bbGetInputWinTitle()));
389 //=========================================================================
392 //==================================================================
393 // void WxBlackBox::InitWindowManagerIfNeeded() { Wx::
394 void WxBlackBox::IncNbWindowsAlive() { Wx::IncNbWindowsAlive(); }
395 void WxBlackBox::DecNbWindowsAlive() { Wx::DecNbWindowsAlive(); }
396 int WxBlackBox::GetNbWindowsAlive() { return Wx::GetNbWindowsAlive(); }
397 bool WxBlackBox::IsSomeWindowAlive() { return Wx::IsSomeWindowAlive(); }
399 void WxBlackBox::IncNbWindowsShown() { Wx::IncNbWindowsShown(); }
400 void WxBlackBox::DecNbWindowsShown() { Wx::DecNbWindowsShown(); }
401 int WxBlackBox::GetNbWindowsShown() { return Wx::GetNbWindowsShown(); }
402 bool WxBlackBox::IsSomeWindowShown() { return Wx::GetNbWindowsShown(); }
403 //==================================================================