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.

969 lines
35 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: COMPROG.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 9/28/1999
  12. *
  13. * DESCRIPTION: Download progress dialog. Displays the thumbnail and download progress.
  14. *
  15. *******************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #include <commctrl.h>
  19. #include "comprog.h"
  20. #include "resource.h"
  21. #include "pviewids.h"
  22. #include "simcrack.h"
  23. #include "gwiaevnt.h"
  24. #include "mboxex.h"
  25. #include "runnpwiz.h"
  26. #define PWM_SETDEFBUTTON (WM_USER+1)
  27. CCommonProgressPage::CCommonProgressPage( HWND hWnd )
  28. : m_hWnd(hWnd),
  29. m_pControllerWindow(NULL),
  30. m_hCancelDownloadEvent(CreateEvent(NULL,TRUE,FALSE,TEXT(""))),
  31. m_nThreadNotificationMessage(RegisterWindowMessage(STR_THREAD_NOTIFICATION_MESSAGE)),
  32. m_nWiaEventMessage(RegisterWindowMessage(STR_WIAEVENT_NOTIFICATION_MESSAGE)),
  33. m_hSwitchToNextPage(NULL),
  34. m_bQueryingUser(false)
  35. {
  36. }
  37. CCommonProgressPage::~CCommonProgressPage(void)
  38. {
  39. m_hWnd = NULL;
  40. m_pControllerWindow = NULL;
  41. if (m_hCancelDownloadEvent)
  42. {
  43. CloseHandle(m_hCancelDownloadEvent);
  44. m_hCancelDownloadEvent = NULL;
  45. }
  46. }
  47. void CCommonProgressPage::UpdatePercentComplete( int nPercent, bool bUploading )
  48. {
  49. if (nPercent >= 0)
  50. {
  51. int nPercentStringResId;
  52. if (bUploading)
  53. {
  54. nPercentStringResId = IDS_PERCENT_COMPLETE_UPLOADING;
  55. }
  56. else
  57. {
  58. // Assume copying is the appropropriate description
  59. nPercentStringResId = IDS_PERCENT_COMPLETE_COPYING;
  60. switch (m_pControllerWindow->m_DeviceTypeMode)
  61. {
  62. case CAcquisitionManagerControllerWindow::ScannerMode:
  63. nPercentStringResId = IDS_PERCENT_COMPLETE_SCANNING;
  64. break;
  65. };
  66. }
  67. SendDlgItemMessage( m_hWnd, IDC_COMPROG_DOWNLOADPROGRESS, PBM_SETPOS, nPercent, 0 );
  68. CSimpleString().Format( nPercentStringResId, g_hInstance, nPercent ).SetWindowText( GetDlgItem( m_hWnd, IDC_COMPROG_DOWNLOADPROGRESS_TEXT ) );
  69. }
  70. else
  71. {
  72. SendDlgItemMessage( m_hWnd, IDC_COMPROG_DOWNLOADPROGRESS, PBM_SETPOS, 0, 0 );
  73. SendDlgItemMessage( m_hWnd, IDC_COMPROG_DOWNLOADPROGRESS_TEXT, WM_SETTEXT, 0, reinterpret_cast<LPARAM>("") );
  74. }
  75. }
  76. void CCommonProgressPage::UpdateCurrentPicture( int nPicture )
  77. {
  78. if (nPicture >= 0)
  79. {
  80. SendDlgItemMessage( m_hWnd, IDC_COMPROG_CURRENTIMAGE, PBM_SETPOS, nPicture, 0 );
  81. CSimpleString().Format( IDS_FILEN_OF_M, g_hInstance, nPicture+1, m_nPictureCount ).SetWindowText( GetDlgItem( m_hWnd, IDC_COMPROG_CURRENTIMAGE_TEXT ) );
  82. }
  83. else
  84. {
  85. SendDlgItemMessage( m_hWnd, IDC_COMPROG_CURRENTIMAGE, PBM_SETPOS, 0, 0 );
  86. SendDlgItemMessage( m_hWnd, IDC_COMPROG_CURRENTIMAGE_TEXT, WM_SETTEXT, 0, reinterpret_cast<LPARAM>("") );
  87. }
  88. }
  89. void CCommonProgressPage::UpdateThumbnail( HBITMAP hBitmap, CWiaItem *pWiaItem )
  90. {
  91. WIA_PUSH_FUNCTION((TEXT("CCommonProgressPage::UpdateThumbnail( HBITMAP hBitmap=0x%08X, CWiaItem *pWiaItem=0x%08X )"), hBitmap, pWiaItem ));
  92. HWND hWndPreview = GetDlgItem( m_hWnd, IDC_COMPROG_CURRENTTHUMBNAIL );
  93. if (hWndPreview)
  94. {
  95. if (pWiaItem && m_pControllerWindow && hBitmap)
  96. {
  97. switch (m_pControllerWindow->m_DeviceTypeMode)
  98. {
  99. case CAcquisitionManagerControllerWindow::ScannerMode:
  100. {
  101. //
  102. // If the item has a bitmap image, it already has a preview scan available
  103. //
  104. WIA_TRACE((TEXT("pWiaItem->BitmapImage() = %08X"), pWiaItem->BitmapImage() ));
  105. if (pWiaItem->BitmapImage())
  106. {
  107. //
  108. // Hide the preview window while we are futzing with it
  109. //
  110. ShowWindow( hWndPreview, SW_HIDE );
  111. //
  112. // Crop the image to the selected region
  113. //
  114. WiaPreviewControl_SetResolution( hWndPreview, &pWiaItem->ScanRegionSettings().sizeResolution );
  115. WiaPreviewControl_SetSelOrigin( hWndPreview, 0, FALSE, &pWiaItem->ScanRegionSettings().ptOrigin );
  116. WiaPreviewControl_SetSelExtent( hWndPreview, 0, FALSE, &pWiaItem->ScanRegionSettings().sizeExtent );
  117. //
  118. // Set the control to preview mode
  119. //
  120. WiaPreviewControl_SetPreviewMode( hWndPreview, TRUE );
  121. //
  122. // If this is a scanner item, we don't want to let the preview control take ownership of the bitmap.
  123. // We don't want it to be deleted
  124. //
  125. WiaPreviewControl_SetBitmap( hWndPreview, TRUE, TRUE, hBitmap );
  126. //
  127. // Show the preview window
  128. //
  129. ShowWindow( hWndPreview, SW_SHOW );
  130. }
  131. else
  132. {
  133. //
  134. // This means we are getting a preview image from the driver
  135. // We don't want to delete this image
  136. //
  137. WiaPreviewControl_SetBitmap( hWndPreview, TRUE, TRUE, hBitmap );
  138. //
  139. // Make sure the window is visible
  140. //
  141. ShowWindow( hWndPreview, SW_SHOW );
  142. }
  143. }
  144. break;
  145. default:
  146. {
  147. //
  148. // Go ahead and rotate the bitmap, even if it isn't necessary.
  149. //
  150. HBITMAP hRotatedThumbnail = NULL;
  151. if (SUCCEEDED(m_GdiPlusHelper.Rotate( hBitmap, hRotatedThumbnail, pWiaItem->Rotation())))
  152. {
  153. //
  154. // Set it to the rotated bitmap, and ALLOW this bitmap to be deleted
  155. //
  156. WiaPreviewControl_SetBitmap( hWndPreview, TRUE, FALSE, hRotatedThumbnail );
  157. }
  158. //
  159. // Make sure the window is visible
  160. //
  161. ShowWindow( hWndPreview, SW_SHOW );
  162. //
  163. // Delete the source bitmap
  164. //
  165. DeleteObject(hBitmap);
  166. }
  167. }
  168. }
  169. else
  170. {
  171. ShowWindow( hWndPreview, SW_HIDE );
  172. WiaPreviewControl_SetBitmap( hWndPreview, TRUE, TRUE, NULL );
  173. }
  174. }
  175. }
  176. LRESULT CCommonProgressPage::OnInitDialog( WPARAM, LPARAM lParam )
  177. {
  178. //
  179. // Make sure this starts out NULL
  180. //
  181. m_pControllerWindow = NULL;
  182. //
  183. // Get the PROPSHEETPAGE.lParam
  184. //
  185. PROPSHEETPAGE *pPropSheetPage = reinterpret_cast<PROPSHEETPAGE*>(lParam);
  186. if (pPropSheetPage)
  187. {
  188. m_pControllerWindow = reinterpret_cast<CAcquisitionManagerControllerWindow*>(pPropSheetPage->lParam);
  189. if (m_pControllerWindow)
  190. {
  191. m_pControllerWindow->m_WindowList.Add(m_hWnd);
  192. }
  193. }
  194. //
  195. // Bail out
  196. //
  197. if (!m_pControllerWindow)
  198. {
  199. EndDialog(m_hWnd,IDCANCEL);
  200. return -1;
  201. }
  202. //
  203. // Prepare the preview control
  204. //
  205. HWND hWndThumbnail = GetDlgItem( m_hWnd, IDC_COMPROG_CURRENTTHUMBNAIL );
  206. if (hWndThumbnail)
  207. {
  208. //
  209. // We only want to set the preview mode for scanners
  210. //
  211. if (CAcquisitionManagerControllerWindow::ScannerMode==m_pControllerWindow->m_DeviceTypeMode)
  212. {
  213. WiaPreviewControl_SetPreviewMode( hWndThumbnail, TRUE );
  214. }
  215. else
  216. {
  217. WiaPreviewControl_AllowNullSelection( hWndThumbnail, TRUE );
  218. WiaPreviewControl_ClearSelection( hWndThumbnail );
  219. }
  220. WiaPreviewControl_SetBgAlpha( hWndThumbnail, FALSE, 0xFF );
  221. WiaPreviewControl_DisableSelection( hWndThumbnail, TRUE );
  222. WiaPreviewControl_SetEnableStretch( hWndThumbnail, FALSE );
  223. WiaPreviewControl_SetBkColor( hWndThumbnail, FALSE, TRUE, GetSysColor(COLOR_WINDOW) );
  224. WiaPreviewControl_HideEmptyPreview( hWndThumbnail, TRUE );
  225. WiaPreviewControl_SetPreviewAlignment( hWndThumbnail, PREVIEW_WINDOW_CENTER, PREVIEW_WINDOW_CENTER, FALSE );
  226. }
  227. return 0;
  228. }
  229. void CCommonProgressPage::OnNotifyDownloadError( UINT nMsg, CThreadNotificationMessage *pThreadNotificationMessage )
  230. {
  231. WIA_PUSH_FUNCTION((TEXT("CCommonProgressPage::OnNotifyDownloadError")));
  232. CDownloadErrorNotificationMessage *pDownloadErrorNotificationMessage = dynamic_cast<CDownloadErrorNotificationMessage*>(pThreadNotificationMessage);
  233. if (pDownloadErrorNotificationMessage && m_pControllerWindow)
  234. {
  235. pDownloadErrorNotificationMessage->Handled();
  236. if (m_pControllerWindow->m_bDisconnected)
  237. {
  238. pDownloadErrorNotificationMessage->Response( IDCANCEL );
  239. }
  240. else
  241. {
  242. WIA_TRACE((TEXT("MessageBox flags: %08X"), pDownloadErrorNotificationMessage->MessageBoxFlags() ));
  243. int nResponse = CMessageBoxEx::MessageBox( m_hWnd, pDownloadErrorNotificationMessage->Message(), CSimpleString( IDS_ERROR_TITLE, g_hInstance ), pDownloadErrorNotificationMessage->MessageBoxFlags() );
  244. pDownloadErrorNotificationMessage->Response( nResponse );
  245. }
  246. }
  247. }
  248. void CCommonProgressPage::OnNotifyDownloadImage( UINT nMsg, CThreadNotificationMessage *pThreadNotificationMessage )
  249. {
  250. WIA_PUSHFUNCTION(TEXT("CCommonProgressPage::OnNotifyDownloadImage"));
  251. CDownloadImagesThreadNotifyMessage *pDownloadImageThreadNotifyMessage = dynamic_cast<CDownloadImagesThreadNotifyMessage*>(pThreadNotificationMessage);
  252. if (pDownloadImageThreadNotifyMessage && m_pControllerWindow)
  253. {
  254. switch (pDownloadImageThreadNotifyMessage->Status())
  255. {
  256. case CDownloadImagesThreadNotifyMessage::Begin:
  257. {
  258. switch (pDownloadImageThreadNotifyMessage->Operation())
  259. {
  260. case CDownloadImagesThreadNotifyMessage::DownloadAll:
  261. {
  262. //
  263. // Store the number of images we'll be downloading
  264. //
  265. m_nPictureCount = pDownloadImageThreadNotifyMessage->PictureCount();
  266. //
  267. // Show the current picture controls if there are multiple pictures being downloaded
  268. //
  269. if (m_nPictureCount > 1)
  270. {
  271. ShowWindow( GetDlgItem( m_hWnd, IDC_COMPROG_CURRENTIMAGE_TEXT ), SW_SHOW );
  272. ShowWindow( GetDlgItem( m_hWnd, IDC_COMPROG_CURRENTIMAGE ), SW_SHOW );
  273. }
  274. //
  275. // Initialize current image count progress bar
  276. //
  277. SendDlgItemMessage( m_hWnd, IDC_COMPROG_CURRENTIMAGE, PBM_SETRANGE32, 0, m_nPictureCount);
  278. UpdateCurrentPicture(0);
  279. //
  280. // Enable the file download progress controls
  281. //
  282. EnableWindow( GetDlgItem( m_hWnd, IDC_COMPROG_DOWNLOADPROGRESS_TEXT ), TRUE );
  283. EnableWindow( GetDlgItem( m_hWnd, IDC_COMPROG_DOWNLOADPROGRESS ), TRUE );
  284. //
  285. // Initialize download progress bar
  286. //
  287. SendDlgItemMessage( m_hWnd, IDC_COMPROG_DOWNLOADPROGRESS, PBM_SETRANGE, 0, MAKELPARAM(0,100));
  288. UpdatePercentComplete(0,false);
  289. }
  290. break;
  291. case CDownloadImagesThreadNotifyMessage::DownloadImage:
  292. {
  293. //
  294. // Display thumbnail
  295. //
  296. HBITMAP hBitmapThumbnail = NULL;
  297. CWiaItem *pWiaItem = m_pControllerWindow->m_WiaItemList.Find( pDownloadImageThreadNotifyMessage->Cookie() );
  298. if (pWiaItem)
  299. {
  300. //
  301. // This will only work if it is a scanner item
  302. //
  303. hBitmapThumbnail = pWiaItem->BitmapImage();
  304. if (!hBitmapThumbnail)
  305. {
  306. //
  307. // Since it didn't work, this is a camera item, so create a thumbnail.
  308. // We have to make sure we nuke this bitmap or it is a leak!
  309. //
  310. HDC hDC = GetDC(NULL);
  311. if (hDC)
  312. {
  313. hBitmapThumbnail = pWiaItem->CreateThumbnailBitmap(hDC);
  314. ReleaseDC( NULL, hDC );
  315. }
  316. }
  317. }
  318. else
  319. {
  320. WIA_ERROR((TEXT("Unable to find the item with the cookie %08X"), pDownloadImageThreadNotifyMessage->Cookie() ));
  321. }
  322. //
  323. // Update the thumbnail in the progress window
  324. //
  325. UpdateThumbnail( hBitmapThumbnail, pWiaItem );
  326. //
  327. // Increment file queue progress
  328. //
  329. UpdateCurrentPicture(pDownloadImageThreadNotifyMessage->CurrentPicture());
  330. //
  331. // Clear file download progress
  332. //
  333. UpdatePercentComplete(0,false);
  334. //
  335. // Display the filename we are downloading
  336. //
  337. TCHAR szFileTitle[MAX_PATH] = TEXT("");
  338. GetFileTitle( pDownloadImageThreadNotifyMessage->Filename(), szFileTitle, ARRAYSIZE(szFileTitle) );
  339. SetDlgItemText( m_hWnd, IDC_COMPROG_IMAGENAME, szFileTitle );
  340. }
  341. break;
  342. case CDownloadImagesThreadNotifyMessage::PreviewImage:
  343. {
  344. CWiaItem *pWiaItem = m_pControllerWindow->m_WiaItemList.Find( pDownloadImageThreadNotifyMessage->Cookie() );
  345. if (pWiaItem && !pWiaItem->BitmapImage() && !pWiaItem->BitmapData())
  346. {
  347. UpdateThumbnail( pDownloadImageThreadNotifyMessage->PreviewBitmap(), pWiaItem );
  348. }
  349. }
  350. break;
  351. }
  352. }
  353. break;
  354. case CDownloadImagesThreadNotifyMessage::Update:
  355. {
  356. switch (pDownloadImageThreadNotifyMessage->Operation())
  357. {
  358. case CDownloadImagesThreadNotifyMessage::DownloadImage:
  359. {
  360. //
  361. // Update file download progress
  362. //
  363. UpdatePercentComplete(pDownloadImageThreadNotifyMessage->PercentComplete(),false);
  364. }
  365. break;
  366. case CDownloadImagesThreadNotifyMessage::PreviewImage:
  367. {
  368. CWiaItem *pWiaItem = m_pControllerWindow->m_WiaItemList.Find( pDownloadImageThreadNotifyMessage->Cookie() );
  369. if (pWiaItem && !pWiaItem->BitmapImage() && !pWiaItem->BitmapData())
  370. {
  371. WiaPreviewControl_RefreshBitmap( GetDlgItem( m_hWnd, IDC_COMPROG_CURRENTTHUMBNAIL ) );
  372. }
  373. }
  374. break;
  375. }
  376. }
  377. break;
  378. case CDownloadImagesThreadNotifyMessage::End:
  379. switch (pDownloadImageThreadNotifyMessage->Operation())
  380. {
  381. case CDownloadImagesThreadNotifyMessage::DownloadImage:
  382. {
  383. if (!SUCCEEDED(pDownloadImageThreadNotifyMessage->hr()))
  384. {
  385. //
  386. // Clear the thumbnail in the progress window
  387. //
  388. UpdateThumbnail( NULL, NULL );
  389. //
  390. // Clear file download progress
  391. //
  392. UpdatePercentComplete(0,false);
  393. //
  394. // Increment file queue progress
  395. //
  396. UpdateCurrentPicture(pDownloadImageThreadNotifyMessage->CurrentPicture());
  397. //
  398. // Clear the filename
  399. //
  400. SetDlgItemText( m_hWnd, IDC_COMPROG_IMAGENAME, TEXT("") );
  401. }
  402. else
  403. {
  404. //
  405. // Update file download progress
  406. //
  407. UpdatePercentComplete(100,false);
  408. }
  409. }
  410. break;
  411. case CDownloadImagesThreadNotifyMessage::DownloadAll:
  412. {
  413. //
  414. // Clear the filename when we are all done
  415. //
  416. SetDlgItemText( m_hWnd, IDC_COMPROG_IMAGENAME, TEXT("") );
  417. CSimpleString strMessage;
  418. if (FAILED(pDownloadImageThreadNotifyMessage->hr()))
  419. {
  420. WIA_PRINTHRESULT((pDownloadImageThreadNotifyMessage->hr(),TEXT("CDownloadImagesThreadNotifyMessage::DownloadAll (%s)"), pDownloadImageThreadNotifyMessage->ExtendedErrorInformation().String()));
  421. //
  422. // If we already have a good error message, let's use it
  423. //
  424. if (pDownloadImageThreadNotifyMessage->ExtendedErrorInformation().Length())
  425. {
  426. strMessage = pDownloadImageThreadNotifyMessage->ExtendedErrorInformation();
  427. }
  428. else
  429. {
  430. //
  431. // If we haven't already created a good error message, and we think we can here, let's do it
  432. //
  433. switch (pDownloadImageThreadNotifyMessage->hr())
  434. {
  435. case HRESULT_FROM_WIN32(ERROR_DISK_FULL):
  436. strMessage.LoadString( IDS_DISKFULL, g_hInstance );
  437. break;
  438. case HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE):
  439. strMessage.LoadString( IDS_UNABLETOTRANSFER, g_hInstance );
  440. break;
  441. case WIA_ERROR_PAPER_JAM:
  442. strMessage.LoadString( IDS_WIA_ERROR_PAPER_JAM, g_hInstance );
  443. break;
  444. case WIA_ERROR_PAPER_EMPTY:
  445. strMessage.LoadString( IDS_WIA_ERROR_PAPER_EMPTY, g_hInstance );
  446. break;
  447. case WIA_ERROR_PAPER_PROBLEM:
  448. strMessage.LoadString( IDS_WIA_ERROR_PAPER_PROBLEM, g_hInstance );
  449. break;
  450. case WIA_ERROR_OFFLINE:
  451. strMessage.LoadString( IDS_WIA_ERROR_OFFLINE, g_hInstance );
  452. break;
  453. case WIA_ERROR_BUSY:
  454. strMessage.LoadString( IDS_WIA_ERROR_BUSY, g_hInstance );
  455. break;
  456. case WIA_ERROR_WARMING_UP:
  457. strMessage.LoadString( IDS_WIA_ERROR_WARMING_UP, g_hInstance );
  458. break;
  459. case WIA_ERROR_USER_INTERVENTION:
  460. strMessage.LoadString( IDS_WIA_ERROR_USER_INTERVENTION, g_hInstance );
  461. break;
  462. case WIA_ERROR_ITEM_DELETED:
  463. strMessage.LoadString( IDS_WIA_ERROR_ITEM_DELETED, g_hInstance );
  464. break;
  465. case WIA_ERROR_DEVICE_COMMUNICATION:
  466. strMessage.LoadString( IDS_WIA_ERROR_DEVICE_COMMUNICATION, g_hInstance );
  467. break;
  468. case WIA_ERROR_INVALID_COMMAND:
  469. strMessage.LoadString( IDS_WIA_ERROR_INVALID_COMMAND, g_hInstance );
  470. break;
  471. case WIA_ERROR_INCORRECT_HARDWARE_SETTING:
  472. strMessage.LoadString( IDS_WIA_ERROR_INCORRECT_HARDWARE_SETTING, g_hInstance );
  473. break;
  474. case WIA_ERROR_DEVICE_LOCKED:
  475. strMessage.LoadString( IDS_WIA_ERROR_DEVICE_LOCKED, g_hInstance );
  476. break;
  477. default:
  478. strMessage = WiaUiUtil::GetErrorTextFromHResult(pDownloadImageThreadNotifyMessage->hr());
  479. if (!strMessage.Length())
  480. {
  481. strMessage.Format( CSimpleString( IDS_TRANSFER_ERROR_OCCURRED, g_hInstance ), pDownloadImageThreadNotifyMessage->hr() );
  482. }
  483. break;
  484. }
  485. }
  486. WIA_TRACE((TEXT("strMessage: (%s)"), strMessage.String()));
  487. //
  488. // Tell the user something bad happened. Save the error message.
  489. //
  490. m_pControllerWindow->m_strErrorMessage = strMessage;
  491. }
  492. //
  493. // Save the hresult
  494. //
  495. m_pControllerWindow->m_hrDownloadResult = pDownloadImageThreadNotifyMessage->hr();
  496. //
  497. // Just to be sure we catch cancels
  498. //
  499. if (S_FALSE == m_pControllerWindow->m_hrDownloadResult)
  500. {
  501. m_pControllerWindow->m_bDownloadCancelled = true;
  502. }
  503. //
  504. // Continue downloading thumbnails, in case it was paused
  505. //
  506. m_pControllerWindow->DownloadAllThumbnails();
  507. //
  508. // Go to the next page. Assume it will be the upload query page.
  509. //
  510. HPROPSHEETPAGE hNextPage = PropSheet_IndexToPage( GetParent(m_hWnd), m_pControllerWindow->m_nFinishPageIndex );
  511. //
  512. // If the transfer was successful
  513. //
  514. if (!m_pControllerWindow->m_bDownloadCancelled && S_OK==m_pControllerWindow->m_hrDownloadResult)
  515. {
  516. //
  517. // If we are deleting from the device, send us to the delete progress page
  518. //
  519. if (m_pControllerWindow->m_bDeletePicturesIfSuccessful)
  520. {
  521. hNextPage = PropSheet_IndexToPage( GetParent(m_hWnd), m_pControllerWindow->m_nDeleteProgressPageIndex );
  522. }
  523. //
  524. // Otherwise, go to the upload query page
  525. //
  526. else
  527. {
  528. hNextPage = PropSheet_IndexToPage( GetParent(m_hWnd), m_pControllerWindow->m_nUploadQueryPageIndex );
  529. }
  530. }
  531. //
  532. // If there is a message box active, save this page till the message box is dismissed
  533. //
  534. if (m_bQueryingUser)
  535. {
  536. m_hSwitchToNextPage = hNextPage;
  537. }
  538. else
  539. {
  540. //
  541. // Set the next page
  542. //
  543. PropSheet_SetCurSel( GetParent(m_hWnd), hNextPage, -1 );
  544. }
  545. }
  546. break;
  547. case CDownloadImagesThreadNotifyMessage::PreviewImage:
  548. {
  549. CWiaItem *pWiaItem = m_pControllerWindow->m_WiaItemList.Find( pDownloadImageThreadNotifyMessage->Cookie() );
  550. UpdateThumbnail( NULL, pWiaItem );
  551. }
  552. break;
  553. }
  554. }
  555. }
  556. }
  557. LRESULT CCommonProgressPage::OnSetActive( WPARAM, LPARAM )
  558. {
  559. //
  560. // Make sure we have a valid controller window
  561. //
  562. if (!m_pControllerWindow)
  563. {
  564. return -1;
  565. }
  566. //
  567. // Initialize the download error message
  568. //
  569. m_pControllerWindow->m_strErrorMessage = TEXT("");
  570. //
  571. // Initialize the download result
  572. //
  573. m_pControllerWindow->m_hrDownloadResult = S_OK;
  574. //
  575. // Initialize upload result to S_OK
  576. //
  577. m_pControllerWindow->m_hrUploadResult = S_OK;
  578. //
  579. // Initialize delete result to E_FAIL
  580. //
  581. m_pControllerWindow->m_hrDeleteResult = E_FAIL;
  582. //
  583. // Reset the cancelled flag
  584. //
  585. m_pControllerWindow->m_bDownloadCancelled = false;
  586. //
  587. // Clear the downloaded file list
  588. //
  589. m_pControllerWindow->m_DownloadedFileInformationList.Destroy();
  590. //
  591. // Clear all of the controls
  592. //
  593. UpdatePercentComplete(-1,false);
  594. UpdateCurrentPicture(-1);
  595. UpdateThumbnail(NULL,NULL);
  596. //
  597. // Reset the selected region, in case this is a scanner
  598. //
  599. WiaPreviewControl_SetResolution( GetDlgItem( m_hWnd, IDC_COMPROG_CURRENTTHUMBNAIL ), NULL );
  600. WiaPreviewControl_SetSelOrigin( GetDlgItem( m_hWnd, IDC_COMPROG_CURRENTTHUMBNAIL ), 0, FALSE, NULL );
  601. WiaPreviewControl_SetSelExtent( GetDlgItem( m_hWnd, IDC_COMPROG_CURRENTTHUMBNAIL ), 0, FALSE, NULL );
  602. //
  603. // Set the control to preview mode
  604. //
  605. WiaPreviewControl_SetPreviewMode( GetDlgItem( m_hWnd, IDC_COMPROG_CURRENTTHUMBNAIL ), TRUE );
  606. //
  607. // Reset the download event cancel
  608. //
  609. if (m_hCancelDownloadEvent)
  610. {
  611. ResetEvent(m_hCancelDownloadEvent);
  612. }
  613. //
  614. // Cancel thumbnail downloading
  615. //
  616. m_pControllerWindow->m_EventThumbnailCancel.Signal();
  617. //
  618. // Start the download
  619. //
  620. if (!m_pControllerWindow->DownloadSelectedImages(m_hCancelDownloadEvent))
  621. {
  622. WIA_ERROR((TEXT("m_pControllerWindow->DownloadSelectedImages FAILED!")));
  623. MessageBox( m_hWnd, CSimpleString( IDS_UNABLETOTRANSFER, g_hInstance ), CSimpleString( IDS_ERROR_TITLE, g_hInstance ), MB_ICONHAND );
  624. return -1;
  625. }
  626. //
  627. // Tell the user where the pictures are going
  628. //
  629. CSimpleString strDestinationDisplayName = m_pControllerWindow->m_CurrentDownloadDestination.DisplayName(m_pControllerWindow->m_DestinationNameData);
  630. strDestinationDisplayName.SetWindowText( GetDlgItem( m_hWnd, IDC_COMPROG_DESTNAME) );
  631. SendDlgItemMessage( m_hWnd, IDC_COMPROG_DESTNAME, EM_SETSEL, strDestinationDisplayName.Length(), strDestinationDisplayName.Length() );
  632. SendDlgItemMessage( m_hWnd, IDC_COMPROG_DESTNAME, EM_SCROLLCARET, 0, 0 );
  633. //
  634. // Hide the current image controls in case there is only one image
  635. //
  636. ShowWindow( GetDlgItem( m_hWnd, IDC_COMPROG_CURRENTIMAGE_TEXT ), SW_HIDE );
  637. ShowWindow( GetDlgItem( m_hWnd, IDC_COMPROG_CURRENTIMAGE ), SW_HIDE );
  638. //
  639. // No next, back or finish
  640. //
  641. PropSheet_SetWizButtons( GetParent(m_hWnd), 0 );
  642. //
  643. // We do want to exit on disconnect if we are on this page
  644. //
  645. m_pControllerWindow->m_OnDisconnect = CAcquisitionManagerControllerWindow::OnDisconnectGotoLastpage|CAcquisitionManagerControllerWindow::OnDisconnectFailDownload|CAcquisitionManagerControllerWindow::OnDisconnectFailUpload|CAcquisitionManagerControllerWindow::OnDisconnectFailDelete|CAcquisitionManagerControllerWindow::DontAllowSuspend;
  646. return 0;
  647. }
  648. LRESULT CCommonProgressPage::OnWizNext( WPARAM, LPARAM )
  649. {
  650. return 0;
  651. }
  652. LRESULT CCommonProgressPage::OnWizBack( WPARAM, LPARAM )
  653. {
  654. return 0;
  655. }
  656. LRESULT CCommonProgressPage::OnReset( WPARAM, LPARAM )
  657. {
  658. //
  659. // Cancel the current download
  660. //
  661. if (m_hCancelDownloadEvent)
  662. {
  663. SetEvent(m_hCancelDownloadEvent);
  664. }
  665. return 0;
  666. }
  667. LRESULT CCommonProgressPage::OnEventNotification( WPARAM, LPARAM lParam )
  668. {
  669. WIA_PUSHFUNCTION(TEXT("CCommonFirstPage::OnEventNotification"));
  670. CGenericWiaEventHandler::CEventMessage *pEventMessage = reinterpret_cast<CGenericWiaEventHandler::CEventMessage *>(lParam);
  671. if (pEventMessage)
  672. {
  673. //
  674. // Don't delete the message, it is deleted in the controller window
  675. //
  676. }
  677. return 0;
  678. }
  679. bool CCommonProgressPage::QueryCancel(void)
  680. {
  681. //
  682. // Make sure this is the current page
  683. //
  684. if (PropSheet_GetCurrentPageHwnd(GetParent(m_hWnd)) != m_hWnd)
  685. {
  686. return true;
  687. }
  688. //
  689. // Pause the background thread
  690. //
  691. m_pControllerWindow->m_EventPauseBackgroundThread.Reset();
  692. //
  693. // Assume the user doesn't want to cancel
  694. //
  695. bool bResult = false;
  696. //
  697. // Set the querying user flag so the event handler won't change pages
  698. //
  699. m_bQueryingUser = true;
  700. //
  701. // We may be called on to switch pages when we are done here. If so, this will be non-NULL then.
  702. //
  703. m_hSwitchToNextPage = NULL;
  704. //
  705. // Don't ask again if we've already asked
  706. //
  707. if (!m_pControllerWindow->m_bDownloadCancelled)
  708. {
  709. //
  710. // Ask the user if they want to cancel
  711. //
  712. if (CMessageBoxEx::IDMBEX_YES == CMessageBoxEx::MessageBox( m_hWnd, CSimpleString(IDS_CONFIRM_CANCEL_DOWNLOAD,g_hInstance), CSimpleString(IDS_ERROR_TITLE,g_hInstance), CMessageBoxEx::MBEX_YESNO|CMessageBoxEx::MBEX_ICONQUESTION ))
  713. {
  714. //
  715. // The user does want to cancel, so set the cancel event, set the cancel flag and return false
  716. //
  717. m_pControllerWindow->m_bDownloadCancelled = true;
  718. //
  719. // Tell the device to cancel the current operation
  720. //
  721. WiaUiUtil::IssueWiaCancelIO(m_pControllerWindow->m_pWiaItemRoot);
  722. //
  723. // Make sure the cancel button is disabled
  724. //
  725. EnableWindow( GetDlgItem( GetParent(m_hWnd), IDCANCEL ), FALSE );
  726. //
  727. // Set the event that tells the background thread to stop transferring images
  728. //
  729. if (m_hCancelDownloadEvent)
  730. {
  731. SetEvent(m_hCancelDownloadEvent);
  732. }
  733. //
  734. // Return true to indicate we are cancelling
  735. //
  736. bResult = true;
  737. }
  738. }
  739. //
  740. // If we are supposed to switch pages, switch now
  741. //
  742. if (m_hSwitchToNextPage)
  743. {
  744. PropSheet_SetCurSel( GetParent(m_hWnd), m_hSwitchToNextPage, -1 );
  745. }
  746. //
  747. // Reset the querying user flag so the event handler can change pages as needed
  748. //
  749. m_bQueryingUser = false;
  750. //
  751. // Unpause the background thread
  752. //
  753. m_pControllerWindow->m_EventPauseBackgroundThread.Signal();
  754. return bResult;
  755. }
  756. LRESULT CCommonProgressPage::OnQueryCancel( WPARAM, LPARAM )
  757. {
  758. //
  759. // The user is not allowed to cancel out of this page
  760. //
  761. BOOL bResult = TRUE;
  762. //
  763. // Since we don't let them cancel in this page, just ignore the result
  764. //
  765. QueryCancel();
  766. return bResult;
  767. }
  768. LRESULT CCommonProgressPage::OnKillActive( WPARAM, LPARAM )
  769. {
  770. //
  771. // If we cancelled, make sure we delete any already downloaded files here.
  772. //
  773. if (m_pControllerWindow->m_bDownloadCancelled)
  774. {
  775. m_pControllerWindow->m_DownloadedFileInformationList.DeleteAllFiles();
  776. }
  777. //
  778. // Make sure the cancel button is enabled
  779. //
  780. EnableWindow( GetDlgItem( GetParent(m_hWnd), IDCANCEL ), TRUE );
  781. return 0;
  782. }
  783. LRESULT CCommonProgressPage::OnQueryEndSession( WPARAM, LPARAM )
  784. {
  785. bool bCancel = QueryCancel();
  786. if (bCancel)
  787. {
  788. return TRUE;
  789. }
  790. else
  791. {
  792. return FALSE;
  793. }
  794. }
  795. LRESULT CCommonProgressPage::OnSysColorChange( WPARAM wParam, LPARAM lParam )
  796. {
  797. WiaPreviewControl_SetBkColor( GetDlgItem( m_hWnd, IDC_COMPROG_CURRENTTHUMBNAIL ), TRUE, TRUE, GetSysColor(COLOR_WINDOW) );
  798. WiaPreviewControl_SetBkColor( GetDlgItem( m_hWnd, IDC_COMPROG_CURRENTTHUMBNAIL ), TRUE, FALSE, GetSysColor(COLOR_WINDOW) );
  799. return 0;
  800. }
  801. LRESULT CCommonProgressPage::OnCommand( WPARAM wParam, LPARAM lParam )
  802. {
  803. SC_BEGIN_COMMAND_HANDLERS()
  804. {
  805. }
  806. SC_END_COMMAND_HANDLERS();
  807. }
  808. LRESULT CCommonProgressPage::OnThreadNotification( WPARAM wParam, LPARAM lParam )
  809. {
  810. WTM_BEGIN_THREAD_NOTIFY_MESSAGE_HANDLERS()
  811. {
  812. WTM_HANDLE_NOTIFY_MESSAGE( TQ_DOWNLOADIMAGE, OnNotifyDownloadImage );
  813. WTM_HANDLE_NOTIFY_MESSAGE( TQ_DOWNLOADERROR, OnNotifyDownloadError );
  814. }
  815. WTM_END_THREAD_NOTIFY_MESSAGE_HANDLERS();
  816. }
  817. LRESULT CCommonProgressPage::OnNotify( WPARAM wParam, LPARAM lParam )
  818. {
  819. SC_BEGIN_NOTIFY_MESSAGE_HANDLERS()
  820. {
  821. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_WIZBACK,OnWizBack);
  822. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_WIZNEXT,OnWizNext);
  823. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_SETACTIVE,OnSetActive);
  824. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_KILLACTIVE,OnKillActive);
  825. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_RESET,OnReset);
  826. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_QUERYCANCEL,OnQueryCancel);
  827. }
  828. SC_END_NOTIFY_MESSAGE_HANDLERS();
  829. }
  830. INT_PTR CALLBACK CCommonProgressPage::DialogProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  831. {
  832. SC_BEGIN_DIALOG_MESSAGE_HANDLERS(CCommonProgressPage)
  833. {
  834. SC_HANDLE_DIALOG_MESSAGE( WM_INITDIALOG, OnInitDialog );
  835. SC_HANDLE_DIALOG_MESSAGE( WM_COMMAND, OnCommand );
  836. SC_HANDLE_DIALOG_MESSAGE( WM_NOTIFY, OnNotify );
  837. SC_HANDLE_DIALOG_MESSAGE( WM_QUERYENDSESSION, OnQueryEndSession );
  838. SC_HANDLE_DIALOG_MESSAGE( WM_SYSCOLORCHANGE, OnSysColorChange );
  839. }
  840. SC_HANDLE_REGISTERED_DIALOG_MESSAGE( m_nThreadNotificationMessage, OnThreadNotification );
  841. SC_HANDLE_REGISTERED_DIALOG_MESSAGE( m_nWiaEventMessage, OnEventNotification );
  842. SC_END_DIALOG_MESSAGE_HANDLERS();
  843. }