Cocoa: Implement mouse and keyboard grab.

Change-Id: Id53ff19d43213d79aaf8f1a6617a06ef9d0cfb4b
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@nokia.com>
bb10
Morten Sorvig 2011-11-09 10:35:11 +01:00 committed by Qt by Nokia
parent 260416393e
commit 2fd3dbb00c
2 changed files with 53 additions and 3 deletions

View File

@ -52,6 +52,20 @@
QT_BEGIN_NAMESPACE
@interface QNSWindow : NSWindow {
}
- (BOOL)canBecomeKeyWindow;
@end
@interface QNSPanel : QNSWindow {
}
@end
class QCocoaWindow : public QPlatformWindow
{
public:
@ -63,8 +77,9 @@ public:
void setWindowTitle(const QString &title);
void raise();
void lower();
void propagateSizeHints();
bool setKeyboardGrabEnabled(bool grab);
bool setMouseGrabEnabled(bool grab);
WId winId() const;
NSView *contentView() const;

View File

@ -54,6 +54,23 @@
#include <QDebug>
@implementation QNSWindow
- (BOOL)canBecomeKeyWindow
{
// The default implementation returns NO for title-bar less windows,
// override and return yes here to make sure popup windows such as
// the combobox popup can become the key window.
return YES;
}
@end
@implementation QNSPanel
@end
QCocoaWindow::QCocoaWindow(QWindow *tlw)
: QPlatformWindow(tlw)
, m_windowAttributes(0)
@ -163,6 +180,24 @@ void QCocoaWindow::propagateSizeHints()
}
}
bool QCocoaWindow::setKeyboardGrabEnabled(bool grab)
{
if (grab && ![m_nsWindow isKeyWindow])
[m_nsWindow makeKeyWindow];
else if (!grab && [m_nsWindow isKeyWindow])
[m_nsWindow resignKeyWindow];
return true;
}
bool QCocoaWindow::setMouseGrabEnabled(bool grab)
{
if (grab && ![m_nsWindow isKeyWindow])
[m_nsWindow makeKeyWindow];
else if (!grab && [m_nsWindow isKeyWindow])
[m_nsWindow resignKeyWindow];
return true;
}
WId QCocoaWindow::winId() const
{
return WId(m_nsWindow);
@ -343,7 +378,7 @@ NSWindow * QCocoaWindow::createWindow()
break;
}
panel = [[NSPanel alloc] initWithContentRect:frame
panel = [[QNSPanel alloc] initWithContentRect:frame
styleMask:m_windowAttributes
backing:NSBackingStoreBuffered
defer:NO]; // see window case below
@ -354,7 +389,7 @@ NSWindow * QCocoaWindow::createWindow()
break;
}
default:
window = [[NSWindow alloc] initWithContentRect:frame
window = [[QNSWindow alloc] initWithContentRect:frame
styleMask:(NSResizableWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSTitledWindowMask)
backing:NSBackingStoreBuffered
defer:NO]; // Deferring window creation breaks OpenGL (the GL context is set up