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.

400 lines
16 KiB

  1. #ifndef HSFOLDER_H__
  2. #define HSFOLDER_H__
  3. #ifdef __cplusplus
  4. #include <debug.h>
  5. #include "iface.h"
  6. #include <stralign.h>
  7. // Forward class declarations
  8. class CHistFolderEnum;
  9. class CHistFolder;
  10. class CHistItem;
  11. #define LOTS_OF_FILES (10)
  12. // The number of "top" sites displayed in the "Most Frequently Viewed..." history view
  13. #define NUM_TOP_SITES 20
  14. void _GetURLDispName(LPBASEPIDL pcei, LPTSTR pszName, UINT cchName) ;
  15. UNALIGNED const TCHAR* _GetURLTitle(LPBASEPIDL pcei);
  16. LPBASEPIDL _CreateBaseFolderPidl(BOOL fOleAlloc, DWORD cbSize, USHORT usSign);
  17. LPBASEPIDL _CreateIdCacheFolderPidl(BOOL fOleAlloc, USHORT usSign, LPCTSTR szId);
  18. LPHEIPIDL _CreateHCacheFolderPidl(BOOL fOleMalloc, LPCTSTR pszUrl, FILETIME ftModified, LPSTATURL lpStatURL,
  19. __int64 llPriority = 0, DWORD dwNumHits = 0);
  20. #define ua_GetURLTitle(d,p) TSTR_ALIGNED_STACK_COPY(d,_GetURLTitle(p))
  21. __inline LPCWSTR _GetURLTitleAlign(LPBASEPIDL pcei, LPTSTR szBuf, DWORD cchBuf)
  22. {
  23. LPCUTSTR urlTitle;
  24. urlTitle = _GetURLTitle(pcei);
  25. #if defined(UNICODE) && defined(ALIGNMENT_MACHINE)
  26. if (TSTR_ALIGNED(urlTitle)) {
  27. return (LPCTSTR)urlTitle;
  28. } else {
  29. ualstrcpyn(szBuf, _GetURLTitle(pcei), cchBuf);
  30. return szBuf;
  31. }
  32. #else
  33. return urlTitle;
  34. #endif
  35. }
  36. // returns TRUE if _GetURLTitle would retrieve an URL when given this PIDL
  37. inline BOOL _URLTitleIsURL(LPBASEPIDL pcei)
  38. {
  39. return ((pcei->usSign == HEIPIDL_SIGN) && (((LPHEIPIDL) pcei)->usTitle == 0));
  40. }
  41. inline LPCTSTR HPidlToSourceUrl(LPBASEPIDL pidl)
  42. {
  43. if (pidl->usSign == (USHORT)HEIPIDL_SIGN)
  44. {
  45. LPHEIPIDL pheipidl = (LPHEIPIDL) pidl;
  46. return (LPCTSTR)(((BYTE*)pheipidl) + pheipidl->usUrl);
  47. }
  48. return NULL;
  49. }
  50. inline LPCTSTR HPidlToSourceUrl(LPCITEMIDLIST pidl)
  51. {
  52. return HPidlToSourceUrl((LPBASEPIDL) pidl);
  53. }
  54. inline int _CompareHCURLs(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
  55. {
  56. LPCTSTR url1 = _StripHistoryUrlToUrl(HPidlToSourceUrl((LPBASEPIDL)pidl1));
  57. LPCTSTR url2 = _StripHistoryUrlToUrl(HPidlToSourceUrl((LPBASEPIDL)pidl2));
  58. ASSERT(url1 && url2);
  59. return StrCmpI(url1, url2);
  60. }
  61. inline int _CompareHFolderPidl(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
  62. {
  63. return StrCmpI(HPidlToSourceUrl((LPBASEPIDL)pidl1), HPidlToSourceUrl((LPBASEPIDL)pidl2));
  64. }
  65. ///////////////////////
  66. //
  67. // Column definition for the History Folder Defview
  68. //
  69. enum {
  70. ICOLH_URL_NAME = 0,
  71. ICOLH_URL_TITLE,
  72. ICOLH_URL_LASTVISITED,
  73. ICOLH_URL_MAX // Make sure this is the last enum item
  74. };
  75. #define INTERVAL_PREFIX_LEN (6)
  76. #define INTERVAL_VERS_LEN (2)
  77. #define INTERVAL_VERS (TEXT("01"))
  78. #define OUR_VERS (1)
  79. #define UNK_INTERVAL_VERS (0xFFFF)
  80. #define RANGE_LEN (16)
  81. #define INTERVAL_MIN_SIZE (RANGE_LEN+INTERVAL_PREFIX_LEN)
  82. #define INTERVAL_SIZE (RANGE_LEN+INTERVAL_VERS_LEN+INTERVAL_PREFIX_LEN)
  83. #define PREFIX_SIZE (RANGE_LEN+3)
  84. // NOTE: the interval is closed at the start but open at the end, that
  85. // is inclusion is time >= start and time < end
  86. typedef struct _HSFINTERVAL
  87. {
  88. FILETIME ftStart;
  89. FILETIME ftEnd;
  90. TCHAR szPrefix[PREFIX_SIZE+1];
  91. USHORT usSign;
  92. USHORT usVers;
  93. } HSFINTERVAL;
  94. BOOL GetDisplayNameForTimeInterval( const FILETIME *pStartTime, const FILETIME *pEndTime,
  95. LPTSTR pszBuffer, int cchBufferLength);
  96. HRESULT _ValueToIntervalW(LPCUWSTR wzInterval, FILETIME *pftStart, FILETIME *pftEnd);
  97. // DeleteEntries filter callback
  98. typedef BOOL (*PFNDELETECALLBACK)(LPINTERNET_CACHE_ENTRY_INFO pceiWorking, LPVOID pDelData, LPITEMIDLIST *ppidlNotify);
  99. // Forward declarations for create instance functions
  100. HRESULT CHistItem_CreateInstance(CHistFolder *pHCFolder, HWND hwndOwner, UINT cidl, LPCITEMIDLIST *ppidl, REFIID riid, void **ppvOut);
  101. //////////////////////////////////////////////////////////////////////////////
  102. //
  103. // CHistFolderEnum Object
  104. //
  105. //////////////////////////////////////////////////////////////////////////////
  106. class CHistFolderEnum : public IEnumIDList
  107. {
  108. public:
  109. CHistFolderEnum(DWORD grfFlags, CHistFolder *pHCFolder);
  110. // IUnknown Methods
  111. STDMETHODIMP QueryInterface(REFIID,void **);
  112. STDMETHODIMP_(ULONG) AddRef(void);
  113. STDMETHODIMP_(ULONG) Release(void);
  114. // IEnumIDList
  115. STDMETHODIMP Next(ULONG celt, LPITEMIDLIST *rgelt, ULONG *pceltFetched);
  116. STDMETHODIMP Skip(ULONG celt);
  117. STDMETHODIMP Reset();
  118. STDMETHODIMP Clone(IEnumIDList **ppenum);
  119. protected:
  120. ~CHistFolderEnum();
  121. HRESULT _NextHistInterval(ULONG celt, LPITEMIDLIST *rgelt, ULONG *pceltFetched);
  122. HRESULT _NextViewPart(ULONG celt, LPITEMIDLIST *rgelt, ULONG *pceltFetched);
  123. HRESULT _NextViewPart_OrderToday(ULONG celt, LPITEMIDLIST *rgelt, ULONG *pceltFetched);
  124. HRESULT _NextViewPart_OrderSite(ULONG celt, LPITEMIDLIST *rgelt, ULONG *pceltFetched);
  125. HRESULT _NextViewPart_OrderFreq(ULONG celt, LPITEMIDLIST *rgelt, ULONG *pceltFetched);
  126. HRESULT _NextViewPart_OrderSearch(ULONG celt, LPITEMIDLIST *rgelt, ULONG *pceltFetched);
  127. class OrderedList* _GetMostFrequentPages();
  128. LPCTSTR _GetLocalHost(void);
  129. LONG _cRef; // ref count
  130. CHistFolder *_pHCFolder;// this is what we enumerate
  131. UINT _grfFlags; // enumeration flags
  132. UINT _uFlags; // local flags
  133. LPINTERNET_CACHE_ENTRY_INFO _pceiWorking;
  134. HANDLE _hEnum;
  135. int _cbCurrentInterval; // position in enum of time intervals
  136. int _cbIntervals;
  137. HSFINTERVAL *_pIntervalCache;
  138. HSFINTERVAL *_pIntervalCur;
  139. class StrHash *_pshHashTable; // used to keep track of what I gave out
  140. class OrderedList *_polFrequentPages; // used to store most frequently viewed pgs
  141. IEnumSTATURL *_pstatenum; // used in search enumerator
  142. TCHAR _szLocalHost[INTERNET_MAX_HOST_NAME_LENGTH]; // "My Computer" cached...
  143. static BOOL_PTR s_DoCacheSearch(LPINTERNET_CACHE_ENTRY_INFO pcei,
  144. LPTSTR pszUserName, UINT uUserNameLen, CHistFolderEnum *penum,
  145. class _CurrentSearches *pcsThisThread, IUrlHistoryPriv *pUrlHistStg);
  146. static DWORD WINAPI s_CacheSearchThreadProc(CHistFolderEnum *penum);
  147. };
  148. //////////////////////////////////////////////////////////////////////////////
  149. //
  150. // CHistFolder Object
  151. //
  152. //////////////////////////////////////////////////////////////////////////////
  153. class CHistFolder :
  154. public IShellFolder2,
  155. public IShellIcon,
  156. public IShellFolderViewType,
  157. public IShellFolderSearchable,
  158. public IHistSFPrivate,
  159. public IPersistFolder2
  160. {
  161. friend CHistFolderEnum;
  162. friend CHistItem;
  163. friend HRESULT HistFolderView_CreateInstance(CHistFolder *pHCFolder, void **ppvOut);
  164. friend HRESULT HistFolderView_DidDragDrop(IDataObject *pdo, DWORD dwEffect);
  165. public:
  166. CHistFolder(FOLDER_TYPE FolderType);
  167. public:
  168. // IUnknown Methods
  169. STDMETHODIMP QueryInterface(REFIID, void **);
  170. STDMETHODIMP_(ULONG) AddRef(void);
  171. STDMETHODIMP_(ULONG) Release(void);
  172. // IShellFolder methods
  173. STDMETHODIMP ParseDisplayName(HWND hwnd, LPBC pbc, LPOLESTR pszDisplayName,
  174. ULONG *pchEaten, LPITEMIDLIST *ppidl, ULONG *pdwAttributes);
  175. STDMETHODIMP EnumObjects(HWND hwnd, DWORD grfFlags, IEnumIDList **ppenumIDList);
  176. STDMETHODIMP BindToObject(LPCITEMIDLIST pidl, LPBC pbc, REFIID riid, void **ppvOut);
  177. STDMETHODIMP BindToStorage(LPCITEMIDLIST pidl, LPBC pbc, REFIID riid, void **ppvObj);
  178. STDMETHODIMP CompareIDs(LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2);
  179. STDMETHODIMP CreateViewObject(HWND hwnd, REFIID riid, void **ppvOut);
  180. STDMETHODIMP GetAttributesOf(UINT cidl, LPCITEMIDLIST *apidl, ULONG *rgfInOut);
  181. STDMETHODIMP GetUIObjectOf(HWND hwnd, UINT cidl, LPCITEMIDLIST * apidl,
  182. REFIID riid, UINT * prgfInOut, void **ppvOut);
  183. STDMETHODIMP GetDisplayNameOf(LPCITEMIDLIST pidl, DWORD uFlags, LPSTRRET lpName);
  184. STDMETHODIMP SetNameOf(HWND hwnd, LPCITEMIDLIST pidl,
  185. LPCOLESTR lpszName, DWORD uFlags, LPITEMIDLIST * ppidlOut);
  186. // IShellFolder2
  187. STDMETHODIMP GetDefaultSearchGUID(LPGUID lpGuid) { return E_NOTIMPL; };
  188. STDMETHODIMP EnumSearches(LPENUMEXTRASEARCH *ppenum) { *ppenum = NULL; return E_NOTIMPL; };
  189. STDMETHODIMP GetDefaultColumn(DWORD dwRes, ULONG *pSort, ULONG *pDisplay);
  190. STDMETHODIMP GetDefaultColumnState(UINT iColumn, DWORD *pbState) { return E_NOTIMPL; };
  191. STDMETHODIMP GetDetailsEx(LPCITEMIDLIST pidl, const SHCOLUMNID *pscid, VARIANT *pv) { return E_NOTIMPL; };
  192. STDMETHODIMP GetDetailsOf(LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS *pDetails);
  193. STDMETHODIMP MapColumnToSCID(UINT iCol, SHCOLUMNID *pscid) { return E_NOTIMPL; };
  194. // IShellIcon
  195. STDMETHODIMP GetIconOf(LPCITEMIDLIST pidl, UINT flags, LPINT lpIconIndex);
  196. // IPersist
  197. STDMETHODIMP GetClassID(CLSID *pClassID);
  198. // IPersistFolder
  199. STDMETHODIMP Initialize(LPCITEMIDLIST pidl);
  200. // IPersistFolder2 Methods
  201. STDMETHODIMP GetCurFolder(LPITEMIDLIST *ppidl);
  202. // IShellFolderViewType Methods
  203. STDMETHODIMP EnumViews(ULONG grfFlags, IEnumIDList ** ppenum);
  204. STDMETHODIMP GetDefaultViewName(DWORD uFlags, LPWSTR *ppwszName);
  205. STDMETHODIMP GetViewTypeProperties(LPCITEMIDLIST pidl, DWORD *pdwFlags);
  206. STDMETHODIMP TranslateViewPidl(LPCITEMIDLIST pidl, LPCITEMIDLIST pidlView,
  207. LPITEMIDLIST *pidlOut);
  208. // IShellFolderSearchable Methods
  209. STDMETHODIMP FindString(LPCWSTR pwszTarget, DWORD *pdwFlags,
  210. IUnknown *punkOnAsyncSearch, LPITEMIDLIST *ppidlOut);
  211. STDMETHODIMP CancelAsyncSearch(LPCITEMIDLIST pidlSearch, DWORD *pdwFlags);
  212. STDMETHODIMP InvalidateSearch(LPCITEMIDLIST pidlSearch, DWORD *pdwFlags);
  213. // IHistSFPrivate
  214. STDMETHODIMP SetCachePrefix(LPCWSTR pszCachePrefix);
  215. STDMETHODIMP SetDomain(LPCWSTR pszDomain);
  216. STDMETHODIMP WriteHistory(LPCWSTR pszPrefixedUrl, FILETIME ftExpires,
  217. FILETIME ftModified, LPITEMIDLIST * ppidlSelect);
  218. STDMETHODIMP ClearHistory();
  219. HRESULT _ExtractInfoFromPidl();
  220. protected:
  221. ~CHistFolder();
  222. STDMETHODIMP _GetDetail(LPCITEMIDLIST pidl, UINT iColumn, LPTSTR pszStr, UINT cchStr);
  223. void _GetHistURLDispName(LPHEIPIDL phei, LPTSTR pszStr, UINT cchStr);
  224. HRESULT _CompareAlignedIDs(LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2);
  225. HRESULT _CopyTSTRField(LPTSTR *ppszField, LPCTSTR pszValue);
  226. HRESULT _LoadIntervalCache();
  227. HRESULT _GetInterval(FILETIME *pftItem, BOOL fWeekOnly, HSFINTERVAL **pInterval);
  228. HRESULT _CreateInterval(FILETIME *pftStart, DWORD dwDays);
  229. HRESULT _PrefixUrl(LPCTSTR pszStrippedUrl,
  230. FILETIME *pftLastModifiedTime,
  231. LPTSTR pszPrefixedUrl,
  232. DWORD cbPrefixedUrl);
  233. HRESULT _CopyEntries(LPCTSTR pszHistPrefix);
  234. HRESULT _DeleteEntries(LPCTSTR pszHistPrefix, PFNDELETECALLBACK pfnDeleteFilter, LPVOID pdcbData);
  235. HRESULT _DeleteInterval(HSFINTERVAL *pInterval);
  236. HRESULT _CleanUpHistory(FILETIME ftLimit, FILETIME ftTommorrow);
  237. HRESULT _ValidateIntervalCache();
  238. HRESULT _GetPrefixForInterval(LPCTSTR pszInterval, LPCTSTR *ppszCachePrefix);
  239. HRESULT _ViewType_NotifyEvent(LPITEMIDLIST pidlRoot,
  240. LPITEMIDLIST pidlHost,
  241. LPITEMIDLIST pidlPage,
  242. LONG wEventId);
  243. HRESULT _WriteHistory(LPCTSTR pszPrefixedUrl, FILETIME ftExpires, FILETIME ftModified,
  244. BOOL fSendNotify, LPITEMIDLIST * ppidlSelect);
  245. HRESULT _NotifyWrite(LPTSTR pszUrl, int cchUrl, FILETIME *pftModified, LPITEMIDLIST * ppidlSelect);
  246. HRESULT _NotifyInterval(HSFINTERVAL *pInterval, LONG lEventID);
  247. IUrlHistoryPriv *_GetHistStg();
  248. HRESULT _EnsureHistStg();
  249. HRESULT _GetUserName(LPTSTR pszUserName, DWORD cchUserName);
  250. HRESULT _GetInfoTip(LPCITEMIDLIST pidl, DWORD dwFlags, WCHAR **ppwszTip);
  251. HRESULT _DeleteItems(LPCITEMIDLIST *ppidl, UINT cidl);
  252. LPITEMIDLIST _HostPidl(LPCTSTR pszHostUrl, HSFINTERVAL *pInterval);
  253. DWORD _SearchFlatCacheForUrl(LPCTSTR pszUrl, LPINTERNET_CACHE_ENTRY_INFO pcei, DWORD *pdwBuffSize);
  254. HRESULT _ViewPidl_BindToObject(LPCITEMIDLIST pidl, LPBC pbc, REFIID riid, void **ppv);
  255. HRESULT _ViewType_BindToObject(LPCITEMIDLIST pidl, LPBC pbc, REFIID riid, void **ppv);
  256. HRESULT _ViewType_CompareIDs(LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2);
  257. int _View_ContinueCompare(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2);
  258. HRESULT _DeleteUrlFromBucket(LPCTSTR pszPrefixedUrl);
  259. HRESULT _ViewType_DeleteItems(LPCITEMIDLIST *ppidl, UINT cidl);
  260. HRESULT _ViewBySite_DeleteItems(LPCITEMIDLIST *ppidl, UINT cidl);
  261. HRESULT _ViewType_NotifyUpdateAll();
  262. HRESULT _ViewType_GetAttributesOf(UINT cidl, LPCITEMIDLIST *apidl, ULONG *prgfInOut);
  263. HRESULT _DeleteUrlHistoryGlobal(LPCTSTR pszUrl);
  264. DWORD _GetHitCount(LPCTSTR pszUrl);
  265. LPHEIPIDL _CreateHCacheFolderPidlFromUrl(BOOL fOleMalloc, LPCTSTR pszPrefixedUrl);
  266. BOOL _IsLeaf();
  267. LPCTSTR _GetLocalHost(void);
  268. LONG _cRef;
  269. FOLDER_TYPE _foldertype;
  270. TCHAR *_pszCachePrefix;
  271. TCHAR *_pszDomain;
  272. DWORD _dwIntervalCached;
  273. FILETIME _ftDayCached;
  274. int _cbIntervals;
  275. HSFINTERVAL *_pIntervalCache;
  276. BOOL _fValidatingCache;
  277. UINT _uFlags; // copied from CacheFolder struct
  278. LPITEMIDLIST _pidl; // copied from CacheFolder struct
  279. LPITEMIDLIST _pidlRest; // suffix of _pidl
  280. IUrlHistoryPriv *_pUrlHistStg; // used to get extended properties of history leafs
  281. UINT _uViewType; // if this shell folder is implementing a special view
  282. UINT _uViewDepth; // depth of the pidl
  283. const static DWORD _rdwFlagsTable[];
  284. TCHAR _szLocalHost[INTERNET_MAX_HOST_NAME_LENGTH]; // "My Computer" cached...
  285. class _CurrentSearches *_pcsCurrentSearch; // for CacheSearches
  286. static HRESULT CALLBACK _sViewCallback(IShellView *psv, IShellFolder *psf, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  287. };
  288. ////////////////////////////////////////////////////////////////////////////
  289. //
  290. // CHistItem Object
  291. //
  292. ////////////////////////////////////////////////////////////////////////////
  293. class CHistItem : public CBaseItem
  294. {
  295. // CHistItem interfaces
  296. friend HRESULT HistFolderView_DidDragDrop(IDataObject *pdo, DWORD dwEffect);
  297. public:
  298. CHistItem();
  299. HRESULT Initialize(CHistFolder *pHCFolder, HWND hwnd, UINT cidl, LPCITEMIDLIST *ppidl);
  300. // IUnknown Methods
  301. STDMETHODIMP QueryInterface(REFIID,void **);
  302. // IQueryInfo Methods
  303. STDMETHODIMP GetInfoTip(DWORD dwFlags, WCHAR **ppwszTip);
  304. // IContextMenu Methods
  305. STDMETHODIMP QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst,
  306. UINT idCmdLast, UINT uFlags);
  307. STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO lpici);
  308. // IDataObject Methods...
  309. STDMETHODIMP GetData(LPFORMATETC pFEIn, LPSTGMEDIUM pSTM);
  310. STDMETHODIMP QueryGetData(LPFORMATETC pFE);
  311. STDMETHODIMP EnumFormatEtc(DWORD dwDirection, LPENUMFORMATETC *ppEnum);
  312. // IExtractIconA Methods
  313. STDMETHODIMP GetIconLocation(UINT uFlags, LPSTR pszIconFile, UINT ucchMax, PINT pniIcon, PUINT puFlags);
  314. protected:
  315. ~CHistItem();
  316. virtual LPCTSTR _GetUrl(int nIndex);
  317. virtual UNALIGNED const TCHAR* _GetURLTitle(LPCITEMIDLIST pcei);
  318. virtual LPCTSTR _PidlToSourceUrl(LPCITEMIDLIST pidl);
  319. BOOL _ZoneCheck(int nIndex, DWORD dwUrlAction);
  320. FOLDER_TYPE _foldertype; // are we a history item or cache item
  321. CHistFolder* _pHCFolder; // back pointer to our shell folder
  322. static INT_PTR CALLBACK _sPropDlgProc(HWND, UINT, WPARAM, LPARAM);
  323. HRESULT _CreateFileDescriptorW(STGMEDIUM *pSTM);
  324. };
  325. #endif // __cplusplus
  326. #endif