Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

268 lines
6.5 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. /* File: format.cpp
  3. Description: Implementation for class EnumFORMATETC.
  4. Moved from original location in dataobj.cpp (deleted from project).
  5. Revision History:
  6. Date Description Programmer
  7. -------- --------------------------------------------------- ----------
  8. 05/28/97 Initial creation. BrianAu
  9. */
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #include "pch.h"
  12. #pragma hdrstop
  13. #include "format.h"
  14. EnumFORMATETC::EnumFORMATETC(
  15. UINT cFormats,
  16. LPFORMATETC prgFormats
  17. ) : m_cRef(0),
  18. m_cFormats(0),
  19. m_iCurrent(0),
  20. m_prgFormats(NULL)
  21. {
  22. DBGTRACE((DM_DRAGDROP, DL_HIGH, TEXT("EnumFORMATETC::EnumFORMATETC")));
  23. DBGPRINT((DM_DRAGDROP, DL_HIGH, TEXT("\tthis = 0x%08X"), this));
  24. m_prgFormats = new FORMATETC[m_cFormats = cFormats];
  25. for (UINT i = 0; i < m_cFormats; i++)
  26. {
  27. m_prgFormats[i] = prgFormats[i];
  28. }
  29. }
  30. EnumFORMATETC::EnumFORMATETC(
  31. const EnumFORMATETC& ef
  32. ) : m_cRef(0),
  33. m_cFormats(ef.m_cFormats),
  34. m_iCurrent(0),
  35. m_prgFormats(NULL)
  36. {
  37. DBGTRACE((DM_DRAGDROP, DL_HIGH, TEXT("EnumFORMATETC::EnumFORMATETC (Copy)")));
  38. DBGPRINT((DM_DRAGDROP, DL_HIGH, TEXT("\tthis = 0x%08X"), this));
  39. m_prgFormats = new FORMATETC[m_cFormats];
  40. for (UINT i = 0; i < m_cFormats; i++)
  41. {
  42. m_prgFormats[i] = ef.m_prgFormats[i];
  43. }
  44. }
  45. EnumFORMATETC::~EnumFORMATETC(
  46. VOID
  47. )
  48. {
  49. DBGTRACE((DM_DRAGDROP, DL_HIGH, TEXT("EnumFORMATETC::~EnumFORMATETC")));
  50. DBGPRINT((DM_DRAGDROP, DL_HIGH, TEXT("\tthis = 0x%08X"), this));
  51. if (NULL != m_prgFormats)
  52. delete[] m_prgFormats;
  53. }
  54. ///////////////////////////////////////////////////////////////////////////////
  55. /* Function: EnumFORMATETC::QueryInterface
  56. Description: Returns an interface pointer to the object's IUnknown or
  57. IEnumFORMATETC interface. Only IID_IUnknown and
  58. IID_IEnumFORMATETC are recognized. The object referenced by the
  59. returned interface pointer is uninitialized. The recipient of the
  60. pointer must call Initialize() before the object is usable.
  61. Arguments:
  62. riid - Reference to requested interface ID.
  63. ppvOut - Address of interface pointer variable to accept interface ptr.
  64. Returns:
  65. NO_ERROR - Success.
  66. E_NOINTERFACE - Requested interface not supported.
  67. E_INVALIDARG - ppvOut argument was NULL.
  68. Revision History:
  69. Date Description Programmer
  70. -------- --------------------------------------------------- ----------
  71. 09/25/96 Initial creation. BrianAu
  72. */
  73. ///////////////////////////////////////////////////////////////////////////////
  74. STDMETHODIMP
  75. EnumFORMATETC::QueryInterface(
  76. REFIID riid,
  77. LPVOID *ppvOut
  78. )
  79. {
  80. HRESULT hResult = E_NOINTERFACE;
  81. if (NULL == ppvOut)
  82. return E_INVALIDARG;
  83. *ppvOut = NULL;
  84. if (IID_IUnknown == riid || IID_IEnumFORMATETC == riid)
  85. {
  86. *ppvOut = this;
  87. ((LPUNKNOWN)*ppvOut)->AddRef();
  88. hResult = NOERROR;
  89. }
  90. return hResult;
  91. }
  92. ///////////////////////////////////////////////////////////////////////////////
  93. /* Function: EnumFORMATETC::AddRef
  94. Description: Increments object reference count.
  95. Arguments: None.
  96. Returns: New reference count value.
  97. Revision History:
  98. Date Description Programmer
  99. -------- --------------------------------------------------- ----------
  100. 09/25/96 Initial creation. BrianAu
  101. */
  102. ///////////////////////////////////////////////////////////////////////////////
  103. STDMETHODIMP_(ULONG)
  104. EnumFORMATETC::AddRef(
  105. VOID
  106. )
  107. {
  108. ULONG ulReturn = m_cRef + 1;
  109. DBGPRINT((DM_COM, DL_HIGH, TEXT("EnumFORMATETC::AddRef, 0x%08X %d -> %d\n"),
  110. this, ulReturn - 1, ulReturn));
  111. InterlockedIncrement(&m_cRef);
  112. return ulReturn;
  113. }
  114. ///////////////////////////////////////////////////////////////////////////////
  115. /* Function: EnumFORMATETC::Release
  116. Description: Decrements object reference count. If count drops to 0,
  117. object is deleted.
  118. Arguments: None.
  119. Returns: New reference count value.
  120. Revision History:
  121. Date Description Programmer
  122. -------- --------------------------------------------------- ----------
  123. 09/25/96 Initial creation. BrianAu
  124. */
  125. ///////////////////////////////////////////////////////////////////////////////
  126. STDMETHODIMP_(ULONG)
  127. EnumFORMATETC::Release(
  128. VOID
  129. )
  130. {
  131. ULONG ulReturn = m_cRef - 1;
  132. DBGPRINT((DM_COM, DL_HIGH, TEXT("EnumFORMATETC::Release, 0x%08X %d -> %d\n"),
  133. this, ulReturn + 1, ulReturn));
  134. if (InterlockedDecrement(&m_cRef) == 0)
  135. {
  136. delete this;
  137. ulReturn = 0;
  138. }
  139. return ulReturn;
  140. }
  141. STDMETHODIMP
  142. EnumFORMATETC::Next(
  143. DWORD cFormats,
  144. LPFORMATETC pFormats,
  145. LPDWORD pcReturned
  146. )
  147. {
  148. HRESULT hResult = S_OK;
  149. DBGPRINT((DM_DRAGDROP, DL_MID, TEXT("EnumFORMATETC::Next %d"), cFormats));
  150. DWORD iFormats = 0;
  151. if (NULL == pFormats)
  152. return E_INVALIDARG;
  153. while(cFormats-- > 0)
  154. {
  155. if (m_iCurrent < m_cFormats)
  156. {
  157. *(pFormats + iFormats++) = m_prgFormats[m_iCurrent++];
  158. }
  159. else
  160. {
  161. hResult = S_FALSE;
  162. break;
  163. }
  164. }
  165. if (NULL != pcReturned)
  166. *pcReturned = iFormats;
  167. return hResult;
  168. }
  169. STDMETHODIMP
  170. EnumFORMATETC::Skip(
  171. DWORD cFormats
  172. )
  173. {
  174. DBGPRINT((DM_DRAGDROP, DL_MID, TEXT("EnumFORMATETC::Skip %d"), cFormats));
  175. while((cFormats-- > 0) && (m_iCurrent < m_cFormats))
  176. m_iCurrent++;
  177. return cFormats == 0 ? S_OK : S_FALSE;
  178. }
  179. STDMETHODIMP
  180. EnumFORMATETC::Reset(
  181. VOID
  182. )
  183. {
  184. DBGPRINT((DM_DRAGDROP, DL_MID, TEXT("EnumFORMATETC::Reset")));
  185. m_iCurrent = 0;
  186. return S_OK;
  187. }
  188. STDMETHODIMP
  189. EnumFORMATETC::Clone(
  190. IEnumFORMATETC **ppvOut
  191. )
  192. {
  193. HRESULT hResult = NO_ERROR;
  194. try
  195. {
  196. EnumFORMATETC *pNew = new EnumFORMATETC(*this);
  197. DBGPRINT((DM_DRAGDROP, DL_MID, TEXT("EnumFORMATETC::Clone")));
  198. hResult = pNew->QueryInterface(IID_IEnumFORMATETC, (LPVOID *)ppvOut);
  199. }
  200. catch(CAllocException& e)
  201. {
  202. hResult = E_OUTOFMEMORY;
  203. }
  204. return hResult;
  205. }