summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qmenu_mac.h
diff options
context:
space:
mode:
authorMorten Sorvig <morten.sorvig@nokia.com>2011-09-06 14:10:50 +0200
committerMorten Johan Sørvig <morten.sorvig@nokia.com>2011-09-07 11:00:36 +0200
commitcee63e2c17c8e83a4366741da0cbd5fc852e5835 (patch)
tree75ccc2afe762a51984d6651d6ff6eb875b73cad6 /src/plugins/platforms/cocoa/qmenu_mac.h
parente2be53891fe218c9a1a63c2d385d149d2b1f982f (diff)
Cocoa: QMenu refactor.
This change prepares for enabling native menus on OS X. Move code from src/widgets to cocoa: - qcocoaapplicaiton - qcocoaapplicaitondelegate - qcocoamenuloader - qcocoamenu - qmenu_mac - misc helpers to qcocoahelpers Create a QNSApplication and QCocoaApplicationDelegate at application startup. New Lighthouse API: - class QPlatformMenu - class QPlatformMenuBar - QPlatformIntegration::createPlatformMenu() - QPlatformIntegration::createPlatformMenuBar() Platforms that wants a native menu integration subclasses QPlatformMenu[|Bar] and implements the create function. The default implementation returns 0, which causes QMenu to use the standard Qt menus. This API is based on the current native menu abstraction that Mac, Wince and S60 uses in Qt 4. The main difference is that the platform classes are proper standalone classes and not #ifdeffed into QMenuPrivate. Change-Id: I3da41f80b0ae903a476937908b1f9b88014b7954 Reviewed-on: http://codereview.qt.nokia.com/4068 Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
Diffstat (limited to 'src/plugins/platforms/cocoa/qmenu_mac.h')
-rw-r--r--src/plugins/platforms/cocoa/qmenu_mac.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qmenu_mac.h b/src/plugins/platforms/cocoa/qmenu_mac.h
new file mode 100644
index 0000000000..f20f82c761
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qmenu_mac.h
@@ -0,0 +1,85 @@
+
+#include <private/qt_mac_p.h>
+#include <QtCore/qpointer.h>
+#include <QtWidgets/qmenu.h>
+#include <QtWidgets/qmenubar.h>
+#include <QtWidgets/qplatformmenu_qpa.h>
+
+@class NSMenuItem;
+class QCocoaMenuAction : public QPlatformMenuAction
+{
+public:
+ QCocoaMenuAction();
+ ~QCocoaMenuAction();
+
+ NSMenuItem *menuItem;
+ uchar ignore_accel : 1;
+ uchar merged : 1;
+ OSMenuRef menu;
+ QPointer<QMenu> qtMenu;
+};
+
+struct QMenuMergeItem
+{
+ inline QMenuMergeItem(NSMenuItem *c, QCocoaMenuAction *a) : menuItem(c), action(a) { }
+ NSMenuItem *menuItem;
+ QCocoaMenuAction *action;
+};
+typedef QList<QMenuMergeItem> QMenuMergeList;
+
+class QCocoaMenu : public QPlatformMenu
+{
+public:
+ QCocoaMenu(QMenu *qtMenu);
+ ~QCocoaMenu();
+
+ OSMenuRef macMenu(OSMenuRef merge = 0);
+ void syncSeparatorsCollapsible(bool collapse);
+ void setMenuEnabled(bool enable);
+
+ void addAction(QAction *action, QAction *before);
+ void syncAction(QAction *action);
+ void removeAction(QAction *action);
+
+ void addAction(QCocoaMenuAction *action, QCocoaMenuAction *before);
+ void syncAction(QCocoaMenuAction *action);
+ void removeAction(QCocoaMenuAction *action);
+ bool merged(const QAction *action) const;
+ QCocoaMenuAction *findAction(QAction *action) const;
+
+ OSMenuRef menu;
+ static QHash<OSMenuRef, OSMenuRef> mergeMenuHash;
+ static QHash<OSMenuRef, QMenuMergeList*> mergeMenuItemsHash;
+ QList<QCocoaMenuAction*> actionItems;
+ QMenu *qtMenu;
+};
+
+class QCocoaMenuBar : public QPlatformMenuBar
+{
+public:
+ QCocoaMenuBar(QMenuBar *qtMenuBar);
+ ~QCocoaMenuBar();
+
+ void handleReparent(QWidget *newParent);
+
+ void addAction(QAction *action, QAction *before);
+ void syncAction(QAction *action);
+ void removeAction(QAction *action);
+
+ void addAction(QCocoaMenuAction *action, QCocoaMenuAction *before);
+ void syncAction(QCocoaMenuAction *action);
+ void removeAction(QCocoaMenuAction *action);
+
+ bool macWidgetHasNativeMenubar(QWidget *widget);
+ void macCreateMenuBar(QWidget *parent);
+ void macDestroyMenuBar();
+ OSMenuRef macMenu();
+ static bool macUpdateMenuBarImmediatly();
+ static void macUpdateMenuBar();
+ QCocoaMenuAction *findAction(QAction *action) const;
+
+ OSMenuRef menu;
+ OSMenuRef apple_menu;
+ QList<QCocoaMenuAction*> actionItems;
+ QMenuBar *qtMenuBar;
+};