Add to git.
[monolith.git] / src / ml_horizontal_layout.c
1 /* Monolith horizontal 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_horizontal_layout.c,v 1.1 2002/11/03 09:39:46 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_horizontal_layout.h"
28
29 static void repaint (void *, ml_session, const char *, io_handle);
30
31 struct ml_widget_operations horizontal_layout_ops =
32   {
33     repaint: repaint
34   };
35
36 struct ml_horizontal_layout
37 {
38   struct ml_widget_operations *ops;
39   pool pool;                    /* Pool for allocations. */
40   vector v;                     /* Vector of widgets. */
41 };
42
43 ml_horizontal_layout
44 new_ml_horizontal_layout (pool pool)
45 {
46   ml_horizontal_layout w = pmalloc (pool, sizeof *w);
47
48   w->ops = &horizontal_layout_ops;
49   w->pool = pool;
50   w->v = new_vector (pool, ml_widget);
51
52   return w;
53 }
54
55 void
56 ml_horizontal_layout_push_back (ml_horizontal_layout w, ml_widget _w)
57 {
58   vector_push_back (w->v, _w);
59 }
60
61 void
62 ml_horizontal_layout_pack (ml_horizontal_layout w, ml_widget _w)
63 {
64   vector_push_back (w->v, _w);
65 }
66
67 ml_widget
68 ml_horizontal_layout_pop_back (ml_horizontal_layout w)
69 {
70   ml_widget _w;
71
72   vector_pop_back (w->v, _w);
73   return _w;
74 }
75
76 void
77 ml_horizontal_layout_push_front (ml_horizontal_layout w, ml_widget _w)
78 {
79   vector_push_front (w->v, _w);
80 }
81
82 ml_widget
83 ml_horizontal_layout_pop_front (ml_horizontal_layout w)
84 {
85   ml_widget _w;
86
87   vector_pop_front (w->v, _w);
88   return _w;
89 }
90
91 ml_widget
92 ml_horizontal_layout_get (ml_horizontal_layout w, int i)
93 {
94   ml_widget _w;
95
96   vector_get (w->v, i, _w);
97   return _w;
98 }
99
100 void
101 ml_horizontal_layout_insert (ml_horizontal_layout w, int i, ml_widget _w)
102 {
103   vector_insert (w->v, i, _w);
104 }
105
106 void
107 ml_horizontal_layout_replace (ml_horizontal_layout w, int i, ml_widget _w)
108 {
109   vector_replace (w->v, i, _w);
110 }
111
112 void
113 ml_horizontal_layout_erase (ml_horizontal_layout w, int i)
114 {
115   vector_erase (w->v, i);
116 }
117
118 void
119 ml_horizontal_layout_clear (ml_horizontal_layout w)
120 {
121   vector_clear (w->v);
122 }
123
124 int
125 ml_horizontal_layout_size (ml_horizontal_layout w)
126 {
127   return vector_size (w->v);
128 }
129
130 static void
131 repaint (void *vw, ml_session session, const char *windowid, io_handle io)
132 {
133   ml_horizontal_layout w = (ml_horizontal_layout) vw;
134   int i;
135
136   io_fputs ("<table><tr>", io);
137
138   for (i = 0; i < vector_size (w->v); ++i)
139     {
140       ml_widget _w;
141
142       vector_get (w->v, i, _w);
143       io_fputs ("<td valign=\"top\">", io);
144       ml_widget_repaint (_w, session, windowid, io);
145       io_fputs ("</td>\n", io);
146     }
147
148   io_fputs ("</tr></table>", io);
149 }