1 /*=========================================================================
3 Module: $RCSfile: bbtkWx.cxx,v $
5 Date: $Date: 2009/05/19 10:19:23 $
6 Version: $Revision: 1.14 $
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 * ------------------------------------------------------------------------ */
31 #include "bbtkMessageManager.h"
33 #ifdef _USE_WXWIDGETS_
37 //=========================================================================
39 //=========================================================================
41 //=========================================================================
42 static WxApp* mgWxApp = 0;
43 static wxWindow* mgTopWindow = 0;
44 static wxWindow* mgTopWindowParent = 0;
45 static bool mgAutoDestroyTopWindow = true;
46 static int mgNbWindowsAlive = 0;
47 static int mgNbWindowsShown = 0;
48 //=========================================================================
50 //=========================================================================
52 static Wx::Signal_type mgWxSignal;
54 //=========================================================================
57 //=========================================================================
58 // The wxApp class which is used when no user wxApp was created
59 class WxApp : public wxApp
63 int OnExit() { return true; }
65 //=========================================================================
66 IMPLEMENT_APP_NO_MAIN(WxApp);
67 //=========================================================================
72 //See http://www.wxwindows.org/faqgtk.htm#locale
73 setlocale(LC_NUMERIC, "C");
77 //=========================================================================
79 //=========================================================================
80 void Wx::CreateWxAppIfNeeded()
82 if (wxApp::GetInstance()==0)
86 bbtkGlobalError("Wx::CreateWxAppIfNeeded() : INTERNAL ERROR ! (wxApp::GetInstance()==0) && (mgWxApp != 0)");
88 bbtkDebugMessage("wx",1," --> Creating bbtk wxApp"<<std::endl);
90 wxApp::SetInstance(mgWxApp);
96 //=========================================================================
98 //=========================================================================
99 void Wx::DestroyWxAppIfNeeded()
103 bbtkDebugMessage("wx",1," --> Destructing bbtk WxApp"<<std::endl);
110 //=========================================================================
112 //=========================================================================
113 void Wx::SetTopWindowParent(wxWindow* w)
115 if (mgTopWindowParent != 0)
117 bbtkGlobalError("Wx::SetTopWindowParent : top window parent != 0");
119 mgTopWindowParent = w;
121 //=========================================================================
123 //=========================================================================
124 void Wx::CreateTopWindowIfNeeded()
126 if (mgTopWindow!=0) return;
127 bbtkDebugMessage("wx",1," --> Creating bbtk top window"<<std::endl);
129 CreateWxAppIfNeeded();
132 new wxFrame(mgTopWindowParent,
134 _T("TOP BBTK FRAME (YOU SHOULD NOT SEE ME !!)"));
137 //if (mgTopWindowParent==0)
138 Wx::SetTopWindow(top);
140 //=========================================================================
142 //=========================================================================
143 void Wx::DestroyTopWindowIfNeeded()
145 if ( (mgNbWindowsAlive==0) &&
146 (mgAutoDestroyTopWindow) &&
149 bbtkDebugMessage("wx",1," --> Destructing bbtk top window"<<std::endl);
150 mgTopWindow->Close();
153 DestroyWxAppIfNeeded();
156 //=========================================================================
158 //=========================================================================
159 void Wx::LoopUntilAllWindowsClose()
162 while (mgTopWindow != 0)
166 bbtkDebugMessage("wx",2,"Wx::Loop "<<i << std::endl);
173 //=========================================================================
175 //=========================================================================
176 wxWindow* Wx::GetTopWindow()
178 Wx::CreateTopWindowIfNeeded();
181 //=========================================================================
183 //=========================================================================
184 bool Wx::TopWindowExists()
186 return (mgTopWindow!=0);
188 //=========================================================================
191 //=========================================================================
192 void Wx::AddSignalObserver(Slot_function_type f)
194 mgWxSignal.connect(f);
196 //=========================================================================
199 //=========================================================================
200 void Wx::SetAutoDestroyTopWindow(bool b)
202 mgAutoDestroyTopWindow = b;
204 //=========================================================================
206 //=========================================================================
207 void Wx::SetTopWindow(wxWindow* w)
211 bbtkGlobalError("wx::SetTopWindow : top window already set !");
215 //=========================================================================
218 //=========================================================================
219 void Wx::IncNbWindowsAlive()
222 bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
228 //=========================================================================
230 //=========================================================================
231 void Wx::DecNbWindowsAlive()
234 bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
237 DestroyTopWindowIfNeeded();
242 //=========================================================================
244 //=========================================================================
245 void Wx::IncNbWindowsShown()
248 bbtkDebugMessage("wx",2,"* Number of windows shown = "<<mgNbWindowsShown
254 //=========================================================================
256 //=========================================================================
257 void Wx::DecNbWindowsShown()
260 bbtkDebugMessage("wx",2,"* Number of windows shown = "<<mgNbWindowsShown
263 // DestroyTopWindowIfNeeded();
269 //=========================================================================
272 //=========================================================================
273 int Wx::GetNbWindowsAlive()
275 return mgNbWindowsAlive;
277 //=========================================================================
279 //=========================================================================
280 bool Wx::IsSomeWindowAlive()
282 return (mgNbWindowsAlive>0);
284 //=========================================================================
287 //=========================================================================
288 int Wx::GetNbWindowsShown()
290 return mgNbWindowsShown;
292 //=========================================================================
294 //=========================================================================
295 bool Wx::IsSomeWindowShown()
297 return (mgNbWindowsShown>0);
299 //=========================================================================
302 //=========================================================================
303 Wx::BusyCursor::BusyCursor()
306 if (wxApp::GetInstance()!=0)
308 bbtkDebugMessage("wx",2,
309 "Wx::BusyCursor::BusyCursor() : creating new cursor"
311 //mCursor = new wxBusyCursor;
314 Wx::BusyCursor::~BusyCursor()
319 bbtkDebugMessage("wx",2,
320 "Wx::BusyCursor::~BusyCursor() : deleting cursor"<<std::endl);
323 //=========================================================================
326 //=========================================================================
327 void Wx::ResetCursor()
329 if (!TopWindowExists()) return;
330 bbtkDebugMessage("wx",9,"Wx::ResetCursor()"<<std::endl);
331 while (wxIsBusy()) ::wxEndBusyCursor();
333 //=========================================================================
334 //=========================================================================
335 void Wx::BeginBusyCursor()
337 if (!TopWindowExists()) return;
338 bbtkDebugMessage("wx",9,"Wx::BeginBusyCursor()"<<std::endl);
339 ::wxBeginBusyCursor();
341 //=========================================================================
342 //=========================================================================
343 void Wx::EndBusyCursor()
345 if (!TopWindowExists()) return;
346 bbtkDebugMessage("wx",9,"Wx::EndBusyCursor()"<<std::endl);
349 //=========================================================================
355 //=======================================================================
357 //=========================================================================
360 Wx::BusyCursor::BusyCursor()
363 Wx::BusyCursor::~BusyCursor()
366 //=========================================================================