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