1 /* Monolith form text 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_text.c,v 1.5 2003/01/11 16:39:10 rich Exp $
27 #include <pthr_iolib.h>
30 #include "ml_widget.h"
31 #include "ml_smarttext.h"
32 #include "ml_form_input.h"
33 #include "ml_form_text.h"
35 static void repaint (void *, ml_session, const char *, io_handle);
36 static struct ml_widget_property properties[];
37 static void clear_value (void *);
38 static void set_value (void *, const char *value);
39 static const char *get_value (void *);
41 struct ml_widget_operations form_text_ops =
44 properties: properties,
47 struct ml_form_input_operations form_text_input_ops =
49 clear_value: clear_value,
56 struct ml_widget_operations *ops;
57 struct ml_form_input_operations *fops;
58 pool pool; /* Pool for allocations. */
59 const char *name; /* Name of the input field. */
60 const char *value; /* Value of the input field. */
61 int size; /* Displayed width. */
62 int maxlength; /* Maximum number of characters. */
63 ml_form form; /* The form. */
64 int focus; /* If set, grab focus. */
67 static struct ml_widget_property properties[] =
69 { name: "form.text.size",
70 offset: ml_offsetof (struct ml_form_text, size),
72 { name: "form.text.maxlength",
73 offset: ml_offsetof (struct ml_form_text, maxlength),
79 new_ml_form_text (pool pool, ml_form form)
81 ml_form_text w = pmalloc (pool, sizeof *w);
83 w->ops = &form_text_ops;
84 w->fops = &form_text_input_ops;
87 w->size = w->maxlength = -1;
91 /* Register ourselves with the form. */
92 w->name = _ml_form_register_widget (form, w);
98 ml_form_text_focus (ml_form_text w)
104 clear_value (void *vw)
106 ml_form_text w = (ml_form_text) vw;
112 set_value (void *vw, const char *value)
114 ml_form_text w = (ml_form_text) vw;
123 ml_form_text w = (ml_form_text) vw;
129 repaint (void *vw, ml_session session, const char *windowid, io_handle io)
131 ml_form_text w = (ml_form_text) vw;
133 io_fprintf (io, "<input class=\"ml_form_text\" name=\"%s\" value=\"",
135 if (w->value) ml_plaintext_print (io, w->value);
138 io_fprintf (io, " size=\"%d\"", w->size);
139 if (w->maxlength >= 0)
140 io_fprintf (io, " maxlength=\"%d\"", w->maxlength);
141 io_fputs (" />", io);
143 /* XXX It is quite likely this won't work. It looks like we need to
144 * provide an onLoad function in the window to do this reliably.
148 const char *form_name;
150 ml_widget_get_property (w->form, "form.name", form_name);
152 io_fprintf (io, "<script language=\"javascript\"><!--\n"
153 " document.%s.%s.focus ();\n"