From b8246f08e49eb672974fd3d3d972a5ff13c1524d Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 4 May 2012 14:16:05 +0100 Subject: Cocoa implementation of QPA menu interface. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement the QPA platform menu interface for Cocoa, including native menubar support and merging with the predefined menus created from the bundled .nib. Cleanup code previously used to maintain the menus, and add a manual test of the menus code. Change-Id: Ia99267ddb6485e18e05c540eb32c5aee6cbb85db Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoamenu.h | 97 ++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 36 deletions(-) (limited to 'src/plugins/platforms/cocoa/qcocoamenu.h') diff --git a/src/plugins/platforms/cocoa/qcocoamenu.h b/src/plugins/platforms/cocoa/qcocoamenu.h index bf8bba1ddf..479d4b53c2 100644 --- a/src/plugins/platforms/cocoa/qcocoamenu.h +++ b/src/plugins/platforms/cocoa/qcocoamenu.h @@ -1,9 +1,10 @@ /**************************************************************************** ** ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author James Turner ** Contact: http://www.qt-project.org/ ** -** This file is part of the QtGui module of the Qt Toolkit. +** This file is part of the plugins of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** GNU Lesser General Public License Usage @@ -39,42 +40,66 @@ ** ****************************************************************************/ -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qmacdefines_mac.h" -#import - -QT_FORWARD_DECLARE_CLASS(QMenu) -QT_FORWARD_DECLARE_CLASS(QAction) - -#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5 - -@protocol NSMenuDelegate -- (void)menu:(NSMenu*)menu willHighlightItem:(NSMenuItem*)item; -- (void)menuWillOpen:(NSMenu*)menu; -- (void)menuDidClose:(NSMenu*)menu; -- (BOOL)hasShortcut:(NSMenu *)menu forKey:(NSString *)key forModifiers:(NSUInteger)modifier - whichItem:(NSMenuItem**)outItem; -@end +#ifndef QCOCOAMENU_H +#define QCOCOAMENU_H -#endif +#include +#include +#include "qcocoamenuitem.h" + +@class NSMenuItem; +@class NSMenu; +@class NSObject; + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE -@interface QT_MANGLE_NAMESPACE(QNativeCocoaMenu) : NSMenu +class QCocoaMenu : public QPlatformMenu { - QMenu *qmenu; - QAction *previousAction; -} -- (id)initWithQMenu:(QMenu*)menu; -- (BOOL)menuHasKeyEquivalent:(NSMenu *)menu forEvent:(NSEvent *)event target:(id *)target action:(SEL *)action; -- (NSInteger)indexOfItemWithTarget:(id)anObject andAction:(SEL)actionSelector; -@end +public: + QCocoaMenu(); + + inline virtual void setTag(quintptr tag) + { m_tag = tag; } + inline virtual quintptr tag() const + { return m_tag; } + + void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before); + void removeMenuItem(QPlatformMenuItem *menuItem); + void syncMenuItem(QPlatformMenuItem *menuItem); + void setEnabled(bool enabled); + void syncSeparatorsCollapsible(bool enable); + + void syncModalState(bool modal); + + virtual void setText(const QString &text); + void setParentItem(QCocoaMenuItem* item); + + inline NSMenu *nsMenu() const + { return m_nativeMenu; } + inline NSMenuItem *nsMenuItem() const + { return m_nativeItem; } + + virtual QPlatformMenuItem *menuItemAt(int position) const; + virtual QPlatformMenuItem *menuItemForTag(quintptr tag) const; + + QList merged() const; +private: + QCocoaMenuItem *itemOrNull(int index) const; + void insertNative(QCocoaMenuItem *item, QCocoaMenuItem *beforeItem); + + QList m_menuItems; + NSMenu *m_nativeMenu; + NSMenuItem *m_nativeItem; + NSObject *m_delegate; + bool m_enabled; + quintptr m_tag; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif -- cgit v1.2.3