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.

1289 lines
43 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000.
  5. //
  6. // File: ConfirmationUI.cpp
  7. //
  8. // Contents: Confirmation UI for storage based copy engine
  9. //
  10. // History: 20-Mar-2000 ToddB
  11. //
  12. //--------------------------------------------------------------------------
  13. #include "shellprv.h"
  14. #pragma hdrstop
  15. #include "ConfirmationUI.h"
  16. #include "resource.h"
  17. #include "ntquery.h"
  18. #include "ids.h"
  19. #include <initguid.h>
  20. #define TF_DLGDISPLAY 0x00010000 // messages related to display of the confirmation dialog
  21. #define TF_DLGSTORAGE 0x00020000 // messages related to using the legacy IStorage to get dialog info
  22. #define TF_DLGISF 0x00040000 // messages related to using IShellFolder to get dialog info
  23. #define RECT_WIDTH(rc) ((rc).right - (rc).left)
  24. #define RECT_HEIGHT(rc) ((rc).bottom - (rc).top)
  25. GUID guidStorage = PSGUID_STORAGE;
  26. // prototype some functions that are local to this file:
  27. void ShiftDialogItem(HWND hDlg, int id, int cx, int cy);
  28. BOOL CALLBACK ShiftLeftProc(HWND hwnd, LPARAM lParam);
  29. STDAPI CTransferConfirmation_CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppv)
  30. {
  31. if (!ppv)
  32. return E_POINTER;
  33. CComObject<CTransferConfirmation> *pObj = NULL;
  34. // created with ref count of 0
  35. if (SUCCEEDED(CComObject<CTransferConfirmation>::CreateInstance(&pObj)))
  36. {
  37. // QueryInterface ups the refcount to 1
  38. if (SUCCEEDED(pObj->QueryInterface(riid, ppv)))
  39. {
  40. return S_OK;
  41. }
  42. // failed to get the right interface, delete the object.
  43. delete pObj;
  44. }
  45. *ppv = NULL;
  46. return E_FAIL;
  47. }
  48. CTransferConfirmation::CTransferConfirmation() :
  49. m_fSingle(TRUE)
  50. {
  51. ASSERT(NULL == m_pszDescription);
  52. ASSERT(NULL == m_pszTitle);
  53. ASSERT(NULL == m_hIcon);
  54. ASSERT(NULL == m_pPropUI);
  55. ASSERT(NULL == m_cItems);
  56. }
  57. CTransferConfirmation::~CTransferConfirmation()
  58. {
  59. if (m_pPropUI)
  60. m_pPropUI->Release();
  61. }
  62. int _TitleFromFileOperation(DWORD dwOp)
  63. {
  64. switch (dwOp)
  65. {
  66. case STGOP_RENAME:
  67. return IDS_CONFIRM_FILE_RENAME;
  68. case STGOP_REMOVE:
  69. return IDS_CONFIRM_FILE_DELETE;
  70. case STGOP_MOVE:
  71. return IDS_CONFIRM_FILE_MOVE;
  72. default:
  73. AssertMsg(0, TEXT("Inappropriate Operation code in _TitleFromFileOperation"));
  74. }
  75. return IDS_DEFAULTTITLE;
  76. }
  77. int _TitleFromFolderOperation(DWORD dwOp)
  78. {
  79. switch (dwOp)
  80. {
  81. case STGOP_RENAME:
  82. return IDS_CONFIRM_FOLDER_RENAME;
  83. case STGOP_REMOVE:
  84. return IDS_CONFIRM_FOLDER_DELETE;
  85. case STGOP_MOVE:
  86. return IDS_CONFIRM_FOLDER_MOVE;
  87. default:
  88. AssertMsg(0, TEXT("Inappropriate Operation code in _TitleFromFolderOperation"));
  89. }
  90. return IDS_DEFAULTTITLE;
  91. }
  92. BOOL CTransferConfirmation::_IsCopyOperation(STGOP stgop)
  93. {
  94. return (stgop == STGOP_COPY) || (stgop == STGOP_COPY_PREFERHARDLINK);
  95. }
  96. // TODO: Get better icons for "Nuke File" and "Nuke Folder" from design.
  97. // TODO: Get better icons for "Move File" and "Move Folder" from design.
  98. // TODO: Get better icons for "Secondary Attribute loss" from design (stream loss, encrypt loss, ACL loss, etc)
  99. HRESULT CTransferConfirmation::_GetDialogSettings()
  100. {
  101. _FreeDialogSettings();
  102. ASSERT(NULL == m_pszDescription);
  103. ASSERT(NULL == m_pszTitle);
  104. ASSERT(NULL == m_hIcon);
  105. ASSERT(NULL == m_cItems);
  106. m_fSingle = (m_cop.cRemaining<=1);
  107. // Set the default values of m_crResult so that if the dialog is killed or
  108. // some error occurs we give a valid default response.
  109. m_crResult = CONFRES_CANCEL;
  110. if (m_cop.pcc)
  111. {
  112. // we already have the strings to use
  113. switch (m_cop.pcc->dwButtons)
  114. {
  115. case CCB_YES_SKIP_CANCEL:
  116. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  117. break;
  118. case CCB_RENAME_SKIP_CANCEL:
  119. m_idDialog = IDD_CONFIRM_RENAMESKIPCANCEL;
  120. break;
  121. case CCB_YES_SKIP_RENAME_CANCEL:
  122. m_idDialog = IDD_CONFIRM_YESSKIPRENAMECANCEL;
  123. break;
  124. case CCB_RETRY_SKIP_CANCEL:
  125. m_idDialog = IDD_CONFIRM_RETRYSKIPCANCEL;
  126. break;
  127. case CCB_OK:
  128. m_idDialog = IDD_CONFIRM_OK;
  129. break;
  130. default:
  131. return E_INVALIDARG; // REVIEW: should we define more specific error codes like STG_E_INVALIDBUTTONOPTIONS?
  132. }
  133. if (m_cop.pcc->dwFlags & CCF_SHOW_SOURCE_INFO)
  134. {
  135. _AddItem(m_cop.psiItem);
  136. }
  137. if (m_cop.pcc->dwFlags & CCF_SHOW_DESTINATION_INFO)
  138. {
  139. _AddItem(m_cop.psiDest);
  140. }
  141. }
  142. else
  143. {
  144. TCHAR szBuf[2048];
  145. int idTitle = 0;
  146. int idIcon = 0;
  147. int idDescription = 0;
  148. ////////////////////////////////////////////////////////////////////////////////
  149. // These are "confirmations", i.e. conditions the user can choose to ignore.
  150. // You can typically answer "Yes", "Skip", or "Cancel"
  151. ////////////////////////////////////////////////////////////////////////////////
  152. if (IsEqualIID(m_cop.stc, STCONFIRM_DELETE_STREAM))
  153. {
  154. idTitle = IDS_CONFIRM_FILE_DELETE;
  155. idIcon = IDI_DELETE_FILE;
  156. idDescription = IDS_DELETE_FILE;
  157. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  158. _AddItem(m_cop.psiItem);
  159. }
  160. else if (IsEqualIID(m_cop.stc, STCONFIRM_DELETE_STORAGE))
  161. {
  162. idTitle = IDS_CONFIRM_FOLDER_DELETE;
  163. idIcon = IDI_DELETE_FOLDER;
  164. idDescription = IDS_DELETE_FOLDER;
  165. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  166. _AddItem(m_cop.psiItem);
  167. }
  168. else if (IsEqualIID(m_cop.stc, STCONFIRM_DELETE_READONLY_STREAM))
  169. {
  170. idTitle = IDS_CONFIRM_FILE_DELETE;
  171. idIcon = IDI_DELETE_FILE;
  172. idDescription = IDS_DELETE_READONLY_FILE;
  173. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  174. _AddItem(m_cop.psiItem);
  175. }
  176. else if (IsEqualIID(m_cop.stc, STCONFIRM_DELETE_READONLY_STORAGE))
  177. {
  178. idTitle = IDS_CONFIRM_FOLDER_DELETE;
  179. idIcon = IDI_DELETE_FOLDER;
  180. idDescription = IDS_DELETE_READONLY_FOLDER;
  181. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  182. _AddItem(m_cop.psiItem);
  183. }
  184. else if (IsEqualIID(m_cop.stc, STCONFIRM_DELETE_SYSTEM_STREAM))
  185. {
  186. idTitle = IDS_CONFIRM_FILE_DELETE;
  187. idIcon = IDI_DELETE_FILE;
  188. idDescription = IDS_DELETE_SYSTEM_FILE;
  189. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  190. _AddItem(m_cop.psiItem);
  191. }
  192. else if (IsEqualIID(m_cop.stc, STCONFIRM_DELETE_SYSTEM_STORAGE))
  193. {
  194. idTitle = IDS_CONFIRM_FOLDER_DELETE;
  195. idIcon = IDI_DELETE_FOLDER;
  196. idDescription = IDS_DELETE_SYSTEM_FOLDER;
  197. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  198. _AddItem(m_cop.psiItem);
  199. }
  200. else if (IsEqualIID(m_cop.stc, STCONFIRM_DELETE_TOOLARGE_STREAM))
  201. {
  202. idTitle = IDS_CONFIRM_FILE_DELETE;
  203. idIcon = IDI_NUKE_FILE;
  204. idDescription = IDS_DELETE_TOOBIG_FILE;
  205. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  206. _AddItem(m_cop.psiItem);
  207. }
  208. else if (IsEqualIID(m_cop.stc, STCONFIRM_DELETE_TOOLARGE_STORAGE))
  209. {
  210. idTitle = IDS_CONFIRM_FOLDER_DELETE;
  211. idIcon = IDI_NUKE_FOLDER;
  212. idDescription = IDS_DELETE_TOOBIG_FOLDER;
  213. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  214. _AddItem(m_cop.psiItem);
  215. }
  216. else if (IsEqualIID(m_cop.stc, STCONFIRM_DELETE_WONT_RECYCLE_STREAM))
  217. {
  218. idTitle = IDS_CONFIRM_FILE_DELETE;
  219. idIcon = IDI_NUKE_FILE;
  220. idDescription = IDS_NUKE_FILE;
  221. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  222. _AddItem(m_cop.psiItem);
  223. }
  224. else if (IsEqualIID(m_cop.stc, STCONFIRM_DELETE_WONT_RECYCLE_STORAGE))
  225. {
  226. idTitle = IDS_CONFIRM_FOLDER_DELETE;
  227. idIcon = IDI_NUKE_FOLDER;
  228. idDescription = IDS_NUKE_FOLDER;
  229. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  230. _AddItem(m_cop.psiItem);
  231. }
  232. else if (IsEqualIID(m_cop.stc, STCONFIRM_DELETE_PROGRAM_STREAM))
  233. {
  234. idTitle = IDS_CONFIRM_FILE_DELETE;
  235. idIcon = IDI_DELETE_FILE;
  236. idDescription = IDS_DELETE_PROGRAM_FILE;
  237. m_fShowARPLink = TRUE; // TODO)) implement ShowARPLink
  238. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  239. _AddItem(m_cop.psiItem);
  240. }
  241. else if (IsEqualIID(m_cop.stc, STCONFIRM_MOVE_SYSTEM_STREAM))
  242. {
  243. idTitle = IDS_CONFIRM_FILE_MOVE;
  244. idIcon = IDI_MOVE;
  245. idDescription = IDS_MOVE_SYSTEM_FILE;
  246. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  247. _AddItem(m_cop.psiItem);
  248. }
  249. else if (IsEqualIID(m_cop.stc, STCONFIRM_MOVE_SYSTEM_STORAGE))
  250. {
  251. idTitle = IDS_CONFIRM_FOLDER_MOVE;
  252. idIcon = IDI_MOVE;
  253. idDescription = IDS_MOVE_SYSTEM_FOLDER;
  254. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  255. _AddItem(m_cop.psiItem);
  256. }
  257. else if (IsEqualIID(m_cop.stc, STCONFIRM_RENAME_SYSTEM_STREAM))
  258. {
  259. idTitle = IDS_CONFIRM_FILE_RENAME;
  260. idIcon = IDI_RENAME;
  261. idDescription = IDS_RENAME_SYSTEM_FILE; // Two Arg
  262. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  263. _AddItem(m_cop.psiItem);
  264. }
  265. else if (IsEqualIID(m_cop.stc, STCONFIRM_RENAME_SYSTEM_STORAGE))
  266. {
  267. idTitle = IDS_CONFIRM_FOLDER_RENAME;
  268. idIcon = IDI_RENAME;
  269. idDescription = IDS_RENAME_SYSTEM_FOLDER; // Two Arg
  270. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  271. _AddItem(m_cop.psiItem);
  272. }
  273. else if (IsEqualIID(m_cop.stc, STCONFIRM_STREAM_LOSS_STREAM))
  274. {
  275. idTitle = IDS_CONFIRM_STREAM_LOSS;
  276. idIcon = IDI_NUKE;
  277. idDescription = _IsCopyOperation(m_cop.dwOperation) ? IDS_STREAM_LOSS_COPY_FILE : IDS_STREAM_LOSS_MOVE_FILE;
  278. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  279. _AddItem(m_cop.psiItem);
  280. }
  281. else if (IsEqualIID(m_cop.stc, STCONFIRM_STREAM_LOSS_STORAGE))
  282. {
  283. idTitle = IDS_CONFIRM_STREAM_LOSS;
  284. idIcon = IDI_NUKE;
  285. idDescription = _IsCopyOperation(m_cop.dwOperation) ? IDS_STREAM_LOSS_COPY_FOLDER : IDS_STREAM_LOSS_MOVE_FOLDER;
  286. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  287. _AddItem(m_cop.psiItem);
  288. }
  289. else if (IsEqualIID(m_cop.stc, STCONFIRM_METADATA_LOSS_STREAM))
  290. {
  291. idTitle = IDS_CONFIRM_METADATA_LOSS;
  292. idIcon = IDI_NUKE;
  293. idDescription = _IsCopyOperation(m_cop.dwOperation) ? IDS_METADATA_LOSS_COPY_FILE : IDS_METADATA_LOSS_MOVE_FILE;
  294. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  295. _AddItem(m_cop.psiItem);
  296. }
  297. else if (IsEqualIID(m_cop.stc, STCONFIRM_METADATA_LOSS_STORAGE))
  298. {
  299. idTitle = IDS_CONFIRM_METADATA_LOSS;
  300. idIcon = IDI_NUKE;
  301. idDescription = _IsCopyOperation(m_cop.dwOperation) ? IDS_METADATA_LOSS_COPY_FOLDER : IDS_METADATA_LOSS_MOVE_FOLDER;
  302. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  303. _AddItem(m_cop.psiItem);
  304. }
  305. else if (IsEqualIID(m_cop.stc, STCONFIRM_COMPRESSION_LOSS_STREAM))
  306. {
  307. idTitle = IDS_CONFIRM_COMPRESSION_LOSS;
  308. idIcon = IDI_ATTRIBS_FILE;
  309. idDescription = _IsCopyOperation(m_cop.dwOperation) ? IDS_COMPRESSION_LOSS_COPY_FILE : IDS_COMPRESSION_LOSS_MOVE_FILE;
  310. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  311. _AddItem(m_cop.psiItem);
  312. }
  313. else if (IsEqualIID(m_cop.stc, STCONFIRM_COMPRESSION_LOSS_STORAGE))
  314. {
  315. idTitle = IDS_CONFIRM_COMPRESSION_LOSS;
  316. idIcon = IDI_ATTRIBS_FOLDER;
  317. idDescription = _IsCopyOperation(m_cop.dwOperation) ? IDS_COMPRESSION_LOSS_COPY_FOLDER : IDS_COMPRESSION_LOSS_MOVE_FOLDER;
  318. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  319. _AddItem(m_cop.psiItem);
  320. }
  321. else if (IsEqualIID(m_cop.stc, STCONFIRM_SPARSEDATA_LOSS_STREAM))
  322. {
  323. idTitle = IDS_CONFIRM_COMPRESSION_LOSS;
  324. idIcon = IDI_ATTRIBS_FILE;
  325. idDescription = _IsCopyOperation(m_cop.dwOperation) ? IDS_SPARSE_LOSS_COPY_FILE : IDS_SPARSE_LOSS_MOVE_FILE;
  326. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  327. _AddItem(m_cop.psiItem);
  328. }
  329. else if (IsEqualIID(m_cop.stc, STCONFIRM_ENCRYPTION_LOSS_STREAM))
  330. {
  331. idTitle = IDS_CONFIRM_ENCRYPTION_LOSS;
  332. idIcon = IDI_ATTRIBS_FILE;
  333. idDescription = _IsCopyOperation(m_cop.dwOperation) ? IDS_ENCRYPTION_LOSS_COPY_FILE : IDS_ENCRYPTION_LOSS_MOVE_FILE;
  334. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  335. // is it on purpose that we are not adding item here
  336. }
  337. else if (IsEqualIID(m_cop.stc, STCONFIRM_ENCRYPTION_LOSS_STORAGE))
  338. {
  339. idTitle = IDS_CONFIRM_ENCRYPTION_LOSS;
  340. idIcon = IDI_ATTRIBS_FOLDER;
  341. idDescription = _IsCopyOperation(m_cop.dwOperation) ? IDS_ENCRYPTION_LOSS_COPY_FOLDER : IDS_ENCRYPTION_LOSS_MOVE_FOLDER;
  342. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  343. _AddItem(m_cop.psiItem);
  344. }
  345. else if (IsEqualIID(m_cop.stc, STCONFIRM_ACCESSCONTROL_LOSS_STREAM))
  346. {
  347. idTitle = IDS_CONFIRM_ACL_LOSS;
  348. idIcon = IDI_ATTRIBS_FILE;
  349. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  350. _AddItem(m_cop.psiItem);
  351. }
  352. else if (IsEqualIID(m_cop.stc, STCONFIRM_ACCESSCONTROL_LOSS_STORAGE))
  353. {
  354. idTitle = IDS_CONFIRM_ACL_LOSS;
  355. idIcon = IDI_ATTRIBS_FOLDER;
  356. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  357. _AddItem(m_cop.psiItem);
  358. }
  359. else if (IsEqualIID(m_cop.stc, STCONFIRM_LFNTOFAT_STREAM))
  360. {
  361. idTitle = IDS_SELECT_FILE_NAME;
  362. idIcon = IDI_RENAME;
  363. m_idDialog = IDD_CONFIRM_RENAMESKIPCANCEL;
  364. _AddItem(m_cop.psiItem);
  365. }
  366. else if (IsEqualIID(m_cop.stc, STCONFIRM_LFNTOFAT_STORAGE))
  367. {
  368. idTitle = IDS_SELECT_FOLDER_NAME;
  369. idIcon = IDI_RENAME;
  370. m_idDialog = IDD_CONFIRM_RENAMESKIPCANCEL;
  371. _AddItem(m_cop.psiItem);
  372. }
  373. ////////////////////////////////////////////////////////////////////////////////
  374. // These are the "do you want to replace something" cases, they are special in
  375. // that you can answer "Yes", "Skip", "Rename", or "Cancel"
  376. ////////////////////////////////////////////////////////////////////////////////
  377. else if (IsEqualIID(m_cop.stc, STCONFIRM_REPLACE_STREAM))
  378. {
  379. idTitle = IDS_CONFIRM_FILE_REPLACE;
  380. idIcon = IDI_REPLACE_FILE;
  381. idDescription = IDS_REPLACE_FILE;
  382. m_idDialog = IDD_CONFIRM_YESSKIPRENAMECANCEL;
  383. _AddItem(m_cop.psiDest, IDS_REPLACEEXISTING_FILE);
  384. _AddItem(m_cop.psiItem, IDS_WITHTHIS);
  385. }
  386. else if (IsEqualIID(m_cop.stc, STCONFIRM_REPLACE_STORAGE))
  387. {
  388. idTitle = IDS_CONFIRM_FOLDER_REPLACE;
  389. idIcon = IDI_REPLACE_FOLDER;
  390. idDescription = IDS_REPLACE_FOLDER;
  391. m_idDialog = IDD_CONFIRM_YESSKIPRENAMECANCEL;
  392. _AddItem(m_cop.psiDest, IDS_REPLACEEXISTING_FOLDER);
  393. _AddItem(m_cop.psiItem, IDS_INTOTHIS);
  394. }
  395. ////////////////////////////////////////////////////////////////////////////////
  396. // This group is "error messages", you can typically reply with "Skip",
  397. // "Retry", or "Cancel"
  398. ////////////////////////////////////////////////////////////////////////////////
  399. else
  400. {
  401. // See if the guid is one of our phony guids that's really just an HRESULT and a bunch of zeros.
  402. // To do this we treat the guid like an array of 4 DWORDS and check the last 3 DWORDs against 0.
  403. AssertMsg(sizeof(m_cop.stc) == 4*sizeof(DWORD), TEXT("Size of STGTRANSCONFIRMATION is not 128 bytes!"));
  404. DWORD *pdw = (DWORD*)&m_cop.stc;
  405. if (pdw[1] == 0 && pdw[2] == 0 && pdw[3] == 0)
  406. {
  407. HRESULT hrErr = pdw[0];
  408. switch (hrErr)
  409. {
  410. case STG_E_FILENOTFOUND:
  411. case STG_E_PATHNOTFOUND:
  412. case STG_E_ACCESSDENIED:
  413. case STG_E_INUSE:
  414. case STG_E_SHAREVIOLATION:
  415. case STG_E_LOCKVIOLATION:
  416. case STG_E_DOCFILETOOLARGE:
  417. case STG_E_MEDIUMFULL:
  418. case STG_E_INSUFFICIENTMEMORY:
  419. case STG_E_DISKISWRITEPROTECTED:
  420. case STG_E_FILEALREADYEXISTS:
  421. case STG_E_INVALIDNAME:
  422. case STG_E_REVERTED:
  423. case STG_E_DOCFILECORRUPT:
  424. // these are expected errors for which we should have custom friendly strings:
  425. // TODO: Get friendly messages for these errors from UA
  426. idTitle = IDS_DEFAULTTITLE;
  427. idIcon = IDI_DEFAULTICON;
  428. idDescription = IDS_DEFAULTDESC;
  429. m_idDialog = IDD_CONFIRM_RETRYSKIPCANCEL;
  430. break;
  431. // these are errors I don't think we should ever see, so I'm asserting but then falling through to the
  432. // default case anyway. In most cases I simply don't know what these mean.
  433. case E_PENDING:
  434. case STG_E_CANTSAVE:
  435. case STG_E_SHAREREQUIRED:
  436. case STG_E_NOTCURRENT:
  437. case STG_E_WRITEFAULT:
  438. case STG_E_READFAULT:
  439. case STG_E_SEEKERROR:
  440. case STG_E_NOTFILEBASEDSTORAGE:
  441. case STG_E_NOTSIMPLEFORMAT:
  442. case STG_E_INCOMPLETE:
  443. case STG_E_TERMINATED:
  444. case STG_E_BADBASEADDRESS:
  445. case STG_E_EXTANTMARSHALLINGS:
  446. case STG_E_OLDFORMAT:
  447. case STG_E_OLDDLL:
  448. case STG_E_UNKNOWN:
  449. case STG_E_UNIMPLEMENTEDFUNCTION:
  450. case STG_E_INVALIDFLAG:
  451. case STG_E_PROPSETMISMATCHED:
  452. case STG_E_ABNORMALAPIEXIT:
  453. case STG_E_INVALIDHEADER:
  454. case STG_E_INVALIDPARAMETER:
  455. case STG_E_INVALIDFUNCTION:
  456. case STG_E_TOOMANYOPENFILES:
  457. case STG_E_INVALIDHANDLE:
  458. case STG_E_INVALIDPOINTER:
  459. case STG_E_NOMOREFILES:
  460. TraceMsg(TF_ERROR, "We should never be asked to confirm this error (%08x)", hrErr);
  461. // fall through...
  462. default:
  463. // Use FormatMessage to get the default description for this error message. Sure that's totally
  464. // useless to the end user, but its more useful that nothing which is the altnerative.
  465. idTitle = IDS_DEFAULTTITLE;
  466. idIcon = IDI_DEFAULTICON;
  467. if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, hrErr, 0, szBuf, ARRAYSIZE(szBuf), NULL))
  468. {
  469. m_pszDescription = StrDup(szBuf);
  470. }
  471. else
  472. {
  473. idDescription = IDS_DEFAULTDESC;
  474. }
  475. m_idDialog = IDD_CONFIRM_RETRYSKIPCANCEL;
  476. break;
  477. }
  478. }
  479. else
  480. {
  481. // for the default case we show an "unknown error" message and offer
  482. // "skip", "retry", and "cancel". We should never get to this code path.
  483. TraceMsg(TF_ERROR, "An unknown non-custom error is being display in CTransferConfirmation!");
  484. idTitle = IDS_DEFAULTTITLE;
  485. idIcon = IDI_DEFAULTICON;
  486. idDescription = IDS_DEFAULTDESC;
  487. m_idDialog = IDD_CONFIRM_RETRYSKIPCANCEL;
  488. }
  489. }
  490. if (idTitle && LoadString(_Module.GetResourceInstance(), idTitle, szBuf, ARRAYSIZE(szBuf)))
  491. {
  492. m_pszTitle = StrDup(szBuf);
  493. }
  494. if (idIcon)
  495. {
  496. m_hIcon = (HICON)LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(idIcon), IMAGE_ICON, 0,0, LR_DEFAULTSIZE);
  497. }
  498. if (idDescription && LoadString(_Module.GetResourceInstance(), idDescription, szBuf, ARRAYSIZE(szBuf)))
  499. {
  500. m_pszDescription = StrDup(szBuf);
  501. }
  502. }
  503. if (m_fSingle)
  504. {
  505. // we don't show the "skip" button if only a single item is being moved.
  506. switch(m_idDialog)
  507. {
  508. case IDD_CONFIRM_RETRYSKIPCANCEL:
  509. m_idDialog = IDD_CONFIRM_RETRYCANCEL;
  510. break;
  511. case IDD_CONFIRM_YESSKIPCANCEL:
  512. m_idDialog = IDD_CONFIRM_YESCANCEL;
  513. break;
  514. case IDD_CONFIRM_RENAMESKIPCANCEL:
  515. m_idDialog = IDD_CONFIRM_RENAMECANCEL;
  516. break;
  517. case IDD_CONFIRM_YESSKIPRENAMECANCEL:
  518. m_idDialog = IDD_CONFIRM_YESRENAMECANCEL;
  519. break;
  520. default:
  521. break; // unknown dialog
  522. }
  523. }
  524. // rename - not really implemented yet
  525. switch(m_idDialog)
  526. {
  527. case IDD_CONFIRM_RENAMESKIPCANCEL:
  528. m_idDialog = IDD_CONFIRM_SKIPCANCEL;
  529. break;
  530. case IDD_CONFIRM_RENAMECANCEL:
  531. m_idDialog = IDD_CONFIRM_CANCEL;
  532. break;
  533. case IDD_CONFIRM_YESSKIPRENAMECANCEL:
  534. m_idDialog = IDD_CONFIRM_YESSKIPCANCEL;
  535. break;
  536. case IDD_CONFIRM_YESRENAMECANCEL:
  537. m_idDialog = IDD_CONFIRM_YESCANCEL;
  538. break;
  539. default:
  540. break; // Non-rename dialog
  541. }
  542. return S_OK;
  543. }
  544. // free everything loaded or allocated in _GetDialogSetttings.
  545. HRESULT CTransferConfirmation::_FreeDialogSettings()
  546. {
  547. if (m_pszTitle)
  548. {
  549. LocalFree(m_pszTitle);
  550. m_pszTitle = NULL;
  551. }
  552. if (m_hIcon)
  553. {
  554. DestroyIcon(m_hIcon);
  555. m_hIcon = NULL;
  556. }
  557. if (m_pszDescription)
  558. {
  559. LocalFree(m_pszDescription);
  560. m_pszDescription = NULL;
  561. }
  562. // This array is zeroed before usage, anything that's no longer zero needs to
  563. // be freed in the appropriate mannor.
  564. for (int i=0; i<ARRAYSIZE(m_rgItemInfo); i++)
  565. {
  566. if (m_rgItemInfo[i].pwszIntro)
  567. {
  568. delete [] m_rgItemInfo[i].pwszIntro;
  569. m_rgItemInfo[i].pwszIntro = NULL;
  570. }
  571. if (m_rgItemInfo[i].pwszDisplayName)
  572. {
  573. CoTaskMemFree(m_rgItemInfo[i].pwszDisplayName);
  574. m_rgItemInfo[i].pwszDisplayName = NULL;
  575. }
  576. if (m_rgItemInfo[i].pwszAttribs)
  577. {
  578. SHFree(m_rgItemInfo[i].pwszAttribs);
  579. m_rgItemInfo[i].pwszAttribs = NULL;
  580. }
  581. if (m_rgItemInfo[i].hBitmap)
  582. {
  583. DeleteObject(m_rgItemInfo[i].hBitmap);
  584. m_rgItemInfo[i].hBitmap = NULL;
  585. }
  586. if (m_rgItemInfo[i].hIcon)
  587. {
  588. DestroyIcon(m_rgItemInfo[i].hIcon);
  589. m_rgItemInfo[i].hIcon = NULL;
  590. }
  591. }
  592. m_cItems = 0;
  593. return S_OK;
  594. }
  595. HRESULT CTransferConfirmation::_ClearSettings()
  596. {
  597. m_idDialog = IDD_CONFIRM_RETRYSKIPCANCEL;
  598. m_fShowARPLink = 0;
  599. m_fApplyToAll = 0;
  600. m_cItems = 0;
  601. m_hfont = 0;
  602. ZeroMemory(m_rgItemInfo, sizeof(m_rgItemInfo));
  603. return S_OK;
  604. }
  605. HRESULT CTransferConfirmation::_Init()
  606. {
  607. HRESULT hr = S_OK;
  608. ASSERT(m_pszTitle == NULL);
  609. ASSERT(m_hIcon == NULL);
  610. ASSERT(m_pszDescription == NULL);
  611. _ClearSettings();
  612. if (!m_pPropUI)
  613. {
  614. hr = CoCreateInstance(CLSID_PropertiesUI, NULL, CLSCTX_INPROC_SERVER,
  615. IID_PPV_ARG(IPropertyUI, &m_pPropUI));
  616. }
  617. return hr;
  618. }
  619. STDMETHODIMP CTransferConfirmation::Confirm(CONFIRMOP *pcop, LPCONFIRMATIONRESPONSE pcr, BOOL *pbAll)
  620. {
  621. HRESULT hr = E_INVALIDARG;
  622. if (pcop && pcr)
  623. {
  624. hr = _Init();
  625. if (SUCCEEDED(hr))
  626. {
  627. m_cop = *pcop;
  628. hr = _GetDialogSettings();
  629. if (SUCCEEDED(hr))
  630. {
  631. HWND hwnd;
  632. IUnknown_GetWindow(pcop->punkSite, &hwnd);
  633. int res = (int)DialogBoxParam(_Module.GetResourceInstance(), MAKEINTRESOURCE(m_idDialog), hwnd, s_ConfirmDialogProc, (LPARAM)this);
  634. if (pbAll)
  635. *pbAll = m_fApplyToAll;
  636. *pcr = m_crResult;
  637. }
  638. _FreeDialogSettings();
  639. }
  640. }
  641. return hr;
  642. }
  643. INT_PTR CALLBACK CTransferConfirmation::s_ConfirmDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  644. {
  645. CTransferConfirmation *pThis;
  646. if (WM_INITDIALOG == uMsg)
  647. {
  648. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
  649. pThis = (CTransferConfirmation *)lParam;
  650. }
  651. else
  652. {
  653. pThis = (CTransferConfirmation *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  654. }
  655. if (!pThis)
  656. return 0;
  657. return pThis->ConfirmDialogProc(hwndDlg, uMsg, wParam, lParam);
  658. }
  659. BOOL CTransferConfirmation::ConfirmDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  660. {
  661. switch (uMsg)
  662. {
  663. case WM_INITDIALOG:
  664. return OnInitDialog(hwndDlg, wParam, lParam);
  665. case WM_COMMAND:
  666. return OnCommand(hwndDlg, LOWORD(wParam), (HWND)lParam);
  667. // TODO: In WM_DESTROY I need to free the icon in IDD_ICON
  668. }
  669. return 0;
  670. }
  671. BOOL CTransferConfirmation::OnInitDialog(HWND hwndDlg, WPARAM wParam, LPARAM lParam)
  672. {
  673. TCHAR szBuf[1024];
  674. _CalculateMetrics(hwndDlg);
  675. int cxShift = 0;
  676. int cyShift = 0;
  677. int i;
  678. GetWindowRect(hwndDlg, &m_rcDlg);
  679. // We have one or more items that are part of this confirmation, we must get more
  680. // information about these items. For example, we want to use full path names instead
  681. // of just the file name, we need to know file size, modifided data, and if possible
  682. // the two "most important" attributes of the file.
  683. // set the title
  684. if (m_cop.pcc)
  685. {
  686. SetWindowTextW(hwndDlg, m_cop.pcc->pwszTitle);
  687. }
  688. else if (m_pszTitle)
  689. {
  690. SetWindowText(hwndDlg, m_pszTitle);
  691. }
  692. // set the icon
  693. HICON hicon = NULL;
  694. if (m_cop.pcc)
  695. {
  696. hicon = m_cop.pcc->hicon;
  697. }
  698. else
  699. {
  700. hicon = m_hIcon;
  701. }
  702. if (hicon)
  703. {
  704. SendDlgItemMessage(hwndDlg, IDD_ICON, STM_SETICON, (LPARAM)hicon, 0);
  705. }
  706. else
  707. {
  708. HWND hwnd = GetDlgItem(hwndDlg, IDD_ICON);
  709. RECT rc;
  710. GetClientRect(hwnd, &rc);
  711. ShowWindow(hwnd, SW_HIDE);
  712. cxShift -= rc.right + m_cxControlPadding;
  713. }
  714. // Set the description text. We need to remember the size and position of this window
  715. // so that we can position other controls under this text
  716. HWND hwndDesc = GetDlgItem(hwndDlg, ID_CONDITION_TEXT);
  717. RECT rcDesc;
  718. GetClientRect(hwndDesc, &rcDesc);
  719. USES_CONVERSION;
  720. szBuf[0] = NULL;
  721. if (m_cop.pcc)
  722. {
  723. StrCpyN(szBuf, W2T(m_cop.pcc->pwszDescription), ARRAYSIZE(szBuf));
  724. }
  725. else if (m_pszDescription)
  726. {
  727. DWORD_PTR rg[2];
  728. rg[0] = (DWORD_PTR)m_rgItemInfo[0].pwszDisplayName;
  729. rg[1] = (DWORD_PTR)m_rgItemInfo[1].pwszDisplayName;
  730. FormatMessage(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
  731. m_pszDescription, 0, 0, szBuf, ARRAYSIZE(szBuf),
  732. (va_list*)rg);
  733. }
  734. if (szBuf[0])
  735. {
  736. int cyWndHeight = _WindowHeightFromString(hwndDesc, RECT_WIDTH(rcDesc), szBuf);
  737. cyShift += (cyWndHeight - rcDesc.bottom);
  738. SetWindowPos(hwndDesc, NULL, 0,0, RECT_WIDTH(rcDesc), cyWndHeight, SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
  739. SetWindowText(hwndDesc, szBuf);
  740. }
  741. // We need to convert from the client coordinates of hwndDesc to the client coordinates of hwndDlg.
  742. // We do this converstion after adjusting the size of hwndDesc to fit the description text.
  743. MapWindowPoints(hwndDesc, hwndDlg, (LPPOINT)&rcDesc, 2);
  744. // Create the folder item(s). The first one starts at cyShift+2*cyControlPadding
  745. // The begining insertion point is one spaceing below the description text
  746. rcDesc.bottom += cyShift + m_cyControlPadding;
  747. AssertMsg(m_cItems<=2, TEXT("Illegal m_cItems value (%d) should never be larger than 2."), m_cItems);
  748. for (i=0; i<m_cItems; i++)
  749. {
  750. int cyHeightOtItem = _DisplayItem(i, hwndDlg, rcDesc.left, rcDesc.bottom);
  751. cyShift += cyHeightOtItem;
  752. rcDesc.bottom += cyHeightOtItem;
  753. TraceMsg(TF_DLGDISPLAY, "_DisplayItem returned a height of: %d", cyHeightOtItem);
  754. }
  755. if (m_cop.pcc && m_cop.pcc->pwszAdvancedDetails)
  756. {
  757. // TODO: if there is "advanced text" create a read-only edit control and put the text in it.
  758. }
  759. if (m_fSingle)
  760. {
  761. HWND hwnd = GetDlgItem(hwndDlg, IDD_REPEAT);
  762. if (hwnd)
  763. {
  764. RECT rc;
  765. GetClientRect(hwnd, &rc);
  766. ShowWindow(hwnd, SW_HIDE);
  767. m_rcDlg.bottom -= rc.bottom + m_cyControlPadding;
  768. }
  769. }
  770. if (cxShift)
  771. {
  772. // shift all child windows by cxShift pixels
  773. EnumChildWindows(hwndDlg, ShiftLeftProc, cxShift);
  774. // don't ask! SetWindowPos in ShiftLeftProc, for some reason, does not do anything on mirrored builds
  775. if (!(GetWindowLong(hwndDlg, GWL_EXSTYLE) & WS_EX_LAYOUTRTL))
  776. m_rcDlg.right += cxShift;
  777. }
  778. if (cyShift)
  779. {
  780. ShiftDialogItem(hwndDlg, IDCANCEL, 0, cyShift);
  781. ShiftDialogItem(hwndDlg, IDYES, 0, cyShift);
  782. ShiftDialogItem(hwndDlg, IDNO, 0, cyShift);
  783. ShiftDialogItem(hwndDlg, IDRETRY, 0, cyShift);
  784. ShiftDialogItem(hwndDlg, IDOK, 0, cyShift);
  785. if (!m_fSingle)
  786. ShiftDialogItem(hwndDlg, IDD_REPEAT, 0, cyShift);
  787. m_rcDlg.bottom += cyShift;
  788. }
  789. // now adjust the dialog size to account for all the things we've added and position it properly
  790. int x = 0;
  791. int y = 0;
  792. UINT uFlags = SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE;
  793. HMONITOR hMonitor = MonitorFromWindow(GetParent(hwndDlg), MONITOR_DEFAULTTONEAREST);
  794. if (hMonitor)
  795. {
  796. MONITORINFO mi;
  797. mi.cbSize = sizeof(mi);
  798. if (GetMonitorInfo(hMonitor, &mi))
  799. {
  800. RECT rcMonitor = mi.rcMonitor;
  801. x = max((RECT_WIDTH(rcMonitor)-RECT_WIDTH(m_rcDlg))/2, 0);
  802. y = max((RECT_HEIGHT(rcMonitor)-RECT_HEIGHT(m_rcDlg))/2, 0);
  803. uFlags &= ~SWP_NOMOVE;
  804. }
  805. }
  806. TraceMsg(TF_DLGDISPLAY, "Setting dialog size to %dx%d", RECT_WIDTH(m_rcDlg), RECT_HEIGHT(m_rcDlg));
  807. SetWindowPos(hwndDlg, NULL, x, y, RECT_WIDTH(m_rcDlg), RECT_HEIGHT(m_rcDlg), uFlags);
  808. return 1;
  809. }
  810. BOOL CTransferConfirmation::OnCommand(HWND hwndDlg, int wID, HWND hwndCtl)
  811. {
  812. BOOL fFinish = TRUE;
  813. switch (wID)
  814. {
  815. case IDD_REPEAT:
  816. fFinish = FALSE;
  817. break;
  818. case IDRETRY: // "Retry"
  819. m_crResult = CONFRES_RETRY;
  820. break;
  821. case IDOK:
  822. case IDYES: // "Yes"
  823. m_crResult = CONFRES_CONTINUE;
  824. break;
  825. case IDNO: // "Skip"
  826. m_crResult = CONFRES_SKIP;
  827. break;
  828. case IDCANCEL: // "Cancel"
  829. m_crResult = CONFRES_CANCEL;
  830. break;
  831. default:
  832. // if we get to here, then the command ID was not one of our buttons, and since the
  833. // only command IDs we have our the buttons this should not happen.
  834. AssertMsg(0, TEXT("Invalid command recieved in CTransferConfirmation::OnCommand."));
  835. fFinish = FALSE;
  836. break;
  837. }
  838. if (fFinish)
  839. {
  840. // ignore apply to all for retry case or we can have infinite loop
  841. m_fApplyToAll = (m_crResult != CONFRES_RETRY && BST_CHECKED == SendDlgItemMessage(hwndDlg, IDD_REPEAT, BM_GETCHECK, 0, 0));
  842. EndDialog(hwndDlg, wID);
  843. return 1;
  844. }
  845. return 0;
  846. }
  847. HRESULT CTransferConfirmation::_AddItem(IShellItem *psi, int idIntro)
  848. {
  849. if (idIntro)
  850. {
  851. TCHAR szBuf[1024];
  852. if (LoadString(_Module.GetResourceInstance(), idIntro, szBuf, ARRAYSIZE(szBuf)))
  853. {
  854. m_rgItemInfo[m_cItems].pwszIntro = StrDup(szBuf);
  855. }
  856. }
  857. HRESULT hr = psi->GetDisplayName(SIGDN_NORMALDISPLAY, &m_rgItemInfo[m_cItems].pwszDisplayName);
  858. if (SUCCEEDED(hr))
  859. {
  860. IQueryInfo *pqi;
  861. hr = psi->BindToHandler(NULL, BHID_SFUIObject, IID_PPV_ARG(IQueryInfo, &pqi));
  862. if (SUCCEEDED(hr))
  863. {
  864. hr = pqi->GetInfoTip(0, &m_rgItemInfo[m_cItems].pwszAttribs);
  865. pqi->Release();
  866. }
  867. IExtractImage *pImg;
  868. hr = psi->BindToHandler(NULL, BHID_SFUIObject, IID_PPV_ARG(IExtractImage, &pImg));
  869. if (SUCCEEDED(hr))
  870. {
  871. WCHAR szImage[MAX_PATH];
  872. SIZE sz = {120, 120};
  873. DWORD dwFlags = 0;
  874. hr = pImg->GetLocation(szImage, ARRAYSIZE(szImage), NULL, &sz, 24, &dwFlags);
  875. if (SUCCEEDED(hr))
  876. {
  877. hr = pImg->Extract(&m_rgItemInfo[m_cItems].hBitmap);
  878. }
  879. pImg->Release();
  880. }
  881. if (FAILED(hr))
  882. {
  883. IExtractIcon *pIcon;
  884. hr = psi->BindToHandler(NULL, BHID_SFUIObject, IID_PPV_ARG(IExtractIcon, &pIcon));
  885. if (SUCCEEDED(hr))
  886. {
  887. TCHAR szIconName[MAX_PATH];
  888. int iIconIndex = 0;
  889. UINT dwFlags = 0;
  890. hr = pIcon->GetIconLocation(0, szIconName, ARRAYSIZE(szIconName), &iIconIndex, &dwFlags);
  891. if (SUCCEEDED(hr))
  892. {
  893. hr = pIcon->Extract(szIconName, iIconIndex, &m_rgItemInfo[m_cItems].hIcon, NULL, GetSystemMetrics(SM_CXICON));
  894. }
  895. pIcon->Release();
  896. }
  897. }
  898. if (FAILED(hr))
  899. {
  900. IQueryAssociations *pAssoc;
  901. hr = CoCreateInstance(CLSID_QueryAssociations, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IQueryAssociations, &pAssoc));
  902. if (SUCCEEDED(hr))
  903. {
  904. WCHAR wszAssocInit[MAX_PATH];
  905. DWORD dwFlags = 0;
  906. SFGAOF flags = SFGAO_STREAM;
  907. if (SUCCEEDED(psi->GetAttributes(flags, &flags)) && (flags & SFGAO_STREAM))
  908. {
  909. dwFlags = ASSOCF_INIT_DEFAULTTOSTAR;
  910. StrCpyW(wszAssocInit, PathFindExtensionW(m_rgItemInfo[m_cItems].pwszDisplayName));
  911. }
  912. else
  913. {
  914. dwFlags = ASSOCF_INIT_DEFAULTTOFOLDER;
  915. StrCpyW(wszAssocInit, L"Directory"); // NB: "Directory is a cannonical name and should not be localized
  916. }
  917. hr = pAssoc->Init(dwFlags, wszAssocInit, NULL,NULL);
  918. if (SUCCEEDED(hr))
  919. {
  920. WCHAR wszIconPath[MAX_PATH];
  921. DWORD dwSize = ARRAYSIZE(wszIconPath);
  922. hr = pAssoc->GetString(0, ASSOCSTR_DEFAULTICON, NULL, wszIconPath, &dwSize);
  923. if (SUCCEEDED(hr))
  924. {
  925. int iIndex = 0;
  926. LPWSTR pszArg = StrChrW(wszIconPath, L',');
  927. if (pszArg)
  928. {
  929. *pszArg = NULL;
  930. pszArg++;
  931. iIndex = StrToIntW(pszArg);
  932. }
  933. ExtractIconEx(W2T(wszIconPath), iIndex, &m_rgItemInfo[m_cItems].hIcon, NULL, 1);
  934. if (!m_rgItemInfo[m_cItems].hIcon)
  935. {
  936. TraceMsg(TF_WARNING, "LoadImage(%S) failed", wszIconPath);
  937. }
  938. }
  939. else
  940. {
  941. TraceMsg(TF_WARNING, "pAssoc->GetString() failed");
  942. }
  943. }
  944. else
  945. {
  946. TraceMsg(TF_WARNING, "pAssoc->Init(%S) failed", wszAssocInit);
  947. }
  948. pAssoc->Release();
  949. }
  950. }
  951. // if we fail to extract an image then we show the remaining info anyway:
  952. if (FAILED(hr))
  953. hr = S_FALSE;
  954. }
  955. if (SUCCEEDED(hr))
  956. {
  957. m_cItems++;
  958. }
  959. return hr;
  960. }
  961. BOOL CTransferConfirmation::_CalculateMetrics(HWND hwndDlg)
  962. {
  963. // We space the controls 6 dialog units apart, convert that to pixels
  964. // REVIEW: Is it valid to hardcode this, or does the height in dialog units need to be localized?
  965. RECT rc = {CX_DIALOG_PADDING, CY_DIALOG_PADDING, 0, CY_STATIC_TEXT_HEIGHT};
  966. BOOL bRes = MapDialogRect(hwndDlg, &rc);
  967. m_cxControlPadding = rc.left;
  968. m_cyControlPadding = rc.top;
  969. m_cyText = rc.bottom;
  970. m_hfont = (HFONT)SendMessage(hwndDlg, WM_GETFONT, 0,0);
  971. return bRes;
  972. }
  973. DWORD CTransferConfirmation::_DisplayItem(int iItem, HWND hwndDlg, int x, int y)
  974. {
  975. // We are told what X coordinate to place our left edge, we calculate from that how much room
  976. // we have available for our controls.
  977. int cxAvailable = RECT_WIDTH(m_rcDlg) - x - 2 * m_cxControlPadding;
  978. int yOrig = y;
  979. USES_CONVERSION;
  980. HWND hwnd;
  981. TraceMsg(TF_DLGDISPLAY, "_DisplayItem %d at location (%d,%d) in dialog %08x", iItem, x, y, hwndDlg);
  982. if (m_rgItemInfo[iItem].pwszIntro)
  983. {
  984. TraceMsg(TF_DLGDISPLAY, "CreateWindowEx(0, TEXT(\"STATIC\"), %s, WS_CHILD|WS_VISIBLE, %d,%d, %d,%d, %08x, NULL, %08x, 0);",
  985. m_rgItemInfo[iItem].pwszIntro,
  986. x,y,cxAvailable,m_cyText, hwndDlg, _Module.GetModuleInstance());
  987. hwnd = CreateWindowEx(0, TEXT("STATIC"), m_rgItemInfo[iItem].pwszIntro,
  988. WS_CHILD|WS_VISIBLE,
  989. x,y, cxAvailable,m_cyText,
  990. hwndDlg, NULL,
  991. _Module.GetModuleInstance(), 0);
  992. if (hwnd)
  993. {
  994. // we successfully added the title string for the item
  995. SendMessage(hwnd, WM_SETFONT, (WPARAM)m_hfont, 0);
  996. x += m_cxControlPadding;
  997. y += m_cyText+m_cyControlPadding;
  998. }
  999. }
  1000. RECT rcImg = {0};
  1001. if (m_rgItemInfo[iItem].hBitmap)
  1002. {
  1003. TraceMsg(TF_DLGDISPLAY, "CreateWindowEx(0, TEXT(\"STATIC\"), %s, WS_CHILD|WS_VISIBLE, %d,%d, %d,%d, %08x, NULL, %08x, 0);",
  1004. "_Icon Window_",
  1005. x,y,cxAvailable,m_cyText, hwndDlg, _Module.GetModuleInstance());
  1006. hwnd = CreateWindowEx(0, TEXT("STATIC"), NULL,
  1007. WS_CHILD|WS_VISIBLE|SS_BITMAP,
  1008. x,y,
  1009. 120,120,
  1010. hwndDlg, NULL,
  1011. _Module.GetModuleInstance(), 0);
  1012. if (hwnd)
  1013. {
  1014. SendMessage(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)m_rgItemInfo[iItem].hBitmap);
  1015. GetClientRect(hwnd, &rcImg);
  1016. x += rcImg.right + m_cxControlPadding;
  1017. cxAvailable -= rcImg.right + m_cxControlPadding;
  1018. rcImg.bottom += y;
  1019. }
  1020. }
  1021. else if (m_rgItemInfo[iItem].hIcon)
  1022. {
  1023. TraceMsg(TF_DLGDISPLAY, "CreateWindowEx(0, TEXT(\"STATIC\"), %s, WS_CHILD|WS_VISIBLE, %d,%d, %d,%d, %08x, NULL, %08x, 0);",
  1024. "_Icon Window_",
  1025. x,y,cxAvailable,m_cyText, hwndDlg, _Module.GetModuleInstance());
  1026. hwnd = CreateWindowEx(0, TEXT("STATIC"), NULL,
  1027. WS_CHILD|WS_VISIBLE|SS_ICON,
  1028. x,y,
  1029. GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON),
  1030. hwndDlg, NULL,
  1031. _Module.GetModuleInstance(), 0);
  1032. if (hwnd)
  1033. {
  1034. SendMessage(hwnd, STM_SETICON, (WPARAM)m_rgItemInfo[iItem].hIcon, NULL);
  1035. GetClientRect(hwnd, &rcImg);
  1036. x += rcImg.right + m_cxControlPadding;
  1037. cxAvailable -= rcImg.right + m_cxControlPadding;
  1038. rcImg.bottom += y;
  1039. }
  1040. }
  1041. else
  1042. {
  1043. TraceMsg(TF_DLGDISPLAY, "Not using an image for item %d.", iItem);
  1044. }
  1045. TraceMsg(TF_DLGDISPLAY, "CreateWindowEx(0, TEXT(\"STATIC\"), %s, WS_CHILD|WS_VISIBLE, %d,%d, %d,%d, %08x, NULL, %08x, 0);",
  1046. m_rgItemInfo[iItem].pwszDisplayName,
  1047. x,y,cxAvailable,m_cyText, hwndDlg, _Module.GetModuleInstance());
  1048. int cyWnd = _WindowHeightFromString(hwndDlg, cxAvailable, W2T(m_rgItemInfo[iItem].pwszDisplayName));
  1049. hwnd = CreateWindowEx(0, TEXT("STATIC"), m_rgItemInfo[iItem].pwszDisplayName,
  1050. WS_CHILD|WS_VISIBLE,
  1051. x,y, cxAvailable,cyWnd,
  1052. hwndDlg, NULL,
  1053. _Module.GetModuleInstance(), 0);
  1054. if (hwnd)
  1055. {
  1056. SendMessage(hwnd, WM_SETFONT, (WPARAM)m_hfont, 0);
  1057. y += cyWnd;
  1058. }
  1059. else
  1060. {
  1061. TraceMsg(TF_DLGDISPLAY, "CreateWindowEx for display name failed.");
  1062. }
  1063. TraceMsg(TF_DLGDISPLAY, "CreateWindowEx(0, TEXT(\"STATIC\"), %s, WS_CHILD|WS_VISIBLE, %d,%d, %d,%d, %08x, NULL, %08x, 0);",
  1064. m_rgItemInfo[iItem].pwszAttribs,
  1065. x,y,cxAvailable,m_cyText, hwndDlg, _Module.GetModuleInstance());
  1066. cyWnd = _WindowHeightFromString(hwndDlg, cxAvailable, W2T(m_rgItemInfo[iItem].pwszAttribs));
  1067. hwnd = CreateWindowEx(0, TEXT("STATIC"), m_rgItemInfo[iItem].pwszAttribs,
  1068. WS_CHILD|WS_VISIBLE|SS_LEFT,
  1069. x,y, cxAvailable,cyWnd,
  1070. hwndDlg, NULL,
  1071. _Module.GetModuleInstance(), 0);
  1072. if (hwnd)
  1073. {
  1074. SendMessage(hwnd, WM_SETFONT, (WPARAM)m_hfont, 0);
  1075. y += cyWnd;
  1076. }
  1077. else
  1078. {
  1079. TraceMsg(TF_DLGDISPLAY, "CreateWindowEx for attribs failed.");
  1080. }
  1081. if (rcImg.bottom > y)
  1082. y = rcImg.bottom;
  1083. return (y-yOrig) + m_cyControlPadding;
  1084. }
  1085. int CTransferConfirmation::_WindowHeightFromString(HWND hwnd, int cx, LPTSTR psz)
  1086. {
  1087. RECT rc = {0,0, cx,0 };
  1088. HDC hdc = GetDC(hwnd);
  1089. HFONT hfontOld = NULL;
  1090. DWORD dtFlags = DT_CALCRECT|DT_WORDBREAK;
  1091. if (m_hfont)
  1092. {
  1093. // We need to select the font that the dialog will use so that we calculate the correct size
  1094. hfontOld = (HFONT)SelectObject(hdc, m_hfont);
  1095. }
  1096. else
  1097. {
  1098. // a NULL m_hfont means we are using the system font, using DT_INTERNAL should do the
  1099. // calculation based on the system font.
  1100. dtFlags |= DT_INTERNAL;
  1101. }
  1102. DrawText(hdc, psz, -1, &rc, dtFlags);
  1103. if (hfontOld)
  1104. SelectObject(hdc, hfontOld);
  1105. ReleaseDC(hwnd, hdc);
  1106. return rc.bottom;
  1107. }
  1108. void ShiftWindow(HWND hwnd, int cx, int cy)
  1109. {
  1110. RECT rc;
  1111. // rect in screen coordinates
  1112. GetWindowRect(hwnd, &rc);
  1113. // shift it over
  1114. if (GetWindowLong(GetParent(hwnd), GWL_EXSTYLE) & WS_EX_LAYOUTRTL)
  1115. rc.left -= cx;
  1116. else
  1117. rc.left += cx;
  1118. rc.top += cy;
  1119. // convert to parent windows coords
  1120. MapWindowPoints(NULL, GetParent(hwnd), (LPPOINT)&rc, 2);
  1121. // and move the window
  1122. SetWindowPos(hwnd, NULL, rc.left, rc.top, 0,0, SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE);
  1123. }
  1124. void ShiftDialogItem(HWND hDlg, int id, int cx, int cy)
  1125. {
  1126. HWND hwnd;
  1127. hwnd = GetDlgItem(hDlg, id);
  1128. if (NULL != hwnd)
  1129. {
  1130. ShiftWindow(hwnd, cx, cy);
  1131. }
  1132. }
  1133. BOOL CALLBACK ShiftLeftProc(HWND hwnd, LPARAM lParam)
  1134. {
  1135. ShiftWindow(hwnd, (int)(INT_PTR)lParam, 0);
  1136. return TRUE;
  1137. }