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.

307 lines
15 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: ACQMGRCW.H
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 9/27/1999
  12. *
  13. * DESCRIPTION:
  14. *
  15. *******************************************************************************/
  16. #ifndef __ACQMGRCW_H_INCLUDED
  17. #define __ACQMGRCW_H_INCLUDED
  18. #include <windows.h>
  19. #include "wia.h"
  20. #include "evntparm.h"
  21. #include "bkthread.h"
  22. #include "wiaitem.h"
  23. #include "errors.h"
  24. #include "thrdmsg.h"
  25. #include "thrdntfy.h"
  26. #include "wndlist.h"
  27. #include "shmemsec.h"
  28. #include "wiaregst.h"
  29. #include "wiadevdp.h"
  30. #include "destdata.h"
  31. #include "gwiaevnt.h"
  32. #define REGSTR_PATH_USER_SETTINGS_WIAACMGR REGSTR_PATH_USER_SETTINGS TEXT("\\WiaAcquisitionManager")
  33. #define REGSTR_KEYNAME_USER_SETTINGS_WIAACMGR TEXT("AcquisitionManagerDialogCustomSettings")
  34. #define REG_STR_ROOTNAME_MRU TEXT("RootFileNameMru")
  35. #define REG_STR_DIRNAME_MRU TEXT("DirectoryNameMru")
  36. #define REG_STR_EXIT_AFTER_DOWNLOAD TEXT("ExitAfterDownload")
  37. #define REG_STR_LASTFORMAT TEXT("LastSaveAsFormat")
  38. #define REG_STR_OPENSHELL TEXT("OpenShellAfterDownload")
  39. #define REG_STR_SUPRESSFIRSTPAGE TEXT("SuppressFirstPage")
  40. #define CONNECT_SOUND TEXT("WiaDeviceConnect")
  41. #define DISCONNECT_SOUND TEXT("WiaDeviceDisconnect")
  42. //
  43. // We use different advanced settings for scanners and cameras, thus we store them in different places
  44. //
  45. #define REG_STR_STORE_IN_SUBDIRECTORY_SCANNER TEXT("StorePicturesInSubdirectoryScanner")
  46. #define REG_STR_SUBDIRECTORY_DATED_SCANNER TEXT("UseDatedSubdirectoryScanner")
  47. #define REG_STR_STORE_IN_SUBDIRECTORY_CAMERA TEXT("StorePicturesInSubdirectoryCamera")
  48. #define REG_STR_SUBDIRECTORY_DATED_CAMERA TEXT("UseDatedSubdirectoryCamera")
  49. #define ACQUISITION_MANAGER_CONTROLLER_WINDOW_CLASSNAME TEXT("AcquisitionManagerControllerWindow")
  50. #define ACQUISITION_MANAGER_DEVICE_MUTEX_ROOT_NAME TEXT("AcquisitionManagerDevice:")
  51. #define STR_UPLOAD_WIZARD_MESSAGE TEXT("WiaUploadWizardInternalMessage")
  52. #ifndef StiDeviceTypeStreamingVideo
  53. #define StiDeviceTypeStreamingVideo 3
  54. #endif
  55. #define FE_WIAACMGR TEXT("Scanner and Camera Wizard")
  56. //
  57. // For handling createdevice busy errors
  58. //
  59. #define CREATE_DEVICE_RETRY_MAX_COUNT 10 // 10 tries
  60. #define CREATE_DEVICE_RETRY_WAIT 1000 // 1000 Milliseconds (1 second) wait between retries
  61. #define MAX_WIZ_PAGES 10
  62. //
  63. // Private user window messages
  64. //
  65. #define PWM_POSTINITIALIZE (WM_USER+0x0001)
  66. class CAcquisitionManagerControllerWindow : public IWizardSite, IServiceProvider
  67. {
  68. public:
  69. enum CDeviceTypeMode
  70. {
  71. UnknownMode, // This would be an error
  72. CameraMode,
  73. ScannerMode,
  74. VideoMode
  75. };
  76. enum
  77. {
  78. ScannerTypeUnknown = 0,
  79. ScannerTypeFlatbed = 1,
  80. ScannerTypeScrollFed = 2,
  81. ScannerTypeFlatbedAdf = 3,
  82. };
  83. enum
  84. {
  85. OnDisconnectGotoLastpage = 0x00000001,
  86. OnDisconnectFailDownload = 0x00000002,
  87. OnDisconnectFailUpload = 0x00000004,
  88. OnDisconnectFailDelete = 0x00000008,
  89. DontAllowSuspend = 0x00000100
  90. };
  91. typedef bool (*ComparisonCallbackFuntion)( const CWiaItem &, LPARAM lParam );
  92. private:
  93. //
  94. // Private data
  95. //
  96. public:
  97. //
  98. // Public data
  99. //
  100. CComPtr<IGlobalInterfaceTable> m_pGlobalInterfaceTable; // Global interface table
  101. CComPtr<IUnknown> m_pConnectEventObject; // Event object
  102. CComPtr<IUnknown> m_pCreateItemEventObject; // Event object
  103. CComPtr<IUnknown> m_pDeleteItemEventObject; // Event object
  104. CComPtr<IUnknown> m_pDisconnectEventObject; // Event object
  105. CComPtr<IWiaItem> m_pWiaItemRoot; // Root item
  106. CComPtr<IWiaProgressDialog> m_pWiaProgressDialog; // The progress dialog, used during initialization
  107. CComPtr<IPublishingWizard> m_pPublishingWizard; // Web upload wizard
  108. CDestinationData m_CurrentDownloadDestination; // Current download destination
  109. CDestinationData::CNameData m_DestinationNameData; // Current download destination data
  110. CDeviceTypeMode m_DeviceTypeMode; // Which kind of device are we?
  111. CEventParameters *m_pEventParameters; // The parameters we were started with
  112. CDownloadedFileInformationList m_DownloadedFileInformationList; // A list of filenames we have downloaded
  113. CSimpleEvent m_CancelEvent; // Cancel event, which is set when we want to cancel a download
  114. CSimpleEvent m_EventThumbnailCancel; // Event that is set to cancel thumbnail download
  115. CSimpleEvent m_EventPauseBackgroundThread; // Event that is set pause the background thread
  116. CSimpleString m_strErrorMessage; // Error message to be displayed by the finish page
  117. CSimpleStringWide m_strwDeviceName; // Device name
  118. CSimpleStringWide m_strwDeviceUiClassId; // Device name
  119. CThreadMessageQueue *m_pThreadMessageQueue; // The background queue
  120. CWiaItem *m_pCurrentScannerItem; // The scanner item from which we are transferring data
  121. CWiaItemList m_WiaItemList; // list of all enumerated wia items
  122. CWindowList m_WindowList; // The list of all the windows which are subscribing to broadcast messages
  123. GUID m_guidOutputFormat; // Output format
  124. HANDLE m_hBackgroundThread; // The background worker thread
  125. HICON m_hWizardIconBig; // The large icon used by the wizard
  126. HICON m_hWizardIconSmall; // The small icon used by the wizard
  127. HRESULT m_hrDownloadResult; // HRESULT for the entire download
  128. HRESULT m_hrUploadResult; // HRESULT for the entire upload
  129. HRESULT m_hrDeleteResult; // HRESULT for the entire deletion
  130. HWND m_hWndWizard; // HWND of the main wizard window
  131. LONG m_cRef; // Reference count
  132. LONG m_nDeviceType; // STI Device type
  133. SIZE m_sizeThumbnails; // The size of camera thumbnails
  134. TCHAR m_szDestinationDirectory[MAX_PATH]; // The directory to which we are going to download the images
  135. TCHAR m_szRootFileName[MAX_PATH]; // Base file name
  136. UINT m_nThreadNotificationMessage; // Registered window message, used to identify worker thread notification messages
  137. UINT m_nUploadWizardPageCount; // Number of pages in the web upload wizard
  138. UINT m_nWiaEventMessage; // Registered window message, used to identify event messages
  139. UINT m_nWiaWizardPageCount; // Number of pages in the WIA wizard
  140. UINT m_OnDisconnect; // Flags which specify behavior on receipt of disconnect event
  141. bool m_bDeletePicturesIfSuccessful; // Set to true if we should delete the pictures when we are done
  142. bool m_bDisconnected; // Set to true if the device has been disconnected
  143. bool m_bOpenShellAfterDownload; // Set to true to open the shell after we download all of the pictures
  144. bool m_bStampTimeOnSavedFiles; // Set to true to save the time on files
  145. bool m_bSuppressFirstPage; // Set to true to suppress display of the welcome page
  146. bool m_bTakePictureIsSupported; // Set to true if the device supports the TAKE PICTURE command
  147. bool m_bUploadToWeb; // Set to true to chain NETPLWIZ
  148. bool m_bDownloadCancelled; // Set to true to cancel the web upload
  149. bool m_bUpdateEnumerationCount; // Update the count of images during enumeration. We suppress update for scanners.
  150. int m_nDestinationPageIndex; // The index, in the HPROPSHEETPAGE array, of the destination page
  151. int m_nSelectionPageIndex; // The index, in the HPROPSHEETPAGE array, of the selection page
  152. int m_nFailedImagesCount; // Count of all download failures
  153. int m_nFinishPageIndex; // The index, in the HPROPSHEETPAGE array, of the finish page
  154. int m_nProgressPageIndex; // The index, in the HPROPSHEETPAGE array, of the download progress page
  155. int m_nUploadQueryPageIndex; // The index, in the HPROPSHEETPAGE array, of the upload progress page
  156. int m_nDeleteProgressPageIndex; // The index, in the HPROPSHEETPAGE array, of the delete progress page
  157. int m_nScannerType; // What type of scanner are we dealing with?
  158. HWND m_hWnd; // Our hidden window
  159. DWORD m_dwLastEnumerationTickCount; // To ensure we don't update the progress dialog too often
  160. HPROPSHEETPAGE m_PublishWizardPages[MAX_WIZ_PAGES];
  161. private:
  162. //
  163. // No implementation
  164. //
  165. CAcquisitionManagerControllerWindow(void);
  166. CAcquisitionManagerControllerWindow( const CAcquisitionManagerControllerWindow & );
  167. CAcquisitionManagerControllerWindow &operator=( const CAcquisitionManagerControllerWindow & );
  168. private:
  169. //
  170. // Constructor and destructor
  171. //
  172. explicit CAcquisitionManagerControllerWindow( HWND hWnd );
  173. virtual ~CAcquisitionManagerControllerWindow(void);
  174. //
  175. // Private helper functions
  176. //
  177. HRESULT CreateDevice(void);
  178. void GetCookiesOfSelectedImages( CWiaItem *pCurr, CSimpleDynamicArray<DWORD> &Cookies );
  179. void GetRotationOfSelectedImages( CWiaItem *pCurr, CSimpleDynamicArray<int> &Rotation );
  180. void GetCookiesOfAllImages( CWiaItem *pCurr, CSimpleDynamicArray<DWORD> &Cookies );
  181. void GetSelectedItems( CWiaItem *pCurr, CSimpleDynamicArray<CWiaItem*> &Items );
  182. void MarkAllItemsUnselected( CWiaItem *pCurrItem );
  183. void MarkItemSelected( CWiaItem *pItem, CWiaItem *pCurrItem );
  184. HRESULT CreateAndExecuteWizard(void);
  185. void DetermineScannerType(void);
  186. void AddNewItemToList( CGenericWiaEventHandler::CEventMessage *pEventMessage );
  187. void RequestThumbnailForNewItem( CGenericWiaEventHandler::CEventMessage *pEventMessage );
  188. static bool EnumItemsCallback( CWiaItemList::CEnumEvent EnumEvent, UINT nData, LPARAM lParam, bool bForceUpdate );
  189. //
  190. // Standard windows message handlers
  191. //
  192. LRESULT OnCreate( WPARAM, LPARAM lParam );
  193. LRESULT OnDestroy( WPARAM, LPARAM );
  194. LRESULT OnPowerBroadcast( WPARAM, LPARAM );
  195. //
  196. // Custom windows message handlers
  197. //
  198. LRESULT OnPostInitialize( WPARAM, LPARAM );
  199. LRESULT OnOldThreadNotification( WPARAM, LPARAM );
  200. LRESULT OnThreadNotification( WPARAM, LPARAM );
  201. //
  202. // Thread notification handlers
  203. //
  204. void OnNotifyDownloadThumbnail( UINT nMsg, CThreadNotificationMessage *pThreadNotificationMessage );
  205. void OnNotifyDownloadImage( UINT nMsg, CThreadNotificationMessage *pThreadNotificationMessage );
  206. LRESULT OnEventNotification( WPARAM wParam, LPARAM lParam );
  207. //
  208. // Thread message handlers
  209. //
  210. static BOOL WINAPI OnThreadDestroy( CThreadMessage *pMsg );
  211. static BOOL WINAPI OnThreadDownloadImage( CThreadMessage *pMsg );
  212. static BOOL WINAPI OnThreadDownloadThumbnail( CThreadMessage *pMsg );
  213. static BOOL WINAPI OnThreadPreviewScan( CThreadMessage *pMsg );
  214. static BOOL WINAPI OnThreadDeleteImages( CThreadMessage *pMsg );
  215. private:
  216. //
  217. // Window procedure
  218. //
  219. static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
  220. //
  221. // Property sheet callback
  222. //
  223. static int CALLBACK PropSheetCallback( HWND hWnd, UINT uMsg, LPARAM lParam );
  224. public:
  225. //
  226. // Public functions
  227. //
  228. static bool IsCameraThumbnailDownloaded( const CWiaItem &WiaItem, LPARAM lParam );
  229. int GetCookies( CSimpleDynamicArray<DWORD> &Cookies, CWiaItem *pCurr, ComparisonCallbackFuntion pfnCallback, LPARAM lParam );
  230. bool DownloadSelectedImages( HANDLE hCancelDownloadEvent );
  231. bool DeleteDownloadedImages( HANDLE hCancelDeleteEvent );
  232. bool DeleteSelectedImages(void);
  233. void DownloadAllThumbnails(void);
  234. void SetMainWindowInSharedMemory( HWND hWnd );
  235. bool PerformPreviewScan( CWiaItem *pItem, HANDLE hCancelPreviewEvent );
  236. bool GetAllImageItems( CSimpleDynamicArray<CWiaItem*> &Items, CWiaItem *pCurr );
  237. bool GetAllImageItems( CSimpleDynamicArray<CWiaItem*> &Items );
  238. bool CanSomeSelectedImagesBeDeleted(void);
  239. BOOL ConfirmWizardCancel( HWND hWndParent );
  240. static bool DirectoryExists( LPCTSTR pszDirectoryName );
  241. static bool RecursiveCreateDirectory( CSimpleString strDirectoryName );
  242. static CSimpleString GetCurrentDate(void);
  243. void DisplayDisconnectMessageAndExit(void);
  244. CWiaItem *FindItemByName( LPCWSTR pwszItemName );
  245. int GetSelectedImageCount(void);
  246. bool SuppressFirstPage(void);
  247. bool IsSerialCamera(void);
  248. public:
  249. //
  250. // Public creation functions
  251. //
  252. static bool Register( HINSTANCE hInstance );
  253. static HWND Create( HINSTANCE hInstance, CEventParameters *pEventParameters );
  254. //
  255. // IUnknown
  256. //
  257. STDMETHOD(QueryInterface)(REFIID riid, void **ppvObj);
  258. STDMETHOD_(ULONG,AddRef)(void);
  259. STDMETHOD_(ULONG,Release)(void);
  260. //
  261. // IWizardSite
  262. //
  263. STDMETHODIMP GetPreviousPage(HPROPSHEETPAGE *phPage);
  264. STDMETHODIMP GetNextPage(HPROPSHEETPAGE *phPage);
  265. STDMETHODIMP GetCancelledPage(HPROPSHEETPAGE *phPage);
  266. //
  267. // IServiceProvider
  268. //
  269. STDMETHODIMP QueryService(REFGUID guidService, REFIID riid, void **ppv);
  270. };
  271. #endif //__ACQMGRCW_H_INCLUDED