2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkWx.h,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.13 $
34 =========================================================================*/
39 #ifndef __bbtkWx_h_INCLUDED__
40 #define __bbtkWx_h_INCLUDED__
42 //===========================================================================
45 // For compilers that support precompilation, includes "wx/wx.h".
46 #include "wx/wxprec.h"
47 #include <wx/datetime.h>
66 typedef void wxWindow;
67 typedef void wxBusyCursor;
69 #endif // EO USE_WXWIDGETS
70 //===========================================================================
72 //===========================================================================
73 #include "bbtkSystem.h"
74 //===========================================================================
76 //===========================================================================
77 // SIGNAL/SLOT MECHANISM
78 // FOR bbtk WINDOWS CREATION/DESTRUCTION OBSERVATION
80 #include <boost/signal.hpp>
81 #include <boost/bind.hpp>
83 //===========================================================================
88 //==================================================================
89 /// Global wx handlers (cursor...)
92 #define bbtkAddWxSignalObserver(METHOD) \
93 Wx::AddSignalObserver(boost::bind(&METHOD, this))
96 #define BBTK_BUSY_CURSOR bbtk::Wx::BusyCursor __bbtk_dummy_busy_cursor;
102 typedef boost::signals::trackable SignalObserver;
103 typedef boost::signal<void ()> Signal_type;
104 typedef Signal_type::slot_function_type Slot_function_type;
112 wxBusyCursor* mCursor;
115 static void ProcessPendingEvents();
117 /// Sets the parent of all bbtk windows
118 static void SetTopWindow(wxWindow*);
119 /// Returns the parent of all bbtk windows
120 static wxWindow* GetTopWindow();
123 static void IncNbWindowsAlive();
124 static void DecNbWindowsAlive();
125 static int GetNbWindowsAlive();
126 static bool IsSomeWindowAlive();
129 static void AddSignalObserver(Slot_function_type);
135 static void CreateWxAppIfNeeded();
136 static void DestroyWxAppIfNeeded();
139 //==================================================================
143 //==================================================================
144 /// Conversion std::string to wxString
145 inline wxString std2wx(const std::string& s){
147 const char* my_string=s.c_str();
148 wxMBConvUTF8 *wxconv= new wxMBConvUTF8();
149 wx=wxString(wxconv->cMB2WC(my_string),wxConvUTF8);
151 // test if conversion works of not. In case it fails convert from Ascii
153 wx=wxString(wxString::FromAscii(s.c_str()));
156 //==================================================================
158 //==================================================================
159 /// Conversion wxString to std::string
160 inline std::string wx2std(const wxString& s){
162 if(s.wxString::IsAscii()) {
163 s2=s.wxString::ToAscii();
165 const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(s);
166 const char *tmp_str = (const char*) tmp_buf;
167 s2=std::string(tmp_str, strlen(tmp_str));
171 //==================================================================
172 #endif // EO _USE_WXWIDGETS
178 #endif // EO __bbtkWx_h_INCLUDED__