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

Last change on this file since 345 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 9.3 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
187class QDropData : public QInternalMimeData
188{
189 Q_OBJECT
190public:
191 QDropData();
192 ~QDropData();
193
194protected:
195 bool hasFormat_sys(const QString &mimeType) const;
196 QStringList formats_sys() const;
197 QVariant retrieveData_sys(const QString &mimeType, QVariant::Type type) const;
198
199#if defined(Q_WS_WIN)
200public:
201 LPDATAOBJECT currentDataObject;
202#endif
203};
204
205class Q_GUI_EXPORT QDragManager: public QObject {
206 Q_OBJECT
207
208 QDragManager();
209 ~QDragManager();
210 // only friend classes can use QDragManager.
211 friend class QDrag;
212 friend class QDragMoveEvent;
213 friend class QDropEvent;
214 friend class QApplication;
215#ifdef Q_WS_MAC
216 friend class QWidgetPrivate; //dnd is implemented here
217#endif
218
219 bool eventFilter(QObject *, QEvent *);
220 void timerEvent(QTimerEvent*);
221
222public:
223 Qt::DropAction drag(QDrag *);
224
225 void cancel(bool deleteSource = true);
226 void move(const QPoint &);
227 void drop();
228 void updatePixmap();
229 QWidget *source() const { return object ? object->d_func()->source : 0; }
230 QDragPrivate *dragPrivate() const { return object ? object->d_func() : 0; }
231 static QDragPrivate *dragPrivate(QDrag *drag) { return drag ? drag->d_func() : 0; }
232
233 static QDragManager *self();
234 Qt::DropAction defaultAction(Qt::DropActions possibleActions,
235 Qt::KeyboardModifiers modifiers) const;
236
237 QDrag *object;
238
239 void updateCursor();
240
241 bool beingCancelled;
242 bool restoreCursor;
243 bool willDrop;
244 QEventLoop *eventLoop;
245
246 QPixmap dragCursor(Qt::DropAction action) const;
247
248 bool hasCustomDragCursors() const;
249
250 QDropData *dropData;
251
252 void emitActionChanged(Qt::DropAction newAction) { if (object) emit object->actionChanged(newAction); }
253
254 void setCurrentTarget(QWidget *target, bool dropped = false);
255 QWidget *currentTarget();
256
257#ifdef Q_WS_X11
258 QPixmap xdndMimeTransferedPixmap[2];
259 int xdndMimeTransferedPixmapIndex;
260#endif
261
262private:
263 QPixmap *pm_cursor;
264 int n_cursor;
265#ifdef Q_WS_QWS
266 Qt::DropAction currentActionForOverrideCursor;
267#endif
268
269 QWidget *currentDropTarget;
270
271 static QDragManager *instance;
272 Q_DISABLE_COPY(QDragManager)
273};
274
275
276#if defined(Q_WS_WIN)
277
278class QOleDropTarget : public IDropTarget
279{
280public:
281 QOleDropTarget(QWidget* w);
282 virtual ~QOleDropTarget() {}
283
284 void releaseQt();
285
286 // IUnknown methods
287 STDMETHOD(QueryInterface)(REFIID riid, void FAR* FAR* ppvObj);
288 STDMETHOD_(ULONG, AddRef)(void);
289 STDMETHOD_(ULONG, Release)(void);
290
291 // IDropTarget methods
292 STDMETHOD(DragEnter)(LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect);
293 STDMETHOD(DragOver)(DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect);
294 STDMETHOD(DragLeave)();
295 STDMETHOD(Drop)(LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect);
296
297private:
298 ULONG m_refs;
299 QWidget* widget;
300 QPointer<QWidget> currentWidget;
301 QRect answerRect;
302 QPoint lastPoint;
303 DWORD chosenEffect;
304 DWORD lastKeyState;
305
306 void sendDragEnterEvent(QWidget *to, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect);
307};
308
309#endif
310
311#if defined (Q_WS_MAC)
312class QCocoaDropData : public QInternalMimeData
313{
314 Q_OBJECT
315public:
316 QCocoaDropData(CFStringRef pasteboard);
317 ~QCocoaDropData();
318
319protected:
320 bool hasFormat_sys(const QString &mimeType) const;
321 QStringList formats_sys() const;
322 QVariant retrieveData_sys(const QString &mimeType, QVariant::Type type) const;
323public:
324 CFStringRef dropPasteboard;
325};
326#endif
327
328#endif // !QT_NO_DRAGANDDROP
329
330
331QT_END_NAMESPACE
332
333#endif // QDND_P_H
Note: See TracBrowser for help on using the repository browser.