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