Added simple working implementation of drag and drop. Control now accepts a URL dragged and dropped from the IE address bar.

This commit is contained in:
locka%iol.ie 1999-10-14 07:43:50 +00:00
Родитель c4a9e1b228
Коммит 847e3a4dae
2 изменённых файлов: 116 добавлений и 6 удалений

Просмотреть файл

@ -19,8 +19,15 @@
#include "stdafx.h"
#include "DropTarget.h"
#ifndef CFSTR_SHELLURL
#define CFSTR_SHELLURL _T("UniformResourceLocator")
#endif
static const UINT g_cfURL = RegisterClipboardFormat(CFSTR_SHELLURL);
CDropTarget::CDropTarget()
{
m_pOwner = NULL;
}
@ -29,35 +36,127 @@ CDropTarget::~CDropTarget()
}
void CDropTarget::SetOwner(CMozillaBrowser *pOwner)
{
m_pOwner = pOwner;
}
///////////////////////////////////////////////////////////////////////////////
// IDropTarget implementation
HRESULT STDMETHODCALLTYPE CDropTarget::DragEnter(/* [unique][in] */ IDataObject __RPC_FAR *pDataObj, /* [in] */ DWORD grfKeyState, /* [in] */ POINTL pt, /* [out][in] */ DWORD __RPC_FAR *pdwEffect)
{
// TODO
*pdwEffect = DROPEFFECT_NONE;
if (pdwEffect == NULL || pDataObj == NULL)
{
NG_ASSERT(0);
return E_INVALIDARG;
}
if (m_spDataObject != NULL)
{
NG_ASSERT(0);
return E_UNEXPECTED;
}
// TODO process Internet Shortcuts (*.URL) files
// Test if the data object supports types we can handle
BOOL bSupported = FALSE;
FORMATETC formatetc;
memset(&formatetc, 0, sizeof(formatetc));
formatetc.dwAspect = DVASPECT_CONTENT;
formatetc.lindex = -1;
formatetc.tymed = TYMED_HGLOBAL;
formatetc.cfFormat = g_cfURL;
if (pDataObj->QueryGetData(&formatetc) == S_OK)
{
bSupported = TRUE;
}
if (bSupported)
{
m_spDataObject = pDataObj;
*pdwEffect = DROPEFFECT_LINK;
}
else
{
*pdwEffect = DROPEFFECT_NONE;
}
return S_OK;
}
HRESULT STDMETHODCALLTYPE CDropTarget::DragOver(/* [in] */ DWORD grfKeyState, /* [in] */ POINTL pt, /* [out][in] */ DWORD __RPC_FAR *pdwEffect)
{
// TODO
*pdwEffect = DROPEFFECT_NONE;
if (pdwEffect == NULL)
{
NG_ASSERT(0);
return E_INVALIDARG;
}
*pdwEffect = m_spDataObject ? DROPEFFECT_LINK : DROPEFFECT_NONE;
return S_OK;
}
HRESULT STDMETHODCALLTYPE CDropTarget::DragLeave(void)
{
if (m_spDataObject)
{
m_spDataObject.Release();
}
return S_OK;
}
HRESULT STDMETHODCALLTYPE CDropTarget::Drop(/* [unique][in] */ IDataObject __RPC_FAR *pDataObj, /* [in] */ DWORD grfKeyState, /* [in] */ POINTL pt, /* [out][in] */ DWORD __RPC_FAR *pdwEffect)
{
// TODO
*pdwEffect = DROPEFFECT_NONE;
if (pdwEffect == NULL)
{
NG_ASSERT(0);
return E_INVALIDARG;
}
if (m_spDataObject == NULL)
{
*pdwEffect = DROPEFFECT_NONE;
return S_OK;
}
*pdwEffect = DROPEFFECT_LINK;
// TODO process Internet Shortcuts (*.URL) files
// Get the URL from the data object
FORMATETC formatetc;
STGMEDIUM stgmedium;
memset(&formatetc, 0, sizeof(formatetc));
memset(&stgmedium, 0, sizeof(formatetc));
formatetc.dwAspect = DVASPECT_CONTENT;
formatetc.lindex = -1;
formatetc.tymed = TYMED_HGLOBAL;
formatetc.cfFormat = g_cfURL;
if (m_spDataObject->GetData(&formatetc, &stgmedium) == S_OK)
{
NG_ASSERT(stgmedium.tymed == TYMED_HGLOBAL);
NG_ASSERT(stgmedium.hGlobal);
char *pszURL = (char *) GlobalLock(stgmedium.hGlobal);
NG_TRACE("URL \"%s\" dragged over control\n", pszURL);
// Browse to the URL
if (m_pOwner)
{
USES_CONVERSION;
BSTR bstrURL = SysAllocString(A2OLE(pszURL));
m_pOwner->Navigate(bstrURL, NULL, NULL, NULL, NULL);
SysFreeString(bstrURL);
}
GlobalUnlock(stgmedium.hGlobal);
ReleaseStgMedium(&stgmedium);
}
m_spDataObject.Release();
return S_OK;
}

Просмотреть файл

@ -18,6 +18,8 @@
#ifndef DROPTARGET_H
#define DROPTARGET_H
#include "MozillaBrowser.h"
// Simple drop target implementation
class CDropTarget : public CComObjectRootEx<CComSingleThreadModel>,
@ -31,6 +33,15 @@ BEGIN_COM_MAP(CDropTarget)
COM_INTERFACE_ENTRY(IDropTarget)
END_COM_MAP()
// Data object currently being dragged
CIPtr(IDataObject) m_spDataObject;
// Owner of this object
CMozillaBrowser *m_pOwner;
// Sets the owner of this object
void SetOwner(CMozillaBrowser *pOwner);
// IDropTarget
virtual HRESULT STDMETHODCALLTYPE DragEnter(/* [unique][in] */ IDataObject __RPC_FAR *pDataObj, /* [in] */ DWORD grfKeyState, /* [in] */ POINTL pt, /* [out][in] */ DWORD __RPC_FAR *pdwEffect);
virtual HRESULT STDMETHODCALLTYPE DragOver(/* [in] */ DWORD grfKeyState, /* [in] */ POINTL pt, /* [out][in] */ DWORD __RPC_FAR *pdwEffect);