File: sp_slider.c

package info (click to toggle)
libforms 1.0.93sp1-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 11,548 kB
  • sloc: ansic: 97,227; sh: 9,236; makefile: 858
file content (341 lines) | stat: -rw-r--r-- 9,381 bytes parent folder | download | duplicates (2)
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
/*
 * This file is part of XForms.
 *
 *  XForms is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU Lesser General Public License as
 *  published by the Free Software Foundation; either version 2.1, or
 *  (at your option) any later version.
 *
 *  XForms is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with XForms.  If not, see <http://www.gnu.org/licenses/>.
 */


/**
 * \file sp_slider.c
 *
 *  This file is part of XForms package
 *  Copyright (c) 1996-2002  T.C. Zhao and Mark Overmars
 *  All rights reserved.
 *
 * Settting slider class specific attributes.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "include/forms.h"
#include "fd_main.h"
#include "fd_spec.h"
#include "spec/slider_spec.h"

extern FD_sliderattrib *create_form_sliderattrib( void );

static FD_sliderattrib *sl_attrib;
static SuperSPEC *slider_spec;
static void show_spec( SuperSPEC * );


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

void *
get_slider_spec_fdform( void )
{
    if ( ! sl_attrib )
    {
        sl_attrib = create_form_sliderattrib( );

        setup_how_return_menu( sl_attrib->returnsetting );
        fl_set_menu_item_mode( sl_attrib->returnsetting, 5,
                               FL_PUP_BOX | FL_PUP_GRAY );
        fl_set_menu_item_mode( sl_attrib->returnsetting, 6,
                               FL_PUP_BOX | FL_PUP_GRAY );
    }
    return sl_attrib;
}


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

void
slider_spec_restore( FL_OBJECT * ob    FL_UNUSED_ARG,
                     long        data  FL_UNUSED_ARG )
{
    FL_OBJECT *edit_obj = sl_attrib->vdata;

    superspec_to_spec( edit_obj );
    show_spec( get_superspec( edit_obj ) );
    redraw_the_form( 0 );
}


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

static void
show_spec( SuperSPEC * spec )
{
    set_finput_value( sl_attrib->minval, spec->min, spec->prec );
    set_finput_value( sl_attrib->maxval, spec->max, spec->prec );
    set_finput_value( sl_attrib->initial_val, spec->val, spec->prec );
    set_finput_value( sl_attrib->slsize, spec->slsize, 2 );
    set_finput_value( sl_attrib->step, spec->step, 3 );
    set_finput_value( sl_attrib->ldelta, spec->ldelta, -1 );
    set_finput_value( sl_attrib->rdelta, spec->rdelta, -1 );

    fl_set_counter_value( sl_attrib->prec, spec->prec );

    reset_how_return_menu( sl_attrib->returnsetting, spec->how_return );
}


#define is_vert(t)     (    t == FL_VERT_SLIDER          \
                         || t == FL_VERT_NICE_SLIDER     \
                         || t == FL_VERT_BROWSER_SLIDER  \
                         || t == FL_VERT_FILL_SLIDER )


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

int
set_slider_attrib( FL_OBJECT * ob )
{
    sl_attrib->vdata = ob;
    slider_spec = get_superspec( ob );

    fl_freeze_form( sl_attrib->sliderattrib );

    if ( ob->objclass == FL_VALSLIDER )
        fl_show_object( sl_attrib->prec );
    else
        fl_hide_object( sl_attrib->prec );

    fl_set_counter_step( sl_attrib->prec, 1, 2 );
    fl_set_counter_precision( sl_attrib->prec, 0 );
    fl_set_counter_bounds( sl_attrib->prec, 0, 6 );
    fl_redraw_object( sl_attrib->prec );   /* need this to draw counter fully */

    if ( is_vert( ob->type ) )
    {
        fl_set_object_label( sl_attrib->minval, "Value at top" );
        fl_set_object_label( sl_attrib->maxval, "Value at bottom" );
    }
    else
    {
        fl_set_object_label( sl_attrib->minval, "Value at left" );
        fl_set_object_label( sl_attrib->maxval, "Value at right" );
    }

    show_spec( slider_spec );

    fl_unfreeze_form( sl_attrib->sliderattrib );

    return 0;
}


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

void
emit_slider_code( FILE      * fp,
                  FL_OBJECT * ob )
{
    FL_OBJECT *defobj;
    SuperSPEC *sp,
              *defsp;

    if ( ob->objclass != FL_SLIDER && ob->objclass != FL_VALSLIDER )
        return;

    /* create a default object */

    defobj = ( ob->objclass == FL_SLIDER ?
               fl_create_slider : fl_create_valslider )
                 ( ob->type, 0, 0, 0, 0, "");

    defsp = get_superspec( defobj );
    sp = get_superspec( ob );

    if ( sp->prec != defsp->prec )
        fprintf( fp, "    fl_set_slider_precision( obj, %d );\n", sp->prec );

    if ( sp->min != defsp->min || sp->max != defsp->max )
        fprintf( fp, "    fl_set_slider_bounds( obj, %g, %g );\n",
                 sp->min, sp->max );

    if ( sp->val != defsp->val )
        fprintf( fp, "    fl_set_slider_value( obj, %g );\n", sp->val );

    if ( sp->slsize != defsp->slsize )
        fprintf( fp, "    fl_set_slider_size( obj, %.2f );\n", sp->slsize );

    if ( sp->step != defsp->step )
        fprintf( fp, "    fl_set_slider_step( obj, %g );\n", sp->step );

    if ( sp->ldelta != defsp->ldelta || sp->rdelta != defsp->rdelta )
        fprintf( fp, "    fl_set_slider_increment( obj, %g, %g );\n",
                 sp->ldelta, sp->rdelta );
}


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

void
save_slider_attrib( FILE      * fp,
                    FL_OBJECT * ob )
{
    FL_OBJECT *defobj;
    SuperSPEC *defsp, *sp;

    if ( ob->objclass != FL_SLIDER && ob->objclass != FL_VALSLIDER )
        return;

    /* create a default object */

    defobj = ( ob->objclass == FL_SLIDER ?
               fl_create_slider : fl_create_valslider )
                 ( ob->type, 0, 0, 0, 0, "" );

    defsp = get_superspec( defobj );
    sp = get_superspec( ob );

    if ( sp->min != defsp->min || sp->max != defsp->max )
        fprintf( fp, "    bounds: %g %g\n", sp->min, sp->max );
    if ( sp->prec != defsp->prec )
        fprintf( fp, "    precision: %d\n", sp->prec );
    if ( sp->val != defsp->val )
        fprintf( fp, "    value: %g\n", sp->val );
    if ( sp->ldelta != defsp->ldelta || sp->rdelta != defsp->rdelta )
        fprintf( fp, "    increment: %g %g\n", sp->ldelta, sp->rdelta );
    if ( sp->slsize != defsp->slsize )
        fprintf( fp, "    slsize: %.2f\n", sp->slsize );
    if ( sp->step != defsp->step )
        fprintf( fp, "    step: %g\n", sp->step );
}


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

void
adjust_precision( FL_OBJECT * ob,
                  long        data  FL_UNUSED_ARG )
{
    double p = fl_get_counter_value( ob );

    fl_set_slider_precision( sl_attrib->vdata, p );
    if ( auto_apply )
        redraw_the_form( 0 );
}


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

void
minmax_change( FL_OBJECT * ob    FL_UNUSED_ARG,
               long        data  FL_UNUSED_ARG )
{
    double min = get_finput_value( sl_attrib->minval );
    double max = get_finput_value( sl_attrib->maxval );

    fl_set_slider_bounds( sl_attrib->vdata, min, max );
    if ( auto_apply )
        redraw_the_form( 0 );
}


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

void
slsize_change( FL_OBJECT * ob    FL_UNUSED_ARG,
               long        data  FL_UNUSED_ARG )
{
    double slsize = get_finput_value( sl_attrib->slsize );

    fl_set_slider_size( sl_attrib->vdata, slsize );
    if ( auto_apply )
        redraw_the_form( 0 );
}


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

void
step_change( FL_OBJECT * ob    FL_UNUSED_ARG,
             long        data  FL_UNUSED_ARG )
{
    double step = get_finput_value( sl_attrib->step );

    fl_set_slider_step( sl_attrib->vdata, step );
    if ( auto_apply )
        redraw_the_form( 0 );
}


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

void
increment_change( FL_OBJECT * ob    FL_UNUSED_ARG,
                  long        data  FL_UNUSED_ARG )
{
    double l = get_finput_value( sl_attrib->ldelta );
    double r = get_finput_value( sl_attrib->rdelta );

    fl_set_slider_increment( sl_attrib->vdata, l, r );
}


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

void
initialvalue_change( FL_OBJECT * ob    FL_UNUSED_ARG,
                     long        data  FL_UNUSED_ARG )
{
    double val = get_finput_value( sl_attrib->initial_val );

    fl_set_slider_value( sl_attrib->vdata, val );
    slider_spec->val = fl_get_slider_value( sl_attrib->vdata );
    set_finput_value( sl_attrib->initial_val, slider_spec->val,
                      slider_spec->prec );
    if ( auto_apply )
        redraw_the_form( 0 );
}


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

void
returnsetting_change( FL_OBJECT * ob    FL_UNUSED_ARG,
                      long        data  FL_UNUSED_ARG )
{
    handle_how_return_changes( sl_attrib->returnsetting,
                               sl_attrib->vdata );
}


#include "spec/slider_spec.c"


/*
 * Local variables:
 * tab-width: 4
 * indent-tabs-mode: nil
 * End:
 */