File: tedDocprops.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 (530 lines) | stat: -rw-r--r-- 15,127 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
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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
/************************************************************************/
/*  Dialog with document properties.					*/
/************************************************************************/

#   include	"tedConfig.h"

#   include	<stdlib.h>
#   include	<stdio.h>
#   include	<stddef.h>
#   include	<string.h>

#   include	<appDebugon.h>

#   include	"tedApp.h"

#   define	DRH_CM	4.5

/************************************************************************/
/*  Represents a mail dialog.						*/
/************************************************************************/
#   define	FILEL	400

typedef struct PropertyDialog
    {
    AppDialog			dpdDialog;

    APP_WIDGET			dpdOkButton;

    char *			dpdOkText;
    char *			dpdCancelText;

    char *			dpdTitleText;
    char *			dpdAuthorText;
    char *			dpdSubjectText;
    char *			dpdKeywordsText;
    char *			dpdCommentText;
    char *			dpdHlinkbaseText;

    char *			dpdCreatimText;
    char *			dpdRevtimText;
    char *			dpdPrintimText;

    char *			dpdPageCountText;
    char *			dpdParaCountText;
    char *			dpdLineCountText;
    char *			dpdWordCountText;
    char *			dpdCharCountText;

    APP_WIDGET			dpdTitleWidget;
    APP_WIDGET			dpdAuthorWidget;
    APP_WIDGET			dpdSubjectWidget;
    APP_WIDGET			dpdKeywordsWidget;
    APP_WIDGET			dpdCommentWidget;
    APP_WIDGET			dpdHlinkbaseWidget;

    APP_WIDGET			dpdCreatimWidget;
    APP_WIDGET			dpdRevtimWidget;
    APP_WIDGET			dpdPrintimWidget;

    APP_WIDGET			dpdPageCountWidget;
    APP_WIDGET			dpdParaCountWidget;
    APP_WIDGET			dpdLineCountWidget;
    APP_WIDGET			dpdWordCountWidget;
    APP_WIDGET			dpdCharCountWidget;
    } PropertyDialog;

static PropertyDialog *	TED_PropertyDialog;

static AppConfigurableResource TED_PropertyDialogResourceTable[]=
    {
	APP_RESOURCE( "propDialogTitle",
		    offsetof(PropertyDialog,dpdTitleText),
		    "Title" ),
	APP_RESOURCE( "propDialogAuthor",
		    offsetof(PropertyDialog,dpdAuthorText),
		    "Author" ),
	APP_RESOURCE( "propDialogSubject",
		    offsetof(PropertyDialog,dpdSubjectText),
		    "Subject" ),
	APP_RESOURCE( "propDialogKeywords",
		    offsetof(PropertyDialog,dpdKeywordsText),
		    "Keywords" ),
	APP_RESOURCE( "propDialogComment",
		    offsetof(PropertyDialog,dpdCommentText),
		    "Comment" ),
	APP_RESOURCE( "propDialogHlinkbase",
		    offsetof(PropertyDialog,dpdHlinkbaseText),
		    "Links Relative to" ),

	APP_RESOURCE( "propDialogCreatim",
		    offsetof(PropertyDialog,dpdCreatimText),
		    "Created" ),
	APP_RESOURCE( "propDialogRevtim",
		    offsetof(PropertyDialog,dpdRevtimText),
		    "Last Changed" ),
	APP_RESOURCE( "propDialogPrintim",
		    offsetof(PropertyDialog,dpdPrintimText),
		    "Last Printed" ),

	APP_RESOURCE( "propDialogPages",
		    offsetof(PropertyDialog,dpdPageCountText),
		    "Pages" ),
	APP_RESOURCE( "propDialogParagraphs",
		    offsetof(PropertyDialog,dpdParaCountText),
		    "Paragraphs" ),
	APP_RESOURCE( "propDialogLines",
		    offsetof(PropertyDialog,dpdLineCountText),
		    "Lines" ),
	APP_RESOURCE( "propDialogWords",
		    offsetof(PropertyDialog,dpdWordCountText),
		    "Words" ),
	APP_RESOURCE( "propDialogCharacters",
		    offsetof(PropertyDialog,dpdCharCountText),
		    "Characters" ),

	APP_RESOURCE( "propDialogCancel",
		    offsetof(PropertyDialog,dpdCancelText),
		    "Cancel" ),
	APP_RESOURCE( "propDialogOk",
		    offsetof(PropertyDialog,dpdOkText),
		    "Ok" ),
    };

/************************************************************************/
/*									*/
/*  One of the Text widgets changed.					*/
/*									*/
/************************************************************************/

static void tedPropertyChanged(	APP_WIDGET	w,
				void *		voiddpd,
				void *		call_data )
    {
    PropertyDialog *	dpd= (PropertyDialog *)voiddpd;

    appGuiEnableWidget( dpd->dpdOkButton, 1 );

    appGuiSetDefaultButtonForDialog( &(dpd->dpdDialog), dpd->dpdOkButton );

    return;
    }

/************************************************************************/
/*									*/
/*  The buttons have been pushed.					*/
/*									*/
/************************************************************************/

static void tedPropertiesCancelPushed(	APP_WIDGET	w,
					void *		voiddpd,
					void *		voidpbcs )
    {
    PropertyDialog *	dpd= (PropertyDialog *)voiddpd;

    appGuiBreakDialog( &(dpd->dpdDialog), AQDrespCANCEL );

    return;
    }

static void tedPropertiesOkPushed(	APP_WIDGET	w,
					void *		voiddpd,
					void *		voidpbcs	 )
    {
    PropertyDialog *	dpd= (PropertyDialog *)voiddpd;

    appGuiBreakDialog( &(dpd->dpdDialog), AQDrespOK );

    return;
    }

/************************************************************************/
/*									*/
/*  A Property Dialog must be destroyed.				*/
/*									*/
/************************************************************************/

static APP_CLOSE_CALLBACK( tedClosePropertyDialog, w, voiddpd )
    {
    PropertyDialog *	dpd= (PropertyDialog *)voiddpd;

    appGuiBreakDialog( &(dpd->dpdDialog), AQDrespCANCEL );

    return;
    }

static void tedPropsDialogMakePropertyRow(	APP_WIDGET*	pRow,
						APP_WIDGET *	pLabel,
						APP_WIDGET *	pText,
						APP_WIDGET	parent,
						PropertyDialog * dpd,
						const char *	labelText,
						int		textEnabled )
    {
    APP_WIDGET		row;
    APP_WIDGET		label;
    APP_WIDGET		text;

    const int		heightResizable= 0;
    const int		columnCount= 5;
    const int		labelColumn= 0;
    const int		labelColspan= 1;
    const int		textColumn= 1;
    const int		textColspan= 4;
    const int		textColumns= 50;

    row= appMakeRowInColumn( parent, columnCount, heightResizable );

    appMakeLabelInRow( &label, row, labelColumn, labelColspan, labelText );
    appMakeTextInRow( &text, row, textColumn, textColspan,
						textColumns, textEnabled );

    *pRow= row; *pLabel= label; *pText= text;

    if  ( textEnabled )
	{
	appGuiSetTypingCallbackForText( text,
					    tedPropertyChanged, (void *)dpd );
	}

    return;
    }

static void tedPropsDialogMakeTextForm( APP_WIDGET		parent,
					PropertyDialog *	dpd )
    {
    APP_WIDGET		row;
    APP_WIDGET		label;

    const int		changeable= 1;
    const int		derived= 0;

    tedPropsDialogMakePropertyRow( &row, &label, &(dpd->dpdTitleWidget),
			    parent, dpd, dpd->dpdTitleText, changeable );

    tedPropsDialogMakePropertyRow( &row, &label, &(dpd->dpdAuthorWidget),
			    parent, dpd, dpd->dpdAuthorText, changeable );

    tedPropsDialogMakePropertyRow( &row, &label, &(dpd->dpdSubjectWidget),
			    parent, dpd, dpd->dpdSubjectText, changeable );

    tedPropsDialogMakePropertyRow( &row, &label, &(dpd->dpdKeywordsWidget),
			    parent, dpd, dpd->dpdKeywordsText, changeable );

    tedPropsDialogMakePropertyRow( &row, &label, &(dpd->dpdCommentWidget),
			    parent, dpd, dpd->dpdCommentText, changeable );

    tedPropsDialogMakePropertyRow( &row, &label, &(dpd->dpdHlinkbaseWidget),
			    parent, dpd, dpd->dpdHlinkbaseText, changeable );

    /**/

    tedPropsDialogMakePropertyRow( &row, &label, &(dpd->dpdCreatimWidget),
			    parent, dpd, dpd->dpdCreatimText, derived );

    tedPropsDialogMakePropertyRow( &row, &label, &(dpd->dpdRevtimWidget),
			    parent, dpd, dpd->dpdRevtimText, derived );

    tedPropsDialogMakePropertyRow( &row, &label, &(dpd->dpdPrintimWidget),
			    parent, dpd, dpd->dpdPrintimText, derived );

    /**/

    tedPropsDialogMakePropertyRow( &row, &label, &(dpd->dpdPageCountWidget),
			    parent, dpd, dpd->dpdPageCountText, derived );

    tedPropsDialogMakePropertyRow( &row, &label, &(dpd->dpdParaCountWidget),
			    parent, dpd, dpd->dpdParaCountText, derived );

    tedPropsDialogMakePropertyRow( &row, &label, &(dpd->dpdLineCountWidget),
			    parent, dpd, dpd->dpdLineCountText, derived );

    tedPropsDialogMakePropertyRow( &row, &label, &(dpd->dpdWordCountWidget),
			    parent, dpd, dpd->dpdWordCountText, derived );

    tedPropsDialogMakePropertyRow( &row, &label, &(dpd->dpdCharCountWidget),
			    parent, dpd, dpd->dpdCharCountText, derived );

    return;
    }

/************************************************************************/
/*									*/
/*  Make the form with the two buttons.					*/
/*									*/
/************************************************************************/

static APP_WIDGET tedPropsDialogMakeButtonRow( APP_WIDGET	parent,
					PropertyDialog *	dpd )
    {
    APP_WIDGET	row;
    APP_WIDGET	cancelButton;
    const int	heightResizable= 0;

    row= appMakeRowInColumn( parent, 2, heightResizable );

    appMakeButtonInRow( &(dpd->dpdOkButton), row, dpd->dpdOkText,
				tedPropertiesOkPushed, (void *)dpd, 0, 1 );

    appMakeButtonInRow( &(cancelButton), row, dpd->dpdCancelText, 
			    tedPropertiesCancelPushed, (void *)dpd, 1, 0 );

    appGuiSetCancelButtonForDialog( &(dpd->dpdDialog), cancelButton );

    return row;
    }

/************************************************************************/
/*									*/
/*  Make a document properties dialog.					*/
/*									*/
/************************************************************************/

static PropertyDialog * tedMakePropertyDialog( EditDocument *	ed,
					APP_WIDGET		printOption,
					const char *		pixmapName )
    {
    EditApplication *	ea= ed->edApplication;
    PropertyDialog *	dpd;
    
    APP_WIDGET		paned;
    APP_WIDGET		separator;
    APP_WIDGET		buttonForm;

    APP_BITMAP_IMAGE	iconPixmap= (APP_BITMAP_IMAGE)0;
    APP_BITMAP_MASK	iconMask= (APP_BITMAP_MASK)0;

    if  ( appGetImagePixmap( ea, pixmapName, &iconPixmap, &iconMask )  )
	{ SDEB(pixmapName); return (PropertyDialog *)0;	}

    dpd= (PropertyDialog *)malloc( sizeof(PropertyDialog) );
    if  ( ! dpd )
	{ XDEB(dpd); return (PropertyDialog *)0;	}

    appGuiGetResourceValues( ea, dpd, TED_PropertyDialogResourceTable,
				    sizeof(TED_PropertyDialogResourceTable)/
				    sizeof(AppConfigurableResource) );

    appMakeVerticalDialog( &(dpd->dpdDialog), &paned, ea,
						tedClosePropertyDialog,
						(APP_CALLBACK_FUNC)0,
						(void *)dpd,
						"tedPropertyDialog" );

    appSetShellTitle( dpd->dpdDialog.adTopWidget,
				    printOption, ea->eaApplicationName );


    tedPropsDialogMakeTextForm( paned, dpd );

    appGuiInsertSeparatorInColumn( &separator, paned );

    buttonForm= tedPropsDialogMakeButtonRow( paned, dpd );

    appGuiShowDialog( &(dpd->dpdDialog), ed->edToplevel.atTopWidget );

    return dpd;
    }

/************************************************************************/

static int tedPropChangeProperty(	int *			pChanged,
					unsigned char **	pValue,
					APP_WIDGET		textWidget )
    {
    char *	oldValue= (char *)*pValue;
    char *	newValue;
    char *	saved= (char *)0;

    newValue= appGetStringFromTextWidget( textWidget );

    if  ( ! oldValue || ! oldValue[0] )
	{
	if  ( ! newValue[0] )
	    { appFreeStringFromTextWidget( newValue ); return 0;	}
	}
    else{
	if  ( ! strcmp( oldValue, newValue ) )
	    { appFreeStringFromTextWidget( newValue ); return 0;	}
	}

    if  ( newValue[0] )
	{
	saved= strdup( newValue );
	if  ( ! saved )
	    { XDEB(saved); return -1;	}
	}

    appFreeStringFromTextWidget( newValue );

    if  ( oldValue )
	{ free( oldValue );	}

    *pChanged= 1; *pValue= (unsigned char *)saved;

    return 0;
    }

/************************************************************************/
/*									*/
/*  Show the 'Document Properties...' dialog.				*/
/*									*/
/*  1)	Make or just show it.						*/
/*  2)	Set the default content.					*/
/*									*/
/************************************************************************/

static void tedPropToWidget(	APP_WIDGET			w,
				const unsigned char *		prop )
    {
    if  ( prop )
	{ appStringToTextWidget( w, (char *)prop );	}
    else{ appStringToTextWidget( w, "" );		}

    return;
    }

static void tedDateToWidget(	APP_WIDGET			w,
				const struct tm *		tm )
    {
    if  ( tm->tm_mday == 0 )
	{ appStringToTextWidget( w, "" );	}
    else{
	char		scratch[40+1];
	const char *	frm;

	/*  GCC Shut Up! */
	frm= "%c";
	if  ( strftime( scratch, sizeof(scratch)- 1, frm, tm ) < 1 )
	    { LDEB(1); appStringToTextWidget( w, "?" );	}
	else{ appStringToTextWidget( w, scratch );	}
	}

    return;
    }

int tedRunPropertyDialog(	EditDocument *			ed,
				const DocumentStatistics *	ds,
				APP_WIDGET			option,
				const char *			pixmapName )
    {
    int				rval= 0;
    int				changed= 0;

    PropertyDialog *		dpd= TED_PropertyDialog;

    EditApplication *		ea= ed->edApplication;
    TedDocument *		td= (TedDocument *)ed->edPrivateData;
    BufferDocument *		bd= td->tdDocument;
    DocumentProperties *	dp= &(bd->bdProperties);

    /*  1  */
    if  ( ! dpd )
	{
	dpd= TED_PropertyDialog= tedMakePropertyDialog( ed, option,
								pixmapName );
	if  ( ! dpd )
	    { XDEB(dpd); return -1;	}

	}
    else{
	appSetShellTitle( dpd->dpdDialog.adTopWidget,
					    option, ea->eaApplicationName );

	appGuiShowDialog( &(dpd->dpdDialog), ed->edToplevel.atTopWidget );
	}

    tedPropToWidget( dpd->dpdTitleWidget, dp->dpTitle );
    tedPropToWidget( dpd->dpdAuthorWidget, dp->dpAuthor );
    tedPropToWidget( dpd->dpdSubjectWidget, dp->dpSubject );
    tedPropToWidget( dpd->dpdKeywordsWidget, dp->dpKeywords );
    tedPropToWidget( dpd->dpdCommentWidget, dp->dpComment );
    tedPropToWidget( dpd->dpdHlinkbaseWidget, dp->dpHlinkbase );

    tedDateToWidget( dpd->dpdCreatimWidget, &(dp->dpCreatim) );
    tedDateToWidget( dpd->dpdRevtimWidget, &(dp->dpRevtim) );
    tedDateToWidget( dpd->dpdPrintimWidget, &(dp->dpPrintim) );

    appIntegerToTextWidget( dpd->dpdPageCountWidget, ds->dsPageCount );
    appIntegerToTextWidget( dpd->dpdParaCountWidget, ds->dsParagraphCount );
    appIntegerToTextWidget( dpd->dpdLineCountWidget, ds->dsLineCount );
    appIntegerToTextWidget( dpd->dpdWordCountWidget, ds->dsWordCount );
    appIntegerToTextWidget( dpd->dpdCharCountWidget, ds->dsCharacterCount );

    appGuiEnableWidget( dpd->dpdOkButton, 0 );

    appGuiRunDialog( &(dpd->dpdDialog), AQDrespNONE, ea );

    switch( dpd->dpdDialog.adResponse )
	{
	case AQDrespOK:
	    break;
	default:
	    LDEB(dpd->dpdDialog.adResponse);
	    /*FALLTHROUGH*/
	case AQDrespCANCEL:
	    appGuiHideDialog( &(dpd->dpdDialog) );
	    return -1;
	}

    appGuiHideDialog( &(dpd->dpdDialog) );

    if  ( tedPropChangeProperty( &changed, &(dp->dpTitle),
						dpd->dpdTitleWidget ) )
	{ LDEB(1); return -1;	}

    if  ( tedPropChangeProperty( &changed, &(dp->dpAuthor),
						dpd->dpdAuthorWidget ) )
	{ LDEB(1); return -1;	}

    if  ( tedPropChangeProperty( &changed, &(dp->dpSubject),
						dpd->dpdSubjectWidget ) )
	{ LDEB(1); return -1;	}

    if  ( tedPropChangeProperty( &changed, &(dp->dpKeywords),
						dpd->dpdKeywordsWidget ) )
	{ LDEB(1); return -1;	}

    if  ( tedPropChangeProperty( &changed, &(dp->dpComment),
						dpd->dpdCommentWidget ) )
	{ LDEB(1); return -1;	}

    if  ( tedPropChangeProperty( &changed, &(dp->dpHlinkbase),
						dpd->dpdHlinkbaseWidget ) )
	{ LDEB(1); return -1;	}

    if  ( changed )
	{ appDocumentChanged( ed, 1 ); }

    return rval;
    }