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