File: tedTableTool.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 (335 lines) | stat: -rw-r--r-- 9,475 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
/************************************************************************/
/*									*/
/*  A Format Tool.							*/
/*									*/
/************************************************************************/

#   include	"tedConfig.h"

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

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

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

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

static void tedFormatToolRefreshTablePage(	TableTool *	tt )
    {
    RowProperties *	rp= &(tt->ttPropertiesChosen);

    char		scratch[50];

    appGeoLengthToString( scratch, rp->rpHalfGapWidthTwips, UNITtyPOINTS );
    appStringToTextWidget( tt->ttCellMarginText, scratch );

    appGeoLengthToString( scratch, rp->rpLeftIndentTwips, UNITtyPOINTS );
    appStringToTextWidget( tt->ttLeftIndentText, scratch );
    }

void tedFormatToolRefreshTableTool(
			    TableTool *			tt,
			    int *			pEnabled,
			    InspectorSubject *		is,
			    const DocumentSelection *	ds )
    {
    const RowProperties *	rp;
    const DocumentGeometry *	dg;

    const BufferItem *		rowBi;
    const BufferItem *		sectBi;

    if  ( tedGetTableRectangle( &(tt->ttTableRectangle), ds ) )
	{
	docInitTableRectangle( &(tt->ttTableRectangle) );
	*pEnabled= 0; return;
	}

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

    dg= &(sectBi->biSectDocumentGeometry);

    tt->ttPageRight= dg->dgPageWideTwips-
			    dg->dgLeftMarginTwips- dg->dgRightMarginTwips;
    tt->ttPageLeftMargin= dg->dgLeftMarginTwips;

    rp= &(rowBi->biRowProperties);

    if  ( docCopyRowProperties( &(tt->ttPropertiesChosen), rp ) )
	{ LDEB(1); return;	}
    if  ( docCopyRowProperties( &(tt->ttPropertiesSet), rp ) )
	{ LDEB(1); return;	}

    tedFormatToolRefreshTablePage( tt );

    *pEnabled= 1;
    return;
    }

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

static void tedTableChangeTablePushed(	APP_WIDGET	w,
					void *		voidtt,
					void *		voidpbcs	 )
    {
    TableTool *			tt= (TableTool *)voidtt;
    RowProperties *		rp= &(tt->ttPropertiesChosen);
    const TableRectangle *	tr= &(tt->ttTableRectangle);

    int				width;
    int				res;

    res= tedFormatToolGetRowLeftIndent( rp, tt->ttPageLeftMargin,
					    &width, tt->ttLeftIndentText );
    if  ( res != 0 )
	{ return;	}
    rp->rpLeftIndentTwips= width;

    res= tedFormatToolGetGapWidth( rp, &width, tt->ttCellMarginText );
    if  ( res != 0 )
	{ return;	}
    rp->rpHalfGapWidthTwips= width;

    tedAppSetTableProperties( tt->ttApplication, tr, rp );

    return;
    }

static void tedFormatRevertTablePushed(	APP_WIDGET	w,
					void *		voidtt,
					void *		voidpbcs )
    {
    TableTool *	tt= (TableTool *)voidtt;

    docCopyRowProperties( &(tt->ttPropertiesChosen), &(tt->ttPropertiesSet) );

    tedFormatToolRefreshTablePage( tt );

    return;
    }

/************************************************************************/
/*									*/
/*  Check the cell margin that was entered on the 'Table' page of the	*/
/*  format tool.							*/
/*									*/
/************************************************************************/

static void tedTableCellMarginChanged(	APP_WIDGET	w,
					void *		voidtt,
					void *		voidpbcs )
    {
    TableTool *		tt= (TableTool *)voidtt;
    RowProperties *	rp= &(tt->ttPropertiesChosen);

    int			value;

    if  ( ! tedFormatToolGetGapWidth( rp, &value, tt->ttCellMarginText ) )
	{
	char	scratch[50];

	appGeoLengthToString( scratch, value, UNITtyPOINTS );
	appStringToTextWidget( tt->ttCellMarginText, scratch );
	}
    }

/************************************************************************/
/*									*/
/*  Check the left indent that was entered on the 'Table' page of the	*/
/*  format tool.							*/
/*									*/
/************************************************************************/

static void tedTableLeftIndentChanged(	APP_WIDGET	w,
					void *		voidtt,
					void *		voidpbcs )
    {
    TableTool *		tt= (TableTool *)voidtt;
    RowProperties *	rp= &(tt->ttPropertiesChosen);

    int			value;

    if  ( ! tedFormatToolGetRowLeftIndent( rp, tt->ttPageLeftMargin, &value,
						    tt->ttLeftIndentText ) )
	{
	char	scratch[50];

	appGeoLengthToString( scratch, value, UNITtyPOINTS );
	appStringToTextWidget( tt->ttLeftIndentText, scratch );
	}
    }

/************************************************************************/
/*									*/
/*  Delete/Select Table buttons have been pushed.			*/
/*									*/
/************************************************************************/

static void tedTableDeleteTable(	APP_WIDGET	w,
					void *		voidtt,
					void *		voidpbcs )
    {
    TableTool *			tt= (TableTool *)voidtt;
    EditApplication *		ea= tt->ttApplication;
    EditDocument *		ed= ea->eaCurrentDocument;

    const TableRectangle *	tr= &(tt->ttTableRectangle);

    if  ( tedDeleteRowsFromTable( ed, tr->trRow00, tr->trRow11 ) )
	{ LLDEB(tr->trRow00,tr->trRow11); return;	}

    appDocumentChanged( ed, 1 );

    return;
    }

static void tedTableSelectTable(	APP_WIDGET	w,
					void *		voidtt,
					void *		voidpbcs )
    {
    TableTool *			tt= (TableTool *)voidtt;
    EditApplication *		ea= tt->ttApplication;
    EditDocument *		ed= ea->eaCurrentDocument;
    TedDocument *		td;

    TableRectangle		trSet= tt->ttTableRectangle;

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

    td= (TedDocument *)ed->edPrivateData;

    docExpandTableRectangleToWholeTable( &trSet );

    tedAppSetTableSelection( ed, &trSet );
    }

/************************************************************************/
/*									*/
/*  Make the 'Table' page of the format tool.				*/
/*									*/
/************************************************************************/

void tedFormatFillTablePage(	TableTool *			tt,
				const TablePageResources *	tpr,
				InspectorSubject *		is,
				APP_WIDGET			pageWidget,
				const InspectorSubjectResources * isr )
    {
    APP_WIDGET	widthLabel;
    APP_WIDGET	leftLabel;

    APP_WIDGET	row= (APP_WIDGET )0;

    const int	textColumns= 10;

    /**/
    tt->ttPageResources= tpr;

    /**/
    docInitTableRectangle( &(tt->ttTableRectangle) );

    docInitRowProperties( &(tt->ttPropertiesSet) );
    docInitRowProperties( &(tt->ttPropertiesChosen) );

    /**************/
    appMakeLabelAndTextRow( &row, &leftLabel, &(tt->ttLeftIndentText),
			pageWidget, tpr->tprLeftIndent, textColumns, 1 );

    appGuiSetGotValueCallbackForText( tt->ttLeftIndentText,
				tedTableLeftIndentChanged, (void *)tt );

    /**************/
    appMakeLabelAndTextRow( &row, &widthLabel, &(tt->ttCellMarginText),
		    pageWidget, tpr->tprCellMargin, textColumns, 1 );

    appGuiSetGotValueCallbackForText( tt->ttCellMarginText,
				tedTableCellMarginChanged, (void *)tt );

    /**************/
    appInspectorMakeButtonRow( &row, pageWidget,
		&(is->isSelectButton), &(is->isDeleteButton),
		isr->isrSelectButtonText, isr->isrDeleteButtonText,
		tedTableSelectTable, tedTableDeleteTable, (void *)tt );

    appInspectorMakeButtonRow( &row, pageWidget,
		&(is->isRevertButton), &(is->isApplyButton),
		isr->isrRevert, isr->isrApplyToSubject,
		tedFormatRevertTablePushed, tedTableChangeTablePushed,
		(void *)tt );

    return;
    }

/************************************************************************/
/*									*/
/*  Get Table tool resources.						*/
/*									*/
/************************************************************************/

static AppConfigurableResource TED_TedTableSubjectResourceTable[]=
    {
    APP_RESOURCE( "tableToolTable",
		offsetof(InspectorSubjectResources,isrSubjectName),
		"Table" ),
    APP_RESOURCE( "tableToolChangeTable",
		offsetof(InspectorSubjectResources,isrApplyToSubject),
		"Apply to Table" ),
    APP_RESOURCE( "tableToolRevert",
		offsetof(InspectorSubjectResources,isrRevert),
		"Revert" ),
    /*  no Next Table */
    /*  no Prev Table */
    APP_RESOURCE( "tableToolSelectTable",
		offsetof(InspectorSubjectResources,isrSelectButtonText),
		"Select Table" ),
    APP_RESOURCE( "tableToolDeleteTable",
		offsetof(InspectorSubjectResources,isrDeleteButtonText),
		"Delete Table" ),
    /*  no Insert Table */
    /*  no Append Table */
    };

static AppConfigurableResource TED_TedTableToolResourceTable[]=
    {
    /**/
    APP_RESOURCE( "tableToolCellMargin",
		    offsetof(TablePageResources,tprCellMargin),
		    "Cell Margin" ),
    APP_RESOURCE( "tableToolLeftIndent",
		    offsetof(TablePageResources,tprLeftIndent),
		    "Left Margin" ),
    };

void tedFormatToolGetTableResourceTable( EditApplication *		ea,
					TablePageResources *		tpr,
					InspectorSubjectResources *	isr )
    {
    appGuiGetResourceValues( ea, (void *)tpr,
				TED_TedTableToolResourceTable,
				sizeof(TED_TedTableToolResourceTable)/
				sizeof(AppConfigurableResource) );

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

    return;
    }