summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@nokia.com>2010-01-28 09:40:41 (GMT)
committerRichard Moe Gustavsen <richard.gustavsen@nokia.com>2010-01-28 10:10:06 (GMT)
commit5ed327e29906717d3b95b910e147de6314512a61 (patch)
treef0a8527ba8008cfae08ae568f90a655b637a0ed1 /src/gui
parente60ea3cef1dec60b0f00ddc8fa48ed639ea06ddc (diff)
downloadQt-5ed327e29906717d3b95b910e147de6314512a61.zip
Qt-5ed327e29906717d3b95b910e147de6314512a61.tar.gz
Qt-5ed327e29906717d3b95b910e147de6314512a61.tar.bz2
Cocoa: implement usage of override cursors
This have never worked in the Cocoa port, it seems. This patch gives it a try. Reviewed-by: msorvig
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/qapplication_mac.mm38
-rw-r--r--src/gui/kernel/qapplication_p.h3
-rw-r--r--src/gui/kernel/qeventdispatcher_mac.mm2
-rw-r--r--src/gui/kernel/qwidget_mac.mm3
4 files changed, 43 insertions, 3 deletions
diff --git a/src/gui/kernel/qapplication_mac.mm b/src/gui/kernel/qapplication_mac.mm
index e72194e..961a3f6 100644
--- a/src/gui/kernel/qapplication_mac.mm
+++ b/src/gui/kernel/qapplication_mac.mm
@@ -1337,12 +1337,39 @@ void QApplication::setMainWidget(QWidget *mainWidget)
/*****************************************************************************
QApplication cursor stack
*****************************************************************************/
+#ifdef QT_MAC_USE_COCOA
+void QApplicationPrivate::disableUsageOfCursorRects(bool disable)
+{
+ // In Cocoa there are two competing ways of setting the cursor; either
+ // by using cursor rects (see qcocoaview_mac.mm), or by pushing/popping
+ // the cursor manually. When we use override cursors, it makes most sense
+ // to use the latter. But then we need to tell cocoa to stop using the
+ // first approach so it doesn't change the cursor back when hovering over
+ // a cursor rect:
+ QWidgetList topLevels = qApp->topLevelWidgets();
+ for (int i=0; i<topLevels.size(); ++i) {
+ if (NSWindow *window = qt_mac_window_for(topLevels.at(i)))
+ disable ? [window disableCursorRects] : [window enableCursorRects];
+ }
+}
+
+void QApplicationPrivate::updateOverrideCursor()
+{
+ // Sometimes Cocoa forgets that we have set a Cursor
+ // manually. In those cases, remind it again:
+ if (QCursor *override = qApp->overrideCursor())
+ [static_cast<NSCursor *>(qt_mac_nsCursorForQCursor(*override)) set];
+}
+#endif
+
void QApplication::setOverrideCursor(const QCursor &cursor)
{
qApp->d_func()->cursor_list.prepend(cursor);
#ifdef QT_MAC_USE_COCOA
QMacCocoaAutoReleasePool pool;
+ if (qApp->d_func()->cursor_list.size() == 1)
+ qApp->d_func()->disableUsageOfCursorRects(true);
[static_cast<NSCursor *>(qt_mac_nsCursorForQCursor(cursor)) push];
#else
if (qApp && qApp->activeWindow())
@@ -1359,6 +1386,8 @@ void QApplication::restoreOverrideCursor()
#ifdef QT_MAC_USE_COCOA
QMacCocoaAutoReleasePool pool;
[NSCursor pop];
+ if (qApp->d_func()->cursor_list.isEmpty())
+ qApp->d_func()->disableUsageOfCursorRects(false);
#else
if (qApp && qApp->activeWindow()) {
const QCursor def(Qt::ArrowCursor);
@@ -2432,6 +2461,12 @@ QApplicationPrivate::globalEventProcessor(EventHandlerCallRef er, EventRef event
}
#ifdef QT_MAC_USE_COCOA
+void QApplicationPrivate::qt_initAfterNSAppStarted()
+{
+ setupAppleEvents();
+ updateOverrideCursor();
+}
+
void QApplicationPrivate::setupAppleEvents()
{
// This function is called from the event dispatcher when NSApplication has
@@ -2444,7 +2479,6 @@ void QApplicationPrivate::setupAppleEvents()
forEventClass:kCoreEventClass andEventID:kAEQuitApplication];
[eventManager setEventHandler:newDelegate andSelector:@selector(getUrl:withReplyEvent:)
forEventClass:kInternetEventClass andEventID:kAEGetURL];
-
}
#endif
@@ -2995,7 +3029,7 @@ void onApplicationWindowChangedActivation(QWidget *widget, bool activated)
}
QMenuBar::macUpdateMenuBar();
-
+ QApplicationPrivate::updateOverrideCursor();
#else
Q_UNUSED(widget);
Q_UNUSED(activated);
diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h
index a796048..59565d4 100644
--- a/src/gui/kernel/qapplication_p.h
+++ b/src/gui/kernel/qapplication_p.h
@@ -458,7 +458,10 @@ public:
static OSStatus globalAppleEventProcessor(const AppleEvent *, AppleEvent *, long);
static OSStatus tabletProximityCallback(EventHandlerCallRef, EventRef, void *);
#ifdef QT_MAC_USE_COCOA
+ static void qt_initAfterNSAppStarted();
static void setupAppleEvents();
+ static void updateOverrideCursor();
+ static void disableUsageOfCursorRects(bool disable);
#endif
static bool qt_mac_apply_settings();
#endif
diff --git a/src/gui/kernel/qeventdispatcher_mac.mm b/src/gui/kernel/qeventdispatcher_mac.mm
index 84d37ae..2a1da41 100644
--- a/src/gui/kernel/qeventdispatcher_mac.mm
+++ b/src/gui/kernel/qeventdispatcher_mac.mm
@@ -1049,7 +1049,7 @@ void QEventDispatcherMacPrivate::firstLoopEntry(CFRunLoopObserverRef ref,
Q_UNUSED(ref);
Q_UNUSED(activity);
#ifdef QT_MAC_USE_COCOA
- QApplicationPrivate::setupAppleEvents();
+ QApplicationPrivate::qt_initAfterNSAppStarted();
#endif
processPostedEvents(static_cast<QEventDispatcherMacPrivate *>(info), blockSendPostedEvents);
}
diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm
index 20c0cde..5b5ab40 100644
--- a/src/gui/kernel/qwidget_mac.mm
+++ b/src/gui/kernel/qwidget_mac.mm
@@ -2311,6 +2311,9 @@ void QWidgetPrivate::finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ voidWin
q->setAttribute(Qt::WA_WState_WindowOpacitySet, false);
}
+ if (qApp->overrideCursor())
+ [windowRef disableCursorRects];
+
setWindowLevel();
macUpdateHideOnSuspend();
macUpdateOpaqueSizeGrip();