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.

452 lines
16 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: UPQUERY.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 "upquery.h"
  19. #include "resource.h"
  20. #include "simcrack.h"
  21. #include "mboxex.h"
  22. #include "runnpwiz.h"
  23. #include "pviewids.h"
  24. #include <wininet.h>
  25. //
  26. // This is the ID of the help hyperlink
  27. //
  28. #define STR_WORKING_WITH_PICTURES_HYPERLINK TEXT("WorkingWithPictures")
  29. //
  30. // This is the URL to which we navigate to display the "working with pictures" help
  31. //
  32. #define STR_HELP_DESTINATION TEXT("hcp://services/subsite?node=TopLevelBucket_1/Music__video__games_and_photos&topic=MS-ITS%3A%25HELP_LOCATION%25%5Cfilefold.chm%3A%3A/manage_your_pictures.htm&select=TopLevelBucket_1/Music__video__games_and_photos/photos_and_other_digital_images")
  33. CCommonUploadQueryPage::CCommonUploadQueryPage( HWND hWnd )
  34. : m_hWnd(hWnd),
  35. m_pControllerWindow(NULL),
  36. m_nWiaEventMessage(RegisterWindowMessage(STR_WIAEVENT_NOTIFICATION_MESSAGE))
  37. {
  38. }
  39. CCommonUploadQueryPage::~CCommonUploadQueryPage(void)
  40. {
  41. m_hWnd = NULL;
  42. m_pControllerWindow = NULL;
  43. }
  44. LRESULT CCommonUploadQueryPage::OnInitDialog( WPARAM, LPARAM lParam )
  45. {
  46. //
  47. // Make sure this starts out NULL
  48. //
  49. m_pControllerWindow = NULL;
  50. //
  51. // Get the PROPSHEETPAGE.lParam
  52. //
  53. PROPSHEETPAGE *pPropSheetPage = reinterpret_cast<PROPSHEETPAGE*>(lParam);
  54. if (pPropSheetPage)
  55. {
  56. m_pControllerWindow = reinterpret_cast<CAcquisitionManagerControllerWindow*>(pPropSheetPage->lParam);
  57. if (m_pControllerWindow)
  58. {
  59. m_pControllerWindow->m_WindowList.Add(m_hWnd);
  60. }
  61. }
  62. //
  63. // Bail out
  64. //
  65. if (!m_pControllerWindow)
  66. {
  67. EndDialog(m_hWnd,IDCANCEL);
  68. return -1;
  69. }
  70. SendDlgItemMessage( m_hWnd, IDC_TRANSFER_UPLOAD_NO, BM_SETCHECK, BST_CHECKED, 0 );
  71. return 0;
  72. }
  73. LRESULT CCommonUploadQueryPage::OnSetActive( WPARAM, LPARAM )
  74. {
  75. WIA_PUSH_FUNCTION((TEXT("CCommonUploadQueryPage::OnSetActive")));
  76. //
  77. // We do NOT want to exit on disconnect if we are on this page
  78. //
  79. m_pControllerWindow->m_OnDisconnect = 0;
  80. //
  81. // Set the buttons
  82. //
  83. if (m_pControllerWindow->m_bDisconnected)
  84. {
  85. //
  86. // Don't allow "back" if we've been disabled
  87. //
  88. PropSheet_SetWizButtons( GetParent(m_hWnd), PSWIZB_NEXT );
  89. }
  90. else
  91. {
  92. //
  93. // Allow finish and back
  94. //
  95. PropSheet_SetWizButtons( GetParent(m_hWnd), PSWIZB_NEXT|PSWIZB_BACK );
  96. }
  97. return 0;
  98. }
  99. void CCommonUploadQueryPage::CleanupUploadWizard()
  100. {
  101. //
  102. // Remove the old wizard's pages and clear everything
  103. //
  104. for (UINT i=0;i<m_pControllerWindow->m_nUploadWizardPageCount;++i)
  105. {
  106. if (m_pControllerWindow->m_PublishWizardPages[i])
  107. {
  108. PropSheet_RemovePage( GetParent( m_hWnd ), 0, m_pControllerWindow->m_PublishWizardPages[i] );
  109. }
  110. }
  111. ZeroMemory( m_pControllerWindow->m_PublishWizardPages, sizeof(m_pControllerWindow->m_PublishWizardPages[0])*MAX_WIZ_PAGES );
  112. m_pControllerWindow->m_nUploadWizardPageCount = 0;
  113. //
  114. // Release the old publish wizard
  115. //
  116. if (m_pControllerWindow->m_pPublishingWizard)
  117. {
  118. IUnknown_SetSite( m_pControllerWindow->m_pPublishingWizard, NULL );
  119. }
  120. m_pControllerWindow->m_pPublishingWizard = NULL;
  121. }
  122. LRESULT CCommonUploadQueryPage::OnWizNext( WPARAM, LPARAM )
  123. {
  124. //
  125. // If the user has selected a web transfer, start the web transfer wizard
  126. //
  127. m_pControllerWindow->m_bUploadToWeb = false;
  128. //
  129. // Get the next page. Assume the finish page.
  130. //
  131. HPROPSHEETPAGE hNextPage = PropSheet_IndexToPage( GetParent(m_hWnd), m_pControllerWindow->m_nFinishPageIndex );
  132. //
  133. // Assume we aren't uploading the pictures
  134. //
  135. m_pControllerWindow->m_bUploadToWeb = false;
  136. //
  137. // Initialize the hresult
  138. //
  139. m_pControllerWindow->m_hrUploadResult = S_OK;
  140. //
  141. // Destroy the existing wizard if it exists
  142. //
  143. CleanupUploadWizard();
  144. //
  145. // If the user wants to publish these pictures
  146. //
  147. if (BST_CHECKED != SendDlgItemMessage( m_hWnd, IDC_TRANSFER_UPLOAD_NO, BM_GETCHECK, 0, 0 ))
  148. {
  149. //
  150. // This means we are uploading
  151. //
  152. m_pControllerWindow->m_bUploadToWeb = true;
  153. //
  154. // Assume failure
  155. //
  156. m_pControllerWindow->m_hrUploadResult = E_FAIL;
  157. //
  158. // Which wizard?
  159. //
  160. DWORD dwFlags = SHPWHF_NONETPLACECREATE | SHPWHF_NORECOMPRESS;
  161. LPTSTR pszWizardDefn = TEXT("InternetPhotoPrinting");
  162. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_TRANSFER_UPLOAD_TO_WEB, BM_GETCHECK, 0, 0 ))
  163. {
  164. dwFlags = 0;
  165. pszWizardDefn = TEXT("PublishingWizard");
  166. }
  167. //
  168. // Get all of the *UNIQUE* downloaded files
  169. //
  170. CSimpleDynamicArray<CSimpleString> UniqueFiles;
  171. m_pControllerWindow->m_DownloadedFileInformationList.GetUniqueFiles(UniqueFiles);
  172. //
  173. // Make sure we have some files
  174. //
  175. if (UniqueFiles.Size())
  176. {
  177. //
  178. // Get the data object for this file set
  179. //
  180. CComPtr<IDataObject> pDataObject;
  181. m_pControllerWindow->m_hrUploadResult = NetPublishingWizard::CreateDataObjectFromFileList( UniqueFiles, &pDataObject );
  182. if (SUCCEEDED(m_pControllerWindow->m_hrUploadResult) && pDataObject)
  183. {
  184. //
  185. // Create a new publishing wizard
  186. //
  187. WIA_PRINTGUID((CLSID_PublishingWizard,TEXT("CLSID_PublishingWizard")));
  188. WIA_PRINTGUID((IID_IPublishingWizard,TEXT("IID_IPublishingWizard")));
  189. m_pControllerWindow->m_hrUploadResult = CoCreateInstance( CLSID_PublishingWizard, NULL, CLSCTX_INPROC_SERVER, IID_IPublishingWizard, (void**)&m_pControllerWindow->m_pPublishingWizard );
  190. if (SUCCEEDED(m_pControllerWindow->m_hrUploadResult))
  191. {
  192. //
  193. // Initialize the publishing wizard
  194. //
  195. m_pControllerWindow->m_hrUploadResult = m_pControllerWindow->m_pPublishingWizard->Initialize( pDataObject, dwFlags, pszWizardDefn);
  196. if (SUCCEEDED(m_pControllerWindow->m_hrUploadResult))
  197. {
  198. //
  199. // Get our wizard site
  200. //
  201. CComPtr<IWizardSite> pWizardSite;
  202. m_pControllerWindow->m_hrUploadResult = m_pControllerWindow->QueryInterface( IID_IWizardSite, (void**)&pWizardSite );
  203. if (SUCCEEDED(m_pControllerWindow->m_hrUploadResult))
  204. {
  205. //
  206. // Set the wizard site
  207. //
  208. m_pControllerWindow->m_hrUploadResult = IUnknown_SetSite( m_pControllerWindow->m_pPublishingWizard, pWizardSite );
  209. if (SUCCEEDED(m_pControllerWindow->m_hrUploadResult))
  210. {
  211. //
  212. // Get the publishing wizard pages
  213. //
  214. m_pControllerWindow->m_hrUploadResult = m_pControllerWindow->m_pPublishingWizard->AddPages( m_pControllerWindow->m_PublishWizardPages, MAX_WIZ_PAGES, &m_pControllerWindow->m_nUploadWizardPageCount );
  215. if (SUCCEEDED(m_pControllerWindow->m_hrUploadResult))
  216. {
  217. //
  218. // Loop through and add all of the pages to the property sheet
  219. //
  220. for (UINT i=0;i<m_pControllerWindow->m_nUploadWizardPageCount && SUCCEEDED(m_pControllerWindow->m_hrUploadResult);++i)
  221. {
  222. //
  223. // Make sure this is a valid page
  224. //
  225. if (m_pControllerWindow->m_PublishWizardPages[i])
  226. {
  227. //
  228. // If we can't add a page, that is an error
  229. //
  230. if (!PropSheet_AddPage( GetParent( m_hWnd ), m_pControllerWindow->m_PublishWizardPages[i] ))
  231. {
  232. WIA_ERROR((TEXT("PropSheet_AddPage failed")));
  233. m_pControllerWindow->m_hrUploadResult = E_FAIL;
  234. }
  235. }
  236. else
  237. {
  238. WIA_ERROR((TEXT("m_pControllerWindow->m_PublishWizardPages[i] was NULL")));
  239. m_pControllerWindow->m_hrUploadResult = E_FAIL;
  240. }
  241. }
  242. //
  243. // If everything is OK up till now, we can transition to the first page of the publishing wizard
  244. //
  245. if (SUCCEEDED(m_pControllerWindow->m_hrUploadResult))
  246. {
  247. hNextPage = m_pControllerWindow->m_PublishWizardPages[0];
  248. }
  249. }
  250. else
  251. {
  252. WIA_PRINTHRESULT((m_pControllerWindow->m_hrUploadResult,TEXT("m_pControllerWindow->m_pPublishingWizard->AddPages failed")));
  253. }
  254. }
  255. else
  256. {
  257. WIA_PRINTHRESULT((m_pControllerWindow->m_hrUploadResult,TEXT("IUnknown_SetSite failed")));
  258. }
  259. }
  260. else
  261. {
  262. WIA_PRINTHRESULT((m_pControllerWindow->m_hrUploadResult,TEXT("m_pControllerWindow->QueryInterface( IID_IWizardSite ) failed")));
  263. }
  264. }
  265. else
  266. {
  267. WIA_PRINTHRESULT((m_pControllerWindow->m_hrUploadResult,TEXT("m_pPublishingWizard->Initialize failed")));
  268. }
  269. }
  270. else
  271. {
  272. WIA_PRINTHRESULT((m_pControllerWindow->m_hrUploadResult,TEXT("CoCreateInstance( CLSID_PublishingWizard failed")));
  273. }
  274. }
  275. else
  276. {
  277. WIA_PRINTHRESULT((m_pControllerWindow->m_hrUploadResult,TEXT("NetPublishingWizard::CreateDataObjectFromFileList failed")));
  278. }
  279. }
  280. else
  281. {
  282. m_pControllerWindow->m_hrUploadResult = E_FAIL;
  283. WIA_ERROR((TEXT("There were no files")));
  284. }
  285. //
  286. // If an error occurred, alert the user and clean up
  287. //
  288. if (FAILED(m_pControllerWindow->m_hrUploadResult))
  289. {
  290. //
  291. // Clean up
  292. //
  293. CleanupUploadWizard();
  294. //
  295. // Tell the user
  296. //
  297. MessageBox( m_hWnd, CSimpleString(IDS_UNABLE_TO_PUBLISH,g_hInstance), CSimpleString(IDS_ERROR_TITLE,g_hInstance), MB_ICONERROR );
  298. }
  299. }
  300. //
  301. // If we have a next page, navigate to it.
  302. //
  303. if (hNextPage)
  304. {
  305. PropSheet_SetCurSel( GetParent(m_hWnd), hNextPage, -1 );
  306. return -1;
  307. }
  308. return 0;
  309. }
  310. LRESULT CCommonUploadQueryPage::OnWizBack( WPARAM, LPARAM )
  311. {
  312. PropSheet_SetCurSel( GetParent(m_hWnd), 0, m_pControllerWindow->m_nDestinationPageIndex );
  313. return 0;
  314. }
  315. LRESULT CCommonUploadQueryPage::OnQueryInitialFocus( WPARAM, LPARAM )
  316. {
  317. LRESULT lResult = 0;
  318. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_TRANSFER_UPLOAD_TO_WEB, BM_GETCHECK, 0, 0 ))
  319. {
  320. lResult = reinterpret_cast<LRESULT>(GetDlgItem( m_hWnd, IDC_TRANSFER_UPLOAD_TO_WEB ));
  321. }
  322. else if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_TRANSFER_UPLOAD_TO_PRINT, BM_GETCHECK, 0, 0 ))
  323. {
  324. lResult = reinterpret_cast<LRESULT>(GetDlgItem( m_hWnd, IDC_TRANSFER_UPLOAD_TO_PRINT ));
  325. }
  326. else
  327. {
  328. lResult = reinterpret_cast<LRESULT>(GetDlgItem( m_hWnd, IDC_TRANSFER_UPLOAD_NO ));
  329. }
  330. return lResult;
  331. }
  332. LRESULT CCommonUploadQueryPage::OnEventNotification( WPARAM, LPARAM lParam )
  333. {
  334. WIA_PUSH_FUNCTION((TEXT("CCommonUploadQueryPage::OnEventNotification") ));
  335. CGenericWiaEventHandler::CEventMessage *pEventMessage = reinterpret_cast<CGenericWiaEventHandler::CEventMessage *>(lParam);
  336. if (pEventMessage)
  337. {
  338. if (pEventMessage->EventId() == WIA_EVENT_DEVICE_DISCONNECTED)
  339. {
  340. if (PropSheet_GetCurrentPageHwnd(GetParent(m_hWnd)) == m_hWnd)
  341. {
  342. //
  343. // Disable "back"
  344. //
  345. PropSheet_SetWizButtons( GetParent(m_hWnd), PSWIZB_NEXT );
  346. }
  347. }
  348. //
  349. // Don't delete the message, it is deleted in the controller window
  350. //
  351. }
  352. return 0;
  353. }
  354. LRESULT CCommonUploadQueryPage::OnHyperlinkClick( WPARAM wParam, LPARAM lParam )
  355. {
  356. LRESULT lResult = FALSE;
  357. NMLINK *pNmLink = reinterpret_cast<NMLINK*>(lParam);
  358. if (pNmLink)
  359. {
  360. WIA_TRACE((TEXT("ID: %s"),pNmLink->item.szID));
  361. switch (pNmLink->hdr.idFrom)
  362. {
  363. case IDC_TRANSFER_UPLOAD_HELP:
  364. {
  365. if (!lstrcmp(pNmLink->item.szID,STR_WORKING_WITH_PICTURES_HYPERLINK))
  366. {
  367. ShellExecute( m_hWnd, NULL, STR_HELP_DESTINATION, NULL, TEXT(""), SW_SHOWNORMAL );
  368. }
  369. }
  370. }
  371. }
  372. return lResult;
  373. }
  374. LRESULT CCommonUploadQueryPage::OnCommand( WPARAM wParam, LPARAM lParam )
  375. {
  376. SC_BEGIN_COMMAND_HANDLERS()
  377. {
  378. }
  379. SC_END_COMMAND_HANDLERS();
  380. }
  381. LRESULT CCommonUploadQueryPage::OnNotify( WPARAM wParam, LPARAM lParam )
  382. {
  383. SC_BEGIN_NOTIFY_MESSAGE_HANDLERS()
  384. {
  385. SC_HANDLE_NOTIFY_MESSAGE_CONTROL(NM_RETURN,IDC_TRANSFER_UPLOAD_HELP,OnHyperlinkClick);
  386. SC_HANDLE_NOTIFY_MESSAGE_CONTROL(NM_CLICK,IDC_TRANSFER_UPLOAD_HELP,OnHyperlinkClick);
  387. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_WIZBACK,OnWizBack);
  388. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_WIZNEXT,OnWizNext);
  389. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_SETACTIVE,OnSetActive);
  390. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_QUERYINITIALFOCUS,OnQueryInitialFocus);
  391. }
  392. SC_END_NOTIFY_MESSAGE_HANDLERS();
  393. }
  394. INT_PTR CALLBACK CCommonUploadQueryPage::DialogProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  395. {
  396. SC_BEGIN_DIALOG_MESSAGE_HANDLERS(CCommonUploadQueryPage)
  397. {
  398. SC_HANDLE_DIALOG_MESSAGE( WM_INITDIALOG, OnInitDialog );
  399. SC_HANDLE_DIALOG_MESSAGE( WM_COMMAND, OnCommand );
  400. SC_HANDLE_DIALOG_MESSAGE( WM_NOTIFY, OnNotify );
  401. }
  402. SC_HANDLE_REGISTERED_DIALOG_MESSAGE( m_nWiaEventMessage, OnEventNotification );
  403. SC_END_DIALOG_MESSAGE_HANDLERS();
  404. }