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.

253 lines
8.2 KiB

  1. #ifndef CHCOMMON_H__
  2. #define CHCOMMON_H__
  3. #ifdef __cplusplus
  4. HRESULT _GetShortcut(LPCTSTR pszUrl, REFIID riid, void **ppv);
  5. HRESULT AlignPidl(LPCITEMIDLIST* ppidl, BOOL* pfRealigned);
  6. HRESULT AlignPidlArray(LPCITEMIDLIST* apidl, int cidl, LPCITEMIDLIST** papidl,
  7. BOOL* pfRealigned);
  8. void FreeRealignedPidlArray(LPCITEMIDLIST* apidl, int cidl);
  9. void inline FreeRealignedPidl(LPCITEMIDLIST pidl)
  10. {
  11. ILFree((LPITEMIDLIST)pidl);
  12. }
  13. UINT MergeMenuHierarchy(HMENU hmenuDst, HMENU hmenuSrc, UINT idcMin, UINT idcMax);
  14. void ResizeStatusBar(HWND hwnd, BOOL fInit);
  15. HRESULT _ArrangeFolder(HWND hwnd, UINT uID);
  16. BOOL _TitleIsGood(LPCWSTR psz);
  17. //////////////////////////////////////////////////////////////////////
  18. // StrHash -- A generic string hasher
  19. // Stores (char*, void*) pairs
  20. // Marc Miller (t-marcmi), 1998
  21. /*
  22. * TODO:
  23. * provide a way to update/delete entries
  24. * provice a way to specify a beginning table size
  25. * provide a way to pass in a destructor function
  26. * for void* values
  27. */
  28. class StrHash {
  29. public:
  30. StrHash(int fCaseInsensitive = 0);
  31. ~StrHash();
  32. void* insertUnique(LPCTSTR pszKey, int fCopy, void* pvVal);
  33. void* retrieve(LPCTSTR pszKey);
  34. #ifdef DEBUG
  35. void _RemoveHashNodesFromMemList();
  36. void _AddHashNodesFromMemList();
  37. #endif // DEBUG
  38. protected:
  39. class StrHashNode {
  40. friend class StrHash;
  41. protected:
  42. LPCTSTR pszKey;
  43. void* pvVal;
  44. int fCopy;
  45. StrHashNode* next;
  46. public:
  47. StrHashNode(LPCTSTR psz, void* pv, int fCopy, StrHashNode* next);
  48. ~StrHashNode();
  49. };
  50. // possible hash-table sizes, chosen from primes not close to powers of 2
  51. static const unsigned int sc_auPrimes[];
  52. static const unsigned int c_uNumPrimes;
  53. static const unsigned int c_uFirstPrime;
  54. static const unsigned int c_uMaxLoadFactor; // scaled by USHORT_MAX
  55. unsigned int nCurPrime; // current index into sc_auPrimes
  56. unsigned int nBuckets;
  57. unsigned int nElements;
  58. StrHashNode** ppshnHashChain;
  59. int _fCaseInsensitive;
  60. unsigned int _hashValue(LPCTSTR, unsigned int);
  61. StrHashNode* _findKey(LPCTSTR pszStr, unsigned int ubucketNum);
  62. unsigned int _loadFactor();
  63. int _prepareForInsert();
  64. private:
  65. // empty private copy constructor to prevent copying
  66. StrHash(const StrHash& strHash) { }
  67. // empty private assignment constructor to prevent assignment
  68. StrHash& operator=(const StrHash& strHash) { return *this; }
  69. };
  70. //////////////////////////////////////////////////////////////////////
  71. /// OrderedList
  72. class OrderedList {
  73. public:
  74. class Element {
  75. public:
  76. friend class OrderedList;
  77. virtual int compareWith(Element *pelt) = 0;
  78. virtual ~Element() { }
  79. private:
  80. Element* next;
  81. };
  82. OrderedList(unsigned int uSize);
  83. ~OrderedList();
  84. #if DEBUG
  85. void _RemoveElementsFromMemlist();
  86. void _AddElementsToMemlist();
  87. #endif //DEBUg
  88. void insert(Element *pelt);
  89. Element *removeFirst();
  90. Element *peek() { return peltHead; }
  91. protected:
  92. Element *peltHead; // points to smallest in list
  93. unsigned int uSize;
  94. unsigned int uCount;
  95. public:
  96. // variable access functions
  97. unsigned int count() { return uCount; }
  98. BOOL full() { return (uSize && (uCount >= uSize)); }
  99. private:
  100. OrderedList(const OrderedList& ol) { }
  101. OrderedList& operator=(const OrderedList& ol) { return *this; }
  102. };
  103. class CDetailsOfFolder : public IShellDetails
  104. {
  105. public:
  106. CDetailsOfFolder(HWND hwnd, IShellFolder2 *psf) : _cRef(1), _psf(psf), _hwnd(hwnd)
  107. {
  108. _psf->AddRef();
  109. }
  110. // *** IUnknown methods ***
  111. STDMETHOD(QueryInterface)(REFIID riid, void ** ppv);
  112. STDMETHOD_(ULONG,AddRef)();
  113. STDMETHOD_(ULONG,Release)();
  114. // IShellDetails
  115. STDMETHOD(GetDetailsOf)(LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS *pdi);
  116. STDMETHOD(ColumnClick)(UINT iColumn);
  117. private:
  118. virtual ~CDetailsOfFolder() { _psf->Release(); }
  119. LONG _cRef;
  120. IShellFolder2 *_psf;
  121. HWND _hwnd;
  122. };
  123. class CFolderArrangeMenu : public IContextMenu
  124. {
  125. public:
  126. CFolderArrangeMenu(UINT idMenu) : _cRef(1), _idMenu(idMenu)
  127. {
  128. }
  129. // IUnknown
  130. STDMETHOD(QueryInterface)(REFIID riid, void ** ppv);
  131. STDMETHOD_(ULONG,AddRef)();
  132. STDMETHOD_(ULONG,Release)();
  133. // IContextMenu
  134. STDMETHODIMP QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst,
  135. UINT idCmdLast, UINT uFlags);
  136. STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO lpici);
  137. STDMETHODIMP GetCommandString(UINT_PTR idCmd, UINT uType,UINT *pwReserved,
  138. LPSTR pszName, UINT cchMax);
  139. private:
  140. virtual ~CFolderArrangeMenu() { }
  141. LONG _cRef;
  142. UINT _idMenu;
  143. };
  144. ////////////////////////////////////////////////////////////////////////////
  145. //
  146. // CBaseItem Object
  147. //
  148. ////////////////////////////////////////////////////////////////////////////
  149. class CBaseItem :
  150. public IContextMenu,
  151. public IDataObject,
  152. public IExtractIconA,
  153. public IExtractIconW,
  154. public IQueryInfo
  155. {
  156. public:
  157. CBaseItem();
  158. HRESULT Initialize(HWND hwnd, UINT cidl, LPCITEMIDLIST *ppidl);
  159. // IUnknown Methods
  160. STDMETHODIMP QueryInterface(REFIID,void **);
  161. STDMETHODIMP_(ULONG) AddRef(void);
  162. STDMETHODIMP_(ULONG) Release(void);
  163. // IContextMenu Methods
  164. // STDMETHODIMP QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst,
  165. // UINT idCmdLast, UINT uFlags);
  166. // STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO lpici);
  167. STDMETHODIMP GetCommandString(UINT_PTR idCmd, UINT uType,UINT *pwReserved,
  168. LPSTR pszName, UINT cchMax);
  169. // IQueryInfo Methods
  170. // STDMETHODIMP GetInfoTip(DWORD dwFlags, WCHAR **ppwszTip);
  171. STDMETHODIMP GetInfoFlags(DWORD *pdwFlags);
  172. // IExtractIconA Methods
  173. STDMETHODIMP GetIconLocation(UINT uFlags, LPSTR pszIconFile, UINT ucchMax, PINT pniIcon, PUINT puFlags) = 0;
  174. STDMETHODIMP Extract(LPCSTR pcszFile, UINT uIconIndex, HICON * phiconLarge, HICON * phiconSmall, UINT ucIconSize);
  175. // IExtractIconW Methods
  176. STDMETHODIMP GetIconLocation(UINT uFlags, LPWSTR pwzIconFile, UINT ucchMax, PINT pniIcon, PUINT puFlags);
  177. STDMETHODIMP Extract(LPCWSTR pcwzFile, UINT uIconIndex, HICON * phiconLarge, HICON * phiconSmall, UINT ucIconSize);
  178. // IDataObject Methods...
  179. // STDMETHODIMP GetData(LPFORMATETC pFEIn, LPSTGMEDIUM pSTM);
  180. STDMETHODIMP GetDataHere(LPFORMATETC pFE, LPSTGMEDIUM pSTM);
  181. // STDMETHODIMP QueryGetData(LPFORMATETC pFE);
  182. STDMETHODIMP GetCanonicalFormatEtc(LPFORMATETC pFEIn, LPFORMATETC pFEOut);
  183. STDMETHODIMP SetData(LPFORMATETC pFE, LPSTGMEDIUM pSTM, BOOL fRelease);
  184. // STDMETHODIMP EnumFormatEtc(DWORD dwDirection, LPENUMFORMATETC *ppEnum);
  185. STDMETHODIMP DAdvise(LPFORMATETC pFE, DWORD grfAdv, LPADVISESINK pAdvSink,
  186. DWORD *pdwConnection);
  187. STDMETHODIMP DUnadvise(DWORD dwConnection);
  188. STDMETHODIMP EnumDAdvise(LPENUMSTATDATA *ppEnum);
  189. // IDataObject helper functions
  190. HRESULT _CreateHTEXT(STGMEDIUM *pmedium);
  191. HRESULT _CreateUnicodeTEXT(STGMEDIUM *pmedium);
  192. HRESULT _CreateFileDescriptorA(STGMEDIUM *pSTM);
  193. HRESULT _CreateFileContents(STGMEDIUM *pSTM, LONG lindex);
  194. HRESULT _CreateURL(STGMEDIUM *pSTM);
  195. HRESULT _CreatePrefDropEffect(STGMEDIUM *pSTM);
  196. protected:
  197. virtual ~CBaseItem();
  198. virtual LPCTSTR _GetUrl(int nIndex) = 0;
  199. virtual LPCTSTR _PidlToSourceUrl(LPCITEMIDLIST pidl) = 0;
  200. virtual UNALIGNED const TCHAR* _GetURLTitle(LPCITEMIDLIST pcei) = 0;
  201. LPCTSTR _GetDisplayUrlForPidl(LPCITEMIDLIST pidl, LPTSTR pszDisplayUrl, DWORD dwDisplayUrl);
  202. HRESULT _AddToFavorites(int nIndex);
  203. LONG _cRef; // reference count
  204. UINT _cItems; // number of items we represent
  205. LPCITEMIDLIST* _ppidl; // variable size array of items
  206. HWND _hwndOwner;
  207. };
  208. #endif // __cplusplus
  209. #endif