From 5e9f7b9579f654d3b7b9c7a8a05949f2b780c75d Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Fri, 27 Mar 2015 12:12:32 +0100 Subject: [PATCH] Cocoa integration - menus and Qt::Tool windows If an app has only Qt::Tool window(s) at start, menu is not updated, since Qt::Tool is also a Qt::Popup (included) and we have a special logic for Qt::Popup in QCocoaMenuBar::updateMenuBarImmediately. Using QCocoaApplicationDelegate (ivar 'inLaunch') we can avoid this problem. Change-Id: Ie1c4ef241cd19fa0af93c54de2b36e6e932cb77c Task-number: QTBUG-32539 Reviewed-by: Shawn Rutledge Reviewed-by: Gabriel de Dietrich --- .../cocoa/qcocoaapplicationdelegate.h | 1 + .../cocoa/qcocoaapplicationdelegate.mm | 5 +++++ src/plugins/platforms/cocoa/qcocoamenubar.mm | 18 ++++++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.h b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.h index 04e51d53924..abaaba91a57 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.h +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.h @@ -100,6 +100,7 @@ - (void)setReflectionDelegate:(NSObject *)oldDelegate; - (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent; - (void) removeAppleEventHandlers; +- (bool) inLaunch; @end QT_NAMESPACE_ALIAS_OBJC_CLASS(QCocoaApplicationDelegate); diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index f3a02168702..67d9de859fa 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -284,6 +284,11 @@ QT_END_NAMESPACE [eventManager removeEventHandlerForEventClass:kInternetEventClass andEventID:kAEGetURL]; } +- (bool) inLaunch +{ + return inLaunch; +} + - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { Q_UNUSED(aNotification); diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.mm b/src/plugins/platforms/cocoa/qcocoamenubar.mm index 764a01370d2..7c902a0e537 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.mm +++ b/src/plugins/platforms/cocoa/qcocoamenubar.mm @@ -38,6 +38,7 @@ #include "qcocoamenuloader.h" #include "qcocoaapplication.h" // for custom application category #include "qcocoaautoreleasepool.h" +#include "qcocoaapplicationdelegate.h" #include #include @@ -265,8 +266,21 @@ void QCocoaMenuBar::updateMenuBarImmediately() QCocoaWindow *cw = findWindowForMenubar(); QWindow *win = cw ? cw->window() : 0; - if (win && (win->flags() & Qt::Popup) == Qt::Popup) - return; // context menus, comboboxes, etc. don't need to update the menubar + if (win && (win->flags() & Qt::Popup) == Qt::Popup) { + // context menus, comboboxes, etc. don't need to update the menubar, + // but if an application has only Qt::Tool window(s) on start, + // we still have to update the menubar. + if ((win->flags() & Qt::WindowType_Mask) != Qt::Tool) + return; + typedef QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) AppDelegate; + NSApplication *app = [NSApplication sharedApplication]; + if (![app.delegate isKindOfClass:[AppDelegate class]]) + return; + // We apply this logic _only_ during the startup. + AppDelegate *appDelegate = app.delegate; + if (!appDelegate.inLaunch) + return; + } if (cw && cw->menubar()) mb = cw->menubar();