]> Creatis software - bbtk.git/blob - kernel/src/bbtkWt.h
#249 8BBTK Feature New Normal - wt-version kernel
[bbtk.git] / kernel / src / bbtkWt.h
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: bbtkQt.h,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:49:01 $
33   Version:   $Revision: 1.3 $
34 =========================================================================*/
35
36
37
38 #ifndef __bbtkWt_h_INCLUDED__
39 #define __bbtkWt_h_INCLUDED__
40
41 //===========================================================================
42 // SIGNAL/SLOT MECHANISM 
43 // FOR bbtk WINDOWS CREATION/DESTRUCTION OBSERVATION 
44 // BBTKWXSIG
45 #include <boost/signal.hpp>
46 #include <boost/bind.hpp>
47
48 //typedef boost::signals::trackable SignalObserver;
49 // \BBTKWXSIG
50 //===========================================================================
51
52
53 //===========================================================================
54 // Wt headers
55 // DEFINIR LOS HEADERS Wt que se necesitan  *-*-*-*-*-*-*-*-*-*
56 #ifdef USE_WT
57
58 //TODO Include libs in the CMake escription
59 #include <Wt/WApplication>
60 #include <Wt/WEnvironment>
61 #include <Wt/WContainerWidget>
62 #include <Wt/WWidget>
63 #include <Wt/WCheckBox>
64 #include <Wt/WServer>
65 #include <Wt/WText>
66 #include <Wt/WPushButton>
67 #include <Wt/WSlider>
68 #include <Wt/WHBoxLayout>
69 #include <Wt/WVBoxLayout>
70 #include <Wt/WBorderLayout>
71 #include <Wt/WLineEdit>
72 #include <Wt/WComboBox>
73 #include <Wt/WSelectionBox>
74 #include <Wt/WGroupBox>
75 #include <Wt/WRadioButton>
76 #include <Wt/WButtonGroup>
77 #include <Wt/WLayout>
78 #include <Wt/WHBoxLayout>
79 #include <Wt/WVBoxLayout>
80 #include <Wt/WRadioButton>
81 #include <Wt/Ext/Splitter>
82 #include <Wt/WTabWidget>
83 #include <Wt/WFileUpload>
84 #include <Wt/WLength>
85
86
87 #else //USE_WT
88
89 #endif // EO USE_WT
90
91
92
93
94 #ifdef USE_WT
95
96
97 // Definition of some classes used in tehe code
98 typedef Wt::WEnvironment WtWEnvironment;
99 typedef Wt::WWidget WtWWidget;
100 //typedef Wt::WContainerWidget WtWContainerWidget;
101 typedef Wt::WApplication WtWApplication;
102 typedef Wt::WString WtWString;
103
104
105
106 #else // EO_USE_WT
107
108
109 typedef void WtWidget;
110 typedef void WtWContainerWidget;
111 typedef void WtWApplication;
112 typedef void WtBusyCursor;
113
114 #endif // EO USE_WT
115
116
117 //==========================================================================
118
119 //===========================================================================
120 #include "bbtkSystem.h"
121 //===========================================================================
122
123
124
125
126
127 namespace bbtk
128 {
129
130   //==================================================================
131   /// Global wt handlers (cursor...)
132
133
134 // BBTKWXSIG BBTK_ADD_BLACK_BOX_TO_PACKAGE(MyProjectWT,Testing)
135
136 #define bbtkAddWtSignalObserver(METHOD)         \
137   WWt::AddSignalObserver(boost::bind(&METHOD, this))
138 // \BBTKWXSIG
139
140 #define BBTK_BUSY_CURSOR bbtk::WWt::BusyCursor __bbtk_dummy_busy_cursor;
141
142   struct BBTK_EXPORT WWt
143   {     
144   public:
145     // BBTKWXSIG
146     // The keyword 'signals' is also a macro in qt
147     //    typedef boost::signals::trackable SignalObserver;
148     typedef boost::signals::trackable SignalObserver;
149     typedef boost::signal<void ()>  Signal_type;
150     typedef Signal_type::slot_function_type Slot_function_type;
151     // \BBTKWXSIG
152                 
153     /*
154     static void ResetCursor();
155     static void BeginBusyCursor(); 
156     static void EndBusyCursor();
157     */
158
159     static void LoopUntilAllWindowsClose();
160
161     class BusyCursor
162     {
163     public:
164       BusyCursor();
165       ~BusyCursor();
166       //wxBusyCursor* mCursor; The wxBusyCursor is only for comunicate to the client/user that the program is busy. 
167     };
168
169
170     static void ProcessPendingEvents();
171
172 #ifdef USE_WT
173     /// Sets the parent of all bbtk windows
174     static void SetTopWindow(Wt::WContainerWidget*);
175     /// Returns the parent of all bbtk windows 
176     static Wt::WContainerWidget* GetTopWindow();
177 #endif // EO USE_WT
178
179     
180     static void IncNbWindowsAlive();
181     static void DecNbWindowsAlive();
182     static int  GetNbWindowsAlive();
183     static bool IsSomeWindowAlive();
184     
185
186     // BBTKWXSIG
187     static void AddSignalObserver(Slot_function_type);
188     // \BBTKWXSIG
189
190
191
192
193   //private:
194     static void CreateWtAppIfNeeded();
195     static void DestroyWtAppIfNeeded();
196
197   }; // struct Wt
198   //==================================================================
199   
200 #ifdef USE_WT
201
202
203         static std::string jScript;
204   //==================================================================
205   /// Conversion std::string to wxString 
206   inline Wt::WString std2wt(const std::string& s)
207   {
208   //  Wt::WString wt;
209 /*
210     const char* my_string=s.c_str();
211     wxMBConvUTF8 *wxconv= new wxMBConvUTF8();
212     wx=wxString(wxconv->cMB2WC(my_string),wxConvUTF8);
213     delete wxconv;
214     // test if conversion works of not. In case it fails convert from Ascii
215     if(wx.length()==0)
216       wx=wxString(wxString::FromAscii(s.c_str()));
217 */      
218     return Wt::WString::fromUTF8(s,false);
219     //return new Wt::WString(s);//wt;
220   }
221   //==================================================================
222
223   //==================================================================
224   /// Conversion wxString to std::string
225   inline  std::string wt2std(const Wt::WString& s){
226    /* std::string s2;
227     if(s.wxString::IsAscii()) {
228       s2=s.wxString::ToAscii();
229     } else {
230       const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(s);
231       const char *tmp_str = (const char*) tmp_buf;
232       s2=std::string(tmp_str, strlen(tmp_str));
233     }
234
235     return s2;*/
236         return s.toUTF8();
237   }
238   //==================================================================
239 #endif // EO _USE_WXWIDGETS
240
241
242
243
244   
245 } // namespace bbtk
246   
247
248 #endif // EO __bbtkWt_h_INCLUDED__