1 /* Monolith tabbed layout 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_tabbed_layout.c,v 1.1 2002/11/13 20:46:37 rich Exp $
28 #include <pthr_iolib.h>
30 #include "ml_widget.h"
32 #include "ml_tabbed_layout.h"
34 static void repaint (void *, ml_session, const char *, io_handle);
36 struct ml_widget_operations tabbed_layout_ops =
41 struct ml_tabbed_layout
43 struct ml_widget_operations *ops;
44 pool pool; /* Pool for allocations. */
45 vector tabs; /* Vector of tabs. */
46 vector order; /* Display order (first = top). */
51 const char *name; /* Name of the tab. */
52 ml_widget w; /* Widget. */
56 new_ml_tabbed_layout (pool pool)
58 ml_tabbed_layout w = pmalloc (pool, sizeof *w);
60 w->ops = &tabbed_layout_ops;
62 w->tabs = new_vector (pool, struct tab);
63 w->order = new_vector (pool, int);
69 add_tab_to_order (ml_tabbed_layout w, int index)
71 vector_push_back (w->order, index);
75 del_tab_from_order (ml_tabbed_layout w, int index)
79 for (n = 0; n < vector_size (w->order); ++n)
81 vector_get (w->order, n, i);
84 vector_erase (w->order, n);
91 increment_order (ml_tabbed_layout w, int first_index)
95 for (n = 0; n < vector_size (w->order); ++n)
97 vector_get (w->order, n, i);
101 vector_replace (w->order, n, i);
107 decrement_order (ml_tabbed_layout w, int first_index)
111 for (n = 0; n < vector_size (w->order); ++n)
113 vector_get (w->order, n, i);
114 if (i >= first_index)
117 vector_replace (w->order, n, i);
123 ml_tabbed_layout_push_back (ml_tabbed_layout w, const char *name, ml_widget _w)
129 vector_push_back (w->tabs, tab);
131 add_tab_to_order (w, vector_size (w->tabs) - 1);
135 ml_tabbed_layout_pop_back (ml_tabbed_layout w)
139 vector_pop_back (w->tabs, tab);
140 del_tab_from_order (w, vector_size (w->tabs));
145 ml_tabbed_layout_push_front (ml_tabbed_layout w,
146 const char *name, ml_widget _w)
152 vector_push_front (w->tabs, tab);
154 increment_order (w, 0);
155 add_tab_to_order (w, 0);
159 ml_tabbed_layout_pop_front (ml_tabbed_layout w)
163 vector_pop_front (w->tabs, tab);
164 del_tab_from_order (w, vector_size (w->tabs));
165 decrement_order (w, 1);
170 ml_tabbed_layout_get (ml_tabbed_layout w, int i)
174 vector_get (w->tabs, i, tab);
179 ml_tabbed_layout_insert (ml_tabbed_layout w, int i,
180 const char *name, ml_widget _w)
186 vector_insert (w->tabs, i, tab);
188 increment_order (w, i);
189 add_tab_to_order (w, i);
193 ml_tabbed_layout_replace (ml_tabbed_layout w, int i,
194 const char *name, ml_widget _w)
200 vector_replace (w->tabs, i, tab);
202 ml_tabbed_layout_send_to_back (w, i);
206 ml_tabbed_layout_erase (ml_tabbed_layout w, int i)
208 vector_erase (w->tabs, i);
209 del_tab_from_order (w, i);
210 decrement_order (w, i+1);
214 ml_tabbed_layout_clear (ml_tabbed_layout w)
216 vector_clear (w->tabs);
217 vector_clear (w->order);
221 ml_tabbed_layout_size (ml_tabbed_layout w)
223 return vector_size (w->tabs);
227 ml_tabbed_layout_pack (ml_tabbed_layout w, const char *name, ml_widget _w)
229 ml_tabbed_layout_push_back (w, name, _w);
233 ml_tabbed_layout_bring_to_front (ml_tabbed_layout w, int i)
237 vector_pop_back (w->order, i);
238 vector_push_front (w->order, i);
242 ml_tabbed_layout_send_to_back (ml_tabbed_layout w, int i)
246 vector_pop_front (w->order, i);
247 vector_push_back (w->order, i);
251 ml_tabbed_layout_get_front_tab (ml_tabbed_layout w)
255 vector_get (w->order, 0, i);
259 /* This function verifies the integrity of the internal structures. We
260 * can remove it once the tabbed layout has become a bit more mature.
263 verify_structures (ml_tabbed_layout w)
269 assert (vector_size (w->tabs) == vector_size (w->order));
271 marks = new_vector (w->pool, unsigned char);
272 vector_fill (marks, c, vector_size (w->tabs));
274 for (n = 0; n < vector_size (w->order); ++n)
276 vector_get (w->order, n, i);
277 vector_get (marks, i, c);
280 vector_replace (marks, i, c);
285 repaint (void *vw, ml_session session, const char *windowid, io_handle io)
287 ml_tabbed_layout w = (ml_tabbed_layout) vw;
290 verify_structures (w);
294 for (i = 0; i < vector_size (w->v); ++i)
298 vector_get (w->v, i, _w);
299 ml_widget_repaint (_w, session, windowid, io);