Add to git.
[monolith.git] / src / ml_vertical_layout.c
1 /* Monolith vertical layout 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_vertical_layout.c,v 1.2 2003/01/12 22:12:42 rich Exp $
19  */
20
21 #include "config.h"
22
23 #include <pthr_iolib.h>
24
25 #include "ml_widget.h"
26 #include "monolith.h"
27 #include "ml_vertical_layout.h"
28
29 static void repaint (void *, ml_session, const char *, io_handle);
30 static struct ml_widget_property properties[];
31
32 struct ml_widget_operations vertical_layout_ops =
33   {
34     repaint: repaint,
35     properties: properties
36   };
37
38 struct ml_vertical_layout
39 {
40   struct ml_widget_operations *ops;
41   pool pool;                    /* Pool for allocations. */
42   const char *clazz;            /* Stylesheet class. */
43   vector v;                     /* Vector of widgets. */
44 };
45
46 static struct ml_widget_property properties[] =
47   {
48     { name: "class",
49       offset: ml_offsetof (struct ml_vertical_layout, clazz),
50       type: ML_PROP_STRING },
51     { 0 }
52   };
53
54 ml_vertical_layout
55 new_ml_vertical_layout (pool pool)
56 {
57   ml_vertical_layout w = pmalloc (pool, sizeof *w);
58
59   w->ops = &vertical_layout_ops;
60   w->pool = pool;
61   w->clazz = 0;
62   w->v = new_vector (pool, ml_widget);
63
64   return w;
65 }
66
67 void
68 ml_vertical_layout_push_back (ml_vertical_layout w, ml_widget _w)
69 {
70   vector_push_back (w->v, _w);
71 }
72
73 void
74 ml_vertical_layout_pack (ml_vertical_layout w, ml_widget _w)
75 {
76   vector_push_back (w->v, _w);
77 }
78
79 ml_widget
80 ml_vertical_layout_pop_back (ml_vertical_layout w)
81 {
82   ml_widget _w;
83
84   vector_pop_back (w->v, _w);
85   return _w;
86 }
87
88 void
89 ml_vertical_layout_push_front (ml_vertical_layout w, ml_widget _w)
90 {
91   vector_push_front (w->v, _w);
92 }
93
94 ml_widget
95 ml_vertical_layout_pop_front (ml_vertical_layout w)
96 {
97   ml_widget _w;
98
99   vector_pop_front (w->v, _w);
100   return _w;
101 }
102
103 ml_widget
104 ml_vertical_layout_get (ml_vertical_layout w, int i)
105 {
106   ml_widget _w;
107
108   vector_get (w->v, i, _w);
109   return _w;
110 }
111
112 void
113 ml_vertical_layout_insert (ml_vertical_layout w, int i, ml_widget _w)
114 {
115   vector_insert (w->v, i, _w);
116 }
117
118 void
119 ml_vertical_layout_replace (ml_vertical_layout w, int i, ml_widget _w)
120 {
121   vector_replace (w->v, i, _w);
122 }
123
124 void
125 ml_vertical_layout_erase (ml_vertical_layout w, int i)
126 {
127   vector_erase (w->v, i);
128 }
129
130 void
131 ml_vertical_layout_clear (ml_vertical_layout w)
132 {
133   vector_clear (w->v);
134 }
135
136 int
137 ml_vertical_layout_size (ml_vertical_layout w)
138 {
139   return vector_size (w->v);
140 }
141
142 static void
143 repaint (void *vw, ml_session session, const char *windowid, io_handle io)
144 {
145   ml_vertical_layout w = (ml_vertical_layout) vw;
146   int i;
147
148   for (i = 0; i < vector_size (w->v); ++i)
149     {
150       ml_widget _w;
151
152       vector_get (w->v, i, _w);
153       io_fputs ("<div", io);
154       if (w->clazz) io_fprintf (io, " class=\"%s\"", w->clazz);
155       io_fputc ('>', io);
156       ml_widget_repaint (_w, session, windowid, io);
157       io_fputs ("</div>\n", io);
158     }
159 }