1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** 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 are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qapplication.h"
|
---|
43 | #ifndef QT_NO_DRAGANDDROP
|
---|
44 | #include "qbitmap.h"
|
---|
45 | #include "qcursor.h"
|
---|
46 | #include "qevent.h"
|
---|
47 | #include "qpainter.h"
|
---|
48 | #include "qurl.h"
|
---|
49 | #include "qwidget.h"
|
---|
50 | #include "qfile.h"
|
---|
51 | #include "qfileinfo.h"
|
---|
52 | #include <stdlib.h>
|
---|
53 | #include <string.h>
|
---|
54 | #ifndef QT_NO_ACCESSIBILITY
|
---|
55 | # include "qaccessible.h"
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | #include <private/qapplication_p.h>
|
---|
59 | #include <private/qwidget_p.h>
|
---|
60 | #include <private/qdnd_p.h>
|
---|
61 | #include <private/qt_mac_p.h>
|
---|
62 |
|
---|
63 | QT_BEGIN_NAMESPACE
|
---|
64 |
|
---|
65 | QT_USE_NAMESPACE
|
---|
66 |
|
---|
67 | QMacDndAnswerRecord qt_mac_dnd_answer_rec;
|
---|
68 |
|
---|
69 | /*****************************************************************************
|
---|
70 | QDnD debug facilities
|
---|
71 | *****************************************************************************/
|
---|
72 | //#define DEBUG_DRAG_EVENTS
|
---|
73 | //#define DEBUG_DRAG_PROMISES
|
---|
74 |
|
---|
75 | /*****************************************************************************
|
---|
76 | QDnD globals
|
---|
77 | *****************************************************************************/
|
---|
78 | bool qt_mac_in_drag = false;
|
---|
79 | #ifndef QT_MAC_USE_COCOA
|
---|
80 | static DragReference qt_mac_current_dragRef = 0;
|
---|
81 | #endif
|
---|
82 |
|
---|
83 | /*****************************************************************************
|
---|
84 | Externals
|
---|
85 | *****************************************************************************/
|
---|
86 | extern void qt_mac_send_modifiers_changed(quint32, QObject *); //qapplication_mac.cpp
|
---|
87 | extern uint qGlobalPostedEventsCount(); //qapplication.cpp
|
---|
88 | extern RgnHandle qt_mac_get_rgn(); // qregion_mac.cpp
|
---|
89 | extern void qt_mac_dispose_rgn(RgnHandle); // qregion_mac.cpp
|
---|
90 | /*****************************************************************************
|
---|
91 | QDnD utility functions
|
---|
92 | *****************************************************************************/
|
---|
93 |
|
---|
94 | //default pixmap
|
---|
95 | static const int default_pm_hotx = -2;
|
---|
96 | static const int default_pm_hoty = -16;
|
---|
97 | #ifndef QT_MAC_USE_COCOA
|
---|
98 | static const char * const default_pm[] = {
|
---|
99 | "13 9 3 1",
|
---|
100 | ". c None",
|
---|
101 | " c #000000",
|
---|
102 | "X c #FFFFFF",
|
---|
103 | "X X X X X X X",
|
---|
104 | " X X X X X X ",
|
---|
105 | "X ......... X",
|
---|
106 | " X.........X ",
|
---|
107 | "X ......... X",
|
---|
108 | " X.........X ",
|
---|
109 | "X ......... X",
|
---|
110 | " X X X X X X ",
|
---|
111 | "X X X X X X X",
|
---|
112 | };
|
---|
113 | #endif
|
---|
114 |
|
---|
115 | //action management
|
---|
116 | #ifdef DEBUG_DRAG_EVENTS
|
---|
117 | # define MAP_MAC_ENUM(x) x, #x
|
---|
118 | #else
|
---|
119 | # define MAP_MAC_ENUM(x) x
|
---|
120 | #endif
|
---|
121 | struct mac_enum_mapper
|
---|
122 | {
|
---|
123 | int mac_code;
|
---|
124 | int qt_code;
|
---|
125 | #ifdef DEBUG_DRAG_EVENTS
|
---|
126 | char *qt_desc;
|
---|
127 | #endif
|
---|
128 | };
|
---|
129 | #ifndef QT_MAC_USE_COCOA
|
---|
130 | static mac_enum_mapper dnd_action_symbols[] = {
|
---|
131 | { kDragActionAlias, MAP_MAC_ENUM(Qt::LinkAction) },
|
---|
132 | { kDragActionMove, MAP_MAC_ENUM(Qt::MoveAction) },
|
---|
133 | { kDragActionGeneric, MAP_MAC_ENUM(Qt::CopyAction) },
|
---|
134 | { kDragActionCopy, MAP_MAC_ENUM(Qt::CopyAction) },
|
---|
135 | { 0, MAP_MAC_ENUM(0) }
|
---|
136 | };
|
---|
137 | static DragActions qt_mac_dnd_map_qt_actions(Qt::DropActions qActions)
|
---|
138 | {
|
---|
139 | DragActions ret = kDragActionNothing;
|
---|
140 | for(int i = 0; dnd_action_symbols[i].qt_code; ++i) {
|
---|
141 | if(qActions & dnd_action_symbols[i].qt_code)
|
---|
142 | ret |= dnd_action_symbols[i].mac_code;
|
---|
143 | }
|
---|
144 | return ret;
|
---|
145 | }
|
---|
146 | static Qt::DropActions qt_mac_dnd_map_mac_actions(DragActions macActions)
|
---|
147 | {
|
---|
148 | #ifdef DEBUG_DRAG_EVENTS
|
---|
149 | qDebug("Converting DND ActionList: 0x%lx", macActions);
|
---|
150 | #endif
|
---|
151 | Qt::DropActions ret = Qt::IgnoreAction;
|
---|
152 | for(int i = 0; dnd_action_symbols[i].qt_code; ++i) {
|
---|
153 | #ifdef DEBUG_DRAG_EVENTS
|
---|
154 | qDebug(" %d) [%s] : %s", i, dnd_action_symbols[i].qt_desc,
|
---|
155 | (macActions & dnd_action_symbols[i].mac_code) ? "true" : "false");
|
---|
156 | #endif
|
---|
157 | if(macActions & dnd_action_symbols[i].mac_code)
|
---|
158 | ret |= Qt::DropAction(dnd_action_symbols[i].qt_code);
|
---|
159 | }
|
---|
160 | return ret;
|
---|
161 | }
|
---|
162 | static Qt::DropAction qt_mac_dnd_map_mac_default_action(DragActions macActions)
|
---|
163 | {
|
---|
164 | static Qt::DropAction preferred_actions[] = { Qt::CopyAction, Qt::LinkAction, //in order
|
---|
165 | Qt::MoveAction, Qt::IgnoreAction };
|
---|
166 | Qt::DropAction ret = Qt::IgnoreAction;
|
---|
167 | const Qt::DropActions qtActions = qt_mac_dnd_map_mac_actions(macActions);
|
---|
168 | for(int i = 0; preferred_actions[i] != Qt::IgnoreAction; ++i) {
|
---|
169 | if(qtActions & preferred_actions[i]) {
|
---|
170 | ret = preferred_actions[i];
|
---|
171 | break;
|
---|
172 | }
|
---|
173 | }
|
---|
174 | #ifdef DEBUG_DRAG_EVENTS
|
---|
175 | for(int i = 0; dnd_action_symbols[i].qt_code; ++i) {
|
---|
176 | if(dnd_action_symbols[i].qt_code == ret) {
|
---|
177 | qDebug("Got default action: %s [0x%lx]", dnd_action_symbols[i].qt_desc, macActions);
|
---|
178 | break;
|
---|
179 | }
|
---|
180 | }
|
---|
181 | #endif
|
---|
182 | return ret;
|
---|
183 | }
|
---|
184 | static void qt_mac_dnd_update_action(DragReference dragRef) {
|
---|
185 | SInt16 modifiers;
|
---|
186 | GetDragModifiers(dragRef, &modifiers, 0, 0);
|
---|
187 | qt_mac_send_modifiers_changed(modifiers, qApp);
|
---|
188 |
|
---|
189 | Qt::DropAction qtAction = Qt::IgnoreAction;
|
---|
190 | {
|
---|
191 | DragActions macAllowed = kDragActionNothing;
|
---|
192 | GetDragDropAction(dragRef, &macAllowed);
|
---|
193 | Qt::DropActions qtAllowed = qt_mac_dnd_map_mac_actions(macAllowed);
|
---|
194 | qtAction = QDragManager::self()->defaultAction(qtAllowed, QApplication::keyboardModifiers());
|
---|
195 | #if 1
|
---|
196 | if(!(qtAllowed & qtAction))
|
---|
197 | qtAction = qt_mac_dnd_map_mac_default_action(macAllowed);
|
---|
198 | #endif
|
---|
199 | }
|
---|
200 | DragActions macAction = qt_mac_dnd_map_qt_actions(qtAction);
|
---|
201 |
|
---|
202 | DragActions currentActions;
|
---|
203 | GetDragDropAction(dragRef, ¤tActions);
|
---|
204 | if(currentActions != macAction) {
|
---|
205 | SetDragDropAction(dragRef, macAction);
|
---|
206 | QDragManager::self()->emitActionChanged(qtAction);
|
---|
207 | }
|
---|
208 | }
|
---|
209 | #endif // !QT_MAC_USE_COCOA
|
---|
210 |
|
---|
211 | /*****************************************************************************
|
---|
212 | DnD functions
|
---|
213 | *****************************************************************************/
|
---|
214 | bool QDropData::hasFormat_sys(const QString &mime) const
|
---|
215 | {
|
---|
216 | #ifndef QT_MAC_USE_COCOA
|
---|
217 | OSPasteboardRef board;
|
---|
218 | if(GetDragPasteboard(qt_mac_current_dragRef, &board) != noErr) {
|
---|
219 | qDebug("DnD: Cannot get PasteBoard!");
|
---|
220 | return false;
|
---|
221 | }
|
---|
222 | return QMacPasteboard(board, QMacPasteboardMime::MIME_DND).hasFormat(mime);
|
---|
223 | #else
|
---|
224 | Q_UNUSED(mime);
|
---|
225 | return false;
|
---|
226 | #endif // !QT_MAC_USE_COCOA
|
---|
227 | }
|
---|
228 |
|
---|
229 | QVariant QDropData::retrieveData_sys(const QString &mime, QVariant::Type type) const
|
---|
230 | {
|
---|
231 | #ifndef QT_MAC_USE_COCOA
|
---|
232 | OSPasteboardRef board;
|
---|
233 | if(GetDragPasteboard(qt_mac_current_dragRef, &board) != noErr) {
|
---|
|
---|