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.

280 lines
4.9 KiB

  1. /*
  2. * b a s e m h t . c p p
  3. *
  4. * Purpose:
  5. * Base classes for MHTML packer objects
  6. *
  7. * History
  8. * October 1998: brettm - created
  9. *
  10. * Copyright (C) Microsoft Corp. 1995, 1996.
  11. */
  12. #include <pch.hxx>
  13. #include "mhtml.h"
  14. #include "basemht.h"
  15. ASSERTDATA
  16. /*
  17. * m a c r o s
  18. */
  19. /*
  20. * c o n s t a n t s
  21. */
  22. /*
  23. * t y p e d e f s
  24. */
  25. /*
  26. * F u n c t i o n s
  27. */
  28. CBaseTag::CBaseTag()
  29. {
  30. m_cRef = 1;
  31. m_pElem = NULL;
  32. m_bstrDest = NULL;
  33. m_bstrSrc = NULL;
  34. }
  35. CBaseTag::~CBaseTag()
  36. {
  37. ReleaseObj(m_pElem);
  38. SysFreeString(m_bstrDest);
  39. SysFreeString(m_bstrSrc);
  40. }
  41. ULONG CBaseTag::AddRef()
  42. {
  43. return ++m_cRef;
  44. }
  45. ULONG CBaseTag::Release()
  46. {
  47. if (--m_cRef==0)
  48. {
  49. delete this;
  50. return 0;
  51. }
  52. return m_cRef;
  53. }
  54. HRESULT CBaseTag::QueryInterface(REFIID riid, LPVOID *lplpObj)
  55. {
  56. if(!lplpObj)
  57. return TraceResult(E_INVALIDARG);
  58. *lplpObj = NULL; // set to NULL, in case we fail.
  59. if (IsEqualIID(riid, IID_IUnknown))
  60. *lplpObj = (LPVOID)(IUnknown *)this;
  61. else if (IsEqualIID(riid, IID_IMimeEditTag))
  62. *lplpObj = (LPVOID)(IMimeEditTag *)this;
  63. else
  64. return E_NOINTERFACE;
  65. AddRef();
  66. return NOERROR;
  67. }
  68. HRESULT CBaseTag::Init(IHTMLElement *pElem)
  69. {
  70. if (pElem == NULL)
  71. return TraceResult(E_INVALIDARG);
  72. ReplaceInterface(m_pElem, pElem);
  73. return S_OK;
  74. }
  75. HRESULT CBaseTag::GetSrc(BSTR *pbstr)
  76. {
  77. if (pbstr == NULL)
  78. return TraceResult(E_INVALIDARG);
  79. *pbstr = SysAllocString(m_bstrSrc);
  80. return *pbstr ? S_OK : E_FAIL;
  81. }
  82. HRESULT CBaseTag::SetSrc(BSTR bstr)
  83. {
  84. return E_NOTIMPL;
  85. }
  86. HRESULT CBaseTag::GetDest(BSTR *pbstr)
  87. {
  88. if (pbstr == NULL)
  89. return TraceResult(E_INVALIDARG);
  90. *pbstr = SysAllocString(m_bstrDest);
  91. return *pbstr ? S_OK : E_FAIL;
  92. }
  93. HRESULT CBaseTag::SetDest(BSTR bstr)
  94. {
  95. SysFreeString(m_bstrDest);
  96. m_bstrDest = SysAllocString(bstr);
  97. return S_OK;
  98. }
  99. HRESULT CBaseTag::OnPreSave()
  100. {
  101. return S_OK;
  102. }
  103. HRESULT CBaseTag::OnPostSave()
  104. {
  105. return S_OK;
  106. }
  107. HRESULT CBaseTag::CanPackage()
  108. {
  109. return S_OK;
  110. }
  111. HRESULT CBaseTag::IsValidMimeType(LPWSTR pszTypeW)
  112. {
  113. return S_OK;
  114. }
  115. CBaseTagCollection::CBaseTagCollection()
  116. {
  117. m_cRef = 1;
  118. m_rgpTags = NULL;
  119. m_cTags = 0;
  120. m_uEnum = 0;
  121. }
  122. CBaseTagCollection::~CBaseTagCollection()
  123. {
  124. _FreeCollection();
  125. }
  126. ULONG CBaseTagCollection::AddRef()
  127. {
  128. return ++m_cRef;
  129. }
  130. ULONG CBaseTagCollection::Release()
  131. {
  132. if (--m_cRef==0)
  133. {
  134. delete this;
  135. return 0;
  136. }
  137. return m_cRef;
  138. }
  139. HRESULT CBaseTagCollection::QueryInterface(REFIID riid, LPVOID *lplpObj)
  140. {
  141. if(!lplpObj)
  142. return TraceResult(E_INVALIDARG);
  143. *lplpObj = NULL; // set to NULL, in case we fail.
  144. if (IsEqualIID(riid, IID_IUnknown))
  145. *lplpObj = (LPVOID)(IUnknown *)this;
  146. else if (IsEqualIID(riid, IID_IMimeEditTagCollection))
  147. *lplpObj = (LPVOID)(IMimeEditTagCollection *)this;
  148. else
  149. return E_NOINTERFACE;
  150. AddRef();
  151. return NOERROR;
  152. }
  153. HRESULT CBaseTagCollection::Init(IUnknown *pDocUnk)
  154. {
  155. IHTMLDocument2 *pDoc=0;
  156. HRESULT hr;
  157. if (pDocUnk == NULL)
  158. return E_INVALIDARG;
  159. hr = pDocUnk->QueryInterface(IID_IHTMLDocument2, (LPVOID *)&pDoc);
  160. if (FAILED(hr))
  161. goto error;
  162. hr = _BuildCollection(pDoc);
  163. if (FAILED(hr))
  164. goto error;
  165. error:
  166. ReleaseObj(pDoc);
  167. return hr;
  168. }
  169. HRESULT CBaseTagCollection::Next(ULONG cWanted, IMimeEditTag **prgpTag, ULONG *pcFetched)
  170. {
  171. HRESULT hr=S_OK;
  172. ULONG cFetch,
  173. uTag;
  174. if (pcFetched)
  175. *pcFetched = 0;
  176. // nothing to give back
  177. if (m_cTags == 0)
  178. goto exit;
  179. // Compute number to fetch
  180. cFetch = min(cWanted, m_cTags - m_uEnum);
  181. if (0 == cFetch)
  182. goto exit;
  183. // Copy cWanted
  184. for (uTag=0; uTag<cFetch; uTag++)
  185. {
  186. prgpTag[uTag] = m_rgpTags[m_uEnum++];
  187. if (prgpTag[uTag])
  188. prgpTag[uTag]->AddRef();
  189. }
  190. // Return fetced ?
  191. if (pcFetched)
  192. *pcFetched = cFetch;
  193. exit:
  194. return hr;
  195. }
  196. HRESULT CBaseTagCollection::Reset()
  197. {
  198. m_uEnum = 0;
  199. return S_OK;
  200. }
  201. HRESULT CBaseTagCollection::Count(ULONG *pcItems)
  202. {
  203. if (pcItems == NULL)
  204. return TraceResult(E_INVALIDARG);
  205. *pcItems = m_cTags;
  206. return S_OK;
  207. }
  208. HRESULT CBaseTagCollection::_FreeCollection()
  209. {
  210. ULONG uImages;
  211. if (m_rgpTags)
  212. {
  213. for (uImages = 0; uImages < m_cTags; uImages++)
  214. ReleaseObj(m_rgpTags[uImages]);
  215. MemFree(m_rgpTags);
  216. m_rgpTags = 0;
  217. m_cTags = 0;
  218. }
  219. return S_OK;
  220. }