]> Creatis software - bbtk.git/blob - kernel/src/bbtkWx.h
a27aae1e88a87b5f3439313b68db913facb5d193
[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 namespace bbtk
35 {
36   //==================================================================
37   /// Global wx handlers (cursor...)
38   
39   struct BBTK_EXPORT Wx
40   {     
41   public:
42     static void ResetCursor();
43     static void BeginBusyCursor(); 
44     static void EndBusyCursor();
45     static int mBeginBusyCallsCount;
46
47     /// Returns the global parent of all bbtk windows
48     static wxWindow* GetTopWindow() { return mgTopWindow; }
49     /// Sets the global parent of all bbtk windows
50     static void SetTopWindow(wxWindow*);
51     
52     static void IncNbWindowsAlive() { mgNbWindowsAlive++; }
53     static void DecNbWindowsAlive();
54     static int  GetNbWindowsAlive() { return mgNbWindowsAlive; }
55     static bool IsSomeWindowAlive() { return (mgNbWindowsAlive>0);}
56     
57     static void IncNbWindowsShown() { mgNbWindowsShown++; }
58     static void DecNbWindowsShown();
59     static int  GetNbWindowsShown() { return mgNbWindowsShown; }
60     static bool IsSomeWindowShown() { return (mgNbWindowsShown>0);}
61     
62   private:
63     static wxWindow* mgTopWindow;
64     static int mgNbWindowsAlive;
65     static int mgNbWindowsShown;
66
67   }; // struct Wx
68   //==================================================================
69   
70   
71   //==================================================================
72   /// Conversion std::string to wxString 
73   inline wxString std2wx(const std::string& s){
74     wxString wx;
75     const char* my_string=s.c_str();
76     wxMBConvUTF8 *wxconv= new wxMBConvUTF8();
77     wx=wxString(wxconv->cMB2WC(my_string),wxConvUTF8);
78     delete wxconv;
79     // test if conversion works of not. In case it fails convert from Ascii
80     if(wx.length()==0)
81       wx=wxString(wxString::FromAscii(s.c_str()));
82     return wx;
83   }
84   //==================================================================
85
86   //==================================================================
87   /// Conversion wxString to std::string
88   inline std::string wx2std(const wxString& s){
89     std::string s2;
90     if(s.wxString::IsAscii()) {
91       s2=s.wxString::ToAscii();
92     } else {
93       const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(s);
94       const char *tmp_str = (const char*) tmp_buf;
95       s2=std::string(tmp_str, strlen(tmp_str));
96     }
97     return s2;
98   }
99   //==================================================================
100
101
102   
103 } // namespace bbtk
104   
105
106
107 #else // _USE_WXWIDGETS
108
109
110 namespace bbtk
111 {
112
113   struct BBTK_EXPORT Wx
114   {
115     static void ResetCursor() {}
116     static void BeginBusyCursor() {}
117     static void EndBusyCursor() {}
118     static wxWindow* GetTopWindow() { return 0; }
119     static void SetTopWindow(wxWindow*) {}
120     static void IncNbWindowsAlive() {}
121     static void DecNbWindowsAlive() {}
122     static int  GetNbWindowsAlive() { return 0; }
123     static bool IsSomeWindowAlive() { return false; }
124     
125     static void IncNbWindowsShown() {}
126     static void DecNbWindowsShown() {}
127     static int  GetNbWindowsShown() { return 0; }
128     static bool IsSomeWindowShown() { return false; }
129   }; // struct Wx
130
131 } // namespace bbtk
132   
133
134
135 #endif // EO _USE_WXWIDGETS
136 #endif // EO __bbtkWx_h_INCLUDED__