[m_nsWindow setDelegate:delegate];
[m_nsWindow setAcceptsMouseMovedEvents:YES];
+ // Prevent Cocoa from releasing the window on close. Qt
+ // handles the close event asynchronously and we want to
+ // make sure that m_nsWindow stays valid until the
+ // QCocoaWindow is deleted by Qt.
+ [m_nsWindow setReleasedWhenClosed : NO];
+
m_contentView = [[QNSView alloc] initWithQWindow:tlw];
- if (tlw->surfaceType() == QWindow::OpenGLSurface) {
- NSRect glFrame = globalGeometry(window()->geometry());
- 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;
- }
+ setGeometry(tlw->geometry());
[m_nsWindow setContentView:m_contentView];
}
QCocoaWindow::~QCocoaWindow()
{
-
+ [m_nsWindow release];
}
void QCocoaWindow::setGeometry(const QRect &rect)
{
QPlatformWindow::setGeometry(rect);
- NSRect bounds = globalGeometry(window()->geometry());
+ NSRect bounds = globalGeometry(rect);
[[m_nsWindow contentView]setFrameSize:bounds.size];
+ [m_nsWindow setContentSize : bounds.size];
[m_nsWindow setFrameOrigin : bounds.origin];
if (m_glContext)
if (window()->transientParent())
setGeometry(window()->geometry());
+ // Make sure the QWindow has a frame ready before we show the NSWindow.
+ QWindowSystemInterface::handleSynchronousExposeEvent(window(), QRect(QPoint(), geometry().size()));
+
[m_nsWindow makeKeyAndOrderFront:nil];
- QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(), geometry().size()));
} else {
[m_nsWindow orderOut:nil];
}
return [m_nsWindow contentView];
}
-NSView *QCocoaWindow::windowSurfaceView() const
-{
- return m_windowSurfaceView;
-}
-
void QCocoaWindow::windowDidMove()
{
if (m_glContext)
void QCocoaWindow::windowDidResize()
{
+ if (m_glContext)
+ m_glContext->update();
+
NSRect rect = [[m_nsWindow contentView]frame];
QRect geo(rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);
QWindowSystemInterface::handleSynchronousGeometryChange(window(), geo);
+}
- if (m_glContext)
- m_glContext->update();
+
+void QCocoaWindow::windowWillClose()
+{
+ QWindowSystemInterface::handleCloseEvent(window());
}
void QCocoaWindow::setCurrentContext(QCocoaGLContext *context)
panel = [[NSPanel alloc] initWithContentRect:frame
styleMask:m_windowAttributes
backing:NSBackingStoreBuffered
- defer:YES];
+ defer:NO]; // see window case below
// ### crashes
// [panel setFloatingPanel:needFloating];
// [panel setWorksWhenModal:worksWhenModal];
break;
}
default:
- window = [[NSWindow alloc] initWithContentRect:frame
- styleMask:m_windowAttributes
+ window = [[QNSWindow alloc] initWithContentRect:frame
+ styleMask:(NSResizableWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSTitledWindowMask)
backing:NSBackingStoreBuffered
- defer:YES];
+ defer:NO]; // Deferring window creation breaks OpenGL (the GL context is set up
+ // before the window is shown and needs a proper window.).
break;
}