Leaked source code of windows server 2003
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.

263 lines
6.7 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 cRef = InterlockedIncrement(&m_cRef);
  109. DBGPRINT((DM_COM, DL_HIGH, TEXT("EnumFORMATETC::AddRef, 0x%08X %d -> %d\n"), this, cRef - 1, cRef ));
  110. return cRef;
  111. }
  112. ///////////////////////////////////////////////////////////////////////////////
  113. /* Function: EnumFORMATETC::Release
  114. Description: Decrements object reference count. If count drops to 0,
  115. object is deleted.
  116. Arguments: None.
  117. Returns: New reference count value.
  118. Revision History:
  119. Date Description Programmer
  120. -------- --------------------------------------------------- ----------
  121. 09/25/96 Initial creation. BrianAu
  122. */
  123. ///////////////////////////////////////////////////////////////////////////////
  124. STDMETHODIMP_(ULONG)
  125. EnumFORMATETC::Release(
  126. VOID
  127. )
  128. {
  129. ASSERT( 0 != m_cRef );
  130. ULONG cRef = InterlockedDecrement(&m_cRef);
  131. DBGPRINT((DM_COM, DL_HIGH, TEXT("EnumFORMATETC::Release, 0x%08X %d -> %d\n"),
  132. this, cRef + 1, cRef));
  133. if ( 0 == cRef )
  134. {
  135. delete this;
  136. }
  137. return cRef;
  138. }
  139. STDMETHODIMP
  140. EnumFORMATETC::Next(
  141. DWORD cFormats,
  142. LPFORMATETC pFormats,
  143. LPDWORD pcReturned
  144. )
  145. {
  146. HRESULT hResult = S_OK;
  147. DBGPRINT((DM_DRAGDROP, DL_MID, TEXT("EnumFORMATETC::Next %d"), cFormats));
  148. DWORD iFormats = 0;
  149. if (NULL == pFormats)
  150. return E_INVALIDARG;
  151. while(cFormats-- > 0)
  152. {
  153. if (m_iCurrent < m_cFormats)
  154. {
  155. *(pFormats + iFormats++) = m_prgFormats[m_iCurrent++];
  156. }
  157. else
  158. {
  159. hResult = S_FALSE;
  160. break;
  161. }
  162. }
  163. if (NULL != pcReturned)
  164. *pcReturned = iFormats;
  165. return hResult;
  166. }
  167. STDMETHODIMP
  168. EnumFORMATETC::Skip(
  169. DWORD cFormats
  170. )
  171. {
  172. DBGPRINT((DM_DRAGDROP, DL_MID, TEXT("EnumFORMATETC::Skip %d"), cFormats));
  173. while((cFormats-- > 0) && (m_iCurrent < m_cFormats))
  174. m_iCurrent++;
  175. return cFormats == 0 ? S_OK : S_FALSE;
  176. }
  177. STDMETHODIMP
  178. EnumFORMATETC::Reset(
  179. VOID
  180. )
  181. {
  182. DBGPRINT((DM_DRAGDROP, DL_MID, TEXT("EnumFORMATETC::Reset")));
  183. m_iCurrent = 0;
  184. return S_OK;
  185. }
  186. STDMETHODIMP
  187. EnumFORMATETC::Clone(
  188. IEnumFORMATETC **ppvOut
  189. )
  190. {
  191. HRESULT hResult = NO_ERROR;
  192. try
  193. {
  194. EnumFORMATETC *pNew = new EnumFORMATETC(*this);
  195. DBGPRINT((DM_DRAGDROP, DL_MID, TEXT("EnumFORMATETC::Clone")));
  196. hResult = pNew->QueryInterface(IID_IEnumFORMATETC, (LPVOID *)ppvOut);
  197. }
  198. catch(CAllocException& e)
  199. {
  200. hResult = E_OUTOFMEMORY;
  201. }
  202. return hResult;
  203. }