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_map (GtkWidget *widget);
58 static void gtk_table_unmap (GtkWidget *widget);
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 GtkType 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 GtkType table_type = 0;
112 static const GtkTypeInfo table_info =
116 sizeof (GtkTableClass),
117 (GtkClassInitFunc) gtk_table_class_init,
118 (GtkObjectInitFunc) gtk_table_init,
119 /* reserved_1 */ NULL,
120 /* reserved_2 */ NULL,
121 (GtkClassInitFunc) NULL,
124 table_type = gtk_type_unique (gtk_container_get_type (), &table_info);
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->map = gtk_table_map;
145 widget_class->unmap = gtk_table_unmap;
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 _("The number of rows in the table"),
166 g_object_class_install_property (gobject_class,
168 g_param_spec_uint ("n_columns",
170 _("The number of columns in the table"),
175 g_object_class_install_property (gobject_class,
177 g_param_spec_uint ("row_spacing",
179 _("The amount of space between two consecutive rows"),
184 g_object_class_install_property (gobject_class,
186 g_param_spec_uint ("column_spacing",
188 _("The amount of space between two consecutive columns"),
193 g_object_class_install_property (gobject_class,
195 g_param_spec_boolean ("homogeneous",
197 _("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", NULL, NULL,
206 gtk_container_class_install_child_property (container_class,
207 CHILD_PROP_RIGHT_ATTACH,
208 g_param_spec_uint ("right_attach", NULL, NULL,
211 gtk_container_class_install_child_property (container_class,
212 CHILD_PROP_TOP_ATTACH,
213 g_param_spec_uint ("top_attach", NULL, NULL,
216 gtk_container_class_install_child_property (container_class,
217 CHILD_PROP_BOTTOM_ATTACH,
218 g_param_spec_uint ("bottom_attach", NULL, NULL,
221 gtk_container_class_install_child_property (container_class,
222 CHILD_PROP_X_OPTIONS,
223 g_param_spec_flags ("x_options", NULL, NULL,
224 GTK_TYPE_ATTACH_OPTIONS, GTK_EXPAND | GTK_FILL,
226 gtk_container_class_install_child_property (container_class,
227 CHILD_PROP_Y_OPTIONS,
228 g_param_spec_flags ("y_options", NULL, NULL,
229 GTK_TYPE_ATTACH_OPTIONS, GTK_EXPAND | GTK_FILL,
231 gtk_container_class_install_child_property (container_class,
232 CHILD_PROP_X_PADDING,
233 g_param_spec_uint ("x_padding", NULL, NULL,
236 gtk_container_class_install_child_property (container_class,
237 CHILD_PROP_Y_PADDING,
238 g_param_spec_uint ("y_padding", NULL, NULL,
244 gtk_table_child_type (GtkContainer *container)
246 return GTK_TYPE_WIDGET;
250 gtk_table_get_property (GObject *object,
257 table = GTK_TABLE (object);
262 g_value_set_uint (value, table->nrows);
265 g_value_set_uint (value, table->ncols);
267 case PROP_ROW_SPACING:
268 g_value_set_uint (value, table->row_spacing);
270 case PROP_COLUMN_SPACING:
271 g_value_set_uint (value, table->column_spacing);
273 case PROP_HOMOGENEOUS:
274 g_value_set_boolean (value, table->homogeneous);
277 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
283 gtk_table_set_property (GObject *object,
290 table = GTK_TABLE (object);
295 gtk_table_resize (table, g_value_get_uint (value), table->ncols);
298 gtk_table_resize (table, table->nrows, g_value_get_uint (value));
300 case PROP_ROW_SPACING:
301 gtk_table_set_row_spacings (table, g_value_get_uint (value));
303 case PROP_COLUMN_SPACING:
304 gtk_table_set_col_spacings (table, g_value_get_uint (value));
306 case PROP_HOMOGENEOUS:
307 gtk_table_set_homogeneous (table, g_value_get_boolean (value));
310 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
316 gtk_table_set_child_property (GtkContainer *container,
322 GtkTable *table = GTK_TABLE (container);
323 GtkTableChild *table_child;
327 for (list = table->children; list; list = list->next)
329 table_child = list->data;
331 if (table_child->widget == child)
336 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
342 case CHILD_PROP_LEFT_ATTACH:
343 table_child->left_attach = g_value_get_uint (value);
344 if (table_child->right_attach <= table_child->left_attach)
345 table_child->right_attach = table_child->left_attach + 1;
346 if (table_child->right_attach >= table->ncols)
347 gtk_table_resize (table, table->ncols, table_child->right_attach);
349 case CHILD_PROP_RIGHT_ATTACH:
350 table_child->right_attach = g_value_get_uint (value);
351 if (table_child->right_attach <= table_child->left_attach)
352 table_child->left_attach = table_child->right_attach - 1;
353 if (table_child->right_attach >= table->ncols)
354 gtk_table_resize (table, table->ncols, table_child->right_attach);
356 case CHILD_PROP_TOP_ATTACH:
357 table_child->top_attach = g_value_get_uint (value);
358 if (table_child->bottom_attach <= table_child->top_attach)
359 table_child->bottom_attach = table_child->top_attach + 1;
360 if (table_child->bottom_attach >= table->nrows)
361 gtk_table_resize (table, table_child->bottom_attach, table->ncols);
363 case CHILD_PROP_BOTTOM_ATTACH:
364 table_child->bottom_attach = g_value_get_uint (value);
365 if (table_child->bottom_attach <= table_child->top_attach)
366 table_child->top_attach = table_child->bottom_attach - 1;
367 if (table_child->bottom_attach >= table->nrows)
368 gtk_table_resize (table, table_child->bottom_attach, table->ncols);
370 case CHILD_PROP_X_OPTIONS:
371 table_child->xexpand = (g_value_get_flags (value) & GTK_EXPAND) != 0;
372 table_child->xshrink = (g_value_get_flags (value) & GTK_SHRINK) != 0;
373 table_child->xfill = (g_value_get_flags (value) & GTK_FILL) != 0;
375 case CHILD_PROP_Y_OPTIONS:
376 table_child->yexpand = (g_value_get_flags (value) & GTK_EXPAND) != 0;
377 table_child->yshrink = (g_value_get_flags (value) & GTK_SHRINK) != 0;
378 table_child->yfill = (g_value_get_flags (value) & GTK_FILL) != 0;
380 case CHILD_PROP_X_PADDING:
381 table_child->xpadding = g_value_get_uint (value);
383 case CHILD_PROP_Y_PADDING:
384 table_child->ypadding = g_value_get_uint (value);
387 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
390 if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (table))
391 gtk_widget_queue_resize (child);
395 gtk_table_get_child_property (GtkContainer *container,
401 GtkTable *table = GTK_TABLE (container);
402 GtkTableChild *table_child;
406 for (list = table->children; list; list = list->next)
408 table_child = list->data;
410 if (table_child->widget == child)
415 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
421 case CHILD_PROP_LEFT_ATTACH:
422 g_value_set_uint (value, table_child->left_attach);
424 case CHILD_PROP_RIGHT_ATTACH:
425 g_value_set_uint (value, table_child->right_attach);
427 case CHILD_PROP_TOP_ATTACH:
428 g_value_set_uint (value, table_child->top_attach);
430 case CHILD_PROP_BOTTOM_ATTACH:
431 g_value_set_uint (value, table_child->bottom_attach);
433 case CHILD_PROP_X_OPTIONS:
434 g_value_set_flags (value, (table_child->xexpand * GTK_EXPAND |
435 table_child->xshrink * GTK_SHRINK |
436 table_child->xfill * GTK_FILL));
438 case CHILD_PROP_Y_OPTIONS:
439 g_value_set_flags (value, (table_child->yexpand * GTK_EXPAND |
440 table_child->yshrink * GTK_SHRINK |
441 table_child->yfill * GTK_FILL));
443 case CHILD_PROP_X_PADDING:
444 g_value_set_uint (value, table_child->xpadding);
446 case CHILD_PROP_Y_PADDING:
447 g_value_set_uint (value, table_child->ypadding);
450 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
456 gtk_table_init (GtkTable *table)
458 GTK_WIDGET_SET_FLAGS (table, GTK_NO_WINDOW);
460 table->children = NULL;
465 table->column_spacing = 0;
466 table->row_spacing = 0;
467 table->homogeneous = FALSE;
469 gtk_table_resize (table, 1, 1);
473 gtk_table_new (guint rows,
475 gboolean homogeneous)
484 table = gtk_type_new (gtk_table_get_type ());
486 table->homogeneous = (homogeneous ? TRUE : FALSE);
488 gtk_table_resize (table, rows, columns);
490 return GTK_WIDGET (table);
494 gtk_table_resize (GtkTable *table,
498 g_return_if_fail (GTK_IS_TABLE (table));
499 g_return_if_fail (n_rows > 0 && n_rows < 65536);
500 g_return_if_fail (n_rows > 0 && n_cols < 65536);
502 n_rows = MAX (n_rows, 1);
503 n_cols = MAX (n_cols, 1);
505 if (n_rows != table->nrows ||
506 n_cols != table->ncols)
510 for (list = table->children; list; list = list->next)
512 GtkTableChild *child;
516 n_rows = MAX (n_rows, child->bottom_attach);
517 n_cols = MAX (n_cols, child->right_attach);
520 if (n_rows != table->nrows)
525 table->nrows = n_rows;
526 table->rows = g_realloc (table->rows, table->nrows * sizeof (GtkTableRowCol));
528 for (; i < table->nrows; i++)
530 table->rows[i].requisition = 0;
531 table->rows[i].allocation = 0;
532 table->rows[i].spacing = table->row_spacing;
533 table->rows[i].need_expand = 0;
534 table->rows[i].need_shrink = 0;
535 table->rows[i].expand = 0;
536 table->rows[i].shrink = 0;
539 g_object_notify (G_OBJECT (table), "n_rows");
542 if (n_cols != table->ncols)
547 table->ncols = n_cols;
548 table->cols = g_realloc (table->cols, table->ncols * sizeof (GtkTableRowCol));
550 for (; i < table->ncols; i++)
552 table->cols[i].requisition = 0;
553 table->cols[i].allocation = 0;
554 table->cols[i].spacing = table->column_spacing;
555 table->cols[i].need_expand = 0;
556 table->cols[i].need_shrink = 0;
557 table->cols[i].expand = 0;
558 table->cols[i].shrink = 0;
561 g_object_notify (G_OBJECT (table), "n_columns");
567 gtk_table_attach (GtkTable *table,
573 GtkAttachOptions xoptions,
574 GtkAttachOptions yoptions,
578 GtkTableChild *table_child;
580 g_return_if_fail (GTK_IS_TABLE (table));
581 g_return_if_fail (GTK_IS_WIDGET (child));
582 g_return_if_fail (child->parent == NULL);
584 /* g_return_if_fail (left_attach >= 0); */
585 g_return_if_fail (left_attach < right_attach);
586 /* g_return_if_fail (top_attach >= 0); */
587 g_return_if_fail (top_attach < bottom_attach);
589 if (right_attach >= table->ncols)
590 gtk_table_resize (table, table->nrows, right_attach);
592 if (bottom_attach >= table->nrows)
593 gtk_table_resize (table, bottom_attach, table->ncols);
595 table_child = g_new (GtkTableChild, 1);
596 table_child->widget = child;
597 table_child->left_attach = left_attach;
598 table_child->right_attach = right_attach;
599 table_child->top_attach = top_attach;
600 table_child->bottom_attach = bottom_attach;
601 table_child->xexpand = (xoptions & GTK_EXPAND) != 0;
602 table_child->xshrink = (xoptions & GTK_SHRINK) != 0;
603 table_child->xfill = (xoptions & GTK_FILL) != 0;
604 table_child->xpadding = xpadding;
605 table_child->yexpand = (yoptions & GTK_EXPAND) != 0;
606 table_child->yshrink = (yoptions & GTK_SHRINK) != 0;
607 table_child->yfill = (yoptions & GTK_FILL) != 0;
608 table_child->ypadding = ypadding;
610 table->children = g_list_prepend (table->children, table_child);
612 gtk_widget_set_parent (child, GTK_WIDGET (table));
614 if (GTK_WIDGET_REALIZED (child->parent))
615 gtk_widget_realize (child);
617 if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child))
619 if (GTK_WIDGET_MAPPED (child->parent))
620 gtk_widget_map (child);
622 gtk_widget_queue_resize (child);
627 gtk_table_attach_defaults (GtkTable *table,
634 gtk_table_attach (table, widget,
635 left_attach, right_attach,
636 top_attach, bottom_attach,
637 GTK_EXPAND | GTK_FILL,
638 GTK_EXPAND | GTK_FILL,
643 gtk_table_set_row_spacing (GtkTable *table,
647 g_return_if_fail (GTK_IS_TABLE (table));
648 g_return_if_fail (row < table->nrows);
650 if (table->rows[row].spacing != spacing)
652 table->rows[row].spacing = spacing;
654 if (GTK_WIDGET_VISIBLE (table))
655 gtk_widget_queue_resize (GTK_WIDGET (table));
658 g_object_notify (G_OBJECT (table), "row_spacing");
662 * gtk_table_get_row_spacing:
663 * @table: a #GtkTable
664 * @row: a row in the table, 0 indicates the first row
666 * Gets the amount of space between row @row, and
667 * row @row + 1. See gtk_table_set_row_spacing().
669 * Return value: the row spacing
672 gtk_table_get_row_spacing (GtkTable *table,
675 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
676 g_return_val_if_fail (row < table->nrows - 1, 0);
678 return table->rows[row].spacing;
682 gtk_table_set_col_spacing (GtkTable *table,
686 g_return_if_fail (GTK_IS_TABLE (table));
687 g_return_if_fail (column < table->ncols);
689 if (table->cols[column].spacing != spacing)
691 table->cols[column].spacing = spacing;
693 if (GTK_WIDGET_VISIBLE (table))
694 gtk_widget_queue_resize (GTK_WIDGET (table));
697 g_object_notify (G_OBJECT (table), "column_spacing");
701 * gtk_table_get_col_spacing:
702 * @table: a #GtkTable
703 * @col: 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));
737 * gtk_table_get_default_row_spacing:
738 * @table: a #GtkTable
740 * Gets the default row spacing for the table. This is
741 * the spacing that will be used for newly added rows.
742 * (See gtk_table_set_row_spacings())
744 * Returns value: the default row spacing
747 gtk_table_get_default_row_spacing (GtkTable *table)
749 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
751 return table->row_spacing;
755 gtk_table_set_col_spacings (GtkTable *table,
760 g_return_if_fail (GTK_IS_TABLE (table));
762 table->column_spacing = spacing;
763 for (col = 0; col < table->ncols; col++)
764 table->cols[col].spacing = spacing;
766 if (GTK_WIDGET_VISIBLE (table))
767 gtk_widget_queue_resize (GTK_WIDGET (table));
771 * gtk_table_get_default_col_spacing:
772 * @table: a #GtkTable
774 * Gets the default column spacing for the table. This is
775 * the spacing that will be used for newly added columns.
776 * (See gtk_table_set_col_spacings())
778 * Returns value: the default column spacing
781 gtk_table_get_default_col_spacing (GtkTable *table)
783 g_return_val_if_fail (GTK_IS_TABLE (table), 0);
785 return table->column_spacing;
789 gtk_table_set_homogeneous (GtkTable *table,
790 gboolean homogeneous)
792 g_return_if_fail (GTK_IS_TABLE (table));
794 homogeneous = (homogeneous != 0);
795 if (homogeneous != table->homogeneous)
797 table->homogeneous = homogeneous;
799 if (GTK_WIDGET_VISIBLE (table))
800 gtk_widget_queue_resize (GTK_WIDGET (table));
805 * gtk_table_get_homogeneous:
806 * @table: a #GtkTable
808 * Returns whether the table cells are all constrained to the same
809 * width and height. (See gtk_table_set_homogenous ())
811 * Return value: %TRUE if the cells are all constrained to the same size
814 gtk_table_get_homogeneous (GtkTable *table)
816 g_return_val_if_fail (GTK_IS_TABLE (table), FALSE);
818 return table->homogeneous;
822 gtk_table_finalize (GObject *object)
826 g_return_if_fail (GTK_IS_TABLE (object));
828 table = GTK_TABLE (object);
830 g_free (table->rows);
831 g_free (table->cols);
833 G_OBJECT_CLASS (parent_class)->finalize (object);
837 gtk_table_map (GtkWidget *widget)
840 GtkTableChild *child;
843 g_return_if_fail (GTK_IS_TABLE (widget));
845 table = GTK_TABLE (widget);
846 GTK_WIDGET_SET_FLAGS (table, GTK_MAPPED);
848 children = table->children;
851 child = children->data;
852 children = children->next;
854 if (GTK_WIDGET_VISIBLE (child->widget) &&
855 !GTK_WIDGET_MAPPED (child->widget))
856 gtk_widget_map (child->widget);
861 gtk_table_unmap (GtkWidget *widget)
864 GtkTableChild *child;
867 g_return_if_fail (GTK_IS_TABLE (widget));
869 table = GTK_TABLE (widget);
870 GTK_WIDGET_UNSET_FLAGS (table, GTK_MAPPED);
872 children = table->children;
875 child = children->data;
876 children = children->next;
878 if (GTK_WIDGET_VISIBLE (child->widget) &&
879 GTK_WIDGET_MAPPED (child->widget))
880 gtk_widget_unmap (child->widget);
885 gtk_table_size_request (GtkWidget *widget,
886 GtkRequisition *requisition)
891 g_return_if_fail (GTK_IS_TABLE (widget));
892 g_return_if_fail (requisition != NULL);
894 table = GTK_TABLE (widget);
896 requisition->width = 0;
897 requisition->height = 0;
899 gtk_table_size_request_init (table);
900 gtk_table_size_request_pass1 (table);
901 gtk_table_size_request_pass2 (table);
902 gtk_table_size_request_pass3 (table);
903 gtk_table_size_request_pass2 (table);
905 for (col = 0; col < table->ncols; col++)
906 requisition->width += table->cols[col].requisition;
907 for (col = 0; col + 1 < table->ncols; col++)
908 requisition->width += table->cols[col].spacing;
910 for (row = 0; row < table->nrows; row++)
911 requisition->height += table->rows[row].requisition;
912 for (row = 0; row + 1 < table->nrows; row++)
913 requisition->height += table->rows[row].spacing;
915 requisition->width += GTK_CONTAINER (table)->border_width * 2;
916 requisition->height += GTK_CONTAINER (table)->border_width * 2;
920 gtk_table_size_allocate (GtkWidget *widget,
921 GtkAllocation *allocation)
925 g_return_if_fail (GTK_IS_TABLE (widget));
926 g_return_if_fail (allocation != NULL);
928 widget->allocation = *allocation;
929 table = GTK_TABLE (widget);
931 gtk_table_size_allocate_init (table);
932 gtk_table_size_allocate_pass1 (table);
933 gtk_table_size_allocate_pass2 (table);
937 gtk_table_add (GtkContainer *container,
940 g_return_if_fail (GTK_IS_TABLE (container));
941 g_return_if_fail (widget != NULL);
943 gtk_table_attach_defaults (GTK_TABLE (container), widget, 0, 1, 0, 1);
947 gtk_table_remove (GtkContainer *container,
951 GtkTableChild *child;
954 g_return_if_fail (GTK_IS_TABLE (container));
955 g_return_if_fail (widget != NULL);
957 table = GTK_TABLE (container);
958 children = table->children;
962 child = children->data;
963 children = children->next;
965 if (child->widget == widget)
967 gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
969 gtk_widget_unparent (widget);
971 table->children = g_list_remove (table->children, child);
974 if (was_visible && GTK_WIDGET_VISIBLE (container))
975 gtk_container_queue_resize (container);
982 gtk_table_forall (GtkContainer *container,
983 gboolean include_internals,
984 GtkCallback callback,
985 gpointer callback_data)
988 GtkTableChild *child;
991 g_return_if_fail (GTK_IS_TABLE (container));
992 g_return_if_fail (callback != NULL);
994 table = GTK_TABLE (container);
995 children = table->children;
999 child = children->data;
1000 children = children->next;
1002 (* callback) (child->widget, callback_data);
1007 gtk_table_size_request_init (GtkTable *table)
1009 GtkTableChild *child;
1013 for (row = 0; row < table->nrows; row++)
1014 table->rows[row].requisition = 0;
1015 for (col = 0; col < table->ncols; col++)
1016 table->cols[col].requisition = 0;
1018 children = table->children;
1021 child = children->data;
1022 children = children->next;
1024 if (GTK_WIDGET_VISIBLE (child->widget))
1025 gtk_widget_size_request (child->widget, NULL);
1030 gtk_table_size_request_pass1 (GtkTable *table)
1032 GtkTableChild *child;
1037 children = table->children;
1040 child = children->data;
1041 children = children->next;
1043 if (GTK_WIDGET_VISIBLE (child->widget))
1045 GtkRequisition child_requisition;
1046 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1048 /* Child spans a single column.
1050 if (child->left_attach == (child->right_attach - 1))
1052 width = child_requisition.width + child->xpadding * 2;
1053 table->cols[child->left_attach].requisition = MAX (table->cols[child->left_attach].requisition, width);
1056 /* Child spans a single row.
1058 if (child->top_attach == (child->bottom_attach - 1))
1060 height = child_requisition.height + child->ypadding * 2;
1061 table->rows[child->top_attach].requisition = MAX (table->rows[child->top_attach].requisition, height);
1068 gtk_table_size_request_pass2 (GtkTable *table)
1074 if (table->homogeneous)
1079 for (col = 0; col < table->ncols; col++)
1080 max_width = MAX (max_width, table->cols[col].requisition);
1081 for (row = 0; row < table->nrows; row++)
1082 max_height = MAX (max_height, table->rows[row].requisition);
1084 for (col = 0; col < table->ncols; col++)
1085 table->cols[col].requisition = max_width;
1086 for (row = 0; row < table->nrows; row++)
1087 table->rows[row].requisition = max_height;
1092 gtk_table_size_request_pass3 (GtkTable *table)
1094 GtkTableChild *child;
1100 children = table->children;
1103 child = children->data;
1104 children = children->next;
1106 if (GTK_WIDGET_VISIBLE (child->widget))
1108 /* Child spans multiple columns.
1110 if (child->left_attach != (child->right_attach - 1))
1112 GtkRequisition child_requisition;
1114 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1116 /* Check and see if there is already enough space
1120 for (col = child->left_attach; col < child->right_attach; col++)
1122 width += table->cols[col].requisition;
1123 if ((col + 1) < child->right_attach)
1124 width += table->cols[col].spacing;
1127 /* If we need to request more space for this child to fill
1128 * its requisition, then divide up the needed space evenly
1129 * amongst the columns it spans.
1131 if (width < child_requisition.width + child->xpadding * 2)
1133 width = child_requisition.width + child->xpadding * 2 - width;
1135 for (col = child->left_attach; col < child->right_attach; col++)
1137 extra = width / (child->right_attach - col);
1138 table->cols[col].requisition += extra;
1144 /* Child spans multiple rows.
1146 if (child->top_attach != (child->bottom_attach - 1))
1148 GtkRequisition child_requisition;
1150 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1152 /* Check and see if there is already enough space
1156 for (row = child->top_attach; row < child->bottom_attach; row++)
1158 height += table->rows[row].requisition;
1159 if ((row + 1) < child->bottom_attach)
1160 height += table->rows[row].spacing;
1163 /* If we need to request more space for this child to fill
1164 * its requisition, then divide up the needed space evenly
1165 * amongst the columns it spans.
1167 if (height < child_requisition.height + child->ypadding * 2)
1169 height = child_requisition.height + child->ypadding * 2 - height;
1171 for (row = child->top_attach; row < child->bottom_attach; row++)
1173 extra = height / (child->bottom_attach - row);
1174 table->rows[row].requisition += extra;
1184 gtk_table_size_allocate_init (GtkTable *table)
1186 GtkTableChild *child;
1192 /* Initialize the rows and cols.
1193 * By default, rows and cols do not expand and do shrink.
1194 * Those values are modified by the children that occupy
1195 * the rows and cols.
1197 for (col = 0; col < table->ncols; col++)
1199 table->cols[col].allocation = table->cols[col].requisition;
1200 table->cols[col].need_expand = FALSE;
1201 table->cols[col].need_shrink = TRUE;
1202 table->cols[col].expand = FALSE;
1203 table->cols[col].shrink = TRUE;
1204 table->cols[col].empty = TRUE;
1206 for (row = 0; row < table->nrows; row++)
1208 table->rows[row].allocation = table->rows[row].requisition;
1209 table->rows[row].need_expand = FALSE;
1210 table->rows[row].need_shrink = TRUE;
1211 table->rows[row].expand = FALSE;
1212 table->rows[row].shrink = TRUE;
1213 table->rows[row].empty = TRUE;
1216 /* Loop over all the children and adjust the row and col values
1217 * based on whether the children want to be allowed to expand
1218 * or shrink. This loop handles children that occupy a single
1221 children = table->children;
1224 child = children->data;
1225 children = children->next;
1227 if (GTK_WIDGET_VISIBLE (child->widget))
1229 if (child->left_attach == (child->right_attach - 1))
1232 table->cols[child->left_attach].expand = TRUE;
1234 if (!child->xshrink)
1235 table->cols[child->left_attach].shrink = FALSE;
1237 table->cols[child->left_attach].empty = FALSE;
1240 if (child->top_attach == (child->bottom_attach - 1))
1243 table->rows[child->top_attach].expand = TRUE;
1245 if (!child->yshrink)
1246 table->rows[child->top_attach].shrink = FALSE;
1248 table->rows[child->top_attach].empty = FALSE;
1253 /* Loop over all the children again and this time handle children
1254 * which span multiple rows or columns.
1256 children = table->children;
1259 child = children->data;
1260 children = children->next;
1262 if (GTK_WIDGET_VISIBLE (child->widget))
1264 if (child->left_attach != (child->right_attach - 1))
1266 for (col = child->left_attach; col < child->right_attach; col++)
1267 table->cols[col].empty = FALSE;
1272 for (col = child->left_attach; col < child->right_attach; col++)
1273 if (table->cols[col].expand)
1280 for (col = child->left_attach; col < child->right_attach; col++)
1281 table->cols[col].need_expand = TRUE;
1284 if (!child->xshrink)
1287 for (col = child->left_attach; col < child->right_attach; col++)
1288 if (!table->cols[col].shrink)
1295 for (col = child->left_attach; col < child->right_attach; col++)
1296 table->cols[col].need_shrink = FALSE;
1300 if (child->top_attach != (child->bottom_attach - 1))
1302 for (row = child->top_attach; row < child->bottom_attach; row++)
1303 table->rows[row].empty = FALSE;
1308 for (row = child->top_attach; row < child->bottom_attach; row++)
1309 if (table->rows[row].expand)
1316 for (row = child->top_attach; row < child->bottom_attach; row++)
1317 table->rows[row].need_expand = TRUE;
1320 if (!child->yshrink)
1323 for (row = child->top_attach; row < child->bottom_attach; row++)
1324 if (!table->rows[row].shrink)
1331 for (row = child->top_attach; row < child->bottom_attach; row++)
1332 table->rows[row].need_shrink = FALSE;
1338 /* Loop over the columns and set the expand and shrink values
1339 * if the column can be expanded or shrunk.
1341 for (col = 0; col < table->ncols; col++)
1343 if (table->cols[col].empty)
1345 table->cols[col].expand = FALSE;
1346 table->cols[col].shrink = FALSE;
1350 if (table->cols[col].need_expand)
1351 table->cols[col].expand = TRUE;
1352 if (!table->cols[col].need_shrink)
1353 table->cols[col].shrink = FALSE;
1357 /* Loop over the rows and set the expand and shrink values
1358 * if the row can be expanded or shrunk.
1360 for (row = 0; row < table->nrows; row++)
1362 if (table->rows[row].empty)
1364 table->rows[row].expand = FALSE;
1365 table->rows[row].shrink = FALSE;
1369 if (table->rows[row].need_expand)
1370 table->rows[row].expand = TRUE;
1371 if (!table->rows[row].need_shrink)
1372 table->rows[row].shrink = FALSE;
1378 gtk_table_size_allocate_pass1 (GtkTable *table)
1388 /* If we were allocated more space than we requested
1389 * then we have to expand any expandable rows and columns
1390 * to fill in the extra space.
1393 real_width = GTK_WIDGET (table)->allocation.width - GTK_CONTAINER (table)->border_width * 2;
1394 real_height = GTK_WIDGET (table)->allocation.height - GTK_CONTAINER (table)->border_width * 2;
1396 if (table->homogeneous)
1399 for (col = 0; col < table->ncols; col++)
1400 if (table->cols[col].expand)
1410 for (col = 0; col + 1 < table->ncols; col++)
1411 width -= table->cols[col].spacing;
1413 for (col = 0; col < table->ncols; col++)
1415 extra = width / (table->ncols - col);
1416 table->cols[col].allocation = MAX (1, extra);
1427 for (col = 0; col < table->ncols; col++)
1429 width += table->cols[col].requisition;
1430 if (table->cols[col].expand)
1432 if (table->cols[col].shrink)
1435 for (col = 0; col + 1 < table->ncols; col++)
1436 width += table->cols[col].spacing;
1438 /* Check to see if we were allocated more width than we requested.
1440 if ((width < real_width) && (nexpand >= 1))
1442 width = real_width - width;
1444 for (col = 0; col < table->ncols; col++)
1445 if (table->cols[col].expand)
1447 extra = width / nexpand;
1448 table->cols[col].allocation += extra;
1455 /* Check to see if we were allocated less width than we requested,
1456 * then shrink until we fit the size give.
1458 if (width > real_width)
1460 gint total_nshrink = nshrink;
1462 extra = width - real_width;
1463 while (total_nshrink > 0 && extra > 0)
1465 nshrink = total_nshrink;
1466 for (col = 0; col < table->ncols; col++)
1467 if (table->cols[col].shrink)
1469 gint allocation = table->cols[col].allocation;
1471 table->cols[col].allocation = MAX (1, (gint) table->cols[col].allocation - extra / nshrink);
1472 extra -= allocation - table->cols[col].allocation;
1474 if (table->cols[col].allocation < 2)
1477 table->cols[col].shrink = FALSE;
1484 if (table->homogeneous)
1487 for (row = 0; row < table->nrows; row++)
1488 if (table->rows[row].expand)
1496 height = real_height;
1498 for (row = 0; row + 1 < table->nrows; row++)
1499 height -= table->rows[row].spacing;
1502 for (row = 0; row < table->nrows; row++)
1504 extra = height / (table->nrows - row);
1505 table->rows[row].allocation = MAX (1, extra);
1516 for (row = 0; row < table->nrows; row++)
1518 height += table->rows[row].requisition;
1519 if (table->rows[row].expand)
1521 if (table->rows[row].shrink)
1524 for (row = 0; row + 1 < table->nrows; row++)
1525 height += table->rows[row].spacing;
1527 /* Check to see if we were allocated more height than we requested.
1529 if ((height < real_height) && (nexpand >= 1))
1531 height = real_height - height;
1533 for (row = 0; row < table->nrows; row++)
1534 if (table->rows[row].expand)
1536 extra = height / nexpand;
1537 table->rows[row].allocation += extra;
1544 /* Check to see if we were allocated less height than we requested.
1545 * then shrink until we fit the size give.
1547 if (height > real_height)
1549 gint total_nshrink = nshrink;
1551 extra = height - real_height;
1552 while (total_nshrink > 0 && extra > 0)
1554 nshrink = total_nshrink;
1555 for (row = 0; row < table->nrows; row++)
1556 if (table->rows[row].shrink)
1558 gint allocation = table->rows[row].allocation;
1560 table->rows[row].allocation = MAX (1, (gint) table->rows[row].allocation - extra / nshrink);
1561 extra -= allocation - table->rows[row].allocation;
1563 if (table->rows[row].allocation < 2)
1566 table->rows[row].shrink = FALSE;
1575 gtk_table_size_allocate_pass2 (GtkTable *table)
1577 GtkTableChild *child;
1583 GtkAllocation allocation;
1584 GtkWidget *widget = GTK_WIDGET (table);
1586 children = table->children;
1589 child = children->data;
1590 children = children->next;
1592 if (GTK_WIDGET_VISIBLE (child->widget))
1594 GtkRequisition child_requisition;
1595 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1597 x = GTK_WIDGET (table)->allocation.x + GTK_CONTAINER (table)->border_width;
1598 y = GTK_WIDGET (table)->allocation.y + GTK_CONTAINER (table)->border_width;
1602 for (col = 0; col < child->left_attach; col++)
1604 x += table->cols[col].allocation;
1605 x += table->cols[col].spacing;
1608 for (col = child->left_attach; col < child->right_attach; col++)
1610 max_width += table->cols[col].allocation;
1611 if ((col + 1) < child->right_attach)
1612 max_width += table->cols[col].spacing;
1615 for (row = 0; row < child->top_attach; row++)
1617 y += table->rows[row].allocation;
1618 y += table->rows[row].spacing;
1621 for (row = child->top_attach; row < child->bottom_attach; row++)
1623 max_height += table->rows[row].allocation;
1624 if ((row + 1) < child->bottom_attach)
1625 max_height += table->rows[row].spacing;
1630 allocation.width = MAX (1, max_width - (gint)child->xpadding * 2);
1631 allocation.x = x + (max_width - allocation.width) / 2;
1635 allocation.width = child_requisition.width;
1636 allocation.x = x + (max_width - allocation.width) / 2;
1641 allocation.height = MAX (1, max_height - (gint)child->ypadding * 2);
1642 allocation.y = y + (max_height - allocation.height) / 2;
1646 allocation.height = child_requisition.height;
1647 allocation.y = y + (max_height - allocation.height) / 2;
1650 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1651 allocation.x = widget->allocation.x + widget->allocation.width
1652 - (allocation.x - widget->allocation.x) - allocation.width;
1654 gtk_widget_size_allocate (child->widget, &allocation);