1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the plugins of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
41 #include "qcocoawindow.h"
42 #include "qnswindowdelegate.h"
43 #include "qcocoaautoreleasepool.h"
44 #include "qcocoaeventdispatcher.h"
45 #include "qcocoaglcontext.h"
46 #include "qcocoahelpers.h"
48 #include <QtCore/qfileinfo.h>
49 #include <QtCore/private/qcore_mac_p.h>
51 #include <qpa/qwindowsysteminterface.h>
52 #include <qpa/qplatformscreen.h>
54 #include <Cocoa/Cocoa.h>
55 #include <Carbon/Carbon.h>
59 static bool isMouseEvent(NSEvent *ev)
64 case NSRightMouseDown:
67 case NSLeftMouseDragged:
68 case NSRightMouseDragged:
75 @interface NSWindow (CocoaWindowCategory)
76 - (void) clearPlatformWindow;
77 - (NSRect) legacyConvertRectFromScreen:(NSRect) rect;
80 @implementation NSWindow (CocoaWindowCategory)
81 - (void) clearPlatformWindow
85 - (NSRect) legacyConvertRectFromScreen:(NSRect) rect
87 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
88 if (QSysInfo::QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) {
89 return [self convertRectFromScreen: rect];
93 r.origin = [self convertScreenToBase:rect.origin];
98 @implementation QNSWindow
100 - (BOOL)canBecomeKeyWindow
102 // The default implementation returns NO for title-bar less windows,
103 // override and return yes here to make sure popup windows such as
104 // the combobox popup can become the key window.
108 - (BOOL)canBecomeMainWindow
110 BOOL canBecomeMain = YES; // By default, windows can become the main window
112 // Windows with a transient parent (such as combobox popup windows)
113 // cannot become the main window:
114 if (m_cocoaPlatformWindow->window()->transientParent())
117 return canBecomeMain;
120 - (void) sendEvent: (NSEvent*) theEvent
122 [super sendEvent: theEvent];
124 if (!m_cocoaPlatformWindow)
127 if (m_cocoaPlatformWindow->frameStrutEventsEnabled() && isMouseEvent(theEvent)) {
128 NSPoint loc = [theEvent locationInWindow];
129 NSRect windowFrame = [self legacyConvertRectFromScreen:[self frame]];
130 NSRect contentFrame = [[self contentView] frame];
131 if (NSMouseInRect(loc, windowFrame, NO) &&
132 !NSMouseInRect(loc, contentFrame, NO))
134 QNSView *contentView = (QNSView *) m_cocoaPlatformWindow->contentView();
135 [contentView handleFrameStrutMouseEvent: theEvent];
140 - (void)clearPlatformWindow
142 m_cocoaPlatformWindow = 0;
147 @implementation QNSPanel
149 - (BOOL)canBecomeKeyWindow
151 // Most panels can be come the key window. Exceptions are:
152 if (m_cocoaPlatformWindow->window()->windowType() == Qt::ToolTip)
154 if (m_cocoaPlatformWindow->window()->windowType() == Qt::SplashScreen)
159 - (void) sendEvent: (NSEvent*) theEvent
161 [super sendEvent: theEvent];
163 if (!m_cocoaPlatformWindow)
166 if (m_cocoaPlatformWindow->frameStrutEventsEnabled() && isMouseEvent(theEvent)) {
167 NSPoint loc = [theEvent locationInWindow];
168 NSRect windowFrame = [self legacyConvertRectFromScreen:[self frame]];
169 NSRect contentFrame = [[self contentView] frame];
170 if (NSMouseInRect(loc, windowFrame, NO) &&
171 !NSMouseInRect(loc, contentFrame, NO))
173 QNSView *contentView = (QNSView *) m_cocoaPlatformWindow->contentView();
174 [contentView handleFrameStrutMouseEvent: theEvent];
179 - (void)clearPlatformWindow
181 m_cocoaPlatformWindow = 0;
186 QCocoaWindow::QCocoaWindow(QWindow *tlw)
187 : QPlatformWindow(tlw)
189 , m_synchedWindowState(Qt::WindowActive)
190 , m_inConstructor(true)
193 , m_hasModalSession(false)
194 , m_frameStrutEventsEnabled(false)
196 #ifdef QT_COCOA_ENABLE_WINDOW_DEBUG
197 qDebug() << "QCocoaWindow::QCocoaWindow" << this;
199 QCocoaAutoReleasePool pool;
201 m_contentView = [[QNSView alloc] initWithQWindow:tlw platformWindow:this];
202 setGeometry(tlw->geometry());
204 recreateWindow(parent());
206 m_inConstructor = false;
209 QCocoaWindow::~QCocoaWindow()
211 #ifdef QT_COCOA_ENABLE_WINDOW_DEBUG
212 qDebug() << "QCocoaWindow::~QCocoaWindow" << this;
215 QCocoaAutoReleasePool pool;
216 clearNSWindow(m_nsWindow);
217 [m_contentView release];
218 [m_nsWindow release];
221 void QCocoaWindow::setGeometry(const QRect &rect)
223 if (geometry() == rect)
225 #ifdef QT_COCOA_ENABLE_WINDOW_DEBUG
226 qDebug() << "QCocoaWindow::setGeometry" << this << rect;
228 QPlatformWindow::setGeometry(rect);
229 setCocoaGeometry(rect);
232 void QCocoaWindow::setCocoaGeometry(const QRect &rect)
234 QCocoaAutoReleasePool pool;
236 NSRect bounds = qt_mac_flipRect(rect, window());
237 [m_nsWindow setContentSize : bounds.size];
238 [m_nsWindow setFrameOrigin : bounds.origin];
240 [m_contentView setFrame : NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height())];
244 void QCocoaWindow::setVisible(bool visible)
246 QCocoaAutoReleasePool pool;
247 #ifdef QT_COCOA_ENABLE_WINDOW_DEBUG
248 qDebug() << "QCocoaWindow::setVisible" << window() << visible;
251 QCocoaWindow *parentCocoaWindow = 0;
252 if (window()->transientParent()) {
253 parentCocoaWindow = static_cast<QCocoaWindow *>(window()->transientParent()->handle());
255 // The parent window might have moved while this window was hidden,
256 // update the window geometry if there is a parent.
257 setGeometry(window()->geometry());
259 // Register popup windows so that the parent window can
260 // close them when needed.
261 if (window()->windowType() == Qt::Popup) {
262 // qDebug() << "transientParent and popup" << window()->windowType() << Qt::Popup << (window()->windowType() & Qt::Popup);
263 parentCocoaWindow->m_activePopupWindow = window();
268 // Make sure the QWindow has a frame ready before we show the NSWindow.
269 QWindowSystemInterface::handleSynchronousExposeEvent(window(), QRect(QPoint(), geometry().size()));
272 // setWindowState might have been called while the window was hidden and
273 // will not change the NSWindow state in that case. Sync up here:
274 syncWindowState(window()->windowState());
276 if (window()->windowState() != Qt::WindowMinimized) {
277 if ((window()->windowModality() == Qt::WindowModal
278 || window()->windowType() == Qt::Sheet)
279 && parentCocoaWindow) {
280 // show the window as a sheet
281 [NSApp beginSheet:m_nsWindow modalForWindow:parentCocoaWindow->m_nsWindow modalDelegate:nil didEndSelector:nil contextInfo:nil];
282 } else if (window()->windowModality() != Qt::NonModal) {
283 // show the window as application modal
284 QCocoaEventDispatcher *cocoaEventDispatcher = qobject_cast<QCocoaEventDispatcher *>(QGuiApplication::instance()->eventDispatcher());
285 Q_ASSERT(cocoaEventDispatcher != 0);
286 QCocoaEventDispatcherPrivate *cocoaEventDispatcherPrivate = static_cast<QCocoaEventDispatcherPrivate *>(QObjectPrivate::get(cocoaEventDispatcher));
287 cocoaEventDispatcherPrivate->beginModalSession(window());
288 m_hasModalSession = true;
289 } else if ([m_nsWindow canBecomeKeyWindow]) {
290 [m_nsWindow makeKeyAndOrderFront:nil];
292 [m_nsWindow orderFront: nil];
297 // qDebug() << "close" << this;
299 if (m_hasModalSession) {
300 QCocoaEventDispatcher *cocoaEventDispatcher = qobject_cast<QCocoaEventDispatcher *>(QGuiApplication::instance()->eventDispatcher());
301 Q_ASSERT(cocoaEventDispatcher != 0);
302 QCocoaEventDispatcherPrivate *cocoaEventDispatcherPrivate = static_cast<QCocoaEventDispatcherPrivate *>(QObjectPrivate::get(cocoaEventDispatcher));
303 cocoaEventDispatcherPrivate->endModalSession(window());
304 m_hasModalSession = false;
306 if ([m_nsWindow isSheet])
307 [NSApp endSheet:m_nsWindow];
309 [m_nsWindow orderOut:m_nsWindow];
311 if (!QCoreApplication::closingDown())
312 QWindowSystemInterface::handleExposeEvent(window(), QRegion());
316 NSInteger QCocoaWindow::windowLevel(Qt::WindowFlags flags)
318 Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
320 NSInteger windowLevel = NSNormalWindowLevel;
322 if (type == Qt::Tool)
323 windowLevel = NSFloatingWindowLevel;
324 else if ((type & Qt::Popup) == Qt::Popup)
325 windowLevel = NSPopUpMenuWindowLevel;
327 // StayOnTop window should appear above Tool windows.
328 if (flags & Qt::WindowStaysOnTopHint)
329 windowLevel = NSPopUpMenuWindowLevel;
330 // Tooltips should appear above StayOnTop windows.
331 if (type == Qt::ToolTip)
332 windowLevel = NSScreenSaverWindowLevel;
334 // A window should be in at least the same level as its parent.
335 const QWindow * const transientParent = window()->transientParent();
336 const QCocoaWindow * const transientParentWindow = transientParent ? static_cast<QCocoaWindow *>(transientParent->handle()) : 0;
337 if (transientParentWindow)
338 windowLevel = qMax([transientParentWindow->m_nsWindow level], windowLevel);
343 NSUInteger QCocoaWindow::windowStyleMask(Qt::WindowFlags flags)
345 Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
346 NSInteger styleMask = NSBorderlessWindowMask;
348 if ((type & Qt::Popup) == Qt::Popup) {
349 if (!windowIsPopupType(type))
350 styleMask = (NSUtilityWindowMask | NSResizableWindowMask | NSClosableWindowMask |
351 NSMiniaturizableWindowMask | NSTitledWindowMask);
353 // Filter flags for supported properties
354 flags &= Qt::WindowType_Mask | Qt::FramelessWindowHint | Qt::WindowTitleHint |
355 Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint;
356 if (flags == Qt::Window) {
357 styleMask = (NSResizableWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSTitledWindowMask);
358 } else if (!(flags & Qt::FramelessWindowHint)) {
359 if (flags & Qt::WindowMaximizeButtonHint)
360 styleMask |= NSResizableWindowMask;
361 if (flags & Qt::WindowTitleHint)
362 styleMask |= NSTitledWindowMask;
363 if (flags & Qt::WindowCloseButtonHint)
364 styleMask |= NSClosableWindowMask;
365 if (flags & Qt::WindowMinimizeButtonHint)
366 styleMask |= NSMiniaturizableWindowMask;
373 void QCocoaWindow::setWindowShadow(Qt::WindowFlags flags)
375 bool keepShadow = !(flags & Qt::NoDropShadowWindowHint);
376 [m_nsWindow setHasShadow:(keepShadow ? YES : NO)];
379 Qt::WindowFlags QCocoaWindow::setWindowFlags(Qt::WindowFlags flags)
382 NSUInteger styleMask = windowStyleMask(flags);
383 NSInteger level = this->windowLevel(flags);
384 [m_nsWindow setStyleMask:styleMask];
385 [m_nsWindow setLevel:level];
386 setWindowShadow(flags);
389 m_windowFlags = flags;
390 return m_windowFlags;
393 Qt::WindowState QCocoaWindow::setWindowState(Qt::WindowState state)
395 if ([m_nsWindow isVisible])
396 syncWindowState(state); // Window state set for hidden windows take effect when show() is called.
401 void QCocoaWindow::setWindowTitle(const QString &title)
403 QCocoaAutoReleasePool pool;
407 CFStringRef windowTitle = QCFString::toCFStringRef(title);
408 [m_nsWindow setTitle: const_cast<NSString *>(reinterpret_cast<const NSString *>(windowTitle))];
409 CFRelease(windowTitle);
412 void QCocoaWindow::setWindowFilePath(const QString &filePath)
414 QCocoaAutoReleasePool pool;
418 QFileInfo fi(filePath);
419 [m_nsWindow setRepresentedFilename: fi.exists() ? QCFString::toNSString(filePath) : @""];
422 void QCocoaWindow::raise()
424 //qDebug() << "raise" << this;
425 // ### handle spaces (see Qt 4 raise_sys in qwidget_mac.mm)
428 if ([m_nsWindow isVisible])
429 [m_nsWindow orderFront: m_nsWindow];
432 void QCocoaWindow::lower()
436 if ([m_nsWindow isVisible])
437 [m_nsWindow orderBack: m_nsWindow];
440 void QCocoaWindow::propagateSizeHints()
442 QCocoaAutoReleasePool pool;
446 #ifdef QT_COCOA_ENABLE_WINDOW_DEBUG
447 qDebug() << "QCocoaWindow::propagateSizeHints" << this;
448 qDebug() << " min/max " << window()->minimumSize() << window()->maximumSize();
449 qDebug() << "size increment" << window()->sizeIncrement();
450 qDebug() << " basesize" << window()->baseSize();
451 qDebug() << " geometry" << geometry();
454 // Set the minimum content size.
455 const QSize minimumSize = window()->minimumSize();
456 if (!minimumSize.isValid()) // minimumSize is (-1, -1) when not set. Make that (0, 0) for Cocoa.
457 [m_nsWindow setContentMinSize : NSMakeSize(0.0, 0.0)];
458 [m_nsWindow setContentMinSize : NSMakeSize(minimumSize.width(), minimumSize.height())];
460 // Set the maximum content size.
461 const QSize maximumSize = window()->maximumSize();
462 [m_nsWindow setContentMaxSize : NSMakeSize(maximumSize.width(), maximumSize.height())];
464 // sizeIncrement is observed to take values of (-1, -1) and (0, 0) for windows that should be
465 // resizable and that have no specific size increment set. Cocoa expects (1.0, 1.0) in this case.
466 if (!window()->sizeIncrement().isEmpty())
467 [m_nsWindow setResizeIncrements : qt_mac_toNSSize(window()->sizeIncrement())];
469 [m_nsWindow setResizeIncrements : NSMakeSize(1.0, 1.0)];
471 QRect rect = geometry();
472 QSize baseSize = window()->baseSize();
473 if (!baseSize.isNull() && baseSize.isValid()) {
474 [m_nsWindow setFrame:NSMakeRect(rect.x(), rect.y(), baseSize.width(), baseSize.height()) display:YES];
478 void QCocoaWindow::setOpacity(qreal level)
481 [m_nsWindow setAlphaValue:level];
484 bool QCocoaWindow::setKeyboardGrabEnabled(bool grab)
489 if (grab && ![m_nsWindow isKeyWindow])
490 [m_nsWindow makeKeyWindow];
491 else if (!grab && [m_nsWindow isKeyWindow])
492 [m_nsWindow resignKeyWindow];
496 bool QCocoaWindow::setMouseGrabEnabled(bool grab)
501 if (grab && ![m_nsWindow isKeyWindow])
502 [m_nsWindow makeKeyWindow];
503 else if (!grab && [m_nsWindow isKeyWindow])
504 [m_nsWindow resignKeyWindow];
508 WId QCocoaWindow::winId() const
510 return WId(m_contentView);
513 void QCocoaWindow::setParent(const QPlatformWindow *parentWindow)
515 // recreate the window for compatibility
516 recreateWindow(parentWindow);
517 setCocoaGeometry(geometry());
520 NSView *QCocoaWindow::contentView() const
522 return m_contentView;
525 void QCocoaWindow::windowWillMove()
527 // Close any open popups on window move
528 if (m_activePopupWindow) {
529 QWindowSystemInterface::handleSynchronousCloseEvent(m_activePopupWindow);
530 m_activePopupWindow = 0;
534 void QCocoaWindow::windowDidMove()
536 [m_contentView updateGeometry];
539 void QCocoaWindow::windowDidResize()
544 NSRect rect = [[m_nsWindow contentView]frame];
545 // Call setFrameSize which will trigger a frameDidChangeNotification on QNSView.
546 [[m_nsWindow contentView] setFrameSize:rect.size];
549 void QCocoaWindow::windowWillClose()
551 QWindowSystemInterface::handleSynchronousCloseEvent(window());
554 bool QCocoaWindow::windowIsPopupType(Qt::WindowType type) const
556 if (type == Qt::Widget)
557 type = window()->windowType();
558 if (type == Qt::Tool)
559 return false; // Qt::Tool has the Popup bit set but isn't, at least on Mac.
561 return ((type & Qt::Popup) == Qt::Popup);
564 void QCocoaWindow::setCurrentContext(QCocoaGLContext *context)
566 m_glContext = context;
569 QCocoaGLContext *QCocoaWindow::currentContext() const
574 void QCocoaWindow::recreateWindow(const QPlatformWindow *parentWindow)
576 // Remove current window (if any)
578 clearNSWindow(m_nsWindow);
580 [m_nsWindow release];
585 // Create a new NSWindow if this is a top-level window.
586 m_nsWindow = createNSWindow();
587 setNSWindow(m_nsWindow);
589 // QPlatformWindow subclasses must sync up with QWindow on creation:
590 propagateSizeHints();
591 setWindowFlags(window()->windowFlags());
592 setWindowTitle(window()->windowTitle());
593 setWindowState(window()->windowState());
595 // Child windows have no NSWindow, link the NSViews instead.
596 const QCocoaWindow *parentCococaWindow = static_cast<const QCocoaWindow *>(parentWindow);
597 [parentCococaWindow->m_contentView addSubview : m_contentView];
601 NSWindow * QCocoaWindow::createNSWindow()
603 QCocoaAutoReleasePool pool;
605 NSRect frame = qt_mac_flipRect(window()->geometry(), window());
607 Qt::WindowType type = window()->windowType();
608 Qt::WindowFlags flags = window()->windowFlags();
610 NSUInteger styleMask = windowStyleMask(flags);
611 NSWindow *createdWindow = 0;
613 // Use NSPanel for popup-type windows. (Popup, Tool, ToolTip, SplashScreen)
614 if ((type & Qt::Popup) == Qt::Popup) {
616 window = [[QNSPanel alloc] initWithContentRect:frame
618 backing:NSBackingStoreBuffered
619 defer:NO]; // Deferring window creation breaks OpenGL (the GL context is set up
620 // before the window is shown and needs a proper window.).
621 [window setHasShadow:YES];
623 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
624 if (QSysInfo::QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) {
625 // Make popup winows show on the same desktop as the parent full-screen window.
626 [window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary];
629 window->m_cocoaPlatformWindow = this;
630 createdWindow = window;
633 window = [[QNSWindow alloc] initWithContentRect:frame
635 backing:NSBackingStoreBuffered
636 defer:NO]; // Deferring window creation breaks OpenGL (the GL context is set up
637 // before the window is shown and needs a proper window.).
638 window->m_cocoaPlatformWindow = this;
639 setWindowShadow(flags);
641 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
642 if (QSysInfo::QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) {
643 // All windows with the WindowMaximizeButtonHint set also get a full-screen button.
644 if (flags & Qt::WindowMaximizeButtonHint)
645 [window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
649 createdWindow = window;
652 NSInteger level = windowLevel(flags);
653 [createdWindow setLevel:level];
655 return createdWindow;
658 void QCocoaWindow::setNSWindow(NSWindow *window)
660 QNSWindowDelegate *delegate = [[QNSWindowDelegate alloc] initWithQCocoaWindow:this];
661 [window setDelegate:delegate];
662 [window setAcceptsMouseMovedEvents:YES];
664 // Prevent Cocoa from releasing the window on close. Qt
665 // handles the close event asynchronously and we want to
666 // make sure that m_nsWindow stays valid until the
667 // QCocoaWindow is deleted by Qt.
668 [window setReleasedWhenClosed : NO];
671 [[NSNotificationCenter defaultCenter] addObserver:m_contentView
672 selector:@selector(windowNotification:)
673 name:nil // Get all notifications
676 // ### Accept touch events by default.
677 // Beware that enabling touch events has a negative impact on the overall performance.
678 // We probably need a QWindowSystemInterface API to enable/disable touch events.
679 [m_contentView setAcceptsTouchEvents:YES];
681 [window setContentView:m_contentView];
684 void QCocoaWindow::clearNSWindow(NSWindow *window)
686 [window setDelegate:nil];
687 [window clearPlatformWindow];
688 [[NSNotificationCenter defaultCenter] removeObserver:m_contentView];
691 // Returns the current global screen geometry for the nswindow associated with this window.
692 QRect QCocoaWindow::windowGeometry() const
697 NSRect rect = [m_nsWindow frame];
698 QPlatformScreen *onScreen = QPlatformScreen::platformScreenForWindow(window());
699 int flippedY = onScreen->geometry().height() - rect.origin.y - rect.size.height; // account for nswindow inverted y.
700 QRect qRect = QRect(rect.origin.x, flippedY, rect.size.width, rect.size.height);
704 // Returns a pointer to the parent QCocoaWindow for this window, or 0 if there is none.
705 QCocoaWindow *QCocoaWindow::parentCocoaWindow() const
707 if (window() && window()->transientParent()) {
708 return static_cast<QCocoaWindow*>(window()->transientParent()->handle());
713 // Syncs the NSWindow minimize/maximize/fullscreen state with the current QWindow state
714 void QCocoaWindow::syncWindowState(Qt::WindowState newState)
719 if ((m_synchedWindowState & Qt::WindowMaximized) != (newState & Qt::WindowMaximized)) {
720 [m_nsWindow performZoom : m_nsWindow]; // toggles
723 if ((m_synchedWindowState & Qt::WindowMinimized) != (newState & Qt::WindowMinimized)) {
724 if (newState & Qt::WindowMinimized) {
725 [m_nsWindow performMiniaturize : m_nsWindow];
727 [m_nsWindow deminiaturize : m_nsWindow];
731 if ((m_synchedWindowState & Qt::WindowFullScreen) != (newState & Qt::WindowFullScreen)) {
732 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
733 if (QSysInfo::QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) {
734 [m_nsWindow toggleFullScreen : m_nsWindow];
736 // TODO: "normal" fullscreen
741 // New state is now the current synched state
742 m_synchedWindowState = newState;
745 bool QCocoaWindow::setWindowModified(bool modified)
749 [m_nsWindow setDocumentEdited:(modified?YES:NO)];
753 void QCocoaWindow::setMenubar(QCocoaMenuBar *mb)
758 QCocoaMenuBar *QCocoaWindow::menubar() const
763 QMargins QCocoaWindow::frameMargins() const
765 NSRect frameW = [m_nsWindow frame];
766 NSRect frameC = [m_nsWindow contentRectForFrameRect:frameW];
768 return QMargins(frameW.origin.x - frameC.origin.x,
769 (frameW.origin.y + frameW.size.height) - (frameC.origin.y + frameC.size.height),
770 (frameW.origin.x + frameW.size.width) - (frameC.origin.x + frameC.size.width),
771 frameC.origin.y - frameW.origin.y);
774 void QCocoaWindow::setFrameStrutEventsEnabled(bool enabled)
776 m_frameStrutEventsEnabled = enabled;