1 /*=========================================================================
3 Module: $RCSfile: bbtkWx.h,v $
5 Date: $Date: 2009/05/28 08:12:06 $
6 Version: $Revision: 1.11 $
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 //===========================================================================
61 // For compilers that support precompilation, includes "wx/wx.h".
62 #include "wx/wxprec.h"
63 #include <wx/datetime.h>
82 typedef void wxWindow;
83 typedef void wxBusyCursor;
85 #endif // EO USE_WXWIDGETS
86 //===========================================================================
88 //===========================================================================
89 #include "bbtkSystem.h"
90 //===========================================================================
92 //===========================================================================
93 // SIGNAL/SLOT MECHANISM
94 // FOR bbtk WINDOWS CREATION/DESTRUCTION OBSERVATION
96 #include <boost/signal.hpp>
97 #include <boost/bind.hpp>
99 //===========================================================================
104 //==================================================================
105 /// Global wx handlers (cursor...)
108 #define bbtkAddWxSignalObserver(METHOD) \
109 Wx::AddSignalObserver(boost::bind(&METHOD, this))
112 #define BBTK_BUSY_CURSOR bbtk::Wx::BusyCursor __bbtk_dummy_busy_cursor;
114 struct BBTK_EXPORT Wx
118 typedef boost::signals::trackable SignalObserver;
119 typedef boost::signal<void ()> Signal_type;
120 typedef Signal_type::slot_function_type Slot_function_type;
128 wxBusyCursor* mCursor;
131 static void ProcessPendingEvents();
133 /// Sets the parent of all bbtk windows
134 static void SetTopWindow(wxWindow*);
135 /// Returns the parent of all bbtk windows
136 static wxWindow* GetTopWindow();
139 static void IncNbWindowsAlive();
140 static void DecNbWindowsAlive();
141 static int GetNbWindowsAlive();
142 static bool IsSomeWindowAlive();
145 static void AddSignalObserver(Slot_function_type);
151 static void CreateWxAppIfNeeded();
152 static void DestroyWxAppIfNeeded();
155 //==================================================================
161 //==================================================================
162 /// Conversion std::string to wxString
163 inline wxString std2wx(const std::string& s){
165 const char* my_string=s.c_str();
166 wxMBConvUTF8 *wxconv= new wxMBConvUTF8();
167 wx=wxString(wxconv->cMB2WC(my_string),wxConvUTF8);
169 // test if conversion works of not. In case it fails convert from Ascii
171 wx=wxString(wxString::FromAscii(s.c_str()));
174 //==================================================================
176 //==================================================================
177 /// Conversion wxString to std::string
178 inline std::string wx2std(const wxString& s){
180 if(s.wxString::IsAscii()) {
181 s2=s.wxString::ToAscii();
183 const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(s);
184 const char *tmp_str = (const char*) tmp_buf;
185 s2=std::string(tmp_str, strlen(tmp_str));
189 //==================================================================
190 #endif // EO _USE_WXWIDGETS
196 #endif // EO __bbtkWx_h_INCLUDED__