summaryrefslogblamecommitdiffstats
path: root/private/mvdm/wow16/write/diapara.c
blob: 368055fa194483fcc606be3f75f4d7cd2aadd5d2 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458









































































































































































































































































































































































































































































                                                                                                                         
/************************************************************/
/* Windows Write, Copyright 1985-1992 Microsoft Corporation */
/************************************************************/

/* DiaPara.c -- Paragraph Format dialog box specific routines */
#define NOGDICAPMASKS
#define NOVIRTUALKEYCODES
#define NOWINSTYLES
#define NOCLIPBOARD
#define NOSYSMETRICS
#define NOMENUS
#define NOCOMM
#define NOSOUND
#define NOSCROLL
#define NOCOLOR
#define NOBITMAP
#define NOFONT
#define NODRAWTEXT
#define NOMSG
#define NOWNDCLASS
#define NOKEYSTATE
#define NORASTEROPS
#define NOGDI
#define NOBRUSH
#define NOPEN
#include <windows.h>

#include "mw.h"
#include "cmddefs.h"
#include "docdefs.h"
#include "prmdefs.h"
#include "propdefs.h"
#include "editdefs.h"
#include "dlgdefs.h"
#include "dispdefs.h"
#include "str.h"
#include "wwdefs.h"

extern struct WWD *pwwdCur;
extern HANDLE hParentWw;
extern struct PAP vpapAbs;
extern struct PAP *vppapNormal;
extern int rgval[];
extern typeCP cpMacCur;
extern int utCur;
extern struct SEL selCur; /* Current selection (i.e., sel in current ww */
extern int docCur; /* Document in current ww */
extern CHAR stBuf[];
extern HWND vhWndMsgBoxParent;
extern int vfCursorVisible;
extern HCURSOR vhcArrow;

#ifdef RULERALSO /* enable out because no need to bring ruler up when tab or indents is invoked */
extern int docRulerSprm;
extern struct TBD rgtbdRuler[];
extern HWND vhDlgIndent;
extern BOOL vfDisableMenus;
extern int vfTabsChanged;
extern int vfTempRuler;
extern struct WWD rgwwd[];
#endif


#ifdef CASHMERE
/* D O	F O R M A T  P A R A */
DoFormatPara(rgval)
VAL rgval[];
	/* add para sprms */

	int val, ival;
	int *pval;
	int sprm;
	struct PAP *ppap;
	typeCP dcp;
	typeCP cpFirst, cpLim;
	struct SEL selSave;
/* this temp array is used to assemble sprm values */
	CHAR rgb[cchTBD * itbdMax + 2/* >> cwPAPBase */];
	int rgw[cwPAPBase];
	ppap = (struct PAP *)&rgw[0];

	if (!FWriteCk(fwcNil))
		return; /* Check for munging end mark in footnote window */

	if (docRulerSprm != docNil) ClearRulerSprm();
	ExpandCurSel(&selSave);

	dcp = (cpLim = selCur.cpLim) - (cpFirst = selCur.cpFirst);
	if (cpLim > cpMacCur)
		{
		SetUndo(uacReplNS, docCur, cpFirst, dcp,
			docNil, cpNil, dcp - ccpEol, 0);
		InsertEolInsert(docCur, cpMacCur);
		}
	else
		SetUndo(uacReplNS, docCur, cpFirst, dcp,
			docNil, cpNil, dcp, 0);
/* reset adjusted selCur */
	selCur.cpFirst = cpFirst;
	selCur.cpLim = cpLim;


/* any gray fields ? */
	for (ival = 0; ival <= 8; ival++)
		if (rgval[ival] == valNil)
			{
/* yes. generate sprms for any that are not gray */
			for (ival = 0; ival <= 8; ival++)
				if ((val = rgval[ival]) != valNil)
					{
					switch(ival)
						{
					case 0:
						sprm = sprmPJc;
						goto LPara1;
					case 1:
						val = !val;
						sprm = sprmPKeep;
						goto LPara1;
					case 2:
						sprm = sprmPLMarg;
						break;
					case 3:
						sprm = sprmPFIndent;
						break;
					case 4:
						sprm = sprmPRMarg;
						break;
					case 5:
						sprm = sprmPDyaLine;
						break;
					case 6:
						sprm = sprmPDyaBefore;
						break;
					case 7:
						sprm = sprmPDyaAfter;
						break;
					case 8:
						val = !val;
						sprm = sprmPKeepFollow;
						goto LPara1;
						}
/* we come here with one word value */
					bltbyte(&val, &rgb[1], cchINT);
					goto LPara2;
/* we come here with one char value */
LPara1: 	    rgb[1] = val;
LPara2: 	    rgb[0] = sprm;
					AddSprm(rgb);
					}
			goto ParaCommon;
			}
/* otherwise generate a sprm that applies all properties except the tabs */
	blt(vppapNormal, ppap, cwPAPBase);
	pval = &rgval[0];
	ppap->jc = *pval++;
	ppap->fKeep = !*pval++;
	ppap->dxaLeft = *pval++;
	ppap->dxaLeft1 = *pval++;
	ppap->dxaRight = *pval++;
	ppap->dyaLine = *pval++;
	ppap->dyaBefore = *pval++;
	ppap->dyaAfter = *pval++;
	ppap->fKeepFollow = !*pval++;
	bltbyte(ppap, &rgb[2], cwPAPBase * cchINT);
	rgb[1] = cwPAPBase * cchINT;
/* we have: sprm, rgb[1 - n] set up */
	rgb[0] = sprmPSame;
	CachePara(docCur, selCur.cpFirst);
	if (CchDiffer(&vpapAbs, ppap, cwPAPBase * cchINT))
		AddSprm(rgb);
ParaCommon: ;
	if (vfTabsChanged)
		{
		int itbd;
		int cchRgtbd;
/* some tab changes were also made in the ruler */
		for (itbd = 0; rgtbdRuler[itbd].dxa != 0; itbd++);
		bltbyte((CHAR *)rgtbdRuler, &rgb[2], cchRgtbd = cwTBD * cchINT * itbd);
		rgb[1] = cchRgtbd;
		rgb[0] = sprmPRgtbd;
		AddSprm(rgb);
		}
	EndLookSel(&selSave, fTrue);
	SetRgvalAgain(rgval, uacFormatPara);
}

#else			      /* MEMO, not CASHMERE */

/* D O	F O R M A T  P A R A */
DoFormatPara(rgval)
VAL rgval[];
{
	/* add para sprms */

	int val, ival;
	int *pval;
	int sprm;
	struct PAP *ppap;
	typeCP dcp;
	typeCP cpFirst, cpLim;
	struct SEL selSave;
/* this temp array is used to assemble sprm values */
	CHAR rgb[cchTBD * itbdMax + 2/* >> cwPAPBase */];
	int rgw[cwPAPBase];
	ppap = (struct PAP *)&rgw[0];

	if (!FWriteOk( fwcNil ))
	    return;

#ifdef ENABLE /* no ClearRulerSprm yet */
	if (docRulerSprm != docNil) ClearRulerSprm();
#endif
	ExpandCurSel(&selSave);

	dcp = (cpLim = selCur.cpLim) - (cpFirst = selCur.cpFirst);
	if (cpLim > cpMacCur)
		{
		SetUndo(uacReplNS, docCur, cpFirst, dcp,
			docNil, cpNil, dcp - ccpEol, 0);
		InsertEolInsert(docCur, cpMacCur);
		}
	else
		SetUndo(uacReplNS, docCur, cpFirst, dcp,
			docNil, cpNil, dcp, 0);
/* reset adjusted selCur */
	selCur.cpFirst = cpFirst;
	selCur.cpLim = cpLim;

	for (ival = 0; ival <= 2; ival++)
		if ((val = rgval[ival]) != valNil)
			{
			switch(ival)
				{
				case 0:
					sprm = sprmPLMarg;
					break;
				case 1:
					sprm = sprmPFIndent;
					break;
				case 2:
					sprm = sprmPRMarg;
					break;
				}
/* we come here with one word value */
			bltbyte(&val, &rgb[1], cchINT);
			rgb[0] = sprm;
			AddSprm(rgb);
			}

#ifdef RULERALSO /* tabs in format para dialog box */
	if (vfTabsChanged)
		{
		int itbd;
		int cchRgtbd;
/* some tab changes were also made in the ruler */
		for (itbd = 0; rgtbdRuler[itbd].dxa != 0; itbd++);
		bltbyte((CHAR *)rgtbdRuler, &rgb[2], cchRgtbd = cwTBD * cchINT * itbd);
		rgb[1] = cchRgtbd;
		rgb[0] = sprmPRgtbd;
		AddSprm(rgb);
		}
#endif

	EndLookSel(&selSave, fTrue);
#ifdef ENABLE
	SetRgvalAgain(rgval, uacFormatPara);
#endif
} /* end of DoFormatPara */
#endif /* MEMO, not CASHMERE */


/* P U T  P A R A  N U M */
/* convert n according to unit ut, and leave result in stBuf */
PutParaNum(n, ut)
int n, ut;
	{
	CHAR *pch = &stBuf[1];
	stBuf[0] = CchExpZa(&pch, n, ut, cchMaxNum);
	}


BOOL far PASCAL DialogParaFormats( hDlg, message, wParam, lParam )
HWND	hDlg;			/* Handle to the dialog box */
unsigned message;
WORD wParam;
LONG lParam;
{
    /* This routine handles input to the Paragraph Formats dialog box. */
    extern struct SEP vsepNormal;
    extern int ferror;
    unsigned dxaText;
    int wLowLim;
    int i;
    TSV rgtsv[itsvchMax];  /* gets attributes and gray flags from CHP */

    switch (message)
		{
		case WM_INITDIALOG:
#ifdef RULERALSO /* enable out because no need to bring ruler up */
			InitSpecialDialog(&vhDlgIndent, hDlg);
#else
			EnableOtherModeless(FALSE);
#endif
			GetRgtsvPapSel(rgtsv);	/* get paragraph properties */

			  /* note the following loop assumes that the
			     itsv Indent codes are in the same order as
			     the idiPar Indent codes */

			for (i = 0; i < 3; i++)
			    if (rgtsv[itsvLIndent + i].fGray == 0)
				{
				PutParaNum(rgtsv[itsvLIndent + i].wTsv, utCur);
				SetDlgItemText(hDlg, (idiParLfIndent + i),
				      (LPSTR)&stBuf[1]);
				}

			SelectIdiText(hDlg, idiParLfIndent);
			break;

	       case WM_SETVISIBLE:
		       if (wParam)
			   EndLongOp(vhcArrow);
		       return(FALSE);

	       case WM_ACTIVATE:
			if (wParam)
			    vhWndMsgBoxParent = hDlg;
			if (vfCursorVisible)
			    ShowCursor(wParam);
			return(FALSE); /* so that we leave the activate message to
			the dialog manager to take care of setting the focus right */

		case WM_COMMAND:
			switch (wParam)
			{
			case idiOk:
			/* Get xaLeft, First line, and xaRight */
				if (!WPdxaFromItDxa2WId(&rgval[0], hDlg, idiParLfIndent, 0, dxaText = vsepNormal.dxaText,
					wBlank | wSpaces, IDPMTNOTDXA))
					{
					ferror = FALSE; /* minor error, stay in dialog */
					break;
					}
				if (rgval[0] == valNil)
					wLowLim = 0;
				else
					wLowLim = (int) -rgval[0];
				if (!WPdxaFromItDxa2WId(&rgval[1], hDlg, idiParFirst, wLowLim, dxaText,
					wBlank | wSpaces, IDPMTNOTDXA) ||
				    !WPdxaFromItDxa2WId(&rgval[2], hDlg, idiParRtIndent, 0, dxaText,
					wBlank | wSpaces, IDPMTNOTDXA))
					{
					ferror = FALSE; /* minor error, stay in dialog */
					break;
					}
/* we have in rgval:
	0	xaLeft
	1	xaLeft1
	2	xaRight */
				DoFormatPara(rgval);
				/* FALL THROUGH */
			case idiCancel:
#ifdef RULERALSO /* enable out because no need to bring up ruler */
				CancelSpecialDialog(&vhDlgIndent);
#else
				OurEndDialog(hDlg, TRUE);
#endif
				break;
			default:
				return(FALSE);
			}
			break;

		case WM_CLOSE:
#ifdef RULERALSO /* enable out because no need to bring up ruler */
			CancelSpecialDialog(&vhDlgIndent);
#else
			OurEndDialog(hDlg, TRUE);
#endif
			break;

		default:
			return(FALSE);
		}
    return(TRUE);
}
/* end of DialogParaFormats */


#ifdef RULERALSO/* no need to bring up ruler when tab or indent dialog box was invoked */
InitSpecialDialog(phDlg, hDlg)
HANDLE *phDlg;
HANDLE hDlg;
{
/* Special dialog box is a modal dialog box that needs to invoke a ruler if
   not already there.  Since the ruler is a child window, the parent has to
   be enabled and other children except the ruler and/or modeless dialog
   boxes has to be disabled.  Top level menu and the system menu have to
   be locked.

   phDlg : address of the global handle to store the special
	   dialog created (ptr to either vhDlgIndent or vhDlgTab)
	   Ruler relies on these global handle to see if need to
	   update any dialog's items when tabs or indents are moved.
   hDlg  : handle to the special dialog box created.
*/

	*phDlg = hDlg;
	EnableOtherModeless(FALSE); /* disable other modeless dialogs */
	EnableWindow(hParentWw, TRUE);
	EnableWindow(wwdCurrentDoc.wwptr, FALSE);
	if (!pwwdCur->fRuler)
		{
		vfTempRuler = TRUE;
		pwwdCur->fRuler = TRUE;
		CreateRuler();
		}
	else
		UpdateRuler();
	vfTabsChanged = FALSE;
	vfDisableMenus = TRUE;
} /* InitSpecialDialog */


CancelSpecialDialog(phDlg)
HANDLE * phDlg;
{
/* Destroy the special dialog box involves destroying the ruler if it is
   invoked by the creation of the dialog box, then enable the children
   and/or any modeless dialogs that were disabled in InitSpecialDialog.
   System menu and the top level menu has to be unlocked.
   The last thing is to reset the global dialog handle (vhDlgTab or
   vhDlgIndent).  Ruler relies on these global handle to see if need to
   update any dialog's items when tabs or indents are moved.

   phDlg : address of the global handle that stores the special
	   dialog created (ptr to either vhDlgIndent or vhDlgTab)
*/
HANDLE hDlg = *phDlg;

	if (vfTempRuler)
		{
		DestroyRuler();
		vfTempRuler = FALSE;
		pwwdCur->fRuler = FALSE;
		}
	else
		UpdateRuler();
	EndDialog(hDlg, TRUE);
	EnableWindow(wwdCurrentDoc.wwptr, TRUE);
	EnableOtherModeless(TRUE); /* enable other modeless dialogs */
	*phDlg = (HANDLE)NULL;
	vfDisableMenus = FALSE;

} /* CancelSpecialDialog */
#endif /* RULERALSO -- no need to bring up ruler when tab or indent dialog box is invoked */