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/.
42 CHILD_ARG_LEFT_ATTACH,
43 CHILD_ARG_RIGHT_ATTACH,
45 CHILD_ARG_BOTTOM_ATTACH,
53 static void gtk_table_class_init (GtkTableClass *klass);
54 static void gtk_table_init (GtkTable *table);
55 static void gtk_table_finalize (GObject *object);
56 static void gtk_table_map (GtkWidget *widget);
57 static void gtk_table_unmap (GtkWidget *widget);
58 static void gtk_table_size_request (GtkWidget *widget,
59 GtkRequisition *requisition);
60 static void gtk_table_size_allocate (GtkWidget *widget,
61 GtkAllocation *allocation);
62 static void gtk_table_add (GtkContainer *container,
64 static void gtk_table_remove (GtkContainer *container,
66 static void gtk_table_forall (GtkContainer *container,
67 gboolean include_internals,
69 gpointer callback_data);
70 static void gtk_table_get_arg (GtkObject *object,
73 static void gtk_table_set_arg (GtkObject *object,
76 static void gtk_table_set_child_arg (GtkContainer *container,
80 static void gtk_table_get_child_arg (GtkContainer *container,
84 static GtkType gtk_table_child_type (GtkContainer *container);
87 static void gtk_table_size_request_init (GtkTable *table);
88 static void gtk_table_size_request_pass1 (GtkTable *table);
89 static void gtk_table_size_request_pass2 (GtkTable *table);
90 static void gtk_table_size_request_pass3 (GtkTable *table);
92 static void gtk_table_size_allocate_init (GtkTable *table);
93 static void gtk_table_size_allocate_pass1 (GtkTable *table);
94 static void gtk_table_size_allocate_pass2 (GtkTable *table);
97 static GtkContainerClass *parent_class = NULL;
101 gtk_table_get_type (void)
103 static GtkType table_type = 0;
107 static const GtkTypeInfo table_info =
111 sizeof (GtkTableClass),
112 (GtkClassInitFunc) gtk_table_class_init,
113 (GtkObjectInitFunc) gtk_table_init,
114 /* reserved_1 */ NULL,
115 /* reserved_2 */ NULL,
116 (GtkClassInitFunc) NULL,
119 table_type = gtk_type_unique (gtk_container_get_type (), &table_info);
126 gtk_table_class_init (GtkTableClass *class)
128 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
129 GtkObjectClass *object_class;
130 GtkWidgetClass *widget_class;
131 GtkContainerClass *container_class;
133 object_class = (GtkObjectClass*) class;
134 widget_class = (GtkWidgetClass*) class;
135 container_class = (GtkContainerClass*) class;
137 parent_class = gtk_type_class (gtk_container_get_type ());
139 gobject_class->finalize = gtk_table_finalize;
141 object_class->get_arg = gtk_table_get_arg;
142 object_class->set_arg = gtk_table_set_arg;
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_arg = gtk_table_set_child_arg;
154 container_class->get_child_arg = gtk_table_get_child_arg;
156 gtk_object_add_arg_type ("GtkTable::n_rows", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_N_ROWS);
157 gtk_object_add_arg_type ("GtkTable::n_columns", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_N_COLUMNS);
158 gtk_object_add_arg_type ("GtkTable::row_spacing", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_ROW_SPACING);
159 gtk_object_add_arg_type ("GtkTable::column_spacing", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_COLUMN_SPACING);
160 gtk_object_add_arg_type ("GtkTable::homogeneous", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_HOMOGENEOUS);
161 gtk_container_add_child_arg_type ("GtkTable::left_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_LEFT_ATTACH);
162 gtk_container_add_child_arg_type ("GtkTable::right_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_RIGHT_ATTACH);
163 gtk_container_add_child_arg_type ("GtkTable::top_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_TOP_ATTACH);
164 gtk_container_add_child_arg_type ("GtkTable::bottom_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_BOTTOM_ATTACH);
165 gtk_container_add_child_arg_type ("GtkTable::x_options", GTK_TYPE_ATTACH_OPTIONS, GTK_ARG_READWRITE, CHILD_ARG_X_OPTIONS);
166 gtk_container_add_child_arg_type ("GtkTable::y_options", GTK_TYPE_ATTACH_OPTIONS, GTK_ARG_READWRITE, CHILD_ARG_Y_OPTIONS);
167 gtk_container_add_child_arg_type ("GtkTable::x_padding", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_X_PADDING);
168 gtk_container_add_child_arg_type ("GtkTable::y_padding", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_Y_PADDING);
172 gtk_table_child_type (GtkContainer *container)
174 return GTK_TYPE_WIDGET;
178 gtk_table_get_arg (GtkObject *object,
184 table = GTK_TABLE (object);
189 GTK_VALUE_UINT (*arg) = table->nrows;
192 GTK_VALUE_UINT (*arg) = table->ncols;
194 case ARG_ROW_SPACING:
195 GTK_VALUE_UINT (*arg) = table->row_spacing;
197 case ARG_COLUMN_SPACING:
198 GTK_VALUE_UINT (*arg) = table->column_spacing;
200 case ARG_HOMOGENEOUS:
201 GTK_VALUE_BOOL (*arg) = table->homogeneous;
204 arg->type = GTK_TYPE_INVALID;
210 gtk_table_set_arg (GtkObject *object,
216 table = GTK_TABLE (object);
221 gtk_table_resize (table, GTK_VALUE_UINT (*arg), table->ncols);
224 gtk_table_resize (table, table->nrows, GTK_VALUE_UINT (*arg));
226 case ARG_ROW_SPACING:
227 gtk_table_set_row_spacings (table, GTK_VALUE_UINT (*arg));
229 case ARG_COLUMN_SPACING:
230 gtk_table_set_col_spacings (table, GTK_VALUE_UINT (*arg));
232 case ARG_HOMOGENEOUS:
233 gtk_table_set_homogeneous (table, GTK_VALUE_BOOL (*arg));
241 gtk_table_set_child_arg (GtkContainer *container,
247 GtkTableChild *table_child;
250 table = GTK_TABLE (container);
252 for (list = table->children; list; list = list->next)
254 table_child = list->data;
256 if (table_child->widget == child)
264 case CHILD_ARG_LEFT_ATTACH:
265 table_child->left_attach = GTK_VALUE_UINT (*arg);
266 if (table_child->right_attach <= table_child->left_attach)
267 table_child->right_attach = table_child->left_attach + 1;
268 if (table_child->right_attach >= table->ncols)
269 gtk_table_resize (table, table->ncols, table_child->right_attach);
271 case CHILD_ARG_RIGHT_ATTACH:
272 if (GTK_VALUE_UINT (*arg) > 0)
274 table_child->right_attach = GTK_VALUE_UINT (*arg);
275 if (table_child->right_attach <= table_child->left_attach)
276 table_child->left_attach = table_child->right_attach - 1;
277 if (table_child->right_attach >= table->ncols)
278 gtk_table_resize (table, table->ncols, table_child->right_attach);
281 case CHILD_ARG_TOP_ATTACH:
282 table_child->top_attach = GTK_VALUE_UINT (*arg);
283 if (table_child->bottom_attach <= table_child->top_attach)
284 table_child->bottom_attach = table_child->top_attach + 1;
285 if (table_child->bottom_attach >= table->nrows)
286 gtk_table_resize (table, table_child->bottom_attach, table->ncols);
288 case CHILD_ARG_BOTTOM_ATTACH:
289 if (GTK_VALUE_UINT (*arg) > 0)
291 table_child->bottom_attach = GTK_VALUE_UINT (*arg);
292 if (table_child->bottom_attach <= table_child->top_attach)
293 table_child->top_attach = table_child->bottom_attach - 1;
294 if (table_child->bottom_attach >= table->nrows)
295 gtk_table_resize (table, table_child->bottom_attach, table->ncols);
298 case CHILD_ARG_X_OPTIONS:
299 table_child->xexpand = (GTK_VALUE_FLAGS (*arg) & GTK_EXPAND) != 0;
300 table_child->xshrink = (GTK_VALUE_FLAGS (*arg) & GTK_SHRINK) != 0;
301 table_child->xfill = (GTK_VALUE_FLAGS (*arg) & GTK_FILL) != 0;
303 case CHILD_ARG_Y_OPTIONS:
304 table_child->yexpand = (GTK_VALUE_FLAGS (*arg) & GTK_EXPAND) != 0;
305 table_child->yshrink = (GTK_VALUE_FLAGS (*arg) & GTK_SHRINK) != 0;
306 table_child->yfill = (GTK_VALUE_FLAGS (*arg) & GTK_FILL) != 0;
308 case CHILD_ARG_X_PADDING:
309 table_child->xpadding = GTK_VALUE_UINT (*arg);
311 case CHILD_ARG_Y_PADDING:
312 table_child->ypadding = GTK_VALUE_UINT (*arg);
317 if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (table))
318 gtk_widget_queue_resize (child);
322 gtk_table_get_child_arg (GtkContainer *container,
328 GtkTableChild *table_child;
331 table = GTK_TABLE (container);
333 for (list = table->children; list; list = list->next)
335 table_child = list->data;
337 if (table_child->widget == child)
345 case CHILD_ARG_LEFT_ATTACH:
346 GTK_VALUE_UINT (*arg) = table_child->left_attach;
348 case CHILD_ARG_RIGHT_ATTACH:
349 GTK_VALUE_UINT (*arg) = table_child->right_attach;
351 case CHILD_ARG_TOP_ATTACH:
352 GTK_VALUE_UINT (*arg) = table_child->top_attach;
354 case CHILD_ARG_BOTTOM_ATTACH:
355 GTK_VALUE_UINT (*arg) = table_child->bottom_attach;
357 case CHILD_ARG_X_OPTIONS:
358 GTK_VALUE_FLAGS (*arg) = (table_child->xexpand * GTK_EXPAND |
359 table_child->xshrink * GTK_SHRINK |
360 table_child->xfill * GTK_FILL);
362 case CHILD_ARG_Y_OPTIONS:
363 GTK_VALUE_FLAGS (*arg) = (table_child->yexpand * GTK_EXPAND |
364 table_child->yshrink * GTK_SHRINK |
365 table_child->yfill * GTK_FILL);
367 case CHILD_ARG_X_PADDING:
368 GTK_VALUE_UINT (*arg) = table_child->xpadding;
370 case CHILD_ARG_Y_PADDING:
371 GTK_VALUE_UINT (*arg) = table_child->ypadding;
374 arg->type = GTK_TYPE_INVALID;
380 gtk_table_init (GtkTable *table)
382 GTK_WIDGET_SET_FLAGS (table, GTK_NO_WINDOW);
384 table->children = NULL;
389 table->column_spacing = 0;
390 table->row_spacing = 0;
391 table->homogeneous = FALSE;
393 gtk_table_resize (table, 1, 1);
397 gtk_table_new (guint rows,
399 gboolean homogeneous)
408 table = gtk_type_new (gtk_table_get_type ());
410 table->homogeneous = (homogeneous ? TRUE : FALSE);
412 gtk_table_resize (table, rows, columns);
414 return GTK_WIDGET (table);
418 gtk_table_resize (GtkTable *table,
422 g_return_if_fail (table != NULL);
423 g_return_if_fail (GTK_IS_TABLE (table));
425 n_rows = MAX (n_rows, 1);
426 n_cols = MAX (n_cols, 1);
428 if (n_rows != table->nrows ||
429 n_cols != table->ncols)
433 for (list = table->children; list; list = list->next)
435 GtkTableChild *child;
439 n_rows = MAX (n_rows, child->bottom_attach);
440 n_cols = MAX (n_cols, child->right_attach);
443 if (n_rows != table->nrows)
448 table->nrows = n_rows;
449 table->rows = g_realloc (table->rows, table->nrows * sizeof (GtkTableRowCol));
451 for (; i < table->nrows; i++)
453 table->rows[i].requisition = 0;
454 table->rows[i].allocation = 0;
455 table->rows[i].spacing = table->row_spacing;
456 table->rows[i].need_expand = 0;
457 table->rows[i].need_shrink = 0;
458 table->rows[i].expand = 0;
459 table->rows[i].shrink = 0;
463 if (n_cols != table->ncols)
468 table->ncols = n_cols;
469 table->cols = g_realloc (table->cols, table->ncols * sizeof (GtkTableRowCol));
471 for (; i < table->ncols; i++)
473 table->cols[i].requisition = 0;
474 table->cols[i].allocation = 0;
475 table->cols[i].spacing = table->column_spacing;
476 table->cols[i].need_expand = 0;
477 table->cols[i].need_shrink = 0;
478 table->cols[i].expand = 0;
479 table->cols[i].shrink = 0;
486 gtk_table_attach (GtkTable *table,
492 GtkAttachOptions xoptions,
493 GtkAttachOptions yoptions,
497 GtkTableChild *table_child;
499 g_return_if_fail (table != NULL);
500 g_return_if_fail (GTK_IS_TABLE (table));
501 g_return_if_fail (child != NULL);
502 g_return_if_fail (GTK_IS_WIDGET (child));
503 g_return_if_fail (child->parent == NULL);
505 /* g_return_if_fail (left_attach >= 0); */
506 g_return_if_fail (left_attach < right_attach);
507 /* g_return_if_fail (top_attach >= 0); */
508 g_return_if_fail (top_attach < bottom_attach);
510 if (right_attach >= table->ncols)
511 gtk_table_resize (table, table->nrows, right_attach);
513 if (bottom_attach >= table->nrows)
514 gtk_table_resize (table, bottom_attach, table->ncols);
516 table_child = g_new (GtkTableChild, 1);
517 table_child->widget = child;
518 table_child->left_attach = left_attach;
519 table_child->right_attach = right_attach;
520 table_child->top_attach = top_attach;
521 table_child->bottom_attach = bottom_attach;
522 table_child->xexpand = (xoptions & GTK_EXPAND) != 0;
523 table_child->xshrink = (xoptions & GTK_SHRINK) != 0;
524 table_child->xfill = (xoptions & GTK_FILL) != 0;
525 table_child->xpadding = xpadding;
526 table_child->yexpand = (yoptions & GTK_EXPAND) != 0;
527 table_child->yshrink = (yoptions & GTK_SHRINK) != 0;
528 table_child->yfill = (yoptions & GTK_FILL) != 0;
529 table_child->ypadding = ypadding;
531 table->children = g_list_prepend (table->children, table_child);
533 gtk_widget_set_parent (child, GTK_WIDGET (table));
535 if (GTK_WIDGET_REALIZED (child->parent))
536 gtk_widget_realize (child);
538 if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child))
540 if (GTK_WIDGET_MAPPED (child->parent))
541 gtk_widget_map (child);
543 gtk_widget_queue_resize (child);
548 gtk_table_attach_defaults (GtkTable *table,
555 gtk_table_attach (table, widget,
556 left_attach, right_attach,
557 top_attach, bottom_attach,
558 GTK_EXPAND | GTK_FILL,
559 GTK_EXPAND | GTK_FILL,
564 gtk_table_set_row_spacing (GtkTable *table,
568 g_return_if_fail (table != NULL);
569 g_return_if_fail (GTK_IS_TABLE (table));
570 g_return_if_fail (row < table->nrows);
572 if (table->rows[row].spacing != spacing)
574 table->rows[row].spacing = spacing;
576 if (GTK_WIDGET_VISIBLE (table))
577 gtk_widget_queue_resize (GTK_WIDGET (table));
582 gtk_table_set_col_spacing (GtkTable *table,
586 g_return_if_fail (table != NULL);
587 g_return_if_fail (GTK_IS_TABLE (table));
588 g_return_if_fail (column < table->ncols);
590 if (table->cols[column].spacing != spacing)
592 table->cols[column].spacing = spacing;
594 if (GTK_WIDGET_VISIBLE (table))
595 gtk_widget_queue_resize (GTK_WIDGET (table));
600 gtk_table_set_row_spacings (GtkTable *table,
605 g_return_if_fail (table != NULL);
606 g_return_if_fail (GTK_IS_TABLE (table));
608 table->row_spacing = spacing;
609 for (row = 0; row < table->nrows; row++)
610 table->rows[row].spacing = spacing;
612 if (GTK_WIDGET_VISIBLE (table))
613 gtk_widget_queue_resize (GTK_WIDGET (table));
617 gtk_table_set_col_spacings (GtkTable *table,
622 g_return_if_fail (table != NULL);
623 g_return_if_fail (GTK_IS_TABLE (table));
625 table->column_spacing = spacing;
626 for (col = 0; col < table->ncols; col++)
627 table->cols[col].spacing = spacing;
629 if (GTK_WIDGET_VISIBLE (table))
630 gtk_widget_queue_resize (GTK_WIDGET (table));
634 gtk_table_set_homogeneous (GtkTable *table,
635 gboolean homogeneous)
637 g_return_if_fail (table != NULL);
638 g_return_if_fail (GTK_IS_TABLE (table));
640 homogeneous = (homogeneous != 0);
641 if (homogeneous != table->homogeneous)
643 table->homogeneous = homogeneous;
645 if (GTK_WIDGET_VISIBLE (table))
646 gtk_widget_queue_resize (GTK_WIDGET (table));
651 gtk_table_finalize (GObject *object)
655 g_return_if_fail (GTK_IS_TABLE (object));
657 table = GTK_TABLE (object);
659 g_free (table->rows);
660 g_free (table->cols);
662 G_OBJECT_CLASS (parent_class)->finalize (object);
666 gtk_table_map (GtkWidget *widget)
669 GtkTableChild *child;
672 g_return_if_fail (widget != NULL);
673 g_return_if_fail (GTK_IS_TABLE (widget));
675 table = GTK_TABLE (widget);
676 GTK_WIDGET_SET_FLAGS (table, GTK_MAPPED);
678 children = table->children;
681 child = children->data;
682 children = children->next;
684 if (GTK_WIDGET_VISIBLE (child->widget) &&
685 !GTK_WIDGET_MAPPED (child->widget))
686 gtk_widget_map (child->widget);
691 gtk_table_unmap (GtkWidget *widget)
694 GtkTableChild *child;
697 g_return_if_fail (widget != NULL);
698 g_return_if_fail (GTK_IS_TABLE (widget));
700 table = GTK_TABLE (widget);
701 GTK_WIDGET_UNSET_FLAGS (table, GTK_MAPPED);
703 children = table->children;
706 child = children->data;
707 children = children->next;
709 if (GTK_WIDGET_VISIBLE (child->widget) &&
710 GTK_WIDGET_MAPPED (child->widget))
711 gtk_widget_unmap (child->widget);
716 gtk_table_size_request (GtkWidget *widget,
717 GtkRequisition *requisition)
722 g_return_if_fail (widget != NULL);
723 g_return_if_fail (GTK_IS_TABLE (widget));
724 g_return_if_fail (requisition != NULL);
726 table = GTK_TABLE (widget);
728 requisition->width = 0;
729 requisition->height = 0;
731 gtk_table_size_request_init (table);
732 gtk_table_size_request_pass1 (table);
733 gtk_table_size_request_pass2 (table);
734 gtk_table_size_request_pass3 (table);
735 gtk_table_size_request_pass2 (table);
737 for (col = 0; col < table->ncols; col++)
738 requisition->width += table->cols[col].requisition;
739 for (col = 0; col + 1 < table->ncols; col++)
740 requisition->width += table->cols[col].spacing;
742 for (row = 0; row < table->nrows; row++)
743 requisition->height += table->rows[row].requisition;
744 for (row = 0; row + 1 < table->nrows; row++)
745 requisition->height += table->rows[row].spacing;
747 requisition->width += GTK_CONTAINER (table)->border_width * 2;
748 requisition->height += GTK_CONTAINER (table)->border_width * 2;
752 gtk_table_size_allocate (GtkWidget *widget,
753 GtkAllocation *allocation)
757 g_return_if_fail (widget != NULL);
758 g_return_if_fail (GTK_IS_TABLE (widget));
759 g_return_if_fail (allocation != NULL);
761 widget->allocation = *allocation;
762 table = GTK_TABLE (widget);
764 gtk_table_size_allocate_init (table);
765 gtk_table_size_allocate_pass1 (table);
766 gtk_table_size_allocate_pass2 (table);
770 gtk_table_add (GtkContainer *container,
773 g_return_if_fail (container != NULL);
774 g_return_if_fail (GTK_IS_TABLE (container));
775 g_return_if_fail (widget != NULL);
777 gtk_table_attach_defaults (GTK_TABLE (container), widget, 0, 1, 0, 1);
781 gtk_table_remove (GtkContainer *container,
785 GtkTableChild *child;
788 g_return_if_fail (container != NULL);
789 g_return_if_fail (GTK_IS_TABLE (container));
790 g_return_if_fail (widget != NULL);
792 table = GTK_TABLE (container);
793 children = table->children;
797 child = children->data;
798 children = children->next;
800 if (child->widget == widget)
802 gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
804 gtk_widget_unparent (widget);
806 table->children = g_list_remove (table->children, child);
809 if (was_visible && GTK_WIDGET_VISIBLE (container))
810 gtk_container_queue_resize (container);
817 gtk_table_forall (GtkContainer *container,
818 gboolean include_internals,
819 GtkCallback callback,
820 gpointer callback_data)
823 GtkTableChild *child;
826 g_return_if_fail (container != NULL);
827 g_return_if_fail (GTK_IS_TABLE (container));
828 g_return_if_fail (callback != NULL);
830 table = GTK_TABLE (container);
831 children = table->children;
835 child = children->data;
836 children = children->next;
838 (* callback) (child->widget, callback_data);
843 gtk_table_size_request_init (GtkTable *table)
845 GtkTableChild *child;
849 for (row = 0; row < table->nrows; row++)
850 table->rows[row].requisition = 0;
851 for (col = 0; col < table->ncols; col++)
852 table->cols[col].requisition = 0;
854 children = table->children;
857 child = children->data;
858 children = children->next;
860 if (GTK_WIDGET_VISIBLE (child->widget))
861 gtk_widget_size_request (child->widget, NULL);
866 gtk_table_size_request_pass1 (GtkTable *table)
868 GtkTableChild *child;
873 children = table->children;
876 child = children->data;
877 children = children->next;
879 if (GTK_WIDGET_VISIBLE (child->widget))
881 GtkRequisition child_requisition;
882 gtk_widget_get_child_requisition (child->widget, &child_requisition);
884 /* Child spans a single column.
886 if (child->left_attach == (child->right_attach - 1))
888 width = child_requisition.width + child->xpadding * 2;
889 table->cols[child->left_attach].requisition = MAX (table->cols[child->left_attach].requisition, width);
892 /* Child spans a single row.
894 if (child->top_attach == (child->bottom_attach - 1))
896 height = child_requisition.height + child->ypadding * 2;
897 table->rows[child->top_attach].requisition = MAX (table->rows[child->top_attach].requisition, height);
904 gtk_table_size_request_pass2 (GtkTable *table)
910 if (table->homogeneous)
915 for (col = 0; col < table->ncols; col++)
916 max_width = MAX (max_width, table->cols[col].requisition);
917 for (row = 0; row < table->nrows; row++)
918 max_height = MAX (max_height, table->rows[row].requisition);
920 for (col = 0; col < table->ncols; col++)
921 table->cols[col].requisition = max_width;
922 for (row = 0; row < table->nrows; row++)
923 table->rows[row].requisition = max_height;
928 gtk_table_size_request_pass3 (GtkTable *table)
930 GtkTableChild *child;
936 children = table->children;
939 child = children->data;
940 children = children->next;
942 if (GTK_WIDGET_VISIBLE (child->widget))
944 /* Child spans multiple columns.
946 if (child->left_attach != (child->right_attach - 1))
948 GtkRequisition child_requisition;
950 gtk_widget_get_child_requisition (child->widget, &child_requisition);
952 /* Check and see if there is already enough space
956 for (col = child->left_attach; col < child->right_attach; col++)
958 width += table->cols[col].requisition;
959 if ((col + 1) < child->right_attach)
960 width += table->cols[col].spacing;
963 /* If we need to request more space for this child to fill
964 * its requisition, then divide up the needed space evenly
965 * amongst the columns it spans.
967 if (width < child_requisition.width + child->xpadding * 2)
969 width = child_requisition.width + child->xpadding * 2 - width;
971 for (col = child->left_attach; col < child->right_attach; col++)
973 extra = width / (child->right_attach - col);
974 table->cols[col].requisition += extra;
980 /* Child spans multiple rows.
982 if (child->top_attach != (child->bottom_attach - 1))
984 GtkRequisition child_requisition;
986 gtk_widget_get_child_requisition (child->widget, &child_requisition);
988 /* Check and see if there is already enough space
992 for (row = child->top_attach; row < child->bottom_attach; row++)
994 height += table->rows[row].requisition;
995 if ((row + 1) < child->bottom_attach)
996 height += table->rows[row].spacing;
999 /* If we need to request more space for this child to fill
1000 * its requisition, then divide up the needed space evenly
1001 * amongst the columns it spans.
1003 if (height < child_requisition.height + child->ypadding * 2)
1005 height = child_requisition.height + child->ypadding * 2 - height;
1007 for (row = child->top_attach; row < child->bottom_attach; row++)
1009 extra = height / (child->bottom_attach - row);
1010 table->rows[row].requisition += extra;
1020 gtk_table_size_allocate_init (GtkTable *table)
1022 GtkTableChild *child;
1028 /* Initialize the rows and cols.
1029 * By default, rows and cols do not expand and do shrink.
1030 * Those values are modified by the children that occupy
1031 * the rows and cols.
1033 for (col = 0; col < table->ncols; col++)
1035 table->cols[col].allocation = table->cols[col].requisition;
1036 table->cols[col].need_expand = FALSE;
1037 table->cols[col].need_shrink = TRUE;
1038 table->cols[col].expand = FALSE;
1039 table->cols[col].shrink = TRUE;
1040 table->cols[col].empty = TRUE;
1042 for (row = 0; row < table->nrows; row++)
1044 table->rows[row].allocation = table->rows[row].requisition;
1045 table->rows[row].need_expand = FALSE;
1046 table->rows[row].need_shrink = TRUE;
1047 table->rows[row].expand = FALSE;
1048 table->rows[row].shrink = TRUE;
1049 table->rows[row].empty = TRUE;
1052 /* Loop over all the children and adjust the row and col values
1053 * based on whether the children want to be allowed to expand
1054 * or shrink. This loop handles children that occupy a single
1057 children = table->children;
1060 child = children->data;
1061 children = children->next;
1063 if (GTK_WIDGET_VISIBLE (child->widget))
1065 if (child->left_attach == (child->right_attach - 1))
1068 table->cols[child->left_attach].expand = TRUE;
1070 if (!child->xshrink)
1071 table->cols[child->left_attach].shrink = FALSE;
1073 table->cols[child->left_attach].empty = FALSE;
1076 if (child->top_attach == (child->bottom_attach - 1))
1079 table->rows[child->top_attach].expand = TRUE;
1081 if (!child->yshrink)
1082 table->rows[child->top_attach].shrink = FALSE;
1084 table->rows[child->top_attach].empty = FALSE;
1089 /* Loop over all the children again and this time handle children
1090 * which span multiple rows or columns.
1092 children = table->children;
1095 child = children->data;
1096 children = children->next;
1098 if (GTK_WIDGET_VISIBLE (child->widget))
1100 if (child->left_attach != (child->right_attach - 1))
1102 for (col = child->left_attach; col < child->right_attach; col++)
1103 table->cols[col].empty = FALSE;
1108 for (col = child->left_attach; col < child->right_attach; col++)
1109 if (table->cols[col].expand)
1116 for (col = child->left_attach; col < child->right_attach; col++)
1117 table->cols[col].need_expand = TRUE;
1120 if (!child->xshrink)
1123 for (col = child->left_attach; col < child->right_attach; col++)
1124 if (!table->cols[col].shrink)
1131 for (col = child->left_attach; col < child->right_attach; col++)
1132 table->cols[col].need_shrink = FALSE;
1136 if (child->top_attach != (child->bottom_attach - 1))
1138 for (row = child->top_attach; row < child->bottom_attach; row++)
1139 table->rows[row].empty = FALSE;
1144 for (row = child->top_attach; row < child->bottom_attach; row++)
1145 if (table->rows[row].expand)
1152 for (row = child->top_attach; row < child->bottom_attach; row++)
1153 table->rows[row].need_expand = TRUE;
1156 if (!child->yshrink)
1159 for (row = child->top_attach; row < child->bottom_attach; row++)
1160 if (!table->rows[row].shrink)
1167 for (row = child->top_attach; row < child->bottom_attach; row++)
1168 table->rows[row].need_shrink = FALSE;
1174 /* Loop over the columns and set the expand and shrink values
1175 * if the column can be expanded or shrunk.
1177 for (col = 0; col < table->ncols; col++)
1179 if (table->cols[col].empty)
1181 table->cols[col].expand = FALSE;
1182 table->cols[col].shrink = FALSE;
1186 if (table->cols[col].need_expand)
1187 table->cols[col].expand = TRUE;
1188 if (!table->cols[col].need_shrink)
1189 table->cols[col].shrink = FALSE;
1193 /* Loop over the rows and set the expand and shrink values
1194 * if the row can be expanded or shrunk.
1196 for (row = 0; row < table->nrows; row++)
1198 if (table->rows[row].empty)
1200 table->rows[row].expand = FALSE;
1201 table->rows[row].shrink = FALSE;
1205 if (table->rows[row].need_expand)
1206 table->rows[row].expand = TRUE;
1207 if (!table->rows[row].need_shrink)
1208 table->rows[row].shrink = FALSE;
1214 gtk_table_size_allocate_pass1 (GtkTable *table)
1224 /* If we were allocated more space than we requested
1225 * then we have to expand any expandable rows and columns
1226 * to fill in the extra space.
1229 real_width = GTK_WIDGET (table)->allocation.width - GTK_CONTAINER (table)->border_width * 2;
1230 real_height = GTK_WIDGET (table)->allocation.height - GTK_CONTAINER (table)->border_width * 2;
1232 if (table->homogeneous)
1235 for (col = 0; col < table->ncols; col++)
1236 if (table->cols[col].expand)
1246 for (col = 0; col + 1 < table->ncols; col++)
1247 width -= table->cols[col].spacing;
1249 for (col = 0; col < table->ncols; col++)
1251 extra = width / (table->ncols - col);
1252 table->cols[col].allocation = MAX (1, extra);
1263 for (col = 0; col < table->ncols; col++)
1265 width += table->cols[col].requisition;
1266 if (table->cols[col].expand)
1268 if (table->cols[col].shrink)
1271 for (col = 0; col + 1 < table->ncols; col++)
1272 width += table->cols[col].spacing;
1274 /* Check to see if we were allocated more width than we requested.
1276 if ((width < real_width) && (nexpand >= 1))
1278 width = real_width - width;
1280 for (col = 0; col < table->ncols; col++)
1281 if (table->cols[col].expand)
1283 extra = width / nexpand;
1284 table->cols[col].allocation += extra;
1291 /* Check to see if we were allocated less width than we requested,
1292 * then shrink until we fit the size give.
1294 if (width > real_width)
1296 gint total_nshrink = nshrink;
1298 extra = width - real_width;
1299 while (total_nshrink > 0 && extra > 0)
1301 nshrink = total_nshrink;
1302 for (col = 0; col < table->ncols; col++)
1303 if (table->cols[col].shrink)
1305 gint allocation = table->cols[col].allocation;
1307 table->cols[col].allocation = MAX (1, (gint) table->cols[col].allocation - extra / nshrink);
1308 extra -= allocation - table->cols[col].allocation;
1310 if (table->cols[col].allocation < 2)
1313 table->cols[col].shrink = FALSE;
1320 if (table->homogeneous)
1323 for (row = 0; row < table->nrows; row++)
1324 if (table->rows[row].expand)
1332 height = real_height;
1334 for (row = 0; row + 1 < table->nrows; row++)
1335 height -= table->rows[row].spacing;
1338 for (row = 0; row < table->nrows; row++)
1340 extra = height / (table->nrows - row);
1341 table->rows[row].allocation = MAX (1, extra);
1352 for (row = 0; row < table->nrows; row++)
1354 height += table->rows[row].requisition;
1355 if (table->rows[row].expand)
1357 if (table->rows[row].shrink)
1360 for (row = 0; row + 1 < table->nrows; row++)
1361 height += table->rows[row].spacing;
1363 /* Check to see if we were allocated more height than we requested.
1365 if ((height < real_height) && (nexpand >= 1))
1367 height = real_height - height;
1369 for (row = 0; row < table->nrows; row++)
1370 if (table->rows[row].expand)
1372 extra = height / nexpand;
1373 table->rows[row].allocation += extra;
1380 /* Check to see if we were allocated less height than we requested.
1381 * then shrink until we fit the size give.
1383 if (height > real_height)
1385 gint total_nshrink = nshrink;
1387 extra = height - real_height;
1388 while (total_nshrink > 0 && extra > 0)
1390 nshrink = total_nshrink;
1391 for (row = 0; row < table->nrows; row++)
1392 if (table->rows[row].shrink)
1394 gint allocation = table->rows[row].allocation;
1396 table->rows[row].allocation = MAX (1, (gint) table->rows[row].allocation - extra / nshrink);
1397 extra -= allocation - table->rows[row].allocation;
1399 if (table->rows[row].allocation < 2)
1402 table->rows[row].shrink = FALSE;
1411 gtk_table_size_allocate_pass2 (GtkTable *table)
1413 GtkTableChild *child;
1419 GtkAllocation allocation;
1420 GtkWidget *widget = GTK_WIDGET (table);
1422 children = table->children;
1425 child = children->data;
1426 children = children->next;
1428 if (GTK_WIDGET_VISIBLE (child->widget))
1430 GtkRequisition child_requisition;
1431 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1433 x = GTK_WIDGET (table)->allocation.x + GTK_CONTAINER (table)->border_width;
1434 y = GTK_WIDGET (table)->allocation.y + GTK_CONTAINER (table)->border_width;
1438 for (col = 0; col < child->left_attach; col++)
1440 x += table->cols[col].allocation;
1441 x += table->cols[col].spacing;
1444 for (col = child->left_attach; col < child->right_attach; col++)
1446 max_width += table->cols[col].allocation;
1447 if ((col + 1) < child->right_attach)
1448 max_width += table->cols[col].spacing;
1451 for (row = 0; row < child->top_attach; row++)
1453 y += table->rows[row].allocation;
1454 y += table->rows[row].spacing;
1457 for (row = child->top_attach; row < child->bottom_attach; row++)
1459 max_height += table->rows[row].allocation;
1460 if ((row + 1) < child->bottom_attach)
1461 max_height += table->rows[row].spacing;
1466 allocation.width = MAX (1, max_width - (gint)child->xpadding * 2);
1467 allocation.x = x + (max_width - allocation.width) / 2;
1471 allocation.width = child_requisition.width;
1472 allocation.x = x + (max_width - allocation.width) / 2;
1477 allocation.height = MAX (1, max_height - (gint)child->ypadding * 2);
1478 allocation.y = y + (max_height - allocation.height) / 2;
1482 allocation.height = child_requisition.height;
1483 allocation.y = y + (max_height - allocation.height) / 2;
1486 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1487 allocation.x = widget->allocation.x + widget->allocation.width
1488 - (allocation.x - widget->allocation.x) - allocation.width;
1490 gtk_widget_size_allocate (child->widget, &allocation);