]>
Commit | Line | Data |
---|---|---|
a24aff65 | 1 | ///////////////////////////////////////////////////////////////////////////// |
5558135c RN |
2 | // Name: cursor.mm |
3 | // Purpose: wxCursor class for wxCocoa | |
4 | // Author: Ryan Norton | |
a24aff65 | 5 | // Modified by: |
5558135c | 6 | // Created: 2004-10-05 |
a24aff65 | 7 | // RCS-ID: $Id$ |
5558135c | 8 | // Copyright: (c) Ryan Norton |
065e208e | 9 | // Licence: wxWidgets licence |
a24aff65 DE |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "cursor.h" | |
14 | #endif | |
15 | ||
449c5673 DE |
16 | #include "wx/wxprec.h" |
17 | #ifndef WX_PRECOMP | |
18 | #include "wx/icon.h" | |
19 | #include "wx/cursor.h" | |
20 | #endif //WX_PRECOMP | |
a24aff65 | 21 | |
5558135c RN |
22 | #import <AppKit/NSCursor.h> |
23 | #import <AppKit/NSImage.h> | |
24 | #include <wx/cocoa/string.h> | |
25 | ||
a24aff65 DE |
26 | #if !USE_SHARED_LIBRARIES |
27 | IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap) | |
28 | #endif | |
29 | ||
5558135c RN |
30 | wxCursorRefData::wxCursorRefData() : |
31 | m_width(32), m_height(32), m_hCursor(nil) | |
a24aff65 | 32 | { |
a24aff65 DE |
33 | } |
34 | ||
35 | wxCursorRefData::~wxCursorRefData() | |
36 | { | |
5558135c RN |
37 | if (m_hCursor) |
38 | [m_hCursor release]; | |
a24aff65 DE |
39 | } |
40 | ||
41 | // Cursors | |
42 | wxCursor::wxCursor() | |
43 | { | |
44 | } | |
45 | ||
46 | wxCursor::wxCursor(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height), | |
47 | int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), const char WXUNUSED(maskBits)[]) | |
48 | { | |
5558135c | 49 | |
a24aff65 DE |
50 | } |
51 | ||
52 | wxCursor::wxCursor(const wxString& cursor_file, long flags, int hotSpotX, int hotSpotY) | |
53 | { | |
54 | m_refData = new wxCursorRefData; | |
5558135c RN |
55 | |
56 | //TODO: Not sure if this works or not | |
57 | NSImage* theImage; | |
58 | ||
59 | if (flags & wxBITMAP_TYPE_MACCURSOR_RESOURCE) | |
60 | { | |
61 | //[NSBundle bundleForClass:[self class]]? | |
62 | theImage = [[NSImage alloc] | |
63 | initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:wxNSStringWithWxString(cursor_file) ofType:nil] | |
64 | ]; | |
65 | ||
66 | } | |
67 | else | |
68 | theImage = [[NSImage alloc] initByReferencingFile:wxNSStringWithWxString(cursor_file) | |
69 | ]; | |
70 | ||
71 | wxASSERT(theImage); | |
72 | ||
73 | M_CURSORDATA->m_hCursor = [[NSCursor alloc] initWithImage:theImage | |
74 | hotSpot:NSMakePoint(hotSpotX, hotSpotY) | |
75 | ]; | |
76 | ||
77 | [theImage release]; | |
a24aff65 DE |
78 | } |
79 | ||
80 | // Cursors by stock number | |
81 | wxCursor::wxCursor(int cursor_type) | |
82 | { | |
83 | m_refData = new wxCursorRefData; | |
84 | ||
a24aff65 DE |
85 | switch (cursor_type) |
86 | { | |
5558135c RN |
87 | case wxCURSOR_IBEAM: |
88 | M_CURSORDATA->m_hCursor = [[NSCursor IBeamCursor] retain]; | |
89 | break; | |
90 | case wxCURSOR_ARROW: | |
91 | M_CURSORDATA->m_hCursor = [[NSCursor arrowCursor] retain]; | |
92 | break; | |
93 | /* TODO | |
a24aff65 DE |
94 | case wxCURSOR_WAIT: |
95 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_WAIT); | |
96 | break; | |
a24aff65 DE |
97 | case wxCURSOR_CROSS: |
98 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_CROSS); | |
99 | break; | |
100 | case wxCURSOR_SIZENWSE: | |
101 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_SIZENWSE); | |
102 | break; | |
103 | case wxCURSOR_SIZENESW: | |
104 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_SIZENESW); | |
105 | break; | |
106 | case wxCURSOR_SIZEWE: | |
107 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_SIZEWE); | |
108 | break; | |
109 | case wxCURSOR_SIZENS: | |
110 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_SIZENS); | |
111 | break; | |
112 | case wxCURSOR_CHAR: | |
113 | { | |
114 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_ARROW); | |
115 | break; | |
116 | } | |
117 | case wxCURSOR_HAND: | |
118 | { | |
119 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_HAND"); | |
120 | break; | |
121 | } | |
122 | case wxCURSOR_BULLSEYE: | |
123 | { | |
124 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_BULLSEYE"); | |
125 | break; | |
126 | } | |
127 | case wxCURSOR_PENCIL: | |
128 | { | |
129 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_PENCIL"); | |
130 | break; | |
131 | } | |
132 | case wxCURSOR_MAGNIFIER: | |
133 | { | |
134 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_MAGNIFIER"); | |
135 | break; | |
136 | } | |
137 | case wxCURSOR_NO_ENTRY: | |
138 | { | |
139 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_NO_ENTRY"); | |
140 | break; | |
141 | } | |
142 | case wxCURSOR_LEFT_BUTTON: | |
143 | { | |
144 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_ARROW); | |
145 | break; | |
146 | } | |
147 | case wxCURSOR_RIGHT_BUTTON: | |
148 | { | |
149 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_ARROW); | |
150 | break; | |
151 | } | |
152 | case wxCURSOR_MIDDLE_BUTTON: | |
153 | { | |
154 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_ARROW); | |
155 | break; | |
156 | } | |
157 | case wxCURSOR_SIZING: | |
158 | { | |
159 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_SIZING"); | |
160 | break; | |
161 | } | |
162 | case wxCURSOR_WATCH: | |
163 | { | |
164 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_WATCH"); | |
165 | break; | |
166 | } | |
167 | case wxCURSOR_SPRAYCAN: | |
168 | { | |
169 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_ROLLER"); | |
170 | break; | |
171 | } | |
172 | case wxCURSOR_PAINT_BRUSH: | |
173 | { | |
174 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_PBRUSH"); | |
175 | break; | |
176 | } | |
177 | case wxCURSOR_POINT_LEFT: | |
178 | { | |
179 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_PLEFT"); | |
180 | break; | |
181 | } | |
182 | case wxCURSOR_POINT_RIGHT: | |
183 | { | |
184 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_PRIGHT"); | |
185 | break; | |
186 | } | |
187 | case wxCURSOR_QUESTION_ARROW: | |
188 | { | |
189 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_QARROW"); | |
190 | break; | |
191 | } | |
192 | case wxCURSOR_BLANK: | |
193 | { | |
194 | M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_BLANK"); | |
195 | break; | |
196 | } | |
5558135c | 197 | */ |
a24aff65 | 198 | default: |
5558135c | 199 | break; |
a24aff65 | 200 | } |
a24aff65 DE |
201 | |
202 | } | |
203 | ||
204 | wxCursor::~wxCursor() | |
205 | { | |
206 | } | |
207 | ||
208 | // Global cursor setting | |
209 | void wxSetCursor(const wxCursor& cursor) | |
210 | { | |
5558135c RN |
211 | if (cursor.GetNSCursor()) |
212 | [cursor.GetNSCursor() push]; | |
a24aff65 DE |
213 | } |
214 | ||
215 | static int wxBusyCursorCount = 0; | |
216 | ||
217 | // Set the cursor to the busy cursor for all windows | |
218 | void wxBeginBusyCursor(wxCursor *cursor) | |
219 | { | |
220 | wxBusyCursorCount ++; | |
221 | if (wxBusyCursorCount == 1) | |
222 | { | |
223 | // TODO | |
224 | } | |
225 | else | |
226 | { | |
227 | // TODO | |
228 | } | |
229 | } | |
230 | ||
231 | // Restore cursor to normal | |
232 | void wxEndBusyCursor() | |
233 | { | |
234 | if (wxBusyCursorCount == 0) | |
235 | return; | |
236 | ||
237 | wxBusyCursorCount --; | |
238 | if (wxBusyCursorCount == 0) | |
239 | { | |
240 | // TODO | |
241 | } | |
242 | } | |
243 | ||
244 | // TRUE if we're between the above two calls | |
245 | bool wxIsBusy() | |
246 | { | |
247 | return (wxBusyCursorCount > 0); | |
248 | } | |
249 |