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_dial.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 dial 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_dial.h"
36 #include "private/pdial.h"
37 #include "spec/dial_spec.h"
38 
39 static FD_dialattrib * dial_attrib;
40 static FL_OBJECT * curobj;
41 
42 #define VN( a )  { a, #a }
43 
44 static FLI_VN_PAIR dial_dir[ ] =
45 {
46     VN( FL_DIAL_CW ),
47     VN( FL_DIAL_CCW ),
48     { -1, NULL }
49 };
50 
51 
52 /***************************************
53  ***************************************/
54 
55 int
get_direction_value(const char * s)56 get_direction_value( const char * s )
57 {
58     return fli_get_vn_value( dial_dir, s );
59 }
60 
61 
62 /***************************************
63  ***************************************/
64 
65 FL_FORM *
dial_create_spec_form(void)66 dial_create_spec_form( void )
67 {
68     if ( dial_attrib )
69         return dial_attrib->dialattrib;
70 
71     dial_attrib = create_form_dialattrib( );
72     fl_addto_choice( dial_attrib->dir, dial_dir[ 0 ].name );
73     fl_addto_choice( dial_attrib->dir, dial_dir[ 1 ].name );
74 
75     setup_how_return_menu( dial_attrib->returnsetting );
76     fl_set_menu_item_mode( dial_attrib->returnsetting, 5,
77                            FL_PUP_BOX | FL_PUP_GRAY );
78     fl_set_menu_item_mode( dial_attrib->returnsetting, 6,
79                            FL_PUP_BOX | FL_PUP_GRAY );
80     return dial_attrib->dialattrib;
81 }
82 
83 
84 /***************************************
85  ***************************************/
86 
87 void
dial_fill_in_spec_form(FL_OBJECT * obj)88 dial_fill_in_spec_form( FL_OBJECT * obj )
89 {
90     FLI_DIAL_SPEC *sp = obj->spec;
91     curobj = obj;
92 
93     set_finput_value( dial_attrib->minval,     sp->min,    -1 );
94     set_finput_value( dial_attrib->maxval,     sp->max,    -1 );
95     set_finput_value( dial_attrib->initialval, sp->val,    -1 );
96     set_finput_value( dial_attrib->thetai,     sp->thetai, -1 );
97     set_finput_value( dial_attrib->thetaf,     sp->thetaf, -1 );
98     set_finput_value( dial_attrib->step,       sp->step,   -1 );
99 
100     fl_set_choice_text( dial_attrib->dir,
101                         fli_get_vn_name( dial_dir, sp->direction ) );
102 
103     reset_how_return_menu( dial_attrib->returnsetting, curobj->how_return );
104 }
105 
106 
107 /***************************************
108  ***************************************/
109 
110 void
dial_reread_spec_form(FL_OBJECT * obj)111 dial_reread_spec_form( FL_OBJECT * obj )
112 {
113     double r1, r2;
114     int dir = fl_get_choice( dial_attrib->dir ) - 1;
115 
116     if (    get_checked_float( fl_get_input( dial_attrib->minval ), &r1 )
117          && get_checked_float( fl_get_input( dial_attrib->maxval ), &r2 ) )
118          fl_set_dial_bounds( obj, r1, r2 );
119 
120     if ( get_checked_float( fl_get_input( dial_attrib->initialval ), &r1 ) )
121         fl_set_dial_value( obj, r1 );
122 
123     if (    get_checked_float( fl_get_input( dial_attrib->thetai ), &r1 )
124          && get_checked_float( fl_get_input( dial_attrib->thetaf ), &r2 ) )
125         fl_set_dial_angles( obj, r1, r2 );
126 
127     if ( get_checked_float( fl_get_input( dial_attrib->step ), &r1 ) )
128         fl_set_dial_step( obj, r1 );
129 
130     if ( dir >= 0 )
131         fl_set_dial_direction( obj, dial_dir[ dir ].val );
132 
133     redraw_the_form( 0 );
134 }
135 
136 
137 /***************************************
138  ***************************************/
139 
140 void
dial_emit_spec_fd_code(FILE * fp,FL_OBJECT * obj)141 dial_emit_spec_fd_code( FILE      * fp,
142                         FL_OBJECT * obj )
143 {
144     FL_OBJECT *defobj = fl_create_dial( obj->type, 0, 0, 0, 0, "" );
145     FLI_DIAL_SPEC *sp    = obj->spec,
146                   *defsp = defobj->spec;
147 
148     if ( sp->min != defsp->min || sp->max != defsp->max )
149         fprintf( fp, "    bounds: %g %g\n", sp->min, sp->max );
150 
151     if ( sp->thetai != defsp->thetai || sp->thetaf != defsp->thetaf )
152         fprintf( fp, "    angles: %g %g\n", sp->thetai, sp->thetaf );
153 
154     if ( sp->val != defsp->val )
155         fprintf( fp, "    value: %g\n", sp->val );
156 
157     if ( sp->step != defsp->step )
158         fprintf( fp, "    step: %g\n", sp->step );
159 
160     if ( sp->direction != defsp->direction )
161         fprintf( fp, "    dir: %s\n",
162                  fli_get_vn_name( dial_dir, sp->direction ) );
163 
164     fl_free_object( defobj );
165 }
166 
167 
168 /***************************************
169  ***************************************/
170 
171 void
dial_emit_spec_c_code(FILE * fp,FL_OBJECT * obj)172 dial_emit_spec_c_code( FILE      * fp,
173                        FL_OBJECT * obj )
174 {
175     FL_OBJECT *defobj = fl_create_dial( obj->type, 0, 0, 0, 0, "" );
176     FLI_DIAL_SPEC *sp    = obj->spec,
177                   *defsp = defobj->spec;
178 
179     if ( sp->min != defsp->min || sp->max != defsp->max )
180         fprintf( fp, "    fl_set_dial_bounds( obj, %g, %g );\n",
181                  sp->min, sp->max );
182 
183     if ( sp->thetai != defsp->thetai || sp->thetaf != defsp->thetaf )
184         fprintf( fp, "    fl_set_dial_angles( obj, %g, %g );\n",
185                  sp->thetai, sp->thetaf );
186 
187     if ( sp->val != defsp->val )
188         fprintf( fp, "    fl_set_dial_value( obj, %g );\n", sp->val );
189 
190     if ( sp->step != defsp->step )
191         fprintf( fp, "    fl_set_dial_step( obj, %g );\n", sp->step );
192 
193     if ( sp->direction != defsp->direction )
194         fprintf( fp, "    fl_set_dial_direction( obj, %s );\n",
195                  fli_get_vn_name( dial_dir, sp->direction ) );
196 
197     fl_free_object( defobj );
198 }
199 
200 
201 /***************************************
202  ***************************************/
203 
204 void
dial_minmax_change(FL_OBJECT * ob FL_UNUSED_ARG,long data FL_UNUSED_ARG)205 dial_minmax_change( FL_OBJECT * ob    FL_UNUSED_ARG,
206                     long        data  FL_UNUSED_ARG )
207 {
208     fl_set_dial_bounds( curobj, get_finput_value( dial_attrib->minval ),
209                         get_finput_value( dial_attrib->maxval ) );
210     redraw_the_form( 0 );
211 }
212 
213 
214 /***************************************
215  ***************************************/
216 
217 void
dial_thetachange_cb(FL_OBJECT * ob FL_UNUSED_ARG,long data FL_UNUSED_ARG)218 dial_thetachange_cb( FL_OBJECT * ob    FL_UNUSED_ARG,
219                      long        data  FL_UNUSED_ARG )
220 {
221     fl_set_dial_angles( curobj, get_finput_value( dial_attrib->thetai ),
222                         get_finput_value( dial_attrib->thetaf ));
223     redraw_the_form( 0 );
224 }
225 
226 
227 /***************************************
228  ***************************************/
229 
230 void
dial_stepchange_cb(FL_OBJECT * ob FL_UNUSED_ARG,long data FL_UNUSED_ARG)231 dial_stepchange_cb( FL_OBJECT * ob    FL_UNUSED_ARG,
232                     long        data  FL_UNUSED_ARG )
233 {
234     fl_set_dial_step( curobj, get_finput_value( dial_attrib->step ) );
235     redraw_the_form( 0 );
236 }
237 
238 
239 /***************************************
240  ***************************************/
241 
242 void
dial_initialvalue_change(FL_OBJECT * ob FL_UNUSED_ARG,long data FL_UNUSED_ARG)243 dial_initialvalue_change( FL_OBJECT * ob    FL_UNUSED_ARG,
244                           long        data  FL_UNUSED_ARG )
245 {
246     fl_set_dial_value( curobj, get_finput_value( dial_attrib->initialval ) );
247     redraw_the_form( 0 );
248 }
249 
250 
251 /***************************************
252  * direction change
253  ***************************************/
254 
255 void
dir_cb(FL_OBJECT * ob FL_UNUSED_ARG,long data FL_UNUSED_ARG)256 dir_cb( FL_OBJECT * ob    FL_UNUSED_ARG,
257         long        data  FL_UNUSED_ARG )
258 {
259     int dir = fl_get_choice( dial_attrib->dir ) - 1;
260 
261     if ( dir >= 0 )
262     {
263         fl_set_dial_direction( dial_attrib->vdata, dial_dir[ dir ].val );
264         redraw_the_form( 0 );
265     }
266 }
267 
268 
269 /***************************************
270  ***************************************/
271 
272 void
dial_returnsetting_change(FL_OBJECT * ob FL_UNUSED_ARG,long data FL_UNUSED_ARG)273 dial_returnsetting_change( FL_OBJECT * ob    FL_UNUSED_ARG,
274                            long        data  FL_UNUSED_ARG )
275 {
276     handle_how_return_changes( dial_attrib->returnsetting, curobj );
277 }
278 
279 
280 #include "spec/dial_spec.c"
281 
282 
283 /*
284  * Local variables:
285  * tab-width: 4
286  * indent-tabs-mode: nil
287  * End:
288  */
289