File: tedHeaderFooter.c

package info (click to toggle)
ted 2.11-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 11,064 kB
  • ctags: 13,935
  • sloc: ansic: 120,446; makefile: 7,469; sh: 253
file content (342 lines) | stat: -rw-r--r-- 8,374 bytes parent folder | download
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
/************************************************************************/
/*									*/
/*  Edit/Make headers and footers.					*/
/*  Jump back and forth between the body of a document and notes.	*/
/*									*/
/************************************************************************/

#   include	"tedConfig.h"

#   include	<stddef.h>
#   include	<stdlib.h>
#   include	<stdio.h>
#   include	<ctype.h>
#   include	<limits.h>

#   include	"docLayout.h"
#   include	"tedApp.h"

#   include	<appDebugon.h>

/************************************************************************/
/*									*/
/*  Move the current selection to a certain header/Footer. If the	*/
/*  header or footer does not exist, make it.				*/
/*									*/
/************************************************************************/

static int TED_TryPageOffsets[]=
    {
     0,
     1,
    -1,
     2
    };

void tedAppEditHeaderFooter(		EditApplication *	ea,
					APP_WIDGET		relative,
					APP_WIDGET		option,
					int			which )
    {
    EditDocument *		ed= ea->eaCurrentDocument;
    AppDrawingData *		add;
    TedDocument *		td;
    BufferDocument *		bd;
    const DocumentProperties *	docp;

    ExternalItem *		ei;
    ExternalItem *		hfTry;
    BufferItem *		bodySectBi;

    DocumentSelection		ds;
    SelectionGeometry		sg;
    SelectionScope *		ss;
    DocumentPosition		dp;

    int				page= -1;
    int				pg;
    int				i;

    int				scrolledX= 0;
    int				scrolledY= 0;

    DocumentRectangle		drChanged;

    if  ( ! ed )
	{ XDEB(ed); return;	}

    add= &(ed->edDrawingData);
    td= (TedDocument *)ed->edPrivateData;
    bd= td->tdDocument;
    docp= &(bd->bdProperties);

    if  ( tedGetSelection( &ds, &sg, td ) )
	{ LDEB(1); return;	}
    ss= &(ds.dsSelectionScope);

    drChanged= sg.sgRectangle;

    if  ( docGetHeaderFooter( &ei, &bodySectBi, &ds, bd, which ) )
	{ LDEB(which); return;	}

    if  ( ss->ssInExternalItem == which					&&
	  ss->ssSectNrExternalTo == bodySectBi->biNumberInParent	)
	{ return;	}

    if  ( ! ei->eiItem )
	{
	BufferItem *	paraBi;
	const int	noteIndex= -1;

	paraBi= docMakeExternalparagraph( bd, ei, bodySectBi,
				td->tdCurrentTextAttribute, noteIndex, which );
	if  ( ! paraBi )
	    { XDEB(paraBi); return; }

	if  ( tedLayoutItem( bodySectBi, bd, add, &drChanged ) )
	    { LDEB(1); return;	}

	appDocumentChanged( ed, 1 );
	}

    switch( which )
	{
	case DOCinFIRST_HEADER:
	case DOCinFIRST_FOOTER:
	    page= bodySectBi->biTopPosition.lpPage;
	    break;

	case DOCinSECT_HEADER:
	case DOCinLEFT_HEADER:
	case DOCinRIGHT_HEADER:
	    for ( i= 0; i < sizeof(TED_TryPageOffsets)/sizeof(int); i++ )
		{
		pg= sg.sgBegin.pgTopPosition.lpPage+ TED_TryPageOffsets[i];

		if  ( pg < bodySectBi->biTopPosition.lpPage		||
		      pg > bodySectBi->biBelowPosition.lpPage	)
		    { continue;	}

		if  ( docWhatPageHeader( &hfTry, bodySectBi, pg, docp )
								    == which )
		    { page= pg; break;	}
		}
	    break;

	case DOCinSECT_FOOTER:
	case DOCinLEFT_FOOTER:
	case DOCinRIGHT_FOOTER:
	    for ( i= 0; i < sizeof(TED_TryPageOffsets)/sizeof(int); i++ )
		{
		pg= sg.sgBegin.pgTopPosition.lpPage+ TED_TryPageOffsets[i];

		if  ( pg < bodySectBi->biTopPosition.lpPage		||
		      pg > bodySectBi->biBelowPosition.lpPage	)
		    { continue;	}

		if  ( docWhatPageFooter( &hfTry, bodySectBi, pg, docp )
								    == which )
		    { page= pg; break;	}
		}
	    break;

	default:
	    LDEB(which); return;
	}

    if  ( page < bodySectBi->biTopPosition.lpPage		||
	  page > bodySectBi->biBelowPosition.lpPage		)
	{
	TedAppResources *	tar= (TedAppResources *)ea->eaResourceData;

	appQuestionRunErrorDialog( ea, relative, option,
					    tar->tarHeadFootNotReachable );
	return;
	}

    if  ( docFirstPosition( &dp, ei->eiItem ) )
	{ LDEB(1); return;	}

    tedSetSelectedPosition( ed, &dp, &scrolledX, &scrolledY );

    tedAdaptToolsToSelection( ed );

    return;
    }

/************************************************************************/
/*									*/
/*  Delete a particular page Header/Footer from the first section of	*/
/*  the selection.							*/
/*									*/
/*  1)  Get the given header/footer.					*/
/*  2)  If it exists.. Delete it.					*/
/*  3)  If the current selection is inside the header/footer to be	*/
/*	deleted.. Move the selection to the body somewhere nearby.	*/
/*									*/
/************************************************************************/

void tedAppDeleteHeaderFooter(		EditApplication *	ea,
					int			which )
    {
    EditDocument *		ed= ea->eaCurrentDocument;
    TedDocument *		td;
    BufferDocument *		bd;

    ExternalItem *		ei= (ExternalItem *)0;
    BufferItem *		bodySectBi;

    DocumentSelection		ds;
    SelectionGeometry		sg;

    int				scrolledX= 0;
    int				scrolledY= 0;

    if  ( ! ed )
	{ XDEB(ed); return;	}

    td= (TedDocument *)ed->edPrivateData;
    bd= td->tdDocument;

    if  ( tedGetSelection( &ds, &sg, td ) )
	{ LDEB(1); return;	}

    /*  1  */
    if  ( docGetHeaderFooter( &ei, &bodySectBi, &ds, bd, which ) )
	{ LDEB(which); return;	}

    /*  2  */
    if  ( ei && ei->eiItem )
	{
	AppDrawingData *	add= &(ed->edDrawingData);
	DocumentRectangle	drChanged= add->addBackRect;

	/*  3  */
	if  ( ds.dsBegin.dpBi->biInExternalItem == which )
	    {
	    int			docX;
	    int			docY;

	    DocumentPosition	dp;
	    PositionGeometry	pg;

	    docX= sg.sgBegin.pgXPixels;
	    docY= sg.sgBegin.pgBaselinePixels;

	    if  ( tedFindPosition( &dp, &pg, &(bd->bdItem), add, docX, docY ) )
		{ LLDEB(docX,docY); return;	}

	    tedSetSelectedPosition( ed, &dp, &scrolledX, &scrolledY );
	    }

	docCleanExternalItem( bd, ei );
	docInitExternalItem( ei );

	appDocumentChanged( ed, 1 );

	appDocExposeRectangle( ed, &drChanged, scrolledX, scrolledY );
	}

    return;
    }

/************************************************************************/
/*									*/
/*  Jump to the foot/end note thet is selected in the body of the	*/
/*  document.								*/
/*									*/
/************************************************************************/

void tedAppEditNote(		EditApplication *	ea )
    {
    EditDocument *		ed= ea->eaCurrentDocument;
    TedDocument *		td;
    BufferDocument *		bd;

    int				noteIndex;
    DocumentNote *		dn= (DocumentNote *)0;
    ExternalItem *		eiNote= (ExternalItem *)0;

    DocumentSelection		ds;
    SelectionGeometry		sg;

    DocumentPosition		dp;

    int				scrolledX= 0;
    int				scrolledY= 0;

    td= (TedDocument *)ed->edPrivateData;
    bd= td->tdDocument;

    if  ( tedGetSelection( &ds, &sg, td ) )
	{ LDEB(1); return;	}

    if  ( ds.dsSelectionScope.ssInExternalItem != DOCinBODY )
	{ LDEB(ds.dsSelectionScope.ssInExternalItem); return;	}

    noteIndex= docGetSelectedNote( &dn, bd, &ds );
    if  ( noteIndex < 0 )
	{ LDEB(noteIndex); return;	}

    eiNote= &(dn->dnExternalItem);

    if  ( ! eiNote->eiItem )
	{ XDEB(eiNote->eiItem); return;	}

    if  ( docFirstPosition( &dp, eiNote->eiItem ) )
	{ LDEB(1); return;	}

    tedSetSelectedPosition( ed, &dp, &scrolledX, &scrolledY );

    tedAdaptToolsToSelection( ed );

    return;
    }

/************************************************************************/
/*									*/
/*  Jump to the foot/end note thet is selected in the body of the	*/
/*  document.								*/
/*									*/
/************************************************************************/

void tedAppGotoNoteRef(		EditApplication *	ea )
    {
    EditDocument *		ed= ea->eaCurrentDocument;
    TedDocument *		td;
    BufferDocument *		bd;

    int				noteIndex;
    DocumentNote *		dn= (DocumentNote *)0;

    DocumentSelection		ds;
    SelectionGeometry		sg;

    BufferItem *		bi;

    int				scrolledX= 0;
    int				scrolledY= 0;

    td= (TedDocument *)ed->edPrivateData;
    bd= td->tdDocument;

    if  ( tedGetSelection( &ds, &sg, td ) )
	{ LDEB(1); return;	}

    if  ( ds.dsSelectionScope.ssInExternalItem != DOCinFOOTNOTE	&&
	  ds.dsSelectionScope.ssInExternalItem != DOCinENDNOTE	)
	{ LDEB(ds.dsSelectionScope.ssInExternalItem); return;	}

    noteIndex= docGetSelectedNote( &dn, bd, &ds );
    if  ( noteIndex < 0 )
	{ LDEB(noteIndex); return;	}

    bi= docGetParagraphByNumber( &(bd->bdItem), dn->dnParaNr );
    if  ( ! bi )
	{ LXDEB(dn->dnParaNr,bi); return;	}

    tedSetIBarSelection( ed, bi, dn->dnStroff, &scrolledX, &scrolledY );

    return;
    }