1 /* $Id: box.hg,v 1.10 2006/01/28 18:49:13 jjongsma Exp $ */
3 /* Copyright (C) 1998-2002 The gtkmm Development Team
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 _PINCLUDE(gtkmm/private/container_p.h)
23 #include <gtkmm/container.h>
24 #include <glibmm/helperlist.h>
25 #include <gtk/gtkbox.h> /* For _GtkBoxChild */
31 /** Packing options for adding child widgets to a Box with pack_start() and pack_end().
36 PACK_SHRINK, /**< Space is contracted to the child widget size. */
37 PACK_EXPAND_PADDING, /**< Space is expanded, with extra space filled with padding. */
38 PACK_EXPAND_WIDGET /**< Space is expanded, with extra space filled by increasing the child widget size. */
46 //This may not have any data or virtual functions. See below.
47 class Child : protected _GtkBoxChild
50 Child& operator=(const Child&); //Not implemented.
51 Child(const Child&); //Not implemented.
54 /// Provides access to the underlying C GObject.
55 inline _GtkBoxChild* gobj() { return this; }
56 /// Provides access to the underlying C GObject.
57 inline const _GtkBoxChild* gobj() const { return this; }
59 Widget* get_widget() const;
61 inline guint16 get_padding() const { return (gobj()->padding); }
62 inline bool get_expand() const { return (gobj()->expand); }
63 inline bool get_fill() const { return (gobj()->fill); }
64 inline bool get_pack() const { return (gobj()->pack); }
66 void set_options(PackOptions options, guint padding = 0);
67 void set_options(bool expand, bool fill, guint padding = 0);
69 void set_pack(PackType pack);
72 inline GtkBox* parent()
73 { return (GtkBox*) (gobj()->widget->parent); }
77 #ifndef DOXYGEN_SHOULD_SKIP_THIS
78 friend class Dummy_; // silence the compiler (Child has only private ctors)
85 Element(Widget& widget,
86 PackOptions options = PACK_EXPAND_WIDGET,
88 PackType pack = PACK_START)
89 : widget_(&widget), options_(options),
90 padding_(padding), pack_(pack)
99 typedef Element StartElem;
101 struct EndElem : public Element
103 EndElem(Widget& widget,
104 PackOptions options = PACK_EXPAND_WIDGET,
106 : Element (widget, options, padding, PACK_END)
111 GP_LIST(BoxList,Box,GtkBox,Child,children)
112 //The standard iterator, instead of List_Cpp_Iterator,
113 //only works because Child is derived from _GtkBoxChild.
115 GP_LIST_FIND(get_widget)
116 GP_LIST_CONTAINER_REMOVE(get_widget)
118 void reorder(iterator loc,iterator pos);
121 } /* namespace Box_Helpers */
124 /** A base class for box containers
126 * Abstract base class for horizontal and vertical boxes, which organize a
127 * variable number of widgets into a rectangular area. This is an abstract
128 * class and it defers choice of which way the widgets are packed to the screen
129 * to the derived classes. It provides a common interface for inserting
130 * widgets to a box indepenently of how it is shown in the screen.
132 * Gtk::Box uses a notion of packing. Packing refers to adding widgets with
133 * reference to a particular position in a Gtk::Container. There are two
134 * reference positions: the start and the end of the box. For a VBox, the start
135 * is defined as the top of the box and the end is defined as the bottom. For
136 * a HBox the start is defined as the left side and the end is defined as the
137 * right side. Use repeated calls to pack_start() to pack widgets into a
138 * Gtk::Box from start to end. Use pack_end() to add widgets from end to start.
139 * You may intersperse these calls and add widgets from both ends of the same
140 * Gtk::Box. The last widget added with pack_start() will be placed just before
141 * the last widget added with pack_end()
143 * Because Gtk::Box is a Gtk::Container, you may also use Gtk::Container::add()
144 * to insert widgets, and they will be packed as if with pack_start(). Use
145 * Gtk::Container::remove() to remove widgets.
147 * Use set_homogeneous() to specify whether or not all children of the Gtk::Box
148 * occupy the same amount of space. Use set_spacing() to determine the minimum
149 * space placed between all children in the Gtk::Box. Use reorder_child() to
150 * move a child widget to a different place in the box. Use
151 * set_child_packing() to reset the pack options and padding attributes of any
152 * Gtk::Box child. Use query_child_packing() to query these fields.
154 class Box : public Container
156 _CLASS_GTKOBJECT(Box,GtkBox,GTK_BOX,Gtk::Container,GtkContainer)
157 _IGNORE(gtk_box_pack_end_defaults, gtk_box_set_child_packing, gtk_box_pack_start_defaults, gtk_box_query_child_packing)
159 typedef Box_Helpers::BoxList BoxList;
165 _WRAP_METHOD(void pack_start(Widget& child, bool expand, bool fill, guint padding = 0), gtk_box_pack_start)
167 /** Left side insert a widget to a box.
168 * @param child A Widget to be added to box.
169 * @param options Controls how the widget expands to fill space, and how the space around them is used.
170 * @param padding Padding that is added on either side of the widget. This is different to spacing set when the box is created (or with set_spacing()) - spacing is added between objects, and padding is added on either side of an object.
172 void pack_start(Widget& child, PackOptions options = PACK_EXPAND_WIDGET, guint padding = 0);
174 _WRAP_METHOD(void pack_end(Widget& child, bool expand, bool fill, guint padding = 0), gtk_box_pack_end)
176 /** Right side insert a widget to a box.
177 * @param child A Widget to be added to box.
178 * @param options Controls how the widget expands to fill space, and how the space around them is used.
179 * @param padding Padding that is added on either side of the widget. This is different to spacing set when the box is created (or with set_spacing()) - spacing is added between objects, and padding is added on either side of an object.
181 void pack_end(Widget& child, PackOptions options = PACK_EXPAND_WIDGET, guint padding = 0);
183 _WRAP_METHOD(void set_homogeneous(bool homogeneous = true), gtk_box_set_homogeneous)
184 _WRAP_METHOD(bool get_homogeneous() const, gtk_box_get_homogeneous)
186 _WRAP_METHOD(void set_spacing(int spacing), gtk_box_set_spacing)
187 _WRAP_METHOD(int get_spacing() const, gtk_box_get_spacing)
189 _WRAP_METHOD(void reorder_child(Widget& child, int pos), gtk_box_reorder_child)
191 /* Get the child widgets.
192 * @result An STL-style container of pointers to the box's child widgets.
196 /* Get the child widgets.
197 * @result An STL-style container of pointers to the box's child widgets.
199 const BoxList& children() const;
201 _WRAP_PROPERTY("spacing", int)
202 _WRAP_PROPERTY("homogeneous", bool)
205 #ifndef DOXYGEN_SHOULD_SKIP_THIS
206 mutable BoxList children_proxy_;
207 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
211 /** Vertical Box for laying widgets in a vertical row.
213 * You should create these objects, but it is more confortable to pass
214 * around pointers of Gtk::Box. All the methods that do anything are in
215 * class Gtk::Box and this allows you to later change the direction of the
216 * box, when there's no dependencies to HBox and VBox classes.
219 * @ingroup Containers
221 class VBox : public Box
223 _CLASS_GTKOBJECT(VBox,GtkVBox,GTK_VBOX,Gtk::Box,GtkBox)
226 /** Creates a new vertical box.
227 * @param homogeneous Whether each widget in the VBox should have the same
228 * height. If set, a PACK_SHRINK argument to pack_start() or pack_end() is
230 * @param spacing Determines the space in pixels between child widgets.
232 _WRAP_CTOR(VBox(bool homogeneous = false, int spacing = 0), gtk_vbox_new)
236 /** Horizontal Box for laying widgets in a horizontal row.
238 * You should create these objects, but it is more confortable to pass
239 * around pointers of Gtk::Box. All the methods that do anything are in
240 * class Gtk::Box and this allows you to later change the direction of the
241 * box, when there's no dependencies to HBox and VBox classes.
243 * Use the Gtk::Box packing interface to determine the arrangement, spacing,
244 * width, and alignment of Gtk::HBox children.
246 * All children are allocated the same height.
249 * @ingroup Containers
251 class HBox : public Box
253 _CLASS_GTKOBJECT(HBox,GtkHBox,GTK_HBOX,Gtk::Box,GtkBox)
256 /** Creates a new horizontal box.
257 * @param homogeneous Whether each widget in the HBox should have the same
258 * width. If set, a PACK_SHRINK argument to pack_start() or pack_end() is
260 * @param spacing Determines the space in pixels between child widgets.
262 _WRAP_CTOR(HBox(bool homogeneous = false, int spacing = 0), gtk_hbox_new)