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_xyplot.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 xyplot 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_xyplot.h"
36 #include "private/pxyplot.h"
37 #include "spec/xyplot_spec.h"
38
39 static FD_xyplotattrib *xyplot_attrib;
40 static FL_OBJECT *curobj;
41
42
43 /***************************************
44 ***************************************/
45
46 FL_FORM *
xyplot_create_spec_form(void)47 xyplot_create_spec_form( void )
48 {
49 if ( xyplot_attrib )
50 return xyplot_attrib->xyplotattrib;
51
52 xyplot_attrib = create_form_xyplotattrib( );
53
54 fl_addto_choice( xyplot_attrib->xscale, get_scale_string( ) );
55 fl_addto_choice( xyplot_attrib->yscale, get_scale_string( ) );
56 fl_addto_choice( xyplot_attrib->xgrid, get_grid_string( ) );
57 fl_addto_choice( xyplot_attrib->ygrid, get_grid_string( ) );
58 fl_addto_choice( xyplot_attrib->gridstyle, get_linestyle_string( ) );
59
60 setup_how_return_menu( xyplot_attrib->how_return );
61 fl_set_menu_item_mode( xyplot_attrib->how_return, 5,
62 FL_PUP_BOX | FL_PUP_GRAY );
63 fl_set_menu_item_mode( xyplot_attrib->how_return, 6,
64 FL_PUP_BOX | FL_PUP_GRAY );
65
66 return xyplot_attrib->xyplotattrib;
67 }
68
69
70 /***************************************
71 ***************************************/
72
73 void
xyplot_adjust_spec_form(FL_OBJECT * obj)74 xyplot_adjust_spec_form( FL_OBJECT * obj )
75 {
76 FLI_XYPLOT_SPEC *sp = obj->spec;
77
78 curobj = obj;
79
80 if ( obj->type != FL_ACTIVE_XYPLOT )
81 {
82 fl_hide_object( xyplot_attrib->how_return );
83 fl_hide_object( xyplot_attrib->mark_active );
84 }
85 else
86 {
87 fl_show_object( xyplot_attrib->how_return );
88 fl_show_object( xyplot_attrib->mark_active );
89 }
90
91 if ( sp->xscale != FL_LOG )
92 fl_hide_object( xyplot_attrib->xbase );
93 else
94 fl_show_object( xyplot_attrib->xbase );
95
96 if ( sp->yscale != FL_LOG )
97 fl_hide_object( xyplot_attrib->ybase );
98 else
99 fl_show_object( xyplot_attrib->ybase );
100
101 if ( sp->xgrid || sp->ygrid )
102 fl_show_object( xyplot_attrib->gridstyle );
103 else
104 fl_hide_object( xyplot_attrib->gridstyle );
105 }
106
107
108 /***************************************
109 ***************************************/
110
111 void
xyplot_fill_in_spec_form(FL_OBJECT * obj)112 xyplot_fill_in_spec_form( FL_OBJECT * obj )
113 {
114 FLI_XYPLOT_SPEC *sp = obj->spec;
115
116 fl_set_counter_value( xyplot_attrib->xmajor, sp->xmajor );
117 fl_set_counter_value( xyplot_attrib->xminor, sp->xminor );
118 fl_set_counter_value( xyplot_attrib->ymajor, sp->ymajor );
119 fl_set_counter_value( xyplot_attrib->yminor, sp->yminor );
120
121 fl_set_choice( xyplot_attrib->xgrid, sp->xgrid + 1 );
122 fl_set_choice( xyplot_attrib->ygrid, sp->ygrid + 1 );
123 fl_set_choice( xyplot_attrib->xscale, sp->xscale + 1 );
124 fl_set_choice( xyplot_attrib->yscale, sp->yscale + 1 );
125
126 fl_set_choice( xyplot_attrib->gridstyle, sp->grid_linestyle + 1 );
127
128 set_finput_value( xyplot_attrib->xbase, sp->xbase, -1 );
129 set_finput_value( xyplot_attrib->ybase, sp->ybase, -1 );
130
131 reset_how_return_menu( xyplot_attrib->how_return, obj->how_return );
132
133 fl_set_button( xyplot_attrib->mark_active, sp->mark_active );
134 }
135
136
137 /***************************************
138 ***************************************/
139
140 void
xyplot_emit_spec_fd_code(FILE * fp,FL_OBJECT * ob)141 xyplot_emit_spec_fd_code( FILE * fp,
142 FL_OBJECT * ob )
143 {
144 FL_OBJECT *defobj;
145 SuperSPEC *defsp,
146 *sp;
147
148 if ( ob->objclass != FL_XYPLOT )
149 return;
150
151 /* create a default object */
152
153 defobj = fl_create_xyplot( ob->type, 0, 0, 0, 0, "" );
154
155 defsp = get_superspec( defobj );
156 sp = get_superspec( ob );
157
158 if ( sp->xmajor != defsp->xmajor || sp->xminor != defsp->xminor )
159 fprintf( fp, " xtics: %d %d\n", sp->xmajor, sp->xminor );
160
161 if ( sp->ymajor != defsp->ymajor || sp->yminor != defsp->yminor )
162 fprintf( fp, " ytics: %d %d\n", sp->ymajor, sp->yminor );
163
164 if ( sp->xgrid != defsp->xgrid || sp->ygrid != defsp->ygrid )
165 fprintf( fp, " grid: %s %s\n",
166 get_grid_name( sp->xgrid ), get_grid_name( sp->ygrid ) );
167
168 if ( sp->grid_linestyle != defsp->grid_linestyle )
169 fprintf( fp, " gridstyle: %s\n",
170 get_linestyle_name( sp->grid_linestyle ) );
171
172 if ( sp->xscale != defsp->xscale || sp->xbase != defsp->xbase )
173 fprintf( fp, " xscale: %s %g\n",
174 get_scale_name( sp->xscale ), sp->xbase );
175
176 if ( sp->yscale != defsp->yscale || sp->ybase != defsp->ybase )
177 fprintf( fp, " yscale: %s %g\n",
178 get_scale_name( sp->yscale ), sp->ybase );
179
180 if ( ob->type == FL_ACTIVE_XYPLOT )
181 {
182 if ( sp->mark_active != defsp->mark_active )
183 fprintf( fp, " markactive: %d\n", sp->mark_active );
184 }
185
186 fl_free_object( defobj );
187 }
188
189
190 /***************************************
191 ***************************************/
192
193 void
xyplot_emit_spec_c_code(FILE * fp,FL_OBJECT * ob)194 xyplot_emit_spec_c_code( FILE * fp,
195 FL_OBJECT * ob )
196 {
197 FL_OBJECT *defobj;
198 SuperSPEC *sp,
199 *defsp;
200
201 if ( ob->objclass != FL_XYPLOT )
202 {
203 M_err( "EmitXYPlotCode", "not xyplot class!" );
204 return;
205 }
206
207 /* create a default object */
208
209 defobj = fl_create_xyplot( ob->type, 0, 0, 0, 0, "" );
210
211 defsp = get_superspec( defobj );
212 sp = get_superspec( ob );
213
214 if ( sp->xmajor != defsp->xmajor || sp->xminor != defsp->xminor )
215 fprintf( fp, " fl_set_xyplot_xtics( obj, %d, %d );\n",
216 sp->xmajor, sp->xminor );
217
218 if ( sp->ymajor != defsp->ymajor || sp->yminor != defsp->yminor )
219 fprintf( fp, " fl_set_xyplot_ytics( obj, %d, %d );\n",
220 sp->ymajor, sp->yminor );
221
222 if ( sp->xscale != defsp->xscale
223 || ( sp->xscale == FL_LOG && sp->xbase != defsp->xbase ) )
224 fprintf( fp, " fl_set_xyplot_xscale( obj, %s, %g );\n",
225 get_scale_name( sp->xscale ), sp->xbase );
226
227 if ( sp->yscale != defsp->yscale
228 || ( sp->yscale == FL_LOG && sp->ybase != defsp->ybase ) )
229 fprintf( fp, " fl_set_xyplot_yscale( obj, %s, %g );\n",
230 get_scale_name( sp->yscale ), sp->ybase );
231
232 if ( sp->xgrid != defsp->xgrid )
233 fprintf( fp, " fl_set_xyplot_xgrid( obj, %s );\n",
234 get_grid_name( sp->xgrid ) );
235
236 if ( sp->ygrid != defsp->ygrid )
237 fprintf( fp, " fl_set_xyplot_ygrid( obj, %s );\n",
238 get_grid_name( sp->ygrid ) );
239
240 if ( sp->grid_linestyle != defsp->grid_linestyle )
241 fprintf( fp, " fl_set_xyplot_grid_linestyle( obj, %s );\n",
242 get_linestyle_name( sp->grid_linestyle ) );
243
244 if ( ob->type == FL_ACTIVE_XYPLOT )
245 {
246 if ( sp->mark_active != defsp->mark_active )
247 fprintf( fp, " fl_set_xyplot_mark_active( obj, %d );\n",
248 sp->mark_active );
249 }
250
251 fl_free_object( defobj );
252 }
253
254
255 /***************************************
256 ***************************************/
257
258 void
grid_change_cb(FL_OBJECT * obj FL_UNUSED_ARG,long data FL_UNUSED_ARG)259 grid_change_cb( FL_OBJECT * obj FL_UNUSED_ARG,
260 long data FL_UNUSED_ARG )
261 {
262 int xg = fl_get_choice( xyplot_attrib->xgrid ) - 1;
263 int yg = fl_get_choice( xyplot_attrib->ygrid ) - 1;
264
265 if ( xg || yg )
266 fl_show_object( xyplot_attrib->gridstyle );
267 else
268 fl_hide_object( xyplot_attrib->gridstyle );
269
270 fl_set_xyplot_xgrid( curobj, xg );
271 fl_set_xyplot_ygrid( curobj, yg );
272
273 redraw_the_form( 0 );
274 }
275
276
277 /***************************************
278 ***************************************/
279
280 void
markactive_change_cb(FL_OBJECT * obj,long data FL_UNUSED_ARG)281 markactive_change_cb( FL_OBJECT * obj,
282 long data FL_UNUSED_ARG )
283 {
284 fl_set_xyplot_mark_active( curobj, fl_get_button( obj ) );
285 redraw_the_form( 0 );
286 }
287
288
289 /***************************************
290 ***************************************/
291
292 void
gridstyle_change_cb(FL_OBJECT * obj,long data FL_UNUSED_ARG)293 gridstyle_change_cb( FL_OBJECT * obj,
294 long data FL_UNUSED_ARG )
295 {
296 fl_set_xyplot_grid_linestyle( curobj, fl_get_choice( obj ) - 1 );
297 redraw_the_form( 0 );
298 }
299
300
301 /***************************************
302 ***************************************/
303
304 void
xscale_change_cb(FL_OBJECT * obj FL_UNUSED_ARG,long data FL_UNUSED_ARG)305 xscale_change_cb( FL_OBJECT * obj FL_UNUSED_ARG,
306 long data FL_UNUSED_ARG )
307 {
308 int s = fl_get_choice( xyplot_attrib->xscale ) - 1;
309
310 if ( s == FL_LOG )
311 fl_show_object( xyplot_attrib->xbase );
312 else
313 fl_hide_object( xyplot_attrib->xbase );
314
315 fl_set_xyplot_xscale( curobj, s, get_finput_value( xyplot_attrib->xbase ) );
316 redraw_the_form( 0 );
317
318 }
319
320
321 /***************************************
322 ***************************************/
323
324 void
yscale_change_cb(FL_OBJECT * obj FL_UNUSED_ARG,long data FL_UNUSED_ARG)325 yscale_change_cb( FL_OBJECT * obj FL_UNUSED_ARG,
326 long data FL_UNUSED_ARG )
327 {
328 int s = fl_get_choice( xyplot_attrib->yscale ) - 1;
329
330 if ( s == FL_LOG )
331 fl_show_object( xyplot_attrib->ybase );
332 else
333 fl_hide_object( xyplot_attrib->ybase );
334
335 fl_set_xyplot_yscale( curobj, s, get_finput_value( xyplot_attrib->ybase ) );
336 redraw_the_form( 0 );
337 }
338
339
340 /***************************************
341 ***************************************/
342
343 void
ymajorminor_change_cb(FL_OBJECT * obj FL_UNUSED_ARG,long data FL_UNUSED_ARG)344 ymajorminor_change_cb( FL_OBJECT * obj FL_UNUSED_ARG,
345 long data FL_UNUSED_ARG )
346 {
347 /* fill-in code for callback */
348
349 fl_set_xyplot_ytics( curobj,
350 fl_get_counter_value( xyplot_attrib->ymajor ),
351 fl_get_counter_value( xyplot_attrib->yminor ) );
352 redraw_the_form( 0 );
353 }
354
355
356 /***************************************
357 ***************************************/
358
359 void
xmajorminor_change_cb(FL_OBJECT * obj FL_UNUSED_ARG,long data FL_UNUSED_ARG)360 xmajorminor_change_cb( FL_OBJECT * obj FL_UNUSED_ARG,
361 long data FL_UNUSED_ARG )
362 {
363 fl_set_xyplot_xtics( curobj,
364 fl_get_counter_value( xyplot_attrib->xmajor ),
365 fl_get_counter_value( xyplot_attrib->xminor ) );
366 redraw_the_form( 0 );
367 }
368
369
370 /***************************************
371 ***************************************/
372
373 void
xyplot_returnsetting_change(FL_OBJECT * obj,long data FL_UNUSED_ARG)374 xyplot_returnsetting_change( FL_OBJECT * obj,
375 long data FL_UNUSED_ARG )
376 {
377 handle_how_return_changes( obj, curobj );
378 }
379
380
381 #include "spec/xyplot_spec.c"
382
383
384 /*
385 * Local variables:
386 * tab-width: 4
387 * indent-tabs-mode: nil
388 * End:
389 */
390