]> Creatis software - bbtk.git/blob - kernel/src/bbtkWx.h
bbtk now depends on crea !
[bbtk.git] / kernel / src / bbtkWx.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWx.h,v $
4   Language:  C++
5   Date:      $Date: 2008/12/11 15:30:04 $
6   Version:   $Revision: 1.9 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31
32 /* ---------------------------------------------------------------------
33
34 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
35 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
36 *
37 *  This software is governed by the CeCILL-B license under French law and 
38 *  abiding by the rules of distribution of free software. You can  use, 
39 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
40 *  license as circulated by CEA, CNRS and INRIA at the following URL 
41 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
42 *  or in the file LICENSE.txt.
43 *
44 *  As a counterpart to the access to the source code and  rights to copy,
45 *  modify and redistribute granted by the license, users are provided only
46 *  with a limited warranty  and the software's author,  the holder of the
47 *  economic rights,  and the successive licensors  have only  limited
48 *  liability. 
49 *
50 *  The fact that you are presently reading this means that you have had
51 *  knowledge of the CeCILL-B license and that you accept its terms.
52 * ------------------------------------------------------------------------ */                                                                         
53
54
55 #ifndef __bbtkWx_h_INCLUDED__
56 #define __bbtkWx_h_INCLUDED__
57
58 //===========================================================================
59 // Wx headers
60 #ifdef USE_WXWIDGETS
61 // For compilers that support precompilation, includes "wx/wx.h".
62 #include "wx/wxprec.h"
63 #include <wx/datetime.h>
64
65
66 #ifdef __BORLANDC__
67 #pragma hdrstop
68 #endif
69
70 #ifndef WX_PRECOMP
71 #include <wx/wx.h>
72 #endif
73
74 #ifdef __WXGTK__
75 # include <locale.h>
76 #endif //__WXGTK__
77 // EO Wx headers
78
79 #else //USE_WXWIDGETS
80
81 // define wxWindow
82 typedef void wxWindow;
83
84 #endif // EO USE_WXWIDGETS
85 //===========================================================================
86
87 //===========================================================================
88 #include "bbtkSystem.h"
89 //===========================================================================
90
91 //===========================================================================
92 // SIGNAL/SLOT MECHANISM 
93 // FOR bbtk WINDOWS CREATION/DESTRUCTION OBSERVATION 
94 // BBTKWXSIG
95 #include <boost/signal.hpp>
96 #include <boost/bind.hpp>
97 // \BBTKWXSIG
98 //===========================================================================
99
100 namespace bbtk
101 {
102
103   //==================================================================
104   /// Global wx handlers (cursor...)
105   
106 // BBTKWXSIG
107 #define bbtkAddWxSignalObserver(METHOD)         \
108   Wx::AddSignalObserver(boost::bind(&METHOD, this))
109 // \BBTKWXSIG
110
111 #define BBTK_BUSY_CURSOR bbtk::Wx::BusyCursor __bbtk_dummy_busy_cursor;
112
113   struct BBTK_EXPORT Wx
114   {     
115   public:
116     // BBTKWXSIG
117     typedef boost::signals::trackable SignalObserver;
118     typedef boost::signal<void ()>  Signal_type;
119     typedef Signal_type::slot_function_type Slot_function_type;
120     // \BBTKWXSIG
121
122     /*
123     static void ResetCursor();
124     static void BeginBusyCursor(); 
125     static void EndBusyCursor();
126     */
127
128     static void LoopUntilAllWindowsClose();
129
130     class BusyCursor
131     {
132     public:
133       BusyCursor();
134       ~BusyCursor();
135       wxBusyCursor* mCursor;
136     };
137
138     static void SetTopWindowParent(wxWindow*);
139     static void SetAutoDestroyTopWindow(bool);
140
141     /// Returns the creation time parent of all bbtk windows 
142     /// (window can be reparented after creation)
143     static wxWindow* GetTopWindow();
144     static bool TopWindowExists();
145     
146     static void IncNbWindowsAlive();
147     static void DecNbWindowsAlive();
148     static int  GetNbWindowsAlive();
149     static bool IsSomeWindowAlive();
150     
151     static void IncNbWindowsShown();
152     static void DecNbWindowsShown();
153     static int  GetNbWindowsShown();
154     static bool IsSomeWindowShown();
155
156     // BBTKWXSIG
157     static void AddSignalObserver(Slot_function_type);
158     // \BBTKWXSIG
159
160   private:
161
162     static void CreateWxAppIfNeeded();
163     static void DestroyWxAppIfNeeded();
164
165     static void CreateTopWindowIfNeeded();
166     static void DestroyTopWindowIfNeeded();
167
168     /// Sets the creation time parent of all bbtk windows
169     static void SetTopWindow(wxWindow*);
170   }; // struct Wx
171   //==================================================================
172   
173
174
175
176 #ifdef USE_WXWIDGETS
177   //==================================================================
178   /// Conversion std::string to wxString 
179   inline wxString std2wx(const std::string& s){
180     wxString wx;
181     const char* my_string=s.c_str();
182     wxMBConvUTF8 *wxconv= new wxMBConvUTF8();
183     wx=wxString(wxconv->cMB2WC(my_string),wxConvUTF8);
184     delete wxconv;
185     // test if conversion works of not. In case it fails convert from Ascii
186     if(wx.length()==0)
187       wx=wxString(wxString::FromAscii(s.c_str()));
188     return wx;
189   }
190   //==================================================================
191
192   //==================================================================
193   /// Conversion wxString to std::string
194   inline std::string wx2std(const wxString& s){
195     std::string s2;
196     if(s.wxString::IsAscii()) {
197       s2=s.wxString::ToAscii();
198     } else {
199       const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(s);
200       const char *tmp_str = (const char*) tmp_buf;
201       s2=std::string(tmp_str, strlen(tmp_str));
202     }
203     return s2;
204   }
205   //==================================================================
206 #endif // EO _USE_WXWIDGETS
207
208   
209 } // namespace bbtk
210   
211
212 #endif // EO __bbtkWx_h_INCLUDED__