| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 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 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 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(currentCursor && currentCursor->type == QCursorData::TYPE_ThemeCursor
|
|---|
| 118 | && currentCursor->curs.tc.anim)
|
|---|
| 119 | currentCursor->curs.tc.anim->stop();
|
|---|
| 120 | if(c->d->type == QCursorData::TYPE_ImageCursor) {
|
|---|
| 121 | [static_cast<NSCursor *>(c->d->curs.cp.nscursor) set];
|
|---|
| 122 | } else if(c->d->type == QCursorData::TYPE_ThemeCursor) {
|
|---|
| 123 | if(SetAnimatedThemeCursor(c->d->curs.tc.curs, 0) == themeBadCursorIndexErr) {
|
|---|
| 124 | SetThemeCursor(c->d->curs.tc.curs);
|
|---|
| 125 | } else {
|
|---|
| 126 | if(!c->d->curs.tc.anim)
|
|---|
| 127 | c->d->curs.tc.anim = new QMacAnimateCursor;
|
|---|
| 128 | c->d->curs.tc.anim->start(c->d->curs.tc.curs);
|
|---|
| 129 | }
|
|---|
| 130 | }
|
|---|
| 131 | currentCursor = c->d;
|
|---|
| 132 | #endif
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | void qt_mac_update_cursor_at_global_pos(const QPoint &globalPos)
|
|---|
| 136 | {
|
|---|
| 137 | #ifdef QT_MAC_USE_COCOA
|
|---|
| 138 | Q_UNUSED(globalPos);
|
|---|
| 139 | return;
|
|---|
| 140 | #else
|
|---|
| 141 | QCursor cursor(Qt::ArrowCursor);
|
|---|
| 142 | if (QApplication::overrideCursor()) {
|
|---|
| 143 | cursor = *QApplication::overrideCursor();
|
|---|
| 144 | } else {
|
|---|
| 145 | for(QWidget *w = QApplication::widgetAt(globalPos); w; w = w->parentWidget()) {
|
|---|
| 146 | if(w->testAttribute(Qt::WA_SetCursor)) {
|
|---|
| 147 | cursor = w->cursor();
|
|---|
| 148 | break;
|
|---|
| 149 | }
|
|---|
| 150 | }
|
|---|
| 151 | }
|
|---|
| 152 | qt_mac_set_cursor(&cursor, globalPos);
|
|---|
| 153 | #endif
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | void qt_mac_update_cursor()
|
|---|
| 157 | {
|
|---|
| 158 | qt_mac_update_cursor_at_global_pos(QCursor::pos());
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | static int nextCursorId = Qt::BitmapCursor;
|
|---|
| 162 |
|
|---|
| 163 | QCursorData::QCursorData(Qt::CursorShape s)
|
|---|
| 164 | : cshape(s), bm(0), bmm(0), hx(-1), hy(-1), mId(s), type(TYPE_None)
|
|---|
| 165 | {
|
|---|
| 166 | ref = 1;
|
|---|
| 167 | memset(&curs, '\0', sizeof(curs));
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | QCursorData::~QCursorData()
|
|---|
| 171 | {
|
|---|
| 172 | if (type == TYPE_ImageCursor) {
|
|---|
| 173 | if (curs.cp.my_cursor) {
|
|---|
| 174 | QMacCocoaAutoReleasePool pool;
|
|---|
| 175 | [static_cast<NSCursor *>(curs.cp.nscursor) release];
|
|---|
| 176 | }
|
|---|
| 177 | } else if(type == TYPE_ThemeCursor) {
|
|---|
| 178 | delete curs.tc.anim;
|
|---|
| 179 | }
|
|---|
| 180 | type = TYPE_None;
|
|---|
| 181 |
|
|---|
| 182 | delete bm;
|
|---|
| 183 | delete bmm;
|
|---|
| 184 | if(currentCursor == this)
|
|---|
| 185 | currentCursor = 0;
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)
|
|---|
| 189 | {
|
|---|
| 190 | if (!QCursorData::initialized)
|
|---|
| 191 | QCursorData::initialize();
|
|---|
| 192 | if (bitmap.depth() != 1 || mask.depth() != 1 || bitmap.size() != mask.size()) {
|
|---|
| 193 | qWarning("Qt: QCursor: Cannot create bitmap cursor; invalid bitmap(s)");
|
|---|
| 194 | QCursorData *c = qt_cursorTable[0];
|
|---|
| 195 | c->ref.ref();
|
|---|
| 196 | return c;
|
|---|
| 197 | }
|
|---|
| 198 | // This is silly, but this is apparently called outside the constructor, so we have
|
|---|
| 199 | // to be ready for that case.
|
|---|
| 200 | QCursorData *x = new QCursorData;
|
|---|
| 201 | x->ref = 1;
|
|---|
| 202 | x->mId = ++nextCursorId;
|
|---|
| 203 | x->bm = new QBitmap(bitmap);
|
|---|
| 204 | x->bmm = new QBitmap(mask);
|
|---|
| 205 | x->cshape = Qt::BitmapCursor;
|
|---|
| 206 | x->hx = hotX >= 0 ? hotX : bitmap.width() / 2;
|
|---|
| 207 | x->hy = hotY >= 0 ? hotY : bitmap.height() / 2;
|
|---|
| 208 | return x;
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | Qt::HANDLE QCursor::handle() const
|
|---|
| 212 | {
|
|---|
| 213 | if(!QCursorData::initialized)
|
|---|
| 214 | QCursorData::initialize();
|
|---|
| 215 | if(d->type == QCursorData::TYPE_None)
|
|---|
| 216 | d->update();
|
|---|
| 217 | return (Qt::HANDLE)d->mId;
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | QPoint QCursor::pos()
|
|---|
| 221 | {
|
|---|
| 222 | return flipPoint([NSEvent mouseLocation]).toPoint();
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | void QCursor::setPos(int x, int y)
|
|---|
| 226 | {
|
|---|
| 227 | #ifdef QT_MAC_USE_COCOA
|
|---|
| 228 | CGPoint pos;
|
|---|
| 229 | pos.x = x;
|
|---|
| 230 | pos.y = y;
|
|---|
| 231 |
|
|---|
| 232 | CGEventRef e = CGEventCreateMouseEvent(0, kCGEventMouseMoved, pos, 0);
|
|---|
| 233 | CGEventPost(kCGHIDEventTap, e);
|
|---|
| 234 | CFRelease(e);
|
|---|
| 235 | #else
|
|---|
| 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 | #endif
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | void QCursorData::initCursorFromBitmap()
|
|---|
| 256 | {
|
|---|
| 257 | NSImage *nsimage;
|
|---|
| 258 | QImage finalCursor(bm->size(), QImage::Format_ARGB32);
|
|---|
| 259 | QImage bmi = bm->toImage().convertToFormat(QImage::Format_RGB32);
|
|---|
| 260 | QImage bmmi = bmm->toImage().convertToFormat(QImage::Format_RGB32);
|
|---|
| 261 | for (int row = 0; row < finalCursor.height(); ++row) {
|
|---|
| 262 | QRgb *bmData = reinterpret_cast<QRgb *>(bmi.scanLine(row));
|
|---|
| 263 | QRgb *bmmData = reinterpret_cast<QRgb *>(bmmi.scanLine(row));
|
|---|
| 264 | QRgb *finalData = reinterpret_cast<QRgb *>(finalCursor.scanLine(row));
|
|---|
| 265 | for (int col = 0; col < finalCursor.width(); ++col) {
|
|---|
| 266 | if (bmmData[col] == 0xff000000 && bmData[col] == 0xffffffff) {
|
|---|
| 267 | finalData[col] = 0xffffffff;
|
|---|
| 268 | } else if (bmmData[col] == 0xff000000 && bmData[col] == 0xffffffff) {
|
|---|
| 269 | finalData[col] = 0x7f000000;
|
|---|
| 270 | } else if (bmmData[col] == 0xffffffff && bmData[col] == 0xffffffff) {
|
|---|
| 271 | finalData[col] = 0x00000000;
|
|---|
| 272 | } else {
|
|---|
| 273 | finalData[col] = 0xff000000;
|
|---|
| 274 | }
|
|---|
| 275 | }
|
|---|
| 276 | }
|
|---|
| 277 | type = QCursorData::TYPE_ImageCursor;
|
|---|
| 278 | curs.cp.my_cursor = true;
|
|---|
| 279 | QPixmap bmCopy = QPixmap::fromImage(finalCursor);
|
|---|
| 280 | NSPoint hotSpot = { hx, hy };
|
|---|
| 281 | nsimage = static_cast<NSImage*>(qt_mac_create_nsimage(bmCopy));
|
|---|
| 282 | curs.cp.nscursor = [[NSCursor alloc] initWithImage:nsimage hotSpot: hotSpot];
|
|---|
| 283 | [nsimage release];
|
|---|
| 284 | }
|
|---|
| 285 |
|
|---|
| 286 | void QCursorData::initCursorFromPixmap()
|
|---|
| 287 | {
|
|---|
| 288 | type = QCursorData::TYPE_ImageCursor;
|
|---|
| 289 | curs.cp.my_cursor = true;
|
|---|
| 290 | NSPoint hotSpot = { hx, hy };
|
|---|
| 291 | NSImage *nsimage;
|
|---|
| 292 | nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(pixmap));
|
|---|
| 293 | curs.cp.nscursor = [[NSCursor alloc] initWithImage:nsimage hotSpot: hotSpot];
|
|---|
| 294 | [nsimage release];
|
|---|
| 295 | }
|
|---|
| 296 |
|
|---|
| 297 | void QCursorData::update()
|
|---|
| 298 | {
|
|---|
| 299 | if(!QCursorData::initialized)
|
|---|
| 300 | QCursorData::initialize();
|
|---|
| 301 | if(type != QCursorData::TYPE_None)
|
|---|
| 302 | return;
|
|---|
| 303 |
|
|---|
| 304 | /* Note to self... ***
|
|---|
| 305 | * mask x data
|
|---|
| 306 | * 0xFF x 0x00 == fully opaque white
|
|---|
| 307 | * 0x00 x 0xFF == xor'd black
|
|---|
| 308 | * 0xFF x 0xFF == fully opaque black
|
|---|
| 309 | * 0x00 x 0x00 == fully transparent
|
|---|
| 310 | */
|
|---|
| 311 |
|
|---|
| 312 | if (hx < 0)
|
|---|
| 313 | hx = 0;
|
|---|
| 314 | if (hy < 0)
|
|---|
| 315 | hy = 0;
|
|---|
| 316 |
|
|---|
| 317 | #define QT_USE_APPROXIMATE_CURSORS
|
|---|
| 318 | #ifdef QT_USE_APPROXIMATE_CURSORS
|
|---|
| 319 | static const uchar cur_ver_bits[] = {
|
|---|
| 320 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x03, 0xc0, 0x07, 0xe0, 0x0f, 0xf0,
|
|---|
| 321 | 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x0f, 0xf0,
|
|---|
| 322 | 0x07, 0xe0, 0x03, 0xc0, 0x01, 0x80, 0x00, 0x00 };
|
|---|
| 323 | static const uchar mcur_ver_bits[] = {
|
|---|
| 324 | 0x00, 0x00, 0x03, 0x80, 0x07, 0xc0, 0x0f, 0xe0, 0x1f, 0xf0, 0x3f, 0xf8,
|
|---|
| 325 | 0x7f, 0xfc, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x7f, 0xfc, 0x3f, 0xf8,
|
|---|
| 326 | 0x1f, 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80 };
|
|---|
| 327 |
|
|---|
| 328 | static const uchar cur_hor_bits[] = {
|
|---|
| 329 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x20, 0x18, 0x30,
|
|---|
| 330 | 0x38, 0x38, 0x7f, 0xfc, 0x7f, 0xfc, 0x38, 0x38, 0x18, 0x30, 0x08, 0x20,
|
|---|
| 331 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|---|
| 332 | static const uchar mcur_hor_bits[] = {
|
|---|
| 333 | 0x00, 0x00, 0x00, 0x00, 0x04, 0x40, 0x0c, 0x60, 0x1c, 0x70, 0x3c, 0x78,
|
|---|
| 334 | 0x7f, 0xfc, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0x7f, 0xfc, 0x3c, 0x78,
|
|---|
| 335 | 0x1c, 0x70, 0x0c, 0x60, 0x04, 0x40, 0x00, 0x00 };
|
|---|
| 336 |
|
|---|
| 337 | static const uchar cur_fdiag_bits[] = {
|
|---|
| 338 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x00, 0xf8, 0x00, 0x78,
|
|---|
| 339 | 0x00, 0xf8, 0x01, 0xd8, 0x23, 0x88, 0x37, 0x00, 0x3e, 0x00, 0x3c, 0x00,
|
|---|
| 340 | 0x3e, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|---|
| 341 | static const uchar mcur_fdiag_bits[] = {
|
|---|
| 342 | 0x00, 0x00, 0x00, 0x00, 0x07, 0xfc, 0x03, 0xfc, 0x01, 0xfc, 0x00, 0xfc,
|
|---|
| 343 | 0x41, 0xfc, 0x63, 0xfc, 0x77, 0xdc, 0x7f, 0x8c, 0x7f, 0x04, 0x7e, 0x00,
|
|---|
| 344 | 0x7f, 0x00, 0x7f, 0x80, 0x7f, 0xc0, 0x00, 0x00 };
|
|---|
| 345 |
|
|---|
| 346 | static const uchar cur_bdiag_bits[] = {
|
|---|
| 347 | 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0x3e, 0x00,
|
|---|
| 348 | 0x37, 0x00, 0x23, 0x88, 0x01, 0xd8, 0x00, 0xf8, 0x00, 0x78, 0x00, 0xf8,
|
|---|
| 349 | 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|---|
| 350 | static const uchar mcur_bdiag_bits[] = {
|
|---|
| 351 | 0x00, 0x00, 0x7f, 0xc0, 0x7f, 0x80, 0x7f, 0x00, 0x7e, 0x00, 0x7f, 0x04,
|
|---|
| 352 | 0x7f, 0x8c, 0x77, 0xdc, 0x63, 0xfc, 0x41, 0xfc, 0x00, 0xfc, 0x01, 0xfc,
|
|---|
| 353 | 0x03, 0xfc, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00 };
|
|---|
| 354 |
|
|---|
| 355 | static const unsigned char cur_up_arrow_bits[] = {
|
|---|
| 356 | 0x00, 0x80, 0x01, 0x40, 0x01, 0x40, 0x02, 0x20, 0x02, 0x20, 0x04, 0x10,
|
|---|
| 357 | 0x04, 0x10, 0x08, 0x08, 0x0f, 0x78, 0x01, 0x40, 0x01, 0x40, 0x01, 0x40,
|
|---|
| 358 | 0x01, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01, 0xc0 };
|
|---|
| 359 | static const unsigned char mcur_up_arrow_bits[] = {
|
|---|
| 360 | 0x00, 0x80, 0x01, 0xc0, 0x01, 0xc0, 0x03, 0xe0, 0x03, 0xe0, 0x07, 0xf0,
|
|---|
| 361 | 0x07, 0xf0, 0x0f, 0xf8, 0x0f, 0xf8, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0,
|
|---|
| 362 | 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0 };
|
|---|
| 363 | #endif
|
|---|
| 364 | const uchar *cursorData = 0;
|
|---|
| 365 | const uchar *cursorMaskData = 0;
|
|---|
| 366 | #ifdef QT_MAC_USE_COCOA
|
|---|
| 367 | switch (cshape) { // map Q cursor to MAC cursor
|
|---|
| 368 | case Qt::BitmapCursor: {
|
|---|
| 369 | if (pixmap.isNull())
|
|---|
| 370 | initCursorFromBitmap();
|
|---|
| 371 | else
|
|---|
| 372 | initCursorFromPixmap();
|
|---|
| 373 | break; }
|
|---|
| 374 | case Qt::BlankCursor: {
|
|---|
| 375 | pixmap = QPixmap(16, 16);
|
|---|
| 376 | pixmap.fill(Qt::transparent);
|
|---|
| 377 | initCursorFromPixmap();
|
|---|
| 378 | break; }
|
|---|
| 379 | case Qt::ArrowCursor: {
|
|---|
| 380 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 381 | curs.cp.nscursor = [NSCursor arrowCursor];
|
|---|
| 382 | break; }
|
|---|
| 383 | case Qt::CrossCursor: {
|
|---|
| 384 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 385 | curs.cp.nscursor = [NSCursor crosshairCursor];
|
|---|
| 386 | break; }
|
|---|
| 387 | case Qt::WaitCursor: {
|
|---|
| 388 | pixmap = QPixmap(QLatin1String(":/trolltech/mac/cursors/images/spincursor.png"));
|
|---|
| 389 | initCursorFromPixmap();
|
|---|
| 390 | break; }
|
|---|
| 391 | case Qt::IBeamCursor: {
|
|---|
| 392 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 393 | curs.cp.nscursor = [NSCursor IBeamCursor];
|
|---|
| 394 | break; }
|
|---|
| 395 | case Qt::SizeAllCursor: {
|
|---|
| 396 | pixmap = QPixmap(QLatin1String(":/trolltech/mac/cursors/images/pluscursor.png"));
|
|---|
| 397 | initCursorFromPixmap();
|
|---|
| 398 | break; }
|
|---|
| 399 | case Qt::WhatsThisCursor: { //for now just use the pointing hand
|
|---|
| 400 | case Qt::PointingHandCursor:
|
|---|
| 401 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 402 | curs.cp.nscursor = [NSCursor pointingHandCursor];
|
|---|
| 403 | break; }
|
|---|
| 404 | case Qt::BusyCursor: {
|
|---|
| 405 | pixmap = QPixmap(QLatin1String(":/trolltech/mac/cursors/images/waitcursor.png"));
|
|---|
| 406 | initCursorFromPixmap();
|
|---|
| 407 | break; }
|
|---|
| 408 | case Qt::SplitVCursor: {
|
|---|
| 409 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 410 | curs.cp.nscursor = [NSCursor resizeUpDownCursor];
|
|---|
| 411 | break; }
|
|---|
| 412 | case Qt::SplitHCursor: {
|
|---|
| 413 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 414 | curs.cp.nscursor = [NSCursor resizeLeftRightCursor];
|
|---|
| 415 | break; }
|
|---|
| 416 | case Qt::ForbiddenCursor: {
|
|---|
| 417 | pixmap = QPixmap(QLatin1String(":/trolltech/mac/cursors/images/forbiddencursor.png"));
|
|---|
| 418 | initCursorFromPixmap();
|
|---|
| 419 | break; }
|
|---|
| 420 | case Qt::OpenHandCursor:
|
|---|
| 421 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 422 | curs.cp.nscursor = [NSCursor openHandCursor];
|
|---|
| 423 | break;
|
|---|
| 424 | case Qt::ClosedHandCursor:
|
|---|
| 425 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 426 | curs.cp.nscursor = [NSCursor closedHandCursor];
|
|---|
| 427 | break;
|
|---|
| 428 | case Qt::DragCopyCursor:
|
|---|
| 429 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 430 | curs.cp.nscursor = [NSCursor dragCopyCursor];
|
|---|
| 431 | break;
|
|---|
| 432 | case Qt::DragMoveCursor:
|
|---|
| 433 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 434 | curs.cp.nscursor = [NSCursor arrowCursor];
|
|---|
| 435 | break;
|
|---|
| 436 | case Qt::DragLinkCursor:
|
|---|
| 437 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 438 | curs.cp.nscursor = [NSCursor dragLinkCursor];
|
|---|
| 439 | break;
|
|---|
| 440 | #define QT_USE_APPROXIMATE_CURSORS
|
|---|
| 441 | #ifdef QT_USE_APPROXIMATE_CURSORS
|
|---|
| 442 | case Qt::SizeVerCursor:
|
|---|
| 443 | cursorData = cur_ver_bits;
|
|---|
| 444 | cursorMaskData = mcur_ver_bits;
|
|---|
| 445 | hx = hy = 8;
|
|---|
| 446 | break;
|
|---|
| 447 | case Qt::SizeHorCursor:
|
|---|
| 448 | cursorData = cur_hor_bits;
|
|---|
| 449 | cursorMaskData = mcur_hor_bits;
|
|---|
| 450 | hx = hy = 8;
|
|---|
| 451 | break;
|
|---|
| 452 | case Qt::SizeBDiagCursor:
|
|---|
| 453 | cursorData = cur_fdiag_bits;
|
|---|
| 454 | cursorMaskData = mcur_fdiag_bits;
|
|---|
| 455 | hx = hy = 8;
|
|---|
| 456 | break;
|
|---|
| 457 | case Qt::SizeFDiagCursor:
|
|---|
| 458 | cursorData = cur_bdiag_bits;
|
|---|
| 459 | cursorMaskData = mcur_bdiag_bits;
|
|---|
| 460 | hx = hy = 8;
|
|---|
| 461 | break;
|
|---|
| 462 | case Qt::UpArrowCursor:
|
|---|
| 463 | cursorData = cur_up_arrow_bits;
|
|---|
| 464 | cursorMaskData = mcur_up_arrow_bits;
|
|---|
| 465 | hx = 8;
|
|---|
| 466 | break;
|
|---|
| 467 | #endif
|
|---|
| 468 | default:
|
|---|
| 469 | qWarning("Qt: QCursor::update: Invalid cursor shape %d", cshape);
|
|---|
| 470 | return;
|
|---|
| 471 | }
|
|---|
| 472 | #else
|
|---|
| 473 | // Carbon
|
|---|
| 474 | switch (cshape) { // map Q cursor to MAC cursor
|
|---|
| 475 | case Qt::BitmapCursor: {
|
|---|
| 476 | if (pixmap.isNull())
|
|---|
| 477 | initCursorFromBitmap();
|
|---|
| 478 | else
|
|---|
| 479 | initCursorFromPixmap();
|
|---|
| 480 | break; }
|
|---|
| 481 | case Qt::BlankCursor: {
|
|---|
| 482 | pixmap = QPixmap(16, 16);
|
|---|
| 483 | pixmap.fill(Qt::transparent);
|
|---|
| 484 | initCursorFromPixmap();
|
|---|
| 485 | break; }
|
|---|
| 486 | case Qt::ArrowCursor: {
|
|---|
| 487 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 488 | curs.tc.curs = kThemeArrowCursor;
|
|---|
| 489 | break; }
|
|---|
| 490 | case Qt::CrossCursor: {
|
|---|
| 491 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 492 | curs.tc.curs = kThemeCrossCursor;
|
|---|
| 493 | break; }
|
|---|
| 494 | case Qt::WaitCursor: {
|
|---|
| 495 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 496 | curs.tc.curs = kThemeWatchCursor;
|
|---|
| 497 | break; }
|
|---|
| 498 | case Qt::IBeamCursor: {
|
|---|
| 499 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 500 | curs.tc.curs = kThemeIBeamCursor;
|
|---|
| 501 | break; }
|
|---|
| 502 | case Qt::SizeAllCursor: {
|
|---|
| 503 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 504 | curs.tc.curs = kThemePlusCursor;
|
|---|
| 505 | break; }
|
|---|
| 506 | case Qt::WhatsThisCursor: { //for now just use the pointing hand
|
|---|
| 507 | case Qt::PointingHandCursor:
|
|---|
| 508 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 509 | curs.tc.curs = kThemePointingHandCursor;
|
|---|
| 510 | break; }
|
|---|
| 511 | case Qt::BusyCursor: {
|
|---|
| 512 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 513 | curs.tc.curs = kThemeSpinningCursor;
|
|---|
| 514 | break; }
|
|---|
| 515 | case Qt::SplitVCursor: {
|
|---|
| 516 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 517 | curs.tc.curs = kThemeResizeUpDownCursor;
|
|---|
| 518 | break; }
|
|---|
| 519 | case Qt::SplitHCursor: {
|
|---|
| 520 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 521 | curs.tc.curs = kThemeResizeLeftRightCursor;
|
|---|
| 522 | break; }
|
|---|
| 523 | case Qt::ForbiddenCursor: {
|
|---|
| 524 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 525 | curs.tc.curs = kThemeNotAllowedCursor;
|
|---|
| 526 | break; }
|
|---|
| 527 | case Qt::OpenHandCursor:
|
|---|
| 528 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 529 | curs.tc.curs = kThemeOpenHandCursor;
|
|---|
| 530 | break;
|
|---|
| 531 | case Qt::ClosedHandCursor:
|
|---|
| 532 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 533 | curs.tc.curs = kThemeClosedHandCursor;
|
|---|
| 534 | break;
|
|---|
| 535 | case Qt::DragMoveCursor:
|
|---|
| 536 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 537 | curs.tc.curs = kThemeArrowCursor;
|
|---|
| 538 | break;
|
|---|
| 539 | case Qt::DragCopyCursor:
|
|---|
| 540 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 541 | curs.tc.curs = kThemeCopyArrowCursor;
|
|---|
| 542 | break;
|
|---|
| 543 | case Qt::DragLinkCursor:
|
|---|
| 544 | type = QCursorData::TYPE_ThemeCursor;
|
|---|
| 545 | curs.tc.curs = kThemeAliasArrowCursor;
|
|---|
| 546 | break;
|
|---|
| 547 | #define QT_USE_APPROXIMATE_CURSORS
|
|---|
| 548 | #ifdef QT_USE_APPROXIMATE_CURSORS
|
|---|
| 549 | case Qt::SizeVerCursor:
|
|---|
| 550 | cursorData = cur_ver_bits;
|
|---|
| 551 | cursorMaskData = mcur_ver_bits;
|
|---|
| 552 | hx = hy = 8;
|
|---|
| 553 | break;
|
|---|
| 554 | case Qt::SizeHorCursor:
|
|---|
| 555 | cursorData = cur_hor_bits;
|
|---|
| 556 | cursorMaskData = mcur_hor_bits;
|
|---|
| 557 | hx = hy = 8;
|
|---|
| 558 | break;
|
|---|
| 559 | case Qt::SizeBDiagCursor:
|
|---|
| 560 | cursorData = cur_fdiag_bits;
|
|---|
| 561 | cursorMaskData = mcur_fdiag_bits;
|
|---|
| 562 | hx = hy = 8;
|
|---|
| 563 | break;
|
|---|
| 564 | case Qt::SizeFDiagCursor:
|
|---|
| 565 | cursorData = cur_bdiag_bits;
|
|---|
| 566 | cursorMaskData = mcur_bdiag_bits;
|
|---|
| 567 | hx = hy = 8;
|
|---|
| 568 | break;
|
|---|
| 569 | case Qt::UpArrowCursor:
|
|---|
| 570 | cursorData = cur_up_arrow_bits;
|
|---|
| 571 | cursorMaskData = mcur_up_arrow_bits;
|
|---|
| 572 | hx = 8;
|
|---|
| 573 | break;
|
|---|
| 574 | #endif
|
|---|
| 575 | default:
|
|---|
| 576 | qWarning("Qt: QCursor::update: Invalid cursor shape %d", cshape);
|
|---|
| 577 | return;
|
|---|
| 578 | }
|
|---|
| 579 | #endif
|
|---|
| 580 |
|
|---|
| 581 | if (cursorData) {
|
|---|
| 582 | bm = new QBitmap(QBitmap::fromData(QSize(16, 16), cursorData,
|
|---|
| 583 | QImage::Format_Mono));
|
|---|
| 584 | bmm = new QBitmap(QBitmap::fromData(QSize(16, 16), cursorMaskData,
|
|---|
| 585 | QImage::Format_Mono));
|
|---|
| 586 | initCursorFromBitmap();
|
|---|
| 587 | }
|
|---|
| 588 |
|
|---|
| 589 | #if 0
|
|---|
| 590 | if(type == QCursorData::TYPE_CursPtr && curs.cp.hcurs && curs.cp.my_cursor) {
|
|---|
| 591 | curs.cp.hcurs->hotSpot.h = hx >= 0 ? hx : 8;
|
|---|
| 592 | curs.cp.hcurs->hotSpot.v = hy >= 0 ? hy : 8;
|
|---|
| 593 | }
|
|---|
| 594 | #endif
|
|---|
| 595 | }
|
|---|
| 596 |
|
|---|
| 597 | QT_END_NAMESPACE
|
|---|