1 #   include	"tedConfig.h"
2 
3 #   include	<stddef.h>
4 #   include	<stdlib.h>
5 #   include	<stdio.h>
6 #   include	<ctype.h>
7 
8 #   include	<textOfficeCharset.h>
9 #   include	<appQuestion.h>
10 
11 #   include	"tedApp.h"
12 #   include	"tedSelect.h"
13 #   include	"tedRuler.h"
14 #   include	"tedAppResources.h"
15 #   include	"tedLayout.h"
16 #   include	"tedDocument.h"
17 #   include	"tedDocFront.h"
18 
19 #   include	<docDebug.h>
20 #   include	<docScreenLayout.h>
21 #   include	<docFind.h>
22 #   include	<docField.h>
23 #   include	<docParaParticules.h>
24 #   include	<docRecalculateTocField.h>
25 #   include	<docNodeTree.h>
26 #   include	<docEditCommand.h>
27 
28 #   include	<guiDrawingWidget.h>
29 #   include	<psNup.h>
30 
31 #   include	<appDebugon.h>
32 
33 #   define VALIDATE_TREE	0
34 
35 /************************************************************************/
36 /*									*/
37 /*  Extension of the trace file.					*/
38 /*									*/
39 /************************************************************************/
40 
41 const char TedTraceExtension[]= "Ted";
42 
43 /************************************************************************/
44 /*									*/
45 /*  Scrolling callbacks.						*/
46 /*									*/
47 /************************************************************************/
48 
tedMoveObjectWindows(EditDocument * ed)49 void tedMoveObjectWindows(	EditDocument *		ed )
50     {
51     InsertedObject *		io;
52 
53     DocumentPosition		dpObj;
54     PositionGeometry		pg;
55     int				partObj;
56 
57     LayoutContext		lc;
58 
59     layoutInitContext( &lc );
60     tedSetScreenLayoutContext( &lc, ed );
61 
62     docInitDocumentPosition( &dpObj );
63 
64     if  ( tedGetObjectSelection( ed, &partObj, &dpObj, &io ) )
65 	{ LDEB(1); return;	}
66 
67     tedPositionGeometry( &pg, &dpObj, PARAfindLAST, &lc );
68 
69     tedSetObjectWindows( ed, &pg, io, &lc );
70     }
71 
72 /************************************************************************/
73 /*									*/
74 /*  Make a document readOnly.						*/
75 /*									*/
76 /************************************************************************/
77 
tedMakeDocumentReadonly(EditDocument * ed,int readonly)78 void tedMakeDocumentReadonly(	EditDocument *	ed,
79 				int		readonly )
80     {
81     TedDocument *	td= (TedDocument *)ed->edPrivateData;
82     const int		visible= ! readonly;
83 
84     guiShowMenuOption( td->tdFileSaveOption, visible );
85 
86     guiShowMenuOption( td->tdCutOption, visible );
87     guiShowMenuOption( td->tdPasteOption, visible );
88     guiShowMenuOption( td->tdUndoOption, visible );
89     guiShowMenuOption( td->tdRepeatOption, visible );
90 
91     guiShowMenuOption( td->tdInsPictOption, visible );
92     guiShowMenuOption( td->tdInsSymbolOption, visible );
93     guiShowMenuOption( td->tdInsFileOption, visible );
94     guiShowMenuOption( td->tdInsInsertFootnoteOption, visible );
95     guiShowMenuOption( td->tdInsInsertEndnoteOption, visible );
96     guiShowMenuOption( td->tdInsInsertChftnsepOption, visible );
97     guiShowMenuOption( td->tdInsInsertTableOption, visible );
98     guiShowMenuOption( td->tdInsInsertPageNumberOption, visible );
99 
100     guiShowMenuOption( td->tdTabInsertTableOption, visible );
101     guiShowMenuOption( td->tdTabAddRowOption, visible );
102     guiShowMenuOption( td->tdTabAddColumnOption, visible );
103     guiShowMenuOption( td->tdTabInsertSeparator, visible );
104 
105     guiShowMenuOption( td->tdTabDeleteTableOption, visible );
106     guiShowMenuOption( td->tdTabDeleteRowOption, visible );
107     guiShowMenuOption( td->tdTabDeleteColumnOption, visible );
108     guiShowMenuOption( td->tdTabDeleteSeparator, visible );
109 
110     guiShowMenuOption( td->tdInsInsertLineBreakOption, visible );
111     guiShowMenuOption( td->tdInsInsertPageBreakOption, visible );
112     guiShowMenuOption( td->tdInsInsertColumnBreakOption, visible );
113     guiShowMenuOption( td->tdInsInsertSectBreakOption, visible );
114 
115     guiShowMenuOption( td->tdFontBoldOption, visible );
116     guiShowMenuOption( td->tdFontItalicOption, visible );
117     guiShowMenuOption( td->tdFontUnderlinedOption, visible );
118     guiShowMenuOption( td->tdFontSuperscriptOption, visible );
119     guiShowMenuOption( td->tdFontSubscriptOption, visible );
120     guiShowMenuOption( td->tdFontToggleSeparator, visible );
121     guiShowMenuOption( td->tdFontPasteOption, visible );
122 
123     guiShowMenuOption( td->tdFormatOneParaOption, visible );
124     guiShowMenuOption( td->tdFormatOneParaSeparator, visible );
125 
126     guiShowMenuOption( td->tdFormatPasteRulerOption, visible );
127     guiShowMenuOption( td->tdFormatIncreaseIndentOption, visible );
128     guiShowMenuOption( td->tdFormatDecreaseIndentOption, visible );
129     guiShowMenuOption( td->tdFormatRulerSeparator, visible );
130 
131     guiShowMenuOption( td->tdFormatAlignLeftOption, visible );
132     guiShowMenuOption( td->tdFormatAlignRightOption, visible );
133     guiShowMenuOption( td->tdFormatAlignCenterOption, visible );
134     guiShowMenuOption( td->tdFormatAlignJustifyOption, visible );
135     guiShowMenuOption( td->tdFormatAlignSeparator, visible );
136 
137     guiShowMenuOption( td->tdToolsFontOption, visible );
138     guiShowMenuOption( td->tdToolsSpellingOption, visible );
139     guiShowMenuOption( td->tdToolsPageLayoutOption, visible );
140     guiShowMenuOption( td->tdToolsSymbolOption, visible );
141 
142     /* Oops wrong call */
143     guiShowMenuOption( td->tdInsertMenuButton, visible );
144     }
145 
146 /************************************************************************/
147 /*									*/
148 /*  Last phase in building a document window.				*/
149 /*									*/
150 /*  1)  Set the position by hand, because the regular routine sends an	*/
151 /*	expose to a window that does not exist yet.			*/
152 /*  2)  Forget the name of document templates to force a save-as.	*/
153 /*	Also forget it is a template, to make sure that it is saved as	*/
154 /*	an ordinary document.						*/
155 /*									*/
156 /************************************************************************/
157 
tedFinishDocumentSetup(EditDocument * ed)158 int tedFinishDocumentSetup(	EditDocument *		ed )
159     {
160     EditApplication *		ea= ed->edApplication;
161 
162     TedDocument *		td= (TedDocument *)ed->edPrivateData;
163     BufferDocument *		bd= td->tdDocument;
164     DocumentProperties *	dp= &(bd->bdProperties);
165 
166     const TedAppResources *	tar= (TedAppResources *)ea->eaResourceData;
167 
168     LayoutContext		lc;
169 
170     int				luma;
171     int				chroma;
172     int				hue;
173 
174     layoutInitContext( &lc );
175     tedSetScreenLayoutContext( &lc, ed );
176 
177     {
178     DocumentPosition		dpFirst;
179     const BufferItem *		bodySectNode= (const BufferItem *)0;
180 
181     /*  1  */
182     if  ( ! docGotoFirstPosition( &dpFirst, bd->bdBody.dtRoot ) )
183 	{
184 	const int			lastLine= 0;
185 	BufferItem *			bodyNode= bd->bdBody.dtRoot;
186 
187 	if  ( tar->tarFindPattern					&&
188 	      ! docFindSetPattern( &(td->tdFindProg),
189 			    tar->tarFindPattern, tar->tarFindRegex )	&&
190 	      ! docFindFindNextInDocument( &(td->tdSelection),
191 		    &dpFirst, bd,
192 		    docFindParaFindNext, td->tdFindProg )	)
193 	    { bodySectNode= docGetBodySectNode( dpFirst.dpNode, bd );	}
194 	else{
195 	    docAvoidParaHeadField( &dpFirst, (int *)0, bd );
196 
197 	    docSetIBarSelection( &(td->tdSelection), &dpFirst );
198 	    bodySectNode= bodyNode->biChildren[0];
199 	    }
200 
201 	tedSelectionGeometry( &(td->tdSelectionGeometry),
202 			     &(td->tdSelection), bodySectNode, lastLine,
203 			     &lc );
204 
205 	tedDescribeSelection( ed );
206 	}
207     else{ docListNode( 0, bd->bdBody.dtRoot, 0 );	}
208 
209     /*  2  */
210     if  ( dp->dpIsDocumentTemplate )
211 	{
212 	appSetDocumentFilename( ed, (const MemoryBuffer *)0 );
213 	dp->dpIsDocumentTemplate= 0;
214 	}
215 
216 #   if VALIDATE_TREE
217     LDEB(1);
218     if  ( docCheckNode( bodyNode ) )
219 	{ LDEB(2); docListNode( 0, bodyNode ); abort();	}
220 #   endif
221 
222     }
223 
224     if  ( appFinishDocumentSetup( ed ) )
225 	{ LDEB(1); return -1;	}
226 
227     /*
228     if  ( dw->dwColors.acAllocator.caDepth < 4 )
229     */
230     if  ( 0 )
231 	{
232 	td->tdDrawMonochrome= 1;
233 
234 	utilRGB8SolidBlack( &(td->tdSelColor) );
235 	utilRGB8SolidBlack( &(td->tdCopiedSelColor) );
236 	utilRGB8SolidBlack( &(td->tdTableColor) );
237 	}
238     else{
239 	td->tdDrawMonochrome= 0;
240 
241 	td->tdSelColor.rgb8Red= 176;
242 	td->tdSelColor.rgb8Green= 196;
243 	td->tdSelColor.rgb8Blue= 222;
244 
245 	td->tdCopiedSelColor.rgb8Red= 176;
246 	td->tdCopiedSelColor.rgb8Green= 176;
247 	td->tdCopiedSelColor.rgb8Blue= 176;
248 
249 	td->tdTableColor.rgb8Red= 192;
250 	td->tdTableColor.rgb8Green= 192;
251 	td->tdTableColor.rgb8Blue= 192;
252 	}
253 
254     if  ( utilRGB8LumaChromaHue( &luma, &chroma, &hue,
255 						&(ed->edBackgroundColor) ) )
256 	{ LDEB(1);	}
257     else{
258 	const int	maxLuma= 220;
259 	const int	minLuma= 64;
260 	int		changed= 0;
261 
262 	/*  Must be possible to distinguish background from white */
263 	if  ( luma > maxLuma )
264 	    { luma= maxLuma; changed= 1;	}
265 	if  ( luma < minLuma )
266 	    { luma= minLuma; changed= 1;	}
267 
268 	/*? td->tdTableColor= ed->edBackgroundColor; */
269 
270 	if  ( changed )
271 	    {
272 	    if  ( utilRGB8FromLumaChromaHue( &(ed->edBackgroundColor),
273 							luma, chroma, hue ) )
274 		{ LLLDEB(luma,chroma,hue);	}
275 
276 	    /*? td->tdTableColor= ed->edBackgroundColor; */
277 
278 	    if  ( ed->edTopRuler )
279 		{
280 		tedTopRulerSetBackground( ed->edTopRuler,
281 						&(ed->edBackgroundColor) );
282 		}
283 	    if  ( ed->edLeftRuler )
284 		{
285 		tedVerticalRulerSetBackground( ed->edLeftRuler,
286 						&(ed->edBackgroundColor) );
287 		}
288 	    if  ( ed->edRightRuler )
289 		{
290 		tedVerticalRulerSetBackground( ed->edRightRuler,
291 						&(ed->edBackgroundColor) );
292 		}
293 	    if  ( ed->edBottomRuler )
294 		{
295 		tedBottomRulerSetBackground( ed->edBottomRuler,
296 						&(ed->edBackgroundColor) );
297 		}
298 	    }
299 	}
300 
301     if  ( tedOpenTreeObjects( &(bd->bdBody), &lc ) )
302 	{ LDEB(1);	}
303 
304     td->tdDrawTableGrid= tar->tarShowTableGridInt;
305 
306     appGuiSetToggleItemState( td->tdDrawTableGridOption,
307 						td->tdDrawTableGrid >= 0 );
308 
309     if  ( ! utilMemoryBufferIsEmpty( &(td->tdRecoveredName) ) )
310 	{
311 	const EditTrace *	et= &(td->tdEditTrace);
312 	const int		direction= 1;
313 	int			n= et->etBase;
314 	int			lastEdit= -1;
315 	const TraceStep *	ts;
316 
317 	while( n < et->etCount )
318 	    {
319 	    int		isRepeat= 0;
320 
321 	    n= docEditGetTraceStep( &ts, &isRepeat, direction, et, n+ 1 );
322 	    if  ( n < 0 || n >= et->etCount || isRepeat )
323 		{ break;	}
324 
325 	    if  ( ts->tsCommand < EDITcmd_EDIT_COUNT		&&
326 		  ts->tsCommand != EDITcmdEXTEND_REPLACE	)
327 		{ lastEdit= n;	}
328 	    }
329 
330 	while( et->etIndex < lastEdit )
331 	    {
332 	    if  ( tedDocRepeat( ed ) )
333 		{ LLDEB(et->etIndex,lastEdit); break; }
334 	    }
335 
336 	td->tdTraced= 1;
337 
338 	appSetDocumentFilename( ed, &(td->tdRecoveredName) );
339 	appSetDocumentTitle( ed, &(td->tdRecoveredName) );
340 
341 	tedSetTracedChangedFlag( ed );
342 	guiShowMenuOption( td->tdFileUnlockOption, 0 );
343 	guiShowMenuOption( td->tdFileRecoverOption, 0 );
344 	}
345     else{
346 	if  ( td->tdEditTrace.etTraceStatus == TRACING_EXIST )
347 	    {
348 	    guiShowMenuOption( td->tdFileUnlockOption, 1 );
349 	    guiShowMenuOption( td->tdFileRecoverOption,
350 						td->tdEditTrace.etBase >= 0 );
351 
352 	    if  ( ed->edFormat == TEDdockindTRACE )
353 		{ guiShowMenuOption( td->tdFileSaveAsOption, 0 );	}
354 
355 	    ed->edIsReadonly= 1;
356 	    }
357 	else{
358 	    guiShowMenuOption( td->tdFileUnlockOption, 0 );
359 	    guiShowMenuOption( td->tdFileRecoverOption, 0 );
360 	    }
361 	}
362 
363     if  ( ed->edIsReadonly )
364 	{ tedMakeDocumentReadonly( ed, ed->edIsReadonly );	}
365 
366     if  ( tedHasSelection( ed ) )
367 	{
368 	tedDescribeSelection( ed );
369 	tedAdaptToolsToSelection( ed );
370 	}
371 
372     return 0;
373     }
374 
375 /************************************************************************/
376 /*									*/
377 /*  Scroll to the selection the first time the document becomes visible	*/
378 /*									*/
379 /************************************************************************/
380 
tedDocumentFirstVisible(EditDocument * ed)381 void tedDocumentFirstVisible(	EditDocument *	ed )
382     {
383     TedDocument *		td= (TedDocument *)ed->edPrivateData;
384     DocumentRectangle		dr= ed->edVisibleRect;
385 
386     if  ( td->tdSelectionGeometry.sgRectangle.drX1 > dr.drX1 )
387 	{
388 	int sh= td->tdSelectionGeometry.sgRectangle.drX1- dr.drX1;
389 
390 	dr.drX0 += sh;
391 	dr.drX1 += sh;
392 	}
393     if  ( td->tdSelectionGeometry.sgRectangle.drY1 > dr.drY1 )
394 	{
395 	int sh= td->tdSelectionGeometry.sgRectangle.drY1- dr.drY1;
396 
397 	dr.drY0 += sh;
398 	dr.drY1 += sh;
399 	}
400 
401     appScrollToRectangle( ed, &dr, (int *)0, (int *)0 );
402 
403     return;
404     }
405 
406 /************************************************************************/
407 /*									*/
408 /*  Make the document widget and the rulers.				*/
409 /*									*/
410 /*  1)  Calculate the different width of the margins.			*/
411 /*  2)  Insert a Form in the scrolled window.				*/
412 /*  3)  Insert the top ruler in the form.				*/
413 /*  4)  Insert the bottom ruler in the form.				*/
414 /*  5)  Insert the left ruler in the form.				*/
415 /*  6)  Insert the right ruler in the form.				*/
416 /*  7)  Insert the document widget in the form.				*/
417 /*									*/
418 /************************************************************************/
419 
tedFreeDocument(void * voidtd,int format)420 void tedFreeDocument(		void *			voidtd,
421 				int			format )
422     {
423     TedDocument *	td= (TedDocument *)voidtd;
424 
425     tedCleanCursorBlink( td );
426 
427     if  ( td->tdDocument )
428 	{
429 	docCleanDocumentObjects( td->tdDocument, docScreenCloseObject );
430 	docFreeDocument( td->tdDocument );
431 	}
432 
433     utilCleanMemoryBuffer( &(td->tdRecoveredName) );
434 
435     utilCleanIndexMapping( &(td->tdAttributeToScreenFont) );
436     docCleanEditTrace( &(td->tdEditTrace) );
437 
438     utilCleanMemoryBuffer( &(td->tdCopiedSelection) );
439     utilCleanMemoryBuffer( &(td->tdCopiedFont) );
440     utilCleanMemoryBuffer( &(td->tdCopiedRuler) );
441 
442     bmCleanRasterImage( &(td->tdCopiedImage) );
443 
444     docFindSetPattern( &(td->tdFindProg), (const char *)0, 0 );
445 
446     free( td );
447     }
448 
tedMakeDocumentWidget(EditApplication * ea,EditDocument * ed)449 int tedMakeDocumentWidget(	EditApplication *	ea,
450 				EditDocument *		ed )
451     {
452     if  ( appMakeDocumentWidget( ea, ed ) )
453 	{ LDEB(1); return -1;	}
454 
455     if  ( ! ea->eaDocumentCursor	&&
456 	  tedMakeDocumentCursor( ea )	)
457 	{ LDEB(1);	}
458 
459     return 0;
460     }
461 
462 /************************************************************************/
463 /*									*/
464 /*  Perform the setup of the editing environment for a document.	*/
465 /*									*/
466 /*  8)  Determine the code page of the document.			*/
467 /*  9)  Do not use the 1252 codepage as an explicit setting: It is	*/
468 /*	almost certainly returned by a default 'Ted' installation, and	*/
469 /*	is almost impossible to get rid of.				*/
470 /*									*/
471 /************************************************************************/
472 
tedFirstRecalculateFields(RecalculateFields * rf,DOC_CLOSE_OBJECT closeObject,BufferDocument * bd)473 int tedFirstRecalculateFields(	RecalculateFields *	rf,
474 				DOC_CLOSE_OBJECT	closeObject,
475 				BufferDocument *	bd )
476     {
477     const int			page= 0;
478 
479     rf->rfDocument= bd;
480     rf->rfCloseObject= closeObject;
481     rf->rfUpdateFlags= FIELDdoDOC_INFO|FIELDdoDOC_COMPLETE|FIELDdoCHFTN;
482     rf->rfFieldsUpdated= 0;
483 
484     rf->rfBodySectNode= bd->bdBody.dtRoot->biChildren[0];
485 
486     if  ( docRecalculateTocFields( rf ) )
487 	{ LDEB(1); return -1;	}
488 
489     if  ( docRecalculateTextLevelFieldsInDocumentTree( rf, &(bd->bdBody),
490 				    bd->bdBody.dtRoot->biChildren[0], page ) )
491 	{ LDEB(1); return -1;	}
492 
493     return 0;
494     }
495 
tedLayoutDocument(DocumentRectangle * drScreen,DocumentRectangle * drVisible,void * privateData,int format,DrawingSurface ds,const PostScriptFontList * psfl,const DocumentGeometry * dgDef)496 int tedLayoutDocument(		DocumentRectangle *		drScreen,
497 				DocumentRectangle *		drVisible,
498 				void *				privateData,
499 				int				format,
500 				DrawingSurface			ds,
501 				const PostScriptFontList *	psfl,
502 				const DocumentGeometry *	dgDef )
503     {
504     TedDocument *		td= (TedDocument *)privateData;
505     BufferDocument *		bd= td->tdDocument;
506 
507     const int			page= 0;
508     int				noteNumbersChanged= 0;
509     int				reachedBottom= 0;
510 
511     RecalculateFields		rf;
512     LayoutContext		lc;
513 
514     DocumentRectangle		drOutside;
515     DocumentRectangle		drInside;
516 
517     BufferItem *		rootNode= bd->bdBody.dtRoot;
518 
519     docInitRecalculateFields( &rf );
520     layoutInitContext( &lc );
521 
522     docPageRectsPixels( &drOutside, &drInside, td->tdPixelsPerTwip,
523 						rootNode->biChildren[0], bd );
524 
525     *drScreen= drOutside;
526     *drVisible= drOutside;
527 
528     tedSetDocumentLayoutContext( &lc, ds, psfl, td );
529 
530     if  ( tedFirstRecalculateFields( &rf, docScreenCloseObject, bd ) )
531 	{ LDEB(page); return -1;	}
532 
533     if  ( tedLayoutDocumentBody( &reachedBottom, &lc ) )
534 	{ LDEB(1); return -1;	}
535 
536     docRenumberNotes( &noteNumbersChanged, bd );
537 
538     rf.rfUpdateFlags= FIELDdoDOC_FORMATTED;
539     rf.rfFieldsUpdated= 0;
540 
541     if  ( noteNumbersChanged )
542 	{ rf.rfUpdateFlags |= FIELDdoCHFTN;	}
543 
544     if  ( docRecalculateTextLevelFieldsInDocumentTree( &rf, &(bd->bdBody),
545 					    rootNode->biChildren[0], page ) )
546 	{ LDEB(1); return -1;	}
547 
548     if  ( rf.rfFieldsUpdated > 0				&&
549 	  tedLayoutDocumentBody( &reachedBottom, &lc )	)
550 	{ LDEB(1); return -1;	}
551 
552     docGetPixelRectangleForPages( drScreen, &lc,
553 					rootNode->biTopPosition.lpPage,
554 					rootNode->biBelowPosition.lpPage );
555 
556     /* LDEB(1); docListNode(0,rootNode,1); */
557 
558     return 0;
559     }
560 
561 /************************************************************************/
562 /*									*/
563 /*  Allocate private data for a document.				*/
564 /*									*/
565 /************************************************************************/
566 
tedMakePrivateData(void)567 void * tedMakePrivateData( void )
568     {
569     int			i;
570     TedDocument *	td;
571 
572     td= (TedDocument *)malloc( sizeof(TedDocument) );
573     if  ( ! td )
574 	{ XDEB(td); return (void *)0;	}
575 
576     docInitSelectionDescription( &(td->tdSelectionDescription) );
577     td->tdBodySectionNumber= -1;
578 
579     td->tdDocument= (BufferDocument *)0;
580     td->tdCurrentScreenFont= -1;
581 
582     utilInitMemoryBuffer( &(td->tdRecoveredName) );
583 
584     td->tdPageGapTwips= 0;
585 
586     td->tdTraced= 0;
587     td->tdOverstrike= 0;
588 
589     utilInitIndexMapping( &(td->tdAttributeToScreenFont) );
590     docInitEditTrace( &(td->tdEditTrace) );
591 
592     td->tdFormatMenu= (APP_WIDGET)0;
593     td->tdFormatMenuButton= (APP_WIDGET)0;
594     td->tdFormatOneParaOption= (APP_WIDGET)0;
595     td->tdFormatOneParaSeparator= (APP_WIDGET)0;
596 
597     td->tdFormatPasteRulerOption= (APP_WIDGET)0;
598     td->tdFormatIncreaseIndentOption= (APP_WIDGET)0;
599     td->tdFormatDecreaseIndentOption= (APP_WIDGET)0;
600     td->tdFormatRulerSeparator= (APP_WIDGET)0;
601 
602     td->tdFormatAlignLeftOption= (APP_WIDGET)0;
603     td->tdFormatAlignRightOption= (APP_WIDGET)0;
604     td->tdFormatAlignCenterOption= (APP_WIDGET)0;
605     td->tdFormatAlignJustifyOption= (APP_WIDGET)0;
606     td->tdFormatAlignSeparator= (APP_WIDGET)0;
607 
608     td->tdFileOpenOption= (APP_WIDGET)0;
609     td->tdFileSaveOption= (APP_WIDGET)0;
610     td->tdFileSaveAsOption= (APP_WIDGET)0;
611     td->tdFileUnlockOption= (APP_WIDGET)0;
612     td->tdFileRecoverOption= (APP_WIDGET)0;
613     td->tdFilePropertiesOption= (APP_WIDGET)0;
614     td->tdFileCloseOption= (APP_WIDGET)0;
615     td->tdFileQuitSeparator= (APP_WIDGET)0;
616     td->tdFileQuitOption= (APP_WIDGET)0;
617 
618     td->tdCopyOption= (APP_WIDGET)0;
619     td->tdUndoOption= (APP_WIDGET)0;
620     td->tdRepeatOption= (APP_WIDGET)0;
621     td->tdCutOption= (APP_WIDGET)0;
622     td->tdPasteOption= (APP_WIDGET)0;
623 
624     td->tdInsertMenu= (APP_WIDGET)0;
625     td->tdInsertMenuButton= (APP_WIDGET)0;
626     td->tdInsPictOption= (APP_WIDGET)0;
627     td->tdInsFileOption= (APP_WIDGET)0;
628     td->tdInsSymbolOption= (APP_WIDGET)0;
629     td->tdInsHyperlinkOption= (APP_WIDGET)0;
630     td->tdInsBookmarkOption= (APP_WIDGET)0;
631     td->tdInsInsertFootnoteOption= (APP_WIDGET)0;
632     td->tdInsInsertEndnoteOption= (APP_WIDGET)0;
633     td->tdInsInsertChftnsepOption= (APP_WIDGET)0;
634     td->tdInsInsertTableOption= (APP_WIDGET)0;
635     td->tdInsInsertPageNumberOption= (APP_WIDGET)0;
636     td->tdInsInsertLineBreakOption= (APP_WIDGET)0;
637     td->tdInsInsertPageBreakOption= (APP_WIDGET)0;
638     td->tdInsInsertColumnBreakOption= (APP_WIDGET)0;
639     td->tdInsInsertSectBreakOption= (APP_WIDGET)0;
640 
641     td->tdTableMenu= (APP_WIDGET)0;
642     td->tdTableMenuButton= (APP_WIDGET)0;
643 
644     td->tdTabInsertTableOption= (APP_WIDGET)0;
645     td->tdTabAddRowOption= (APP_WIDGET)0;
646     td->tdTabAddColumnOption= (APP_WIDGET)0;
647     td->tdTabInsertSeparator= (APP_WIDGET)0;
648 
649     td->tdTabSelectTableOption= (APP_WIDGET)0;
650     td->tdTabSelectRowOption= (APP_WIDGET)0;
651     td->tdTabSelectColumnOption= (APP_WIDGET)0;
652     td->tdTabSelectSeparator= (APP_WIDGET)0;
653 
654     td->tdTabDeleteTableOption= (APP_WIDGET)0;
655     td->tdTabDeleteRowOption= (APP_WIDGET)0;
656     td->tdTabDeleteColumnOption= (APP_WIDGET)0;
657     td->tdTabDeleteSeparator= (APP_WIDGET)0;
658 
659     td->tdDrawTableGridOption= (APP_WIDGET)0;
660 
661     td->tdFontMenu= (APP_WIDGET)0;
662     td->tdFontMenuButton= (APP_WIDGET)0;
663     td->tdFontBoldOption= (APP_WIDGET)0;
664     td->tdFontItalicOption= (APP_WIDGET)0;
665     td->tdFontUnderlinedOption= (APP_WIDGET)0;
666     td->tdFontSuperscriptOption= (APP_WIDGET)0;
667     td->tdFontSubscriptOption= (APP_WIDGET)0;
668     td->tdFontToggleSeparator= (APP_WIDGET)0;
669     td->tdFontPasteOption= (APP_WIDGET)0;
670 
671     td->tdToolsMenu= (APP_WIDGET)0;
672     td->tdToolsMenuButton= (APP_WIDGET)0;
673     td->tdToolsFormatToolOption= (APP_WIDGET)0;
674 
675     td->tdToolsFontOption= (APP_WIDGET)0;
676     td->tdToolsFindOption= (APP_WIDGET)0;
677     td->tdToolsSpellingOption= (APP_WIDGET)0;
678     td->tdToolsPageLayoutOption= (APP_WIDGET)0;
679     td->tdToolsSymbolOption= (APP_WIDGET)0;
680 
681     docInitDocumentSelection( &(td->tdSelection) );
682     docInitSelectionGeometry( &(td->tdSelectionGeometry) );
683 
684     td->tdVisibleSelectionCopied= 0;
685 
686     utilInitMemoryBuffer( &(td->tdCopiedSelection) );
687     utilInitMemoryBuffer( &(td->tdCopiedFont) );
688     utilInitMemoryBuffer( &(td->tdCopiedRuler) );
689 
690     bmInitRasterImage( &(td->tdCopiedImage) );
691 
692     td->tdFindProg= (void *)0;
693     td->tdOwnsPrimarySelection= 0;
694 
695 #   ifdef USE_MOTIF
696     td->tdHideIBarId= (XtIntervalId)0;
697     td->tdShowIBarId= (XtIntervalId)0;
698 #   endif
699 #   ifdef USE_GTK
700     td->tdHideIBarId= 0;
701     td->tdShowIBarId= 0;
702 #   endif
703 
704     td->tdObjectWindow= (APP_WINDOW)0;
705     for ( i= 0; i < RESIZE_COUNT; i++ )
706 	{ td->tdObjectResizeWindows[i]= (APP_WINDOW)0;	}
707     td->tdObjectResizeCorner= -1;
708     td->tdObjectCornerMovedX= 0;
709     td->tdObjectCornerMovedY= 0;
710     td->tdScaleChangedX= 0;
711     td->tdScaleChangedY= 0;
712 
713     td->tdDrawTableGrid= 1;
714     td->tdDrawMonochrome= 0;
715     td->tdInProgrammaticChange= 0;
716 
717     return (void *)td;
718     }
719 
720 /************************************************************************/
721 /*									*/
722 /*  Keep track of focus.						*/
723 /*									*/
724 /************************************************************************/
725 
tedObserveFocus(EditDocument * ed,int inout)726 void tedObserveFocus(	EditDocument *	ed,
727 			int		inout )
728     {
729     EditApplication *	ea= ed->edApplication;
730 
731     if  ( inout > 0 )
732 	{
733 	if  ( ea->eaCurrentDocument != ed )
734 	    {
735 	    appSetCurrentDocument( ea, ed );
736 
737 	    tedAdaptPageToolToDocument( ea, ed );
738 
739 	    tedAdaptFormatToolToDocument( ed, 0 );
740 	    }
741 
742 	if  ( tedHasIBarSelection( ed ) )
743 	    { tedStartCursorBlink( ed );	}
744 	}
745 
746     if  ( inout < 0 )
747 	{ tedStopCursorBlink( ed ); }
748 
749     return;
750     }
751 
tedSuggestPageSetup(PrintGeometry * pg,void * privateData,int sheetSize)752 void tedSuggestPageSetup(	PrintGeometry *	pg,
753 				void *		privateData,
754 				int		sheetSize )
755     {
756     TedDocument *		td= (TedDocument *)privateData;
757     BufferDocument *		bd= td->tdDocument;
758     DocumentProperties *	dp= &(bd->bdProperties);
759 
760     if  ( sheetSize )
761 	{ pg->pgSheetGeometry= dp->dpGeometry;	}
762 
763     if  ( dp->dpTwoOnOne )
764 	{
765 	pg->pgGridRows= 2;
766 	pg->pgGridCols= 1;
767 	pg->pgGridHorizontal= 1;
768 	pg->pgScalePagesToFit= 1;
769 	}
770 
771     return;
772     }
773 
tedSetTracedChangedFlag(EditDocument * ed)774 void tedSetTracedChangedFlag(	EditDocument *	ed )
775     {
776     const TedDocument *	td= (TedDocument *)ed->edPrivateData;
777     const EditTrace *	et= &(td->tdEditTrace);
778     int			changed;
779 
780     if  ( ! td->tdTraced )
781 	{ LDEB(td->tdTraced); return;	}
782 
783     changed= et->etIndex < et->etBase || et->etIndex > et->etBase+ 1;
784 
785     appDocumentChanged( ed, changed );
786 
787     return;
788     }
789 
790