]> Creatis software - bbtk.git/blob - kernel/src/bbtkWx.cxx
Feature #1774
[bbtk.git] / kernel / src / bbtkWx.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbtkWx.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:49:01 $
33   Version:   $Revision: 1.17 $
34 =========================================================================*/
35
36
37
38 #include "bbtkWx.h"
39 #include "bbtkMessageManager.h"
40
41 #ifdef _USE_WXWIDGETS_
42
43 namespace bbtk
44 {
45   //=========================================================================
46   class WxApp;
47   //=========================================================================
48
49   //=========================================================================
50   static WxApp* mgWxApp = 0;
51   static wxWindow* mgTopWindow = 0;
52   static int mgNbWindowsAlive  = 0;
53   //=========================================================================
54   
55   //=========================================================================
56   // BBTKWXSIG
57   static Wx::Signal_type mgWxSignal;
58   // \BBTKWXSIG
59   //=========================================================================
60
61  
62   //=========================================================================
63   // The wxApp class which is used when no user wxApp was created
64   class WxApp : public wxApp
65   {
66   public:
67     bool OnInit( );
68     int  OnExit() { return true; }
69   };
70   //=========================================================================
71   IMPLEMENT_APP_NO_MAIN(WxApp);
72   //=========================================================================
73   bool WxApp::OnInit( )
74   {      
75     wxApp::OnInit();
76 #ifdef __WXGTK__
77     //See http://www.wxwindows.org/faqgtk.htm#locale
78     setlocale(LC_NUMERIC, "C");
79 #endif
80     return true;
81   }
82   //=========================================================================
83
84   //=========================================================================
85   void Wx::CreateWxAppIfNeeded()
86   {
87     if (wxApp::GetInstance()==0)
88       {
89         if (mgWxApp != 0) 
90           {
91             bbtkGlobalError("Wx::CreateWxAppIfNeeded() : INTERNAL ERROR ! (wxApp::GetInstance()==0) && (mgWxApp != 0)");
92           }
93         bbtkDebugMessage("wx",1,"  --> Creating bbtk wxApp"<<std::endl);
94         mgWxApp = new WxApp;
95         wxApp::SetInstance(mgWxApp);
96         wxInitialize();
97       } 
98   }
99   //=========================================================================
100
101   //=========================================================================
102   void Wx::DestroyWxAppIfNeeded()
103   {
104     if (mgWxApp!= 0) 
105       {
106         //      bbtkDebugMessage("wx",1,"  --> Destructing bbtk WxApp"<<std::endl);
107         //delete mgWxApp;
108         //      mgWxApp = 0;
109         // Uninit wx
110         //      wxUninitialize();
111       }
112   }
113   //=========================================================================
114
115
116   //=========================================================================
117   void Wx::ProcessPendingEvents()
118   {
119     /*
120     if (Wx::GetTopWindow() != 0)
121       {
122         Wx::GetTopWindow()->DestroyChildren();
123       }
124     */
125
126     /*
127     wxApp* a = (wxApp*)wxApp::GetInstance();
128     if (a==0) return;
129     
130     std::cout << "$$$$$$$$$$$$$$ PROCESS PENDING "<<std::endl;
131     while (a->Pending())
132       a->Dispatch();
133     std::cout << "$$$$$$$$$$$$$$ PROCESS PENDING DONE"<<std::endl;
134     */
135   }
136
137
138   //=========================================================================
139   wxWindow* Wx::GetTopWindow() 
140   { 
141     return mgTopWindow; 
142   }
143   //=========================================================================
144   
145
146   // BBTKWXSIG
147   //=========================================================================
148   void Wx::AddSignalObserver(Slot_function_type f)
149   {
150     mgWxSignal.connect(f);
151   }
152   //=========================================================================
153   // \BBTKWXSIG
154
155   
156   //=========================================================================
157   void Wx::SetTopWindow(wxWindow* w) 
158   {
159     if ( mgTopWindow ) 
160       {
161         bbtkGlobalError("Wx::SetTopWindow : top window already set !");
162       } 
163     //mgTopWindow = w;
164   }
165   //=========================================================================
166
167
168   //=========================================================================
169   void Wx::IncNbWindowsAlive() 
170   { 
171     mgNbWindowsAlive++; 
172     bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
173                      <<std::endl);
174     // BBTKWXSIG
175     mgWxSignal();
176     // \BBTKWXSIG
177   }
178   //=========================================================================
179
180   //=========================================================================
181   void Wx::DecNbWindowsAlive()
182   { 
183     mgNbWindowsAlive--; 
184     bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
185                      <<std::endl);
186
187     // BBTKWXSIG
188     mgWxSignal();
189     // \BBTKWXSIG
190   }
191   //=========================================================================
192
193   //=========================================================================
194   int  Wx::GetNbWindowsAlive() 
195   { 
196     return mgNbWindowsAlive; 
197   }
198   //=========================================================================
199   
200   //=========================================================================
201   bool Wx::IsSomeWindowAlive() 
202   { 
203     return (mgNbWindowsAlive!=0);
204   }
205   //=========================================================================
206   
207
208   //=========================================================================
209   Wx::BusyCursor::BusyCursor()
210   {
211     mCursor = 0;
212     if (wxApp::GetInstance()!=0) 
213       {         
214         bbtkDebugMessage("wx",2,
215                          "Wx::BusyCursor::BusyCursor() : creating new cursor"
216                          <<std::endl);
217         //mCursor = new wxBusyCursor; 
218     }
219   }
220   //=========================================================================
221   //=========================================================================
222   Wx::BusyCursor::~BusyCursor()
223   {
224     if (mCursor)
225       { 
226         //delete mCursor;
227         bbtkDebugMessage("wx",2,
228                          "Wx::BusyCursor::~BusyCursor() : deleting cursor"<<std::endl);
229       }
230   }
231   //=========================================================================
232
233
234
235 } // namespace bbtk
236
237 #else
238 //=======================================================================
239 // WITHOUT WX
240 //=========================================================================
241 namespace bbtk
242 {
243    //=========================================================================
244   Wx::BusyCursor::BusyCursor()
245   {
246   }
247   Wx::BusyCursor::~BusyCursor()
248   {
249   }
250   //=========================================================================
251
252 } // namespace bbtk
253 #endif
254