/*
*********************************************************************
*
*	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: CTXTDATA.CPP
*
*	Purpose: Implementation of simple IDataObject containing text
*
*********************************************************************
*/

#include <windows.h>
#include "ctxtdata.h"
#include "cenum.h"

FORMATETC feArray []= {
						{ CF_TEXT, NULL, DVASPECT_CONTENT,  -1, TYMED_HGLOBAL },
					 	{ CF_METAFILEPICT, NULL, DVASPECT_CONTENT,  -1, TYMED_MFPICT }								 
					  };
/*
constructor/destructor 
*/

CTextData::CTextData(LPSTR lpString)
{
/*
STEP 1
Allocate memory and save string in constructor
*/
	
	m_RefCount = 1 ; 
	
    return;
}


CTextData::~CTextData(void)
{

/*
STEP 1
Free memory in destructor
*/

    return;
}




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


HRESULT CTextData::QueryInterface(REFIID riid, LPVOID FAR *ppv)
{
    if (IsEqualIID(riid, IID_IUnknown)
        || IsEqualIID(riid, IID_IDataObject))
    {
        *ppv = (LPVOID)this;  
        AddRef();
        return S_OK ;
    }
    else
    {
    	*ppv = NULL;       
    	return E_NOINTERFACE ;
    }
}


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


STDMETHODIMP_(ULONG) CTextData::Release(void)
{
    
    m_RefCount -- ;
    
    if (m_RefCount == 0L)
    {
        delete this;
    }	return 0 ;

    return m_RefCount ;
}


/*
STEP 3
Implement GetData( ) method.

GetData Method.  Caller is asking if we can supply data in a given 
format and medium
*/

STDMETHODIMP CTextData::GetData (LPFORMATETC lpfe, LPSTGMEDIUM lpstg) 
{


/*
User asked for a format that we couldn't supply.  Return error code.
*/
	
	return DATA_E_FORMATETC ;
}


/*
STEP 2
Implement QueryGetData( ) method
*/


STDMETHODIMP CTextData::QueryGetData (LPFORMATETC lpfe) 
{

	return DATA_E_FORMATETC ;
}

/*
STEP 4
Implement EnumFormatEtc( ) method.
*/


STDMETHODIMP CTextData::EnumFormatEtc (DWORD dwDir, LPENUMFORMATETC * lpEnum) 
{
	return S_OK ;
}

/*
Unimplemented members
*/

STDMETHODIMP CTextData::GetDataHere (LPFORMATETC lpfe, LPSTGMEDIUM lpst)
{
	return E_NOTIMPL ;
}

STDMETHODIMP CTextData::GetCanonicalFormatEtc (LPFORMATETC lpout, LPFORMATETC lpin)
{
	return E_NOTIMPL ;
}

STDMETHODIMP CTextData::SetData (LPFORMATETC lpfe, STGMEDIUM * lpst, BOOL fRelease)
{
	return E_NOTIMPL ;
}

STDMETHODIMP CTextData::DAdvise (FORMATETC * lpfe, DWORD dw, LPADVISESINK lpas, 
	DWORD FAR* lpdw) 
{
	return E_NOTIMPL ;
}

STDMETHODIMP CTextData::DUnadvise  (DWORD dw)
{
	return E_NOTIMPL ;
}

STDMETHODIMP CTextData::EnumDAdvise  (LPENUMSTATDATA * lpen)
{
	*lpen = NULL ;
	return E_NOTIMPL ;
}
