| 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 | #import <private/qcocoaview_mac_p.h>
|
|---|
| 43 | #ifdef QT_MAC_USE_COCOA
|
|---|
| 44 |
|
|---|
| 45 | #include <private/qwidget_p.h>
|
|---|
| 46 | #include <private/qt_mac_p.h>
|
|---|
| 47 | #include <private/qapplication_p.h>
|
|---|
| 48 | #include <private/qabstractscrollarea_p.h>
|
|---|
| 49 | #include <private/qt_cocoa_helpers_mac_p.h>
|
|---|
| 50 | #include <private/qdnd_p.h>
|
|---|
| 51 | #include <private/qmacinputcontext_p.h>
|
|---|
| 52 | #include <private/qmultitouch_mac_p.h>
|
|---|
| 53 | #include <private/qevent_p.h>
|
|---|
| 54 | #include <private/qbackingstore_p.h>
|
|---|
| 55 |
|
|---|
| 56 | #include <qscrollarea.h>
|
|---|
| 57 | #include <qhash.h>
|
|---|
| 58 | #include <qtextformat.h>
|
|---|
| 59 | #include <qpaintengine.h>
|
|---|
| 60 | #include <QUrl>
|
|---|
| 61 | #include <QAccessible>
|
|---|
| 62 | #include <QFileInfo>
|
|---|
| 63 | #include <QFile>
|
|---|
| 64 |
|
|---|
| 65 | #include <qdebug.h>
|
|---|
| 66 |
|
|---|
| 67 | @interface NSEvent (Qt_Compile_Leopard_DeviceDelta)
|
|---|
| 68 | - (CGFloat)deviceDeltaX;
|
|---|
| 69 | - (CGFloat)deviceDeltaY;
|
|---|
| 70 | - (CGFloat)deviceDeltaZ;
|
|---|
| 71 | @end
|
|---|
| 72 |
|
|---|
| 73 | @interface NSEvent (Qt_Compile_Leopard_Gestures)
|
|---|
| 74 | - (CGFloat)magnification;
|
|---|
| 75 | @end
|
|---|
| 76 |
|
|---|
| 77 | QT_BEGIN_NAMESPACE
|
|---|
| 78 |
|
|---|
| 79 | Q_GLOBAL_STATIC(DnDParams, qMacDnDParams);
|
|---|
| 80 |
|
|---|
| 81 | extern void qt_mac_update_cursor_at_global_pos(const QPoint &globalPos); // qcursor_mac.mm
|
|---|
| 82 | extern bool qt_sendSpontaneousEvent(QObject *, QEvent *); // qapplication.cpp
|
|---|
| 83 | extern OSViewRef qt_mac_nativeview_for(const QWidget *w); // qwidget_mac.mm
|
|---|
| 84 | extern const QStringList& qEnabledDraggedTypes(); // qmime_mac.cpp
|
|---|
| 85 | extern QPointer<QWidget> qt_mouseover; //qapplication_mac.mm
|
|---|
| 86 | extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp
|
|---|
| 87 |
|
|---|
| 88 | Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum)
|
|---|
| 89 | {
|
|---|
| 90 | if (buttonNum == 0)
|
|---|
| 91 | return Qt::LeftButton;
|
|---|
| 92 | if (buttonNum == 1)
|
|---|
| 93 | return Qt::RightButton;
|
|---|
| 94 | if (buttonNum == 2)
|
|---|
| 95 | return Qt::MidButton;
|
|---|
| 96 | if (buttonNum == 3)
|
|---|
| 97 | return Qt::XButton1;
|
|---|
| 98 | if (buttonNum == 4)
|
|---|
| 99 | return Qt::XButton2;
|
|---|
| 100 | return Qt::NoButton;
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | struct dndenum_mapper
|
|---|
| 104 | {
|
|---|
| 105 | NSDragOperation mac_code;
|
|---|
| 106 | Qt::DropAction qt_code;
|
|---|
| 107 | bool Qt2Mac;
|
|---|
| 108 | };
|
|---|
| 109 |
|
|---|
| 110 | static dndenum_mapper dnd_enums[] = {
|
|---|
| 111 | { NSDragOperationLink, Qt::LinkAction, true },
|
|---|
| 112 | { NSDragOperationMove, Qt::MoveAction, true },
|
|---|
| 113 | { NSDragOperationCopy, Qt::CopyAction, true },
|
|---|
| 114 | { NSDragOperationGeneric, Qt::CopyAction, false },
|
|---|
| 115 | { NSDragOperationEvery, Qt::ActionMask, false },
|
|---|
| 116 | { NSDragOperationNone, Qt::IgnoreAction, false }
|
|---|
| 117 | };
|
|---|
| 118 |
|
|---|
| 119 | static NSDragOperation qt_mac_mapDropAction(Qt::DropAction action)
|
|---|
| 120 | {
|
|---|
| 121 | for (int i=0; dnd_enums[i].qt_code; i++) {
|
|---|
| 122 | if (dnd_enums[i].Qt2Mac && (action & dnd_enums[i].qt_code)) {
|
|---|
| 123 | return dnd_enums[i].mac_code;
|
|---|
| 124 | }
|
|---|
| 125 | }
|
|---|
| 126 | return NSDragOperationNone;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | static NSDragOperation qt_mac_mapDropActions(Qt::DropActions actions)
|
|---|
| 130 | {
|
|---|
| 131 | NSDragOperation nsActions = NSDragOperationNone;
|
|---|
| 132 | for (int i=0; dnd_enums[i].qt_code; i++) {
|
|---|
| 133 | if (dnd_enums[i].Qt2Mac && (actions & dnd_enums[i].qt_code))
|
|---|
| 134 | nsActions |= dnd_enums[i].mac_code;
|
|---|
| 135 | }
|
|---|
| 136 | return nsActions;
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | static Qt::DropAction qt_mac_mapNSDragOperation(NSDragOperation nsActions)
|
|---|
| 140 | {
|
|---|
| 141 | Qt::DropAction action = Qt::IgnoreAction;
|
|---|
| 142 | for (int i=0; dnd_enums[i].mac_code; i++) {
|
|---|
| 143 | if (nsActions & dnd_enums[i].mac_code)
|
|---|
| 144 | return dnd_enums[i].qt_code;
|
|---|
| 145 | }
|
|---|
| 146 | return action;
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | static Qt::DropActions qt_mac_mapNSDragOperations(NSDragOperation nsActions)
|
|---|
| 150 | {
|
|---|
| 151 | Qt::DropActions actions = Qt::IgnoreAction;
|
|---|
| 152 | for (int i=0; dnd_enums[i].mac_code; i++) {
|
|---|
| 153 | if (nsActions & dnd_enums[i].mac_code)
|
|---|
| 154 | actions |= dnd_enums[i].qt_code;
|
|---|
| 155 | }
|
|---|
| 156 | return actions;
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | static QColor colorFrom(NSColor *color)
|
|---|
| 160 | {
|
|---|
| 161 | QColor qtColor;
|
|---|
| 162 | NSString *colorSpace = [color colorSpaceName];
|
|---|
| 163 | if (colorSpace == NSDeviceCMYKColorSpace) {
|
|---|
| 164 | CGFloat cyan, magenta, yellow, black, alpha;
|
|---|
| 165 | [color getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha];
|
|---|
| 166 | qtColor.setCmykF(cyan, magenta, yellow, black, alpha);
|
|---|
| 167 | } else {
|
|---|
| 168 | NSColor *tmpColor;
|
|---|
| 169 | tmpColor = [color colorUsingColorSpaceName:NSDeviceRGBColorSpace];
|
|---|
| 170 | CGFloat red, green, blue, alpha;
|
|---|
| 171 | [tmpColor getRed:&red green:&green blue:&blue alpha:&alpha];
|
|---|
| 172 | qtColor.setRgbF(red, green, blue, alpha);
|
|---|
| 173 | }
|
|---|
| 174 | return qtColor;
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | QT_END_NAMESPACE
|
|---|
| 178 |
|
|---|
| 179 | QT_FORWARD_DECLARE_CLASS(QMacCocoaAutoReleasePool)
|
|---|
| 180 | QT_FORWARD_DECLARE_CLASS(QCFString)
|
|---|
| 181 | QT_FORWARD_DECLARE_CLASS(QDragManager)
|
|---|
| 182 | QT_FORWARD_DECLARE_CLASS(QMimeData)
|
|---|
|
|---|