]> Creatis software - crea.git/blob - src/creaWx.h
Feature #1763
[crea.git] / src / creaWx.h
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 #
8 #  This software is governed by the CeCILL-B license under French law and 
9 #  abiding by the rules of distribution of free software. You can  use, 
10 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
11 #  license as circulated by CEA, CNRS and INRIA at the following URL 
12 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
13 #  or in the file LICENSE.txt.
14 #
15 #  As a counterpart to the access to the source code and  rights to copy,
16 #  modify and redistribute granted by the license, users are provided only
17 #  with a limited warranty  and the software's author,  the holder of the
18 #  economic rights,  and the successive licensors  have only  limited
19 #  liability. 
20 #
21 #  The fact that you are presently reading this means that you have had
22 #  knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------ */                                                                         
24
25
26 #ifndef __creaWx_h__INCLUDED__
27 #define __creaWx_h__INCLUDED__
28
29 //===========================================================================
30 // Wx headers
31 #ifdef USE_WXWIDGETS
32 // For compilers that support precompilation, includes "wx/wx.h".
33 #include "wx/wxprec.h"
34 #include <wx/datetime.h>
35
36 #ifdef __BORLANDC__
37 #pragma hdrstop
38 #endif
39
40 #ifndef WX_PRECOMP
41 #include <wx/wx.h>
42 #endif
43
44 #ifdef __WXGTK__
45 # include <locale.h>
46 #endif //__WXGTK__
47 // EO Wx headers
48 //===========================================================================
49 #else // USE_WXWIDGETS
50 // define wxWindow as void hence wxWindow* are void*
51 typedef void wxWindow;
52 #endif // EO USE_WXWIDGETS
53 //===========================================================================
54
55 //===========================================================================
56 #ifdef USE_WXWIDGETS
57
58 #if defined(_WIN32) 
59
60 //  How to have a Console and wxWidgets
61 //  http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
62 //   In Visual C++ 6 (7 should be similar), to create an application that is both a console application 
63 //  (cout's to the console are visible) and has a wxWidgets GUI, 
64 //  you need to use the linker option "/subsystem:console" and the following code:
65
66 #define CREA_WXMAIN_WITH_CONSOLE                                        \
67   int main(int argc, char* argv[])                                      \
68   {                                                                     \
69     return WinMain(::GetModuleHandle(NULL), NULL,                       \
70                    ::GetCommandLine(), SW_SHOWNORMAL);                  \
71   }                                                                     
72
73 #else // defined(_WIN32) 
74
75 #define CREA_WXMAIN_WITH_CONSOLE
76
77 #endif // defined(_WIN32) 
78
79 #include <string>
80
81 namespace crea
82 {
83   //==================================================================
84   /// Conversion std::string to wxString 
85   inline wxString std2wx(const std::string& s) {
86     wxString wx;
87     const char* my_string=s.c_str();
88     wxMBConvUTF8 *wxconv= new wxMBConvUTF8();
89     wx=wxString(wxconv->cMB2WC(my_string),wxConvUTF8);
90     delete wxconv;
91     // test if conversion works of not. In case it fails convert from Ascii
92     if(wx.length()==0)
93       wx=wxString(wxString::FromAscii(s.c_str()));
94     return wx;
95   }
96   //==================================================================
97
98   //==================================================================
99   /// Conversion wxString to std::string
100   inline std::string wx2std(const wxString& s){
101     std::string s2;
102     if(s.wxString::IsAscii()) {
103       s2=s.wxString::ToAscii();
104     } else {
105       const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(s);
106       const char *tmp_str = (const char*) tmp_buf;
107       s2=std::string(tmp_str, strlen(tmp_str));
108     }
109     return s2;
110   }
111   //==================================================================
112 }
113
114 #endif // EO USE_WXWIDGETS
115
116 #endif