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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 #include "gtkprivate.h"
46 CHILD_PROP_LEFT_ATTACH,
47 CHILD_PROP_RIGHT_ATTACH,
48 CHILD_PROP_TOP_ATTACH,
49 CHILD_PROP_BOTTOM_ATTACH,
57 static void gtk_table_finalize (GObject *object);
58 static void gtk_table_size_request (GtkWidget *widget,
59 GtkRequisition *requisition);
60 static void gtk_table_size_allocate (GtkWidget *widget,
61 GtkAllocation *allocation);
62 static void gtk_table_add (GtkContainer *container,
64 static void gtk_table_remove (GtkContainer *container,
66 static void gtk_table_forall (GtkContainer *container,
67 gboolean include_internals,
69 gpointer callback_data);
70 static void gtk_table_get_property (GObject *object,
74 static void gtk_table_set_property (GObject *object,
78 static void gtk_table_set_child_property (GtkContainer *container,
83 static void gtk_table_get_child_property (GtkContainer *container,
88 static GType gtk_table_child_type (GtkContainer *container);
91 static void gtk_table_size_request_init (GtkTable *table);
92 static void gtk_table_size_request_pass1 (GtkTable *table);
93 static void gtk_table_size_request_pass2 (GtkTable *table);
94 static void gtk_table_size_request_pass3 (GtkTable *table);
96 static void gtk_table_size_allocate_init (GtkTable *table);
97 static void gtk_table_size_allocate_pass1 (GtkTable *table);
98 static void gtk_table_size_allocate_pass2 (GtkTable *table);
101 G_DEFINE_TYPE (GtkTable, gtk_table, GTK_TYPE_CONTAINER)
104 gtk_table_class_init (GtkTableClass *class)
106 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
107 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
108 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
110 gobject_class->finalize = gtk_table_finalize;
112 gobject_class->get_property = gtk_table_get_property;
113 gobject_class->set_property = gtk_table_set_property;
115 widget_class->size_request = gtk_table_size_request;
116 widget_class->size_allocate = gtk_table_size_allocate;
118 container_class->add = gtk_table_add;
119 container_class->remove = gtk_table_remove;
120 container_class->forall = gtk_table_forall;
121 container_class->child_type = gtk_table_child_type;
122 container_class->set_child_property = gtk_table_set_child_property;
123 container_class->get_child_property = gtk_table_get_child_property;
126 g_object_class_install_property (gobject_class,
128 g_param_spec_uint ("n-rows",
130 P_("The number of rows in the table"),
134 GTK_PARAM_READWRITE));
135 g_object_class_install_property (gobject_class,
137 g_param_spec_uint ("n-columns",
139 P_("The number of columns in the table"),
143 GTK_PARAM_READWRITE));
144 g_object_class_install_property (gobject_class,
146 g_param_spec_uint ("row-spacing",
148 P_("The amount of space between two consecutive rows"),
152 GTK_PARAM_READWRITE));
153 g_object_class_install_property (gobject_class,
155 g_param_spec_uint ("column-spacing",
156 P_("Column spacing"),
157 P_("The amount of space between two consecutive columns"),
161 GTK_PARAM_READWRITE));
162 g_object_class_install_property (gobject_class,
164 g_param_spec_boolean ("homogeneous",
166 P_("If TRUE, the table cells are all the same width/height"),
168 GTK_PARAM_READWRITE));
170 gtk_container_class_install_child_property (container_class,
171 CHILD_PROP_LEFT_ATTACH,
172 g_param_spec_uint ("left-attach",
173 P_("Left attachment"),
174 P_("The column number to attach the left side of the child to"),
176 GTK_PARAM_READWRITE));
177 gtk_container_class_install_child_property (container_class,
178 CHILD_PROP_RIGHT_ATTACH,
179 g_param_spec_uint ("right-attach",
180 P_("Right attachment"),
181 P_("The column number to attach the right side of a child widget to"),
183 GTK_PARAM_READWRITE));
184 gtk_container_class_install_child_property (container_class,
185 CHILD_PROP_TOP_ATTACH,
186 g_param_spec_uint ("top-attach",
187 P_("Top attachment"),
188 P_("The row number to attach the top of a child widget to"),
190 GTK_PARAM_READWRITE));
191 gtk_container_class_install_child_property (container_class,
192 CHILD_PROP_BOTTOM_ATTACH,
193 g_param_spec_uint ("bottom-attach",
194 P_("Bottom attachment"),
195 P_("The row number to attach the bottom of the child to"),
197 GTK_PARAM_READWRITE));
198 gtk_container_class_install_child_property (container_class,
199 CHILD_PROP_X_OPTIONS,
200 g_param_spec_flags ("x-options",
201 P_("Horizontal options"),
202 P_("Options specifying the horizontal behaviour of the child"),
203 GTK_TYPE_ATTACH_OPTIONS, GTK_EXPAND | GTK_FILL,
204 GTK_PARAM_READWRITE));
205 gtk_container_class_install_child_property (container_class,
206 CHILD_PROP_Y_OPTIONS,
207 g_param_spec_flags ("y-options",
208 P_("Vertical options"),
209 P_("Options specifying the vertical behaviour of the child"),
210 GTK_TYPE_ATTACH_OPTIONS, GTK_EXPAND | GTK_FILL,
211 GTK_PARAM_READWRITE));
212 gtk_container_class_install_child_property (container_class,
213 CHILD_PROP_X_PADDING,
214 g_param_spec_uint ("x-padding",
215 P_("Horizontal padding"),
216 P_("Extra space to put between the child and its left and right neighbors, in pixels"),
218 GTK_PARAM_READWRITE));
219 gtk_container_class_install_child_property (container_class,
220 CHILD_PROP_Y_PADDING,
221 g_param_spec_uint ("y-padding",
222 P_("Vertical padding"),
223 P_("Extra space to put between the child and its upper and lower neighbors, in pixels"),
225 GTK_PARAM_READWRITE));
229 gtk_table_child_type (GtkContainer *container)
231 return GTK_TYPE_WIDGET;
235 gtk_table_get_property (GObject *object,
242 table = GTK_TABLE (object);
247 g_value_set_uint (value, table->nrows);
250 g_value_set_uint (value, table->ncols);
252 case PROP_ROW_SPACING:
253 g_value_set_uint (value, table->row_spacing);
255 case PROP_COLUMN_SPACING:
256 g_value_set_uint (value, table->column_spacing);
258 case PROP_HOMOGENEOUS:
259 g_value_set_boolean (value, table->homogeneous);
262 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
268 gtk_table_set_property (GObject *object,
275 table = GTK_TABLE (object);
280 gtk_table_resize (table, g_value_get_uint (value), table->ncols);
283 gtk_table_resize (table, table->nrows, g_value_get_uint (value));
285 case PROP_ROW_SPACING:
286 gtk_table_set_row_spacings (table, g_value_get_uint (value));
288 case PROP_COLUMN_SPACING:
289 gtk_table_set_col_spacings (table, g_value_get_uint (value));
291 case PROP_HOMOGENEOUS:
292 gtk_table_set_homogeneous (table, g_value_get_boolean (value));
295 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
301 gtk_table_set_child_property (GtkContainer *container,
307 GtkTable *table = GTK_TABLE (container);
308 GtkTableChild *table_child;
312 for (list = table->children; list; list = list->next)
314 table_child = list->data;
316 if (table_child->widget == child)
321 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
327 case CHILD_PROP_LEFT_ATTACH:
328 table_child->left_attach = g_value_get_uint (value);
329 if (table_child->right_attach <= table_child->left_attach)
330 table_child->right_attach = table_child->left_attach + 1;
331 if (table_child->right_attach >= table->ncols)
332 gtk_table_resize (table, table->nrows, table_child->right_attach);
334 case CHILD_PROP_RIGHT_ATTACH:
335 table_child->right_attach = g_value_get_uint (value);
336 if (table_child->right_attach <= table_child->left_attach)
337 table_child->left_attach = table_child->right_attach - 1;
338 if (table_child->right_attach >= table->ncols)
339 gtk_table_resize (table, table->nrows, table_child->right_attach);
341 case CHILD_PROP_TOP_ATTACH:
342 table_child->top_attach = g_value_get_uint (value);
343 if (table_child->bottom_attach <= table_child->top_attach)
344 table_child->bottom_attach = table_child->top_attach + 1;
345 if (table_child->bottom_attach >= table->nrows)
346 gtk_table_resize (table, table_child->bottom_attach, table->ncols);
348 case CHILD_PROP_BOTTOM_ATTACH:
349 table_child->bottom_attach = g_value_get_uint (value);
350 if (table_child->bottom_attach <= table_child->top_attach)
351 table_child->top_attach = table_child->bottom_attach - 1;
352 if (table_child->bottom_attach >= table->nrows)
353 gtk_table_resize (table, table_child->bottom_attach, table->ncols);
355 case CHILD_PROP_X_OPTIONS:
356 table_child->xexpand = (g_value_get_flags (value) & GTK_EXPAND) != 0;
357 table_child->xshrink = (g_value_get_flags (value) & GTK_SHRINK) != 0;
358 table_child->xfill = (g_value_get_flags (value) & GTK_FILL) != 0;
360 case CHILD_PROP_Y_OPTIONS:
361 table_child->yexpand = (g_value_get_flags (value) & GTK_EXPAND) != 0;
362 table_child->yshrink = (g_value_get_flags (value) & GTK_SHRINK) != 0;
363 table_child->yfill = (g_value_get_flags (value) & GTK_FILL) != 0;
365 case CHILD_PROP_X_PADDING:
366 table_child->xpadding = g_value_get_uint (value);
368 case CHILD_PROP_Y_PADDING:
369 table_child->ypadding = g_value_get_uint (value);
372 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
375 if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (table))
376 gtk_widget_queue_resize (child);
380 gtk_table_get_child_property (GtkContainer *container,
386 GtkTable *table = GTK_TABLE (container);
387 GtkTableChild *table_child;
391 for (list = table->children; list; list = list->next)
393 table_child = list->data;
395 if (table_child->widget == child)
400 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
406 case CHILD_PROP_LEFT_ATTACH:
407 g_value_set_uint (value, table_child->left_attach);
409 case CHILD_PROP_RIGHT_ATTACH:
410 g_value_set_uint (value, table_child->right_attach);
412 case CHILD_PROP_TOP_ATTACH:
413 g_value_set_uint (value, table_child->top_attach);
415 case CHILD_PROP_BOTTOM_ATTACH:
416 g_value_set_uint (value, table_child->bottom_attach);
418 case CHILD_PROP_X_OPTIONS:
419 g_value_set_flags (value, (table_child->xexpand * GTK_EXPAND |
420 table_child->xshrink * GTK_SHRINK |
421 table_child->xfill * GTK_FILL));
423 case CHILD_PROP_Y_OPTIONS:
424 g_value_set_flags (value, (table_child->yexpand * GTK_EXPAND |
425 table_child->yshrink * GTK_SHRINK |
426 table_child->yfill * GTK_FILL));
428 case CHILD_PROP_X_PADDING:
429 g_value_set_uint (value, table_child->xpadding);
431 case CHILD_PROP_Y_PADDING:
432 g_value_set_uint (value, table_child->ypadding);
435 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
441 gtk_table_init (GtkTable *table)
443 GTK_WIDGET_SET_FLAGS (table, GTK_NO_WINDOW);
444 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (table), FALSE);
446 table->children = NULL;
451 table->column_spacing = 0;
452 table->row_spacing = 0;
453 table->homogeneous = FALSE;
455 gtk_table_resize (table, 1, 1);
459 gtk_table_new (guint rows,
461 gboolean homogeneous)
470 table = g_object_new (GTK_TYPE_TABLE, NULL);
472 table->homogeneous = (homogeneous ? TRUE : FALSE);
474 gtk_table_resize (table, rows, columns);
476 return GTK_WIDGET (table);
480 gtk_table_resize (GtkTable *table,
484 g_return_if_fail (GTK_IS_TABLE (table));
485 g_return_if_fail (n_rows > 0 && n_rows <= 65535);
486 g_return_if_fail (n_cols > 0 && n_cols <= 65535);
488 n_rows = MAX (n_rows, 1);
489 n_cols = MAX (n_cols, 1);
491 if (n_rows != table->nrows ||
492 n_cols != table->ncols)
496 for (list = table->children; list; list = list->next)
498 GtkTableChild *child;
502 n_rows = MAX (n_rows, child->bottom_attach);
503 n_cols = MAX (n_cols, child->right_attach);
506 if (n_rows != table->nrows)
511 table->nrows = n_rows;
512 table->rows = g_realloc (table->rows, table->nrows * sizeof (GtkTableRowCol));
514 for (; i < table->nrows; i++)
516 table->rows[i].requisition = 0;
517 table->rows[i].allocation = 0;
518 table->rows[i].spacing = table->row_spacing;
519 table->rows[i].need_expand = 0;
520 table->rows[i].need_shrink = 0;
521 table->rows[i].expand = 0;
522 table->rows[i].shrink = 0;
525 g_object_notify (G_OBJECT (table), "n-rows");
528 if (n_cols != table->ncols)
533 table->ncols = n_cols;
534 table->cols = g_realloc (table->cols, table->ncols * sizeof (GtkTableRowCol));
536 for (; i < table->ncols; i++)
538 table->cols[i].requisition = 0;
539 table->cols[i].allocation = 0;
540 table->cols[i].spacing = table->column_spacing;
541 table->cols[i].need_expand = 0;
542 table->cols[i].need_shrink = 0;
543 table->cols[i].expand = 0;
544 table->cols[i].shrink = 0;
547 g_object_notify (G_OBJECT (table), "n-columns");
553 gtk_table_attach (GtkTable *table,
559 GtkAttachOptions xoptions,
560 GtkAttachOptions yoptions,
564 GtkTableChild *table_child;
566 g_return_if_fail (GTK_IS_TABLE (table));
567 g_return_if_fail (GTK_IS_WIDGET (child));
568 g_return_if_fail (child->parent == NULL);
570 /* g_return_if_fail (left_attach >= 0); */
571 g_return_if_fail (left_attach < right_attach);
572 /* g_return_if_fail (top_attach >= 0); */
573 g_return_if_fail (top_attach < bottom_attach);
575 if (right_attach >= table->ncols)
576 gtk_table_resize (table, table->nrows, right_attach);
578 if (bottom_attach >= table->nrows)
579 gtk_table_resize (table, bottom_attach, table->ncols);
581 table_child = g_new (GtkTableChild, 1);
582 table_child->widget = child;
583 table_child->left_attach = left_attach;
584 table_child->right_attach = right_attach;
585 table_child->top_attach = top_attach;
586 table_child->bottom_attach = bottom_attach;
587 table_child->xexpand = (xoptions & GTK_EXPAND) != 0;
588 table_child->xshrink = (xoptions & GTK_SHRINK) != 0;
589 table_child->xfill = (xoptions & GTK_FILL) != 0;
590 table_child->xpadding = xpadding;
591 table_child->yexpand = (yoptions & GTK_EXPAND) != 0;
592 table_child->yshrink = (yoptions & GTK_SHRINK) != 0;
593 table_child->yfill = (yoptions & GTK_FILL) != 0;
594 table_child->ypadding = ypadding;
596 table->children = g_list_prepend (table->children, table_child);
598 gtk_widget_set_parent (child, GTK_WIDGET (table));
602 gtk_table_attach_defaults (GtkTable *table,
609 gtk_table_attach (table, widget,
610 left_attach, right_attach,
611 top_attach, bottom_attach,
612 GTK_EXPAND | GTK_FILL,
613 GTK_EXPAND | GTK_FILL,
618 gtk_table_set_row_spacing (GtkTable *table,
622 g_return_if_fail (GTK_IS_TABLE (table));
623 g_return_if_fail (row < table->nrows);
625 if (table->rows[row].spacing != spacing)
627 table->rows[row].spacing = spacing;
629 if (GTK_WIDGET_VISIBLE (table))
630 gtk_widget_queue_resize (GTK_WIDGET (table));
635 * gtk_table_get_row_spacing:
636 * @table: a #GtkTable
637 * @row: a row in the table, 0 indicates the first row
639 * Gets the amount of space between row @row, and
640 * row @row + 1. See gtk_table_set_row_spacing().
642 * Return value: the row spacing
645 gtk_table_get_row_spacing (GtkTable *table,
648 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
649 g_return_val_if_fail (row < table->nrows - 1, 0);
651 return table->rows[row].spacing;
655 gtk_table_set_col_spacing (GtkTable *table,
659 g_return_if_fail (GTK_IS_TABLE (table));
660 g_return_if_fail (column < table->ncols);
662 if (table->cols[column].spacing != spacing)
664 table->cols[column].spacing = spacing;
666 if (GTK_WIDGET_VISIBLE (table))
667 gtk_widget_queue_resize (GTK_WIDGET (table));
672 * gtk_table_get_col_spacing:
673 * @table: a #GtkTable
674 * @column: a column in the table, 0 indicates the first column
676 * Gets the amount of space between column @col, and
677 * column @col + 1. See gtk_table_set_col_spacing().
679 * Return value: the column spacing
682 gtk_table_get_col_spacing (GtkTable *table,
685 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
686 g_return_val_if_fail (column < table->ncols, 0);
688 return table->cols[column].spacing;
692 gtk_table_set_row_spacings (GtkTable *table,
697 g_return_if_fail (GTK_IS_TABLE (table));
699 table->row_spacing = spacing;
700 for (row = 0; row < table->nrows; row++)
701 table->rows[row].spacing = spacing;
703 if (GTK_WIDGET_VISIBLE (table))
704 gtk_widget_queue_resize (GTK_WIDGET (table));
706 g_object_notify (G_OBJECT (table), "row-spacing");
710 * gtk_table_get_default_row_spacing:
711 * @table: a #GtkTable
713 * Gets the default row spacing for the table. This is
714 * the spacing that will be used for newly added rows.
715 * (See gtk_table_set_row_spacings())
717 * Return value: the default row spacing
720 gtk_table_get_default_row_spacing (GtkTable *table)
722 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
724 return table->row_spacing;
728 gtk_table_set_col_spacings (GtkTable *table,
733 g_return_if_fail (GTK_IS_TABLE (table));
735 table->column_spacing = spacing;
736 for (col = 0; col < table->ncols; col++)
737 table->cols[col].spacing = spacing;
739 if (GTK_WIDGET_VISIBLE (table))
740 gtk_widget_queue_resize (GTK_WIDGET (table));
742 g_object_notify (G_OBJECT (table), "column-spacing");
746 * gtk_table_get_default_col_spacing:
747 * @table: a #GtkTable
749 * Gets the default column spacing for the table. This is
750 * the spacing that will be used for newly added columns.
751 * (See gtk_table_set_col_spacings())
753 * Return value: the default column spacing
756 gtk_table_get_default_col_spacing (GtkTable *table)
758 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
760 return table->column_spacing;
764 gtk_table_set_homogeneous (GtkTable *table,
765 gboolean homogeneous)
767 g_return_if_fail (GTK_IS_TABLE (table));
769 homogeneous = (homogeneous != 0);
770 if (homogeneous != table->homogeneous)
772 table->homogeneous = homogeneous;
774 if (GTK_WIDGET_VISIBLE (table))
775 gtk_widget_queue_resize (GTK_WIDGET (table));
777 g_object_notify (G_OBJECT (table), "homogeneous");
782 * gtk_table_get_homogeneous:
783 * @table: a #GtkTable
785 * Returns whether the table cells are all constrained to the same
786 * width and height. (See gtk_table_set_homogenous ())
788 * Return value: %TRUE if the cells are all constrained to the same size
791 gtk_table_get_homogeneous (GtkTable *table)
793 g_return_val_if_fail (GTK_IS_TABLE (table), FALSE);
795 return table->homogeneous;
799 gtk_table_finalize (GObject *object)
801 GtkTable *table = GTK_TABLE (object);
803 g_free (table->rows);
804 g_free (table->cols);
806 G_OBJECT_CLASS (gtk_table_parent_class)->finalize (object);
810 gtk_table_size_request (GtkWidget *widget,
811 GtkRequisition *requisition)
813 GtkTable *table = GTK_TABLE (widget);
816 requisition->width = 0;
817 requisition->height = 0;
819 gtk_table_size_request_init (table);
820 gtk_table_size_request_pass1 (table);
821 gtk_table_size_request_pass2 (table);
822 gtk_table_size_request_pass3 (table);
823 gtk_table_size_request_pass2 (table);
825 for (col = 0; col < table->ncols; col++)
826 requisition->width += table->cols[col].requisition;
827 for (col = 0; col + 1 < table->ncols; col++)
828 requisition->width += table->cols[col].spacing;
830 for (row = 0; row < table->nrows; row++)
831 requisition->height += table->rows[row].requisition;
832 for (row = 0; row + 1 < table->nrows; row++)
833 requisition->height += table->rows[row].spacing;
835 requisition->width += GTK_CONTAINER (table)->border_width * 2;
836 requisition->height += GTK_CONTAINER (table)->border_width * 2;
840 gtk_table_size_allocate (GtkWidget *widget,
841 GtkAllocation *allocation)
843 GtkTable *table = GTK_TABLE (widget);
845 widget->allocation = *allocation;
847 gtk_table_size_allocate_init (table);
848 gtk_table_size_allocate_pass1 (table);
849 gtk_table_size_allocate_pass2 (table);
853 gtk_table_add (GtkContainer *container,
856 gtk_table_attach_defaults (GTK_TABLE (container), widget, 0, 1, 0, 1);
860 gtk_table_remove (GtkContainer *container,
863 GtkTable *table = GTK_TABLE (container);
864 GtkTableChild *child;
867 children = table->children;
871 child = children->data;
872 children = children->next;
874 if (child->widget == widget)
876 gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
878 gtk_widget_unparent (widget);
880 table->children = g_list_remove (table->children, child);
883 if (was_visible && GTK_WIDGET_VISIBLE (container))
884 gtk_widget_queue_resize (GTK_WIDGET (container));
891 gtk_table_forall (GtkContainer *container,
892 gboolean include_internals,
893 GtkCallback callback,
894 gpointer callback_data)
896 GtkTable *table = GTK_TABLE (container);
897 GtkTableChild *child;
900 children = table->children;
904 child = children->data;
905 children = children->next;
907 (* callback) (child->widget, callback_data);
912 gtk_table_size_request_init (GtkTable *table)
914 GtkTableChild *child;
918 for (row = 0; row < table->nrows; row++)
920 table->rows[row].requisition = 0;
921 table->rows[row].expand = FALSE;
923 for (col = 0; col < table->ncols; col++)
925 table->cols[col].requisition = 0;
926 table->cols[col].expand = FALSE;
929 children = table->children;
932 child = children->data;
933 children = children->next;
935 if (GTK_WIDGET_VISIBLE (child->widget))
936 gtk_widget_size_request (child->widget, NULL);
938 if (child->left_attach == (child->right_attach - 1) && child->xexpand)
939 table->cols[child->left_attach].expand = TRUE;
941 if (child->top_attach == (child->bottom_attach - 1) && child->yexpand)
942 table->rows[child->top_attach].expand = TRUE;
947 gtk_table_size_request_pass1 (GtkTable *table)
949 GtkTableChild *child;
954 children = table->children;
957 child = children->data;
958 children = children->next;
960 if (GTK_WIDGET_VISIBLE (child->widget))
962 GtkRequisition child_requisition;
963 gtk_widget_get_child_requisition (child->widget, &child_requisition);
965 /* Child spans a single column.
967 if (child->left_attach == (child->right_attach - 1))
969 width = child_requisition.width + child->xpadding * 2;
970 table->cols[child->left_attach].requisition = MAX (table->cols[child->left_attach].requisition, width);
973 /* Child spans a single row.
975 if (child->top_attach == (child->bottom_attach - 1))
977 height = child_requisition.height + child->ypadding * 2;
978 table->rows[child->top_attach].requisition = MAX (table->rows[child->top_attach].requisition, height);
985 gtk_table_size_request_pass2 (GtkTable *table)
991 if (table->homogeneous)
996 for (col = 0; col < table->ncols; col++)
997 max_width = MAX (max_width, table->cols[col].requisition);
998 for (row = 0; row < table->nrows; row++)
999 max_height = MAX (max_height, table->rows[row].requisition);
1001 for (col = 0; col < table->ncols; col++)
1002 table->cols[col].requisition = max_width;
1003 for (row = 0; row < table->nrows; row++)
1004 table->rows[row].requisition = max_height;
1009 gtk_table_size_request_pass3 (GtkTable *table)
1011 GtkTableChild *child;
1017 children = table->children;
1020 child = children->data;
1021 children = children->next;
1023 if (GTK_WIDGET_VISIBLE (child->widget))
1025 /* Child spans multiple columns.
1027 if (child->left_attach != (child->right_attach - 1))
1029 GtkRequisition child_requisition;
1031 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1033 /* Check and see if there is already enough space
1037 for (col = child->left_attach; col < child->right_attach; col++)
1039 width += table->cols[col].requisition;
1040 if ((col + 1) < child->right_attach)
1041 width += table->cols[col].spacing;
1044 /* If we need to request more space for this child to fill
1045 * its requisition, then divide up the needed space amongst the
1046 * columns it spans, favoring expandable columns if any.
1048 if (width < child_requisition.width + child->xpadding * 2)
1051 gboolean force_expand = FALSE;
1053 width = child_requisition.width + child->xpadding * 2 - width;
1055 for (col = child->left_attach; col < child->right_attach; col++)
1056 if (table->cols[col].expand)
1061 n_expand = (child->right_attach - child->left_attach);
1062 force_expand = TRUE;
1065 for (col = child->left_attach; col < child->right_attach; col++)
1066 if (force_expand || table->cols[col].expand)
1068 extra = width / n_expand;
1069 table->cols[col].requisition += extra;
1076 /* Child spans multiple rows.
1078 if (child->top_attach != (child->bottom_attach - 1))
1080 GtkRequisition child_requisition;
1082 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1084 /* Check and see if there is already enough space
1088 for (row = child->top_attach; row < child->bottom_attach; row++)
1090 height += table->rows[row].requisition;
1091 if ((row + 1) < child->bottom_attach)
1092 height += table->rows[row].spacing;
1095 /* If we need to request more space for this child to fill
1096 * its requisition, then divide up the needed space amongst the
1097 * rows it spans, favoring expandable rows if any.
1099 if (height < child_requisition.height + child->ypadding * 2)
1102 gboolean force_expand = FALSE;
1104 height = child_requisition.height + child->ypadding * 2 - height;
1106 for (row = child->top_attach; row < child->bottom_attach; row++)
1108 if (table->rows[row].expand)
1114 n_expand = (child->bottom_attach - child->top_attach);
1115 force_expand = TRUE;
1118 for (row = child->top_attach; row < child->bottom_attach; row++)
1119 if (force_expand || table->rows[row].expand)
1121 extra = height / n_expand;
1122 table->rows[row].requisition += extra;
1133 gtk_table_size_allocate_init (GtkTable *table)
1135 GtkTableChild *child;
1141 /* Initialize the rows and cols.
1142 * By default, rows and cols do not expand and do shrink.
1143 * Those values are modified by the children that occupy
1144 * the rows and cols.
1146 for (col = 0; col < table->ncols; col++)
1148 table->cols[col].allocation = table->cols[col].requisition;
1149 table->cols[col].need_expand = FALSE;
1150 table->cols[col].need_shrink = TRUE;
1151 table->cols[col].expand = FALSE;
1152 table->cols[col].shrink = TRUE;
1153 table->cols[col].empty = TRUE;
1155 for (row = 0; row < table->nrows; row++)
1157 table->rows[row].allocation = table->rows[row].requisition;
1158 table->rows[row].need_expand = FALSE;
1159 table->rows[row].need_shrink = TRUE;
1160 table->rows[row].expand = FALSE;
1161 table->rows[row].shrink = TRUE;
1162 table->rows[row].empty = TRUE;
1165 /* Loop over all the children and adjust the row and col values
1166 * based on whether the children want to be allowed to expand
1167 * or shrink. This loop handles children that occupy a single
1170 children = table->children;
1173 child = children->data;
1174 children = children->next;
1176 if (GTK_WIDGET_VISIBLE (child->widget))
1178 if (child->left_attach == (child->right_attach - 1))
1181 table->cols[child->left_attach].expand = TRUE;
1183 if (!child->xshrink)
1184 table->cols[child->left_attach].shrink = FALSE;
1186 table->cols[child->left_attach].empty = FALSE;
1189 if (child->top_attach == (child->bottom_attach - 1))
1192 table->rows[child->top_attach].expand = TRUE;
1194 if (!child->yshrink)
1195 table->rows[child->top_attach].shrink = FALSE;
1197 table->rows[child->top_attach].empty = FALSE;
1202 /* Loop over all the children again and this time handle children
1203 * which span multiple rows or columns.
1205 children = table->children;
1208 child = children->data;
1209 children = children->next;
1211 if (GTK_WIDGET_VISIBLE (child->widget))
1213 if (child->left_attach != (child->right_attach - 1))
1215 for (col = child->left_attach; col < child->right_attach; col++)
1216 table->cols[col].empty = FALSE;
1221 for (col = child->left_attach; col < child->right_attach; col++)
1222 if (table->cols[col].expand)
1229 for (col = child->left_attach; col < child->right_attach; col++)
1230 table->cols[col].need_expand = TRUE;
1233 if (!child->xshrink)
1236 for (col = child->left_attach; col < child->right_attach; col++)
1237 if (!table->cols[col].shrink)
1244 for (col = child->left_attach; col < child->right_attach; col++)
1245 table->cols[col].need_shrink = FALSE;
1249 if (child->top_attach != (child->bottom_attach - 1))
1251 for (row = child->top_attach; row < child->bottom_attach; row++)
1252 table->rows[row].empty = FALSE;
1257 for (row = child->top_attach; row < child->bottom_attach; row++)
1258 if (table->rows[row].expand)
1265 for (row = child->top_attach; row < child->bottom_attach; row++)
1266 table->rows[row].need_expand = TRUE;
1269 if (!child->yshrink)
1272 for (row = child->top_attach; row < child->bottom_attach; row++)
1273 if (!table->rows[row].shrink)
1280 for (row = child->top_attach; row < child->bottom_attach; row++)
1281 table->rows[row].need_shrink = FALSE;
1287 /* Loop over the columns and set the expand and shrink values
1288 * if the column can be expanded or shrunk.
1290 for (col = 0; col < table->ncols; col++)
1292 if (table->cols[col].empty)
1294 table->cols[col].expand = FALSE;
1295 table->cols[col].shrink = FALSE;
1299 if (table->cols[col].need_expand)
1300 table->cols[col].expand = TRUE;
1301 if (!table->cols[col].need_shrink)
1302 table->cols[col].shrink = FALSE;
1306 /* Loop over the rows and set the expand and shrink values
1307 * if the row can be expanded or shrunk.
1309 for (row = 0; row < table->nrows; row++)
1311 if (table->rows[row].empty)
1313 table->rows[row].expand = FALSE;
1314 table->rows[row].shrink = FALSE;
1318 if (table->rows[row].need_expand)
1319 table->rows[row].expand = TRUE;
1320 if (!table->rows[row].need_shrink)
1321 table->rows[row].shrink = FALSE;
1327 gtk_table_size_allocate_pass1 (GtkTable *table)
1337 /* If we were allocated more space than we requested
1338 * then we have to expand any expandable rows and columns
1339 * to fill in the extra space.
1342 real_width = GTK_WIDGET (table)->allocation.width - GTK_CONTAINER (table)->border_width * 2;
1343 real_height = GTK_WIDGET (table)->allocation.height - GTK_CONTAINER (table)->border_width * 2;
1345 if (table->homogeneous)
1347 if (!table->children)
1352 for (col = 0; col < table->ncols; col++)
1353 if (table->cols[col].expand)
1362 for (col = 0; col + 1 < table->ncols; col++)
1363 width -= table->cols[col].spacing;
1365 for (col = 0; col < table->ncols; col++)
1367 extra = width / (table->ncols - col);
1368 table->cols[col].allocation = MAX (1, extra);
1379 for (col = 0; col < table->ncols; col++)
1381 width += table->cols[col].requisition;
1382 if (table->cols[col].expand)
1384 if (table->cols[col].shrink)
1387 for (col = 0; col + 1 < table->ncols; col++)
1388 width += table->cols[col].spacing;
1390 /* Check to see if we were allocated more width than we requested.
1392 if ((width < real_width) && (nexpand >= 1))
1394 width = real_width - width;
1396 for (col = 0; col < table->ncols; col++)
1397 if (table->cols[col].expand)
1399 extra = width / nexpand;
1400 table->cols[col].allocation += extra;
1407 /* Check to see if we were allocated less width than we requested,
1408 * then shrink until we fit the size give.
1410 if (width > real_width)
1412 gint total_nshrink = nshrink;
1414 extra = width - real_width;
1415 while (total_nshrink > 0 && extra > 0)
1417 nshrink = total_nshrink;
1418 for (col = 0; col < table->ncols; col++)
1419 if (table->cols[col].shrink)
1421 gint allocation = table->cols[col].allocation;
1423 table->cols[col].allocation = MAX (1, (gint) table->cols[col].allocation - extra / nshrink);
1424 extra -= allocation - table->cols[col].allocation;
1426 if (table->cols[col].allocation < 2)
1429 table->cols[col].shrink = FALSE;
1436 if (table->homogeneous)
1438 if (!table->children)
1443 for (row = 0; row < table->nrows; row++)
1444 if (table->rows[row].expand)
1452 height = real_height;
1454 for (row = 0; row + 1 < table->nrows; row++)
1455 height -= table->rows[row].spacing;
1458 for (row = 0; row < table->nrows; row++)
1460 extra = height / (table->nrows - row);
1461 table->rows[row].allocation = MAX (1, extra);
1472 for (row = 0; row < table->nrows; row++)
1474 height += table->rows[row].requisition;
1475 if (table->rows[row].expand)
1477 if (table->rows[row].shrink)
1480 for (row = 0; row + 1 < table->nrows; row++)
1481 height += table->rows[row].spacing;
1483 /* Check to see if we were allocated more height than we requested.
1485 if ((height < real_height) && (nexpand >= 1))
1487 height = real_height - height;
1489 for (row = 0; row < table->nrows; row++)
1490 if (table->rows[row].expand)
1492 extra = height / nexpand;
1493 table->rows[row].allocation += extra;
1500 /* Check to see if we were allocated less height than we requested.
1501 * then shrink until we fit the size give.
1503 if (height > real_height)
1505 gint total_nshrink = nshrink;
1507 extra = height - real_height;
1508 while (total_nshrink > 0 && extra > 0)
1510 nshrink = total_nshrink;
1511 for (row = 0; row < table->nrows; row++)
1512 if (table->rows[row].shrink)
1514 gint allocation = table->rows[row].allocation;
1516 table->rows[row].allocation = MAX (1, (gint) table->rows[row].allocation - extra / nshrink);
1517 extra -= allocation - table->rows[row].allocation;
1519 if (table->rows[row].allocation < 2)
1522 table->rows[row].shrink = FALSE;
1531 gtk_table_size_allocate_pass2 (GtkTable *table)
1533 GtkTableChild *child;
1539 GtkAllocation allocation;
1540 GtkWidget *widget = GTK_WIDGET (table);
1542 children = table->children;
1545 child = children->data;
1546 children = children->next;
1548 if (GTK_WIDGET_VISIBLE (child->widget))
1550 GtkRequisition child_requisition;
1551 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1553 x = GTK_WIDGET (table)->allocation.x + GTK_CONTAINER (table)->border_width;
1554 y = GTK_WIDGET (table)->allocation.y + GTK_CONTAINER (table)->border_width;
1558 for (col = 0; col < child->left_attach; col++)
1560 x += table->cols[col].allocation;
1561 x += table->cols[col].spacing;
1564 for (col = child->left_attach; col < child->right_attach; col++)
1566 max_width += table->cols[col].allocation;
1567 if ((col + 1) < child->right_attach)
1568 max_width += table->cols[col].spacing;
1571 for (row = 0; row < child->top_attach; row++)
1573 y += table->rows[row].allocation;
1574 y += table->rows[row].spacing;
1577 for (row = child->top_attach; row < child->bottom_attach; row++)
1579 max_height += table->rows[row].allocation;
1580 if ((row + 1) < child->bottom_attach)
1581 max_height += table->rows[row].spacing;
1586 allocation.width = MAX (1, max_width - (gint)child->xpadding * 2);
1587 allocation.x = x + (max_width - allocation.width) / 2;
1591 allocation.width = child_requisition.width;
1592 allocation.x = x + (max_width - allocation.width) / 2;
1597 allocation.height = MAX (1, max_height - (gint)child->ypadding * 2);
1598 allocation.y = y + (max_height - allocation.height) / 2;
1602 allocation.height = child_requisition.height;
1603 allocation.y = y + (max_height - allocation.height) / 2;
1606 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1607 allocation.x = widget->allocation.x + widget->allocation.width
1608 - (allocation.x - widget->allocation.x) - allocation.width;
1610 gtk_widget_size_allocate (child->widget, &allocation);
1615 #define __GTK_TABLE_C__
1616 #include "gtkaliasdef.c"