| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | /****************************************************************************
|
|---|
| 43 | NB: This is not a header file, dispite the file name suffix. This file is
|
|---|
| 44 | included directly into the source code of qcocoawindow_mac.mm and
|
|---|
| 45 | qcocoapanel_mac.mm to avoid manually doing copy and paste of the exact
|
|---|
| 46 | same code needed at both places. This solution makes it more difficult
|
|---|
| 47 | to e.g fix a bug in qcocoawindow_mac.mm, but forget to do the same in
|
|---|
| 48 | qcocoapanel_mac.mm.
|
|---|
| 49 | The reason we need to do copy and paste in the first place, rather than
|
|---|
| 50 | resolve to method overriding, is that QCocoaPanel needs to inherit from
|
|---|
| 51 | NSPanel, while QCocoaWindow needs to inherit NSWindow rather than NSPanel).
|
|---|
| 52 | ****************************************************************************/
|
|---|
| 53 |
|
|---|
| 54 | // WARNING: Don't include any header files from within this file. Put them
|
|---|
| 55 | // directly into qcocoawindow_mac_p.h and qcocoapanel_mac_p.h
|
|---|
| 56 |
|
|---|
| 57 | QT_BEGIN_NAMESPACE
|
|---|
| 58 | extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); // qcocoaview.mm
|
|---|
| 59 | extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp
|
|---|
| 60 | QT_END_NAMESPACE
|
|---|
| 61 |
|
|---|
| 62 | - (BOOL)canBecomeKeyWindow
|
|---|
| 63 | {
|
|---|
| 64 | QWidget *widget = [self QT_MANGLE_NAMESPACE(qt_qwidget)];
|
|---|
| 65 |
|
|---|
| 66 | bool isToolTip = (widget->windowType() == Qt::ToolTip);
|
|---|
| 67 | bool isPopup = (widget->windowType() == Qt::Popup);
|
|---|
| 68 | return !(isPopup || isToolTip);
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | - (void)toggleToolbarShown:(id)sender
|
|---|
| 72 | {
|
|---|
| 73 | macSendToolbarChangeEvent([self QT_MANGLE_NAMESPACE(qt_qwidget)]);
|
|---|
| 74 | [super toggleToolbarShown:sender];
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | /*
|
|---|
| 78 | The methods keyDown, keyUp, and flagsChanged... These really shouldn't ever
|
|---|
| 79 | get hit. We automatically say we can be first responder if we are a window.
|
|---|
| 80 | So, the handling should get handled by the view. This is here more as a
|
|---|
| 81 | last resort (i.e., this is code that can potentially be removed).
|
|---|
| 82 | */
|
|---|
| 83 | - (void)keyDown:(NSEvent *)theEvent
|
|---|
| 84 | {
|
|---|
| 85 | bool keyOK = qt_dispatchKeyEvent(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]);
|
|---|
| 86 | if (!keyOK)
|
|---|
| 87 | [super keyDown:theEvent];
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | - (void)keyUp:(NSEvent *)theEvent
|
|---|
| 91 | {
|
|---|
| 92 | bool keyOK = qt_dispatchKeyEvent(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]);
|
|---|
| 93 | if (!keyOK)
|
|---|
| 94 | [super keyUp:theEvent];
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | - (void)flagsChanged:(NSEvent *)theEvent
|
|---|
| 98 | {
|
|---|
| 99 | qt_dispatchModifiersChanged(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]);
|
|---|
| 100 | [super flagsChanged:theEvent];
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 | - (void)tabletProximity:(NSEvent *)tabletEvent
|
|---|
| 105 | {
|
|---|
| 106 | qt_dispatchTabletProximityEvent(tabletEvent);
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | - (void)sendEvent:(NSEvent *)event
|
|---|
| 110 | {
|
|---|
| 111 | QWidget *widget = [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] qt_qwidgetForWindow:self];
|
|---|
| 112 |
|
|---|
| 113 | // Cocoa can hold onto the window after we've disavowed its knowledge. So,
|
|---|
| 114 | // if we get sent an event afterwards just have it go through the super's
|
|---|
| 115 | // version and don't do any stuff with Qt.
|
|---|
| 116 | if (!widget) {
|
|---|
| 117 | [super sendEvent:event];
|
|---|
| 118 | return;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | [self retain];
|
|---|
| 122 | QT_MANGLE_NAMESPACE(QCocoaView) *view = static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(qt_mac_nativeview_for(widget));
|
|---|
| 123 | Qt::MouseButton mouseButton = cocoaButton2QtButton([event buttonNumber]);
|
|---|
| 124 |
|
|---|
| 125 | bool handled = false;
|
|---|
| 126 | // sometimes need to redirect mouse events to the popup.
|
|---|
| 127 | QWidget *popup = qAppInstance()->activePopupWidget();
|
|---|
| 128 | if (popup) {
|
|---|
| 129 | switch([event type])
|
|---|
| 130 | {
|
|---|
| 131 | case NSLeftMouseDown:
|
|---|
| 132 | if (!qt_button_down)
|
|---|
| 133 | qt_button_down = widget;
|
|---|
| 134 | handled = qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonPress, mouseButton);
|
|---|
| 135 | // Don't call super here. This prevents us from getting the mouseUp event,
|
|---|
| 136 | // which we need to send even if the mouseDown event was not accepted.
|
|---|
| 137 | // (this is standard Qt behavior.)
|
|---|
| 138 | break;
|
|---|
| 139 | case NSRightMouseDown:
|
|---|
| 140 | case NSOtherMouseDown:
|
|---|
| 141 | if (!qt_button_down)
|
|---|
| 142 | qt_button_down = widget;
|
|---|
| 143 | handled = qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonPress, mouseButton);
|
|---|
| 144 | break;
|
|---|
| 145 | case NSLeftMouseUp:
|
|---|
| 146 | case NSRightMouseUp:
|
|---|
| 147 | case NSOtherMouseUp:
|
|---|
| 148 | handled = qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonRelease, mouseButton);
|
|---|
| 149 | qt_button_down = 0;
|
|---|
| 150 | break;
|
|---|
| 151 | case NSMouseMoved:
|
|---|
| 152 | handled = qt_mac_handleMouseEvent(view, event, QEvent::MouseMove, Qt::NoButton);
|
|---|
| 153 | break;
|
|---|
| 154 | case NSLeftMouseDragged:
|
|---|
| 155 | case NSRightMouseDragged:
|
|---|
| 156 | case NSOtherMouseDragged:
|
|---|
| 157 | [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->view = view;
|
|---|
| 158 | [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->theEvent = event;
|
|---|
| 159 | handled = qt_mac_handleMouseEvent(view, event, QEvent::MouseMove, mouseButton);
|
|---|
| 160 | break;
|
|---|
| 161 | default:
|
|---|
| 162 | [super sendEvent:event];
|
|---|
| 163 | break;
|
|---|
| 164 | }
|
|---|
| 165 | } else {
|
|---|
| 166 | [super sendEvent:event];
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | if (!handled)
|
|---|
| 170 | qt_mac_dispatchNCMouseMessage(self, event, [self QT_MANGLE_NAMESPACE(qt_qwidget)], leftButtonIsRightButton);
|
|---|
| 171 |
|
|---|
| 172 | [self release];
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | - (BOOL)makeFirstResponder:(NSResponder *)responder
|
|---|
| 176 | {
|
|---|
| 177 | // For some reason Cocoa wants to flip the first responder
|
|---|
| 178 | // when Qt doesn't want to, sorry, but "No" :-)
|
|---|
| 179 | if (responder == nil && qApp->focusWidget())
|
|---|
| 180 | return NO;
|
|---|
| 181 | return [super makeFirstResponder:responder];
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | + (Class)frameViewClassForStyleMask:(NSUInteger)styleMask
|
|---|
| 185 | {
|
|---|
| 186 | if (styleMask & QtMacCustomizeWindow)
|
|---|
| 187 | return [QT_MANGLE_NAMESPACE(QCocoaWindowCustomThemeFrame) class];
|
|---|
| 188 | return [super frameViewClassForStyleMask:styleMask];
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | - (void)displayIfNeeded
|
|---|
| 192 | {
|
|---|
| 193 |
|
|---|
| 194 | QWidget *qwidget = [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] qt_qwidgetForWindow:self];
|
|---|
| 195 | if (qwidget == 0) {
|
|---|
| 196 | [super displayIfNeeded];
|
|---|
| 197 | return;
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | if (QApplicationPrivate::graphicsSystem() != 0) {
|
|---|
| 201 | if (QWidgetBackingStore *bs = qt_widget_private(qwidget)->maybeBackingStore())
|
|---|
| 202 | bs->sync(qwidget, qwidget->rect());
|
|---|
| 203 | }
|
|---|
| 204 | [super displayIfNeeded];
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|