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