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