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/.
43 CHILD_PROP_LEFT_ATTACH,
44 CHILD_PROP_RIGHT_ATTACH,
45 CHILD_PROP_TOP_ATTACH,
46 CHILD_PROP_BOTTOM_ATTACH,
54 static void gtk_table_class_init (GtkTableClass *klass);
55 static void gtk_table_init (GtkTable *table);
56 static void gtk_table_finalize (GObject *object);
57 static void gtk_table_size_request (GtkWidget *widget,
58 GtkRequisition *requisition);
59 static void gtk_table_size_allocate (GtkWidget *widget,
60 GtkAllocation *allocation);
61 static void gtk_table_add (GtkContainer *container,
63 static void gtk_table_remove (GtkContainer *container,
65 static void gtk_table_forall (GtkContainer *container,
66 gboolean include_internals,
68 gpointer callback_data);
69 static void gtk_table_get_property (GObject *object,
73 static void gtk_table_set_property (GObject *object,
77 static void gtk_table_set_child_property (GtkContainer *container,
82 static void gtk_table_get_child_property (GtkContainer *container,
87 static GtkType gtk_table_child_type (GtkContainer *container);
90 static void gtk_table_size_request_init (GtkTable *table);
91 static void gtk_table_size_request_pass1 (GtkTable *table);
92 static void gtk_table_size_request_pass2 (GtkTable *table);
93 static void gtk_table_size_request_pass3 (GtkTable *table);
95 static void gtk_table_size_allocate_init (GtkTable *table);
96 static void gtk_table_size_allocate_pass1 (GtkTable *table);
97 static void gtk_table_size_allocate_pass2 (GtkTable *table);
100 static GtkContainerClass *parent_class = NULL;
104 gtk_table_get_type (void)
106 static GtkType table_type = 0;
110 static const GtkTypeInfo table_info =
114 sizeof (GtkTableClass),
115 (GtkClassInitFunc) gtk_table_class_init,
116 (GtkObjectInitFunc) gtk_table_init,
117 /* reserved_1 */ NULL,
118 /* reserved_2 */ NULL,
119 (GtkClassInitFunc) NULL,
122 table_type = gtk_type_unique (gtk_container_get_type (), &table_info);
129 gtk_table_class_init (GtkTableClass *class)
131 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
132 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
133 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
135 parent_class = g_type_class_peek_parent (class);
137 gobject_class->finalize = gtk_table_finalize;
139 gobject_class->get_property = gtk_table_get_property;
140 gobject_class->set_property = gtk_table_set_property;
142 widget_class->size_request = gtk_table_size_request;
143 widget_class->size_allocate = gtk_table_size_allocate;
145 container_class->add = gtk_table_add;
146 container_class->remove = gtk_table_remove;
147 container_class->forall = gtk_table_forall;
148 container_class->child_type = gtk_table_child_type;
149 container_class->set_child_property = gtk_table_set_child_property;
150 container_class->get_child_property = gtk_table_get_child_property;
153 g_object_class_install_property (gobject_class,
155 g_param_spec_uint ("n_rows",
157 _("The number of rows in the table"),
162 g_object_class_install_property (gobject_class,
164 g_param_spec_uint ("n_columns",
166 _("The number of columns in the table"),
171 g_object_class_install_property (gobject_class,
173 g_param_spec_uint ("row_spacing",
175 _("The amount of space between two consecutive rows"),
180 g_object_class_install_property (gobject_class,
182 g_param_spec_uint ("column_spacing",
184 _("The amount of space between two consecutive columns"),
189 g_object_class_install_property (gobject_class,
191 g_param_spec_boolean ("homogeneous",
193 _("If TRUE this means the table cells are all the same width/height"),
197 gtk_container_class_install_child_property (container_class,
198 CHILD_PROP_LEFT_ATTACH,
199 g_param_spec_uint ("left_attach", NULL, NULL,
202 gtk_container_class_install_child_property (container_class,
203 CHILD_PROP_RIGHT_ATTACH,
204 g_param_spec_uint ("right_attach", NULL, NULL,
207 gtk_container_class_install_child_property (container_class,
208 CHILD_PROP_TOP_ATTACH,
209 g_param_spec_uint ("top_attach", NULL, NULL,
212 gtk_container_class_install_child_property (container_class,
213 CHILD_PROP_BOTTOM_ATTACH,
214 g_param_spec_uint ("bottom_attach", NULL, NULL,
217 gtk_container_class_install_child_property (container_class,
218 CHILD_PROP_X_OPTIONS,
219 g_param_spec_flags ("x_options", NULL, NULL,
220 GTK_TYPE_ATTACH_OPTIONS, GTK_EXPAND | GTK_FILL,
222 gtk_container_class_install_child_property (container_class,
223 CHILD_PROP_Y_OPTIONS,
224 g_param_spec_flags ("y_options", NULL, NULL,
225 GTK_TYPE_ATTACH_OPTIONS, GTK_EXPAND | GTK_FILL,
227 gtk_container_class_install_child_property (container_class,
228 CHILD_PROP_X_PADDING,
229 g_param_spec_uint ("x_padding", NULL, NULL,
232 gtk_container_class_install_child_property (container_class,
233 CHILD_PROP_Y_PADDING,
234 g_param_spec_uint ("y_padding", NULL, NULL,
240 gtk_table_child_type (GtkContainer *container)
242 return GTK_TYPE_WIDGET;
246 gtk_table_get_property (GObject *object,
253 table = GTK_TABLE (object);
258 g_value_set_uint (value, table->nrows);
261 g_value_set_uint (value, table->ncols);
263 case PROP_ROW_SPACING:
264 g_value_set_uint (value, table->row_spacing);
266 case PROP_COLUMN_SPACING:
267 g_value_set_uint (value, table->column_spacing);
269 case PROP_HOMOGENEOUS:
270 g_value_set_boolean (value, table->homogeneous);
273 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
279 gtk_table_set_property (GObject *object,
286 table = GTK_TABLE (object);
291 gtk_table_resize (table, g_value_get_uint (value), table->ncols);
294 gtk_table_resize (table, table->nrows, g_value_get_uint (value));
296 case PROP_ROW_SPACING:
297 gtk_table_set_row_spacings (table, g_value_get_uint (value));
299 case PROP_COLUMN_SPACING:
300 gtk_table_set_col_spacings (table, g_value_get_uint (value));
302 case PROP_HOMOGENEOUS:
303 gtk_table_set_homogeneous (table, g_value_get_boolean (value));
306 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
312 gtk_table_set_child_property (GtkContainer *container,
318 GtkTable *table = GTK_TABLE (container);
319 GtkTableChild *table_child;
323 for (list = table->children; list; list = list->next)
325 table_child = list->data;
327 if (table_child->widget == child)
332 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
338 case CHILD_PROP_LEFT_ATTACH:
339 table_child->left_attach = g_value_get_uint (value);
340 if (table_child->right_attach <= table_child->left_attach)
341 table_child->right_attach = table_child->left_attach + 1;
342 if (table_child->right_attach >= table->ncols)
343 gtk_table_resize (table, table->nrows, table_child->right_attach);
345 case CHILD_PROP_RIGHT_ATTACH:
346 table_child->right_attach = g_value_get_uint (value);
347 if (table_child->right_attach <= table_child->left_attach)
348 table_child->left_attach = table_child->right_attach - 1;
349 if (table_child->right_attach >= table->ncols)
350 gtk_table_resize (table, table->nrows, table_child->right_attach);
352 case CHILD_PROP_TOP_ATTACH:
353 table_child->top_attach = g_value_get_uint (value);
354 if (table_child->bottom_attach <= table_child->top_attach)
355 table_child->bottom_attach = table_child->top_attach + 1;
356 if (table_child->bottom_attach >= table->nrows)
357 gtk_table_resize (table, table_child->bottom_attach, table->ncols);
359 case CHILD_PROP_BOTTOM_ATTACH:
360 table_child->bottom_attach = g_value_get_uint (value);
361 if (table_child->bottom_attach <= table_child->top_attach)
362 table_child->top_attach = table_child->bottom_attach - 1;
363 if (table_child->bottom_attach >= table->nrows)
364 gtk_table_resize (table, table_child->bottom_attach, table->ncols);
366 case CHILD_PROP_X_OPTIONS:
367 table_child->xexpand = (g_value_get_flags (value) & GTK_EXPAND) != 0;
368 table_child->xshrink = (g_value_get_flags (value) & GTK_SHRINK) != 0;
369 table_child->xfill = (g_value_get_flags (value) & GTK_FILL) != 0;
371 case CHILD_PROP_Y_OPTIONS:
372 table_child->yexpand = (g_value_get_flags (value) & GTK_EXPAND) != 0;
373 table_child->yshrink = (g_value_get_flags (value) & GTK_SHRINK) != 0;
374 table_child->yfill = (g_value_get_flags (value) & GTK_FILL) != 0;
376 case CHILD_PROP_X_PADDING:
377 table_child->xpadding = g_value_get_uint (value);
379 case CHILD_PROP_Y_PADDING:
380 table_child->ypadding = g_value_get_uint (value);
383 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
386 if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (table))
387 gtk_widget_queue_resize (child);
391 gtk_table_get_child_property (GtkContainer *container,
397 GtkTable *table = GTK_TABLE (container);
398 GtkTableChild *table_child;
402 for (list = table->children; list; list = list->next)
404 table_child = list->data;
406 if (table_child->widget == child)
411 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
417 case CHILD_PROP_LEFT_ATTACH:
418 g_value_set_uint (value, table_child->left_attach);
420 case CHILD_PROP_RIGHT_ATTACH:
421 g_value_set_uint (value, table_child->right_attach);
423 case CHILD_PROP_TOP_ATTACH:
424 g_value_set_uint (value, table_child->top_attach);
426 case CHILD_PROP_BOTTOM_ATTACH:
427 g_value_set_uint (value, table_child->bottom_attach);
429 case CHILD_PROP_X_OPTIONS:
430 g_value_set_flags (value, (table_child->xexpand * GTK_EXPAND |
431 table_child->xshrink * GTK_SHRINK |
432 table_child->xfill * GTK_FILL));
434 case CHILD_PROP_Y_OPTIONS:
435 g_value_set_flags (value, (table_child->yexpand * GTK_EXPAND |
436 table_child->yshrink * GTK_SHRINK |
437 table_child->yfill * GTK_FILL));
439 case CHILD_PROP_X_PADDING:
440 g_value_set_uint (value, table_child->xpadding);
442 case CHILD_PROP_Y_PADDING:
443 g_value_set_uint (value, table_child->ypadding);
446 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
452 gtk_table_init (GtkTable *table)
454 GTK_WIDGET_SET_FLAGS (table, GTK_NO_WINDOW);
456 table->children = NULL;
461 table->column_spacing = 0;
462 table->row_spacing = 0;
463 table->homogeneous = FALSE;
465 gtk_table_resize (table, 1, 1);
469 gtk_table_new (guint rows,
471 gboolean homogeneous)
480 table = gtk_type_new (gtk_table_get_type ());
482 table->homogeneous = (homogeneous ? TRUE : FALSE);
484 gtk_table_resize (table, rows, columns);
486 return GTK_WIDGET (table);
490 gtk_table_resize (GtkTable *table,
494 g_return_if_fail (GTK_IS_TABLE (table));
495 g_return_if_fail (n_rows > 0 && n_rows < 65536);
496 g_return_if_fail (n_rows > 0 && n_cols < 65536);
498 n_rows = MAX (n_rows, 1);
499 n_cols = MAX (n_cols, 1);
501 if (n_rows != table->nrows ||
502 n_cols != table->ncols)
506 for (list = table->children; list; list = list->next)
508 GtkTableChild *child;
512 n_rows = MAX (n_rows, child->bottom_attach);
513 n_cols = MAX (n_cols, child->right_attach);
516 if (n_rows != table->nrows)
521 table->nrows = n_rows;
522 table->rows = g_realloc (table->rows, table->nrows * sizeof (GtkTableRowCol));
524 for (; i < table->nrows; i++)
526 table->rows[i].requisition = 0;
527 table->rows[i].allocation = 0;
528 table->rows[i].spacing = table->row_spacing;
529 table->rows[i].need_expand = 0;
530 table->rows[i].need_shrink = 0;
531 table->rows[i].expand = 0;
532 table->rows[i].shrink = 0;
535 g_object_notify (G_OBJECT (table), "n_rows");
538 if (n_cols != table->ncols)
543 table->ncols = n_cols;
544 table->cols = g_realloc (table->cols, table->ncols * sizeof (GtkTableRowCol));
546 for (; i < table->ncols; i++)
548 table->cols[i].requisition = 0;
549 table->cols[i].allocation = 0;
550 table->cols[i].spacing = table->column_spacing;
551 table->cols[i].need_expand = 0;
552 table->cols[i].need_shrink = 0;
553 table->cols[i].expand = 0;
554 table->cols[i].shrink = 0;
557 g_object_notify (G_OBJECT (table), "n_columns");
563 gtk_table_attach (GtkTable *table,
569 GtkAttachOptions xoptions,
570 GtkAttachOptions yoptions,
574 GtkTableChild *table_child;
576 g_return_if_fail (GTK_IS_TABLE (table));
577 g_return_if_fail (GTK_IS_WIDGET (child));
578 g_return_if_fail (child->parent == NULL);
580 /* g_return_if_fail (left_attach >= 0); */
581 g_return_if_fail (left_attach < right_attach);
582 /* g_return_if_fail (top_attach >= 0); */
583 g_return_if_fail (top_attach < bottom_attach);
585 if (right_attach >= table->ncols)
586 gtk_table_resize (table, table->nrows, right_attach);
588 if (bottom_attach >= table->nrows)
589 gtk_table_resize (table, bottom_attach, table->ncols);
591 table_child = g_new (GtkTableChild, 1);
592 table_child->widget = child;
593 table_child->left_attach = left_attach;
594 table_child->right_attach = right_attach;
595 table_child->top_attach = top_attach;
596 table_child->bottom_attach = bottom_attach;
597 table_child->xexpand = (xoptions & GTK_EXPAND) != 0;
598 table_child->xshrink = (xoptions & GTK_SHRINK) != 0;
599 table_child->xfill = (xoptions & GTK_FILL) != 0;
600 table_child->xpadding = xpadding;
601 table_child->yexpand = (yoptions & GTK_EXPAND) != 0;
602 table_child->yshrink = (yoptions & GTK_SHRINK) != 0;
603 table_child->yfill = (yoptions & GTK_FILL) != 0;
604 table_child->ypadding = ypadding;
606 table->children = g_list_prepend (table->children, table_child);
608 gtk_widget_set_parent (child, GTK_WIDGET (table));
612 gtk_table_attach_defaults (GtkTable *table,
619 gtk_table_attach (table, widget,
620 left_attach, right_attach,
621 top_attach, bottom_attach,
622 GTK_EXPAND | GTK_FILL,
623 GTK_EXPAND | GTK_FILL,
628 gtk_table_set_row_spacing (GtkTable *table,
632 g_return_if_fail (GTK_IS_TABLE (table));
633 g_return_if_fail (row < table->nrows);
635 if (table->rows[row].spacing != spacing)
637 table->rows[row].spacing = spacing;
639 if (GTK_WIDGET_VISIBLE (table))
640 gtk_widget_queue_resize (GTK_WIDGET (table));
643 g_object_notify (G_OBJECT (table), "row_spacing");
647 * gtk_table_get_row_spacing:
648 * @table: a #GtkTable
649 * @row: a row in the table, 0 indicates the first row
651 * Gets the amount of space between row @row, and
652 * row @row + 1. See gtk_table_set_row_spacing().
654 * Return value: the row spacing
657 gtk_table_get_row_spacing (GtkTable *table,
660 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
661 g_return_val_if_fail (row < table->nrows - 1, 0);
663 return table->rows[row].spacing;
667 gtk_table_set_col_spacing (GtkTable *table,
671 g_return_if_fail (GTK_IS_TABLE (table));
672 g_return_if_fail (column < table->ncols);
674 if (table->cols[column].spacing != spacing)
676 table->cols[column].spacing = spacing;
678 if (GTK_WIDGET_VISIBLE (table))
679 gtk_widget_queue_resize (GTK_WIDGET (table));
682 g_object_notify (G_OBJECT (table), "column_spacing");
686 * gtk_table_get_col_spacing:
687 * @table: a #GtkTable
688 * @col: a column in the table, 0 indicates the first column
690 * Gets the amount of space between column @col, and
691 * column @col + 1. See gtk_table_set_col_spacing().
693 * Return value: the column spacing
696 gtk_table_get_col_spacing (GtkTable *table,
699 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
700 g_return_val_if_fail (column < table->ncols, 0);
702 return table->cols[column].spacing;
706 gtk_table_set_row_spacings (GtkTable *table,
711 g_return_if_fail (GTK_IS_TABLE (table));
713 table->row_spacing = spacing;
714 for (row = 0; row < table->nrows; row++)
715 table->rows[row].spacing = spacing;
717 if (GTK_WIDGET_VISIBLE (table))
718 gtk_widget_queue_resize (GTK_WIDGET (table));
722 * gtk_table_get_default_row_spacing:
723 * @table: a #GtkTable
725 * Gets the default row spacing for the table. This is
726 * the spacing that will be used for newly added rows.
727 * (See gtk_table_set_row_spacings())
729 * Returns value: the default row spacing
732 gtk_table_get_default_row_spacing (GtkTable *table)
734 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
736 return table->row_spacing;
740 gtk_table_set_col_spacings (GtkTable *table,
745 g_return_if_fail (GTK_IS_TABLE (table));
747 table->column_spacing = spacing;
748 for (col = 0; col < table->ncols; col++)
749 table->cols[col].spacing = spacing;
751 if (GTK_WIDGET_VISIBLE (table))
752 gtk_widget_queue_resize (GTK_WIDGET (table));
756 * gtk_table_get_default_col_spacing:
757 * @table: a #GtkTable
759 * Gets the default column spacing for the table. This is
760 * the spacing that will be used for newly added columns.
761 * (See gtk_table_set_col_spacings())
763 * Returns value: the default column spacing
766 gtk_table_get_default_col_spacing (GtkTable *table)
768 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
770 return table->column_spacing;
774 gtk_table_set_homogeneous (GtkTable *table,
775 gboolean homogeneous)
777 g_return_if_fail (GTK_IS_TABLE (table));
779 homogeneous = (homogeneous != 0);
780 if (homogeneous != table->homogeneous)
782 table->homogeneous = homogeneous;
784 if (GTK_WIDGET_VISIBLE (table))
785 gtk_widget_queue_resize (GTK_WIDGET (table));
790 * gtk_table_get_homogeneous:
791 * @table: a #GtkTable
793 * Returns whether the table cells are all constrained to the same
794 * width and height. (See gtk_table_set_homogenous ())
796 * Return value: %TRUE if the cells are all constrained to the same size
799 gtk_table_get_homogeneous (GtkTable *table)
801 g_return_val_if_fail (GTK_IS_TABLE (table), FALSE);
803 return table->homogeneous;
807 gtk_table_finalize (GObject *object)
811 g_return_if_fail (GTK_IS_TABLE (object));
813 table = GTK_TABLE (object);
815 g_free (table->rows);
816 g_free (table->cols);
818 G_OBJECT_CLASS (parent_class)->finalize (object);
822 gtk_table_size_request (GtkWidget *widget,
823 GtkRequisition *requisition)
828 g_return_if_fail (GTK_IS_TABLE (widget));
829 g_return_if_fail (requisition != NULL);
831 table = GTK_TABLE (widget);
833 requisition->width = 0;
834 requisition->height = 0;
836 gtk_table_size_request_init (table);
837 gtk_table_size_request_pass1 (table);
838 gtk_table_size_request_pass2 (table);
839 gtk_table_size_request_pass3 (table);
840 gtk_table_size_request_pass2 (table);
842 for (col = 0; col < table->ncols; col++)
843 requisition->width += table->cols[col].requisition;
844 for (col = 0; col + 1 < table->ncols; col++)
845 requisition->width += table->cols[col].spacing;
847 for (row = 0; row < table->nrows; row++)
848 requisition->height += table->rows[row].requisition;
849 for (row = 0; row + 1 < table->nrows; row++)
850 requisition->height += table->rows[row].spacing;
852 requisition->width += GTK_CONTAINER (table)->border_width * 2;
853 requisition->height += GTK_CONTAINER (table)->border_width * 2;
857 gtk_table_size_allocate (GtkWidget *widget,
858 GtkAllocation *allocation)
862 g_return_if_fail (GTK_IS_TABLE (widget));
863 g_return_if_fail (allocation != NULL);
865 widget->allocation = *allocation;
866 table = GTK_TABLE (widget);
868 gtk_table_size_allocate_init (table);
869 gtk_table_size_allocate_pass1 (table);
870 gtk_table_size_allocate_pass2 (table);
874 gtk_table_add (GtkContainer *container,
877 g_return_if_fail (GTK_IS_TABLE (container));
878 g_return_if_fail (widget != NULL);
880 gtk_table_attach_defaults (GTK_TABLE (container), widget, 0, 1, 0, 1);
884 gtk_table_remove (GtkContainer *container,
888 GtkTableChild *child;
891 g_return_if_fail (GTK_IS_TABLE (container));
892 g_return_if_fail (widget != NULL);
894 table = GTK_TABLE (container);
895 children = table->children;
899 child = children->data;
900 children = children->next;
902 if (child->widget == widget)
904 gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
906 gtk_widget_unparent (widget);
908 table->children = g_list_remove (table->children, child);
911 if (was_visible && GTK_WIDGET_VISIBLE (container))
912 gtk_container_queue_resize (container);
919 gtk_table_forall (GtkContainer *container,
920 gboolean include_internals,
921 GtkCallback callback,
922 gpointer callback_data)
925 GtkTableChild *child;
928 g_return_if_fail (GTK_IS_TABLE (container));
929 g_return_if_fail (callback != NULL);
931 table = GTK_TABLE (container);
932 children = table->children;
936 child = children->data;
937 children = children->next;
939 (* callback) (child->widget, callback_data);
944 gtk_table_size_request_init (GtkTable *table)
946 GtkTableChild *child;
950 for (row = 0; row < table->nrows; row++)
951 table->rows[row].requisition = 0;
952 for (col = 0; col < table->ncols; col++)
953 table->cols[col].requisition = 0;
955 children = table->children;
958 child = children->data;
959 children = children->next;
961 if (GTK_WIDGET_VISIBLE (child->widget))
962 gtk_widget_size_request (child->widget, NULL);
967 gtk_table_size_request_pass1 (GtkTable *table)
969 GtkTableChild *child;
974 children = table->children;
977 child = children->data;
978 children = children->next;
980 if (GTK_WIDGET_VISIBLE (child->widget))
982 GtkRequisition child_requisition;
983 gtk_widget_get_child_requisition (child->widget, &child_requisition);
985 /* Child spans a single column.
987 if (child->left_attach == (child->right_attach - 1))
989 width = child_requisition.width + child->xpadding * 2;
990 table->cols[child->left_attach].requisition = MAX (table->cols[child->left_attach].requisition, width);
993 /* Child spans a single row.
995 if (child->top_attach == (child->bottom_attach - 1))
997 height = child_requisition.height + child->ypadding * 2;
998 table->rows[child->top_attach].requisition = MAX (table->rows[child->top_attach].requisition, height);
1005 gtk_table_size_request_pass2 (GtkTable *table)
1011 if (table->homogeneous)
1016 for (col = 0; col < table->ncols; col++)
1017 max_width = MAX (max_width, table->cols[col].requisition);
1018 for (row = 0; row < table->nrows; row++)
1019 max_height = MAX (max_height, table->rows[row].requisition);
1021 for (col = 0; col < table->ncols; col++)
1022 table->cols[col].requisition = max_width;
1023 for (row = 0; row < table->nrows; row++)
1024 table->rows[row].requisition = max_height;
1029 gtk_table_size_request_pass3 (GtkTable *table)
1031 GtkTableChild *child;
1037 children = table->children;
1040 child = children->data;
1041 children = children->next;
1043 if (GTK_WIDGET_VISIBLE (child->widget))
1045 /* Child spans multiple columns.
1047 if (child->left_attach != (child->right_attach - 1))
1049 GtkRequisition child_requisition;
1051 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1053 /* Check and see if there is already enough space
1057 for (col = child->left_attach; col < child->right_attach; col++)
1059 width += table->cols[col].requisition;
1060 if ((col + 1) < child->right_attach)
1061 width += table->cols[col].spacing;
1064 /* If we need to request more space for this child to fill
1065 * its requisition, then divide up the needed space evenly
1066 * amongst the columns it spans.
1068 if (width < child_requisition.width + child->xpadding * 2)
1070 width = child_requisition.width + child->xpadding * 2 - width;
1072 for (col = child->left_attach; col < child->right_attach; col++)
1074 extra = width / (child->right_attach - col);
1075 table->cols[col].requisition += extra;
1081 /* Child spans multiple rows.
1083 if (child->top_attach != (child->bottom_attach - 1))
1085 GtkRequisition child_requisition;
1087 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1089 /* Check and see if there is already enough space
1093 for (row = child->top_attach; row < child->bottom_attach; row++)
1095 height += table->rows[row].requisition;
1096 if ((row + 1) < child->bottom_attach)
1097 height += table->rows[row].spacing;
1100 /* If we need to request more space for this child to fill
1101 * its requisition, then divide up the needed space evenly
1102 * amongst the columns it spans.
1104 if (height < child_requisition.height + child->ypadding * 2)
1106 height = child_requisition.height + child->ypadding * 2 - height;
1108 for (row = child->top_attach; row < child->bottom_attach; row++)
1110 extra = height / (child->bottom_attach - row);
1111 table->rows[row].requisition += extra;
1121 gtk_table_size_allocate_init (GtkTable *table)
1123 GtkTableChild *child;
1129 /* Initialize the rows and cols.
1130 * By default, rows and cols do not expand and do shrink.
1131 * Those values are modified by the children that occupy
1132 * the rows and cols.
1134 for (col = 0; col < table->ncols; col++)
1136 table->cols[col].allocation = table->cols[col].requisition;
1137 table->cols[col].need_expand = FALSE;
1138 table->cols[col].need_shrink = TRUE;
1139 table->cols[col].expand = FALSE;
1140 table->cols[col].shrink = TRUE;
1141 table->cols[col].empty = TRUE;
1143 for (row = 0; row < table->nrows; row++)
1145 table->rows[row].allocation = table->rows[row].requisition;
1146 table->rows[row].need_expand = FALSE;
1147 table->rows[row].need_shrink = TRUE;
1148 table->rows[row].expand = FALSE;
1149 table->rows[row].shrink = TRUE;
1150 table->rows[row].empty = TRUE;
1153 /* Loop over all the children and adjust the row and col values
1154 * based on whether the children want to be allowed to expand
1155 * or shrink. This loop handles children that occupy a single
1158 children = table->children;
1161 child = children->data;
1162 children = children->next;
1164 if (GTK_WIDGET_VISIBLE (child->widget))
1166 if (child->left_attach == (child->right_attach - 1))
1169 table->cols[child->left_attach].expand = TRUE;
1171 if (!child->xshrink)
1172 table->cols[child->left_attach].shrink = FALSE;
1174 table->cols[child->left_attach].empty = FALSE;
1177 if (child->top_attach == (child->bottom_attach - 1))
1180 table->rows[child->top_attach].expand = TRUE;
1182 if (!child->yshrink)
1183 table->rows[child->top_attach].shrink = FALSE;
1185 table->rows[child->top_attach].empty = FALSE;
1190 /* Loop over all the children again and this time handle children
1191 * which span multiple rows or columns.
1193 children = table->children;
1196 child = children->data;
1197 children = children->next;
1199 if (GTK_WIDGET_VISIBLE (child->widget))
1201 if (child->left_attach != (child->right_attach - 1))
1203 for (col = child->left_attach; col < child->right_attach; col++)
1204 table->cols[col].empty = FALSE;
1209 for (col = child->left_attach; col < child->right_attach; col++)
1210 if (table->cols[col].expand)
1217 for (col = child->left_attach; col < child->right_attach; col++)
1218 table->cols[col].need_expand = TRUE;
1221 if (!child->xshrink)
1224 for (col = child->left_attach; col < child->right_attach; col++)
1225 if (!table->cols[col].shrink)
1232 for (col = child->left_attach; col < child->right_attach; col++)
1233 table->cols[col].need_shrink = FALSE;
1237 if (child->top_attach != (child->bottom_attach - 1))
1239 for (row = child->top_attach; row < child->bottom_attach; row++)
1240 table->rows[row].empty = FALSE;
1245 for (row = child->top_attach; row < child->bottom_attach; row++)
1246 if (table->rows[row].expand)
1253 for (row = child->top_attach; row < child->bottom_attach; row++)
1254 table->rows[row].need_expand = TRUE;
1257 if (!child->yshrink)
1260 for (row = child->top_attach; row < child->bottom_attach; row++)
1261 if (!table->rows[row].shrink)
1268 for (row = child->top_attach; row < child->bottom_attach; row++)
1269 table->rows[row].need_shrink = FALSE;
1275 /* Loop over the columns and set the expand and shrink values
1276 * if the column can be expanded or shrunk.
1278 for (col = 0; col < table->ncols; col++)
1280 if (table->cols[col].empty)
1282 table->cols[col].expand = FALSE;
1283 table->cols[col].shrink = FALSE;
1287 if (table->cols[col].need_expand)
1288 table->cols[col].expand = TRUE;
1289 if (!table->cols[col].need_shrink)
1290 table->cols[col].shrink = FALSE;
1294 /* Loop over the rows and set the expand and shrink values
1295 * if the row can be expanded or shrunk.
1297 for (row = 0; row < table->nrows; row++)
1299 if (table->rows[row].empty)
1301 table->rows[row].expand = FALSE;
1302 table->rows[row].shrink = FALSE;
1306 if (table->rows[row].need_expand)
1307 table->rows[row].expand = TRUE;
1308 if (!table->rows[row].need_shrink)
1309 table->rows[row].shrink = FALSE;
1315 gtk_table_size_allocate_pass1 (GtkTable *table)
1325 /* If we were allocated more space than we requested
1326 * then we have to expand any expandable rows and columns
1327 * to fill in the extra space.
1330 real_width = GTK_WIDGET (table)->allocation.width - GTK_CONTAINER (table)->border_width * 2;
1331 real_height = GTK_WIDGET (table)->allocation.height - GTK_CONTAINER (table)->border_width * 2;
1333 if (table->homogeneous)
1336 for (col = 0; col < table->ncols; col++)
1337 if (table->cols[col].expand)
1347 for (col = 0; col + 1 < table->ncols; col++)
1348 width -= table->cols[col].spacing;
1350 for (col = 0; col < table->ncols; col++)
1352 extra = width / (table->ncols - col);
1353 table->cols[col].allocation = MAX (1, extra);
1364 for (col = 0; col < table->ncols; col++)
1366 width += table->cols[col].requisition;
1367 if (table->cols[col].expand)
1369 if (table->cols[col].shrink)
1372 for (col = 0; col + 1 < table->ncols; col++)
1373 width += table->cols[col].spacing;
1375 /* Check to see if we were allocated more width than we requested.
1377 if ((width < real_width) && (nexpand >= 1))
1379 width = real_width - width;
1381 for (col = 0; col < table->ncols; col++)
1382 if (table->cols[col].expand)
1384 extra = width / nexpand;
1385 table->cols[col].allocation += extra;
1392 /* Check to see if we were allocated less width than we requested,
1393 * then shrink until we fit the size give.
1395 if (width > real_width)
1397 gint total_nshrink = nshrink;
1399 extra = width - real_width;
1400 while (total_nshrink > 0 && extra > 0)
1402 nshrink = total_nshrink;
1403 for (col = 0; col < table->ncols; col++)
1404 if (table->cols[col].shrink)
1406 gint allocation = table->cols[col].allocation;
1408 table->cols[col].allocation = MAX (1, (gint) table->cols[col].allocation - extra / nshrink);
1409 extra -= allocation - table->cols[col].allocation;
1411 if (table->cols[col].allocation < 2)
1414 table->cols[col].shrink = FALSE;
1421 if (table->homogeneous)
1424 for (row = 0; row < table->nrows; row++)
1425 if (table->rows[row].expand)
1433 height = real_height;
1435 for (row = 0; row + 1 < table->nrows; row++)
1436 height -= table->rows[row].spacing;
1439 for (row = 0; row < table->nrows; row++)
1441 extra = height / (table->nrows - row);
1442 table->rows[row].allocation = MAX (1, extra);
1453 for (row = 0; row < table->nrows; row++)
1455 height += table->rows[row].requisition;
1456 if (table->rows[row].expand)
1458 if (table->rows[row].shrink)
1461 for (row = 0; row + 1 < table->nrows; row++)
1462 height += table->rows[row].spacing;
1464 /* Check to see if we were allocated more height than we requested.
1466 if ((height < real_height) && (nexpand >= 1))
1468 height = real_height - height;
1470 for (row = 0; row < table->nrows; row++)
1471 if (table->rows[row].expand)
1473 extra = height / nexpand;
1474 table->rows[row].allocation += extra;
1481 /* Check to see if we were allocated less height than we requested.
1482 * then shrink until we fit the size give.
1484 if (height > real_height)
1486 gint total_nshrink = nshrink;
1488 extra = height - real_height;
1489 while (total_nshrink > 0 && extra > 0)
1491 nshrink = total_nshrink;
1492 for (row = 0; row < table->nrows; row++)
1493 if (table->rows[row].shrink)
1495 gint allocation = table->rows[row].allocation;
1497 table->rows[row].allocation = MAX (1, (gint) table->rows[row].allocation - extra / nshrink);
1498 extra -= allocation - table->rows[row].allocation;
1500 if (table->rows[row].allocation < 2)
1503 table->rows[row].shrink = FALSE;
1512 gtk_table_size_allocate_pass2 (GtkTable *table)
1514 GtkTableChild *child;
1520 GtkAllocation allocation;
1521 GtkWidget *widget = GTK_WIDGET (table);
1523 children = table->children;
1526 child = children->data;
1527 children = children->next;
1529 if (GTK_WIDGET_VISIBLE (child->widget))
1531 GtkRequisition child_requisition;
1532 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1534 x = GTK_WIDGET (table)->allocation.x + GTK_CONTAINER (table)->border_width;
1535 y = GTK_WIDGET (table)->allocation.y + GTK_CONTAINER (table)->border_width;
1539 for (col = 0; col < child->left_attach; col++)
1541 x += table->cols[col].allocation;
1542 x += table->cols[col].spacing;
1545 for (col = child->left_attach; col < child->right_attach; col++)
1547 max_width += table->cols[col].allocation;
1548 if ((col + 1) < child->right_attach)
1549 max_width += table->cols[col].spacing;
1552 for (row = 0; row < child->top_attach; row++)
1554 y += table->rows[row].allocation;
1555 y += table->rows[row].spacing;
1558 for (row = child->top_attach; row < child->bottom_attach; row++)
1560 max_height += table->rows[row].allocation;
1561 if ((row + 1) < child->bottom_attach)
1562 max_height += table->rows[row].spacing;
1567 allocation.width = MAX (1, max_width - (gint)child->xpadding * 2);
1568 allocation.x = x + (max_width - allocation.width) / 2;
1572 allocation.width = child_requisition.width;
1573 allocation.x = x + (max_width - allocation.width) / 2;
1578 allocation.height = MAX (1, max_height - (gint)child->ypadding * 2);
1579 allocation.y = y + (max_height - allocation.height) / 2;
1583 allocation.height = child_requisition.height;
1584 allocation.y = y + (max_height - allocation.height) / 2;
1587 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1588 allocation.x = widget->allocation.x + widget->allocation.width
1589 - (allocation.x - widget->allocation.x) - allocation.width;
1591 gtk_widget_size_allocate (child->widget, &allocation);