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 // Popup should be in at least the same level as its parent.
328 const QWindow * const transientParent = window()->transientParent();
329 const QCocoaWindow * const transientParentWindow = transientParent ? static_cast<QCocoaWindow *>(transientParent->handle()) : 0;
330 if (transientParentWindow)
331 windowLevel = qMax([transientParentWindow->m_nsWindow level], windowLevel);
334 // StayOnTop window should appear above Tool windows.
335 if (flags & Qt::WindowStaysOnTopHint)
336 windowLevel = NSPopUpMenuWindowLevel;
337 // Tooltips should appear above StayOnTop windows.
338 if (type == Qt::ToolTip)
339 windowLevel = NSScreenSaverWindowLevel;
344 NSUInteger QCocoaWindow::windowStyleMask(Qt::WindowFlags flags)
346 Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
347 NSInteger styleMask = NSBorderlessWindowMask;
349 if ((type & Qt::Popup) == Qt::Popup) {
350 if (!windowIsPopupType(type))
351 styleMask = (NSUtilityWindowMask | NSResizableWindowMask | NSClosableWindowMask |
352 NSMiniaturizableWindowMask | NSTitledWindowMask);
354 // Filter flags for supported properties
355 flags &= Qt::WindowType_Mask | Qt::FramelessWindowHint | Qt::WindowTitleHint |
356 Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint;
357 if (flags == Qt::Window) {
358 styleMask = (NSResizableWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSTitledWindowMask);
359 } else if (!(flags & Qt::FramelessWindowHint)) {
360 if (flags & Qt::WindowMaximizeButtonHint)
361 styleMask |= NSResizableWindowMask;
362 if (flags & Qt::WindowTitleHint)
363 styleMask |= NSTitledWindowMask;
364 if (flags & Qt::WindowCloseButtonHint)
365 styleMask |= NSClosableWindowMask;
366 if (flags & Qt::WindowMinimizeButtonHint)
367 styleMask |= NSMiniaturizableWindowMask;
374 void QCocoaWindow::setWindowShadow(Qt::WindowFlags flags)
376 bool keepShadow = !(flags & Qt::NoDropShadowWindowHint);
377 [m_nsWindow setHasShadow:(keepShadow ? YES : NO)];
380 Qt::WindowFlags QCocoaWindow::setWindowFlags(Qt::WindowFlags flags)
383 NSUInteger styleMask = windowStyleMask(flags);
384 NSInteger level = this->windowLevel(flags);
385 [m_nsWindow setStyleMask:styleMask];
386 [m_nsWindow setLevel:level];
387 setWindowShadow(flags);
390 m_windowFlags = flags;
391 return m_windowFlags;
394 Qt::WindowState QCocoaWindow::setWindowState(Qt::WindowState state)
396 if ([m_nsWindow isVisible])
397 syncWindowState(state); // Window state set for hidden windows take effect when show() is called.
402 void QCocoaWindow::setWindowTitle(const QString &title)
404 QCocoaAutoReleasePool pool;
408 CFStringRef windowTitle = QCFString::toCFStringRef(title);
409 [m_nsWindow setTitle: const_cast<NSString *>(reinterpret_cast<const NSString *>(windowTitle))];
410 CFRelease(windowTitle);
413 void QCocoaWindow::setWindowFilePath(const QString &filePath)
415 QCocoaAutoReleasePool pool;
419 QFileInfo fi(filePath);
420 [m_nsWindow setRepresentedFilename: fi.exists() ? QCFString::toNSString(filePath) : @""];
423 void QCocoaWindow::raise()
425 //qDebug() << "raise" << this;
426 // ### handle spaces (see Qt 4 raise_sys in qwidget_mac.mm)
429 if ([m_nsWindow isVisible])
430 [m_nsWindow orderFront: m_nsWindow];
433 void QCocoaWindow::lower()
437 if ([m_nsWindow isVisible])
438 [m_nsWindow orderBack: m_nsWindow];
441 void QCocoaWindow::propagateSizeHints()
443 QCocoaAutoReleasePool pool;
447 #ifdef QT_COCOA_ENABLE_WINDOW_DEBUG
448 qDebug() << "QCocoaWindow::propagateSizeHints" << this;
449 qDebug() << " min/max " << window()->minimumSize() << window()->maximumSize();
450 qDebug() << "size increment" << window()->sizeIncrement();
451 qDebug() << " basesize" << window()->baseSize();
452 qDebug() << " geometry" << geometry();
455 // Set the minimum content size.
456 const QSize minimumSize = window()->minimumSize();
457 if (!minimumSize.isValid()) // minimumSize is (-1, -1) when not set. Make that (0, 0) for Cocoa.
458 [m_nsWindow setContentMinSize : NSMakeSize(0.0, 0.0)];
459 [m_nsWindow setContentMinSize : NSMakeSize(minimumSize.width(), minimumSize.height())];
461 // Set the maximum content size.
462 const QSize maximumSize = window()->maximumSize();
463 [m_nsWindow setContentMaxSize : NSMakeSize(maximumSize.width(), maximumSize.height())];
465 // sizeIncrement is observed to take values of (-1, -1) and (0, 0) for windows that should be
466 // resizable and that have no specific size increment set. Cocoa expects (1.0, 1.0) in this case.
467 if (!window()->sizeIncrement().isEmpty())
468 [m_nsWindow setResizeIncrements : qt_mac_toNSSize(window()->sizeIncrement())];
470 [m_nsWindow setResizeIncrements : NSMakeSize(1.0, 1.0)];
472 QRect rect = geometry();
473 QSize baseSize = window()->baseSize();
474 if (!baseSize.isNull() && baseSize.isValid()) {
475 [m_nsWindow setFrame:NSMakeRect(rect.x(), rect.y(), baseSize.width(), baseSize.height()) display:YES];
479 void QCocoaWindow::setOpacity(qreal level)
482 [m_nsWindow setAlphaValue:level];
485 bool QCocoaWindow::setKeyboardGrabEnabled(bool grab)
490 if (grab && ![m_nsWindow isKeyWindow])
491 [m_nsWindow makeKeyWindow];
492 else if (!grab && [m_nsWindow isKeyWindow])
493 [m_nsWindow resignKeyWindow];
497 bool QCocoaWindow::setMouseGrabEnabled(bool grab)
502 if (grab && ![m_nsWindow isKeyWindow])
503 [m_nsWindow makeKeyWindow];
504 else if (!grab && [m_nsWindow isKeyWindow])
505 [m_nsWindow resignKeyWindow];
509 WId QCocoaWindow::winId() const
511 return WId(m_contentView);
514 void QCocoaWindow::setParent(const QPlatformWindow *parentWindow)
516 // recreate the window for compatibility
517 recreateWindow(parentWindow);
518 setCocoaGeometry(geometry());
521 NSView *QCocoaWindow::contentView() const
523 return m_contentView;
526 void QCocoaWindow::windowWillMove()
528 // Close any open popups on window move
529 if (m_activePopupWindow) {
530 QWindowSystemInterface::handleSynchronousCloseEvent(m_activePopupWindow);
531 m_activePopupWindow = 0;
535 void QCocoaWindow::windowDidMove()
537 [m_contentView updateGeometry];
540 void QCocoaWindow::windowDidResize()
545 NSRect rect = [[m_nsWindow contentView]frame];
546 // Call setFrameSize which will trigger a frameDidChangeNotification on QNSView.
547 [[m_nsWindow contentView] setFrameSize:rect.size];
550 void QCocoaWindow::windowWillClose()
552 QWindowSystemInterface::handleSynchronousCloseEvent(window());
555 bool QCocoaWindow::windowIsPopupType(Qt::WindowType type) const
557 if (type == Qt::Widget)
558 type = window()->windowType();
559 if (type == Qt::Tool)
560 return false; // Qt::Tool has the Popup bit set but isn't, at least on Mac.
562 return ((type & Qt::Popup) == Qt::Popup);
565 void QCocoaWindow::setCurrentContext(QCocoaGLContext *context)
567 m_glContext = context;
570 QCocoaGLContext *QCocoaWindow::currentContext() const
575 void QCocoaWindow::recreateWindow(const QPlatformWindow *parentWindow)
577 // Remove current window (if any)
579 clearNSWindow(m_nsWindow);
581 [m_nsWindow release];
586 // Create a new NSWindow if this is a top-level window.
587 m_nsWindow = createNSWindow();
588 setNSWindow(m_nsWindow);
590 // QPlatformWindow subclasses must sync up with QWindow on creation:
591 propagateSizeHints();
592 setWindowFlags(window()->windowFlags());
593 setWindowTitle(window()->windowTitle());
594 setWindowState(window()->windowState());
596 if (window()->transientParent()) {
597 // keep this window on the same level as its transient parent (which may be a modal dialog, for example)
598 QCocoaWindow *parentCocoaWindow = static_cast<QCocoaWindow *>(window()->transientParent()->handle());
599 [m_nsWindow setLevel:[parentCocoaWindow->m_nsWindow level]];
602 // Child windows have no NSWindow, link the NSViews instead.
603 const QCocoaWindow *parentCococaWindow = static_cast<const QCocoaWindow *>(parentWindow);
604 [parentCococaWindow->m_contentView addSubview : m_contentView];
608 NSWindow * QCocoaWindow::createNSWindow()
610 QCocoaAutoReleasePool pool;
612 NSRect frame = qt_mac_flipRect(window()->geometry(), window());
614 Qt::WindowType type = window()->windowType();
615 Qt::WindowFlags flags = window()->windowFlags();
617 NSUInteger styleMask = windowStyleMask(flags);
618 NSWindow *createdWindow = 0;
620 // Use NSPanel for popup-type windows. (Popup, Tool, ToolTip, SplashScreen)
621 if ((type & Qt::Popup) == Qt::Popup) {
623 window = [[QNSPanel alloc] initWithContentRect:frame
625 backing:NSBackingStoreBuffered
626 defer:NO]; // Deferring window creation breaks OpenGL (the GL context is set up
627 // before the window is shown and needs a proper window.).
628 [window setHasShadow:YES];
630 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
631 if (QSysInfo::QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) {
632 // Make popup winows show on the same desktop as the parent full-screen window.
633 [window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary];
636 window->m_cocoaPlatformWindow = this;
637 createdWindow = window;
640 window = [[QNSWindow alloc] initWithContentRect:frame
642 backing:NSBackingStoreBuffered
643 defer:NO]; // Deferring window creation breaks OpenGL (the GL context is set up
644 // before the window is shown and needs a proper window.).
645 window->m_cocoaPlatformWindow = this;
646 setWindowShadow(flags);
648 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
649 if (QSysInfo::QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) {
650 // All windows with the WindowMaximizeButtonHint set also get a full-screen button.
651 if (flags & Qt::WindowMaximizeButtonHint)
652 [window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
656 createdWindow = window;
659 NSInteger level = windowLevel(flags);
660 [createdWindow setLevel:level];
662 return createdWindow;
665 void QCocoaWindow::setNSWindow(NSWindow *window)
667 QNSWindowDelegate *delegate = [[QNSWindowDelegate alloc] initWithQCocoaWindow:this];
668 [window setDelegate:delegate];
669 [window setAcceptsMouseMovedEvents:YES];
671 // Prevent Cocoa from releasing the window on close. Qt
672 // handles the close event asynchronously and we want to
673 // make sure that m_nsWindow stays valid until the
674 // QCocoaWindow is deleted by Qt.
675 [window setReleasedWhenClosed : NO];
678 [[NSNotificationCenter defaultCenter] addObserver:m_contentView
679 selector:@selector(windowNotification:)
680 name:nil // Get all notifications
683 // ### Accept touch events by default.
684 // Beware that enabling touch events has a negative impact on the overall performance.
685 // We probably need a QWindowSystemInterface API to enable/disable touch events.
686 [m_contentView setAcceptsTouchEvents:YES];
688 [window setContentView:m_contentView];
691 void QCocoaWindow::clearNSWindow(NSWindow *window)
693 [window setDelegate:nil];
694 [window clearPlatformWindow];
695 [[NSNotificationCenter defaultCenter] removeObserver:m_contentView];
698 // Returns the current global screen geometry for the nswindow associated with this window.
699 QRect QCocoaWindow::windowGeometry() const
704 NSRect rect = [m_nsWindow frame];
705 QPlatformScreen *onScreen = QPlatformScreen::platformScreenForWindow(window());
706 int flippedY = onScreen->geometry().height() - rect.origin.y - rect.size.height; // account for nswindow inverted y.
707 QRect qRect = QRect(rect.origin.x, flippedY, rect.size.width, rect.size.height);
711 // Returns a pointer to the parent QCocoaWindow for this window, or 0 if there is none.
712 QCocoaWindow *QCocoaWindow::parentCocoaWindow() const
714 if (window() && window()->transientParent()) {
715 return static_cast<QCocoaWindow*>(window()->transientParent()->handle());
720 // Syncs the NSWindow minimize/maximize/fullscreen state with the current QWindow state
721 void QCocoaWindow::syncWindowState(Qt::WindowState newState)
726 if ((m_synchedWindowState & Qt::WindowMaximized) != (newState & Qt::WindowMaximized)) {
727 [m_nsWindow performZoom : m_nsWindow]; // toggles
730 if ((m_synchedWindowState & Qt::WindowMinimized) != (newState & Qt::WindowMinimized)) {
731 if (newState & Qt::WindowMinimized) {
732 [m_nsWindow performMiniaturize : m_nsWindow];
734 [m_nsWindow deminiaturize : m_nsWindow];
738 if ((m_synchedWindowState & Qt::WindowFullScreen) != (newState & Qt::WindowFullScreen)) {
739 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
740 if (QSysInfo::QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) {
741 [m_nsWindow toggleFullScreen : m_nsWindow];
743 // TODO: "normal" fullscreen
748 // New state is now the current synched state
749 m_synchedWindowState = newState;
752 bool QCocoaWindow::setWindowModified(bool modified)
756 [m_nsWindow setDocumentEdited:(modified?YES:NO)];
760 void QCocoaWindow::setMenubar(QCocoaMenuBar *mb)
765 QCocoaMenuBar *QCocoaWindow::menubar() const
770 QMargins QCocoaWindow::frameMargins() const
772 NSRect frameW = [m_nsWindow frame];
773 NSRect frameC = [m_nsWindow contentRectForFrameRect:frameW];
775 return QMargins(frameW.origin.x - frameC.origin.x,
776 (frameW.origin.y + frameW.size.height) - (frameC.origin.y + frameC.size.height),
777 (frameW.origin.x + frameW.size.width) - (frameC.origin.x + frameC.size.width),
778 frameC.origin.y - frameW.origin.y);
781 void QCocoaWindow::setFrameStrutEventsEnabled(bool enabled)
783 m_frameStrutEventsEnabled = enabled;