1 /*=========================================================================
3 Module: $RCSfile: bbtkWx.h,v $
5 Date: $Date: 2010/01/14 13:17:27 $
6 Version: $Revision: 1.12 $
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 #ifndef __bbtkWx_h_INCLUDED__
33 #define __bbtkWx_h_INCLUDED__
35 //===========================================================================
38 // For compilers that support precompilation, includes "wx/wx.h".
39 #include "wx/wxprec.h"
40 #include <wx/datetime.h>
59 typedef void wxWindow;
60 typedef void wxBusyCursor;
62 #endif // EO USE_WXWIDGETS
63 //===========================================================================
65 //===========================================================================
66 #include "bbtkSystem.h"
67 //===========================================================================
69 //===========================================================================
70 // SIGNAL/SLOT MECHANISM
71 // FOR bbtk WINDOWS CREATION/DESTRUCTION OBSERVATION
73 #include <boost/signal.hpp>
74 #include <boost/bind.hpp>
76 //===========================================================================
81 //==================================================================
82 /// Global wx handlers (cursor...)
85 #define bbtkAddWxSignalObserver(METHOD) \
86 Wx::AddSignalObserver(boost::bind(&METHOD, this))
89 #define BBTK_BUSY_CURSOR bbtk::Wx::BusyCursor __bbtk_dummy_busy_cursor;
95 typedef boost::signals::trackable SignalObserver;
96 typedef boost::signal<void ()> Signal_type;
97 typedef Signal_type::slot_function_type Slot_function_type;
105 wxBusyCursor* mCursor;
108 static void ProcessPendingEvents();
110 /// Sets the parent of all bbtk windows
111 static void SetTopWindow(wxWindow*);
112 /// Returns the parent of all bbtk windows
113 static wxWindow* GetTopWindow();
116 static void IncNbWindowsAlive();
117 static void DecNbWindowsAlive();
118 static int GetNbWindowsAlive();
119 static bool IsSomeWindowAlive();
122 static void AddSignalObserver(Slot_function_type);
128 static void CreateWxAppIfNeeded();
129 static void DestroyWxAppIfNeeded();
132 //==================================================================
136 //==================================================================
137 /// Conversion std::string to wxString
138 inline wxString std2wx(const std::string& s){
140 const char* my_string=s.c_str();
141 wxMBConvUTF8 *wxconv= new wxMBConvUTF8();
142 wx=wxString(wxconv->cMB2WC(my_string),wxConvUTF8);
144 // test if conversion works of not. In case it fails convert from Ascii
146 wx=wxString(wxString::FromAscii(s.c_str()));
149 //==================================================================
151 //==================================================================
152 /// Conversion wxString to std::string
153 inline std::string wx2std(const wxString& s){
155 if(s.wxString::IsAscii()) {
156 s2=s.wxString::ToAscii();
158 const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(s);
159 const char *tmp_str = (const char*) tmp_buf;
160 s2=std::string(tmp_str, strlen(tmp_str));
164 //==================================================================
165 #endif // EO _USE_WXWIDGETS
171 #endif // EO __bbtkWx_h_INCLUDED__