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 <shawn.rutledge@digia.com>
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
This commit is contained in:
Timur Pocheptsov 2015-03-27 12:12:32 +01:00
parent 51af196ba0
commit 5e9f7b9579
3 changed files with 22 additions and 2 deletions

View File

@ -100,6 +100,7 @@
- (void)setReflectionDelegate:(NSObject <NSApplicationDelegate> *)oldDelegate;
- (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent;
- (void) removeAppleEventHandlers;
- (bool) inLaunch;
@end
QT_NAMESPACE_ALIAS_OBJC_CLASS(QCocoaApplicationDelegate);

View File

@ -284,6 +284,11 @@ QT_END_NAMESPACE
[eventManager removeEventHandlerForEventClass:kInternetEventClass andEventID:kAEGetURL];
}
- (bool) inLaunch
{
return inLaunch;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
Q_UNUSED(aNotification);

View File

@ -38,6 +38,7 @@
#include "qcocoamenuloader.h"
#include "qcocoaapplication.h" // for custom application category
#include "qcocoaautoreleasepool.h"
#include "qcocoaapplicationdelegate.h"
#include <QtGui/QGuiApplication>
#include <QtCore/QDebug>
@ -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();