1 /* Monolith form checkbox input class.
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_checkbox.c,v 1.1 2002/08/30 14:28:47 rich Exp $
27 #include <pthr_iolib.h>
30 #include "ml_widget.h"
31 #include "ml_form_input.h"
32 #include "ml_form_checkbox.h"
34 static void repaint (void *, ml_session, const char *, io_handle);
35 static void clear_value (void *);
36 static void set_value (void *, const char *value);
37 static const char *get_value (void *);
39 struct ml_widget_operations form_checkbox_ops =
44 struct ml_form_input_operations form_checkbox_input_ops =
46 clear_value: clear_value,
51 struct ml_form_checkbox
53 struct ml_widget_operations *ops;
54 struct ml_form_input_operations *fops;
55 pool pool; /* Pool for allocations. */
56 const char *name; /* Name of the input field. */
57 const char *value; /* Value of the input field. */
61 new_ml_form_checkbox (pool pool, ml_form form)
63 ml_form_checkbox w = pmalloc (pool, sizeof *w);
65 w->ops = &form_checkbox_ops;
66 w->fops = &form_checkbox_input_ops;
70 /* Register ourselves with the form. */
71 w->name = _ml_form_register_widget (form, w);
77 clear_value (void *vw)
79 ml_form_checkbox w = (ml_form_checkbox) vw;
85 set_value (void *vw, const char *value)
87 ml_form_checkbox w = (ml_form_checkbox) vw;
96 ml_form_checkbox w = (ml_form_checkbox) vw;
102 repaint (void *vw, ml_session session, const char *windowid, io_handle io)
104 ml_form_checkbox w = (ml_form_checkbox) vw;
106 io_fprintf (io, "<input class=\"ml_form_checkbox\" type=\"checkbox\" "
107 "name=\"%s\" value=\"1\""
109 w->name, w->value ? " checked=\"1\"" : "");