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,
|
---|
|
---|