1 /* Monolith widget 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_widget.c,v 1.5 2002/11/29 10:43:03 rich Exp $
35 #include "ml_widget.h"
37 /* This is what generic widget objects *actually* look like. */
40 struct ml_widget_operations *ops;
44 ml_widget_repaint (void *vw, ml_session session, const char *windowid,
47 struct widget *w = (struct widget *) vw;
49 if (w->ops->repaint) w->ops->repaint (vw, session, windowid, io);
52 const struct ml_widget_property *
53 ml_widget_get_properties (void *vw)
55 struct widget *w = (struct widget *) vw;
57 return w->ops->properties;
61 ml_widget_set_property (void *vw, const char *property_name, ...)
63 struct widget *w = (struct widget *) vw;
64 struct ml_widget_property *properties = w->ops->properties;
67 /* If you hit this assertion, then you've tried to set properties
68 * on a widget which isn't property-aware.
70 assert (properties != 0);
72 /* Search for the appropriate property. */
73 while (properties->name)
75 if (strcmp (properties->name, property_name) == 0)
78 assert (!(properties->flags & ML_PROP_READ_ONLY));
80 va_start (args, property_name);
83 switch (properties->type) {
86 char **v = (char **) (vw + properties->offset);
87 *v = va_arg (args, char *);
92 int *v = (int *) (vw + properties->offset);
93 *v = va_arg (args, int);
98 char *v = (char *) (vw + properties->offset);
99 *v = va_arg (args, int); /* sic */
104 ml_widget *v = (ml_widget *) (vw + properties->offset);
105 *v = va_arg (args, ml_widget);
109 abort (); /* Unknown type. */
114 if (properties->on_set) properties->on_set (vw);
122 /* If you reach here, then you've tried to update a non-existant
123 * property in a widget.
126 "ml_widget_set_property: unknown property name: %s\n",
132 _ml_widget_get_property (void *vw, const char *property_name, void *varptr)
134 struct widget *w = (struct widget *) vw;
135 struct ml_widget_property *properties = w->ops->properties;
138 /* If you hit this assertion, then you've tried to get properties
139 * on a widget which isn't property-aware.
141 assert (properties != 0);
143 /* Search for the appropriate property. */
144 while (properties->name)
146 if (strcmp (properties->name, property_name) == 0)
149 assert (!(properties->flags & ML_PROP_WRITE_ONLY));
151 if (properties->on_get) properties->on_get (vw);
154 switch (properties->type) {
156 size = sizeof (char *); break;
158 size = sizeof (int); break;
160 size = sizeof (char); break;
162 size = sizeof (ml_widget); break;
164 abort (); /* Unknown type. */
167 memcpy (varptr, vw + properties->offset, size);
175 /* If you reach here, then you've tried to update a non-existant
176 * property in a widget.
179 "_ml_widget_get_property: unknown property name: %s\n",