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 GType 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 GType table_type = 0;
110 static const GTypeInfo table_info =
112 sizeof (GtkTableClass),
115 (GClassInitFunc) gtk_table_class_init,
120 (GInstanceInitFunc) gtk_table_init,
123 table_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkTable",
131 gtk_table_class_init (GtkTableClass *class)
133 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
134 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
135 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
137 parent_class = g_type_class_peek_parent (class);
139 gobject_class->finalize = gtk_table_finalize;
141 gobject_class->get_property = gtk_table_get_property;
142 gobject_class->set_property = gtk_table_set_property;
144 widget_class->size_request = gtk_table_size_request;
145 widget_class->size_allocate = gtk_table_size_allocate;
147 container_class->add = gtk_table_add;
148 container_class->remove = gtk_table_remove;
149 container_class->forall = gtk_table_forall;
150 container_class->child_type = gtk_table_child_type;
151 container_class->set_child_property = gtk_table_set_child_property;
152 container_class->get_child_property = gtk_table_get_child_property;
155 g_object_class_install_property (gobject_class,
157 g_param_spec_uint ("n_rows",
159 _("The number of rows in the table"),
164 g_object_class_install_property (gobject_class,
166 g_param_spec_uint ("n_columns",
168 _("The number of columns in the table"),
173 g_object_class_install_property (gobject_class,
175 g_param_spec_uint ("row_spacing",
177 _("The amount of space between two consecutive rows"),
182 g_object_class_install_property (gobject_class,
184 g_param_spec_uint ("column_spacing",
186 _("The amount of space between two consecutive columns"),
191 g_object_class_install_property (gobject_class,
193 g_param_spec_boolean ("homogeneous",
195 _("If TRUE this means the table cells are all the same width/height"),
199 gtk_container_class_install_child_property (container_class,
200 CHILD_PROP_LEFT_ATTACH,
201 g_param_spec_uint ("left_attach",
202 _("Left attachment"),
203 _("The column number to attach the left side of the child to"),
206 gtk_container_class_install_child_property (container_class,
207 CHILD_PROP_RIGHT_ATTACH,
208 g_param_spec_uint ("right_attach",
209 _("Right attachment"),
210 _("the column number to attach the right side of a child widget to"),
213 gtk_container_class_install_child_property (container_class,
214 CHILD_PROP_TOP_ATTACH,
215 g_param_spec_uint ("top_attach",
217 _("The row number to attach the top of a child widget to"),
220 gtk_container_class_install_child_property (container_class,
221 CHILD_PROP_BOTTOM_ATTACH,
222 g_param_spec_uint ("bottom_attach",
223 _("Bottom attachment"),
224 _("The row number to attach the bottom of the child to"),
227 gtk_container_class_install_child_property (container_class,
228 CHILD_PROP_X_OPTIONS,
229 g_param_spec_flags ("x_options",
230 _("Horizontal options"),
231 _("Options specifying the horizontal behaviour of the child"),
232 GTK_TYPE_ATTACH_OPTIONS, GTK_EXPAND | GTK_FILL,
234 gtk_container_class_install_child_property (container_class,
235 CHILD_PROP_Y_OPTIONS,
236 g_param_spec_flags ("y_options",
237 _("Vertical options"),
238 _("Options specifying the vertical behaviour of the child"),
239 GTK_TYPE_ATTACH_OPTIONS, GTK_EXPAND | GTK_FILL,
241 gtk_container_class_install_child_property (container_class,
242 CHILD_PROP_X_PADDING,
243 g_param_spec_uint ("x_padding",
244 _("Horizontal padding"),
245 _("Extra space to put between the child and its left and right neighbors, in pixels"),
248 gtk_container_class_install_child_property (container_class,
249 CHILD_PROP_Y_PADDING,
250 g_param_spec_uint ("y_padding",
251 _("Vertical padding"),
252 _("Extra space to put between the child and its upper and lower neighbors, in pixels"),
258 gtk_table_child_type (GtkContainer *container)
260 return GTK_TYPE_WIDGET;
264 gtk_table_get_property (GObject *object,
271 table = GTK_TABLE (object);
276 g_value_set_uint (value, table->nrows);
279 g_value_set_uint (value, table->ncols);
281 case PROP_ROW_SPACING:
282 g_value_set_uint (value, table->row_spacing);
284 case PROP_COLUMN_SPACING:
285 g_value_set_uint (value, table->column_spacing);
287 case PROP_HOMOGENEOUS:
288 g_value_set_boolean (value, table->homogeneous);
291 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
297 gtk_table_set_property (GObject *object,
304 table = GTK_TABLE (object);
309 gtk_table_resize (table, g_value_get_uint (value), table->ncols);
312 gtk_table_resize (table, table->nrows, g_value_get_uint (value));
314 case PROP_ROW_SPACING:
315 gtk_table_set_row_spacings (table, g_value_get_uint (value));
317 case PROP_COLUMN_SPACING:
318 gtk_table_set_col_spacings (table, g_value_get_uint (value));
320 case PROP_HOMOGENEOUS:
321 gtk_table_set_homogeneous (table, g_value_get_boolean (value));
324 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
330 gtk_table_set_child_property (GtkContainer *container,
336 GtkTable *table = GTK_TABLE (container);
337 GtkTableChild *table_child;
341 for (list = table->children; list; list = list->next)
343 table_child = list->data;
345 if (table_child->widget == child)
350 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
356 case CHILD_PROP_LEFT_ATTACH:
357 table_child->left_attach = g_value_get_uint (value);
358 if (table_child->right_attach <= table_child->left_attach)
359 table_child->right_attach = table_child->left_attach + 1;
360 if (table_child->right_attach >= table->ncols)
361 gtk_table_resize (table, table->nrows, table_child->right_attach);
363 case CHILD_PROP_RIGHT_ATTACH:
364 table_child->right_attach = g_value_get_uint (value);
365 if (table_child->right_attach <= table_child->left_attach)
366 table_child->left_attach = table_child->right_attach - 1;
367 if (table_child->right_attach >= table->ncols)
368 gtk_table_resize (table, table->nrows, table_child->right_attach);
370 case CHILD_PROP_TOP_ATTACH:
371 table_child->top_attach = g_value_get_uint (value);
372 if (table_child->bottom_attach <= table_child->top_attach)
373 table_child->bottom_attach = table_child->top_attach + 1;
374 if (table_child->bottom_attach >= table->nrows)
375 gtk_table_resize (table, table_child->bottom_attach, table->ncols);
377 case CHILD_PROP_BOTTOM_ATTACH:
378 table_child->bottom_attach = g_value_get_uint (value);
379 if (table_child->bottom_attach <= table_child->top_attach)
380 table_child->top_attach = table_child->bottom_attach - 1;
381 if (table_child->bottom_attach >= table->nrows)
382 gtk_table_resize (table, table_child->bottom_attach, table->ncols);
384 case CHILD_PROP_X_OPTIONS:
385 table_child->xexpand = (g_value_get_flags (value) & GTK_EXPAND) != 0;
386 table_child->xshrink = (g_value_get_flags (value) & GTK_SHRINK) != 0;
387 table_child->xfill = (g_value_get_flags (value) & GTK_FILL) != 0;
389 case CHILD_PROP_Y_OPTIONS:
390 table_child->yexpand = (g_value_get_flags (value) & GTK_EXPAND) != 0;
391 table_child->yshrink = (g_value_get_flags (value) & GTK_SHRINK) != 0;
392 table_child->yfill = (g_value_get_flags (value) & GTK_FILL) != 0;
394 case CHILD_PROP_X_PADDING:
395 table_child->xpadding = g_value_get_uint (value);
397 case CHILD_PROP_Y_PADDING:
398 table_child->ypadding = g_value_get_uint (value);
401 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
404 if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (table))
405 gtk_widget_queue_resize (child);
409 gtk_table_get_child_property (GtkContainer *container,
415 GtkTable *table = GTK_TABLE (container);
416 GtkTableChild *table_child;
420 for (list = table->children; list; list = list->next)
422 table_child = list->data;
424 if (table_child->widget == child)
429 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
435 case CHILD_PROP_LEFT_ATTACH:
436 g_value_set_uint (value, table_child->left_attach);
438 case CHILD_PROP_RIGHT_ATTACH:
439 g_value_set_uint (value, table_child->right_attach);
441 case CHILD_PROP_TOP_ATTACH:
442 g_value_set_uint (value, table_child->top_attach);
444 case CHILD_PROP_BOTTOM_ATTACH:
445 g_value_set_uint (value, table_child->bottom_attach);
447 case CHILD_PROP_X_OPTIONS:
448 g_value_set_flags (value, (table_child->xexpand * GTK_EXPAND |
449 table_child->xshrink * GTK_SHRINK |
450 table_child->xfill * GTK_FILL));
452 case CHILD_PROP_Y_OPTIONS:
453 g_value_set_flags (value, (table_child->yexpand * GTK_EXPAND |
454 table_child->yshrink * GTK_SHRINK |
455 table_child->yfill * GTK_FILL));
457 case CHILD_PROP_X_PADDING:
458 g_value_set_uint (value, table_child->xpadding);
460 case CHILD_PROP_Y_PADDING:
461 g_value_set_uint (value, table_child->ypadding);
464 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
470 gtk_table_init (GtkTable *table)
472 GTK_WIDGET_SET_FLAGS (table, GTK_NO_WINDOW);
473 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (table), FALSE);
475 table->children = NULL;
480 table->column_spacing = 0;
481 table->row_spacing = 0;
482 table->homogeneous = FALSE;
484 gtk_table_resize (table, 1, 1);
488 gtk_table_new (guint rows,
490 gboolean homogeneous)
499 table = g_object_new (GTK_TYPE_TABLE, NULL);
501 table->homogeneous = (homogeneous ? TRUE : FALSE);
503 gtk_table_resize (table, rows, columns);
505 return GTK_WIDGET (table);
509 gtk_table_resize (GtkTable *table,
513 g_return_if_fail (GTK_IS_TABLE (table));
514 g_return_if_fail (n_rows > 0 && n_rows < 65536);
515 g_return_if_fail (n_rows > 0 && n_cols < 65536);
517 n_rows = MAX (n_rows, 1);
518 n_cols = MAX (n_cols, 1);
520 if (n_rows != table->nrows ||
521 n_cols != table->ncols)
525 for (list = table->children; list; list = list->next)
527 GtkTableChild *child;
531 n_rows = MAX (n_rows, child->bottom_attach);
532 n_cols = MAX (n_cols, child->right_attach);
535 if (n_rows != table->nrows)
540 table->nrows = n_rows;
541 table->rows = g_realloc (table->rows, table->nrows * sizeof (GtkTableRowCol));
543 for (; i < table->nrows; i++)
545 table->rows[i].requisition = 0;
546 table->rows[i].allocation = 0;
547 table->rows[i].spacing = table->row_spacing;
548 table->rows[i].need_expand = 0;
549 table->rows[i].need_shrink = 0;
550 table->rows[i].expand = 0;
551 table->rows[i].shrink = 0;
554 g_object_notify (G_OBJECT (table), "n_rows");
557 if (n_cols != table->ncols)
562 table->ncols = n_cols;
563 table->cols = g_realloc (table->cols, table->ncols * sizeof (GtkTableRowCol));
565 for (; i < table->ncols; i++)
567 table->cols[i].requisition = 0;
568 table->cols[i].allocation = 0;
569 table->cols[i].spacing = table->column_spacing;
570 table->cols[i].need_expand = 0;
571 table->cols[i].need_shrink = 0;
572 table->cols[i].expand = 0;
573 table->cols[i].shrink = 0;
576 g_object_notify (G_OBJECT (table), "n_columns");
582 gtk_table_attach (GtkTable *table,
588 GtkAttachOptions xoptions,
589 GtkAttachOptions yoptions,
593 GtkTableChild *table_child;
595 g_return_if_fail (GTK_IS_TABLE (table));
596 g_return_if_fail (GTK_IS_WIDGET (child));
597 g_return_if_fail (child->parent == NULL);
599 /* g_return_if_fail (left_attach >= 0); */
600 g_return_if_fail (left_attach < right_attach);
601 /* g_return_if_fail (top_attach >= 0); */
602 g_return_if_fail (top_attach < bottom_attach);
604 if (right_attach >= table->ncols)
605 gtk_table_resize (table, table->nrows, right_attach);
607 if (bottom_attach >= table->nrows)
608 gtk_table_resize (table, bottom_attach, table->ncols);
610 table_child = g_new (GtkTableChild, 1);
611 table_child->widget = child;
612 table_child->left_attach = left_attach;
613 table_child->right_attach = right_attach;
614 table_child->top_attach = top_attach;
615 table_child->bottom_attach = bottom_attach;
616 table_child->xexpand = (xoptions & GTK_EXPAND) != 0;
617 table_child->xshrink = (xoptions & GTK_SHRINK) != 0;
618 table_child->xfill = (xoptions & GTK_FILL) != 0;
619 table_child->xpadding = xpadding;
620 table_child->yexpand = (yoptions & GTK_EXPAND) != 0;
621 table_child->yshrink = (yoptions & GTK_SHRINK) != 0;
622 table_child->yfill = (yoptions & GTK_FILL) != 0;
623 table_child->ypadding = ypadding;
625 table->children = g_list_prepend (table->children, table_child);
627 gtk_widget_set_parent (child, GTK_WIDGET (table));
631 gtk_table_attach_defaults (GtkTable *table,
638 gtk_table_attach (table, widget,
639 left_attach, right_attach,
640 top_attach, bottom_attach,
641 GTK_EXPAND | GTK_FILL,
642 GTK_EXPAND | GTK_FILL,
647 gtk_table_set_row_spacing (GtkTable *table,
651 g_return_if_fail (GTK_IS_TABLE (table));
652 g_return_if_fail (row < table->nrows);
654 if (table->rows[row].spacing != spacing)
656 table->rows[row].spacing = spacing;
658 if (GTK_WIDGET_VISIBLE (table))
659 gtk_widget_queue_resize (GTK_WIDGET (table));
664 * gtk_table_get_row_spacing:
665 * @table: a #GtkTable
666 * @row: a row in the table, 0 indicates the first row
668 * Gets the amount of space between row @row, and
669 * row @row + 1. See gtk_table_set_row_spacing().
671 * Return value: the row spacing
674 gtk_table_get_row_spacing (GtkTable *table,
677 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
678 g_return_val_if_fail (row < table->nrows - 1, 0);
680 return table->rows[row].spacing;
684 gtk_table_set_col_spacing (GtkTable *table,
688 g_return_if_fail (GTK_IS_TABLE (table));
689 g_return_if_fail (column < table->ncols);
691 if (table->cols[column].spacing != spacing)
693 table->cols[column].spacing = spacing;
695 if (GTK_WIDGET_VISIBLE (table))
696 gtk_widget_queue_resize (GTK_WIDGET (table));
701 * gtk_table_get_col_spacing:
702 * @table: a #GtkTable
703 * @column: a column in the table, 0 indicates the first column
705 * Gets the amount of space between column @col, and
706 * column @col + 1. See gtk_table_set_col_spacing().
708 * Return value: the column spacing
711 gtk_table_get_col_spacing (GtkTable *table,
714 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
715 g_return_val_if_fail (column < table->ncols, 0);
717 return table->cols[column].spacing;
721 gtk_table_set_row_spacings (GtkTable *table,
726 g_return_if_fail (GTK_IS_TABLE (table));
728 table->row_spacing = spacing;
729 for (row = 0; row < table->nrows; row++)
730 table->rows[row].spacing = spacing;
732 if (GTK_WIDGET_VISIBLE (table))
733 gtk_widget_queue_resize (GTK_WIDGET (table));
735 g_object_notify (G_OBJECT (table), "row_spacing");
739 * gtk_table_get_default_row_spacing:
740 * @table: a #GtkTable
742 * Gets the default row spacing for the table. This is
743 * the spacing that will be used for newly added rows.
744 * (See gtk_table_set_row_spacings())
746 * Returns value: the default row spacing
749 gtk_table_get_default_row_spacing (GtkTable *table)
751 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
753 return table->row_spacing;
757 gtk_table_set_col_spacings (GtkTable *table,
762 g_return_if_fail (GTK_IS_TABLE (table));
764 table->column_spacing = spacing;
765 for (col = 0; col < table->ncols; col++)
766 table->cols[col].spacing = spacing;
768 if (GTK_WIDGET_VISIBLE (table))
769 gtk_widget_queue_resize (GTK_WIDGET (table));
771 g_object_notify (G_OBJECT (table), "column_spacing");
775 * gtk_table_get_default_col_spacing:
776 * @table: a #GtkTable
778 * Gets the default column spacing for the table. This is
779 * the spacing that will be used for newly added columns.
780 * (See gtk_table_set_col_spacings())
782 * Returns value: the default column spacing
785 gtk_table_get_default_col_spacing (GtkTable *table)
787 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
789 return table->column_spacing;
793 gtk_table_set_homogeneous (GtkTable *table,
794 gboolean homogeneous)
796 g_return_if_fail (GTK_IS_TABLE (table));
798 homogeneous = (homogeneous != 0);
799 if (homogeneous != table->homogeneous)
801 table->homogeneous = homogeneous;
803 if (GTK_WIDGET_VISIBLE (table))
804 gtk_widget_queue_resize (GTK_WIDGET (table));
806 g_object_notify (G_OBJECT (table), "homogeneous");
811 * gtk_table_get_homogeneous:
812 * @table: a #GtkTable
814 * Returns whether the table cells are all constrained to the same
815 * width and height. (See gtk_table_set_homogenous ())
817 * Return value: %TRUE if the cells are all constrained to the same size
820 gtk_table_get_homogeneous (GtkTable *table)
822 g_return_val_if_fail (GTK_IS_TABLE (table), FALSE);
824 return table->homogeneous;
828 gtk_table_finalize (GObject *object)
832 g_return_if_fail (GTK_IS_TABLE (object));
834 table = GTK_TABLE (object);
836 g_free (table->rows);
837 g_free (table->cols);
839 G_OBJECT_CLASS (parent_class)->finalize (object);
843 gtk_table_size_request (GtkWidget *widget,
844 GtkRequisition *requisition)
849 g_return_if_fail (GTK_IS_TABLE (widget));
850 g_return_if_fail (requisition != NULL);
852 table = GTK_TABLE (widget);
854 requisition->width = 0;
855 requisition->height = 0;
857 gtk_table_size_request_init (table);
858 gtk_table_size_request_pass1 (table);
859 gtk_table_size_request_pass2 (table);
860 gtk_table_size_request_pass3 (table);
861 gtk_table_size_request_pass2 (table);
863 for (col = 0; col < table->ncols; col++)
864 requisition->width += table->cols[col].requisition;
865 for (col = 0; col + 1 < table->ncols; col++)
866 requisition->width += table->cols[col].spacing;
868 for (row = 0; row < table->nrows; row++)
869 requisition->height += table->rows[row].requisition;
870 for (row = 0; row + 1 < table->nrows; row++)
871 requisition->height += table->rows[row].spacing;
873 requisition->width += GTK_CONTAINER (table)->border_width * 2;
874 requisition->height += GTK_CONTAINER (table)->border_width * 2;
878 gtk_table_size_allocate (GtkWidget *widget,
879 GtkAllocation *allocation)
883 g_return_if_fail (GTK_IS_TABLE (widget));
884 g_return_if_fail (allocation != NULL);
886 widget->allocation = *allocation;
887 table = GTK_TABLE (widget);
889 gtk_table_size_allocate_init (table);
890 gtk_table_size_allocate_pass1 (table);
891 gtk_table_size_allocate_pass2 (table);
895 gtk_table_add (GtkContainer *container,
898 g_return_if_fail (GTK_IS_TABLE (container));
899 g_return_if_fail (widget != NULL);
901 gtk_table_attach_defaults (GTK_TABLE (container), widget, 0, 1, 0, 1);
905 gtk_table_remove (GtkContainer *container,
909 GtkTableChild *child;
912 g_return_if_fail (GTK_IS_TABLE (container));
913 g_return_if_fail (widget != NULL);
915 table = GTK_TABLE (container);
916 children = table->children;
920 child = children->data;
921 children = children->next;
923 if (child->widget == widget)
925 gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
927 gtk_widget_unparent (widget);
929 table->children = g_list_remove (table->children, child);
932 if (was_visible && GTK_WIDGET_VISIBLE (container))
933 gtk_widget_queue_resize (GTK_WIDGET (container));
940 gtk_table_forall (GtkContainer *container,
941 gboolean include_internals,
942 GtkCallback callback,
943 gpointer callback_data)
946 GtkTableChild *child;
949 g_return_if_fail (GTK_IS_TABLE (container));
950 g_return_if_fail (callback != NULL);
952 table = GTK_TABLE (container);
953 children = table->children;
957 child = children->data;
958 children = children->next;
960 (* callback) (child->widget, callback_data);
965 gtk_table_size_request_init (GtkTable *table)
967 GtkTableChild *child;
971 for (row = 0; row < table->nrows; row++)
973 table->rows[row].requisition = 0;
974 table->rows[row].expand = FALSE;
976 for (col = 0; col < table->ncols; col++)
978 table->cols[col].requisition = 0;
979 table->cols[col].expand = FALSE;
982 children = table->children;
985 child = children->data;
986 children = children->next;
988 if (GTK_WIDGET_VISIBLE (child->widget))
989 gtk_widget_size_request (child->widget, NULL);
991 if (child->left_attach == (child->right_attach - 1) && child->xexpand)
992 table->cols[child->left_attach].expand = TRUE;
994 if (child->top_attach == (child->bottom_attach - 1) && child->yexpand)
995 table->rows[child->top_attach].expand = TRUE;
1000 gtk_table_size_request_pass1 (GtkTable *table)
1002 GtkTableChild *child;
1007 children = table->children;
1010 child = children->data;
1011 children = children->next;
1013 if (GTK_WIDGET_VISIBLE (child->widget))
1015 GtkRequisition child_requisition;
1016 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1018 /* Child spans a single column.
1020 if (child->left_attach == (child->right_attach - 1))
1022 width = child_requisition.width + child->xpadding * 2;
1023 table->cols[child->left_attach].requisition = MAX (table->cols[child->left_attach].requisition, width);
1026 /* Child spans a single row.
1028 if (child->top_attach == (child->bottom_attach - 1))
1030 height = child_requisition.height + child->ypadding * 2;
1031 table->rows[child->top_attach].requisition = MAX (table->rows[child->top_attach].requisition, height);
1038 gtk_table_size_request_pass2 (GtkTable *table)
1044 if (table->homogeneous)
1049 for (col = 0; col < table->ncols; col++)
1050 max_width = MAX (max_width, table->cols[col].requisition);
1051 for (row = 0; row < table->nrows; row++)
1052 max_height = MAX (max_height, table->rows[row].requisition);
1054 for (col = 0; col < table->ncols; col++)
1055 table->cols[col].requisition = max_width;
1056 for (row = 0; row < table->nrows; row++)
1057 table->rows[row].requisition = max_height;
1062 gtk_table_size_request_pass3 (GtkTable *table)
1064 GtkTableChild *child;
1070 children = table->children;
1073 child = children->data;
1074 children = children->next;
1076 if (GTK_WIDGET_VISIBLE (child->widget))
1078 /* Child spans multiple columns.
1080 if (child->left_attach != (child->right_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 (col = child->left_attach; col < child->right_attach; col++)
1092 width += table->cols[col].requisition;
1093 if ((col + 1) < child->right_attach)
1094 width += table->cols[col].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 * columns it spans, favoring expandable columns if any.
1101 if (width < child_requisition.width + child->xpadding * 2)
1104 gboolean force_expand = FALSE;
1106 width = child_requisition.width + child->xpadding * 2 - width;
1108 for (col = child->left_attach; col < child->right_attach; col++)
1109 if (table->cols[col].expand)
1114 n_expand = (child->right_attach - child->left_attach);
1115 force_expand = TRUE;
1118 for (col = child->left_attach; col < child->right_attach; col++)
1119 if (force_expand || table->cols[col].expand)
1121 extra = width / n_expand;
1122 table->cols[col].requisition += extra;
1129 /* Child spans multiple rows.
1131 if (child->top_attach != (child->bottom_attach - 1))
1133 GtkRequisition child_requisition;
1135 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1137 /* Check and see if there is already enough space
1141 for (row = child->top_attach; row < child->bottom_attach; row++)
1143 height += table->rows[row].requisition;
1144 if ((row + 1) < child->bottom_attach)
1145 height += table->rows[row].spacing;
1148 /* If we need to request more space for this child to fill
1149 * its requisition, then divide up the needed space amongst the
1150 * rows it spans, favoring expandable rows if any.
1152 if (height < child_requisition.height + child->ypadding * 2)
1155 gboolean force_expand = FALSE;
1157 height = child_requisition.height + child->ypadding * 2 - height;
1159 for (row = child->top_attach; row < child->bottom_attach; row++)
1161 if (table->rows[row].expand)
1167 n_expand = (child->bottom_attach - child->top_attach);
1168 force_expand = TRUE;
1171 for (row = child->top_attach; row < child->bottom_attach; row++)
1172 if (force_expand || table->rows[row].expand)
1174 extra = height / n_expand;
1175 table->rows[row].requisition += extra;
1186 gtk_table_size_allocate_init (GtkTable *table)
1188 GtkTableChild *child;
1194 /* Initialize the rows and cols.
1195 * By default, rows and cols do not expand and do shrink.
1196 * Those values are modified by the children that occupy
1197 * the rows and cols.
1199 for (col = 0; col < table->ncols; col++)
1201 table->cols[col].allocation = table->cols[col].requisition;
1202 table->cols[col].need_expand = FALSE;
1203 table->cols[col].need_shrink = TRUE;
1204 table->cols[col].expand = FALSE;
1205 table->cols[col].shrink = TRUE;
1206 table->cols[col].empty = TRUE;
1208 for (row = 0; row < table->nrows; row++)
1210 table->rows[row].allocation = table->rows[row].requisition;
1211 table->rows[row].need_expand = FALSE;
1212 table->rows[row].need_shrink = TRUE;
1213 table->rows[row].expand = FALSE;
1214 table->rows[row].shrink = TRUE;
1215 table->rows[row].empty = TRUE;
1218 /* Loop over all the children and adjust the row and col values
1219 * based on whether the children want to be allowed to expand
1220 * or shrink. This loop handles children that occupy a single
1223 children = table->children;
1226 child = children->data;
1227 children = children->next;
1229 if (GTK_WIDGET_VISIBLE (child->widget))
1231 if (child->left_attach == (child->right_attach - 1))
1234 table->cols[child->left_attach].expand = TRUE;
1236 if (!child->xshrink)
1237 table->cols[child->left_attach].shrink = FALSE;
1239 table->cols[child->left_attach].empty = FALSE;
1242 if (child->top_attach == (child->bottom_attach - 1))
1245 table->rows[child->top_attach].expand = TRUE;
1247 if (!child->yshrink)
1248 table->rows[child->top_attach].shrink = FALSE;
1250 table->rows[child->top_attach].empty = FALSE;
1255 /* Loop over all the children again and this time handle children
1256 * which span multiple rows or columns.
1258 children = table->children;
1261 child = children->data;
1262 children = children->next;
1264 if (GTK_WIDGET_VISIBLE (child->widget))
1266 if (child->left_attach != (child->right_attach - 1))
1268 for (col = child->left_attach; col < child->right_attach; col++)
1269 table->cols[col].empty = FALSE;
1274 for (col = child->left_attach; col < child->right_attach; col++)
1275 if (table->cols[col].expand)
1282 for (col = child->left_attach; col < child->right_attach; col++)
1283 table->cols[col].need_expand = TRUE;
1286 if (!child->xshrink)
1289 for (col = child->left_attach; col < child->right_attach; col++)
1290 if (!table->cols[col].shrink)
1297 for (col = child->left_attach; col < child->right_attach; col++)
1298 table->cols[col].need_shrink = FALSE;
1302 if (child->top_attach != (child->bottom_attach - 1))
1304 for (row = child->top_attach; row < child->bottom_attach; row++)
1305 table->rows[row].empty = FALSE;
1310 for (row = child->top_attach; row < child->bottom_attach; row++)
1311 if (table->rows[row].expand)
1318 for (row = child->top_attach; row < child->bottom_attach; row++)
1319 table->rows[row].need_expand = TRUE;
1322 if (!child->yshrink)
1325 for (row = child->top_attach; row < child->bottom_attach; row++)
1326 if (!table->rows[row].shrink)
1333 for (row = child->top_attach; row < child->bottom_attach; row++)
1334 table->rows[row].need_shrink = FALSE;
1340 /* Loop over the columns and set the expand and shrink values
1341 * if the column can be expanded or shrunk.
1343 for (col = 0; col < table->ncols; col++)
1345 if (table->cols[col].empty)
1347 table->cols[col].expand = FALSE;
1348 table->cols[col].shrink = FALSE;
1352 if (table->cols[col].need_expand)
1353 table->cols[col].expand = TRUE;
1354 if (!table->cols[col].need_shrink)
1355 table->cols[col].shrink = FALSE;
1359 /* Loop over the rows and set the expand and shrink values
1360 * if the row can be expanded or shrunk.
1362 for (row = 0; row < table->nrows; row++)
1364 if (table->rows[row].empty)
1366 table->rows[row].expand = FALSE;
1367 table->rows[row].shrink = FALSE;
1371 if (table->rows[row].need_expand)
1372 table->rows[row].expand = TRUE;
1373 if (!table->rows[row].need_shrink)
1374 table->rows[row].shrink = FALSE;
1380 gtk_table_size_allocate_pass1 (GtkTable *table)
1390 /* If we were allocated more space than we requested
1391 * then we have to expand any expandable rows and columns
1392 * to fill in the extra space.
1395 real_width = GTK_WIDGET (table)->allocation.width - GTK_CONTAINER (table)->border_width * 2;
1396 real_height = GTK_WIDGET (table)->allocation.height - GTK_CONTAINER (table)->border_width * 2;
1398 if (table->homogeneous)
1400 if (!table->children)
1405 for (col = 0; col < table->ncols; col++)
1406 if (table->cols[col].expand)
1415 for (col = 0; col + 1 < table->ncols; col++)
1416 width -= table->cols[col].spacing;
1418 for (col = 0; col < table->ncols; col++)
1420 extra = width / (table->ncols - col);
1421 table->cols[col].allocation = MAX (1, extra);
1432 for (col = 0; col < table->ncols; col++)
1434 width += table->cols[col].requisition;
1435 if (table->cols[col].expand)
1437 if (table->cols[col].shrink)
1440 for (col = 0; col + 1 < table->ncols; col++)
1441 width += table->cols[col].spacing;
1443 /* Check to see if we were allocated more width than we requested.
1445 if ((width < real_width) && (nexpand >= 1))
1447 width = real_width - width;
1449 for (col = 0; col < table->ncols; col++)
1450 if (table->cols[col].expand)
1452 extra = width / nexpand;
1453 table->cols[col].allocation += extra;
1460 /* Check to see if we were allocated less width than we requested,
1461 * then shrink until we fit the size give.
1463 if (width > real_width)
1465 gint total_nshrink = nshrink;
1467 extra = width - real_width;
1468 while (total_nshrink > 0 && extra > 0)
1470 nshrink = total_nshrink;
1471 for (col = 0; col < table->ncols; col++)
1472 if (table->cols[col].shrink)
1474 gint allocation = table->cols[col].allocation;
1476 table->cols[col].allocation = MAX (1, (gint) table->cols[col].allocation - extra / nshrink);
1477 extra -= allocation - table->cols[col].allocation;
1479 if (table->cols[col].allocation < 2)
1482 table->cols[col].shrink = FALSE;
1489 if (table->homogeneous)
1491 if (!table->children)
1496 for (row = 0; row < table->nrows; row++)
1497 if (table->rows[row].expand)
1505 height = real_height;
1507 for (row = 0; row + 1 < table->nrows; row++)
1508 height -= table->rows[row].spacing;
1511 for (row = 0; row < table->nrows; row++)
1513 extra = height / (table->nrows - row);
1514 table->rows[row].allocation = MAX (1, extra);
1525 for (row = 0; row < table->nrows; row++)
1527 height += table->rows[row].requisition;
1528 if (table->rows[row].expand)
1530 if (table->rows[row].shrink)
1533 for (row = 0; row + 1 < table->nrows; row++)
1534 height += table->rows[row].spacing;
1536 /* Check to see if we were allocated more height than we requested.
1538 if ((height < real_height) && (nexpand >= 1))
1540 height = real_height - height;
1542 for (row = 0; row < table->nrows; row++)
1543 if (table->rows[row].expand)
1545 extra = height / nexpand;
1546 table->rows[row].allocation += extra;
1553 /* Check to see if we were allocated less height than we requested.
1554 * then shrink until we fit the size give.
1556 if (height > real_height)
1558 gint total_nshrink = nshrink;
1560 extra = height - real_height;
1561 while (total_nshrink > 0 && extra > 0)
1563 nshrink = total_nshrink;
1564 for (row = 0; row < table->nrows; row++)
1565 if (table->rows[row].shrink)
1567 gint allocation = table->rows[row].allocation;
1569 table->rows[row].allocation = MAX (1, (gint) table->rows[row].allocation - extra / nshrink);
1570 extra -= allocation - table->rows[row].allocation;
1572 if (table->rows[row].allocation < 2)
1575 table->rows[row].shrink = FALSE;
1584 gtk_table_size_allocate_pass2 (GtkTable *table)
1586 GtkTableChild *child;
1592 GtkAllocation allocation;
1593 GtkWidget *widget = GTK_WIDGET (table);
1595 children = table->children;
1598 child = children->data;
1599 children = children->next;
1601 if (GTK_WIDGET_VISIBLE (child->widget))
1603 GtkRequisition child_requisition;
1604 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1606 x = GTK_WIDGET (table)->allocation.x + GTK_CONTAINER (table)->border_width;
1607 y = GTK_WIDGET (table)->allocation.y + GTK_CONTAINER (table)->border_width;
1611 for (col = 0; col < child->left_attach; col++)
1613 x += table->cols[col].allocation;
1614 x += table->cols[col].spacing;
1617 for (col = child->left_attach; col < child->right_attach; col++)
1619 max_width += table->cols[col].allocation;
1620 if ((col + 1) < child->right_attach)
1621 max_width += table->cols[col].spacing;
1624 for (row = 0; row < child->top_attach; row++)
1626 y += table->rows[row].allocation;
1627 y += table->rows[row].spacing;
1630 for (row = child->top_attach; row < child->bottom_attach; row++)
1632 max_height += table->rows[row].allocation;
1633 if ((row + 1) < child->bottom_attach)
1634 max_height += table->rows[row].spacing;
1639 allocation.width = MAX (1, max_width - (gint)child->xpadding * 2);
1640 allocation.x = x + (max_width - allocation.width) / 2;
1644 allocation.width = child_requisition.width;
1645 allocation.x = x + (max_width - allocation.width) / 2;
1650 allocation.height = MAX (1, max_height - (gint)child->ypadding * 2);
1651 allocation.y = y + (max_height - allocation.height) / 2;
1655 allocation.height = child_requisition.height;
1656 allocation.y = y + (max_height - allocation.height) / 2;
1659 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1660 allocation.x = widget->allocation.x + widget->allocation.width
1661 - (allocation.x - widget->allocation.x) - allocation.width;
1663 gtk_widget_size_allocate (child->widget, &allocation);