4 #include "ecore_win32_dnd_enumformatetc.h"
9 CEnumFormatEtc::CEnumFormatEtc(FORMATETC *format_etc, int formats_num)
12 , formats_num_(formats_num)
13 , format_etc_(new FORMATETC[formats_num])
15 // make a new copy of each FORMATETC structure
16 for (unsigned int i = 0; i < formats_num_; i++)
18 DeepCopyFormatEtc(&format_etc_[i], &format_etc[i]);
22 CEnumFormatEtc::~CEnumFormatEtc()
26 // first free any DVTARGETDEVICE structures
27 for (ULONG i = 0; i < formats_num_; i++)
29 if (format_etc_[i].ptd)
30 CoTaskMemFree(format_etc_[i].ptd);
33 // now free the main array
40 ULONG __stdcall CEnumFormatEtc::AddRef(void)
42 // increment object reference count
43 return InterlockedIncrement(&ref_count_);
46 ULONG __stdcall CEnumFormatEtc::Release(void)
48 // decrement object reference count
49 LONG count = InterlockedDecrement(&ref_count_);
62 HRESULT __stdcall CEnumFormatEtc::QueryInterface(REFIID iid, void **ppvObject)
64 // check to see what interface has been requested
65 if ((iid == IID_IEnumFORMATETC) || (iid == IID_IUnknown))
80 HRESULT CEnumFormatEtc::Reset(void)
86 HRESULT CEnumFormatEtc::Skip(ULONG celt)
89 return (index_ <= formats_num_) ? S_OK : S_FALSE;
92 HRESULT CEnumFormatEtc::Clone(IEnumFORMATETC **ppEnumFormatEtc)
96 // make a duplicate enumerator
97 hResult = CreateEnumFormatEtc(formats_num_, format_etc_, ppEnumFormatEtc);
101 // manually set the index state
102 ((CEnumFormatEtc *)*ppEnumFormatEtc)->index_ = index_;
108 HRESULT CEnumFormatEtc::Next(ULONG celt, FORMATETC *pFormatEtc, ULONG *pceltFetched)
112 // validate arguments
113 if ((celt == 0) || (pFormatEtc == 0))
116 // copy the FORMATETC structures into the caller's buffer
117 while (index_ < formats_num_ && copied < celt)
119 DeepCopyFormatEtc(&pFormatEtc[copied], &format_etc_[index_]);
125 if (pceltFetched != 0)
126 *pceltFetched = copied;
128 // did we copy all that was requested?
129 return (copied == celt) ? S_OK : S_FALSE;
132 // external functions
134 void DeepCopyFormatEtc(FORMATETC *dest, FORMATETC *source)
136 // copy the source FORMATETC into dest
141 // allocate memory for the DVTARGETDEVICE if necessary
142 dest->ptd = (DVTARGETDEVICE*)CoTaskMemAlloc(sizeof(DVTARGETDEVICE));
144 // copy the contents of the source DVTARGETDEVICE into dest->ptd
145 *(dest->ptd) = *(source->ptd);
149 HRESULT CreateEnumFormatEtc(UINT cfmt, FORMATETC *afmt, IEnumFORMATETC **ppEnumFormatEtc)
151 if((cfmt == 0) || (afmt == 0) || (ppEnumFormatEtc == 0))
154 *ppEnumFormatEtc = new CEnumFormatEtc(afmt, cfmt);
156 return (*ppEnumFormatEtc) ? S_OK : E_OUTOFMEMORY;