summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets/qmenu_mac.mm
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@nokia.com>2010-04-20 11:44:59 (GMT)
committerRichard Moe Gustavsen <richard.gustavsen@nokia.com>2010-04-20 13:16:22 (GMT)
commit327fabf8e8819b199aa24912ffe6893020b465d4 (patch)
tree305272c5ce4ac953b0c0127fc3a5ae92ee1e77af /src/gui/widgets/qmenu_mac.mm
parent528ffd602cc5a501713cd768df0cf6870a36ddad (diff)
downloadQt-327fabf8e8819b199aa24912ffe6893020b465d4.zip
Qt-327fabf8e8819b199aa24912ffe6893020b465d4.tar.gz
Qt-327fabf8e8819b199aa24912ffe6893020b465d4.tar.bz2
Default (Parentless) QMenuBar actions do not work
This bug is a bit nasty. The problem is that Cocoa is trying to be smart behind our back, and enable/disable menu items depending on the menu item targets. But in Qt, we have a different policy that Cocoa on when a menu bar should be disabled or not. E.g. we allow a modal dialog to access the application menu bar if it is the only window on screen. This patch will work around cocoa being smart by setting the menu item targets dynamically, depending on the modal state of Qt. Setting it to nil will make the items enabled when there is a modal dialog on screen, and setting it to the menu loader will enable it when there is _no_ window on screen at all. Task-number: QTBUG-9209 Reviewed-by: prasanth
Diffstat (limited to 'src/gui/widgets/qmenu_mac.mm')
-rw-r--r--src/gui/widgets/qmenu_mac.mm19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/gui/widgets/qmenu_mac.mm b/src/gui/widgets/qmenu_mac.mm
index 6a0eb53..7645c23 100644
--- a/src/gui/widgets/qmenu_mac.mm
+++ b/src/gui/widgets/qmenu_mac.mm
@@ -665,6 +665,7 @@ void qt_mac_set_modal_state_helper_recursive(OSMenuRef menu, OSMenuRef merge, bo
}
}
#else
+ bool modalWindowOnScreen = qApp->activeModalWidget() != 0;
for (NSMenuItem *item in [menu itemArray]) {
OSMenuRef submenu = [item submenu];
if (submenu != merge) {
@@ -674,10 +675,20 @@ void qt_mac_set_modal_state_helper_recursive(OSMenuRef menu, OSMenuRef merge, bo
// The item should follow what the QAction has.
if ([item tag]) {
QAction *action = reinterpret_cast<QAction *>([item tag]);
- syncNSMenuItemEnabled(item, action->isEnabled());
- } else {
- syncNSMenuItemEnabled(item, YES);
- }
+ syncNSMenuItemEnabled(item, action->isEnabled());
+ } else {
+ syncNSMenuItemEnabled(item, YES);
+ }
+ // We sneak in some extra code here to handle a menu problem:
+ // If there is no window on screen, we cannot set 'nil' as
+ // menu item target, because then cocoa will disable the item
+ // (guess it assumes that there will be no first responder to
+ // catch the trigger anyway?) OTOH, If we have a modal window,
+ // then setting the menu loader as target will make cocoa not
+ // deliver the trigger because the loader is then seen as modally
+ // shaddowed). So either way there are shortcomings. Instead, we
+ // decide the target as late as possible:
+ [item setTarget:modalWindowOnScreen ? nil : getMenuLoader()];
} else {
syncNSMenuItemEnabled(item, NO);
}