File: tedHeightTool.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 (220 lines) | stat: -rw-r--r-- 5,002 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
/************************************************************************/
/*									*/
/*  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 a height chooser.						*/
/*									*/
/************************************************************************/

void tedFormatRefreshHeightChooser(	HeightChooser *	hc,
					int		height )
    {
    char		scratch[50];

    if  ( height == 0 )
	{
	appEnableText( hc->hcText, 0 );

	hc->hcHow= HC_FREE;
	appStringToTextWidget( hc->hcText, "" );
	}
    else{
	appEnableText( hc->hcText, 1 );

	if  ( height > 0 )
	    {
	    hc->hcHow= HC_AT_LEAST;
	    appGeoLengthToString( scratch,  height, UNITtyPOINTS );
	    }
	else{
	    hc->hcHow= HC_EXACTLY;
	    appGeoLengthToString( scratch, -height, UNITtyPOINTS );
	    }

	appStringToTextWidget( hc->hcText, scratch );
	}

    appSetOptionmenu( &(hc->hcOptionmenu), hc->hcHow );
    }

int tedFormatToolGetHeight(	int *		pHeight,
				HeightChooser *	hc )
    {
    int			sign;

    int			height;
    int			changed;

    const int		minValue= 1;
    const int		adaptToMin= 0;
    const int		maxValue= INT_MAX;
    const int		adaptToMax= 0;

    switch( hc->hcHow )
	{
	case HC_FREE:
	    sign= height= 0;
	    break;
	case HC_AT_LEAST:
	    sign=  1;
	    break;
	case HC_EXACTLY:
	    sign= -1;
	    break;
	default:
	    LDEB(hc->hcHow); return -1;
	}

    height= *pHeight;
    height *= sign;

    if  ( sign != 0 )
	{
	if  ( appGetLengthFromTextWidget( hc->hcText,
				&height, &changed, UNITtyPOINTS,
				minValue, adaptToMin, maxValue, adaptToMax ) )
	    { return -1; }

	height *= sign;
	}

    *pHeight= height;

    return 0;
    }

/************************************************************************/
/*									*/
/*  Callback for a height chooser.					*/
/*									*/
/************************************************************************/

void tedFormatHeightChosen(	APP_WIDGET		w,
				HeightChooser *		hc,
				int			defaultValue )
    {
    char		scratch[50];
    int			val;
    int			how;

    for ( how= 0; how < HC__COUNT; how++ )
	{
	if  ( hc->hcMenuItems[how] == w )
	    { break;	}
	}

    if  ( how < 0 || how >= HC__COUNT )
	{ LDEB(how); return;	}

    switch( how )
	{
	case HC_FREE:
	    appEnableText( hc->hcText, 0 );
	    appStringToTextWidget( hc->hcText, "" );
	    hc->hcHow= how;
	    return;

	case HC_AT_LEAST:
	    appEnableText( hc->hcText, 1 );
	    val= defaultValue;
	    if  ( val < 0 )
		{ val= -val;	}
	    appGeoLengthToString( scratch, val, UNITtyPOINTS );
	    appStringToTextWidget( hc->hcText, scratch );
	    hc->hcHow= how;
	    return;

	case HC_EXACTLY:
	    appEnableText( hc->hcText, 1 );
	    val= defaultValue;
	    appGeoLengthToString( scratch, val, UNITtyPOINTS );
	    appStringToTextWidget( hc->hcText, scratch );
	    hc->hcHow= how;
	    return;

	default:
	    LDEB(how); return;
	}

    LDEB(1);
    }

void tedFormatMakeHeightRow(	APP_WIDGET *		pRow,
				void *			through,
				APP_WIDGET		parent,
				HeightChooser *		hc,
				APP_CALLBACK_FUNC	callback )
    {
    APP_WIDGET	row;
    APP_WIDGET	text;

    const int	menuColumn= 0;
    const int	menuColspan= 1;
    const int	textColumn= menuColumn+ menuColspan;
    const int	textColspan= 1;
    const int	heightResizable= 0;

    row= appMakeRowInColumn( parent, 2, heightResizable );

    appMakeOptionmenuInRow( &(hc->hcOptionmenu), row, menuColumn, menuColspan );

    appMakeTextInRow( &text, row, textColumn, textColspan, 10, 0 );

    if  ( callback )
	{ appGuiSetGotValueCallbackForText( text, callback, through ); }

    *pRow= row;
    hc->hcText= text;

    return;
    }

/************************************************************************/
/*									*/
/*  Fill the menu in a height chooser.					*/
/*									*/
/************************************************************************/

void tedFormatFillHeightChooser(	HeightChooser *		hc,
					APP_CALLBACK_FUNC	callback,
					void *			voidtft,
					const char *		freeText,
					const char *		atLeastText,
					const char *		exactlyText )
    {
    appEmptyOptionmenu( &(hc->hcOptionmenu) );

    hc->hcMenuItems[HC_FREE]= appAddItemToOptionmenu( &(hc->hcOptionmenu),
				    freeText, callback, voidtft );

    hc->hcMenuItems[HC_AT_LEAST]= appAddItemToOptionmenu( &(hc->hcOptionmenu),
				    atLeastText, callback, voidtft );

    hc->hcMenuItems[HC_EXACTLY]= appAddItemToOptionmenu( &(hc->hcOptionmenu),
				    exactlyText, callback, voidtft );

    appSetOptionmenu( &(hc->hcOptionmenu), HC_FREE );
    hc->hcHow= HC_FREE;

    appOptionmenuRefreshWidth( &(hc->hcOptionmenu) );
    }