diff options
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoawindow.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoawindow.mm | 117 |
1 files changed, 71 insertions, 46 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index e4cd57a115..29cc4130ed 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1,31 +1,37 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the plugins of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL21$ +** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** 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 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. ** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** @@ -47,8 +53,7 @@ #include <qpa/qwindowsysteminterface.h> #include <qpa/qplatformscreen.h> -#include <Cocoa/Cocoa.h> -#include <Carbon/Carbon.h> +#include <AppKit/AppKit.h> #include <QDebug> @@ -369,9 +374,8 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw) , m_bottomContentBorderThickness(0) , m_normalGeometry(QRect(0,0,-1,-1)) { -#ifdef QT_COCOA_ENABLE_WINDOW_DEBUG - qDebug() << "QCocoaWindow::QCocoaWindow" << this; -#endif + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::QCocoaWindow" << window(); + QMacAutoReleasePool pool; if (tlw->type() == Qt::ForeignWindow) { @@ -404,9 +408,7 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw) QCocoaWindow::~QCocoaWindow() { -#ifdef QT_COCOA_ENABLE_WINDOW_DEBUG - qDebug() << "QCocoaWindow::~QCocoaWindow" << this; -#endif + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::~QCocoaWindow" << window(); QMacAutoReleasePool pool; [m_nsWindow makeFirstResponder:nil]; @@ -464,6 +466,8 @@ QSurfaceFormat QCocoaWindow::format() const void QCocoaWindow::setGeometry(const QRect &rectIn) { + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::setGeometry" << window() << rectIn; + QBoolBlocker inSetGeometry(m_inSetGeometry, true); QRect rect = rectIn; @@ -476,9 +480,7 @@ void QCocoaWindow::setGeometry(const QRect &rectIn) } if (geometry() == rect) return; -#ifdef QT_COCOA_ENABLE_WINDOW_DEBUG - qDebug() << "QCocoaWindow::setGeometry" << this << rect; -#endif + setCocoaGeometry(rect); } @@ -501,6 +503,7 @@ QRect QCocoaWindow::geometry() const void QCocoaWindow::setCocoaGeometry(const QRect &rect) { + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::setCocoaGeometry" << window() << rect; QMacAutoReleasePool pool; if (m_contentViewIsEmbedded) { @@ -624,6 +627,8 @@ void QCocoaWindow::show(bool becauseOfAncestor) void QCocoaWindow::setVisible(bool visible) { + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::setVisible" << window() << visible; + if (m_isNSWindowChild && m_hiddenByClipping) return; @@ -633,9 +638,7 @@ void QCocoaWindow::setVisible(bool visible) QCocoaWindow *parentCocoaWindow = 0; if (window()->transientParent()) parentCocoaWindow = static_cast<QCocoaWindow *>(window()->transientParent()->handle()); -#ifdef QT_COCOA_ENABLE_WINDOW_DEBUG - qDebug() << "QCocoaWindow::setVisible" << window() << visible; -#endif + if (visible) { // We need to recreate if the modality has changed as the style mask will need updating if (m_windowModality != window()->modality()) @@ -690,7 +693,16 @@ void QCocoaWindow::setVisible(bool visible) cocoaEventDispatcherPrivate->beginModalSession(window()); m_hasModalSession = true; } else if ([m_nsWindow canBecomeKeyWindow]) { - [m_nsWindow makeKeyAndOrderFront:nil]; + QCocoaEventDispatcher *cocoaEventDispatcher = qobject_cast<QCocoaEventDispatcher *>(QGuiApplication::instance()->eventDispatcher()); + QCocoaEventDispatcherPrivate *cocoaEventDispatcherPrivate = 0; + if (cocoaEventDispatcher) + cocoaEventDispatcherPrivate = static_cast<QCocoaEventDispatcherPrivate *>(QObjectPrivate::get(cocoaEventDispatcher)); + + if (!(cocoaEventDispatcherPrivate && cocoaEventDispatcherPrivate->currentModalSession())) + [m_nsWindow makeKeyAndOrderFront:nil]; + else + [m_nsWindow orderFront:nil]; + foreach (QCocoaWindow *childWindow, m_childWindows) childWindow->show(true); } else { @@ -847,9 +859,6 @@ NSUInteger QCocoaWindow::windowStyleMask(Qt::WindowFlags flags) if (m_drawContentBorderGradient) styleMask |= NSTexturedBackgroundWindowMask; -#ifdef QT_COCOA_ENABLE_WINDOW_DEBUG - qDebug("windowStyleMask of '%s': flags %X -> styleMask %lX", qPrintable(window()->title()), (int)flags, styleMask); -#endif return styleMask; } @@ -971,7 +980,8 @@ bool QCocoaWindow::isAlertState() const void QCocoaWindow::raise() { - //qDebug() << "raise" << this; + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::raise" << window(); + // ### handle spaces (see Qt 4 raise_sys in qwidget_mac.mm) if (!m_nsWindow) return; @@ -1012,6 +1022,7 @@ void QCocoaWindow::raise() void QCocoaWindow::lower() { + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::lower" << window(); if (!m_nsWindow) return; if (m_isNSWindowChild) { @@ -1064,13 +1075,11 @@ void QCocoaWindow::propagateSizeHints() if (!m_nsWindow) return; -#ifdef QT_COCOA_ENABLE_WINDOW_DEBUG - qDebug() << "QCocoaWindow::propagateSizeHints" << this; - qDebug() << " min/max" << windowMinimumSize() << windowMaximumSize(); - qDebug() << "size increment" << windowSizeIncrement(); - qDebug() << " basesize" << windowBaseSize(); - qDebug() << " geometry" << windowGeometry(); -#endif + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::propagateSizeHints" << window() << "\n" + << " min/max" << windowMinimumSize() << windowMaximumSize() + << "size increment" << windowSizeIncrement() + << " basesize" << windowBaseSize() + << " geometry" << windowGeometry(); // Set the minimum content size. const QSize minimumSize = windowMinimumSize(); @@ -1102,6 +1111,7 @@ void QCocoaWindow::propagateSizeHints() void QCocoaWindow::setOpacity(qreal level) { + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::setOpacity" << level; if (m_nsWindow) { [m_nsWindow setAlphaValue:level]; [m_nsWindow setOpaque: isOpaque()]; @@ -1110,6 +1120,7 @@ void QCocoaWindow::setOpacity(qreal level) void QCocoaWindow::setMask(const QRegion ®ion) { + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::setMask" << window() << region; if (m_nsWindow) [m_nsWindow setBackgroundColor:[NSColor clearColor]]; @@ -1119,6 +1130,7 @@ void QCocoaWindow::setMask(const QRegion ®ion) bool QCocoaWindow::setKeyboardGrabEnabled(bool grab) { + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::setKeyboardGrabEnabled" << window() << grab; if (!m_nsWindow) return false; @@ -1131,6 +1143,7 @@ bool QCocoaWindow::setKeyboardGrabEnabled(bool grab) bool QCocoaWindow::setMouseGrabEnabled(bool grab) { + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::setMouseGrabEnabled" << window() << grab; if (!m_nsWindow) return false; @@ -1148,6 +1161,8 @@ WId QCocoaWindow::winId() const void QCocoaWindow::setParent(const QPlatformWindow *parentWindow) { + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::setParent" << window() << (parentWindow ? parentWindow->window() : 0); + // recreate the window for compatibility bool unhideAfterRecreate = parentWindow && !m_contentViewIsToBeEmbedded && ![m_contentView isHidden]; recreateWindow(parentWindow); @@ -1231,6 +1246,7 @@ void QCocoaWindow::windowDidEndLiveResize() bool QCocoaWindow::windowShouldClose() { + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::windowShouldClose" << window(); // This callback should technically only determine if the window // should (be allowed to) close, but since our QPA API to determine // that also involves actually closing the window we do both at the @@ -1271,6 +1287,9 @@ QCocoaGLContext *QCocoaWindow::currentContext() const void QCocoaWindow::recreateWindow(const QPlatformWindow *parentWindow) { + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::recreateWindow" << window() + << "parent" << (parentWindow ? parentWindow->window() : 0); + bool wasNSWindowChild = m_isNSWindowChild; BOOL requestNSWindowChild = qt_mac_resolveOption(NO, window(), "_q_platform_MacUseNSWindow", "QT_MAC_USE_NSWINDOW"); @@ -1354,6 +1373,9 @@ void QCocoaWindow::recreateWindow(const QPlatformWindow *parentWindow) } } else { // Child windows have no NSWindow, link the NSViews instead. + if ([m_contentView superview]) + [m_contentView removeFromSuperview]; + [m_parentCocoaWindow->m_contentView addSubview : m_contentView]; QRect rect = windowGeometry(); // Prevent setting a (0,0) window size; causes opengl context @@ -1604,10 +1626,6 @@ void QCocoaWindow::syncWindowState(Qt::WindowState newState) } } -#ifdef QT_COCOA_ENABLE_WINDOW_DEBUG - qDebug() << "QCocoaWindow::syncWindowState" << newState << "actual" << predictedState << "was" << m_synchedWindowState << "effectively maximized" << m_effectivelyMaximized; -#endif - // New state is now the current synched state m_synchedWindowState = predictedState; } @@ -1800,7 +1818,9 @@ void QCocoaWindow::exposeWindow() m_isExposed = true; m_exposedGeometry = geometry(); m_exposedDevicePixelRatio = devicePixelRatio(); - QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(0, 0), m_exposedGeometry.size())); + QRect geometry(QPoint(0, 0), m_exposedGeometry.size()); + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow: exposeWindow" << window() << geometry; + QWindowSystemInterface::handleExposeEvent(window(), geometry); } } @@ -1810,6 +1830,8 @@ void QCocoaWindow::obscureWindow() if (m_isExposed) { m_geometryUpdateExposeAllowed = false; m_isExposed = false; + + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::obscureWindow" << window(); QWindowSystemInterface::handleExposeEvent(window(), QRegion()); } } @@ -1836,7 +1858,10 @@ void QCocoaWindow::updateExposedGeometry() m_isExposed = true; m_exposedGeometry = geometry(); m_exposedDevicePixelRatio = devicePixelRatio(); - QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(0, 0), m_exposedGeometry.size())); + + QRect geometry(QPoint(0, 0), m_exposedGeometry.size()); + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::updateExposedGeometry" << window() << geometry; + QWindowSystemInterface::handleExposeEvent(window(), geometry); } QWindow *QCocoaWindow::childWindowAt(QPoint windowPoint) |