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_positioner.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 counter 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_positioner.h"
36 #include "private/ppositioner.h"
37 #include "spec/positioner_spec.h"
38 
39 static FD_posattrib * pos_attrib;
40 static FL_OBJECT * curobj;
41 
42 
43 /***************************************
44  ***************************************/
45 
46 FL_FORM *
positioner_create_spec_form(void)47 positioner_create_spec_form( void )
48 {
49     if ( pos_attrib )
50         return pos_attrib->posattrib;
51 
52     pos_attrib = create_form_posattrib( );
53 
54     setup_how_return_menu( pos_attrib->returnsetting );
55     fl_set_menu_item_mode( pos_attrib->returnsetting, 5,
56                            FL_PUP_BOX | FL_PUP_GRAY );
57     fl_set_menu_item_mode( pos_attrib->returnsetting, 6,
58                            FL_PUP_BOX | FL_PUP_GRAY );
59 
60     return pos_attrib->posattrib;
61 }
62 
63 
64 /***************************************
65  ***************************************/
66 
67 void
positioner_fill_in_spec_form(FL_OBJECT * obj)68 positioner_fill_in_spec_form( FL_OBJECT * obj )
69 {
70     FLI_POSITIONER_SPEC *sp = obj->spec;
71 
72 
73     curobj = obj;
74 
75     set_finput_value( pos_attrib->xminval, sp->xmin, -1 );
76     set_finput_value( pos_attrib->xmaxval, sp->xmax, -1 );
77     set_finput_value( pos_attrib->yminval, sp->ymin, -1 );
78     set_finput_value( pos_attrib->ymaxval, sp->ymax, -1 );
79 
80     set_finput_value( pos_attrib->initialxval, sp->xval, -1 );
81     set_finput_value( pos_attrib->initialyval, sp->yval, -1 );
82 
83     set_finput_value( pos_attrib->xstep, sp->xstep, -1 );
84     set_finput_value( pos_attrib->ystep, sp->ystep, -1 );
85 
86     reset_how_return_menu( pos_attrib->returnsetting, obj->how_return );
87 }
88 
89 
90 /***************************************
91  ***************************************/
92 
93 void
positioner_reread_spec_form(FL_OBJECT * obj)94 positioner_reread_spec_form( FL_OBJECT * obj )
95 {
96     double r1, r2;
97 
98     if (    get_checked_float( fl_get_input( pos_attrib->xminval ), &r1 )
99          && get_checked_float( fl_get_input( pos_attrib->xmaxval ), &r2 ) )
100         fl_set_positioner_xbounds( obj, r1, r2 );
101 
102     if (    get_checked_float( fl_get_input( pos_attrib->yminval ), &r1 )
103          && get_checked_float( fl_get_input( pos_attrib->ymaxval ), &r2 ) )
104         fl_set_positioner_ybounds( obj, r1, r2 );
105 
106     if ( get_checked_float( fl_get_input( pos_attrib->initialxval ), &r1 ) )
107          fl_set_positioner_xvalue( obj, r1 );
108     if ( get_checked_float( fl_get_input( pos_attrib->initialyval ), &r1 ) )
109          fl_set_positioner_yvalue( obj, r1 );
110 
111     if ( get_checked_float( fl_get_input( pos_attrib->xstep ), &r1 ) )
112          fl_set_positioner_xstep( obj, r1 );
113     if ( get_checked_float( fl_get_input( pos_attrib->ystep ), &r1 ) )
114          fl_set_positioner_ystep( obj, r1 );
115 
116     redraw_the_form( 0 );
117 }
118 
119 
120 /***************************************
121  ***************************************/
122 
123 void
positioner_emit_spec_fd_code(FILE * fp,FL_OBJECT * obj)124 positioner_emit_spec_fd_code( FILE      * fp,
125                               FL_OBJECT * obj )
126 {
127     FL_OBJECT *defobj = fl_create_positioner( obj->type, 0, 0, 0, 0, "" );
128     FLI_POSITIONER_SPEC *sp    = obj->spec,
129                         *defsp = defobj->spec;
130 
131     if ( sp->xmin != defsp->xmin || sp->xmax != defsp->xmax )
132         fprintf( fp, "    xbounds: %g %g\n", sp->xmin, sp->xmax );
133 
134     if ( sp->ymin != defsp->ymin || sp->ymax != defsp->ymax )
135         fprintf( fp, "    ybounds: %g %g\n", sp->ymin, sp->ymax );
136 
137     if ( sp->xval != defsp->xval )
138         fprintf( fp, "    xvalue: %g\n", sp->xval );
139 
140     if ( sp->yval != defsp->yval )
141         fprintf( fp, "    yvalue: %g\n", sp->yval );
142 
143     if ( sp->xstep != defsp->xstep )
144         fprintf( fp, "    xstep: %g\n", sp->xstep );
145 
146     if ( sp->ystep != defsp->ystep )
147         fprintf( fp, "    ystep: %g\n", sp->ystep );
148 
149     fl_free_object( defobj );
150 }
151 
152 
153 /***************************************
154  ***************************************/
155 
156 void
positioner_emit_spec_c_code(FILE * fp,FL_OBJECT * obj)157 positioner_emit_spec_c_code( FILE      * fp,
158                              FL_OBJECT * obj )
159 {
160     FL_OBJECT *defobj = fl_create_positioner( obj->type, 0, 0, 0, 0, "" );
161     FLI_POSITIONER_SPEC *sp    = obj->spec,
162                         *defsp = defobj->spec;
163 
164     if ( sp->xmin != defsp->xmin || sp->xmax != defsp->xmax )
165         fprintf( fp, "    fl_set_positioner_xbounds( obj, %g, %g );\n",
166                  sp->xmin, sp->xmax );
167 
168     if ( sp->ymin != defsp->ymin || sp->ymax != defsp->ymax )
169         fprintf( fp, "    fl_set_positioner_ybounds( obj, %g, %g );\n",
170                  sp->ymin, sp->ymax );
171 
172     if ( sp->xval != defsp->xval )
173         fprintf( fp, "    fl_set_positioner_xvalue( obj, %g );\n", sp->xval );
174 
175     if ( sp->yval != defsp->yval )
176         fprintf( fp, "    fl_set_positioner_yvalue( obj, %g );\n", sp->yval );
177 
178     if ( sp->xstep != defsp->xstep )
179         fprintf( fp, "    fl_set_positioner_xstep( obj, %g );\n", sp->xstep );
180 
181     if ( sp->ystep != defsp->ystep )
182         fprintf( fp, "    fl_set_positioner_ystep( obj, %g );\n", sp->ystep );
183 
184     fl_free_object( defobj );
185 }
186 
187 
188 /***************************************
189  ***************************************/
190 
191 void
pos_xminmax_change(FL_OBJECT * ob FL_UNUSED_ARG,long data FL_UNUSED_ARG)192 pos_xminmax_change( FL_OBJECT * ob    FL_UNUSED_ARG,
193                     long        data  FL_UNUSED_ARG )
194 {
195     fl_set_positioner_xbounds( curobj,
196                                get_finput_value( pos_attrib->xminval ),
197                                get_finput_value( pos_attrib->xmaxval ) );
198     redraw_the_form( 0 );
199 }
200 
201 
202 /***************************************
203  ***************************************/
204 
205 void
pos_yminmax_change(FL_OBJECT * ob FL_UNUSED_ARG,long data FL_UNUSED_ARG)206 pos_yminmax_change( FL_OBJECT * ob    FL_UNUSED_ARG,
207                     long        data  FL_UNUSED_ARG )
208 {
209     fl_set_positioner_ybounds( curobj,
210                                get_finput_value( pos_attrib->yminval ),
211                                get_finput_value( pos_attrib->ymaxval ) );
212     redraw_the_form( 0 );
213 }
214 
215 
216 /***************************************
217  ***************************************/
218 
219 void
pos_xstepchange_cb(FL_OBJECT * obj,long data FL_UNUSED_ARG)220 pos_xstepchange_cb( FL_OBJECT * obj,
221                     long        data  FL_UNUSED_ARG )
222 {
223     fl_set_positioner_xstep( curobj, get_finput_value( obj ) );
224     redraw_the_form( 0 );
225 }
226 
227 
228 /***************************************
229  ***************************************/
230 
231 void
pos_ystepchange_cb(FL_OBJECT * obj,long data FL_UNUSED_ARG)232 pos_ystepchange_cb( FL_OBJECT * obj,
233                     long        data  FL_UNUSED_ARG )
234 {
235     fl_set_positioner_ystep( curobj, get_finput_value( obj ) );
236     redraw_the_form( 0 );
237 }
238 
239 
240 /***************************************
241  ***************************************/
242 
243 void
pos_initialxvalue_change(FL_OBJECT * obj,long data FL_UNUSED_ARG)244 pos_initialxvalue_change( FL_OBJECT * obj,
245                           long        data  FL_UNUSED_ARG )
246 {
247     fl_set_positioner_xvalue( curobj, get_finput_value( obj ) );
248     redraw_the_form( 0 );
249 }
250 
251 
252 /***************************************
253  ***************************************/
254 
255 void
pos_initialyvalue_change(FL_OBJECT * obj,long data FL_UNUSED_ARG)256 pos_initialyvalue_change( FL_OBJECT * obj,
257                           long        data  FL_UNUSED_ARG)
258 {
259     fl_set_positioner_yvalue( curobj, get_finput_value( obj ) );
260     redraw_the_form( 0 );
261 }
262 
263 
264 /***************************************
265  ***************************************/
266 
267 void
pos_returnsetting_change(FL_OBJECT * obj,long data FL_UNUSED_ARG)268 pos_returnsetting_change( FL_OBJECT * obj,
269                           long        data  FL_UNUSED_ARG )
270 {
271     handle_how_return_changes( obj, curobj );
272 }
273 
274 #include "spec/positioner_spec.c"
275 
276 
277 /*
278  * Local variables:
279  * tab-width: 4
280  * indent-tabs-mode: nil
281  * End:
282  */
283