1 /*=========================================================================
3 Module: $RCSfile: bbtkWx.cxx,v $
5 Date: $Date: 2009/04/08 07:56:11 $
6 Version: $Revision: 1.13 $
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 Wx::SetTopWindow(top);
139 //=========================================================================
141 //=========================================================================
142 void Wx::DestroyTopWindowIfNeeded()
144 if ( (mgNbWindowsAlive==0) &&
145 (mgAutoDestroyTopWindow) )
147 bbtkDebugMessage("wx",1," --> Destructing bbtk top window"<<std::endl);
148 mgTopWindow->Close();
151 DestroyWxAppIfNeeded();
154 //=========================================================================
156 //=========================================================================
157 void Wx::LoopUntilAllWindowsClose()
160 while (mgTopWindow != 0)
164 bbtkDebugMessage("wx",2,"Wx::Loop "<<i << std::endl);
171 //=========================================================================
173 //=========================================================================
174 wxWindow* Wx::GetTopWindow()
176 Wx::CreateTopWindowIfNeeded();
179 //=========================================================================
181 //=========================================================================
182 bool Wx::TopWindowExists()
184 return (mgTopWindow!=0);
186 //=========================================================================
189 //=========================================================================
190 void Wx::AddSignalObserver(Slot_function_type f)
192 mgWxSignal.connect(f);
194 //=========================================================================
197 //=========================================================================
198 void Wx::SetAutoDestroyTopWindow(bool b)
200 mgAutoDestroyTopWindow = b;
202 //=========================================================================
204 //=========================================================================
205 void Wx::SetTopWindow(wxWindow* w)
209 bbtkGlobalError("wx::SetTopWindow : top window already set !");
213 //=========================================================================
216 //=========================================================================
217 void Wx::IncNbWindowsAlive()
220 bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
226 //=========================================================================
228 //=========================================================================
229 void Wx::DecNbWindowsAlive()
232 bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
235 DestroyTopWindowIfNeeded();
240 //=========================================================================
242 //=========================================================================
243 void Wx::IncNbWindowsShown()
246 bbtkDebugMessage("wx",2,"* Number of windows shown = "<<mgNbWindowsShown
252 //=========================================================================
254 //=========================================================================
255 void Wx::DecNbWindowsShown()
258 bbtkDebugMessage("wx",2,"* Number of windows shown = "<<mgNbWindowsShown
261 DestroyTopWindowIfNeeded();
267 //=========================================================================
270 //=========================================================================
271 int Wx::GetNbWindowsAlive()
273 return mgNbWindowsAlive;
275 //=========================================================================
277 //=========================================================================
278 bool Wx::IsSomeWindowAlive()
280 return (mgNbWindowsAlive>0);
282 //=========================================================================
285 //=========================================================================
286 int Wx::GetNbWindowsShown()
288 return mgNbWindowsShown;
290 //=========================================================================
292 //=========================================================================
293 bool Wx::IsSomeWindowShown()
295 return (mgNbWindowsShown>0);
297 //=========================================================================
300 //=========================================================================
301 Wx::BusyCursor::BusyCursor()
304 if (wxApp::GetInstance()!=0)
306 bbtkDebugMessage("wx",2,
307 "Wx::BusyCursor::BusyCursor() : creating new cursor"
309 mCursor = new wxBusyCursor;
312 Wx::BusyCursor::~BusyCursor()
317 bbtkDebugMessage("wx",2,
318 "Wx::BusyCursor::~BusyCursor() : deleting cursor"<<std::endl);
321 //=========================================================================
324 //=========================================================================
325 void Wx::ResetCursor()
327 if (!TopWindowExists()) return;
328 bbtkDebugMessage("wx",9,"Wx::ResetCursor()"<<std::endl);
329 while (wxIsBusy()) ::wxEndBusyCursor();
331 //=========================================================================
332 //=========================================================================
333 void Wx::BeginBusyCursor()
335 if (!TopWindowExists()) return;
336 bbtkDebugMessage("wx",9,"Wx::BeginBusyCursor()"<<std::endl);
337 ::wxBeginBusyCursor();
339 //=========================================================================
340 //=========================================================================
341 void Wx::EndBusyCursor()
343 if (!TopWindowExists()) return;
344 bbtkDebugMessage("wx",9,"Wx::EndBusyCursor()"<<std::endl);
347 //=========================================================================
353 //=======================================================================
355 //=========================================================================
358 Wx::BusyCursor::BusyCursor()
361 Wx::BusyCursor::~BusyCursor()
364 //=========================================================================