From cee63e2c17c8e83a4366741da0cbd5fc852e5835 Mon Sep 17 00:00:00 2001 From: Morten Sorvig Date: Tue, 6 Sep 2011 14:10:50 +0200 Subject: Cocoa: QMenu refactor. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/plugins/platforms/cocoa/qmenu_mac.h | 85 +++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/plugins/platforms/cocoa/qmenu_mac.h (limited to 'src/plugins/platforms/cocoa/qmenu_mac.h') 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 +#include +#include +#include +#include + +@class NSMenuItem; +class QCocoaMenuAction : public QPlatformMenuAction +{ +public: + QCocoaMenuAction(); + ~QCocoaMenuAction(); + + NSMenuItem *menuItem; + uchar ignore_accel : 1; + uchar merged : 1; + OSMenuRef menu; + QPointer qtMenu; +}; + +struct QMenuMergeItem +{ + inline QMenuMergeItem(NSMenuItem *c, QCocoaMenuAction *a) : menuItem(c), action(a) { } + NSMenuItem *menuItem; + QCocoaMenuAction *action; +}; +typedef QList 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 mergeMenuHash; + static QHash mergeMenuItemsHash; + QList 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 actionItems; + QMenuBar *qtMenuBar; +}; -- cgit v1.2.3