1 /* Monolith group of radio buttons.
2 * - by Richard W.M. Jones <rich@annexia.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * $Id: ml_form_radio_group.c,v 1.1 2002/08/30 14:28:47 rich Exp $
30 #include <pthr_iolib.h>
33 #include "ml_widget.h"
35 #include "ml_form_input.h"
36 #include "ml_form_radio.h"
37 #include "ml_form_radio_group.h"
39 static void repaint (void *, ml_session, const char *, io_handle);
40 static void clear_value (void *);
41 static void set_value (void *, const char *value);
42 static const char *get_value (void *);
44 struct ml_widget_operations form_radio_group_ops =
49 struct ml_form_input_operations form_radio_group_input_ops =
51 clear_value: clear_value,
56 struct ml_form_radio_group
58 struct ml_widget_operations *ops;
59 struct ml_form_input_operations *fops;
60 pool pool; /* Pool for allocations. */
61 const char *name; /* Name of the input field. */
62 const char *value; /* Value of the input field. */
63 ml_widget w; /* Packed widget. */
64 shash buttons; /* Related buttons (value -> radio button). */
68 new_ml_form_radio_group (pool pool, ml_form form)
70 ml_form_radio_group w = pmalloc (pool, sizeof *w);
72 w->ops = &form_radio_group_ops;
73 w->fops = &form_radio_group_input_ops;
77 w->buttons = new_shash (pool, ml_form_radio);
79 /* Register ourselves with the form. */
80 w->name = _ml_form_register_widget (form, w);
86 _ml_form_radio_group_register (ml_form_radio_group w, ml_form_radio r,
89 shash_insert (w->buttons, value, r);
94 ml_form_radio_group_pack (ml_form_radio_group w, ml_widget _w)
100 clear_value (void *vw)
102 ml_form_radio_group w = (ml_form_radio_group) vw;
107 /* Uncheck all of the buttons. */
108 values = shash_values (w->buttons);
109 for (i = 0; i < vector_size (values); ++i)
111 vector_get (values, i, r);
112 ml_form_radio_set_checked (r, 0);
118 set_value (void *vw, const char *value)
120 ml_form_radio_group w = (ml_form_radio_group) vw;
124 if (shash_get (w->buttons, value, r))
125 ml_form_radio_set_checked (r, 1);
132 ml_form_radio_group w = (ml_form_radio_group) vw;
138 repaint (void *vw, ml_session session, const char *windowid, io_handle io)
140 ml_form_radio_group w = (ml_form_radio_group) vw;
143 ml_widget_repaint (w->w, session, windowid, io);