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.

458 lines
11 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* DiaPara.c -- Paragraph Format dialog box specific routines */
  5. #define NOGDICAPMASKS
  6. #define NOVIRTUALKEYCODES
  7. #define NOWINSTYLES
  8. #define NOCLIPBOARD
  9. #define NOSYSMETRICS
  10. #define NOMENUS
  11. #define NOCOMM
  12. #define NOSOUND
  13. #define NOSCROLL
  14. #define NOCOLOR
  15. #define NOBITMAP
  16. #define NOFONT
  17. #define NODRAWTEXT
  18. #define NOMSG
  19. #define NOWNDCLASS
  20. #define NOKEYSTATE
  21. #define NORASTEROPS
  22. #define NOGDI
  23. #define NOBRUSH
  24. #define NOPEN
  25. #include <windows.h>
  26. #include "mw.h"
  27. #include "cmddefs.h"
  28. #include "docdefs.h"
  29. #include "prmdefs.h"
  30. #include "propdefs.h"
  31. #include "editdefs.h"
  32. #include "dlgdefs.h"
  33. #include "dispdefs.h"
  34. #include "str.h"
  35. #include "wwdefs.h"
  36. extern struct WWD *pwwdCur;
  37. extern HANDLE hParentWw;
  38. extern struct PAP vpapAbs;
  39. extern struct PAP *vppapNormal;
  40. extern int rgval[];
  41. extern typeCP cpMacCur;
  42. extern int utCur;
  43. extern struct SEL selCur; /* Current selection (i.e., sel in current ww */
  44. extern int docCur; /* Document in current ww */
  45. extern CHAR stBuf[];
  46. extern HWND vhWndMsgBoxParent;
  47. extern int vfCursorVisible;
  48. extern HCURSOR vhcArrow;
  49. #ifdef RULERALSO /* enable out because no need to bring ruler up when tab or indents is invoked */
  50. extern int docRulerSprm;
  51. extern struct TBD rgtbdRuler[];
  52. extern HWND vhDlgIndent;
  53. extern BOOL vfDisableMenus;
  54. extern int vfTabsChanged;
  55. extern int vfTempRuler;
  56. extern struct WWD rgwwd[];
  57. #endif
  58. #ifdef CASHMERE
  59. /* D O F O R M A T P A R A */
  60. DoFormatPara(rgval)
  61. VAL rgval[];
  62. /* add para sprms */
  63. int val, ival;
  64. int *pval;
  65. int sprm;
  66. struct PAP *ppap;
  67. typeCP dcp;
  68. typeCP cpFirst, cpLim;
  69. struct SEL selSave;
  70. /* this temp array is used to assemble sprm values */
  71. CHAR rgb[cchTBD * itbdMax + 2/* >> cwPAPBase */];
  72. int rgw[cwPAPBase];
  73. ppap = (struct PAP *)&rgw[0];
  74. if (!FWriteCk(fwcNil))
  75. return; /* Check for munging end mark in footnote window */
  76. if (docRulerSprm != docNil) ClearRulerSprm();
  77. ExpandCurSel(&selSave);
  78. dcp = (cpLim = selCur.cpLim) - (cpFirst = selCur.cpFirst);
  79. if (cpLim > cpMacCur)
  80. {
  81. SetUndo(uacReplNS, docCur, cpFirst, dcp,
  82. docNil, cpNil, dcp - ccpEol, 0);
  83. InsertEolInsert(docCur, cpMacCur);
  84. }
  85. else
  86. SetUndo(uacReplNS, docCur, cpFirst, dcp,
  87. docNil, cpNil, dcp, 0);
  88. /* reset adjusted selCur */
  89. selCur.cpFirst = cpFirst;
  90. selCur.cpLim = cpLim;
  91. /* any gray fields ? */
  92. for (ival = 0; ival <= 8; ival++)
  93. if (rgval[ival] == valNil)
  94. {
  95. /* yes. generate sprms for any that are not gray */
  96. for (ival = 0; ival <= 8; ival++)
  97. if ((val = rgval[ival]) != valNil)
  98. {
  99. switch(ival)
  100. {
  101. case 0:
  102. sprm = sprmPJc;
  103. goto LPara1;
  104. case 1:
  105. val = !val;
  106. sprm = sprmPKeep;
  107. goto LPara1;
  108. case 2:
  109. sprm = sprmPLMarg;
  110. break;
  111. case 3:
  112. sprm = sprmPFIndent;
  113. break;
  114. case 4:
  115. sprm = sprmPRMarg;
  116. break;
  117. case 5:
  118. sprm = sprmPDyaLine;
  119. break;
  120. case 6:
  121. sprm = sprmPDyaBefore;
  122. break;
  123. case 7:
  124. sprm = sprmPDyaAfter;
  125. break;
  126. case 8:
  127. val = !val;
  128. sprm = sprmPKeepFollow;
  129. goto LPara1;
  130. }
  131. /* we come here with one word value */
  132. bltbyte(&val, &rgb[1], cchINT);
  133. goto LPara2;
  134. /* we come here with one char value */
  135. LPara1: rgb[1] = val;
  136. LPara2: rgb[0] = sprm;
  137. AddSprm(rgb);
  138. }
  139. goto ParaCommon;
  140. }
  141. /* otherwise generate a sprm that applies all properties except the tabs */
  142. blt(vppapNormal, ppap, cwPAPBase);
  143. pval = &rgval[0];
  144. ppap->jc = *pval++;
  145. ppap->fKeep = !*pval++;
  146. ppap->dxaLeft = *pval++;
  147. ppap->dxaLeft1 = *pval++;
  148. ppap->dxaRight = *pval++;
  149. ppap->dyaLine = *pval++;
  150. ppap->dyaBefore = *pval++;
  151. ppap->dyaAfter = *pval++;
  152. ppap->fKeepFollow = !*pval++;
  153. bltbyte(ppap, &rgb[2], cwPAPBase * cchINT);
  154. rgb[1] = cwPAPBase * cchINT;
  155. /* we have: sprm, rgb[1 - n] set up */
  156. rgb[0] = sprmPSame;
  157. CachePara(docCur, selCur.cpFirst);
  158. if (CchDiffer(&vpapAbs, ppap, cwPAPBase * cchINT))
  159. AddSprm(rgb);
  160. ParaCommon: ;
  161. if (vfTabsChanged)
  162. {
  163. int itbd;
  164. int cchRgtbd;
  165. /* some tab changes were also made in the ruler */
  166. for (itbd = 0; rgtbdRuler[itbd].dxa != 0; itbd++);
  167. bltbyte((CHAR *)rgtbdRuler, &rgb[2], cchRgtbd = cwTBD * cchINT * itbd);
  168. rgb[1] = cchRgtbd;
  169. rgb[0] = sprmPRgtbd;
  170. AddSprm(rgb);
  171. }
  172. EndLookSel(&selSave, fTrue);
  173. SetRgvalAgain(rgval, uacFormatPara);
  174. }
  175. #else /* MEMO, not CASHMERE */
  176. /* D O F O R M A T P A R A */
  177. DoFormatPara(rgval)
  178. VAL rgval[];
  179. {
  180. /* add para sprms */
  181. int val, ival;
  182. int *pval;
  183. int sprm;
  184. struct PAP *ppap;
  185. typeCP dcp;
  186. typeCP cpFirst, cpLim;
  187. struct SEL selSave;
  188. /* this temp array is used to assemble sprm values */
  189. CHAR rgb[cchTBD * itbdMax + 2/* >> cwPAPBase */];
  190. int rgw[cwPAPBase];
  191. ppap = (struct PAP *)&rgw[0];
  192. if (!FWriteOk( fwcNil ))
  193. return;
  194. #ifdef ENABLE /* no ClearRulerSprm yet */
  195. if (docRulerSprm != docNil) ClearRulerSprm();
  196. #endif
  197. ExpandCurSel(&selSave);
  198. dcp = (cpLim = selCur.cpLim) - (cpFirst = selCur.cpFirst);
  199. if (cpLim > cpMacCur)
  200. {
  201. SetUndo(uacReplNS, docCur, cpFirst, dcp,
  202. docNil, cpNil, dcp - ccpEol, 0);
  203. InsertEolInsert(docCur, cpMacCur);
  204. }
  205. else
  206. SetUndo(uacReplNS, docCur, cpFirst, dcp,
  207. docNil, cpNil, dcp, 0);
  208. /* reset adjusted selCur */
  209. selCur.cpFirst = cpFirst;
  210. selCur.cpLim = cpLim;
  211. for (ival = 0; ival <= 2; ival++)
  212. if ((val = rgval[ival]) != valNil)
  213. {
  214. switch(ival)
  215. {
  216. case 0:
  217. sprm = sprmPLMarg;
  218. break;
  219. case 1:
  220. sprm = sprmPFIndent;
  221. break;
  222. case 2:
  223. sprm = sprmPRMarg;
  224. break;
  225. }
  226. /* we come here with one word value */
  227. bltbyte(&val, &rgb[1], cchINT);
  228. rgb[0] = sprm;
  229. AddSprm(rgb);
  230. }
  231. #ifdef RULERALSO /* tabs in format para dialog box */
  232. if (vfTabsChanged)
  233. {
  234. int itbd;
  235. int cchRgtbd;
  236. /* some tab changes were also made in the ruler */
  237. for (itbd = 0; rgtbdRuler[itbd].dxa != 0; itbd++);
  238. bltbyte((CHAR *)rgtbdRuler, &rgb[2], cchRgtbd = cwTBD * cchINT * itbd);
  239. rgb[1] = cchRgtbd;
  240. rgb[0] = sprmPRgtbd;
  241. AddSprm(rgb);
  242. }
  243. #endif
  244. EndLookSel(&selSave, fTrue);
  245. #ifdef ENABLE
  246. SetRgvalAgain(rgval, uacFormatPara);
  247. #endif
  248. } /* end of DoFormatPara */
  249. #endif /* MEMO, not CASHMERE */
  250. /* P U T P A R A N U M */
  251. /* convert n according to unit ut, and leave result in stBuf */
  252. PutParaNum(n, ut)
  253. int n, ut;
  254. {
  255. CHAR *pch = &stBuf[1];
  256. stBuf[0] = CchExpZa(&pch, n, ut, cchMaxNum);
  257. }
  258. BOOL far PASCAL DialogParaFormats( hDlg, message, wParam, lParam )
  259. HWND hDlg; /* Handle to the dialog box */
  260. unsigned message;
  261. WORD wParam;
  262. LONG lParam;
  263. {
  264. /* This routine handles input to the Paragraph Formats dialog box. */
  265. extern struct SEP vsepNormal;
  266. extern int ferror;
  267. unsigned dxaText;
  268. int wLowLim;
  269. int i;
  270. TSV rgtsv[itsvchMax]; /* gets attributes and gray flags from CHP */
  271. switch (message)
  272. {
  273. case WM_INITDIALOG:
  274. #ifdef RULERALSO /* enable out because no need to bring ruler up */
  275. InitSpecialDialog(&vhDlgIndent, hDlg);
  276. #else
  277. EnableOtherModeless(FALSE);
  278. #endif
  279. GetRgtsvPapSel(rgtsv); /* get paragraph properties */
  280. /* note the following loop assumes that the
  281. itsv Indent codes are in the same order as
  282. the idiPar Indent codes */
  283. for (i = 0; i < 3; i++)
  284. if (rgtsv[itsvLIndent + i].fGray == 0)
  285. {
  286. PutParaNum(rgtsv[itsvLIndent + i].wTsv, utCur);
  287. SetDlgItemText(hDlg, (idiParLfIndent + i),
  288. (LPSTR)&stBuf[1]);
  289. }
  290. SelectIdiText(hDlg, idiParLfIndent);
  291. break;
  292. case WM_SETVISIBLE:
  293. if (wParam)
  294. EndLongOp(vhcArrow);
  295. return(FALSE);
  296. case WM_ACTIVATE:
  297. if (wParam)
  298. vhWndMsgBoxParent = hDlg;
  299. if (vfCursorVisible)
  300. ShowCursor(wParam);
  301. return(FALSE); /* so that we leave the activate message to
  302. the dialog manager to take care of setting the focus right */
  303. case WM_COMMAND:
  304. switch (wParam)
  305. {
  306. case idiOk:
  307. /* Get xaLeft, First line, and xaRight */
  308. if (!WPdxaFromItDxa2WId(&rgval[0], hDlg, idiParLfIndent, 0, dxaText = vsepNormal.dxaText,
  309. wBlank | wSpaces, IDPMTNOTDXA))
  310. {
  311. ferror = FALSE; /* minor error, stay in dialog */
  312. break;
  313. }
  314. if (rgval[0] == valNil)
  315. wLowLim = 0;
  316. else
  317. wLowLim = (int) -rgval[0];
  318. if (!WPdxaFromItDxa2WId(&rgval[1], hDlg, idiParFirst, wLowLim, dxaText,
  319. wBlank | wSpaces, IDPMTNOTDXA) ||
  320. !WPdxaFromItDxa2WId(&rgval[2], hDlg, idiParRtIndent, 0, dxaText,
  321. wBlank | wSpaces, IDPMTNOTDXA))
  322. {
  323. ferror = FALSE; /* minor error, stay in dialog */
  324. break;
  325. }
  326. /* we have in rgval:
  327. 0 xaLeft
  328. 1 xaLeft1
  329. 2 xaRight */
  330. DoFormatPara(rgval);
  331. /* FALL THROUGH */
  332. case idiCancel:
  333. #ifdef RULERALSO /* enable out because no need to bring up ruler */
  334. CancelSpecialDialog(&vhDlgIndent);
  335. #else
  336. OurEndDialog(hDlg, TRUE);
  337. #endif
  338. break;
  339. default:
  340. return(FALSE);
  341. }
  342. break;
  343. case WM_CLOSE:
  344. #ifdef RULERALSO /* enable out because no need to bring up ruler */
  345. CancelSpecialDialog(&vhDlgIndent);
  346. #else
  347. OurEndDialog(hDlg, TRUE);
  348. #endif
  349. break;
  350. default:
  351. return(FALSE);
  352. }
  353. return(TRUE);
  354. }
  355. /* end of DialogParaFormats */
  356. #ifdef RULERALSO/* no need to bring up ruler when tab or indent dialog box was invoked */
  357. InitSpecialDialog(phDlg, hDlg)
  358. HANDLE *phDlg;
  359. HANDLE hDlg;
  360. {
  361. /* Special dialog box is a modal dialog box that needs to invoke a ruler if
  362. not already there. Since the ruler is a child window, the parent has to
  363. be enabled and other children except the ruler and/or modeless dialog
  364. boxes has to be disabled. Top level menu and the system menu have to
  365. be locked.
  366. phDlg : address of the global handle to store the special
  367. dialog created (ptr to either vhDlgIndent or vhDlgTab)
  368. Ruler relies on these global handle to see if need to
  369. update any dialog's items when tabs or indents are moved.
  370. hDlg : handle to the special dialog box created.
  371. */
  372. *phDlg = hDlg;
  373. EnableOtherModeless(FALSE); /* disable other modeless dialogs */
  374. EnableWindow(hParentWw, TRUE);
  375. EnableWindow(wwdCurrentDoc.wwptr, FALSE);
  376. if (!pwwdCur->fRuler)
  377. {
  378. vfTempRuler = TRUE;
  379. pwwdCur->fRuler = TRUE;
  380. CreateRuler();
  381. }
  382. else
  383. UpdateRuler();
  384. vfTabsChanged = FALSE;
  385. vfDisableMenus = TRUE;
  386. } /* InitSpecialDialog */
  387. CancelSpecialDialog(phDlg)
  388. HANDLE * phDlg;
  389. {
  390. /* Destroy the special dialog box involves destroying the ruler if it is
  391. invoked by the creation of the dialog box, then enable the children
  392. and/or any modeless dialogs that were disabled in InitSpecialDialog.
  393. System menu and the top level menu has to be unlocked.
  394. The last thing is to reset the global dialog handle (vhDlgTab or
  395. vhDlgIndent). Ruler relies on these global handle to see if need to
  396. update any dialog's items when tabs or indents are moved.
  397. phDlg : address of the global handle that stores the special
  398. dialog created (ptr to either vhDlgIndent or vhDlgTab)
  399. */
  400. HANDLE hDlg = *phDlg;
  401. if (vfTempRuler)
  402. {
  403. DestroyRuler();
  404. vfTempRuler = FALSE;
  405. pwwdCur->fRuler = FALSE;
  406. }
  407. else
  408. UpdateRuler();
  409. EndDialog(hDlg, TRUE);
  410. EnableWindow(wwdCurrentDoc.wwptr, TRUE);
  411. EnableOtherModeless(TRUE); /* enable other modeless dialogs */
  412. *phDlg = (HANDLE)NULL;
  413. vfDisableMenus = FALSE;
  414. } /* CancelSpecialDialog */
  415. #endif /* RULERALSO -- no need to bring up ruler when tab or indent dialog box is invoked */
  416.