diff options
author | Jake Petroules <jake.petroules@petroules.com> | 2013-04-12 22:13:39 -0400 |
---|---|---|
committer | Jake Petroules <jake.petroules@petroules.com> | 2013-04-15 14:51:34 +0200 |
commit | fd69d80b2c5dd0927c1170f0538c6d4c7692306a (patch) | |
tree | d12a305e93f6ab486496091505e62e56435d6595 | |
parent | 490296e44ef496543118948372956894885522dc (diff) |
Modularize QtMacFunctions a bit by splitting it into several files.
qmacfunctions.mm contains implementations of functions for OS X and iOS.
qmacfunctions_mac.mm contains OS X only implementations.
qmacfunctions_ios.mm would contain iOS only implementations.
qmacfunctions_p.h contains shared helpers for the above three files.
Change-Id: I3222c2276c1de33e3086fdcc0b27eeab57e94175
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
-rw-r--r-- | src/macextras/macextras-lib.pri | 2 | ||||
-rw-r--r-- | src/macextras/qmacfunctions.h | 9 | ||||
-rw-r--r-- | src/macextras/qmacfunctions.mm | 81 | ||||
-rw-r--r-- | src/macextras/qmacfunctions_mac.mm | 115 | ||||
-rw-r--r-- | src/macextras/qmacfunctions_p.h | 68 |
5 files changed, 192 insertions, 83 deletions
diff --git a/src/macextras/macextras-lib.pri b/src/macextras/macextras-lib.pri index ce00be9..7d28cb5 100644 --- a/src/macextras/macextras-lib.pri +++ b/src/macextras/macextras-lib.pri @@ -2,6 +2,7 @@ INCLUDEPATH += $$PWD mac { PUBLIC_HEADERS += $$PWD/qmacfunctions.h + PRIVATE_HEADERS += $$PWD/qmacfunctions_p.h OBJECTIVE_SOURCES += $$PWD/qmacfunctions.mm !ios { @@ -17,6 +18,7 @@ mac { OBJECTIVE_SOURCES += \ $$PWD/qmaccocoaviewcontainer.mm \ + $$PWD/qmacfunctions_mac.mm \ $$PWD/qmacnativetoolbar.mm \ $$PWD/qmacnativewidget.mm \ $$PWD/qmactoolbardelegate.mm \ diff --git a/src/macextras/qmacfunctions.h b/src/macextras/qmacfunctions.h index 3949412..b0c521d 100644 --- a/src/macextras/qmacfunctions.h +++ b/src/macextras/qmacfunctions.h @@ -50,7 +50,6 @@ typedef struct CGImage *CGImageRef; - #ifdef __OBJC__ @class NSImage; @class NSString; @@ -72,14 +71,16 @@ namespace QtMacExtras { Q_MACEXTRAS_EXPORT NSString* toNSString(const QString &string); Q_MACEXTRAS_EXPORT QString fromNSString(const NSString *string); + Q_MACEXTRAS_EXPORT CGImageRef toCGImageRef(const QPixmap &pixmap); Q_MACEXTRAS_EXPORT QPixmap fromCGImageRef(CGImageRef image); #ifndef Q_OS_IOS -Q_MACEXTRAS_EXPORT NSMenu* toNSMenu(QMenu *menu); -Q_MACEXTRAS_EXPORT NSMenu *toNSMenu(QMenuBar *menubar); Q_MACEXTRAS_EXPORT NSImage* toNSImage(const QPixmap &pixmap); +Q_MACEXTRAS_EXPORT NSMenu* toNSMenu(QMenu *menu); +Q_MACEXTRAS_EXPORT NSMenu* toNSMenu(QMenuBar *menubar); + Q_MACEXTRAS_EXPORT void setDockMenu(QMenu *menu); #endif } @@ -91,4 +92,4 @@ inline void qt_mac_set_dock_menu(QMenu *menu) { QtMacExtras::setDockMenu(menu); QT_END_NAMESPACE -#endif //QMACFUNCTIONS +#endif // QMACFUNCTIONS_H diff --git a/src/macextras/qmacfunctions.mm b/src/macextras/qmacfunctions.mm index f460c18..93160fc 100644 --- a/src/macextras/qmacfunctions.mm +++ b/src/macextras/qmacfunctions.mm @@ -40,66 +40,13 @@ ****************************************************************************/ #include "qmacfunctions.h" -#ifdef Q_OS_IOS +#include "qmacfunctions_p.h" +#include <QPixmap> #import <Foundation/Foundation.h> #import <CoreGraphics/CoreGraphics.h> -#else -#import <Cocoa/Cocoa.h> -#endif QT_BEGIN_NAMESPACE -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) -#include <QtCore/qDebug.h> -#include <QtGui/QGuiApplication> -#include <QtWidgets/QMenu> -#include <QtWidgets/QMenuBar> -#include <qpa/qplatformmenu.h> -#include <qpa/qplatformnativeinterface.h> - -QPlatformNativeInterface::NativeResourceForIntegrationFunction resolvePlatformFunction(const QByteArray &functionName) -{ - QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); - QPlatformNativeInterface::NativeResourceForIntegrationFunction function = - nativeInterface->nativeResourceFunctionForIntegration(functionName); - if (!function) - qWarning() << "Qt could not resolve function" << functionName - << "from QGuiApplication::platformNativeInterface()->nativeResourceFunctionForIntegration()"; - return function; -} - -#ifndef Q_OS_IOS -NSMenu *QtMacExtras::toNSMenu(QMenu *menu) -{ - // Get the platform menu, which will be a QCocoaMenu - QPlatformMenu *platformMenu = menu->platformMenu(); - - // Get the qMenuToNSMenu function and call it. - QPlatformNativeInterface::NativeResourceForIntegrationFunction function = resolvePlatformFunction("qmenutonsmenu"); - if (function) { - typedef void* (*QMenuToNSMenuFunction)(QPlatformMenu *platformMenu); - return reinterpret_cast<NSMenu *>(reinterpret_cast<QMenuToNSMenuFunction>(function)(platformMenu)); - } - return nil; -} -#endif - -NSMenu *QtMacExtras::toNSMenu(QMenuBar *menubar) -{ - // Get the platform menubar, which will be a QCocoaMenuBar - QPlatformMenuBar *platformMenuBar = menubar->platformMenuBar(); - - // Get the qMenuBarToNSMenu function and call it. - QPlatformNativeInterface::NativeResourceForIntegrationFunction function = resolvePlatformFunction("qmenubartonsmenu"); - if (function) { - typedef void* (*QMenuBarToNSMenuFunction)(QPlatformMenuBar *platformMenuBar); - return reinterpret_cast<NSMenu *>(reinterpret_cast<QMenuBarToNSMenuFunction>(function)(platformMenuBar)); - } - return nil; -} - -#endif - namespace QtMacExtras { @@ -145,30 +92,6 @@ CGImageRef toCGImageRef(const QPixmap &pixmap) #endif } -#ifndef Q_OS_IOS -NSImage* toNSImage(const QPixmap &pixmap) -{ - NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithCGImage:toCGImageRef(pixmap)]; - NSImage *image = [[NSImage alloc] init]; - [image addRepresentation:bitmapRep]; - [bitmapRep release]; - return image; -} - -void setDockMenu(QMenu *menu) -{ - // Get the platform menu, which will be a QCocoaMenu - QPlatformMenu *platformMenu = menu->platformMenu(); - - // Get the setDockMenu function and call it. - QPlatformNativeInterface::NativeResourceForIntegrationFunction function = resolvePlatformFunction("setdockmenu"); - if (function) { - typedef void (*SetDockMenuFunction)(QPlatformMenu *platformMenu); - reinterpret_cast<SetDockMenuFunction>(function)(platformMenu); - } -} -#endif - /*! Returns a QPixmap that is equivalent to the given \a image. diff --git a/src/macextras/qmacfunctions_mac.mm b/src/macextras/qmacfunctions_mac.mm new file mode 100644 index 0000000..728c235 --- /dev/null +++ b/src/macextras/qmacfunctions_mac.mm @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtMacExtras module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmacfunctions.h" +#include "qmacfunctions_p.h" +#import <Cocoa/Cocoa.h> + +QT_BEGIN_NAMESPACE + +#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0) +#include <QtWidgets/QMenu> +#include <QtWidgets/QMenuBar> +#include <qpa/qplatformmenu.h> +#endif + +namespace QtMacExtras +{ + +NSImage* toNSImage(const QPixmap &pixmap) +{ + NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithCGImage:toCGImageRef(pixmap)]; + NSImage *image = [[NSImage alloc] init]; + [image addRepresentation:bitmapRep]; + [bitmapRep release]; + return image; +} + +NSMenu* toNSMenu(QMenu *menu) +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + // Get the platform menu, which will be a QCocoaMenu + QPlatformMenu *platformMenu = menu->platformMenu(); + + // Get the qMenuToNSMenu function and call it. + QPlatformNativeInterface::NativeResourceForIntegrationFunction function = resolvePlatformFunction("qmenutonsmenu"); + if (function) { + typedef void* (*QMenuToNSMenuFunction)(QPlatformMenu *platformMenu); + return reinterpret_cast<NSMenu *>(reinterpret_cast<QMenuToNSMenuFunction>(function)(platformMenu)); + } + return nil; +#else + return menu->nsMenu(); +#endif +} + +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) +NSMenu* toNSMenu(QMenuBar *menubar) +{ + // Get the platform menubar, which will be a QCocoaMenuBar + QPlatformMenuBar *platformMenuBar = menubar->platformMenuBar(); + + // Get the qMenuBarToNSMenu function and call it. + QPlatformNativeInterface::NativeResourceForIntegrationFunction function = resolvePlatformFunction("qmenubartonsmenu"); + if (function) { + typedef void* (*QMenuBarToNSMenuFunction)(QPlatformMenuBar *platformMenuBar); + return reinterpret_cast<NSMenu *>(reinterpret_cast<QMenuBarToNSMenuFunction>(function)(platformMenuBar)); + } + return nil; +} +#endif + +void setDockMenu(QMenu *menu) +{ + // Get the platform menu, which will be a QCocoaMenu + QPlatformMenu *platformMenu = menu->platformMenu(); + + // Get the setDockMenu function and call it. + QPlatformNativeInterface::NativeResourceForIntegrationFunction function = resolvePlatformFunction("setdockmenu"); + if (function) { + typedef void (*SetDockMenuFunction)(QPlatformMenu *platformMenu); + reinterpret_cast<SetDockMenuFunction>(function)(platformMenu); + } +} + +} // namespace QtMacExtras + +QT_END_NAMESPACE diff --git a/src/macextras/qmacfunctions_p.h b/src/macextras/qmacfunctions_p.h new file mode 100644 index 0000000..77f83ab --- /dev/null +++ b/src/macextras/qmacfunctions_p.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtMacExtras module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMACFUNCTIONS_P_H +#define QMACFUNCTIONS_P_H + +#include "qmacfunctions.h" + +QT_BEGIN_NAMESPACE + +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) +#include <QtCore/QDebug> +#include <QtGui/QGuiApplication> +#include <qpa/qplatformnativeinterface.h> + +inline QPlatformNativeInterface::NativeResourceForIntegrationFunction resolvePlatformFunction(const QByteArray &functionName) +{ + QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); + QPlatformNativeInterface::NativeResourceForIntegrationFunction function = + nativeInterface->nativeResourceFunctionForIntegration(functionName); + if (!function) + qWarning() << "Qt could not resolve function" << functionName + << "from QGuiApplication::platformNativeInterface()->nativeResourceFunctionForIntegration()"; + return function; +} +#endif + +QT_END_NAMESPACE + +#endif // QMACFUNCTIONS_P_H |