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.

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