summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
authorMorten Sorvig <morten.sorvig@nokia.com>2011-05-18 12:09:17 +0200
committerMorten Sorvig <morten.sorvig@nokia.com>2011-05-18 12:09:17 +0200
commit864815ef2efbc3b5dca2a645c1b63f9bb67285d0 (patch)
treeae2c208919d2f0ff5c9fadadce009170bee46ad5 /src/plugins/platforms
parent516f4e283ba4626d7239630397ef867ab0366071 (diff)
Port Qt 5 to Mac.
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r--src/plugins/platforms/cocoa/cocoa.pro10
-rw-r--r--src/plugins/platforms/cocoa/qcocoaeventloopintegration.mm3
-rw-r--r--src/plugins/platforms/cocoa/qcocoaglcontext.h27
-rw-r--r--src/plugins/platforms/cocoa/qcocoaglcontext.mm78
-rw-r--r--src/plugins/platforms/cocoa/qcocoaintegration.h4
-rw-r--r--src/plugins/platforms/cocoa/qcocoaintegration.mm16
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.h15
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm40
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindowsurface.h6
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindowsurface.mm17
-rw-r--r--src/plugins/platforms/cocoa/qnsview.h11
-rw-r--r--src/plugins/platforms/cocoa/qnsview.mm131
-rw-r--r--src/plugins/platforms/cocoa/qnswindowdelegate.h20
-rw-r--r--src/plugins/platforms/cocoa/qnswindowdelegate.mm2
14 files changed, 306 insertions, 74 deletions
diff --git a/src/plugins/platforms/cocoa/cocoa.pro b/src/plugins/platforms/cocoa/cocoa.pro
index 705e60439e..87846a9092 100644
--- a/src/plugins/platforms/cocoa/cocoa.pro
+++ b/src/plugins/platforms/cocoa/cocoa.pro
@@ -9,7 +9,8 @@ OBJECTIVE_SOURCES = main.mm \
qnsview.mm \
qcocoaeventloopintegration.mm \
qcocoaautoreleasepool.mm \
- qnswindowdelegate.mm
+ qnswindowdelegate.mm \
+ qcocoaglcontext.mm
OBJECTIVE_HEADERS = qcocoaintegration.h \
qcocoawindowsurface.h \
@@ -17,13 +18,16 @@ OBJECTIVE_HEADERS = qcocoaintegration.h \
qnsview.h \
qcocoaeventloopintegration.h \
qcocoaautoreleasepool.h \
- qnswindowdelegate.h
+ qnswindowdelegate.h \
+ qcocoaglcontext.h
#add libz for freetype.
LIBS += -lz
LIBS += -framework cocoa
-include(../fontdatabases/coretext/coretext.pri)
+QT += core-private gui-private
+
+include(../fontdatabases/basicunix/basicunix.pri)
target.path += $$[QT_INSTALL_PLUGINS]/platforms
INSTALLS += target
diff --git a/src/plugins/platforms/cocoa/qcocoaeventloopintegration.mm b/src/plugins/platforms/cocoa/qcocoaeventloopintegration.mm
index 885916ed74..d9858b0e9a 100644
--- a/src/plugins/platforms/cocoa/qcocoaeventloopintegration.mm
+++ b/src/plugins/platforms/cocoa/qcocoaeventloopintegration.mm
@@ -47,9 +47,6 @@
#include <QtCore/QElapsedTimer>
-#include <QDebug>
-#include <QApplication>
-
void wakeupCallback ( void * ) {
QPlatformEventLoopIntegration::processEvents();
}
diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.h b/src/plugins/platforms/cocoa/qcocoaglcontext.h
new file mode 100644
index 0000000000..b9a84a1606
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qcocoaglcontext.h
@@ -0,0 +1,27 @@
+#ifndef QCOCOAGLCONTEXT_H
+#define QCOCOAGLCONTEXT_H
+
+#include <QtGui/QPlatformGLContext>
+#include <QtGui/QWindowFormat>
+
+#include <Cocoa/Cocoa.h>
+
+QT_BEGIN_NAMESPACE
+
+class QCocoaGLContext : public QPlatformGLContext
+{
+public:
+ QCocoaGLContext(NSOpenGLView *glView);
+ void makeCurrent();
+ void doneCurrent();
+ void swapBuffers();
+ void* getProcAddress(const QString& procName);
+ QWindowFormat windowFormat() const;
+ static NSOpenGLPixelFormat *createNSOpenGLPixelFormat();
+private:
+ NSOpenGLView *m_glView;
+};
+
+QT_END_NAMESPACE
+
+#endif // QCOCOAGLCONTEXT_H
diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm
new file mode 100644
index 0000000000..505be4a9de
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm
@@ -0,0 +1,78 @@
+#include "qcocoaglcontext.h"
+#include <qdebug.h>
+#include <QtCore/private/qcore_mac_p.h>
+
+#import <Cocoa/Cocoa.h>
+
+QCocoaGLContext::QCocoaGLContext(NSOpenGLView *glView)
+:m_glView(glView)
+{
+
+}
+
+void QCocoaGLContext::makeCurrent()
+{
+ [[m_glView openGLContext] makeCurrentContext];
+}
+void QCocoaGLContext::doneCurrent()
+{
+ [NSOpenGLContext clearCurrentContext];
+}
+
+void QCocoaGLContext::swapBuffers()
+{
+ [[m_glView openGLContext] flushBuffer];
+}
+
+void* QCocoaGLContext::getProcAddress(const QString& procName)
+{
+ CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
+ CFSTR("/System/Library/Frameworks/OpenGL.framework"), kCFURLPOSIXPathStyle, false);
+ CFBundleRef bundle = CFBundleCreate(kCFAllocatorDefault, url);
+ CFStringRef procNameCF = QCFString::toCFStringRef(procName);
+ void *proc = CFBundleGetFunctionPointerForName(bundle, procNameCF);
+ CFRelease(url);
+ CFRelease(bundle);
+ CFRelease(procNameCF);
+ return proc;
+}
+
+// Match up with createNSOpenGLPixelFormat below!
+QWindowFormat QCocoaGLContext::windowFormat() const
+{
+ QWindowFormat format;
+ format.setRedBufferSize(8);
+ format.setGreenBufferSize(8);
+ format.setBlueBufferSize(8);
+ format.setAlphaBufferSize(8);
+
+/*
+ format.setDepthBufferSize(24);
+ format.setAccumBufferSize(0);
+ format.setStencilBufferSize(8);
+ format.setSampleBuffers(false);
+ format.setSamples(1);
+ format.setDepth(true);
+ format.setRgba(true);
+ format.setAlpha(true);
+ format.setAccum(false);
+ format.setStencil(true);
+ format.setStereo(false);
+ format.setDirectRendering(false);
+*/
+ return format;
+}
+
+NSOpenGLPixelFormat *QCocoaGLContext::createNSOpenGLPixelFormat()
+{
+ NSOpenGLPixelFormatAttribute attrs[] =
+ {
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFADepthSize, 32,
+ 0
+ };
+
+ NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
+ return pixelFormat;
+}
+
diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.h b/src/plugins/platforms/cocoa/qcocoaintegration.h
index 2a04e8c2ed..21bdf6c045 100644
--- a/src/plugins/platforms/cocoa/qcocoaintegration.h
+++ b/src/plugins/platforms/cocoa/qcocoaintegration.h
@@ -77,8 +77,8 @@ public:
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;
+ QPlatformWindow *createPlatformWindow(QWindow *window) const;
+ QWindowSurface *createWindowSurface(QWindow *widget, WId winId) const;
QList<QPlatformScreen *> screens() const { return mScreens; }
diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm
index 7c4319c5e7..ab8763ad4a 100644
--- a/src/plugins/platforms/cocoa/qcocoaintegration.mm
+++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm
@@ -45,9 +45,7 @@
#include "qcocoawindowsurface.h"
#include "qcocoaeventloopintegration.h"
-#include "qcoretextfontdatabase.h"
-
-#include <QtGui/QApplication>
+#include "qbasicunixfontdatabase.h"
#include <private/qpixmap_raster_p.h>
@@ -74,7 +72,7 @@ QCocoaScreen::~QCocoaScreen()
}
QCocoaIntegration::QCocoaIntegration()
- : mFontDb(new QCoreTextFontDatabase())
+ : mFontDb(new QBasicUnixFontDatabase())
{
mPool = new QCocoaAutoReleasePool;
@@ -98,6 +96,7 @@ bool QCocoaIntegration::hasCapability(QPlatformIntegration::Capability cap) cons
{
switch (cap) {
case ThreadedPixmaps: return true;
+ case OpenGL : return true;
default: return QPlatformIntegration::hasCapability(cap);
}
}
@@ -109,15 +108,14 @@ QPixmapData *QCocoaIntegration::createPixmapData(QPixmapData::PixelType type) co
return new QRasterPixmapData(type);
}
-QPlatformWindow *QCocoaIntegration::createPlatformWindow(QWidget *widget, WId winId) const
+QPlatformWindow *QCocoaIntegration::createPlatformWindow(QWindow *window) const
{
- Q_UNUSED(winId);
- return new QCocoaWindow(widget);
+ return new QCocoaWindow(window);
}
-QWindowSurface *QCocoaIntegration::createWindowSurface(QWidget *widget, WId winId) const
+QWindowSurface *QCocoaIntegration::createWindowSurface(QWindow *window, WId winId) const
{
- return new QCocoaWindowSurface(widget,winId);
+ return new QCocoaWindowSurface(window, winId);
}
QPlatformFontDatabase *QCocoaIntegration::fontDatabase() const
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h
index b71879de41..98e3de29cb 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.h
+++ b/src/plugins/platforms/cocoa/qcocoawindow.h
@@ -46,27 +46,32 @@
#include <QPlatformWindow>
+#include "qcocoaglcontext.h"
+#include "qnsview.h"
+
QT_BEGIN_NAMESPACE
class QCocoaWindow : public QPlatformWindow
{
public:
- QCocoaWindow(QWidget *tlw);
+ QCocoaWindow(QWindow *tlw);
~QCocoaWindow();
void setGeometry(const QRect &rect);
-
void setVisible(bool visible);
-
WId winId() const;
-
NSView *contentView() const;
- void setContentView(NSView *contentView);
void windowDidResize();
+ QPlatformGLContext *glContext() const;
+
private:
+ friend class QCocoaWindowSurface;
NSWindow *m_nsWindow;
+ QNSView *m_contentView;
+ NSView *m_windowSurfaceView;
+ mutable QCocoaGLContext *m_glContext;
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index aa54fe90ad..a0ac3a69a8 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -41,17 +41,16 @@
#include "qcocoawindow.h"
#include "qnswindowdelegate.h"
#include "qcocoaautoreleasepool.h"
-
-#include <QWidget>
-
-#include <QtGui/QApplication>
+#include "qcocoaglcontext.h"
+#include "qnsview.h"
#include <QWindowSystemInterface>
#include <QDebug>
-QCocoaWindow::QCocoaWindow(QWidget *tlw)
+QCocoaWindow::QCocoaWindow(QWindow *tlw)
: QPlatformWindow(tlw)
+ , m_glContext(0)
{
QCocoaAutoReleasePool pool;
const QRect geo = tlw->geometry();
@@ -67,6 +66,20 @@ QCocoaWindow::QCocoaWindow(QWidget *tlw)
[m_nsWindow makeKeyAndOrderFront:nil];
[m_nsWindow setAcceptsMouseMovedEvents:YES];
+
+ m_contentView = [[QNSView alloc] initWithQWindow:tlw];
+
+ if (tlw->surfaceType() == QWindow::OpenGLSurface) {
+ NSRect glFrame = NSMakeRect(0, 0, geo.width(), geo.height());
+ m_windowSurfaceView = [[NSOpenGLView alloc] initWithFrame : glFrame pixelFormat : QCocoaGLContext::createNSOpenGLPixelFormat() ];
+ [m_contentView setAutoresizesSubviews : YES];
+ [m_windowSurfaceView setAutoresizingMask : (NSViewWidthSizable | NSViewHeightSizable)];
+ [m_contentView addSubview : m_windowSurfaceView];
+ } else {
+ m_windowSurfaceView = m_contentView;
+ }
+
+ [m_nsWindow setContentView:m_contentView];
}
QCocoaWindow::~QCocoaWindow()
@@ -88,7 +101,7 @@ void QCocoaWindow::setVisible(bool visible)
WId QCocoaWindow::winId() const
{
- return WId([m_nsWindow windowNumber]);
+ return WId(m_nsWindow);
}
NSView *QCocoaWindow::contentView() const
@@ -96,15 +109,18 @@ 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);
+ QWindowSystemInterface::handleGeometryChange(window(),geo);
+}
+
+QPlatformGLContext *QCocoaWindow::glContext() const
+{
+ if (!m_glContext) {
+ m_glContext = new QCocoaGLContext(m_windowSurfaceView);
+ }
+ return m_glContext;
}
diff --git a/src/plugins/platforms/cocoa/qcocoawindowsurface.h b/src/plugins/platforms/cocoa/qcocoawindowsurface.h
index 5ae7be197d..01e504e08d 100644
--- a/src/plugins/platforms/cocoa/qcocoawindowsurface.h
+++ b/src/plugins/platforms/cocoa/qcocoawindowsurface.h
@@ -54,18 +54,16 @@ QT_BEGIN_NAMESPACE
class QCocoaWindowSurface : public QWindowSurface
{
public:
- QCocoaWindowSurface(QWidget *window, WId wid);
+ QCocoaWindowSurface(QWindow *window, WId wid);
~QCocoaWindowSurface();
QPaintDevice *paintDevice();
- void flush(QWidget *widget, const QRegion &region, const QPoint &offset);
+ void flush(QWindow *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
diff --git a/src/plugins/platforms/cocoa/qcocoawindowsurface.mm b/src/plugins/platforms/cocoa/qcocoawindowsurface.mm
index ecf6879c67..02d5617f96 100644
--- a/src/plugins/platforms/cocoa/qcocoawindowsurface.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindowsurface.mm
@@ -42,7 +42,6 @@
#include "qcocoawindowsurface.h"
#include <QtCore/qdebug.h>
-
#include <QtGui/QPainter>
QT_BEGIN_NAMESPACE
@@ -56,17 +55,16 @@ QRect flipedRect(const QRect &sourceRect,int height)
return flippedRect;
}
-QCocoaWindowSurface::QCocoaWindowSurface(QWidget *window, WId wId)
+QCocoaWindowSurface::QCocoaWindowSurface(QWindow *window, WId wId)
: QWindowSurface(window)
{
- m_cocoaWindow = static_cast<QCocoaWindow *>(window->platformWindow());
+ Q_UNUSED(wId);
+ m_cocoaWindow = static_cast<QCocoaWindow *>(window->handle());
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);
+ m_image = new QImage(window->geometry().size(),QImage::Format_ARGB32);
}
QCocoaWindowSurface::~QCocoaWindowSurface()
@@ -79,7 +77,7 @@ QPaintDevice *QCocoaWindowSurface::paintDevice()
return m_image;
}
-void QCocoaWindowSurface::flush(QWidget *widget, const QRegion &region, const QPoint &offset)
+void QCocoaWindowSurface::flush(QWindow *widget, const QRegion &region, const QPoint &offset)
{
Q_UNUSED(widget);
Q_UNUSED(offset);
@@ -87,7 +85,7 @@ void QCocoaWindowSurface::flush(QWidget *widget, const QRegion &region, const QP
QRect geo = region.boundingRect();
NSRect rect = NSMakeRect(geo.x(), geo.y(), geo.width(), geo.height());
- [m_contentView displayRect:rect];
+ [m_cocoaWindow->m_windowSurfaceView displayRect:rect];
}
void QCocoaWindowSurface::resize(const QSize &size)
@@ -96,8 +94,7 @@ void QCocoaWindowSurface::resize(const QSize &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];
-
+ [m_cocoaWindow->m_windowSurfaceView setImage:m_image];
}
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qnsview.h b/src/plugins/platforms/cocoa/qnsview.h
index fc946e2f29..81bea27304 100644
--- a/src/plugins/platforms/cocoa/qnsview.h
+++ b/src/plugins/platforms/cocoa/qnsview.h
@@ -48,17 +48,18 @@
@interface QNSView : NSView {
CGImageRef m_cgImage;
- QWidget *m_widget;
+ QWindow *m_window;
Qt::MouseButtons m_buttons;
}
- (id)init;
-- (id)initWithWidget:(QWidget *)widget;
+- (id)initWithQWindow:(QWindow *)window;
- (void)setImage:(QImage *)image;
- (void)drawRect:(NSRect)dirtyRect;
- (BOOL)isFlipped;
+- (BOOL)acceptsFirstResponder;
- (void)handleMouseEvent:(NSEvent *)theEvent;
- (void)mouseDown:(NSEvent *)theEvent;
@@ -74,6 +75,12 @@
- (void)otherMouseDragged:(NSEvent *)theEvent;
- (void)otherMouseUp:(NSEvent *)theEvent;
+- (int) convertKeyCode : (QChar)keyCode;
+- (Qt::KeyboardModifiers) convertKeyModifiers : (ulong)modifierFlags;
+- (void)handleKeyEvent:(NSEvent *)theEvent eventType:(int)eventType;
+- (void)keyDown:(NSEvent *)theEvent;
+- (void)keyUp:(NSEvent *)theEvent;
+
@end
#endif //QNSVIEW_H
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index 6fda27b352..ba9bb9e691 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -52,16 +52,16 @@
self = [super init];
if (self) {
m_cgImage = 0;
- m_widget = 0;
+ m_window = 0;
m_buttons = Qt::NoButton;
}
return self;
}
-- (id)initWithWidget:(QWidget *)widget {
+- (id)initWithQWindow:(QWindow *)widget {
self = [self init];
if (self) {
- m_widget = widget;
+ m_window = widget;
}
return self;
}
@@ -130,6 +130,11 @@
return YES;
}
+- (BOOL)acceptsFirstResponder
+{
+ return YES;
+}
+
- (void)handleMouseEvent:(NSEvent *)theEvent;
{
NSPoint point = [self convertPoint: [theEvent locationInWindow] fromView: nil];
@@ -138,40 +143,42 @@
NSTimeInterval timestamp = [theEvent timestamp];
ulong qt_timestamp = timestamp * 1000;
- QWindowSystemInterface::handleMouseEvent(m_widget,qt_timestamp,qt_localPoint,QPoint(),m_buttons);
+ QWindowSystemInterface::handleMouseEvent(m_window,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)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);
+ QWindowSystemInterface::handleEnterEvent(m_window);
}
- (void)mouseExited:(NSEvent *)theEvent
{
Q_UNUSED(theEvent);
- QWindowSystemInterface::handleLeaveEvent(m_widget);
+ QWindowSystemInterface::handleLeaveEvent(m_window);
}
- (void)rightMouseDown:(NSEvent *)theEvent
{
@@ -206,6 +213,84 @@
[self handleMouseEvent:theEvent];
}
+- (int) convertKeyCode : (QChar)keyChar
+{
+ if (keyChar.isLower())
+ keyChar = keyChar.toUpper();
+ int keyCode = keyChar.unicode();
+
+ int qtKeyCode = Qt::Key(keyCode); // default case, overrides below
+ switch (keyCode) {
+ case NSEnterCharacter: qtKeyCode = Qt::Key_Enter; break;
+ case NSBackspaceCharacter: qtKeyCode = Qt::Key_Backspace; break;
+ case NSTabCharacter: qtKeyCode = Qt::Key_Tab; break;
+ case NSNewlineCharacter: qtKeyCode = Qt::Key_Return; break;
+ case NSCarriageReturnCharacter: qtKeyCode = Qt::Key_Return; break;
+ case NSBackTabCharacter: qtKeyCode = Qt::Key_Backtab; break;
+ case 27 : qtKeyCode = Qt::Key_Escape; break;
+ case NSDeleteCharacter : qtKeyCode = Qt::Key_Backspace; break; // Cocoa sends us delete when pressing backspace.
+ case NSUpArrowFunctionKey: qtKeyCode = Qt::Key_Up; break;
+ case NSDownArrowFunctionKey: qtKeyCode = Qt::Key_Down; break;
+ case NSLeftArrowFunctionKey: qtKeyCode = Qt::Key_Left; break;
+ case NSRightArrowFunctionKey: qtKeyCode = Qt::Key_Right; break;
+ case NSInsertFunctionKey: qtKeyCode = Qt::Key_Insert; break;
+ case NSDeleteFunctionKey: qtKeyCode = Qt::Key_Delete; break;
+ case NSHomeFunctionKey: qtKeyCode = Qt::Key_Home; break;
+ case NSEndFunctionKey: qtKeyCode = Qt::Key_End; break;
+ case NSPageUpFunctionKey: qtKeyCode = Qt::Key_PageUp; break;
+ case NSPageDownFunctionKey: qtKeyCode = Qt::Key_PageDown; break;
+ case NSPrintScreenFunctionKey: qtKeyCode = Qt::Key_Print; break;
+ case NSScrollLockFunctionKey: qtKeyCode = Qt::Key_ScrollLock; break;
+ case NSPauseFunctionKey: qtKeyCode = Qt::Key_Pause; break;
+ case NSSysReqFunctionKey: qtKeyCode = Qt::Key_SysReq; break;
+ case NSMenuFunctionKey: qtKeyCode = Qt::Key_Menu; break;
+ case NSHelpFunctionKey: qtKeyCode = Qt::Key_Help; break;
+ default : break;
+ }
+
+ // handle all function keys (F1-F35)
+ if (keyCode >= NSF1FunctionKey && keyCode <= NSF35FunctionKey)
+ qtKeyCode = Qt::Key_F1 + (keyCode - NSF1FunctionKey);
+
+ return qtKeyCode;
+}
+
+- (Qt::KeyboardModifiers) convertKeyModifiers : (ulong)modifierFlags
+{
+ Qt::KeyboardModifiers qtMods =Qt::NoModifier;
+ if (modifierFlags & NSShiftKeyMask)
+ qtMods |= Qt::ShiftModifier;
+ if (modifierFlags & NSControlKeyMask)
+ qtMods |= Qt::MetaModifier;
+ if (modifierFlags & NSAlternateKeyMask)
+ qtMods |= Qt::AltModifier;
+ if (modifierFlags & NSCommandKeyMask)
+ qtMods |= Qt::ControlModifier;
+ if (modifierFlags & NSNumericPadKeyMask)
+ qtMods |= Qt::KeypadModifier;
+ return qtMods;
+}
+
+- (void)handleKeyEvent:(NSEvent *)theEvent eventType:(int)eventType
+{
+ NSTimeInterval timestamp = [theEvent timestamp];
+ ulong qt_timestamp = timestamp * 1000;
+ QString characters = QString::fromUtf8([[theEvent characters] UTF8String]);
+ Qt::KeyboardModifiers modifiers = [self convertKeyModifiers : [theEvent modifierFlags]];
+ QChar ch([[theEvent charactersIgnoringModifiers] characterAtIndex:0]);
+ int keyCode = [self convertKeyCode : ch];
+
+ QWindowSystemInterface::handleKeyEvent(m_window, qt_timestamp, QEvent::Type(eventType), keyCode, modifiers, characters);
+}
+- (void)keyDown:(NSEvent *)theEvent
+{
+ [self handleKeyEvent : theEvent eventType :int(QEvent::KeyPress)];
+}
+
+- (void)keyUp:(NSEvent *)theEvent
+{
+ [self handleKeyEvent : theEvent eventType :int(QEvent::KeyRelease)];
+}
@end
diff --git a/src/plugins/platforms/cocoa/qnswindowdelegate.h b/src/plugins/platforms/cocoa/qnswindowdelegate.h
index f4dcec73dd..d6dabf05cb 100644
--- a/src/plugins/platforms/cocoa/qnswindowdelegate.h
+++ b/src/plugins/platforms/cocoa/qnswindowdelegate.h
@@ -46,6 +46,26 @@
#include "qcocoawindow.h"
+#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5
+@protocol NSWindowDelegate <NSObject>
+//- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize;
+//- (void)windowDidMiniaturize:(NSNotification*)notification;
+- (void)windowDidResize:(NSNotification *)notification;
+- (void)windowWillClose:(NSNotification *)notification;
+//- (NSRect)windowWillUseStandardFrame:(NSWindow *)window defaultFrame:(NSRect)defaultFrame;
+//- (void)windowDidMove:(NSNotification *)notification;
+//- (BOOL)windowShouldClose:(id)window;
+//- (void)windowDidDeminiaturize:(NSNotification *)notification;
+//- (void)windowDidBecomeMain:(NSNotification*)notification;
+//- (void)windowDidResignMain:(NSNotification*)notification;
+//- (void)windowDidBecomeKey:(NSNotification*)notification;
+//- (void)windowDidResignKey:(NSNotification*)notification;
+//- (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu;
+//- (BOOL)window:(NSWindow *)window shouldDragDocumentWithEvent:(NSEvent *)event from:(NSPoint)dragImageLocation withPasteboard:(NSPasteboard *)pasteboard;
+//- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame;
+@end
+#endif
+
@interface QNSWindowDelegate : NSObject <NSWindowDelegate>
{
QCocoaWindow *m_cocoaWindow;
diff --git a/src/plugins/platforms/cocoa/qnswindowdelegate.mm b/src/plugins/platforms/cocoa/qnswindowdelegate.mm
index 58dffb7c09..80e9ba272b 100644
--- a/src/plugins/platforms/cocoa/qnswindowdelegate.mm
+++ b/src/plugins/platforms/cocoa/qnswindowdelegate.mm
@@ -67,7 +67,7 @@
- (void)windowWillClose:(NSNotification *)notification
{
Q_UNUSED(notification);
- QWindowSystemInterface::handleCloseEvent(m_cocoaWindow->widget());
+ QWindowSystemInterface::handleCloseEvent(m_cocoaWindow->window());
}
@end