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/.
45 CHILD_PROP_LEFT_ATTACH,
46 CHILD_PROP_RIGHT_ATTACH,
47 CHILD_PROP_TOP_ATTACH,
48 CHILD_PROP_BOTTOM_ATTACH,
56 static void gtk_table_class_init (GtkTableClass *klass);
57 static void gtk_table_init (GtkTable *table);
58 static void gtk_table_finalize (GObject *object);
59 static void gtk_table_size_request (GtkWidget *widget,
60 GtkRequisition *requisition);
61 static void gtk_table_size_allocate (GtkWidget *widget,
62 GtkAllocation *allocation);
63 static void gtk_table_add (GtkContainer *container,
65 static void gtk_table_remove (GtkContainer *container,
67 static void gtk_table_forall (GtkContainer *container,
68 gboolean include_internals,
70 gpointer callback_data);
71 static void gtk_table_get_property (GObject *object,
75 static void gtk_table_set_property (GObject *object,
79 static void gtk_table_set_child_property (GtkContainer *container,
84 static void gtk_table_get_child_property (GtkContainer *container,
89 static GType gtk_table_child_type (GtkContainer *container);
92 static void gtk_table_size_request_init (GtkTable *table);
93 static void gtk_table_size_request_pass1 (GtkTable *table);
94 static void gtk_table_size_request_pass2 (GtkTable *table);
95 static void gtk_table_size_request_pass3 (GtkTable *table);
97 static void gtk_table_size_allocate_init (GtkTable *table);
98 static void gtk_table_size_allocate_pass1 (GtkTable *table);
99 static void gtk_table_size_allocate_pass2 (GtkTable *table);
102 static GtkContainerClass *parent_class = NULL;
106 gtk_table_get_type (void)
108 static GType table_type = 0;
112 static const GTypeInfo table_info =
114 sizeof (GtkTableClass),
117 (GClassInitFunc) gtk_table_class_init,
122 (GInstanceInitFunc) gtk_table_init,
125 table_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkTable",
133 gtk_table_class_init (GtkTableClass *class)
135 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
136 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
137 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
139 parent_class = g_type_class_peek_parent (class);
141 gobject_class->finalize = gtk_table_finalize;
143 gobject_class->get_property = gtk_table_get_property;
144 gobject_class->set_property = gtk_table_set_property;
146 widget_class->size_request = gtk_table_size_request;
147 widget_class->size_allocate = gtk_table_size_allocate;
149 container_class->add = gtk_table_add;
150 container_class->remove = gtk_table_remove;
151 container_class->forall = gtk_table_forall;
152 container_class->child_type = gtk_table_child_type;
153 container_class->set_child_property = gtk_table_set_child_property;
154 container_class->get_child_property = gtk_table_get_child_property;
157 g_object_class_install_property (gobject_class,
159 g_param_spec_uint ("n-rows",
161 P_("The number of rows in the table"),
166 g_object_class_install_property (gobject_class,
168 g_param_spec_uint ("n-columns",
170 P_("The number of columns in the table"),
175 g_object_class_install_property (gobject_class,
177 g_param_spec_uint ("row-spacing",
179 P_("The amount of space between two consecutive rows"),
184 g_object_class_install_property (gobject_class,
186 g_param_spec_uint ("column-spacing",
187 P_("Column spacing"),
188 P_("The amount of space between two consecutive columns"),
193 g_object_class_install_property (gobject_class,
195 g_param_spec_boolean ("homogeneous",
197 P_("If TRUE this means the table cells are all the same width/height"),
201 gtk_container_class_install_child_property (container_class,
202 CHILD_PROP_LEFT_ATTACH,
203 g_param_spec_uint ("left-attach",
204 P_("Left attachment"),
205 P_("The column number to attach the left side of the child to"),
208 gtk_container_class_install_child_property (container_class,
209 CHILD_PROP_RIGHT_ATTACH,
210 g_param_spec_uint ("right-attach",
211 P_("Right attachment"),
212 P_("The column number to attach the right side of a child widget to"),
215 gtk_container_class_install_child_property (container_class,
216 CHILD_PROP_TOP_ATTACH,
217 g_param_spec_uint ("top-attach",
218 P_("Top attachment"),
219 P_("The row number to attach the top of a child widget to"),
222 gtk_container_class_install_child_property (container_class,
223 CHILD_PROP_BOTTOM_ATTACH,
224 g_param_spec_uint ("bottom-attach",
225 P_("Bottom attachment"),
226 P_("The row number to attach the bottom of the child to"),
229 gtk_container_class_install_child_property (container_class,
230 CHILD_PROP_X_OPTIONS,
231 g_param_spec_flags ("x-options",
232 P_("Horizontal options"),
233 P_("Options specifying the horizontal behaviour of the child"),
234 GTK_TYPE_ATTACH_OPTIONS, GTK_EXPAND | GTK_FILL,
236 gtk_container_class_install_child_property (container_class,
237 CHILD_PROP_Y_OPTIONS,
238 g_param_spec_flags ("y-options",
239 P_("Vertical options"),
240 P_("Options specifying the vertical behaviour of the child"),
241 GTK_TYPE_ATTACH_OPTIONS, GTK_EXPAND | GTK_FILL,
243 gtk_container_class_install_child_property (container_class,
244 CHILD_PROP_X_PADDING,
245 g_param_spec_uint ("x-padding",
246 P_("Horizontal padding"),
247 P_("Extra space to put between the child and its left and right neighbors, in pixels"),
250 gtk_container_class_install_child_property (container_class,
251 CHILD_PROP_Y_PADDING,
252 g_param_spec_uint ("y-padding",
253 P_("Vertical padding"),
254 P_("Extra space to put between the child and its upper and lower neighbors, in pixels"),
260 gtk_table_child_type (GtkContainer *container)
262 return GTK_TYPE_WIDGET;
266 gtk_table_get_property (GObject *object,
273 table = GTK_TABLE (object);
278 g_value_set_uint (value, table->nrows);
281 g_value_set_uint (value, table->ncols);
283 case PROP_ROW_SPACING:
284 g_value_set_uint (value, table->row_spacing);
286 case PROP_COLUMN_SPACING:
287 g_value_set_uint (value, table->column_spacing);
289 case PROP_HOMOGENEOUS:
290 g_value_set_boolean (value, table->homogeneous);
293 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
299 gtk_table_set_property (GObject *object,
306 table = GTK_TABLE (object);
311 gtk_table_resize (table, g_value_get_uint (value), table->ncols);
314 gtk_table_resize (table, table->nrows, g_value_get_uint (value));
316 case PROP_ROW_SPACING:
317 gtk_table_set_row_spacings (table, g_value_get_uint (value));
319 case PROP_COLUMN_SPACING:
320 gtk_table_set_col_spacings (table, g_value_get_uint (value));
322 case PROP_HOMOGENEOUS:
323 gtk_table_set_homogeneous (table, g_value_get_boolean (value));
326 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
332 gtk_table_set_child_property (GtkContainer *container,
338 GtkTable *table = GTK_TABLE (container);
339 GtkTableChild *table_child;
343 for (list = table->children; list; list = list->next)
345 table_child = list->data;
347 if (table_child->widget == child)
352 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
358 case CHILD_PROP_LEFT_ATTACH:
359 table_child->left_attach = g_value_get_uint (value);
360 if (table_child->right_attach <= table_child->left_attach)
361 table_child->right_attach = table_child->left_attach + 1;
362 if (table_child->right_attach >= table->ncols)
363 gtk_table_resize (table, table->nrows, table_child->right_attach);
365 case CHILD_PROP_RIGHT_ATTACH:
366 table_child->right_attach = g_value_get_uint (value);
367 if (table_child->right_attach <= table_child->left_attach)
368 table_child->left_attach = table_child->right_attach - 1;
369 if (table_child->right_attach >= table->ncols)
370 gtk_table_resize (table, table->nrows, table_child->right_attach);
372 case CHILD_PROP_TOP_ATTACH:
373 table_child->top_attach = g_value_get_uint (value);
374 if (table_child->bottom_attach <= table_child->top_attach)
375 table_child->bottom_attach = table_child->top_attach + 1;
376 if (table_child->bottom_attach >= table->nrows)
377 gtk_table_resize (table, table_child->bottom_attach, table->ncols);
379 case CHILD_PROP_BOTTOM_ATTACH:
380 table_child->bottom_attach = g_value_get_uint (value);
381 if (table_child->bottom_attach <= table_child->top_attach)
382 table_child->top_attach = table_child->bottom_attach - 1;
383 if (table_child->bottom_attach >= table->nrows)
384 gtk_table_resize (table, table_child->bottom_attach, table->ncols);
386 case CHILD_PROP_X_OPTIONS:
387 table_child->xexpand = (g_value_get_flags (value) & GTK_EXPAND) != 0;
388 table_child->xshrink = (g_value_get_flags (value) & GTK_SHRINK) != 0;
389 table_child->xfill = (g_value_get_flags (value) & GTK_FILL) != 0;
391 case CHILD_PROP_Y_OPTIONS:
392 table_child->yexpand = (g_value_get_flags (value) & GTK_EXPAND) != 0;
393 table_child->yshrink = (g_value_get_flags (value) & GTK_SHRINK) != 0;
394 table_child->yfill = (g_value_get_flags (value) & GTK_FILL) != 0;
396 case CHILD_PROP_X_PADDING:
397 table_child->xpadding = g_value_get_uint (value);
399 case CHILD_PROP_Y_PADDING:
400 table_child->ypadding = g_value_get_uint (value);
403 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
406 if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (table))
407 gtk_widget_queue_resize (child);
411 gtk_table_get_child_property (GtkContainer *container,
417 GtkTable *table = GTK_TABLE (container);
418 GtkTableChild *table_child;
422 for (list = table->children; list; list = list->next)
424 table_child = list->data;
426 if (table_child->widget == child)
431 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
437 case CHILD_PROP_LEFT_ATTACH:
438 g_value_set_uint (value, table_child->left_attach);
440 case CHILD_PROP_RIGHT_ATTACH:
441 g_value_set_uint (value, table_child->right_attach);
443 case CHILD_PROP_TOP_ATTACH:
444 g_value_set_uint (value, table_child->top_attach);
446 case CHILD_PROP_BOTTOM_ATTACH:
447 g_value_set_uint (value, table_child->bottom_attach);
449 case CHILD_PROP_X_OPTIONS:
450 g_value_set_flags (value, (table_child->xexpand * GTK_EXPAND |
451 table_child->xshrink * GTK_SHRINK |
452 table_child->xfill * GTK_FILL));
454 case CHILD_PROP_Y_OPTIONS:
455 g_value_set_flags (value, (table_child->yexpand * GTK_EXPAND |
456 table_child->yshrink * GTK_SHRINK |
457 table_child->yfill * GTK_FILL));
459 case CHILD_PROP_X_PADDING:
460 g_value_set_uint (value, table_child->xpadding);
462 case CHILD_PROP_Y_PADDING:
463 g_value_set_uint (value, table_child->ypadding);
466 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
472 gtk_table_init (GtkTable *table)
474 GTK_WIDGET_SET_FLAGS (table, GTK_NO_WINDOW);
475 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (table), FALSE);
477 table->children = NULL;
482 table->column_spacing = 0;
483 table->row_spacing = 0;
484 table->homogeneous = FALSE;
486 gtk_table_resize (table, 1, 1);
490 gtk_table_new (guint rows,
492 gboolean homogeneous)
501 table = g_object_new (GTK_TYPE_TABLE, NULL);
503 table->homogeneous = (homogeneous ? TRUE : FALSE);
505 gtk_table_resize (table, rows, columns);
507 return GTK_WIDGET (table);
511 gtk_table_resize (GtkTable *table,
515 g_return_if_fail (GTK_IS_TABLE (table));
516 g_return_if_fail (n_rows > 0 && n_rows < 65536);
517 g_return_if_fail (n_cols > 0 && n_cols < 65536);
519 n_rows = MAX (n_rows, 1);
520 n_cols = MAX (n_cols, 1);
522 if (n_rows != table->nrows ||
523 n_cols != table->ncols)
527 for (list = table->children; list; list = list->next)
529 GtkTableChild *child;
533 n_rows = MAX (n_rows, child->bottom_attach);
534 n_cols = MAX (n_cols, child->right_attach);
537 if (n_rows != table->nrows)
542 table->nrows = n_rows;
543 table->rows = g_realloc (table->rows, table->nrows * sizeof (GtkTableRowCol));
545 for (; i < table->nrows; i++)
547 table->rows[i].requisition = 0;
548 table->rows[i].allocation = 0;
549 table->rows[i].spacing = table->row_spacing;
550 table->rows[i].need_expand = 0;
551 table->rows[i].need_shrink = 0;
552 table->rows[i].expand = 0;
553 table->rows[i].shrink = 0;
556 g_object_notify (G_OBJECT (table), "n_rows");
559 if (n_cols != table->ncols)
564 table->ncols = n_cols;
565 table->cols = g_realloc (table->cols, table->ncols * sizeof (GtkTableRowCol));
567 for (; i < table->ncols; i++)
569 table->cols[i].requisition = 0;
570 table->cols[i].allocation = 0;
571 table->cols[i].spacing = table->column_spacing;
572 table->cols[i].need_expand = 0;
573 table->cols[i].need_shrink = 0;
574 table->cols[i].expand = 0;
575 table->cols[i].shrink = 0;
578 g_object_notify (G_OBJECT (table), "n_columns");
584 gtk_table_attach (GtkTable *table,
590 GtkAttachOptions xoptions,
591 GtkAttachOptions yoptions,
595 GtkTableChild *table_child;
597 g_return_if_fail (GTK_IS_TABLE (table));
598 g_return_if_fail (GTK_IS_WIDGET (child));
599 g_return_if_fail (child->parent == NULL);
601 /* g_return_if_fail (left_attach >= 0); */
602 g_return_if_fail (left_attach < right_attach);
603 /* g_return_if_fail (top_attach >= 0); */
604 g_return_if_fail (top_attach < bottom_attach);
606 if (right_attach >= table->ncols)
607 gtk_table_resize (table, table->nrows, right_attach);
609 if (bottom_attach >= table->nrows)
610 gtk_table_resize (table, bottom_attach, table->ncols);
612 table_child = g_new (GtkTableChild, 1);
613 table_child->widget = child;
614 table_child->left_attach = left_attach;
615 table_child->right_attach = right_attach;
616 table_child->top_attach = top_attach;
617 table_child->bottom_attach = bottom_attach;
618 table_child->xexpand = (xoptions & GTK_EXPAND) != 0;
619 table_child->xshrink = (xoptions & GTK_SHRINK) != 0;
620 table_child->xfill = (xoptions & GTK_FILL) != 0;
621 table_child->xpadding = xpadding;
622 table_child->yexpand = (yoptions & GTK_EXPAND) != 0;
623 table_child->yshrink = (yoptions & GTK_SHRINK) != 0;
624 table_child->yfill = (yoptions & GTK_FILL) != 0;
625 table_child->ypadding = ypadding;
627 table->children = g_list_prepend (table->children, table_child);
629 gtk_widget_set_parent (child, GTK_WIDGET (table));
633 gtk_table_attach_defaults (GtkTable *table,
640 gtk_table_attach (table, widget,
641 left_attach, right_attach,
642 top_attach, bottom_attach,
643 GTK_EXPAND | GTK_FILL,
644 GTK_EXPAND | GTK_FILL,
649 gtk_table_set_row_spacing (GtkTable *table,
653 g_return_if_fail (GTK_IS_TABLE (table));
654 g_return_if_fail (row < table->nrows);
656 if (table->rows[row].spacing != spacing)
658 table->rows[row].spacing = spacing;
660 if (GTK_WIDGET_VISIBLE (table))
661 gtk_widget_queue_resize (GTK_WIDGET (table));
666 * gtk_table_get_row_spacing:
667 * @table: a #GtkTable
668 * @row: a row in the table, 0 indicates the first row
670 * Gets the amount of space between row @row, and
671 * row @row + 1. See gtk_table_set_row_spacing().
673 * Return value: the row spacing
676 gtk_table_get_row_spacing (GtkTable *table,
679 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
680 g_return_val_if_fail (row < table->nrows - 1, 0);
682 return table->rows[row].spacing;
686 gtk_table_set_col_spacing (GtkTable *table,
690 g_return_if_fail (GTK_IS_TABLE (table));
691 g_return_if_fail (column < table->ncols);
693 if (table->cols[column].spacing != spacing)
695 table->cols[column].spacing = spacing;
697 if (GTK_WIDGET_VISIBLE (table))
698 gtk_widget_queue_resize (GTK_WIDGET (table));
703 * gtk_table_get_col_spacing:
704 * @table: a #GtkTable
705 * @column: a column in the table, 0 indicates the first column
707 * Gets the amount of space between column @col, and
708 * column @col + 1. See gtk_table_set_col_spacing().
710 * Return value: the column spacing
713 gtk_table_get_col_spacing (GtkTable *table,
716 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
717 g_return_val_if_fail (column < table->ncols, 0);
719 return table->cols[column].spacing;
723 gtk_table_set_row_spacings (GtkTable *table,
728 g_return_if_fail (GTK_IS_TABLE (table));
730 table->row_spacing = spacing;
731 for (row = 0; row < table->nrows; row++)
732 table->rows[row].spacing = spacing;
734 if (GTK_WIDGET_VISIBLE (table))
735 gtk_widget_queue_resize (GTK_WIDGET (table));
737 g_object_notify (G_OBJECT (table), "row_spacing");
741 * gtk_table_get_default_row_spacing:
742 * @table: a #GtkTable
744 * Gets the default row spacing for the table. This is
745 * the spacing that will be used for newly added rows.
746 * (See gtk_table_set_row_spacings())
748 * Returns value: the default row spacing
751 gtk_table_get_default_row_spacing (GtkTable *table)
753 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
755 return table->row_spacing;
759 gtk_table_set_col_spacings (GtkTable *table,
764 g_return_if_fail (GTK_IS_TABLE (table));
766 table->column_spacing = spacing;
767 for (col = 0; col < table->ncols; col++)
768 table->cols[col].spacing = spacing;
770 if (GTK_WIDGET_VISIBLE (table))
771 gtk_widget_queue_resize (GTK_WIDGET (table));
773 g_object_notify (G_OBJECT (table), "column_spacing");
777 * gtk_table_get_default_col_spacing:
778 * @table: a #GtkTable
780 * Gets the default column spacing for the table. This is
781 * the spacing that will be used for newly added columns.
782 * (See gtk_table_set_col_spacings())
784 * Returns value: the default column spacing
787 gtk_table_get_default_col_spacing (GtkTable *table)
789 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
791 return table->column_spacing;
795 gtk_table_set_homogeneous (GtkTable *table,
796 gboolean homogeneous)
798 g_return_if_fail (GTK_IS_TABLE (table));
800 homogeneous = (homogeneous != 0);
801 if (homogeneous != table->homogeneous)
803 table->homogeneous = homogeneous;
805 if (GTK_WIDGET_VISIBLE (table))
806 gtk_widget_queue_resize (GTK_WIDGET (table));
808 g_object_notify (G_OBJECT (table), "homogeneous");
813 * gtk_table_get_homogeneous:
814 * @table: a #GtkTable
816 * Returns whether the table cells are all constrained to the same
817 * width and height. (See gtk_table_set_homogenous ())
819 * Return value: %TRUE if the cells are all constrained to the same size
822 gtk_table_get_homogeneous (GtkTable *table)
824 g_return_val_if_fail (GTK_IS_TABLE (table), FALSE);
826 return table->homogeneous;
830 gtk_table_finalize (GObject *object)
834 g_return_if_fail (GTK_IS_TABLE (object));
836 table = GTK_TABLE (object);
838 g_free (table->rows);
839 g_free (table->cols);
841 G_OBJECT_CLASS (parent_class)->finalize (object);
845 gtk_table_size_request (GtkWidget *widget,
846 GtkRequisition *requisition)
851 g_return_if_fail (GTK_IS_TABLE (widget));
852 g_return_if_fail (requisition != NULL);
854 table = GTK_TABLE (widget);
856 requisition->width = 0;
857 requisition->height = 0;
859 gtk_table_size_request_init (table);
860 gtk_table_size_request_pass1 (table);
861 gtk_table_size_request_pass2 (table);
862 gtk_table_size_request_pass3 (table);
863 gtk_table_size_request_pass2 (table);
865 for (col = 0; col < table->ncols; col++)
866 requisition->width += table->cols[col].requisition;
867 for (col = 0; col + 1 < table->ncols; col++)
868 requisition->width += table->cols[col].spacing;
870 for (row = 0; row < table->nrows; row++)
871 requisition->height += table->rows[row].requisition;
872 for (row = 0; row + 1 < table->nrows; row++)
873 requisition->height += table->rows[row].spacing;
875 requisition->width += GTK_CONTAINER (table)->border_width * 2;
876 requisition->height += GTK_CONTAINER (table)->border_width * 2;
880 gtk_table_size_allocate (GtkWidget *widget,
881 GtkAllocation *allocation)
885 g_return_if_fail (GTK_IS_TABLE (widget));
886 g_return_if_fail (allocation != NULL);
888 widget->allocation = *allocation;
889 table = GTK_TABLE (widget);
891 gtk_table_size_allocate_init (table);
892 gtk_table_size_allocate_pass1 (table);
893 gtk_table_size_allocate_pass2 (table);
897 gtk_table_add (GtkContainer *container,
900 g_return_if_fail (GTK_IS_TABLE (container));
901 g_return_if_fail (widget != NULL);
903 gtk_table_attach_defaults (GTK_TABLE (container), widget, 0, 1, 0, 1);
907 gtk_table_remove (GtkContainer *container,
911 GtkTableChild *child;
914 g_return_if_fail (GTK_IS_TABLE (container));
915 g_return_if_fail (widget != NULL);
917 table = GTK_TABLE (container);
918 children = table->children;
922 child = children->data;
923 children = children->next;
925 if (child->widget == widget)
927 gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
929 gtk_widget_unparent (widget);
931 table->children = g_list_remove (table->children, child);
934 if (was_visible && GTK_WIDGET_VISIBLE (container))
935 gtk_widget_queue_resize (GTK_WIDGET (container));
942 gtk_table_forall (GtkContainer *container,
943 gboolean include_internals,
944 GtkCallback callback,
945 gpointer callback_data)
948 GtkTableChild *child;
951 g_return_if_fail (GTK_IS_TABLE (container));
952 g_return_if_fail (callback != NULL);
954 table = GTK_TABLE (container);
955 children = table->children;
959 child = children->data;
960 children = children->next;
962 (* callback) (child->widget, callback_data);
967 gtk_table_size_request_init (GtkTable *table)
969 GtkTableChild *child;
973 for (row = 0; row < table->nrows; row++)
975 table->rows[row].requisition = 0;
976 table->rows[row].expand = FALSE;
978 for (col = 0; col < table->ncols; col++)
980 table->cols[col].requisition = 0;
981 table->cols[col].expand = FALSE;
984 children = table->children;
987 child = children->data;
988 children = children->next;
990 if (GTK_WIDGET_VISIBLE (child->widget))
991 gtk_widget_size_request (child->widget, NULL);
993 if (child->left_attach == (child->right_attach - 1) && child->xexpand)
994 table->cols[child->left_attach].expand = TRUE;
996 if (child->top_attach == (child->bottom_attach - 1) && child->yexpand)
997 table->rows[child->top_attach].expand = TRUE;
1002 gtk_table_size_request_pass1 (GtkTable *table)
1004 GtkTableChild *child;
1009 children = table->children;
1012 child = children->data;
1013 children = children->next;
1015 if (GTK_WIDGET_VISIBLE (child->widget))
1017 GtkRequisition child_requisition;
1018 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1020 /* Child spans a single column.
1022 if (child->left_attach == (child->right_attach - 1))
1024 width = child_requisition.width + child->xpadding * 2;
1025 table->cols[child->left_attach].requisition = MAX (table->cols[child->left_attach].requisition, width);
1028 /* Child spans a single row.
1030 if (child->top_attach == (child->bottom_attach - 1))
1032 height = child_requisition.height + child->ypadding * 2;
1033 table->rows[child->top_attach].requisition = MAX (table->rows[child->top_attach].requisition, height);
1040 gtk_table_size_request_pass2 (GtkTable *table)
1046 if (table->homogeneous)
1051 for (col = 0; col < table->ncols; col++)
1052 max_width = MAX (max_width, table->cols[col].requisition);
1053 for (row = 0; row < table->nrows; row++)
1054 max_height = MAX (max_height, table->rows[row].requisition);
1056 for (col = 0; col < table->ncols; col++)
1057 table->cols[col].requisition = max_width;
1058 for (row = 0; row < table->nrows; row++)
1059 table->rows[row].requisition = max_height;
1064 gtk_table_size_request_pass3 (GtkTable *table)
1066 GtkTableChild *child;
1072 children = table->children;
1075 child = children->data;
1076 children = children->next;
1078 if (GTK_WIDGET_VISIBLE (child->widget))
1080 /* Child spans multiple columns.
1082 if (child->left_attach != (child->right_attach - 1))
1084 GtkRequisition child_requisition;
1086 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1088 /* Check and see if there is already enough space
1092 for (col = child->left_attach; col < child->right_attach; col++)
1094 width += table->cols[col].requisition;
1095 if ((col + 1) < child->right_attach)
1096 width += table->cols[col].spacing;
1099 /* If we need to request more space for this child to fill
1100 * its requisition, then divide up the needed space amongst the
1101 * columns it spans, favoring expandable columns if any.
1103 if (width < child_requisition.width + child->xpadding * 2)
1106 gboolean force_expand = FALSE;
1108 width = child_requisition.width + child->xpadding * 2 - width;
1110 for (col = child->left_attach; col < child->right_attach; col++)
1111 if (table->cols[col].expand)
1116 n_expand = (child->right_attach - child->left_attach);
1117 force_expand = TRUE;
1120 for (col = child->left_attach; col < child->right_attach; col++)
1121 if (force_expand || table->cols[col].expand)
1123 extra = width / n_expand;
1124 table->cols[col].requisition += extra;
1131 /* Child spans multiple rows.
1133 if (child->top_attach != (child->bottom_attach - 1))
1135 GtkRequisition child_requisition;
1137 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1139 /* Check and see if there is already enough space
1143 for (row = child->top_attach; row < child->bottom_attach; row++)
1145 height += table->rows[row].requisition;
1146 if ((row + 1) < child->bottom_attach)
1147 height += table->rows[row].spacing;
1150 /* If we need to request more space for this child to fill
1151 * its requisition, then divide up the needed space amongst the
1152 * rows it spans, favoring expandable rows if any.
1154 if (height < child_requisition.height + child->ypadding * 2)
1157 gboolean force_expand = FALSE;
1159 height = child_requisition.height + child->ypadding * 2 - height;
1161 for (row = child->top_attach; row < child->bottom_attach; row++)
1163 if (table->rows[row].expand)
1169 n_expand = (child->bottom_attach - child->top_attach);
1170 force_expand = TRUE;
1173 for (row = child->top_attach; row < child->bottom_attach; row++)
1174 if (force_expand || table->rows[row].expand)
1176 extra = height / n_expand;
1177 table->rows[row].requisition += extra;
1188 gtk_table_size_allocate_init (GtkTable *table)
1190 GtkTableChild *child;
1196 /* Initialize the rows and cols.
1197 * By default, rows and cols do not expand and do shrink.
1198 * Those values are modified by the children that occupy
1199 * the rows and cols.
1201 for (col = 0; col < table->ncols; col++)
1203 table->cols[col].allocation = table->cols[col].requisition;
1204 table->cols[col].need_expand = FALSE;
1205 table->cols[col].need_shrink = TRUE;
1206 table->cols[col].expand = FALSE;
1207 table->cols[col].shrink = TRUE;
1208 table->cols[col].empty = TRUE;
1210 for (row = 0; row < table->nrows; row++)
1212 table->rows[row].allocation = table->rows[row].requisition;
1213 table->rows[row].need_expand = FALSE;
1214 table->rows[row].need_shrink = TRUE;
1215 table->rows[row].expand = FALSE;
1216 table->rows[row].shrink = TRUE;
1217 table->rows[row].empty = TRUE;
1220 /* Loop over all the children and adjust the row and col values
1221 * based on whether the children want to be allowed to expand
1222 * or shrink. This loop handles children that occupy a single
1225 children = table->children;
1228 child = children->data;
1229 children = children->next;
1231 if (GTK_WIDGET_VISIBLE (child->widget))
1233 if (child->left_attach == (child->right_attach - 1))
1236 table->cols[child->left_attach].expand = TRUE;
1238 if (!child->xshrink)
1239 table->cols[child->left_attach].shrink = FALSE;
1241 table->cols[child->left_attach].empty = FALSE;
1244 if (child->top_attach == (child->bottom_attach - 1))
1247 table->rows[child->top_attach].expand = TRUE;
1249 if (!child->yshrink)
1250 table->rows[child->top_attach].shrink = FALSE;
1252 table->rows[child->top_attach].empty = FALSE;
1257 /* Loop over all the children again and this time handle children
1258 * which span multiple rows or columns.
1260 children = table->children;
1263 child = children->data;
1264 children = children->next;
1266 if (GTK_WIDGET_VISIBLE (child->widget))
1268 if (child->left_attach != (child->right_attach - 1))
1270 for (col = child->left_attach; col < child->right_attach; col++)
1271 table->cols[col].empty = FALSE;
1276 for (col = child->left_attach; col < child->right_attach; col++)
1277 if (table->cols[col].expand)
1284 for (col = child->left_attach; col < child->right_attach; col++)
1285 table->cols[col].need_expand = TRUE;
1288 if (!child->xshrink)
1291 for (col = child->left_attach; col < child->right_attach; col++)
1292 if (!table->cols[col].shrink)
1299 for (col = child->left_attach; col < child->right_attach; col++)
1300 table->cols[col].need_shrink = FALSE;
1304 if (child->top_attach != (child->bottom_attach - 1))
1306 for (row = child->top_attach; row < child->bottom_attach; row++)
1307 table->rows[row].empty = FALSE;
1312 for (row = child->top_attach; row < child->bottom_attach; row++)
1313 if (table->rows[row].expand)
1320 for (row = child->top_attach; row < child->bottom_attach; row++)
1321 table->rows[row].need_expand = TRUE;
1324 if (!child->yshrink)
1327 for (row = child->top_attach; row < child->bottom_attach; row++)
1328 if (!table->rows[row].shrink)
1335 for (row = child->top_attach; row < child->bottom_attach; row++)
1336 table->rows[row].need_shrink = FALSE;
1342 /* Loop over the columns and set the expand and shrink values
1343 * if the column can be expanded or shrunk.
1345 for (col = 0; col < table->ncols; col++)
1347 if (table->cols[col].empty)
1349 table->cols[col].expand = FALSE;
1350 table->cols[col].shrink = FALSE;
1354 if (table->cols[col].need_expand)
1355 table->cols[col].expand = TRUE;
1356 if (!table->cols[col].need_shrink)
1357 table->cols[col].shrink = FALSE;
1361 /* Loop over the rows and set the expand and shrink values
1362 * if the row can be expanded or shrunk.
1364 for (row = 0; row < table->nrows; row++)
1366 if (table->rows[row].empty)
1368 table->rows[row].expand = FALSE;
1369 table->rows[row].shrink = FALSE;
1373 if (table->rows[row].need_expand)
1374 table->rows[row].expand = TRUE;
1375 if (!table->rows[row].need_shrink)
1376 table->rows[row].shrink = FALSE;
1382 gtk_table_size_allocate_pass1 (GtkTable *table)
1392 /* If we were allocated more space than we requested
1393 * then we have to expand any expandable rows and columns
1394 * to fill in the extra space.
1397 real_width = GTK_WIDGET (table)->allocation.width - GTK_CONTAINER (table)->border_width * 2;
1398 real_height = GTK_WIDGET (table)->allocation.height - GTK_CONTAINER (table)->border_width * 2;
1400 if (table->homogeneous)
1402 if (!table->children)
1407 for (col = 0; col < table->ncols; col++)
1408 if (table->cols[col].expand)
1417 for (col = 0; col + 1 < table->ncols; col++)
1418 width -= table->cols[col].spacing;
1420 for (col = 0; col < table->ncols; col++)
1422 extra = width / (table->ncols - col);
1423 table->cols[col].allocation = MAX (1, extra);
1434 for (col = 0; col < table->ncols; col++)
1436 width += table->cols[col].requisition;
1437 if (table->cols[col].expand)
1439 if (table->cols[col].shrink)
1442 for (col = 0; col + 1 < table->ncols; col++)
1443 width += table->cols[col].spacing;
1445 /* Check to see if we were allocated more width than we requested.
1447 if ((width < real_width) && (nexpand >= 1))
1449 width = real_width - width;
1451 for (col = 0; col < table->ncols; col++)
1452 if (table->cols[col].expand)
1454 extra = width / nexpand;
1455 table->cols[col].allocation += extra;
1462 /* Check to see if we were allocated less width than we requested,
1463 * then shrink until we fit the size give.
1465 if (width > real_width)
1467 gint total_nshrink = nshrink;
1469 extra = width - real_width;
1470 while (total_nshrink > 0 && extra > 0)
1472 nshrink = total_nshrink;
1473 for (col = 0; col < table->ncols; col++)
1474 if (table->cols[col].shrink)
1476 gint allocation = table->cols[col].allocation;
1478 table->cols[col].allocation = MAX (1, (gint) table->cols[col].allocation - extra / nshrink);
1479 extra -= allocation - table->cols[col].allocation;
1481 if (table->cols[col].allocation < 2)
1484 table->cols[col].shrink = FALSE;
1491 if (table->homogeneous)
1493 if (!table->children)
1498 for (row = 0; row < table->nrows; row++)
1499 if (table->rows[row].expand)
1507 height = real_height;
1509 for (row = 0; row + 1 < table->nrows; row++)
1510 height -= table->rows[row].spacing;
1513 for (row = 0; row < table->nrows; row++)
1515 extra = height / (table->nrows - row);
1516 table->rows[row].allocation = MAX (1, extra);
1527 for (row = 0; row < table->nrows; row++)
1529 height += table->rows[row].requisition;
1530 if (table->rows[row].expand)
1532 if (table->rows[row].shrink)
1535 for (row = 0; row + 1 < table->nrows; row++)
1536 height += table->rows[row].spacing;
1538 /* Check to see if we were allocated more height than we requested.
1540 if ((height < real_height) && (nexpand >= 1))
1542 height = real_height - height;
1544 for (row = 0; row < table->nrows; row++)
1545 if (table->rows[row].expand)
1547 extra = height / nexpand;
1548 table->rows[row].allocation += extra;
1555 /* Check to see if we were allocated less height than we requested.
1556 * then shrink until we fit the size give.
1558 if (height > real_height)
1560 gint total_nshrink = nshrink;
1562 extra = height - real_height;
1563 while (total_nshrink > 0 && extra > 0)
1565 nshrink = total_nshrink;
1566 for (row = 0; row < table->nrows; row++)
1567 if (table->rows[row].shrink)
1569 gint allocation = table->rows[row].allocation;
1571 table->rows[row].allocation = MAX (1, (gint) table->rows[row].allocation - extra / nshrink);
1572 extra -= allocation - table->rows[row].allocation;
1574 if (table->rows[row].allocation < 2)
1577 table->rows[row].shrink = FALSE;
1586 gtk_table_size_allocate_pass2 (GtkTable *table)
1588 GtkTableChild *child;
1594 GtkAllocation allocation;
1595 GtkWidget *widget = GTK_WIDGET (table);
1597 children = table->children;
1600 child = children->data;
1601 children = children->next;
1603 if (GTK_WIDGET_VISIBLE (child->widget))
1605 GtkRequisition child_requisition;
1606 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1608 x = GTK_WIDGET (table)->allocation.x + GTK_CONTAINER (table)->border_width;
1609 y = GTK_WIDGET (table)->allocation.y + GTK_CONTAINER (table)->border_width;
1613 for (col = 0; col < child->left_attach; col++)
1615 x += table->cols[col].allocation;
1616 x += table->cols[col].spacing;
1619 for (col = child->left_attach; col < child->right_attach; col++)
1621 max_width += table->cols[col].allocation;
1622 if ((col + 1) < child->right_attach)
1623 max_width += table->cols[col].spacing;
1626 for (row = 0; row < child->top_attach; row++)
1628 y += table->rows[row].allocation;
1629 y += table->rows[row].spacing;
1632 for (row = child->top_attach; row < child->bottom_attach; row++)
1634 max_height += table->rows[row].allocation;
1635 if ((row + 1) < child->bottom_attach)
1636 max_height += table->rows[row].spacing;
1641 allocation.width = MAX (1, max_width - (gint)child->xpadding * 2);
1642 allocation.x = x + (max_width - allocation.width) / 2;
1646 allocation.width = child_requisition.width;
1647 allocation.x = x + (max_width - allocation.width) / 2;
1652 allocation.height = MAX (1, max_height - (gint)child->ypadding * 2);
1653 allocation.y = y + (max_height - allocation.height) / 2;
1657 allocation.height = child_requisition.height;
1658 allocation.y = y + (max_height - allocation.height) / 2;
1661 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1662 allocation.x = widget->allocation.x + widget->allocation.width
1663 - (allocation.x - widget->allocation.x) - allocation.width;
1665 gtk_widget_size_allocate (child->widget, &allocation);
1670 #define __GTK_TABLE_C__
1671 #include "gtkaliasdef.c"