cdfview.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 6k
Category:

Windows Kernel

Development Platform:

Visual C++

  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.     //
  90.     // As long as this class is around the dll should stay loaded.
  91.     //
  92.     TraceMsg(TF_OBJECTS, "+ IShellFolder %s", CDFIDL_GetName(pcdfidl));
  93.     //TraceMsg(TF_ALWAYS,  "+ IShellFolder %0x08d", this);
  94.     DllAddRef();
  95. return;
  96. }
  97. //\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\
  98. //
  99. // *** CCdfView::~CCdfView **
  100. //
  101. //    Destructor.
  102. //
  103. ////////////////////////////////////////////////////////////////////////////////
  104. CCdfView::~CCdfView (
  105. void
  106. )
  107. {
  108.     ASSERT(0 == m_cRef);
  109.     if (m_pidlPath)
  110.         ILFree(m_pidlPath);
  111.     if (m_pcdfidl)
  112.         CDFIDL_Free(m_pcdfidl);
  113.     if (m_pIXMLElementCollection)
  114.         m_pIXMLElementCollection->Release();
  115.     //
  116.     // Matching Release for the constructor Addref.
  117.     //
  118.     TraceMsg(TF_OBJECTS, "- IShellFolder");
  119.     //TraceMsg(TF_ALWAYS,  "- IShellFolder %0x08d", this);
  120.     DllRelease();
  121. return;
  122. }
  123. //
  124. // IUnknown methods.
  125. //
  126. //\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\
  127. //
  128. // *** CCdfView::QueryInterface **
  129. //
  130. //    Cdf view QI.
  131. //
  132. ////////////////////////////////////////////////////////////////////////////////
  133. STDMETHODIMP
  134. CCdfView::QueryInterface (
  135.     REFIID riid,
  136.     void **ppv
  137. )
  138. {
  139.     ASSERT(ppv);
  140.     HRESULT hr;
  141.     *ppv = NULL;
  142.     if (IID_IUnknown == riid || IID_IShellFolder == riid)
  143.     {
  144.         *ppv = (IShellFolder*)this;
  145.     }
  146.     else if (IID_IPersist == riid || IID_IPersistFile == riid)
  147.     {
  148.         *ppv = (IPersistFile*)this;
  149.     }
  150.     else if (IID_IPersistFolder == riid)
  151.     {
  152.         *ppv = (IPersistFolder*)this;
  153.     }
  154.     else if (IID_IPersistMoniker == riid)
  155.     {
  156.         *ppv = (IPersistMoniker*)this;
  157.     }
  158.     else if (IID_IOleObject == riid)
  159.     {
  160.         *ppv = (IOleObject*)this;
  161.     }
  162.     if (*ppv)
  163.     {
  164.         ((IUnknown*)*ppv)->AddRef();
  165.         hr = S_OK;
  166.     }
  167.     else if (IID_IShellView == riid)
  168.     {
  169.         ASSERT(0);  // Is this required?
  170.         /*LPITEMIDLIST pidl = ILClone((LPITEMIDLIST)m_pcdfidl);
  171.         if (pidl)
  172.         {
  173.             hr = CreateDefaultShellView((IShellFolder*)this, pidl,
  174.                                         (IShellView**)ppv);
  175.         }
  176.         else
  177.         {
  178.             hr = E_OUTOFMEMORY;
  179.         }*/
  180.     }
  181.     else
  182.     {
  183.         hr = E_NOINTERFACE;
  184.     }
  185.     ASSERT((SUCCEEDED(hr) && *ppv) || (FAILED(hr) && NULL == *ppv));
  186.     return hr;
  187. }
  188. //\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\
  189. //
  190. // *** CCdfView::AddRef **
  191. //
  192. //    Cdf view AddRef.
  193. //
  194. ////////////////////////////////////////////////////////////////////////////////
  195. STDMETHODIMP_(ULONG)
  196. CCdfView::AddRef (
  197.     void
  198. )
  199. {
  200.     ASSERT(m_cRef != 0);
  201.     ASSERT(m_cRef < (ULONG)-1);
  202.     return ++m_cRef;
  203. }
  204. //\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\
  205. //
  206. // *** CCdfView::Release **
  207. //
  208. //    Cdf view Release.
  209. //
  210. ////////////////////////////////////////////////////////////////////////////////
  211. STDMETHODIMP_(ULONG)
  212. CCdfView::Release (
  213.     void
  214. )
  215. {
  216.     ASSERT (m_cRef != 0);
  217.     ULONG cRef = --m_cRef;
  218.     
  219.     if (0 == cRef)
  220.         delete this;
  221.     return cRef;
  222. }
  223. #ifdef UNIX
  224. void unixEnsureFileScheme(TCHAR  *pszIn)
  225. {
  226.     if(pszIn && *pszIn == TEXT(FILENAME_SEPARATOR))
  227.     {
  228.         TCHAR tmpBuffer[MAX_PATH];
  229.         int len = lstrlen(pszIn);
  230.         lstrcpy(tmpBuffer,TEXT("file://"));
  231.         lstrcat(tmpBuffer,pszIn);
  232.         lstrcpy(pszIn,tmpBuffer);
  233.     }
  234. }
  235. #endif /* UNIX */