]> Creatis software - crea.git/blob - src/creaWx.h
29fb0619f09ec2c72aafe29335bd9f42a5a95eaa
[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
41
42 #if defined(_WIN32) 
43 //  How to have a Console and wxWidgets
44 //  http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
45 //   In Visual C++ 6 (7 should be similar), to create an application that is both a console application 
46 //  (cout's to the console are visible) and has a wxWidgets GUI, 
47 //  you need to use the linker option "/subsystem:console" and the following code:
48 #define CREA_WXMAIN_WITH_CONSOLE                                        \
49   int main(int argc, char* argv[])                                      \
50   {                                                                     \
51     return WinMain(::GetModuleHandle(NULL), NULL,                       \
52                    ::GetCommandLine(), SW_SHOWNORMAL);                  \
53   }                                                                     
54 #else // defined(_WIN32) 
55 #define CREA_WXMAIN_WITH_CONSOLE
56 #endif // defined(_WIN32) 
57
58
59
60
61 namespace crea
62 {
63   //==================================================================
64   /// Conversion std::string to wxString 
65   inline wxString std2wx(const std::string& s){
66     wxString wx;
67     const char* my_string=s.c_str();
68     wxMBConvUTF8 *wxconv= new wxMBConvUTF8();
69     wx=wxString(wxconv->cMB2WC(my_string),wxConvUTF8);
70     delete wxconv;
71     // test if conversion works of not. In case it fails convert from Ascii
72     if(wx.length()==0)
73       wx=wxString(wxString::FromAscii(s.c_str()));
74     return wx;
75   }
76   //==================================================================
77   
78   //==================================================================
79   /// Conversion wxString to std::string
80   inline std::string wx2std(const wxString& s){
81     std::string s2;
82     if(s.wxString::IsAscii()) {
83       s2=s.wxString::ToAscii();
84     } else {
85       const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(s);
86       const char *tmp_str = (const char*) tmp_buf;
87       s2=std::string(tmp_str, strlen(tmp_str));
88     }
89     return s2;
90   }
91   //==================================================================
92   
93
94 }
95
96 #endif // EO USE_WXWIDGETS
97
98 #endif