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