0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtGui module of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
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 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
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_WIN)
|
|
69 |
# include <qt_windows.h>
|
|
70 |
# include <objidl.h>
|
|
71 |
#endif
|
|
72 |
|
|
73 |
QT_BEGIN_NAMESPACE
|
|
74 |
|
|
75 |
class QEventLoop;
|
|
76 |
|
|
77 |
#if !(defined(QT_NO_DRAGANDDROP) && defined(QT_NO_CLIPBOARD))
|
|
78 |
|
|
79 |
class QInternalMimeData : public QMimeData
|
|
80 |
{
|
|
81 |
Q_OBJECT
|
|
82 |
public:
|
|
83 |
QInternalMimeData();
|
|
84 |
~QInternalMimeData();
|
|
85 |
|
|
86 |
bool hasFormat(const QString &mimeType) const;
|
|
87 |
QStringList formats() const;
|
|
88 |
static bool canReadData(const QString &mimeType);
|
|
89 |
|
|
90 |
|
|
91 |
static QStringList formatsHelper(const QMimeData *data);
|
|
92 |
static bool hasFormatHelper(const QString &mimeType, const QMimeData *data);
|
|
93 |
static QByteArray renderDataHelper(const QString &mimeType, const QMimeData *data);
|
|
94 |
|
|
95 |
protected:
|
|
96 |
QVariant retrieveData(const QString &mimeType, QVariant::Type type) const;
|
|
97 |
|
|
98 |
virtual bool hasFormat_sys(const QString &mimeType) const = 0;
|
|
99 |
virtual QStringList formats_sys() const = 0;
|
|
100 |
virtual QVariant retrieveData_sys(const QString &mimeType, QVariant::Type type) const = 0;
|
|
101 |
};
|
|
102 |
|
|
103 |
#ifdef Q_WS_WIN
|
|
104 |
class QOleDataObject : public IDataObject
|
|
105 |
{
|
|
106 |
public:
|
|
107 |
explicit QOleDataObject(QMimeData *mimeData);
|
|
108 |
virtual ~QOleDataObject();
|
|
109 |
|
|
110 |
void releaseQt();
|
|
111 |
const QMimeData *mimeData() const;
|
|
112 |
DWORD reportedPerformedEffect() const;
|
|
113 |
|
|
114 |
// IUnknown methods
|
|
115 |
STDMETHOD(QueryInterface)(REFIID riid, void FAR* FAR* ppvObj);
|
|
116 |
STDMETHOD_(ULONG,AddRef)(void);
|
|
117 |
STDMETHOD_(ULONG,Release)(void);
|
|
118 |
|
|
119 |
// IDataObject methods
|
|
120 |
STDMETHOD(GetData)(LPFORMATETC pformatetcIn, LPSTGMEDIUM pmedium);
|
|
121 |
STDMETHOD(GetDataHere)(LPFORMATETC pformatetc, LPSTGMEDIUM pmedium);
|
|
122 |
STDMETHOD(QueryGetData)(LPFORMATETC pformatetc);
|
|
123 |
STDMETHOD(GetCanonicalFormatEtc)(LPFORMATETC pformatetc, LPFORMATETC pformatetcOut);
|
|
124 |
STDMETHOD(SetData)(LPFORMATETC pformatetc, STGMEDIUM FAR * pmedium,
|
|
125 |
BOOL fRelease);
|
|
126 |
STDMETHOD(EnumFormatEtc)(DWORD dwDirection, LPENUMFORMATETC FAR* ppenumFormatEtc);
|
|
127 |
STDMETHOD(DAdvise)(FORMATETC FAR* pFormatetc, DWORD advf,
|
|
128 |
LPADVISESINK pAdvSink, DWORD FAR* pdwConnection);
|
|
129 |
STDMETHOD(DUnadvise)(DWORD dwConnection);
|
|
130 |
STDMETHOD(EnumDAdvise)(LPENUMSTATDATA FAR* ppenumAdvise);
|
|
131 |
|
|
132 |
private:
|
|
133 |
ULONG m_refs;
|
|
134 |
QPointer<QMimeData> data;
|
|
135 |
int CF_PERFORMEDDROPEFFECT;
|
|
136 |
DWORD performedEffect;
|
|
137 |
};
|
|
138 |
|
|
139 |
class QOleEnumFmtEtc : public IEnumFORMATETC
|
|
140 |
{
|
|
141 |
public:
|
|
142 |
explicit QOleEnumFmtEtc(const QVector<FORMATETC> &fmtetcs);
|
|
143 |
explicit QOleEnumFmtEtc(const QVector<LPFORMATETC> &lpfmtetcs);
|
|
144 |
virtual ~QOleEnumFmtEtc();
|
|
145 |
|
|
146 |
bool isNull() const;
|
|
147 |
|
|
148 |
// IUnknown methods
|
|
149 |
STDMETHOD(QueryInterface)(REFIID riid, void FAR* FAR* ppvObj);
|
|
150 |
STDMETHOD_(ULONG,AddRef)(void);
|
|
151 |
STDMETHOD_(ULONG,Release)(void);
|
|
152 |
|
|
153 |
// IEnumFORMATETC methods
|
|
154 |
STDMETHOD(Next)(ULONG celt, LPFORMATETC rgelt, ULONG FAR* pceltFetched);
|
|
155 |
STDMETHOD(Skip)(ULONG celt);
|
|
156 |
STDMETHOD(Reset)(void);
|
|
157 |
STDMETHOD(Clone)(LPENUMFORMATETC FAR* newEnum);
|
|
158 |
|
|
159 |
private:
|
|
160 |
bool copyFormatEtc(LPFORMATETC dest, LPFORMATETC src) const;
|
|
161 |
|
|
162 |
ULONG m_dwRefs;
|
|
163 |
ULONG m_nIndex;
|
|
164 |
QVector<LPFORMATETC> m_lpfmtetcs;
|
|
165 |
bool m_isNull;
|
|
166 |
};
|
|
167 |
|
|
168 |
#endif
|
|
169 |
|
|
170 |
#endif //QT_NO_DRAGANDDROP && QT_NO_CLIPBOARD
|
|
171 |
|
|
172 |
#ifndef QT_NO_DRAGANDDROP
|
|
173 |
|
|
174 |
class QDragPrivate : public QObjectPrivate
|
|
175 |
{
|
|
176 |
public:
|
|
177 |
QWidget *source;
|
|
178 |
QWidget *target;
|
|
179 |
QMimeData *data;
|
|
180 |
QPixmap pixmap;
|
|
181 |
QPoint hotspot;
|
|
182 |
Qt::DropActions possible_actions;
|
|
183 |
Qt::DropAction executed_action;
|
|
184 |
QMap<Qt::DropAction, QPixmap> customCursors;
|
|
185 |
Qt::DropAction defaultDropAction;
|
|
186 |
};
|
|
187 |
|
|
188 |
class QDropData : public QInternalMimeData
|
|
189 |
{
|
|
190 |
Q_OBJECT
|
|
191 |
public:
|
|
192 |
QDropData();
|
|
193 |
~QDropData();
|
|
194 |
|
|
195 |
protected:
|
|
196 |
bool hasFormat_sys(const QString &mimeType) const;
|
|
197 |
QStringList formats_sys() const;
|
|
198 |
QVariant retrieveData_sys(const QString &mimeType, QVariant::Type type) const;
|
|
199 |
|
|
200 |
#if defined(Q_WS_WIN)
|
|
201 |
public:
|
|
202 |
LPDATAOBJECT currentDataObject;
|
|
203 |
#endif
|
|
204 |
};
|
|
205 |
|
|
206 |
class QDragManager: public QObject {
|
|
207 |
Q_OBJECT
|
|
208 |
|
|
209 |
QDragManager();
|
|
210 |
~QDragManager();
|
|
211 |
// only friend classes can use QDragManager.
|
|
212 |
friend class QDrag;
|
|
213 |
friend class QDragMoveEvent;
|
|
214 |
friend class QDropEvent;
|
|
215 |
friend class QApplication;
|
|
216 |
#ifdef Q_WS_MAC
|
|
217 |
friend class QWidgetPrivate; //dnd is implemented here
|
|
218 |
#endif
|
|
219 |
|
|
220 |
bool eventFilter(QObject *, QEvent *);
|
|
221 |
void timerEvent(QTimerEvent*);
|
|
222 |
|
|
223 |
public:
|
|
224 |
Qt::DropAction drag(QDrag *);
|
|
225 |
|
|
226 |
void cancel(bool deleteSource = true);
|
|
227 |
void move(const QPoint &);
|
|
228 |
void drop();
|
|
229 |
void updatePixmap();
|
|
230 |
QWidget *source() const { return object ? object->d_func()->source : 0; }
|
|
231 |
QDragPrivate *dragPrivate() const { return object ? object->d_func() : 0; }
|
|
232 |
static QDragPrivate *dragPrivate(QDrag *drag) { return drag ? drag->d_func() : 0; }
|
|
233 |
|
|
234 |
static QDragManager *self();
|
|
235 |
Qt::DropAction defaultAction(Qt::DropActions possibleActions,
|
|
236 |
Qt::KeyboardModifiers modifiers) const;
|
|
237 |
|
|
238 |
QDrag *object;
|
|
239 |
|
|
240 |
void updateCursor();
|
|
241 |
|
|
242 |
bool beingCancelled;
|
|
243 |
bool restoreCursor;
|
|
244 |
bool willDrop;
|
|
245 |
QEventLoop *eventLoop;
|
|
246 |
|
|
247 |
QPixmap dragCursor(Qt::DropAction action) const;
|
|
248 |
|
|
249 |
bool hasCustomDragCursors() const;
|
|
250 |
|
|
251 |
QDropData *dropData;
|
|
252 |
|
|
253 |
void emitActionChanged(Qt::DropAction newAction) { if (object) emit object->actionChanged(newAction); }
|
|
254 |
|
|
255 |
void setCurrentTarget(QWidget *target, bool dropped = false);
|
|
256 |
QWidget *currentTarget();
|
|
257 |
|
|
258 |
#ifdef Q_WS_X11
|
|
259 |
QPixmap xdndMimeTransferedPixmap[2];
|
|
260 |
int xdndMimeTransferedPixmapIndex;
|
|
261 |
#endif
|
|
262 |
|
|
263 |
private:
|
|
264 |
QPixmap *pm_cursor;
|
|
265 |
int n_cursor;
|
|
266 |
#ifdef Q_WS_QWS
|
|
267 |
Qt::DropAction currentActionForOverrideCursor;
|
|
268 |
#endif
|
|
269 |
#ifdef Q_OS_SYMBIAN
|
|
270 |
#ifndef QT_NO_CURSOR
|
|
271 |
QCursor overrideCursor;
|
|
272 |
#endif
|
|
273 |
#endif
|
|
274 |
QWidget *currentDropTarget;
|
|
275 |
|
|
276 |
static QDragManager *instance;
|
|
277 |
Q_DISABLE_COPY(QDragManager)
|
|
278 |
};
|
|
279 |
|
|
280 |
|
|
281 |
#if defined(Q_WS_WIN)
|
|
282 |
|
|
283 |
class QOleDropTarget : public IDropTarget
|
|
284 |
{
|
|
285 |
public:
|
|
286 |
QOleDropTarget(QWidget* w);
|
|
287 |
virtual ~QOleDropTarget() {}
|
|
288 |
|
|
289 |
void releaseQt();
|
|
290 |
|
|
291 |
// IUnknown methods
|
|
292 |
STDMETHOD(QueryInterface)(REFIID riid, void FAR* FAR* ppvObj);
|
|
293 |
STDMETHOD_(ULONG, AddRef)(void);
|
|
294 |
STDMETHOD_(ULONG, Release)(void);
|
|
295 |
|
|
296 |
// IDropTarget methods
|
|
297 |
STDMETHOD(DragEnter)(LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect);
|
|
298 |
STDMETHOD(DragOver)(DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect);
|
|
299 |
STDMETHOD(DragLeave)();
|
|
300 |
STDMETHOD(Drop)(LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect);
|
|
301 |
|
|
302 |
private:
|
|
303 |
ULONG m_refs;
|
|
304 |
QWidget* widget;
|
|
305 |
QPointer<QWidget> currentWidget;
|
|
306 |
QRect answerRect;
|
|
307 |
QPoint lastPoint;
|
|
308 |
DWORD chosenEffect;
|
|
309 |
DWORD lastKeyState;
|
|
310 |
|
|
311 |
void sendDragEnterEvent(QWidget *to, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect);
|
|
312 |
};
|
|
313 |
|
|
314 |
#endif
|
|
315 |
|
|
316 |
#if defined (Q_WS_MAC)
|
|
317 |
class QCocoaDropData : public QInternalMimeData
|
|
318 |
{
|
|
319 |
Q_OBJECT
|
|
320 |
public:
|
|
321 |
QCocoaDropData(CFStringRef pasteboard);
|
|
322 |
~QCocoaDropData();
|
|
323 |
|
|
324 |
protected:
|
|
325 |
bool hasFormat_sys(const QString &mimeType) const;
|
|
326 |
QStringList formats_sys() const;
|
|
327 |
QVariant retrieveData_sys(const QString &mimeType, QVariant::Type type) const;
|
|
328 |
public:
|
|
329 |
CFStringRef dropPasteboard;
|
|
330 |
};
|
|
331 |
#endif
|
|
332 |
|
|
333 |
#endif // !QT_NO_DRAGANDDROP
|
|
334 |
|
|
335 |
|
|
336 |
QT_END_NAMESPACE
|
|
337 |
|
|
338 |
#endif // QDND_P_H
|