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 /tests | |
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 'tests')
-rw-r--r-- | tests/auto/qmenu/qmenu.pro | 6 | ||||
-rw-r--r-- | tests/auto/qmenu/tst_qmenu.cpp | 92 | ||||
-rw-r--r-- | tests/auto/qmenu/tst_qmenu_mac_helpers.h | 55 | ||||
-rw-r--r-- | tests/auto/qmenu/tst_qmenu_mac_helpers.mm | 57 |
4 files changed, 210 insertions, 0 deletions
diff --git a/tests/auto/qmenu/qmenu.pro b/tests/auto/qmenu/qmenu.pro index acb07fb..74408f0 100644 --- a/tests/auto/qmenu/qmenu.pro +++ b/tests/auto/qmenu/qmenu.pro @@ -1,5 +1,11 @@ load(qttest_p4) SOURCES += tst_qmenu.cpp +macx { + LIBS += -framework AppKit + OBJECTIVE_SOURCES += tst_qmenu_mac_helpers.mm + HEADERS += tst_qmenu_mac_helpers.h +} + contains(QT_CONFIG, qt3support): QT += qt3support diff --git a/tests/auto/qmenu/tst_qmenu.cpp b/tests/auto/qmenu/tst_qmenu.cpp index 4bca6c1..d196c79 100644 --- a/tests/auto/qmenu/tst_qmenu.cpp +++ b/tests/auto/qmenu/tst_qmenu.cpp @@ -57,6 +57,10 @@ #include <qstyle.h> #include <qdebug.h> +#ifdef QT_MAC_USE_COCOA +#include "tst_qmenu_mac_helpers.h" +#endif + #include "../../shared/util.h" //TESTED_CLASS= @@ -108,6 +112,11 @@ private slots: void QTBUG7907_submenus_autoselect(); void QTBUG7411_submenus_activate(); void QTBUG_10735_crashWithDialog(); + void QTBUG_25544_macMenuState(); + void QTBUG_25544_macMenuActionState(); + void QTBUG_26399_macMenuActionVisible(); + void QTBUG_7538_macAddItemToDisabledMenu(); + protected slots: void onActivated(QAction*); void onHighlighted(QAction*); @@ -1025,6 +1034,89 @@ void tst_QMenu::QTBUG_10735_crashWithDialog() } +void tst_QMenu::QTBUG_25544_macMenuState() +{ +#ifndef QT_MAC_USE_COCOA + QSKIP("Applicable only on OS X Cocoa", SkipAll); +#else + QMenuBar mb; + MyMenu2 menu; + menu.setTitle("Test menu"); + menu.addAction("foo"); + mb.addMenu(&menu); + + menu.setEnabled(false); + menu.show(); + QTest::qWaitForWindowShown(&menu); + QVERIFY(!menu.isNativeMenuEnabled()); + + menu.setEnabled(true); + QVERIFY(menu.isNativeMenuEnabled()); +#endif +} + +void tst_QMenu::QTBUG_25544_macMenuActionState() +{ +#ifndef QT_MAC_USE_COCOA + QSKIP("Applicable only on OS X Cocoa", SkipAll); +#else + QMenuBar menubar; + MyMenu2 menu; + menu.setTitle("Test menu"); + menu.addAction("foo"); + menubar.addMenu(&menu); + + menu.show(); + QTest::qWaitForWindowShown(&menu); + + menu.menuAction()->setEnabled(false); + QVERIFY(!menu.isNativeMenuEnabled()); + + menu.menuAction()->setEnabled(true); + QVERIFY(menu.isNativeMenuEnabled()); +#endif +} + +void tst_QMenu::QTBUG_26399_macMenuActionVisible() +{ +#ifndef QT_MAC_USE_COCOA + QSKIP("Applicable only on OS X Cocoa", SkipAll); +#else + QMenuBar menubar; + MyMenu2 menu; + menu.setTitle("Test menu"); + menu.addAction("foo"); + menubar.addMenu(&menu); + + menu.show(); + menu.menuAction()->setVisible(false); + QTest::qWaitForWindowShown(&menu); + + QVERIFY(!menu.isNativeMenuEnabled()); + + menu.menuAction()->setVisible(true); + QVERIFY(menu.isNativeMenuEnabled()); +#endif +} + +void tst_QMenu::QTBUG_7538_macAddItemToDisabledMenu() +{ +#ifndef QT_MAC_USE_COCOA + QSKIP("Applicable only on OS X Cocoa", SkipAll); +#else + QMenuBar menubar; + MyMenu2 menu; + menu.setTitle("Test menu"); + menu.addAction("foo"); + menubar.addMenu(&menu); + + menu.show(); + QTest::qWaitForWindowShown(&menu); + menu.setEnabled(false); + QAction *act = menu.addAction("bar"); + QVERIFY(!menu.isNativeMenuItemEnabled(act)); +#endif +} QTEST_MAIN(tst_QMenu) #include "tst_qmenu.moc" diff --git a/tests/auto/qmenu/tst_qmenu_mac_helpers.h b/tests/auto/qmenu/tst_qmenu_mac_helpers.h new file mode 100644 index 0000000..a5c8d21 --- /dev/null +++ b/tests/auto/qmenu/tst_qmenu_mac_helpers.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TST_QMENU_MAC_HELPERS_H +#define TST_QMENU_MAC_HELPERS_H + +#include <QMenu> + +class MyMenu2 : public QMenu +{ + Q_OBJECT +public: + bool isNativeMenuEnabled(); + bool isNativeMenuItemEnabled(QAction *act); +}; + +#endif // TST_QMENU_MAC_HELPERS_H diff --git a/tests/auto/qmenu/tst_qmenu_mac_helpers.mm b/tests/auto/qmenu/tst_qmenu_mac_helpers.mm new file mode 100644 index 0000000..22b45d7 --- /dev/null +++ b/tests/auto/qmenu/tst_qmenu_mac_helpers.mm @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#import <AppKit/NSMenuItem.h> +#include <private/qmenu_p.h> +#include "tst_qmenu_mac_helpers.h" + +bool MyMenu2::isNativeMenuEnabled() +{ + QMenuPrivate *p = static_cast<QMenuPrivate*>(d_ptr.data()); + return [[[p->mac_menu->menu supermenu] itemWithTag:(long)menuAction()] isEnabled]; +} + +bool MyMenu2::isNativeMenuItemEnabled(QAction *act) +{ + QMenuPrivate *p = static_cast<QMenuPrivate*>(d_ptr.data()); + QMacMenuAction *macMenu = p->mac_menu->findAction(act); + return [macMenu->menuItem isEnabled]; +} |