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/widgets/widgets/qmenu_p.h | 75 +++---------------------------------------- 1 file changed, 4 insertions(+), 71 deletions(-) (limited to 'src/widgets/widgets/qmenu_p.h') diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index cfe1ecf2b9..bd360f5e25 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -83,37 +83,6 @@ void qt_symbian_show_submenu(CEikMenuPane* menuPane, int id); class QTornOffMenu; class QEventLoop; -#ifdef Q_OS_MAC -# ifdef __OBJC__ -QT_END_NAMESPACE -@class NSMenuItem; -QT_BEGIN_NAMESPACE -# else -typedef void NSMenuItem; -# endif //__OBJC__ -struct QMacMenuAction { - QMacMenuAction() - : menuItem(0) - , ignore_accel(0), merged(0), menu(0) - { - } - ~QMacMenuAction(); - NSMenuItem *menuItem; - uchar ignore_accel : 1; - uchar merged : 1; - QPointer action; - OSMenuRef menu; -}; - -struct QMenuMergeItem -{ - inline QMenuMergeItem(NSMenuItem *c, QMacMenuAction *a) : menuItem(c), action(a) { } - NSMenuItem *menuItem; - QMacMenuAction *action; -}; -typedef QList QMenuMergeList; -#endif // Q_OS_MAC - #ifdef Q_WS_WINCE struct QWceMenuAction { uint command; @@ -144,13 +113,8 @@ public: cancelAction(0), #endif scroll(0), eventLoop(0), tearoff(0), tornoff(0), tearoffHighlighted(0), - hasCheckableItems(0), sloppyAction(0), doChildEffects(false) -#ifdef QT3_SUPPORT - ,emitHighlighted(false) -#endif -#ifdef Q_OS_MAC - ,mac_menu(0) -#endif + hasCheckableItems(0), sloppyAction(0), doChildEffects(false), platformMenu(0) + #if defined(Q_WS_WINCE) && !defined(QT_NO_MENUBAR) ,wce_menu(0) #endif @@ -161,9 +125,7 @@ public: ~QMenuPrivate() { delete scroll; -#ifdef Q_OS_MAC - delete mac_menu; -#endif + delete platformMenu; #if defined(Q_WS_WINCE) && !defined(QT_NO_MENUBAR) delete wce_menu; #endif @@ -293,36 +255,7 @@ public: //menu fading/scrolling effects bool doChildEffects; -#ifdef Q_OS_MAC - //mac menu binding - struct QMacMenuPrivate { - QList actionItems; - OSMenuRef menu; - QMacMenuPrivate(); - ~QMacMenuPrivate(); - - bool merged(const QAction *action) const; - void addAction(QAction *, QMacMenuAction* =0, QMenuPrivate *qmenu = 0); - void addAction(QMacMenuAction *, QMacMenuAction* =0, QMenuPrivate *qmenu = 0); - void syncAction(QMacMenuAction *); - inline void syncAction(QAction *a) { syncAction(findAction(a)); } - void removeAction(QMacMenuAction *); - inline void removeAction(QAction *a) { removeAction(findAction(a)); } - inline QMacMenuAction *findAction(QAction *a) { - for(int i = 0; i < actionItems.size(); i++) { - QMacMenuAction *act = actionItems[i]; - if(a == act->action) - return act; - } - return 0; - } - } *mac_menu; - OSMenuRef macMenu(OSMenuRef merge); - void setMacMenuEnabled(bool enable = true); - void syncSeparatorsCollapsible(bool collapsible); - static QHash mergeMenuHash; - static QHash mergeMenuItemsHash; -#endif + QPlatformMenu *platformMenu; QPointer actionAboutToTrigger; #ifdef QT3_SUPPORT -- cgit v1.2.3