From 4d56c86f802a49e0fa5481e13ab1f000ff284637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Thu, 13 Mar 2014 12:46:10 +0100 Subject: [PATCH] Cocoa: Disable the zoom button when appropriate Disable the zoom (maximize) button for fixed-size windows and customized windows with the MaximizeButton flag not set. Task-number: QTBUG-37078 Change-Id: I6da88496474713de37b48aa65742203632ba99d6 Reviewed-by: Gabriel de Dietrich --- src/plugins/platforms/cocoa/qcocoawindow.h | 1 + src/plugins/platforms/cocoa/qcocoawindow.mm | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h index 9128b05746..fe82edd618 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.h +++ b/src/plugins/platforms/cocoa/qcocoawindow.h @@ -190,6 +190,7 @@ public: NSInteger windowLevel(Qt::WindowFlags flags); NSUInteger windowStyleMask(Qt::WindowFlags flags); void setWindowShadow(Qt::WindowFlags flags); + void setWindowZoomButton(Qt::WindowFlags flags); void setCurrentContext(QCocoaGLContext *context); QCocoaGLContext *currentContext() const; diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index c2a0c81b31..957428d043 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -805,6 +805,18 @@ void QCocoaWindow::setWindowShadow(Qt::WindowFlags flags) [m_nsWindow setHasShadow:(keepShadow ? YES : NO)]; } +void QCocoaWindow::setWindowZoomButton(Qt::WindowFlags flags) +{ + // Disable the zoom (maximize) button for fixed-sized windows and customized + // no-WindowMaximizeButtonHint windows. From a Qt perspective it migth be expected + // that the button would be removed in the latter case, but disabling it is more + // in line with the platform style guidelines. + bool fixedSizeNoZoom = (window()->minimumSize().isValid() && window()->maximumSize().isValid() + && window()->minimumSize() == window()->maximumSize()); + bool customizeNoZoom = ((flags & Qt::CustomizeWindowHint) && !(flags & Qt::WindowMaximizeButtonHint)); + [[m_nsWindow standardWindowButton:NSWindowZoomButton] setEnabled:!(fixedSizeNoZoom || customizeNoZoom)]; +} + void QCocoaWindow::setWindowFlags(Qt::WindowFlags flags) { if (m_nsWindow && !m_isNSWindowChild) { @@ -830,6 +842,7 @@ void QCocoaWindow::setWindowFlags(Qt::WindowFlags flags) } } #endif + setWindowZoomButton(flags); } m_windowFlags = flags; @@ -993,6 +1006,9 @@ void QCocoaWindow::propagateSizeHints() const QSize maximumSize = window()->maximumSize(); [m_nsWindow setContentMaxSize : NSMakeSize(maximumSize.width(), maximumSize.height())]; + // The window may end up with a fixed size; in this case the zoom button should be disabled. + setWindowZoomButton(m_windowFlags); + // sizeIncrement is observed to take values of (-1, -1) and (0, 0) for windows that should be // resizable and that have no specific size increment set. Cocoa expects (1.0, 1.0) in this case. if (!window()->sizeIncrement().isEmpty())