1 #ifndef __bbtkWx_h_INCLUDED__
2 #define __bbtkWx_h_INCLUDED__
4 //===========================================================================
7 // For compilers that support precompilation, includes "wx/wx.h".
9 #include <wx/datetime.h>
25 #else //_USE_WXWIDGETS_
28 typedef void wxWindow;
30 #endif // EO _USE_WXWIDGETS_
31 //===========================================================================
33 //===========================================================================
34 #include "bbtkSystem.h"
35 //===========================================================================
37 //===========================================================================
38 // SIGNAL/SLOT MECHANISM
39 // FOR bbtk WINDOWS CREATION/DESTRUCTION OBSERVATION
41 #include <boost/signal.hpp>
42 #include <boost/bind.hpp>
44 //===========================================================================
49 //==================================================================
50 /// Global wx handlers (cursor...)
53 #define bbtkAddWxSignalObserver(METHOD) \
54 Wx::AddSignalObserver(boost::bind(&METHOD, this))
61 typedef boost::signals::trackable SignalObserver;
62 typedef boost::signal<void ()> Signal_type;
63 typedef Signal_type::slot_function_type Slot_function_type;
67 static void ResetCursor();
68 static void BeginBusyCursor();
69 static void EndBusyCursor();
72 static void LoopUntilAllWindowsClose();
81 static void SetTopWindowParent(wxWindow*);
82 static void SetAutoDestroyTopWindow(bool);
84 /// Returns the creation time parent of all bbtk windows
85 /// (window can be reparented after creation)
86 static wxWindow* GetTopWindow();
87 static bool TopWindowExists();
89 static void IncNbWindowsAlive();
90 static void DecNbWindowsAlive();
91 static int GetNbWindowsAlive();
92 static bool IsSomeWindowAlive();
94 static void IncNbWindowsShown();
95 static void DecNbWindowsShown();
96 static int GetNbWindowsShown();
97 static bool IsSomeWindowShown();
100 static void AddSignalObserver(Slot_function_type);
105 static void CreateWxAppIfNeeded();
106 static void DestroyWxAppIfNeeded();
108 static void CreateTopWindowIfNeeded();
109 static void DestroyTopWindowIfNeeded();
111 /// Sets the creation time parent of all bbtk windows
112 static void SetTopWindow(wxWindow*);
114 //==================================================================
119 #ifdef _USE_WXWIDGETS_
120 //==================================================================
121 /// Conversion std::string to wxString
122 inline wxString std2wx(const std::string& s){
124 const char* my_string=s.c_str();
125 wxMBConvUTF8 *wxconv= new wxMBConvUTF8();
126 wx=wxString(wxconv->cMB2WC(my_string),wxConvUTF8);
128 // test if conversion works of not. In case it fails convert from Ascii
130 wx=wxString(wxString::FromAscii(s.c_str()));
133 //==================================================================
135 //==================================================================
136 /// Conversion wxString to std::string
137 inline std::string wx2std(const wxString& s){
139 if(s.wxString::IsAscii()) {
140 s2=s.wxString::ToAscii();
142 const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(s);
143 const char *tmp_str = (const char*) tmp_buf;
144 s2=std::string(tmp_str, strlen(tmp_str));
148 //==================================================================
149 #endif // EO _USE_WXWIDGETS
155 #endif // EO __bbtkWx_h_INCLUDED__