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.

439 lines
12 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 2000
  4. *
  5. * TITLE: DESTDATA.H
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 4/6/2000
  12. *
  13. * DESCRIPTION: wrapper class to encapsulate plugins and directories
  14. *
  15. *******************************************************************************/
  16. #ifndef __DESTDATA_H_INCLUDED
  17. #define __DESTDATA_H_INCLUDED
  18. #include <windows.h>
  19. #include <uicommon.h>
  20. #include "simidlst.h"
  21. #include "simstr.h"
  22. class CDestinationData
  23. {
  24. public:
  25. enum
  26. {
  27. APPEND_DATE_TO_PATH = 0x00000001,
  28. APPEND_TOPIC_TO_PATH = 0x00000002,
  29. DECORATION_MASK = 0x0000000F,
  30. SPECIAL_FOLDER = 0x00000020
  31. };
  32. struct CNameData
  33. {
  34. public:
  35. CSimpleString strDate;
  36. CSimpleString strTopic;
  37. CSimpleString strDateAndTopic;
  38. };
  39. private:
  40. CSimpleIdList m_IdList;
  41. DWORD m_dwFlags;
  42. CNameData m_NameData;
  43. DWORD m_dwCsidl;
  44. HICON m_hSmallIcon;
  45. public:
  46. CDestinationData(void)
  47. : m_dwFlags(0),
  48. m_dwCsidl(0),
  49. m_hSmallIcon(NULL)
  50. {
  51. }
  52. CDestinationData( const CDestinationData &other )
  53. : m_IdList(other.IdList()),
  54. m_dwFlags(other.Flags()),
  55. m_dwCsidl(other.Csidl()),
  56. m_hSmallIcon(NULL)
  57. {
  58. }
  59. void AssignFromIdList( const CSimpleIdList &idList, DWORD dwDecorationFlags )
  60. {
  61. Destroy();
  62. //
  63. // Here is the list of special folders we want to display
  64. // with their short names. Others will be stored as full paths
  65. // in PIDLs.
  66. //
  67. static const DWORD cs_SpecialFolders[] =
  68. {
  69. CSIDL_MYPICTURES,
  70. CSIDL_PERSONAL,
  71. CSIDL_COMMON_PICTURES
  72. };
  73. //
  74. // Try to find a matching PIDL in the list.
  75. //
  76. for (int i=0;i<ARRAYSIZE(cs_SpecialFolders);i++)
  77. {
  78. //
  79. // If we've found one, store the CSIDL and mark this one as a special folder.
  80. // Then exit the loop.
  81. //
  82. if (CSimpleIdList().GetSpecialFolder(NULL,cs_SpecialFolders[i]|CSIDL_FLAG_CREATE) == idList)
  83. {
  84. m_dwFlags |= SPECIAL_FOLDER;
  85. m_dwCsidl = cs_SpecialFolders[i];
  86. break;
  87. }
  88. }
  89. //
  90. // If we didn't find a special pidl, store it as a full path
  91. //
  92. if (!m_dwCsidl)
  93. {
  94. m_IdList = idList;
  95. }
  96. //
  97. // Add in any decoration flags
  98. //
  99. m_dwFlags |= dwDecorationFlags;
  100. }
  101. CDestinationData( LPITEMIDLIST pidl, DWORD dwDecorationFlags=0)
  102. : m_dwFlags(0),
  103. m_dwCsidl(0)
  104. {
  105. AssignFromIdList( pidl, dwDecorationFlags );
  106. }
  107. CDestinationData( CSimpleIdList idList, DWORD dwDecorationFlags=0 )
  108. : m_dwFlags(0),
  109. m_dwCsidl(0)
  110. {
  111. AssignFromIdList( idList, dwDecorationFlags );
  112. }
  113. CDestinationData( int nCsidl, DWORD dwDecorationFlags=0 )
  114. : m_dwFlags(dwDecorationFlags | SPECIAL_FOLDER),
  115. m_dwCsidl(static_cast<DWORD>(nCsidl))
  116. {
  117. }
  118. DWORD Flags(void) const
  119. {
  120. return m_dwFlags;
  121. }
  122. DWORD Csidl(void) const
  123. {
  124. return m_dwCsidl;
  125. }
  126. CDestinationData &operator=( const CDestinationData &other )
  127. {
  128. if (this != &other)
  129. {
  130. Destroy();
  131. m_IdList = other.IdList();
  132. m_dwFlags = other.Flags();
  133. m_dwCsidl = other.Csidl();
  134. }
  135. return *this;
  136. }
  137. ~CDestinationData(void)
  138. {
  139. Destroy();
  140. }
  141. void Destroy(void)
  142. {
  143. m_IdList.Destroy();
  144. m_dwFlags = 0;
  145. m_dwCsidl = 0;
  146. if (m_hSmallIcon)
  147. {
  148. DestroyIcon(m_hSmallIcon);
  149. m_hSmallIcon = NULL;
  150. }
  151. }
  152. const CSimpleIdList &IdList(void) const
  153. {
  154. return m_IdList;
  155. }
  156. bool IsSpecialFolder(void) const
  157. {
  158. if (m_dwFlags & SPECIAL_FOLDER)
  159. {
  160. return true;
  161. }
  162. return false;
  163. }
  164. bool operator==( const CDestinationData &other ) const
  165. {
  166. if (IsSpecialFolder() && other.IsSpecialFolder())
  167. {
  168. if (Csidl() == other.Csidl())
  169. {
  170. if ((Flags() & DECORATION_MASK) == (other.Flags() & DECORATION_MASK))
  171. {
  172. return true;
  173. }
  174. }
  175. return false;
  176. }
  177. else if (m_IdList.Name() == other.IdList().Name())
  178. {
  179. if ((Flags() & DECORATION_MASK) == (other.Flags() & DECORATION_MASK))
  180. {
  181. return true;
  182. }
  183. }
  184. return false;
  185. }
  186. bool GetDecoration( CSimpleString &strResult, const CNameData &NameData ) const
  187. {
  188. if ((Flags() & DECORATION_MASK)==(APPEND_TOPIC_TO_PATH|APPEND_DATE_TO_PATH))
  189. {
  190. strResult = NameData.strDateAndTopic;
  191. }
  192. else if ((Flags() & DECORATION_MASK)==APPEND_DATE_TO_PATH)
  193. {
  194. strResult = NameData.strDate;
  195. }
  196. else if ((Flags() & DECORATION_MASK)==APPEND_TOPIC_TO_PATH)
  197. {
  198. strResult = NameData.strTopic;
  199. }
  200. return (strResult.Length() != 0);
  201. }
  202. void AppendDecoration( CSimpleString &strResult, const CNameData &NameData ) const
  203. {
  204. if ((Flags() & DECORATION_MASK)==(APPEND_TOPIC_TO_PATH|APPEND_DATE_TO_PATH))
  205. {
  206. strResult += TEXT("\\");
  207. strResult += NameData.strDateAndTopic;
  208. }
  209. else if ((Flags() & DECORATION_MASK)==APPEND_DATE_TO_PATH)
  210. {
  211. strResult += TEXT("\\");
  212. strResult += NameData.strDate;
  213. }
  214. else if ((Flags() & DECORATION_MASK)==APPEND_TOPIC_TO_PATH)
  215. {
  216. strResult += TEXT("\\");
  217. strResult += NameData.strTopic;
  218. }
  219. }
  220. CSimpleString Path( const CNameData &NameData ) const
  221. {
  222. CSimpleString strResult;
  223. if (IsSpecialFolder())
  224. {
  225. strResult = CSimpleIdList().GetSpecialFolder(NULL,m_dwCsidl|CSIDL_FLAG_CREATE).Name();
  226. AppendDecoration( strResult, NameData );
  227. }
  228. else
  229. {
  230. strResult = m_IdList.Name();
  231. AppendDecoration( strResult, NameData );
  232. }
  233. return strResult;
  234. }
  235. bool IsValidFileSystemPath( const CNameData &NameData ) const
  236. {
  237. bool bResult = true;
  238. CSimpleString strDecoration;
  239. if (GetDecoration( strDecoration, NameData ))
  240. {
  241. for (LPCTSTR pszCurr = strDecoration.String();pszCurr && *pszCurr && bResult;pszCurr = CharNext(pszCurr))
  242. {
  243. if (*pszCurr == TEXT(':') ||
  244. *pszCurr == TEXT('\\') ||
  245. *pszCurr == TEXT('/') ||
  246. *pszCurr == TEXT('?') ||
  247. *pszCurr == TEXT('"') ||
  248. *pszCurr == TEXT('<') ||
  249. *pszCurr == TEXT('>') ||
  250. *pszCurr == TEXT('|') ||
  251. *pszCurr == TEXT('*'))
  252. {
  253. bResult = false;
  254. }
  255. }
  256. }
  257. return bResult;
  258. }
  259. bool operator!=( const CDestinationData &other ) const
  260. {
  261. return ((*this == other) == false);
  262. }
  263. bool IsValid(void) const
  264. {
  265. if (IsSpecialFolder())
  266. {
  267. return true;
  268. }
  269. else
  270. {
  271. return m_IdList.IsValid();
  272. }
  273. }
  274. HICON SmallIcon()
  275. {
  276. if (m_hSmallIcon)
  277. {
  278. return m_hSmallIcon;
  279. }
  280. if (IsValid())
  281. {
  282. if (IsSpecialFolder())
  283. {
  284. //
  285. // Get the folder's small icon
  286. //
  287. SHFILEINFO shfi = {0};
  288. HIMAGELIST hShellImageList = reinterpret_cast<HIMAGELIST>(SHGetFileInfo( reinterpret_cast<LPCTSTR>(CSimpleIdList().GetSpecialFolder(NULL,m_dwCsidl|CSIDL_FLAG_CREATE).IdList()), 0, &shfi, sizeof(shfi), SHGFI_SMALLICON | SHGFI_ICON | SHGFI_PIDL ));
  289. if (hShellImageList)
  290. {
  291. m_hSmallIcon = shfi.hIcon;
  292. }
  293. }
  294. else
  295. {
  296. //
  297. // Get the folder's small icon
  298. //
  299. SHFILEINFO shfi = {0};
  300. HIMAGELIST hShellImageList = reinterpret_cast<HIMAGELIST>(SHGetFileInfo( reinterpret_cast<LPCTSTR>(m_IdList.IdList()), 0, &shfi, sizeof(shfi), SHGFI_SMALLICON | SHGFI_ICON | SHGFI_PIDL ));
  301. if (hShellImageList)
  302. {
  303. m_hSmallIcon = shfi.hIcon;
  304. }
  305. }
  306. }
  307. return m_hSmallIcon;
  308. }
  309. CSimpleString DisplayName( const CNameData &NameData )
  310. {
  311. CSimpleString strDisplayName;
  312. //
  313. // Get the folder's display name
  314. //
  315. if (IsSpecialFolder())
  316. {
  317. SHFILEINFO shfi = {0};
  318. if (SHGetFileInfo( reinterpret_cast<LPCTSTR>(CSimpleIdList().GetSpecialFolder(NULL,m_dwCsidl|CSIDL_FLAG_CREATE).IdList()), 0, &shfi, sizeof(shfi), SHGFI_PIDL | SHGFI_DISPLAYNAME ))
  319. {
  320. strDisplayName = shfi.szDisplayName;
  321. }
  322. AppendDecoration( strDisplayName, NameData );
  323. }
  324. else if (m_IdList.IsValid())
  325. {
  326. TCHAR szPath[MAX_PATH];
  327. if (SHGetPathFromIDList( m_IdList.IdList(), szPath ))
  328. {
  329. strDisplayName = szPath;
  330. }
  331. AppendDecoration( strDisplayName, NameData );
  332. }
  333. return strDisplayName;
  334. }
  335. UINT RegistryDataSize(void) const
  336. {
  337. if (m_dwCsidl)
  338. {
  339. return sizeof(DWORD) + sizeof(DWORD);
  340. }
  341. else
  342. {
  343. return sizeof(DWORD) + sizeof(DWORD) + m_IdList.Size();
  344. }
  345. }
  346. UINT GetRegistryData( PBYTE pData, UINT nLength ) const
  347. {
  348. UINT nResult = 0;
  349. if (pData)
  350. {
  351. if (nLength >= RegistryDataSize())
  352. {
  353. if (IsSpecialFolder())
  354. {
  355. CopyMemory(pData,&m_dwFlags,sizeof(DWORD));
  356. pData += sizeof(DWORD);
  357. CopyMemory( pData, &m_dwCsidl, sizeof(DWORD));
  358. }
  359. else
  360. {
  361. CopyMemory(pData,&m_dwFlags,sizeof(DWORD));
  362. pData += sizeof(DWORD);
  363. DWORD dwSize = m_IdList.Size();
  364. CopyMemory(pData,&dwSize,sizeof(DWORD));
  365. pData += sizeof(DWORD);
  366. CopyMemory(pData,m_IdList.IdList(),dwSize);
  367. }
  368. nResult = RegistryDataSize();
  369. }
  370. }
  371. return nResult;
  372. }
  373. UINT SetRegistryData( PBYTE pData, UINT nLength )
  374. {
  375. UINT nResult = 0;
  376. Destroy();
  377. if (pData)
  378. {
  379. //
  380. // Copy the flags
  381. //
  382. CopyMemory( &m_dwFlags, pData, sizeof(DWORD) );
  383. pData += sizeof(DWORD);
  384. nLength -= sizeof(DWORD);
  385. //
  386. // If this is a web destination, we already have what we need
  387. //
  388. if (m_dwFlags & SPECIAL_FOLDER)
  389. {
  390. CopyMemory(&m_dwCsidl,pData,sizeof(DWORD));
  391. nLength -= sizeof(DWORD);
  392. nResult = nLength;
  393. }
  394. else
  395. {
  396. DWORD dwPidlLength = 0;
  397. CopyMemory(&dwPidlLength,pData,sizeof(DWORD));
  398. pData += sizeof(DWORD);
  399. nLength -= sizeof(DWORD);
  400. if (nLength >= dwPidlLength)
  401. {
  402. m_IdList = CSimpleIdList(pData,dwPidlLength);
  403. if (m_IdList.IsValid())
  404. {
  405. nResult = nLength;
  406. }
  407. }
  408. }
  409. }
  410. return nResult;
  411. }
  412. };
  413. #endif // __DESTDATA_H_INCLUDED