Qt 4.8
Classes | Macros | Functions | Variables
qcursor_mac.mm File Reference
#include <private/qcursor_p.h>
#include <private/qpixmap_mac_p.h>
#include <qapplication.h>
#include <qbitmap.h>
#include <qcursor.h>
#include <qevent.h>
#include <string.h>
#include <unistd.h>
#include <AppKit/NSCursor.h>
#include <qpainter.h>
#include <private/qt_cocoa_helpers_mac_p.h>
#include <private/qapplication_p.h>

Go to the source code of this file.

Classes

class  QMacAnimateCursor
 

Macros

#define QT_USE_APPROXIMATE_CURSORS
 
#define QT_USE_APPROXIMATE_CURSORS
 

Functions

void * qt_mac_nsCursorForQCursor (const QCursor &c)
 
GrafPtr qt_mac_qd_context (const QPaintDevice *)
 Returns the QuickDraw CGrafPtr of the paint device. More...
 
void qt_mac_set_cursor (const QCursor *c)
 
void qt_mac_setMouseGrabCursor (bool set, QCursor *const cursor=0)
 
void qt_mac_update_cursor ()
 
void qt_mac_update_cursor_at_global_pos (const QPoint &globalPos)
 
void qt_mac_updateCursorWithWidgetUnderMouse (QWidget *widgetUnderMouse)
 
OSWindowRef qt_mac_window_for (const QWidget *)
 
bool qt_sendSpontaneousEvent (QObject *, QEvent *)
 

Variables

static QCursorDatacurrentCursor = 0
 
static QCursorgrabCursor = 0
 
static QPointer< QWidgetlastMouseCursorWidget = 0
 
static QPointer< QWidgetlastWidgetUnderMouse = 0
 
static int nextCursorId = Qt::BitmapCursor
 
QPointer< QWidgetqt_button_down
 
static bool qt_button_down_on_prev_call = false
 
QCursorDataqt_cursorTable [Qt::LastCursor+1]
 

Macro Definition Documentation

◆ QT_USE_APPROXIMATE_CURSORS [1/2]

#define QT_USE_APPROXIMATE_CURSORS

◆ QT_USE_APPROXIMATE_CURSORS [2/2]

#define QT_USE_APPROXIMATE_CURSORS

Function Documentation

◆ qt_mac_nsCursorForQCursor()

void* qt_mac_nsCursorForQCursor ( const QCursor c)
inline

Definition at line 100 of file qcursor_mac.mm.

Referenced by qt_mac_set_cursor().

101 {
102  c.d->update();
103  return [[static_cast<NSCursor *>(c.d->curs.cp.nscursor) retain] autorelease];
104 }
void update()
Creates the cursor.
Definition: qcursor_mac.mm:387
QCursorData * d
Definition: qcursor.h:141

◆ qt_mac_qd_context()

GrafPtr qt_mac_qd_context ( const QPaintDevice device)

Returns the QuickDraw CGrafPtr of the paint device.

Warning
This function is not part of the public interface.

0 is returned if it can't be obtained. Do not hold the pointer around for long as it can be relocated.

Warning
This function is only available on Mac OS X.

Definition at line 91 of file qpaintdevice_mac.cpp.

92 {
93  if (device->devType() == QInternal::Pixmap) {
94  return static_cast<GrafPtr>(static_cast<const QPixmap *>(device)->macQDHandle());
95  } else if(device->devType() == QInternal::Widget) {
96  return static_cast<GrafPtr>(static_cast<const QWidget *>(device)->macQDHandle());
97  } else if(device->devType() == QInternal::Printer) {
98  QPaintEngine *engine = static_cast<const QPrinter *>(device)->paintEngine();
99  return static_cast<GrafPtr>(static_cast<const QMacPrintEngine *>(engine)->handle());
100  }
101  return 0;
102 }
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
virtual int devType() const
Definition: qpaintdevice.h:167
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:90
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71

◆ qt_mac_set_cursor()

void qt_mac_set_cursor ( const QCursor c)

Definition at line 108 of file qcursor_mac.mm.

Referenced by QApplicationPrivate::globalEventProcessor(), qt_mac_mouse_inside_answer_rect(), qt_mac_updateCursorWithWidgetUnderMouse(), QApplication::restoreOverrideCursor(), and QApplication::setOverrideCursor().

109 {
110 #ifdef QT_MAC_USE_COCOA
112  [static_cast<NSCursor *>(qt_mac_nsCursorForQCursor(*c)) set];
113 #else
114  if (!c) {
115  currentCursor = 0;
116  return;
117  }
118  c->handle(); //force the cursor to get loaded, if it's not
119 
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);
128  } else {
129  if(!c->d->curs.tc.anim)
130  c->d->curs.tc.anim = new QMacAnimateCursor;
131  c->d->curs.tc.anim->start(c->d->curs.tc.curs);
132  }
133  }
134 
135  currentCursor = c->d;
136 #endif
137 }
HCURSOR_or_HANDLE handle() const
Returns a platform-specific cursor handle.
Definition: qcursor_mac.mm:301
void * qt_mac_nsCursorForQCursor(const QCursor &c)
Definition: qcursor_mac.mm:100
static QCursorData * currentCursor
Definition: qcursor_mac.mm:106
QCursorData * d
Definition: qcursor.h:141

◆ qt_mac_setMouseGrabCursor()

void qt_mac_setMouseGrabCursor ( bool  set,
QCursor *const  cursor = 0 
)

Definition at line 227 of file qcursor_mac.mm.

Referenced by QWidget::grabMouse(), and QWidget::releaseMouse().

228 {
229  if (grabCursor) {
230  delete grabCursor;
231  grabCursor = 0;
232  }
233  if (set) {
234  if (cursor)
235  grabCursor = new QCursor(*cursor);
236  else if (lastMouseCursorWidget)
238  else
240  }
242 }
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition: qcursor.h:89
static QPointer< QWidget > lastMouseCursorWidget
Definition: qcursor_mac.mm:140
void qt_mac_update_cursor()
Definition: qcursor_mac.mm:201
QCursor cursor
the cursor shape for this widget
Definition: qwidget.h:183
static QCursor * grabCursor
Definition: qcursor_mac.mm:142

◆ qt_mac_update_cursor()

void qt_mac_update_cursor ( )

Definition at line 201 of file qcursor_mac.mm.

Referenced by QApplicationPrivate::globalEventProcessor(), QWidgetPrivate::hide_sys(), onApplicationChangedActivation(), onApplicationWindowChangedActivation(), qt_mac_setMouseGrabCursor(), QApplication::restoreOverrideCursor(), QWidgetPrivate::setCursor_sys(), QApplication::setOverrideCursor(), QWidgetPrivate::show_sys(), and QWidgetPrivate::unsetCursor_sys().

202 {
203  // This function is similar to qt_mac_updateCursorWithWidgetUnderMouse
204  // except that is clears the optimization cache, and finds the widget
205  // under mouse itself. Clearing the cache is useful in cases where the
206  // application has been deactivated/activated etc.
207  // NB: since we dont have any true native widget, the call to
208  // qt_mac_getTargetForMouseEvent will fail when the mouse is over QMacNativeWidgets.
209 #ifdef QT_MAC_USE_COCOA
212  QWidget *widgetUnderMouse = 0;
213 
214  if (qt_button_down) {
215  widgetUnderMouse = qt_button_down;
216  } else {
217  QPoint localPoint;
218  QPoint globalPoint;
219  qt_mac_getTargetForMouseEvent(0, QEvent::None, localPoint, globalPoint, 0, &widgetUnderMouse);
220  }
221  qt_mac_updateCursorWithWidgetUnderMouse(widgetUnderMouse);
222 #else
224 #endif
225 }
void qt_mac_updateCursorWithWidgetUnderMouse(QWidget *widgetUnderMouse)
Definition: qcursor_mac.mm:144
static QPointer< QWidget > lastWidgetUnderMouse
Definition: qcursor_mac.mm:139
static QPointer< QWidget > lastMouseCursorWidget
Definition: qcursor_mac.mm:140
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static QWidget * widgetAt(const QPoint &p)
Returns the widget at global screen position point, or 0 if there is no Qt widget there...
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QPointer< QWidget > qt_button_down
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310
qt_mac_getTargetForMouseEvent(event, QEvent::Gesture, qlocal, qglobal, 0, &widgetToGetTouch)

◆ qt_mac_update_cursor_at_global_pos()

void qt_mac_update_cursor_at_global_pos ( const QPoint globalPos)

Definition at line 245 of file qcursor_mac.mm.

246 {
248 }
void qt_mac_updateCursorWithWidgetUnderMouse(QWidget *widgetUnderMouse)
Definition: qcursor_mac.mm:144
static QWidget * widgetAt(const QPoint &p)
Returns the widget at global screen position point, or 0 if there is no Qt widget there...

◆ qt_mac_updateCursorWithWidgetUnderMouse()

void qt_mac_updateCursorWithWidgetUnderMouse ( QWidget widgetUnderMouse)

Definition at line 144 of file qcursor_mac.mm.

Referenced by flipPoint(), QMacWindowFader::performFade(), qt_mac_update_cursor(), and qt_mac_update_cursor_at_global_pos().

145 {
146  QCursor cursor(Qt::ArrowCursor);
147  if (qt_button_down) {
148  // The widget that is currently pressed
149  // grabs the mouse cursor:
150  widgetUnderMouse = qt_button_down;
152  } else if (qt_button_down_on_prev_call) {
153  // Grab has been released, so do
154  // a full check:
158  }
159 
161  cursor = *QApplication::overrideCursor();
162  } else if (grabCursor) {
163  cursor = *grabCursor;
164  } else if (widgetUnderMouse) {
165  if (widgetUnderMouse == lastWidgetUnderMouse) {
166  // Optimization that should hit when the widget under
167  // the mouse does not change as the mouse moves:
169  cursor = lastMouseCursorWidget->cursor();
170  } else {
171  QWidget *w = widgetUnderMouse;
172  for (; w; w = w->parentWidget()) {
174  cursor = w->cursor();
175  break;
176  }
177  if (w->isWindow())
178  break;
179  }
180  // One final check in case we ran out of parents in the loop:
181  if (w && !w->testAttribute(Qt::WA_SetCursor))
182  w = 0;
183 
184  lastWidgetUnderMouse = widgetUnderMouse;
186  }
187  }
188 
189 #ifdef QT_MAC_USE_COCOA
190  cursor.d->update();
191  NSCursor *nsCursor = static_cast<NSCursor *>(cursor.d->curs.cp.nscursor);
192  if ([NSCursor currentCursor] != nsCursor) {
194  [nsCursor set];
195  }
196 #else
197  qt_mac_set_cursor(&cursor);
198 #endif
199 }
void qt_mac_set_cursor(const QCursor *c)
Definition: qcursor_mac.mm:108
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition: qcursor.h:89
static QPointer< QWidget > lastWidgetUnderMouse
Definition: qcursor_mac.mm:139
static QPointer< QWidget > lastMouseCursorWidget
Definition: qcursor_mac.mm:140
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
static QCursor * overrideCursor()
Strips out vertical alignment flags and transforms an alignment align of Qt::AlignLeft into Qt::Align...
static QCursorData * currentCursor
Definition: qcursor_mac.mm:106
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
QCursor cursor
the cursor shape for this widget
Definition: qwidget.h:183
static bool qt_button_down_on_prev_call
Definition: qcursor_mac.mm:141
static QCursor * grabCursor
Definition: qcursor_mac.mm:142
QPointer< QWidget > qt_button_down

◆ qt_mac_window_for()

OSWindowRef qt_mac_window_for ( const QWidget )

Definition at line 484 of file qwidget_mac.mm.

485 {
486  if (OSViewRef hiview = qt_mac_effectiveview_for(w)) {
488  if (window)
489  return window;
490 
491  if (qt_isGenuineQWidget(hiview)) {
492  // This is a workaround for NSToolbar. When a widget is hidden
493  // by clicking the toolbar button, Cocoa reparents the widgets
494  // to another window (but Qt doesn't know about it).
495  // When we start showing them, it reparents back,
496  // but at this point it's window is nil, but the window it's being brought
497  // into (the Qt one) is for sure created.
498  // This stops the hierarchy moving under our feet.
499  QWidget *toplevel = w->window();
500  if (toplevel != w) {
501  hiview = qt_mac_nativeview_for(toplevel);
502  if (OSWindowRef w = qt_mac_window_for(hiview))
503  return w;
504  }
505 
506  toplevel->d_func()->createWindow_sys();
507  // Reget the hiview since "create window" could potentially move the view (I guess).
508  hiview = qt_mac_nativeview_for(toplevel);
509  return qt_mac_window_for(hiview);
510  }
511  }
512  return 0;
513 }
Q_GUI_EXPORT OSWindowRef qt_mac_window_for(OSViewRef view)
Definition: qwidget_mac.mm:453
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
NSWindow * window
static bool qt_isGenuineQWidget(OSViewRef ref)
Definition: qwidget_mac.mm:464
WindowRef OSWindowRef
Q_GUI_EXPORT OSViewRef qt_mac_nativeview_for(const QWidget *w)
Definition: qwidget_mac.mm:419
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
HIViewRef OSViewRef
Q_GUI_EXPORT OSViewRef qt_mac_effectiveview_for(const QWidget *w)
Definition: qwidget_mac.mm:424

◆ qt_sendSpontaneousEvent()

bool qt_sendSpontaneousEvent ( QObject ,
QEvent  
)

Definition at line 5779 of file qapplication.cpp.

Referenced by QCursor::setPos().

5780 {
5782 }
EventRef event
static bool sendSpontaneousEvent(QObject *receiver, QEvent *event)

Variable Documentation

◆ currentCursor

QCursorData* currentCursor = 0
static

Definition at line 106 of file qcursor_mac.mm.

Referenced by QtWndProc().

◆ grabCursor

QCursor* grabCursor = 0
static

◆ lastMouseCursorWidget

QPointer<QWidget> lastMouseCursorWidget = 0
static

Definition at line 140 of file qcursor_mac.mm.

◆ lastWidgetUnderMouse

QPointer<QWidget> lastWidgetUnderMouse = 0
static

Definition at line 139 of file qcursor_mac.mm.

◆ nextCursorId

int nextCursorId = Qt::BitmapCursor
static

Definition at line 251 of file qcursor_mac.mm.

Referenced by QCursorData::setBitmap().

◆ qt_button_down

QPointer<QWidget> qt_button_down

◆ qt_button_down_on_prev_call

bool qt_button_down_on_prev_call = false
static

Definition at line 141 of file qcursor_mac.mm.

Referenced by qt_mac_updateCursorWithWidgetUnderMouse().

◆ qt_cursorTable

QCursorData* qt_cursorTable[Qt::LastCursor+1]

Definition at line 398 of file qcursor.cpp.

Referenced by QCursorData::setBitmap().