]> Creatis software - crea.git/blob - src/creaWx.h
re-indent
[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 #ifdef __BORLANDC__
13 #pragma hdrstop
14 #endif
15
16 #ifndef WX_PRECOMP
17 #include <wx/wx.h>
18 #endif
19
20 #ifdef __WXGTK__
21 # include <locale.h>
22 #endif //__WXGTK__
23 // EO Wx headers
24 //===========================================================================
25 #else // USE_WXWIDGETS
26 // define wxWindow as void hence wxWindow* are void*
27 typedef void wxWindow;
28 #endif // EO USE_WXWIDGETS
29 //===========================================================================
30
31 //===========================================================================
32 #ifdef USE_WXWIDGETS
33
34 #if defined(_WIN32) 
35
36 //  How to have a Console and wxWidgets
37 //  http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
38 //   In Visual C++ 6 (7 should be similar), to create an application that is both a console application 
39 //  (cout's to the console are visible) and has a wxWidgets GUI, 
40 //  you need to use the linker option "/subsystem:console" and the following code:
41
42 #define CREA_WXMAIN_WITH_CONSOLE                                        \
43   int main(int argc, char* argv[])                                      \
44   {                                                                     \
45     return WinMain(::GetModuleHandle(NULL), NULL,                       \
46                    ::GetCommandLine(), SW_SHOWNORMAL);                  \
47   }                                                                     
48
49 #else // defined(_WIN32) 
50
51 #define CREA_WXMAIN_WITH_CONSOLE
52
53 #endif // defined(_WIN32) 
54
55 #include <string>
56
57 namespace crea
58 {
59   //==================================================================
60   /// Conversion std::string to wxString 
61   inline wxString std2wx(const std::string& s) {
62     wxString wx;
63     const char* my_string=s.c_str();
64     wxMBConvUTF8 *wxconv= new wxMBConvUTF8();
65     wx=wxString(wxconv->cMB2WC(my_string),wxConvUTF8);
66     delete wxconv;
67     // test if conversion works of not. In case it fails convert from Ascii
68     if(wx.length()==0)
69       wx=wxString(wxString::FromAscii(s.c_str()));
70     return wx;
71   }
72   //==================================================================
73
74   //==================================================================
75   /// Conversion wxString to std::string
76   inline std::string wx2std(const wxString& s){
77     std::string s2;
78     if(s.wxString::IsAscii()) {
79       s2=s.wxString::ToAscii();
80     } else {
81       const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(s);
82       const char *tmp_str = (const char*) tmp_buf;
83       s2=std::string(tmp_str, strlen(tmp_str));
84     }
85     return s2;
86   }
87   //==================================================================
88 }
89
90 #endif // EO USE_WXWIDGETS
91
92 #endif