]> Creatis software - bbtk.git/blob - kernel/src/bbtkWx.cxx
9a144705b4f2aa5ab0fe1ccba7c94398aeb93712
[bbtk.git] / kernel / src / bbtkWx.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWx.cxx,v $
4   Language:  C++
5   Date:      $Date: 2009/05/28 08:12:06 $
6   Version:   $Revision: 1.15 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
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.
20 *
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
25 *  liability. 
26 *
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 * ------------------------------------------------------------------------ */                                                                         
30 #include "bbtkWx.h"
31 #include "bbtkMessageManager.h"
32
33 #ifdef _USE_WXWIDGETS_
34
35 namespace bbtk
36 {
37   //=========================================================================
38   class WxApp;
39   //=========================================================================
40
41   //=========================================================================
42   static WxApp* mgWxApp = 0;
43   static wxWindow* mgTopWindow = 0;
44   static int mgNbWindowsAlive  = 0;
45   //=========================================================================
46   
47   //=========================================================================
48   // BBTKWXSIG
49   static Wx::Signal_type mgWxSignal;
50   // \BBTKWXSIG
51   //=========================================================================
52
53  
54   //=========================================================================
55   // The wxApp class which is used when no user wxApp was created
56   class WxApp : public wxApp
57   {
58   public:
59     bool OnInit( );
60     int  OnExit() { return true; }
61   };
62   //=========================================================================
63   IMPLEMENT_APP_NO_MAIN(WxApp);
64   //=========================================================================
65   bool WxApp::OnInit( )
66   {      
67     wxApp::OnInit();
68 #ifdef __WXGTK__
69     //See http://www.wxwindows.org/faqgtk.htm#locale
70     setlocale(LC_NUMERIC, "C");
71 #endif
72     return true;
73   }
74   //=========================================================================
75
76   //=========================================================================
77   void Wx::CreateWxAppIfNeeded()
78   {
79     if (wxApp::GetInstance()==0)
80       {
81         if (mgWxApp != 0) 
82           {
83             bbtkGlobalError("Wx::CreateWxAppIfNeeded() : INTERNAL ERROR ! (wxApp::GetInstance()==0) && (mgWxApp != 0)");
84           }
85         bbtkDebugMessage("wx",1,"  --> Creating bbtk wxApp"<<std::endl);
86         mgWxApp = new WxApp;
87         wxApp::SetInstance(mgWxApp);
88         wxInitialize();
89       } 
90   }
91   //=========================================================================
92
93   //=========================================================================
94   void Wx::DestroyWxAppIfNeeded()
95   {
96     if (mgWxApp!= 0) 
97       {
98         //      bbtkDebugMessage("wx",1,"  --> Destructing bbtk WxApp"<<std::endl);
99         //delete mgWxApp;
100         //      mgWxApp = 0;
101         // Uninit wx
102         //      wxUninitialize();
103       }
104   }
105   //=========================================================================
106
107
108   //=========================================================================
109   void Wx::ProcessPendingEvents()
110   {
111     /*
112     if (Wx::GetTopWindow() != 0)
113       {
114         Wx::GetTopWindow()->DestroyChildren();
115       }
116     */
117
118     /*
119     wxApp* a = (wxApp*)wxApp::GetInstance();
120     if (a==0) return;
121     
122     std::cout << "$$$$$$$$$$$$$$ PROCESS PENDING "<<std::endl;
123     while (a->Pending())
124       a->Dispatch();
125     std::cout << "$$$$$$$$$$$$$$ PROCESS PENDING DONE"<<std::endl;
126     */
127   }
128
129
130   //=========================================================================
131   wxWindow* Wx::GetTopWindow() 
132   { 
133     return mgTopWindow; 
134   }
135   //=========================================================================
136   
137
138   // BBTKWXSIG
139   //=========================================================================
140   void Wx::AddSignalObserver(Slot_function_type f)
141   {
142     mgWxSignal.connect(f);
143   }
144   //=========================================================================
145   // \BBTKWXSIG
146
147   
148   //=========================================================================
149   void Wx::SetTopWindow(wxWindow* w) 
150   {
151     if ( mgTopWindow ) 
152       {
153         bbtkGlobalError("Wx::SetTopWindow : top window already set !");
154       } 
155     //mgTopWindow = w;
156   }
157   //=========================================================================
158
159
160   //=========================================================================
161   void Wx::IncNbWindowsAlive() 
162   { 
163     mgNbWindowsAlive++; 
164     bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
165                      <<std::endl);
166     // BBTKWXSIG
167     mgWxSignal();
168     // \BBTKWXSIG
169   }
170   //=========================================================================
171
172   //=========================================================================
173   void Wx::DecNbWindowsAlive()
174   { 
175     mgNbWindowsAlive--; 
176     bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
177                      <<std::endl);
178
179     // BBTKWXSIG
180     mgWxSignal();
181     // \BBTKWXSIG
182   }
183   //=========================================================================
184
185   //=========================================================================
186   int  Wx::GetNbWindowsAlive() 
187   { 
188     return mgNbWindowsAlive; 
189   }
190   //=========================================================================
191   
192   //=========================================================================
193   bool Wx::IsSomeWindowAlive() 
194   { 
195     return (mgNbWindowsAlive!=0);
196   }
197   //=========================================================================
198   
199
200   //=========================================================================
201   Wx::BusyCursor::BusyCursor()
202   {
203     mCursor = 0;
204     if (wxApp::GetInstance()!=0) 
205       {         
206         bbtkDebugMessage("wx",2,
207                          "Wx::BusyCursor::BusyCursor() : creating new cursor"
208                          <<std::endl);
209         //mCursor = new wxBusyCursor; 
210     }
211   }
212   //=========================================================================
213   //=========================================================================
214   Wx::BusyCursor::~BusyCursor()
215   {
216     if (mCursor)
217       { 
218         //delete mCursor;
219         bbtkDebugMessage("wx",2,
220                          "Wx::BusyCursor::~BusyCursor() : deleting cursor"<<std::endl);
221       }
222   }
223   //=========================================================================
224
225
226
227 } // namespace bbtk
228
229 #else
230 //=======================================================================
231 // WITHOUT WX
232 //=========================================================================
233 namespace bbtk
234 {
235    //=========================================================================
236   Wx::BusyCursor::BusyCursor()
237   {
238   }
239   Wx::BusyCursor::~BusyCursor()
240   {
241   }
242   //=========================================================================
243
244 } // namespace bbtk
245 #endif
246