Add qMenuToNSMenu() and qMenuBarToNSMenu() to QCocoaNativeInterface.

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 <porten@froglogic.com>
Reviewed-by: Laszlo Papp <lpapp@kde.org>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
This commit is contained in:
Dmytro Tyshchenko 2013-03-20 17:57:05 +01:00 committed by The Qt Project
parent 24c10b0b8d
commit b5a388192c
2 changed files with 25 additions and 0 deletions

View File

@ -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);

View File

@ -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<QCocoaMenu *>(platformMenu);
NSMenu *menu = cocoaPlatformMenu->nsMenu();
return reinterpret_cast<void *>(menu);
}
void *QCocoaNativeInterface::qMenuBarToNSMenu(QPlatformMenuBar *platformMenuBar)
{
QCocoaMenuBar *cocoaPlatformMenuBar = static_cast<QCocoaMenuBar *>(platformMenuBar);
NSMenu *menu = cocoaPlatformMenuBar->nsMenu();
return reinterpret_cast<void *>(menu);
}
CGImageRef QCocoaNativeInterface::qImageToCGImage(const QImage &image)
{
return qt_mac_toCGImage(image, false, 0);