@public QCocoaWindow *m_cocoaPlatformWindow;
}
+- (void)clearPlatformWindow;
- (BOOL)canBecomeKeyWindow;
@end
@interface QNSPanel : NSPanel {
@public QT_PREPEND_NAMESPACE(QCocoaWindow) *m_cocoaPlatformWindow;
}
+- (void)clearPlatformWindow;
- (BOOL)canBecomeKeyWindow;
@end
void setOpacity(qreal level);
bool setKeyboardGrabEnabled(bool grab);
bool setMouseGrabEnabled(bool grab);
+ QMargins frameMargins() const;
WId winId() const;
void setParent(const QPlatformWindow *window);
bool setWindowModified(bool modified) Q_DECL_OVERRIDE;
+ void setFrameStrutEventsEnabled(bool enabled);
+ bool frameStrutEventsEnabled() const
+ { return m_frameStrutEventsEnabled; }
+
void setMenubar(QCocoaMenuBar *mb);
QCocoaMenuBar *menubar() const;
protected:
QCocoaMenuBar *m_menubar;
bool m_hasModalSession;
+ bool m_frameStrutEventsEnabled;
};
QT_END_NAMESPACE
#include "qnsview.h"
#include <QtCore/private/qcore_mac_p.h>
#include <qwindow.h>
-#include <QtGui/qwindowsysteminterface.h>
+#include <QtGui/QWindowSystemInterface>
#include <qpa/qplatformscreen.h>
#include <Cocoa/Cocoa.h>
#include <QDebug>
+static bool isMouseEvent(NSEvent *ev)
+{
+ switch ([ev type]) {
+ case NSLeftMouseDown:
+ case NSLeftMouseUp:
+ case NSRightMouseDown:
+ case NSRightMouseUp:
+ case NSMouseMoved:
+ case NSLeftMouseDragged:
+ case NSRightMouseDragged:
+ return true;
+ default:
+ return false;
+ }
+}
+
+@interface NSWindow (CocoaWindowCategory)
+- (void) clearPlatformWindow;
+- (NSRect) legacyConvertRectFromScreen:(NSRect) rect;
+@end
+
+@implementation NSWindow (CocoaWindowCategory)
+- (void) clearPlatformWindow
+{
+}
+
+- (NSRect) legacyConvertRectFromScreen:(NSRect) rect
+{
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
+ if (QSysInfo::QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) {
+ return [self convertRectFromScreen: rect];
+ }
+#endif
+ NSRect r = rect;
+ r.origin = [self convertScreenToBase:rect.origin];
+ return r;
+}
+@end
+
@implementation QNSWindow
- (BOOL)canBecomeKeyWindow
return canBecomeMain;
}
+- (void) sendEvent: (NSEvent*) theEvent
+{
+ [super sendEvent: theEvent];
+
+ if (!m_cocoaPlatformWindow)
+ return;
+
+ if (m_cocoaPlatformWindow->frameStrutEventsEnabled() && isMouseEvent(theEvent)) {
+ NSPoint loc = [theEvent locationInWindow];
+ NSRect windowFrame = [self legacyConvertRectFromScreen:[self frame]];
+ NSRect contentFrame = [[self contentView] frame];
+ if (NSMouseInRect(loc, windowFrame, NO) &&
+ !NSMouseInRect(loc, contentFrame, NO))
+ {
+ QNSView *contentView = (QNSView *) m_cocoaPlatformWindow->contentView();
+ [contentView handleFrameStrutMouseEvent: theEvent];
+ }
+ }
+}
+
+- (void)clearPlatformWindow
+{
+ m_cocoaPlatformWindow = 0;
+}
@end
return YES;
}
+- (void) sendEvent: (NSEvent*) theEvent
+{
+ [super sendEvent: theEvent];
+
+ if (!m_cocoaPlatformWindow)
+ return;
+
+ if (m_cocoaPlatformWindow->frameStrutEventsEnabled() && isMouseEvent(theEvent)) {
+ NSPoint loc = [theEvent locationInWindow];
+ NSRect windowFrame = [self legacyConvertRectFromScreen:[self frame]];
+ NSRect contentFrame = [[self contentView] frame];
+ if (NSMouseInRect(loc, windowFrame, NO) &&
+ !NSMouseInRect(loc, contentFrame, NO))
+ {
+ QNSView *contentView = (QNSView *) m_cocoaPlatformWindow->contentView();
+ [contentView handleFrameStrutMouseEvent: theEvent];
+ }
+ }
+}
+
+- (void)clearPlatformWindow
+{
+ m_cocoaPlatformWindow = 0;
+}
+
@end
QCocoaWindow::QCocoaWindow(QWindow *tlw)
, m_glContext(0)
, m_menubar(0)
, m_hasModalSession(false)
+ , m_frameStrutEventsEnabled(false)
{
#ifdef QT_COCOA_ENABLE_WINDOW_DEBUG
qDebug() << "QCocoaWindow::QCocoaWindow" << this;
QCocoaWindow::~QCocoaWindow()
{
+#ifdef QT_COCOA_ENABLE_WINDOW_DEBUG
+ qDebug() << "QCocoaWindow::~QCocoaWindow" << this;
+#endif
+
clearNSWindow(m_nsWindow);
[m_contentView release];
[m_nsWindow release];
void QCocoaWindow::clearNSWindow(NSWindow *window)
{
[window setDelegate:nil];
+ [window clearPlatformWindow];
[[NSNotificationCenter defaultCenter] removeObserver:m_contentView];
}
{
return m_menubar;
}
+
+QMargins QCocoaWindow::frameMargins() const
+{
+ NSRect frameW = [m_nsWindow frame];
+ NSRect frameC = [m_nsWindow contentRectForFrameRect:frameW];
+
+ return QMargins(frameW.origin.x - frameC.origin.x,
+ (frameW.origin.y + frameW.size.height) - (frameC.origin.y + frameC.size.height),
+ (frameW.origin.x + frameW.size.width) - (frameC.origin.x + frameC.size.width),
+ frameC.origin.y - frameW.origin.y);
+}
+
+void QCocoaWindow::setFrameStrutEventsEnabled(bool enabled)
+{
+ m_frameStrutEventsEnabled = enabled;
+}
QWindowSystemInterface::handleMouseEvent(m_window, timestamp, qtWindowPoint, qtScreenPoint, m_buttons);
}
+- (void)handleFrameStrutMouseEvent:(NSEvent *)theEvent
+{
+ // get m_buttons in sync
+ NSEventType ty = [theEvent type];
+ switch (ty) {
+ case NSLeftMouseDown:
+ m_buttons |= Qt::LeftButton;
+ break;
+ case NSLeftMouseUp:
+ m_buttons &= QFlag(~int(Qt::LeftButton));
+ break;
+ case NSRightMouseDown:
+ m_buttons |= Qt::RightButton;
+ break;
+ case NSRightMouseUp:
+ m_buttons &= QFlag(~int(Qt::RightButton));
+ break;
+ default:
+ break;
+ }
+
+ NSWindow *window = [self window];
+ int windowHeight = [window frame].size.height;
+ NSPoint windowPoint = [theEvent locationInWindow];
+ NSPoint nsViewPoint = [self convertPoint: windowPoint fromView: nil];
+ QPoint qtWindowPoint = QPoint(windowPoint.x, windowHeight - windowPoint.y);
+ NSPoint screenPoint = [window convertBaseToScreen : windowPoint];
+ QPoint qtScreenPoint = QPoint(screenPoint.x, qt_mac_flipYCoordinate(screenPoint.y));
+
+ ulong timestamp = [theEvent timestamp] * 1000;
+ QWindowSystemInterface::handleFrameStrutMouseEvent(m_window, timestamp, qtWindowPoint, qtScreenPoint, m_buttons);
+}
+
- (void)mouseDown:(NSEvent *)theEvent
{
if (m_platformWindow->m_activePopupWindow) {