summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@nokia.com>2010-04-21 08:00:32 (GMT)
committerRichard Moe Gustavsen <richard.gustavsen@nokia.com>2010-04-21 08:00:32 (GMT)
commit11dad6b10cbf4f3727e03669cfa04a623f1b6308 (patch)
tree3b693bb3e19625afe6f88eb1c3e8b23e43df7586
parentc9a5b8f0d840e67ad33839c8c310aef73a8a855c (diff)
downloadQt-11dad6b10cbf4f3727e03669cfa04a623f1b6308.zip
Qt-11dad6b10cbf4f3727e03669cfa04a623f1b6308.tar.gz
Qt-11dad6b10cbf4f3727e03669cfa04a623f1b6308.tar.bz2
Default (Parentless) QMenuBar actions do not work (without autotest)
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
-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);
}