| 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 | #include "qapplication.h"
|
|---|
| 43 |
|
|---|
| 44 | #include "qapplication_p.h"
|
|---|
| 45 | #include "qevent.h"
|
|---|
| 46 | #include "qpainter.h"
|
|---|
| 47 | #include "qwidget.h"
|
|---|
| 48 | #include "qbuffer.h"
|
|---|
| 49 | #include "qdatastream.h"
|
|---|
| 50 | #include "qcursor.h"
|
|---|
| 51 | #include "qt_windows.h"
|
|---|
| 52 | #include <shlobj.h>
|
|---|
| 53 | #ifndef QT_NO_ACCESSIBILITY
|
|---|
| 54 | #include "qaccessible.h"
|
|---|
| 55 | #endif
|
|---|
| 56 | #include "qdnd_p.h"
|
|---|
| 57 | #include "qdebug.h"
|
|---|
| 58 |
|
|---|
| 59 | #if defined(Q_OS_WINCE)
|
|---|
| 60 | #include "qguifunctions_wince.h"
|
|---|
| 61 | #endif
|
|---|
| 62 |
|
|---|
| 63 | // support for xbuttons
|
|---|
| 64 | #ifndef MK_XBUTTON1
|
|---|
| 65 | #define MK_XBUTTON1 0x0020
|
|---|
| 66 | #define MK_XBUTTON2 0x0040
|
|---|
| 67 | #endif
|
|---|
| 68 |
|
|---|
| 69 | QT_BEGIN_NAMESPACE
|
|---|
| 70 |
|
|---|
| 71 | #if !(defined(QT_NO_DRAGANDDROP) && defined(QT_NO_CLIPBOARD))
|
|---|
| 72 |
|
|---|
| 73 | //---------------------------------------------------------------------
|
|---|
| 74 | // QOleDataObject Constructor
|
|---|
| 75 | //---------------------------------------------------------------------
|
|---|
| 76 |
|
|---|
| 77 | QOleDataObject::QOleDataObject(QMimeData *mimeData)
|
|---|
| 78 | {
|
|---|
| 79 | m_refs = 1;
|
|---|
| 80 | data = mimeData;
|
|---|
| 81 | CF_PERFORMEDDROPEFFECT = RegisterClipboardFormat(CFSTR_PERFORMEDDROPEFFECT);
|
|---|
| 82 | performedEffect = DROPEFFECT_NONE;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | QOleDataObject::~QOleDataObject()
|
|---|
| 86 | {
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | void QOleDataObject::releaseQt()
|
|---|
| 90 | {
|
|---|
| 91 | data = 0;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | const QMimeData *QOleDataObject::mimeData() const
|
|---|
| 95 | {
|
|---|
| 96 | return data;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | DWORD QOleDataObject::reportedPerformedEffect() const
|
|---|
| 100 | {
|
|---|
| 101 | return performedEffect;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | //---------------------------------------------------------------------
|
|---|
| 105 | // IUnknown Methods
|
|---|
| 106 | //---------------------------------------------------------------------
|
|---|
| 107 |
|
|---|
| 108 | STDMETHODIMP
|
|---|
| 109 | QOleDataObject::QueryInterface(REFIID iid, void FAR* FAR* ppv)
|
|---|
| 110 | {
|
|---|
| 111 | if (iid == IID_IUnknown || iid == IID_IDataObject) {
|
|---|
| 112 | *ppv = this;
|
|---|
| 113 | AddRef();
|
|---|
| 114 | return NOERROR;
|
|---|
| 115 | }
|
|---|
| 116 | *ppv = NULL;
|
|---|
| 117 | return ResultFromScode(E_NOINTERFACE);
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | STDMETHODIMP_(ULONG)
|
|---|
| 121 | QOleDataObject::AddRef(void)
|
|---|
| 122 | {
|
|---|
| 123 | return ++m_refs;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | STDMETHODIMP_(ULONG)
|
|---|
| 127 | QOleDataObject::Release(void)
|
|---|
| 128 | {
|
|---|
| 129 | if (--m_refs == 0) {
|
|---|
| 130 | releaseQt();
|
|---|
| 131 | delete this;
|
|---|
| 132 | return 0;
|
|---|
| 133 | }
|
|---|
| 134 | return m_refs;
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | //---------------------------------------------------------------------
|
|---|
| 138 | // IDataObject Methods
|
|---|
| 139 | //
|
|---|
| 140 | // The following methods are NOT supported for data transfer using the
|
|---|
| 141 | // clipboard or drag-drop:
|
|---|
| 142 | //
|
|---|
| 143 | // IDataObject::SetData -- return E_NOTIMPL
|
|---|
| 144 | // IDataObject::DAdvise -- return OLE_E_ADVISENOTSUPPORTED
|
|---|
| 145 | // ::DUnadvise
|
|---|
| 146 | // ::EnumDAdvise
|
|---|
| 147 | // IDataObject::GetCanonicalFormatEtc -- return E_NOTIMPL
|
|---|
| 148 | // (NOTE: must set pformatetcOut->ptd = NULL)
|
|---|
| 149 | //---------------------------------------------------------------------
|
|---|
| 150 |
|
|---|
| 151 | STDMETHODIMP
|
|---|
| 152 | QOleDataObject::GetData(LPFORMATETC pformatetc, LPSTGMEDIUM pmedium)
|
|---|
| 153 | {
|
|---|
| 154 | #ifdef QDND_DEBUG
|
|---|
| 155 | qDebug("QOleDataObject::GetData(LPFORMATETC pformatetc, LPSTGMEDIUM pmedium)");
|
|---|
| 156 | #ifndef Q_OS_WINCE
|
|---|
| 157 | wchar_t buf[256] = {0};
|
|---|
| 158 | GetClipboardFormatName(pformatetc->cfFormat, buf, 255);
|
|---|
| 159 | qDebug("CF = %d : %s", pformatetc->cfFormat, QString::fromWCharArray(buf));
|
|---|
| 160 | #endif
|
|---|
| 161 | #endif
|
|---|
| 162 |
|
|---|
| 163 | if (!data)
|
|---|
| 164 | return ResultFromScode(DATA_E_FORMATETC);
|
|---|
| 165 |
|
|---|
| 166 | QWindowsMime *converter = QWindowsMime::converterFromMime(*pformatetc, data);
|
|---|
| 167 |
|
|---|
| 168 | if (converter && converter->convertFromMime(*pformatetc, data, pmedium))
|
|---|
| 169 | return ResultFromScode(S_OK);
|
|---|
| 170 | else
|
|---|
| 171 | return ResultFromScode(DATA_E_FORMATETC);
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | STDMETHODIMP
|
|---|
| 175 | QOleDataObject::GetDataHere(LPFORMATETC, LPSTGMEDIUM)
|
|---|
| 176 | {
|
|---|
| 177 | return ResultFromScode(DATA_E_FORMATETC);
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | STDMETHODIMP
|
|---|
| 181 | QOleDataObject::QueryGetData(LPFORMATETC pformatetc)
|
|---|
| 182 | {
|
|---|
| 183 | #ifdef QDND_DEBUG
|
|---|
| 184 | qDebug("QOleDataObject::QueryGetData(LPFORMATETC pformatetc)");
|
|---|
| 185 | #endif
|
|---|
| 186 |
|
|---|
| 187 | if (!data)
|
|---|
| 188 | return ResultFromScode(DATA_E_FORMATETC);
|
|---|
| 189 |
|
|---|
| 190 | if (QWindowsMime::converterFromMime(*pformatetc, data))
|
|---|
| 191 | return ResultFromScode(S_OK);
|
|---|
| 192 | return ResultFromScode(S_FALSE);
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | STDMETHODIMP
|
|---|
| 196 | QOleDataObject::GetCanonicalFormatEtc(LPFORMATETC, LPFORMATETC pformatetcOut)
|
|---|
| 197 | {
|
|---|
| 198 | pformatetcOut->ptd = NULL;
|
|---|
| 199 | return ResultFromScode(E_NOTIMPL);
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | STDMETHODIMP
|
|---|
| 203 | QOleDataObject::SetData(LPFORMATETC pFormatetc, STGMEDIUM *pMedium, BOOL fRelease)
|
|---|
| 204 | {
|
|---|
| 205 | if (pFormatetc->cfFormat == CF_PERFORMEDDROPEFFECT && pMedium->tymed == TYMED_HGLOBAL) {
|
|---|
| 206 | DWORD * val = (DWORD*)GlobalLock(pMedium->hGlobal);
|
|---|
| 207 | performedEffect = *val;
|
|---|
| 208 | GlobalUnlock(pMedium->hGlobal);
|
|---|
| 209 | if (fRelease)
|
|---|
| 210 | ReleaseStgMedium(pMedium);
|
|---|
| 211 | return ResultFromScode(S_OK);
|
|---|
| 212 | }
|
|---|
| 213 | return ResultFromScode(E_NOTIMPL);
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 | STDMETHODIMP
|
|---|
| 218 | QOleDataObject::EnumFormatEtc(DWORD dwDirection, LPENUMFORMATETC FAR* ppenumFormatEtc)
|
|---|
| 219 | {
|
|---|
| 220 | #ifdef QDND_DEBUG
|
|---|
| 221 | qDebug("QOleDataObject::EnumFormatEtc(DWORD dwDirection, LPENUMFORMATETC FAR* ppenumFormatEtc)");
|
|---|
| 222 | #endif
|
|---|
| 223 |
|
|---|
| 224 | if (!data)
|
|---|
| 225 | return ResultFromScode(DATA_E_FORMATETC);
|
|---|
| 226 |
|
|---|
| 227 | SCODE sc = S_OK;
|
|---|
| 228 |
|
|---|
| 229 | QVector<FORMATETC> fmtetcs;
|
|---|
| 230 | if (dwDirection == DATADIR_GET) {
|
|---|
| 231 | fmtetcs = QWindowsMime::allFormatsForMime(data);
|
|---|
| 232 | } else {
|
|---|
| 233 | FORMATETC formatetc;
|
|---|
| 234 | formatetc.cfFormat = CF_PERFORMEDDROPEFFECT;
|
|---|
| 235 | formatetc.dwAspect = DVASPECT_CONTENT;
|
|---|
| 236 | formatetc.lindex = -1;
|
|---|
| 237 | formatetc.ptd = NULL;
|
|---|
| 238 | formatetc.tymed = TYMED_HGLOBAL;
|
|---|
| 239 | fmtetcs.append(formatetc);
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | QOleEnumFmtEtc *enumFmtEtc = new QOleEnumFmtEtc(fmtetcs);
|
|---|
| 243 | *ppenumFormatEtc = enumFmtEtc;
|
|---|
| 244 | if (enumFmtEtc->isNull()) {
|
|---|
| 245 | delete enumFmtEtc;
|
|---|
| 246 | *ppenumFormatEtc = NULL;
|
|---|
| 247 | sc = E_OUTOFMEMORY;
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | return ResultFromScode(sc);
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | STDMETHODIMP
|
|---|
| 254 | QOleDataObject::DAdvise(FORMATETC FAR*, DWORD,
|
|---|
| 255 | LPADVISESINK, DWORD FAR*)
|
|---|
| 256 | {
|
|---|
| 257 | return ResultFromScode(OLE_E_ADVISENOTSUPPORTED);
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 | STDMETHODIMP
|
|---|
| 262 | QOleDataObject::DUnadvise(DWORD)
|
|---|
| 263 | {
|
|---|
| 264 | return ResultFromScode(OLE_E_ADVISENOTSUPPORTED);
|
|---|
| 265 | }
|
|---|
| 266 |
|
|---|
| 267 | STDMETHODIMP
|
|---|
| 268 | QOleDataObject::EnumDAdvise(LPENUMSTATDATA FAR*)
|
|---|
| 269 | {
|
|---|
| 270 | return ResultFromScode(OLE_E_ADVISENOTSUPPORTED);
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 | #endif // QT_NO_DRAGANDDROP && QT_NO_CLIPBOARD
|
|---|
| 274 |
|
|---|
| 275 | #ifndef QT_NO_DRAGANDDROP
|
|---|
| 276 |
|
|---|
| 277 | //#define QDND_DEBUG
|
|---|
| 278 |
|
|---|
| 279 | #ifdef QDND_DEBUG
|
|---|
| 280 | extern QString dragActionsToString(Qt::DropActions actions);
|
|---|
| 281 | #endif
|
|---|
| 282 |
|
|---|
| 283 | Qt::DropActions translateToQDragDropActions(DWORD pdwEffects)
|
|---|
| 284 | {
|
|---|
| 285 | Qt::DropActions actions = Qt::IgnoreAction;
|
|---|
| 286 | if (pdwEffects & DROPEFFECT_LINK)
|
|---|
| 287 | actions |= Qt::LinkAction;
|
|---|
| 288 | if (pdwEffects & DROPEFFECT_COPY)
|
|---|
| 289 | actions |= Qt::CopyAction;
|
|---|
| 290 | if (pdwEffects & DROPEFFECT_MOVE)
|
|---|
| 291 | actions |= Qt::MoveAction;
|
|---|
| 292 | return actions;
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | Qt::DropAction translateToQDragDropAction(DWORD pdwEffect)
|
|---|
| 296 | {
|
|---|
| 297 | if (pdwEffect & DROPEFFECT_LINK)
|
|---|
| 298 | return Qt::LinkAction;
|
|---|
| 299 | if (pdwEffect & DROPEFFECT_COPY)
|
|---|
| 300 | return Qt::CopyAction;
|
|---|
| 301 | if (pdwEffect & DROPEFFECT_MOVE)
|
|---|
| 302 | return Qt::MoveAction;
|
|---|
| 303 | return Qt::IgnoreAction;
|
|---|
| 304 | }
|
|---|
| 305 |
|
|---|
| 306 | DWORD translateToWinDragEffects(Qt::DropActions action)
|
|---|
| 307 | {
|
|---|
| 308 | DWORD effect = DROPEFFECT_NONE;
|
|---|
| 309 | if (action & Qt::LinkAction)
|
|---|
| 310 | effect |= DROPEFFECT_LINK;
|
|---|
| 311 | if (action & Qt::CopyAction)
|
|---|
| 312 | effect |= DROPEFFECT_COPY;
|
|---|
| 313 | if (action & Qt::MoveAction)
|
|---|
| 314 | effect |= DROPEFFECT_MOVE;
|
|---|
| 315 | return effect;
|
|---|
| 316 | }
|
|---|
| 317 |
|
|---|
| 318 | Qt::KeyboardModifiers toQtKeyboardModifiers(DWORD keyState)
|
|---|
| 319 | {
|
|---|
| 320 | Qt::KeyboardModifiers modifiers = Qt::NoModifier;
|
|---|
| 321 |
|
|---|
| 322 | if (keyState & MK_SHIFT)
|
|---|
| 323 | modifiers |= Qt::ShiftModifier;
|
|---|
| 324 | if (keyState & MK_CONTROL)
|
|---|
| 325 | modifiers |= Qt::ControlModifier;
|
|---|
| 326 | if (keyState & MK_ALT)
|
|---|
| 327 | modifiers |= Qt::AltModifier;
|
|---|
| 328 |
|
|---|
| 329 | return modifiers;
|
|---|
| 330 | }
|
|---|
| 331 |
|
|---|
| 332 | Qt::MouseButtons toQtMouseButtons(DWORD keyState)
|
|---|
| 333 | {
|
|---|
| 334 | Qt::MouseButtons buttons = Qt::NoButton;
|
|---|
| 335 |
|
|---|
| 336 | if (keyState & MK_LBUTTON)
|
|---|
| 337 | buttons |= Qt::LeftButton;
|
|---|
| 338 | if (keyState & MK_RBUTTON)
|
|---|
| 339 | buttons |= Qt::RightButton;
|
|---|
| 340 | if (keyState & MK_MBUTTON)
|
|---|
| 341 | buttons |= Qt::MidButton;
|
|---|
| 342 |
|
|---|
| 343 | return buttons;
|
|---|
| 344 | }
|
|---|
| 345 |
|
|---|
| 346 | class QOleDropSource : public IDropSource
|
|---|
| 347 | {
|
|---|
| 348 | public:
|
|---|
| 349 | QOleDropSource();
|
|---|
| 350 | virtual ~QOleDropSource();
|
|---|
| 351 |
|
|---|
| 352 | void createCursors();
|
|---|
| 353 |
|
|---|
| 354 | // IUnknown methods
|
|---|
| 355 | STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObj);
|
|---|
| 356 | STDMETHOD_(ULONG,AddRef)(void);
|
|---|
| 357 | STDMETHOD_(ULONG,Release)(void);
|
|---|
| 358 |
|
|---|
| 359 | // IDropSource methods
|
|---|
| 360 | STDMETHOD(QueryContinueDrag)(BOOL fEscapePressed, DWORD grfKeyState);
|
|---|
| 361 | STDMETHOD(GiveFeedback)(DWORD dwEffect);
|
|---|
| 362 |
|
|---|
| 363 | private:
|
|---|
| 364 | Qt::MouseButtons currentButtons;
|
|---|
| 365 | Qt::DropAction currentAction;
|
|---|
| 366 | QMap <Qt::DropAction, QCursor> cursors;
|
|---|
| 367 |
|
|---|
| 368 | ULONG m_refs;
|
|---|
| 369 | };
|
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 | QOleDropSource::QOleDropSource()
|
|---|
| 373 | {
|
|---|
| 374 | currentButtons = Qt::NoButton;
|
|---|
| 375 | m_refs = 1;
|
|---|
| 376 | currentAction = Qt::IgnoreAction;
|
|---|
| 377 | }
|
|---|
| 378 |
|
|---|
| 379 | QOleDropSource::~QOleDropSource()
|
|---|
| 380 | {
|
|---|
| 381 | }
|
|---|
| 382 |
|
|---|
| 383 | void QOleDropSource::createCursors()
|
|---|
| 384 | {
|
|---|
| 385 | QDragManager *manager = QDragManager::self();
|
|---|
| 386 | if (manager && manager->object
|
|---|
| 387 | && (!manager->object->pixmap().isNull()
|
|---|
| 388 | || manager->hasCustomDragCursors())) {
|
|---|
| 389 | QPixmap pm = manager->object->pixmap();
|
|---|
| 390 | QList<Qt::DropAction> actions;
|
|---|
| 391 | actions << Qt::MoveAction << Qt::CopyAction << Qt::LinkAction;
|
|---|
| 392 | if (!manager->object->pixmap().isNull())
|
|---|
| 393 | actions << Qt::IgnoreAction;
|
|---|
| 394 | QPoint hotSpot = manager->object->hotSpot();
|
|---|
| 395 | for (int cnum = 0; cnum < actions.size(); ++cnum) {
|
|---|
| 396 | QPixmap cpm = manager->dragCursor(actions.at(cnum));
|
|---|
| 397 | int w = cpm.width();
|
|---|
| 398 | int h = cpm.height();
|
|---|
| 399 |
|
|---|
| 400 | if (!pm.isNull()) {
|
|---|
| 401 | int x1 = qMin(-hotSpot.x(), 0);
|
|---|
| 402 | int x2 = qMax(pm.width() - hotSpot.x(), cpm.width());
|
|---|
| 403 | int y1 = qMin(-hotSpot.y(), 0);
|
|---|
| 404 | int y2 = qMax(pm.height() - hotSpot.y(), cpm.height());
|
|---|
| 405 |
|
|---|
| 406 | w = x2 - x1 + 1;
|
|---|
| 407 | h = y2 - y1 + 1;
|
|---|
| 408 | }
|
|---|
| 409 |
|
|---|
| 410 | QRect srcRect = pm.rect();
|
|---|
| 411 | QPoint pmDest = QPoint(qMax(0, -hotSpot.x()), qMax(0, -hotSpot.y()));
|
|---|
| 412 | QPoint newHotSpot = hotSpot;
|
|---|
| 413 |
|
|---|
| 414 | #if defined(Q_OS_WINCE)
|
|---|
| 415 | // Limited cursor size
|
|---|
| 416 | int reqw = GetSystemMetrics(SM_CXCURSOR);
|
|---|
| 417 | int reqh = GetSystemMetrics(SM_CYCURSOR);
|
|---|
| 418 |
|
|---|
| 419 | QPoint hotspotInPM = newHotSpot - pmDest;
|
|---|
| 420 | if (reqw < w) {
|
|---|
| 421 | // Not wide enough - move objectpm right
|
|---|
| 422 | qreal r = qreal(newHotSpot.x()) / w;
|
|---|
| 423 | newHotSpot = QPoint(int(r * reqw), newHotSpot.y());
|
|---|
| 424 | if (newHotSpot.x() + cpm.width() > reqw)
|
|---|
| 425 | newHotSpot.setX(reqw - cpm.width());
|
|---|
| 426 |
|
|---|
| 427 | srcRect = QRect(QPoint(hotspotInPM.x() - newHotSpot.x(), srcRect.top()), QSize(reqw, srcRect.height()));
|
|---|
| 428 | }
|
|---|
| 429 | if (reqh < h) {
|
|---|
| 430 | qreal r = qreal(newHotSpot.y()) / h;
|
|---|
| 431 | newHotSpot = QPoint(newHotSpot.x(), int(r * reqh));
|
|---|
| 432 | if (newHotSpot.y() + cpm.height() > reqh)
|
|---|
| 433 | newHotSpot.setY(reqh - cpm.height());
|
|---|
| 434 |
|
|---|
| 435 | srcRect = QRect(QPoint(srcRect.left(), hotspotInPM.y() - newHotSpot.y()), QSize(srcRect.width(), reqh));
|
|---|
| 436 | }
|
|---|
| 437 | // Always use system cursor size
|
|---|
| 438 | w = reqw;
|
|---|
| 439 | h = reqh;
|
|---|
| 440 | #endif
|
|---|
| 441 |
|
|---|
| 442 | QPixmap newCursor(w, h);
|
|---|
| 443 | if (!pm.isNull()) {
|
|---|
| 444 | newCursor.fill(QColor(0, 0, 0, 0));
|
|---|
| 445 | QPainter p(&newCursor);
|
|---|
| 446 | p.drawPixmap(pmDest, pm, srcRect);
|
|---|
| 447 | p.drawPixmap(qMax(0,newHotSpot.x()),qMax(0,newHotSpot.y()),cpm);
|
|---|
| 448 | } else {
|
|---|
| 449 | newCursor = cpm;
|
|---|
| 450 | }
|
|---|
| 451 |
|
|---|
| 452 | #ifndef QT_NO_CURSOR
|
|---|
| 453 | cursors[actions.at(cnum)] = QCursor(newCursor, pm.isNull() ? 0 : qMax(0,newHotSpot.x()),
|
|---|
| 454 | pm.isNull() ? 0 : qMax(0,newHotSpot.y()));
|
|---|
| 455 | #endif
|
|---|
| 456 | }
|
|---|
| 457 | }
|
|---|
| 458 | }
|
|---|
| 459 |
|
|---|
| 460 |
|
|---|
| 461 |
|
|---|
| 462 | //---------------------------------------------------------------------
|
|---|
| 463 | // IUnknown Methods
|
|---|
| 464 | //---------------------------------------------------------------------
|
|---|
| 465 |
|
|---|
| 466 |
|
|---|
| 467 | STDMETHODIMP
|
|---|
| 468 | QOleDropSource::QueryInterface(REFIID iid, void FAR* FAR* ppv)
|
|---|
| 469 | {
|
|---|
| 470 | if(iid == IID_IUnknown || iid == IID_IDropSource)
|
|---|
| 471 | {
|
|---|
| 472 | *ppv = this;
|
|---|
| 473 | ++m_refs;
|
|---|
| 474 | return NOERROR;
|
|---|
| 475 | }
|
|---|
| 476 | *ppv = NULL;
|
|---|
| 477 | return ResultFromScode(E_NOINTERFACE);
|
|---|
| 478 | }
|
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 | STDMETHODIMP_(ULONG)
|
|---|
| 482 | QOleDropSource::AddRef(void)
|
|---|
| 483 | {
|
|---|
| 484 | return ++m_refs;
|
|---|
| 485 | }
|
|---|
| 486 |
|
|---|
| 487 |
|
|---|
| 488 | STDMETHODIMP_(ULONG)
|
|---|
| 489 | QOleDropSource::Release(void)
|
|---|
| 490 | {
|
|---|
| 491 | if(--m_refs == 0)
|
|---|
| 492 | {
|
|---|
| 493 | delete this;
|
|---|
| 494 | return 0;
|
|---|
| 495 | }
|
|---|
| 496 | return m_refs;
|
|---|
| 497 | }
|
|---|
| 498 |
|
|---|
| 499 | static inline Qt::MouseButtons keystate_to_mousebutton(DWORD grfKeyState)
|
|---|
| 500 | {
|
|---|
| 501 | Qt::MouseButtons result;
|
|---|
| 502 | if (grfKeyState & MK_LBUTTON)
|
|---|
| 503 | result |= Qt::LeftButton;
|
|---|
| 504 | if (grfKeyState & MK_MBUTTON)
|
|---|
| 505 | result |= Qt::MidButton;
|
|---|
| 506 | if (grfKeyState & MK_RBUTTON)
|
|---|
| 507 | result |= Qt::RightButton;
|
|---|
| 508 | if (grfKeyState & MK_XBUTTON1)
|
|---|
| 509 | result |= Qt::XButton1;
|
|---|
| 510 | if (grfKeyState & MK_XBUTTON2)
|
|---|
| 511 | result |= Qt::XButton2;
|
|---|
| 512 | return result;
|
|---|
| 513 | }
|
|---|
| 514 |
|
|---|
| 515 | //---------------------------------------------------------------------
|
|---|
| 516 | // IDropSource Methods
|
|---|
| 517 | //---------------------------------------------------------------------
|
|---|
| 518 | QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP
|
|---|
| 519 | QOleDropSource::QueryContinueDrag(BOOL fEscapePressed, DWORD grfKeyState)
|
|---|
| 520 | {
|
|---|
| 521 | #ifdef QDND_DEBUG
|
|---|
| 522 | qDebug("QOleDropSource::QueryContinueDrag(fEscapePressed %d, grfKeyState %d)", fEscapePressed, grfKeyState);
|
|---|
| 523 | #endif
|
|---|
| 524 |
|
|---|
| 525 | if (fEscapePressed) {
|
|---|
| 526 | return ResultFromScode(DRAGDROP_S_CANCEL);
|
|---|
| 527 | } else if ((GetAsyncKeyState(VK_LBUTTON) == 0)
|
|---|
| 528 | && (GetAsyncKeyState(VK_MBUTTON) == 0)
|
|---|
| 529 | && (GetAsyncKeyState(VK_RBUTTON) == 0)) {
|
|---|
| 530 | // grfKeyState is broken on CE & some Windows XP versions,
|
|---|
| 531 | // therefore we need to check the state manually
|
|---|
| 532 | return ResultFromScode(DRAGDROP_S_DROP);
|
|---|
| 533 | } else {
|
|---|
| 534 | #if !defined(Q_OS_WINCE)
|
|---|
| 535 | if (currentButtons == Qt::NoButton) {
|
|---|
| 536 | currentButtons = keystate_to_mousebutton(grfKeyState);
|
|---|
| 537 | } else {
|
|---|
| 538 | Qt::MouseButtons buttons = keystate_to_mousebutton(grfKeyState);
|
|---|
| 539 | if (!(currentButtons & buttons))
|
|---|
| 540 | return ResultFromScode(DRAGDROP_S_DROP);
|
|---|
| 541 | }
|
|---|
| 542 | #endif
|
|---|
| 543 | QApplication::processEvents();
|
|---|
| 544 | return NOERROR;
|
|---|
| 545 | }
|
|---|
| 546 | }
|
|---|
| 547 |
|
|---|
| 548 | QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP
|
|---|
| 549 | QOleDropSource::GiveFeedback(DWORD dwEffect)
|
|---|
| 550 | {
|
|---|
| 551 | Qt::DropAction action = translateToQDragDropAction(dwEffect);
|
|---|
| 552 |
|
|---|
| 553 | #ifdef QDND_DEBUG
|
|---|
| 554 | qDebug("QOleDropSource::GiveFeedback(DWORD dwEffect)");
|
|---|
| 555 | qDebug("dwEffect = %s", dragActionsToString(action).toLatin1().data());
|
|---|
| 556 | #endif
|
|---|
| 557 |
|
|---|
| 558 | if (currentAction != action) {
|
|---|
| 559 | currentAction = action;
|
|---|
| 560 | QDragManager::self()->emitActionChanged(currentAction);
|
|---|
| 561 | }
|
|---|
| 562 |
|
|---|
| 563 | if (cursors.contains(currentAction)) {
|
|---|
| 564 | #ifndef QT_NO_CURSOR
|
|---|
| 565 | SetCursor(cursors[currentAction].handle());
|
|---|
| 566 | #endif
|
|---|
| 567 | return ResultFromScode(S_OK);
|
|---|
| 568 | }
|
|---|
| 569 |
|
|---|
| 570 | return ResultFromScode(DRAGDROP_S_USEDEFAULTCURSORS);
|
|---|
| 571 | }
|
|---|
| 572 |
|
|---|
| 573 | //---------------------------------------------------------------------
|
|---|
| 574 | // QOleDropTarget
|
|---|
| 575 | //---------------------------------------------------------------------
|
|---|
| 576 |
|
|---|
| 577 | QOleDropTarget::QOleDropTarget(QWidget* w)
|
|---|
| 578 | : widget(w)
|
|---|
| 579 | {
|
|---|
| 580 | m_refs = 1;
|
|---|
| 581 | }
|
|---|
| 582 |
|
|---|
| 583 | void QOleDropTarget::releaseQt()
|
|---|
| 584 | {
|
|---|
| 585 | widget = 0;
|
|---|
| 586 | }
|
|---|
| 587 |
|
|---|
| 588 | //---------------------------------------------------------------------
|
|---|
| 589 | // IUnknown Methods
|
|---|
| 590 | //---------------------------------------------------------------------
|
|---|
| 591 |
|
|---|
| 592 |
|
|---|
| 593 | STDMETHODIMP
|
|---|
| 594 | QOleDropTarget::QueryInterface(REFIID iid, void FAR* FAR* ppv)
|
|---|
| 595 | {
|
|---|
| 596 | if(iid == IID_IUnknown || iid == IID_IDropTarget)
|
|---|
| 597 | {
|
|---|
| 598 | *ppv = this;
|
|---|
| 599 | AddRef();
|
|---|
| 600 | return NOERROR;
|
|---|
| 601 | }
|
|---|
| 602 | *ppv = NULL;
|
|---|
| 603 | return ResultFromScode(E_NOINTERFACE);
|
|---|
| 604 | }
|
|---|
| 605 |
|
|---|
| 606 |
|
|---|
| 607 | STDMETHODIMP_(ULONG)
|
|---|
| 608 | QOleDropTarget::AddRef(void)
|
|---|
| 609 | {
|
|---|
| 610 | return ++m_refs;
|
|---|
| 611 | }
|
|---|
| 612 |
|
|---|
| 613 |
|
|---|
| 614 | STDMETHODIMP_(ULONG)
|
|---|
| 615 | QOleDropTarget::Release(void)
|
|---|
| 616 | {
|
|---|
| 617 | if(--m_refs == 0)
|
|---|
| 618 | {
|
|---|
| 619 | delete this;
|
|---|
| 620 | return 0;
|
|---|
| 621 | }
|
|---|
| 622 | return m_refs;
|
|---|
| 623 | }
|
|---|
| 624 |
|
|---|
| 625 | //---------------------------------------------------------------------
|
|---|
| 626 | // IDropTarget Methods
|
|---|
| 627 | //---------------------------------------------------------------------
|
|---|
| 628 |
|
|---|
| 629 | QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP
|
|---|
| 630 | QOleDropTarget::DragEnter(LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)
|
|---|
| 631 | {
|
|---|
| 632 | #ifdef QDND_DEBUG
|
|---|
| 633 | qDebug("QOleDropTarget::DragEnter(LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)");
|
|---|
| 634 | #endif
|
|---|
| 635 |
|
|---|
| 636 | if (!QApplicationPrivate::tryModalHelper(widget)) {
|
|---|
| 637 | *pdwEffect = DROPEFFECT_NONE;
|
|---|
| 638 | return NOERROR;
|
|---|
| 639 | }
|
|---|
| 640 |
|
|---|
| 641 | QDragManager *manager = QDragManager::self();
|
|---|
| 642 | manager->dropData->currentDataObject = pDataObj;
|
|---|
| 643 | manager->dropData->currentDataObject->AddRef();
|
|---|
| 644 | sendDragEnterEvent(widget, grfKeyState, pt, pdwEffect);
|
|---|
| 645 | *pdwEffect = chosenEffect;
|
|---|
| 646 |
|
|---|
| 647 | return NOERROR;
|
|---|
| 648 | }
|
|---|
| 649 |
|
|---|
| 650 | void QOleDropTarget::sendDragEnterEvent(QWidget *dragEnterWidget, DWORD grfKeyState,
|
|---|
| 651 | POINTL pt, LPDWORD pdwEffect)
|
|---|
| 652 | {
|
|---|
| 653 | Q_ASSERT(dragEnterWidget);
|
|---|
| 654 | lastPoint = dragEnterWidget->mapFromGlobal(QPoint(pt.x,pt.y));
|
|---|
| 655 | lastKeyState = grfKeyState;
|
|---|
| 656 |
|
|---|
| 657 | chosenEffect = DROPEFFECT_NONE;
|
|---|
| 658 | currentWidget = dragEnterWidget;
|
|---|
| 659 |
|
|---|
| 660 | QDragManager *manager = QDragManager::self();
|
|---|
| 661 | QMimeData * md = manager->source() ? manager->dragPrivate()->data : manager->dropData;
|
|---|
| 662 | QDragEnterEvent enterEvent(lastPoint, translateToQDragDropActions(*pdwEffect), md,
|
|---|
| 663 | toQtMouseButtons(grfKeyState), toQtKeyboardModifiers(grfKeyState));
|
|---|
| 664 | QApplication::sendEvent(dragEnterWidget, &enterEvent);
|
|---|
| 665 | answerRect = enterEvent.answerRect();
|
|---|
| 666 |
|
|---|
| 667 | if (enterEvent.isAccepted()) {
|
|---|
| 668 | chosenEffect = translateToWinDragEffects(enterEvent.dropAction());
|
|---|
| 669 | }
|
|---|
| 670 |
|
|---|
| 671 | // Documentation states that a drag move event is sendt immidiatly after
|
|---|
| 672 | // a drag enter event. This will honor widgets overriding dragMoveEvent only:
|
|---|
| 673 | if (enterEvent.isAccepted()) {
|
|---|
| 674 | QDragMoveEvent moveEvent(lastPoint, translateToQDragDropActions(*pdwEffect), md,
|
|---|
| 675 | toQtMouseButtons(grfKeyState), toQtKeyboardModifiers(grfKeyState));
|
|---|
| 676 | answerRect = enterEvent.answerRect();
|
|---|
| 677 | moveEvent.setDropAction(enterEvent.dropAction());
|
|---|
| 678 | moveEvent.accept(); // accept by default, since enter event was accepted.
|
|---|
| 679 |
|
|---|
| 680 | QApplication::sendEvent(dragEnterWidget, &moveEvent);
|
|---|
| 681 | if (moveEvent.isAccepted()) {
|
|---|
| 682 | answerRect = moveEvent.answerRect();
|
|---|
| 683 | chosenEffect = translateToWinDragEffects(moveEvent.dropAction());
|
|---|
| 684 | } else {
|
|---|
| 685 | chosenEffect = DROPEFFECT_NONE;
|
|---|
| 686 | }
|
|---|
| 687 | }
|
|---|
| 688 |
|
|---|
| 689 | }
|
|---|
| 690 |
|
|---|
| 691 | QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP
|
|---|
| 692 | QOleDropTarget::DragOver(DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)
|
|---|
| 693 | {
|
|---|
| 694 | #ifdef QDND_DEBUG
|
|---|
| 695 | qDebug("QOleDropTarget::DragOver(grfKeyState %d, pt (%d,%d), pdwEffect %d)", grfKeyState, pt.x, pt.y, pdwEffect);
|
|---|
| 696 | #endif
|
|---|
| 697 |
|
|---|
| 698 | QWidget *dragOverWidget = widget->childAt(widget->mapFromGlobal(QPoint(pt.x, pt.y)));
|
|---|
| 699 | if (!dragOverWidget)
|
|---|
| 700 | dragOverWidget = widget;
|
|---|
| 701 |
|
|---|
| 702 |
|
|---|
| 703 | if (!QApplicationPrivate::tryModalHelper(dragOverWidget)
|
|---|
| 704 | || !dragOverWidget->testAttribute(Qt::WA_DropSiteRegistered)) {
|
|---|
| 705 | *pdwEffect = DROPEFFECT_NONE;
|
|---|
| 706 | return NOERROR;
|
|---|
| 707 | }
|
|---|
| 708 |
|
|---|
| 709 | QPoint tmpPoint = dragOverWidget->mapFromGlobal(QPoint(pt.x, pt.y));
|
|---|
| 710 | // see if we should compress this event
|
|---|
| 711 | if ((tmpPoint == lastPoint || answerRect.contains(tmpPoint)) && lastKeyState == grfKeyState) {
|
|---|
| 712 | *pdwEffect = chosenEffect;
|
|---|
| 713 | return NOERROR;
|
|---|
| 714 | }
|
|---|
| 715 |
|
|---|
| 716 | if (!dragOverWidget->internalWinId() && dragOverWidget != currentWidget) {
|
|---|
| 717 | QPointer<QWidget> dragOverWidgetGuard(dragOverWidget);
|
|---|
| 718 | // Send drag leave event to the previous drag widget.
|
|---|
| 719 | QDragLeaveEvent dragLeave;
|
|---|
| 720 | if (currentWidget)
|
|---|
| 721 | QApplication::sendEvent(currentWidget, &dragLeave);
|
|---|
| 722 | if (!dragOverWidgetGuard) {
|
|---|
| 723 | dragOverWidget = widget->childAt(widget->mapFromGlobal(QPoint(pt.x, pt.y)));
|
|---|
| 724 | if (!dragOverWidget)
|
|---|
| 725 | dragOverWidget = widget;
|
|---|
| 726 | }
|
|---|
| 727 | // Send drag enter event to the current drag widget.
|
|---|
| 728 | sendDragEnterEvent(dragOverWidget, grfKeyState, pt, pdwEffect);
|
|---|
| 729 | }
|
|---|
| 730 |
|
|---|
| 731 | QDragManager *manager = QDragManager::self();
|
|---|
| 732 | QMimeData *md = manager->source() ? manager->dragPrivate()->data : manager->dropData;
|
|---|
| 733 |
|
|---|
| 734 | QDragMoveEvent oldEvent(lastPoint, translateToQDragDropActions(*pdwEffect), md,
|
|---|
| 735 | toQtMouseButtons(lastKeyState), toQtKeyboardModifiers(lastKeyState));
|
|---|
| 736 |
|
|---|
| 737 |
|
|---|
| 738 | lastPoint = tmpPoint;
|
|---|
| 739 | lastKeyState = grfKeyState;
|
|---|
| 740 |
|
|---|
| 741 | QDragMoveEvent e(lastPoint, translateToQDragDropActions(*pdwEffect), md,
|
|---|
| 742 | toQtMouseButtons(grfKeyState), toQtKeyboardModifiers(grfKeyState));
|
|---|
| 743 | if (chosenEffect != DROPEFFECT_NONE) {
|
|---|
| 744 | if (oldEvent.dropAction() == e.dropAction() &&
|
|---|
| 745 | oldEvent.keyboardModifiers() == e.keyboardModifiers())
|
|---|
| 746 | e.setDropAction(translateToQDragDropAction(chosenEffect));
|
|---|
| 747 | e.accept();
|
|---|
| 748 | }
|
|---|
| 749 | QApplication::sendEvent(dragOverWidget, &e);
|
|---|
| 750 |
|
|---|
| 751 | answerRect = e.answerRect();
|
|---|
| 752 | if (e.isAccepted())
|
|---|
| 753 | chosenEffect = translateToWinDragEffects(e.dropAction());
|
|---|
| 754 | else
|
|---|
| 755 | chosenEffect = DROPEFFECT_NONE;
|
|---|
| 756 | *pdwEffect = chosenEffect;
|
|---|
| 757 |
|
|---|
| 758 | return NOERROR;
|
|---|
| 759 | }
|
|---|
| 760 |
|
|---|
| 761 | QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP
|
|---|
| 762 | QOleDropTarget::DragLeave()
|
|---|
| 763 | {
|
|---|
| 764 | #ifdef QDND_DEBUG
|
|---|
| 765 | qDebug("QOleDropTarget::DragLeave()");
|
|---|
| 766 | #endif
|
|---|
| 767 |
|
|---|
| 768 | if (!QApplicationPrivate::tryModalHelper(widget)) {
|
|---|
| 769 | return NOERROR;
|
|---|
| 770 | }
|
|---|
| 771 |
|
|---|
| 772 | currentWidget = 0;
|
|---|
| 773 | QDragLeaveEvent e;
|
|---|
| 774 | QApplication::sendEvent(widget, &e);
|
|---|
| 775 |
|
|---|
| 776 | QDragManager *manager = QDragManager::self();
|
|---|
| 777 |
|
|---|
| 778 | if (manager->dropData->currentDataObject) { // Sanity
|
|---|
| 779 | manager->dropData->currentDataObject->Release();
|
|---|
| 780 | manager->dropData->currentDataObject = 0;
|
|---|
| 781 | }
|
|---|
| 782 |
|
|---|
| 783 | return NOERROR;
|
|---|
| 784 | }
|
|---|
| 785 |
|
|---|
| 786 | #define KEY_STATE_BUTTON_MASK (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON)
|
|---|
| 787 |
|
|---|
| 788 | QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP
|
|---|
| 789 | QOleDropTarget::Drop(LPDATAOBJECT /*pDataObj*/, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)
|
|---|
| 790 | {
|
|---|
| 791 | #ifdef QDND_DEBUG
|
|---|
| 792 | qDebug("QOleDropTarget::Drop(LPDATAOBJECT /*pDataObj*/, grfKeyState %d, POINTL pt, LPDWORD pdwEffect)", grfKeyState);
|
|---|
| 793 | #endif
|
|---|
| 794 |
|
|---|
| 795 | QWidget *dropWidget = widget->childAt(widget->mapFromGlobal(QPoint(pt.x, pt.y)));
|
|---|
| 796 | if (!dropWidget)
|
|---|
| 797 | dropWidget = widget;
|
|---|
| 798 |
|
|---|
| 799 | if (!QApplicationPrivate::tryModalHelper(dropWidget)
|
|---|
| 800 | || !dropWidget->testAttribute(Qt::WA_DropSiteRegistered)) {
|
|---|
| 801 | *pdwEffect = DROPEFFECT_NONE;
|
|---|
| 802 | return NOERROR;
|
|---|
| 803 | }
|
|---|
| 804 |
|
|---|
| 805 | lastPoint = dropWidget->mapFromGlobal(QPoint(pt.x,pt.y));
|
|---|
| 806 | // grfKeyState does not all ways contain button state in the drop so if
|
|---|
| 807 | // it doesn't then use the last known button state;
|
|---|
| 808 | if ((grfKeyState & KEY_STATE_BUTTON_MASK) == 0)
|
|---|
| 809 | grfKeyState |= lastKeyState & KEY_STATE_BUTTON_MASK;
|
|---|
| 810 | lastKeyState = grfKeyState;
|
|---|
| 811 |
|
|---|
| 812 | QDragManager *manager = QDragManager::self();
|
|---|
| 813 | QMimeData *md = manager->source() ? manager->dragPrivate()->data : manager->dropData;
|
|---|
| 814 | QDropEvent e(lastPoint, translateToQDragDropActions(*pdwEffect), md,
|
|---|
| 815 | toQtMouseButtons(grfKeyState), toQtKeyboardModifiers(grfKeyState));
|
|---|
| 816 | if (chosenEffect != DROPEFFECT_NONE) {
|
|---|
| 817 | e.setDropAction(translateToQDragDropAction(chosenEffect));
|
|---|
| 818 | }
|
|---|
| 819 | QApplication::sendEvent(dropWidget, &e);
|
|---|
| 820 |
|
|---|
| 821 | if (chosenEffect != DROPEFFECT_NONE) {
|
|---|
| 822 | e.accept();
|
|---|
| 823 | }
|
|---|
| 824 |
|
|---|
| 825 |
|
|---|
| 826 | if (e.isAccepted()) {
|
|---|
| 827 | if (e.dropAction() == Qt::MoveAction || e.dropAction() == Qt::TargetMoveAction) {
|
|---|
| 828 | if (e.dropAction() == Qt::MoveAction)
|
|---|
| 829 | chosenEffect = DROPEFFECT_MOVE;
|
|---|
| 830 | else
|
|---|
| 831 | chosenEffect = DROPEFFECT_COPY;
|
|---|
| 832 | HGLOBAL hData = GlobalAlloc(0, sizeof(DWORD));
|
|---|
| 833 | if (hData) {
|
|---|
| 834 | DWORD *moveEffect = (DWORD *)GlobalLock(hData);;
|
|---|
| 835 | *moveEffect = DROPEFFECT_MOVE;
|
|---|
| 836 | GlobalUnlock(hData);
|
|---|
| 837 | STGMEDIUM medium;
|
|---|
| 838 | memset(&medium, 0, sizeof(STGMEDIUM));
|
|---|
| 839 | medium.tymed = TYMED_HGLOBAL;
|
|---|
| 840 | medium.hGlobal = hData;
|
|---|
| 841 | FORMATETC format;
|
|---|
| 842 | format.cfFormat = RegisterClipboardFormat(CFSTR_PERFORMEDDROPEFFECT);
|
|---|
| 843 | format.tymed = TYMED_HGLOBAL;
|
|---|
| 844 | format.ptd = 0;
|
|---|
| 845 | format.dwAspect = 1;
|
|---|
| 846 | format.lindex = -1;
|
|---|
| 847 | manager->dropData->currentDataObject->SetData(&format, &medium, true);
|
|---|
| 848 | }
|
|---|
| 849 | } else {
|
|---|
| 850 | chosenEffect = translateToWinDragEffects(e.dropAction());
|
|---|
| 851 | }
|
|---|
| 852 | } else {
|
|---|
| 853 | chosenEffect = DROPEFFECT_NONE;
|
|---|
| 854 | }
|
|---|
| 855 | *pdwEffect = chosenEffect;
|
|---|
| 856 |
|
|---|
| 857 |
|
|---|
| 858 | if (manager->dropData->currentDataObject) {
|
|---|
| 859 | manager->dropData->currentDataObject->Release();
|
|---|
| 860 | manager->dropData->currentDataObject = 0;
|
|---|
| 861 | }
|
|---|
| 862 |
|
|---|
| 863 | return NOERROR;
|
|---|
| 864 |
|
|---|
| 865 | // We won't get any mouserelease-event, so manually adjust qApp state:
|
|---|
| 866 | ///### test this QApplication::winMouseButtonUp();
|
|---|
| 867 | }
|
|---|
| 868 |
|
|---|
| 869 | //---------------------------------------------------------------------
|
|---|
| 870 | // QDropData
|
|---|
| 871 | //---------------------------------------------------------------------
|
|---|
| 872 |
|
|---|
| 873 | bool QDropData::hasFormat_sys(const QString &mimeType) const
|
|---|
| 874 | {
|
|---|
| 875 | if (!currentDataObject) // Sanity
|
|---|
| 876 | return false;
|
|---|
| 877 |
|
|---|
| 878 | return QWindowsMime::converterToMime(mimeType, currentDataObject) != 0;
|
|---|
| 879 | }
|
|---|
| 880 |
|
|---|
| 881 | QStringList QDropData::formats_sys() const
|
|---|
| 882 | {
|
|---|
| 883 | QStringList fmts;
|
|---|
| 884 | if (!currentDataObject) // Sanity
|
|---|
| 885 | return fmts;
|
|---|
| 886 |
|
|---|
| 887 | fmts = QWindowsMime::allMimesForFormats(currentDataObject);
|
|---|
| 888 |
|
|---|
| 889 | return fmts;
|
|---|
| 890 | }
|
|---|
| 891 |
|
|---|
| 892 | QVariant QDropData::retrieveData_sys(const QString &mimeType, QVariant::Type type) const
|
|---|
| 893 | {
|
|---|
| 894 | QVariant result;
|
|---|
| 895 |
|
|---|
| 896 | if (!currentDataObject) // Sanity
|
|---|
| 897 | return result;
|
|---|
| 898 |
|
|---|
| 899 | QWindowsMime *converter = QWindowsMime::converterToMime(mimeType, currentDataObject);
|
|---|
| 900 |
|
|---|
| 901 | if (converter)
|
|---|
| 902 | result = converter->convertToMime(mimeType, currentDataObject, type);
|
|---|
| 903 |
|
|---|
| 904 | return result;
|
|---|
| 905 | }
|
|---|
| 906 |
|
|---|
| 907 | Qt::DropAction QDragManager::drag(QDrag *o)
|
|---|
| 908 |
|
|---|
| 909 | {
|
|---|
| 910 | #ifdef QDND_DEBUG
|
|---|
| 911 | qDebug("QDragManager::drag(QDrag *drag)");
|
|---|
| 912 | #endif
|
|---|
| 913 |
|
|---|
| 914 | if (object == o || !o || !o->d_func()->source)
|
|---|
| 915 | return Qt::IgnoreAction;
|
|---|
| 916 |
|
|---|
| 917 | if (object) {
|
|---|
| 918 | cancel();
|
|---|
| 919 | qApp->removeEventFilter(this);
|
|---|
| 920 | beingCancelled = false;
|
|---|
| 921 | }
|
|---|
| 922 |
|
|---|
| 923 | object = o;
|
|---|
| 924 |
|
|---|
| 925 | #ifdef QDND_DEBUG
|
|---|
| 926 | qDebug("actions = %s", dragActionsToString(dragPrivate()->possible_actions).toLatin1().data());
|
|---|
| 927 | #endif
|
|---|
| 928 |
|
|---|
| 929 | dragPrivate()->target = 0;
|
|---|
| 930 |
|
|---|
| 931 | #ifndef QT_NO_ACCESSIBILITY
|
|---|
| 932 | QAccessible::updateAccessibility(this, 0, QAccessible::DragDropStart);
|
|---|
| 933 | #endif
|
|---|
| 934 |
|
|---|
| 935 | DWORD resultEffect;
|
|---|
| 936 | QOleDropSource *src = new QOleDropSource();
|
|---|
| 937 | src->createCursors();
|
|---|
| 938 | QOleDataObject *obj = new QOleDataObject(o->mimeData());
|
|---|
| 939 | DWORD allowedEffects = translateToWinDragEffects(dragPrivate()->possible_actions);
|
|---|
| 940 |
|
|---|
| 941 | #if !defined(Q_OS_WINCE) || defined(GWES_ICONCURS)
|
|---|
| 942 | HRESULT r = DoDragDrop(obj, src, allowedEffects, &resultEffect);
|
|---|
| 943 | #else
|
|---|
| 944 | HRESULT r = DRAGDROP_S_CANCEL;
|
|---|
| 945 | resultEffect = DROPEFFECT_MOVE;
|
|---|
| 946 | #endif
|
|---|
| 947 |
|
|---|
| 948 | Qt::DropAction ret = Qt::IgnoreAction;
|
|---|
| 949 | if (r == DRAGDROP_S_DROP) {
|
|---|
| 950 | if (obj->reportedPerformedEffect() == DROPEFFECT_MOVE && resultEffect != DROPEFFECT_MOVE) {
|
|---|
| 951 | ret = Qt::TargetMoveAction;
|
|---|
| 952 | resultEffect = DROPEFFECT_MOVE;
|
|---|
| 953 | } else {
|
|---|
| 954 | ret = translateToQDragDropAction(resultEffect);
|
|---|
| 955 | }
|
|---|
| 956 | // Force it to be a copy if an unsupported operation occurred.
|
|---|
| 957 | // This indicates a bug in the drop target.
|
|---|
| 958 | if (resultEffect != DROPEFFECT_NONE && !(resultEffect & allowedEffects))
|
|---|
| 959 | ret = Qt::CopyAction;
|
|---|
| 960 | } else {
|
|---|
| 961 | dragPrivate()->target = 0;
|
|---|
| 962 | }
|
|---|
| 963 |
|
|---|
| 964 | // clean up
|
|---|
| 965 | obj->releaseQt();
|
|---|
| 966 | obj->Release(); // Will delete obj if refcount becomes 0
|
|---|
| 967 | src->Release(); // Will delete src if refcount becomes 0
|
|---|
| 968 | object = 0;
|
|---|
| 969 | o->setMimeData(0);
|
|---|
| 970 | o->deleteLater();
|
|---|
| 971 |
|
|---|
| 972 | #ifndef QT_NO_ACCESSIBILITY
|
|---|
| 973 | QAccessible::updateAccessibility(this, 0, QAccessible::DragDropEnd);
|
|---|
| 974 | #endif
|
|---|
| 975 |
|
|---|
| 976 | return ret;
|
|---|
| 977 | }
|
|---|
| 978 |
|
|---|
| 979 | void QDragManager::cancel(bool /* deleteSource */)
|
|---|
| 980 | {
|
|---|
| 981 | if (object) {
|
|---|
| 982 | beingCancelled = true;
|
|---|
| 983 | object = 0;
|
|---|
| 984 | }
|
|---|
| 985 |
|
|---|
| 986 | #ifndef QT_NO_CURSOR
|
|---|
| 987 | // insert cancel code here ######## todo
|
|---|
| 988 |
|
|---|
| 989 | if (restoreCursor) {
|
|---|
| 990 | QApplication::restoreOverrideCursor();
|
|---|
| 991 | restoreCursor = false;
|
|---|
| 992 | }
|
|---|
| 993 | #endif
|
|---|
| 994 | #ifndef QT_NO_ACCESSIBILITY
|
|---|
| 995 | QAccessible::updateAccessibility(this, 0, QAccessible::DragDropEnd);
|
|---|
| 996 | #endif
|
|---|
| 997 | }
|
|---|
| 998 |
|
|---|
| 999 | void QDragManager::updatePixmap()
|
|---|
| 1000 | {
|
|---|
| 1001 | // not used in windows implementation
|
|---|
| 1002 | }
|
|---|
| 1003 |
|
|---|
| 1004 | bool QDragManager::eventFilter(QObject *, QEvent *)
|
|---|
| 1005 | {
|
|---|
| 1006 | // not used in windows implementation
|
|---|
| 1007 | return false;
|
|---|
| 1008 | }
|
|---|
| 1009 |
|
|---|
| 1010 | void QDragManager::timerEvent(QTimerEvent*)
|
|---|
| 1011 | {
|
|---|
| 1012 | // not used in windows implementation
|
|---|
| 1013 | }
|
|---|
| 1014 |
|
|---|
| 1015 | void QDragManager::move(const QPoint &)
|
|---|
| 1016 | {
|
|---|
| 1017 | // not used in windows implementation
|
|---|
| 1018 | }
|
|---|
| 1019 |
|
|---|
| 1020 | void QDragManager::drop()
|
|---|
| 1021 | {
|
|---|
| 1022 | // not used in windows implementation
|
|---|
| 1023 | }
|
|---|
| 1024 |
|
|---|
| 1025 | QT_END_NAMESPACE
|
|---|
| 1026 |
|
|---|
| 1027 | #endif // QT_NO_DRAGANDDROP
|
|---|