|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtGui module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <private/qcursor_p.h> |
|
43 #include <private/qpixmap_mac_p.h> |
|
44 #include <qapplication.h> |
|
45 #include <qbitmap.h> |
|
46 #include <qcursor.h> |
|
47 #include <qevent.h> |
|
48 #include <string.h> |
|
49 #include <unistd.h> |
|
50 #include <AppKit/NSCursor.h> |
|
51 #include <qpainter.h> |
|
52 #include <private/qt_cocoa_helpers_mac_p.h> |
|
53 |
|
54 QT_BEGIN_NAMESPACE |
|
55 |
|
56 /***************************************************************************** |
|
57 Externals |
|
58 *****************************************************************************/ |
|
59 extern QCursorData *qt_cursorTable[Qt::LastCursor + 1]; |
|
60 extern OSWindowRef qt_mac_window_for(const QWidget *); //qwidget_mac.cpp |
|
61 extern GrafPtr qt_mac_qd_context(const QPaintDevice *); //qpaintdevice_mac.cpp |
|
62 extern bool qt_sendSpontaneousEvent(QObject *, QEvent *); //qapplication_mac.cpp |
|
63 |
|
64 /***************************************************************************** |
|
65 Internal QCursorData class |
|
66 *****************************************************************************/ |
|
67 |
|
68 class QMacAnimateCursor : public QObject |
|
69 { |
|
70 int timerId, step; |
|
71 ThemeCursor curs; |
|
72 public: |
|
73 QMacAnimateCursor() : QObject(), timerId(-1) { } |
|
74 void start(ThemeCursor c) { |
|
75 step = 1; |
|
76 if(timerId != -1) |
|
77 killTimer(timerId); |
|
78 timerId = startTimer(300); |
|
79 curs = c; |
|
80 } |
|
81 void stop() { |
|
82 if(timerId != -1) { |
|
83 killTimer(timerId); |
|
84 timerId = -1; |
|
85 } |
|
86 } |
|
87 protected: |
|
88 void timerEvent(QTimerEvent *e) { |
|
89 if(e->timerId() == timerId) { |
|
90 /* |
|
91 if(SetAnimatedThemeCursor(curs, step++) == themeBadCursorIndexErr) |
|
92 stop(); |
|
93 */ |
|
94 } |
|
95 } |
|
96 }; |
|
97 |
|
98 void *qt_mac_nsCursorForQCursor(const QCursor &c) |
|
99 { |
|
100 c.d->update(); |
|
101 return [[static_cast<NSCursor *>(c.d->curs.cp.nscursor) retain] autorelease]; |
|
102 } |
|
103 |
|
104 static QCursorData *currentCursor = 0; //current cursor |
|
105 void qt_mac_set_cursor(const QCursor *c, const QPoint &) |
|
106 { |
|
107 #ifdef QT_MAC_USE_COCOA |
|
108 Q_UNUSED(c); |
|
109 return; |
|
110 #else |
|
111 if (!c) { |
|
112 currentCursor = 0; |
|
113 return; |
|
114 } |
|
115 c->handle(); //force the cursor to get loaded, if it's not |
|
116 |
|
117 if(1 || currentCursor != c->d) { |
|
118 if(currentCursor && currentCursor->type == QCursorData::TYPE_ThemeCursor |
|
119 && currentCursor->curs.tc.anim) |
|
120 currentCursor->curs.tc.anim->stop(); |
|
121 QMacCocoaAutoReleasePool pool; |
|
122 if(c->d->type == QCursorData::TYPE_ImageCursor) { |
|
123 [static_cast<NSCursor *>(c->d->curs.cp.nscursor) set]; |
|
124 } else if(c->d->type == QCursorData::TYPE_ThemeCursor) { |
|
125 #ifdef QT_MAC_USE_COCOA |
|
126 if (c->d->curs.cp.nscursor == 0) |
|
127 [[NSCursor arrowCursor] set]; |
|
128 [static_cast<NSCursor *>(c->d->curs.cp.nscursor) set]; |
|
129 #else |
|
130 if(SetAnimatedThemeCursor(c->d->curs.tc.curs, 0) == themeBadCursorIndexErr) { |
|
131 SetThemeCursor(c->d->curs.tc.curs); |
|
132 } else { |
|
133 if(!c->d->curs.tc.anim) |
|
134 c->d->curs.tc.anim = new QMacAnimateCursor; |
|
135 c->d->curs.tc.anim->start(c->d->curs.tc.curs); |
|
136 } |
|
137 #endif |
|
138 } |
|
139 } |
|
140 currentCursor = c->d; |
|
141 #endif |
|
142 } |
|
143 |
|
144 void qt_mac_update_cursor_at_global_pos(const QPoint &globalPos) |
|
145 { |
|
146 #ifdef QT_MAC_USE_COCOA |
|
147 Q_UNUSED(globalPos); |
|
148 return; |
|
149 #else |
|
150 QCursor cursor(Qt::ArrowCursor); |
|
151 if (QApplication::overrideCursor()) { |
|
152 cursor = *QApplication::overrideCursor(); |
|
153 } else { |
|
154 for(QWidget *w = QApplication::widgetAt(globalPos); w; w = w->parentWidget()) { |
|
155 if(w->testAttribute(Qt::WA_SetCursor)) { |
|
156 cursor = w->cursor(); |
|
157 break; |
|
158 } |
|
159 } |
|
160 } |
|
161 qt_mac_set_cursor(&cursor, globalPos); |
|
162 #endif |
|
163 } |
|
164 |
|
165 void qt_mac_update_cursor() |
|
166 { |
|
167 qt_mac_update_cursor_at_global_pos(QCursor::pos()); |
|
168 } |
|
169 |
|
170 static int nextCursorId = Qt::BitmapCursor; |
|
171 |
|
172 QCursorData::QCursorData(Qt::CursorShape s) |
|
173 : cshape(s), bm(0), bmm(0), hx(-1), hy(-1), mId(s), type(TYPE_None) |
|
174 { |
|
175 ref = 1; |
|
176 memset(&curs, '\0', sizeof(curs)); |
|
177 } |
|
178 |
|
179 QCursorData::~QCursorData() |
|
180 { |
|
181 if (type == TYPE_ImageCursor) { |
|
182 if (curs.cp.my_cursor) { |
|
183 QMacCocoaAutoReleasePool pool; |
|
184 [static_cast<NSCursor *>(curs.cp.nscursor) release]; |
|
185 } |
|
186 } else if(type == TYPE_ThemeCursor) { |
|
187 delete curs.tc.anim; |
|
188 } |
|
189 type = TYPE_None; |
|
190 |
|
191 delete bm; |
|
192 delete bmm; |
|
193 if(currentCursor == this) |
|
194 currentCursor = 0; |
|
195 } |
|
196 |
|
197 QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY) |
|
198 { |
|
199 if (!QCursorData::initialized) |
|
200 QCursorData::initialize(); |
|
201 if (bitmap.depth() != 1 || mask.depth() != 1 || bitmap.size() != mask.size()) { |
|
202 qWarning("Qt: QCursor: Cannot create bitmap cursor; invalid bitmap(s)"); |
|
203 QCursorData *c = qt_cursorTable[0]; |
|
204 c->ref.ref(); |
|
205 return c; |
|
206 } |
|
207 // This is silly, but this is apparently called outside the constructor, so we have |
|
208 // to be ready for that case. |
|
209 QCursorData *x = new QCursorData; |
|
210 x->ref = 1; |
|
211 x->mId = ++nextCursorId; |
|
212 x->bm = new QBitmap(bitmap); |
|
213 x->bmm = new QBitmap(mask); |
|
214 x->cshape = Qt::BitmapCursor; |
|
215 x->hx = hotX >= 0 ? hotX : bitmap.width() / 2; |
|
216 x->hy = hotY >= 0 ? hotY : bitmap.height() / 2; |
|
217 return x; |
|
218 } |
|
219 |
|
220 Qt::HANDLE QCursor::handle() const |
|
221 { |
|
222 if(!QCursorData::initialized) |
|
223 QCursorData::initialize(); |
|
224 if(d->type == QCursorData::TYPE_None) |
|
225 d->update(); |
|
226 return (Qt::HANDLE)d->mId; |
|
227 } |
|
228 |
|
229 QPoint QCursor::pos() |
|
230 { |
|
231 return flipPoint([NSEvent mouseLocation]).toPoint(); |
|
232 } |
|
233 |
|
234 void QCursor::setPos(int x, int y) |
|
235 { |
|
236 CGWarpMouseCursorPosition(CGPointMake(x, y)); |
|
237 |
|
238 /* I'm not too keen on doing this, but this makes it a lot easier, so I just |
|
239 send the event back through the event system and let it get propagated correctly |
|
240 ideally this would not really need to be faked --Sam |
|
241 */ |
|
242 QWidget *widget = 0; |
|
243 if(QWidget *grb = QWidget::mouseGrabber()) |
|
244 widget = grb; |
|
245 else |
|
246 widget = QApplication::widgetAt(QPoint(x, y)); |
|
247 if(widget) { |
|
248 QMouseEvent me(QMouseEvent::MouseMove, widget->mapFromGlobal(QPoint(x, y)), Qt::NoButton, |
|
249 QApplication::mouseButtons(), QApplication::keyboardModifiers()); |
|
250 qt_sendSpontaneousEvent(widget, &me); |
|
251 } |
|
252 } |
|
253 |
|
254 void QCursorData::initCursorFromBitmap() |
|
255 { |
|
256 NSImage *nsimage; |
|
257 QImage finalCursor(bm->size(), QImage::Format_ARGB32); |
|
258 QImage bmi = bm->toImage().convertToFormat(QImage::Format_RGB32); |
|
259 QImage bmmi = bmm->toImage().convertToFormat(QImage::Format_RGB32); |
|
260 for (int row = 0; row < finalCursor.height(); ++row) { |
|
261 QRgb *bmData = reinterpret_cast<QRgb *>(bmi.scanLine(row)); |
|
262 QRgb *bmmData = reinterpret_cast<QRgb *>(bmmi.scanLine(row)); |
|
263 QRgb *finalData = reinterpret_cast<QRgb *>(finalCursor.scanLine(row)); |
|
264 for (int col = 0; col < finalCursor.width(); ++col) { |
|
265 if (bmmData[col] == 0xff000000 && bmData[col] == 0xffffffff) { |
|
266 finalData[col] = 0xffffffff; |
|
267 } else if (bmmData[col] == 0xff000000 && bmData[col] == 0xffffffff) { |
|
268 finalData[col] = 0x7f000000; |
|
269 } else if (bmmData[col] == 0xffffffff && bmData[col] == 0xffffffff) { |
|
270 finalData[col] = 0x00000000; |
|
271 } else { |
|
272 finalData[col] = 0xff000000; |
|
273 } |
|
274 } |
|
275 } |
|
276 type = QCursorData::TYPE_ImageCursor; |
|
277 curs.cp.my_cursor = true; |
|
278 QPixmap bmCopy = QPixmap::fromImage(finalCursor); |
|
279 NSPoint hotSpot = { hx, hy }; |
|
280 nsimage = static_cast<NSImage*>(qt_mac_create_nsimage(bmCopy)); |
|
281 curs.cp.nscursor = [[NSCursor alloc] initWithImage:nsimage hotSpot: hotSpot]; |
|
282 [nsimage release]; |
|
283 } |
|
284 |
|
285 void QCursorData::initCursorFromPixmap() |
|
286 { |
|
287 type = QCursorData::TYPE_ImageCursor; |
|
288 curs.cp.my_cursor = true; |
|
289 NSPoint hotSpot = { hx, hy }; |
|
290 NSImage *nsimage; |
|
291 nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(pixmap)); |
|
292 curs.cp.nscursor = [[NSCursor alloc] initWithImage:nsimage hotSpot: hotSpot]; |
|
293 [nsimage release]; |
|
294 } |
|
295 |
|
296 void QCursorData::update() |
|
297 { |
|
298 if(!QCursorData::initialized) |
|
299 QCursorData::initialize(); |
|
300 if(type != QCursorData::TYPE_None) |
|
301 return; |
|
302 |
|
303 /* Note to self... *** |
|
304 * mask x data |
|
305 * 0xFF x 0x00 == fully opaque white |
|
306 * 0x00 x 0xFF == xor'd black |
|
307 * 0xFF x 0xFF == fully opaque black |
|
308 * 0x00 x 0x00 == fully transparent |
|
309 */ |
|
310 |
|
311 if (hx < 0) |
|
312 hx = 0; |
|
313 if (hy < 0) |
|
314 hy = 0; |
|
315 |
|
316 #define QT_USE_APPROXIMATE_CURSORS |
|
317 #ifdef QT_USE_APPROXIMATE_CURSORS |
|
318 static const uchar cur_ver_bits[] = { |
|
319 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x03, 0xc0, 0x07, 0xe0, 0x0f, 0xf0, |
|
320 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x0f, 0xf0, |
|
321 0x07, 0xe0, 0x03, 0xc0, 0x01, 0x80, 0x00, 0x00 }; |
|
322 static const uchar mcur_ver_bits[] = { |
|
323 0x00, 0x00, 0x03, 0x80, 0x07, 0xc0, 0x0f, 0xe0, 0x1f, 0xf0, 0x3f, 0xf8, |
|
324 0x7f, 0xfc, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x7f, 0xfc, 0x3f, 0xf8, |
|
325 0x1f, 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80 }; |
|
326 |
|
327 static const uchar cur_hor_bits[] = { |
|
328 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x20, 0x18, 0x30, |
|
329 0x38, 0x38, 0x7f, 0xfc, 0x7f, 0xfc, 0x38, 0x38, 0x18, 0x30, 0x08, 0x20, |
|
330 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
|
331 static const uchar mcur_hor_bits[] = { |
|
332 0x00, 0x00, 0x00, 0x00, 0x04, 0x40, 0x0c, 0x60, 0x1c, 0x70, 0x3c, 0x78, |
|
333 0x7f, 0xfc, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0x7f, 0xfc, 0x3c, 0x78, |
|
334 0x1c, 0x70, 0x0c, 0x60, 0x04, 0x40, 0x00, 0x00 }; |
|
335 |
|
336 static const uchar cur_fdiag_bits[] = { |
|
337 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x00, 0xf8, 0x00, 0x78, |
|
338 0x00, 0xf8, 0x01, 0xd8, 0x23, 0x88, 0x37, 0x00, 0x3e, 0x00, 0x3c, 0x00, |
|
339 0x3e, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
|
340 static const uchar mcur_fdiag_bits[] = { |
|
341 0x00, 0x00, 0x00, 0x00, 0x07, 0xfc, 0x03, 0xfc, 0x01, 0xfc, 0x00, 0xfc, |
|
342 0x41, 0xfc, 0x63, 0xfc, 0x77, 0xdc, 0x7f, 0x8c, 0x7f, 0x04, 0x7e, 0x00, |
|
343 0x7f, 0x00, 0x7f, 0x80, 0x7f, 0xc0, 0x00, 0x00 }; |
|
344 |
|
345 static const uchar cur_bdiag_bits[] = { |
|
346 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0x3e, 0x00, |
|
347 0x37, 0x00, 0x23, 0x88, 0x01, 0xd8, 0x00, 0xf8, 0x00, 0x78, 0x00, 0xf8, |
|
348 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
|
349 static const uchar mcur_bdiag_bits[] = { |
|
350 0x00, 0x00, 0x7f, 0xc0, 0x7f, 0x80, 0x7f, 0x00, 0x7e, 0x00, 0x7f, 0x04, |
|
351 0x7f, 0x8c, 0x77, 0xdc, 0x63, 0xfc, 0x41, 0xfc, 0x00, 0xfc, 0x01, 0xfc, |
|
352 0x03, 0xfc, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00 }; |
|
353 |
|
354 static const unsigned char cur_up_arrow_bits[] = { |
|
355 0x00, 0x80, 0x01, 0x40, 0x01, 0x40, 0x02, 0x20, 0x02, 0x20, 0x04, 0x10, |
|
356 0x04, 0x10, 0x08, 0x08, 0x0f, 0x78, 0x01, 0x40, 0x01, 0x40, 0x01, 0x40, |
|
357 0x01, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01, 0xc0 }; |
|
358 static const unsigned char mcur_up_arrow_bits[] = { |
|
359 0x00, 0x80, 0x01, 0xc0, 0x01, 0xc0, 0x03, 0xe0, 0x03, 0xe0, 0x07, 0xf0, |
|
360 0x07, 0xf0, 0x0f, 0xf8, 0x0f, 0xf8, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, |
|
361 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0 }; |
|
362 #endif |
|
363 const uchar *cursorData = 0; |
|
364 const uchar *cursorMaskData = 0; |
|
365 #ifdef QT_MAC_USE_COCOA |
|
366 switch (cshape) { // map Q cursor to MAC cursor |
|
367 case Qt::BitmapCursor: { |
|
368 if (pixmap.isNull()) |
|
369 initCursorFromBitmap(); |
|
370 else |
|
371 initCursorFromPixmap(); |
|
372 break; } |
|
373 case Qt::BlankCursor: { |
|
374 pixmap = QPixmap(16, 16); |
|
375 pixmap.fill(Qt::transparent); |
|
376 initCursorFromPixmap(); |
|
377 break; } |
|
378 case Qt::ArrowCursor: { |
|
379 type = QCursorData::TYPE_ThemeCursor; |
|
380 curs.cp.nscursor = [NSCursor arrowCursor]; |
|
381 break; } |
|
382 case Qt::CrossCursor: { |
|
383 type = QCursorData::TYPE_ThemeCursor; |
|
384 curs.cp.nscursor = [NSCursor crosshairCursor]; |
|
385 break; } |
|
386 case Qt::WaitCursor: { |
|
387 pixmap = QPixmap(QLatin1String(":/trolltech/mac/cursors/images/spincursor.png")); |
|
388 initCursorFromPixmap(); |
|
389 break; } |
|
390 case Qt::IBeamCursor: { |
|
391 type = QCursorData::TYPE_ThemeCursor; |
|
392 curs.cp.nscursor = [NSCursor IBeamCursor]; |
|
393 break; } |
|
394 case Qt::SizeAllCursor: { |
|
395 pixmap = QPixmap(QLatin1String(":/trolltech/mac/cursors/images/pluscursor.png")); |
|
396 initCursorFromPixmap(); |
|
397 break; } |
|
398 case Qt::WhatsThisCursor: { //for now just use the pointing hand |
|
399 case Qt::PointingHandCursor: |
|
400 type = QCursorData::TYPE_ThemeCursor; |
|
401 curs.cp.nscursor = [NSCursor pointingHandCursor]; |
|
402 break; } |
|
403 case Qt::BusyCursor: { |
|
404 pixmap = QPixmap(QLatin1String(":/trolltech/mac/cursors/images/waitcursor.png")); |
|
405 initCursorFromPixmap(); |
|
406 break; } |
|
407 case Qt::SplitVCursor: { |
|
408 type = QCursorData::TYPE_ThemeCursor; |
|
409 curs.cp.nscursor = [NSCursor resizeUpDownCursor]; |
|
410 break; } |
|
411 case Qt::SplitHCursor: { |
|
412 type = QCursorData::TYPE_ThemeCursor; |
|
413 curs.cp.nscursor = [NSCursor resizeLeftRightCursor]; |
|
414 break; } |
|
415 case Qt::ForbiddenCursor: { |
|
416 pixmap = QPixmap(QLatin1String(":/trolltech/mac/cursors/images/forbiddencursor.png")); |
|
417 initCursorFromPixmap(); |
|
418 break; } |
|
419 case Qt::OpenHandCursor: |
|
420 type = QCursorData::TYPE_ThemeCursor; |
|
421 curs.cp.nscursor = [NSCursor openHandCursor]; |
|
422 break; |
|
423 case Qt::ClosedHandCursor: |
|
424 type = QCursorData::TYPE_ThemeCursor; |
|
425 curs.cp.nscursor = [NSCursor closedHandCursor]; |
|
426 break; |
|
427 #define QT_USE_APPROXIMATE_CURSORS |
|
428 #ifdef QT_USE_APPROXIMATE_CURSORS |
|
429 case Qt::SizeVerCursor: |
|
430 cursorData = cur_ver_bits; |
|
431 cursorMaskData = mcur_ver_bits; |
|
432 hx = hy = 8; |
|
433 break; |
|
434 case Qt::SizeHorCursor: |
|
435 cursorData = cur_hor_bits; |
|
436 cursorMaskData = mcur_hor_bits; |
|
437 hx = hy = 8; |
|
438 break; |
|
439 case Qt::SizeBDiagCursor: |
|
440 cursorData = cur_fdiag_bits; |
|
441 cursorMaskData = mcur_fdiag_bits; |
|
442 hx = hy = 8; |
|
443 break; |
|
444 case Qt::SizeFDiagCursor: |
|
445 cursorData = cur_bdiag_bits; |
|
446 cursorMaskData = mcur_bdiag_bits; |
|
447 hx = hy = 8; |
|
448 break; |
|
449 case Qt::UpArrowCursor: |
|
450 cursorData = cur_up_arrow_bits; |
|
451 cursorMaskData = mcur_up_arrow_bits; |
|
452 hx = 8; |
|
453 break; |
|
454 #endif |
|
455 default: |
|
456 qWarning("Qt: QCursor::update: Invalid cursor shape %d", cshape); |
|
457 return; |
|
458 } |
|
459 #else |
|
460 // Carbon |
|
461 switch (cshape) { // map Q cursor to MAC cursor |
|
462 case Qt::BitmapCursor: { |
|
463 if (pixmap.isNull()) |
|
464 initCursorFromBitmap(); |
|
465 else |
|
466 initCursorFromPixmap(); |
|
467 break; } |
|
468 case Qt::BlankCursor: { |
|
469 pixmap = QPixmap(16, 16); |
|
470 pixmap.fill(Qt::transparent); |
|
471 initCursorFromPixmap(); |
|
472 break; } |
|
473 case Qt::ArrowCursor: { |
|
474 type = QCursorData::TYPE_ThemeCursor; |
|
475 curs.tc.curs = kThemeArrowCursor; |
|
476 break; } |
|
477 case Qt::CrossCursor: { |
|
478 type = QCursorData::TYPE_ThemeCursor; |
|
479 curs.tc.curs = kThemeCrossCursor; |
|
480 break; } |
|
481 case Qt::WaitCursor: { |
|
482 type = QCursorData::TYPE_ThemeCursor; |
|
483 curs.tc.curs = kThemeWatchCursor; |
|
484 break; } |
|
485 case Qt::IBeamCursor: { |
|
486 type = QCursorData::TYPE_ThemeCursor; |
|
487 curs.tc.curs = kThemeIBeamCursor; |
|
488 break; } |
|
489 case Qt::SizeAllCursor: { |
|
490 type = QCursorData::TYPE_ThemeCursor; |
|
491 curs.tc.curs = kThemePlusCursor; |
|
492 break; } |
|
493 case Qt::WhatsThisCursor: { //for now just use the pointing hand |
|
494 case Qt::PointingHandCursor: |
|
495 type = QCursorData::TYPE_ThemeCursor; |
|
496 curs.tc.curs = kThemePointingHandCursor; |
|
497 break; } |
|
498 case Qt::BusyCursor: { |
|
499 type = QCursorData::TYPE_ThemeCursor; |
|
500 curs.tc.curs = kThemeSpinningCursor; |
|
501 break; } |
|
502 case Qt::SplitVCursor: { |
|
503 type = QCursorData::TYPE_ThemeCursor; |
|
504 curs.tc.curs = kThemeResizeUpDownCursor; |
|
505 break; } |
|
506 case Qt::SplitHCursor: { |
|
507 type = QCursorData::TYPE_ThemeCursor; |
|
508 curs.tc.curs = kThemeResizeLeftRightCursor; |
|
509 break; } |
|
510 case Qt::ForbiddenCursor: { |
|
511 type = QCursorData::TYPE_ThemeCursor; |
|
512 curs.tc.curs = kThemeNotAllowedCursor; |
|
513 break; } |
|
514 case Qt::OpenHandCursor: |
|
515 type = QCursorData::TYPE_ThemeCursor; |
|
516 curs.tc.curs = kThemeOpenHandCursor; |
|
517 break; |
|
518 case Qt::ClosedHandCursor: |
|
519 type = QCursorData::TYPE_ThemeCursor; |
|
520 curs.tc.curs = kThemeClosedHandCursor; |
|
521 break; |
|
522 #define QT_USE_APPROXIMATE_CURSORS |
|
523 #ifdef QT_USE_APPROXIMATE_CURSORS |
|
524 case Qt::SizeVerCursor: |
|
525 cursorData = cur_ver_bits; |
|
526 cursorMaskData = mcur_ver_bits; |
|
527 hx = hy = 8; |
|
528 break; |
|
529 case Qt::SizeHorCursor: |
|
530 cursorData = cur_hor_bits; |
|
531 cursorMaskData = mcur_hor_bits; |
|
532 hx = hy = 8; |
|
533 break; |
|
534 case Qt::SizeBDiagCursor: |
|
535 cursorData = cur_fdiag_bits; |
|
536 cursorMaskData = mcur_fdiag_bits; |
|
537 hx = hy = 8; |
|
538 break; |
|
539 case Qt::SizeFDiagCursor: |
|
540 cursorData = cur_bdiag_bits; |
|
541 cursorMaskData = mcur_bdiag_bits; |
|
542 hx = hy = 8; |
|
543 break; |
|
544 case Qt::UpArrowCursor: |
|
545 cursorData = cur_up_arrow_bits; |
|
546 cursorMaskData = mcur_up_arrow_bits; |
|
547 hx = 8; |
|
548 break; |
|
549 #endif |
|
550 default: |
|
551 qWarning("Qt: QCursor::update: Invalid cursor shape %d", cshape); |
|
552 return; |
|
553 } |
|
554 #endif |
|
555 |
|
556 if (cursorData) { |
|
557 bm = new QBitmap(QBitmap::fromData(QSize(16, 16), cursorData, |
|
558 QImage::Format_Mono)); |
|
559 bmm = new QBitmap(QBitmap::fromData(QSize(16, 16), cursorMaskData, |
|
560 QImage::Format_Mono)); |
|
561 initCursorFromBitmap(); |
|
562 } |
|
563 |
|
564 #if 0 |
|
565 if(type == QCursorData::TYPE_CursPtr && curs.cp.hcurs && curs.cp.my_cursor) { |
|
566 curs.cp.hcurs->hotSpot.h = hx >= 0 ? hx : 8; |
|
567 curs.cp.hcurs->hotSpot.v = hy >= 0 ? hy : 8; |
|
568 } |
|
569 #endif |
|
570 } |
|
571 |
|
572 QT_END_NAMESPACE |