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