Add to git.
[monolith.git] / src / ml_iframe.c
1 /* Monolith iframe class.
2  * - by Richard W.M. Jones <rich@annexia.org>
3  *
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.
8  *
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.
13  *
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.
17  *
18  * $Id: ml_iframe.c,v 1.1 2002/11/08 23:19:14 rich Exp $
19  */
20
21 #include "config.h"
22
23 #include <pool.h>
24 #include <pstring.h>
25 #include <pthr_iolib.h>
26
27 #include "monolith.h"
28 #include "ml_widget.h"
29 #include "ml_iframe.h"
30
31 static void repaint (void *, ml_session, const char *, io_handle);
32 static struct ml_widget_property properties[];
33
34 struct ml_widget_operations iframe_ops =
35   {
36     repaint: repaint,
37     properties: properties,
38   };
39
40 struct ml_iframe
41 {
42   struct ml_widget_operations *ops;
43   pool pool;                    /* Pool for allocations. */
44   const char *action_id;        /* Action. */
45   ml_widget non_frame_widget;   /* Alternative for non-frames browsers. */
46   int width, height;            /* Width, height. */
47   const char *clazz;            /* Class. */
48   const char *scrolling;        /* "yes", "no" or "auto". */
49 };
50
51 static struct ml_widget_property properties[] =
52   {
53     { name: "width",
54       offset: ml_offsetof (struct ml_iframe, width),
55       type: ML_PROP_INT },
56     { name: "height",
57       offset: ml_offsetof (struct ml_iframe, height),
58       type: ML_PROP_INT },
59     { name: "class",
60       offset: ml_offsetof (struct ml_iframe, clazz),
61       type: ML_PROP_STRING },
62     { name: "scrolling",
63       offset: ml_offsetof (struct ml_iframe, scrolling),
64       type: ML_PROP_STRING },
65     { 0 }
66   };
67
68 ml_iframe
69 new_ml_iframe (pool pool, void (*fn) (ml_session, void *),
70                ml_session session, void *data,
71                ml_widget non_frame_widget)
72 {
73   ml_iframe w = pmalloc (pool, sizeof *w);
74
75   w->ops = &iframe_ops;
76   w->pool = pool;
77   w->clazz = 0;
78   w->scrolling = 0;
79   w->width = w->height = 0;
80   w->non_frame_widget = non_frame_widget;
81
82   /* Register the callback. */
83   w->action_id = ml_register_action (session, fn, data);
84
85   return w;
86 }
87
88 static void
89 repaint (void *vw, ml_session session, const char *windowid, io_handle io)
90 {
91   ml_iframe w = (ml_iframe) vw;
92
93   io_fprintf (io, "<iframe src=\"%s?ml_action=%s&ml_window=%s\"",
94               ml_session_script_name (session), w->action_id, windowid);
95
96   if (w->clazz)
97     io_fprintf (io, " class=\"%s\"", w->clazz);
98   if (w->width)
99     io_fprintf (io, " width=\"%d\"", w->width);
100   if (w->height)
101     io_fprintf (io, " height=\"%d\"", w->height);
102   if (w->scrolling)
103     io_fprintf (io, " scrolling=\"%s\"", w->scrolling);
104   io_fputs (">", io);
105
106   if (w->non_frame_widget)
107     ml_widget_repaint (w->non_frame_widget, session, windowid, io);
108   else
109     io_fputs ("Your browser does not support frames.", io);
110
111   io_fputs ("</iframe>", io);
112 }