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.

250 lines
5.5 KiB

  1. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  2. //
  3. // cdfview.cpp
  4. //
  5. // IUnknown for the cdfview class.
  6. //
  7. // History:
  8. //
  9. // 3/16/97 edwardp Created.
  10. //
  11. ////////////////////////////////////////////////////////////////////////////////
  12. //
  13. // Includes
  14. //
  15. #include "stdinc.h"
  16. #include "cdfidl.h"
  17. #include "persist.h"
  18. #include "cdfview.h"
  19. #include "view.h"
  20. #include "xmlutil.h"
  21. #include "dll.h"
  22. //
  23. // Constructor and destructor.
  24. //
  25. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  26. //
  27. // *** CCdfView::CCdfView ***
  28. //
  29. // Constructor.
  30. //
  31. ////////////////////////////////////////////////////////////////////////////////
  32. CCdfView::CCdfView (
  33. void
  34. )
  35. : CPersist(FALSE), // TRUE indicates cdf hasn't been parsed.
  36. m_cRef(1),
  37. m_fIsRootFolder(TRUE)
  38. {
  39. //
  40. // Memory allocs are assumed to be zero init'ed.
  41. //
  42. ASSERT(NULL == m_pcdfidl);
  43. ASSERT(NULL == m_pIXMLElementCollection);
  44. ASSERT(NULL == m_pidlPath);
  45. //
  46. // As long as this class is around the dll should stay loaded.
  47. //
  48. TraceMsg(TF_OBJECTS, "+ IShellFolder");
  49. //TraceMsg(TF_ALWAYS, "+ IShellFolder %0x08d", this);
  50. DllAddRef();
  51. return;
  52. }
  53. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  54. //
  55. // *** CCdfView::CCdfView ***
  56. //
  57. // Constructor.
  58. //
  59. ////////////////////////////////////////////////////////////////////////////////
  60. CCdfView::CCdfView (
  61. PCDFITEMIDLIST pcdfidl,
  62. LPCITEMIDLIST pidlParentPath,
  63. IXMLElementCollection* pParentIXMLElementCollection
  64. )
  65. : CPersist(TRUE), // TRUE indicates cdf already parsed.
  66. m_cRef(1),
  67. m_fIsRootFolder(FALSE)
  68. {
  69. ASSERT(CDFIDL_IsValid(pcdfidl));
  70. ASSERT(pParentIXMLElementCollection == NULL ||
  71. XML_IsCdfidlMemberOf(pParentIXMLElementCollection, pcdfidl));
  72. ASSERT(NULL == m_pidlPath);
  73. ASSERT(NULL == m_pIXMLElementCollection);
  74. //
  75. // Note that m_pidlPath, m_pcdfidl & m_pIXMLElementCollection could be
  76. // NULL in low memory conditions.
  77. //
  78. m_pcdfidl = (PCDFITEMIDLIST)ILCloneFirst((LPITEMIDLIST)pcdfidl);
  79. ASSERT(CDFIDL_IsValid(m_pcdfidl) || NULL == m_pcdfidl);
  80. ASSERT(ILIsEmpty(_ILNext((LPITEMIDLIST)m_pcdfidl)) || NULL == m_pcdfidl);
  81. m_pidlPath = ILCombine(pidlParentPath, (LPITEMIDLIST)m_pcdfidl);
  82. if (pParentIXMLElementCollection)
  83. {
  84. XML_GetChildElementCollection(pParentIXMLElementCollection,
  85. CDFIDL_GetIndexId(&pcdfidl->mkid),
  86. &m_pIXMLElementCollection);
  87. }
  88. //
  89. // As long as this class is around the dll should stay loaded.
  90. //
  91. TraceMsg(TF_OBJECTS, "+ IShellFolder %s", CDFIDL_GetName(pcdfidl));
  92. //TraceMsg(TF_ALWAYS, "+ IShellFolder %0x08d", this);
  93. DllAddRef();
  94. return;
  95. }
  96. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  97. //
  98. // *** CCdfView::~CCdfView **
  99. //
  100. // Destructor.
  101. //
  102. ////////////////////////////////////////////////////////////////////////////////
  103. CCdfView::~CCdfView (
  104. void
  105. )
  106. {
  107. ASSERT(0 == m_cRef);
  108. if (m_pidlPath)
  109. ILFree(m_pidlPath);
  110. if (m_pcdfidl)
  111. CDFIDL_Free(m_pcdfidl);
  112. if (m_pIXMLElementCollection)
  113. m_pIXMLElementCollection->Release();
  114. //
  115. // Matching Release for the constructor Addref.
  116. //
  117. TraceMsg(TF_OBJECTS, "- IShellFolder");
  118. //TraceMsg(TF_ALWAYS, "- IShellFolder %0x08d", this);
  119. DllRelease();
  120. return;
  121. }
  122. //
  123. // IUnknown methods.
  124. //
  125. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  126. //
  127. // *** CCdfView::QueryInterface **
  128. //
  129. // Cdf view QI.
  130. //
  131. ////////////////////////////////////////////////////////////////////////////////
  132. STDMETHODIMP
  133. CCdfView::QueryInterface (
  134. REFIID riid,
  135. void **ppv
  136. )
  137. {
  138. ASSERT(ppv);
  139. HRESULT hr;
  140. *ppv = NULL;
  141. if (IID_IUnknown == riid || IID_IShellFolder == riid)
  142. {
  143. *ppv = (IShellFolder*)this;
  144. }
  145. else if (IID_IPersist == riid || IID_IPersistFile == riid)
  146. {
  147. *ppv = (IPersistFile*)this;
  148. }
  149. else if (IID_IPersistFolder == riid)
  150. {
  151. *ppv = (IPersistFolder*)this;
  152. }
  153. else if (IID_IPersistMoniker == riid)
  154. {
  155. *ppv = (IPersistMoniker*)this;
  156. }
  157. else if (IID_IOleObject == riid)
  158. {
  159. *ppv = (IOleObject*)this;
  160. }
  161. if (*ppv)
  162. {
  163. ((IUnknown*)*ppv)->AddRef();
  164. hr = S_OK;
  165. }
  166. else
  167. {
  168. hr = E_NOINTERFACE;
  169. }
  170. ASSERT((SUCCEEDED(hr) && *ppv) || (FAILED(hr) && NULL == *ppv));
  171. return hr;
  172. }
  173. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  174. //
  175. // *** CCdfView::AddRef **
  176. //
  177. // Cdf view AddRef.
  178. //
  179. ////////////////////////////////////////////////////////////////////////////////
  180. STDMETHODIMP_(ULONG)
  181. CCdfView::AddRef (
  182. void
  183. )
  184. {
  185. ASSERT(m_cRef != 0);
  186. ASSERT(m_cRef < (ULONG)-1);
  187. return ++m_cRef;
  188. }
  189. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  190. //
  191. // *** CCdfView::Release **
  192. //
  193. // Cdf view Release.
  194. //
  195. ////////////////////////////////////////////////////////////////////////////////
  196. STDMETHODIMP_(ULONG)
  197. CCdfView::Release (
  198. void
  199. )
  200. {
  201. ASSERT (m_cRef != 0);
  202. ULONG cRef = --m_cRef;
  203. if (0 == cRef)
  204. delete this;
  205. return cRef;
  206. }