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.

598 lines
18 KiB

  1. /****************************************************************************/
  2. /* */
  3. /* WFDLGS.C - */
  4. /* */
  5. /* Windows File System Dialog procedures */
  6. /* */
  7. /****************************************************************************/
  8. #include "winfile.h"
  9. #include "winnet.h"
  10. #include "lfn.h"
  11. #include "wfcopy.h"
  12. #include "commdlg.h"
  13. #include "dlgs.h"
  14. typedef BOOL (APIENTRY *LPFNFONTPROC)(HWND, UINT, DWORD, LONG);
  15. VOID
  16. APIENTRY
  17. SaveWindows(
  18. HWND hwndMain
  19. )
  20. {
  21. CHAR szPath[MAXPATHLEN];
  22. CHAR buf2[MAXPATHLEN + 6*12];
  23. CHAR key[10];
  24. INT dir_num;
  25. UINT sw;
  26. HWND hwnd;
  27. BOOL bCounting;
  28. POINT ptIcon;
  29. RECT rcWindow;
  30. LONG view, sort, attribs;
  31. // save main window position
  32. sw = GetInternalWindowPos(hwndMain, &rcWindow, &ptIcon);
  33. wsprintf(buf2, "%d,%d,%d,%d, , ,%d", rcWindow.left, rcWindow.top,
  34. rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top, sw);
  35. WritePrivateProfileString(szSettings, szWindow, buf2, szTheINIFile);
  36. // write out dir window strings in reverse order
  37. // so that when we read them back in we get the same Z order
  38. bCounting = TRUE;
  39. dir_num = 0;
  40. DO_AGAIN:
  41. for (hwnd = GetWindow(hwndMDIClient, GW_CHILD); hwnd; hwnd = GetWindow(hwnd, GW_HWNDNEXT)) {
  42. HWND ht = HasTreeWindow(hwnd);
  43. INT nReadLevel = ht? GetWindowLong(ht, GWL_READLEVEL) : 0;
  44. // don't save MDI icon title windows or search windows,
  45. // or any dir window which is currently recursing
  46. if ((GetWindow(hwnd, GW_OWNER) == NULL) &&
  47. GetWindowLong(hwnd, GWL_TYPE) != TYPE_SEARCH)
  48. //nReadLevel == 0)
  49. {
  50. if (bCounting) {
  51. dir_num++;
  52. continue;
  53. }
  54. sw = GetInternalWindowPos(hwnd, &rcWindow, &ptIcon);
  55. view = GetWindowLong(hwnd, GWL_VIEW);
  56. sort = GetWindowLong(hwnd, GWL_SORT);
  57. attribs = GetWindowLong(hwnd, GWL_ATTRIBS);
  58. GetMDIWindowText(hwnd, szPath, sizeof(szPath));
  59. wsprintf(key, szDirKeyFormat, dir_num--);
  60. // format:
  61. // x_win, y_win,
  62. // x_win, y_win,
  63. // x_icon, y_icon,
  64. // show_window, view, sort, attribs, split, directory
  65. wsprintf(buf2, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%s",
  66. rcWindow.left, rcWindow.top,
  67. rcWindow.right, rcWindow.bottom,
  68. ptIcon.x, ptIcon.y,
  69. sw, view, sort, attribs,
  70. GetSplit(hwnd),
  71. (LPSTR)szPath);
  72. // the dir is an ANSI string (?)
  73. WritePrivateProfileString(szSettings, key, buf2, szTheINIFile);
  74. }
  75. }
  76. if (bCounting) {
  77. bCounting = FALSE;
  78. // erase the last dir window so that if they save with
  79. // fewer dirs open we don't pull in old open windows
  80. wsprintf(key, szDirKeyFormat, dir_num + 1);
  81. WritePrivateProfileString(szSettings, key, NULL, szTheINIFile);
  82. goto DO_AGAIN;
  83. }
  84. }
  85. /*--------------------------------------------------------------------------*/
  86. /* */
  87. /* OtherDlgProc() - */
  88. /* */
  89. /*--------------------------------------------------------------------------*/
  90. INT_PTR
  91. APIENTRY
  92. OtherDlgProc(
  93. register HWND hDlg,
  94. UINT wMsg,
  95. WPARAM wParam,
  96. LPARAM lParam
  97. )
  98. {
  99. LONG wView;
  100. register HWND hwndActive;
  101. hwndActive = (HWND)SendMessage(hwndMDIClient, WM_MDIGETACTIVE, 0, 0L);
  102. switch (wMsg) {
  103. case WM_INITDIALOG:
  104. wView = GetWindowLong(hwndActive, GWL_VIEW);
  105. CheckDlgButton(hDlg, IDD_SIZE, wView & VIEW_SIZE);
  106. CheckDlgButton(hDlg, IDD_DATE, wView & VIEW_DATE);
  107. CheckDlgButton(hDlg, IDD_TIME, wView & VIEW_TIME);
  108. CheckDlgButton(hDlg, IDD_FLAGS, wView & VIEW_FLAGS);
  109. break;
  110. case WM_COMMAND:
  111. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  112. case IDD_HELP:
  113. goto DoHelp;
  114. case IDCANCEL:
  115. EndDialog(hDlg, FALSE);
  116. break;
  117. case IDOK:
  118. {
  119. HWND hwnd;
  120. wView = GetWindowLong(hwndActive, GWL_VIEW) & VIEW_PLUSES;
  121. if (IsDlgButtonChecked(hDlg, IDD_SIZE))
  122. wView |= VIEW_SIZE;
  123. if (IsDlgButtonChecked(hDlg, IDD_DATE))
  124. wView |= VIEW_DATE;
  125. if (IsDlgButtonChecked(hDlg, IDD_TIME))
  126. wView |= VIEW_TIME;
  127. if (IsDlgButtonChecked(hDlg, IDD_FLAGS))
  128. wView |= VIEW_FLAGS;
  129. EndDialog(hDlg, TRUE);
  130. if (hwnd = HasDirWindow(hwndActive))
  131. SendMessage(hwnd, FS_CHANGEDISPLAY, CD_VIEW, (DWORD)wView);
  132. else if (hwndActive == hwndSearch) {
  133. SetWindowLong(hwndActive, GWL_VIEW, wView);
  134. InvalidateRect(hwndActive, NULL, TRUE);
  135. }
  136. break;
  137. }
  138. default:
  139. return FALSE;
  140. }
  141. break;
  142. default:
  143. if (wMsg == wHelpMessage) {
  144. DoHelp:
  145. WFHelp(hDlg);
  146. return TRUE;
  147. } else
  148. return FALSE;
  149. }
  150. return TRUE;
  151. }
  152. /*--------------------------------------------------------------------------*/
  153. /* */
  154. /* IncludeDlgProc() - */
  155. /* */
  156. /*--------------------------------------------------------------------------*/
  157. INT_PTR
  158. APIENTRY
  159. IncludeDlgProc(
  160. HWND hDlg,
  161. UINT wMsg,
  162. WPARAM wParam,
  163. LPARAM lParam
  164. )
  165. {
  166. DWORD dwAttribs;
  167. HWND hwndActive;
  168. CHAR szTemp[MAXPATHLEN];
  169. CHAR szInclude[MAXFILENAMELEN];
  170. HWND hwndDir;
  171. hwndActive = (HWND)SendMessage(hwndMDIClient, WM_MDIGETACTIVE, 0, 0L);
  172. switch (wMsg) {
  173. case WM_INITDIALOG:
  174. SendMessage(hwndActive, FS_GETFILESPEC, sizeof(szTemp), (LPARAM)szTemp);
  175. SetDlgItemText(hDlg, IDD_NAME, szTemp);
  176. SendDlgItemMessage(hDlg, IDD_NAME, EM_LIMITTEXT, MAXFILENAMELEN-1, 0L);
  177. dwAttribs = (DWORD)GetWindowLong(hwndActive, GWL_ATTRIBS);
  178. CheckDlgButton(hDlg, IDD_DIR, dwAttribs & ATTR_DIR);
  179. CheckDlgButton(hDlg, IDD_PROGRAMS, dwAttribs & ATTR_PROGRAMS);
  180. CheckDlgButton(hDlg, IDD_DOCS, dwAttribs & ATTR_DOCS);
  181. CheckDlgButton(hDlg, IDD_OTHER, dwAttribs & ATTR_OTHER);
  182. CheckDlgButton(hDlg, IDD_SHOWHIDDEN, dwAttribs & ATTR_HIDDEN);
  183. break;
  184. case WM_COMMAND:
  185. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  186. case IDD_HELP:
  187. goto DoHelp;
  188. case IDCANCEL:
  189. EndDialog(hDlg, FALSE);
  190. break;
  191. case IDOK:
  192. GetDlgItemText(hDlg, IDD_NAME, szInclude, sizeof(szInclude));
  193. if (szInclude[0] == 0L)
  194. lstrcpy(szInclude, szStarDotStar);
  195. dwAttribs = 0;
  196. if (IsDlgButtonChecked(hDlg, IDD_DIR))
  197. dwAttribs |= ATTR_DIR;
  198. if (IsDlgButtonChecked(hDlg, IDD_PROGRAMS))
  199. dwAttribs |= ATTR_PROGRAMS;
  200. if (IsDlgButtonChecked(hDlg, IDD_DOCS))
  201. dwAttribs |= ATTR_DOCS;
  202. if (IsDlgButtonChecked(hDlg, IDD_OTHER))
  203. dwAttribs |= ATTR_OTHER;
  204. if (IsDlgButtonChecked(hDlg, IDD_SHOWHIDDEN))
  205. dwAttribs |= ATTR_HS;
  206. if (!dwAttribs)
  207. dwAttribs = ATTR_EVERYTHING;
  208. EndDialog(hDlg, TRUE); // here to avoid exces repaints
  209. // we need to update the tree if they changed the system/hidden
  210. // flags. major bummer... FIX31
  211. if (hwndDir = HasDirWindow(hwndActive)) {
  212. SendMessage(hwndDir, FS_GETDIRECTORY, sizeof(szTemp), (LPARAM)szTemp);
  213. lstrcat(szTemp, szInclude);
  214. SetWindowText(hwndActive, szTemp);
  215. SetWindowLong(hwndActive, GWL_ATTRIBS, dwAttribs);
  216. SendMessage(hwndDir, FS_CHANGEDISPLAY, CD_PATH, 0L);
  217. }
  218. break;
  219. default:
  220. return FALSE;
  221. }
  222. break;
  223. default:
  224. if (wMsg == wHelpMessage) {
  225. DoHelp:
  226. WFHelp(hDlg);
  227. return TRUE;
  228. } else
  229. return FALSE;
  230. }
  231. return TRUE;
  232. }
  233. INT_PTR
  234. APIENTRY
  235. SelectDlgProc(
  236. HWND hDlg,
  237. UINT wMsg,
  238. WPARAM wParam,
  239. LPARAM lParam)
  240. {
  241. HWND hwndActive, hwnd;
  242. CHAR szList[128];
  243. CHAR szSpec[MAXFILENAMELEN];
  244. LPSTR p;
  245. switch (wMsg) {
  246. case WM_INITDIALOG:
  247. SendDlgItemMessage(hDlg, IDD_NAME, EM_LIMITTEXT, sizeof(szList)-1, 0L);
  248. SetDlgItemText(hDlg, IDD_NAME, szStarDotStar);
  249. break;
  250. case WM_COMMAND:
  251. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  252. case IDD_HELP:
  253. goto DoHelp;
  254. case IDCANCEL:
  255. EndDialog(hDlg, FALSE);
  256. break;
  257. case IDOK: // select
  258. case IDYES: // unselect
  259. // change "Cancel" to "Close"
  260. LoadString(hAppInstance, IDS_CLOSE, szSpec, sizeof(szSpec));
  261. SetDlgItemText(hDlg, IDCANCEL, szSpec);
  262. hwndActive = (HWND)SendMessage(hwndMDIClient, WM_MDIGETACTIVE, 0, 0L);
  263. if (!hwndActive)
  264. break;
  265. GetDlgItemText(hDlg, IDD_NAME, szList, sizeof(szList));
  266. if (hwndActive == hwndSearch)
  267. hwnd = hwndSearch;
  268. else
  269. hwnd = HasDirWindow(hwndActive);
  270. if (hwnd) {
  271. p = szList;
  272. while (p = GetNextFile(p, szSpec, sizeof(szSpec)))
  273. SendMessage(hwnd, FS_SETSELECTION, (BOOL)(GET_WM_COMMAND_ID(wParam, lParam) == IDOK), (LPARAM)szSpec);
  274. }
  275. UpdateStatus(hwndActive);
  276. break;
  277. default:
  278. return FALSE;
  279. }
  280. break;
  281. default:
  282. if (wMsg == wHelpMessage) {
  283. DoHelp:
  284. WFHelp(hDlg);
  285. return TRUE;
  286. } else
  287. return FALSE;
  288. }
  289. return TRUE;
  290. }
  291. UINT_PTR
  292. FontHookProc(
  293. HWND hDlg,
  294. UINT wMsg,
  295. WPARAM wParam,
  296. LPARAM lParam
  297. )
  298. {
  299. UNREFERENCED_PARAMETER(lParam);
  300. switch (wMsg) {
  301. case WM_INITDIALOG:
  302. CheckDlgButton(hDlg, chx3, wTextAttribs & TA_LOWERCASE);
  303. break;
  304. case WM_COMMAND:
  305. switch (wParam) {
  306. case pshHelp:
  307. SendMessage(hwndFrame, wHelpMessage, 0, 0L);
  308. break;
  309. case IDOK:
  310. if (IsDlgButtonChecked(hDlg, chx3))
  311. wTextAttribs |= TA_LOWERCASE;
  312. else
  313. wTextAttribs &= ~TA_LOWERCASE;
  314. break;
  315. }
  316. }
  317. return FALSE;
  318. }
  319. #define abs(x) ((x < 0) ? -x : x)
  320. VOID
  321. APIENTRY
  322. NewFont()
  323. {
  324. HFONT hOldFont;
  325. HANDLE hOld;
  326. HWND hwnd, hwndT;
  327. HDC hdc;
  328. RECT rc;
  329. LOGFONT lf;
  330. CHOOSEFONT cf;
  331. CHAR szBuf[10];
  332. INT res;
  333. WORD iOld,iNew;
  334. #define MAX_PT_SIZE 36
  335. GetObject(hFont, sizeof(lf), (LPSTR)(LPLOGFONT)&lf);
  336. iOld = (WORD)abs(lf.lfHeight);
  337. cf.lStructSize = sizeof(cf);
  338. cf.hwndOwner = hwndFrame;
  339. cf.lpLogFont = &lf;
  340. cf.hInstance = hAppInstance;
  341. cf.lpTemplateName = MAKEINTRESOURCE(FONTDLG);
  342. cf.lpfnHook = FontHookProc;
  343. cf.nSizeMin = 4;
  344. cf.nSizeMax = 36;
  345. cf.Flags = CF_SCREENFONTS | CF_ANSIONLY | CF_SHOWHELP |
  346. CF_ENABLEHOOK | CF_ENABLETEMPLATE |
  347. CF_INITTOLOGFONTSTRUCT | CF_LIMITSIZE;
  348. res = ChooseFont(&cf);
  349. if (!res)
  350. return;
  351. wsprintf(szBuf, "%d", cf.iPointSize / 10);
  352. iNew = (WORD)abs(lf.lfHeight);
  353. // Set wTextAttribs BOLD and ITALIC flags
  354. if (lf.lfWeight == 700)
  355. wTextAttribs |= TA_BOLD;
  356. else
  357. wTextAttribs &= ~TA_BOLD;
  358. if (lf.lfItalic != 0)
  359. wTextAttribs |= TA_ITALIC;
  360. else
  361. wTextAttribs &= ~TA_ITALIC;
  362. WritePrivateProfileString(szSettings, szFace, lf.lfFaceName, szTheINIFile);
  363. WritePrivateProfileString(szSettings, szSize, szBuf, szTheINIFile);
  364. WritePrivateProfileBool(szLowerCase, wTextAttribs);
  365. hOldFont = hFont;
  366. hFont = CreateFontIndirect(&lf);
  367. if (!hFont) {
  368. DeleteObject(hOldFont);
  369. return;
  370. }
  371. // recalc all the metrics for the new font
  372. hdc = GetDC(NULL);
  373. hOld = SelectObject(hdc, hFont);
  374. GetTextStuff(hdc);
  375. if (hOld)
  376. SelectObject(hdc, hOld);
  377. ReleaseDC(NULL, hdc);
  378. // now update all listboxes that are using the old
  379. // font with the new font
  380. for (hwnd = GetWindow(hwndMDIClient, GW_CHILD); hwnd;
  381. hwnd = GetWindow(hwnd, GW_HWNDNEXT)) {
  382. if (GetWindow(hwnd, GW_OWNER))
  383. continue;
  384. if ((INT)GetWindowLong(hwnd, GWL_TYPE) == TYPE_SEARCH) {
  385. SendMessage((HWND)GetDlgItem(hwnd, IDCW_LISTBOX), WM_SETFONT, (WPARAM)hFont, 0L);
  386. SendMessage((HWND)GetDlgItem(hwnd, IDCW_LISTBOX), LB_SETITEMHEIGHT, 0, (LONG)dyFileName);
  387. // we should really update the case of the search
  388. // window here. but this is a rare case...
  389. } else {
  390. // resize the drives, tree, dir
  391. if (hwndT = HasDrivesWindow(hwnd)) {
  392. GetClientRect(hwnd, &rc);
  393. SendMessage(hwnd, WM_SIZE, SIZENOMDICRAP, MAKELONG(rc.right, rc.bottom));
  394. }
  395. if (hwndT = HasDirWindow(hwnd))
  396. SetLBFont(hwndT, GetDlgItem(hwndT, IDCW_LISTBOX), hFont);
  397. if (hwndT = HasTreeWindow(hwnd)) {
  398. // the tree list box
  399. hwndT = GetDlgItem(hwndT, IDCW_TREELISTBOX);
  400. /*
  401. Kludge alert: xTreeMax is a single var representing the width of
  402. all tree windows. It always grows, never shrinks (like the budget
  403. deficit).
  404. */
  405. xTreeMax = (WORD)((xTreeMax * iNew) / iOld);
  406. SendMessage(hwndT, LB_SETHORIZONTALEXTENT, xTreeMax, 0L);
  407. SendMessage(hwndT, WM_SETFONT, (WPARAM)hFont, 0L);
  408. SendMessage(hwndT, LB_SETITEMHEIGHT, 0, (LONG)dyFileName);
  409. }
  410. }
  411. // now repaint after all the font changes
  412. InvalidateRect(hwnd, NULL, TRUE);
  413. }
  414. DeleteObject(hOldFont); // done with this now, delete it
  415. }
  416. /*--------------------------------------------------------------------------*/
  417. /* */
  418. /* ConfirmDlgProc() - */
  419. /* */
  420. /*--------------------------------------------------------------------------*/
  421. INT_PTR
  422. APIENTRY
  423. ConfirmDlgProc(
  424. HWND hDlg,
  425. UINT wMsg,
  426. WPARAM wParam,
  427. LPARAM lParam
  428. )
  429. {
  430. switch (wMsg) {
  431. case WM_INITDIALOG:
  432. CheckDlgButton(hDlg, IDD_DELETE, bConfirmDelete);
  433. CheckDlgButton(hDlg, IDD_SUBDEL, bConfirmSubDel);
  434. CheckDlgButton(hDlg, IDD_REPLACE, bConfirmReplace);
  435. CheckDlgButton(hDlg, IDD_MOUSE, bConfirmMouse);
  436. CheckDlgButton(hDlg, IDD_CONFIG, bConfirmFormat);
  437. break;
  438. case WM_COMMAND:
  439. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  440. case IDD_HELP:
  441. goto DoHelp;
  442. case IDCANCEL:
  443. EndDialog(hDlg, FALSE);
  444. break;
  445. case IDOK:
  446. bConfirmDelete = IsDlgButtonChecked(hDlg, IDD_DELETE);
  447. bConfirmSubDel = IsDlgButtonChecked(hDlg, IDD_SUBDEL);
  448. bConfirmReplace = IsDlgButtonChecked(hDlg, IDD_REPLACE);
  449. bConfirmMouse = IsDlgButtonChecked(hDlg, IDD_MOUSE);
  450. bConfirmFormat = IsDlgButtonChecked(hDlg, IDD_CONFIG);
  451. WritePrivateProfileBool(szConfirmDelete, bConfirmDelete);
  452. WritePrivateProfileBool(szConfirmSubDel, bConfirmSubDel);
  453. WritePrivateProfileBool(szConfirmReplace, bConfirmReplace);
  454. WritePrivateProfileBool(szConfirmMouse, bConfirmMouse);
  455. WritePrivateProfileBool(szConfirmFormat, bConfirmFormat);
  456. EndDialog(hDlg, TRUE);
  457. break;
  458. default:
  459. return(FALSE);
  460. }
  461. break;
  462. default:
  463. if (wMsg == wHelpMessage) {
  464. DoHelp:
  465. WFHelp(hDlg);
  466. return TRUE;
  467. } else
  468. return FALSE;
  469. }
  470. return TRUE;
  471. }