📄 dxfrobj.cpp
字号:
return NULL;
}
if( !ped->IsRich() )
{
// plain text case
pdo->_prgFormats[0] = g_rgFETC[iAnsiFETC];
pdo->_prgFormats[1] = g_rgFETC[iUnicodeFETC];
return pdo;
}
// We only offer up the six formats that we know how to handle in GetData.
// The actual values differ somewhat from regular rich text and text
// with embedded objects
if( ped->HasObjects() && pdo->_cch == 1 )
{
if( prg->GetChar(&ch) == NOERROR && ch == WCH_EMBEDDING )
{
COleObject *pobj = ped->_pobjmgr->GetObjectFromCp(pdo->_cpMin);
IUnknown *punk = pobj->GetIUnknown();
if (punk &&
punk->QueryInterface(IID_IOleObject,
(void **) &pdo->_pOleObj) == NOERROR)
{
// have an OLE object; we can offer all OLE formats
// plus RTF
pdo->_prgFormats[0] = g_rgFETC[iEmbObj]; // EmbeddedObject
pdo->_prgFormats[1] = g_rgFETC[iObtDesc]; // ObjectDescriptor
pdo->_prgFormats[2] = g_rgFETC[iMfPict]; // Metafile
pdo->_prgFormats[3] = g_rgFETC[iRtfFETC]; // RTF
pdo->_prgFormats[4] = g_rgFETC[iRtfNoObjs]; // RTF with no objects
pdo->_prgFormats[5] = g_rgFETC[iRtfUtf8]; // RTF in UTF-8
// Get the embedded object formats now
pdo->_hObjDesc =
pdo->GetDataForObjectDescriptor( pdo->_pOleObj,
pobj->GetDvaspect() );
pdo->_pObjStg = pdo->GetDataForEmbeddedObject( pdo->_pOleObj, NULL );
pdo->_hMFPict = (HMETAFILE) OleStdGetMetafilePictFromOleObject(
pdo->_pOleObj,
pobj->GetDvaspect(),
NULL,
NULL);
return pdo;
}
}
}
// regular rich text case
pdo->_prgFormats[0] = g_rgFETC[iRtfFETC]; // RTF
pdo->_prgFormats[1] = g_rgFETC[iRtfNoObjs]; // RTF with no objects
pdo->_prgFormats[2] = g_rgFETC[iRtfAsTextFETC]; // RTF as Text
pdo->_prgFormats[3] = g_rgFETC[iAnsiFETC]; // ANSI plain text
pdo->_prgFormats[4] = g_rgFETC[iUnicodeFETC]; // Unicode plain text
pdo->_prgFormats[5] = g_rgFETC[iRtfUtf8]; // RTF in Utf8
return pdo;
}
/*
* CDataTransferObj::TextToHglobal(hText, tKind)
*
* @mfunc
* Instantiates text on demand for the data object.
*
* @rdesc
* HGLOBAL
*/
HGLOBAL CDataTransferObj::TextToHglobal(
HGLOBAL &hText,
TEXTKIND tKind)
{
TRACEBEGIN(TRCSUBSYSDTE, TRCSCOPEINTERN, "CDataTransferObj::PlainTextToHglobal");
if (hText == NULL)
{
CTxtRange rg(_ped, _cpMin, -_cch);
if (tKind == tPlain)
{
hText = _ped->GetDTE()->UnicodePlainTextFromRange(&rg);
}
else if(_ped->IsRich())
{
LONG lStreamFormat = _lStreamFormat;
if(tKind == tRtfUtf8)
lStreamFormat |= SFF_UTF8;
hText = _ped->GetDTE()->RtfFromRange(&rg, lStreamFormat);
}
}
return hText;
}
//
// CDataTransferObj PRIVATE methods
//
/*
* CDataTransferObj::CDataTransferObj()
*
* @mfunc
* Private constructor
*/
CDataTransferObj::CDataTransferObj( CTxtEdit *ped )
{
TRACEBEGIN(TRCSUBSYSDTE, TRCSCOPEINTERN, "CDataTransferObj::CDataTransferObj");
_ped = ped;
_crefs = 1;
_cTotal = CFETC;
_prgFormats = g_rgFETC;
_cch = 0;
_cObjs = 0;
}
/*
* CDataTransferObj::~CDataTransferObj
*
* @mfunc
* Private destructor
*/
CDataTransferObj::~CDataTransferObj()
{
TRACEBEGIN(TRCSUBSYSDTE, TRCSCOPEINTERN, "CDataTransferObj::~CDataTransferObj");
// No need to monitor notifications any more
CNotifyMgr *pnm;
if( _ped )
{
pnm = _ped->GetNotifyMgr();
if( pnm )
{
pnm->Remove( (ITxNotify *)this );
}
}
if( _prgFormats && _prgFormats != g_rgFETC)
{
delete _prgFormats;
}
if (_pOleObj)
{
_pOleObj->Release();
}
if (_pObjStg)
{
_pObjStg->Release();
}
#ifndef NOMETAFILES
if (_hMFPict)
{
(void) DeleteMetaFile(_hMFPict);
}
#endif
GlobalFree(_hObjDesc);
}
//
// CEnumFormatEtc PUBLIC methods
//
/*
* CEnumFormatEtc::QueryInterface (riid, ppvObj)
*
* @mfunc
* IUnknown method
*
* @rdesc
* HRESULT
*/
STDMETHODIMP CEnumFormatEtc::QueryInterface(
REFIID riid, // @parm Reference to requested interface ID
void ** ppv) // @parm out parm for interface ptr
{
TRACEBEGIN(TRCSUBSYSDTE, TRCSCOPEINTERN, "CEnumFormatEtc::QueryInterface");
HRESULT hresult = E_NOINTERFACE;
*ppv = NULL;
if( IsEqualIID(riid, IID_IUnknown) ||
IsEqualIID(riid, IID_IEnumFORMATETC) )
{
*ppv = this;
AddRef();
hresult = NOERROR;
}
return hresult;
}
/*
* CEnumFormatEtc::AddRef()
*
* @mfunc
* IUnknown method
*
* @rdesc
* ULONG - incremented reference count
*/
STDMETHODIMP_(ULONG) CEnumFormatEtc::AddRef( )
{
TRACEBEGIN(TRCSUBSYSDTE, TRCSCOPEINTERN, "CEnumFormatEtc::AddRef");
return ++_crefs;
}
/*
* CEnumFormatEtc::Release()
*
* @mfunc
* IUnknown method
*
* @rdesc
* ULONG - decremented reference count
*/
STDMETHODIMP_(ULONG) CEnumFormatEtc::Release( )
{
TRACEBEGIN(TRCSUBSYSDTE, TRCSCOPEINTERN, "CEnumFormatEtc::Release");
_crefs--;
if( _crefs == 0 )
{
delete this;
return 0;
}
return _crefs;
}
/*
* CEnumFormatEtc::Next (celt, rgelt, pceltFetched)
*
* @mfunc
* fetches the next [celt] elements in our formatetc collection
*
* @rdesc
* HRESULT
*/
STDMETHODIMP CEnumFormatEtc::Next( ULONG celt, FORMATETC *rgelt,
ULONG *pceltFetched)
{
TRACEBEGIN(TRCSUBSYSDTE, TRCSCOPEINTERN, "CEnumFormatEtc::Next");
HRESULT hresult = NOERROR;
ULONG cFetched;
if( pceltFetched == NULL && celt != 1 )
{
// the spec says that if pceltFetched == NULL, then
// the count of elements to fetch must be 1
return E_INVALIDARG;
}
// we can only grab as many elements as there are left
if( celt > _cTotal - _iCurrent )
{
cFetched = _cTotal - _iCurrent;
hresult = S_FALSE;
}
else
{
cFetched = celt;
}
// Only copy if we have elements to copy
if( cFetched > 0 )
{
memcpy( rgelt, _prgFormats + _iCurrent,
cFetched * sizeof(FORMATETC) );
}
_iCurrent += cFetched;
if( pceltFetched )
{
*pceltFetched = cFetched;
}
return hresult;
}
/*
* CEnumFormatEtc::Skip
*
* @mfunc
* skips the next [celt] formats
*
* @rdesc
* HRESULT
*/
STDMETHODIMP CEnumFormatEtc::Skip( ULONG celt )
{
TRACEBEGIN(TRCSUBSYSDTE, TRCSCOPEINTERN, "CEnumFormatEtc::Skip");
HRESULT hresult = NOERROR;
_iCurrent += celt;
if( _iCurrent > _cTotal )
{
// whoops, skipped too far ahead. Set us to the max limit.
_iCurrent = _cTotal;
hresult = S_FALSE;
}
return hresult;
}
/*
* CEnumFormatEtc::Reset
*
* @mfunc
* resets the seek pointer to zero
*
* @rdesc
* HRESULT
*/
STDMETHODIMP CEnumFormatEtc::Reset( void )
{
TRACEBEGIN(TRCSUBSYSDTE, TRCSCOPEINTERN, "CEnumFormatEtc::Reset");
_iCurrent = 0;
return NOERROR;
}
/*
* CEnumFormatEtc::Clone
*
* @mfunc
* clones the enumerator
*
* @rdesc
* HRESULT
*/
STDMETHODIMP CEnumFormatEtc::Clone( IEnumFORMATETC **ppIEnum )
{
TRACEBEGIN(TRCSUBSYSDTE, TRCSCOPEINTERN, "CEnumFormatEtc::Clone");
return CEnumFormatEtc::Create(_prgFormats, _cTotal, ppIEnum);
}
/*
* CEnumFormatEtc::Create (prgFormats, cTotal, hr)
*
* @mfunc
* creates a new format enumerator
*
* @rdesc
* HRESULT
*
* @devnote
* *copies* the formats passed in. We do this as it simplifies
* memory management under OLE object liveness rules
*/
HRESULT CEnumFormatEtc::Create( FORMATETC *prgFormats, ULONG cTotal,
IEnumFORMATETC **ppenum )
{
TRACEBEGIN(TRCSUBSYSDTE, TRCSCOPEINTERN, "CEnumFormatEtc::Create");
CEnumFormatEtc *penum = new CEnumFormatEtc();
if( penum != NULL )
{
// _iCurrent, _crefs are set in the constructor
if( cTotal > 0 )
{
penum->_prgFormats = new FORMATETC[cTotal];
if( penum->_prgFormats )
{
penum->_cTotal = cTotal;
memcpy(penum->_prgFormats, prgFormats,
cTotal * sizeof(FORMATETC));
*ppenum = penum;
return NOERROR;
}
}
else
{
TRACEERRORSZ("!!Total Formats is <= 0 - was Object initialized correctly?");
delete penum;
*ppenum = NULL;
return E_INVALIDARG;
}
}
return E_OUTOFMEMORY;
}
//
// CEnumFormatEtc PRIVATE methods
//
/*
* CEnumFormatEtc::CEnumFormatEtc()
*
* @mfunc
* Private constructor
*/
CEnumFormatEtc::CEnumFormatEtc()
{
TRACEBEGIN(TRCSUBSYSDTE, TRCSCOPEINTERN, "CEnumFormatEtc::CEnumFormatEtc");
_cTotal = 0;
_crefs = 1;
_prgFormats = NULL;
_iCurrent = 0;
}
/*
* CEnumFormatEtc::~CEnumFormatEtc()
*
* @mfunc
* Private destructor
*/
CEnumFormatEtc::~CEnumFormatEtc( void )
{
TRACEBEGIN(TRCSUBSYSDTE, TRCSCOPEINTERN, "CEnumFormatEtc::~CEnumFormatEtc");
if( _prgFormats )
{
delete _prgFormats;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -