]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/cursor.cpp
added GetStdIcon support to wxRenderer
[wxWidgets.git] / src / mgl / cursor.cpp
CommitLineData
32b8ec41
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: cursor.cpp
3// Purpose:
4// Author: Vaclav Slavik
5// Id: $Id$
8f7b34a8 6// Copyright: (c) 2001 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"
23#include "wx/utils.h"
24#include "wx/log.h"
25#include "wx/intl.h"
26
ef344ff8 27#include "wx/mgl/private.h"
32b8ec41
VZ
28
29
30//-----------------------------------------------------------------------------
31// wxCursor
32//-----------------------------------------------------------------------------
33
34class wxCursorRefData: public wxObjectRefData
35{
36 public:
37
38 wxCursorRefData();
39 ~wxCursorRefData();
40
41 MGLCursor *m_cursor;
42};
43
44wxCursorRefData::wxCursorRefData()
45{
46 m_cursor = (MGLCursor*) NULL;
47}
48
49wxCursorRefData::~wxCursorRefData()
50{
51 delete m_cursor;
52}
53
54//-----------------------------------------------------------------------------
55
56#define M_CURSORDATA ((wxCursorRefData *)m_refData)
57
58IMPLEMENT_DYNAMIC_CLASS(wxCursor,wxObject)
59
60wxCursor::wxCursor()
61{
62}
63
64wxCursor::wxCursor(int cursorId)
65{
66 const char *cursorname = NULL;
67 m_refData = new wxCursorRefData();
68
69 switch (cursorId)
70 {
7bdc1879
VS
71 // FIXME_MGL -- what about storing these default cursors in executable
72 // as XPMs so that wxMGL binary wouldn't depend on
73 // tons of files in $MGL_ROOT/cursors? I don't know yet...
32b8ec41
VZ
74 case wxCURSOR_ARROW: cursorname = "arrow.cur"; break;
75 case wxCURSOR_BULLSEYE: cursorname = "bullseye.cur"; break;
76 case wxCURSOR_CHAR: cursorname = "char.cur"; break;
77 case wxCURSOR_CROSS: cursorname = "cross.cur"; break;
78 case wxCURSOR_HAND: cursorname = "hand.cur"; break;
79 case wxCURSOR_IBEAM: cursorname = "ibeam.cur"; break;
80 case wxCURSOR_LEFT_BUTTON: cursorname = "leftbtn.cur"; break;
81 case wxCURSOR_MAGNIFIER: cursorname = "magnif1.cur"; break;
82 case wxCURSOR_MIDDLE_BUTTON: cursorname = "midbtn.cur"; break;
83 case wxCURSOR_NO_ENTRY: cursorname = "noentry.cur"; break;
84 case wxCURSOR_PAINT_BRUSH: cursorname = "pbrush.cur"; break;
85 case wxCURSOR_PENCIL: cursorname = "pencil.cur"; break;
86 case wxCURSOR_POINT_LEFT: cursorname = "pntleft.cur"; break;
87 case wxCURSOR_POINT_RIGHT: cursorname = "pntright.cur"; break;
88 case wxCURSOR_QUESTION_ARROW: cursorname = "query.cur"; break;
89 case wxCURSOR_RIGHT_BUTTON: cursorname = "rightbtn.cur"; break;
90 case wxCURSOR_SIZENESW: cursorname = "sizenesw.cur"; break;
91 case wxCURSOR_SIZENS: cursorname = "sizens.cur"; break;
92 case wxCURSOR_SIZENWSE: cursorname = "sizenwse.cur"; break;
93 case wxCURSOR_SIZEWE: cursorname = "sizewe.cur"; break;
94 case wxCURSOR_SIZING: cursorname = "size.cur"; break;
95 case wxCURSOR_SPRAYCAN: cursorname = "spraycan.cur"; break;
96 case wxCURSOR_WAIT: cursorname = "wait.cur"; break;
97 case wxCURSOR_WATCH: cursorname = "clock.cur"; break;
98 case wxCURSOR_BLANK: cursorname = "blank.cur"; break;
99
100 case wxCURSOR_NONE:
32b8ec41
VZ
101 *this = wxNullCursor;
102 return;
103 break;
104
105 default:
106 wxFAIL_MSG(wxT("unsupported cursor type"));
107 break;
108 }
109
110 M_CURSORDATA->m_cursor = new MGLCursor(cursorname);
111
112 // if we cannot load arrow cursor, use MGL's default arrow cursor:
113 if ( !M_CURSORDATA->m_cursor->valid() && cursorId == wxCURSOR_ARROW )
114 {
115 delete M_CURSORDATA->m_cursor;
116 M_CURSORDATA->m_cursor = new MGLCursor(MGL_DEF_CURSOR);
117 }
118
119 if ( !M_CURSORDATA->m_cursor->valid() )
120 {
121 wxLogError(_("Couldn't create cursor."));
122 UnRef();
123 }
124}
125
126wxCursor::wxCursor(const char WXUNUSED(bits)[],
127 int WXUNUSED(width),
128 int WXUNUSED(height),
129 int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY),
130 const char WXUNUSED(maskBits)[],
131 wxColour * WXUNUSED(fg), wxColour * WXUNUSED(bg) )
132{
133 //FIXME_MGL
134}
135
136wxCursor::wxCursor(const wxString& cursor_file,
137 long flags,
138 int hotSpotX, int hotSpotY)
139{
140 if ( flags == wxBITMAP_TYPE_CUR || flags == wxBITMAP_TYPE_CUR_RESOURCE )
141 {
142 m_refData = new wxCursorRefData();
143 M_CURSORDATA->m_cursor = new MGLCursor(cursor_file.mb_str());
144 if ( !M_CURSORDATA->m_cursor->valid() )
145 {
146 wxLogError(_("Couldn't create cursor."));
147 UnRef();
148 }
149 }
150 else
151 {
152 wxLogError(wxT("Cannot load cursor resource of this type."));
153 }
154}
155
156wxCursor::wxCursor(const wxCursor &cursor)
157{
158 Ref(cursor);
159}
160
161wxCursor::~wxCursor()
162{
163 // wxObject unrefs data
164}
165
166wxCursor& wxCursor::operator = (const wxCursor& cursor)
167{
168 if ( *this == cursor )
169 return (*this);
170 Ref(cursor);
171 return *this;
172}
173
174bool wxCursor::operator == (const wxCursor& cursor) const
175{
176 return (m_refData == cursor.m_refData);
177}
178
179bool wxCursor::operator != (const wxCursor& cursor) const
180{
181 return (m_refData != cursor.m_refData);
182}
183
184bool wxCursor::Ok() const
185{
186 return (m_refData != NULL);
187}
188
189MGLCursor *wxCursor::GetMGLCursor() const
190{
191 return M_CURSORDATA->m_cursor;
192}
193
194
195
196// ----------------------------------------------------------------------------
197// Global cursor setting
198// ----------------------------------------------------------------------------
199
5fd1ea32 200static wxCursor gs_globalCursor = wxNullCursor;
32b8ec41
VZ
201
202void wxSetCursor(const wxCursor& cursor)
203{
204 if ( cursor.Ok() )
205 {
ef344ff8 206 MGL_wmSetGlobalCursor(g_winMng, *cursor.GetMGLCursor());
5fd1ea32
VS
207 gs_globalCursor = cursor;
208 }
209 else
210 {
211 MGL_wmSetGlobalCursor(g_winMng, NULL);
212 gs_globalCursor = wxNullCursor;
32b8ec41
VZ
213 }
214}
215
216
217
218//-----------------------------------------------------------------------------
219// busy cursor routines
220//-----------------------------------------------------------------------------
221
ef344ff8 222static wxCursor gs_savedCursor = wxNullCursor;
32b8ec41
VZ
223static int gs_busyCount = 0;
224
225const wxCursor &wxBusyCursor::GetStoredCursor()
226{
227 return gs_savedCursor;
228}
229
230const wxCursor wxBusyCursor::GetBusyCursor()
231{
5fd1ea32 232 return gs_globalCursor;
32b8ec41
VZ
233}
234
235void wxEndBusyCursor()
236{
237 if ( --gs_busyCount > 0 ) return;
238
239 wxSetCursor(gs_savedCursor);
240 gs_savedCursor = wxNullCursor;
32b8ec41
VZ
241}
242
ef344ff8 243void wxBeginBusyCursor(wxCursor *cursor)
32b8ec41
VZ
244{
245 if ( gs_busyCount++ > 0 ) return;
246
247 wxASSERT_MSG( !gs_savedCursor.Ok(),
248 wxT("forgot to call wxEndBusyCursor, will leak memory") );
249
5fd1ea32 250 gs_savedCursor = gs_globalCursor;
ef344ff8
VS
251 if ( cursor->Ok() )
252 wxSetCursor(*cursor);
253 else
254 wxSetCursor(wxCursor(wxCURSOR_WAIT));
32b8ec41
VZ
255}
256
257bool wxIsBusy()
258{
259 return (gs_busyCount > 0);
260}
261