]> Creatis software - bbtk.git/blob - kernel/src/bbtkWx.h
d3f3318f86bd3a854ad93d266d743ebb3320e20a
[bbtk.git] / kernel / src / bbtkWx.h
1 #ifndef __bbtkWx_h_INCLUDED__
2 #define __bbtkWx_h_INCLUDED__
3
4 //===========================================================================
5 // Wx headers
6 #ifdef _USE_WXWIDGETS_
7 // For compilers that support precompilation, includes "wx/wx.h".
8 #include "wx/wxprec.h"
9 #include <wx/datetime.h>
10
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
27 // define wxWindow
28 typedef void wxWindow;
29
30 #endif // EO _USE_WXWIDGETS_
31 //===========================================================================
32
33 //===========================================================================
34 #include "bbtkSystem.h"
35 //===========================================================================
36
37 //===========================================================================
38 // SIGNAL/SLOT MECHANISM 
39 // FOR bbtk WINDOWS CREATION/DESTRUCTION OBSERVATION 
40 // BBTKWXSIG
41 #include <boost/signal.hpp>
42 #include <boost/bind.hpp>
43 // \BBTKWXSIG
44 //===========================================================================
45
46 namespace bbtk
47 {
48
49   //==================================================================
50   /// Global wx handlers (cursor...)
51   
52 // BBTKWXSIG
53 #define bbtkAddWxSignalObserver(METHOD)         \
54   Wx::AddSignalObserver(boost::bind(&METHOD, this))
55 // \BBTKWXSIG
56
57   struct BBTK_EXPORT Wx
58   {     
59   public:
60     // BBTKWXSIG
61     typedef boost::signals::trackable SignalObserver;
62     typedef boost::signal<void ()>  Signal_type;
63     typedef Signal_type::slot_function_type Slot_function_type;
64     // \BBTKWXSIG
65
66     /*
67     static void ResetCursor();
68     static void BeginBusyCursor(); 
69     static void EndBusyCursor();
70     */
71
72     static void LoopUntilAllWindowsClose();
73
74     class BusyCursor
75     {
76     public:
77       BusyCursor();
78       ~BusyCursor();
79     };
80
81     static void SetTopWindowParent(wxWindow*);
82     static void SetAutoDestroyTopWindow(bool);
83
84     /// Returns the creation time parent of all bbtk windows 
85     /// (window can be reparented after creation)
86     static wxWindow* GetTopWindow();
87     static bool TopWindowExists();
88     
89     static void IncNbWindowsAlive();
90     static void DecNbWindowsAlive();
91     static int  GetNbWindowsAlive();
92     static bool IsSomeWindowAlive();
93     
94     static void IncNbWindowsShown();
95     static void DecNbWindowsShown();
96     static int  GetNbWindowsShown();
97     static bool IsSomeWindowShown();
98
99     // BBTKWXSIG
100     static void AddSignalObserver(Slot_function_type);
101     // \BBTKWXSIG
102
103   private:
104
105     static void CreateWxAppIfNeeded();
106     static void DestroyWxAppIfNeeded();
107
108     static void CreateTopWindowIfNeeded();
109     static void DestroyTopWindowIfNeeded();
110
111     /// Sets the creation time parent of all bbtk windows
112     static void SetTopWindow(wxWindow*);
113   }; // struct Wx
114   //==================================================================
115   
116
117
118
119 #ifdef _USE_WXWIDGETS_
120   //==================================================================
121   /// Conversion std::string to wxString 
122   inline wxString std2wx(const std::string& s){
123     wxString wx;
124     const char* my_string=s.c_str();
125     wxMBConvUTF8 *wxconv= new wxMBConvUTF8();
126     wx=wxString(wxconv->cMB2WC(my_string),wxConvUTF8);
127     delete wxconv;
128     // test if conversion works of not. In case it fails convert from Ascii
129     if(wx.length()==0)
130       wx=wxString(wxString::FromAscii(s.c_str()));
131     return wx;
132   }
133   //==================================================================
134
135   //==================================================================
136   /// Conversion wxString to std::string
137   inline std::string wx2std(const wxString& s){
138     std::string s2;
139     if(s.wxString::IsAscii()) {
140       s2=s.wxString::ToAscii();
141     } else {
142       const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(s);
143       const char *tmp_str = (const char*) tmp_buf;
144       s2=std::string(tmp_str, strlen(tmp_str));
145     }
146     return s2;
147   }
148   //==================================================================
149 #endif // EO _USE_WXWIDGETS
150
151   
152 } // namespace bbtk
153   
154
155 #endif // EO __bbtkWx_h_INCLUDED__