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