File: tedColumnTool.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 (632 lines) | stat: -rw-r--r-- 17,326 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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
/************************************************************************/
/*									*/
/*  A Format Tool.							*/
/*									*/
/************************************************************************/

#   include	"tedConfig.h"

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

#   include	<appDebugon.h>

#   include	<appGeoString.h>
#   include	<appUnit.h>

#   include	"tedApp.h"
#   include	"tedFormatTool.h"

/************************************************************************/
/*									*/
/*  Refresh the 'Column' page of the format tool.			*/
/*									*/
/************************************************************************/

static void tedFormatToolRefreshColumnPage(	ColumnTool *	ct )
    {
    RowProperties *		rp= &(ct->ctPropertiesChosen);
    CellProperties *		cp;
    const TableRectangle *	tr= &(ct->ctTableRectangle);

    int				width;
    char			scratch[50];

    appIntegerToTextWidget( ct->ctNumberText, tr->trCol0+ 1 );

    if  ( tr->trCol0 == 0 )
	{
	width= rp->rpCells[tr->trCol0  ].cpRightBoundaryTwips-
						    rp->rpLeftIndentTwips;
	}
    else{
	width= rp->rpCells[tr->trCol0  ].cpRightBoundaryTwips-
			    rp->rpCells[tr->trCol0-1].cpRightBoundaryTwips;
	}

    appGeoLengthToString( scratch, width, UNITtyPOINTS );
    appStringToTextWidget( ct->ctWidthText, scratch );

    cp= rp->rpCells;

    tedFormatReflectBorder( &(ct->ctLeftBorderTool),
					&(cp[tr->trCol0].cpLeftBorder) );
    tedFormatReflectBorder( &(ct->ctRightBorderTool),
					&(cp[tr->trCol0].cpRightBorder) );
    }

void tedFormatToolRefreshColumnTool(
				ColumnTool *			ct,
				int *				pEnabled,
				InspectorSubject *		is,
				const DocumentSelection *	ds )
    {
    const RowProperties *	rp;
    const DocumentGeometry *	dg;

    const BufferItem *		rowBi;
    const BufferItem *		sectBi;

    TableRectangle *		tr= &(ct->ctTableRectangle);

    if  ( tedGetTableRectangle( tr, ds )	||
	  tr->trCol1 != tr->trCol0		)
	{
	docInitTableRectangle( tr );
	*pEnabled= 0; return;
	}

    rowBi= ds->dsBegin.dpBi;
    rowBi= rowBi->biParent;
    rowBi= rowBi->biParent;
    sectBi= rowBi->biParent;

    dg= &(sectBi->biSectDocumentGeometry);

    ct->ctPageRight= dg->dgPageWideTwips-
			    dg->dgLeftMarginTwips- dg->dgRightMarginTwips;
    ct->ctPageLeftMargin= dg->dgLeftMarginTwips;

    rp= &(rowBi->biRowProperties);

    if  ( docCopyRowProperties( &(ct->ctPropertiesChosen), rp ) )
	{ LDEB(1); return;	}
    if  ( docCopyRowProperties( &(ct->ctPropertiesSet), rp ) )
	{ LDEB(1); return;	}

    appGuiEnableWidget( is->isPrevButton,
				ct->ctTableRectangle.trCol0 > 0 );
    appGuiEnableWidget( is->isNextButton,
				ct->ctTableRectangle.trCol1 <
				ct->ctTableRectangle.trCol11 );

    tedFormatToolRefreshColumnPage( ct );

    appGuiEnableWidget( is->isDeleteButton, rp->rpCellCount > 1 );

    *pEnabled= 1;
    return;
    }

static int tedFormatToolGetColumnWidth(	const RowProperties *	rp,
					int			col0,
					int			pageRight,
					int *			pValue,
					int *			pShift,
					APP_WIDGET		w )
    {
    int				width;
    int				changed;

    const CellProperties *	cp= &(rp->rpCells[col0]);
    int				rightRight;

    int				right;
    int				d;

    const int			minValue= 1;
    const int			adaptToMin= 0;
    const int			maxValue= INT_MAX;
    const int			adaptToMax= 0;
    
    right= cp->cpRightBoundaryTwips;
    if  ( col0 == 0 )
	{ width= right- rp->rpLeftIndentTwips;		}
    else{ width= right- cp[-1].cpRightBoundaryTwips;	}

    if  ( appGetLengthFromTextWidget( w, &width, &changed, UNITtyPOINTS,
				minValue, adaptToMin, maxValue, adaptToMax ) )
	{ return -1; }

    if  ( col0 == 0 )
	{ right= rp->rpLeftIndentTwips+ width;		}
    else{ right= cp[-1].cpRightBoundaryTwips+ width;	}

    d= right- cp->cpRightBoundaryTwips;

    rightRight= rp->rpCells[rp->rpCellCount-1].cpRightBoundaryTwips;
    rightRight -= rp->rpHalfGapWidthTwips;

    if  ( rightRight+ d >= pageRight )
	{
	char		scratch[50];

	d= pageRight- rightRight;
	right= cp->cpRightBoundaryTwips+ d;

	if  ( col0 == 0 )
	    { width= right- rp->rpLeftIndentTwips;		}
	else{ width= right- cp[-1].cpRightBoundaryTwips;	}

	width -= 10;

	if  ( width <= 0 )
	    { appRefuseTextValue( w ); return -1;	}

	appGeoLengthToString( scratch, width, UNITtyPOINTS );
	appStringToTextWidget( w, scratch );
	appRefuseTextValue( w );
	return 1;
	}

    *pValue= width; *pShift= d; return 0;
    }

/************************************************************************/
/*									*/
/*  Set/Revert buttons have been pushed.				*/
/*									*/
/************************************************************************/

static void tedTableChangeColumnPushed(	APP_WIDGET	w,
					void *		voidct,
					void *		voidpbcs	 )
    {
    ColumnTool *		ct= (ColumnTool *)voidct;
    RowProperties *		rp= &(ct->ctPropertiesChosen);
    const TableRectangle *	tr= &(ct->ctTableRectangle);
    CellProperties *		cp= &(rp->rpCells[tr->trCol0]);

    int				col;

    int				d;
    int				width;
    int				res;

    TableRectangle		trChange;

    res= tedFormatToolGetColumnWidth( rp, tr->trCol0,
			    ct->ctPageRight, &width, &d, ct->ctWidthText );
    if  ( res != 0 )
	{ return;	}

    if  ( tedBorderToolGetWidth( &(ct->ctLeftBorderTool),
						&(cp->cpLeftBorder) ) )
	{ return;	}

    if  ( tedBorderToolGetWidth( &(ct->ctRightBorderTool),
						&(cp->cpRightBorder) ) )
	{ return;	}

    for ( col= tr->trCol0; col < rp->rpCellCount; cp++, col++ )
	{ cp->cpRightBoundaryTwips += d; }

    trChange= *tr;
    docExpandTableRectangleToWholeColumns( &trChange );

    tedAppSetTableProperties( ct->ctApplication, &trChange, rp );

    return;
    }

static void tedFormatRevertColumnPushed(	APP_WIDGET	w,
						void *		voidct,
						void *		voidpbcs )
    {
    ColumnTool *	ct= (ColumnTool *)voidct;

    docCopyRowProperties( &(ct->ctPropertiesChosen), &(ct->ctPropertiesSet) );

    tedFormatToolRefreshColumnPage( ct );

    return;
    }

/************************************************************************/
/*									*/
/*  A border style has been chosen.					*/
/*									*/
/************************************************************************/

static void tedColumnBorderStyleChosen(	APP_WIDGET	w,
					void *		voidct,
					void *		voidtbcs )
    {
    ColumnTool *		ct= (ColumnTool *)voidct;
    RowProperties *		rp= &(ct->ctPropertiesChosen);
    const TableRectangle *	tr= &(ct->ctTableRectangle);
    CellProperties *		cp= &(rp->rpCells[tr->trCol0]);

    if  ( ! tedBorderToolGetStyle( &(ct->ctLeftBorderTool),
						&(cp->cpLeftBorder), w ) )
	{ return;	}

    if  ( ! tedBorderToolGetStyle( &(ct->ctRightBorderTool),
						&(cp->cpRightBorder), w ) )
	{ return;	}

    XDEB(w); return;
    }

/************************************************************************/
/*									*/
/*  Check a number as typed by the user.				*/
/*									*/
/************************************************************************/

static void tedColumnWidthChanged(	APP_WIDGET	w,
					void *		voidct,
					void *		voidpbcs )
    {
    ColumnTool *		ct= (ColumnTool *)voidct;
    RowProperties *		rp= &(ct->ctPropertiesChosen);
    const TableRectangle *	tr= &(ct->ctTableRectangle);

    int				d;
    int				width;

    if  ( ! tedFormatToolGetColumnWidth( rp, tr->trCol0,
			    ct->ctPageRight, &width, &d, ct->ctWidthText ) )
	{
	char	scratch[50];

	appGeoLengthToString( scratch, width, UNITtyPOINTS );

	appStringToTextWidget( ct->ctWidthText, scratch );
	}
    }

/************************************************************************/
/*									*/
/*  Previous/Next Column/Row buttons have been pushed.			*/
/*									*/
/************************************************************************/

static void tedColumnPreviousColumn(	APP_WIDGET	w,
					void *		voidct,
					void *		voidpbcs	 )
    {
    ColumnTool *	ct= (ColumnTool *)voidct;
    EditApplication *	ea= ct->ctApplication;
    EditDocument *	ed= ea->eaCurrentDocument;
    TedDocument *	td;

    TableRectangle	tr;

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

    tr= ct->ctTableRectangle;
    td= (TedDocument *)ed->edPrivateData;

    docExpandTableRectangleToWholeColumns( &tr );

    if  ( docShiftTableRectangleByColumns( &tr, -1 ) )
	{ return;	}

    tedAppSetTableSelection( ed, &tr );

    return;
    }

static void tedTableSelectColumn(	APP_WIDGET	w,
					void *		voidct,
					void *		voidpbcs	 )
    {
    ColumnTool *	ct= (ColumnTool *)voidct;
    EditApplication *	ea= ct->ctApplication;
    EditDocument *	ed= ea->eaCurrentDocument;
    TedDocument *	td;

    TableRectangle	tr;

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

    tr= ct->ctTableRectangle;
    td= (TedDocument *)ed->edPrivateData;

    docExpandTableRectangleToWholeColumns( &tr );

    tedAppSetTableSelection( ed, &tr );

    return;
    }

static void tedColumnNextColumn(		APP_WIDGET	w,
					void *		voidct,
					void *		voidpbcs	 )
    {
    ColumnTool *	ct= (ColumnTool *)voidct;
    EditApplication *	ea= ct->ctApplication;
    EditDocument *	ed= ea->eaCurrentDocument;
    TedDocument *	td;

    TableRectangle	tr;

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

    tr= ct->ctTableRectangle;
    td= (TedDocument *)ed->edPrivateData;

    docExpandTableRectangleToWholeColumns( &tr );

    if  ( docShiftTableRectangleByColumns( &tr, +1 ) )
	{ return;	}

    tedAppSetTableSelection( ed, &tr );

    return;
    }

/************************************************************************/
/*									*/
/*  Delete Column/Row/Table buttons have been pushed.			*/
/*									*/
/************************************************************************/

static void tedTableDeleteColumn(	APP_WIDGET	w,
					void *		voidct,
					void *		voidpbcs	 )
    {
    ColumnTool *		ct= (ColumnTool *)voidct;
    const TableRectangle *	tr= &(ct->ctTableRectangle);
    EditApplication *		ea= ct->ctApplication;
    EditDocument *		ed= ea->eaCurrentDocument;

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

    if  ( tedDeleteColumnsFromRows( ed,
		tr->trRow00, tr->trRow11, tr->trCol0, tr->trCol1 ) )
	{ LLDEB(tr->trRow00,tr->trRow11); return;	}

    appDocumentChanged( ed, 1 );

    return;
    }

/************************************************************************/
/*									*/
/*  Insert/Append Column/Row buttons have been pushed.			*/
/*									*/
/************************************************************************/

static void tedTableInsertColumn(	APP_WIDGET	w,
					void *		voidct,
					void *		voidpbcs	 )
    {
    ColumnTool *	ct= (ColumnTool *)voidct;
    EditApplication *	ea= ct->ctApplication;

    EditDocument *	ed= ea->eaCurrentDocument;

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

    tedInsertColumnInTable( ed );

    appDocumentChanged( ed, 1 );
    }

static void tedTableAppendColumn(	APP_WIDGET	w,
					void *		voidct,
					void *		voidpbcs	 )
    {
    ColumnTool *	ct= (ColumnTool *)voidct;
    EditApplication *	ea= ct->ctApplication;

    EditDocument *	ed= ea->eaCurrentDocument;

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

    tedAppendColumnToTable( ed );

    appDocumentChanged( ed, 1 );
    }

/************************************************************************/
/*									*/
/*  One of the 'Column Border' toggles has been activated.		*/
/*									*/
/************************************************************************/

static void tedColumnToggleBorder(	APP_WIDGET	w,
					void *		voidct,
					void *		voidtbcs )
    {
    ColumnTool *		ct= (ColumnTool *)voidct;
    RowProperties *		rp= &(ct->ctPropertiesChosen);
    const TableRectangle *	tr= &(ct->ctTableRectangle);
    CellProperties *		cp= &(rp->rpCells[tr->trCol0]);

    int				set;

    const int			influenceStyleMenu= 1;

    set= appGuiGetToggleStateFromCallback( w, voidtbcs );

    if  ( w == ct->ctLeftBorderTool.btOnOffToggle )
	{
	tedFormatToggleBorder( &(cp->cpLeftBorder), &(ct->ctLeftBorderTool),
						    influenceStyleMenu, set );
	return;
	}

    if  ( w == ct->ctRightBorderTool.btOnOffToggle )
	{
	tedFormatToggleBorder( &(cp->cpRightBorder), &(ct->ctRightBorderTool),
						    influenceStyleMenu, set );
	return;
	}

    XDEB(w); return;
    }

/************************************************************************/
/*									*/
/*  Make a column tool, I.E. the 'Column' page of the format tool.	*/
/*									*/
/************************************************************************/

void tedFormatFillColumnPage(	ColumnTool *			ct,
				const ColumnPageResources *	cpr,
				InspectorSubject *		is,
				APP_WIDGET			pageWidget,
				const InspectorSubjectResources * isr )
    {
    APP_WIDGET	widthLabel;
    APP_WIDGET	columnLabel;

    APP_WIDGET	row= (APP_WIDGET)0;

    const int	textColumns= 10;

    /**/
    ct->ctPageResources= cpr;

    /**/

    docInitTableRectangle( &(ct->ctTableRectangle) );

    docInitRowProperties( &(ct->ctPropertiesSet) );
    docInitRowProperties( &(ct->ctPropertiesChosen) );

    /**/
    appMakeLabelAndTextRow( &row, &columnLabel, &(ct->ctNumberText),
			    pageWidget, isr->isrSubjectName, textColumns, 0 );

    appMakeLabelAndTextRow( &row, &widthLabel, &(ct->ctWidthText),
			pageWidget, cpr->cprWidth, textColumns, 1 );

    appGuiSetGotValueCallbackForText( ct->ctWidthText,
					tedColumnWidthChanged, (void *)ct );

    tedFormatMakeBorderTool( &(ct->ctLeftBorderTool), &row, pageWidget,
		    cpr->cprLeftBorder, tedColumnToggleBorder, (void *)ct );

    tedFormatMakeBorderTool( &(ct->ctRightBorderTool), &row, pageWidget,
		    cpr->cprRightBorder, tedColumnToggleBorder, (void *)ct );

    appInspectorMakeButtonRow( &row, pageWidget,
		    &(is->isPrevButton), &(is->isNextButton),
		    isr->isrPrevButtonText, isr->isrNextButtonText,
		    tedColumnPreviousColumn, tedColumnNextColumn, ct );

    appInspectorMakeButtonRow( &row, pageWidget,
		    &(is->isSelectButton), &(is->isDeleteButton),
		    isr->isrSelectButtonText, isr->isrDeleteButtonText,
		    tedTableSelectColumn, tedTableDeleteColumn, ct );

    appInspectorMakeButtonRow( &row, pageWidget,
		    &(is->isInsertButton), &(is->isAppendButton),
		    isr->isrInsertButtonText, isr->isrAppendButtonText,
		    tedTableInsertColumn, tedTableAppendColumn, ct );

    appInspectorMakeButtonRow( &row, pageWidget,
		    &(is->isRevertButton), &(is->isApplyButton),
		    isr->isrRevert, isr->isrApplyToSubject,
		    tedFormatRevertColumnPushed, tedTableChangeColumnPushed,
		    (void *)ct );

    return;
    }

void tedFormatFillColumnChoosers(	ColumnTool *			ct,
					const ColumnPageResources *	cpr )
    {
    tedFormatFillBorderTool( &(ct->ctLeftBorderTool),
				    tedColumnBorderStyleChosen, (void *)ct );
    tedFormatFillBorderTool( &(ct->ctRightBorderTool),
				    tedColumnBorderStyleChosen, (void *)ct );
    return;
    }

void tedFormatFinishColumnPage(		ColumnTool *			ct,
					TedFormatTool *			tft,
					const ColumnPageResources *	cpr )
    {
    tedFormatFinishBorderTool( &(ct->ctLeftBorderTool), tft );
    tedFormatFinishBorderTool( &(ct->ctRightBorderTool), tft );
    }

/************************************************************************/
/*									*/
/*  Get column tool resources.						*/
/*									*/
/************************************************************************/

static AppConfigurableResource TED_TedColumnSubjectResourceTable[]=
    {
    APP_RESOURCE( "tableToolColumn",
		offsetof(InspectorSubjectResources,isrSubjectName),
		"Column" ),
    APP_RESOURCE( "tableToolChangeColumn",
		offsetof(InspectorSubjectResources,isrApplyToSubject),
		"Apply to Column" ),
    APP_RESOURCE( "tableToolRevert",
		offsetof(InspectorSubjectResources,isrRevert),
		"Revert" ),
    APP_RESOURCE( "tableToolNextColumn",
		offsetof(InspectorSubjectResources,isrNextButtonText),
		"Next Column" ),
    APP_RESOURCE( "tableToolPreviousColumn",
		offsetof(InspectorSubjectResources,isrPrevButtonText),
		"Previous Column" ),
    APP_RESOURCE( "tableToolSelectColumn",
		offsetof(InspectorSubjectResources,isrSelectButtonText),
		"Select Column" ),
    APP_RESOURCE( "tableToolDeleteColumn",
		offsetof(InspectorSubjectResources,isrDeleteButtonText),
		"Delete Column" ),
    APP_RESOURCE( "tableToolInsertColumn",
		offsetof(InspectorSubjectResources,isrInsertButtonText),
		"Insert Column" ),
    APP_RESOURCE( "tableToolAppendColumn",
		offsetof(InspectorSubjectResources,isrAppendButtonText),
		"Append Column" ),
    };

static AppConfigurableResource TED_TedColumnToolResourceTable[]=
    {
    APP_RESOURCE( "tableToolWidth",
		offsetof(ColumnPageResources,cprWidth),
		"Width" ),
    APP_RESOURCE( "tableToolColumnLeftBorder",
		offsetof(ColumnPageResources,cprLeftBorder),
		"Left Border" ),
    APP_RESOURCE( "tableToolColumnRightBorder",
		offsetof(ColumnPageResources,cprRightBorder),
		"Right Border" ),
    };

void tedFormatToolGetColumnResourceTable(EditApplication *		ea,
					ColumnPageResources *		cpr,
					InspectorSubjectResources *	isr )
    {
    appGuiGetResourceValues( ea, (void *)cpr,
				TED_TedColumnToolResourceTable,
				sizeof(TED_TedColumnToolResourceTable)/
				sizeof(AppConfigurableResource) );

    appGuiGetResourceValues( ea, (void *)isr,
				TED_TedColumnSubjectResourceTable,
				sizeof(TED_TedColumnSubjectResourceTable)/
				sizeof(AppConfigurableResource) );

    return;
    }