Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes
CDropTarget Class Reference

#include <DropTarget.h>

List of all members.

Public Member Functions

 CDropTarget ()
virtual ~CDropTarget ()
 CIPtr (IDataObject) m_spDataObject
void SetOwner (CMozillaBrowser *pOwner)
HRESULT GetURLFromFile (const TCHAR *pszFile, tstring &szURL)
virtual HRESULT STDMETHODCALLTYPE DragEnter (IDataObject __RPC_FAR *pDataObj, DWORD grfKeyState, POINTL pt, DWORD __RPC_FAR *pdwEffect)
virtual HRESULT STDMETHODCALLTYPE DragOver (DWORD grfKeyState, POINTL pt, DWORD __RPC_FAR *pdwEffect)
virtual HRESULT STDMETHODCALLTYPE DragLeave (void)
virtual HRESULT STDMETHODCALLTYPE Drop (IDataObject __RPC_FAR *pDataObj, DWORD grfKeyState, POINTL pt, DWORD __RPC_FAR *pdwEffect)

Public Attributes

CMozillaBrowser * m_pOwner

Detailed Description

Definition at line 45 of file DropTarget.h.


Constructor & Destructor Documentation

Definition at line 62 of file DropTarget.cpp.

{
    m_pOwner = NULL;
}

Definition at line 68 of file DropTarget.cpp.

{
}

Member Function Documentation

CDropTarget::CIPtr ( IDataObject  )

Here is the caller graph for this function:

HRESULT STDMETHODCALLTYPE CDropTarget::DragEnter ( IDataObject __RPC_FAR *  pDataObj,
DWORD  grfKeyState,
POINTL  pt,
DWORD __RPC_FAR *  pdwEffect 
) [virtual]

Definition at line 123 of file DropTarget.cpp.

{
    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
    FORMATETC formatetc;
    memset(&formatetc, 0, sizeof(formatetc));
    formatetc.dwAspect = DVASPECT_CONTENT;
    formatetc.lindex = -1;
    formatetc.tymed = TYMED_HGLOBAL;

    // Test if the data object contains a text URL format
    formatetc.cfFormat = g_cfURL;
    if (pDataObj->QueryGetData(&formatetc) == S_OK)
    {
        m_spDataObject = pDataObj;
        *pdwEffect = DROPEFFECT_LINK;
        return S_OK;
    }

    // Test if the data object contains a file name
    formatetc.cfFormat = g_cfFileName;
    if (pDataObj->QueryGetData(&formatetc) == S_OK)
    {
        m_spDataObject = pDataObj;
        *pdwEffect = DROPEFFECT_LINK;
        return S_OK;
    }
    
    // Test if the data object contains a wide character file name
    formatetc.cfFormat = g_cfFileName;
    if (pDataObj->QueryGetData(&formatetc) == S_OK)
    {
        m_spDataObject = pDataObj;
        *pdwEffect = DROPEFFECT_LINK;
        return S_OK;
    }

    // If we got here, then the format is not supported
    *pdwEffect = DROPEFFECT_NONE;
    return S_OK;
}

Here is the call graph for this function:

HRESULT STDMETHODCALLTYPE CDropTarget::DragLeave ( void  ) [virtual]

Definition at line 189 of file DropTarget.cpp.

{
    if (m_spDataObject)
    {
        m_spDataObject.Release();
    }
    return S_OK;
}
HRESULT STDMETHODCALLTYPE CDropTarget::DragOver ( DWORD  grfKeyState,
POINTL  pt,
DWORD __RPC_FAR *  pdwEffect 
) [virtual]

Definition at line 177 of file DropTarget.cpp.

{
    if (pdwEffect == NULL)
    {
        NG_ASSERT(0);
        return E_INVALIDARG;
    }
    *pdwEffect = m_spDataObject ? DROPEFFECT_LINK : DROPEFFECT_NONE;
    return S_OK;
}
HRESULT STDMETHODCALLTYPE CDropTarget::Drop ( IDataObject __RPC_FAR *  pDataObj,
DWORD  grfKeyState,
POINTL  pt,
DWORD __RPC_FAR *  pdwEffect 
) [virtual]

Definition at line 199 of file DropTarget.cpp.

{
    if (pdwEffect == NULL)
    {
        NG_ASSERT(0);
        return E_INVALIDARG;
    }
    if (m_spDataObject == NULL)
    {
        *pdwEffect = DROPEFFECT_NONE;
        return S_OK;
    }

    *pdwEffect = DROPEFFECT_LINK;

    // Get the URL from the data object
    BSTR bstrURL = NULL;
    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;

    // Does the data object contain a URL?
    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;
            bstrURL = SysAllocString(A2OLE(pszURL));
        }
        GlobalUnlock(stgmedium.hGlobal);
        goto finish;
    }

    // Does the data object point to a file?
    formatetc.cfFormat = g_cfFileName;
    if (m_spDataObject->GetData(&formatetc, &stgmedium) == S_OK)
    {
        USES_CONVERSION;
        NG_ASSERT(stgmedium.tymed == TYMED_HGLOBAL);
        NG_ASSERT(stgmedium.hGlobal);
        tstring szURL;
        char *pszURLFile = (char *) GlobalLock(stgmedium.hGlobal);
        NG_TRACE("File \"%s\" dragged over control\n", pszURLFile);
        if (SUCCEEDED(GetURLFromFile(A2T(pszURLFile), szURL)))
        {
            bstrURL = SysAllocString(T2OLE(szURL.c_str()));
        }
        GlobalUnlock(stgmedium.hGlobal);
        goto finish;
    }
    
    // Does the data object point to a wide character file?
    formatetc.cfFormat = g_cfFileNameW;
    if (m_spDataObject->GetData(&formatetc, &stgmedium) == S_OK)
    {
        USES_CONVERSION;
        NG_ASSERT(stgmedium.tymed == TYMED_HGLOBAL);
        NG_ASSERT(stgmedium.hGlobal);
        tstring szURL;
        WCHAR *pszURLFile = (WCHAR *) GlobalLock(stgmedium.hGlobal);
        NG_TRACE("File \"%s\" dragged over control\n", W2A(pszURLFile));
        if (SUCCEEDED(GetURLFromFile(W2T(pszURLFile), szURL)))
        {
            USES_CONVERSION;
            bstrURL = SysAllocString(T2OLE(szURL.c_str()));
        }
        GlobalUnlock(stgmedium.hGlobal);
        goto finish;
    }

finish:
    // If we got a URL, browse there!
    if (bstrURL)
    {
        m_pOwner->Navigate(bstrURL, NULL, NULL, NULL, NULL);
        SysFreeString(bstrURL);
    }

    ReleaseStgMedium(&stgmedium);
    m_spDataObject.Release();

    return S_OK;
}

Here is the call graph for this function:

HRESULT CDropTarget::GetURLFromFile ( const TCHAR pszFile,
tstring szURL 
)

Definition at line 79 of file DropTarget.cpp.

{
    USES_CONVERSION;
    CIPtr(IUniformResourceLocator) spUrl;

    // Let's see if the file is an Internet Shortcut...
    HRESULT hr = CoCreateInstance (CLSID_InternetShortcut, NULL, CLSCTX_INPROC_SERVER, IID_IUniformResourceLocator, (void **) &spUrl);
    if (spUrl == NULL)
    {
        return E_FAIL;
    }

    // Get the IPersistFile interface
    CIPtr(IPersistFile) spFile = spUrl;
    if (spFile == NULL)
    {
        return E_FAIL;
    }

    // Initialise the URL object from the filename
    LPSTR lpTemp = NULL;
    if (FAILED(spFile->Load(T2OLE(pszFile), STGM_READ)) ||
        FAILED(spUrl->GetURL(&lpTemp)))
    {
        return E_FAIL;
    }

    // Free the memory
    CIPtr(IMalloc) spMalloc;
    if (FAILED(SHGetMalloc(&spMalloc)))
    {
        return E_FAIL;
    }
    
    // Copy the URL & cleanup
    szURL = A2T(lpTemp);
    spMalloc->Free(lpTemp);

    return S_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void CDropTarget::SetOwner ( CMozillaBrowser *  pOwner)

Definition at line 73 of file DropTarget.cpp.

{
    m_pOwner = pOwner;
}

Member Data Documentation

CMozillaBrowser* CDropTarget::m_pOwner

Definition at line 60 of file DropTarget.h.


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