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.

476 lines
13 KiB

  1. #ifndef __CITEMLST_H_INCLUDED
  2. #define __CITEMLST_H_INCLUDED
  3. #include <windows.h>
  4. #include "wia.h"
  5. #include "uicommon.h"
  6. #include "simevent.h"
  7. class CCameraItem
  8. {
  9. public:
  10. enum CDeleteState
  11. {
  12. Delete_Visible,
  13. Delete_Pending,
  14. Delete_Deleted
  15. };
  16. private:
  17. CSimpleString m_strPreviewFileName;
  18. CComPtr<IWiaItem> m_pIWiaItem;
  19. CSimpleStringWide m_strwFullItemName;
  20. CCameraItem *m_pNext;
  21. CCameraItem *m_pChildren;
  22. CCameraItem *m_pParent;
  23. int m_nImageListIndex;
  24. int m_nCurrentPreviewPercentage;
  25. DWORD m_dwGlobalInterfaceTableCookie;
  26. CSimpleEvent m_CancelQueueEvent;
  27. CDeleteState m_DeleteState;
  28. LONG m_nItemType;
  29. LONG m_nItemRights;
  30. private:
  31. //
  32. // No implementation
  33. //
  34. CCameraItem(void);
  35. CCameraItem(const CCameraItem &);
  36. CCameraItem &operator=( const CCameraItem & );
  37. public:
  38. explicit CCameraItem( IWiaItem *pIWiaItem )
  39. : m_pIWiaItem(pIWiaItem),
  40. m_pNext(NULL),
  41. m_pChildren(NULL),
  42. m_pParent(NULL),
  43. m_nImageListIndex(-1),
  44. m_nCurrentPreviewPercentage(0),
  45. m_dwGlobalInterfaceTableCookie(0),
  46. m_CancelQueueEvent(true),
  47. m_DeleteState(Delete_Visible),
  48. m_nItemType(0),
  49. m_nItemRights(0)
  50. {
  51. WIA_PUSHFUNCTION(TEXT("CCameraItem::CCameraItem"));
  52. AddItemToGlobalInterfaceTable();
  53. WIA_TRACE((TEXT("Created CCameraItem(0x%08X)"),m_pIWiaItem.p));
  54. PropStorageHelpers::GetProperty( m_pIWiaItem, WIA_IPA_FULL_ITEM_NAME, m_strwFullItemName );
  55. PropStorageHelpers::GetProperty( m_pIWiaItem, WIA_IPA_ACCESS_RIGHTS, m_nItemRights );
  56. }
  57. HRESULT AddItemToGlobalInterfaceTable(void)
  58. {
  59. HRESULT hr = E_FAIL;
  60. if (Item())
  61. {
  62. CComPtr<IGlobalInterfaceTable> pGlobalInterfaceTable;
  63. hr = CoCreateInstance( CLSID_StdGlobalInterfaceTable,
  64. NULL,
  65. CLSCTX_INPROC_SERVER,
  66. IID_IGlobalInterfaceTable,
  67. (void **)&pGlobalInterfaceTable);
  68. if (SUCCEEDED(hr))
  69. {
  70. hr = pGlobalInterfaceTable->RegisterInterfaceInGlobal( Item(), IID_IWiaItem, &m_dwGlobalInterfaceTableCookie );
  71. if (SUCCEEDED(hr))
  72. {
  73. hr = S_OK;
  74. }
  75. }
  76. }
  77. return (hr);
  78. }
  79. HRESULT RemoveItemFromGlobalInterfaceTable(void)
  80. {
  81. HRESULT hr = E_FAIL;
  82. if (Item())
  83. {
  84. CComPtr<IGlobalInterfaceTable> pGlobalInterfaceTable;
  85. hr = CoCreateInstance( CLSID_StdGlobalInterfaceTable,
  86. NULL,
  87. CLSCTX_INPROC_SERVER,
  88. IID_IGlobalInterfaceTable,
  89. (void **)&pGlobalInterfaceTable);
  90. if (SUCCEEDED(hr))
  91. {
  92. hr = pGlobalInterfaceTable->RevokeInterfaceFromGlobal( m_dwGlobalInterfaceTableCookie );
  93. if (SUCCEEDED(hr))
  94. {
  95. hr = S_OK;
  96. }
  97. }
  98. }
  99. return (hr);
  100. }
  101. DWORD GlobalInterfaceTableCookie(void) const
  102. {
  103. return m_dwGlobalInterfaceTableCookie;
  104. }
  105. ~CCameraItem(void)
  106. {
  107. WIA_PUSHFUNCTION(TEXT("CCameraItem::~CCameraItem"));
  108. WIA_TRACE((TEXT("Destroyed CCameraItem(0x%08X)"),m_pIWiaItem.p));
  109. RemoveItemFromGlobalInterfaceTable();
  110. m_pIWiaItem.Release();
  111. if (m_strPreviewFileName.Length())
  112. {
  113. DeleteFile( m_strPreviewFileName.String() );
  114. m_strPreviewFileName = TEXT("");
  115. }
  116. m_pNext = m_pChildren = m_pParent = NULL;
  117. m_nImageListIndex = 0;
  118. m_CancelQueueEvent.Signal();
  119. m_CancelQueueEvent.Close();
  120. }
  121. IWiaItem *Item(void)
  122. {
  123. return(m_pIWiaItem);
  124. }
  125. const IWiaItem *Item(void) const
  126. {
  127. return(m_pIWiaItem.p);
  128. }
  129. IWiaItem *Item(IWiaItem *pIWiaItem)
  130. {
  131. return(m_pIWiaItem = pIWiaItem);
  132. }
  133. CDeleteState DeleteState(void) const
  134. {
  135. return m_DeleteState;
  136. }
  137. void DeleteState( CDeleteState DeleteState )
  138. {
  139. m_DeleteState = DeleteState;
  140. }
  141. int CurrentPreviewPercentage(void) const
  142. {
  143. return m_nCurrentPreviewPercentage;
  144. }
  145. int CurrentPreviewPercentage( int nCurrentPreviewPercentage )
  146. {
  147. return (m_nCurrentPreviewPercentage = nCurrentPreviewPercentage);
  148. }
  149. bool CreateCancelEvent(void)
  150. {
  151. m_nCurrentPreviewPercentage = 0;
  152. return m_CancelQueueEvent.Create();
  153. }
  154. bool CloseCancelEvent(void)
  155. {
  156. m_nCurrentPreviewPercentage = 0;
  157. return m_CancelQueueEvent.Close();
  158. }
  159. void SetCancelEvent(void)
  160. {
  161. m_CancelQueueEvent.Signal();
  162. }
  163. void ResetCancelEvent(void)
  164. {
  165. m_CancelQueueEvent.Reset();
  166. }
  167. CSimpleEvent &CancelQueueEvent(void)
  168. {
  169. return m_CancelQueueEvent;
  170. }
  171. bool PreviewRequestPending(void) const
  172. {
  173. return (m_CancelQueueEvent.Event() != NULL);
  174. }
  175. CSimpleString PreviewFileName(void) const
  176. {
  177. return m_strPreviewFileName;
  178. }
  179. const CSimpleString &PreviewFileName( const CSimpleString &strPreviewFileName )
  180. {
  181. return (m_strPreviewFileName = strPreviewFileName);
  182. }
  183. int ImageListIndex(void) const
  184. {
  185. return(m_nImageListIndex);
  186. }
  187. int ImageListIndex( int nImageListIndex )
  188. {
  189. return (m_nImageListIndex = nImageListIndex);
  190. }
  191. LONG ItemType(void)
  192. {
  193. if (!Item())
  194. {
  195. return 0;
  196. }
  197. if (!m_nItemType)
  198. {
  199. Item()->GetItemType(&m_nItemType);
  200. }
  201. return m_nItemType;
  202. }
  203. LONG ItemRights() const
  204. {
  205. return m_nItemRights;
  206. }
  207. bool IsFolder(void)
  208. {
  209. return ((ItemType() & WiaItemTypeFolder) != 0);
  210. }
  211. bool IsImage(void)
  212. {
  213. return ((ItemType() & WiaItemTypeImage) != 0);
  214. }
  215. CSimpleStringWide FullItemName(void) const
  216. {
  217. return m_strwFullItemName;
  218. }
  219. bool operator==( const CCameraItem &other )
  220. {
  221. return(Item() == other.Item());
  222. }
  223. const CCameraItem *Next(void) const
  224. {
  225. return(m_pNext);
  226. }
  227. CCameraItem *Next(void)
  228. {
  229. return(m_pNext);
  230. }
  231. CCameraItem *Next( CCameraItem *pNext )
  232. {
  233. return(m_pNext = pNext);
  234. }
  235. const CCameraItem *Children(void) const
  236. {
  237. return(m_pChildren);
  238. }
  239. CCameraItem *Children(void)
  240. {
  241. return(m_pChildren);
  242. }
  243. CCameraItem *Children( CCameraItem *pChildren )
  244. {
  245. return(m_pChildren = pChildren);
  246. }
  247. const CCameraItem *Parent(void) const
  248. {
  249. return(m_pParent);
  250. }
  251. CCameraItem *Parent(void)
  252. {
  253. return(m_pParent);
  254. }
  255. CCameraItem *Parent( CCameraItem *pParent )
  256. {
  257. return(m_pParent = pParent);
  258. }
  259. };
  260. class CCameraItemList
  261. {
  262. private:
  263. CCameraItem *m_pRoot;
  264. public:
  265. CCameraItemList(void)
  266. : m_pRoot(NULL)
  267. {
  268. }
  269. ~CCameraItemList(void)
  270. {
  271. Destroy(m_pRoot);
  272. m_pRoot = NULL;
  273. }
  274. void Destroy( CCameraItem *pRoot )
  275. {
  276. while (pRoot)
  277. {
  278. Destroy(pRoot->Children());
  279. CCameraItem *pCurr = pRoot;
  280. pRoot = pRoot->Next();
  281. delete pCurr;
  282. }
  283. }
  284. const CCameraItem *Root(void) const
  285. {
  286. return(m_pRoot);
  287. }
  288. CCameraItem *Root(void)
  289. {
  290. return(m_pRoot);
  291. }
  292. CCameraItem *Root( CCameraItem *pRoot )
  293. {
  294. return(m_pRoot = pRoot);
  295. }
  296. static CCameraItem *Find( CCameraItem *pRoot, const CCameraItem *pNode )
  297. {
  298. for (CCameraItem *pCurr = pRoot;pCurr;pCurr = pCurr->Next())
  299. {
  300. if (pCurr->DeleteState() != CCameraItem::Delete_Deleted)
  301. {
  302. if (*pCurr == *pNode)
  303. return(pCurr);
  304. if (pCurr->Children())
  305. {
  306. CCameraItem *pFind = Find( pCurr->Children(), pNode );
  307. if (pFind)
  308. return pFind;
  309. }
  310. }
  311. }
  312. return(NULL);
  313. }
  314. CCameraItem *Find( CCameraItem *pNode )
  315. {
  316. return(Find( m_pRoot, pNode ));
  317. }
  318. static CCameraItem *Find( CCameraItem *pRoot, IWiaItem *pItem )
  319. {
  320. for (CCameraItem *pCurr = pRoot;pCurr;pCurr = pCurr->Next())
  321. {
  322. if (pCurr->DeleteState() != CCameraItem::Delete_Deleted)
  323. {
  324. if (pCurr->Item() == pItem)
  325. return(pCurr);
  326. if (pCurr->Children())
  327. {
  328. CCameraItem *pFind = Find( pCurr->Children(), pItem );
  329. if (pFind)
  330. return pFind;
  331. }
  332. }
  333. }
  334. return(NULL);
  335. }
  336. CCameraItem *Find( IWiaItem *pItem )
  337. {
  338. return(Find( m_pRoot, pItem ));
  339. }
  340. static CCameraItem *Find( CCameraItem *pRoot, DWORD dwGlobalInterfaceTableCookie )
  341. {
  342. for (CCameraItem *pCurr = pRoot;pCurr;pCurr = pCurr->Next())
  343. {
  344. if (pCurr->DeleteState() != CCameraItem::Delete_Deleted)
  345. {
  346. if (pCurr->GlobalInterfaceTableCookie() == dwGlobalInterfaceTableCookie)
  347. return(pCurr);
  348. if (pCurr->Children())
  349. {
  350. CCameraItem *pFind = Find( pCurr->Children(), dwGlobalInterfaceTableCookie );
  351. if (pFind)
  352. return pFind;
  353. }
  354. }
  355. }
  356. return(NULL);
  357. }
  358. CCameraItem *Find( DWORD dwGlobalInterfaceTableCookie )
  359. {
  360. return(Find( m_pRoot, dwGlobalInterfaceTableCookie ));
  361. }
  362. CCameraItem *Find( CCameraItem *pRoot, const CSimpleBStr &bstrFullItemName )
  363. {
  364. CSimpleStringWide strwTemp;
  365. for (CCameraItem *pCurr = pRoot;pCurr && bstrFullItemName.BString();pCurr = pCurr->Next())
  366. {
  367. if (pCurr->DeleteState() != CCameraItem::Delete_Deleted)
  368. {
  369. strwTemp = pCurr->FullItemName();
  370. if (wcscmp(strwTemp, bstrFullItemName) == 0)
  371. {
  372. return pCurr;
  373. }
  374. if (pCurr->Children())
  375. {
  376. CCameraItem *pFind = Find( pCurr->Children(), bstrFullItemName );
  377. if (pFind)
  378. return pFind;
  379. }
  380. }
  381. }
  382. return NULL;
  383. }
  384. CCameraItem *Find( const CSimpleBStr &bstrFullItemName )
  385. {
  386. return Find( m_pRoot, bstrFullItemName );
  387. }
  388. void Add( CCameraItem *pParent, CCameraItem *pNewCameraItemNode )
  389. {
  390. WIA_PUSHFUNCTION(TEXT("CCameraItemList::Add"));
  391. WIA_TRACE((TEXT("Root(): 0x%08X"), Root()));
  392. if (pNewCameraItemNode)
  393. {
  394. if (!Root())
  395. {
  396. Root(pNewCameraItemNode);
  397. pNewCameraItemNode->Parent(NULL);
  398. pNewCameraItemNode->Children(NULL);
  399. pNewCameraItemNode->Next(NULL);
  400. }
  401. else
  402. {
  403. if (!pParent)
  404. {
  405. CCameraItem *pCurr=Root();
  406. while (pCurr && pCurr->Next())
  407. {
  408. pCurr=pCurr->Next();
  409. }
  410. if (pCurr)
  411. {
  412. pCurr->Next(pNewCameraItemNode);
  413. }
  414. pNewCameraItemNode->Next(NULL);
  415. pNewCameraItemNode->Children(NULL);
  416. pNewCameraItemNode->Parent(NULL);
  417. }
  418. else if (!pParent->Children())
  419. {
  420. pParent->Children(pNewCameraItemNode);
  421. pNewCameraItemNode->Next(NULL);
  422. pNewCameraItemNode->Children(NULL);
  423. pNewCameraItemNode->Parent(pParent);
  424. }
  425. else
  426. {
  427. CCameraItem *pCurr=pParent->Children();
  428. while (pCurr && pCurr->Next())
  429. {
  430. pCurr=pCurr->Next();
  431. }
  432. if (pCurr)
  433. {
  434. pCurr->Next(pNewCameraItemNode);
  435. }
  436. pNewCameraItemNode->Next(NULL);
  437. pNewCameraItemNode->Children(NULL);
  438. pNewCameraItemNode->Parent(pParent);
  439. }
  440. }
  441. }
  442. }
  443. };
  444. #endif //__CITEMLST_H_INCLUDED