Qt 4.8
Public Functions | Private Functions | Properties | List of all members
QOleDropTarget Class Reference

#include <qdnd_p.h>

Inheritance diagram for QOleDropTarget:

Public Functions

STDMETHOD() DragEnter (LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)
 
STDMETHOD() DragLeave ()
 
STDMETHOD() DragOver (DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)
 
STDMETHOD() Drop (LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)
 
 QOleDropTarget (QWidget *w)
 
STDMETHOD() QueryInterface (REFIID riid, void FAR *FAR *ppvObj)
 
void releaseQt ()
 
 STDMETHOD_ (ULONG, AddRef)(void)
 
 STDMETHOD_ (ULONG, Release)(void)
 
virtual ~QOleDropTarget ()
 

Private Functions

void sendDragEnterEvent (QWidget *to, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)
 

Properties

QRect answerRect
 
DWORD chosenEffect
 
QPointer< QWidgetcurrentWidget
 
DWORD lastKeyState
 
QPoint lastPoint
 
ULONG m_refs
 
QWidgetwidget
 

Detailed Description

Definition at line 281 of file qdnd_p.h.

Constructors and Destructors

◆ QOleDropTarget()

QOleDropTarget::QOleDropTarget ( QWidget w)

Definition at line 579 of file qdnd_win.cpp.

580 : widget(w)
581 {
582  m_refs = 1;
583 }
ULONG m_refs
Definition: qdnd_p.h:301
QWidget * widget
Definition: qdnd_p.h:302

◆ ~QOleDropTarget()

virtual QOleDropTarget::~QOleDropTarget ( )
inlinevirtual

Definition at line 285 of file qdnd_p.h.

285 {}

Functions

◆ DragEnter()

QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP QOleDropTarget::DragEnter ( LPDATAOBJECT  pDataObj,
DWORD  grfKeyState,
POINTL  pt,
LPDWORD  pdwEffect 
)

Definition at line 632 of file qdnd_win.cpp.

633 {
634 #ifdef QDND_DEBUG
635  qDebug("QOleDropTarget::DragEnter(LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)");
636 #endif
637 
639  *pdwEffect = DROPEFFECT_NONE;
640  return NOERROR;
641  }
642 
643  QDragManager *manager = QDragManager::self();
644  manager->dropData->currentDataObject = pDataObj;
645  manager->dropData->currentDataObject->AddRef();
646  sendDragEnterEvent(widget, grfKeyState, pt, pdwEffect);
647  *pdwEffect = chosenEffect;
648 
649  return NOERROR;
650 }
void sendDragEnterEvent(QWidget *to, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)
Definition: qdnd_win.cpp:652
Q_CORE_EXPORT void qDebug(const char *,...)
QWidget * widget
Definition: qdnd_p.h:302
static QDragManager * self()
Definition: qdnd.cpp:163
static bool tryModalHelper(QWidget *widget, QWidget **rettop=0)
LPDATAOBJECT currentDataObject
Definition: qdnd_p.h:202
QDropData * dropData
Definition: qdnd_p.h:251
DWORD chosenEffect
Definition: qdnd_p.h:306

◆ DragLeave()

QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP QOleDropTarget::DragLeave ( )

Definition at line 778 of file qdnd_win.cpp.

779 {
780 #ifdef QDND_DEBUG
781  qDebug("QOleDropTarget::DragLeave()");
782 #endif
783 
785  return NOERROR;
786  }
787 
788  currentWidget = 0;
789  QDragLeaveEvent e;
791 
792  QDragManager *manager = QDragManager::self();
793 
794  if (manager->dropData->currentDataObject) { // Sanity
795  manager->dropData->currentDataObject->Release();
796  manager->dropData->currentDataObject = 0;
797  }
798 
799  return NOERROR;
800 }
QPointer< QWidget > currentWidget
Definition: qdnd_p.h:303
Q_CORE_EXPORT void qDebug(const char *,...)
QWidget * widget
Definition: qdnd_p.h:302
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leav...
Definition: qevent.h:577
static QDragManager * self()
Definition: qdnd.cpp:163
static bool tryModalHelper(QWidget *widget, QWidget **rettop=0)
LPDATAOBJECT currentDataObject
Definition: qdnd_p.h:202
QDropData * dropData
Definition: qdnd_p.h:251

◆ DragOver()

QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP QOleDropTarget::DragOver ( DWORD  grfKeyState,
POINTL  pt,
LPDWORD  pdwEffect 
)

Definition at line 699 of file qdnd_win.cpp.

700 {
701 #ifdef QDND_DEBUG
702  qDebug("QOleDropTarget::DragOver(grfKeyState %d, pt (%d,%d), pdwEffect %d)", grfKeyState, pt.x, pt.y, pdwEffect);
703 #endif
704 
705  QWidget *dragOverWidget = widget->childAt(widget->mapFromGlobal(QPoint(pt.x, pt.y)));
706  if (!dragOverWidget)
707  dragOverWidget = widget;
708 
709 
710  if (!QApplicationPrivate::tryModalHelper(dragOverWidget)) {
711  *pdwEffect = DROPEFFECT_NONE;
712  return NOERROR;
713  }
714 
715  // Try to find a drop-enabled target in the hierarchy. Go beyond 'widget' in case
716  // it is a native child window which has its own drop site registered (QTBUG-27265).
717  while (dragOverWidget && !dragOverWidget->isWindow() && !acceptsDrop(dragOverWidget))
718  dragOverWidget = dragOverWidget->parentWidget();
719 
720  if (!dragOverWidget || !acceptsDrop(dragOverWidget)) {
721  *pdwEffect = DROPEFFECT_NONE;
722  return NOERROR;
723  }
724 
725  QPoint tmpPoint = dragOverWidget->mapFromGlobal(QPoint(pt.x, pt.y));
726  // see if we should compress this event
727  if ((tmpPoint == lastPoint || answerRect.contains(tmpPoint)) && lastKeyState == grfKeyState) {
728  *pdwEffect = chosenEffect;
729  return NOERROR;
730  }
731 
732  if (!dragOverWidget->internalWinId() && dragOverWidget != currentWidget) {
733  QPointer<QWidget> dragOverWidgetGuard(dragOverWidget);
734  // Send drag leave event to the previous drag widget.
735  QDragLeaveEvent dragLeave;
736  if (currentWidget)
738  if (!dragOverWidgetGuard) {
739  dragOverWidget = widget->childAt(widget->mapFromGlobal(QPoint(pt.x, pt.y)));
740  if (!dragOverWidget)
741  dragOverWidget = widget;
742  }
743  // Send drag enter event to the current drag widget.
744  sendDragEnterEvent(dragOverWidget, grfKeyState, pt, pdwEffect);
745  }
746 
747  QDragManager *manager = QDragManager::self();
748  QMimeData *md = manager->source() ? manager->dragPrivate()->data : manager->dropData;
749 
750  QDragMoveEvent oldEvent(lastPoint, translateToQDragDropActions(*pdwEffect), md,
752 
753 
754  lastPoint = tmpPoint;
755  lastKeyState = grfKeyState;
756 
758  toQtMouseButtons(grfKeyState), toQtKeyboardModifiers(grfKeyState));
759  if (chosenEffect != DROPEFFECT_NONE) {
760  if (oldEvent.dropAction() == e.dropAction() &&
761  oldEvent.keyboardModifiers() == e.keyboardModifiers())
762  e.setDropAction(translateToQDragDropAction(chosenEffect));
763  e.accept();
764  }
765  QApplication::sendEvent(dragOverWidget, &e);
766 
767  answerRect = e.answerRect();
768  if (e.isAccepted())
769  chosenEffect = translateToWinDragEffects(e.dropAction());
770  else
771  chosenEffect = DROPEFFECT_NONE;
772  *pdwEffect = chosenEffect;
773 
774  return NOERROR;
775 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
Qt::DropActions translateToQDragDropActions(DWORD pdwEffects)
Definition: qdnd_win.cpp:283
QPointer< QWidget > currentWidget
Definition: qdnd_p.h:303
Qt::DropAction translateToQDragDropAction(DWORD pdwEffect)
Definition: qdnd_win.cpp:295
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
void sendDragEnterEvent(QWidget *to, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)
Definition: qdnd_win.cpp:652
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QRect answerRect
Definition: qdnd_p.h:304
The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress...
Definition: qevent.h:530
DWORD translateToWinDragEffects(Qt::DropActions action)
Definition: qdnd_win.cpp:306
QWidget * source() const
Definition: qdnd_p.h:230
Q_CORE_EXPORT void qDebug(const char *,...)
QWidget * widget
Definition: qdnd_p.h:302
QWidget * childAt(int x, int y) const
Returns the visible child widget at the position ({x}, {y}) in the widget&#39;s coordinate system...
Definition: qwidget.h:934
QPoint lastPoint
Definition: qdnd_p.h:305
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leav...
Definition: qevent.h:577
Qt::MouseButtons toQtMouseButtons(DWORD keyState)
Definition: qdnd_win.cpp:332
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
static QDragManager * self()
Definition: qdnd.cpp:163
static bool tryModalHelper(QWidget *widget, QWidget **rettop=0)
QMimeData * data
Definition: qdnd_p.h:179
static bool acceptsDrop(const QWidget *w)
Definition: qdnd_win.cpp:693
QDropData * dropData
Definition: qdnd_p.h:251
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
WId internalWinId() const
Returns the window system identifier of the widget, or 0 if the widget is not created yet...
Definition: qwidget.h:244
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
DWORD lastKeyState
Definition: qdnd_p.h:307
DWORD chosenEffect
Definition: qdnd_p.h:306
QDragPrivate * dragPrivate() const
Definition: qdnd_p.h:231
Qt::KeyboardModifiers toQtKeyboardModifiers(DWORD keyState)
Definition: qdnd_win.cpp:318

◆ Drop()

QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP QOleDropTarget::Drop ( LPDATAOBJECT  pDataObj,
DWORD  grfKeyState,
POINTL  pt,
LPDWORD  pdwEffect 
)

test this QApplication::winMouseButtonUp();

Definition at line 805 of file qdnd_win.cpp.

806 {
807 #ifdef QDND_DEBUG
808  qDebug("QOleDropTarget::Drop(LPDATAOBJECT /*pDataObj*/, grfKeyState %d, POINTL pt, LPDWORD pdwEffect)", grfKeyState);
809 #endif
810 
812  if (!dropWidget)
813  dropWidget = widget;
814 
815  if (!QApplicationPrivate::tryModalHelper(dropWidget)
816  || !dropWidget->testAttribute(Qt::WA_DropSiteRegistered)) {
817  *pdwEffect = DROPEFFECT_NONE;
818  return NOERROR;
819  }
820 
821  lastPoint = dropWidget->mapFromGlobal(QPoint(pt.x,pt.y));
822  // grfKeyState does not all ways contain button state in the drop so if
823  // it doesn't then use the last known button state;
824  if ((grfKeyState & KEY_STATE_BUTTON_MASK) == 0)
825  grfKeyState |= lastKeyState & KEY_STATE_BUTTON_MASK;
826  lastKeyState = grfKeyState;
827 
828  QDragManager *manager = QDragManager::self();
829  QMimeData *md = manager->source() ? manager->dragPrivate()->data : manager->dropData;
831  toQtMouseButtons(grfKeyState), toQtKeyboardModifiers(grfKeyState));
832  if (chosenEffect != DROPEFFECT_NONE) {
833  e.setDropAction(translateToQDragDropAction(chosenEffect));
834  }
835  QApplication::sendEvent(dropWidget, &e);
836 
837  if (chosenEffect != DROPEFFECT_NONE) {
838  e.accept();
839  }
840 
841 
842  if (e.isAccepted()) {
843  if (e.dropAction() == Qt::MoveAction || e.dropAction() == Qt::TargetMoveAction) {
844  if (e.dropAction() == Qt::MoveAction)
845  chosenEffect = DROPEFFECT_MOVE;
846  else
847  chosenEffect = DROPEFFECT_COPY;
848  HGLOBAL hData = GlobalAlloc(0, sizeof(DWORD));
849  if (hData) {
850  DWORD *moveEffect = (DWORD *)GlobalLock(hData);;
851  *moveEffect = DROPEFFECT_MOVE;
852  GlobalUnlock(hData);
853  STGMEDIUM medium;
854  memset(&medium, 0, sizeof(STGMEDIUM));
855  medium.tymed = TYMED_HGLOBAL;
856  medium.hGlobal = hData;
858  format.cfFormat = RegisterClipboardFormat(CFSTR_PERFORMEDDROPEFFECT);
859  format.tymed = TYMED_HGLOBAL;
860  format.ptd = 0;
861  format.dwAspect = 1;
862  format.lindex = -1;
863  manager->dropData->currentDataObject->SetData(&format, &medium, true);
864  }
865  } else {
866  chosenEffect = translateToWinDragEffects(e.dropAction());
867  }
868  } else {
869  chosenEffect = DROPEFFECT_NONE;
870  }
871  *pdwEffect = chosenEffect;
872 
873 
874  if (manager->dropData->currentDataObject) {
875  manager->dropData->currentDataObject->Release();
876  manager->dropData->currentDataObject = 0;
877  }
878 
879  return NOERROR;
880 
881  // We won't get any mouserelease-event, so manually adjust qApp state:
883 }
Qt::DropActions translateToQDragDropActions(DWORD pdwEffects)
Definition: qdnd_win.cpp:283
Qt::DropAction translateToQDragDropAction(DWORD pdwEffect)
Definition: qdnd_win.cpp:295
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define KEY_STATE_BUTTON_MASK
Definition: qdnd_win.cpp:802
#define CFSTR_PERFORMEDDROPEFFECT
struct tagFORMATETC FORMATETC
Definition: qmime.h:66
DWORD translateToWinDragEffects(Qt::DropActions action)
Definition: qdnd_win.cpp:306
QWidget * source() const
Definition: qdnd_p.h:230
Q_CORE_EXPORT void qDebug(const char *,...)
QWidget * widget
Definition: qdnd_p.h:302
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
QWidget * childAt(int x, int y) const
Returns the visible child widget at the position ({x}, {y}) in the widget&#39;s coordinate system...
Definition: qwidget.h:934
QPoint lastPoint
Definition: qdnd_p.h:305
struct tagSTGMEDIUM STGMEDIUM
Definition: qmime.h:67
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
Qt::MouseButtons toQtMouseButtons(DWORD keyState)
Definition: qdnd_win.cpp:332
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
static QDragManager * self()
Definition: qdnd.cpp:163
static bool tryModalHelper(QWidget *widget, QWidget **rettop=0)
The QDropEvent class provides an event which is sent when a drag and drop action is completed...
Definition: qevent.h:476
LPDATAOBJECT currentDataObject
Definition: qdnd_p.h:202
QMimeData * data
Definition: qdnd_p.h:179
QDropData * dropData
Definition: qdnd_p.h:251
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
DWORD lastKeyState
Definition: qdnd_p.h:307
DWORD chosenEffect
Definition: qdnd_p.h:306
QDragPrivate * dragPrivate() const
Definition: qdnd_p.h:231
static QWidget * dropWidget
Qt::KeyboardModifiers toQtKeyboardModifiers(DWORD keyState)
Definition: qdnd_win.cpp:318

◆ QueryInterface()

STDMETHODIMP QOleDropTarget::QueryInterface ( REFIID  riid,
void FAR *FAR *  ppvObj 
)

Definition at line 596 of file qdnd_win.cpp.

597 {
598  if(iid == IID_IUnknown || iid == IID_IDropTarget)
599  {
600  *ppv = this;
601  AddRef();
602  return NOERROR;
603  }
604  *ppv = NULL;
605  return ResultFromScode(E_NOINTERFACE);
606 }

◆ releaseQt()

void QOleDropTarget::releaseQt ( )

Definition at line 585 of file qdnd_win.cpp.

Referenced by qt_grab_cursor().

586 {
587  widget = 0;
588 }
QWidget * widget
Definition: qdnd_p.h:302

◆ sendDragEnterEvent()

void QOleDropTarget::sendDragEnterEvent ( QWidget to,
DWORD  grfKeyState,
POINTL  pt,
LPDWORD  pdwEffect 
)
private

Definition at line 652 of file qdnd_win.cpp.

Referenced by DragEnter(), and DragOver().

654 {
655  Q_ASSERT(dragEnterWidget);
656  lastPoint = dragEnterWidget->mapFromGlobal(QPoint(pt.x,pt.y));
657  lastKeyState = grfKeyState;
658 
659  chosenEffect = DROPEFFECT_NONE;
660  currentWidget = dragEnterWidget;
661 
662  QDragManager *manager = QDragManager::self();
663  QMimeData * md = manager->source() ? manager->dragPrivate()->data : manager->dropData;
664  QDragEnterEvent enterEvent(lastPoint, translateToQDragDropActions(*pdwEffect), md,
665  toQtMouseButtons(grfKeyState), toQtKeyboardModifiers(grfKeyState));
666  QApplication::sendEvent(dragEnterWidget, &enterEvent);
667  answerRect = enterEvent.answerRect();
668 
669  if (enterEvent.isAccepted()) {
670  chosenEffect = translateToWinDragEffects(enterEvent.dropAction());
671  }
672 
673  // Documentation states that a drag move event is sendt immidiatly after
674  // a drag enter event. This will honor widgets overriding dragMoveEvent only:
675  if (enterEvent.isAccepted()) {
676  QDragMoveEvent moveEvent(lastPoint, translateToQDragDropActions(*pdwEffect), md,
677  toQtMouseButtons(grfKeyState), toQtKeyboardModifiers(grfKeyState));
678  answerRect = enterEvent.answerRect();
679  moveEvent.setDropAction(enterEvent.dropAction());
680  moveEvent.accept(); // accept by default, since enter event was accepted.
681 
682  QApplication::sendEvent(dragEnterWidget, &moveEvent);
683  if (moveEvent.isAccepted()) {
684  answerRect = moveEvent.answerRect();
685  chosenEffect = translateToWinDragEffects(moveEvent.dropAction());
686  } else {
687  chosenEffect = DROPEFFECT_NONE;
688  }
689  }
690 
691 }
Qt::DropActions translateToQDragDropActions(DWORD pdwEffects)
Definition: qdnd_win.cpp:283
QPointer< QWidget > currentWidget
Definition: qdnd_p.h:303
QRect answerRect
Definition: qdnd_p.h:304
The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress...
Definition: qevent.h:530
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
DWORD translateToWinDragEffects(Qt::DropActions action)
Definition: qdnd_win.cpp:306
QWidget * source() const
Definition: qdnd_p.h:230
QPoint lastPoint
Definition: qdnd_p.h:305
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
Qt::MouseButtons toQtMouseButtons(DWORD keyState)
Definition: qdnd_win.cpp:332
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
static QDragManager * self()
Definition: qdnd.cpp:163
QMimeData * data
Definition: qdnd_p.h:179
QDropData * dropData
Definition: qdnd_p.h:251
The QDragEnterEvent class provides an event which is sent to a widget when a drag and drop action ent...
Definition: qevent.h:555
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
DWORD lastKeyState
Definition: qdnd_p.h:307
DWORD chosenEffect
Definition: qdnd_p.h:306
QDragPrivate * dragPrivate() const
Definition: qdnd_p.h:231
Qt::KeyboardModifiers toQtKeyboardModifiers(DWORD keyState)
Definition: qdnd_win.cpp:318

◆ STDMETHOD_() [1/2]

QOleDropTarget::STDMETHOD_ ( ULONG  ,
AddRef   
)

◆ STDMETHOD_() [2/2]

QOleDropTarget::STDMETHOD_ ( ULONG  ,
Release   
)

Properties

◆ answerRect

QRect QOleDropTarget::answerRect
private

Definition at line 304 of file qdnd_p.h.

Referenced by DragOver(), and sendDragEnterEvent().

◆ chosenEffect

DWORD QOleDropTarget::chosenEffect
private

Definition at line 306 of file qdnd_p.h.

Referenced by DragEnter(), DragOver(), Drop(), and sendDragEnterEvent().

◆ currentWidget

QPointer<QWidget> QOleDropTarget::currentWidget
private

Definition at line 303 of file qdnd_p.h.

Referenced by DragLeave(), DragOver(), and sendDragEnterEvent().

◆ lastKeyState

DWORD QOleDropTarget::lastKeyState
private

Definition at line 307 of file qdnd_p.h.

Referenced by DragOver(), Drop(), and sendDragEnterEvent().

◆ lastPoint

QPoint QOleDropTarget::lastPoint
private

Definition at line 305 of file qdnd_p.h.

Referenced by DragOver(), Drop(), and sendDragEnterEvent().

◆ m_refs

ULONG QOleDropTarget::m_refs
private

Definition at line 301 of file qdnd_p.h.

Referenced by QOleDropTarget(), and QueryInterface().

◆ widget

QWidget* QOleDropTarget::widget
private

Definition at line 302 of file qdnd_p.h.

Referenced by DragEnter(), DragLeave(), DragOver(), Drop(), and releaseQt().


The documentation for this class was generated from the following files: