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.

195 lines
4.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // File: cidl.h
  4. //
  5. // Contents: CIDList
  6. //
  7. // History: Sep-26-96 Davepl Created (from old VZip code)
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef __PIDL_H__
  11. #define __PIDL_H__
  12. #include <shlobj.h>
  13. #include "autoptr.h"
  14. #include "tstring.h"
  15. #include "cshalloc.h"
  16. #define CB_IDLIST_TERMINATOR (sizeof(USHORT))
  17. //
  18. // CIDList - ITEMIDLIST wrapper class
  19. //
  20. class CIDList : public ITEMIDLIST
  21. {
  22. public:
  23. tstring GetPath() const;
  24. //
  25. // (LPITEMIDLIST) operator - allows silent casting of CIDlist to ITEMIDLIST
  26. //
  27. operator ITEMIDLIST()
  28. {
  29. return *this;
  30. }
  31. operator LPITEMIDLIST()
  32. {
  33. return this;
  34. }
  35. //
  36. // CombineWith - Adds another idlist to this one, result to a new idlist
  37. //
  38. HRESULT CombineWith(const CIDList * pidlwith, CIDList * * ppidlto);
  39. //
  40. // IsEmpty - returns TRUE if this is an empty (cb == 0) pidl
  41. //
  42. BOOL IsEmpty() const
  43. {
  44. return mkid.cb == 0 ? TRUE : FALSE;
  45. }
  46. //
  47. // IsDesktop - Checks to see if the pidl is empty, meaning desktop
  48. //
  49. BOOL IsDesktop() const
  50. {
  51. return IsEmpty();
  52. }
  53. //
  54. // Skip - advance this pidl pointer by 'cb' bytes
  55. //
  56. CIDList * Skip(const UINT cb) const
  57. {
  58. return (CIDList *) (((BYTE *)this) + cb);
  59. }
  60. //
  61. // Next - returns this next entry in this idlist
  62. //
  63. CIDList * Next() const
  64. {
  65. return Skip(mkid.cb);
  66. }
  67. //
  68. // FindChild - Given _this_ as a parent pidl, and some pidlchild which is
  69. // a child of it, returns the portion of the child not found
  70. // in the parent.
  71. //
  72. const CIDList * FindChild (const CIDList * pidlchild) const;
  73. //
  74. // IsParentOf - Tests whether or not _this_ pidl is a parent of some
  75. // other pidl
  76. //
  77. BOOL IsParentOf(const CIDList * pidlother, BOOL fImmediate) const;
  78. //
  79. // GetSize - returns the size, in bytes, of the IDList starting
  80. // at this pidl
  81. //
  82. UINT GetSize() const
  83. {
  84. UINT cbTotal = 0;
  85. const CIDList * pidl = this;
  86. {
  87. // We need a NULL entry at the end, so adjust size accordingly
  88. cbTotal += CB_IDLIST_TERMINATOR;
  89. while (pidl->mkid.cb)
  90. {
  91. cbTotal += pidl->mkid.cb;
  92. pidl = pidl->Next();
  93. }
  94. }
  95. return cbTotal;
  96. }
  97. //
  98. // Clone - uses the shell's task allocator to allocate memory for
  99. // a clone of this pidl (the _entire_ pidl starting here)
  100. // and copies this pidl into that buffer
  101. //
  102. HRESULT CloneTo(CIDList * * ppidlclone) const
  103. {
  104. if (ppidlclone)
  105. {
  106. const UINT cb = GetSize();
  107. *ppidlclone = (CIDList *) g_SHAlloc.Alloc(cb);
  108. if (*ppidlclone)
  109. {
  110. memcpy(*ppidlclone, this, cb);
  111. }
  112. }
  113. return *ppidlclone ? S_OK : E_OUTOFMEMORY;
  114. }
  115. //
  116. // AppendPath - Append a text filesystem path to the idlist
  117. //
  118. HRESULT AppendPath(LPCTSTR pszPath, CIDList * * ppidlResult);
  119. //
  120. // GetIShellFolder - returns the IShellFolder interface for this idlist,
  121. // which assumes it is a folder pidl
  122. //
  123. HRESULT GetIShellFolder(IShellFolder ** pFolder);
  124. // FindLastID - Finds the last itemid at the end of this id list
  125. //
  126. CIDList * FindLastID()
  127. {
  128. CIDList * pidlLast = this;
  129. CIDList * pidlNext = this;
  130. // Scan to the end and return the last pidl
  131. while (pidlNext->mkid.cb)
  132. {
  133. pidlLast = pidlNext;
  134. pidlNext = pidlLast->Next();
  135. }
  136. return pidlLast;
  137. }
  138. //
  139. // RemoveLastID - chops the last child idlist off the end of
  140. // this chain
  141. //
  142. void RemoveLastID()
  143. {
  144. if (FALSE == IsEmpty())
  145. {
  146. CIDList * pidlLast = FindLastID();
  147. // Remove the last one
  148. pidlLast->mkid.cb = 0;
  149. }
  150. }
  151. };
  152. // void StrRetToTString(CIDList * pidl, LPSTRRET lpStr, tstring &str);
  153. #endif // __PIDL_H__