/**************************************************************************** ** ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). ** All rights reserved. ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtGui module of the Qt Toolkit. ** ** $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 Digia. For licensing terms and ** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/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 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional ** rights. These rights are described in the Digia Qt 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 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ /**************************************************************************** NB: This is not a header file, dispite the file name suffix. This file is included directly into the source code of qcocoawindow_mac.mm and qcocoapanel_mac.mm to avoid manually doing copy and paste of the exact same code needed at both places. This solution makes it more difficult to e.g fix a bug in qcocoawindow_mac.mm, but forget to do the same in qcocoapanel_mac.mm. The reason we need to do copy and paste in the first place, rather than resolve to method overriding, is that QCocoaPanel needs to inherit from NSPanel, while QCocoaWindow needs to inherit NSWindow rather than NSPanel). ****************************************************************************/ // WARNING: Don't include any header files from within this file. Put them // directly into qcocoawindow_mac_p.h and qcocoapanel_mac_p.h QT_BEGIN_NAMESPACE extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); // qcocoaview.mm extern QPointer qt_button_down; //qapplication_mac.cpp QT_END_NAMESPACE - (BOOL)canBecomeKeyWindow { QWidget *widget = [self QT_MANGLE_NAMESPACE(qt_qwidget)]; bool isToolTip = (widget->windowType() == Qt::ToolTip); bool isPopup = (widget->windowType() == Qt::Popup); return !(isPopup || isToolTip); } - (void)toggleToolbarShown:(id)sender { macSendToolbarChangeEvent([self QT_MANGLE_NAMESPACE(qt_qwidget)]); [super toggleToolbarShown:sender]; } - (void)flagsChanged:(NSEvent *)theEvent { qt_dispatchModifiersChanged(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]); [super flagsChanged:theEvent]; } - (void)tabletProximity:(NSEvent *)tabletEvent { qt_dispatchTabletProximityEvent(tabletEvent); } - (void)sendEvent:(NSEvent *)event { QWidget *widget = [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] qt_qwidgetForWindow:self]; // Cocoa can hold onto the window after we've disavowed its knowledge. So, // if we get sent an event afterwards just have it go through the super's // version and don't do any stuff with Qt. if (!widget) { [super sendEvent:event]; return; } [self retain]; QT_MANGLE_NAMESPACE(QCocoaView) *view = static_cast(qt_mac_nativeview_for(widget)); Qt::MouseButton mouseButton = cocoaButton2QtButton([event buttonNumber]); bool handled = false; // sometimes need to redirect mouse events to the popup. QWidget *popup = qAppInstance()->activePopupWidget(); if (popup) { switch([event type]) { case NSLeftMouseDown: if (!qt_button_down) qt_button_down = widget; handled = qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonPress, mouseButton); // Don't call super here. This prevents us from getting the mouseUp event, // which we need to send even if the mouseDown event was not accepted. // (this is standard Qt behavior.) break; case NSRightMouseDown: case NSOtherMouseDown: if (!qt_button_down) qt_button_down = widget; handled = qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonPress, mouseButton); break; case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp: handled = qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonRelease, mouseButton); qt_button_down = 0; break; case NSMouseMoved: handled = qt_mac_handleMouseEvent(view, event, QEvent::MouseMove, Qt::NoButton); break; case NSLeftMouseDragged: case NSRightMouseDragged: case NSOtherMouseDragged: [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->view = view; [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->theEvent = event; handled = qt_mac_handleMouseEvent(view, event, QEvent::MouseMove, mouseButton); break; default: [super sendEvent:event]; break; } } else { [super sendEvent:event]; } if (!handled) qt_mac_dispatchNCMouseMessage(self, event, [self QT_MANGLE_NAMESPACE(qt_qwidget)], leftButtonIsRightButton); [self release]; } - (BOOL)makeFirstResponder:(NSResponder *)responder { // For some reason Cocoa wants to flip the first responder // when Qt doesn't want to, sorry, but "No" :-) if (responder == nil && qApp->focusWidget()) return NO; return [super makeFirstResponder:responder]; } + (Class)frameViewClassForStyleMask:(NSUInteger)styleMask { if (styleMask & QtMacCustomizeWindow) return [QT_MANGLE_NAMESPACE(QCocoaWindowCustomThemeFrame) class]; return [super frameViewClassForStyleMask:styleMask]; } - (void)displayIfNeeded { QWidget *qwidget = [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] qt_qwidgetForWindow:self]; if (qwidget == 0) { [super displayIfNeeded]; return; } if (QApplicationPrivate::graphicsSystem() != 0) { if (QWidgetBackingStore *bs = qt_widget_private(qwidget)->maybeBackingStore()) bs->sync(qwidget, qwidget->rect()); } [super displayIfNeeded]; }