bool CTextObject::AcceptDataFormat(IDataObject* pDataObject)
{
	if (pDataObject == NULL)
		return false;
	CLIPFORMAT cfFormat = GetDataFormat(pDataObject);
	return (cfFormat != CLIPFORMAT(0));
}
Exemple #2
0
QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP
QWindowsOleDropTarget::Drop(LPDATAOBJECT pDataObj, DWORD grfKeyState,
                            POINTL pt, LPDWORD pdwEffect)
{
    if (IDropTargetHelper* dh = QWindowsDrag::instance()->dropHelper())
        dh->Drop(pDataObj, reinterpret_cast<POINT*>(&pt), *pdwEffect);

    qCDebug(lcQpaMime) << __FUNCTION__ << ' ' << m_window
        << "keys=" << grfKeyState << "pt=" << pt.x << ',' << pt.y;

    m_lastPoint = QWindowsGeometryHint::mapFromGlobal(m_window, QPoint(pt.x,pt.y));
    // grfKeyState does not all ways contain button state in the drop
    QGuiApplicationPrivate::mouse_buttons = toQtMouseButtons(m_lastKeyState);
    QGuiApplicationPrivate::modifier_buttons = toQtKeyboardModifiers(grfKeyState);

    QWindowsDrag *windowsDrag = QWindowsDrag::instance();

    const QPlatformDropQtResponse response =
        QWindowSystemInterface::handleDrop(m_window, windowsDrag->dropData(),
                                           m_lastPoint,
                                           translateToQDragDropActions(*pdwEffect));

    QGuiApplicationPrivate::mouse_buttons = toQtMouseButtons(grfKeyState);
    m_lastKeyState = grfKeyState;

    if (response.isAccepted()) {
        const Qt::DropAction action = response.acceptedAction();
        if (action == Qt::MoveAction || action == Qt::TargetMoveAction) {
            if (action == Qt::MoveAction)
                m_chosenEffect = DROPEFFECT_MOVE;
            else
                m_chosenEffect = DROPEFFECT_COPY;
            HGLOBAL hData = GlobalAlloc(0, sizeof(DWORD));
            if (hData) {
                DWORD *moveEffect = reinterpret_cast<DWORD *>(GlobalLock(hData));
                *moveEffect = DROPEFFECT_MOVE;
                GlobalUnlock(hData);
                STGMEDIUM medium;
                memset(&medium, 0, sizeof(STGMEDIUM));
                medium.tymed = TYMED_HGLOBAL;
                medium.hGlobal = hData;
                FORMATETC format;
                format.cfFormat = CLIPFORMAT(RegisterClipboardFormat(CFSTR_PERFORMEDDROPEFFECT));
                format.tymed = TYMED_HGLOBAL;
                format.ptd = 0;
                format.dwAspect = 1;
                format.lindex = -1;
                windowsDrag->dropDataObject()->SetData(&format, &medium, true);
            }
        } else {
            m_chosenEffect = translateToWinDragEffects(action);
        }
    } else {
        m_chosenEffect = DROPEFFECT_NONE;
    }
    *pdwEffect = m_chosenEffect;

    windowsDrag->releaseDropDataObject();
    return NOERROR;
}
void _Copy<FORMATETC>::init(FORMATETC* p)
{
	p->cfFormat = CLIPFORMAT(0);
	p->dwAspect = DVASPECT_CONTENT;
	p->lindex = -1;
	p->ptd = NULL;
	p->tymed = TYMED_NULL;
}
CLIPFORMAT CTextObject::GetDataFormat(IDataObject* pDataObject)
{
	CLIPFORMAT cfFormat;
#ifdef _UNICODE
	if (CheckDataFormat(pDataObject, CF_UNICODETEXT))
		cfFormat = CF_UNICODETEXT;
	else if (CheckDataFormat(pDataObject, CF_TEXT))
		cfFormat = CF_TEXT;
	else
		cfFormat = CLIPFORMAT(0);
#else
	if (CheckDataFormat(pDataObject, CF_TEXT))
		cfFormat = CF_TEXT;
	else if (CheckDataFormat(pDataObject, CF_UNICODETEXT))
		cfFormat = CF_UNICODETEXT;
	else
		cfFormat = CLIPFORMAT(0);
#endif
	return cfFormat;
}
bool CTextObject::SetObjectText(IDataObject* pDataObject)
{
	if (pDataObject == NULL)
		return false;
	CLIPFORMAT cfFormat = GetDataFormat(pDataObject);
	if (cfFormat == CLIPFORMAT(0))
		return false;
	FORMATETC format;
	format.cfFormat = cfFormat;
	format.dwAspect = DVASPECT_CONTENT;
	format.lindex = -1;
	format.ptd = NULL;
	format.tymed = SUPPORTED_MEDIUM_TYPES;
	STGMEDIUM stgm;
	stgm.tymed = TYMED_NULL;
	stgm.pUnkForRelease = NULL;
	HRESULT hRes = pDataObject->GetData(&format, &stgm);
	if (FAILED(hRes))
		return false;
	hRes = SetData(&format, &stgm, TRUE);
	return SUCCEEDED(hRes);
}