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