1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the plugins of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
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/private/qcore_mac_p.h>
50 #include <qpa/qwindowsysteminterface.h>
51 #include <qpa/qplatformscreen.h>
53 #include <Cocoa/Cocoa.h>
54 #include <Carbon/Carbon.h>
58 static bool isMouseEvent(NSEvent *ev)
63 case NSRightMouseDown:
66 case NSLeftMouseDragged:
67 case NSRightMouseDragged:
74 @interface NSWindow (CocoaWindowCategory)
75 - (void) clearPlatformWindow;
76 - (NSRect) legacyConvertRectFromScreen:(NSRect) rect;
79 @implementation NSWindow (CocoaWindowCategory)
80 - (void) clearPlatformWindow
84 - (NSRect) legacyConvertRectFromScreen:(NSRect) rect
86 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
87 if (QSysInfo::QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) {
88 return [self convertRectFromScreen: rect];
92 r.origin = [self convertScreenToBase:rect.origin];
97 @implementation QNSWindow
99 - (BOOL)canBecomeKeyWindow
101 // The default implementation returns NO for title-bar less windows,
102 // override and return yes here to make sure popup windows such as
103 // the combobox popup can become the key window.
107 - (BOOL)canBecomeMainWindow
109 BOOL canBecomeMain = YES; // By default, windows can become the main window
111 // Windows with a transient parent (such as combobox popup windows)
112 // cannot become the main window:
113 if (m_cocoaPlatformWindow->window()->transientParent())
116 return canBecomeMain;
119 - (void) sendEvent: (NSEvent*) theEvent
121 [super sendEvent: theEvent];
123 if (!m_cocoaPlatformWindow)
126 if (m_cocoaPlatformWindow->frameStrutEventsEnabled() && isMouseEvent(theEvent)) {
127 NSPoint loc = [theEvent locationInWindow];
128 NSRect windowFrame = [self legacyConvertRectFromScreen:[self frame]];
129 NSRect contentFrame = [[self contentView] frame];
130 if (NSMouseInRect(loc, windowFrame, NO) &&
131 !NSMouseInRect(loc, contentFrame, NO))
133 QNSView *contentView = (QNSView *) m_cocoaPlatformWindow->contentView();
134 [contentView handleFrameStrutMouseEvent: theEvent];
139 - (void)clearPlatformWindow
141 m_cocoaPlatformWindow = 0;
146 @implementation QNSPanel
148 - (BOOL)canBecomeKeyWindow
150 // Most panels can be come the key window. Exceptions are:
151 if (m_cocoaPlatformWindow->window()->windowType() == Qt::ToolTip)
153 if (m_cocoaPlatformWindow->window()->windowType() == Qt::SplashScreen)
158 - (void) sendEvent: (NSEvent*) theEvent
160 [super sendEvent: theEvent];
162 if (!m_cocoaPlatformWindow)
165 if (m_cocoaPlatformWindow->frameStrutEventsEnabled() && isMouseEvent(theEvent)) {
166 NSPoint loc = [theEvent locationInWindow];
167 NSRect windowFrame = [self legacyConvertRectFromScreen:[self frame]];
168 NSRect contentFrame = [[self contentView] frame];
169 if (NSMouseInRect(loc, windowFrame, NO) &&
170 !NSMouseInRect(loc, contentFrame, NO))
172 QNSView *contentView = (QNSView *) m_cocoaPlatformWindow->contentView();
173 [contentView handleFrameStrutMouseEvent: theEvent];
178 - (void)clearPlatformWindow
180 m_cocoaPlatformWindow = 0;
185 QCocoaWindow::QCocoaWindow(QWindow *tlw)
186 : QPlatformWindow(tlw)
188 , m_synchedWindowState(Qt::WindowActive)
189 , m_inConstructor(true)
192 , m_hasModalSession(false)
193 , m_frameStrutEventsEnabled(false)
195 #ifdef QT_COCOA_ENABLE_WINDOW_DEBUG
196 qDebug() << "QCocoaWindow::QCocoaWindow" << this;
198 QCocoaAutoReleasePool pool;
200 m_contentView = [[QNSView alloc] initWithQWindow:tlw platformWindow:this];
201 setGeometry(tlw->geometry());
203 recreateWindow(parent());
205 m_inConstructor = false;
208 QCocoaWindow::~QCocoaWindow()
210 #ifdef QT_COCOA_ENABLE_WINDOW_DEBUG
211 qDebug() << "QCocoaWindow::~QCocoaWindow" << this;
214 QCocoaAutoReleasePool pool;
215 clearNSWindow(m_nsWindow);
216 [m_contentView release];
217 [m_nsWindow release];
220 void QCocoaWindow::setGeometry(const QRect &rect)
222 if (geometry() == rect)
224 #ifdef QT_COCOA_ENABLE_WINDOW_DEBUG
225 qDebug() << "QCocoaWindow::setGeometry" << this << rect;
227 QPlatformWindow::setGeometry(rect);
228 setCocoaGeometry(rect);
231 void QCocoaWindow::setCocoaGeometry(const QRect &rect)
233 QCocoaAutoReleasePool pool;
235 NSRect bounds = qt_mac_flipRect(rect, window());
236 [m_nsWindow setContentSize : bounds.size];
237 [m_nsWindow setFrameOrigin : bounds.origin];
239 [m_contentView setFrame : NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height())];
243 void QCocoaWindow::setVisible(bool visible)
245 QCocoaAutoReleasePool pool;
246 #ifdef QT_COCOA_ENABLE_WINDOW_DEBUG
247 qDebug() << "QCocoaWindow::setVisible" << window() << visible;
250 QCocoaWindow *parentCocoaWindow = 0;
251 if (window()->transientParent()) {
252 parentCocoaWindow = static_cast<QCocoaWindow *>(window()->transientParent()->handle());
254 // The parent window might have moved while this window was hidden,
255 // update the window geometry if there is a parent.
256 setGeometry(window()->geometry());
258 // Register popup windows so that the parent window can
259 // close them when needed.
260 if (window()->windowType() == Qt::Popup) {
261 // qDebug() << "transientParent and popup" << window()->windowType() << Qt::Popup << (window()->windowType() & Qt::Popup);
262 parentCocoaWindow->m_activePopupWindow = window();
267 // Make sure the QWindow has a frame ready before we show the NSWindow.
268 QWindowSystemInterface::handleSynchronousExposeEvent(window(), QRect(QPoint(), geometry().size()));
271 // setWindowState might have been called while the window was hidden and
272 // will not change the NSWindow state in that case. Sync up here:
273 syncWindowState(window()->windowState());
275 if (window()->windowState() != Qt::WindowMinimized) {
276 if ((window()->windowModality() == Qt::WindowModal
277 || window()->windowType() == Qt::Sheet)
278 && parentCocoaWindow) {
279 // show the window as a sheet
280 [NSApp beginSheet:m_nsWindow modalForWindow:parentCocoaWindow->m_nsWindow modalDelegate:nil didEndSelector:nil contextInfo:nil];
281 } else if (window()->windowModality() != Qt::NonModal) {
282 // show the window as application modal
283 QCocoaEventDispatcher *cocoaEventDispatcher = qobject_cast<QCocoaEventDispatcher *>(QGuiApplication::instance()->eventDispatcher());
284 Q_ASSERT(cocoaEventDispatcher != 0);
285 QCocoaEventDispatcherPrivate *cocoaEventDispatcherPrivate = static_cast<QCocoaEventDispatcherPrivate *>(QObjectPrivate::get(cocoaEventDispatcher));
286 cocoaEventDispatcherPrivate->beginModalSession(window());
287 m_hasModalSession = true;
288 } else if ([m_nsWindow canBecomeKeyWindow]) {
289 [m_nsWindow makeKeyAndOrderFront:nil];
291 [m_nsWindow orderFront: nil];
296 // qDebug() << "close" << this;
298 if (m_hasModalSession) {
299 QCocoaEventDispatcher *cocoaEventDispatcher = qobject_cast<QCocoaEventDispatcher *>(QGuiApplication::instance()->eventDispatcher());
300 Q_ASSERT(cocoaEventDispatcher != 0);
301 QCocoaEventDispatcherPrivate *cocoaEventDispatcherPrivate = static_cast<QCocoaEventDispatcherPrivate *>(QObjectPrivate::get(cocoaEventDispatcher));
302 cocoaEventDispatcherPrivate->endModalSession(window());
303 m_hasModalSession = false;
305 if ([m_nsWindow isSheet])
306 [NSApp endSheet:m_nsWindow];
308 [m_nsWindow orderOut:m_nsWindow];
310 if (!QCoreApplication::closingDown())
311 QWindowSystemInterface::handleExposeEvent(window(), QRegion());
315 NSInteger QCocoaWindow::windowLevel(Qt::WindowFlags flags)
317 Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
319 NSInteger windowLevel = NSNormalWindowLevel;
321 if (type == Qt::Tool) {
322 windowLevel = NSFloatingWindowLevel;
323 } else if ((type & Qt::Popup) == Qt::Popup) {
324 windowLevel = NSPopUpMenuWindowLevel;
326 // Popup should be in at least the same level as its parent.
327 const QWindow * const transientParent = window()->transientParent();
328 const QCocoaWindow * const transientParentWindow = transientParent ? static_cast<QCocoaWindow *>(transientParent->handle()) : 0;
329 if (transientParentWindow)
330 windowLevel = qMax([transientParentWindow->m_nsWindow level], windowLevel);
333 // StayOnTop window should appear above Tool windows.
334 if (flags & Qt::WindowStaysOnTopHint)
335 windowLevel = NSPopUpMenuWindowLevel;
336 // Tooltips should appear above StayOnTop windows.
337 if (type == Qt::ToolTip)
338 windowLevel = NSScreenSaverWindowLevel;
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::raise()
414 //qDebug() << "raise" << this;
415 // ### handle spaces (see Qt 4 raise_sys in qwidget_mac.mm)
418 if ([m_nsWindow isVisible])
419 [m_nsWindow orderFront: m_nsWindow];
422 void QCocoaWindow::lower()
426 if ([m_nsWindow isVisible])
427 [m_nsWindow orderBack: m_nsWindow];
430 void QCocoaWindow::propagateSizeHints()
432 QCocoaAutoReleasePool pool;
436 #ifdef QT_COCOA_ENABLE_WINDOW_DEBUG
437 qDebug() << "QCocoaWindow::propagateSizeHints" << this;
438 qDebug() << " min/max " << window()->minimumSize() << window()->maximumSize();
439 qDebug() << "size increment" << window()->sizeIncrement();
440 qDebug() << " basesize" << window()->baseSize();
441 qDebug() << " geometry" << geometry();
444 // Set the minimum content size.
445 const QSize minimumSize = window()->minimumSize();
446 if (!minimumSize.isValid()) // minimumSize is (-1, -1) when not set. Make that (0, 0) for Cocoa.
447 [m_nsWindow setContentMinSize : NSMakeSize(0.0, 0.0)];
448 [m_nsWindow setContentMinSize : NSMakeSize(minimumSize.width(), minimumSize.height())];
450 // Set the maximum content size.
451 const QSize maximumSize = window()->maximumSize();
452 [m_nsWindow setContentMaxSize : NSMakeSize(maximumSize.width(), maximumSize.height())];
454 // sizeIncrement is observed to take values of (-1, -1) and (0, 0) for windows that should be
455 // resizable and that have no specific size increment set. Cocoa expects (1.0, 1.0) in this case.
456 if (!window()->sizeIncrement().isEmpty())
457 [m_nsWindow setResizeIncrements : qt_mac_toNSSize(window()->sizeIncrement())];
459 [m_nsWindow setResizeIncrements : NSMakeSize(1.0, 1.0)];
461 QRect rect = geometry();
462 QSize baseSize = window()->baseSize();
463 if (!baseSize.isNull() && baseSize.isValid()) {
464 [m_nsWindow setFrame:NSMakeRect(rect.x(), rect.y(), baseSize.width(), baseSize.height()) display:YES];
468 void QCocoaWindow::setOpacity(qreal level)
471 [m_nsWindow setAlphaValue:level];
474 bool QCocoaWindow::setKeyboardGrabEnabled(bool grab)
479 if (grab && ![m_nsWindow isKeyWindow])
480 [m_nsWindow makeKeyWindow];
481 else if (!grab && [m_nsWindow isKeyWindow])
482 [m_nsWindow resignKeyWindow];
486 bool QCocoaWindow::setMouseGrabEnabled(bool grab)
491 if (grab && ![m_nsWindow isKeyWindow])
492 [m_nsWindow makeKeyWindow];
493 else if (!grab && [m_nsWindow isKeyWindow])
494 [m_nsWindow resignKeyWindow];
498 WId QCocoaWindow::winId() const
500 return WId(m_contentView);
503 void QCocoaWindow::setParent(const QPlatformWindow *parentWindow)
505 // recreate the window for compatibility
506 recreateWindow(parentWindow);
507 setCocoaGeometry(geometry());
510 NSView *QCocoaWindow::contentView() const
512 return m_contentView;
515 void QCocoaWindow::windowWillMove()
517 // Close any open popups on window move
518 if (m_activePopupWindow) {
519 QWindowSystemInterface::handleSynchronousCloseEvent(m_activePopupWindow);
520 m_activePopupWindow = 0;
524 void QCocoaWindow::windowDidMove()
526 [m_contentView updateGeometry];
529 void QCocoaWindow::windowDidResize()
534 NSRect rect = [[m_nsWindow contentView]frame];
535 // Call setFrameSize which will trigger a frameDidChangeNotification on QNSView.
536 [[m_nsWindow contentView] setFrameSize:rect.size];
539 void QCocoaWindow::windowWillClose()
541 QWindowSystemInterface::handleSynchronousCloseEvent(window());
544 bool QCocoaWindow::windowIsPopupType(Qt::WindowType type) const
546 if (type == Qt::Widget)
547 type = window()->windowType();
548 if (type == Qt::Tool)
549 return false; // Qt::Tool has the Popup bit set but isn't, at least on Mac.
551 return ((type & Qt::Popup) == Qt::Popup);
554 void QCocoaWindow::setCurrentContext(QCocoaGLContext *context)
556 m_glContext = context;
559 QCocoaGLContext *QCocoaWindow::currentContext() const
564 void QCocoaWindow::recreateWindow(const QPlatformWindow *parentWindow)
566 // Remove current window (if any)
568 clearNSWindow(m_nsWindow);
570 [m_nsWindow release];
575 // Create a new NSWindow if this is a top-level window.
576 m_nsWindow = createNSWindow();
577 setNSWindow(m_nsWindow);
579 // QPlatformWindow subclasses must sync up with QWindow on creation:
580 propagateSizeHints();
581 setWindowFlags(window()->windowFlags());
582 setWindowTitle(window()->windowTitle());
583 setWindowState(window()->windowState());
585 if (window()->transientParent()) {
586 // keep this window on the same level as its transient parent (which may be a modal dialog, for example)
587 QCocoaWindow *parentCocoaWindow = static_cast<QCocoaWindow *>(window()->transientParent()->handle());
588 [m_nsWindow setLevel:[parentCocoaWindow->m_nsWindow level]];
591 // Child windows have no NSWindow, link the NSViews instead.
592 const QCocoaWindow *parentCococaWindow = static_cast<const QCocoaWindow *>(parentWindow);
593 [parentCococaWindow->m_contentView addSubview : m_contentView];
597 NSWindow * QCocoaWindow::createNSWindow()
599 QCocoaAutoReleasePool pool;
601 NSRect frame = qt_mac_flipRect(window()->geometry(), window());
603 Qt::WindowType type = window()->windowType();
604 Qt::WindowFlags flags = window()->windowFlags();
606 NSUInteger styleMask = windowStyleMask(flags);
607 NSWindow *createdWindow = 0;
609 // Use NSPanel for popup-type windows. (Popup, Tool, ToolTip, SplashScreen)
610 if ((type & Qt::Popup) == Qt::Popup) {
612 window = [[QNSPanel alloc] initWithContentRect:frame
614 backing:NSBackingStoreBuffered
615 defer:NO]; // Deferring window creation breaks OpenGL (the GL context is set up
616 // before the window is shown and needs a proper window.).
617 [window setHasShadow:YES];
619 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
620 if (QSysInfo::QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) {
621 // Make popup winows show on the same desktop as the parent full-screen window.
622 [window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary];
625 window->m_cocoaPlatformWindow = this;
626 createdWindow = window;
629 window = [[QNSWindow alloc] initWithContentRect:frame
631 backing:NSBackingStoreBuffered
632 defer:NO]; // Deferring window creation breaks OpenGL (the GL context is set up
633 // before the window is shown and needs a proper window.).
634 window->m_cocoaPlatformWindow = this;
635 setWindowShadow(flags);
637 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
638 if (QSysInfo::QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) {
639 // All windows with the WindowMaximizeButtonHint set also get a full-screen button.
640 if (flags & Qt::WindowMaximizeButtonHint)
641 [window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
645 createdWindow = window;
648 NSInteger level = windowLevel(flags);
649 [createdWindow setLevel:level];
651 return createdWindow;
654 void QCocoaWindow::setNSWindow(NSWindow *window)
656 QNSWindowDelegate *delegate = [[QNSWindowDelegate alloc] initWithQCocoaWindow:this];
657 [window setDelegate:delegate];
658 [window setAcceptsMouseMovedEvents:YES];
660 // Prevent Cocoa from releasing the window on close. Qt
661 // handles the close event asynchronously and we want to
662 // make sure that m_nsWindow stays valid until the
663 // QCocoaWindow is deleted by Qt.
664 [window setReleasedWhenClosed : NO];
667 [[NSNotificationCenter defaultCenter] addObserver:m_contentView
668 selector:@selector(windowNotification:)
669 name:nil // Get all notifications
672 // ### Accept touch events by default.
673 // Beware that enabling touch events has a negative impact on the overall performance.
674 // We probably need a QWindowSystemInterface API to enable/disable touch events.
675 [m_contentView setAcceptsTouchEvents:YES];
677 [window setContentView:m_contentView];
680 void QCocoaWindow::clearNSWindow(NSWindow *window)
682 [window setDelegate:nil];
683 [window clearPlatformWindow];
684 [[NSNotificationCenter defaultCenter] removeObserver:m_contentView];
687 // Returns the current global screen geometry for the nswindow associated with this window.
688 QRect QCocoaWindow::windowGeometry() const
693 NSRect rect = [m_nsWindow frame];
694 QPlatformScreen *onScreen = QPlatformScreen::platformScreenForWindow(window());
695 int flippedY = onScreen->geometry().height() - rect.origin.y - rect.size.height; // account for nswindow inverted y.
696 QRect qRect = QRect(rect.origin.x, flippedY, rect.size.width, rect.size.height);
700 // Returns a pointer to the parent QCocoaWindow for this window, or 0 if there is none.
701 QCocoaWindow *QCocoaWindow::parentCocoaWindow() const
703 if (window() && window()->transientParent()) {
704 return static_cast<QCocoaWindow*>(window()->transientParent()->handle());
709 // Syncs the NSWindow minimize/maximize/fullscreen state with the current QWindow state
710 void QCocoaWindow::syncWindowState(Qt::WindowState newState)
715 if ((m_synchedWindowState & Qt::WindowMaximized) != (newState & Qt::WindowMaximized)) {
716 [m_nsWindow performZoom : m_nsWindow]; // toggles
719 if ((m_synchedWindowState & Qt::WindowMinimized) != (newState & Qt::WindowMinimized)) {
720 if (newState & Qt::WindowMinimized) {
721 [m_nsWindow performMiniaturize : m_nsWindow];
723 [m_nsWindow deminiaturize : m_nsWindow];
727 if ((m_synchedWindowState & Qt::WindowFullScreen) != (newState & Qt::WindowFullScreen)) {
728 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
729 if (QSysInfo::QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) {
730 [m_nsWindow toggleFullScreen : m_nsWindow];
732 // TODO: "normal" fullscreen
737 // New state is now the current synched state
738 m_synchedWindowState = newState;
741 bool QCocoaWindow::setWindowModified(bool modified)
745 [m_nsWindow setDocumentEdited:(modified?YES:NO)];
749 void QCocoaWindow::setMenubar(QCocoaMenuBar *mb)
754 QCocoaMenuBar *QCocoaWindow::menubar() const
759 QMargins QCocoaWindow::frameMargins() const
761 NSRect frameW = [m_nsWindow frame];
762 NSRect frameC = [m_nsWindow contentRectForFrameRect:frameW];
764 return QMargins(frameW.origin.x - frameC.origin.x,
765 (frameW.origin.y + frameW.size.height) - (frameC.origin.y + frameC.size.height),
766 (frameW.origin.x + frameW.size.width) - (frameC.origin.x + frameC.size.width),
767 frameC.origin.y - frameW.origin.y);
770 void QCocoaWindow::setFrameStrutEventsEnabled(bool enabled)
772 m_frameStrutEventsEnabled = enabled;