From b5a388192c886fd346daf461a8d738a1867c21e0 Mon Sep 17 00:00:00 2001 From: Dmytro Tyshchenko Date: Wed, 20 Mar 2013 17:57:05 +0100 Subject: [PATCH] Add qMenuToNSMenu() and qMenuBarToNSMenu() to QCocoaNativeInterface. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Preparing the addition of toNSMenu() functions to QtMacExtras which will expose the native handle of a QMenu or QMenuBar. Task-number: QTBUG-28869 Change-Id: Ib07712f5da0758addbbf8a84d6881297420e7ac8 Reviewed-by: Harri Porten Reviewed-by: Laszlo Papp Reviewed-by: Morten Johan Sørvig --- .../platforms/cocoa/qcocoanativeinterface.h | 7 +++++++ .../platforms/cocoa/qcocoanativeinterface.mm | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.h b/src/plugins/platforms/cocoa/qcocoanativeinterface.h index 2f79b49534..b1b8dccca5 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.h +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.h @@ -52,6 +52,7 @@ class QWidget; class QPlatformPrinterSupport; class QPrintEngine; class QPlatformMenu; +class QPlatformMenuBar; class QCocoaNativeInterface : public QPlatformNativeInterface { @@ -99,6 +100,12 @@ private: // Dock menu support static void setDockMenu(QPlatformMenu *platformMenu); + // Function to return NSMenu * from QPlatformMenu + static void *qMenuToNSMenu(QPlatformMenu *platformMenu); + + // Function to return NSMenu * from QPlatformMenuBar + static void *qMenuBarToNSMenu(QPlatformMenuBar *platformMenuBar); + // QImage <-> CGImage conversion functions static CGImageRef qImageToCGImage(const QImage &image); static QImage cgImageToQImage(CGImageRef image); diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm index 9990537c1f..fde93a38db 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm @@ -109,6 +109,10 @@ QPlatformNativeInterface::NativeResourceForIntegrationFunction QCocoaNativeInter return NativeResourceForIntegrationFunction(QCocoaNativeInterface::registerDraggedTypes); if (resource.toLower() == "setdockmenu") return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setDockMenu); + if (resource.toLower() == "qmenutonsmenu") + return NativeResourceForIntegrationFunction(QCocoaNativeInterface::qMenuToNSMenu); + if (resource.toLower() == "qmenubartonsmenu") + return NativeResourceForIntegrationFunction(QCocoaNativeInterface::qMenuBarToNSMenu); if (resource.toLower() == "qimagetocgimage") return NativeResourceForIntegrationFunction(QCocoaNativeInterface::qImageToCGImage); if (resource.toLower() == "cgimagetoqimage") @@ -190,6 +194,20 @@ void QCocoaNativeInterface::setDockMenu(QPlatformMenu *platformMenu) [NSApp setDockMenu: menu]; } +void *QCocoaNativeInterface::qMenuToNSMenu(QPlatformMenu *platformMenu) +{ + QCocoaMenu *cocoaPlatformMenu = static_cast(platformMenu); + NSMenu *menu = cocoaPlatformMenu->nsMenu(); + return reinterpret_cast(menu); +} + +void *QCocoaNativeInterface::qMenuBarToNSMenu(QPlatformMenuBar *platformMenuBar) +{ + QCocoaMenuBar *cocoaPlatformMenuBar = static_cast(platformMenuBar); + NSMenu *menu = cocoaPlatformMenuBar->nsMenu(); + return reinterpret_cast(menu); +} + CGImageRef QCocoaNativeInterface::qImageToCGImage(const QImage &image) { return qt_mac_toCGImage(image, false, 0);