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.

1179 lines
36 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: THRDMSG.H
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 9/28/1999
  12. *
  13. * DESCRIPTION: These classes are instantiated for each message posted to the
  14. * background thread. Each is derived from CThreadMessage, and
  15. * is sent to the thread message handler.
  16. *
  17. *******************************************************************************/
  18. #ifndef __THRDMSG_H_INCLUDED
  19. #define __THRDMSG_H_INCLUDED
  20. #include <windows.h>
  21. #include "bkthread.h"
  22. #include "wia.h"
  23. #include "memdib.h"
  24. #include "gphelper.h"
  25. #include "thrdntfy.h"
  26. #include "itranspl.h"
  27. #include "itranhlp.h"
  28. #include "isuppfmt.h"
  29. #include "wiadevdp.h"
  30. // Thread queue messages
  31. #define TQ_DESTROY (WM_USER+1)
  32. #define TQ_DOWNLOADIMAGE (WM_USER+2)
  33. #define TQ_DOWNLOADTHUMBNAIL (WM_USER+3)
  34. #define TQ_SCANPREVIEW (WM_USER+4)
  35. #define TQ_DOWNLOADERROR (WM_USER+5)
  36. #define TQ_DELETEIMAGES (WM_USER+6)
  37. // Base class for other thread messages messages
  38. class CGlobalInterfaceTableThreadMessage : public CNotifyThreadMessage
  39. {
  40. private:
  41. DWORD m_dwGlobalInterfaceTableCookie;
  42. private:
  43. // No implementation
  44. CGlobalInterfaceTableThreadMessage(void);
  45. CGlobalInterfaceTableThreadMessage &operator=( const CGlobalInterfaceTableThreadMessage & );
  46. CGlobalInterfaceTableThreadMessage( const CGlobalInterfaceTableThreadMessage & );
  47. public:
  48. CGlobalInterfaceTableThreadMessage( int nMessage, HWND hWndNotify, DWORD dwGlobalInterfaceTableCookie );
  49. DWORD GlobalInterfaceTableCookie(void) const;
  50. };
  51. //
  52. // Thread handler class for downloading all the camera thumbnails images
  53. //
  54. class CDownloadThumbnailsThreadMessage : public CNotifyThreadMessage
  55. {
  56. private:
  57. CSimpleDynamicArray<DWORD> m_Cookies;
  58. HANDLE m_hCancelEvent;
  59. private:
  60. // No implementation
  61. CDownloadThumbnailsThreadMessage(void);
  62. CDownloadThumbnailsThreadMessage &operator=( const CDownloadThumbnailsThreadMessage & );
  63. CDownloadThumbnailsThreadMessage( const CDownloadThumbnailsThreadMessage & );
  64. public:
  65. // Sole constructor
  66. CDownloadThumbnailsThreadMessage(
  67. HWND hWndNotify,
  68. const CSimpleDynamicArray<DWORD> &Cookies,
  69. HANDLE hCancelEvent
  70. );
  71. virtual ~CDownloadThumbnailsThreadMessage(void);
  72. HRESULT Download(void);
  73. };
  74. //
  75. // Notification message that gets sent for each thumbnail download
  76. //
  77. class CDownloadThumbnailsThreadNotifyMessage : public CThreadNotificationMessage
  78. {
  79. public:
  80. enum COperation
  81. {
  82. DownloadAll,
  83. DownloadThumbnail
  84. };
  85. enum CStatus
  86. {
  87. Begin,
  88. Update,
  89. End
  90. };
  91. private:
  92. COperation m_Operation;
  93. CStatus m_Status;
  94. HRESULT m_hr;
  95. UINT m_nPictureCount;
  96. UINT m_nCurrentPicture;
  97. DWORD m_dwCookie;
  98. PBYTE m_pBitmapData;
  99. LONG m_nWidth;
  100. LONG m_nHeight;
  101. LONG m_nBitmapDataLength;
  102. GUID m_guidDefaultFormat;
  103. LONG m_nAccessRights;
  104. LONG m_nPictureWidth;
  105. LONG m_nPictureHeight;
  106. CAnnotationType m_AnnotationType;
  107. CSimpleString m_strDefExt;
  108. private:
  109. CDownloadThumbnailsThreadNotifyMessage(void);
  110. CDownloadThumbnailsThreadNotifyMessage( const CDownloadThumbnailsThreadNotifyMessage & );
  111. CDownloadThumbnailsThreadNotifyMessage &operator=( const CDownloadThumbnailsThreadNotifyMessage & );
  112. private:
  113. CDownloadThumbnailsThreadNotifyMessage( COperation Operation, CStatus Status, HRESULT hr, UINT nPictureCount, UINT nCurrentPicture, DWORD dwCookie, PBYTE pBitmapData, LONG nWidth, LONG nHeight, LONG nBitmapDataLength, const GUID &guidDefaultFormat, LONG nAccessRights, LONG nPictureWidth, LONG nPictureHeight, CAnnotationType AnnotationType, const CSimpleString &strDefExt )
  114. : CThreadNotificationMessage( TQ_DOWNLOADTHUMBNAIL ),
  115. m_Operation(Operation),
  116. m_Status(Status),
  117. m_hr(hr),
  118. m_nPictureCount(nPictureCount),
  119. m_nCurrentPicture(nCurrentPicture),
  120. m_dwCookie(dwCookie),
  121. m_pBitmapData(pBitmapData),
  122. m_nWidth(nWidth),
  123. m_nHeight(nHeight),
  124. m_nBitmapDataLength(nBitmapDataLength),
  125. m_guidDefaultFormat(guidDefaultFormat),
  126. m_nAccessRights(nAccessRights),
  127. m_nPictureWidth(nPictureWidth),
  128. m_nPictureHeight(nPictureHeight),
  129. m_AnnotationType(AnnotationType),
  130. m_strDefExt(strDefExt)
  131. {
  132. }
  133. public:
  134. virtual ~CDownloadThumbnailsThreadNotifyMessage(void)
  135. {
  136. if (m_pBitmapData)
  137. {
  138. LocalFree(m_pBitmapData);
  139. m_pBitmapData = NULL;
  140. }
  141. }
  142. COperation Operation(void) const
  143. {
  144. return m_Operation;
  145. }
  146. CStatus Status(void) const
  147. {
  148. return m_Status;
  149. }
  150. HRESULT hr(void) const
  151. {
  152. return m_hr;
  153. }
  154. UINT PictureCount(void) const
  155. {
  156. return m_nPictureCount;
  157. }
  158. UINT CurrentPicture(void) const
  159. {
  160. return m_nCurrentPicture;
  161. }
  162. DWORD Cookie(void) const
  163. {
  164. return m_dwCookie;
  165. }
  166. PBYTE BitmapData(void) const
  167. {
  168. return m_pBitmapData;
  169. }
  170. LONG Width(void) const
  171. {
  172. return m_nWidth;
  173. }
  174. LONG Height(void) const
  175. {
  176. return m_nHeight;
  177. }
  178. LONG BitmapDataLength(void) const
  179. {
  180. return m_nBitmapDataLength;
  181. }
  182. GUID DefaultFormat(void) const
  183. {
  184. return m_guidDefaultFormat;
  185. }
  186. LONG AccessRights(void) const
  187. {
  188. return m_nAccessRights;
  189. }
  190. LONG PictureWidth(void) const
  191. {
  192. return m_nPictureWidth;
  193. }
  194. LONG PictureHeight(void) const
  195. {
  196. return m_nPictureHeight;
  197. }
  198. PBYTE DetachBitmapData(void)
  199. {
  200. PBYTE pResult = m_pBitmapData;
  201. m_pBitmapData = NULL;
  202. return pResult;
  203. }
  204. CAnnotationType AnnotationType(void) const
  205. {
  206. return m_AnnotationType;
  207. }
  208. CSimpleString DefExt() const
  209. {
  210. return m_strDefExt;
  211. }
  212. public:
  213. static CDownloadThumbnailsThreadNotifyMessage *BeginDownloadAllMessage( UINT nPictureCount )
  214. {
  215. return new CDownloadThumbnailsThreadNotifyMessage( DownloadAll, Begin, S_OK, nPictureCount, 0, 0, NULL, 0, 0, 0, IID_NULL, 0, 0, 0, AnnotationNone, TEXT("") );
  216. }
  217. static CDownloadThumbnailsThreadNotifyMessage *BeginDownloadThumbnailMessage( UINT nCurrentPicture, DWORD dwCookie )
  218. {
  219. return new CDownloadThumbnailsThreadNotifyMessage( DownloadThumbnail, Begin, S_OK, 0, nCurrentPicture, dwCookie, NULL, 0, 0, 0, IID_NULL, 0, 0, 0, AnnotationNone, TEXT("") );
  220. }
  221. static CDownloadThumbnailsThreadNotifyMessage *EndDownloadThumbnailMessage( UINT nCurrentPicture, DWORD dwCookie, PBYTE pBitmapData, LONG nWidth, LONG nHeight, LONG nBitmapDataLength, const GUID &guidFormat, LONG nAccessRights, LONG nPictureWidth, LONG nPictureHeight, CAnnotationType AnnotationType, const CSimpleString &strDefExt )
  222. {
  223. return new CDownloadThumbnailsThreadNotifyMessage( DownloadThumbnail, End, S_OK, 0, nCurrentPicture, dwCookie, pBitmapData, nWidth, nHeight, nBitmapDataLength, guidFormat, nAccessRights, nPictureWidth, nPictureHeight, AnnotationType, strDefExt );
  224. }
  225. static CDownloadThumbnailsThreadNotifyMessage *EndDownloadAllMessage( HRESULT hr )
  226. {
  227. return new CDownloadThumbnailsThreadNotifyMessage( DownloadAll, End, hr, 0, 0, 0, 0, 0, 0, NULL, IID_NULL, 0, 0, 0, AnnotationNone, TEXT("") );
  228. }
  229. };
  230. class CTransferItem
  231. {
  232. private:
  233. CComPtr<IWiaItem> m_pWiaItem;
  234. CSimpleString m_strFilename;
  235. GUID m_guidInputFormat;
  236. GUID m_guidOutputFormat;
  237. HANDLE m_hFile;
  238. LONG m_nMediaType;
  239. public:
  240. CTransferItem( IWiaItem *pWiaItem = NULL, const CSimpleString &strFilename=TEXT("") )
  241. : m_pWiaItem(pWiaItem),
  242. m_strFilename(strFilename),
  243. m_guidInputFormat(IID_NULL),
  244. m_guidOutputFormat(IID_NULL),
  245. m_hFile(INVALID_HANDLE_VALUE),
  246. m_nMediaType(TYMED_FILE)
  247. {
  248. }
  249. CTransferItem( const CTransferItem &other )
  250. : m_pWiaItem(other.WiaItem()),
  251. m_strFilename(other.Filename()),
  252. m_guidInputFormat(other.InputFormat()),
  253. m_guidOutputFormat(other.OutputFormat()),
  254. m_hFile(INVALID_HANDLE_VALUE),
  255. m_nMediaType(other.MediaType())
  256. {
  257. if (other.FileHandle() != INVALID_HANDLE_VALUE)
  258. {
  259. DuplicateHandle( GetCurrentProcess(), other.FileHandle(), GetCurrentProcess(), &m_hFile, 0, FALSE, DUPLICATE_SAME_ACCESS );
  260. }
  261. }
  262. void Destroy(void)
  263. {
  264. ClosePlaceholderFile();
  265. m_pWiaItem = NULL;
  266. m_strFilename = TEXT("");
  267. m_guidInputFormat = IID_NULL;
  268. m_guidOutputFormat = IID_NULL;
  269. m_nMediaType = 0;
  270. }
  271. ~CTransferItem(void)
  272. {
  273. Destroy();
  274. }
  275. CTransferItem &operator=( const CTransferItem &other )
  276. {
  277. if (&other != this)
  278. {
  279. Destroy();
  280. m_pWiaItem = other.WiaItem();
  281. m_strFilename = other.Filename();
  282. m_guidInputFormat = other.InputFormat();
  283. m_guidOutputFormat = other.OutputFormat();
  284. m_nMediaType = other.MediaType();
  285. if (other.FileHandle() != INVALID_HANDLE_VALUE)
  286. {
  287. DuplicateHandle( GetCurrentProcess(), other.FileHandle(), GetCurrentProcess(), &m_hFile, 0, FALSE, DUPLICATE_SAME_ACCESS );
  288. }
  289. }
  290. return *this;
  291. }
  292. bool operator==( const CTransferItem &other )
  293. {
  294. return (other.WiaItem() == WiaItem());
  295. }
  296. IWiaItem *WiaItem(void) const
  297. {
  298. return m_pWiaItem;
  299. }
  300. IWiaItem *WiaItem(void)
  301. {
  302. return m_pWiaItem;
  303. }
  304. void WiaItem( IWiaItem *pWiaItem )
  305. {
  306. m_pWiaItem = pWiaItem;
  307. }
  308. CSimpleString Filename(void) const
  309. {
  310. return m_strFilename;
  311. }
  312. void Filename( const CSimpleString &strFilename )
  313. {
  314. m_strFilename = strFilename;
  315. }
  316. GUID InputFormat(void) const
  317. {
  318. //
  319. // Assume IID_NULL;
  320. //
  321. GUID guidResult = m_guidInputFormat;
  322. if (guidResult == IID_NULL)
  323. {
  324. //
  325. // Get the InputFormat helpers
  326. //
  327. CComPtr<IWiaSupportedFormats> pWiaSupportedFormats;
  328. HRESULT hr = CoCreateInstance( CLSID_WiaDefaultUi, NULL, CLSCTX_INPROC_SERVER, IID_IWiaSupportedFormats, (void**)&pWiaSupportedFormats );
  329. if (SUCCEEDED(hr))
  330. {
  331. //
  332. // Initialize the supported formats helper by telling it we are saving to a file
  333. //
  334. hr = pWiaSupportedFormats->Initialize( m_pWiaItem, TYMED_FILE );
  335. if (SUCCEEDED(hr))
  336. {
  337. //
  338. // Get the default InputFormat
  339. //
  340. hr = pWiaSupportedFormats->GetDefaultClipboardFileFormat( &guidResult );
  341. }
  342. }
  343. }
  344. return guidResult;
  345. }
  346. GUID OutputFormat(void) const
  347. {
  348. //
  349. // Assume IID_NULL;
  350. //
  351. GUID guidResult = m_guidOutputFormat;
  352. if (guidResult == IID_NULL)
  353. {
  354. //
  355. // Get the OutputFormat helpers
  356. //
  357. CComPtr<IWiaSupportedFormats> pWiaSupportedFormats;
  358. HRESULT hr = CoCreateInstance( CLSID_WiaDefaultUi, NULL, CLSCTX_INPROC_SERVER, IID_IWiaSupportedFormats, (void**)&pWiaSupportedFormats );
  359. if (SUCCEEDED(hr))
  360. {
  361. //
  362. // Initialize the supported formats helper by telling it we are saving to a file
  363. //
  364. hr = pWiaSupportedFormats->Initialize( m_pWiaItem, TYMED_FILE );
  365. if (SUCCEEDED(hr))
  366. {
  367. //
  368. // Get the default OutputFormat
  369. //
  370. hr = pWiaSupportedFormats->GetDefaultClipboardFileFormat( &guidResult );
  371. }
  372. }
  373. }
  374. return guidResult;
  375. }
  376. void InputFormat( const GUID &guidInputFormat )
  377. {
  378. m_guidInputFormat = guidInputFormat;
  379. }
  380. void OutputFormat( const GUID &guidOutputFormat )
  381. {
  382. m_guidOutputFormat = guidOutputFormat;
  383. }
  384. HRESULT OpenPlaceholderFile(void)
  385. {
  386. HRESULT hr;
  387. if (m_strFilename.Length())
  388. {
  389. m_hFile = CreateFile( m_strFilename, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL );
  390. if (m_hFile != INVALID_HANDLE_VALUE)
  391. {
  392. hr = S_OK;
  393. }
  394. else
  395. {
  396. hr = HRESULT_FROM_WIN32(GetLastError());
  397. }
  398. }
  399. else
  400. {
  401. hr = E_FAIL;
  402. }
  403. return hr;
  404. }
  405. HRESULT ClosePlaceholderFile(void)
  406. {
  407. if (m_hFile != INVALID_HANDLE_VALUE)
  408. {
  409. CloseHandle(m_hFile);
  410. m_hFile = INVALID_HANDLE_VALUE;
  411. }
  412. return S_OK;
  413. }
  414. HRESULT DeleteFile(void)
  415. {
  416. ClosePlaceholderFile();
  417. if (m_strFilename.Length())
  418. {
  419. ::DeleteFile( m_strFilename );
  420. }
  421. return S_OK;
  422. }
  423. HANDLE FileHandle(void) const
  424. {
  425. return m_hFile;
  426. }
  427. LONG MediaType(void) const
  428. {
  429. return m_nMediaType;
  430. }
  431. void MediaType( LONG nMediaType )
  432. {
  433. m_nMediaType = nMediaType;
  434. }
  435. };
  436. //
  437. // Thread handler class for downloading selected images
  438. //
  439. class CDownloadImagesThreadMessage : public CNotifyThreadMessage, public IWiaDataCallback
  440. {
  441. private:
  442. CSimpleDynamicArray<DWORD> m_Cookies;
  443. CSimpleDynamicArray<int> m_Rotation;
  444. CSimpleString m_strDirectory;
  445. CSimpleString m_strFilename;
  446. GUID m_guidFormat;
  447. HANDLE m_hCancelDownloadEvent;
  448. HANDLE m_hPauseDownloadEvent;
  449. HANDLE m_hFilenameCreationMutex;
  450. CGdiPlusHelper m_GdiPlusHelper;
  451. bool m_bStampTime;
  452. UINT m_nLastStatusUpdatePercent;
  453. CMemoryDib m_MemoryDib;
  454. bool m_bFirstTransfer;
  455. DWORD m_nCurrentCookie;
  456. int m_nCurrentPreviewImageLine;
  457. private:
  458. //
  459. // No implementation
  460. //
  461. CDownloadImagesThreadMessage(void);
  462. CDownloadImagesThreadMessage &operator=( const CDownloadImagesThreadMessage & );
  463. CDownloadImagesThreadMessage( const CDownloadImagesThreadMessage & );
  464. public:
  465. //
  466. // Sole constructor
  467. //
  468. CDownloadImagesThreadMessage(
  469. HWND hWndNotify,
  470. const CSimpleDynamicArray<DWORD> &Cookies,
  471. const CSimpleDynamicArray<int> &Rotation,
  472. LPCTSTR pszDirectory,
  473. LPCTSTR pszFilename,
  474. const GUID &guidFormat,
  475. HANDLE hCancelDownloadEvent,
  476. bool bStampTime,
  477. HANDLE hPauseDownloadEvent
  478. );
  479. virtual ~CDownloadImagesThreadMessage(void);
  480. //
  481. // Worker functions
  482. //
  483. HRESULT Download(void);
  484. //
  485. // Static helper functions
  486. //
  487. static CSimpleString GetDateString(void);
  488. static int ReportError( HWND hWndNotify, const CSimpleString &strMessage, int nMessageBoxFlags );
  489. static int ReportDownloadError( HWND hWndNotify, IWiaItem *pWiaItem, HRESULT &hr, bool bAllowContinue, bool bPageFeederActive, bool bMultipageFile, bool bMultiPageTransfer );
  490. static HRESULT GetListOfTransferItems( IWiaItem *pWiaItem, CSimpleDynamicArray<CTransferItem> &TransferItems );
  491. BOOL GetCancelledState();
  492. HRESULT ReserveTransferItemFilenames( CSimpleDynamicArray<CTransferItem> &TransferItems, LPCTSTR pszDirectory, LPCTSTR pszFilename, LPCTSTR pszNumberMask, bool bAllowUnNumberedFile, int &nPrevFileNumber );
  493. //
  494. // IUnknown
  495. //
  496. STDMETHODIMP QueryInterface( REFIID riid, LPVOID *ppvObject );
  497. STDMETHODIMP_(ULONG) AddRef(void);
  498. STDMETHODIMP_(ULONG) Release(void);
  499. //
  500. // IWiaDataCallback
  501. //
  502. STDMETHODIMP BandedDataCallback( LONG, LONG, LONG, LONG, LONG, LONG, LONG, PBYTE );
  503. //
  504. // IImageTransferPluginProgressCallback methods
  505. //
  506. STDMETHODIMP SetProgressMessage( BSTR bstrMessage );
  507. STDMETHODIMP SetCurrentFile( UINT nIndex );
  508. STDMETHODIMP SetOverallPercent( UINT nPercent );
  509. STDMETHODIMP SetFilePercent( UINT nPercent );
  510. STDMETHODIMP Cancelled( UINT *bCancelled );
  511. };
  512. class CDownloadedFileInformation
  513. {
  514. private:
  515. bool m_bDeleteOnError;
  516. CSimpleString m_strFilename;
  517. DWORD m_dwCookie;
  518. bool m_bIncludeInFileCount;
  519. public:
  520. CDownloadedFileInformation( const CDownloadedFileInformation &other )
  521. : m_bDeleteOnError(other.DeleteOnError()),
  522. m_strFilename(other.Filename()),
  523. m_dwCookie(other.Cookie()),
  524. m_bIncludeInFileCount(other.IncludeInFileCount())
  525. {
  526. }
  527. CDownloadedFileInformation( const CSimpleString &strFilename, bool bDeleteOnError, DWORD dwCookie, bool bIncludeInFileCount )
  528. : m_bDeleteOnError(bDeleteOnError),
  529. m_strFilename(strFilename),
  530. m_dwCookie(dwCookie),
  531. m_bIncludeInFileCount(bIncludeInFileCount)
  532. {
  533. }
  534. CDownloadedFileInformation(void)
  535. : m_bDeleteOnError(false),
  536. m_strFilename(TEXT("")),
  537. m_dwCookie(0),
  538. m_bIncludeInFileCount(false)
  539. {
  540. }
  541. CDownloadedFileInformation &operator=( const CDownloadedFileInformation &other )
  542. {
  543. if (this != &other)
  544. {
  545. m_bDeleteOnError = other.DeleteOnError();
  546. m_strFilename = other.Filename();
  547. m_dwCookie = other.Cookie();
  548. m_bIncludeInFileCount = other.IncludeInFileCount();
  549. }
  550. return *this;
  551. }
  552. bool DeleteOnError(void) const
  553. {
  554. return m_bDeleteOnError;
  555. }
  556. void DeleteOnError( bool bDeleteOnError )
  557. {
  558. m_bDeleteOnError = bDeleteOnError;
  559. }
  560. const CSimpleString &Filename(void) const
  561. {
  562. return m_strFilename;
  563. }
  564. DWORD Cookie(void) const
  565. {
  566. return m_dwCookie;
  567. }
  568. bool IncludeInFileCount(void) const
  569. {
  570. return m_bIncludeInFileCount;
  571. }
  572. };
  573. class CDownloadedFileInformationList : public CSimpleDynamicArray<CDownloadedFileInformation>
  574. {
  575. public:
  576. CDownloadedFileInformationList(void)
  577. {
  578. }
  579. CDownloadedFileInformationList( const CDownloadedFileInformationList &other )
  580. {
  581. for (int i=0;i<other.Size();i++)
  582. {
  583. Append(other[i]);
  584. }
  585. }
  586. CDownloadedFileInformationList &operator=( const CDownloadedFileInformationList &other )
  587. {
  588. if (&other != this)
  589. {
  590. Destroy();
  591. for (int i=0;i<other.Size();i++)
  592. {
  593. Append(other[i]);
  594. }
  595. }
  596. return *this;
  597. }
  598. HRESULT DeleteAllFiles(void)
  599. {
  600. WIA_PUSHFUNCTION(TEXT("DeleteAllFiles"));
  601. HRESULT hr = S_OK;
  602. for (int i=0;i<Size();i++)
  603. {
  604. if ((*this)[i].DeleteOnError())
  605. {
  606. WIA_TRACE((TEXT("Calling DeleteFile on %s!"),(*this)[i].Filename().String()));
  607. if (!DeleteFile((*this)[i].Filename()))
  608. {
  609. if (SUCCEEDED(hr))
  610. {
  611. hr = HRESULT_FROM_WIN32(GetLastError());
  612. }
  613. WIA_PRINTHRESULT((hr,TEXT("DeleteFile failed on %s!"),(*this)[i].Filename().String()));
  614. }
  615. }
  616. }
  617. return hr;
  618. }
  619. HRESULT GetAllFiles( CSimpleDynamicArray<CSimpleStringAnsi> &AllFiles )
  620. {
  621. AllFiles.Destroy();
  622. for (int i=0;i<Size();i++)
  623. {
  624. AllFiles.Append(CSimpleStringConvert::AnsiString((*this)[i].Filename()));
  625. }
  626. return S_OK;
  627. }
  628. HRESULT GetAllFiles( CSimpleDynamicArray<CSimpleStringWide> &AllFiles )
  629. {
  630. AllFiles.Destroy();
  631. for (int i=0;i<Size();i++)
  632. {
  633. AllFiles.Append(CSimpleStringConvert::WideString((*this)[i].Filename()));
  634. }
  635. return S_OK;
  636. }
  637. HRESULT GetUniqueFiles( CSimpleDynamicArray<CSimpleString> &UniqueFiles )
  638. {
  639. UniqueFiles.Destroy();
  640. for (int i=0;i<Size();i++)
  641. {
  642. if (UniqueFiles.Find((*this)[i].Filename()) < 0)
  643. {
  644. UniqueFiles.Append((*this)[i].Filename());
  645. }
  646. }
  647. return S_OK;
  648. }
  649. int Find( LPCTSTR pszFilename )
  650. {
  651. if (pszFilename && lstrlen(pszFilename))
  652. {
  653. for (int i=0;i<Size();i++)
  654. {
  655. if ((*this)[i].Filename().Length())
  656. {
  657. if (!lstrcmp(pszFilename,(*this)[i].Filename()))
  658. {
  659. //
  660. // Found a match
  661. //
  662. return i;
  663. }
  664. }
  665. }
  666. }
  667. return -1;
  668. }
  669. int FindByFilenameOnly( LPCTSTR pszFilename )
  670. {
  671. if (pszFilename)
  672. {
  673. for (int i=0;i<Size();i++)
  674. {
  675. if ((*this)[i].Filename().Length())
  676. {
  677. LPTSTR pszFilenameOnly = PathFindFileName( (*this)[i].Filename() );
  678. if (pszFilenameOnly && !lstrcmp(pszFilenameOnly,pszFilename))
  679. {
  680. //
  681. // Found a match
  682. //
  683. return i;
  684. }
  685. }
  686. }
  687. }
  688. return -1;
  689. }
  690. };
  691. class CDownloadImagesThreadNotifyMessage : public CThreadNotificationMessage
  692. {
  693. public:
  694. enum COperation
  695. {
  696. DownloadAll,
  697. DownloadImage,
  698. PreviewImage
  699. };
  700. enum CStatus
  701. {
  702. Begin,
  703. Update,
  704. End
  705. };
  706. private:
  707. COperation m_Operation;
  708. CStatus m_Status;
  709. HRESULT m_hr;
  710. UINT m_nPercentComplete;
  711. UINT m_nPictureCount;
  712. UINT m_nCurrentPicture;
  713. DWORD m_dwCookie;
  714. CSimpleString m_strExtendedErrorInformation;
  715. CSimpleString m_strFilename;
  716. CDownloadedFileInformationList m_DownloadedFileInformation;
  717. HBITMAP m_hPreviewBitmap;
  718. private:
  719. CDownloadImagesThreadNotifyMessage(void);
  720. CDownloadImagesThreadNotifyMessage( const CDownloadImagesThreadNotifyMessage & );
  721. CDownloadImagesThreadNotifyMessage &operator=( const CDownloadImagesThreadNotifyMessage & );
  722. private:
  723. CDownloadImagesThreadNotifyMessage( COperation Operation, CStatus Status, HRESULT hr, UINT nPercentComplete, UINT nPictureCount, UINT nCurrentPicture, DWORD dwCookie, const CSimpleString &strExtendedErrorInformation, const CSimpleString &strFilename, const CDownloadedFileInformationList *pDownloadedFileInformation, HBITMAP hPreviewBitmap )
  724. : CThreadNotificationMessage( TQ_DOWNLOADIMAGE ),
  725. m_Operation(Operation),
  726. m_Status(Status),
  727. m_hr(hr),
  728. m_nPercentComplete(nPercentComplete),
  729. m_nPictureCount(nPictureCount),
  730. m_nCurrentPicture(nCurrentPicture),
  731. m_dwCookie(dwCookie),
  732. m_strExtendedErrorInformation(strExtendedErrorInformation),
  733. m_strFilename(strFilename),
  734. m_hPreviewBitmap(hPreviewBitmap)
  735. {
  736. if (pDownloadedFileInformation)
  737. {
  738. m_DownloadedFileInformation = *pDownloadedFileInformation;
  739. }
  740. }
  741. public:
  742. virtual ~CDownloadImagesThreadNotifyMessage(void)
  743. {
  744. }
  745. COperation Operation(void) const
  746. {
  747. return m_Operation;
  748. }
  749. CStatus Status(void) const
  750. {
  751. return m_Status;
  752. }
  753. HRESULT hr(void) const
  754. {
  755. return m_hr;
  756. }
  757. UINT PercentComplete(void) const
  758. {
  759. return m_nPercentComplete;
  760. }
  761. UINT PictureCount(void) const
  762. {
  763. return m_nPictureCount;
  764. }
  765. UINT CurrentPicture(void) const
  766. {
  767. return m_nCurrentPicture;
  768. }
  769. DWORD Cookie(void) const
  770. {
  771. return m_dwCookie;
  772. }
  773. CSimpleString ExtendedErrorInformation(void)
  774. {
  775. return m_strExtendedErrorInformation;
  776. }
  777. CSimpleString Filename(void)
  778. {
  779. return m_strFilename;
  780. }
  781. const CDownloadedFileInformationList &DownloadedFileInformation(void) const
  782. {
  783. return m_DownloadedFileInformation;
  784. }
  785. HBITMAP PreviewBitmap(void) const
  786. {
  787. return m_hPreviewBitmap;
  788. }
  789. public:
  790. static CDownloadImagesThreadNotifyMessage *BeginDownloadAllMessage( UINT nPictureCount )
  791. {
  792. return new CDownloadImagesThreadNotifyMessage( DownloadAll, Begin, S_OK, 0, nPictureCount, 0, 0, TEXT(""), TEXT(""), NULL, NULL );
  793. }
  794. static CDownloadImagesThreadNotifyMessage *BeginDownloadImageMessage( UINT nCurrentPicture, DWORD dwCookie, const CSimpleString &strFilename )
  795. {
  796. return new CDownloadImagesThreadNotifyMessage( DownloadImage, Begin, S_OK, 0, 0, nCurrentPicture, dwCookie, TEXT(""), strFilename, NULL, NULL );
  797. }
  798. static CDownloadImagesThreadNotifyMessage *UpdateDownloadImageMessage( UINT nPercentComplete )
  799. {
  800. return new CDownloadImagesThreadNotifyMessage( DownloadImage, Update, S_OK, nPercentComplete, 0, 0, 0, TEXT(""), TEXT(""), NULL, NULL );
  801. }
  802. static CDownloadImagesThreadNotifyMessage *EndDownloadImageMessage( UINT nCurrentPicture, DWORD dwCookie, const CSimpleString &strFilename, HRESULT hr )
  803. {
  804. return new CDownloadImagesThreadNotifyMessage( DownloadImage, End, hr, 100, 0, nCurrentPicture, dwCookie, TEXT(""), strFilename, NULL, NULL );
  805. }
  806. static CDownloadImagesThreadNotifyMessage *EndDownloadAllMessage( HRESULT hr, const CSimpleString &strExtendedErrorInformation, const CDownloadedFileInformationList *pDownloadedFileInformation )
  807. {
  808. return new CDownloadImagesThreadNotifyMessage( DownloadAll, End, hr, 0, 0, 0, 0, strExtendedErrorInformation, TEXT(""), pDownloadedFileInformation, NULL );
  809. }
  810. static CDownloadImagesThreadNotifyMessage *BeginPreviewMessage( DWORD dwCookie, HBITMAP hPreviewBitmap )
  811. {
  812. return new CDownloadImagesThreadNotifyMessage( PreviewImage, Begin, S_OK, 100, 0, 0, dwCookie, TEXT(""), TEXT(""), NULL, hPreviewBitmap );
  813. }
  814. static CDownloadImagesThreadNotifyMessage *UpdatePreviewMessage( DWORD dwCookie, HBITMAP hPreviewBitmap )
  815. {
  816. return new CDownloadImagesThreadNotifyMessage( PreviewImage, Update, S_OK, 100, 0, 0, dwCookie, TEXT(""), TEXT(""), NULL, hPreviewBitmap );
  817. }
  818. static CDownloadImagesThreadNotifyMessage *EndPreviewMessage( DWORD dwCookie )
  819. {
  820. return new CDownloadImagesThreadNotifyMessage( PreviewImage, End, S_OK, 100, 0, 0, dwCookie, TEXT(""), TEXT(""), NULL, NULL );
  821. }
  822. };
  823. //
  824. // Thread handler class for deleting selected images
  825. //
  826. class CDeleteImagesThreadMessage : public CNotifyThreadMessage
  827. {
  828. private:
  829. CSimpleDynamicArray<DWORD> m_Cookies;
  830. HANDLE m_hCancelDeleteEvent;
  831. HANDLE m_hPauseDeleteEvent;
  832. bool m_bSlowItDown;
  833. private:
  834. //
  835. // No implementation
  836. //
  837. CDeleteImagesThreadMessage(void);
  838. CDeleteImagesThreadMessage &operator=( const CDeleteImagesThreadMessage & );
  839. CDeleteImagesThreadMessage( const CDeleteImagesThreadMessage & );
  840. public:
  841. //
  842. // Sole constructor
  843. //
  844. CDeleteImagesThreadMessage(
  845. HWND hWndNotify,
  846. const CSimpleDynamicArray<DWORD> &Cookies,
  847. HANDLE hCancelDeleteEvent,
  848. HANDLE hPauseDeleteEvent,
  849. bool bSlowItDown
  850. );
  851. virtual ~CDeleteImagesThreadMessage(void);
  852. //
  853. // Worker functions
  854. //
  855. HRESULT DeleteImages(void);
  856. };
  857. class CDeleteImagesThreadNotifyMessage : public CThreadNotificationMessage
  858. {
  859. public:
  860. enum COperation
  861. {
  862. DeleteAll,
  863. DeleteImage,
  864. };
  865. enum CStatus
  866. {
  867. Begin,
  868. End
  869. };
  870. private:
  871. COperation m_Operation;
  872. CStatus m_Status;
  873. HRESULT m_hr;
  874. UINT m_nPictureCount;
  875. UINT m_nCurrentPicture;
  876. DWORD m_dwCookie;
  877. private:
  878. CDeleteImagesThreadNotifyMessage(void);
  879. CDeleteImagesThreadNotifyMessage( const CDeleteImagesThreadNotifyMessage & );
  880. CDeleteImagesThreadNotifyMessage &operator=( const CDeleteImagesThreadNotifyMessage & );
  881. private:
  882. CDeleteImagesThreadNotifyMessage( COperation Operation, CStatus Status, HRESULT hr, UINT nPictureCount, UINT nCurrentPicture, DWORD dwCookie )
  883. : CThreadNotificationMessage( TQ_DOWNLOADIMAGE ),
  884. m_Operation(Operation),
  885. m_Status(Status),
  886. m_hr(hr),
  887. m_nPictureCount(nPictureCount),
  888. m_nCurrentPicture(nCurrentPicture),
  889. m_dwCookie(dwCookie)
  890. {
  891. }
  892. public:
  893. virtual ~CDeleteImagesThreadNotifyMessage(void)
  894. {
  895. }
  896. COperation Operation(void) const
  897. {
  898. return m_Operation;
  899. }
  900. CStatus Status(void) const
  901. {
  902. return m_Status;
  903. }
  904. HRESULT hr(void) const
  905. {
  906. return m_hr;
  907. }
  908. UINT PictureCount(void) const
  909. {
  910. return m_nPictureCount;
  911. }
  912. UINT CurrentPicture(void) const
  913. {
  914. return m_nCurrentPicture;
  915. }
  916. DWORD Cookie(void) const
  917. {
  918. return m_dwCookie;
  919. }
  920. public:
  921. static CDeleteImagesThreadNotifyMessage *BeginDeleteAllMessage( UINT nPictureCount )
  922. {
  923. return new CDeleteImagesThreadNotifyMessage( DeleteAll, Begin, S_OK, nPictureCount, 0, 0 );
  924. }
  925. static CDeleteImagesThreadNotifyMessage *BeginDeleteImageMessage( UINT nCurrentPicture, DWORD dwCookie )
  926. {
  927. return new CDeleteImagesThreadNotifyMessage( DeleteImage, Begin, S_OK, 0, nCurrentPicture, dwCookie );
  928. }
  929. static CDeleteImagesThreadNotifyMessage *EndDeleteImageMessage( UINT nCurrentPicture, DWORD dwCookie, HRESULT hr )
  930. {
  931. return new CDeleteImagesThreadNotifyMessage( DeleteImage, End, hr, 0, nCurrentPicture, dwCookie );
  932. }
  933. static CDeleteImagesThreadNotifyMessage *EndDeleteAllMessage( HRESULT hr )
  934. {
  935. return new CDeleteImagesThreadNotifyMessage( DeleteAll, End, hr, 0, 0, 0 );
  936. }
  937. };
  938. //
  939. // Notification message that gets sent when there is a download error
  940. //
  941. class CDownloadErrorNotificationMessage : public CThreadNotificationMessage
  942. {
  943. private:
  944. CSimpleString m_strMessage;
  945. HANDLE m_hHandledMessageEvent;
  946. HANDLE m_hRespondedMessageEvent;
  947. int m_nMessageBoxFlags;
  948. int &m_nResult;
  949. private:
  950. CDownloadErrorNotificationMessage(void);
  951. CDownloadErrorNotificationMessage( const CDownloadErrorNotificationMessage & );
  952. CDownloadErrorNotificationMessage &operator=( const CDownloadErrorNotificationMessage & );
  953. private:
  954. CDownloadErrorNotificationMessage( const CSimpleString &strMessage, HANDLE hHandledMessageEvent, HANDLE hRespondedMessageEvent, int nMessageBoxFlags, int &nResult )
  955. : CThreadNotificationMessage( TQ_DOWNLOADERROR ),
  956. m_strMessage(strMessage),
  957. m_hHandledMessageEvent(hHandledMessageEvent),
  958. m_hRespondedMessageEvent(hRespondedMessageEvent),
  959. m_nMessageBoxFlags(nMessageBoxFlags),
  960. m_nResult(nResult)
  961. {
  962. }
  963. public:
  964. virtual ~CDownloadErrorNotificationMessage(void)
  965. {
  966. }
  967. CSimpleString Message(void) const
  968. {
  969. return m_strMessage;
  970. }
  971. int MessageBoxFlags(void)
  972. {
  973. return m_nMessageBoxFlags;
  974. }
  975. void Handled(void)
  976. {
  977. if (m_hHandledMessageEvent)
  978. {
  979. SetEvent(m_hHandledMessageEvent);
  980. }
  981. }
  982. void Response( int nResult )
  983. {
  984. m_nResult = nResult;
  985. if (m_hRespondedMessageEvent)
  986. {
  987. SetEvent(m_hRespondedMessageEvent);
  988. }
  989. }
  990. public:
  991. static CDownloadErrorNotificationMessage *ReportDownloadError( const CSimpleString &strMessage, HANDLE hHandledMessageEvent, HANDLE hRespondedMessageEvent, int nMessageBoxFlags, int &nResult )
  992. {
  993. return new CDownloadErrorNotificationMessage( strMessage, hHandledMessageEvent, hRespondedMessageEvent, nMessageBoxFlags, nResult );
  994. }
  995. };
  996. // Thread handler class for downloading selected images
  997. class CPreviewScanThreadMessage : public CNotifyThreadMessage, public IWiaDataCallback
  998. {
  999. private:
  1000. HWND m_hwndNotify;
  1001. DWORD m_dwCookie;
  1002. CMemoryDib m_MemoryDib;
  1003. bool m_bFirstTransfer;
  1004. HANDLE m_hCancelPreviewEvent;
  1005. private:
  1006. // No implementation
  1007. CPreviewScanThreadMessage(void);
  1008. CPreviewScanThreadMessage &operator=( const CPreviewScanThreadMessage & );
  1009. CPreviewScanThreadMessage( const CPreviewScanThreadMessage & );
  1010. public:
  1011. // Sole constructor
  1012. CPreviewScanThreadMessage(
  1013. HWND hWndNotify,
  1014. DWORD dwCookie,
  1015. HANDLE hCancelPreviewEvent
  1016. );
  1017. ~CPreviewScanThreadMessage();
  1018. HRESULT Scan(void);
  1019. // IUnknown
  1020. STDMETHODIMP QueryInterface( REFIID riid, LPVOID *ppvObject );
  1021. STDMETHODIMP_(ULONG) AddRef(void);
  1022. STDMETHODIMP_(ULONG) Release(void);
  1023. // IWiaDataCallback
  1024. STDMETHODIMP BandedDataCallback( LONG, LONG, LONG, LONG, LONG, LONG, LONG, PBYTE );
  1025. };
  1026. class CPreviewScanThreadNotifyMessage : public CThreadNotificationMessage
  1027. {
  1028. public:
  1029. enum CStatus
  1030. {
  1031. Begin,
  1032. Update,
  1033. End
  1034. };
  1035. private:
  1036. CStatus m_Status;
  1037. HRESULT m_hr;
  1038. DWORD m_dwCookie;
  1039. HBITMAP m_hBitmap;
  1040. private:
  1041. CPreviewScanThreadNotifyMessage(void);
  1042. CPreviewScanThreadNotifyMessage( const CPreviewScanThreadNotifyMessage & );
  1043. CPreviewScanThreadNotifyMessage &operator=( const CPreviewScanThreadNotifyMessage & );
  1044. private:
  1045. CPreviewScanThreadNotifyMessage( CStatus Status, HRESULT hr, DWORD dwCookie, HBITMAP hBitmap )
  1046. : CThreadNotificationMessage( TQ_SCANPREVIEW ),
  1047. m_Status(Status),
  1048. m_hr(hr),
  1049. m_dwCookie(dwCookie),
  1050. m_hBitmap(hBitmap)
  1051. {
  1052. }
  1053. public:
  1054. virtual ~CPreviewScanThreadNotifyMessage(void)
  1055. {
  1056. m_hBitmap = NULL;
  1057. }
  1058. CStatus Status(void) const
  1059. {
  1060. return m_Status;
  1061. }
  1062. HRESULT hr(void) const
  1063. {
  1064. return m_hr;
  1065. }
  1066. DWORD Cookie(void) const
  1067. {
  1068. return m_dwCookie;
  1069. }
  1070. HBITMAP Bitmap(void) const
  1071. {
  1072. return m_hBitmap;
  1073. }
  1074. public:
  1075. static CPreviewScanThreadNotifyMessage *BeginDownloadMessage( DWORD dwCookie )
  1076. {
  1077. return new CPreviewScanThreadNotifyMessage( Begin, S_OK, dwCookie, NULL );
  1078. }
  1079. static CPreviewScanThreadNotifyMessage *UpdateDownloadMessage( DWORD dwCookie, HBITMAP hBitmap )
  1080. {
  1081. return new CPreviewScanThreadNotifyMessage( Update, S_OK, dwCookie, hBitmap );
  1082. }
  1083. static CPreviewScanThreadNotifyMessage *EndDownloadMessage( DWORD dwCookie, HBITMAP hBitmap, HRESULT hr )
  1084. {
  1085. return new CPreviewScanThreadNotifyMessage( End, hr, dwCookie, hBitmap );
  1086. }
  1087. };
  1088. #endif // __THRDMSG_H_INCLUDED