File: sp_twheel.c

package info (click to toggle)
libforms1 1.0-7
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 6,648 kB
  • ctags: 14,351
  • sloc: ansic: 90,441; makefile: 9,902; sh: 8
file content (220 lines) | stat: -rw-r--r-- 5,801 bytes parent folder | download | duplicates (3)
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
/*
 *
 * 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; see the file COPYING.  If not, write to
 * the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA.
 *
 */


/*
 * $Id: sp_twheel.c,v 1.0 2002/05/08 05:27:39 zhao Release $
 *
 *.
 *  This file is part of XForms package
 *  Copyright (c) 1996-2002  T.C. Zhao and Mark Overmars
 *  All rights reserved.
 *.
 * Settting twheel class specific attributes.
 *
 */

#include "forms.h"
#include "fd_main.h"
#include "fd_spec.h"
#include "twheel_spec.h"

extern FD_twheelattrib *create_form_twheelattrib(void);

static FD_twheelattrib *twheel_attrib;
static SuperSPEC *twheel_spec;
static void show_spec(SuperSPEC *);

void *
get_twheel_spec_fdform(void)
{
    if (!twheel_attrib)
    {
	twheel_attrib = create_form_twheelattrib();
	fl_clear_choice(twheel_attrib->returnsetting);
	fl_addto_choice(twheel_attrib->returnsetting, get_how_return_str());
    }
    return twheel_attrib;
}


void
twheel_spec_restore(FL_OBJECT * ob, long data)
{
    FL_OBJECT *edit_obj;

    edit_obj = twheel_attrib->vdata;
    superspec_to_spec(edit_obj);
    redraw_the_form(0);
}

static void
show_spec(SuperSPEC * spec)
{
    set_finput_value(twheel_attrib->minval, spec->min, spec->prec);
    set_finput_value(twheel_attrib->maxval, spec->max, spec->prec);
    set_finput_value(twheel_attrib->initial_val, spec->val, spec->prec);
    set_finput_value(twheel_attrib->step, spec->step, 3);

    fl_set_counter_value(twheel_attrib->prec, spec->prec);
    /* fl_call_object_callback(twheel_attrib->prec); */

    fl_set_choice_text(twheel_attrib->returnsetting,
		       get_how_return_str_name(spec->how_return));
}

int
set_twheel_attrib(FL_OBJECT * ob)
{
    twheel_attrib->vdata = ob;
    twheel_spec = get_superspec(ob);

    fl_freeze_form(twheel_attrib->twheelattrib);


    fl_set_counter_step(twheel_attrib->prec, 1, 2);
    fl_set_counter_precision(twheel_attrib->prec, 0);
    fl_set_counter_bounds(twheel_attrib->prec, 0, 6);
    fl_hide_object(twheel_attrib->prec);

    show_spec(twheel_spec);

    fl_unfreeze_form(twheel_attrib->twheelattrib);

    return 0;
}

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

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

    /* create a default object */
    defobj = fl_create_thumbwheel(ob->type, 0, 0, 0, 0, "");

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

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

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

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

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

    if (sp->how_return != defsp->how_return)
	fprintf(fp, "    fl_set_thumbwheel_return(obj, %s);\n",
		get_how_return_name(sp->how_return));

}

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

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

    /* create a default object */
    defobj = fl_create_thumbwheel(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, "\tbounds: %g %g\n", sp->min, sp->max);
    if (sp->prec != defsp->prec)
	fprintf(fp, "\tprecision: %d\n", sp->prec);
    if (sp->val != defsp->val)
	fprintf(fp, "\tvalue: %g\n", sp->val);
    if (sp->ldelta != defsp->ldelta || sp->rdelta != defsp->rdelta)
	fprintf(fp, "\tincrement: %g %g\n", sp->ldelta, sp->rdelta);
    if (sp->slsize != defsp->slsize)
	fprintf(fp, "\tslsize: %.2f\n", sp->slsize);
    if (sp->step != defsp->step)
	fprintf(fp, "\tstep: %g\n", sp->step);
    if (sp->how_return != defsp->how_return)
	fprintf(fp, "\treturn: %s\n", get_how_return_name(sp->how_return));
}

void
twheel_minmax_change(FL_OBJECT * ob, long data)
{
    double min = get_finput_value(twheel_attrib->minval, 3);
    double max = get_finput_value(twheel_attrib->maxval, 3);

    fl_set_thumbwheel_bounds(twheel_attrib->vdata, min, max);
    if (auto_apply)
	redraw_the_form(0);
}

void
twheel_step_change(FL_OBJECT * ob, long data)
{
    double step = get_finput_value(twheel_attrib->step, 5);

    fl_set_thumbwheel_step(twheel_attrib->vdata, step);
    if (auto_apply)
	redraw_the_form(0);
}

void
twheel_initialvalue_change(FL_OBJECT * ob, long data)
{
    double val = get_finput_value(twheel_attrib->initial_val, 2);

    fl_set_thumbwheel_value(twheel_attrib->vdata, val);
    twheel_spec->val = fl_get_thumbwheel_value(twheel_attrib->vdata);
    set_finput_value(twheel_attrib->initial_val, twheel_spec->val,
		     twheel_spec->prec);
    if (auto_apply)
	redraw_the_form(0);
}

void
twheel_returnsetting_change(FL_OBJECT * ob, long data)
{
    const char *s = fl_get_choice_text(twheel_attrib->returnsetting);
    fl_set_thumbwheel_return(twheel_attrib->vdata,
			     get_how_return_str_value(s));
}

void
twheel_adjust_precision(FL_OBJECT * ob, long data)
{
}


#include "twheel_spec.c"