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