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.

626 lines
19 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: COMDELP.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 9/28/1999
  12. *
  13. * DESCRIPTION: Delete progress dialog. Displays the thumbnail and download progress.
  14. *
  15. *******************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #include <commctrl.h>
  19. #include "comdelp.h"
  20. #include "resource.h"
  21. #include "pviewids.h"
  22. #include "simcrack.h"
  23. #include "mboxex.h"
  24. #include "runnpwiz.h"
  25. CCommonDeleteProgressPage::CCommonDeleteProgressPage( HWND hWnd )
  26. : m_hWnd(hWnd),
  27. m_pControllerWindow(NULL),
  28. m_hCancelDeleteEvent(CreateEvent(NULL,TRUE,FALSE,TEXT(""))),
  29. m_nThreadNotificationMessage(RegisterWindowMessage(STR_THREAD_NOTIFICATION_MESSAGE)),
  30. m_hSwitchToNextPage(NULL),
  31. m_bQueryingUser(false),
  32. m_nPictureCount(0),
  33. m_bDeleteCancelled(false)
  34. {
  35. }
  36. CCommonDeleteProgressPage::~CCommonDeleteProgressPage(void)
  37. {
  38. m_hWnd = NULL;
  39. m_pControllerWindow = NULL;
  40. if (m_hCancelDeleteEvent)
  41. {
  42. CloseHandle(m_hCancelDeleteEvent);
  43. m_hCancelDeleteEvent = NULL;
  44. }
  45. }
  46. void CCommonDeleteProgressPage::UpdateCurrentPicture( int nPicture )
  47. {
  48. if (nPicture >= 0)
  49. {
  50. SendDlgItemMessage( m_hWnd, IDC_COMDEL_CURRENTIMAGE, PBM_SETPOS, nPicture+1, 0 );
  51. CSimpleString().Format( IDS_DELETING_FILEN_OF_M, g_hInstance, nPicture+1, m_nPictureCount ).SetWindowText( GetDlgItem( m_hWnd, IDC_COMDEL_CURRENTIMAGE_TEXT ) );
  52. }
  53. else
  54. {
  55. SendDlgItemMessage( m_hWnd, IDC_COMDEL_CURRENTIMAGE, PBM_SETPOS, 0, 0 );
  56. SendDlgItemMessage( m_hWnd, IDC_COMDEL_CURRENTIMAGE_TEXT, WM_SETTEXT, 0, reinterpret_cast<LPARAM>("") );
  57. }
  58. }
  59. void CCommonDeleteProgressPage::UpdateThumbnail( HBITMAP hBitmap, CWiaItem *pWiaItem )
  60. {
  61. WIA_PUSH_FUNCTION((TEXT("CCommonDeleteProgressPage::UpdateThumbnail( HBITMAP hBitmap=0x%08X, CWiaItem *pWiaItem=0x%08X )"), hBitmap, pWiaItem ));
  62. HWND hWndPreview = GetDlgItem( m_hWnd, IDC_COMDEL_CURRENTTHUMBNAIL );
  63. if (hWndPreview)
  64. {
  65. if (pWiaItem && m_pControllerWindow && hBitmap)
  66. {
  67. switch (m_pControllerWindow->m_DeviceTypeMode)
  68. {
  69. case CAcquisitionManagerControllerWindow::ScannerMode:
  70. {
  71. //
  72. // If the item has a bitmap image, it already has a preview scan available
  73. //
  74. WIA_TRACE((TEXT("pWiaItem->BitmapImage() = %08X"), pWiaItem->BitmapImage() ));
  75. if (pWiaItem->BitmapImage())
  76. {
  77. //
  78. // Hide the preview window while we are futzing with it
  79. //
  80. ShowWindow( hWndPreview, SW_HIDE );
  81. //
  82. // Crop the image to the selected region
  83. //
  84. WiaPreviewControl_SetResolution( hWndPreview, &pWiaItem->ScanRegionSettings().sizeResolution );
  85. WiaPreviewControl_SetSelOrigin( hWndPreview, 0, FALSE, &pWiaItem->ScanRegionSettings().ptOrigin );
  86. WiaPreviewControl_SetSelExtent( hWndPreview, 0, FALSE, &pWiaItem->ScanRegionSettings().sizeExtent );
  87. //
  88. // Set the control to preview mode
  89. //
  90. WiaPreviewControl_SetPreviewMode( hWndPreview, TRUE );
  91. //
  92. // If this is a scanner item, we don't want to let the preview control take ownership of the bitmap.
  93. // We don't want it to be deleted
  94. //
  95. WiaPreviewControl_SetBitmap( hWndPreview, TRUE, TRUE, hBitmap );
  96. //
  97. // Show the preview window
  98. //
  99. ShowWindow( hWndPreview, SW_SHOW );
  100. }
  101. else
  102. {
  103. //
  104. // This means we are getting a preview image from the driver
  105. // We don't want to delete this image
  106. //
  107. WiaPreviewControl_SetBitmap( hWndPreview, TRUE, TRUE, hBitmap );
  108. //
  109. // Make sure the window is visible
  110. //
  111. ShowWindow( hWndPreview, SW_SHOW );
  112. }
  113. }
  114. break;
  115. default:
  116. {
  117. //
  118. // Go ahead and rotate the bitmap, even if it isn't necessary.
  119. //
  120. HBITMAP hRotatedThumbnail = NULL;
  121. if (SUCCEEDED(m_GdiPlusHelper.Rotate( hBitmap, hRotatedThumbnail, pWiaItem->Rotation())))
  122. {
  123. //
  124. // Set it to the rotated bitmap, and ALLOW this bitmap to be deleted
  125. //
  126. WiaPreviewControl_SetBitmap( hWndPreview, TRUE, FALSE, hRotatedThumbnail );
  127. }
  128. //
  129. // Make sure the window is visible
  130. //
  131. ShowWindow( hWndPreview, SW_SHOW );
  132. //
  133. // Delete the source bitmap
  134. //
  135. DeleteObject(hBitmap);
  136. }
  137. }
  138. }
  139. else
  140. {
  141. ShowWindow( hWndPreview, SW_HIDE );
  142. WiaPreviewControl_SetBitmap( hWndPreview, TRUE, TRUE, NULL );
  143. }
  144. }
  145. }
  146. LRESULT CCommonDeleteProgressPage::OnInitDialog( WPARAM, LPARAM lParam )
  147. {
  148. //
  149. // Make sure this starts out NULL
  150. //
  151. m_pControllerWindow = NULL;
  152. //
  153. // Get the PROPSHEETPAGE.lParam
  154. //
  155. PROPSHEETPAGE *pPropSheetPage = reinterpret_cast<PROPSHEETPAGE*>(lParam);
  156. if (pPropSheetPage)
  157. {
  158. m_pControllerWindow = reinterpret_cast<CAcquisitionManagerControllerWindow*>(pPropSheetPage->lParam);
  159. if (m_pControllerWindow)
  160. {
  161. m_pControllerWindow->m_WindowList.Add(m_hWnd);
  162. }
  163. }
  164. //
  165. // Bail out
  166. //
  167. if (!m_pControllerWindow)
  168. {
  169. EndDialog(m_hWnd,IDCANCEL);
  170. return -1;
  171. }
  172. //
  173. // Prepare the preview control
  174. //
  175. HWND hWndThumbnail = GetDlgItem( m_hWnd, IDC_COMDEL_CURRENTTHUMBNAIL );
  176. if (hWndThumbnail)
  177. {
  178. //
  179. // We only want to set the preview mode for scanners
  180. //
  181. if (CAcquisitionManagerControllerWindow::ScannerMode==m_pControllerWindow->m_DeviceTypeMode)
  182. {
  183. WiaPreviewControl_SetPreviewMode( hWndThumbnail, TRUE );
  184. }
  185. else
  186. {
  187. WiaPreviewControl_AllowNullSelection( hWndThumbnail, TRUE );
  188. WiaPreviewControl_ClearSelection( hWndThumbnail );
  189. }
  190. WiaPreviewControl_SetBgAlpha( hWndThumbnail, FALSE, 0xFF );
  191. WiaPreviewControl_DisableSelection( hWndThumbnail, TRUE );
  192. WiaPreviewControl_SetEnableStretch( hWndThumbnail, FALSE );
  193. WiaPreviewControl_SetBkColor( hWndThumbnail, FALSE, TRUE, GetSysColor(COLOR_WINDOW) );
  194. WiaPreviewControl_HideEmptyPreview( hWndThumbnail, TRUE );
  195. WiaPreviewControl_SetPreviewAlignment( hWndThumbnail, PREVIEW_WINDOW_CENTER, PREVIEW_WINDOW_CENTER, FALSE );
  196. }
  197. return 0;
  198. }
  199. void CCommonDeleteProgressPage::OnNotifyDeleteImage( UINT nMsg, CThreadNotificationMessage *pThreadNotificationMessage )
  200. {
  201. WIA_PUSHFUNCTION(TEXT("CCommonDeleteProgressPage::OnNotifyDeleteImage()"));
  202. //
  203. // Don't handle delete messages if we are not on this page
  204. //
  205. if (PropSheet_GetCurrentPageHwnd(GetParent(m_hWnd)) != m_hWnd)
  206. {
  207. return;
  208. }
  209. CDeleteImagesThreadNotifyMessage *pDeleteImageThreadNotifyMessage = dynamic_cast<CDeleteImagesThreadNotifyMessage*>(pThreadNotificationMessage);
  210. if (pDeleteImageThreadNotifyMessage && m_pControllerWindow)
  211. {
  212. switch (pDeleteImageThreadNotifyMessage->Status())
  213. {
  214. case CDeleteImagesThreadNotifyMessage::Begin:
  215. {
  216. switch (pDeleteImageThreadNotifyMessage->Operation())
  217. {
  218. case CDeleteImagesThreadNotifyMessage::DeleteAll:
  219. {
  220. //
  221. // Store the number of images we'll be deleting
  222. //
  223. m_nPictureCount = pDeleteImageThreadNotifyMessage->PictureCount();
  224. //
  225. // Initialize current image count progress bar
  226. //
  227. SendDlgItemMessage( m_hWnd, IDC_COMDEL_CURRENTIMAGE, PBM_SETRANGE32, 0, m_nPictureCount);
  228. UpdateCurrentPicture(0);
  229. }
  230. break;
  231. case CDeleteImagesThreadNotifyMessage::DeleteImage:
  232. {
  233. HBITMAP hBitmapThumbnail = NULL;
  234. CWiaItem *pWiaItem = m_pControllerWindow->m_WiaItemList.Find( pDeleteImageThreadNotifyMessage->Cookie() );
  235. if (pWiaItem)
  236. {
  237. //
  238. // This will only work if it is a scanner item
  239. //
  240. hBitmapThumbnail = pWiaItem->BitmapImage();
  241. if (!hBitmapThumbnail)
  242. {
  243. //
  244. // Since it didn't work, this is a camera item, so create a thumbnail.
  245. // We have to make sure we nuke this bitmap or it is a leak!
  246. //
  247. HDC hDC = GetDC(NULL);
  248. if (hDC)
  249. {
  250. hBitmapThumbnail = pWiaItem->CreateThumbnailBitmap(hDC);
  251. ReleaseDC(NULL,hDC);
  252. }
  253. }
  254. }
  255. //
  256. // Update the thumbnail in the progress window
  257. //
  258. UpdateThumbnail( hBitmapThumbnail, pWiaItem );
  259. //
  260. // Increment file queue progress
  261. //
  262. UpdateCurrentPicture(pDeleteImageThreadNotifyMessage->CurrentPicture());
  263. }
  264. }
  265. }
  266. break;
  267. case CDeleteImagesThreadNotifyMessage::End:
  268. {
  269. switch (pDeleteImageThreadNotifyMessage->Operation())
  270. {
  271. case CDeleteImagesThreadNotifyMessage::DeleteAll:
  272. {
  273. //
  274. // Save the delete result
  275. //
  276. m_pControllerWindow->m_hrDeleteResult = pDeleteImageThreadNotifyMessage->hr();
  277. WIA_PRINTHRESULT((m_pControllerWindow->m_hrDeleteResult,TEXT("m_pControllerWindow->m_hrDeleteResult")));
  278. //
  279. // Assume the upload query page
  280. //
  281. HPROPSHEETPAGE hNextPage = PropSheet_IndexToPage( GetParent(m_hWnd), m_pControllerWindow->m_nUploadQueryPageIndex );
  282. //
  283. // If there is a message box active, save this page till the message box is dismissed
  284. //
  285. if (m_bQueryingUser)
  286. {
  287. m_hSwitchToNextPage = hNextPage;
  288. }
  289. else
  290. {
  291. //
  292. // Set the next page
  293. //
  294. PropSheet_SetCurSel( GetParent(m_hWnd), hNextPage, -1 );
  295. }
  296. }
  297. break;
  298. }
  299. }
  300. }
  301. }
  302. }
  303. LRESULT CCommonDeleteProgressPage::OnSetActive( WPARAM, LPARAM )
  304. {
  305. //
  306. // Make sure we have a valid controller window
  307. //
  308. if (!m_pControllerWindow)
  309. {
  310. return -1;
  311. }
  312. //
  313. // Make sure we are actually supposed to delete the images
  314. //
  315. if (!m_pControllerWindow->m_bDeletePicturesIfSuccessful)
  316. {
  317. return -1;
  318. }
  319. //
  320. // Initialize the download error message
  321. //
  322. m_pControllerWindow->m_strErrorMessage = TEXT("");
  323. //
  324. // Initialize the delete result
  325. //
  326. m_pControllerWindow->m_hrDeleteResult = S_OK;
  327. //
  328. // Reset the cancelled flag
  329. //
  330. m_bDeleteCancelled = false;
  331. //
  332. // Clear all of the controls
  333. //
  334. UpdateCurrentPicture(-1);
  335. UpdateThumbnail(NULL,NULL);
  336. //
  337. // Reset the selected region, in case this is a scanner
  338. //
  339. WiaPreviewControl_SetResolution( GetDlgItem( m_hWnd, IDC_COMDEL_CURRENTTHUMBNAIL ), NULL );
  340. WiaPreviewControl_SetSelOrigin( GetDlgItem( m_hWnd, IDC_COMDEL_CURRENTTHUMBNAIL ), 0, FALSE, NULL );
  341. WiaPreviewControl_SetSelExtent( GetDlgItem( m_hWnd, IDC_COMDEL_CURRENTTHUMBNAIL ), 0, FALSE, NULL );
  342. //
  343. // Set the control to preview mode
  344. //
  345. WiaPreviewControl_SetPreviewMode( GetDlgItem( m_hWnd, IDC_COMDEL_CURRENTTHUMBNAIL ), TRUE );
  346. //
  347. // Reset the download event cancel
  348. //
  349. if (m_hCancelDeleteEvent)
  350. {
  351. ResetEvent(m_hCancelDeleteEvent);
  352. }
  353. //
  354. // Cancel thumbnail downloading
  355. //
  356. m_pControllerWindow->m_EventThumbnailCancel.Signal();
  357. //
  358. // We don't want to exit on disconnect if we are on this page
  359. //
  360. m_pControllerWindow->m_OnDisconnect = CAcquisitionManagerControllerWindow::OnDisconnectFailDelete|CAcquisitionManagerControllerWindow::DontAllowSuspend;
  361. //
  362. // Start the download
  363. //
  364. if (!m_pControllerWindow->DeleteDownloadedImages(m_hCancelDeleteEvent))
  365. {
  366. WIA_ERROR((TEXT("m_pControllerWindow->DeleteDownloadedImages FAILED!")));
  367. return -1;
  368. }
  369. //
  370. // No next, back or finish
  371. //
  372. PropSheet_SetWizButtons( GetParent(m_hWnd), 0 );
  373. return 0;
  374. }
  375. LRESULT CCommonDeleteProgressPage::OnWizNext( WPARAM, LPARAM )
  376. {
  377. return 0;
  378. }
  379. LRESULT CCommonDeleteProgressPage::OnWizBack( WPARAM, LPARAM )
  380. {
  381. return 0;
  382. }
  383. LRESULT CCommonDeleteProgressPage::OnReset( WPARAM, LPARAM )
  384. {
  385. //
  386. // Cancel the current download
  387. //
  388. if (m_hCancelDeleteEvent)
  389. {
  390. SetEvent(m_hCancelDeleteEvent);
  391. }
  392. return 0;
  393. }
  394. bool CCommonDeleteProgressPage::QueryCancel(void)
  395. {
  396. //
  397. // Make sure this is the current page
  398. //
  399. if (PropSheet_GetCurrentPageHwnd(GetParent(m_hWnd)) != m_hWnd)
  400. {
  401. return true;
  402. }
  403. //
  404. // Pause the background thread
  405. //
  406. m_pControllerWindow->m_EventPauseBackgroundThread.Reset();
  407. //
  408. // Assume the user doesn't want to cancel
  409. //
  410. bool bResult = false;
  411. //
  412. // Set the querying user flag so the event handler won't change pages
  413. //
  414. m_bQueryingUser = true;
  415. //
  416. // We may be called on to switch pages when we are done here. If so, this will be non-NULL then.
  417. //
  418. m_hSwitchToNextPage = NULL;
  419. //
  420. // Don't ask again if we've already asked
  421. //
  422. if (!m_bDeleteCancelled)
  423. {
  424. //
  425. // Ask the user if they want to cancel
  426. //
  427. if (CMessageBoxEx::IDMBEX_YES == CMessageBoxEx::MessageBox( m_hWnd, CSimpleString(IDS_CONFIRM_CANCEL_DELETE,g_hInstance), CSimpleString(IDS_ERROR_TITLE,g_hInstance), CMessageBoxEx::MBEX_YESNO|CMessageBoxEx::MBEX_ICONQUESTION ))
  428. {
  429. //
  430. // The user does want to cancel, so set the cancel event
  431. //
  432. if (m_hCancelDeleteEvent)
  433. {
  434. SetEvent(m_hCancelDeleteEvent);
  435. }
  436. //
  437. // Ensure we are cancelled so we don't get here again
  438. //
  439. m_bDeleteCancelled = true;
  440. //
  441. // Make sure the cancel button is disabled
  442. //
  443. EnableWindow( GetDlgItem( GetParent(m_hWnd), IDCANCEL ), FALSE );
  444. //
  445. // return true
  446. //
  447. bResult = true;
  448. }
  449. }
  450. //
  451. // If we are supposed to switch pages, switch now
  452. //
  453. if (m_hSwitchToNextPage)
  454. {
  455. PropSheet_SetCurSel( GetParent(m_hWnd), m_hSwitchToNextPage, -1 );
  456. }
  457. //
  458. // Reset the querying user flag so the event handler can change pages as needed
  459. //
  460. m_bQueryingUser = false;
  461. //
  462. // Unpause the background thread
  463. //
  464. m_pControllerWindow->m_EventPauseBackgroundThread.Signal();
  465. return bResult;
  466. }
  467. LRESULT CCommonDeleteProgressPage::OnQueryCancel( WPARAM, LPARAM )
  468. {
  469. //
  470. // The user is not allowed to cancel out of this page
  471. //
  472. BOOL bResult = TRUE;
  473. //
  474. // Since we don't let them cancel in this page, just ignore the result
  475. //
  476. QueryCancel();
  477. return bResult;
  478. }
  479. LRESULT CCommonDeleteProgressPage::OnKillActive( WPARAM, LPARAM )
  480. {
  481. //
  482. // Make sure the cancel button is enabled
  483. //
  484. EnableWindow( GetDlgItem( GetParent(m_hWnd), IDCANCEL ), TRUE );
  485. return 0;
  486. }
  487. LRESULT CCommonDeleteProgressPage::OnQueryEndSession( WPARAM, LPARAM )
  488. {
  489. bool bCancel = QueryCancel();
  490. if (bCancel)
  491. {
  492. return TRUE;
  493. }
  494. else
  495. {
  496. return FALSE;
  497. }
  498. }
  499. LRESULT CCommonDeleteProgressPage::OnSysColorChange( WPARAM wParam, LPARAM lParam )
  500. {
  501. WiaPreviewControl_SetBkColor( GetDlgItem( m_hWnd, IDC_COMDEL_CURRENTTHUMBNAIL ), TRUE, TRUE, GetSysColor(COLOR_WINDOW) );
  502. WiaPreviewControl_SetBkColor( GetDlgItem( m_hWnd, IDC_COMDEL_CURRENTTHUMBNAIL ), TRUE, FALSE, GetSysColor(COLOR_WINDOW) );
  503. return 0;
  504. }
  505. LRESULT CCommonDeleteProgressPage::OnCommand( WPARAM wParam, LPARAM lParam )
  506. {
  507. SC_BEGIN_COMMAND_HANDLERS()
  508. {
  509. }
  510. SC_END_COMMAND_HANDLERS();
  511. }
  512. LRESULT CCommonDeleteProgressPage::OnThreadNotification( WPARAM wParam, LPARAM lParam )
  513. {
  514. WTM_BEGIN_THREAD_NOTIFY_MESSAGE_HANDLERS()
  515. {
  516. WTM_HANDLE_NOTIFY_MESSAGE( TQ_DOWNLOADIMAGE, OnNotifyDeleteImage );
  517. }
  518. WTM_END_THREAD_NOTIFY_MESSAGE_HANDLERS();
  519. }
  520. LRESULT CCommonDeleteProgressPage::OnNotify( WPARAM wParam, LPARAM lParam )
  521. {
  522. SC_BEGIN_NOTIFY_MESSAGE_HANDLERS()
  523. {
  524. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_WIZBACK,OnWizBack);
  525. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_WIZNEXT,OnWizNext);
  526. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_SETACTIVE,OnSetActive);
  527. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_KILLACTIVE,OnKillActive);
  528. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_RESET,OnReset);
  529. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_QUERYCANCEL,OnQueryCancel);
  530. }
  531. SC_END_NOTIFY_MESSAGE_HANDLERS();
  532. }
  533. INT_PTR CALLBACK CCommonDeleteProgressPage::DialogProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  534. {
  535. SC_BEGIN_DIALOG_MESSAGE_HANDLERS(CCommonDeleteProgressPage)
  536. {
  537. SC_HANDLE_DIALOG_MESSAGE( WM_INITDIALOG, OnInitDialog );
  538. SC_HANDLE_DIALOG_MESSAGE( WM_COMMAND, OnCommand );
  539. SC_HANDLE_DIALOG_MESSAGE( WM_NOTIFY, OnNotify );
  540. SC_HANDLE_DIALOG_MESSAGE( WM_QUERYENDSESSION, OnQueryEndSession );
  541. SC_HANDLE_DIALOG_MESSAGE( WM_SYSCOLORCHANGE, OnSysColorChange );
  542. }
  543. SC_HANDLE_REGISTERED_DIALOG_MESSAGE( m_nThreadNotificationMessage, OnThreadNotification );
  544. SC_END_DIALOG_MESSAGE_HANDLERS();
  545. }