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.

628 lines
19 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. #define NOGDICAPMASKS
  5. #define NOVIRTUALKEYCODES
  6. #define NOWINSTYLES
  7. #define NOSYSMETRICS
  8. #define NOICON
  9. #define NOKEYSTATE
  10. #define NOSYSCOMMANDS
  11. #define NOSHOWWINDOW
  12. #define NOATOM
  13. #define NOGDI
  14. #define NOFONT
  15. #define NOBRUSH
  16. #define NOCLIPBOARD
  17. #define NOCOLOR
  18. #define NOCREATESTRUCT
  19. #define NODRAWTEXT
  20. #define NOMB
  21. #define NOMEMMGR
  22. #define NOMETAFILE
  23. #define NOMINMAX
  24. #define NOOPENFILE
  25. #define NOPEN
  26. #define NOREGION
  27. #define NOSCROLL
  28. #define NOSOUND
  29. #define NOTEXTMETRIC
  30. #define NOWH
  31. #define NOWINOFFSETS
  32. #define NOWNDCLASS
  33. #define NOCOMM
  34. #include <windows.h>
  35. #include "mw.h"
  36. #include "dlgdefs.h"
  37. #include "cmddefs.h"
  38. #include "propdefs.h"
  39. #include "docdefs.h"
  40. #include "str.h"
  41. #include "printdef.h"
  42. extern HCURSOR vhcArrow;
  43. extern int vfCursorVisible;
  44. extern int utCur; /* current conversion unit */
  45. BOOL far PASCAL DialogTabs(hDlg, message, wParam, lParam)
  46. HWND hDlg;
  47. unsigned message;
  48. WORD wParam;
  49. LONG lParam;
  50. {
  51. /* This routine handles input to the Tabs dialog box. */
  52. extern struct DOD (**hpdocdod)[];
  53. extern int docCur;
  54. extern int vdocParaCache;
  55. extern HWND vhWndMsgBoxParent;
  56. extern int ferror;
  57. struct TBD (**hgtbd)[];
  58. int idi;
  59. switch (message)
  60. {
  61. case WM_INITDIALOG:
  62. /* Disable modeless dialog boxes. */
  63. EnableOtherModeless(FALSE);
  64. /* Set up the fields for each of the tabs. */
  65. hgtbd = (**hpdocdod)[docCur].hgtbd;
  66. if (hgtbd != NULL)
  67. {
  68. struct TBD *ptbd;
  69. unsigned dxa;
  70. CHAR szT[cchMaxNum];
  71. CHAR *pch;
  72. for (ptbd = &(**hgtbd)[0], idi = idiTabPos0; (dxa = ptbd->dxa) != 0;
  73. ptbd++, idi++)
  74. {
  75. pch = &szT[0];
  76. CchExpZa(&pch, dxa, utCur, cchMaxNum);
  77. SetDlgItemText(hDlg, idi, (LPSTR)szT);
  78. CheckDlgButton(hDlg, idi + (idiTabDec0 - idiTabPos0), ptbd->jc
  79. == (jcTabDecimal - jcTabMin));
  80. }
  81. }
  82. break;
  83. case WM_SETVISIBLE:
  84. if (wParam)
  85. EndLongOp(vhcArrow);
  86. return(FALSE);
  87. case WM_ACTIVATE:
  88. if (wParam)
  89. {
  90. vhWndMsgBoxParent = hDlg;
  91. }
  92. if (vfCursorVisible)
  93. ShowCursor(wParam);
  94. return(FALSE); /* so that we leave the activate message to
  95. the dialog manager to take care of setting the focus correctly */
  96. case WM_COMMAND:
  97. switch (wParam)
  98. {
  99. struct TBD rgtbd[itbdMax];
  100. struct TBD *ptbdLast;
  101. case idiOk:
  102. /* Sort the new tab descriptors. */
  103. bltc(rgtbd, 0, itbdMax * cwTBD);
  104. ptbdLast = &rgtbd[itbdMax - 1];
  105. for (idi = idiTabPos0; idi <= idiTabPos11; idi++)
  106. {
  107. unsigned dxa;
  108. unsigned dxaTab;
  109. struct TBD *ptbd;
  110. /* If an invalid position was entered, then punt. */
  111. if (!FPdxaPosBIt(&dxa, hDlg, idi))
  112. {
  113. ferror = FALSE;
  114. return (TRUE);
  115. }
  116. /* Ignore blank tabs or tabs at zero. */
  117. if (dxa == valNil || dxa == 0)
  118. {
  119. continue;
  120. }
  121. for (ptbd = &rgtbd[0]; (dxaTab = ptbd->dxa) != 0; ptbd++)
  122. {
  123. /* If there is already a tab at this position, then ignore
  124. the new tab. */
  125. if (dxa == dxaTab)
  126. {
  127. goto GetNextTab;
  128. }
  129. /* If the new tab position is smaller than the current tab,
  130. then make room for the new tab. */
  131. if (dxa < dxaTab)
  132. {
  133. bltbyte(ptbd, ptbd + 1, (unsigned)ptbdLast - (unsigned)ptbd);
  134. break;
  135. }
  136. }
  137. /* Put the tab into rgtbd. */
  138. ptbd->dxa = dxa;
  139. ptbd->jc = (IsDlgButtonChecked(hDlg, idi + (idiTabDec0 -
  140. idiTabPos0)) ? jcTabDecimal : jcTabLeft) - jcTabMin;
  141. GetNextTab:;
  142. }
  143. /* Set up the undo stuff. */
  144. SetUndo(uacFormatTabs, docCur, cp0, cp0, docNil, cpNil, cpNil, 0);
  145. /* Ensure that this document has a tab-stop table. */
  146. if ((hgtbd = (**hpdocdod)[docCur].hgtbd) == NULL)
  147. {
  148. if (FNoHeap(hgtbd = (struct TBD (**)[])HAllocate(itbdMax *
  149. cwTBD)))
  150. {
  151. goto DestroyDlg;
  152. }
  153. (**hpdocdod)[docCur].hgtbd = hgtbd;
  154. }
  155. blt(rgtbd, &(**hgtbd)[0], itbdMax * cwTBD);
  156. /* Changing the tabs makes everything dirty. */
  157. (**hpdocdod)[docCur].fDirty = TRUE;
  158. vdocParaCache = docNil;
  159. TrashAllWws();
  160. case idiCancel:
  161. DestroyDlg:
  162. /* Destroy the tabs dialog box and enable any existing modeless
  163. dialog boxes.*/
  164. OurEndDialog(hDlg, NULL);
  165. break;
  166. case idiTabClearAll:
  167. /* Clear all of the tabs. */
  168. for (idi = idiTabPos0; idi <= idiTabPos11; idi++)
  169. {
  170. SetDlgItemText(hDlg, idi, (LPSTR)"");
  171. CheckDlgButton(hDlg, idi + (idiTabDec0 - idiTabPos0), FALSE);
  172. }
  173. break;
  174. case idiTabDec0:
  175. case idiTabDec1:
  176. case idiTabDec2:
  177. case idiTabDec3:
  178. case idiTabDec4:
  179. case idiTabDec5:
  180. case idiTabDec6:
  181. case idiTabDec7:
  182. case idiTabDec8:
  183. case idiTabDec9:
  184. case idiTabDec10:
  185. case idiTabDec11:
  186. CheckDlgButton(hDlg, wParam, !IsDlgButtonChecked(hDlg, wParam));
  187. break;
  188. default:
  189. return(FALSE);
  190. }
  191. break;
  192. case WM_CLOSE:
  193. goto DestroyDlg;
  194. default:
  195. return(FALSE);
  196. }
  197. return(TRUE);
  198. }
  199. /* end of DialogTabs */
  200. BOOL far PASCAL DialogDivision(hDlg, message, wParam, lParam)
  201. HWND hDlg;
  202. unsigned message;
  203. WORD wParam;
  204. LONG lParam;
  205. {
  206. /* This routine handles input to the Division dialog box. */
  207. extern struct DOD (**hpdocdod)[];
  208. extern int docCur;
  209. extern struct SEP vsepNormal;
  210. extern int vdocSectCache;
  211. extern BOOL vfPrinterValid;
  212. extern int dxaPrOffset;
  213. extern int dyaPrOffset;
  214. extern int dxaPrPage;
  215. extern int dyaPrPage;
  216. extern HWND vhWndMsgBoxParent;
  217. extern typeCP cpMinDocument;
  218. extern int ferror;
  219. struct SEP **hsep = (**hpdocdod)[docCur].hsep;
  220. register struct SEP *psep;
  221. CHAR szT[cchMaxNum];
  222. CHAR *pch = &szT[0];
  223. #ifdef KINTL /* Kanji/International version */
  224. static int iRBDown;
  225. static int utInit;
  226. #endif
  227. switch (message)
  228. {
  229. case WM_INITDIALOG:
  230. #ifdef KINTL /* Kanji/International version */
  231. /* base initial setting on value in utCur */
  232. utInit = utCur; /* for testing at ok */
  233. if (utCur == utCm)
  234. iRBDown = idiDivCm;
  235. else
  236. iRBDown = idiDivInch;
  237. CheckDlgButton(hDlg, iRBDown, TRUE);
  238. #endif
  239. EnableOtherModeless(FALSE);
  240. /* Get a pointer to the section properties. */
  241. psep = (hsep == NULL) ? &vsepNormal : *hsep;
  242. /* Initialize the starting page number. */
  243. if (psep->pgnStart != pgnNil)
  244. {
  245. szT[ncvtu(psep->pgnStart, &pch)] = '\0';
  246. SetDlgItemText(hDlg, idiDivPNStart, (LPSTR)szT);
  247. pch = &szT[0];
  248. }
  249. else
  250. {
  251. SetDlgItemText(hDlg, idiDivPNStart, (LPSTR)"1");
  252. }
  253. SelectIdiText(hDlg, idiDivPNStart);
  254. /* Initialize the margins. */
  255. #ifdef DMARGINS
  256. CommSzNum("Left Twips: ", psep->xaLeft);
  257. CommSzNum("Right Twips: ", psep->xaMac - psep->dxaText - psep->xaLeft);
  258. CommSzNum("Top Twips: ", psep->yaTop);
  259. CommSzNum("Bottom Twips: ", psep->yaMac - psep->dyaText - psep->yaTop);
  260. #endif /* DEBUG */
  261. #ifdef KOREA
  262. if (vfPrinterValid)
  263. CchExpZa(&pch, imax(psep->xaLeft, dxaPrOffset), utCur,cchMaxNum);
  264. else
  265. CchExpZa(&pch, psep->xaLeft, utCur, cchMaxNum);
  266. #else
  267. CchExpZa(&pch, psep->xaLeft, utCur, cchMaxNum);
  268. #endif
  269. SetDlgItemText(hDlg, idiDivLMarg, (LPSTR)szT);
  270. pch = &szT[0];
  271. #ifdef KOREA /* 90.12.29 sangl */
  272. if ( vfPrinterValid )
  273. CchExpZa (&pch, imax(psep->xaMac - psep->dxaText - psep->xaLeft,
  274. vsepNormal.xaMac - dxaPrOffset - dxaPrPage), utCur, cchMaxNum);
  275. else
  276. CchExpZa(&pch, psep->xaMac - psep->dxaText - psep->xaLeft, utCur,
  277. cchMaxNum);
  278. #else
  279. CchExpZa(&pch, psep->xaMac - psep->dxaText - psep->xaLeft, utCur,
  280. cchMaxNum);
  281. #endif
  282. SetDlgItemText(hDlg, idiDivRMarg, (LPSTR)szT);
  283. pch = &szT[0];
  284. #ifdef KOREA /* 90.12.29 sangl */
  285. if (vfPrinterValid)
  286. CchExpZa(&pch, imax( psep->yaTop, dyaPrOffset), utCur, cchMaxNum);
  287. else
  288. CchExpZa(&pch, psep->yaTop, utCur, cchMaxNum);
  289. #else
  290. CchExpZa(&pch, psep->yaTop, utCur, cchMaxNum);
  291. #endif
  292. SetDlgItemText(hDlg, idiDivTMarg, (LPSTR)szT);
  293. pch = &szT[0];
  294. #ifdef KOREA /* 90.12.29 sangl */
  295. if (vfPrinterValid)
  296. CchExpZa(&pch, imax(psep->yaMac - psep->dyaText - psep->yaTop,
  297. vsepNormal.yaMac - dyaPrOffset - dyaPrPage), utCur, cchMaxNum);
  298. else
  299. CchExpZa(&pch, psep->yaMac - psep->dyaText - psep->yaTop, utCur,
  300. cchMaxNum);
  301. #else
  302. CchExpZa(&pch, psep->yaMac - psep->dyaText - psep->yaTop, utCur,
  303. cchMaxNum);
  304. #endif
  305. SetDlgItemText(hDlg, idiDivBMarg, (LPSTR)szT);
  306. break;
  307. case WM_SETVISIBLE:
  308. if (wParam)
  309. EndLongOp(vhcArrow);
  310. return(FALSE);
  311. case WM_ACTIVATE:
  312. if (wParam)
  313. {
  314. vhWndMsgBoxParent = hDlg;
  315. }
  316. if (vfCursorVisible)
  317. ShowCursor(wParam);
  318. return(FALSE); /* so that we leave the activate message to
  319. the dialog manager to take care of setting the focus correctly */
  320. case WM_COMMAND:
  321. switch (wParam)
  322. {
  323. int pgn;
  324. int iza;
  325. int za[4];
  326. int zaMin[4];
  327. int dza;
  328. int *pza;
  329. int dxaMax;
  330. int dyaMax;
  331. case idiOk:
  332. /* Is the page number valid? */
  333. if (!WPwFromItW3Id(&pgn, hDlg, idiDivPNStart, pgnMin, pgnMax,
  334. wNormal, IDPMTNPI))
  335. {
  336. ferror = FALSE; /* minor error, stay in dialog */
  337. break;
  338. }
  339. /* Determine the minimum margins of the page. */
  340. if (vfPrinterValid)
  341. {
  342. zaMin[0] = dxaPrOffset;
  343. zaMin[1] = imax(0, vsepNormal.xaMac - dxaPrOffset - dxaPrPage);
  344. zaMin[2] = dyaPrOffset;
  345. zaMin[3] = imax(0, vsepNormal.yaMac - dyaPrOffset - dyaPrPage);
  346. }
  347. else
  348. {
  349. zaMin[0] = zaMin[1] = zaMin[2] = zaMin[3] = 0;
  350. }
  351. /* Are the margins valid? */
  352. for (iza = 0; iza < 4; iza++)
  353. {
  354. /* Is the margin a positive measurement? */
  355. if (!FPdxaPosIt(&za[iza], hDlg, iza + idiDivLMarg
  356. ))
  357. {
  358. ferror = FALSE; /* minor error, stay in dialog */
  359. return (TRUE);
  360. }
  361. /* Is it less than the minimum? */
  362. if (FUserZaLessThanZa(za[iza], zaMin[iza]))
  363. {
  364. ErrorBadMargins(hDlg, zaMin[0], zaMin[1], zaMin[2],
  365. zaMin[3]);
  366. SelectIdiText(hDlg, iza + idiDivLMarg);
  367. SetFocus(GetDlgItem(hDlg, iza + idiDivLMarg));
  368. return (TRUE);
  369. }
  370. }
  371. #ifdef DMARGINS
  372. CommSzNum("New Left Twips: ", za[0]);
  373. CommSzNum("New Right Twips: ", za[1]);
  374. CommSzNum("New Top Twips: ", za[2]);
  375. CommSzNum("New Bottom Twips: ", za[3]);
  376. #endif /* DEBUG */
  377. /* Ensure that this document has a valid section property
  378. descriptor. */
  379. if (hsep == NULL)
  380. {
  381. if (FNoHeap(hsep = (struct SEP **)HAllocate(cwSEP)))
  382. {
  383. goto DestroyDlg;
  384. }
  385. blt(&vsepNormal, *hsep, cwSEP);
  386. (**hpdocdod)[docCur].hsep = hsep;
  387. }
  388. psep = *hsep;
  389. /* Are the combined margins longer or wider than the page? */
  390. pza = &za[0];
  391. dxaMax = psep->xaMac - dxaMinUseful;
  392. dyaMax = psep->yaMac - dyaMinUseful;
  393. if ((dza = *pza) > dxaMax || (dza += *(++pza)) > dxaMax ||
  394. (dza = *(++pza)) > dyaMax || (dza += *(++pza)) > dyaMax)
  395. {
  396. Error(IDPMTMTL);
  397. ferror = FALSE; /* minor error, stay in dialog */
  398. SelectIdiText(hDlg, (int)(idiDivLMarg + (pza - &za[0])));
  399. SetFocus(GetDlgItem(hDlg, (int)(idiDivLMarg + (pza - &za[0]))));
  400. return (FALSE);
  401. }
  402. /* If the margins have changed, then set the new values. */
  403. if (psep->pgnStart != pgn || psep->xaLeft != za[0] || psep->dxaText
  404. != psep->xaMac - za[0] - za[1] || psep->yaTop != za[2] ||
  405. psep->dyaText != psep->yaMac - za[2] - za[3])
  406. {
  407. /* Set up the undo stuff. */
  408. SetUndo(uacFormatSection, docCur, cp0, cp0, docNil, cpNil,
  409. cpNil, 0);
  410. /* Reset psep in case some heap movement has taken place. */
  411. psep = *hsep;
  412. if (psep->pgnStart != pgn)
  413. {
  414. /* Renumber the page table. */
  415. extern int docMode;
  416. register struct PGTB **hpgtb = (**hpdocdod)[docCur].hpgtb;
  417. register struct PGD *ppgd;
  418. int ipgd;
  419. int cpgdMac;
  420. /* Initialize page table if it does not already exist. */
  421. if (hpgtb == NULL)
  422. {
  423. if (FNoHeap(hpgtb =
  424. (struct PGTB **)HAllocate(cwPgtbBase + cpgdChunk *
  425. cwPGD)))
  426. {
  427. NoUndo();
  428. return(TRUE);
  429. }
  430. (**hpgtb).cpgdMax = cpgdChunk;
  431. (**hpgtb).cpgd = 1;
  432. (**hpgtb).rgpgd[0].cpMin = cpMinDocument;
  433. /* Reset psep because of heap movement. */
  434. psep = *hsep;
  435. }
  436. /* Save the starting page number in the section properties.
  437. */
  438. psep->pgnStart = pgn;
  439. /* Update the page table with the new starting page number.
  440. */
  441. for (ipgd = 0, cpgdMac = (**hpgtb).cpgd, ppgd =
  442. &((**hpgtb).rgpgd[0]) ; ipgd < cpgdMac; ipgd++, ppgd++)
  443. {
  444. ppgd->pgn = pgn++;
  445. }
  446. /* Force the page info window to be repainted. */
  447. docMode = docNil;
  448. }
  449. /* Set the new section properties. */
  450. psep->dxaText = psep->xaMac - (psep->xaLeft = za[0]) - za[1];
  451. psep->dyaText = psep->yaMac - (psep->yaTop = za[2]) - za[3];
  452. /* Invalidate the section cache. */
  453. vdocSectCache = docNil;
  454. TrashAllWws();
  455. /* Mark the document as dirty. */
  456. (**hpdocdod)[docCur].fDirty = TRUE;
  457. }
  458. #ifdef KINTL /* Kanji/International version */
  459. /* redraw ruler if visible and units changed */
  460. if (utInit != utCur) {
  461. ReframeRuler();
  462. }
  463. #endif
  464. goto DestroyDlg;
  465. case idiCancel:
  466. #ifdef KINTL /* International version */
  467. utCur = utInit; /* restore units at actual cancel */
  468. #endif /* KINTL */
  469. DestroyDlg:
  470. OurEndDialog(hDlg, TRUE);
  471. break;
  472. #ifdef KINTL /* International version */
  473. {
  474. int margin;
  475. /* Maximum number of characters in the edit control */
  476. #define cchMaxEditText 64
  477. case idiDivInch:
  478. utCur = utInch;
  479. goto SetUnits;
  480. case idiDivCm:
  481. utCur = utCm;
  482. /* measurment button fall into this code */
  483. SetUnits:
  484. /* set up buttons appropriately */
  485. #ifdef INTL
  486. CheckRadioButton(hDlg, idiDivInch, idiDivCm, wParam);
  487. #else /* KANJI */
  488. CheckRadioButton(hDlg, idiDivInch, idiDivCch, wParam);
  489. #endif
  490. if (wParam != iRBDown) {
  491. /* reevaluate margin values based on new units */
  492. iRBDown = wParam;
  493. /* want most recently entered value from screen into
  494. twips, then convert using current unit scale */
  495. szT[0] = GetDlgItemText(hDlg, idiDivLMarg,
  496. (LPSTR) &szT[1], cchMaxNum);
  497. if (FZaFromSs (&margin, szT+1, *szT, utCur))
  498. {
  499. pch = &szT[0];
  500. CchExpZa(&pch, margin, utCur, cchMaxNum);
  501. SetDlgItemText(hDlg, idiDivLMarg, (LPSTR)szT);
  502. }
  503. szT[0] = GetDlgItemText(hDlg, idiDivRMarg,
  504. (LPSTR) &szT[1], cchMaxNum);
  505. if (FZaFromSs (&margin, szT+1, *szT, utCur))
  506. {
  507. pch = &szT[0];
  508. CchExpZa(&pch, margin, utCur, cchMaxNum);
  509. SetDlgItemText(hDlg, idiDivRMarg, (LPSTR)szT);
  510. }
  511. szT[0] = GetDlgItemText(hDlg, idiDivTMarg,
  512. (LPSTR) &szT[1], cchMaxNum);
  513. if (FZaFromSs (&margin, szT+1, *szT, utCur))
  514. {
  515. pch = &szT[0];
  516. CchExpZa(&pch, margin, utCur, cchMaxNum);
  517. SetDlgItemText(hDlg, idiDivTMarg, (LPSTR)szT);
  518. }
  519. szT[0] = GetDlgItemText(hDlg, idiDivBMarg,
  520. (LPSTR) &szT[1], cchMaxNum);
  521. if (FZaFromSs (&margin, szT+1, *szT, utCur))
  522. {
  523. pch = &szT[0];
  524. CchExpZa(&pch, margin, utCur, cchMaxNum);
  525. SetDlgItemText(hDlg, idiDivBMarg, (LPSTR)szT);
  526. }
  527. }
  528. break;
  529. }
  530. #endif /* KINTL */
  531. default:
  532. return (FALSE);
  533. }
  534. break;
  535. default:
  536. return (FALSE);
  537. }
  538. return (TRUE);
  539. } /* end of DialogDivision */
  540.