1 /*=========================================================================
3 Module: $RCSfile: bbtkWx.h,v $
5 Date: $Date: 2008/10/17 08:18:14 $
6 Version: $Revision: 1.8 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
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.
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
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 * ------------------------------------------------------------------------ */
32 /* ---------------------------------------------------------------------
34 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
35 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
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.
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
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 * ------------------------------------------------------------------------ */
55 #ifndef __bbtkWx_h_INCLUDED__
56 #define __bbtkWx_h_INCLUDED__
58 //===========================================================================
60 #ifdef _USE_WXWIDGETS_
61 // For compilers that support precompilation, includes "wx/wx.h".
62 #include "wx/wxprec.h"
63 #include <wx/datetime.h>
79 #else //_USE_WXWIDGETS_
82 typedef void wxWindow;
84 #endif // EO _USE_WXWIDGETS_
85 //===========================================================================
87 //===========================================================================
88 #include "bbtkSystem.h"
89 //===========================================================================
91 //===========================================================================
92 // SIGNAL/SLOT MECHANISM
93 // FOR bbtk WINDOWS CREATION/DESTRUCTION OBSERVATION
95 #include <boost/signal.hpp>
96 #include <boost/bind.hpp>
98 //===========================================================================
103 //==================================================================
104 /// Global wx handlers (cursor...)
107 #define bbtkAddWxSignalObserver(METHOD) \
108 Wx::AddSignalObserver(boost::bind(&METHOD, this))
111 #define BBTK_BUSY_CURSOR bbtk::Wx::BusyCursor __bbtk_dummy_busy_cursor;
113 struct BBTK_EXPORT Wx
117 typedef boost::signals::trackable SignalObserver;
118 typedef boost::signal<void ()> Signal_type;
119 typedef Signal_type::slot_function_type Slot_function_type;
123 static void ResetCursor();
124 static void BeginBusyCursor();
125 static void EndBusyCursor();
128 static void LoopUntilAllWindowsClose();
135 wxBusyCursor* mCursor;
138 static void SetTopWindowParent(wxWindow*);
139 static void SetAutoDestroyTopWindow(bool);
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();
146 static void IncNbWindowsAlive();
147 static void DecNbWindowsAlive();
148 static int GetNbWindowsAlive();
149 static bool IsSomeWindowAlive();
151 static void IncNbWindowsShown();
152 static void DecNbWindowsShown();
153 static int GetNbWindowsShown();
154 static bool IsSomeWindowShown();
157 static void AddSignalObserver(Slot_function_type);
162 static void CreateWxAppIfNeeded();
163 static void DestroyWxAppIfNeeded();
165 static void CreateTopWindowIfNeeded();
166 static void DestroyTopWindowIfNeeded();
168 /// Sets the creation time parent of all bbtk windows
169 static void SetTopWindow(wxWindow*);
171 //==================================================================
176 #ifdef _USE_WXWIDGETS_
177 //==================================================================
178 /// Conversion std::string to wxString
179 inline wxString std2wx(const std::string& s){
181 const char* my_string=s.c_str();
182 wxMBConvUTF8 *wxconv= new wxMBConvUTF8();
183 wx=wxString(wxconv->cMB2WC(my_string),wxConvUTF8);
185 // test if conversion works of not. In case it fails convert from Ascii
187 wx=wxString(wxString::FromAscii(s.c_str()));
190 //==================================================================
192 //==================================================================
193 /// Conversion wxString to std::string
194 inline std::string wx2std(const wxString& s){
196 if(s.wxString::IsAscii()) {
197 s2=s.wxString::ToAscii();
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));
205 //==================================================================
206 #endif // EO _USE_WXWIDGETS
212 #endif // EO __bbtkWx_h_INCLUDED__