]> Creatis software - bbtk.git/blob - kernel/src/bbtkWx.cxx
78848c1cef825e7d66fad5a5c6da2cbc90a38712
[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         //      bbtkDebugMessage("wx",1,"  --> Destructing bbtk WxApp"<<std::endl);
110         //delete mgWxApp;
111         //      mgWxApp = 0;
112         // Uninit wx
113         //      wxUninitialize();
114       }
115   }
116   //=========================================================================
117
118
119   //=========================================================================
120   void Wx::ProcessPendingEvents()
121   {
122     /*
123     if (Wx::GetTopWindow() != 0)
124       {
125         Wx::GetTopWindow()->DestroyChildren();
126       }
127     */
128
129     /*
130     wxApp* a = (wxApp*)wxApp::GetInstance();
131     if (a==0) return;
132     
133     std::cout << "$$$$$$$$$$$$$$ PROCESS PENDING "<<std::endl;
134     while (a->Pending())
135       a->Dispatch();
136     std::cout << "$$$$$$$$$$$$$$ PROCESS PENDING DONE"<<std::endl;
137     */
138   }
139
140
141   //=========================================================================
142   wxWindow* Wx::GetTopWindow() 
143   { 
144     return mgTopWindow; 
145   }
146   //=========================================================================
147   
148
149   // BBTKWXSIG
150   //=========================================================================
151   void Wx::AddSignalObserver(Slot_function_type f)
152   {
153     mgWxSignal.connect(f);
154   }
155   //=========================================================================
156   // \BBTKWXSIG
157
158   
159   //=========================================================================
160   void Wx::SetTopWindow(wxWindow* w) 
161   {
162     if ( mgTopWindow ) 
163       {
164         bbtkGlobalError("Wx::SetTopWindow : top window already set !");
165       } 
166     //mgTopWindow = w;
167   }
168   //=========================================================================
169
170
171   //=========================================================================
172   void Wx::IncNbWindowsAlive() 
173   { 
174     mgNbWindowsAlive++; 
175     bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
176                      <<std::endl);
177     // BBTKWXSIG
178     mgWxSignal();
179     // \BBTKWXSIG
180   }
181   //=========================================================================
182
183   //=========================================================================
184   void Wx::DecNbWindowsAlive()
185   { 
186     mgNbWindowsAlive--; 
187     bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
188                      <<std::endl);
189
190     // BBTKWXSIG
191     mgWxSignal();
192     // \BBTKWXSIG
193   }
194   //=========================================================================
195
196   //=========================================================================
197   int  Wx::GetNbWindowsAlive() 
198   { 
199     return mgNbWindowsAlive; 
200   }
201   //=========================================================================
202   
203   //=========================================================================
204   bool Wx::IsSomeWindowAlive() 
205   { 
206     return (mgNbWindowsAlive!=0);
207   }
208   //=========================================================================
209   
210
211   //=========================================================================
212   Wx::BusyCursor::BusyCursor()
213   {
214     mCursor = 0;
215     if (wxApp::GetInstance()!=0) 
216       {         
217         bbtkDebugMessage("wx",2,
218                          "Wx::BusyCursor::BusyCursor() : creating new cursor"
219                          <<std::endl);
220         //mCursor = new wxBusyCursor; 
221     }
222   }
223   //=========================================================================
224   //=========================================================================
225   Wx::BusyCursor::~BusyCursor()
226   {
227     if (mCursor)
228       { 
229         //delete mCursor;
230         bbtkDebugMessage("wx",2,
231                          "Wx::BusyCursor::~BusyCursor() : deleting cursor"<<std::endl);
232       }
233   }
234   //=========================================================================
235
236
237
238 } // namespace bbtk
239
240 #else
241 //=======================================================================
242 // WITHOUT WX
243 //=========================================================================
244 namespace bbtk
245 {
246    //=========================================================================
247   Wx::BusyCursor::BusyCursor()
248   {
249   }
250   Wx::BusyCursor::~BusyCursor()
251   {
252   }
253   //=========================================================================
254
255 } // namespace bbtk
256 #endif
257