]>
Commit | Line | Data |
---|---|---|
32b8ec41 | 1 | ///////////////////////////////////////////////////////////////////////////// |
127eab18 | 2 | // Name: src/mgl/cursor.cpp |
32b8ec41 VZ |
3 | // Purpose: |
4 | // Author: Vaclav Slavik | |
5 | // Id: $Id$ | |
99ee04b9 | 6 | // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com) |
65571936 | 7 | // Licence: wxWindows licence |
32b8ec41 VZ |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
32b8ec41 VZ |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
13 | #ifdef __BORLANDC__ | |
14 | #pragma hdrstop | |
15 | #endif | |
16 | ||
17 | #include "wx/cursor.h" | |
99ee04b9 | 18 | #include "wx/module.h" |
32b8ec41 VZ |
19 | #include "wx/utils.h" |
20 | #include "wx/log.h" | |
21 | #include "wx/intl.h" | |
99ee04b9 | 22 | #include "wx/hashmap.h" |
32b8ec41 | 23 | |
ef344ff8 | 24 | #include "wx/mgl/private.h" |
32b8ec41 VZ |
25 | |
26 | ||
27 | //----------------------------------------------------------------------------- | |
28 | // wxCursor | |
29 | //----------------------------------------------------------------------------- | |
30 | ||
31 | class wxCursorRefData: public wxObjectRefData | |
32 | { | |
33 | public: | |
34 | ||
35 | wxCursorRefData(); | |
36 | ~wxCursorRefData(); | |
37 | ||
38 | MGLCursor *m_cursor; | |
39 | }; | |
40 | ||
41 | wxCursorRefData::wxCursorRefData() | |
42 | { | |
43 | m_cursor = (MGLCursor*) NULL; | |
44 | } | |
45 | ||
46 | wxCursorRefData::~wxCursorRefData() | |
47 | { | |
48 | delete m_cursor; | |
49 | } | |
50 | ||
99ee04b9 VS |
51 | #define M_CURSORDATA ((wxCursorRefData *)m_refData) |
52 | ||
32b8ec41 VZ |
53 | //----------------------------------------------------------------------------- |
54 | ||
dac7d53a | 55 | WX_DECLARE_HASH_MAP(int, wxCursor, wxIntegerHash, wxIntegerEqual, wxCursorsHash); |
99ee04b9 VS |
56 | |
57 | static wxCursorsHash *gs_cursorsHash = NULL; | |
32b8ec41 VZ |
58 | |
59 | IMPLEMENT_DYNAMIC_CLASS(wxCursor,wxObject) | |
60 | ||
61 | wxCursor::wxCursor() | |
62 | { | |
63 | } | |
64 | ||
65 | wxCursor::wxCursor(int cursorId) | |
66 | { | |
c41c20a5 VS |
67 | if ( !gs_cursorsHash ) |
68 | gs_cursorsHash = new wxCursorsHash; | |
69 | ||
99ee04b9 VS |
70 | if ( gs_cursorsHash->find(cursorId) != gs_cursorsHash->end() ) |
71 | { | |
72 | wxLogTrace(_T("mglcursor"), _T("cursor id %i fetched from cache"), cursorId); | |
73 | *this = (*gs_cursorsHash)[cursorId]; | |
74 | return; | |
75 | } | |
76 | ||
32b8ec41 VZ |
77 | const char *cursorname = NULL; |
78 | m_refData = new wxCursorRefData(); | |
79 | ||
80 | switch (cursorId) | |
81 | { | |
82 | case wxCURSOR_ARROW: cursorname = "arrow.cur"; break; | |
a7c8e710 | 83 | case wxCURSOR_RIGHT_ARROW: cursorname = "rightarr.cur"; break; |
32b8ec41 VZ |
84 | case wxCURSOR_BULLSEYE: cursorname = "bullseye.cur"; break; |
85 | case wxCURSOR_CHAR: cursorname = "char.cur"; break; | |
86 | case wxCURSOR_CROSS: cursorname = "cross.cur"; break; | |
87 | case wxCURSOR_HAND: cursorname = "hand.cur"; break; | |
88 | case wxCURSOR_IBEAM: cursorname = "ibeam.cur"; break; | |
89 | case wxCURSOR_LEFT_BUTTON: cursorname = "leftbtn.cur"; break; | |
90 | case wxCURSOR_MAGNIFIER: cursorname = "magnif1.cur"; break; | |
91 | case wxCURSOR_MIDDLE_BUTTON: cursorname = "midbtn.cur"; break; | |
92 | case wxCURSOR_NO_ENTRY: cursorname = "noentry.cur"; break; | |
93 | case wxCURSOR_PAINT_BRUSH: cursorname = "pbrush.cur"; break; | |
94 | case wxCURSOR_PENCIL: cursorname = "pencil.cur"; break; | |
95 | case wxCURSOR_POINT_LEFT: cursorname = "pntleft.cur"; break; | |
96 | case wxCURSOR_POINT_RIGHT: cursorname = "pntright.cur"; break; | |
97 | case wxCURSOR_QUESTION_ARROW: cursorname = "query.cur"; break; | |
98 | case wxCURSOR_RIGHT_BUTTON: cursorname = "rightbtn.cur"; break; | |
99 | case wxCURSOR_SIZENESW: cursorname = "sizenesw.cur"; break; | |
100 | case wxCURSOR_SIZENS: cursorname = "sizens.cur"; break; | |
101 | case wxCURSOR_SIZENWSE: cursorname = "sizenwse.cur"; break; | |
102 | case wxCURSOR_SIZEWE: cursorname = "sizewe.cur"; break; | |
103 | case wxCURSOR_SIZING: cursorname = "size.cur"; break; | |
104 | case wxCURSOR_SPRAYCAN: cursorname = "spraycan.cur"; break; | |
105 | case wxCURSOR_WAIT: cursorname = "wait.cur"; break; | |
106 | case wxCURSOR_WATCH: cursorname = "clock.cur"; break; | |
107 | case wxCURSOR_BLANK: cursorname = "blank.cur"; break; | |
108 | ||
109 | case wxCURSOR_NONE: | |
32b8ec41 VZ |
110 | *this = wxNullCursor; |
111 | return; | |
32b8ec41 VZ |
112 | |
113 | default: | |
114 | wxFAIL_MSG(wxT("unsupported cursor type")); | |
115 | break; | |
116 | } | |
127eab18 | 117 | |
32b8ec41 VZ |
118 | M_CURSORDATA->m_cursor = new MGLCursor(cursorname); |
119 | ||
120 | // if we cannot load arrow cursor, use MGL's default arrow cursor: | |
121 | if ( !M_CURSORDATA->m_cursor->valid() && cursorId == wxCURSOR_ARROW ) | |
122 | { | |
123 | delete M_CURSORDATA->m_cursor; | |
124 | M_CURSORDATA->m_cursor = new MGLCursor(MGL_DEF_CURSOR); | |
125 | } | |
127eab18 | 126 | |
32b8ec41 VZ |
127 | if ( !M_CURSORDATA->m_cursor->valid() ) |
128 | { | |
129 | wxLogError(_("Couldn't create cursor.")); | |
130 | UnRef(); | |
131 | } | |
99ee04b9 VS |
132 | else |
133 | { | |
134 | (*gs_cursorsHash)[cursorId] = *this; | |
127eab18 | 135 | wxLogTrace(_T("mglcursor"), _T("cursor id %i added to cache (%s)"), |
99ee04b9 VS |
136 | cursorId, cursorname); |
137 | } | |
32b8ec41 VZ |
138 | } |
139 | ||
140 | wxCursor::wxCursor(const char WXUNUSED(bits)[], | |
141 | int WXUNUSED(width), | |
142 | int WXUNUSED(height), | |
143 | int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), | |
144 | const char WXUNUSED(maskBits)[], | |
145 | wxColour * WXUNUSED(fg), wxColour * WXUNUSED(bg) ) | |
146 | { | |
147 | //FIXME_MGL | |
148 | } | |
149 | ||
150 | wxCursor::wxCursor(const wxString& cursor_file, | |
151 | long flags, | |
127eab18 | 152 | int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY)) |
32b8ec41 VZ |
153 | { |
154 | if ( flags == wxBITMAP_TYPE_CUR || flags == wxBITMAP_TYPE_CUR_RESOURCE ) | |
155 | { | |
156 | m_refData = new wxCursorRefData(); | |
157 | M_CURSORDATA->m_cursor = new MGLCursor(cursor_file.mb_str()); | |
158 | if ( !M_CURSORDATA->m_cursor->valid() ) | |
159 | { | |
160 | wxLogError(_("Couldn't create cursor.")); | |
161 | UnRef(); | |
162 | } | |
163 | } | |
164 | else | |
165 | { | |
166 | wxLogError(wxT("Cannot load cursor resource of this type.")); | |
167 | } | |
168 | } | |
169 | ||
32b8ec41 VZ |
170 | wxCursor::~wxCursor() |
171 | { | |
172 | // wxObject unrefs data | |
173 | } | |
174 | ||
32b8ec41 VZ |
175 | bool wxCursor::operator == (const wxCursor& cursor) const |
176 | { | |
177 | return (m_refData == cursor.m_refData); | |
178 | } | |
179 | ||
180 | bool wxCursor::operator != (const wxCursor& cursor) const | |
181 | { | |
182 | return (m_refData != cursor.m_refData); | |
183 | } | |
184 | ||
185 | bool wxCursor::Ok() const | |
186 | { | |
187 | return (m_refData != NULL); | |
188 | } | |
189 | ||
190 | MGLCursor *wxCursor::GetMGLCursor() const | |
191 | { | |
192 | return M_CURSORDATA->m_cursor; | |
193 | } | |
194 | ||
195 | ||
196 | ||
197 | // ---------------------------------------------------------------------------- | |
198 | // Global cursor setting | |
199 | // ---------------------------------------------------------------------------- | |
200 | ||
5fd1ea32 | 201 | static wxCursor gs_globalCursor = wxNullCursor; |
32b8ec41 VZ |
202 | |
203 | void wxSetCursor(const wxCursor& cursor) | |
204 | { | |
205 | if ( cursor.Ok() ) | |
206 | { | |
9006f25e VS |
207 | if ( g_winMng ) |
208 | MGL_wmSetGlobalCursor(g_winMng, *cursor.GetMGLCursor()); | |
5fd1ea32 VS |
209 | gs_globalCursor = cursor; |
210 | } | |
211 | else | |
212 | { | |
9006f25e VS |
213 | if ( g_winMng ) |
214 | MGL_wmSetGlobalCursor(g_winMng, NULL); | |
127eab18 | 215 | gs_globalCursor = wxNullCursor; |
32b8ec41 VZ |
216 | } |
217 | } | |
218 | ||
219 | ||
220 | ||
221 | //----------------------------------------------------------------------------- | |
222 | // busy cursor routines | |
223 | //----------------------------------------------------------------------------- | |
224 | ||
ef344ff8 | 225 | static wxCursor gs_savedCursor = wxNullCursor; |
32b8ec41 VZ |
226 | static int gs_busyCount = 0; |
227 | ||
228 | const wxCursor &wxBusyCursor::GetStoredCursor() | |
229 | { | |
230 | return gs_savedCursor; | |
231 | } | |
232 | ||
233 | const wxCursor wxBusyCursor::GetBusyCursor() | |
234 | { | |
5fd1ea32 | 235 | return gs_globalCursor; |
32b8ec41 VZ |
236 | } |
237 | ||
238 | void wxEndBusyCursor() | |
239 | { | |
240 | if ( --gs_busyCount > 0 ) return; | |
241 | ||
242 | wxSetCursor(gs_savedCursor); | |
243 | gs_savedCursor = wxNullCursor; | |
32b8ec41 VZ |
244 | } |
245 | ||
f516d986 | 246 | void wxBeginBusyCursor(const wxCursor *cursor) |
32b8ec41 VZ |
247 | { |
248 | if ( gs_busyCount++ > 0 ) return; | |
249 | ||
250 | wxASSERT_MSG( !gs_savedCursor.Ok(), | |
251 | wxT("forgot to call wxEndBusyCursor, will leak memory") ); | |
252 | ||
5fd1ea32 | 253 | gs_savedCursor = gs_globalCursor; |
ef344ff8 VS |
254 | if ( cursor->Ok() ) |
255 | wxSetCursor(*cursor); | |
256 | else | |
257 | wxSetCursor(wxCursor(wxCURSOR_WAIT)); | |
32b8ec41 VZ |
258 | } |
259 | ||
260 | bool wxIsBusy() | |
261 | { | |
262 | return (gs_busyCount > 0); | |
263 | } | |
264 | ||
99ee04b9 VS |
265 | |
266 | ||
267 | //----------------------------------------------------------------------------- | |
268 | // module - clean up code | |
269 | //----------------------------------------------------------------------------- | |
270 | ||
271 | class wxCursorModule : public wxModule | |
272 | { | |
273 | public: | |
127eab18 WS |
274 | virtual bool OnInit() { return true; } |
275 | ||
99ee04b9 VS |
276 | virtual void OnExit() |
277 | { | |
278 | wxDELETE(gs_cursorsHash); | |
279 | } | |
280 | ||
281 | private: | |
282 | DECLARE_DYNAMIC_CLASS(wxCursorModule) | |
283 | }; | |
284 | ||
285 | IMPLEMENT_DYNAMIC_CLASS(wxCursorModule, wxModule) |