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_ARG_LEFT_ATTACH,
44 CHILD_ARG_RIGHT_ATTACH,
46 CHILD_ARG_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_arg (GtkContainer *container,
83 static void gtk_table_get_child_arg (GtkContainer *container,
87 static GtkType gtk_table_child_type (GtkContainer *container);
90 static void gtk_table_size_request_init (GtkTable *table);
91 static void gtk_table_size_request_pass1 (GtkTable *table);
92 static void gtk_table_size_request_pass2 (GtkTable *table);
93 static void gtk_table_size_request_pass3 (GtkTable *table);
95 static void gtk_table_size_allocate_init (GtkTable *table);
96 static void gtk_table_size_allocate_pass1 (GtkTable *table);
97 static void gtk_table_size_allocate_pass2 (GtkTable *table);
100 static GtkContainerClass *parent_class = NULL;
104 gtk_table_get_type (void)
106 static GtkType table_type = 0;
110 static const GtkTypeInfo table_info =
114 sizeof (GtkTableClass),
115 (GtkClassInitFunc) gtk_table_class_init,
116 (GtkObjectInitFunc) gtk_table_init,
117 /* reserved_1 */ NULL,
118 /* reserved_2 */ NULL,
119 (GtkClassInitFunc) NULL,
122 table_type = gtk_type_unique (gtk_container_get_type (), &table_info);
129 gtk_table_class_init (GtkTableClass *class)
131 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
132 GtkObjectClass *object_class;
133 GtkWidgetClass *widget_class;
134 GtkContainerClass *container_class;
136 object_class = (GtkObjectClass*) class;
137 widget_class = (GtkWidgetClass*) class;
138 container_class = (GtkContainerClass*) class;
140 parent_class = gtk_type_class (gtk_container_get_type ());
142 gobject_class->finalize = gtk_table_finalize;
144 gobject_class->get_property = gtk_table_get_property;
145 gobject_class->set_property = gtk_table_set_property;
147 widget_class->map = gtk_table_map;
148 widget_class->unmap = gtk_table_unmap;
149 widget_class->size_request = gtk_table_size_request;
150 widget_class->size_allocate = gtk_table_size_allocate;
152 container_class->add = gtk_table_add;
153 container_class->remove = gtk_table_remove;
154 container_class->forall = gtk_table_forall;
155 container_class->child_type = gtk_table_child_type;
156 container_class->set_child_arg = gtk_table_set_child_arg;
157 container_class->get_child_arg = gtk_table_get_child_arg;
160 g_object_class_install_property (gobject_class,
162 g_param_spec_uint ("n_rows",
164 _("The number of rows in the table"),
170 g_object_class_install_property (gobject_class,
172 g_param_spec_uint ("n_columns",
174 _("The number of columns in the table"),
180 g_object_class_install_property (gobject_class,
182 g_param_spec_uint ("row_spacing",
184 _("The amount of space between two consecutive rows"),
190 g_object_class_install_property (gobject_class,
192 g_param_spec_uint ("column_spacing",
194 _("The amount of space between two consecutive columns"),
200 g_object_class_install_property (gobject_class,
202 g_param_spec_boolean ("homogeneous",
204 _("If TRUE this means the table cells are all the same width/height"),
208 gtk_container_add_child_arg_type ("GtkTable::left_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_LEFT_ATTACH);
209 gtk_container_add_child_arg_type ("GtkTable::right_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_RIGHT_ATTACH);
210 gtk_container_add_child_arg_type ("GtkTable::top_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_TOP_ATTACH);
211 gtk_container_add_child_arg_type ("GtkTable::bottom_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_BOTTOM_ATTACH);
212 gtk_container_add_child_arg_type ("GtkTable::x_options", GTK_TYPE_ATTACH_OPTIONS, GTK_ARG_READWRITE, CHILD_ARG_X_OPTIONS);
213 gtk_container_add_child_arg_type ("GtkTable::y_options", GTK_TYPE_ATTACH_OPTIONS, GTK_ARG_READWRITE, CHILD_ARG_Y_OPTIONS);
214 gtk_container_add_child_arg_type ("GtkTable::x_padding", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_X_PADDING);
215 gtk_container_add_child_arg_type ("GtkTable::y_padding", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_Y_PADDING);
219 gtk_table_child_type (GtkContainer *container)
221 return GTK_TYPE_WIDGET;
225 gtk_table_get_property (GObject *object,
232 table = GTK_TABLE (object);
237 g_value_set_uint (value, table->nrows);
240 g_value_set_uint (value, table->ncols);
242 case PROP_ROW_SPACING:
243 g_value_set_uint (value, table->row_spacing);
245 case PROP_COLUMN_SPACING:
246 g_value_set_uint (value, table->column_spacing);
248 case PROP_HOMOGENEOUS:
249 g_value_set_boolean (value, table->homogeneous);
252 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
258 gtk_table_set_property (GObject *object,
265 table = GTK_TABLE (object);
270 gtk_table_resize (table, g_value_get_uint (value), table->ncols);
273 gtk_table_resize (table, table->nrows, g_value_get_uint (value));
275 case PROP_ROW_SPACING:
276 gtk_table_set_row_spacings (table, g_value_get_uint (value));
278 case PROP_COLUMN_SPACING:
279 gtk_table_set_col_spacings (table, g_value_get_uint (value));
281 case PROP_HOMOGENEOUS:
282 gtk_table_set_homogeneous (table, g_value_get_boolean (value));
285 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
291 gtk_table_set_child_arg (GtkContainer *container,
297 GtkTableChild *table_child;
300 table = GTK_TABLE (container);
302 for (list = table->children; list; list = list->next)
304 table_child = list->data;
306 if (table_child->widget == child)
314 case CHILD_ARG_LEFT_ATTACH:
315 table_child->left_attach = GTK_VALUE_UINT (*arg);
316 if (table_child->right_attach <= table_child->left_attach)
317 table_child->right_attach = table_child->left_attach + 1;
318 if (table_child->right_attach >= table->ncols)
319 gtk_table_resize (table, table->ncols, table_child->right_attach);
321 case CHILD_ARG_RIGHT_ATTACH:
322 if (GTK_VALUE_UINT (*arg) > 0)
324 table_child->right_attach = GTK_VALUE_UINT (*arg);
325 if (table_child->right_attach <= table_child->left_attach)
326 table_child->left_attach = table_child->right_attach - 1;
327 if (table_child->right_attach >= table->ncols)
328 gtk_table_resize (table, table->ncols, table_child->right_attach);
331 case CHILD_ARG_TOP_ATTACH:
332 table_child->top_attach = GTK_VALUE_UINT (*arg);
333 if (table_child->bottom_attach <= table_child->top_attach)
334 table_child->bottom_attach = table_child->top_attach + 1;
335 if (table_child->bottom_attach >= table->nrows)
336 gtk_table_resize (table, table_child->bottom_attach, table->ncols);
338 case CHILD_ARG_BOTTOM_ATTACH:
339 if (GTK_VALUE_UINT (*arg) > 0)
341 table_child->bottom_attach = GTK_VALUE_UINT (*arg);
342 if (table_child->bottom_attach <= table_child->top_attach)
343 table_child->top_attach = table_child->bottom_attach - 1;
344 if (table_child->bottom_attach >= table->nrows)
345 gtk_table_resize (table, table_child->bottom_attach, table->ncols);
348 case CHILD_ARG_X_OPTIONS:
349 table_child->xexpand = (GTK_VALUE_FLAGS (*arg) & GTK_EXPAND) != 0;
350 table_child->xshrink = (GTK_VALUE_FLAGS (*arg) & GTK_SHRINK) != 0;
351 table_child->xfill = (GTK_VALUE_FLAGS (*arg) & GTK_FILL) != 0;
353 case CHILD_ARG_Y_OPTIONS:
354 table_child->yexpand = (GTK_VALUE_FLAGS (*arg) & GTK_EXPAND) != 0;
355 table_child->yshrink = (GTK_VALUE_FLAGS (*arg) & GTK_SHRINK) != 0;
356 table_child->yfill = (GTK_VALUE_FLAGS (*arg) & GTK_FILL) != 0;
358 case CHILD_ARG_X_PADDING:
359 table_child->xpadding = GTK_VALUE_UINT (*arg);
361 case CHILD_ARG_Y_PADDING:
362 table_child->ypadding = GTK_VALUE_UINT (*arg);
367 if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (table))
368 gtk_widget_queue_resize (child);
372 gtk_table_get_child_arg (GtkContainer *container,
378 GtkTableChild *table_child;
381 table = GTK_TABLE (container);
383 for (list = table->children; list; list = list->next)
385 table_child = list->data;
387 if (table_child->widget == child)
395 case CHILD_ARG_LEFT_ATTACH:
396 GTK_VALUE_UINT (*arg) = table_child->left_attach;
398 case CHILD_ARG_RIGHT_ATTACH:
399 GTK_VALUE_UINT (*arg) = table_child->right_attach;
401 case CHILD_ARG_TOP_ATTACH:
402 GTK_VALUE_UINT (*arg) = table_child->top_attach;
404 case CHILD_ARG_BOTTOM_ATTACH:
405 GTK_VALUE_UINT (*arg) = table_child->bottom_attach;
407 case CHILD_ARG_X_OPTIONS:
408 GTK_VALUE_FLAGS (*arg) = (table_child->xexpand * GTK_EXPAND |
409 table_child->xshrink * GTK_SHRINK |
410 table_child->xfill * GTK_FILL);
412 case CHILD_ARG_Y_OPTIONS:
413 GTK_VALUE_FLAGS (*arg) = (table_child->yexpand * GTK_EXPAND |
414 table_child->yshrink * GTK_SHRINK |
415 table_child->yfill * GTK_FILL);
417 case CHILD_ARG_X_PADDING:
418 GTK_VALUE_UINT (*arg) = table_child->xpadding;
420 case CHILD_ARG_Y_PADDING:
421 GTK_VALUE_UINT (*arg) = table_child->ypadding;
424 arg->type = GTK_TYPE_INVALID;
430 gtk_table_init (GtkTable *table)
432 GTK_WIDGET_SET_FLAGS (table, GTK_NO_WINDOW);
434 table->children = NULL;
439 table->column_spacing = 0;
440 table->row_spacing = 0;
441 table->homogeneous = FALSE;
443 gtk_table_resize (table, 1, 1);
447 gtk_table_new (guint rows,
449 gboolean homogeneous)
458 table = gtk_type_new (gtk_table_get_type ());
460 table->homogeneous = (homogeneous ? TRUE : FALSE);
462 gtk_table_resize (table, rows, columns);
464 return GTK_WIDGET (table);
468 gtk_table_resize (GtkTable *table,
472 g_return_if_fail (table != NULL);
473 g_return_if_fail (GTK_IS_TABLE (table));
475 n_rows = MAX (n_rows, 1);
476 n_cols = MAX (n_cols, 1);
478 if (n_rows != table->nrows ||
479 n_cols != table->ncols)
483 for (list = table->children; list; list = list->next)
485 GtkTableChild *child;
489 n_rows = MAX (n_rows, child->bottom_attach);
490 n_cols = MAX (n_cols, child->right_attach);
493 if (n_rows != table->nrows)
498 table->nrows = n_rows;
499 table->rows = g_realloc (table->rows, table->nrows * sizeof (GtkTableRowCol));
501 for (; i < table->nrows; i++)
503 table->rows[i].requisition = 0;
504 table->rows[i].allocation = 0;
505 table->rows[i].spacing = table->row_spacing;
506 table->rows[i].need_expand = 0;
507 table->rows[i].need_shrink = 0;
508 table->rows[i].expand = 0;
509 table->rows[i].shrink = 0;
512 g_object_notify (G_OBJECT (table), "n_rows");
515 if (n_cols != table->ncols)
520 table->ncols = n_cols;
521 table->cols = g_realloc (table->cols, table->ncols * sizeof (GtkTableRowCol));
523 for (; i < table->ncols; i++)
525 table->cols[i].requisition = 0;
526 table->cols[i].allocation = 0;
527 table->cols[i].spacing = table->column_spacing;
528 table->cols[i].need_expand = 0;
529 table->cols[i].need_shrink = 0;
530 table->cols[i].expand = 0;
531 table->cols[i].shrink = 0;
534 g_object_notify (G_OBJECT (table), "n_columns");
540 gtk_table_attach (GtkTable *table,
546 GtkAttachOptions xoptions,
547 GtkAttachOptions yoptions,
551 GtkTableChild *table_child;
553 g_return_if_fail (table != NULL);
554 g_return_if_fail (GTK_IS_TABLE (table));
555 g_return_if_fail (child != NULL);
556 g_return_if_fail (GTK_IS_WIDGET (child));
557 g_return_if_fail (child->parent == NULL);
559 /* g_return_if_fail (left_attach >= 0); */
560 g_return_if_fail (left_attach < right_attach);
561 /* g_return_if_fail (top_attach >= 0); */
562 g_return_if_fail (top_attach < bottom_attach);
564 if (right_attach >= table->ncols)
565 gtk_table_resize (table, table->nrows, right_attach);
567 if (bottom_attach >= table->nrows)
568 gtk_table_resize (table, bottom_attach, table->ncols);
570 table_child = g_new (GtkTableChild, 1);
571 table_child->widget = child;
572 table_child->left_attach = left_attach;
573 table_child->right_attach = right_attach;
574 table_child->top_attach = top_attach;
575 table_child->bottom_attach = bottom_attach;
576 table_child->xexpand = (xoptions & GTK_EXPAND) != 0;
577 table_child->xshrink = (xoptions & GTK_SHRINK) != 0;
578 table_child->xfill = (xoptions & GTK_FILL) != 0;
579 table_child->xpadding = xpadding;
580 table_child->yexpand = (yoptions & GTK_EXPAND) != 0;
581 table_child->yshrink = (yoptions & GTK_SHRINK) != 0;
582 table_child->yfill = (yoptions & GTK_FILL) != 0;
583 table_child->ypadding = ypadding;
585 table->children = g_list_prepend (table->children, table_child);
587 gtk_widget_set_parent (child, GTK_WIDGET (table));
589 if (GTK_WIDGET_REALIZED (child->parent))
590 gtk_widget_realize (child);
592 if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child))
594 if (GTK_WIDGET_MAPPED (child->parent))
595 gtk_widget_map (child);
597 gtk_widget_queue_resize (child);
602 gtk_table_attach_defaults (GtkTable *table,
609 gtk_table_attach (table, widget,
610 left_attach, right_attach,
611 top_attach, bottom_attach,
612 GTK_EXPAND | GTK_FILL,
613 GTK_EXPAND | GTK_FILL,
618 gtk_table_set_row_spacing (GtkTable *table,
622 g_return_if_fail (table != NULL);
623 g_return_if_fail (GTK_IS_TABLE (table));
624 g_return_if_fail (row < table->nrows);
626 if (table->rows[row].spacing != spacing)
628 table->rows[row].spacing = spacing;
630 if (GTK_WIDGET_VISIBLE (table))
631 gtk_widget_queue_resize (GTK_WIDGET (table));
634 g_object_notify (G_OBJECT (table), "row_spacing");
638 gtk_table_set_col_spacing (GtkTable *table,
642 g_return_if_fail (table != NULL);
643 g_return_if_fail (GTK_IS_TABLE (table));
644 g_return_if_fail (column < table->ncols);
646 if (table->cols[column].spacing != spacing)
648 table->cols[column].spacing = spacing;
650 if (GTK_WIDGET_VISIBLE (table))
651 gtk_widget_queue_resize (GTK_WIDGET (table));
654 g_object_notify (G_OBJECT (table), "column_spacing");
658 gtk_table_set_row_spacings (GtkTable *table,
663 g_return_if_fail (table != NULL);
664 g_return_if_fail (GTK_IS_TABLE (table));
666 table->row_spacing = spacing;
667 for (row = 0; row < table->nrows; row++)
668 table->rows[row].spacing = spacing;
670 if (GTK_WIDGET_VISIBLE (table))
671 gtk_widget_queue_resize (GTK_WIDGET (table));
675 gtk_table_set_col_spacings (GtkTable *table,
680 g_return_if_fail (table != NULL);
681 g_return_if_fail (GTK_IS_TABLE (table));
683 table->column_spacing = spacing;
684 for (col = 0; col < table->ncols; col++)
685 table->cols[col].spacing = spacing;
687 if (GTK_WIDGET_VISIBLE (table))
688 gtk_widget_queue_resize (GTK_WIDGET (table));
692 gtk_table_set_homogeneous (GtkTable *table,
693 gboolean homogeneous)
695 g_return_if_fail (table != NULL);
696 g_return_if_fail (GTK_IS_TABLE (table));
698 homogeneous = (homogeneous != 0);
699 if (homogeneous != table->homogeneous)
701 table->homogeneous = homogeneous;
703 if (GTK_WIDGET_VISIBLE (table))
704 gtk_widget_queue_resize (GTK_WIDGET (table));
709 gtk_table_finalize (GObject *object)
713 g_return_if_fail (GTK_IS_TABLE (object));
715 table = GTK_TABLE (object);
717 g_free (table->rows);
718 g_free (table->cols);
720 G_OBJECT_CLASS (parent_class)->finalize (object);
724 gtk_table_map (GtkWidget *widget)
727 GtkTableChild *child;
730 g_return_if_fail (widget != NULL);
731 g_return_if_fail (GTK_IS_TABLE (widget));
733 table = GTK_TABLE (widget);
734 GTK_WIDGET_SET_FLAGS (table, GTK_MAPPED);
736 children = table->children;
739 child = children->data;
740 children = children->next;
742 if (GTK_WIDGET_VISIBLE (child->widget) &&
743 !GTK_WIDGET_MAPPED (child->widget))
744 gtk_widget_map (child->widget);
749 gtk_table_unmap (GtkWidget *widget)
752 GtkTableChild *child;
755 g_return_if_fail (widget != NULL);
756 g_return_if_fail (GTK_IS_TABLE (widget));
758 table = GTK_TABLE (widget);
759 GTK_WIDGET_UNSET_FLAGS (table, GTK_MAPPED);
761 children = table->children;
764 child = children->data;
765 children = children->next;
767 if (GTK_WIDGET_VISIBLE (child->widget) &&
768 GTK_WIDGET_MAPPED (child->widget))
769 gtk_widget_unmap (child->widget);
774 gtk_table_size_request (GtkWidget *widget,
775 GtkRequisition *requisition)
780 g_return_if_fail (widget != NULL);
781 g_return_if_fail (GTK_IS_TABLE (widget));
782 g_return_if_fail (requisition != NULL);
784 table = GTK_TABLE (widget);
786 requisition->width = 0;
787 requisition->height = 0;
789 gtk_table_size_request_init (table);
790 gtk_table_size_request_pass1 (table);
791 gtk_table_size_request_pass2 (table);
792 gtk_table_size_request_pass3 (table);
793 gtk_table_size_request_pass2 (table);
795 for (col = 0; col < table->ncols; col++)
796 requisition->width += table->cols[col].requisition;
797 for (col = 0; col + 1 < table->ncols; col++)
798 requisition->width += table->cols[col].spacing;
800 for (row = 0; row < table->nrows; row++)
801 requisition->height += table->rows[row].requisition;
802 for (row = 0; row + 1 < table->nrows; row++)
803 requisition->height += table->rows[row].spacing;
805 requisition->width += GTK_CONTAINER (table)->border_width * 2;
806 requisition->height += GTK_CONTAINER (table)->border_width * 2;
810 gtk_table_size_allocate (GtkWidget *widget,
811 GtkAllocation *allocation)
815 g_return_if_fail (widget != NULL);
816 g_return_if_fail (GTK_IS_TABLE (widget));
817 g_return_if_fail (allocation != NULL);
819 widget->allocation = *allocation;
820 table = GTK_TABLE (widget);
822 gtk_table_size_allocate_init (table);
823 gtk_table_size_allocate_pass1 (table);
824 gtk_table_size_allocate_pass2 (table);
828 gtk_table_add (GtkContainer *container,
831 g_return_if_fail (container != NULL);
832 g_return_if_fail (GTK_IS_TABLE (container));
833 g_return_if_fail (widget != NULL);
835 gtk_table_attach_defaults (GTK_TABLE (container), widget, 0, 1, 0, 1);
839 gtk_table_remove (GtkContainer *container,
843 GtkTableChild *child;
846 g_return_if_fail (container != NULL);
847 g_return_if_fail (GTK_IS_TABLE (container));
848 g_return_if_fail (widget != NULL);
850 table = GTK_TABLE (container);
851 children = table->children;
855 child = children->data;
856 children = children->next;
858 if (child->widget == widget)
860 gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
862 gtk_widget_unparent (widget);
864 table->children = g_list_remove (table->children, child);
867 if (was_visible && GTK_WIDGET_VISIBLE (container))
868 gtk_container_queue_resize (container);
875 gtk_table_forall (GtkContainer *container,
876 gboolean include_internals,
877 GtkCallback callback,
878 gpointer callback_data)
881 GtkTableChild *child;
884 g_return_if_fail (container != NULL);
885 g_return_if_fail (GTK_IS_TABLE (container));
886 g_return_if_fail (callback != NULL);
888 table = GTK_TABLE (container);
889 children = table->children;
893 child = children->data;
894 children = children->next;
896 (* callback) (child->widget, callback_data);
901 gtk_table_size_request_init (GtkTable *table)
903 GtkTableChild *child;
907 for (row = 0; row < table->nrows; row++)
908 table->rows[row].requisition = 0;
909 for (col = 0; col < table->ncols; col++)
910 table->cols[col].requisition = 0;
912 children = table->children;
915 child = children->data;
916 children = children->next;
918 if (GTK_WIDGET_VISIBLE (child->widget))
919 gtk_widget_size_request (child->widget, NULL);
924 gtk_table_size_request_pass1 (GtkTable *table)
926 GtkTableChild *child;
931 children = table->children;
934 child = children->data;
935 children = children->next;
937 if (GTK_WIDGET_VISIBLE (child->widget))
939 GtkRequisition child_requisition;
940 gtk_widget_get_child_requisition (child->widget, &child_requisition);
942 /* Child spans a single column.
944 if (child->left_attach == (child->right_attach - 1))
946 width = child_requisition.width + child->xpadding * 2;
947 table->cols[child->left_attach].requisition = MAX (table->cols[child->left_attach].requisition, width);
950 /* Child spans a single row.
952 if (child->top_attach == (child->bottom_attach - 1))
954 height = child_requisition.height + child->ypadding * 2;
955 table->rows[child->top_attach].requisition = MAX (table->rows[child->top_attach].requisition, height);
962 gtk_table_size_request_pass2 (GtkTable *table)
968 if (table->homogeneous)
973 for (col = 0; col < table->ncols; col++)
974 max_width = MAX (max_width, table->cols[col].requisition);
975 for (row = 0; row < table->nrows; row++)
976 max_height = MAX (max_height, table->rows[row].requisition);
978 for (col = 0; col < table->ncols; col++)
979 table->cols[col].requisition = max_width;
980 for (row = 0; row < table->nrows; row++)
981 table->rows[row].requisition = max_height;
986 gtk_table_size_request_pass3 (GtkTable *table)
988 GtkTableChild *child;
994 children = table->children;
997 child = children->data;
998 children = children->next;
1000 if (GTK_WIDGET_VISIBLE (child->widget))
1002 /* Child spans multiple columns.
1004 if (child->left_attach != (child->right_attach - 1))
1006 GtkRequisition child_requisition;
1008 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1010 /* Check and see if there is already enough space
1014 for (col = child->left_attach; col < child->right_attach; col++)
1016 width += table->cols[col].requisition;
1017 if ((col + 1) < child->right_attach)
1018 width += table->cols[col].spacing;
1021 /* If we need to request more space for this child to fill
1022 * its requisition, then divide up the needed space evenly
1023 * amongst the columns it spans.
1025 if (width < child_requisition.width + child->xpadding * 2)
1027 width = child_requisition.width + child->xpadding * 2 - width;
1029 for (col = child->left_attach; col < child->right_attach; col++)
1031 extra = width / (child->right_attach - col);
1032 table->cols[col].requisition += extra;
1038 /* Child spans multiple rows.
1040 if (child->top_attach != (child->bottom_attach - 1))
1042 GtkRequisition child_requisition;
1044 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1046 /* Check and see if there is already enough space
1050 for (row = child->top_attach; row < child->bottom_attach; row++)
1052 height += table->rows[row].requisition;
1053 if ((row + 1) < child->bottom_attach)
1054 height += table->rows[row].spacing;
1057 /* If we need to request more space for this child to fill
1058 * its requisition, then divide up the needed space evenly
1059 * amongst the columns it spans.
1061 if (height < child_requisition.height + child->ypadding * 2)
1063 height = child_requisition.height + child->ypadding * 2 - height;
1065 for (row = child->top_attach; row < child->bottom_attach; row++)
1067 extra = height / (child->bottom_attach - row);
1068 table->rows[row].requisition += extra;
1078 gtk_table_size_allocate_init (GtkTable *table)
1080 GtkTableChild *child;
1086 /* Initialize the rows and cols.
1087 * By default, rows and cols do not expand and do shrink.
1088 * Those values are modified by the children that occupy
1089 * the rows and cols.
1091 for (col = 0; col < table->ncols; col++)
1093 table->cols[col].allocation = table->cols[col].requisition;
1094 table->cols[col].need_expand = FALSE;
1095 table->cols[col].need_shrink = TRUE;
1096 table->cols[col].expand = FALSE;
1097 table->cols[col].shrink = TRUE;
1098 table->cols[col].empty = TRUE;
1100 for (row = 0; row < table->nrows; row++)
1102 table->rows[row].allocation = table->rows[row].requisition;
1103 table->rows[row].need_expand = FALSE;
1104 table->rows[row].need_shrink = TRUE;
1105 table->rows[row].expand = FALSE;
1106 table->rows[row].shrink = TRUE;
1107 table->rows[row].empty = TRUE;
1110 /* Loop over all the children and adjust the row and col values
1111 * based on whether the children want to be allowed to expand
1112 * or shrink. This loop handles children that occupy a single
1115 children = table->children;
1118 child = children->data;
1119 children = children->next;
1121 if (GTK_WIDGET_VISIBLE (child->widget))
1123 if (child->left_attach == (child->right_attach - 1))
1126 table->cols[child->left_attach].expand = TRUE;
1128 if (!child->xshrink)
1129 table->cols[child->left_attach].shrink = FALSE;
1131 table->cols[child->left_attach].empty = FALSE;
1134 if (child->top_attach == (child->bottom_attach - 1))
1137 table->rows[child->top_attach].expand = TRUE;
1139 if (!child->yshrink)
1140 table->rows[child->top_attach].shrink = FALSE;
1142 table->rows[child->top_attach].empty = FALSE;
1147 /* Loop over all the children again and this time handle children
1148 * which span multiple rows or columns.
1150 children = table->children;
1153 child = children->data;
1154 children = children->next;
1156 if (GTK_WIDGET_VISIBLE (child->widget))
1158 if (child->left_attach != (child->right_attach - 1))
1160 for (col = child->left_attach; col < child->right_attach; col++)
1161 table->cols[col].empty = FALSE;
1166 for (col = child->left_attach; col < child->right_attach; col++)
1167 if (table->cols[col].expand)
1174 for (col = child->left_attach; col < child->right_attach; col++)
1175 table->cols[col].need_expand = TRUE;
1178 if (!child->xshrink)
1181 for (col = child->left_attach; col < child->right_attach; col++)
1182 if (!table->cols[col].shrink)
1189 for (col = child->left_attach; col < child->right_attach; col++)
1190 table->cols[col].need_shrink = FALSE;
1194 if (child->top_attach != (child->bottom_attach - 1))
1196 for (row = child->top_attach; row < child->bottom_attach; row++)
1197 table->rows[row].empty = FALSE;
1202 for (row = child->top_attach; row < child->bottom_attach; row++)
1203 if (table->rows[row].expand)
1210 for (row = child->top_attach; row < child->bottom_attach; row++)
1211 table->rows[row].need_expand = TRUE;
1214 if (!child->yshrink)
1217 for (row = child->top_attach; row < child->bottom_attach; row++)
1218 if (!table->rows[row].shrink)
1225 for (row = child->top_attach; row < child->bottom_attach; row++)
1226 table->rows[row].need_shrink = FALSE;
1232 /* Loop over the columns and set the expand and shrink values
1233 * if the column can be expanded or shrunk.
1235 for (col = 0; col < table->ncols; col++)
1237 if (table->cols[col].empty)
1239 table->cols[col].expand = FALSE;
1240 table->cols[col].shrink = FALSE;
1244 if (table->cols[col].need_expand)
1245 table->cols[col].expand = TRUE;
1246 if (!table->cols[col].need_shrink)
1247 table->cols[col].shrink = FALSE;
1251 /* Loop over the rows and set the expand and shrink values
1252 * if the row can be expanded or shrunk.
1254 for (row = 0; row < table->nrows; row++)
1256 if (table->rows[row].empty)
1258 table->rows[row].expand = FALSE;
1259 table->rows[row].shrink = FALSE;
1263 if (table->rows[row].need_expand)
1264 table->rows[row].expand = TRUE;
1265 if (!table->rows[row].need_shrink)
1266 table->rows[row].shrink = FALSE;
1272 gtk_table_size_allocate_pass1 (GtkTable *table)
1282 /* If we were allocated more space than we requested
1283 * then we have to expand any expandable rows and columns
1284 * to fill in the extra space.
1287 real_width = GTK_WIDGET (table)->allocation.width - GTK_CONTAINER (table)->border_width * 2;
1288 real_height = GTK_WIDGET (table)->allocation.height - GTK_CONTAINER (table)->border_width * 2;
1290 if (table->homogeneous)
1293 for (col = 0; col < table->ncols; col++)
1294 if (table->cols[col].expand)
1304 for (col = 0; col + 1 < table->ncols; col++)
1305 width -= table->cols[col].spacing;
1307 for (col = 0; col < table->ncols; col++)
1309 extra = width / (table->ncols - col);
1310 table->cols[col].allocation = MAX (1, extra);
1321 for (col = 0; col < table->ncols; col++)
1323 width += table->cols[col].requisition;
1324 if (table->cols[col].expand)
1326 if (table->cols[col].shrink)
1329 for (col = 0; col + 1 < table->ncols; col++)
1330 width += table->cols[col].spacing;
1332 /* Check to see if we were allocated more width than we requested.
1334 if ((width < real_width) && (nexpand >= 1))
1336 width = real_width - width;
1338 for (col = 0; col < table->ncols; col++)
1339 if (table->cols[col].expand)
1341 extra = width / nexpand;
1342 table->cols[col].allocation += extra;
1349 /* Check to see if we were allocated less width than we requested,
1350 * then shrink until we fit the size give.
1352 if (width > real_width)
1354 gint total_nshrink = nshrink;
1356 extra = width - real_width;
1357 while (total_nshrink > 0 && extra > 0)
1359 nshrink = total_nshrink;
1360 for (col = 0; col < table->ncols; col++)
1361 if (table->cols[col].shrink)
1363 gint allocation = table->cols[col].allocation;
1365 table->cols[col].allocation = MAX (1, (gint) table->cols[col].allocation - extra / nshrink);
1366 extra -= allocation - table->cols[col].allocation;
1368 if (table->cols[col].allocation < 2)
1371 table->cols[col].shrink = FALSE;
1378 if (table->homogeneous)
1381 for (row = 0; row < table->nrows; row++)
1382 if (table->rows[row].expand)
1390 height = real_height;
1392 for (row = 0; row + 1 < table->nrows; row++)
1393 height -= table->rows[row].spacing;
1396 for (row = 0; row < table->nrows; row++)
1398 extra = height / (table->nrows - row);
1399 table->rows[row].allocation = MAX (1, extra);
1410 for (row = 0; row < table->nrows; row++)
1412 height += table->rows[row].requisition;
1413 if (table->rows[row].expand)
1415 if (table->rows[row].shrink)
1418 for (row = 0; row + 1 < table->nrows; row++)
1419 height += table->rows[row].spacing;
1421 /* Check to see if we were allocated more height than we requested.
1423 if ((height < real_height) && (nexpand >= 1))
1425 height = real_height - height;
1427 for (row = 0; row < table->nrows; row++)
1428 if (table->rows[row].expand)
1430 extra = height / nexpand;
1431 table->rows[row].allocation += extra;
1438 /* Check to see if we were allocated less height than we requested.
1439 * then shrink until we fit the size give.
1441 if (height > real_height)
1443 gint total_nshrink = nshrink;
1445 extra = height - real_height;
1446 while (total_nshrink > 0 && extra > 0)
1448 nshrink = total_nshrink;
1449 for (row = 0; row < table->nrows; row++)
1450 if (table->rows[row].shrink)
1452 gint allocation = table->rows[row].allocation;
1454 table->rows[row].allocation = MAX (1, (gint) table->rows[row].allocation - extra / nshrink);
1455 extra -= allocation - table->rows[row].allocation;
1457 if (table->rows[row].allocation < 2)
1460 table->rows[row].shrink = FALSE;
1469 gtk_table_size_allocate_pass2 (GtkTable *table)
1471 GtkTableChild *child;
1477 GtkAllocation allocation;
1478 GtkWidget *widget = GTK_WIDGET (table);
1480 children = table->children;
1483 child = children->data;
1484 children = children->next;
1486 if (GTK_WIDGET_VISIBLE (child->widget))
1488 GtkRequisition child_requisition;
1489 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1491 x = GTK_WIDGET (table)->allocation.x + GTK_CONTAINER (table)->border_width;
1492 y = GTK_WIDGET (table)->allocation.y + GTK_CONTAINER (table)->border_width;
1496 for (col = 0; col < child->left_attach; col++)
1498 x += table->cols[col].allocation;
1499 x += table->cols[col].spacing;
1502 for (col = child->left_attach; col < child->right_attach; col++)
1504 max_width += table->cols[col].allocation;
1505 if ((col + 1) < child->right_attach)
1506 max_width += table->cols[col].spacing;
1509 for (row = 0; row < child->top_attach; row++)
1511 y += table->rows[row].allocation;
1512 y += table->rows[row].spacing;
1515 for (row = child->top_attach; row < child->bottom_attach; row++)
1517 max_height += table->rows[row].allocation;
1518 if ((row + 1) < child->bottom_attach)
1519 max_height += table->rows[row].spacing;
1524 allocation.width = MAX (1, max_width - (gint)child->xpadding * 2);
1525 allocation.x = x + (max_width - allocation.width) / 2;
1529 allocation.width = child_requisition.width;
1530 allocation.x = x + (max_width - allocation.width) / 2;
1535 allocation.height = MAX (1, max_height - (gint)child->ypadding * 2);
1536 allocation.y = y + (max_height - allocation.height) / 2;
1540 allocation.height = child_requisition.height;
1541 allocation.y = y + (max_height - allocation.height) / 2;
1544 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1545 allocation.x = widget->allocation.x + widget->allocation.width
1546 - (allocation.x - widget->allocation.x) - allocation.width;
1548 gtk_widget_size_allocate (child->widget, &allocation);