]>
Commit | Line | Data |
---|---|---|
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 | // 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... | |
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: | |
101 | // FIXME_MGL - make sure wxWindow uses cursor with | |
102 | // GetMGLCursor() == NULL correctly, i.e. calls MS_hide() | |
103 | *this = wxNullCursor; | |
104 | return; | |
105 | break; | |
106 | ||
107 | default: | |
108 | wxFAIL_MSG(wxT("unsupported cursor type")); | |
109 | break; | |
110 | } | |
111 | ||
112 | M_CURSORDATA->m_cursor = new MGLCursor(cursorname); | |
113 | ||
114 | // if we cannot load arrow cursor, use MGL's default arrow cursor: | |
115 | if ( !M_CURSORDATA->m_cursor->valid() && cursorId == wxCURSOR_ARROW ) | |
116 | { | |
117 | delete M_CURSORDATA->m_cursor; | |
118 | M_CURSORDATA->m_cursor = new MGLCursor(MGL_DEF_CURSOR); | |
119 | } | |
120 | ||
121 | if ( !M_CURSORDATA->m_cursor->valid() ) | |
122 | { | |
123 | wxLogError(_("Couldn't create cursor.")); | |
124 | UnRef(); | |
125 | } | |
126 | } | |
127 | ||
128 | wxCursor::wxCursor(const char WXUNUSED(bits)[], | |
129 | int WXUNUSED(width), | |
130 | int WXUNUSED(height), | |
131 | int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), | |
132 | const char WXUNUSED(maskBits)[], | |
133 | wxColour * WXUNUSED(fg), wxColour * WXUNUSED(bg) ) | |
134 | { | |
135 | //FIXME_MGL | |
136 | } | |
137 | ||
138 | wxCursor::wxCursor(const wxString& cursor_file, | |
139 | long flags, | |
140 | int hotSpotX, int hotSpotY) | |
141 | { | |
142 | if ( flags == wxBITMAP_TYPE_CUR || flags == wxBITMAP_TYPE_CUR_RESOURCE ) | |
143 | { | |
144 | m_refData = new wxCursorRefData(); | |
145 | M_CURSORDATA->m_cursor = new MGLCursor(cursor_file.mb_str()); | |
146 | if ( !M_CURSORDATA->m_cursor->valid() ) | |
147 | { | |
148 | wxLogError(_("Couldn't create cursor.")); | |
149 | UnRef(); | |
150 | } | |
151 | } | |
152 | else | |
153 | { | |
154 | wxLogError(wxT("Cannot load cursor resource of this type.")); | |
155 | } | |
156 | } | |
157 | ||
158 | wxCursor::wxCursor(const wxCursor &cursor) | |
159 | { | |
160 | Ref(cursor); | |
161 | } | |
162 | ||
163 | wxCursor::~wxCursor() | |
164 | { | |
165 | // wxObject unrefs data | |
166 | } | |
167 | ||
168 | wxCursor& wxCursor::operator = (const wxCursor& cursor) | |
169 | { | |
170 | if ( *this == cursor ) | |
171 | return (*this); | |
172 | Ref(cursor); | |
173 | return *this; | |
174 | } | |
175 | ||
176 | bool wxCursor::operator == (const wxCursor& cursor) const | |
177 | { | |
178 | return (m_refData == cursor.m_refData); | |
179 | } | |
180 | ||
181 | bool wxCursor::operator != (const wxCursor& cursor) const | |
182 | { | |
183 | return (m_refData != cursor.m_refData); | |
184 | } | |
185 | ||
186 | bool wxCursor::Ok() const | |
187 | { | |
188 | return (m_refData != NULL); | |
189 | } | |
190 | ||
191 | MGLCursor *wxCursor::GetMGLCursor() const | |
192 | { | |
193 | return M_CURSORDATA->m_cursor; | |
194 | } | |
195 | ||
196 | ||
197 | ||
198 | // ---------------------------------------------------------------------------- | |
199 | // Global cursor setting | |
200 | // ---------------------------------------------------------------------------- | |
201 | ||
202 | ||
203 | void wxSetCursor(const wxCursor& cursor) | |
204 | { | |
205 | if ( cursor.Ok() ) | |
206 | { | |
207 | //MGL_setGlobalCursor(cursor.GetMGLCursor()); | |
208 | // FIXME_MGL -- needs MGL WM first | |
209 | } | |
210 | } | |
211 | ||
212 | ||
213 | ||
214 | //----------------------------------------------------------------------------- | |
215 | // busy cursor routines | |
216 | //----------------------------------------------------------------------------- | |
217 | ||
218 | // FIXME_MGL -- do we need this? It may be better to incorporate | |
219 | // support for it into MGL (a stack of global cursors?) | |
220 | static wxCursor gs_savedCursor; | |
221 | static wxCursor g_globalCursor; | |
222 | static int gs_busyCount = 0; | |
223 | ||
224 | const wxCursor &wxBusyCursor::GetStoredCursor() | |
225 | { | |
226 | return gs_savedCursor; | |
227 | } | |
228 | ||
229 | const wxCursor wxBusyCursor::GetBusyCursor() | |
230 | { | |
231 | return wxCursor(wxCURSOR_WAIT); | |
232 | } | |
233 | ||
234 | void wxEndBusyCursor() | |
235 | { | |
236 | if ( --gs_busyCount > 0 ) return; | |
237 | ||
238 | wxSetCursor(gs_savedCursor); | |
239 | gs_savedCursor = wxNullCursor; | |
240 | //wxYield(); FIXME_MGL - needed? | |
241 | } | |
242 | ||
243 | void wxBeginBusyCursor(wxCursor *WXUNUSED(cursor)) | |
244 | { | |
245 | if ( gs_busyCount++ > 0 ) return; | |
246 | ||
247 | wxASSERT_MSG( !gs_savedCursor.Ok(), | |
248 | wxT("forgot to call wxEndBusyCursor, will leak memory") ); | |
249 | ||
250 | gs_savedCursor = g_globalCursor; | |
251 | wxSetCursor(wxCursor(wxCURSOR_WAIT)); | |
252 | //wxYield(); FIXME_MGL - needed? | |
253 | } | |
254 | ||
255 | bool wxIsBusy() | |
256 | { | |
257 | return (gs_busyCount > 0); | |
258 | } | |
259 |