summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r--src/plugins/platforms/cocoa/cocoa.pro29
-rw-r--r--src/plugins/platforms/cocoa/main.mm74
-rw-r--r--src/plugins/platforms/cocoa/qcocoaautoreleasepool.h57
-rw-r--r--src/plugins/platforms/cocoa/qcocoaautoreleasepool.mm52
-rw-r--r--src/plugins/platforms/cocoa/qcocoaeventloopintegration.h65
-rw-r--r--src/plugins/platforms/cocoa/qcocoaeventloopintegration.mm112
-rw-r--r--src/plugins/platforms/cocoa/qcocoaintegration.h99
-rw-r--r--src/plugins/platforms/cocoa/qcocoaintegration.mm132
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.h75
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm110
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindowsurface.h73
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindowsurface.mm103
-rw-r--r--src/plugins/platforms/cocoa/qnsview.h79
-rw-r--r--src/plugins/platforms/cocoa/qnsview.mm211
-rw-r--r--src/plugins/platforms/cocoa/qnswindowdelegate.h61
-rw-r--r--src/plugins/platforms/cocoa/qnswindowdelegate.mm73
16 files changed, 1405 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/cocoa.pro b/src/plugins/platforms/cocoa/cocoa.pro
new file mode 100644
index 0000000000..1633ee45c7
--- /dev/null
+++ b/src/plugins/platforms/cocoa/cocoa.pro
@@ -0,0 +1,29 @@
+TARGET = qcocoa
+include(../../qpluginbase.pri)
+QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms
+
+OBJECTIVE_SOURCES = main.mm \
+ qcocoaintegration.mm \
+ qcocoawindowsurface.mm \
+ qcocoawindow.mm \
+ qnsview.mm \
+ qcocoaeventloopintegration.mm \
+ qcocoaautoreleasepool.mm \
+ qnswindowdelegate.mm
+
+OBJECTIVE_HEADERS = qcocoaintegration.h \
+ qcocoawindowsurface.h \
+ qcocoawindow.h \
+ qnsview.h \
+ qcocoaeventloopintegration.h \
+ qcocoaautoreleasepool.h \
+ qnswindowdelegate.h
+
+#add libz for freetype.
+LIBS += -lz
+LIBS += -framework cocoa
+
+include(../fontdatabases/coretext/coretext.pri)
+target.path += $$[QT_INSTALL_PLUGINS]/platforms
+INSTALLS += target
+
diff --git a/src/plugins/platforms/cocoa/main.mm b/src/plugins/platforms/cocoa/main.mm
new file mode 100644
index 0000000000..da7af3ff83
--- /dev/null
+++ b/src/plugins/platforms/cocoa/main.mm
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <Cocoa/Cocoa.h>
+
+#include <QtGui/QPlatformIntegrationPlugin>
+#include "qcocoaintegration.h"
+
+QT_BEGIN_NAMESPACE
+
+class QCocoaIntegrationPlugin : public QPlatformIntegrationPlugin
+{
+public:
+ QStringList keys() const;
+ QPlatformIntegration *create(const QString&, const QStringList&);
+};
+
+QStringList QCocoaIntegrationPlugin::keys() const
+{
+ QStringList list;
+ list << "Cocoa";
+ return list;
+}
+
+QPlatformIntegration * QCocoaIntegrationPlugin::create(const QString& system, const QStringList& paramList)
+{
+ Q_UNUSED(paramList);
+ if (system.toLower() == "cocoa")
+ return new QCocoaIntegration;
+
+ return 0;
+}
+
+Q_EXPORT_PLUGIN2(Cocoa, QCocoaIntegrationPlugin)
+
+QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qcocoaautoreleasepool.h b/src/plugins/platforms/cocoa/qcocoaautoreleasepool.h
new file mode 100644
index 0000000000..6e41e9a38a
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qcocoaautoreleasepool.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QCOCOAAUTORELEASEPOOL_H
+#define QCOCOAAUTORELEASEPOOL_H
+
+#include <Cocoa/Cocoa.h>
+
+class QCocoaAutoReleasePool
+{
+public:
+ QCocoaAutoReleasePool();
+ ~QCocoaAutoReleasePool();
+
+private:
+ NSAutoreleasePool *pool;
+};
+
+#endif // QCOCOAAUTORELEASEPOOL_H
diff --git a/src/plugins/platforms/cocoa/qcocoaautoreleasepool.mm b/src/plugins/platforms/cocoa/qcocoaautoreleasepool.mm
new file mode 100644
index 0000000000..35750cda52
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qcocoaautoreleasepool.mm
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qcocoaautoreleasepool.h"
+
+QCocoaAutoReleasePool::QCocoaAutoReleasePool()
+{
+ pool = [[NSAutoreleasePool alloc] init];
+}
+
+QCocoaAutoReleasePool::~QCocoaAutoReleasePool()
+{
+ [pool release];
+}
diff --git a/src/plugins/platforms/cocoa/qcocoaeventloopintegration.h b/src/plugins/platforms/cocoa/qcocoaeventloopintegration.h
new file mode 100644
index 0000000000..81e272ec1b
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qcocoaeventloopintegration.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QCOCAEVENTLOOPINTEGRATION_H
+#define QCOCAEVENTLOOPINTEGRATION_H
+
+#include <Cocoa/Cocoa.h>
+
+#include <QPlatformEventLoopIntegration>
+
+
+class QCocoaEventLoopIntegration : public QPlatformEventLoopIntegration
+{
+public:
+ QCocoaEventLoopIntegration();
+ void startEventLoop();
+ void quitEventLoop();
+ void qtNeedsToProcessEvents();
+
+private:
+ CFRunLoopSourceContext m_sourceContext;
+ CFRunLoopTimerContext m_timerContext;
+ CFRunLoopSourceRef m_source;
+};
+
+#endif // QCOCAEVENTLOOPINTEGRATION_H
+
diff --git a/src/plugins/platforms/cocoa/qcocoaeventloopintegration.mm b/src/plugins/platforms/cocoa/qcocoaeventloopintegration.mm
new file mode 100644
index 0000000000..885916ed74
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qcocoaeventloopintegration.mm
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qcocoaeventloopintegration.h"
+
+#import <Cocoa/Cocoa.h>
+
+#include "qcocoaautoreleasepool.h"
+
+#include <QtCore/QElapsedTimer>
+
+#include <QDebug>
+#include <QApplication>
+
+void wakeupCallback ( void * ) {
+ QPlatformEventLoopIntegration::processEvents();
+}
+
+void timerCallback( CFRunLoopTimerRef timer, void *info)
+{
+ QPlatformEventLoopIntegration::processEvents();
+ QCocoaEventLoopIntegration *eventLoopIntegration =
+ static_cast<QCocoaEventLoopIntegration *>(info);
+ qint64 nextTime = eventLoopIntegration->nextTimerEvent();
+ CFAbsoluteTime nexttime = CFAbsoluteTimeGetCurrent();
+ nexttime = nexttime + (double(nextTime)/1000);
+ CFRunLoopTimerSetNextFireDate(timer,nexttime);
+}
+
+QCocoaEventLoopIntegration::QCocoaEventLoopIntegration() :
+ QPlatformEventLoopIntegration()
+{
+ [NSApplication sharedApplication];
+ m_sourceContext.version = 0;
+ m_sourceContext.info = this;
+ m_sourceContext.retain = 0;
+ m_sourceContext.release = 0;
+ m_sourceContext.copyDescription = 0;
+ m_sourceContext.equal = 0;
+ m_sourceContext.hash = 0;
+ m_sourceContext.schedule = 0;
+ m_sourceContext.cancel = 0;
+ m_sourceContext.perform = wakeupCallback;
+
+ m_source = CFRunLoopSourceCreate(0,0,&m_sourceContext);
+ CFRunLoopAddSource(CFRunLoopGetMain(),m_source,kCFRunLoopCommonModes);
+
+ m_timerContext.version = 0;
+ m_timerContext.info = this;
+ m_timerContext.retain = 0;
+ m_timerContext.release = 0;
+ m_timerContext.copyDescription = 0;
+ CFAbsoluteTime fireDate = CFAbsoluteTimeGetCurrent ();
+ CFTimeInterval interval = 30;
+
+ CFRunLoopTimerRef m_timerSource = CFRunLoopTimerCreate(0,fireDate,interval,0,0,timerCallback,&m_timerContext);
+ CFRunLoopAddTimer(CFRunLoopGetMain(),m_timerSource,kCFRunLoopCommonModes);
+}
+
+void QCocoaEventLoopIntegration::startEventLoop()
+{
+ [[NSApplication sharedApplication] run];
+}
+
+void QCocoaEventLoopIntegration::quitEventLoop()
+{
+ [[NSApplication sharedApplication] terminate:nil];
+}
+
+void QCocoaEventLoopIntegration::qtNeedsToProcessEvents()
+{
+ CFRunLoopSourceSignal(m_source);
+}
+
diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.h b/src/plugins/platforms/cocoa/qcocoaintegration.h
new file mode 100644
index 0000000000..2a04e8c2ed
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qcocoaintegration.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPLATFORMINTEGRATION_COCOA_H
+#define QPLATFORMINTEGRATION_COCOA_H
+
+#include <Cocoa/Cocoa.h>
+
+#include "qcocoaautoreleasepool.h"
+
+#include <QtGui/QPlatformIntegration>
+
+QT_BEGIN_NAMESPACE
+
+class QCocoaScreen : public QPlatformScreen
+{
+public:
+ QCocoaScreen(int screenIndex);
+ ~QCocoaScreen();
+
+ QRect geometry() const { return m_geometry; }
+ int depth() const { return m_depth; }
+ QImage::Format format() const { return m_format; }
+ QSize physicalSize() const { return m_physicalSize; }
+
+public:
+ NSScreen *m_screen;
+ QRect m_geometry;
+ int m_depth;
+ QImage::Format m_format;
+ QSize m_physicalSize;
+};
+
+class QCocoaIntegration : public QPlatformIntegration
+{
+public:
+ QCocoaIntegration();
+ ~QCocoaIntegration();
+
+ bool hasCapability(QPlatformIntegration::Capability cap) const;
+ QPixmapData *createPixmapData(QPixmapData::PixelType type) const;
+ QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId = 0) const;
+ QWindowSurface *createWindowSurface(QWidget *widget, WId winId) const;
+
+ QList<QPlatformScreen *> screens() const { return mScreens; }
+
+ QPlatformFontDatabase *fontDatabase() const;
+
+ QPlatformEventLoopIntegration *createEventLoopIntegration() const;
+
+private:
+ QList<QPlatformScreen *> mScreens;
+ QPlatformFontDatabase *mFontDb;
+
+ QCocoaAutoReleasePool *mPool;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm
new file mode 100644
index 0000000000..7c4319c5e7
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm
@@ -0,0 +1,132 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qcocoaintegration.h"
+
+#include "qcocoawindow.h"
+#include "qcocoawindowsurface.h"
+#include "qcocoaeventloopintegration.h"
+
+#include "qcoretextfontdatabase.h"
+
+#include <QtGui/QApplication>
+
+#include <private/qpixmap_raster_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QCocoaScreen::QCocoaScreen(int screenIndex)
+ :QPlatformScreen()
+{
+ m_screen = [[NSScreen screens] objectAtIndex:screenIndex];
+ NSRect rect = [m_screen frame];
+ m_geometry = QRect(rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);
+
+ m_format = QImage::Format_ARGB32;
+
+ m_depth = NSBitsPerPixelFromDepth([m_screen depth]);
+
+ const int dpi = 72;
+ const qreal inch = 25.4;
+ m_physicalSize = QSize(qRound(m_geometry.width() * inch / dpi), qRound(m_geometry.height() *inch / dpi));
+}
+
+QCocoaScreen::~QCocoaScreen()
+{
+}
+
+QCocoaIntegration::QCocoaIntegration()
+ : mFontDb(new QCoreTextFontDatabase())
+{
+ mPool = new QCocoaAutoReleasePool;
+
+ //Make sure we have a nsapplication :)
+ [NSApplication sharedApplication];
+// [[OurApplication alloc] init];
+
+ NSArray *screens = [NSScreen screens];
+ for (uint i = 0; i < [screens count]; i++) {
+ QCocoaScreen *screen = new QCocoaScreen(i);
+ mScreens.append(screen);
+ }
+}
+
+QCocoaIntegration::~QCocoaIntegration()
+{
+ delete mPool;
+}
+
+bool QCocoaIntegration::hasCapability(QPlatformIntegration::Capability cap) const
+{
+ switch (cap) {
+ case ThreadedPixmaps: return true;
+ default: return QPlatformIntegration::hasCapability(cap);
+ }
+}
+
+
+
+QPixmapData *QCocoaIntegration::createPixmapData(QPixmapData::PixelType type) const
+{
+ return new QRasterPixmapData(type);
+}
+
+QPlatformWindow *QCocoaIntegration::createPlatformWindow(QWidget *widget, WId winId) const
+{
+ Q_UNUSED(winId);
+ return new QCocoaWindow(widget);
+}
+
+QWindowSurface *QCocoaIntegration::createWindowSurface(QWidget *widget, WId winId) const
+{
+ return new QCocoaWindowSurface(widget,winId);
+}
+
+QPlatformFontDatabase *QCocoaIntegration::fontDatabase() const
+{
+ return mFontDb;
+}
+
+QPlatformEventLoopIntegration *QCocoaIntegration::createEventLoopIntegration() const
+{
+ return new QCocoaEventLoopIntegration();
+}
+QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h
new file mode 100644
index 0000000000..b71879de41
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qcocoawindow.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QCOCOAWINDOW_H
+#define QCOCOAWINDOW_H
+
+#include <Cocoa/Cocoa.h>
+
+#include <QPlatformWindow>
+
+QT_BEGIN_NAMESPACE
+
+class QCocoaWindow : public QPlatformWindow
+{
+public:
+ QCocoaWindow(QWidget *tlw);
+ ~QCocoaWindow();
+
+ void setGeometry(const QRect &rect);
+
+ void setVisible(bool visible);
+
+ WId winId() const;
+
+ NSView *contentView() const;
+ void setContentView(NSView *contentView);
+
+ void windowDidResize();
+
+private:
+ NSWindow *m_nsWindow;
+};
+
+QT_END_NAMESPACE
+
+#endif // QCOCOAWINDOW_H
+
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
new file mode 100644
index 0000000000..aa54fe90ad
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "qcocoawindow.h"
+#include "qnswindowdelegate.h"
+#include "qcocoaautoreleasepool.h"
+
+#include <QWidget>
+
+#include <QtGui/QApplication>
+
+#include <QWindowSystemInterface>
+
+#include <QDebug>
+
+QCocoaWindow::QCocoaWindow(QWidget *tlw)
+ : QPlatformWindow(tlw)
+{
+ QCocoaAutoReleasePool pool;
+ const QRect geo = tlw->geometry();
+ NSRect frame = NSMakeRect(geo.x(), geo.y(), geo.width(), geo.height());
+
+ m_nsWindow = [[NSWindow alloc] initWithContentRect:frame
+ styleMask:NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask
+ backing:NSBackingStoreBuffered
+ defer:YES];
+
+ QNSWindowDelegate *delegate = [[QNSWindowDelegate alloc] initWithQCocoaWindow:this];
+ [m_nsWindow setDelegate:delegate];
+
+ [m_nsWindow makeKeyAndOrderFront:nil];
+ [m_nsWindow setAcceptsMouseMovedEvents:YES];
+}
+
+QCocoaWindow::~QCocoaWindow()
+{
+}
+
+void QCocoaWindow::setGeometry(const QRect &rect)
+{
+ QPlatformWindow::setGeometry(rect);
+
+ NSRect bounds = NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height());
+ [[m_nsWindow contentView]setFrameSize:bounds.size];
+}
+
+void QCocoaWindow::setVisible(bool visible)
+{
+ Q_UNUSED(visible);
+}
+
+WId QCocoaWindow::winId() const
+{
+ return WId([m_nsWindow windowNumber]);
+}
+
+NSView *QCocoaWindow::contentView() const
+{
+ return [m_nsWindow contentView];
+}
+
+void QCocoaWindow::setContentView(NSView *contentView)
+{
+ [m_nsWindow setContentView:contentView];
+}
+
+void QCocoaWindow::windowDidResize()
+{
+ //jlind: XXX This isn't ideal. Eventdispatcher does not run when resizing...
+ NSRect rect = [[m_nsWindow contentView]frame];
+ QRect geo(rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);
+ QWindowSystemInterface::handleGeometryChange(widget(),geo);
+}
diff --git a/src/plugins/platforms/cocoa/qcocoawindowsurface.h b/src/plugins/platforms/cocoa/qcocoawindowsurface.h
new file mode 100644
index 0000000000..5ae7be197d
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qcocoawindowsurface.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QWINDOWSURFACE_COCOA_H
+#define QWINDOWSURFACE_COCOA_H
+
+#include <Cocoa/Cocoa.h>
+
+#include "qcocoawindow.h"
+#include "qnsview.h"
+
+#include <QtGui/private/qwindowsurface_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QCocoaWindowSurface : public QWindowSurface
+{
+public:
+ QCocoaWindowSurface(QWidget *window, WId wid);
+ ~QCocoaWindowSurface();
+
+ QPaintDevice *paintDevice();
+ void flush(QWidget *widget, const QRegion &region, const QPoint &offset);
+ void resize (const QSize &size);
+
+private:
+
+ QCocoaWindow *m_cocoaWindow;
+ QImage *m_image;
+ QNSView *m_contentView;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/platforms/cocoa/qcocoawindowsurface.mm b/src/plugins/platforms/cocoa/qcocoawindowsurface.mm
new file mode 100644
index 0000000000..ecf6879c67
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qcocoawindowsurface.mm
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qcocoawindowsurface.h"
+
+#include <QtCore/qdebug.h>
+
+#include <QtGui/QPainter>
+
+QT_BEGIN_NAMESPACE
+
+QRect flipedRect(const QRect &sourceRect,int height)
+{
+ if (!sourceRect.isValid())
+ return QRect();
+ QRect flippedRect = sourceRect;
+ flippedRect.moveTop(height - sourceRect.y());
+ return flippedRect;
+}
+
+QCocoaWindowSurface::QCocoaWindowSurface(QWidget *window, WId wId)
+ : QWindowSurface(window)
+{
+ m_cocoaWindow = static_cast<QCocoaWindow *>(window->platformWindow());
+
+ const QRect geo = window->geometry();
+ NSRect rect = NSMakeRect(geo.x(),geo.y(),geo.width(),geo.height());
+ m_contentView = [[QNSView alloc] initWithWidget:window];
+ m_cocoaWindow->setContentView(m_contentView);
+
+ m_image = new QImage(window->size(),QImage::Format_ARGB32);
+}
+
+QCocoaWindowSurface::~QCocoaWindowSurface()
+{
+ delete m_image;
+}
+
+QPaintDevice *QCocoaWindowSurface::paintDevice()
+{
+ return m_image;
+}
+
+void QCocoaWindowSurface::flush(QWidget *widget, const QRegion &region, const QPoint &offset)
+{
+ Q_UNUSED(widget);
+ Q_UNUSED(offset);
+
+ QRect geo = region.boundingRect();
+
+ NSRect rect = NSMakeRect(geo.x(), geo.y(), geo.width(), geo.height());
+ [m_contentView displayRect:rect];
+}
+
+void QCocoaWindowSurface::resize(const QSize &size)
+{
+ QWindowSurface::resize(size);
+ delete m_image;
+ m_image = new QImage(size,QImage::Format_ARGB32_Premultiplied);
+ NSSize newSize = NSMakeSize(size.width(),size.height());
+ [m_contentView setImage:m_image];
+
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qnsview.h b/src/plugins/platforms/cocoa/qnsview.h
new file mode 100644
index 0000000000..fc946e2f29
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qnsview.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QNSVIEW_H
+#define QNSVIEW_H
+
+#include <Cocoa/Cocoa.h>
+
+#include <QtGui/QImage>
+
+@interface QNSView : NSView {
+ CGImageRef m_cgImage;
+ QWidget *m_widget;
+ Qt::MouseButtons m_buttons;
+}
+
+- (id)init;
+- (id)initWithWidget:(QWidget *)widget;
+
+- (void)setImage:(QImage *)image;
+- (void)drawRect:(NSRect)dirtyRect;
+
+- (BOOL)isFlipped;
+
+- (void)handleMouseEvent:(NSEvent *)theEvent;
+- (void)mouseDown:(NSEvent *)theEvent;
+- (void)mouseDragged:(NSEvent *)theEvent;
+- (void)mouseUp:(NSEvent *)theEvent;
+- (void)mouseMoved:(NSEvent *)theEvent;
+- (void)mouseEntered:(NSEvent *)theEvent;
+- (void)mouseExited:(NSEvent *)theEvent;
+- (void)rightMouseDown:(NSEvent *)theEvent;
+- (void)rightMouseDragged:(NSEvent *)theEvent;
+- (void)rightMouseUp:(NSEvent *)theEvent;
+- (void)otherMouseDown:(NSEvent *)theEvent;
+- (void)otherMouseDragged:(NSEvent *)theEvent;
+- (void)otherMouseUp:(NSEvent *)theEvent;
+
+@end
+
+#endif //QNSVIEW_H
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
new file mode 100644
index 0000000000..6fda27b352
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -0,0 +1,211 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qnsview.h"
+
+#include <QtGui/QWindowSystemInterface>
+
+#include <QtCore/QDebug>
+
+@implementation QNSView
+
+- (id) init
+{
+ self = [super init];
+ if (self) {
+ m_cgImage = 0;
+ m_widget = 0;
+ m_buttons = Qt::NoButton;
+ }
+ return self;
+}
+
+- (id)initWithWidget:(QWidget *)widget {
+ self = [self init];
+ if (self) {
+ m_widget = widget;
+ }
+ return self;
+}
+
+- (void) setImage:(QImage *)image
+{
+ CGImageRelease(m_cgImage);
+
+ const uchar *imageData = image->bits();
+ int bitDepth = image->depth();
+ int colorBufferSize = 8;
+ int bytesPrLine = image->bytesPerLine();
+ int width = image->width();
+ int height = image->height();
+
+ CGColorSpaceRef cgColourSpaceRef = CGColorSpaceCreateDeviceRGB();
+
+ CGDataProviderRef cgDataProviderRef = CGDataProviderCreateWithData(
+ NULL,
+ imageData,
+ image->byteCount(),
+ NULL);
+
+ m_cgImage = CGImageCreate(width,
+ height,
+ colorBufferSize,
+ bitDepth,
+ bytesPrLine,
+ cgColourSpaceRef,
+ kCGImageAlphaNone,
+ cgDataProviderRef,
+ NULL,
+ false,
+ kCGRenderingIntentDefault);
+
+ CGColorSpaceRelease(cgColourSpaceRef);
+
+}
+
+- (void) drawRect:(NSRect)dirtyRect
+{
+ if (!m_cgImage)
+ return;
+
+ CGRect dirtyCGRect = NSRectToCGRect(dirtyRect);
+
+ NSGraphicsContext *nsGraphicsContext = [NSGraphicsContext currentContext];
+ CGContextRef cgContext = (CGContextRef) [nsGraphicsContext graphicsPort];
+
+ CGContextSaveGState( cgContext );
+ int dy = dirtyCGRect.origin.y + CGRectGetMaxY(dirtyCGRect);
+ CGContextTranslateCTM(cgContext, 0, dy);
+ CGContextScaleCTM(cgContext, 1, -1);
+
+ CGImageRef subImage = CGImageCreateWithImageInRect(m_cgImage, dirtyCGRect);
+ CGContextDrawImage(cgContext,dirtyCGRect,subImage);
+
+ CGContextRestoreGState(cgContext);
+
+ CGImageRelease(subImage);
+
+}
+
+- (BOOL) isFlipped
+{
+ return YES;
+}
+
+- (void)handleMouseEvent:(NSEvent *)theEvent;
+{
+ NSPoint point = [self convertPoint: [theEvent locationInWindow] fromView: nil];
+ QPoint qt_localPoint(point.x,point.y);
+
+ NSTimeInterval timestamp = [theEvent timestamp];
+ ulong qt_timestamp = timestamp * 1000;
+
+ QWindowSystemInterface::handleMouseEvent(m_widget,qt_timestamp,qt_localPoint,QPoint(),m_buttons);
+
+}
+ - (void)mouseDown:(NSEvent *)theEvent
+ {
+ m_buttons |= Qt::LeftButton;
+ [self handleMouseEvent:theEvent];
+ }
+ - (void)mouseDragged:(NSEvent *)theEvent
+ {
+ if (!(m_buttons & Qt::LeftButton))
+ qWarning("Internal Mousebutton tracking invalid(missing Qt::LeftButton");
+ [self handleMouseEvent:theEvent];
+ }
+ - (void)mouseUp:(NSEvent *)theEvent
+ {
+ m_buttons &= QFlag(~int(Qt::LeftButton));
+ [self handleMouseEvent:theEvent];
+ }
+
+- (void)mouseMoved:(NSEvent *)theEvent
+{
+ qDebug() << "mouseMove";
+ [self handleMouseEvent:theEvent];
+}
+- (void)mouseEntered:(NSEvent *)theEvent
+{
+ Q_UNUSED(theEvent);
+ QWindowSystemInterface::handleEnterEvent(m_widget);
+}
+- (void)mouseExited:(NSEvent *)theEvent
+{
+ Q_UNUSED(theEvent);
+ QWindowSystemInterface::handleLeaveEvent(m_widget);
+}
+- (void)rightMouseDown:(NSEvent *)theEvent
+{
+ m_buttons |= Qt::RightButton;
+ [self handleMouseEvent:theEvent];
+}
+- (void)rightMouseDragged:(NSEvent *)theEvent
+{
+ if (!(m_buttons & Qt::LeftButton))
+ qWarning("Internal Mousebutton tracking invalid(missing Qt::LeftButton");
+ [self handleMouseEvent:theEvent];
+}
+- (void)rightMouseUp:(NSEvent *)theEvent
+{
+ m_buttons &= QFlag(~int(Qt::RightButton));
+ [self handleMouseEvent:theEvent];
+}
+- (void)otherMouseDown:(NSEvent *)theEvent
+{
+ m_buttons |= Qt::RightButton;
+ [self handleMouseEvent:theEvent];
+}
+- (void)otherMouseDragged:(NSEvent *)theEvent
+{
+ if (!(m_buttons & Qt::LeftButton))
+ qWarning("Internal Mousebutton tracking invalid(missing Qt::LeftButton");
+ [self handleMouseEvent:theEvent];
+}
+- (void)otherMouseUp:(NSEvent *)theEvent
+{
+ m_buttons &= QFlag(~int(Qt::MiddleButton));
+ [self handleMouseEvent:theEvent];
+}
+
+
+
+@end
diff --git a/src/plugins/platforms/cocoa/qnswindowdelegate.h b/src/plugins/platforms/cocoa/qnswindowdelegate.h
new file mode 100644
index 0000000000..f4dcec73dd
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qnswindowdelegate.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QNSWINDOWDELEGATE_H
+#define QNSWINDOWDELEGATE_H
+
+#include <Cocoa/Cocoa.h>
+
+#include "qcocoawindow.h"
+
+@interface QNSWindowDelegate : NSObject <NSWindowDelegate>
+{
+ QCocoaWindow *m_cocoaWindow;
+}
+
+- (id)initWithQCocoaWindow: (QCocoaWindow *) cocoaWindow;
+
+- (void)windowDidResize:(NSNotification *)notification;
+- (void)windowWillClose:(NSNotification *)notification;
+
+@end
+
+#endif // QNSWINDOWDELEGATE_H
diff --git a/src/plugins/platforms/cocoa/qnswindowdelegate.mm b/src/plugins/platforms/cocoa/qnswindowdelegate.mm
new file mode 100644
index 0000000000..58dffb7c09
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qnswindowdelegate.mm
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qnswindowdelegate.h"
+
+#include <QDebug>
+#include <QWindowSystemInterface>
+
+@implementation QNSWindowDelegate
+
+- (id) initWithQCocoaWindow: (QCocoaWindow *) cocoaWindow
+{
+ self = [super init];
+
+ if (self) {
+ m_cocoaWindow = cocoaWindow;
+ }
+ return self;
+}
+
+- (void)windowDidResize:(NSNotification *)notification
+{
+ Q_UNUSED(notification);
+ if (m_cocoaWindow) {
+ m_cocoaWindow->windowDidResize();
+ }
+}
+
+- (void)windowWillClose:(NSNotification *)notification
+{
+ Q_UNUSED(notification);
+ QWindowSystemInterface::handleCloseEvent(m_cocoaWindow->widget());
+}
+
+@end