source: trunk/src/gui/kernel/qdnd_p.h@ 441

Last change on this file since 441 was 438, checked in by Dmitry A. Kuminov, 15 years ago

gui: First DnD bits.

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