diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-02-18 11:24:05 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-02-18 11:24:05 (GMT) |
commit | c18beac8163634b48bbf1e7280923e96f5ef0a51 (patch) | |
tree | ae6d5d595d1b46bcaa721efc95c98c97e078d214 /src/gui | |
parent | fd3f9dd0f31efeea3aa0ec28b54c70d85712c7ba (diff) | |
parent | eeb121d54e345e92ab74d8c43e07d803a0e144ea (diff) | |
download | Qt-c18beac8163634b48bbf1e7280923e96f5ef0a51.zip Qt-c18beac8163634b48bbf1e7280923e96f5ef0a51.tar.gz Qt-c18beac8163634b48bbf1e7280923e96f5ef0a51.tar.bz2 |
Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into master-integration
* 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1: (62 commits)
Compile.
Remove these friend declarations that aren't necessary in 4.7
Added a new flag to fine-tune gesture propagation policy
AIX has a #define for hz, so undef it
Revert "remove -lz from OPENSSL_LIBS so as to respect qt-zlib"
remove -lz from QT_LFLAGS_PSQL so as to respect qt-zlib
remove -lz from OPENSSL_LIBS so as to respect qt-zlib
Fix compilation with IBM xlC 7:
Fix compilation of Qt Assistant when WebKit isn't built.
Mac: QSystemTrayIcon::DoubleClick and midmouse not working
add test for toDateTime() using QLocale::LongFormat
remove debug info
add test case for QTBUG-7898 that QLocale::toDateTime(QString, FormatType) cannot convert value correctly
fix QTBUG-7898
QNAM HTTP: More micro optimization in QHttpNetworkRequest
QNAM HTTP: Some micro optimization in QHttpNetworkRequest
QNAM HTTP: Trivial optimization
Revert "Optimized QLocale to access system locale on demand."
doc: Added "\sa {QML Basic Types} to each QML basic type page.
Incorrect mouse coordinates used when compressing WM_MOUSEMOVE messages.
...
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/dialogs/qfiledialog_win_p.h | 2 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene.cpp | 78 | ||||
-rw-r--r-- | src/gui/kernel/qapplication_mac.mm | 2 | ||||
-rw-r--r-- | src/gui/kernel/qapplication_win.cpp | 16 | ||||
-rw-r--r-- | src/gui/kernel/qcocoaapplication_mac.mm | 45 | ||||
-rw-r--r-- | src/gui/kernel/qcocoaapplication_mac_p.h | 8 | ||||
-rw-r--r-- | src/gui/kernel/qcocoamenuloader_mac.mm | 6 | ||||
-rw-r--r-- | src/gui/kernel/qcocoamenuloader_mac_p.h | 1 | ||||
-rw-r--r-- | src/gui/kernel/qcocoasharedwindowmethods_mac_p.h | 12 | ||||
-rw-r--r-- | src/gui/kernel/qcocoaview_mac.mm | 26 | ||||
-rw-r--r-- | src/gui/kernel/qeventdispatcher_mac.mm | 3 | ||||
-rw-r--r-- | src/gui/kernel/qt_cocoa_helpers_mac.mm | 60 | ||||
-rw-r--r-- | src/gui/kernel/qt_cocoa_helpers_mac_p.h | 25 | ||||
-rw-r--r-- | src/gui/kernel/qwidget_mac.mm | 44 | ||||
-rw-r--r-- | src/gui/text/qtextdocument.cpp | 19 | ||||
-rw-r--r-- | src/gui/util/qsystemtrayicon_mac.mm | 115 | ||||
-rw-r--r-- | src/gui/widgets/qdialogbuttonbox.cpp | 28 | ||||
-rw-r--r-- | src/gui/widgets/qmenu_mac.mm | 15 | ||||
-rw-r--r-- | src/gui/widgets/qmenubar_p.h | 1 |
19 files changed, 361 insertions, 145 deletions
diff --git a/src/gui/dialogs/qfiledialog_win_p.h b/src/gui/dialogs/qfiledialog_win_p.h index 527ab3f..44b7e43 100644 --- a/src/gui/dialogs/qfiledialog_win_p.h +++ b/src/gui/dialogs/qfiledialog_win_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 9a36d46..3280e86 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -5936,6 +5936,9 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) typedef QHash<QGraphicsObject *, QList<QGesture *> > GesturesPerItem; GesturesPerItem gesturesPerItem; + // gestures that are only supposed to propagate to parent items. + QSet<QGesture *> parentPropagatedGestures; + QSet<QGesture *> startedGestures; foreach (QGesture *gesture, allGestures) { QGraphicsObject *target = gestureTargets.value(gesture, 0); @@ -5946,6 +5949,10 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) startedGestures.insert(gesture); } else { gesturesPerItem[target].append(gesture); + Qt::GestureFlags flags = + target->QGraphicsItem::d_func()->gestureContext.value(gesture->gestureType()); + if (flags & Qt::IgnoredGesturesPropagateToParent) + parentPropagatedGestures.insert(gesture); } } @@ -6035,6 +6042,10 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) Q_ASSERT(!gestureTargets.contains(g)); gestureTargets.insert(g, receiver); gesturesPerItem[receiver].append(g); + Qt::GestureFlags flags = + receiver->QGraphicsItem::d_func()->gestureContext.value(g->gestureType()); + if (flags & Qt::IgnoredGesturesPropagateToParent) + parentPropagatedGestures.insert(g); } it = ignoredConflictedGestures.begin(); e = ignoredConflictedGestures.end(); @@ -6044,13 +6055,17 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) Q_ASSERT(!gestureTargets.contains(g)); gestureTargets.insert(g, receiver); gesturesPerItem[receiver].append(g); + Qt::GestureFlags flags = + receiver->QGraphicsItem::d_func()->gestureContext.value(g->gestureType()); + if (flags & Qt::IgnoredGesturesPropagateToParent) + parentPropagatedGestures.insert(g); } DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" << "Started gestures:" << normalGestures.keys() << "All gestures:" << gesturesPerItem.values(); - // deliver all events + // deliver all gesture events QList<QGesture *> alreadyIgnoredGestures; QHash<QGraphicsObject *, QSet<QGesture *> > itemIgnoredGestures; QList<QGraphicsObject *> targetItems = gesturesPerItem.keys(); @@ -6070,9 +6085,26 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) foreach(QGesture *g, alreadyIgnoredGestures) { QMap<Qt::GestureType, Qt::GestureFlags>::iterator contextit = gid->gestureContext.find(g->gestureType()); - bool deliver = contextit != gid->gestureContext.end() && - (g->state() == Qt::GestureStarted || - (contextit.value() & Qt::ReceivePartialGestures)); + bool deliver = false; + if (contextit != gid->gestureContext.end()) { + if (g->state() == Qt::GestureStarted) { + deliver = true; + } else { + const Qt::GestureFlags flags = contextit.value(); + if (flags & Qt::ReceivePartialGestures) { + QGraphicsObject *originalTarget = gestureTargets.value(g); + Q_ASSERT(originalTarget); + QGraphicsItemPrivate *otd = originalTarget->QGraphicsItem::d_func(); + const Qt::GestureFlags originalTargetFlags = otd->gestureContext.value(g->gestureType()); + if (originalTargetFlags & Qt::IgnoredGesturesPropagateToParent) { + // only deliver to parents of the original target item + deliver = item->isAncestorOf(originalTarget); + } else { + deliver = true; + } + } + } + } if (deliver) gestures += g; } @@ -6100,18 +6132,52 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) << "item has ignored the event, will propagate." << item << ignoredGestures; itemIgnoredGestures[item] += ignoredGestures; + alreadyIgnoredGestures = ignoredGestures.toList(); + + // remove gestures that are supposed to be propagated to + // parent items only. + QSet<QGesture *> parentGestures; + for (QSet<QGesture *>::iterator it = ignoredGestures.begin(); + it != ignoredGestures.end();) { + if (parentPropagatedGestures.contains(*it)) { + parentGestures.insert(*it); + it = ignoredGestures.erase(it); + } else { + ++it; + } + } + + QSet<QGraphicsObject *> itemsSet = targetItems.toSet(); + + foreach(QGesture *g, parentGestures) { + // get the original target for the gesture + QGraphicsItem *item = gestureTargets.value(g, 0); + Q_ASSERT(item); + const Qt::GestureType gestureType = g->gestureType(); + // iterate through parent items of the original gesture + // target item and collect potential receivers + do { + if (QGraphicsObject *obj = item->toGraphicsObject()) { + if (item->d_func()->gestureContext.contains(gestureType)) + itemsSet.insert(obj); + } + if (item->isPanel()) + break; + } while ((item = item->parentItem())); + } + QMap<Qt::GestureType, QGesture *> conflictedGestures; QList<QList<QGraphicsObject *> > itemsForConflictedGestures; QHash<QGesture *, QGraphicsObject *> normalGestures; getGestureTargets(ignoredGestures, viewport, &conflictedGestures, &itemsForConflictedGestures, &normalGestures); - QSet<QGraphicsObject *> itemsSet = targetItems.toSet(); for (int k = 0; k < itemsForConflictedGestures.size(); ++k) itemsSet += itemsForConflictedGestures.at(k).toSet(); + targetItems = itemsSet.toList(); + qSort(targetItems.begin(), targetItems.end(), qt_closestItemFirst); - alreadyIgnoredGestures = conflictedGestures.values(); DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" << "new targets:" << targetItems; i = -1; // start delivery again diff --git a/src/gui/kernel/qapplication_mac.mm b/src/gui/kernel/qapplication_mac.mm index 25c98c5..e511c3a 100644 --- a/src/gui/kernel/qapplication_mac.mm +++ b/src/gui/kernel/qapplication_mac.mm @@ -1237,7 +1237,7 @@ void qt_init(QApplicationPrivate *priv, int) // Cocoa application delegate #ifdef QT_MAC_USE_COCOA - NSApplication *cocoaApp = [NSApplication sharedApplication]; + NSApplication *cocoaApp = [QNSApplication sharedApplication]; QMacCocoaAutoReleasePool pool; NSObject *oldDelegate = [cocoaApp delegate]; QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) *newDelegate = [QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate]; diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp index 0a4869b..31d245f 100644 --- a/src/gui/kernel/qapplication_win.cpp +++ b/src/gui/kernel/qapplication_win.cpp @@ -2551,6 +2551,17 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam result = true; break; } +#ifndef QT_NO_CURSOR + case WM_SETCURSOR: { + QCursor *ovr = QApplication::overrideCursor(); + if (ovr) { + SetCursor(ovr->handle()); + RETURN(TRUE); + } + result = false; + break; + } +#endif default: result = false; // event was not processed break; @@ -2973,7 +2984,10 @@ bool QETWidget::translateMouseEvent(const MSG &msg) // most recent one. msgPtr->lParam = mouseMsg.lParam; msgPtr->wParam = mouseMsg.wParam; - msgPtr->pt = mouseMsg.pt; + // Extract the x,y coordinates from the lParam as we do in the WndProc + msgPtr->pt.x = GET_X_LPARAM(mouseMsg.lParam); + msgPtr->pt.y = GET_Y_LPARAM(mouseMsg.lParam); + ClientToScreen(msg.hwnd, &(msgPtr->pt)); // Remove the mouse move message PeekMessage(&mouseMsg, msg.hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE); diff --git a/src/gui/kernel/qcocoaapplication_mac.mm b/src/gui/kernel/qcocoaapplication_mac.mm index 5b98420..5629940 100644 --- a/src/gui/kernel/qcocoaapplication_mac.mm +++ b/src/gui/kernel/qcocoaapplication_mac.mm @@ -107,5 +107,50 @@ | NSFontPanelStrikethroughEffectModeMask; } + +- (void)qt_sendPostedMessage:(NSEvent *)event +{ + // WARNING: data1 and data2 is truncated to from 64-bit to 32-bit on OS 10.5! + // That is why we need to split the address in two parts: + quint64 lower = [event data1]; + quint64 upper = [event data2]; + QCocoaPostMessageArgs *args = reinterpret_cast<QCocoaPostMessageArgs *>(lower | (upper << 32)); + [args->target performSelector:args->selector]; + delete args; +} + +- (BOOL)qt_sendEvent:(NSEvent *)event +{ + if ([event type] == NSApplicationDefined) { + switch ([event subtype]) { + case QtCocoaEventSubTypePostMessage: + [NSApp qt_sendPostedMessage:event]; + return true; + default: + break; + } + } + return false; +} + @end + +@implementation QNSApplication + +// WARNING: If Qt did not create NSApplication (this can e.g. +// happend if Qt is used as a plugin from a 3rd-party cocoa +// application), QNSApplication::sendEvent will never be called. +// SO DO NOT RELY ON THIS FUNCTION BEING AVAILABLE. +// Plugin developers that _do_ control the NSApplication sub-class +// implementation of the 3rd-party application can call qt_sendEvent +// from the sub-class event handler (like we do here) to work around +// any issues. +- (void)sendEvent:(NSEvent *)event +{ + if (![self qt_sendEvent:event]) + [super sendEvent:event]; +} + +@end + #endif diff --git a/src/gui/kernel/qcocoaapplication_mac_p.h b/src/gui/kernel/qcocoaapplication_mac_p.h index e845d58..5569feb 100644 --- a/src/gui/kernel/qcocoaapplication_mac_p.h +++ b/src/gui/kernel/qcocoaapplication_mac_p.h @@ -99,5 +99,13 @@ QT_FORWARD_DECLARE_CLASS(QApplicationPrivate) - (QApplicationPrivate *)QT_MANGLE_NAMESPACE(qt_qappPrivate); - (QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *)QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader); - (int)QT_MANGLE_NAMESPACE(qt_validModesForFontPanel):(NSFontPanel *)fontPanel; + +- (void)qt_sendPostedMessage:(NSEvent *)event; +- (BOOL)qt_sendEvent:(NSEvent *)event; +@end + +@interface QNSApplication : NSApplication { +} @end + #endif diff --git a/src/gui/kernel/qcocoamenuloader_mac.mm b/src/gui/kernel/qcocoamenuloader_mac.mm index 18b3772..573b763 100644 --- a/src/gui/kernel/qcocoamenuloader_mac.mm +++ b/src/gui/kernel/qcocoamenuloader_mac.mm @@ -46,6 +46,7 @@ #include <private/qcocoamenuloader_mac_p.h> #include <private/qapplication_p.h> #include <private/qt_mac_p.h> +#include <private/qmenubar_p.h> #include <qmenubar.h> QT_FORWARD_DECLARE_CLASS(QCFString) @@ -208,6 +209,11 @@ QT_USE_NAMESPACE [NSApp hide:sender]; } +- (void)qtUpdateMenubar +{ + QMenuBarPrivate::macUpdateMenuBarImmediatly(); +} + - (IBAction)qtDispatcherToQAction:(id)sender { QScopedLoopLevelCounter loopLevelCounter(QApplicationPrivate::instance()->threadData); diff --git a/src/gui/kernel/qcocoamenuloader_mac_p.h b/src/gui/kernel/qcocoamenuloader_mac_p.h index 81c136e..2504b8c 100644 --- a/src/gui/kernel/qcocoamenuloader_mac_p.h +++ b/src/gui/kernel/qcocoamenuloader_mac_p.h @@ -85,6 +85,7 @@ - (IBAction)unhideAllApplications:(id)sender; - (IBAction)hide:(id)sender; - (IBAction)qtDispatcherToQAction:(id)sender; +- (void)qtUpdateMenubar; @end #endif // QT_MAC_USE_COCOA diff --git a/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h b/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h index a1d2c61..9fe5ae0 100644 --- a/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h +++ b/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h @@ -183,8 +183,18 @@ QT_END_NAMESPACE - (void)sendEvent:(NSEvent *)event { - QWidget *widget = [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] qt_qwidgetForWindow:self]; + if ([event type] == NSApplicationDefined) { + switch ([event subtype]) { + case QtCocoaEventSubTypePostMessage: + [NSApp qt_sendPostedMessage:event]; + return; + default: + break; + } + return; + } + QWidget *widget = [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] qt_qwidgetForWindow:self]; // Cocoa can hold onto the window after we've disavowed its knowledge. So, // if we get sent an event afterwards just have it go through the super's // version and don't do any stuff with Qt. diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm index 873fb7e..d5e7534 100644 --- a/src/gui/kernel/qcocoaview_mac.mm +++ b/src/gui/kernel/qcocoaview_mac.mm @@ -84,21 +84,6 @@ extern OSViewRef qt_mac_nativeview_for(const QWidget *w); // qwidget_mac.mm extern QPointer<QWidget> qt_mouseover; //qapplication_mac.mm extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp -Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum) -{ - if (buttonNum == 0) - return Qt::LeftButton; - if (buttonNum == 1) - return Qt::RightButton; - if (buttonNum == 2) - return Qt::MidButton; - if (buttonNum == 3) - return Qt::XButton1; - if (buttonNum == 4) - return Qt::XButton2; - return Qt::NoButton; -} - struct dndenum_mapper { NSDragOperation mac_code; @@ -489,7 +474,15 @@ extern "C" { qWarning("QWidget::repaint: Recursive repaint detected"); const QRect qrect = QRect(aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height); - QRegion qrgn(qrect); + QRegion qrgn; + + const NSRect *rects; + NSInteger count; + [self getRectsBeingDrawn:&rects count:&count]; + for (int i = 0; i < count; ++i) { + QRect tmpRect = QRect(rects[i].origin.x, rects[i].origin.y, rects[i].size.width, rects[i].size.height); + qrgn += tmpRect; + } if (!qwidget->isWindow() && !qobject_cast<QAbstractScrollArea *>(qwidget->parent())) { const QRegion &parentMask = qwidget->window()->mask(); @@ -699,6 +692,7 @@ extern "C" { qt_button_down = 0; } +extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); - (void)otherMouseDown:(NSEvent *)theEvent { if (!qt_button_down) diff --git a/src/gui/kernel/qeventdispatcher_mac.mm b/src/gui/kernel/qeventdispatcher_mac.mm index c7d042d..8a67dee 100644 --- a/src/gui/kernel/qeventdispatcher_mac.mm +++ b/src/gui/kernel/qeventdispatcher_mac.mm @@ -1064,10 +1064,9 @@ void QEventDispatcherMacPrivate::cancelWaitForMoreEvents() // In case the event dispatcher is waiting for more // events somewhere, we post a dummy event to wake it up: QMacCocoaAutoReleasePool pool; - static const short NSAppShouldStopForQt = SHRT_MAX; [NSApp postEvent:[NSEvent otherEventWithType:NSApplicationDefined location:NSZeroPoint modifierFlags:0 timestamp:0. windowNumber:0 context:0 - subtype:NSAppShouldStopForQt data1:0 data2:0] atStart:NO]; + subtype:QtCocoaEventSubTypeWakeup data1:0 data2:0] atStart:NO]; } #endif diff --git a/src/gui/kernel/qt_cocoa_helpers_mac.mm b/src/gui/kernel/qt_cocoa_helpers_mac.mm index 4e51cf4..901bf0e 100644 --- a/src/gui/kernel/qt_cocoa_helpers_mac.mm +++ b/src/gui/kernel/qt_cocoa_helpers_mac.mm @@ -83,6 +83,7 @@ #include <private/qt_cocoa_helpers_mac_p.h> #include <private/qt_mac_p.h> #include <private/qapplication_p.h> +#include <private/qcocoaapplication_mac_p.h> #include <private/qcocoawindow_mac_p.h> #include <private/qcocoaview_mac_p.h> #include <private/qkeymapper_p.h> @@ -647,6 +648,21 @@ bool qt_dispatchKeyEventWithCocoa(void * /*NSEvent * */ keyEvent, QWidget *widge } #endif +Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum) +{ + if (buttonNum == 0) + return Qt::LeftButton; + if (buttonNum == 1) + return Qt::RightButton; + if (buttonNum == 2) + return Qt::MidButton; + if (buttonNum == 3) + return Qt::XButton1; + if (buttonNum == 4) + return Qt::XButton2; + return Qt::NoButton; +} + // Helper to share code between QCocoaWindow and QCocoaView bool qt_dispatchKeyEvent(void * /*NSEvent * */ keyEvent, QWidget *widgetToGetEvent) { @@ -1279,22 +1295,42 @@ void qt_cocoaChangeOverrideCursor(const QCursor &cursor) QMacCocoaAutoReleasePool pool; [static_cast<NSCursor *>(qt_mac_nsCursorForQCursor(cursor)) set]; } -#endif -@implementation DebugNSApplication { -} -- (void)sendEvent:(NSEvent *)event +// WARNING: If Qt did not create NSApplication (e.g. in case it is +// used as a plugin), and at the same time, there is no window on +// screen (or the window that the event is sendt to becomes hidden etc +// before the event gets delivered), the message will not be performed. +bool qt_cocoaPostMessage(id target, SEL selector) { - NSLog(@"NSAppDebug: sendEvent: %@", event); - return [super sendEvent:event]; -} + if (!target) + return false; -- (BOOL)sendAction:(SEL)anAction to:(id)aTarget from:(id)sender -{ - NSLog(@"NSAppDebug: sendAction: %s to %@ from %@", anAction, aTarget, sender); - return [super sendAction:anAction to:aTarget from:sender]; + NSInteger windowNumber = 0; + if (![NSApp isMemberOfClass:[QNSApplication class]]) { + // INVARIANT: Cocoa is not using our NSApplication subclass. That means + // we don't control the main event handler either. So target the event + // for one of the windows on screen: + NSWindow *nswin = [NSApp mainWindow]; + if (!nswin) { + nswin = [NSApp keyWindow]; + if (!nswin) + return false; + } + windowNumber = [nswin windowNumber]; + } + + // WARNING: data1 and data2 is truncated to from 64-bit to 32-bit on OS 10.5! + // That is why we need to split the address in two parts: + QCocoaPostMessageArgs *args = new QCocoaPostMessageArgs(target, selector); + quint32 lower = quintptr(args); + quint32 upper = quintptr(args) >> 32; + NSEvent *e = [NSEvent otherEventWithType:NSApplicationDefined + location:NSZeroPoint modifierFlags:0 timestamp:0 windowNumber:windowNumber + context:nil subtype:QtCocoaEventSubTypePostMessage data1:lower data2:upper]; + [NSApp postEvent:e atStart:NO]; + return true; } -@end +#endif QMacCocoaAutoReleasePool::QMacCocoaAutoReleasePool() { diff --git a/src/gui/kernel/qt_cocoa_helpers_mac_p.h b/src/gui/kernel/qt_cocoa_helpers_mac_p.h index ace8255..c43ea55 100644 --- a/src/gui/kernel/qt_cocoa_helpers_mac_p.h +++ b/src/gui/kernel/qt_cocoa_helpers_mac_p.h @@ -114,6 +114,12 @@ typedef struct CGPoint NSPoint; #endif QT_BEGIN_NAMESPACE + +enum { + QtCocoaEventSubTypeWakeup = SHRT_MAX, + QtCocoaEventSubTypePostMessage = SHRT_MAX-1 +}; + Qt::MouseButtons qt_mac_get_buttons(int buttons); Qt::MouseButton qt_mac_get_button(EventMouseButton button); void macWindowFade(void * /*OSWindowRef*/ window, float durationSeconds = 0.15); @@ -182,8 +188,23 @@ inline QString qt_mac_NSStringToQString(const NSString *nsstr) inline NSString *qt_mac_QStringToNSString(const QString &qstr) { return [reinterpret_cast<const NSString *>(QCFString::toCFStringRef(qstr)) autorelease]; } -@interface DebugNSApplication : NSApplication {} -@end +#ifdef QT_MAC_USE_COCOA +class QCocoaPostMessageArgs { +public: + id target; + SEL selector; + QCocoaPostMessageArgs(id target, SEL selector) : target(target), selector(selector) + { + [target retain]; + } + + ~QCocoaPostMessageArgs() + { + [target release]; + } +}; +bool qt_cocoaPostMessage(id target, SEL selector); +#endif #endif diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index a5633d3..9e642b9 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -3346,38 +3346,20 @@ void QWidgetPrivate::show_sys() return; bool realWindow = isRealWindow(); +#ifndef QT_MAC_USE_COCOA if (realWindow && !q->testAttribute(Qt::WA_Moved)) { + if (qt_mac_is_macsheet(q)) + recreateMacWindow(); q->createWinId(); if (QWidget *p = q->parentWidget()) { p->createWinId(); -#ifndef QT_MAC_USE_COCOA RepositionWindow(qt_mac_window_for(q), qt_mac_window_for(p), kWindowCenterOnParentWindow); -#else - CGRect parentFrame = NSRectToCGRect([qt_mac_window_for(p) frame]); - OSWindowRef windowRef = qt_mac_window_for(q); - NSRect windowFrame = [windowRef frame]; - NSPoint parentCenter = NSMakePoint(CGRectGetMidX(parentFrame), CGRectGetMidY(parentFrame)); - [windowRef setFrameTopLeftPoint:NSMakePoint(parentCenter.x - (windowFrame.size.width / 2), - (parentCenter.y + (windowFrame.size.height / 2)))]; -#endif } else { -#ifndef QT_MAC_USE_COCOA RepositionWindow(qt_mac_window_for(q), 0, kWindowCenterOnMainScreen); -#else - // Ideally we would do a "center" here, but NSWindow's center is more equivalent to - // kWindowAlertPositionOnMainScreen instead of kWindowCenterOnMainScreen. - QRect availGeo = QApplication::desktop()->availableGeometry(q); - // Center the content only. - data.crect.moveCenter(availGeo.center()); - QRect fStrut = frameStrut(); - QRect frameRect(data.crect.x() - fStrut.left(), data.crect.y() - fStrut.top(), - fStrut.left() + fStrut.right() + data.crect.width(), - fStrut.top() + fStrut.bottom() + data.crect.height()); - NSRect cocoaFrameRect = NSMakeRect(frameRect.x(), flipYCoordinate(frameRect.bottom() + 1), frameRect.width(), frameRect.height()); - [qt_mac_window_for(q) setFrame:cocoaFrameRect display:NO]; -#endif } } +#endif + data.fstrut_dirty = true; if (realWindow) { // Delegates can change window state, so record some things earlier. @@ -4270,6 +4252,22 @@ void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove) setGeometry_sys_helper(x, y, w, h, isMove); } #else + if (!isMove && !q->testAttribute(Qt::WA_Moved) && !q->isVisible()) { + // INVARIANT: The location of the window has not yet been set. The default will + // instead be to center it on the desktop, or over the parent, if any. Since we now + // resize the window, we need to adjust the top left position to keep the window + // centeralized. And we need to to this now (and before show) in case the positioning + // of other windows (e.g. sub-windows) depend on this position: + if (QWidget *p = q->parentWidget()) { + x = p->geometry().center().x() - (w / 2); + y = p->geometry().center().y() - (h / 2); + } else { + QRect availGeo = QApplication::desktop()->availableGeometry(q); + x = availGeo.center().x() - (w / 2); + y = availGeo.center().y() - (h / 2); + } + } + QSize olds = q->size(); const bool isResize = (olds != QSize(w, h)); NSWindow *window = qt_mac_window_for(q); diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 80931c9..e1cfa9c 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -435,16 +435,23 @@ void QTextDocument::redo(QTextCursor *cursor) } } +/*! \enum QTextDocument::Stacks + + \value UndoStack The undo stack. + \value RedoStack The redo stack. + \value UndoAndRedoStacks Both the undo and redo stacks. +*/ + /*! \since 4.7 - Clears the specified stacks. + Clears the stacks specified by \a stacksToClear. - This method clears any commands on the undo stack, the redo stack, or both (the - default). If any commands got cleared, the appropriate signals - (\a QTextDocument::undoAvailable or \a QTextDocument::redoAvailable) get - emitted. + This method clears any commands on the undo stack, the redo stack, + or both (the default). If commands are cleared, the appropriate + signals are emitted, QTextDocument::undoAvailable() or + QTextDocument::redoAvailable(). - \sa QTextDocument::undoAvailable QTextDocument::redoAvailable + \sa QTextDocument::undoAvailable() QTextDocument::redoAvailable() */ void QTextDocument::clearUndoRedoStacks(Stacks stacksToClear) { diff --git a/src/gui/util/qsystemtrayicon_mac.mm b/src/gui/util/qsystemtrayicon_mac.mm index 0265a83..5cadbbd 100644 --- a/src/gui/util/qsystemtrayicon_mac.mm +++ b/src/gui/util/qsystemtrayicon_mac.mm @@ -110,7 +110,7 @@ QT_USE_NAMESPACE -(QSystemTrayIcon*)icon; -(NSStatusItem*)item; -(QRectF)geometry; -- (void)triggerSelector:(id)sender; +- (void)triggerSelector:(id)sender button:(Qt::MouseButton)mouseButton; - (void)doubleClickSelector:(id)sender; @end @@ -121,7 +121,7 @@ QT_USE_NAMESPACE -(id)initWithParent:(QNSStatusItem*)myParent; -(QSystemTrayIcon*)icon; -(void)menuTrackingDone:(NSNotification*)notification; --(void)mousePressed:(NSEvent *)mouseEvent; +-(void)mousePressed:(NSEvent *)mouseEvent button:(Qt::MouseButton)mouseButton; @end @@ -333,12 +333,10 @@ QT_END_NAMESPACE [self setNeedsDisplay:YES]; } --(void)mousePressed:(NSEvent *)mouseEvent +-(void)mousePressed:(NSEvent *)mouseEvent button:(Qt::MouseButton)mouseButton { - int clickCount = [mouseEvent clickCount]; - down = !down; - if(!down && [self icon]->contextMenu()) - [self icon]->contextMenu()->hide(); + down = YES; + int clickCount = [mouseEvent clickCount]; [self setNeedsDisplay:YES]; #ifndef QT_MAC_USE_COCOA @@ -348,47 +346,53 @@ QT_END_NAMESPACE const short scale = hgt - 4; #endif - if( down && ![self icon]->icon().isNull() ) { + if (![self icon]->icon().isNull() ) { NSImage *nsaltimage = static_cast<NSImage *>(qt_mac_create_nsimage([self icon]->icon().pixmap(QSize(scale, scale), QIcon::Selected))); [self setImage: nsaltimage]; [nsaltimage release]; } - - if (down) - [parent triggerSelector:self]; - else if ((clickCount%2)) + if ((clickCount == 2)) { + [self menuTrackingDone:nil]; [parent doubleClickSelector:self]; - while (down) { - mouseEvent = [[self window] nextEventMatchingMask:NSLeftMouseDownMask | NSLeftMouseUpMask - | NSLeftMouseDraggedMask | NSRightMouseDownMask | NSRightMouseUpMask - | NSRightMouseDraggedMask]; - switch ([mouseEvent type]) { - case NSRightMouseDown: - case NSRightMouseUp: - case NSLeftMouseDown: - case NSLeftMouseUp: - [self menuTrackingDone:nil]; - break; - case NSRightMouseDragged: - case NSLeftMouseDragged: - default: - /* Ignore any other kind of event. */ - break; - } - }; + } else { + [parent triggerSelector:self button:mouseButton]; + } } -(void)mouseDown:(NSEvent *)mouseEvent { - [self mousePressed:mouseEvent]; + [self mousePressed:mouseEvent button:Qt::LeftButton]; +} + +-(void)mouseUp:(NSEvent *)mouseEvent +{ + Q_UNUSED(mouseEvent); + [self menuTrackingDone:nil]; } - (void)rightMouseDown:(NSEvent *)mouseEvent { - [self mousePressed:mouseEvent]; + [self mousePressed:mouseEvent button:Qt::RightButton]; +} + +-(void)rightMouseUp:(NSEvent *)mouseEvent +{ + Q_UNUSED(mouseEvent); + [self menuTrackingDone:nil]; } +extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); +- (void)otherMouseDown:(NSEvent *)mouseEvent +{ + [self mousePressed:mouseEvent button:cocoaButton2QtButton([mouseEvent buttonNumber])]; +} + +-(void)otherMouseUp:(NSEvent *)mouseEvent +{ + Q_UNUSED(mouseEvent); + [self menuTrackingDone:nil]; +} -(void)drawRect:(NSRect)rect { [[parent item] drawStatusBarBackgroundInRect:rect withHighlight:down]; @@ -433,45 +437,40 @@ QT_END_NAMESPACE } return QRectF(); } -- (void)triggerSelector:(id)sender { + +- (void)triggerSelector:(id)sender button:(Qt::MouseButton)mouseButton { Q_UNUSED(sender); - if(!icon) + if (!icon) return; - qtsystray_sendActivated(icon, QSystemTrayIcon::Trigger); + + if (mouseButton == Qt::MidButton) + qtsystray_sendActivated(icon, QSystemTrayIcon::MiddleClick); + else + qtsystray_sendActivated(icon, QSystemTrayIcon::Trigger); + if (icon->contextMenu()) { -#if 0 - const QRectF geom = [self geometry]; - if(!geom.isNull()) { - [[NSNotificationCenter defaultCenter] addObserver:imageCell - selector:@selector(menuTrackingDone:) - name:nil - object:self]; - icon->contextMenu()->exec(geom.topLeft().toPoint(), 0); - [imageCell menuTrackingDone:nil]; - } else -#endif - { #ifndef QT_MAC_USE_COCOA - [[[self item] view] removeAllToolTips]; - iconPrivate->updateToolTip_sys(); + [[[self item] view] removeAllToolTips]; + iconPrivate->updateToolTip_sys(); #endif - NSMenu *m = [[QNSMenu alloc] initWithQMenu:icon->contextMenu()]; - [m setAutoenablesItems: NO]; - [[NSNotificationCenter defaultCenter] addObserver:imageCell - selector:@selector(menuTrackingDone:) - name:NSMenuDidEndTrackingNotification - object:m]; - [item popUpStatusItemMenu: m]; - [m release]; - } + NSMenu *m = [[QNSMenu alloc] initWithQMenu:icon->contextMenu()]; + [m setAutoenablesItems: NO]; + [[NSNotificationCenter defaultCenter] addObserver:imageCell + selector:@selector(menuTrackingDone:) + name:NSMenuDidEndTrackingNotification + object:m]; + [item popUpStatusItemMenu: m]; + [m release]; } } + - (void)doubleClickSelector:(id)sender { Q_UNUSED(sender); if(!icon) return; qtsystray_sendActivated(icon, QSystemTrayIcon::DoubleClick); } + @end class QSystemTrayIconQMenu : public QMenu diff --git a/src/gui/widgets/qdialogbuttonbox.cpp b/src/gui/widgets/qdialogbuttonbox.cpp index 6a0e363..cc74a53 100644 --- a/src/gui/widgets/qdialogbuttonbox.cpp +++ b/src/gui/widgets/qdialogbuttonbox.cpp @@ -103,7 +103,7 @@ QT_BEGIN_NAMESPACE You can mix and match normal buttons and standard buttons. Currently the buttons are laid out in the following way if the button box is horizontal: - \table 100% + \table \row \o \inlineimage buttonbox-gnomelayout-horizontal.png GnomeLayout Horizontal \o Button box laid out in horizontal GnomeLayout \row \o \inlineimage buttonbox-kdelayout-horizontal.png KdeLayout Horizontal @@ -116,25 +116,23 @@ QT_BEGIN_NAMESPACE The buttons are laid out the following way if the button box is vertical: - \table 100% + \table + \row \o GnomeLayout + \o KdeLayout + \o MacLayout + \o WinLayout \row \o \inlineimage buttonbox-gnomelayout-vertical.png GnomeLayout Vertical - \o Button box laid out in vertical GnomeLayout - \row \o \inlineimage buttonbox-kdelayout-vertical.png KdeLayout Vertical - \o Button box laid out in vertical KdeLayout - \row \o \inlineimage buttonbox-maclayout-vertical.png MacLayout Vertical - \o Button box laid out in vertical MacLayout - \row \o \inlineimage buttonbox-winlayout-vertical.png WinLayout Vertical - \o Button box laid out in vertical WinLayout + \o \inlineimage buttonbox-kdelayout-vertical.png KdeLayout Vertical + \o \inlineimage buttonbox-maclayout-vertical.png MacLayout Vertical + \o \inlineimage buttonbox-winlayout-vertical.png WinLayout Vertical \endtable Additionally, button boxes that contain only buttons with ActionRole or - HelpRole can be considered modeless and have an alternate look on the mac: + HelpRole can be considered modeless and have an alternate look on Mac OS X: - \table 100% - \row \o \inlineimage buttonbox-mac-modeless-horizontal.png Screenshot of modeless horizontal MacLayout - \o modeless horizontal MacLayout - \row \o \inlineimage buttonbox-mac-modeless-vertical.png Screenshot of modeless vertical MacLayout - \o modeless vertical MacLayout + \table + \row \o modeless horizontal MacLayout + \o \inlineimage buttonbox-mac-modeless-horizontal.png Screenshot of modeless horizontal MacLayout \endtable When a button is clicked in the button box, the clicked() signal is emitted diff --git a/src/gui/widgets/qmenu_mac.mm b/src/gui/widgets/qmenu_mac.mm index 658a020..99c550f 100644 --- a/src/gui/widgets/qmenu_mac.mm +++ b/src/gui/widgets/qmenu_mac.mm @@ -2030,6 +2030,18 @@ void qt_mac_clear_menubar() */ bool QMenuBar::macUpdateMenuBar() { +#ifdef QT_MAC_USE_COCOA + QMacCocoaAutoReleasePool pool; + if (!qt_cocoaPostMessage(getMenuLoader(), @selector(qtUpdateMenubar))) + return QMenuBarPrivate::macUpdateMenuBarImmediatly(); + return true; +#else + return QMenuBarPrivate::macUpdateMenuBarImmediatly(); +#endif +} + +bool QMenuBarPrivate::macUpdateMenuBarImmediatly() +{ bool ret = false; cancelAllMenuTracking(); QWidget *w = findWindowThatShouldDisplayMenubar(); @@ -2095,8 +2107,9 @@ bool QMenuBar::macUpdateMenuBar() } } - if(!ret) + if (!ret) { qt_mac_clear_menubar(); + } return ret; } diff --git a/src/gui/widgets/qmenubar_p.h b/src/gui/widgets/qmenubar_p.h index f2e5357..819aee4 100644 --- a/src/gui/widgets/qmenubar_p.h +++ b/src/gui/widgets/qmenubar_p.h @@ -196,6 +196,7 @@ public: return 0; } } *mac_menubar; + static bool macUpdateMenuBarImmediatly(); bool macWidgetHasNativeMenubar(QWidget *widget); void macCreateMenuBar(QWidget *); void macDestroyMenuBar(); |