]> Creatis software - bbtk.git/blob - kernel/src/bbtkWx.cxx
#3472 merge vtk8itk5wx3-mingw64
[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         std::cout<<"Testing OnINIT Wx ---- JFGA !!!DELETE ME!!! bbtkWx"<<std::endl;      
76     wxApp::OnInit();
77 #ifdef __WXGTK__
78     //See http://www.wxwindows.org/faqgtk.htm#locale
79     setlocale(LC_NUMERIC, "C");
80 #endif
81     return true;
82   }
83   //=========================================================================
84
85   //=========================================================================
86   void Wx::CreateWxAppIfNeeded()
87   {
88
89                 std::cout<<"Testing CreateWxAppIfNeeded --- DELETE ME ----"<<std::endl;
90     if (wxApp::GetInstance()==0)
91       {
92         if (mgWxApp != 0) 
93           {
94             bbtkGlobalError("Wx::CreateWxAppIfNeeded() : INTERNAL ERROR ! (wxApp::GetInstance()==0) && (mgWxApp != 0)");
95           }
96         bbtkDebugMessage("wx",1,"  --> Creating bbtk wxApp"<<std::endl);
97         mgWxApp = new WxApp;
98         wxApp::SetInstance(mgWxApp);
99         wxInitialize();
100       } 
101   }
102   //=========================================================================
103
104   //=========================================================================
105   void Wx::DestroyWxAppIfNeeded()
106   {
107     if (mgWxApp!= 0) 
108       {
109           
110 printf("EED Wx::DestroyWxAppIfNeeded \n");
111           
112           
113         //      bbtkDebugMessage("wx",1,"  --> Destructing bbtk WxApp"<<std::endl);
114         //delete mgWxApp;
115         //      mgWxApp = 0;
116         // Uninit wx
117         //      wxUninitialize();
118       }
119   }
120   //=========================================================================
121
122
123   //=========================================================================
124   void Wx::ProcessPendingEvents()
125   {
126     /*
127     if (Wx::GetTopWindow() != 0)
128       {
129         Wx::GetTopWindow()->DestroyChildren();
130       }
131     */
132
133     /*
134     wxApp* a = (wxApp*)wxApp::GetInstance();
135     if (a==0) return;
136     
137     std::cout << "$$$$$$$$$$$$$$ PROCESS PENDING "<<std::endl;
138     while (a->Pending())
139       a->Dispatch();
140     std::cout << "$$$$$$$$$$$$$$ PROCESS PENDING DONE"<<std::endl;
141     */
142   }
143
144
145   //=========================================================================
146   wxWindow* Wx::GetTopWindow() 
147   { 
148     return mgTopWindow; 
149   }
150   //=========================================================================
151   
152
153   // BBTKWXSIG
154   //=========================================================================
155   void Wx::AddSignalObserver(Slot_function_type f)
156   {
157     mgWxSignal.connect(f);
158   }
159   //=========================================================================
160   // \BBTKWXSIG
161
162   
163   //=========================================================================
164   void Wx::SetTopWindow(wxWindow* w) 
165   {
166     if ( mgTopWindow ) 
167       {
168         bbtkGlobalError("Wx::SetTopWindow : top window already set !");
169       } 
170     //mgTopWindow = w;
171   }
172   //=========================================================================
173
174
175   //=========================================================================
176   void Wx::IncNbWindowsAlive() 
177   { 
178     mgNbWindowsAlive++; 
179     bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
180                      <<std::endl);
181     // BBTKWXSIG
182     mgWxSignal();
183     // \BBTKWXSIG
184   }
185   //=========================================================================
186
187   //=========================================================================
188   void Wx::DecNbWindowsAlive()
189   { 
190     mgNbWindowsAlive--; 
191     bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
192                      <<std::endl);
193
194     // BBTKWXSIG
195     mgWxSignal();
196     // \BBTKWXSIG
197   }
198   //=========================================================================
199
200   //=========================================================================
201   int  Wx::GetNbWindowsAlive() 
202   { 
203     return mgNbWindowsAlive; 
204   }
205   //=========================================================================
206   
207   //=========================================================================
208   bool Wx::IsSomeWindowAlive() 
209   { 
210     return (mgNbWindowsAlive!=0);
211   }
212   //=========================================================================
213   
214
215   //=========================================================================
216   Wx::BusyCursor::BusyCursor()
217   {
218     mCursor = 0;
219     if (wxApp::GetInstance()!=0) 
220       {         
221         bbtkDebugMessage("wx",2,
222                          "Wx::BusyCursor::BusyCursor() : creating new cursor"
223                          <<std::endl);
224         //mCursor = new wxBusyCursor; 
225     }
226   }
227   //=========================================================================
228   //=========================================================================
229   Wx::BusyCursor::~BusyCursor()
230   {
231     if (mCursor)
232       { 
233         //delete mCursor;
234         bbtkDebugMessage("wx",2,
235                          "Wx::BusyCursor::~BusyCursor() : deleting cursor"<<std::endl);
236       }
237   }
238   //=========================================================================
239
240
241
242 } // namespace bbtk
243
244 #else
245 //=======================================================================
246 // WITHOUT WX
247 //=========================================================================
248 namespace bbtk
249 {
250    //=========================================================================
251   Wx::BusyCursor::BusyCursor()
252   {
253   }
254   Wx::BusyCursor::~BusyCursor()
255   {
256   }
257   //=========================================================================
258
259 } // namespace bbtk
260 #endif
261