1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser 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 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #define GDK_DISABLE_DEPRECATION_WARNINGS
31 #include "gtktypebuiltins.h"
32 #include "gtkprivate.h"
38 * @Short_description: Pack widgets in regular patterns
42 * The #GtkTable functions allow the programmer to arrange widgets in rows and
43 * columns, making it easy to align many widgets next to each other,
44 * horizontally and vertically.
46 * Tables are created with a call to gtk_table_new(), the size of which can
47 * later be changed with gtk_table_resize().
49 * Widgets can be added to a table using gtk_table_attach() or the more
50 * convenient (but slightly less flexible) gtk_table_attach_defaults().
52 * To alter the space next to a specific row, use gtk_table_set_row_spacing(),
53 * and for a column, gtk_table_set_col_spacing().
54 * The gaps between <emphasis>all</emphasis> rows or columns can be changed by
55 * calling gtk_table_set_row_spacings() or gtk_table_set_col_spacings()
56 * respectively. Note that spacing is added <emphasis>between</emphasis> the
57 * children, while padding added by gtk_table_attach() is added <emphasis>on
58 * either side</emphasis> of the widget it belongs to.
60 * gtk_table_set_homogeneous(), can be used to set whether all cells in the
61 * table will resize themselves to the size of the largest widget in the table.
64 * #GtkTable has been deprecated. Use #GtkGrid instead. It provides the same
65 * capabilities as GtkTable for arranging widgets in a rectangular grid, but
66 * does support height-for-width geometry management.
71 struct _GtkTablePrivate
78 guint16 column_spacing;
83 guint homogeneous : 1;
99 CHILD_PROP_LEFT_ATTACH,
100 CHILD_PROP_RIGHT_ATTACH,
101 CHILD_PROP_TOP_ATTACH,
102 CHILD_PROP_BOTTOM_ATTACH,
103 CHILD_PROP_X_OPTIONS,
104 CHILD_PROP_Y_OPTIONS,
105 CHILD_PROP_X_PADDING,
110 static void gtk_table_finalize (GObject *object);
111 static void gtk_table_get_preferred_width (GtkWidget *widget,
114 static void gtk_table_get_preferred_height (GtkWidget *widget,
117 static void gtk_table_size_allocate (GtkWidget *widget,
118 GtkAllocation *allocation);
119 static void gtk_table_compute_expand (GtkWidget *widget,
122 static void gtk_table_add (GtkContainer *container,
124 static void gtk_table_remove (GtkContainer *container,
126 static void gtk_table_forall (GtkContainer *container,
127 gboolean include_internals,
128 GtkCallback callback,
129 gpointer callback_data);
130 static void gtk_table_get_property (GObject *object,
134 static void gtk_table_set_property (GObject *object,
138 static void gtk_table_set_child_property (GtkContainer *container,
143 static void gtk_table_get_child_property (GtkContainer *container,
148 static GType gtk_table_child_type (GtkContainer *container);
151 static void gtk_table_size_request_init (GtkTable *table);
152 static void gtk_table_size_request_pass1 (GtkTable *table);
153 static void gtk_table_size_request_pass2 (GtkTable *table);
154 static void gtk_table_size_request_pass3 (GtkTable *table);
156 static void gtk_table_size_allocate_init (GtkTable *table);
157 static void gtk_table_size_allocate_pass1 (GtkTable *table);
158 static void gtk_table_size_allocate_pass2 (GtkTable *table);
161 G_DEFINE_TYPE (GtkTable, gtk_table, GTK_TYPE_CONTAINER)
164 gtk_table_class_init (GtkTableClass *class)
166 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
167 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
168 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
170 gobject_class->finalize = gtk_table_finalize;
172 gobject_class->get_property = gtk_table_get_property;
173 gobject_class->set_property = gtk_table_set_property;
175 widget_class->get_preferred_width = gtk_table_get_preferred_width;
176 widget_class->get_preferred_height = gtk_table_get_preferred_height;
177 widget_class->size_allocate = gtk_table_size_allocate;
178 widget_class->compute_expand = gtk_table_compute_expand;
180 container_class->add = gtk_table_add;
181 container_class->remove = gtk_table_remove;
182 container_class->forall = gtk_table_forall;
183 container_class->child_type = gtk_table_child_type;
184 container_class->set_child_property = gtk_table_set_child_property;
185 container_class->get_child_property = gtk_table_get_child_property;
186 gtk_container_class_handle_border_width (container_class);
188 g_object_class_install_property (gobject_class,
190 g_param_spec_uint ("n-rows",
192 P_("The number of rows in the table"),
196 GTK_PARAM_READWRITE));
197 g_object_class_install_property (gobject_class,
199 g_param_spec_uint ("n-columns",
201 P_("The number of columns in the table"),
205 GTK_PARAM_READWRITE));
206 g_object_class_install_property (gobject_class,
208 g_param_spec_uint ("row-spacing",
210 P_("The amount of space between two consecutive rows"),
214 GTK_PARAM_READWRITE));
215 g_object_class_install_property (gobject_class,
217 g_param_spec_uint ("column-spacing",
218 P_("Column spacing"),
219 P_("The amount of space between two consecutive columns"),
223 GTK_PARAM_READWRITE));
224 g_object_class_install_property (gobject_class,
226 g_param_spec_boolean ("homogeneous",
228 P_("If TRUE, the table cells are all the same width/height"),
230 GTK_PARAM_READWRITE));
232 gtk_container_class_install_child_property (container_class,
233 CHILD_PROP_LEFT_ATTACH,
234 g_param_spec_uint ("left-attach",
235 P_("Left attachment"),
236 P_("The column number to attach the left side of the child to"),
238 GTK_PARAM_READWRITE));
239 gtk_container_class_install_child_property (container_class,
240 CHILD_PROP_RIGHT_ATTACH,
241 g_param_spec_uint ("right-attach",
242 P_("Right attachment"),
243 P_("The column number to attach the right side of a child widget to"),
245 GTK_PARAM_READWRITE));
246 gtk_container_class_install_child_property (container_class,
247 CHILD_PROP_TOP_ATTACH,
248 g_param_spec_uint ("top-attach",
249 P_("Top attachment"),
250 P_("The row number to attach the top of a child widget to"),
252 GTK_PARAM_READWRITE));
253 gtk_container_class_install_child_property (container_class,
254 CHILD_PROP_BOTTOM_ATTACH,
255 g_param_spec_uint ("bottom-attach",
256 P_("Bottom attachment"),
257 P_("The row number to attach the bottom of the child to"),
259 GTK_PARAM_READWRITE));
260 gtk_container_class_install_child_property (container_class,
261 CHILD_PROP_X_OPTIONS,
262 g_param_spec_flags ("x-options",
263 P_("Horizontal options"),
264 P_("Options specifying the horizontal behaviour of the child"),
265 GTK_TYPE_ATTACH_OPTIONS, GTK_EXPAND | GTK_FILL,
266 GTK_PARAM_READWRITE));
267 gtk_container_class_install_child_property (container_class,
268 CHILD_PROP_Y_OPTIONS,
269 g_param_spec_flags ("y-options",
270 P_("Vertical options"),
271 P_("Options specifying the vertical behaviour of the child"),
272 GTK_TYPE_ATTACH_OPTIONS, GTK_EXPAND | GTK_FILL,
273 GTK_PARAM_READWRITE));
274 gtk_container_class_install_child_property (container_class,
275 CHILD_PROP_X_PADDING,
276 g_param_spec_uint ("x-padding",
277 P_("Horizontal padding"),
278 P_("Extra space to put between the child and its left and right neighbors, in pixels"),
280 GTK_PARAM_READWRITE));
281 gtk_container_class_install_child_property (container_class,
282 CHILD_PROP_Y_PADDING,
283 g_param_spec_uint ("y-padding",
284 P_("Vertical padding"),
285 P_("Extra space to put between the child and its upper and lower neighbors, in pixels"),
287 GTK_PARAM_READWRITE));
289 g_type_class_add_private (class, sizeof (GtkTablePrivate));
293 gtk_table_compute_expand (GtkWidget *widget,
297 GtkTable *table = GTK_TABLE (widget);
298 GtkTablePrivate *priv = table->priv;
300 GtkTableChild *child;
307 for (list = priv->children; list; list = list->next)
312 hexpand = child->xexpand ||
313 gtk_widget_compute_expand (child->widget,
314 GTK_ORIENTATION_HORIZONTAL);
317 vexpand = child->yexpand ||
318 gtk_widget_compute_expand (child->widget,
319 GTK_ORIENTATION_VERTICAL);
321 if (hexpand && vexpand)
325 *hexpand_p = hexpand;
326 *vexpand_p = vexpand;
330 gtk_table_child_type (GtkContainer *container)
332 return GTK_TYPE_WIDGET;
336 gtk_table_get_property (GObject *object,
341 GtkTable *table = GTK_TABLE (object);
342 GtkTablePrivate *priv = table->priv;
347 g_value_set_uint (value, priv->nrows);
350 g_value_set_uint (value, priv->ncols);
352 case PROP_ROW_SPACING:
353 g_value_set_uint (value, priv->row_spacing);
355 case PROP_COLUMN_SPACING:
356 g_value_set_uint (value, priv->column_spacing);
358 case PROP_HOMOGENEOUS:
359 g_value_set_boolean (value, priv->homogeneous);
362 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
368 gtk_table_set_property (GObject *object,
373 GtkTable *table = GTK_TABLE (object);
374 GtkTablePrivate *priv = table->priv;
379 gtk_table_resize (table, g_value_get_uint (value), priv->ncols);
382 gtk_table_resize (table, priv->nrows, g_value_get_uint (value));
384 case PROP_ROW_SPACING:
385 gtk_table_set_row_spacings (table, g_value_get_uint (value));
387 case PROP_COLUMN_SPACING:
388 gtk_table_set_col_spacings (table, g_value_get_uint (value));
390 case PROP_HOMOGENEOUS:
391 gtk_table_set_homogeneous (table, g_value_get_boolean (value));
394 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
400 gtk_table_set_child_property (GtkContainer *container,
406 GtkTable *table = GTK_TABLE (container);
407 GtkTablePrivate *priv = table->priv;
408 GtkTableChild *table_child;
412 for (list = priv->children; list; list = list->next)
414 table_child = list->data;
416 if (table_child->widget == child)
421 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
427 case CHILD_PROP_LEFT_ATTACH:
428 table_child->left_attach = g_value_get_uint (value);
429 if (table_child->right_attach <= table_child->left_attach)
430 table_child->right_attach = table_child->left_attach + 1;
431 if (table_child->right_attach >= priv->ncols)
432 gtk_table_resize (table, priv->nrows, table_child->right_attach);
434 case CHILD_PROP_RIGHT_ATTACH:
435 table_child->right_attach = g_value_get_uint (value);
436 if (table_child->right_attach <= table_child->left_attach)
437 table_child->left_attach = table_child->right_attach - 1;
438 if (table_child->right_attach >= priv->ncols)
439 gtk_table_resize (table, priv->nrows, table_child->right_attach);
441 case CHILD_PROP_TOP_ATTACH:
442 table_child->top_attach = g_value_get_uint (value);
443 if (table_child->bottom_attach <= table_child->top_attach)
444 table_child->bottom_attach = table_child->top_attach + 1;
445 if (table_child->bottom_attach >= priv->nrows)
446 gtk_table_resize (table, table_child->bottom_attach, priv->ncols);
448 case CHILD_PROP_BOTTOM_ATTACH:
449 table_child->bottom_attach = g_value_get_uint (value);
450 if (table_child->bottom_attach <= table_child->top_attach)
451 table_child->top_attach = table_child->bottom_attach - 1;
452 if (table_child->bottom_attach >= priv->nrows)
453 gtk_table_resize (table, table_child->bottom_attach, priv->ncols);
455 case CHILD_PROP_X_OPTIONS:
459 xexpand = (g_value_get_flags (value) & GTK_EXPAND) != 0;
461 if (table_child->xexpand != xexpand)
463 table_child->xexpand = xexpand;
464 gtk_widget_queue_compute_expand (GTK_WIDGET (table));
467 table_child->xshrink = (g_value_get_flags (value) & GTK_SHRINK) != 0;
468 table_child->xfill = (g_value_get_flags (value) & GTK_FILL) != 0;
471 case CHILD_PROP_Y_OPTIONS:
475 yexpand = (g_value_get_flags (value) & GTK_EXPAND) != 0;
477 if (table_child->yexpand != yexpand)
479 table_child->yexpand = yexpand;
480 gtk_widget_queue_compute_expand (GTK_WIDGET (table));
483 table_child->yshrink = (g_value_get_flags (value) & GTK_SHRINK) != 0;
484 table_child->yfill = (g_value_get_flags (value) & GTK_FILL) != 0;
487 case CHILD_PROP_X_PADDING:
488 table_child->xpadding = g_value_get_uint (value);
490 case CHILD_PROP_Y_PADDING:
491 table_child->ypadding = g_value_get_uint (value);
494 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
497 if (gtk_widget_get_visible (child) &&
498 gtk_widget_get_visible (GTK_WIDGET (table)))
499 gtk_widget_queue_resize (child);
503 gtk_table_get_child_property (GtkContainer *container,
509 GtkTable *table = GTK_TABLE (container);
510 GtkTablePrivate *priv = table->priv;
511 GtkTableChild *table_child;
515 for (list = priv->children; list; list = list->next)
517 table_child = list->data;
519 if (table_child->widget == child)
524 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
530 case CHILD_PROP_LEFT_ATTACH:
531 g_value_set_uint (value, table_child->left_attach);
533 case CHILD_PROP_RIGHT_ATTACH:
534 g_value_set_uint (value, table_child->right_attach);
536 case CHILD_PROP_TOP_ATTACH:
537 g_value_set_uint (value, table_child->top_attach);
539 case CHILD_PROP_BOTTOM_ATTACH:
540 g_value_set_uint (value, table_child->bottom_attach);
542 case CHILD_PROP_X_OPTIONS:
543 g_value_set_flags (value, (table_child->xexpand * GTK_EXPAND |
544 table_child->xshrink * GTK_SHRINK |
545 table_child->xfill * GTK_FILL));
547 case CHILD_PROP_Y_OPTIONS:
548 g_value_set_flags (value, (table_child->yexpand * GTK_EXPAND |
549 table_child->yshrink * GTK_SHRINK |
550 table_child->yfill * GTK_FILL));
552 case CHILD_PROP_X_PADDING:
553 g_value_set_uint (value, table_child->xpadding);
555 case CHILD_PROP_Y_PADDING:
556 g_value_set_uint (value, table_child->ypadding);
559 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
565 gtk_table_init (GtkTable *table)
567 GtkTablePrivate *priv;
569 table->priv = G_TYPE_INSTANCE_GET_PRIVATE (table,
574 gtk_widget_set_has_window (GTK_WIDGET (table), FALSE);
575 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (table), FALSE);
577 priv->children = NULL;
582 priv->column_spacing = 0;
583 priv->row_spacing = 0;
584 priv->homogeneous = FALSE;
586 gtk_table_resize (table, 1, 1);
591 * @rows: The number of rows the new table should have.
592 * @columns: The number of columns the new table should have.
593 * @homogeneous: If set to %TRUE, all table cells are resized to the size of
594 * the cell containing the largest widget.
596 * Used to create a new table widget. An initial size must be given by
597 * specifying how many rows and columns the table should have, although
598 * this can be changed later with gtk_table_resize(). @rows and @columns
599 * must both be in the range 1 .. 65535. For historical reasons, 0 is accepted
600 * as well and is silently interpreted as 1.
602 * Returns: A pointer to the newly created table widget.
604 * Deprecated: 3.4: Use gtk_grid_new().
607 gtk_table_new (guint rows,
609 gboolean homogeneous)
612 GtkTablePrivate *priv;
619 table = g_object_new (GTK_TYPE_TABLE, NULL);
622 priv->homogeneous = (homogeneous ? TRUE : FALSE);
624 gtk_table_resize (table, rows, columns);
626 return GTK_WIDGET (table);
631 * @table: The #GtkTable you wish to change the size of.
632 * @rows: The new number of rows.
633 * @columns: The new number of columns.
635 * If you need to change a table's size <emphasis>after</emphasis>
636 * it has been created, this function allows you to do so.
638 * Deprecated: 3.4: #GtkGrid resizes automatically.
641 gtk_table_resize (GtkTable *table,
645 GtkTablePrivate *priv;
647 g_return_if_fail (GTK_IS_TABLE (table));
648 g_return_if_fail (n_rows > 0 && n_rows <= 65535);
649 g_return_if_fail (n_cols > 0 && n_cols <= 65535);
653 n_rows = MAX (n_rows, 1);
654 n_cols = MAX (n_cols, 1);
656 if (n_rows != priv->nrows ||
657 n_cols != priv->ncols)
661 for (list = priv->children; list; list = list->next)
663 GtkTableChild *child;
667 n_rows = MAX (n_rows, child->bottom_attach);
668 n_cols = MAX (n_cols, child->right_attach);
671 if (n_rows != priv->nrows)
676 priv->nrows = n_rows;
677 priv->rows = g_realloc (priv->rows, priv->nrows * sizeof (GtkTableRowCol));
679 for (; i < priv->nrows; i++)
681 priv->rows[i].requisition = 0;
682 priv->rows[i].allocation = 0;
683 priv->rows[i].spacing = priv->row_spacing;
684 priv->rows[i].need_expand = 0;
685 priv->rows[i].need_shrink = 0;
686 priv->rows[i].expand = 0;
687 priv->rows[i].shrink = 0;
690 g_object_notify (G_OBJECT (table), "n-rows");
693 if (n_cols != priv->ncols)
698 priv->ncols = n_cols;
699 priv->cols = g_realloc (priv->cols, priv->ncols * sizeof (GtkTableRowCol));
701 for (; i < priv->ncols; i++)
703 priv->cols[i].requisition = 0;
704 priv->cols[i].allocation = 0;
705 priv->cols[i].spacing = priv->column_spacing;
706 priv->cols[i].need_expand = 0;
707 priv->cols[i].need_shrink = 0;
708 priv->cols[i].expand = 0;
709 priv->cols[i].shrink = 0;
712 g_object_notify (G_OBJECT (table), "n-columns");
719 * @table: The #GtkTable to add a new widget to.
720 * @child: The widget to add.
721 * @left_attach: the column number to attach the left side of a child widget to.
722 * @right_attach: the column number to attach the right side of a child widget to.
723 * @top_attach: the row number to attach the top of a child widget to.
724 * @bottom_attach: the row number to attach the bottom of a child widget to.
725 * @xoptions: Used to specify the properties of the child widget when the table is resized.
726 * @yoptions: The same as xoptions, except this field determines behaviour of vertical resizing.
727 * @xpadding: An integer value specifying the padding on the left and right of the widget being added to the table.
728 * @ypadding: The amount of padding above and below the child widget.
730 * Adds a widget to a table. The number of 'cells' that a widget will occupy is
731 * specified by @left_attach, @right_attach, @top_attach and @bottom_attach.
732 * These each represent the leftmost, rightmost, uppermost and lowest column
733 * and row numbers of the table. (Columns and rows are indexed from zero).
735 * To make a button occupy the lower right cell of a 2x2 table, use
736 * <informalexample><programlisting>
737 * gtk_table_attach (table, button,
738 * 1, 2, // left, right attach
739 * 1, 2, // top, bottom attach
740 * xoptions, yoptions,
741 * xpadding, ypadding);
742 * </programlisting></informalexample>
743 * If you want to make the button span the entire bottom row, use @left_attach == 0 and @right_attach = 2 instead.
745 * Deprecated: 3.4: Use gtk_grid_attach() with #GtkGrid. Note that the attach
746 * arguments differ between those two functions.
749 gtk_table_attach (GtkTable *table,
755 GtkAttachOptions xoptions,
756 GtkAttachOptions yoptions,
760 GtkTablePrivate *priv;
761 GtkTableChild *table_child;
763 g_return_if_fail (GTK_IS_TABLE (table));
764 g_return_if_fail (GTK_IS_WIDGET (child));
765 g_return_if_fail (gtk_widget_get_parent (child) == NULL);
767 /* g_return_if_fail (left_attach >= 0); */
768 g_return_if_fail (left_attach < right_attach);
769 /* g_return_if_fail (top_attach >= 0); */
770 g_return_if_fail (top_attach < bottom_attach);
774 if (right_attach >= priv->ncols)
775 gtk_table_resize (table, priv->nrows, right_attach);
777 if (bottom_attach >= priv->nrows)
778 gtk_table_resize (table, bottom_attach, priv->ncols);
780 table_child = g_new (GtkTableChild, 1);
781 table_child->widget = child;
782 table_child->left_attach = left_attach;
783 table_child->right_attach = right_attach;
784 table_child->top_attach = top_attach;
785 table_child->bottom_attach = bottom_attach;
786 table_child->xexpand = (xoptions & GTK_EXPAND) != 0;
787 table_child->xshrink = (xoptions & GTK_SHRINK) != 0;
788 table_child->xfill = (xoptions & GTK_FILL) != 0;
789 table_child->xpadding = xpadding;
790 table_child->yexpand = (yoptions & GTK_EXPAND) != 0;
791 table_child->yshrink = (yoptions & GTK_SHRINK) != 0;
792 table_child->yfill = (yoptions & GTK_FILL) != 0;
793 table_child->ypadding = ypadding;
795 priv->children = g_list_prepend (priv->children, table_child);
797 gtk_widget_set_parent (child, GTK_WIDGET (table));
801 * gtk_table_attach_defaults:
802 * @table: The table to add a new child widget to.
803 * @widget: The child widget to add.
804 * @left_attach: The column number to attach the left side of the child widget to.
805 * @right_attach: The column number to attach the right side of the child widget to.
806 * @top_attach: The row number to attach the top of the child widget to.
807 * @bottom_attach: The row number to attach the bottom of the child widget to.
809 * As there are many options associated with gtk_table_attach(), this convenience
810 * function provides the programmer with a means to add children to a table with
811 * identical padding and expansion options. The values used for the #GtkAttachOptions
812 * are <literal>GTK_EXPAND | GTK_FILL</literal>, and the padding is set to 0.
814 * Deprecated: 3.4: Use gtk_grid_attach() with #GtkGrid. Note that the attach
815 * arguments differ between those two functions.
818 gtk_table_attach_defaults (GtkTable *table,
825 gtk_table_attach (table, widget,
826 left_attach, right_attach,
827 top_attach, bottom_attach,
828 GTK_EXPAND | GTK_FILL,
829 GTK_EXPAND | GTK_FILL,
834 * gtk_table_set_row_spacing:
835 * @table: a #GtkTable containing the row whose properties you wish to change.
836 * @row: row number whose spacing will be changed.
837 * @spacing: number of pixels that the spacing should take up.
839 * Changes the space between a given table row and the subsequent row.
841 * Deprecated: 3.4: Use gtk_widget_set_margin_top() and
842 * gtk_widget_set_margin_bottom() on the widgets contained in the row if
843 * you need this functionality. #GtkGrid does not support per-row spacing.
846 gtk_table_set_row_spacing (GtkTable *table,
850 GtkTablePrivate *priv;
852 g_return_if_fail (GTK_IS_TABLE (table));
856 g_return_if_fail (row < priv->nrows);
858 if (priv->rows[row].spacing != spacing)
860 priv->rows[row].spacing = spacing;
862 if (gtk_widget_get_visible (GTK_WIDGET (table)))
863 gtk_widget_queue_resize (GTK_WIDGET (table));
868 * gtk_table_get_row_spacing:
869 * @table: a #GtkTable
870 * @row: a row in the table, 0 indicates the first row
872 * Gets the amount of space between row @row, and
873 * row @row + 1. See gtk_table_set_row_spacing().
875 * Return value: the row spacing
877 * Deprecated: 3.4: #GtkGrid does not offer a replacement for this
881 gtk_table_get_row_spacing (GtkTable *table,
884 GtkTablePrivate *priv;
886 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
890 g_return_val_if_fail (row < priv->nrows - 1, 0);
892 return priv->rows[row].spacing;
896 * gtk_table_set_col_spacing:
897 * @table: a #GtkTable.
898 * @column: the column whose spacing should be changed.
899 * @spacing: number of pixels that the spacing should take up.
901 * Alters the amount of space between a given table column and the following
904 * Deprecated: 3.4: Use gtk_widget_set_margin_left() and
905 * gtk_widget_set_margin_right() on the widgets contained in the row if
906 * you need this functionality. #GtkGrid does not support per-row spacing.
909 gtk_table_set_col_spacing (GtkTable *table,
913 GtkTablePrivate *priv;
915 g_return_if_fail (GTK_IS_TABLE (table));
919 g_return_if_fail (column < priv->ncols);
921 if (priv->cols[column].spacing != spacing)
923 priv->cols[column].spacing = spacing;
925 if (gtk_widget_get_visible (GTK_WIDGET (table)))
926 gtk_widget_queue_resize (GTK_WIDGET (table));
931 * gtk_table_get_col_spacing:
932 * @table: a #GtkTable
933 * @column: a column in the table, 0 indicates the first column
935 * Gets the amount of space between column @col, and
936 * column @col + 1. See gtk_table_set_col_spacing().
938 * Return value: the column spacing
940 * Deprecated: 3.4: #GtkGrid does not offer a replacement for this
944 gtk_table_get_col_spacing (GtkTable *table,
947 GtkTablePrivate *priv;
949 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
953 g_return_val_if_fail (column < priv->ncols, 0);
955 return priv->cols[column].spacing;
959 * gtk_table_set_row_spacings:
960 * @table: a #GtkTable.
961 * @spacing: the number of pixels of space to place between every row in the table.
963 * Sets the space between every row in @table equal to @spacing.
965 * Deprecated: 3.4: Use gtk_grid_set_row_spacing() with #GtkGrid.
968 gtk_table_set_row_spacings (GtkTable *table,
971 GtkTablePrivate *priv;
974 g_return_if_fail (GTK_IS_TABLE (table));
978 priv->row_spacing = spacing;
979 for (row = 0; row < priv->nrows; row++)
980 priv->rows[row].spacing = spacing;
982 if (gtk_widget_get_visible (GTK_WIDGET (table)))
983 gtk_widget_queue_resize (GTK_WIDGET (table));
985 g_object_notify (G_OBJECT (table), "row-spacing");
989 * gtk_table_get_default_row_spacing:
990 * @table: a #GtkTable
992 * Gets the default row spacing for the table. This is
993 * the spacing that will be used for newly added rows.
994 * (See gtk_table_set_row_spacings())
996 * Return value: the default row spacing
998 * Deprecated: 3.4: Use gtk_grid_get_row_spacing() with #GtkGrid.
1001 gtk_table_get_default_row_spacing (GtkTable *table)
1003 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
1005 return table->priv->row_spacing;
1009 * gtk_table_set_col_spacings:
1010 * @table: a #GtkTable.
1011 * @spacing: the number of pixels of space to place between every column
1014 * Sets the space between every column in @table equal to @spacing.
1016 * Deprecated: 3.4: Use gtk_grid_set_column_spacing() with #GtkGrid.
1019 gtk_table_set_col_spacings (GtkTable *table,
1022 GtkTablePrivate *priv;
1025 g_return_if_fail (GTK_IS_TABLE (table));
1029 priv->column_spacing = spacing;
1030 for (col = 0; col < priv->ncols; col++)
1031 priv->cols[col].spacing = spacing;
1033 if (gtk_widget_get_visible (GTK_WIDGET (table)))
1034 gtk_widget_queue_resize (GTK_WIDGET (table));
1036 g_object_notify (G_OBJECT (table), "column-spacing");
1040 * gtk_table_get_default_col_spacing:
1041 * @table: a #GtkTable
1043 * Gets the default column spacing for the table. This is
1044 * the spacing that will be used for newly added columns.
1045 * (See gtk_table_set_col_spacings())
1047 * Return value: the default column spacing
1049 * Deprecated: 3.4: Use gtk_grid_get_column_spacing() with #GtkGrid.
1052 gtk_table_get_default_col_spacing (GtkTable *table)
1054 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
1056 return table->priv->column_spacing;
1060 * gtk_table_set_homogeneous:
1061 * @table: The #GtkTable you wish to set the homogeneous properties of.
1062 * @homogeneous: Set to %TRUE to ensure all table cells are the same size. Set
1063 * to %FALSE if this is not your desired behaviour.
1065 * Changes the homogenous property of table cells, ie. whether all cells are
1066 * an equal size or not.
1068 * Deprecated: 3.4: Use gtk_grid_set_row_homogeneous() and
1069 * gtk_grid_set_column_homogeneous() with #GtkGrid.
1072 gtk_table_set_homogeneous (GtkTable *table,
1073 gboolean homogeneous)
1075 GtkTablePrivate *priv;
1077 g_return_if_fail (GTK_IS_TABLE (table));
1081 homogeneous = (homogeneous != 0);
1082 if (homogeneous != priv->homogeneous)
1084 priv->homogeneous = homogeneous;
1086 if (gtk_widget_get_visible (GTK_WIDGET (table)))
1087 gtk_widget_queue_resize (GTK_WIDGET (table));
1089 g_object_notify (G_OBJECT (table), "homogeneous");
1094 * gtk_table_get_homogeneous:
1095 * @table: a #GtkTable
1097 * Returns whether the table cells are all constrained to the same
1098 * width and height. (See gtk_table_set_homogenous ())
1100 * Return value: %TRUE if the cells are all constrained to the same size
1102 * Deprecated: 3.4: Use gtk_grid_get_row_homogeneous() and
1103 * gtk_grid_get_column_homogeneous() with #GtkGrid.
1106 gtk_table_get_homogeneous (GtkTable *table)
1108 g_return_val_if_fail (GTK_IS_TABLE (table), FALSE);
1110 return table->priv->homogeneous;
1114 * gtk_table_get_size:
1115 * @table: a #GtkTable
1116 * @rows: (out) (allow-none): return location for the number of
1118 * @columns: (out) (allow-none): return location for the number
1119 * of columns, or %NULL
1121 * Gets the number of rows and columns in the table.
1125 * Deprecated: 3.4: #GtkGrid does not expose the number of columns and
1129 gtk_table_get_size (GtkTable *table,
1133 GtkTablePrivate *priv;
1135 g_return_if_fail (GTK_IS_TABLE (table));
1140 *rows = priv->nrows;
1143 *columns = priv->ncols;
1147 gtk_table_finalize (GObject *object)
1149 GtkTable *table = GTK_TABLE (object);
1150 GtkTablePrivate *priv = table->priv;
1152 g_free (priv->rows);
1153 g_free (priv->cols);
1155 G_OBJECT_CLASS (gtk_table_parent_class)->finalize (object);
1159 gtk_table_get_preferred_width (GtkWidget *widget,
1163 GtkTable *table = GTK_TABLE (widget);
1164 GtkTablePrivate *priv = table->priv;
1167 gtk_table_size_request_init (table);
1168 gtk_table_size_request_pass1 (table);
1169 gtk_table_size_request_pass2 (table);
1170 gtk_table_size_request_pass3 (table);
1171 gtk_table_size_request_pass2 (table);
1175 for (col = 0; col < priv->ncols; col++)
1176 *minimum += priv->cols[col].requisition;
1177 for (col = 0; col + 1 < priv->ncols; col++)
1178 *minimum += priv->cols[col].spacing;
1180 *natural = *minimum;
1184 gtk_table_get_preferred_height (GtkWidget *widget,
1188 GtkTable *table = GTK_TABLE (widget);
1189 GtkTablePrivate *priv = table->priv;
1192 gtk_table_size_request_init (table);
1193 gtk_table_size_request_pass1 (table);
1194 gtk_table_size_request_pass2 (table);
1195 gtk_table_size_request_pass3 (table);
1196 gtk_table_size_request_pass2 (table);
1199 for (row = 0; row < priv->nrows; row++)
1200 *minimum += priv->rows[row].requisition;
1201 for (row = 0; row + 1 < priv->nrows; row++)
1202 *minimum += priv->rows[row].spacing;
1204 *natural = *minimum;
1208 gtk_table_size_allocate (GtkWidget *widget,
1209 GtkAllocation *allocation)
1211 GtkTable *table = GTK_TABLE (widget);
1213 gtk_widget_set_allocation (widget, allocation);
1215 gtk_table_size_allocate_init (table);
1216 gtk_table_size_allocate_pass1 (table);
1217 gtk_table_size_allocate_pass2 (table);
1221 gtk_table_add (GtkContainer *container,
1224 gtk_table_attach_defaults (GTK_TABLE (container), widget, 0, 1, 0, 1);
1228 gtk_table_remove (GtkContainer *container,
1231 GtkTable *table = GTK_TABLE (container);
1232 GtkTablePrivate *priv = table->priv;
1233 GtkTableChild *child;
1234 GtkWidget *widget_container = GTK_WIDGET (container);
1237 children = priv->children;
1241 child = children->data;
1242 children = children->next;
1244 if (child->widget == widget)
1246 gboolean was_visible = gtk_widget_get_visible (widget);
1248 gtk_widget_unparent (widget);
1250 priv->children = g_list_remove (priv->children, child);
1253 if (was_visible && gtk_widget_get_visible (widget_container))
1254 gtk_widget_queue_resize (widget_container);
1261 gtk_table_forall (GtkContainer *container,
1262 gboolean include_internals,
1263 GtkCallback callback,
1264 gpointer callback_data)
1266 GtkTable *table = GTK_TABLE (container);
1267 GtkTablePrivate *priv = table->priv;
1268 GtkTableChild *child;
1271 children = priv->children;
1275 child = children->data;
1276 children = children->next;
1278 (* callback) (child->widget, callback_data);
1283 gtk_table_size_request_init (GtkTable *table)
1285 GtkTablePrivate *priv = table->priv;
1286 GtkTableChild *child;
1290 for (row = 0; row < priv->nrows; row++)
1292 priv->rows[row].requisition = 0;
1293 priv->rows[row].expand = FALSE;
1295 for (col = 0; col < priv->ncols; col++)
1297 priv->cols[col].requisition = 0;
1298 priv->cols[col].expand = FALSE;
1301 children = priv->children;
1304 child = children->data;
1305 children = children->next;
1307 if (child->left_attach == (child->right_attach - 1) &&
1308 (child->xexpand || gtk_widget_compute_expand (child->widget, GTK_ORIENTATION_HORIZONTAL)))
1309 priv->cols[child->left_attach].expand = TRUE;
1311 if (child->top_attach == (child->bottom_attach - 1) &&
1312 (child->yexpand || gtk_widget_compute_expand (child->widget, GTK_ORIENTATION_VERTICAL)))
1313 priv->rows[child->top_attach].expand = TRUE;
1318 gtk_table_size_request_pass1 (GtkTable *table)
1320 GtkTablePrivate *priv = table->priv;
1321 GtkTableChild *child;
1326 children = priv->children;
1329 child = children->data;
1330 children = children->next;
1332 if (gtk_widget_get_visible (child->widget))
1334 GtkRequisition child_requisition;
1336 gtk_widget_get_preferred_size (child->widget, &child_requisition, NULL);
1338 /* Child spans a single column.
1340 if (child->left_attach == (child->right_attach - 1))
1342 width = child_requisition.width + child->xpadding * 2;
1343 priv->cols[child->left_attach].requisition = MAX (priv->cols[child->left_attach].requisition, width);
1346 /* Child spans a single row.
1348 if (child->top_attach == (child->bottom_attach - 1))
1350 height = child_requisition.height + child->ypadding * 2;
1351 priv->rows[child->top_attach].requisition = MAX (priv->rows[child->top_attach].requisition, height);
1358 gtk_table_size_request_pass2 (GtkTable *table)
1360 GtkTablePrivate *priv = table->priv;
1365 if (priv->homogeneous)
1370 for (col = 0; col < priv->ncols; col++)
1371 max_width = MAX (max_width, priv->cols[col].requisition);
1372 for (row = 0; row < priv->nrows; row++)
1373 max_height = MAX (max_height, priv->rows[row].requisition);
1375 for (col = 0; col < priv->ncols; col++)
1376 priv->cols[col].requisition = max_width;
1377 for (row = 0; row < priv->nrows; row++)
1378 priv->rows[row].requisition = max_height;
1383 gtk_table_size_request_pass3 (GtkTable *table)
1385 GtkTablePrivate *priv = table->priv;
1386 GtkTableChild *child;
1392 children = priv->children;
1395 child = children->data;
1396 children = children->next;
1398 if (gtk_widget_get_visible (child->widget))
1400 /* Child spans multiple columns.
1402 if (child->left_attach != (child->right_attach - 1))
1404 GtkRequisition child_requisition;
1406 gtk_widget_get_preferred_size (child->widget,
1407 &child_requisition, NULL);
1409 /* Check and see if there is already enough space
1413 for (col = child->left_attach; col < child->right_attach; col++)
1415 width += priv->cols[col].requisition;
1416 if ((col + 1) < child->right_attach)
1417 width += priv->cols[col].spacing;
1420 /* If we need to request more space for this child to fill
1421 * its requisition, then divide up the needed space amongst the
1422 * columns it spans, favoring expandable columns if any.
1424 if (width < child_requisition.width + child->xpadding * 2)
1427 gboolean force_expand = FALSE;
1429 width = child_requisition.width + child->xpadding * 2 - width;
1431 for (col = child->left_attach; col < child->right_attach; col++)
1432 if (priv->cols[col].expand)
1437 n_expand = (child->right_attach - child->left_attach);
1438 force_expand = TRUE;
1441 for (col = child->left_attach; col < child->right_attach; col++)
1442 if (force_expand || priv->cols[col].expand)
1444 extra = width / n_expand;
1445 priv->cols[col].requisition += extra;
1452 /* Child spans multiple rows.
1454 if (child->top_attach != (child->bottom_attach - 1))
1456 GtkRequisition child_requisition;
1458 gtk_widget_get_preferred_size (child->widget,
1459 &child_requisition, NULL);
1461 /* Check and see if there is already enough space
1465 for (row = child->top_attach; row < child->bottom_attach; row++)
1467 height += priv->rows[row].requisition;
1468 if ((row + 1) < child->bottom_attach)
1469 height += priv->rows[row].spacing;
1472 /* If we need to request more space for this child to fill
1473 * its requisition, then divide up the needed space amongst the
1474 * rows it spans, favoring expandable rows if any.
1476 if (height < child_requisition.height + child->ypadding * 2)
1479 gboolean force_expand = FALSE;
1481 height = child_requisition.height + child->ypadding * 2 - height;
1483 for (row = child->top_attach; row < child->bottom_attach; row++)
1485 if (priv->rows[row].expand)
1491 n_expand = (child->bottom_attach - child->top_attach);
1492 force_expand = TRUE;
1495 for (row = child->top_attach; row < child->bottom_attach; row++)
1496 if (force_expand || priv->rows[row].expand)
1498 extra = height / n_expand;
1499 priv->rows[row].requisition += extra;
1510 gtk_table_size_allocate_init (GtkTable *table)
1512 GtkTablePrivate *priv = table->priv;
1513 GtkTableChild *child;
1519 /* Initialize the rows and cols.
1520 * By default, rows and cols do not expand and do shrink.
1521 * Those values are modified by the children that occupy
1522 * the rows and cols.
1524 for (col = 0; col < priv->ncols; col++)
1526 priv->cols[col].allocation = priv->cols[col].requisition;
1527 priv->cols[col].need_expand = FALSE;
1528 priv->cols[col].need_shrink = TRUE;
1529 priv->cols[col].expand = FALSE;
1530 priv->cols[col].shrink = TRUE;
1531 priv->cols[col].empty = TRUE;
1533 for (row = 0; row < priv->nrows; row++)
1535 priv->rows[row].allocation = priv->rows[row].requisition;
1536 priv->rows[row].need_expand = FALSE;
1537 priv->rows[row].need_shrink = TRUE;
1538 priv->rows[row].expand = FALSE;
1539 priv->rows[row].shrink = TRUE;
1540 priv->rows[row].empty = TRUE;
1543 /* Loop over all the children and adjust the row and col values
1544 * based on whether the children want to be allowed to expand
1545 * or shrink. This loop handles children that occupy a single
1548 children = priv->children;
1551 child = children->data;
1552 children = children->next;
1554 if (gtk_widget_get_visible (child->widget))
1556 if (child->left_attach == (child->right_attach - 1))
1558 if (child->xexpand || gtk_widget_compute_expand (child->widget, GTK_ORIENTATION_HORIZONTAL))
1559 priv->cols[child->left_attach].expand = TRUE;
1561 if (!child->xshrink)
1562 priv->cols[child->left_attach].shrink = FALSE;
1564 priv->cols[child->left_attach].empty = FALSE;
1567 if (child->top_attach == (child->bottom_attach - 1))
1569 if (child->yexpand || gtk_widget_compute_expand (child->widget, GTK_ORIENTATION_VERTICAL))
1570 priv->rows[child->top_attach].expand = TRUE;
1572 if (!child->yshrink)
1573 priv->rows[child->top_attach].shrink = FALSE;
1575 priv->rows[child->top_attach].empty = FALSE;
1580 /* Loop over all the children again and this time handle children
1581 * which span multiple rows or columns.
1583 children = priv->children;
1586 child = children->data;
1587 children = children->next;
1589 if (gtk_widget_get_visible (child->widget))
1591 if (child->left_attach != (child->right_attach - 1))
1593 for (col = child->left_attach; col < child->right_attach; col++)
1594 priv->cols[col].empty = FALSE;
1599 for (col = child->left_attach; col < child->right_attach; col++)
1600 if (priv->cols[col].expand)
1607 for (col = child->left_attach; col < child->right_attach; col++)
1608 priv->cols[col].need_expand = TRUE;
1611 if (!child->xshrink)
1614 for (col = child->left_attach; col < child->right_attach; col++)
1615 if (!priv->cols[col].shrink)
1622 for (col = child->left_attach; col < child->right_attach; col++)
1623 priv->cols[col].need_shrink = FALSE;
1627 if (child->top_attach != (child->bottom_attach - 1))
1629 for (row = child->top_attach; row < child->bottom_attach; row++)
1630 priv->rows[row].empty = FALSE;
1635 for (row = child->top_attach; row < child->bottom_attach; row++)
1636 if (priv->rows[row].expand)
1643 for (row = child->top_attach; row < child->bottom_attach; row++)
1644 priv->rows[row].need_expand = TRUE;
1647 if (!child->yshrink)
1650 for (row = child->top_attach; row < child->bottom_attach; row++)
1651 if (!priv->rows[row].shrink)
1658 for (row = child->top_attach; row < child->bottom_attach; row++)
1659 priv->rows[row].need_shrink = FALSE;
1665 /* Loop over the columns and set the expand and shrink values
1666 * if the column can be expanded or shrunk.
1668 for (col = 0; col < priv->ncols; col++)
1670 if (priv->cols[col].empty)
1672 priv->cols[col].expand = FALSE;
1673 priv->cols[col].shrink = FALSE;
1677 if (priv->cols[col].need_expand)
1678 priv->cols[col].expand = TRUE;
1679 if (!priv->cols[col].need_shrink)
1680 priv->cols[col].shrink = FALSE;
1684 /* Loop over the rows and set the expand and shrink values
1685 * if the row can be expanded or shrunk.
1687 for (row = 0; row < priv->nrows; row++)
1689 if (priv->rows[row].empty)
1691 priv->rows[row].expand = FALSE;
1692 priv->rows[row].shrink = FALSE;
1696 if (priv->rows[row].need_expand)
1697 priv->rows[row].expand = TRUE;
1698 if (!priv->rows[row].need_shrink)
1699 priv->rows[row].shrink = FALSE;
1705 gtk_table_size_allocate_pass1 (GtkTable *table)
1707 GtkTablePrivate *priv = table->priv;
1708 GtkAllocation allocation;
1717 /* If we were allocated more space than we requested
1718 * then we have to expand any expandable rows and columns
1719 * to fill in the extra space.
1721 gtk_widget_get_allocation (GTK_WIDGET (table), &allocation);
1722 real_width = allocation.width;
1723 real_height = allocation.height;
1725 if (priv->homogeneous)
1727 if (!priv->children)
1732 for (col = 0; col < priv->ncols; col++)
1733 if (priv->cols[col].expand)
1742 for (col = 0; col + 1 < priv->ncols; col++)
1743 width -= priv->cols[col].spacing;
1745 for (col = 0; col < priv->ncols; col++)
1747 extra = width / (priv->ncols - col);
1748 priv->cols[col].allocation = MAX (1, extra);
1759 for (col = 0; col < priv->ncols; col++)
1761 width += priv->cols[col].requisition;
1762 if (priv->cols[col].expand)
1764 if (priv->cols[col].shrink)
1767 for (col = 0; col + 1 < priv->ncols; col++)
1768 width += priv->cols[col].spacing;
1770 /* Check to see if we were allocated more width than we requested.
1772 if ((width < real_width) && (nexpand >= 1))
1774 width = real_width - width;
1776 for (col = 0; col < priv->ncols; col++)
1777 if (priv->cols[col].expand)
1779 extra = width / nexpand;
1780 priv->cols[col].allocation += extra;
1787 /* Check to see if we were allocated less width than we requested,
1788 * then shrink until we fit the size give.
1790 if (width > real_width)
1792 gint total_nshrink = nshrink;
1794 extra = width - real_width;
1795 while (total_nshrink > 0 && extra > 0)
1797 nshrink = total_nshrink;
1798 for (col = 0; col < priv->ncols; col++)
1799 if (priv->cols[col].shrink)
1801 gint allocation = priv->cols[col].allocation;
1803 priv->cols[col].allocation = MAX (1, (gint) priv->cols[col].allocation - extra / nshrink);
1804 extra -= allocation - priv->cols[col].allocation;
1806 if (priv->cols[col].allocation < 2)
1809 priv->cols[col].shrink = FALSE;
1816 if (priv->homogeneous)
1818 if (!priv->children)
1823 for (row = 0; row < priv->nrows; row++)
1824 if (priv->rows[row].expand)
1832 height = real_height;
1834 for (row = 0; row + 1 < priv->nrows; row++)
1835 height -= priv->rows[row].spacing;
1837 for (row = 0; row < priv->nrows; row++)
1839 extra = height / (priv->nrows - row);
1840 priv->rows[row].allocation = MAX (1, extra);
1851 for (row = 0; row < priv->nrows; row++)
1853 height += priv->rows[row].requisition;
1854 if (priv->rows[row].expand)
1856 if (priv->rows[row].shrink)
1859 for (row = 0; row + 1 < priv->nrows; row++)
1860 height += priv->rows[row].spacing;
1862 /* Check to see if we were allocated more height than we requested.
1864 if ((height < real_height) && (nexpand >= 1))
1866 height = real_height - height;
1868 for (row = 0; row < priv->nrows; row++)
1869 if (priv->rows[row].expand)
1871 extra = height / nexpand;
1872 priv->rows[row].allocation += extra;
1879 /* Check to see if we were allocated less height than we requested.
1880 * then shrink until we fit the size give.
1882 if (height > real_height)
1884 gint total_nshrink = nshrink;
1886 extra = height - real_height;
1887 while (total_nshrink > 0 && extra > 0)
1889 nshrink = total_nshrink;
1890 for (row = 0; row < priv->nrows; row++)
1891 if (priv->rows[row].shrink)
1893 gint allocation = priv->rows[row].allocation;
1895 priv->rows[row].allocation = MAX (1, (gint) priv->rows[row].allocation - extra / nshrink);
1896 extra -= allocation - priv->rows[row].allocation;
1898 if (priv->rows[row].allocation < 2)
1901 priv->rows[row].shrink = FALSE;
1910 gtk_table_size_allocate_pass2 (GtkTable *table)
1912 GtkTablePrivate *priv = table->priv;
1913 GtkTableChild *child;
1919 GtkAllocation allocation;
1920 GtkAllocation table_allocation, widget_allocation;
1921 GtkWidget *widget = GTK_WIDGET (table);
1923 children = priv->children;
1926 child = children->data;
1927 children = children->next;
1929 if (gtk_widget_get_visible (child->widget))
1931 GtkRequisition child_requisition;
1933 gtk_widget_get_preferred_size (child->widget,
1934 &child_requisition, NULL);
1936 gtk_widget_get_allocation (GTK_WIDGET (table), &table_allocation);
1937 x = table_allocation.x;
1938 y = table_allocation.y;
1942 for (col = 0; col < child->left_attach; col++)
1944 x += priv->cols[col].allocation;
1945 x += priv->cols[col].spacing;
1948 for (col = child->left_attach; col < child->right_attach; col++)
1950 max_width += priv->cols[col].allocation;
1951 if ((col + 1) < child->right_attach)
1952 max_width += priv->cols[col].spacing;
1955 for (row = 0; row < child->top_attach; row++)
1957 y += priv->rows[row].allocation;
1958 y += priv->rows[row].spacing;
1961 for (row = child->top_attach; row < child->bottom_attach; row++)
1963 max_height += priv->rows[row].allocation;
1964 if ((row + 1) < child->bottom_attach)
1965 max_height += priv->rows[row].spacing;
1970 allocation.width = MAX (1, max_width - (gint)child->xpadding * 2);
1971 allocation.x = x + (max_width - allocation.width) / 2;
1975 allocation.width = child_requisition.width;
1976 allocation.x = x + (max_width - allocation.width) / 2;
1981 allocation.height = MAX (1, max_height - (gint)child->ypadding * 2);
1982 allocation.y = y + (max_height - allocation.height) / 2;
1986 allocation.height = child_requisition.height;
1987 allocation.y = y + (max_height - allocation.height) / 2;
1990 gtk_widget_get_allocation (widget, &widget_allocation);
1991 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1992 allocation.x = widget_allocation.x + widget_allocation.width
1993 - (allocation.x - widget_allocation.x) - allocation.width;
1995 gtk_widget_size_allocate (child->widget, &allocation);