summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2013-02-17 20:31:38 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-02-17 20:31:38 +0100
commite88011357e5dd3b0ae4e6bc715ef29e5f4f3ffab (patch)
treec5b05d45e49194d70ff4defae41e5d5d5cf75e80 /src/plugins/platforms/cocoa
parent2df8884bc68343ad96962e7496b98d6e585c0347 (diff)
parente65cd6f3794e12e6bc5c2ee985eae8e70ff5f333 (diff)
Merge "Merge remote-tracking branch 'origin/stable' into dev" into refs/staging/dev
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r--src/plugins/platforms/cocoa/qcocoabackingstore.mm2
-rw-r--r--src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm2
-rw-r--r--src/plugins/platforms/cocoa/qcocoahelpers.h3
-rw-r--r--src/plugins/platforms/cocoa/qcocoahelpers.mm55
-rw-r--r--src/plugins/platforms/cocoa/qcocoanativeinterface.h10
-rw-r--r--src/plugins/platforms/cocoa/qcocoanativeinterface.mm29
-rw-r--r--src/plugins/platforms/cocoa/qcocoatheme.mm4
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.h3
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm15
-rw-r--r--src/plugins/platforms/cocoa/qmacclipboard.mm2
-rw-r--r--src/plugins/platforms/cocoa/qnsview.mm2
-rw-r--r--src/plugins/platforms/cocoa/qprintengine_mac.mm2
12 files changed, 96 insertions, 33 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm
index fd0f4529cc..7f022da4c3 100644
--- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm
+++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm
@@ -67,7 +67,7 @@ QPaintDevice *QCocoaBackingStore::paintDevice()
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) {
QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(window()->handle());
- if (cocoaWindow && cocoaWindow->m_contentView) {
+ if (cocoaWindow && cocoaWindow->m_contentView && [cocoaWindow->m_contentView window]) {
scaleFactor = int([[cocoaWindow->m_contentView window] backingScaleFactor]);
}
}
diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
index d8bb72dd45..faea417f0f 100644
--- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
+++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
@@ -251,6 +251,7 @@ static QString strippedText(QString s)
[mSavePanel setDirectoryURL:selectable ? [NSURL fileURLWithPath:QT_PREPEND_NAMESPACE(QCFString::toNSString)(info.filePath())]
: [NSURL fileURLWithPath:QT_PREPEND_NAMESPACE(QCFString::toNSString)(info.path())]];
+ [mSavePanel setNameFieldStringValue:selectable ? QT_PREPEND_NAMESPACE(QCFString::toNSString)(info.fileName()) : nil];
// Call processEvents in case the event dispatcher has been interrupted, and needs to do
// cleanup of modal sessions. Do this before showing the native dialog, otherwise it will
@@ -277,6 +278,7 @@ static QString strippedText(QString s)
[self updateProperties];
[mSavePanel setDirectoryURL:selectable ? [NSURL fileURLWithPath:QT_PREPEND_NAMESPACE(QCFString::toNSString)(info.filePath())]
: [NSURL fileURLWithPath:QT_PREPEND_NAMESPACE(QCFString::toNSString)(info.path())]];
+ [mSavePanel setNameFieldStringValue:selectable ? QT_PREPEND_NAMESPACE(QCFString::toNSString)(info.fileName()) : nil];
NSWindow *nsparent = static_cast<NSWindow *>(qGuiApp->platformNativeInterface()->nativeResourceForWindow("nswindow", parent));
[mSavePanel beginSheetModalForWindow:nsparent completionHandler:^(NSInteger result){
diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.h b/src/plugins/platforms/cocoa/qcocoahelpers.h
index 51beaa97f5..c801d9d926 100644
--- a/src/plugins/platforms/cocoa/qcocoahelpers.h
+++ b/src/plugins/platforms/cocoa/qcocoahelpers.h
@@ -156,8 +156,9 @@ public:
}
};
-CGContextRef qt_mac_cg_context(const QPaintDevice *pdev);
+CGContextRef qt_mac_cg_context(QPaintDevice *pdev);
CGImageRef qt_mac_toCGImage(const QImage &qImage, bool isMask, uchar **dataCopy);
+QImage qt_mac_toQImage(CGImageRef image);
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm
index 08024b7bc6..dc43666bb6 100644
--- a/src/plugins/platforms/cocoa/qcocoahelpers.mm
+++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm
@@ -714,35 +714,38 @@ QString qt_mac_removeAmpersandEscapes(QString s)
\warning This function is only available on Mac OS X.
\warning This function is duplicated in qmacstyle_mac.mm
*/
-CGContextRef qt_mac_cg_context(const QPaintDevice *pdev)
+CGContextRef qt_mac_cg_context(QPaintDevice *pdev)
{
- if (pdev->devType() == QInternal::Pixmap) {
- const QPixmap *pm = static_cast<const QPixmap*>(pdev);
- CGColorSpaceRef colorspace = qt_mac_colorSpaceForDeviceType(pdev);
- uint flags = kCGImageAlphaPremultipliedFirst;
- flags |= kCGBitmapByteOrder32Host;
- CGContextRef ret = 0;
+ // In Qt 5, QWidget and QPixmap (and QImage) paint devices are all QImages under the hood.
+ QImage *image = 0;
+ if (pdev->devType() == QInternal::Image) {
+ image = static_cast<QImage *>(pdev);
+ } else if (pdev->devType() == QInternal::Pixmap) {
+ const QPixmap *pm = static_cast<const QPixmap*>(pdev);
QPlatformPixmap *data = const_cast<QPixmap *>(pm)->data_ptr().data();
if (data && data->classId() == QPlatformPixmap::RasterClass) {
- QImage *image = data->buffer();
- ret = CGBitmapContextCreate(image->bits(), image->width(), image->height(),
- 8, image->bytesPerLine(), colorspace, flags);
+ image = data->buffer();
} else {
qDebug() << "qt_mac_cg_context: Unsupported pixmap class";
}
-
- CGContextTranslateCTM(ret, 0, pm->height());
- CGContextScaleCTM(ret, 1, -1);
- return ret;
} else if (pdev->devType() == QInternal::Widget) {
- //CGContextRef ret = static_cast<CGContextRef>(static_cast<const QWidget *>(pdev)->macCGHandle());
- ///CGContextRetain(ret);
- //return ret;
+ // TODO test: image = static_cast<QImage *>(static_cast<const QWidget *>(pdev)->backingStore()->paintDevice());
qDebug() << "qt_mac_cg_context: not implemented: Widget class";
- return 0;
}
- return 0;
+
+ if (!image)
+ return 0; // Context type not supported.
+
+ CGColorSpaceRef colorspace = qt_mac_colorSpaceForDeviceType(pdev);
+ uint flags = kCGImageAlphaPremultipliedFirst;
+ flags |= kCGBitmapByteOrder32Host;
+ CGContextRef ret = 0;
+ ret = CGBitmapContextCreate(image->bits(), image->width(), image->height(),
+ 8, image->bytesPerLine(), colorspace, flags);
+ CGContextTranslateCTM(ret, 0, image->height());
+ CGContextScaleCTM(ret, 1, -1);
+ return ret;
}
CGImageRef qt_mac_toCGImage(const QImage &qImage, bool isMask, uchar **dataCopy)
@@ -836,4 +839,18 @@ CGImageRef qt_mac_toCGImage(const QImage &qImage, bool isMask, uchar **dataCopy)
return cgImage;
}
+QImage qt_mac_toQImage(CGImageRef image)
+{
+ const size_t w = CGImageGetWidth(image),
+ h = CGImageGetHeight(image);
+ QImage ret(w, h, QImage::Format_ARGB32_Premultiplied);
+ ret.fill(Qt::transparent);
+ CGRect rect = CGRectMake(0, 0, w, h);
+ CGContextRef ctx = qt_mac_cg_context(&ret);
+ qt_mac_drawCGImage(ctx, &rect, image);
+ CGContextRelease(ctx);
+ return ret;
+}
+
+
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.h b/src/plugins/platforms/cocoa/qcocoanativeinterface.h
index 34e8fb61e2..9506f86238 100644
--- a/src/plugins/platforms/cocoa/qcocoanativeinterface.h
+++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.h
@@ -42,6 +42,8 @@
#ifndef QCOCOANATIVEINTERFACE_H
#define QCOCOANATIVEINTERFACE_H
+#include <ApplicationServices/ApplicationServices.h>
+
#include <qpa/qplatformnativeinterface.h>
QT_BEGIN_NAMESPACE
@@ -49,6 +51,7 @@ QT_BEGIN_NAMESPACE
class QWidget;
class QPlatformPrinterSupport;
class QPrintEngine;
+class QPlatformMenu;
class QCocoaNativeInterface : public QPlatformNativeInterface
{
@@ -92,6 +95,13 @@ private:
static void addToMimeList(void *macPasteboardMime);
static void removeFromMimeList(void *macPasteboardMime);
static void registerDraggedTypes(const QStringList &types);
+
+ // Dock menu support
+ static void setDockMenu(QPlatformMenu *platformMenu);
+
+ // QImage <-> CGImage conversion functions
+ static CGImageRef qImageToCGImage(const QImage &image);
+ static QImage cgImageToQImage(CGImageRef image);
};
#endif // QCOCOANATIVEINTERFACE_H
diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
index 08084b5200..bd3a909137 100644
--- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
+++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
@@ -42,8 +42,10 @@
#include "qcocoanativeinterface.h"
#include "qcocoaglcontext.h"
#include "qcocoawindow.h"
+#include "qcocoamenu.h"
#include "qcocoamenubar.h"
#include "qmacmime.h"
+#include "qcocoahelpers.h"
#include <qbytearray.h>
#include <qwindow.h>
@@ -60,6 +62,8 @@
#include <qpa/qplatformprintersupport.h>
#endif
+#include <Cocoa/Cocoa.h>
+
QT_BEGIN_NAMESPACE
QCocoaNativeInterface::QCocoaNativeInterface()
@@ -103,6 +107,12 @@ QPlatformNativeInterface::NativeResourceForIntegrationFunction QCocoaNativeInter
return NativeResourceForIntegrationFunction(QCocoaNativeInterface::removeFromMimeList);
if (resource.toLower() == "registerdraggedtypes")
return NativeResourceForIntegrationFunction(QCocoaNativeInterface::registerDraggedTypes);
+ if (resource.toLower() == "setdockmenu")
+ return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setDockMenu);
+ if (resource.toLower() == "qimagetocgimage")
+ return NativeResourceForIntegrationFunction(QCocoaNativeInterface::qImageToCGImage);
+ if (resource.toLower() == "cgimagetoqimage")
+ return NativeResourceForIntegrationFunction(QCocoaNativeInterface::cgImageToQImage);
return 0;
}
@@ -170,4 +180,23 @@ void QCocoaNativeInterface::registerDraggedTypes(const QStringList &types)
qt_mac_registerDraggedTypes(types);
}
+void QCocoaNativeInterface::setDockMenu(QPlatformMenu *platformMenu)
+{
+ QCocoaMenu *cocoaPlatformMenu = static_cast<QCocoaMenu *>(platformMenu);
+ NSMenu *menu = cocoaPlatformMenu->nsMenu();
+ // setDockMenu seems to be undocumented, but this is what Qt 4 did.
+ [NSApp setDockMenu: menu];
+}
+
+CGImageRef QCocoaNativeInterface::qImageToCGImage(const QImage &image)
+{
+ return qt_mac_toCGImage(image, false, 0);
+}
+
+QImage QCocoaNativeInterface::cgImageToQImage(CGImageRef image)
+{
+ return qt_mac_toQImage(image);
+}
+
+
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm
index 0845ab8e94..beaa50da6d 100644
--- a/src/plugins/platforms/cocoa/qcocoatheme.mm
+++ b/src/plugins/platforms/cocoa/qcocoatheme.mm
@@ -53,6 +53,7 @@
#include "qcocoamenuitem.h"
#include "qcocoamenu.h"
#include "qcocoamenubar.h"
+#include "qcocoahelpers.h"
#include <QtCore/qfileinfo.h>
#include <QtGui/private/qguiapplication_p.h>
@@ -137,9 +138,6 @@ const QFont *QCocoaTheme::font(Font type) const
return m_fonts.value(type, 0);
}
-// Defined in qpaintengine_mac.mm
-extern CGContextRef qt_mac_cg_context(const QPaintDevice *pdev);
-
//! \internal
QPixmap qt_mac_convert_iconref(const IconRef icon, int width, int height)
{
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h
index 66c4deb366..291c688915 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.h
+++ b/src/plugins/platforms/cocoa/qcocoawindow.h
@@ -49,7 +49,8 @@
#include "qcocoaglcontext.h"
#include "qnsview.h"
-class QT_PREPEND_NAMESPACE(QCocoaWindow);
+
+QT_FORWARD_DECLARE_CLASS(QCocoaWindow)
@interface QNSWindow : NSWindow {
@public QCocoaWindow *m_cocoaPlatformWindow;
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index a3d0bc6e54..56ca2e0b14 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -301,9 +301,11 @@ void QCocoaWindow::setVisible(bool visible)
[m_nsWindow orderFront: nil];
}
- // We want the events to properly reach the popup and dialog
- if (window()->type() == Qt::Popup || window()->type() == Qt::Dialog)
+ // We want the events to properly reach the popup, dialog, and tool
+ if ((window()->type() == Qt::Popup || window()->type() == Qt::Dialog || window()->type() == Qt::Tool)
+ && [m_nsWindow isKindOfClass:[NSPanel class]]) {
[(NSPanel *)m_nsWindow setWorksWhenModal:YES];
+ }
}
} else {
[m_contentView setHidden:NO];
@@ -717,6 +719,11 @@ NSWindow * QCocoaWindow::createNSWindow()
createdWindow = window;
}
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
+ if ([createdWindow respondsToSelector:@selector(setRestorable:)])
+ [createdWindow setRestorable: NO];
+#endif
+
NSInteger level = windowLevel(flags);
[createdWindow setLevel:level];
m_windowModality = window()->modality();
@@ -837,11 +844,9 @@ QCocoaMenuBar *QCocoaWindow::menubar() const
qreal QCocoaWindow::devicePixelRatio() const
{
- if (!m_nsWindow)
- return 1.0;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) {
- return qreal([m_nsWindow backingScaleFactor]);
+ return qreal([[m_contentView window] backingScaleFactor]);
} else
#endif
{
diff --git a/src/plugins/platforms/cocoa/qmacclipboard.mm b/src/plugins/platforms/cocoa/qmacclipboard.mm
index 6fcf4d5746..95143fd8ea 100644
--- a/src/plugins/platforms/cocoa/qmacclipboard.mm
+++ b/src/plugins/platforms/cocoa/qmacclipboard.mm
@@ -135,7 +135,7 @@ OSStatus QMacPasteboard::promiseKeeper(PasteboardRef paste, PasteboardItemID id,
}
if (!promise.itemId && flavorAsQString == QLatin1String("com.trolltech.qt.MimeTypeName")) {
- // we have promised this data, but wont be able to convert, so return null data.
+ // we have promised this data, but won't be able to convert, so return null data.
// This helps in making the application/x-qt-mime-type-name hidden from normal use.
QByteArray ba;
QCFType<CFDataRef> data = CFDataCreate(0, (UInt8*)ba.constData(), ba.size());
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index 82fde6221d..c23d924993 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -1047,7 +1047,7 @@ static QTouchDevice *touchDevice = 0;
- (NSUInteger)characterIndexForPoint:(NSPoint)aPoint
{
- // We dont support cursor movements using mouse while composing.
+ // We don't support cursor movements using mouse while composing.
Q_UNUSED(aPoint);
return NSNotFound;
}
diff --git a/src/plugins/platforms/cocoa/qprintengine_mac.mm b/src/plugins/platforms/cocoa/qprintengine_mac.mm
index a5382c5ef6..54019372bc 100644
--- a/src/plugins/platforms/cocoa/qprintengine_mac.mm
+++ b/src/plugins/platforms/cocoa/qprintengine_mac.mm
@@ -109,7 +109,7 @@ bool QMacPrintEngine::end()
if (d->state == QPrinter::Aborted)
return true; // I was just here a function call ago :)
if (d->paintEngine->type() == QPaintEngine::CoreGraphics) {
- // We dont need the paint engine to call restoreGraphicsState()
+ // We don't need the paint engine to call restoreGraphicsState()
static_cast<QCoreGraphicsPaintEngine*>(d->paintEngine)->d_func()->stackCount = 0;
static_cast<QCoreGraphicsPaintEngine*>(d->paintEngine)->d_func()->hd = 0;
}