summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoamenu.h
diff options
context:
space:
mode:
authorJames Turner <james.turner@kdab.com>2012-05-04 14:16:05 +0100
committerQt by Nokia <qt-info@nokia.com>2012-05-19 10:18:21 +0200
commitb8246f08e49eb672974fd3d3d972a5ff13c1524d (patch)
tree509ab759670f0b24aa8d44ced0584fc2832f5e76 /src/plugins/platforms/cocoa/qcocoamenu.h
parent899f1d35a435fd499c73b29aabb6a609d496e5ed (diff)
Cocoa implementation of QPA menu interface.
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 <morten.sorvig@nokia.com>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoamenu.h')
-rw-r--r--src/plugins/platforms/cocoa/qcocoamenu.h97
1 files changed, 61 insertions, 36 deletions
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 <james.turner@kdab.com>
** 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 <Cocoa/Cocoa.h>
-
-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 <NSObject>
-- (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 <QtCore/QList>
+#include <qpa/qplatformmenu.h>
+#include "qcocoamenuitem.h"
+
+@class NSMenuItem;
+@class NSMenu;
+@class NSObject;
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
-@interface QT_MANGLE_NAMESPACE(QNativeCocoaMenu) : NSMenu <NSMenuDelegate>
+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<QCocoaMenuItem *> merged() const;
+private:
+ QCocoaMenuItem *itemOrNull(int index) const;
+ void insertNative(QCocoaMenuItem *item, QCocoaMenuItem *beforeItem);
+
+ QList<QCocoaMenuItem *> m_menuItems;
+ NSMenu *m_nativeMenu;
+ NSMenuItem *m_nativeItem;
+ NSObject *m_delegate;
+ bool m_enabled;
+ quintptr m_tag;
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif