]> Creatis software - crea.git/blob - src/creaWx.h
Initial revision
[crea.git] / src / creaWx.h
1
2 #ifndef __creaWx_h__INCLUDED__
3 #define __creaWx_h__INCLUDED__
4
5 //===========================================================================
6 // Wx headers
7 #ifdef USE_WXWIDGETS
8 // For compilers that support precompilation, includes "wx/wx.h".
9 #include "wx/wxprec.h"
10 #include <wx/datetime.h>
11
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 #ifndef WX_PRECOMP
18 #include <wx/wx.h>
19 #endif
20
21 #ifdef __WXGTK__
22 # include <locale.h>
23 #endif //__WXGTK__
24 // EO Wx headers
25 //===========================================================================
26 #else // USE_WXWIDGETS
27 // define wxWindow as void hence wxWindow* are void*
28 typedef void wxWindow;
29 #endif // EO USE_WXWIDGETS
30 //===========================================================================
31
32
33
34
35
36
37 //===========================================================================
38 #ifdef USE_WXWIDGETS
39
40 namespace crea
41 {
42   //==================================================================
43   /// Conversion std::string to wxString 
44   inline wxString std2wx(const std::string& s){
45     wxString wx;
46     const char* my_string=s.c_str();
47     wxMBConvUTF8 *wxconv= new wxMBConvUTF8();
48     wx=wxString(wxconv->cMB2WC(my_string),wxConvUTF8);
49     delete wxconv;
50     // test if conversion works of not. In case it fails convert from Ascii
51     if(wx.length()==0)
52       wx=wxString(wxString::FromAscii(s.c_str()));
53     return wx;
54   }
55   //==================================================================
56   
57   //==================================================================
58   /// Conversion wxString to std::string
59   inline std::string wx2std(const wxString& s){
60     std::string s2;
61     if(s.wxString::IsAscii()) {
62       s2=s.wxString::ToAscii();
63     } else {
64       const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(s);
65       const char *tmp_str = (const char*) tmp_buf;
66       s2=std::string(tmp_str, strlen(tmp_str));
67     }
68     return s2;
69   }
70   //==================================================================
71   
72
73 }
74
75 #endif // EO USE_WXWIDGETS
76
77 #endif