]> Creatis software - bbtk.git/blob - kernel/src/bbtkWx.h
30c86f8ab7335c3a02ea5fcc1efa72217e322edb
[bbtk.git] / kernel / src / bbtkWx.h
1 #ifndef __bbtkWx_h_INCLUDED__
2 #define __bbtkWx_h_INCLUDED__
3
4
5 /*
6 #ifdef wxUSE_STD_IOSTREAM
7 #undef wxUSE_STD_IOSTREAM
8 #endif
9 #define wxUSE_STD_IOSTREAM 0
10 */
11
12 // Wx headers
13 #ifdef _USE_WXWIDGETS_
14 // For compilers that support precompilation, includes "wx/wx.h".
15 #include "wx/wxprec.h"
16 #include <wx/datetime.h>
17
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include <wx/wx.h>
25 #endif
26
27 #ifdef __WXGTK__
28 # include <locale.h>
29 #endif //__WXGTK__
30 // EO Wx headers
31
32 #include "bbtkSystem.h"
33
34 // SIGNAL/SLOT MECHANISM 
35 // FOR bbtk WINDOWS CREATION/DESTRUCTION OBSERVATION 
36 // BBTKWXSIG
37 #include <boost/signal.hpp>
38 #include <boost/bind.hpp>
39 // \BBTKWXSIG
40
41 namespace bbtk
42 {
43   //==================================================================
44   /// Global wx handlers (cursor...)
45   
46 // BBTKWXSIG
47 #define bbtkAddWxSignalObserver(METHOD)         \
48   Wx::AddSignalObserver(boost::bind(&METHOD, this))
49 // \BBTKWXSIG
50
51   struct BBTK_EXPORT Wx
52   {     
53   public:
54     // BBTKWXSIG
55     typedef boost::signals::trackable SignalObserver;
56     typedef boost::signal<void ()>  Signal_type;
57     typedef Signal_type::slot_function_type Slot_function_type;
58     // \BBTKWXSIG
59
60     static void ResetCursor();
61     static void BeginBusyCursor(); 
62     static void EndBusyCursor();
63
64     static void CreateTopWindow(wxWindow* parent=0, bool autodestroy=true);
65     /// Returns the creation time parent of all bbtk windows 
66     /// (window can be reparented after creation)
67     static wxWindow* GetTopWindow();
68     static bool TopWindowExists();
69
70     static void AutoDestroyTopWindow(bool);
71     
72     static void IncNbWindowsAlive();
73     static void DecNbWindowsAlive();
74     static int  GetNbWindowsAlive();
75     static bool IsSomeWindowAlive();
76     
77     static void IncNbWindowsShown();
78     static void DecNbWindowsShown();
79     static int  GetNbWindowsShown();
80     static bool IsSomeWindowShown();
81
82     // BBTKWXSIG
83     static void AddSignalObserver(Slot_function_type);
84     // \BBTKWXSIG
85   private:
86     /// Sets the creation time parent of all bbtk windows
87     static void SetTopWindow(wxWindow*);
88   }; // struct Wx
89   //==================================================================
90   
91
92
93   //==================================================================
94   /// Conversion std::string to wxString 
95   inline wxString std2wx(const std::string& s){
96     wxString wx;
97     const char* my_string=s.c_str();
98     wxMBConvUTF8 *wxconv= new wxMBConvUTF8();
99     wx=wxString(wxconv->cMB2WC(my_string),wxConvUTF8);
100     delete wxconv;
101     // test if conversion works of not. In case it fails convert from Ascii
102     if(wx.length()==0)
103       wx=wxString(wxString::FromAscii(s.c_str()));
104     return wx;
105   }
106   //==================================================================
107
108   //==================================================================
109   /// Conversion wxString to std::string
110   inline std::string wx2std(const wxString& s){
111     std::string s2;
112     if(s.wxString::IsAscii()) {
113       s2=s.wxString::ToAscii();
114     } else {
115       const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(s);
116       const char *tmp_str = (const char*) tmp_buf;
117       s2=std::string(tmp_str, strlen(tmp_str));
118     }
119     return s2;
120   }
121   //==================================================================
122
123
124   
125 } // namespace bbtk
126   
127
128
129 #else // _USE_WXWIDGETS
130
131
132 namespace bbtk
133 {
134
135   struct BBTK_EXPORT Wx
136   {
137     static void ResetCursor() {}
138     static void BeginBusyCursor() {}
139     static void EndBusyCursor() {}
140     static void CreateInvisibleTopWindow() {}
141     static wxWindow* GetTopWindow() { return 0; }
142     static void SetTopWindow(wxWindow*) {}
143     static void IncNbWindowsAlive() {}
144     static void DecNbWindowsAlive() {}
145     static int  GetNbWindowsAlive() { return 0; }
146     static bool IsSomeWindowAlive() { return false; }
147     
148     static void IncNbWindowsShown() {}
149     static void DecNbWindowsShown() {}
150     static int  GetNbWindowsShown() { return 0; }
151     static bool IsSomeWindowShown() { return false; }
152   }; // struct Wx
153
154 } // namespace bbtk
155   
156
157
158 #endif // EO _USE_WXWIDGETS
159 #endif // EO __bbtkWx_h_INCLUDED__