bbtkWx.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __bbtkWx_h_INCLUDED__
00033 #define __bbtkWx_h_INCLUDED__
00034
00035
00036
00037 #ifdef USE_WXWIDGETS
00038
00039 #include "wx/wxprec.h"
00040 #include <wx/datetime.h>
00041
00042
00043 #ifdef __BORLANDC__
00044 #pragma hdrstop
00045 #endif
00046
00047 #ifndef WX_PRECOMP
00048 #include <wx/wx.h>
00049 #endif
00050
00051 #ifdef __WXGTK__
00052 # include <locale.h>
00053 #endif //__WXGTK__
00054
00055
00056 #else //USE_WXWIDGETS
00057
00058
00059 typedef void wxWindow;
00060 typedef void wxBusyCursor;
00061
00062 #endif // EO USE_WXWIDGETS
00063
00064
00065
00066 #include "bbtkSystem.h"
00067
00068
00069
00070
00071
00072
00073 #include <boost/signal.hpp>
00074 #include <boost/bind.hpp>
00075
00076
00077
00078 namespace bbtk
00079 {
00080
00081
00083
00084
00085 #define bbtkAddWxSignalObserver(METHOD) \
00086 Wx::AddSignalObserver(boost::bind(&METHOD, this))
00087
00088
00089 #define BBTK_BUSY_CURSOR bbtk::Wx::BusyCursor __bbtk_dummy_busy_cursor;
00090
00091 struct BBTK_EXPORT Wx
00092 {
00093 public:
00094
00095 typedef boost::signals::trackable SignalObserver;
00096 typedef boost::signal<void ()> Signal_type;
00097 typedef Signal_type::slot_function_type Slot_function_type;
00098
00099
00100 class BusyCursor
00101 {
00102 public:
00103 BusyCursor();
00104 ~BusyCursor();
00105 wxBusyCursor* mCursor;
00106 };
00107
00108 static void ProcessPendingEvents();
00109
00111 static void SetTopWindow(wxWindow*);
00113 static wxWindow* GetTopWindow();
00114
00115
00116 static void IncNbWindowsAlive();
00117 static void DecNbWindowsAlive();
00118 static int GetNbWindowsAlive();
00119 static bool IsSomeWindowAlive();
00120
00121
00122 static void AddSignalObserver(Slot_function_type);
00123
00124
00125
00126 private:
00127
00128 static void CreateWxAppIfNeeded();
00129 static void DestroyWxAppIfNeeded();
00130
00131 };
00132
00133
00134
00135 #ifdef USE_WXWIDGETS
00136
00138 inline wxString std2wx(const std::string& s){
00139 wxString wx;
00140 const char* my_string=s.c_str();
00141 wxMBConvUTF8 *wxconv= new wxMBConvUTF8();
00142 wx=wxString(wxconv->cMB2WC(my_string),wxConvUTF8);
00143 delete wxconv;
00144
00145 if(wx.length()==0)
00146 wx=wxString(wxString::FromAscii(s.c_str()));
00147 return wx;
00148 }
00149
00150
00151
00153 inline std::string wx2std(const wxString& s){
00154 std::string s2;
00155 if(s.wxString::IsAscii()) {
00156 s2=s.wxString::ToAscii();
00157 } else {
00158 const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(s);
00159 const char *tmp_str = (const char*) tmp_buf;
00160 s2=std::string(tmp_str, strlen(tmp_str));
00161 }
00162 return s2;
00163 }
00164
00165 #endif // EO _USE_WXWIDGETS
00166
00167
00168 }
00169
00170
00171 #endif // EO __bbtkWx_h_INCLUDED__