42 #include <private/qcursor_p.h> 43 #include <private/qpixmap_mac_p.h> 50 #include <AppKit/NSCursor.h> 52 #include <private/qt_cocoa_helpers_mac_p.h> 53 #include <private/qapplication_p.h> 103 return [[
static_cast<NSCursor *
>(c.
d->curs.cp.nscursor) retain] autorelease];
110 #ifdef QT_MAC_USE_COCOA 120 if(currentCursor && currentCursor->type == QCursorData::TYPE_ThemeCursor
121 && currentCursor->curs.tc.anim)
122 currentCursor->curs.tc.anim->stop();
123 if(c->
d->type == QCursorData::TYPE_ImageCursor) {
124 [
static_cast<NSCursor *
>(c->
d->curs.cp.nscursor)
set];
125 }
else if(c->
d->type == QCursorData::TYPE_ThemeCursor) {
126 if(SetAnimatedThemeCursor(c->
d->curs.tc.curs, 0) == themeBadCursorIndexErr) {
127 SetThemeCursor(c->
d->curs.tc.curs);
129 if(!c->
d->curs.tc.anim)
131 c->
d->curs.tc.anim->start(c->
d->curs.tc.curs);
135 currentCursor = c->
d;
147 if (qt_button_down) {
156 lastWidgetUnderMouse = 0;
157 lastMouseCursorWidget = 0;
162 }
else if (grabCursor) {
164 }
else if (widgetUnderMouse) {
165 if (widgetUnderMouse == lastWidgetUnderMouse) {
168 if (lastMouseCursorWidget)
169 cursor = lastMouseCursorWidget->
cursor();
184 lastWidgetUnderMouse = widgetUnderMouse;
185 lastMouseCursorWidget = w;
189 #ifdef QT_MAC_USE_COCOA 191 NSCursor *nsCursor =
static_cast<NSCursor *
>(cursor.
d->curs.cp.nscursor);
192 if ([NSCursor currentCursor] != nsCursor) {
209 #ifdef QT_MAC_USE_COCOA 210 lastWidgetUnderMouse = 0;
211 lastMouseCursorWidget = 0;
214 if (qt_button_down) {
235 grabCursor =
new QCursor(*cursor);
236 else if (lastMouseCursorWidget)
244 #ifndef QT_MAC_USE_COCOA 254 : cshape(s), bm(0), bmm(0), hx(-1), hy(-1), mId(s),
type(TYPE_None)
257 memset(&curs,
'\0',
sizeof(curs));
262 if (
type == TYPE_ImageCursor) {
263 if (curs.cp.my_cursor) {
265 [
static_cast<NSCursor *
>(curs.cp.nscursor) release];
267 }
else if(
type == TYPE_ThemeCursor) {
274 if(currentCursor ==
this)
283 qWarning(
"Qt: QCursor: Cannot create bitmap cursor; invalid bitmap(s)");
296 x->
hx = hotX >= 0 ? hotX : bitmap.
width() / 2;
297 x->
hy = hotY >= 0 ? hotY : bitmap.
height() / 2;
305 if(
d->type == QCursorData::TYPE_None)
317 #ifdef QT_MAC_USE_COCOA 322 CGEventRef e = CGEventCreateMouseEvent(0, kCGEventMouseMoved, pos, 0);
323 CGEventPost(kCGHIDEventTap, e);
326 CGWarpMouseCursorPosition(CGPointMake(x, y));
345 void QCursorData::initCursorFromBitmap()
351 for (
int row = 0; row < finalCursor.height(); ++row) {
352 QRgb *bmData =
reinterpret_cast<QRgb *
>(bmi.scanLine(row));
354 QRgb *finalData =
reinterpret_cast<QRgb *
>(finalCursor.scanLine(row));
355 for (
int col = 0; col < finalCursor.width(); ++col) {
356 if (bmmData[col] == 0xff000000 && bmData[col] == 0xffffffff) {
357 finalData[col] = 0xffffffff;
358 }
else if (bmmData[col] == 0xff000000 && bmData[col] == 0xffffffff) {
359 finalData[col] = 0x7f000000;
360 }
else if (bmmData[col] == 0xffffffff && bmData[col] == 0xffffffff) {
361 finalData[col] = 0x00000000;
363 finalData[col] = 0xff000000;
367 type = QCursorData::TYPE_ImageCursor;
368 curs.cp.my_cursor =
true;
372 curs.cp.nscursor = [[NSCursor alloc] initWithImage:nsimage hotSpot: hotSpot];
376 void QCursorData::initCursorFromPixmap()
378 type = QCursorData::TYPE_ImageCursor;
379 curs.cp.my_cursor =
true;
383 curs.cp.nscursor = [[NSCursor alloc] initWithImage:nsimage hotSpot: hotSpot];
391 if(
type != QCursorData::TYPE_None)
407 #define QT_USE_APPROXIMATE_CURSORS 408 #ifdef QT_USE_APPROXIMATE_CURSORS 410 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x03, 0xc0, 0x07, 0xe0, 0x0f, 0xf0,
411 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x0f, 0xf0,
412 0x07, 0xe0, 0x03, 0xc0, 0x01, 0x80, 0x00, 0x00 };
414 0x00, 0x00, 0x03, 0x80, 0x07, 0xc0, 0x0f, 0xe0, 0x1f, 0xf0, 0x3f, 0xf8,
415 0x7f, 0xfc, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x7f, 0xfc, 0x3f, 0xf8,
416 0x1f, 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80 };
419 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x20, 0x18, 0x30,
420 0x38, 0x38, 0x7f, 0xfc, 0x7f, 0xfc, 0x38, 0x38, 0x18, 0x30, 0x08, 0x20,
421 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
423 0x00, 0x00, 0x00, 0x00, 0x04, 0x40, 0x0c, 0x60, 0x1c, 0x70, 0x3c, 0x78,
424 0x7f, 0xfc, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0x7f, 0xfc, 0x3c, 0x78,
425 0x1c, 0x70, 0x0c, 0x60, 0x04, 0x40, 0x00, 0x00 };
428 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x00, 0xf8, 0x00, 0x78,
429 0x00, 0xf8, 0x01, 0xd8, 0x23, 0x88, 0x37, 0x00, 0x3e, 0x00, 0x3c, 0x00,
430 0x3e, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00 };
432 0x00, 0x00, 0x00, 0x00, 0x07, 0xfc, 0x03, 0xfc, 0x01, 0xfc, 0x00, 0xfc,
433 0x41, 0xfc, 0x63, 0xfc, 0x77, 0xdc, 0x7f, 0x8c, 0x7f, 0x04, 0x7e, 0x00,
434 0x7f, 0x00, 0x7f, 0x80, 0x7f, 0xc0, 0x00, 0x00 };
437 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0x3e, 0x00,
438 0x37, 0x00, 0x23, 0x88, 0x01, 0xd8, 0x00, 0xf8, 0x00, 0x78, 0x00, 0xf8,
439 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
441 0x00, 0x00, 0x7f, 0xc0, 0x7f, 0x80, 0x7f, 0x00, 0x7e, 0x00, 0x7f, 0x04,
442 0x7f, 0x8c, 0x77, 0xdc, 0x63, 0xfc, 0x41, 0xfc, 0x00, 0xfc, 0x01, 0xfc,
443 0x03, 0xfc, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00 };
446 0x00, 0x80, 0x01, 0x40, 0x01, 0x40, 0x02, 0x20, 0x02, 0x20, 0x04, 0x10,
447 0x04, 0x10, 0x08, 0x08, 0x0f, 0x78, 0x01, 0x40, 0x01, 0x40, 0x01, 0x40,
448 0x01, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01, 0xc0 };
450 0x00, 0x80, 0x01, 0xc0, 0x01, 0xc0, 0x03, 0xe0, 0x03, 0xe0, 0x07, 0xf0,
451 0x07, 0xf0, 0x0f, 0xf8, 0x0f, 0xf8, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0,
452 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0 };
454 const uchar *cursorData = 0;
455 const uchar *cursorMaskData = 0;
456 #ifdef QT_MAC_USE_COCOA 460 initCursorFromBitmap();
462 initCursorFromPixmap();
467 initCursorFromPixmap();
470 type = QCursorData::TYPE_ThemeCursor;
471 curs.cp.nscursor = [NSCursor arrowCursor];
474 type = QCursorData::TYPE_ThemeCursor;
475 curs.cp.nscursor = [NSCursor crosshairCursor];
479 initCursorFromPixmap();
482 type = QCursorData::TYPE_ThemeCursor;
487 initCursorFromPixmap();
491 type = QCursorData::TYPE_ThemeCursor;
492 curs.cp.nscursor = [NSCursor pointingHandCursor];
496 initCursorFromPixmap();
499 type = QCursorData::TYPE_ThemeCursor;
500 curs.cp.nscursor = [NSCursor resizeUpDownCursor];
503 type = QCursorData::TYPE_ThemeCursor;
504 curs.cp.nscursor = [NSCursor resizeLeftRightCursor];
508 initCursorFromPixmap();
511 type = QCursorData::TYPE_ThemeCursor;
512 curs.cp.nscursor = [NSCursor openHandCursor];
515 type = QCursorData::TYPE_ThemeCursor;
516 curs.cp.nscursor = [NSCursor closedHandCursor];
519 type = QCursorData::TYPE_ThemeCursor;
520 if ([NSCursor respondsToSelector:
@selector(dragCopyCursor)])
521 curs.cp.nscursor = [NSCursor performSelector:
@selector(dragCopyCursor)];
524 type = QCursorData::TYPE_ThemeCursor;
525 curs.cp.nscursor = [NSCursor arrowCursor];
528 type = QCursorData::TYPE_ThemeCursor;
529 if ([NSCursor respondsToSelector:
@selector(dragLinkCursor)])
530 curs.cp.nscursor = [NSCursor performSelector:
@selector(dragLinkCursor)];
532 #define QT_USE_APPROXIMATE_CURSORS 533 #ifdef QT_USE_APPROXIMATE_CURSORS 569 initCursorFromBitmap();
571 initCursorFromPixmap();
576 initCursorFromPixmap();
579 type = QCursorData::TYPE_ThemeCursor;
580 curs.tc.curs = kThemeArrowCursor;
583 type = QCursorData::TYPE_ThemeCursor;
584 curs.tc.curs = kThemeCrossCursor;
587 type = QCursorData::TYPE_ThemeCursor;
588 curs.tc.curs = kThemeWatchCursor;
591 type = QCursorData::TYPE_ThemeCursor;
592 curs.tc.curs = kThemeIBeamCursor;
595 type = QCursorData::TYPE_ThemeCursor;
596 curs.tc.curs = kThemePlusCursor;
600 type = QCursorData::TYPE_ThemeCursor;
601 curs.tc.curs = kThemePointingHandCursor;
604 type = QCursorData::TYPE_ThemeCursor;
605 curs.tc.curs = kThemeSpinningCursor;
608 type = QCursorData::TYPE_ThemeCursor;
609 curs.tc.curs = kThemeResizeUpDownCursor;
612 type = QCursorData::TYPE_ThemeCursor;
613 curs.tc.curs = kThemeResizeLeftRightCursor;
616 type = QCursorData::TYPE_ThemeCursor;
617 curs.tc.curs = kThemeNotAllowedCursor;
620 type = QCursorData::TYPE_ThemeCursor;
621 curs.tc.curs = kThemeOpenHandCursor;
624 type = QCursorData::TYPE_ThemeCursor;
625 curs.tc.curs = kThemeClosedHandCursor;
628 type = QCursorData::TYPE_ThemeCursor;
629 curs.tc.curs = kThemeArrowCursor;
632 type = QCursorData::TYPE_ThemeCursor;
633 curs.tc.curs = kThemeCopyArrowCursor;
636 type = QCursorData::TYPE_ThemeCursor;
637 curs.tc.curs = kThemeAliasArrowCursor;
639 #define QT_USE_APPROXIMATE_CURSORS 640 #ifdef QT_USE_APPROXIMATE_CURSORS 678 initCursorFromBitmap();
682 if(
type == QCursorData::TYPE_CursPtr && curs.cp.hcurs && curs.cp.my_cursor) {
683 curs.cp.hcurs->hotSpot.h =
hx >= 0 ?
hx : 8;
684 curs.cp.hcurs->hotSpot.v =
hy >= 0 ?
hy : 8;
void qt_mac_updateCursorWithWidgetUnderMouse(QWidget *widgetUnderMouse)
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
void qt_mac_set_cursor(const QCursor *c)
HCURSOR_or_HANDLE handle() const
Returns a platform-specific cursor handle.
QImage toImage() const
Converts the pixmap to a QImage.
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
The QCursor class provides a mouse cursor with an arbitrary shape.
#define QT_END_NAMESPACE
This macro expands to.
static QPointer< QWidget > lastWidgetUnderMouse
static QPointer< QWidget > lastMouseCursorWidget
int width() const
Returns the width of the pixmap.
QPointer< QWidget > widget
QSize size() const
Returns the size of the pixmap.
void start(ThemeCursor c)
void * qt_mac_nsCursorForQCursor(const QCursor &c)
void qt_mac_update_cursor()
static const uchar cur_bdiag_bits[]
static QBitmap fromData(const QSize &size, const uchar *bits, QImage::Format monoFormat=QImage::Format_MonoLSB)
Constructs a bitmap with the given size, and sets the contents to the bits supplied.
static const uchar cur_hor_bits[]
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void * qt_mac_create_nsimage(const QPixmap &pm)
bool ref()
Atomically increments the value of this QAtomicInt.
static const uchar mcur_ver_bits[]
int depth() const
Returns the depth of the pixmap.
QPointF flipPoint(const NSPoint &p)
static void setPos(int x, int y)
Moves the cursor (hot spot) to the global screen position (x, y).
The QObject class is the base class of all Qt objects.
GrafPtr qt_mac_qd_context(const QPaintDevice *)
Returns the QuickDraw CGrafPtr of the paint device.
static const uchar mcur_hor_bits[]
static QWidget * widgetAt(const QPoint &p)
Returns the widget at global screen position point, or 0 if there is no Qt widget there...
static QCursorData * setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)
The QBitmap class provides monochrome (1-bit depth) pixmaps.
void timerEvent(QTimerEvent *e)
This event handler can be reimplemented in a subclass to receive timer events for the object...
static QCursor * overrideCursor()
Strips out vertical alignment flags and transforms an alignment align of Qt::AlignLeft into Qt::Align...
#define QT_BEGIN_NAMESPACE
This macro expands to.
QCursorData(Qt::CursorShape s=Qt::ArrowCursor)
static QCursorData * currentCursor
void qt_mac_setMouseGrabCursor(bool set, QCursor *const cursor=0)
Q_CORE_EXPORT void qWarning(const char *,...)
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
The QImage class provides a hardware-independent image representation that allows direct access to th...
static const unsigned char cur_up_arrow_bits[]
void update()
Creates the cursor.
The QMouseEvent class contains parameters that describe a mouse event.
static bool qt_button_down_on_prev_call
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
static Qt::KeyboardModifiers keyboardModifiers()
Returns the current state of the modifier keys on the keyboard.
The QTimerEvent class contains parameters that describe a timer event.
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
The QPoint class defines a point in the plane using integer precision.
void qt_mac_update_cursor_at_global_pos(const QPoint &globalPos)
The QPixmap class is an off-screen image representation that can be used as a paint device...
static QCursor * grabCursor
int height() const
Returns the height of the pixmap.
static const unsigned char mcur_up_arrow_bits[]
The QSize class defines the size of a two-dimensional object using integer point precision.
static const uchar mcur_bdiag_bits[]
static Qt::MouseButtons mouseButtons()
Returns the current state of the buttons on the mouse.
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
The QEvent class is the base class of all event classes.
static const uchar cur_ver_bits[]
QPointer< QWidget > qt_button_down
static const uchar mcur_fdiag_bits[]
QCursorData * qt_cursorTable[Qt::LastCursor+1]
OSWindowRef qt_mac_window_for(const QWidget *)
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
qt_mac_getTargetForMouseEvent(event, QEvent::Gesture, qlocal, qglobal, 0, &widgetToGetTouch)
void killTimer(int id)
Kills the timer with timer identifier, id.
static const uchar cur_fdiag_bits[]