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_get_visible (child) &&
376 gtk_widget_get_visible (GTK_WIDGET (table)))
377 gtk_widget_queue_resize (child);
381 gtk_table_get_child_property (GtkContainer *container,
387 GtkTable *table = GTK_TABLE (container);
388 GtkTableChild *table_child;
392 for (list = table->children; list; list = list->next)
394 table_child = list->data;
396 if (table_child->widget == child)
401 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
407 case CHILD_PROP_LEFT_ATTACH:
408 g_value_set_uint (value, table_child->left_attach);
410 case CHILD_PROP_RIGHT_ATTACH:
411 g_value_set_uint (value, table_child->right_attach);
413 case CHILD_PROP_TOP_ATTACH:
414 g_value_set_uint (value, table_child->top_attach);
416 case CHILD_PROP_BOTTOM_ATTACH:
417 g_value_set_uint (value, table_child->bottom_attach);
419 case CHILD_PROP_X_OPTIONS:
420 g_value_set_flags (value, (table_child->xexpand * GTK_EXPAND |
421 table_child->xshrink * GTK_SHRINK |
422 table_child->xfill * GTK_FILL));
424 case CHILD_PROP_Y_OPTIONS:
425 g_value_set_flags (value, (table_child->yexpand * GTK_EXPAND |
426 table_child->yshrink * GTK_SHRINK |
427 table_child->yfill * GTK_FILL));
429 case CHILD_PROP_X_PADDING:
430 g_value_set_uint (value, table_child->xpadding);
432 case CHILD_PROP_Y_PADDING:
433 g_value_set_uint (value, table_child->ypadding);
436 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
442 gtk_table_init (GtkTable *table)
444 GTK_WIDGET_SET_FLAGS (table, GTK_NO_WINDOW);
445 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (table), FALSE);
447 table->children = NULL;
452 table->column_spacing = 0;
453 table->row_spacing = 0;
454 table->homogeneous = FALSE;
456 gtk_table_resize (table, 1, 1);
460 gtk_table_new (guint rows,
462 gboolean homogeneous)
471 table = g_object_new (GTK_TYPE_TABLE, NULL);
473 table->homogeneous = (homogeneous ? TRUE : FALSE);
475 gtk_table_resize (table, rows, columns);
477 return GTK_WIDGET (table);
481 gtk_table_resize (GtkTable *table,
485 g_return_if_fail (GTK_IS_TABLE (table));
486 g_return_if_fail (n_rows > 0 && n_rows <= 65535);
487 g_return_if_fail (n_cols > 0 && n_cols <= 65535);
489 n_rows = MAX (n_rows, 1);
490 n_cols = MAX (n_cols, 1);
492 if (n_rows != table->nrows ||
493 n_cols != table->ncols)
497 for (list = table->children; list; list = list->next)
499 GtkTableChild *child;
503 n_rows = MAX (n_rows, child->bottom_attach);
504 n_cols = MAX (n_cols, child->right_attach);
507 if (n_rows != table->nrows)
512 table->nrows = n_rows;
513 table->rows = g_realloc (table->rows, table->nrows * sizeof (GtkTableRowCol));
515 for (; i < table->nrows; i++)
517 table->rows[i].requisition = 0;
518 table->rows[i].allocation = 0;
519 table->rows[i].spacing = table->row_spacing;
520 table->rows[i].need_expand = 0;
521 table->rows[i].need_shrink = 0;
522 table->rows[i].expand = 0;
523 table->rows[i].shrink = 0;
526 g_object_notify (G_OBJECT (table), "n-rows");
529 if (n_cols != table->ncols)
534 table->ncols = n_cols;
535 table->cols = g_realloc (table->cols, table->ncols * sizeof (GtkTableRowCol));
537 for (; i < table->ncols; i++)
539 table->cols[i].requisition = 0;
540 table->cols[i].allocation = 0;
541 table->cols[i].spacing = table->column_spacing;
542 table->cols[i].need_expand = 0;
543 table->cols[i].need_shrink = 0;
544 table->cols[i].expand = 0;
545 table->cols[i].shrink = 0;
548 g_object_notify (G_OBJECT (table), "n-columns");
554 gtk_table_attach (GtkTable *table,
560 GtkAttachOptions xoptions,
561 GtkAttachOptions yoptions,
565 GtkTableChild *table_child;
567 g_return_if_fail (GTK_IS_TABLE (table));
568 g_return_if_fail (GTK_IS_WIDGET (child));
569 g_return_if_fail (child->parent == NULL);
571 /* g_return_if_fail (left_attach >= 0); */
572 g_return_if_fail (left_attach < right_attach);
573 /* g_return_if_fail (top_attach >= 0); */
574 g_return_if_fail (top_attach < bottom_attach);
576 if (right_attach >= table->ncols)
577 gtk_table_resize (table, table->nrows, right_attach);
579 if (bottom_attach >= table->nrows)
580 gtk_table_resize (table, bottom_attach, table->ncols);
582 table_child = g_new (GtkTableChild, 1);
583 table_child->widget = child;
584 table_child->left_attach = left_attach;
585 table_child->right_attach = right_attach;
586 table_child->top_attach = top_attach;
587 table_child->bottom_attach = bottom_attach;
588 table_child->xexpand = (xoptions & GTK_EXPAND) != 0;
589 table_child->xshrink = (xoptions & GTK_SHRINK) != 0;
590 table_child->xfill = (xoptions & GTK_FILL) != 0;
591 table_child->xpadding = xpadding;
592 table_child->yexpand = (yoptions & GTK_EXPAND) != 0;
593 table_child->yshrink = (yoptions & GTK_SHRINK) != 0;
594 table_child->yfill = (yoptions & GTK_FILL) != 0;
595 table_child->ypadding = ypadding;
597 table->children = g_list_prepend (table->children, table_child);
599 gtk_widget_set_parent (child, GTK_WIDGET (table));
603 gtk_table_attach_defaults (GtkTable *table,
610 gtk_table_attach (table, widget,
611 left_attach, right_attach,
612 top_attach, bottom_attach,
613 GTK_EXPAND | GTK_FILL,
614 GTK_EXPAND | GTK_FILL,
619 gtk_table_set_row_spacing (GtkTable *table,
623 g_return_if_fail (GTK_IS_TABLE (table));
624 g_return_if_fail (row < table->nrows);
626 if (table->rows[row].spacing != spacing)
628 table->rows[row].spacing = spacing;
630 if (gtk_widget_get_visible (GTK_WIDGET (table)))
631 gtk_widget_queue_resize (GTK_WIDGET (table));
636 * gtk_table_get_row_spacing:
637 * @table: a #GtkTable
638 * @row: a row in the table, 0 indicates the first row
640 * Gets the amount of space between row @row, and
641 * row @row + 1. See gtk_table_set_row_spacing().
643 * Return value: the row spacing
646 gtk_table_get_row_spacing (GtkTable *table,
649 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
650 g_return_val_if_fail (row < table->nrows - 1, 0);
652 return table->rows[row].spacing;
656 gtk_table_set_col_spacing (GtkTable *table,
660 g_return_if_fail (GTK_IS_TABLE (table));
661 g_return_if_fail (column < table->ncols);
663 if (table->cols[column].spacing != spacing)
665 table->cols[column].spacing = spacing;
667 if (gtk_widget_get_visible (GTK_WIDGET (table)))
668 gtk_widget_queue_resize (GTK_WIDGET (table));
673 * gtk_table_get_col_spacing:
674 * @table: a #GtkTable
675 * @column: a column in the table, 0 indicates the first column
677 * Gets the amount of space between column @col, and
678 * column @col + 1. See gtk_table_set_col_spacing().
680 * Return value: the column spacing
683 gtk_table_get_col_spacing (GtkTable *table,
686 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
687 g_return_val_if_fail (column < table->ncols, 0);
689 return table->cols[column].spacing;
693 gtk_table_set_row_spacings (GtkTable *table,
698 g_return_if_fail (GTK_IS_TABLE (table));
700 table->row_spacing = spacing;
701 for (row = 0; row < table->nrows; row++)
702 table->rows[row].spacing = spacing;
704 if (gtk_widget_get_visible (GTK_WIDGET (table)))
705 gtk_widget_queue_resize (GTK_WIDGET (table));
707 g_object_notify (G_OBJECT (table), "row-spacing");
711 * gtk_table_get_default_row_spacing:
712 * @table: a #GtkTable
714 * Gets the default row spacing for the table. This is
715 * the spacing that will be used for newly added rows.
716 * (See gtk_table_set_row_spacings())
718 * Return value: the default row spacing
721 gtk_table_get_default_row_spacing (GtkTable *table)
723 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
725 return table->row_spacing;
729 gtk_table_set_col_spacings (GtkTable *table,
734 g_return_if_fail (GTK_IS_TABLE (table));
736 table->column_spacing = spacing;
737 for (col = 0; col < table->ncols; col++)
738 table->cols[col].spacing = spacing;
740 if (gtk_widget_get_visible (GTK_WIDGET (table)))
741 gtk_widget_queue_resize (GTK_WIDGET (table));
743 g_object_notify (G_OBJECT (table), "column-spacing");
747 * gtk_table_get_default_col_spacing:
748 * @table: a #GtkTable
750 * Gets the default column spacing for the table. This is
751 * the spacing that will be used for newly added columns.
752 * (See gtk_table_set_col_spacings())
754 * Return value: the default column spacing
757 gtk_table_get_default_col_spacing (GtkTable *table)
759 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
761 return table->column_spacing;
765 gtk_table_set_homogeneous (GtkTable *table,
766 gboolean homogeneous)
768 g_return_if_fail (GTK_IS_TABLE (table));
770 homogeneous = (homogeneous != 0);
771 if (homogeneous != table->homogeneous)
773 table->homogeneous = homogeneous;
775 if (gtk_widget_get_visible (GTK_WIDGET (table)))
776 gtk_widget_queue_resize (GTK_WIDGET (table));
778 g_object_notify (G_OBJECT (table), "homogeneous");
783 * gtk_table_get_homogeneous:
784 * @table: a #GtkTable
786 * Returns whether the table cells are all constrained to the same
787 * width and height. (See gtk_table_set_homogenous ())
789 * Return value: %TRUE if the cells are all constrained to the same size
792 gtk_table_get_homogeneous (GtkTable *table)
794 g_return_val_if_fail (GTK_IS_TABLE (table), FALSE);
796 return table->homogeneous;
800 gtk_table_finalize (GObject *object)
802 GtkTable *table = GTK_TABLE (object);
804 g_free (table->rows);
805 g_free (table->cols);
807 G_OBJECT_CLASS (gtk_table_parent_class)->finalize (object);
811 gtk_table_size_request (GtkWidget *widget,
812 GtkRequisition *requisition)
814 GtkTable *table = GTK_TABLE (widget);
817 requisition->width = 0;
818 requisition->height = 0;
820 gtk_table_size_request_init (table);
821 gtk_table_size_request_pass1 (table);
822 gtk_table_size_request_pass2 (table);
823 gtk_table_size_request_pass3 (table);
824 gtk_table_size_request_pass2 (table);
826 for (col = 0; col < table->ncols; col++)
827 requisition->width += table->cols[col].requisition;
828 for (col = 0; col + 1 < table->ncols; col++)
829 requisition->width += table->cols[col].spacing;
831 for (row = 0; row < table->nrows; row++)
832 requisition->height += table->rows[row].requisition;
833 for (row = 0; row + 1 < table->nrows; row++)
834 requisition->height += table->rows[row].spacing;
836 requisition->width += GTK_CONTAINER (table)->border_width * 2;
837 requisition->height += GTK_CONTAINER (table)->border_width * 2;
841 gtk_table_size_allocate (GtkWidget *widget,
842 GtkAllocation *allocation)
844 GtkTable *table = GTK_TABLE (widget);
846 widget->allocation = *allocation;
848 gtk_table_size_allocate_init (table);
849 gtk_table_size_allocate_pass1 (table);
850 gtk_table_size_allocate_pass2 (table);
854 gtk_table_add (GtkContainer *container,
857 gtk_table_attach_defaults (GTK_TABLE (container), widget, 0, 1, 0, 1);
861 gtk_table_remove (GtkContainer *container,
864 GtkTable *table = GTK_TABLE (container);
865 GtkTableChild *child;
866 GtkWidget *widget_container = GTK_WIDGET (container);
869 children = table->children;
873 child = children->data;
874 children = children->next;
876 if (child->widget == widget)
878 gboolean was_visible = gtk_widget_get_visible (widget);
880 gtk_widget_unparent (widget);
882 table->children = g_list_remove (table->children, child);
885 if (was_visible && gtk_widget_get_visible (widget_container))
886 gtk_widget_queue_resize (widget_container);
893 gtk_table_forall (GtkContainer *container,
894 gboolean include_internals,
895 GtkCallback callback,
896 gpointer callback_data)
898 GtkTable *table = GTK_TABLE (container);
899 GtkTableChild *child;
902 children = table->children;
906 child = children->data;
907 children = children->next;
909 (* callback) (child->widget, callback_data);
914 gtk_table_size_request_init (GtkTable *table)
916 GtkTableChild *child;
920 for (row = 0; row < table->nrows; row++)
922 table->rows[row].requisition = 0;
923 table->rows[row].expand = FALSE;
925 for (col = 0; col < table->ncols; col++)
927 table->cols[col].requisition = 0;
928 table->cols[col].expand = FALSE;
931 children = table->children;
934 child = children->data;
935 children = children->next;
937 if (gtk_widget_get_visible (child->widget))
938 gtk_widget_size_request (child->widget, NULL);
940 if (child->left_attach == (child->right_attach - 1) && child->xexpand)
941 table->cols[child->left_attach].expand = TRUE;
943 if (child->top_attach == (child->bottom_attach - 1) && child->yexpand)
944 table->rows[child->top_attach].expand = TRUE;
949 gtk_table_size_request_pass1 (GtkTable *table)
951 GtkTableChild *child;
956 children = table->children;
959 child = children->data;
960 children = children->next;
962 if (gtk_widget_get_visible (child->widget))
964 GtkRequisition child_requisition;
965 gtk_widget_get_child_requisition (child->widget, &child_requisition);
967 /* Child spans a single column.
969 if (child->left_attach == (child->right_attach - 1))
971 width = child_requisition.width + child->xpadding * 2;
972 table->cols[child->left_attach].requisition = MAX (table->cols[child->left_attach].requisition, width);
975 /* Child spans a single row.
977 if (child->top_attach == (child->bottom_attach - 1))
979 height = child_requisition.height + child->ypadding * 2;
980 table->rows[child->top_attach].requisition = MAX (table->rows[child->top_attach].requisition, height);
987 gtk_table_size_request_pass2 (GtkTable *table)
993 if (table->homogeneous)
998 for (col = 0; col < table->ncols; col++)
999 max_width = MAX (max_width, table->cols[col].requisition);
1000 for (row = 0; row < table->nrows; row++)
1001 max_height = MAX (max_height, table->rows[row].requisition);
1003 for (col = 0; col < table->ncols; col++)
1004 table->cols[col].requisition = max_width;
1005 for (row = 0; row < table->nrows; row++)
1006 table->rows[row].requisition = max_height;
1011 gtk_table_size_request_pass3 (GtkTable *table)
1013 GtkTableChild *child;
1019 children = table->children;
1022 child = children->data;
1023 children = children->next;
1025 if (gtk_widget_get_visible (child->widget))
1027 /* Child spans multiple columns.
1029 if (child->left_attach != (child->right_attach - 1))
1031 GtkRequisition child_requisition;
1033 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1035 /* Check and see if there is already enough space
1039 for (col = child->left_attach; col < child->right_attach; col++)
1041 width += table->cols[col].requisition;
1042 if ((col + 1) < child->right_attach)
1043 width += table->cols[col].spacing;
1046 /* If we need to request more space for this child to fill
1047 * its requisition, then divide up the needed space amongst the
1048 * columns it spans, favoring expandable columns if any.
1050 if (width < child_requisition.width + child->xpadding * 2)
1053 gboolean force_expand = FALSE;
1055 width = child_requisition.width + child->xpadding * 2 - width;
1057 for (col = child->left_attach; col < child->right_attach; col++)
1058 if (table->cols[col].expand)
1063 n_expand = (child->right_attach - child->left_attach);
1064 force_expand = TRUE;
1067 for (col = child->left_attach; col < child->right_attach; col++)
1068 if (force_expand || table->cols[col].expand)
1070 extra = width / n_expand;
1071 table->cols[col].requisition += extra;
1078 /* Child spans multiple rows.
1080 if (child->top_attach != (child->bottom_attach - 1))
1082 GtkRequisition child_requisition;
1084 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1086 /* Check and see if there is already enough space
1090 for (row = child->top_attach; row < child->bottom_attach; row++)
1092 height += table->rows[row].requisition;
1093 if ((row + 1) < child->bottom_attach)
1094 height += table->rows[row].spacing;
1097 /* If we need to request more space for this child to fill
1098 * its requisition, then divide up the needed space amongst the
1099 * rows it spans, favoring expandable rows if any.
1101 if (height < child_requisition.height + child->ypadding * 2)
1104 gboolean force_expand = FALSE;
1106 height = child_requisition.height + child->ypadding * 2 - height;
1108 for (row = child->top_attach; row < child->bottom_attach; row++)
1110 if (table->rows[row].expand)
1116 n_expand = (child->bottom_attach - child->top_attach);
1117 force_expand = TRUE;
1120 for (row = child->top_attach; row < child->bottom_attach; row++)
1121 if (force_expand || table->rows[row].expand)
1123 extra = height / n_expand;
1124 table->rows[row].requisition += extra;
1135 gtk_table_size_allocate_init (GtkTable *table)
1137 GtkTableChild *child;
1143 /* Initialize the rows and cols.
1144 * By default, rows and cols do not expand and do shrink.
1145 * Those values are modified by the children that occupy
1146 * the rows and cols.
1148 for (col = 0; col < table->ncols; col++)
1150 table->cols[col].allocation = table->cols[col].requisition;
1151 table->cols[col].need_expand = FALSE;
1152 table->cols[col].need_shrink = TRUE;
1153 table->cols[col].expand = FALSE;
1154 table->cols[col].shrink = TRUE;
1155 table->cols[col].empty = TRUE;
1157 for (row = 0; row < table->nrows; row++)
1159 table->rows[row].allocation = table->rows[row].requisition;
1160 table->rows[row].need_expand = FALSE;
1161 table->rows[row].need_shrink = TRUE;
1162 table->rows[row].expand = FALSE;
1163 table->rows[row].shrink = TRUE;
1164 table->rows[row].empty = TRUE;
1167 /* Loop over all the children and adjust the row and col values
1168 * based on whether the children want to be allowed to expand
1169 * or shrink. This loop handles children that occupy a single
1172 children = table->children;
1175 child = children->data;
1176 children = children->next;
1178 if (gtk_widget_get_visible (child->widget))
1180 if (child->left_attach == (child->right_attach - 1))
1183 table->cols[child->left_attach].expand = TRUE;
1185 if (!child->xshrink)
1186 table->cols[child->left_attach].shrink = FALSE;
1188 table->cols[child->left_attach].empty = FALSE;
1191 if (child->top_attach == (child->bottom_attach - 1))
1194 table->rows[child->top_attach].expand = TRUE;
1196 if (!child->yshrink)
1197 table->rows[child->top_attach].shrink = FALSE;
1199 table->rows[child->top_attach].empty = FALSE;
1204 /* Loop over all the children again and this time handle children
1205 * which span multiple rows or columns.
1207 children = table->children;
1210 child = children->data;
1211 children = children->next;
1213 if (gtk_widget_get_visible (child->widget))
1215 if (child->left_attach != (child->right_attach - 1))
1217 for (col = child->left_attach; col < child->right_attach; col++)
1218 table->cols[col].empty = FALSE;
1223 for (col = child->left_attach; col < child->right_attach; col++)
1224 if (table->cols[col].expand)
1231 for (col = child->left_attach; col < child->right_attach; col++)
1232 table->cols[col].need_expand = TRUE;
1235 if (!child->xshrink)
1238 for (col = child->left_attach; col < child->right_attach; col++)
1239 if (!table->cols[col].shrink)
1246 for (col = child->left_attach; col < child->right_attach; col++)
1247 table->cols[col].need_shrink = FALSE;
1251 if (child->top_attach != (child->bottom_attach - 1))
1253 for (row = child->top_attach; row < child->bottom_attach; row++)
1254 table->rows[row].empty = FALSE;
1259 for (row = child->top_attach; row < child->bottom_attach; row++)
1260 if (table->rows[row].expand)
1267 for (row = child->top_attach; row < child->bottom_attach; row++)
1268 table->rows[row].need_expand = TRUE;
1271 if (!child->yshrink)
1274 for (row = child->top_attach; row < child->bottom_attach; row++)
1275 if (!table->rows[row].shrink)
1282 for (row = child->top_attach; row < child->bottom_attach; row++)
1283 table->rows[row].need_shrink = FALSE;
1289 /* Loop over the columns and set the expand and shrink values
1290 * if the column can be expanded or shrunk.
1292 for (col = 0; col < table->ncols; col++)
1294 if (table->cols[col].empty)
1296 table->cols[col].expand = FALSE;
1297 table->cols[col].shrink = FALSE;
1301 if (table->cols[col].need_expand)
1302 table->cols[col].expand = TRUE;
1303 if (!table->cols[col].need_shrink)
1304 table->cols[col].shrink = FALSE;
1308 /* Loop over the rows and set the expand and shrink values
1309 * if the row can be expanded or shrunk.
1311 for (row = 0; row < table->nrows; row++)
1313 if (table->rows[row].empty)
1315 table->rows[row].expand = FALSE;
1316 table->rows[row].shrink = FALSE;
1320 if (table->rows[row].need_expand)
1321 table->rows[row].expand = TRUE;
1322 if (!table->rows[row].need_shrink)
1323 table->rows[row].shrink = FALSE;
1329 gtk_table_size_allocate_pass1 (GtkTable *table)
1339 /* If we were allocated more space than we requested
1340 * then we have to expand any expandable rows and columns
1341 * to fill in the extra space.
1344 real_width = GTK_WIDGET (table)->allocation.width - GTK_CONTAINER (table)->border_width * 2;
1345 real_height = GTK_WIDGET (table)->allocation.height - GTK_CONTAINER (table)->border_width * 2;
1347 if (table->homogeneous)
1349 if (!table->children)
1354 for (col = 0; col < table->ncols; col++)
1355 if (table->cols[col].expand)
1364 for (col = 0; col + 1 < table->ncols; col++)
1365 width -= table->cols[col].spacing;
1367 for (col = 0; col < table->ncols; col++)
1369 extra = width / (table->ncols - col);
1370 table->cols[col].allocation = MAX (1, extra);
1381 for (col = 0; col < table->ncols; col++)
1383 width += table->cols[col].requisition;
1384 if (table->cols[col].expand)
1386 if (table->cols[col].shrink)
1389 for (col = 0; col + 1 < table->ncols; col++)
1390 width += table->cols[col].spacing;
1392 /* Check to see if we were allocated more width than we requested.
1394 if ((width < real_width) && (nexpand >= 1))
1396 width = real_width - width;
1398 for (col = 0; col < table->ncols; col++)
1399 if (table->cols[col].expand)
1401 extra = width / nexpand;
1402 table->cols[col].allocation += extra;
1409 /* Check to see if we were allocated less width than we requested,
1410 * then shrink until we fit the size give.
1412 if (width > real_width)
1414 gint total_nshrink = nshrink;
1416 extra = width - real_width;
1417 while (total_nshrink > 0 && extra > 0)
1419 nshrink = total_nshrink;
1420 for (col = 0; col < table->ncols; col++)
1421 if (table->cols[col].shrink)
1423 gint allocation = table->cols[col].allocation;
1425 table->cols[col].allocation = MAX (1, (gint) table->cols[col].allocation - extra / nshrink);
1426 extra -= allocation - table->cols[col].allocation;
1428 if (table->cols[col].allocation < 2)
1431 table->cols[col].shrink = FALSE;
1438 if (table->homogeneous)
1440 if (!table->children)
1445 for (row = 0; row < table->nrows; row++)
1446 if (table->rows[row].expand)
1454 height = real_height;
1456 for (row = 0; row + 1 < table->nrows; row++)
1457 height -= table->rows[row].spacing;
1460 for (row = 0; row < table->nrows; row++)
1462 extra = height / (table->nrows - row);
1463 table->rows[row].allocation = MAX (1, extra);
1474 for (row = 0; row < table->nrows; row++)
1476 height += table->rows[row].requisition;
1477 if (table->rows[row].expand)
1479 if (table->rows[row].shrink)
1482 for (row = 0; row + 1 < table->nrows; row++)
1483 height += table->rows[row].spacing;
1485 /* Check to see if we were allocated more height than we requested.
1487 if ((height < real_height) && (nexpand >= 1))
1489 height = real_height - height;
1491 for (row = 0; row < table->nrows; row++)
1492 if (table->rows[row].expand)
1494 extra = height / nexpand;
1495 table->rows[row].allocation += extra;
1502 /* Check to see if we were allocated less height than we requested.
1503 * then shrink until we fit the size give.
1505 if (height > real_height)
1507 gint total_nshrink = nshrink;
1509 extra = height - real_height;
1510 while (total_nshrink > 0 && extra > 0)
1512 nshrink = total_nshrink;
1513 for (row = 0; row < table->nrows; row++)
1514 if (table->rows[row].shrink)
1516 gint allocation = table->rows[row].allocation;
1518 table->rows[row].allocation = MAX (1, (gint) table->rows[row].allocation - extra / nshrink);
1519 extra -= allocation - table->rows[row].allocation;
1521 if (table->rows[row].allocation < 2)
1524 table->rows[row].shrink = FALSE;
1533 gtk_table_size_allocate_pass2 (GtkTable *table)
1535 GtkTableChild *child;
1541 GtkAllocation allocation;
1542 GtkWidget *widget = GTK_WIDGET (table);
1544 children = table->children;
1547 child = children->data;
1548 children = children->next;
1550 if (gtk_widget_get_visible (child->widget))
1552 GtkRequisition child_requisition;
1553 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1555 x = GTK_WIDGET (table)->allocation.x + GTK_CONTAINER (table)->border_width;
1556 y = GTK_WIDGET (table)->allocation.y + GTK_CONTAINER (table)->border_width;
1560 for (col = 0; col < child->left_attach; col++)
1562 x += table->cols[col].allocation;
1563 x += table->cols[col].spacing;
1566 for (col = child->left_attach; col < child->right_attach; col++)
1568 max_width += table->cols[col].allocation;
1569 if ((col + 1) < child->right_attach)
1570 max_width += table->cols[col].spacing;
1573 for (row = 0; row < child->top_attach; row++)
1575 y += table->rows[row].allocation;
1576 y += table->rows[row].spacing;
1579 for (row = child->top_attach; row < child->bottom_attach; row++)
1581 max_height += table->rows[row].allocation;
1582 if ((row + 1) < child->bottom_attach)
1583 max_height += table->rows[row].spacing;
1588 allocation.width = MAX (1, max_width - (gint)child->xpadding * 2);
1589 allocation.x = x + (max_width - allocation.width) / 2;
1593 allocation.width = child_requisition.width;
1594 allocation.x = x + (max_width - allocation.width) / 2;
1599 allocation.height = MAX (1, max_height - (gint)child->ypadding * 2);
1600 allocation.y = y + (max_height - allocation.height) / 2;
1604 allocation.height = child_requisition.height;
1605 allocation.y = y + (max_height - allocation.height) / 2;
1608 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1609 allocation.x = widget->allocation.x + widget->allocation.width
1610 - (allocation.x - widget->allocation.x) - allocation.width;
1612 gtk_widget_size_allocate (child->widget, &allocation);
1617 #define __GTK_TABLE_C__
1618 #include "gtkaliasdef.c"