]> Creatis software - bbtk.git/blob - kernel/src/bbtkWt.cxx
2498 BBTK Feature New Normal wt-version kernel
[bbtk.git] / kernel / src / bbtkWt.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
25  terms.
26  # ------------------------------------------------------------------------ */
27
28
29 /*=========================================================================
30   Program:   bbtk
31   Module:    $RCSfile: bbtkQt.cxx,v $
32   Language:  C++
33   Date:      $Date: 2012/11/16 08:49:01 $
34   Version:   $Revision: 1.4 $
35 =========================================================================*/
36
37
38 #include "bbtkWt.h"
39 #include "bbtkMessageManager.h"
40
41 #ifdef USE_WT
42
43
44
45
46 namespace bbtk
47 {
48   //=========================================================================
49   class WtApp;
50   Wt::WApplication *createApplication(const Wt::WEnvironment& env);
51   //=========================================================================
52
53   //=========================================================================
54   static WtApp* mgWtApp = 0;
55   static Wt::WContainerWidget* mgTopWindow = 0;
56   static int mgNbWindowsAlive  = 0;
57   //=========================================================================
58   
59   //=========================================================================
60   // BBTKWXSIG
61   static WWt::Signal_type mgWtSignal;
62   // \BBTKWXSIG
63   //=========================================================================
64
65  
66   //=========================================================================
67   // The wxApp class which is used when no user wxApp was created
68  // The application creates itself completly empty.
69 // The default values for the port and address are port:8080 address 0.0.0.0
70   class WtApp : public Wt::WApplication
71   {
72   public:
73     WtApp(const Wt::WEnvironment& env);
74     ~WtApp();
75     static int WtWRun();
76                 //WtWApplication *createApplication(const WtWEnvironment& env);
77     
78   };
79
80         WtApp::WtApp(const Wt::WEnvironment& env):
81                 Wt::WApplication(env)
82         {
83                 //root()->addWidget(WWt::GetTopWindow());
84                 // There is not additional configuration. The new WtApp must have the same behavior that one Wt::WApplication.
85                 
86         }
87
88         WtApp::~WtApp()
89         {
90
91         }
92 /*
93         int WtApp::WtWRun()
94         {
95                 char  *argv[7] =  {"./WtTest","--docroot",".","--http-address","0.0.0.0","--http-port","8080"};
96                 int argc = 7;
97                 return Wt::WRun(argc,argv,&createApplication);  
98         }
99
100
101         Wt::WApplication *createApplication(const Wt::WEnvironment& env)
102         {
103                 return new WtApp(env);
104         }
105 */
106
107
108
109   //=========================================================================
110
111   //=========================================================================
112   void WWt::CreateWtAppIfNeeded()
113   {
114                 std::cout<<"CREATING APP IF NEEDED --------- DELETE ME ------- bbtkWt.cxx"<<std::endl;
115                 if(Wt::WApplication::instance()==0)
116                 {
117                         if (mgWtApp != 0) 
118                 {
119                 bbtkGlobalError("Wt::CreateWtAppIfNeeded() : INTERNAL ERROR ! (Wt::WApplication::instance()==0) && (mgWtApp != 0)");
120                         }
121                         bbtkDebugMessage("wt",1,"  --> Creating bbtk WtApp"<<std::endl);  
122                         //WtApp::WtWRun();
123                 }               
124                 bbtkDebugMessage("process",2,"Create WtApp If needed debuging");
125   }
126   //=========================================================================
127
128   //=========================================================================
129   void WWt::DestroyWtAppIfNeeded()
130   {
131     if (mgWtApp!= 0) 
132       {
133         //      bbtkDebugMessage("wx",1,"  --> Destructing bbtk WxApp"<<std::endl);
134         //delete mgWxApp;
135         //      mgWxApp = 0;
136         // Uninit wx
137         //      wxUninitialize();
138       }
139   }
140   //=========================================================================
141
142
143   //=========================================================================
144   void WWt::ProcessPendingEvents()
145   {
146     /*
147     if (Wx::GetTopWindow() != 0)
148       {
149         Wx::GetTopWindow()->DestroyChildren();
150       }
151     */
152
153     /*
154     wxApp* a = (wxApp*)wxApp::GetInstance();
155     if (a==0) return;
156     
157     std::cout << "$$$$$$$$$$$$$$ PROCESS PENDING "<<std::endl;
158     while (a->Pending())
159       a->Dispatch();
160     std::cout << "$$$$$$$$$$$$$$ PROCESS PENDING DONE"<<std::endl;
161     */
162   }
163
164
165   //=========================================================================
166   Wt::WContainerWidget* WWt::GetTopWindow() 
167   { 
168     return mgTopWindow; 
169   }
170   //=========================================================================
171   
172
173   // BBTKWXSIG
174   //=========================================================================
175   void WWt::AddSignalObserver(Slot_function_type f)
176   {
177     mgWtSignal.connect(f);
178   }
179   //=========================================================================
180   // \BBTKWXSIG
181
182   
183   //=========================================================================
184   void WWt::SetTopWindow(Wt::WContainerWidget* w) 
185   {
186     if ( mgTopWindow ) 
187       {
188         bbtkGlobalError("Wt::SetTopWindow : top window already set !");
189       } 
190     //mgTopWindow = w;
191   }
192   //=========================================================================
193
194
195   //=========================================================================
196   void WWt::IncNbWindowsAlive() 
197   { 
198     mgNbWindowsAlive++; 
199     bbtkDebugMessage("wt",2,"* Number of windows alive = "<<mgNbWindowsAlive
200                      <<std::endl);
201     // BBTKWXSIG
202     mgWtSignal();
203     // \BBTKWXSIG
204   }
205   //=========================================================================
206
207   //=========================================================================
208   void WWt::DecNbWindowsAlive()
209   { 
210     mgNbWindowsAlive--; 
211     bbtkDebugMessage("wt",2,"* Number of windows alive = "<<mgNbWindowsAlive
212                      <<std::endl);
213
214     // BBTKWXSIG
215     mgWtSignal();
216     // \BBTKWXSIG
217   }
218   //=========================================================================
219
220   //=========================================================================
221   int  WWt::GetNbWindowsAlive() 
222   { 
223     return mgNbWindowsAlive; 
224   }
225   //=========================================================================
226   
227   //=========================================================================
228   bool WWt::IsSomeWindowAlive() 
229   { 
230     return (mgNbWindowsAlive!=0);
231   }
232   //=========================================================================
233   
234
235   //=========================================================================
236   WWt::BusyCursor::BusyCursor()
237   {
238    // mCursor = 0;
239     if (Wt::WApplication::instance()!=0) 
240       {         
241         bbtkDebugMessage("wt",2,
242                          "Wt::BusyCursor::BusyCursor() : creating new cursor"
243                          <<std::endl);
244         //mCursor = new wxBusyCursor; 
245     }
246   }
247   //=========================================================================
248   //=========================================================================
249   WWt::BusyCursor::~BusyCursor()
250   {
251    // if (mCursor)
252      // { 
253         //delete mCursor;
254         //bbtkDebugMessage("wt",2,
255         //               "Wt::BusyCursor::~BusyCursor() : deleting cursor"<<std::endl);
256       //}
257   }
258   //=========================================================================
259
260
261
262 } // namespace bbtk
263
264 #else
265 //=======================================================================
266 // WITHOUT WX
267 //=========================================================================
268 namespace bbtk
269 {
270    //=========================================================================
271   WWt::BusyCursor::BusyCursor()
272   {
273   }
274   WWt::BusyCursor::~BusyCursor()
275   {
276   }
277   //=========================================================================
278
279 } // namespace bbtk
280 #endif
281
282