]> Creatis software - crea.git/blob - src/creaWx.h
Automatic Desallocation added so we will desallocates this object when we its pointer...
[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 #define CREA_WXMAIN_WITH_CONSOLE                                        \
50   int main(int argc, char* argv[])                                      \
51   {                                                                     \
52     return WinMain(::GetModuleHandle(NULL), NULL,                       \
53                    ::GetCommandLine(), SW_SHOWNORMAL);                  \
54   }                                                                     
55
56 #else // defined(_WIN32) 
57
58 #define CREA_WXMAIN_WITH_CONSOLE
59
60 #endif // defined(_WIN32) 
61
62
63 #include <string>
64
65
66 namespace crea
67 {
68   //==================================================================
69   /// Conversion std::string to wxString 
70   inline wxString std2wx(const std::string& s) {
71     wxString wx;
72     const char* my_string=s.c_str();
73     wxMBConvUTF8 *wxconv= new wxMBConvUTF8();
74     wx=wxString(wxconv->cMB2WC(my_string),wxConvUTF8);
75     delete wxconv;
76     // test if conversion works of not. In case it fails convert from Ascii
77     if(wx.length()==0)
78       wx=wxString(wxString::FromAscii(s.c_str()));
79     return wx;
80   }
81   //==================================================================
82   
83   //==================================================================
84   /// Conversion wxString to std::string
85   inline std::string wx2std(const wxString& s){
86     std::string s2;
87     if(s.wxString::IsAscii()) {
88       s2=s.wxString::ToAscii();
89     } else {
90       const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(s);
91       const char *tmp_str = (const char*) tmp_buf;
92       s2=std::string(tmp_str, strlen(tmp_str));
93     }
94     return s2;
95   }
96   //==================================================================
97   
98
99 }
100
101 #endif // EO USE_WXWIDGETS
102
103 #endif