1 /*=========================================================================
3 Module: $RCSfile: bbtkWx.cxx,v $
5 Date: $Date: 2008/10/21 13:55:49 $
6 Version: $Revision: 1.11 $
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 #ifdef _USE_WXWIDGETS_
34 #include "bbtkMessageManager.h"
38 //=========================================================================
40 //=========================================================================
42 //=========================================================================
43 static WxApp* mgWxApp = 0;
44 static wxWindow* mgTopWindow = 0;
45 static wxWindow* mgTopWindowParent = 0;
46 static bool mgAutoDestroyTopWindow = true;
47 static int mgNbWindowsAlive = 0;
48 static int mgNbWindowsShown = 0;
49 //=========================================================================
51 //=========================================================================
53 static Wx::Signal_type mgWxSignal;
55 //=========================================================================
58 //=========================================================================
59 // The wxApp class which is used when no user wxApp was created
60 class WxApp : public wxApp
64 int OnExit() { return true; }
66 //=========================================================================
67 IMPLEMENT_APP_NO_MAIN(WxApp);
68 //=========================================================================
73 //See http://www.wxwindows.org/faqgtk.htm#locale
74 setlocale(LC_NUMERIC, "C");
78 //=========================================================================
80 //=========================================================================
81 void Wx::CreateWxAppIfNeeded()
83 if (wxApp::GetInstance()==0)
87 bbtkGlobalError("Wx::CreateWxAppIfNeeded() : INTERNAL ERROR ! (wxApp::GetInstance()==0) && (mgWxApp != 0)");
89 bbtkDebugMessage("wx",1," --> Creating bbtk wxApp"<<std::endl);
91 wxApp::SetInstance(mgWxApp);
97 //=========================================================================
99 //=========================================================================
100 void Wx::DestroyWxAppIfNeeded()
104 bbtkDebugMessage("wx",1," --> Destructing bbtk WxApp"<<std::endl);
111 //=========================================================================
113 //=========================================================================
114 void Wx::SetTopWindowParent(wxWindow* w)
116 if (mgTopWindowParent != 0)
118 bbtkGlobalError("Wx::SetTopWindowParent : top window parent != 0");
120 mgTopWindowParent = w;
122 //=========================================================================
124 //=========================================================================
125 void Wx::CreateTopWindowIfNeeded()
127 if (mgTopWindow!=0) return;
128 bbtkDebugMessage("wx",1," --> Creating bbtk top window"<<std::endl);
130 CreateWxAppIfNeeded();
133 new wxFrame(mgTopWindowParent,
135 _T("TOP BBTK FRAME (YOU SHOULD NOT SEE ME !!)"));
138 Wx::SetTopWindow(top);
140 //=========================================================================
142 //=========================================================================
143 void Wx::DestroyTopWindowIfNeeded()
145 if ( (mgNbWindowsAlive==0) &&
146 (mgAutoDestroyTopWindow) )
148 bbtkDebugMessage("wx",1," --> Destructing bbtk top window"<<std::endl);
149 mgTopWindow->Close();
152 DestroyWxAppIfNeeded();
155 //=========================================================================
157 //=========================================================================
158 void Wx::LoopUntilAllWindowsClose()
161 while (mgTopWindow != 0)
165 bbtkDebugMessage("wx",2,"Wx::Loop "<<i << std::endl);
172 //=========================================================================
174 //=========================================================================
175 wxWindow* Wx::GetTopWindow()
177 Wx::CreateTopWindowIfNeeded();
180 //=========================================================================
182 //=========================================================================
183 bool Wx::TopWindowExists()
185 return (mgTopWindow!=0);
187 //=========================================================================
190 //=========================================================================
191 void Wx::AddSignalObserver(Slot_function_type f)
193 mgWxSignal.connect(f);
195 //=========================================================================
198 //=========================================================================
199 void Wx::SetAutoDestroyTopWindow(bool b)
201 mgAutoDestroyTopWindow = b;
203 //=========================================================================
205 //=========================================================================
206 void Wx::SetTopWindow(wxWindow* w)
210 bbtkGlobalError("wx::SetTopWindow : top window already set !");
214 //=========================================================================
217 //=========================================================================
218 void Wx::IncNbWindowsAlive()
221 bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
227 //=========================================================================
229 //=========================================================================
230 void Wx::DecNbWindowsAlive()
233 bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
236 DestroyTopWindowIfNeeded();
241 //=========================================================================
243 //=========================================================================
244 void Wx::IncNbWindowsShown()
247 bbtkDebugMessage("wx",2,"* Number of windows shown = "<<mgNbWindowsShown
253 //=========================================================================
255 //=========================================================================
256 void Wx::DecNbWindowsShown()
259 bbtkDebugMessage("wx",2,"* Number of windows shown = "<<mgNbWindowsShown
262 DestroyTopWindowIfNeeded();
268 //=========================================================================
271 //=========================================================================
272 int Wx::GetNbWindowsAlive()
274 return mgNbWindowsAlive;
276 //=========================================================================
278 //=========================================================================
279 bool Wx::IsSomeWindowAlive()
281 return (mgNbWindowsAlive>0);
283 //=========================================================================
286 //=========================================================================
287 int Wx::GetNbWindowsShown()
289 return mgNbWindowsShown;
291 //=========================================================================
293 //=========================================================================
294 bool Wx::IsSomeWindowShown()
296 return (mgNbWindowsShown>0);
298 //=========================================================================
301 //=========================================================================
302 Wx::BusyCursor::BusyCursor()
305 if (TopWindowExists())
307 bbtkDebugMessage("wx",2,
308 "Wx::BusyCursor::BusyCursor()"<<std::endl);
309 mCursor = new wxBusyCursor;
310 //::wxBeginBusyCursor();
313 Wx::BusyCursor::~BusyCursor()
315 if (mCursor) delete mCursor;
317 //=========================================================================
320 //=========================================================================
321 void Wx::ResetCursor()
323 if (!TopWindowExists()) return;
324 bbtkDebugMessage("wx",9,"Wx::ResetCursor()"<<std::endl);
325 while (wxIsBusy()) ::wxEndBusyCursor();
327 //=========================================================================
328 //=========================================================================
329 void Wx::BeginBusyCursor()
331 if (!TopWindowExists()) return;
332 bbtkDebugMessage("wx",9,"Wx::BeginBusyCursor()"<<std::endl);
333 ::wxBeginBusyCursor();
335 //=========================================================================
336 //=========================================================================
337 void Wx::EndBusyCursor()
339 if (!TopWindowExists()) return;
340 bbtkDebugMessage("wx",9,"Wx::EndBusyCursor()"<<std::endl);
343 //=========================================================================