]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/cursor.cpp
added new files which were generated by bakefile but were not in cvs for some reason
[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)
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
31class wxCursorRefData: public wxObjectRefData
32{
33 public:
34
35 wxCursorRefData();
36 ~wxCursorRefData();
37
38 MGLCursor *m_cursor;
39};
40
41wxCursorRefData::wxCursorRefData()
42{
43 m_cursor = (MGLCursor*) NULL;
44}
45
46wxCursorRefData::~wxCursorRefData()
47{
48 delete m_cursor;
49}
50
99ee04b9
VS
51#define M_CURSORDATA ((wxCursorRefData *)m_refData)
52
32b8ec41
VZ
53//-----------------------------------------------------------------------------
54
dac7d53a 55WX_DECLARE_HASH_MAP(int, wxCursor, wxIntegerHash, wxIntegerEqual, wxCursorsHash);
99ee04b9
VS
56
57static wxCursorsHash *gs_cursorsHash = NULL;
32b8ec41
VZ
58
59IMPLEMENT_DYNAMIC_CLASS(wxCursor,wxObject)
60
61wxCursor::wxCursor()
62{
63}
64
65wxCursor::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;
112 break;
113
114 default:
115 wxFAIL_MSG(wxT("unsupported cursor type"));
116 break;
117 }
118
119 M_CURSORDATA->m_cursor = new MGLCursor(cursorname);
120
121 // if we cannot load arrow cursor, use MGL's default arrow cursor:
122 if ( !M_CURSORDATA->m_cursor->valid() && cursorId == wxCURSOR_ARROW )
123 {
124 delete M_CURSORDATA->m_cursor;
125 M_CURSORDATA->m_cursor = new MGLCursor(MGL_DEF_CURSOR);
126 }
127
128 if ( !M_CURSORDATA->m_cursor->valid() )
129 {
130 wxLogError(_("Couldn't create cursor."));
131 UnRef();
132 }
99ee04b9
VS
133 else
134 {
135 (*gs_cursorsHash)[cursorId] = *this;
136 wxLogTrace(_T("mglcursor"), _T("cursor id %i added to cache (%s)"),
137 cursorId, cursorname);
138 }
32b8ec41
VZ
139}
140
141wxCursor::wxCursor(const char WXUNUSED(bits)[],
142 int WXUNUSED(width),
143 int WXUNUSED(height),
144 int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY),
145 const char WXUNUSED(maskBits)[],
146 wxColour * WXUNUSED(fg), wxColour * WXUNUSED(bg) )
147{
148 //FIXME_MGL
149}
150
151wxCursor::wxCursor(const wxString& cursor_file,
152 long flags,
153 int hotSpotX, int hotSpotY)
154{
155 if ( flags == wxBITMAP_TYPE_CUR || flags == wxBITMAP_TYPE_CUR_RESOURCE )
156 {
157 m_refData = new wxCursorRefData();
158 M_CURSORDATA->m_cursor = new MGLCursor(cursor_file.mb_str());
159 if ( !M_CURSORDATA->m_cursor->valid() )
160 {
161 wxLogError(_("Couldn't create cursor."));
162 UnRef();
163 }
164 }
165 else
166 {
167 wxLogError(wxT("Cannot load cursor resource of this type."));
168 }
169}
170
171wxCursor::wxCursor(const wxCursor &cursor)
172{
173 Ref(cursor);
174}
175
176wxCursor::~wxCursor()
177{
178 // wxObject unrefs data
179}
180
181wxCursor& wxCursor::operator = (const wxCursor& cursor)
182{
183 if ( *this == cursor )
184 return (*this);
185 Ref(cursor);
186 return *this;
187}
188
189bool wxCursor::operator == (const wxCursor& cursor) const
190{
191 return (m_refData == cursor.m_refData);
192}
193
194bool wxCursor::operator != (const wxCursor& cursor) const
195{
196 return (m_refData != cursor.m_refData);
197}
198
199bool wxCursor::Ok() const
200{
201 return (m_refData != NULL);
202}
203
204MGLCursor *wxCursor::GetMGLCursor() const
205{
206 return M_CURSORDATA->m_cursor;
207}
208
209
210
211// ----------------------------------------------------------------------------
212// Global cursor setting
213// ----------------------------------------------------------------------------
214
5fd1ea32 215static wxCursor gs_globalCursor = wxNullCursor;
32b8ec41
VZ
216
217void wxSetCursor(const wxCursor& cursor)
218{
219 if ( cursor.Ok() )
220 {
9006f25e
VS
221 if ( g_winMng )
222 MGL_wmSetGlobalCursor(g_winMng, *cursor.GetMGLCursor());
5fd1ea32
VS
223 gs_globalCursor = cursor;
224 }
225 else
226 {
9006f25e
VS
227 if ( g_winMng )
228 MGL_wmSetGlobalCursor(g_winMng, NULL);
5fd1ea32 229 gs_globalCursor = wxNullCursor;
32b8ec41
VZ
230 }
231}
232
233
234
235//-----------------------------------------------------------------------------
236// busy cursor routines
237//-----------------------------------------------------------------------------
238
ef344ff8 239static wxCursor gs_savedCursor = wxNullCursor;
32b8ec41
VZ
240static int gs_busyCount = 0;
241
242const wxCursor &wxBusyCursor::GetStoredCursor()
243{
244 return gs_savedCursor;
245}
246
247const wxCursor wxBusyCursor::GetBusyCursor()
248{
5fd1ea32 249 return gs_globalCursor;
32b8ec41
VZ
250}
251
252void wxEndBusyCursor()
253{
254 if ( --gs_busyCount > 0 ) return;
255
256 wxSetCursor(gs_savedCursor);
257 gs_savedCursor = wxNullCursor;
32b8ec41
VZ
258}
259
ef344ff8 260void wxBeginBusyCursor(wxCursor *cursor)
32b8ec41
VZ
261{
262 if ( gs_busyCount++ > 0 ) return;
263
264 wxASSERT_MSG( !gs_savedCursor.Ok(),
265 wxT("forgot to call wxEndBusyCursor, will leak memory") );
266
5fd1ea32 267 gs_savedCursor = gs_globalCursor;
ef344ff8
VS
268 if ( cursor->Ok() )
269 wxSetCursor(*cursor);
270 else
271 wxSetCursor(wxCursor(wxCURSOR_WAIT));
32b8ec41
VZ
272}
273
274bool wxIsBusy()
275{
276 return (gs_busyCount > 0);
277}
278
99ee04b9
VS
279
280
281//-----------------------------------------------------------------------------
282// module - clean up code
283//-----------------------------------------------------------------------------
284
285class wxCursorModule : public wxModule
286{
287public:
c41c20a5 288 virtual bool OnInit() { return TRUE; }
99ee04b9
VS
289
290 virtual void OnExit()
291 {
292 wxDELETE(gs_cursorsHash);
293 }
294
295private:
296 DECLARE_DYNAMIC_CLASS(wxCursorModule)
297};
298
299IMPLEMENT_DYNAMIC_CLASS(wxCursorModule, wxModule)