File: sp_scrollbar.c

package info (click to toggle)
libforms 1.0.93sp1-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 11,548 kB
  • ctags: 9,107
  • sloc: ansic: 97,227; sh: 9,236; makefile: 858
file content (311 lines) | stat: -rw-r--r-- 8,194 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
/*
 * 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_scrollbar.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/scrollbar_spec.h"

extern FD_scrollbarattrib *create_form_scrollbarattrib( void );

static FD_scrollbarattrib *scb_attrib;
static SuperSPEC *scb_spec;
static void show_spec( SuperSPEC * );


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

void *
get_scrollbar_spec_fdform( void )
{
    if ( ! scb_attrib )
    {
        scb_attrib = create_form_scrollbarattrib( );

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

    return scb_attrib;
}


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

void
scrollbar_spec_restore( FL_OBJECT * ob    FL_UNUSED_ARG,
                        long        data  FL_UNUSED_ARG )
{
    FL_OBJECT *edited = scb_attrib->vdata;

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


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

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

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


#define is_vert( t ) (    t == FL_VERT_SCROLLBAR      \
                       || t == FL_VERT_NICE_SCROLLBAR \
                       || t == FL_VERT_THIN_SCROLLBAR )


/***************************************
 * Entry point
 ***************************************/

int
set_scrollbar_attrib( FL_OBJECT * ob )
{
    scb_attrib->vdata = ob;
    scb_spec = get_superspec( ob );

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

    show_spec( scb_spec );

    return 0;
}


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

void
emit_scrollbar_code( FILE      * fp,
                     FL_OBJECT * ob )
{
    FL_OBJECT *defobj;
    SuperSPEC *spec, *defspec;

    if ( ob->objclass != FL_SCROLLBAR )
        return;

    /* create a default object */

    defobj = fl_create_scrollbar( ob->type, 0, 0, 30, 30, "" );

    defspec = get_superspec( defobj );
    spec = get_superspec( ob );

    if ( spec->min != defspec->min || spec->max != defspec->max )
        fprintf( fp, "    fl_set_scrollbar_bounds( obj, %g, %g );\n",
                 spec->min, spec->max );

    if ( spec->val != defspec->val )
        fprintf( fp, "    fl_set_scrollbar_value( obj, %g );\n", spec->val );

    if ( spec->slsize != defspec->slsize )
        fprintf( fp, "    fl_set_scrollbar_size( obj, %.2f );\n",
                 spec->slsize );

    if ( spec->step != defspec->step )
        fprintf( fp, "    fl_set_scrollbar_step( obj, %g );\n", spec->step );

    if ( spec->ldelta != defspec->ldelta || spec->rdelta != defspec->rdelta )
        fprintf( fp, "    fl_set_scrollbar_increment( obj, %g, %g );\n",
                 spec->ldelta, spec->rdelta );
}


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

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

    if ( ob->objclass != FL_SCROLLBAR )
        return;

    /* create a default object */

    defobj = fl_create_scrollbar( ob->type, 0, 0, 50, 50, "" );

    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->val != defsp->val )
        fprintf( fp, "    value: %g\n", sp->val );

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

    if ( sp->step != defsp->step )
        fprintf( fp, "    step: %.3f\n", sp->step );

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


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

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

    fl_set_scrollbar_bounds( scb_attrib->vdata, min, max );

    if ( auto_apply )
        redraw_the_form( 0 );
}


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

void
scb_delta_change( FL_OBJECT * ob    FL_UNUSED_ARG,
                  long        data  FL_UNUSED_ARG )
{
    double ldelta = get_finput_value( scb_attrib->ldelta );
    double rdelta = get_finput_value( scb_attrib->rdelta );

    fl_set_scrollbar_increment( scb_attrib->vdata, ldelta, rdelta );

    if ( auto_apply )
        redraw_the_form( 0 );
}


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

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

    fl_set_scrollbar_size( scb_attrib->vdata, slsize );

    if ( auto_apply )
        redraw_the_form( 0 );
}


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

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

    fl_set_scrollbar_step( scb_attrib->vdata, step );

    if ( auto_apply )
        redraw_the_form( 0 );
}


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

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

    fl_set_scrollbar_value( scb_attrib->vdata, val );
    set_finput_value( scb_attrib->initial_val, scb_spec->val, -1 );

    if ( auto_apply )
        redraw_the_form( 0 );
}


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

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


#include "spec/scrollbar_spec.c"


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