1 /*
2 * This file is part of XForms.
3 *
4 * XForms is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation; either version 2.1, or
7 * (at your option) any later version.
8 *
9 * XForms is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with XForms. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18
19 /**
20 * \file sp_slider.c
21 *
22 * This file is part of XForms package
23 * Copyright (c) 1996-2002 T.C. Zhao and Mark Overmars
24 * All rights reserved.
25 *
26 * Settting slider class specific attributes.
27 */
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include "fd_main.h"
34 #include "fd_spec.h"
35 #include "sp_slider.h"
36 #include "spec/slider_spec.h"
37 #include "private/pslider.h"
38
39
40 static FD_sliderattrib * sl_attrib;
41 static FL_OBJECT * curobj;
42
43
44 /***************************************
45 ***************************************/
46
47 FL_FORM *
slider_create_spec_form(void)48 slider_create_spec_form( void )
49 {
50 if ( sl_attrib )
51 return sl_attrib->sliderattrib;
52
53 sl_attrib = create_form_sliderattrib( );
54
55 setup_how_return_menu( sl_attrib->returnsetting );
56 fl_set_menu_item_mode( sl_attrib->returnsetting, 5,
57 FL_PUP_BOX | FL_PUP_GRAY );
58 fl_set_menu_item_mode( sl_attrib->returnsetting, 6,
59 FL_PUP_BOX | FL_PUP_GRAY );
60
61 fl_set_counter_step( sl_attrib->prec, 1, 2 );
62 fl_set_counter_precision( sl_attrib->prec, 0 );
63 fl_set_counter_bounds( sl_attrib->prec, 0, FL_SLIDER_MAX_PREC );
64
65 return sl_attrib->sliderattrib;
66 }
67
68
69 /***************************************
70 ***************************************/
71
72 void
slider_adjust_spec_form(FL_OBJECT * obj)73 slider_adjust_spec_form( FL_OBJECT * obj )
74 {
75 curobj = obj;
76
77 if ( obj->objclass == FL_VALSLIDER )
78 fl_show_object( sl_attrib->prec );
79 else
80 fl_hide_object( sl_attrib->prec );
81
82 if ( obj->type & FL_HOR_FLAG )
83 {
84 fl_set_object_label( sl_attrib->minval, "Value at left" );
85 fl_set_object_label( sl_attrib->maxval, "Value at right" );
86 }
87 else
88 {
89 fl_set_object_label( sl_attrib->minval, "Value at top" );
90 fl_set_object_label( sl_attrib->maxval, "Value at bottom" );
91 }
92 }
93
94
95 /***************************************
96 ***************************************/
97
98 void
slider_fill_in_spec_form(FL_OBJECT * obj)99 slider_fill_in_spec_form( FL_OBJECT * obj )
100 {
101 FLI_SLIDER_SPEC *sp = obj->spec;
102
103 set_finput_value( sl_attrib->minval, sp->min, sp->prec );
104 set_finput_value( sl_attrib->maxval, sp->max, sp->prec );
105 set_finput_value( sl_attrib->initial_val, sp->val, sp->prec );
106 set_finput_value( sl_attrib->slsize, sp->slsize, 2 );
107 set_finput_value( sl_attrib->step, sp->step, 3 );
108 set_finput_value( sl_attrib->ldelta, sp->ldelta, -1 );
109 set_finput_value( sl_attrib->rdelta, sp->rdelta, -1 );
110 fl_set_counter_value( sl_attrib->prec, sp->prec );
111
112 reset_how_return_menu( sl_attrib->returnsetting, curobj->how_return );
113 }
114
115
116 /***************************************
117 ***************************************/
118
119 void
slider_emit_spec_fd_code(FILE * fp,FL_OBJECT * obj)120 slider_emit_spec_fd_code( FILE * fp,
121 FL_OBJECT * obj )
122 {
123 FL_OBJECT *defobj = ( obj->objclass == FL_SLIDER ?
124 fl_create_slider : fl_create_valslider )
125 ( obj->type, 0, 0, 0, 0, "" );
126 FLI_SLIDER_SPEC *sp = obj->spec,
127 *defsp = defobj->spec;
128
129 if ( sp->min != defsp->min || sp->max != defsp->max )
130 fprintf( fp, " bounds: %g %g\n", sp->min, sp->max );
131 if ( sp->prec != defsp->prec )
132 fprintf( fp, " precision: %d\n", sp->prec );
133 if ( sp->val != defsp->val )
134 fprintf( fp, " value: %g\n", sp->val );
135 if ( sp->ldelta != defsp->ldelta || sp->rdelta != defsp->rdelta )
136 fprintf( fp, " increment: %g %g\n", sp->ldelta, sp->rdelta );
137 if ( sp->slsize != defsp->slsize )
138 fprintf( fp, " slsize: %.2f\n", sp->slsize );
139 if ( sp->step != defsp->step )
140 fprintf( fp, " step: %g\n", sp->step );
141
142 fl_free_object( defobj );
143 }
144
145
146 /***************************************
147 ***************************************/
148
149 void
slider_reread_spec_form(FL_OBJECT * obj)150 slider_reread_spec_form( FL_OBJECT * obj )
151 {
152 double r1, r2;
153
154 if ( get_checked_float( fl_get_input( sl_attrib->minval ), &r1 )
155 && get_checked_float( fl_get_input( sl_attrib->maxval ), &r2 ) )
156 fl_set_slider_bounds( obj, r1, r2 );
157
158 if ( get_checked_float( fl_get_input( sl_attrib->initial_val ), &r1 ) )
159 fl_set_slider_value( obj, r1 );
160
161 if ( get_checked_float( fl_get_input( sl_attrib->step ), &r1 ) )
162 fl_set_slider_step( obj, r1 );
163
164 if ( get_checked_float( fl_get_input( sl_attrib->slsize ), &r1 ) )
165 fl_set_slider_size( obj, r1 );
166
167 if ( get_checked_float( fl_get_input( sl_attrib->ldelta ), &r1 )
168 && get_checked_float( fl_get_input( sl_attrib->ldelta ), &r2 ) )
169 fl_set_slider_increment( obj, r1, r2 );
170
171 redraw_the_form( 0 );
172 }
173
174
175 /***************************************
176 ***************************************/
177
178 void
slider_emit_spec_c_code(FILE * fp,FL_OBJECT * obj)179 slider_emit_spec_c_code( FILE * fp,
180 FL_OBJECT * obj )
181 {
182 FL_OBJECT *defobj = ( obj->objclass == FL_SLIDER ?
183 fl_create_slider : fl_create_valslider )
184 ( obj->type, 0, 0, 0, 0, "" );
185 FLI_SLIDER_SPEC *sp = obj->spec,
186 *defsp = defobj->spec;
187
188 if ( sp->prec != defsp->prec )
189 fprintf( fp, " fl_set_slider_precision( obj, %d );\n", sp->prec );
190
191 if ( sp->min != defsp->min || sp->max != defsp->max )
192 fprintf( fp, " fl_set_slider_bounds( obj, %g, %g );\n",
193 sp->min, sp->max );
194
195 if ( sp->val != defsp->val )
196 fprintf( fp, " fl_set_slider_value( obj, %g );\n", sp->val );
197
198 if ( sp->slsize != defsp->slsize )
199 fprintf( fp, " fl_set_slider_size( obj, %.2f );\n", sp->slsize );
200
201 if ( sp->step != defsp->step )
202 fprintf( fp, " fl_set_slider_step( obj, %g );\n", sp->step );
203
204 if ( sp->ldelta != defsp->ldelta || sp->rdelta != defsp->rdelta )
205 fprintf( fp, " fl_set_slider_increment( obj, %g, %g );\n",
206 sp->ldelta, sp->rdelta );
207
208
209 fl_free_object( defobj );
210 }
211
212
213 /***************************************
214 ***************************************/
215
216 void
adjust_precision(FL_OBJECT * ob,long data FL_UNUSED_ARG)217 adjust_precision( FL_OBJECT * ob,
218 long data FL_UNUSED_ARG )
219 {
220 fl_set_slider_precision( curobj, fl_get_counter_value( ob ) );
221 redraw_the_form( 0 );
222 }
223
224
225 /***************************************
226 ***************************************/
227
228 void
minmax_change(FL_OBJECT * ob FL_UNUSED_ARG,long data FL_UNUSED_ARG)229 minmax_change( FL_OBJECT * ob FL_UNUSED_ARG,
230 long data FL_UNUSED_ARG )
231 {
232 fl_set_slider_bounds( curobj,
233 get_finput_value( sl_attrib->minval ),
234 get_finput_value( sl_attrib->maxval ) );
235 redraw_the_form( 0 );
236 }
237
238
239 /***************************************
240 ***************************************/
241
242 void
slsize_change(FL_OBJECT * obj,long data FL_UNUSED_ARG)243 slsize_change( FL_OBJECT * obj,
244 long data FL_UNUSED_ARG )
245 {
246 fl_set_slider_size( curobj, get_finput_value( obj ) );
247 redraw_the_form( 0 );
248 }
249
250
251 /***************************************
252 ***************************************/
253
254 void
step_change(FL_OBJECT * obj,long data FL_UNUSED_ARG)255 step_change( FL_OBJECT * obj,
256 long data FL_UNUSED_ARG )
257 {
258 FLI_SLIDER_SPEC *sp = curobj->spec;
259
260 set_finput_value( obj, get_finput_value( obj ), sp->prec );
261 fl_set_slider_step( curobj, get_finput_value( obj ) );
262 redraw_the_form( 0 );
263 }
264
265
266 /***************************************
267 ***************************************/
268
269 void
increment_change(FL_OBJECT * ob FL_UNUSED_ARG,long data FL_UNUSED_ARG)270 increment_change( FL_OBJECT * ob FL_UNUSED_ARG,
271 long data FL_UNUSED_ARG )
272 {
273 fl_set_slider_increment( curobj,
274 get_finput_value( sl_attrib->ldelta ),
275 get_finput_value( sl_attrib->rdelta ) );
276 }
277
278
279 /***************************************
280 ***************************************/
281
282 void
initialvalue_change(FL_OBJECT * obj,long data FL_UNUSED_ARG)283 initialvalue_change( FL_OBJECT * obj,
284 long data FL_UNUSED_ARG )
285 {
286 FLI_SLIDER_SPEC *sp = curobj->spec;
287
288 set_finput_value( obj, get_finput_value( obj ), sp->prec );
289 fl_set_slider_value( curobj, get_finput_value( obj ) );
290 redraw_the_form( 0 );
291 }
292
293
294 /***************************************
295 ***************************************/
296
297 void
returnsetting_change(FL_OBJECT * obj,long data FL_UNUSED_ARG)298 returnsetting_change( FL_OBJECT * obj,
299 long data FL_UNUSED_ARG )
300 {
301 handle_how_return_changes( obj, curobj );
302 }
303
304
305 #include "spec/slider_spec.c"
306
307
308 /*
309 * Local variables:
310 * tab-width: 4
311 * indent-tabs-mode: nil
312 * End:
313 */
314