]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/cursor.cpp
Added some XSyncs to help size calculations, but positioning
[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{
99ee04b9
VS
72 if ( gs_cursorsHash->find(cursorId) != gs_cursorsHash->end() )
73 {
74 wxLogTrace(_T("mglcursor"), _T("cursor id %i fetched from cache"), cursorId);
75 *this = (*gs_cursorsHash)[cursorId];
76 return;
77 }
78
32b8ec41
VZ
79 const char *cursorname = NULL;
80 m_refData = new wxCursorRefData();
81
82 switch (cursorId)
83 {
84 case wxCURSOR_ARROW: cursorname = "arrow.cur"; break;
85 case wxCURSOR_BULLSEYE: cursorname = "bullseye.cur"; break;
86 case wxCURSOR_CHAR: cursorname = "char.cur"; break;
87 case wxCURSOR_CROSS: cursorname = "cross.cur"; break;
88 case wxCURSOR_HAND: cursorname = "hand.cur"; break;
89 case wxCURSOR_IBEAM: cursorname = "ibeam.cur"; break;
90 case wxCURSOR_LEFT_BUTTON: cursorname = "leftbtn.cur"; break;
91 case wxCURSOR_MAGNIFIER: cursorname = "magnif1.cur"; break;
92 case wxCURSOR_MIDDLE_BUTTON: cursorname = "midbtn.cur"; break;
93 case wxCURSOR_NO_ENTRY: cursorname = "noentry.cur"; break;
94 case wxCURSOR_PAINT_BRUSH: cursorname = "pbrush.cur"; break;
95 case wxCURSOR_PENCIL: cursorname = "pencil.cur"; break;
96 case wxCURSOR_POINT_LEFT: cursorname = "pntleft.cur"; break;
97 case wxCURSOR_POINT_RIGHT: cursorname = "pntright.cur"; break;
98 case wxCURSOR_QUESTION_ARROW: cursorname = "query.cur"; break;
99 case wxCURSOR_RIGHT_BUTTON: cursorname = "rightbtn.cur"; break;
100 case wxCURSOR_SIZENESW: cursorname = "sizenesw.cur"; break;
101 case wxCURSOR_SIZENS: cursorname = "sizens.cur"; break;
102 case wxCURSOR_SIZENWSE: cursorname = "sizenwse.cur"; break;
103 case wxCURSOR_SIZEWE: cursorname = "sizewe.cur"; break;
104 case wxCURSOR_SIZING: cursorname = "size.cur"; break;
105 case wxCURSOR_SPRAYCAN: cursorname = "spraycan.cur"; break;
106 case wxCURSOR_WAIT: cursorname = "wait.cur"; break;
107 case wxCURSOR_WATCH: cursorname = "clock.cur"; break;
108 case wxCURSOR_BLANK: cursorname = "blank.cur"; break;
109
110 case wxCURSOR_NONE:
32b8ec41
VZ
111 *this = wxNullCursor;
112 return;
113 break;
114
115 default:
116 wxFAIL_MSG(wxT("unsupported cursor type"));
117 break;
118 }
119
120 M_CURSORDATA->m_cursor = new MGLCursor(cursorname);
121
122 // if we cannot load arrow cursor, use MGL's default arrow cursor:
123 if ( !M_CURSORDATA->m_cursor->valid() && cursorId == wxCURSOR_ARROW )
124 {
125 delete M_CURSORDATA->m_cursor;
126 M_CURSORDATA->m_cursor = new MGLCursor(MGL_DEF_CURSOR);
127 }
128
129 if ( !M_CURSORDATA->m_cursor->valid() )
130 {
131 wxLogError(_("Couldn't create cursor."));
132 UnRef();
133 }
99ee04b9
VS
134 else
135 {
136 (*gs_cursorsHash)[cursorId] = *this;
137 wxLogTrace(_T("mglcursor"), _T("cursor id %i added to cache (%s)"),
138 cursorId, cursorname);
139 }
32b8ec41
VZ
140}
141
142wxCursor::wxCursor(const char WXUNUSED(bits)[],
143 int WXUNUSED(width),
144 int WXUNUSED(height),
145 int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY),
146 const char WXUNUSED(maskBits)[],
147 wxColour * WXUNUSED(fg), wxColour * WXUNUSED(bg) )
148{
149 //FIXME_MGL
150}
151
152wxCursor::wxCursor(const wxString& cursor_file,
153 long flags,
154 int hotSpotX, int hotSpotY)
155{
156 if ( flags == wxBITMAP_TYPE_CUR || flags == wxBITMAP_TYPE_CUR_RESOURCE )
157 {
158 m_refData = new wxCursorRefData();
159 M_CURSORDATA->m_cursor = new MGLCursor(cursor_file.mb_str());
160 if ( !M_CURSORDATA->m_cursor->valid() )
161 {
162 wxLogError(_("Couldn't create cursor."));
163 UnRef();
164 }
165 }
166 else
167 {
168 wxLogError(wxT("Cannot load cursor resource of this type."));
169 }
170}
171
172wxCursor::wxCursor(const wxCursor &cursor)
173{
174 Ref(cursor);
175}
176
177wxCursor::~wxCursor()
178{
179 // wxObject unrefs data
180}
181
182wxCursor& wxCursor::operator = (const wxCursor& cursor)
183{
184 if ( *this == cursor )
185 return (*this);
186 Ref(cursor);
187 return *this;
188}
189
190bool wxCursor::operator == (const wxCursor& cursor) const
191{
192 return (m_refData == cursor.m_refData);
193}
194
195bool wxCursor::operator != (const wxCursor& cursor) const
196{
197 return (m_refData != cursor.m_refData);
198}
199
200bool wxCursor::Ok() const
201{
202 return (m_refData != NULL);
203}
204
205MGLCursor *wxCursor::GetMGLCursor() const
206{
207 return M_CURSORDATA->m_cursor;
208}
209
210
211
212// ----------------------------------------------------------------------------
213// Global cursor setting
214// ----------------------------------------------------------------------------
215
5fd1ea32 216static wxCursor gs_globalCursor = wxNullCursor;
32b8ec41
VZ
217
218void wxSetCursor(const wxCursor& cursor)
219{
220 if ( cursor.Ok() )
221 {
9006f25e
VS
222 if ( g_winMng )
223 MGL_wmSetGlobalCursor(g_winMng, *cursor.GetMGLCursor());
5fd1ea32
VS
224 gs_globalCursor = cursor;
225 }
226 else
227 {
9006f25e
VS
228 if ( g_winMng )
229 MGL_wmSetGlobalCursor(g_winMng, NULL);
5fd1ea32 230 gs_globalCursor = wxNullCursor;
32b8ec41
VZ
231 }
232}
233
234
235
236//-----------------------------------------------------------------------------
237// busy cursor routines
238//-----------------------------------------------------------------------------
239
ef344ff8 240static wxCursor gs_savedCursor = wxNullCursor;
32b8ec41
VZ
241static int gs_busyCount = 0;
242
243const wxCursor &wxBusyCursor::GetStoredCursor()
244{
245 return gs_savedCursor;
246}
247
248const wxCursor wxBusyCursor::GetBusyCursor()
249{
5fd1ea32 250 return gs_globalCursor;
32b8ec41
VZ
251}
252
253void wxEndBusyCursor()
254{
255 if ( --gs_busyCount > 0 ) return;
256
257 wxSetCursor(gs_savedCursor);
258 gs_savedCursor = wxNullCursor;
32b8ec41
VZ
259}
260
ef344ff8 261void wxBeginBusyCursor(wxCursor *cursor)
32b8ec41
VZ
262{
263 if ( gs_busyCount++ > 0 ) return;
264
265 wxASSERT_MSG( !gs_savedCursor.Ok(),
266 wxT("forgot to call wxEndBusyCursor, will leak memory") );
267
5fd1ea32 268 gs_savedCursor = gs_globalCursor;
ef344ff8
VS
269 if ( cursor->Ok() )
270 wxSetCursor(*cursor);
271 else
272 wxSetCursor(wxCursor(wxCURSOR_WAIT));
32b8ec41
VZ
273}
274
275bool wxIsBusy()
276{
277 return (gs_busyCount > 0);
278}
279
99ee04b9
VS
280
281
282//-----------------------------------------------------------------------------
283// module - clean up code
284//-----------------------------------------------------------------------------
285
286class wxCursorModule : public wxModule
287{
288public:
289 virtual bool OnInit()
290 {
291 gs_cursorsHash = new wxCursorsHash;
292 return TRUE;
293 }
294
295 virtual void OnExit()
296 {
297 wxDELETE(gs_cursorsHash);
298 }
299
300private:
301 DECLARE_DYNAMIC_CLASS(wxCursorModule)
302};
303
304IMPLEMENT_DYNAMIC_CLASS(wxCursorModule, wxModule)