]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/cursor.cpp
implemented declared but never defined resize() method
[wxWidgets.git] / src / mgl / cursor.cpp
CommitLineData
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"
88a7a4e1
WS
18
19#ifndef WX_PRECOMP
20 #include "wx/intl.h"
e4db172a 21 #include "wx/log.h"
de6185e2 22 #include "wx/utils.h"
88a7a4e1
WS
23#endif
24
99ee04b9 25#include "wx/module.h"
99ee04b9 26#include "wx/hashmap.h"
32b8ec41 27
ef344ff8 28#include "wx/mgl/private.h"
32b8ec41
VZ
29
30
31//-----------------------------------------------------------------------------
32// wxCursor
33//-----------------------------------------------------------------------------
34
35class wxCursorRefData: public wxObjectRefData
36{
37 public:
38
39 wxCursorRefData();
40 ~wxCursorRefData();
41
42 MGLCursor *m_cursor;
43};
44
45wxCursorRefData::wxCursorRefData()
46{
47 m_cursor = (MGLCursor*) NULL;
48}
49
50wxCursorRefData::~wxCursorRefData()
51{
52 delete m_cursor;
53}
54
99ee04b9
VS
55#define M_CURSORDATA ((wxCursorRefData *)m_refData)
56
32b8ec41
VZ
57//-----------------------------------------------------------------------------
58
dac7d53a 59WX_DECLARE_HASH_MAP(int, wxCursor, wxIntegerHash, wxIntegerEqual, wxCursorsHash);
99ee04b9
VS
60
61static wxCursorsHash *gs_cursorsHash = NULL;
32b8ec41
VZ
62
63IMPLEMENT_DYNAMIC_CLASS(wxCursor,wxObject)
64
65wxCursor::wxCursor()
66{
67}
68
69wxCursor::wxCursor(int cursorId)
70{
c41c20a5
VS
71 if ( !gs_cursorsHash )
72 gs_cursorsHash = new wxCursorsHash;
73
99ee04b9
VS
74 if ( gs_cursorsHash->find(cursorId) != gs_cursorsHash->end() )
75 {
76 wxLogTrace(_T("mglcursor"), _T("cursor id %i fetched from cache"), cursorId);
77 *this = (*gs_cursorsHash)[cursorId];
78 return;
79 }
80
32b8ec41
VZ
81 const char *cursorname = NULL;
82 m_refData = new wxCursorRefData();
83
84 switch (cursorId)
85 {
86 case wxCURSOR_ARROW: cursorname = "arrow.cur"; break;
a7c8e710 87 case wxCURSOR_RIGHT_ARROW: cursorname = "rightarr.cur"; break;
32b8ec41
VZ
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;
32b8ec41
VZ
116
117 default:
118 wxFAIL_MSG(wxT("unsupported cursor type"));
119 break;
120 }
127eab18 121
32b8ec41
VZ
122 M_CURSORDATA->m_cursor = new MGLCursor(cursorname);
123
124 // if we cannot load arrow cursor, use MGL's default arrow cursor:
125 if ( !M_CURSORDATA->m_cursor->valid() && cursorId == wxCURSOR_ARROW )
126 {
127 delete M_CURSORDATA->m_cursor;
128 M_CURSORDATA->m_cursor = new MGLCursor(MGL_DEF_CURSOR);
129 }
127eab18 130
32b8ec41
VZ
131 if ( !M_CURSORDATA->m_cursor->valid() )
132 {
133 wxLogError(_("Couldn't create cursor."));
134 UnRef();
135 }
99ee04b9
VS
136 else
137 {
138 (*gs_cursorsHash)[cursorId] = *this;
127eab18 139 wxLogTrace(_T("mglcursor"), _T("cursor id %i added to cache (%s)"),
99ee04b9
VS
140 cursorId, cursorname);
141 }
32b8ec41
VZ
142}
143
144wxCursor::wxCursor(const char WXUNUSED(bits)[],
145 int WXUNUSED(width),
146 int WXUNUSED(height),
147 int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY),
148 const char WXUNUSED(maskBits)[],
149 wxColour * WXUNUSED(fg), wxColour * WXUNUSED(bg) )
150{
151 //FIXME_MGL
152}
153
154wxCursor::wxCursor(const wxString& cursor_file,
155 long flags,
127eab18 156 int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY))
32b8ec41
VZ
157{
158 if ( flags == wxBITMAP_TYPE_CUR || flags == wxBITMAP_TYPE_CUR_RESOURCE )
159 {
160 m_refData = new wxCursorRefData();
161 M_CURSORDATA->m_cursor = new MGLCursor(cursor_file.mb_str());
162 if ( !M_CURSORDATA->m_cursor->valid() )
163 {
164 wxLogError(_("Couldn't create cursor."));
165 UnRef();
166 }
167 }
168 else
169 {
170 wxLogError(wxT("Cannot load cursor resource of this type."));
171 }
172}
173
32b8ec41
VZ
174wxCursor::~wxCursor()
175{
176 // wxObject unrefs data
177}
178
32b8ec41
VZ
179bool wxCursor::operator == (const wxCursor& cursor) const
180{
181 return (m_refData == cursor.m_refData);
182}
183
184bool wxCursor::operator != (const wxCursor& cursor) const
185{
186 return (m_refData != cursor.m_refData);
187}
188
189bool wxCursor::Ok() const
190{
191 return (m_refData != NULL);
192}
193
194MGLCursor *wxCursor::GetMGLCursor() const
195{
196 return M_CURSORDATA->m_cursor;
197}
198
199
200
201// ----------------------------------------------------------------------------
202// Global cursor setting
203// ----------------------------------------------------------------------------
204
5fd1ea32 205static wxCursor gs_globalCursor = wxNullCursor;
32b8ec41
VZ
206
207void wxSetCursor(const wxCursor& cursor)
208{
209 if ( cursor.Ok() )
210 {
9006f25e
VS
211 if ( g_winMng )
212 MGL_wmSetGlobalCursor(g_winMng, *cursor.GetMGLCursor());
5fd1ea32
VS
213 gs_globalCursor = cursor;
214 }
215 else
216 {
9006f25e
VS
217 if ( g_winMng )
218 MGL_wmSetGlobalCursor(g_winMng, NULL);
127eab18 219 gs_globalCursor = wxNullCursor;
32b8ec41
VZ
220 }
221}
222
223
224
225//-----------------------------------------------------------------------------
226// busy cursor routines
227//-----------------------------------------------------------------------------
228
ef344ff8 229static wxCursor gs_savedCursor = wxNullCursor;
32b8ec41
VZ
230static int gs_busyCount = 0;
231
232const wxCursor &wxBusyCursor::GetStoredCursor()
233{
234 return gs_savedCursor;
235}
236
237const wxCursor wxBusyCursor::GetBusyCursor()
238{
5fd1ea32 239 return gs_globalCursor;
32b8ec41
VZ
240}
241
242void wxEndBusyCursor()
243{
244 if ( --gs_busyCount > 0 ) return;
245
246 wxSetCursor(gs_savedCursor);
247 gs_savedCursor = wxNullCursor;
32b8ec41
VZ
248}
249
f516d986 250void wxBeginBusyCursor(const wxCursor *cursor)
32b8ec41
VZ
251{
252 if ( gs_busyCount++ > 0 ) return;
253
254 wxASSERT_MSG( !gs_savedCursor.Ok(),
255 wxT("forgot to call wxEndBusyCursor, will leak memory") );
256
5fd1ea32 257 gs_savedCursor = gs_globalCursor;
ef344ff8
VS
258 if ( cursor->Ok() )
259 wxSetCursor(*cursor);
260 else
261 wxSetCursor(wxCursor(wxCURSOR_WAIT));
32b8ec41
VZ
262}
263
264bool wxIsBusy()
265{
266 return (gs_busyCount > 0);
267}
268
99ee04b9
VS
269
270
271//-----------------------------------------------------------------------------
272// module - clean up code
273//-----------------------------------------------------------------------------
274
275class wxCursorModule : public wxModule
276{
277public:
127eab18
WS
278 virtual bool OnInit() { return true; }
279
99ee04b9
VS
280 virtual void OnExit()
281 {
282 wxDELETE(gs_cursorsHash);
283 }
284
285private:
286 DECLARE_DYNAMIC_CLASS(wxCursorModule)
287};
288
289IMPLEMENT_DYNAMIC_CLASS(wxCursorModule, wxModule)