1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 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 | #ifndef QDND_P_H
|
---|
43 | #define QDND_P_H
|
---|
44 |
|
---|
45 | //
|
---|
46 | // W A R N I N G
|
---|
47 | // -------------
|
---|
48 | //
|
---|
49 | // This file is not part of the Qt API. It exists for the convenience
|
---|
50 | // of other Qt classes. This header file may change from version to
|
---|
51 | // version without notice, or even be removed.
|
---|
52 | //
|
---|
53 | // We mean it.
|
---|
54 | //
|
---|
55 |
|
---|
56 | #include "QtCore/qobject.h"
|
---|
57 | #include "QtCore/qmap.h"
|
---|
58 | #include "QtGui/qmime.h"
|
---|
59 | #include "QtGui/qdrag.h"
|
---|
60 | #include "QtGui/qpixmap.h"
|
---|
61 | #include "QtGui/qcursor.h"
|
---|
62 | #include "QtCore/qpoint.h"
|
---|
63 | #include "private/qobject_p.h"
|
---|
64 | #ifdef Q_WS_MAC
|
---|
65 | # include "private/qt_mac_p.h"
|
---|
66 | #endif
|
---|
67 |
|
---|
68 | #if defined(Q_WS_PM)
|
---|
69 | #include "qt_os2.h"
|
---|
70 | #endif
|
---|
71 |
|
---|
72 | #if defined(Q_WS_WIN)
|
---|
73 | # include <qt_windows.h>
|
---|
74 | # include <objidl.h>
|
---|
75 | #endif
|
---|
76 |
|
---|
77 | QT_BEGIN_NAMESPACE
|
---|
78 |
|
---|
79 | class QEventLoop;
|
---|
80 |
|
---|
81 | #if !(defined(QT_NO_DRAGANDDROP) && defined(QT_NO_CLIPBOARD))
|
---|
82 |
|
---|
83 | class QInternalMimeData : public QMimeData
|
---|
84 | {
|
---|
85 | Q_OBJECT
|
---|
86 | public:
|
---|
87 | QInternalMimeData();
|
---|
88 | ~QInternalMimeData();
|
---|
89 |
|
---|
90 | bool hasFormat(const QString &mimeType) const;
|
---|
91 | QStringList formats() const;
|
---|
92 | static bool canReadData(const QString &mimeType);
|
---|
93 |
|
---|
94 |
|
---|
95 | static QStringList formatsHelper(const QMimeData *data);
|
---|
96 | static bool hasFormatHelper(const QString &mimeType, const QMimeData *data);
|
---|
97 | static QByteArray renderDataHelper(const QString &mimeType, const QMimeData *data);
|
---|
98 |
|
---|
99 | protected:
|
---|
100 | QVariant retrieveData(const QString &mimeType, QVariant::Type type) const;
|
---|
101 |
|
---|
102 | virtual bool hasFormat_sys(const QString &mimeType) const = 0;
|
---|
103 | virtual QStringList formats_sys() const = 0;
|
---|
104 | virtual QVariant retrieveData_sys(const QString &mimeType, QVariant::Type type) const = 0;
|
---|
105 | };
|
---|
106 |
|
---|
107 | #ifdef Q_WS_WIN
|
---|
108 | class QOleDataObject : public IDataObject
|
---|
109 | {
|
---|
110 | public:
|
---|
111 | explicit QOleDataObject(QMimeData *mimeData);
|
---|
112 | virtual ~QOleDataObject();
|
---|
113 |
|
---|
114 | void releaseQt();
|
---|
115 | const QMimeData *mimeData() const;
|
---|
116 | DWORD reportedPerformedEffect() const;
|
---|
117 |
|
---|
118 | // IUnknown methods
|
---|
119 | STDMETHOD(QueryInterface)(REFIID riid, void FAR* FAR* ppvObj);
|
---|
120 | STDMETHOD_(ULONG,AddRef)(void);
|
---|
121 | STDMETHOD_(ULONG,Release)(void);
|
---|
122 |
|
---|
123 | // IDataObject methods
|
---|
124 | STDMETHOD(GetData)(LPFORMATETC pformatetcIn, LPSTGMEDIUM pmedium);
|
---|
125 | STDMETHOD(GetDataHere)(LPFORMATETC pformatetc, LPSTGMEDIUM pmedium);
|
---|
126 | STDMETHOD(QueryGetData)(LPFORMATETC pformatetc);
|
---|
127 | STDMETHOD(GetCanonicalFormatEtc)(LPFORMATETC pformatetc, LPFORMATETC pformatetcOut);
|
---|
128 | STDMETHOD(SetData)(LPFORMATETC pformatetc, STGMEDIUM FAR * pmedium,
|
---|
129 | BOOL fRelease);
|
---|
130 | STDMETHOD(EnumFormatEtc)(DWORD dwDirection, LPENUMFORMATETC FAR* ppenumFormatEtc);
|
---|
131 | STDMETHOD(DAdvise)(FORMATETC FAR* pFormatetc, DWORD advf,
|
---|
132 | LPADVISESINK pAdvSink, DWORD FAR* pdwConnection);
|
---|
133 | STDMETHOD(DUnadvise)(DWORD dwConnection);
|
---|
134 | STDMETHOD(EnumDAdvise)(LPENUMSTATDATA FAR* ppenumAdvise);
|
---|
135 |
|
---|
136 | private:
|
---|
137 | ULONG m_refs;
|
---|
138 | QPointer<QMimeData> data;
|
---|
139 | int CF_PERFORMEDDROPEFFECT;
|
---|
140 | DWORD performedEffect;
|
---|
141 | };
|
---|
142 |
|
---|
143 | class QOleEnumFmtEtc : public IEnumFORMATETC
|
---|
144 | {
|
---|
145 | public:
|
---|
146 | explicit QOleEnumFmtEtc(const QVector<FORMATETC> &fmtetcs);
|
---|
147 | explicit QOleEnumFmtEtc(const QVector<LPFORMATETC> &lpfmtetcs);
|
---|
148 | virtual ~QOleEnumFmtEtc();
|
---|
149 |
|
---|
150 | bool isNull() const;
|
---|
151 |
|
---|
152 | // IUnknown methods
|
---|
153 | STDMETHOD(QueryInterface)(REFIID riid, void FAR* FAR* ppvObj);
|
---|
154 | STDMETHOD_(ULONG,AddRef)(void);
|
---|
155 | STDMETHOD_(ULONG,Release)(void);
|
---|
156 |
|
---|
157 | // IEnumFORMATETC methods
|
---|
158 | STDMETHOD(Next)(ULONG celt, LPFORMATETC rgelt, ULONG FAR* pceltFetched);
|
---|
159 | STDMETHOD(Skip)(ULONG celt);
|
---|
160 | STDMETHOD(Reset)(void);
|
---|
161 | STDMETHOD(Clone)(LPENUMFORMATETC FAR* newEnum);
|
---|
162 |
|
---|
163 | private:
|
---|
164 | bool copyFormatEtc(LPFORMATETC dest, LPFORMATETC src) const;
|
---|
165 |
|
---|
166 | ULONG m_dwRefs;
|
---|
167 | ULONG m_nIndex;
|
---|
168 | QVector<LPFORMATETC> m_lpfmtetcs;
|
---|
169 | bool m_isNull;
|
---|
170 | };
|
---|
171 |
|
---|
172 | #endif
|
---|
173 |
|
---|
174 | #endif //QT_NO_DRAGANDDROP && QT_NO_CLIPBOARD
|
---|
175 |
|
---|
176 | #ifndef QT_NO_DRAGANDDROP
|
---|
177 |
|
---|
178 | class QDragPrivate : public QObjectPrivate
|
---|
179 | {
|
---|
180 | public:
|
---|
181 | QWidget *source;
|
---|
182 | QWidget *target;
|
---|
183 | QMimeData *data;
|
---|
184 | QPixmap pixmap;
|
---|
185 | QPoint hotspot;
|
---|
186 | Qt::DropActions possible_actions;
|
---|
187 | Qt::DropAction executed_action;
|
---|
188 | QMap<Qt::DropAction, QPixmap> customCursors;
|
---|
189 | Qt::DropAction defaultDropAction;
|
---|
190 | };
|
---|
191 |
|
---|
192 | #if defined(Q_WS_PM)
|
---|
193 | class QPMDragData;
|
---|
194 | #endif
|
---|
195 |
|
---|
196 | class QDropData : public QInternalMimeData
|
---|
197 | {
|
---|
198 | Q_OBJECT
|
---|
199 | public:
|
---|
200 | QDropData();
|
---|
201 | ~QDropData();
|
---|
202 |
|
---|
203 | protected:
|
---|
204 | bool hasFormat_sys(const QString &mimeType) const;
|
---|
205 | QStringList formats_sys() const;
|
---|
206 | QVariant retrieveData_sys(const QString &mimeType, QVariant::Type type) const;
|
---|
207 |
|
---|
208 | #if defined(Q_WS_WIN)
|
---|
209 | public:
|
---|
210 | LPDATAOBJECT currentDataObject;
|
---|
211 | #elif defined(Q_WS_PM)
|
---|
212 | friend class QDragManager;
|
---|
213 | QPMDragData *d;
|
---|
214 | #endif
|
---|
215 | };
|
---|
216 |
|
---|
217 | class QDragManager: public QObject {
|
---|
218 | Q_OBJECT
|
---|
219 |
|
---|
220 | QDragManager();
|
---|
221 | ~QDragManager();
|
---|
222 | // only friend classes can use QDragManager.
|
---|
223 | friend class QDrag;
|
---|
224 | friend class QDragMoveEvent;
|
---|
225 | friend class QDropEvent;
|
---|
226 | friend class QApplication;
|
---|
227 | #ifdef Q_WS_MAC
|
---|
228 | friend class QWidgetPrivate; //dnd is implemented here
|
---|
229 | #endif
|
---|
230 |
|
---|
231 | bool eventFilter(QObject *, QEvent *);
|
---|
232 | void timerEvent(QTimerEvent*);
|
---|
233 |
|
---|
234 | public:
|
---|
235 | Qt::DropAction drag(QDrag *);
|
---|
236 |
|
---|
237 | void cancel(bool deleteSource = true);
|
---|
238 | void move(const QPoint &);
|
---|
239 | void drop();
|
---|
240 | void updatePixmap();
|
---|
241 | QWidget *source() const { return object ? object->d_func()->source : 0; }
|
---|
242 | QDragPrivate *dragPrivate() const { return object ? object->d_func() : 0; }
|
---|
243 | static QDragPrivate *dragPrivate(QDrag *drag) { return drag ? drag->d_func() : 0; }
|
---|
244 |
|
---|
245 | static QDragManager *self();
|
---|
246 | Qt::DropAction defaultAction(Qt::DropActions possibleActions,
|
---|
247 | Qt::KeyboardModifiers modifiers) const;
|
---|
248 |
|
---|
249 | QDrag *object;
|
---|
250 |
|
---|
251 | void updateCursor();
|
---|
252 |
|
---|
253 | bool beingCancelled;
|
---|
254 | bool restoreCursor;
|
---|
255 | bool willDrop;
|
---|
256 | QEventLoop *eventLoop;
|
---|
257 |
|
---|
258 | QPixmap dragCursor(Qt::DropAction action) const;
|
---|
259 |
|
---|
260 | bool hasCustomDragCursors() const;
|
---|
261 |
|
---|
262 | QDropData *dropData;
|
---|
263 |
|
---|
264 | void emitActionChanged(Qt::DropAction newAction) { if (object) emit object->actionChanged(newAction); }
|
---|
265 |
|
---|
266 | void setCurrentTarget(QWidget *target, bool dropped = false);
|
---|
267 | QWidget *currentTarget();
|
---|
268 |
|
---|
269 | bool isInOwnDrag() const { return object != 0; }
|
---|
270 |
|
---|
271 | #ifdef Q_WS_X11
|
---|
272 | QPixmap xdndMimeTransferedPixmap[2];
|
---|
273 | int xdndMimeTransferedPixmapIndex;
|
---|
274 | #endif
|
---|
275 |
|
---|
276 | #ifdef Q_WS_PM
|
---|
277 | void init_sys();
|
---|
278 | void uninit_sys();
|
---|
279 | void sendDropEvent(QWidget *receiver, QEvent *event);
|
---|
280 | MRESULT dispatchDragAndDrop(QWidget *widget, const QMSG &qmsg);
|
---|
281 | bool isInDrag() const { return inDrag; }
|
---|
282 | #endif
|
---|
283 |
|
---|
284 | private:
|
---|
285 | #ifdef Q_WS_QWS
|
---|
286 | Qt::DropAction currentActionForOverrideCursor;
|
---|
287 | #endif
|
---|
288 | #ifdef Q_OS_SYMBIAN
|
---|
289 | #ifndef QT_NO_CURSOR
|
---|
290 | QCursor overrideCursor;
|
---|
291 | #endif
|
---|
292 | #endif
|
---|
293 | #ifdef Q_WS_PM
|
---|
294 | bool inDrag;
|
---|
295 | #endif
|
---|
296 |
|
---|
297 | QWidget *currentDropTarget;
|
---|
298 |
|
---|
299 | static QDragManager *instance;
|
---|
300 | Q_DISABLE_COPY(QDragManager)
|
---|
301 | };
|
---|
302 |
|
---|
303 |
|
---|
304 | #if defined(Q_WS_WIN)
|
---|
305 |
|
---|
306 | class QOleDropTarget : public IDropTarget
|
---|
307 | {
|
---|
308 | public:
|
---|
309 | QOleDropTarget(QWidget* w);
|
---|
310 | virtual ~QOleDropTarget() {}
|
---|
311 |
|
---|
312 | void releaseQt();
|
---|
313 |
|
---|
314 | // IUnknown methods
|
---|
315 | STDMETHOD(QueryInterface)(REFIID riid, void FAR* FAR* ppvObj);
|
---|
316 | STDMETHOD_(ULONG, AddRef)(void);
|
---|
317 | STDMETHOD_(ULONG, Release)(void);
|
---|
318 |
|
---|
319 | // IDropTarget methods
|
---|
320 | STDMETHOD(DragEnter)(LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect);
|
---|
321 | STDMETHOD(DragOver)(DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect);
|
---|
322 | STDMETHOD(DragLeave)();
|
---|
323 | STDMETHOD(Drop)(LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect);
|
---|
324 |
|
---|
325 | private:
|
---|
326 | ULONG m_refs;
|
---|
327 | QWidget* widget;
|
---|
328 | QPointer<QWidget> currentWidget;
|
---|
329 | QRect answerRect;
|
---|
330 | QPoint lastPoint;
|
---|
331 | DWORD chosenEffect;
|
---|
332 | DWORD lastKeyState;
|
---|
333 |
|
---|
334 | void sendDragEnterEvent(QWidget *to, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect);
|
---|
335 | };
|
---|
336 |
|
---|
337 | #endif
|
---|
338 |
|
---|
339 | #if defined (Q_WS_MAC)
|
---|
340 | class QCocoaDropData : public QInternalMimeData
|
---|
341 | {
|
---|
342 | Q_OBJECT
|
---|
343 | public:
|
---|
344 | QCocoaDropData(CFStringRef pasteboard);
|
---|
345 | ~QCocoaDropData();
|
---|
346 |
|
---|
347 | protected:
|
---|
348 | bool hasFormat_sys(const QString &mimeType) const;
|
---|
349 | QStringList formats_sys() const;
|
---|
350 | QVariant retrieveData_sys(const QString &mimeType, QVariant::Type type) const;
|
---|
351 | public:
|
---|
352 | CFStringRef dropPasteboard;
|
---|
353 | };
|
---|
354 | #endif
|
---|
355 |
|
---|
356 | #endif // !QT_NO_DRAGANDDROP
|
---|
357 |
|
---|
358 |
|
---|
359 | QT_END_NAMESPACE
|
---|
360 |
|
---|
361 | #endif // QDND_P_H
|
---|