/*
*********************************************************************
*
*	The Essence of OLE
*
*	Source code sample
*
*	Copyright (c) 1996, Rolling Thunder Computing, Ipswich MA
*
*	e-mail: essence@rollthunder.com
*	CompuServe: 73540.3430
*	Web: http://www.rollthunder.com
*
*	File Name: CDROPSRC.CPP
*
*	Purpose: Implementation of IDropSource interface
*
*********************************************************************
*/


#include <windows.h>
#include "cdropsrc.h"


extern HWND hMainWnd ;


CDropSource::CDropSource(void)
{
    m_RefCount = 1 ;
    return;
}

CDropSource::~CDropSource(void)
{
    return;
}




/*
 * CDropSource::QueryInterface
 * CDropSource::AddRef
 * CDropSource::Release
 *
 * Purpose:
 *  IUnknown members for CDropSource object.
 */

STDMETHODIMP CDropSource::QueryInterface(REFIID riid, LPVOID FAR *ppv)
{

    if (IsEqualIID(riid, IID_IUnknown)
        || IsEqualIID(riid, IID_IDropSource))
	{
	    *ppv = (LPVOID)this;  
        AddRef();
        return S_OK ;
    }
    else
    {
    	*ppv = NULL;       
    	return E_NOINTERFACE ;
    }
}


STDMETHODIMP_(ULONG) CDropSource::AddRef(void)
{
    return ++ m_RefCount;
}

STDMETHODIMP_(ULONG) CDropSource::Release(void)
{
	m_RefCount -- ;

    if (m_RefCount == 0)
	{
        delete this;
		return 0 ;
	}

    return m_RefCount ;
}


STDMETHODIMP CDropSource::QueryContinueDrag(BOOL fEsc, DWORD grfKeyState)
{
    if (fEsc)
    {
        return DRAGDROP_S_CANCEL ;
    }

    if (!(grfKeyState & MK_LBUTTON))
    {
        return DRAGDROP_S_DROP ;
    }

    return NOERROR;
}


/*
STEP 7
Have some fun with cursors.
*/


STDMETHODIMP CDropSource::GiveFeedback(DWORD dwEffect)
{
	
    return DRAGDROP_S_USEDEFAULTCURSORS ;
}
