1/* $Id: table.hg,v 1.3 2006/05/16 14:16:08 jjongsma Exp $ */
2
3/* Copyright (C) 1998-2002 The gtkmm Development Team
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
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 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser 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.
18 */
19
20#include <glibmm/helperlist.h>
21#include <gtkmm/container.h>
22#include <gtkmm/enums.h>
23
24//TODO: Careful of including this before box.h,
25//because we need to undef some things first.
26//TODO: Maybe do all includes of gtk.h in a single file.
27#include <gtk/gtk.h> /* for GtkTableChild */
28
29_DEFS(gtkmm,gtk)
30_PINCLUDE(gtkmm/private/container_p.h)
31
32#m4 _PUSH(SECTION_CC_PRE_INCLUDES)
33//Allow us to use the ->children struct field.
34//TODO: We probably need to remove the entire STL-style children() API in a future ABI break.
35#undef GSEAL_ENABLE
36#m4 _POP()
37
38namespace Gtk
39{
40
41class Table;
42
43/** @deprecated Use Container::get_children() instead.
44 */
45namespace Table_Helpers
46{
47
48/** @deprecated Use Container::get_children() instead.
49 */
50class Child : protected _GtkTableChild
51{
52private:
53  Child& operator=(const Child&); //Not implemented.
54  Child(const Child&); //Not implemented.
55
56public:
57  inline _GtkTableChild* gobj() {return (this);}
58  inline const _GtkTableChild* gobj() const {return (this);}
59
60_DEPRECATE_IFDEF_START
61  Widget* get_widget() const;
62
63  //TODO: Which of the GtkTableChild's fields are public API?
64  //Maybe we should remove some of these get()s or add some set()s.
65  //If get_widget() is the only accessor, then we should probably make
66  //the STL-style Table list contain Widgets instead of Childs.
67
68  guint16 get_left_attach() const;
69  guint16 get_right_attach() const;
70  guint16 get_top_attach() const;
71  guint16 get_bottom_attach() const;
72  guint16 get_xpadding() const;
73  guint16 get_ypadding() const;
74  bool get_xexpand() const;
75  bool get_yexpand() const;
76  bool get_xshrink() const;
77  bool get_yshrink() const;
78  bool get_xfill() const;
79  bool get_yfill() const;
80_DEPRECATE_IFDEF_END
81
82protected:
83  inline GtkTable* parent()
84    { return GTK_TABLE(gtk_widget_get_parent(gobj()->widget)); }
85
86#ifndef DOXYGEN_SHOULD_SKIP_THIS
87  friend class Dummy_; // silence the compiler (Child has only private ctors)
88#endif
89};
90
91
92#m4 include(list.m4)
93  GP_LIST(TableList,Table,GtkTable,Child,children)
94  //The standard iterator, instead of List_Cpp_Iterator,
95  //only works because Child is derived from _GtkTableChild.
96
97  GP_LIST_ELEM(Widget)
98  GP_LIST_NOINSERT()
99  GP_LIST_CONTAINER_REMOVE( get_widget )
100  GP_LIST_END()
101
102} // namespace Table_Helpers
103
104
105/** Pack widgets in regular patterns.
106 * @ingroup Widgets
107 * @ingroup Containers
108 * Gtk::Table is one of the primary ways of grouping widgets together.  It
109 * consists of a set of lattice points to to which widgets can be attached.
110 * There are <em>rows</em>&nbsp;+&nbsp;1 lattice points vertically and
111 * <em>columns</em>&nbsp;+&nbsp;1 lattice points horizontally.  Lattice points
112 * start counting from 0.  Lattice points can either be specified to be
113 * <em>homogeneous</em>, meaning equally spaced, or not <em>homogeneous</em>,
114 * meaning each cell should be calculated based on the widgets contained in the
115 * row and column. The <em>homogeneous</em> property defaults to false.
116 *
117 * Widgets can be attached to the table by specifying the top, bottom, left and
118 * right points corresponding to upper, lefthand lattice point and the lower,
119 * righthand lattice point which the widget should span.  Widgets can either be
120 * contained in a cell or may span cells.  A number of options control the
121 * resizing behavior of widgets contained in the table.
122 *
123 * @par Packing options:
124 * There are a number of packing options that can be specified when adding a
125 * widget.  With <tt>Gtk::EXPAND</tt>, the lattice is allowed to grow to fill
126 * space.  With <tt>Gtk::SHRINK</tt>, the lattice is allowed to shrink when
127 * resized.  It is also possible to specify the behaviour of the widgets
128 * allocation within the table.  The flag <tt>Gtk::FILL</tt> declares the
129 * widget should grow to fill lattice.  If this is not set any extra space is
130 * used as padding.  The default is <tt>(Gtk::FILL&nbsp;|&nbsp;Gtk::EXPAND)</tt>.
131 *
132 * @par Table sizing:
133 * The table size is calculated based on the size of the widgets contained
134 * within and the restrictions imposed by specified options.  Padding and
135 * spacing can be used in the table.  Padding is added on either side of a
136 * widget, while spacing is placed between widgets.
137 *
138 * A Table widget looks like this:
139 * @image html table1.png
140 *
141 * @see Gtk::HBox, Gtk::VBox
142 */
143class Table : public Container
144{
145  _CLASS_GTKOBJECT(Table,GtkTable,GTK_TABLE,Gtk::Container,GtkContainer)
146  _IGNORE(gtk_table_attach_defaults)
147public:
148  _WRAP_CTOR(Table(guint n_rows = 1, guint n_columns = 1, bool homogeneous = false), gtk_table_new)
149
150  _WRAP_METHOD(
151        void attach(Widget& child,
152                    guint left_attach, guint right_attach,
153                    guint top_attach, guint bottom_attach,
154                    AttachOptions xoptions = FILL | EXPAND, AttachOptions yoptions = FILL | EXPAND,
155                    guint xpadding = 0, guint ypadding = 0),
156        gtk_table_attach)
157
158
159  _WRAP_METHOD(void resize(guint rows, guint columns), gtk_table_resize)
160
161
162  _WRAP_METHOD(void set_row_spacing(guint row, guint spacing), gtk_table_set_row_spacing)
163  _WRAP_METHOD(guint get_row_spacing(guint row) const, gtk_table_get_row_spacing)
164
165  _WRAP_METHOD(void set_col_spacing(guint column, guint spacing), gtk_table_set_col_spacing)
166  _WRAP_METHOD(guint get_col_spacing(guint column) const, gtk_table_get_col_spacing)
167
168  _WRAP_METHOD(void set_row_spacings(guint spacing), gtk_table_set_row_spacings)
169
170  _WRAP_METHOD(void set_col_spacings(guint spacing), gtk_table_set_col_spacings)
171
172  void set_spacings(guint spacing);
173
174  _WRAP_METHOD(guint get_default_row_spacing(), gtk_table_get_default_row_spacing)
175  _WRAP_METHOD(guint get_default_col_spacing(), gtk_table_get_default_col_spacing)
176
177  _WRAP_METHOD(void set_homogeneous(bool homogeneous = true), gtk_table_set_homogeneous)
178  _WRAP_METHOD(bool get_homogeneous() const, gtk_table_get_homogeneous)
179
180  _WRAP_METHOD(void get_size(guint& rows,  guint& columns) const, gtk_table_get_size)
181
182  /** @deprecated Use Container::get_children() instead.
183   */
184  typedef Table_Helpers::TableList TableList;
185
186_DEPRECATE_IFDEF_START
187  /** @deprecated Use Container::get_children() instead.
188   */
189  TableList& children();
190
191  /** @deprecated Use Container::get_children() instead.
192   */
193  const TableList& children() const;
194_DEPRECATE_IFDEF_END
195
196  _WRAP_PROPERTY("n-rows", guint)
197  _WRAP_PROPERTY("n-columns", guint)
198  _WRAP_PROPERTY("column-spacing", guint)
199  _WRAP_PROPERTY("row-spacing", guint)
200  _WRAP_PROPERTY("homogeneous", bool)
201
202protected:
203#ifndef DOXYGEN_SHOULD_SKIP_THIS
204  mutable TableList children_proxy_;
205#endif /* DOXYGEN_SHOULD_SKIP_THIS */
206};
207
208} // namespace Gtk
209