diff options
author | Pasi Matilainen <pasi.matilainen@digia.com> | 2012-08-23 13:07:45 (GMT) |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-10-02 09:11:32 (GMT) |
commit | d412f11cea4dc336c684aafcd8979d5cec751cb5 (patch) | |
tree | ddc4dcf63d6957d38fdda3e3307efb3d3fe592a7 /src/gui | |
parent | 2884acf635825929204ae1c470b80df304de2d67 (diff) | |
download | Qt-d412f11cea4dc336c684aafcd8979d5cec751cb5.zip Qt-d412f11cea4dc336c684aafcd8979d5cec751cb5.tar.gz Qt-d412f11cea4dc336c684aafcd8979d5cec751cb5.tar.bz2 |
Update the state of native menus correctly on Mac
The state of native menus is currently updated in two incompatible ways
on Mac, either by updating the state of native menu items in a native
menu (when setEnabled is called) or the state of the native menu
item containing the native menu (when the menus are initialized and
when a modal dialog is opened/closed). This causes various problems,
e.g. inability to enable a menu that was disabled before menu
initialization or menus getting enabled incorrectly after a modal
dialog is closed. Fix by always setting the state of the native menu
item that contains the native menu.
Also, autoenable is active for the main menu, resulting in unnecessary
menu validation calls, so turn it off.
Task-number: QTBUG-25544
Task-number: QTBUG-26399
Task-number: QTBUG-7538
Change-Id: Iab335af633604e7b3017eaa55464d1b8fdd7b821
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/widgets/qmenu.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/qmenu_mac.mm | 15 | ||||
-rw-r--r-- | src/gui/widgets/qmenu_p.h | 2 |
3 files changed, 7 insertions, 12 deletions
diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index 59a9d80..fa40c1a 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -2387,7 +2387,7 @@ void QMenu::changeEvent(QEvent *e) if (d->tornPopup) // torn-off menu d->tornPopup->setEnabled(isEnabled()); d->menuAction->setEnabled(isEnabled()); -#ifdef Q_WS_MAC +#if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA) if (d->mac_menu) d->setMacMenuEnabled(isEnabled()); #endif diff --git a/src/gui/widgets/qmenu_mac.mm b/src/gui/widgets/qmenu_mac.mm index d7e4c7a..ef34f69 100644 --- a/src/gui/widgets/qmenu_mac.mm +++ b/src/gui/widgets/qmenu_mac.mm @@ -1564,6 +1564,7 @@ QMenuPrivate::syncSeparatorsCollapsible(bool collapse) +#ifndef QT_MAC_USE_COCOA /*! \internal */ @@ -1577,26 +1578,16 @@ void QMenuPrivate::setMacMenuEnabled(bool enable) for (int i = 0; i < mac_menu->actionItems.count(); ++i) { QMacMenuAction *menuItem = mac_menu->actionItems.at(i); if (menuItem && menuItem->action && menuItem->action->isEnabled()) { -#ifndef QT_MAC_USE_COCOA // Only enable those items which contains an enabled QAction. // i == 0 -> the menu itself, hence i + 1 for items. EnableMenuItem(mac_menu->menu, i + 1); -#else - [menuItem->menuItem setEnabled:true]; -#endif } } } else { -#ifndef QT_MAC_USE_COCOA DisableAllMenuItems(mac_menu->menu); -#else - NSMenu *menu = mac_menu->menu; - for (NSMenuItem *item in [menu itemArray]) { - [item setEnabled:false]; - } -#endif } } +#endif /*! \internal @@ -1754,6 +1745,7 @@ QMenuBarPrivate::QMacMenuBarPrivate::syncAction(QMacMenuAction *action) [item setSubmenu: submenu]; [submenu setTitle:qt_mac_QStringToNSString(qt_mac_removeMnemonics(action->action->text()))]; syncNSMenuItemVisiblity(item, visible); + syncNSMenuItemEnabled(item, action->action->isEnabled()); #endif if (release_submenu) { //no pointers to it #ifndef QT_MAC_USE_COCOA @@ -1856,6 +1848,7 @@ OSMenuRef QMenuBarPrivate::macMenu() return 0; } else if (!mac_menubar->menu) { mac_menubar->menu = qt_mac_create_menu(q); + [mac_menubar->menu setAutoenablesItems:NO]; ProcessSerialNumber mine, front; if (GetCurrentProcess(&mine) == noErr && GetFrontProcess(&front) == noErr) { if (!qt_mac_no_menubar_merge && !mac_menubar->apple_menu) { diff --git a/src/gui/widgets/qmenu_p.h b/src/gui/widgets/qmenu_p.h index c255393..8478fc6 100644 --- a/src/gui/widgets/qmenu_p.h +++ b/src/gui/widgets/qmenu_p.h @@ -327,7 +327,9 @@ public: } } *mac_menu; OSMenuRef macMenu(OSMenuRef merge); +#ifndef QT_MAC_USE_COCOA void setMacMenuEnabled(bool enable = true); +#endif void syncSeparatorsCollapsible(bool collapsible); static QHash<OSMenuRef, OSMenuRef> mergeMenuHash; static QHash<OSMenuRef, QMenuMergeList*> mergeMenuItemsHash; |