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 gint gtk_table_expose (GtkWidget *widget,
59 GdkEventExpose *event);
60 static void gtk_table_size_request (GtkWidget *widget,
61 GtkRequisition *requisition);
62 static void gtk_table_size_allocate (GtkWidget *widget,
63 GtkAllocation *allocation);
64 static void gtk_table_add (GtkContainer *container,
66 static void gtk_table_remove (GtkContainer *container,
68 static void gtk_table_forall (GtkContainer *container,
69 gboolean include_internals,
71 gpointer callback_data);
72 static void gtk_table_get_arg (GtkObject *object,
75 static void gtk_table_set_arg (GtkObject *object,
78 static void gtk_table_set_child_arg (GtkContainer *container,
82 static void gtk_table_get_child_arg (GtkContainer *container,
86 static GtkType gtk_table_child_type (GtkContainer *container);
89 static void gtk_table_size_request_init (GtkTable *table);
90 static void gtk_table_size_request_pass1 (GtkTable *table);
91 static void gtk_table_size_request_pass2 (GtkTable *table);
92 static void gtk_table_size_request_pass3 (GtkTable *table);
94 static void gtk_table_size_allocate_init (GtkTable *table);
95 static void gtk_table_size_allocate_pass1 (GtkTable *table);
96 static void gtk_table_size_allocate_pass2 (GtkTable *table);
99 static GtkContainerClass *parent_class = NULL;
103 gtk_table_get_type (void)
105 static GtkType table_type = 0;
109 static const GtkTypeInfo table_info =
113 sizeof (GtkTableClass),
114 (GtkClassInitFunc) gtk_table_class_init,
115 (GtkObjectInitFunc) gtk_table_init,
116 /* reserved_1 */ NULL,
117 /* reserved_2 */ NULL,
118 (GtkClassInitFunc) NULL,
121 table_type = gtk_type_unique (gtk_container_get_type (), &table_info);
128 gtk_table_class_init (GtkTableClass *class)
130 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
131 GtkObjectClass *object_class;
132 GtkWidgetClass *widget_class;
133 GtkContainerClass *container_class;
135 object_class = (GtkObjectClass*) class;
136 widget_class = (GtkWidgetClass*) class;
137 container_class = (GtkContainerClass*) class;
139 parent_class = gtk_type_class (gtk_container_get_type ());
141 gobject_class->finalize = gtk_table_finalize;
143 object_class->get_arg = gtk_table_get_arg;
144 object_class->set_arg = gtk_table_set_arg;
146 widget_class->map = gtk_table_map;
147 widget_class->unmap = gtk_table_unmap;
148 widget_class->expose_event = gtk_table_expose;
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;
159 gtk_object_add_arg_type ("GtkTable::n_rows", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_N_ROWS);
160 gtk_object_add_arg_type ("GtkTable::n_columns", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_N_COLUMNS);
161 gtk_object_add_arg_type ("GtkTable::row_spacing", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_ROW_SPACING);
162 gtk_object_add_arg_type ("GtkTable::column_spacing", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_COLUMN_SPACING);
163 gtk_object_add_arg_type ("GtkTable::homogeneous", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_HOMOGENEOUS);
164 gtk_container_add_child_arg_type ("GtkTable::left_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_LEFT_ATTACH);
165 gtk_container_add_child_arg_type ("GtkTable::right_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_RIGHT_ATTACH);
166 gtk_container_add_child_arg_type ("GtkTable::top_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_TOP_ATTACH);
167 gtk_container_add_child_arg_type ("GtkTable::bottom_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_BOTTOM_ATTACH);
168 gtk_container_add_child_arg_type ("GtkTable::x_options", GTK_TYPE_ATTACH_OPTIONS, GTK_ARG_READWRITE, CHILD_ARG_X_OPTIONS);
169 gtk_container_add_child_arg_type ("GtkTable::y_options", GTK_TYPE_ATTACH_OPTIONS, GTK_ARG_READWRITE, CHILD_ARG_Y_OPTIONS);
170 gtk_container_add_child_arg_type ("GtkTable::x_padding", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_X_PADDING);
171 gtk_container_add_child_arg_type ("GtkTable::y_padding", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_Y_PADDING);
175 gtk_table_child_type (GtkContainer *container)
177 return GTK_TYPE_WIDGET;
181 gtk_table_get_arg (GtkObject *object,
187 table = GTK_TABLE (object);
192 GTK_VALUE_UINT (*arg) = table->nrows;
195 GTK_VALUE_UINT (*arg) = table->ncols;
197 case ARG_ROW_SPACING:
198 GTK_VALUE_UINT (*arg) = table->row_spacing;
200 case ARG_COLUMN_SPACING:
201 GTK_VALUE_UINT (*arg) = table->column_spacing;
203 case ARG_HOMOGENEOUS:
204 GTK_VALUE_BOOL (*arg) = table->homogeneous;
207 arg->type = GTK_TYPE_INVALID;
213 gtk_table_set_arg (GtkObject *object,
219 table = GTK_TABLE (object);
224 gtk_table_resize (table, GTK_VALUE_UINT (*arg), table->ncols);
227 gtk_table_resize (table, table->nrows, GTK_VALUE_UINT (*arg));
229 case ARG_ROW_SPACING:
230 gtk_table_set_row_spacings (table, GTK_VALUE_UINT (*arg));
232 case ARG_COLUMN_SPACING:
233 gtk_table_set_col_spacings (table, GTK_VALUE_UINT (*arg));
235 case ARG_HOMOGENEOUS:
236 gtk_table_set_homogeneous (table, GTK_VALUE_BOOL (*arg));
244 gtk_table_set_child_arg (GtkContainer *container,
250 GtkTableChild *table_child;
253 table = GTK_TABLE (container);
255 for (list = table->children; list; list = list->next)
257 table_child = list->data;
259 if (table_child->widget == child)
267 case CHILD_ARG_LEFT_ATTACH:
268 table_child->left_attach = GTK_VALUE_UINT (*arg);
269 if (table_child->right_attach <= table_child->left_attach)
270 table_child->right_attach = table_child->left_attach + 1;
271 if (table_child->right_attach >= table->ncols)
272 gtk_table_resize (table, table->ncols, table_child->right_attach);
274 case CHILD_ARG_RIGHT_ATTACH:
275 if (GTK_VALUE_UINT (*arg) > 0)
277 table_child->right_attach = GTK_VALUE_UINT (*arg);
278 if (table_child->right_attach <= table_child->left_attach)
279 table_child->left_attach = table_child->right_attach - 1;
280 if (table_child->right_attach >= table->ncols)
281 gtk_table_resize (table, table->ncols, table_child->right_attach);
284 case CHILD_ARG_TOP_ATTACH:
285 table_child->top_attach = GTK_VALUE_UINT (*arg);
286 if (table_child->bottom_attach <= table_child->top_attach)
287 table_child->bottom_attach = table_child->top_attach + 1;
288 if (table_child->bottom_attach >= table->nrows)
289 gtk_table_resize (table, table_child->bottom_attach, table->ncols);
291 case CHILD_ARG_BOTTOM_ATTACH:
292 if (GTK_VALUE_UINT (*arg) > 0)
294 table_child->bottom_attach = GTK_VALUE_UINT (*arg);
295 if (table_child->bottom_attach <= table_child->top_attach)
296 table_child->top_attach = table_child->bottom_attach - 1;
297 if (table_child->bottom_attach >= table->nrows)
298 gtk_table_resize (table, table_child->bottom_attach, table->ncols);
301 case CHILD_ARG_X_OPTIONS:
302 table_child->xexpand = (GTK_VALUE_FLAGS (*arg) & GTK_EXPAND) != 0;
303 table_child->xshrink = (GTK_VALUE_FLAGS (*arg) & GTK_SHRINK) != 0;
304 table_child->xfill = (GTK_VALUE_FLAGS (*arg) & GTK_FILL) != 0;
306 case CHILD_ARG_Y_OPTIONS:
307 table_child->yexpand = (GTK_VALUE_FLAGS (*arg) & GTK_EXPAND) != 0;
308 table_child->yshrink = (GTK_VALUE_FLAGS (*arg) & GTK_SHRINK) != 0;
309 table_child->yfill = (GTK_VALUE_FLAGS (*arg) & GTK_FILL) != 0;
311 case CHILD_ARG_X_PADDING:
312 table_child->xpadding = GTK_VALUE_UINT (*arg);
314 case CHILD_ARG_Y_PADDING:
315 table_child->ypadding = GTK_VALUE_UINT (*arg);
320 if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (table))
321 gtk_widget_queue_resize (child);
325 gtk_table_get_child_arg (GtkContainer *container,
331 GtkTableChild *table_child;
334 table = GTK_TABLE (container);
336 for (list = table->children; list; list = list->next)
338 table_child = list->data;
340 if (table_child->widget == child)
348 case CHILD_ARG_LEFT_ATTACH:
349 GTK_VALUE_UINT (*arg) = table_child->left_attach;
351 case CHILD_ARG_RIGHT_ATTACH:
352 GTK_VALUE_UINT (*arg) = table_child->right_attach;
354 case CHILD_ARG_TOP_ATTACH:
355 GTK_VALUE_UINT (*arg) = table_child->top_attach;
357 case CHILD_ARG_BOTTOM_ATTACH:
358 GTK_VALUE_UINT (*arg) = table_child->bottom_attach;
360 case CHILD_ARG_X_OPTIONS:
361 GTK_VALUE_FLAGS (*arg) = (table_child->xexpand * GTK_EXPAND |
362 table_child->xshrink * GTK_SHRINK |
363 table_child->xfill * GTK_FILL);
365 case CHILD_ARG_Y_OPTIONS:
366 GTK_VALUE_FLAGS (*arg) = (table_child->yexpand * GTK_EXPAND |
367 table_child->yshrink * GTK_SHRINK |
368 table_child->yfill * GTK_FILL);
370 case CHILD_ARG_X_PADDING:
371 GTK_VALUE_UINT (*arg) = table_child->xpadding;
373 case CHILD_ARG_Y_PADDING:
374 GTK_VALUE_UINT (*arg) = table_child->ypadding;
377 arg->type = GTK_TYPE_INVALID;
383 gtk_table_init (GtkTable *table)
385 GTK_WIDGET_SET_FLAGS (table, GTK_NO_WINDOW);
387 table->children = NULL;
392 table->column_spacing = 0;
393 table->row_spacing = 0;
394 table->homogeneous = FALSE;
396 gtk_table_resize (table, 1, 1);
400 gtk_table_new (guint rows,
402 gboolean homogeneous)
411 table = gtk_type_new (gtk_table_get_type ());
413 table->homogeneous = (homogeneous ? TRUE : FALSE);
415 gtk_table_resize (table, rows, columns);
417 return GTK_WIDGET (table);
421 gtk_table_resize (GtkTable *table,
425 g_return_if_fail (table != NULL);
426 g_return_if_fail (GTK_IS_TABLE (table));
428 n_rows = MAX (n_rows, 1);
429 n_cols = MAX (n_cols, 1);
431 if (n_rows != table->nrows ||
432 n_cols != table->ncols)
436 for (list = table->children; list; list = list->next)
438 GtkTableChild *child;
442 n_rows = MAX (n_rows, child->bottom_attach);
443 n_cols = MAX (n_cols, child->right_attach);
446 if (n_rows != table->nrows)
451 table->nrows = n_rows;
452 table->rows = g_realloc (table->rows, table->nrows * sizeof (GtkTableRowCol));
454 for (; i < table->nrows; i++)
456 table->rows[i].requisition = 0;
457 table->rows[i].allocation = 0;
458 table->rows[i].spacing = table->row_spacing;
459 table->rows[i].need_expand = 0;
460 table->rows[i].need_shrink = 0;
461 table->rows[i].expand = 0;
462 table->rows[i].shrink = 0;
466 if (n_cols != table->ncols)
471 table->ncols = n_cols;
472 table->cols = g_realloc (table->cols, table->ncols * sizeof (GtkTableRowCol));
474 for (; i < table->ncols; i++)
476 table->cols[i].requisition = 0;
477 table->cols[i].allocation = 0;
478 table->cols[i].spacing = table->column_spacing;
479 table->cols[i].need_expand = 0;
480 table->cols[i].need_shrink = 0;
481 table->cols[i].expand = 0;
482 table->cols[i].shrink = 0;
489 gtk_table_attach (GtkTable *table,
495 GtkAttachOptions xoptions,
496 GtkAttachOptions yoptions,
500 GtkTableChild *table_child;
502 g_return_if_fail (table != NULL);
503 g_return_if_fail (GTK_IS_TABLE (table));
504 g_return_if_fail (child != NULL);
505 g_return_if_fail (GTK_IS_WIDGET (child));
506 g_return_if_fail (child->parent == NULL);
508 /* g_return_if_fail (left_attach >= 0); */
509 g_return_if_fail (left_attach < right_attach);
510 /* g_return_if_fail (top_attach >= 0); */
511 g_return_if_fail (top_attach < bottom_attach);
513 if (right_attach >= table->ncols)
514 gtk_table_resize (table, table->nrows, right_attach);
516 if (bottom_attach >= table->nrows)
517 gtk_table_resize (table, bottom_attach, table->ncols);
519 table_child = g_new (GtkTableChild, 1);
520 table_child->widget = child;
521 table_child->left_attach = left_attach;
522 table_child->right_attach = right_attach;
523 table_child->top_attach = top_attach;
524 table_child->bottom_attach = bottom_attach;
525 table_child->xexpand = (xoptions & GTK_EXPAND) != 0;
526 table_child->xshrink = (xoptions & GTK_SHRINK) != 0;
527 table_child->xfill = (xoptions & GTK_FILL) != 0;
528 table_child->xpadding = xpadding;
529 table_child->yexpand = (yoptions & GTK_EXPAND) != 0;
530 table_child->yshrink = (yoptions & GTK_SHRINK) != 0;
531 table_child->yfill = (yoptions & GTK_FILL) != 0;
532 table_child->ypadding = ypadding;
534 table->children = g_list_prepend (table->children, table_child);
536 gtk_widget_set_parent (child, GTK_WIDGET (table));
538 if (GTK_WIDGET_REALIZED (child->parent))
539 gtk_widget_realize (child);
541 if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child))
543 if (GTK_WIDGET_MAPPED (child->parent))
544 gtk_widget_map (child);
546 gtk_widget_queue_resize (child);
551 gtk_table_attach_defaults (GtkTable *table,
558 gtk_table_attach (table, widget,
559 left_attach, right_attach,
560 top_attach, bottom_attach,
561 GTK_EXPAND | GTK_FILL,
562 GTK_EXPAND | GTK_FILL,
567 gtk_table_set_row_spacing (GtkTable *table,
571 g_return_if_fail (table != NULL);
572 g_return_if_fail (GTK_IS_TABLE (table));
573 g_return_if_fail (row < table->nrows);
575 if (table->rows[row].spacing != spacing)
577 table->rows[row].spacing = spacing;
579 if (GTK_WIDGET_VISIBLE (table))
580 gtk_widget_queue_resize (GTK_WIDGET (table));
585 gtk_table_set_col_spacing (GtkTable *table,
589 g_return_if_fail (table != NULL);
590 g_return_if_fail (GTK_IS_TABLE (table));
591 g_return_if_fail (column < table->ncols);
593 if (table->cols[column].spacing != spacing)
595 table->cols[column].spacing = spacing;
597 if (GTK_WIDGET_VISIBLE (table))
598 gtk_widget_queue_resize (GTK_WIDGET (table));
603 gtk_table_set_row_spacings (GtkTable *table,
608 g_return_if_fail (table != NULL);
609 g_return_if_fail (GTK_IS_TABLE (table));
611 table->row_spacing = spacing;
612 for (row = 0; row < table->nrows; row++)
613 table->rows[row].spacing = spacing;
615 if (GTK_WIDGET_VISIBLE (table))
616 gtk_widget_queue_resize (GTK_WIDGET (table));
620 gtk_table_set_col_spacings (GtkTable *table,
625 g_return_if_fail (table != NULL);
626 g_return_if_fail (GTK_IS_TABLE (table));
628 table->column_spacing = spacing;
629 for (col = 0; col < table->ncols; col++)
630 table->cols[col].spacing = spacing;
632 if (GTK_WIDGET_VISIBLE (table))
633 gtk_widget_queue_resize (GTK_WIDGET (table));
637 gtk_table_set_homogeneous (GtkTable *table,
638 gboolean homogeneous)
640 g_return_if_fail (table != NULL);
641 g_return_if_fail (GTK_IS_TABLE (table));
643 homogeneous = (homogeneous != 0);
644 if (homogeneous != table->homogeneous)
646 table->homogeneous = homogeneous;
648 if (GTK_WIDGET_VISIBLE (table))
649 gtk_widget_queue_resize (GTK_WIDGET (table));
654 gtk_table_finalize (GObject *object)
658 g_return_if_fail (GTK_IS_TABLE (object));
660 table = GTK_TABLE (object);
662 g_free (table->rows);
663 g_free (table->cols);
665 G_OBJECT_CLASS (parent_class)->finalize (object);
669 gtk_table_map (GtkWidget *widget)
672 GtkTableChild *child;
675 g_return_if_fail (widget != NULL);
676 g_return_if_fail (GTK_IS_TABLE (widget));
678 table = GTK_TABLE (widget);
679 GTK_WIDGET_SET_FLAGS (table, GTK_MAPPED);
681 children = table->children;
684 child = children->data;
685 children = children->next;
687 if (GTK_WIDGET_VISIBLE (child->widget) &&
688 !GTK_WIDGET_MAPPED (child->widget))
689 gtk_widget_map (child->widget);
694 gtk_table_unmap (GtkWidget *widget)
697 GtkTableChild *child;
700 g_return_if_fail (widget != NULL);
701 g_return_if_fail (GTK_IS_TABLE (widget));
703 table = GTK_TABLE (widget);
704 GTK_WIDGET_UNSET_FLAGS (table, GTK_MAPPED);
706 children = table->children;
709 child = children->data;
710 children = children->next;
712 if (GTK_WIDGET_VISIBLE (child->widget) &&
713 GTK_WIDGET_MAPPED (child->widget))
714 gtk_widget_unmap (child->widget);
719 gtk_table_expose (GtkWidget *widget,
720 GdkEventExpose *event)
723 GtkTableChild *child;
725 GdkEventExpose child_event;
727 g_return_val_if_fail (widget != NULL, FALSE);
728 g_return_val_if_fail (GTK_IS_TABLE (widget), FALSE);
730 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget))
732 table = GTK_TABLE (widget);
734 child_event = *event;
736 children = table->children;
739 child = children->data;
740 children = children->next;
742 if (GTK_WIDGET_NO_WINDOW (child->widget) &&
743 gtk_widget_intersect (child->widget, &event->area, &child_event.area))
744 gtk_widget_event (child->widget, (GdkEvent*) &child_event);
752 gtk_table_size_request (GtkWidget *widget,
753 GtkRequisition *requisition)
758 g_return_if_fail (widget != NULL);
759 g_return_if_fail (GTK_IS_TABLE (widget));
760 g_return_if_fail (requisition != NULL);
762 table = GTK_TABLE (widget);
764 requisition->width = 0;
765 requisition->height = 0;
767 gtk_table_size_request_init (table);
768 gtk_table_size_request_pass1 (table);
769 gtk_table_size_request_pass2 (table);
770 gtk_table_size_request_pass3 (table);
771 gtk_table_size_request_pass2 (table);
773 for (col = 0; col < table->ncols; col++)
774 requisition->width += table->cols[col].requisition;
775 for (col = 0; col + 1 < table->ncols; col++)
776 requisition->width += table->cols[col].spacing;
778 for (row = 0; row < table->nrows; row++)
779 requisition->height += table->rows[row].requisition;
780 for (row = 0; row + 1 < table->nrows; row++)
781 requisition->height += table->rows[row].spacing;
783 requisition->width += GTK_CONTAINER (table)->border_width * 2;
784 requisition->height += GTK_CONTAINER (table)->border_width * 2;
788 gtk_table_size_allocate (GtkWidget *widget,
789 GtkAllocation *allocation)
793 g_return_if_fail (widget != NULL);
794 g_return_if_fail (GTK_IS_TABLE (widget));
795 g_return_if_fail (allocation != NULL);
797 widget->allocation = *allocation;
798 table = GTK_TABLE (widget);
800 gtk_table_size_allocate_init (table);
801 gtk_table_size_allocate_pass1 (table);
802 gtk_table_size_allocate_pass2 (table);
806 gtk_table_add (GtkContainer *container,
809 g_return_if_fail (container != NULL);
810 g_return_if_fail (GTK_IS_TABLE (container));
811 g_return_if_fail (widget != NULL);
813 gtk_table_attach_defaults (GTK_TABLE (container), widget, 0, 1, 0, 1);
817 gtk_table_remove (GtkContainer *container,
821 GtkTableChild *child;
824 g_return_if_fail (container != NULL);
825 g_return_if_fail (GTK_IS_TABLE (container));
826 g_return_if_fail (widget != NULL);
828 table = GTK_TABLE (container);
829 children = table->children;
833 child = children->data;
834 children = children->next;
836 if (child->widget == widget)
838 gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
840 gtk_widget_unparent (widget);
842 table->children = g_list_remove (table->children, child);
845 if (was_visible && GTK_WIDGET_VISIBLE (container))
846 gtk_container_queue_resize (container);
853 gtk_table_forall (GtkContainer *container,
854 gboolean include_internals,
855 GtkCallback callback,
856 gpointer callback_data)
859 GtkTableChild *child;
862 g_return_if_fail (container != NULL);
863 g_return_if_fail (GTK_IS_TABLE (container));
864 g_return_if_fail (callback != NULL);
866 table = GTK_TABLE (container);
867 children = table->children;
871 child = children->data;
872 children = children->next;
874 (* callback) (child->widget, callback_data);
879 gtk_table_size_request_init (GtkTable *table)
881 GtkTableChild *child;
885 for (row = 0; row < table->nrows; row++)
886 table->rows[row].requisition = 0;
887 for (col = 0; col < table->ncols; col++)
888 table->cols[col].requisition = 0;
890 children = table->children;
893 child = children->data;
894 children = children->next;
896 if (GTK_WIDGET_VISIBLE (child->widget))
897 gtk_widget_size_request (child->widget, NULL);
902 gtk_table_size_request_pass1 (GtkTable *table)
904 GtkTableChild *child;
909 children = table->children;
912 child = children->data;
913 children = children->next;
915 if (GTK_WIDGET_VISIBLE (child->widget))
917 GtkRequisition child_requisition;
918 gtk_widget_get_child_requisition (child->widget, &child_requisition);
920 /* Child spans a single column.
922 if (child->left_attach == (child->right_attach - 1))
924 width = child_requisition.width + child->xpadding * 2;
925 table->cols[child->left_attach].requisition = MAX (table->cols[child->left_attach].requisition, width);
928 /* Child spans a single row.
930 if (child->top_attach == (child->bottom_attach - 1))
932 height = child_requisition.height + child->ypadding * 2;
933 table->rows[child->top_attach].requisition = MAX (table->rows[child->top_attach].requisition, height);
940 gtk_table_size_request_pass2 (GtkTable *table)
946 if (table->homogeneous)
951 for (col = 0; col < table->ncols; col++)
952 max_width = MAX (max_width, table->cols[col].requisition);
953 for (row = 0; row < table->nrows; row++)
954 max_height = MAX (max_height, table->rows[row].requisition);
956 for (col = 0; col < table->ncols; col++)
957 table->cols[col].requisition = max_width;
958 for (row = 0; row < table->nrows; row++)
959 table->rows[row].requisition = max_height;
964 gtk_table_size_request_pass3 (GtkTable *table)
966 GtkTableChild *child;
972 children = table->children;
975 child = children->data;
976 children = children->next;
978 if (GTK_WIDGET_VISIBLE (child->widget))
980 /* Child spans multiple columns.
982 if (child->left_attach != (child->right_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 (col = child->left_attach; col < child->right_attach; col++)
994 width += table->cols[col].requisition;
995 if ((col + 1) < child->right_attach)
996 width += table->cols[col].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 (width < child_requisition.width + child->xpadding * 2)
1005 width = child_requisition.width + child->xpadding * 2 - width;
1007 for (col = child->left_attach; col < child->right_attach; col++)
1009 extra = width / (child->right_attach - col);
1010 table->cols[col].requisition += extra;
1016 /* Child spans multiple rows.
1018 if (child->top_attach != (child->bottom_attach - 1))
1020 GtkRequisition child_requisition;
1022 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1024 /* Check and see if there is already enough space
1028 for (row = child->top_attach; row < child->bottom_attach; row++)
1030 height += table->rows[row].requisition;
1031 if ((row + 1) < child->bottom_attach)
1032 height += table->rows[row].spacing;
1035 /* If we need to request more space for this child to fill
1036 * its requisition, then divide up the needed space evenly
1037 * amongst the columns it spans.
1039 if (height < child_requisition.height + child->ypadding * 2)
1041 height = child_requisition.height + child->ypadding * 2 - height;
1043 for (row = child->top_attach; row < child->bottom_attach; row++)
1045 extra = height / (child->bottom_attach - row);
1046 table->rows[row].requisition += extra;
1056 gtk_table_size_allocate_init (GtkTable *table)
1058 GtkTableChild *child;
1064 /* Initialize the rows and cols.
1065 * By default, rows and cols do not expand and do shrink.
1066 * Those values are modified by the children that occupy
1067 * the rows and cols.
1069 for (col = 0; col < table->ncols; col++)
1071 table->cols[col].allocation = table->cols[col].requisition;
1072 table->cols[col].need_expand = FALSE;
1073 table->cols[col].need_shrink = TRUE;
1074 table->cols[col].expand = FALSE;
1075 table->cols[col].shrink = TRUE;
1076 table->cols[col].empty = TRUE;
1078 for (row = 0; row < table->nrows; row++)
1080 table->rows[row].allocation = table->rows[row].requisition;
1081 table->rows[row].need_expand = FALSE;
1082 table->rows[row].need_shrink = TRUE;
1083 table->rows[row].expand = FALSE;
1084 table->rows[row].shrink = TRUE;
1085 table->rows[row].empty = TRUE;
1088 /* Loop over all the children and adjust the row and col values
1089 * based on whether the children want to be allowed to expand
1090 * or shrink. This loop handles children that occupy a single
1093 children = table->children;
1096 child = children->data;
1097 children = children->next;
1099 if (GTK_WIDGET_VISIBLE (child->widget))
1101 if (child->left_attach == (child->right_attach - 1))
1104 table->cols[child->left_attach].expand = TRUE;
1106 if (!child->xshrink)
1107 table->cols[child->left_attach].shrink = FALSE;
1109 table->cols[child->left_attach].empty = FALSE;
1112 if (child->top_attach == (child->bottom_attach - 1))
1115 table->rows[child->top_attach].expand = TRUE;
1117 if (!child->yshrink)
1118 table->rows[child->top_attach].shrink = FALSE;
1120 table->rows[child->top_attach].empty = FALSE;
1125 /* Loop over all the children again and this time handle children
1126 * which span multiple rows or columns.
1128 children = table->children;
1131 child = children->data;
1132 children = children->next;
1134 if (GTK_WIDGET_VISIBLE (child->widget))
1136 if (child->left_attach != (child->right_attach - 1))
1138 for (col = child->left_attach; col < child->right_attach; col++)
1139 table->cols[col].empty = FALSE;
1144 for (col = child->left_attach; col < child->right_attach; col++)
1145 if (table->cols[col].expand)
1152 for (col = child->left_attach; col < child->right_attach; col++)
1153 table->cols[col].need_expand = TRUE;
1156 if (!child->xshrink)
1159 for (col = child->left_attach; col < child->right_attach; col++)
1160 if (!table->cols[col].shrink)
1167 for (col = child->left_attach; col < child->right_attach; col++)
1168 table->cols[col].need_shrink = FALSE;
1172 if (child->top_attach != (child->bottom_attach - 1))
1174 for (row = child->top_attach; row < child->bottom_attach; row++)
1175 table->rows[row].empty = FALSE;
1180 for (row = child->top_attach; row < child->bottom_attach; row++)
1181 if (table->rows[row].expand)
1188 for (row = child->top_attach; row < child->bottom_attach; row++)
1189 table->rows[row].need_expand = TRUE;
1192 if (!child->yshrink)
1195 for (row = child->top_attach; row < child->bottom_attach; row++)
1196 if (!table->rows[row].shrink)
1203 for (row = child->top_attach; row < child->bottom_attach; row++)
1204 table->rows[row].need_shrink = FALSE;
1210 /* Loop over the columns and set the expand and shrink values
1211 * if the column can be expanded or shrunk.
1213 for (col = 0; col < table->ncols; col++)
1215 if (table->cols[col].empty)
1217 table->cols[col].expand = FALSE;
1218 table->cols[col].shrink = FALSE;
1222 if (table->cols[col].need_expand)
1223 table->cols[col].expand = TRUE;
1224 if (!table->cols[col].need_shrink)
1225 table->cols[col].shrink = FALSE;
1229 /* Loop over the rows and set the expand and shrink values
1230 * if the row can be expanded or shrunk.
1232 for (row = 0; row < table->nrows; row++)
1234 if (table->rows[row].empty)
1236 table->rows[row].expand = FALSE;
1237 table->rows[row].shrink = FALSE;
1241 if (table->rows[row].need_expand)
1242 table->rows[row].expand = TRUE;
1243 if (!table->rows[row].need_shrink)
1244 table->rows[row].shrink = FALSE;
1250 gtk_table_size_allocate_pass1 (GtkTable *table)
1260 /* If we were allocated more space than we requested
1261 * then we have to expand any expandable rows and columns
1262 * to fill in the extra space.
1265 real_width = GTK_WIDGET (table)->allocation.width - GTK_CONTAINER (table)->border_width * 2;
1266 real_height = GTK_WIDGET (table)->allocation.height - GTK_CONTAINER (table)->border_width * 2;
1268 if (table->homogeneous)
1271 for (col = 0; col < table->ncols; col++)
1272 if (table->cols[col].expand)
1282 for (col = 0; col + 1 < table->ncols; col++)
1283 width -= table->cols[col].spacing;
1285 for (col = 0; col < table->ncols; col++)
1287 extra = width / (table->ncols - col);
1288 table->cols[col].allocation = MAX (1, extra);
1299 for (col = 0; col < table->ncols; col++)
1301 width += table->cols[col].requisition;
1302 if (table->cols[col].expand)
1304 if (table->cols[col].shrink)
1307 for (col = 0; col + 1 < table->ncols; col++)
1308 width += table->cols[col].spacing;
1310 /* Check to see if we were allocated more width than we requested.
1312 if ((width < real_width) && (nexpand >= 1))
1314 width = real_width - width;
1316 for (col = 0; col < table->ncols; col++)
1317 if (table->cols[col].expand)
1319 extra = width / nexpand;
1320 table->cols[col].allocation += extra;
1327 /* Check to see if we were allocated less width than we requested,
1328 * then shrink until we fit the size give.
1330 if (width > real_width)
1332 gint total_nshrink = nshrink;
1334 extra = width - real_width;
1335 while (total_nshrink > 0 && extra > 0)
1337 nshrink = total_nshrink;
1338 for (col = 0; col < table->ncols; col++)
1339 if (table->cols[col].shrink)
1341 gint allocation = table->cols[col].allocation;
1343 table->cols[col].allocation = MAX (1, (gint) table->cols[col].allocation - extra / nshrink);
1344 extra -= allocation - table->cols[col].allocation;
1346 if (table->cols[col].allocation < 2)
1349 table->cols[col].shrink = FALSE;
1356 if (table->homogeneous)
1359 for (row = 0; row < table->nrows; row++)
1360 if (table->rows[row].expand)
1368 height = real_height;
1370 for (row = 0; row + 1 < table->nrows; row++)
1371 height -= table->rows[row].spacing;
1374 for (row = 0; row < table->nrows; row++)
1376 extra = height / (table->nrows - row);
1377 table->rows[row].allocation = MAX (1, extra);
1388 for (row = 0; row < table->nrows; row++)
1390 height += table->rows[row].requisition;
1391 if (table->rows[row].expand)
1393 if (table->rows[row].shrink)
1396 for (row = 0; row + 1 < table->nrows; row++)
1397 height += table->rows[row].spacing;
1399 /* Check to see if we were allocated more height than we requested.
1401 if ((height < real_height) && (nexpand >= 1))
1403 height = real_height - height;
1405 for (row = 0; row < table->nrows; row++)
1406 if (table->rows[row].expand)
1408 extra = height / nexpand;
1409 table->rows[row].allocation += extra;
1416 /* Check to see if we were allocated less height than we requested.
1417 * then shrink until we fit the size give.
1419 if (height > real_height)
1421 gint total_nshrink = nshrink;
1423 extra = height - real_height;
1424 while (total_nshrink > 0 && extra > 0)
1426 nshrink = total_nshrink;
1427 for (row = 0; row < table->nrows; row++)
1428 if (table->rows[row].shrink)
1430 gint allocation = table->rows[row].allocation;
1432 table->rows[row].allocation = MAX (1, (gint) table->rows[row].allocation - extra / nshrink);
1433 extra -= allocation - table->rows[row].allocation;
1435 if (table->rows[row].allocation < 2)
1438 table->rows[row].shrink = FALSE;
1447 gtk_table_size_allocate_pass2 (GtkTable *table)
1449 GtkTableChild *child;
1455 GtkAllocation allocation;
1456 GtkWidget *widget = GTK_WIDGET (table);
1458 children = table->children;
1461 child = children->data;
1462 children = children->next;
1464 if (GTK_WIDGET_VISIBLE (child->widget))
1466 GtkRequisition child_requisition;
1467 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1469 x = GTK_WIDGET (table)->allocation.x + GTK_CONTAINER (table)->border_width;
1470 y = GTK_WIDGET (table)->allocation.y + GTK_CONTAINER (table)->border_width;
1474 for (col = 0; col < child->left_attach; col++)
1476 x += table->cols[col].allocation;
1477 x += table->cols[col].spacing;
1480 for (col = child->left_attach; col < child->right_attach; col++)
1482 max_width += table->cols[col].allocation;
1483 if ((col + 1) < child->right_attach)
1484 max_width += table->cols[col].spacing;
1487 for (row = 0; row < child->top_attach; row++)
1489 y += table->rows[row].allocation;
1490 y += table->rows[row].spacing;
1493 for (row = child->top_attach; row < child->bottom_attach; row++)
1495 max_height += table->rows[row].allocation;
1496 if ((row + 1) < child->bottom_attach)
1497 max_height += table->rows[row].spacing;
1502 allocation.width = MAX (1, max_width - (gint)child->xpadding * 2);
1503 allocation.x = x + (max_width - allocation.width) / 2;
1507 allocation.width = child_requisition.width;
1508 allocation.x = x + (max_width - allocation.width) / 2;
1513 allocation.height = MAX (1, max_height - (gint)child->ypadding * 2);
1514 allocation.y = y + (max_height - allocation.height) / 2;
1518 allocation.height = child_requisition.height;
1519 allocation.y = y + (max_height - allocation.height) / 2;
1522 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1523 allocation.x = widget->allocation.x + widget->allocation.width
1524 - (allocation.x - widget->allocation.x) - allocation.width;
1526 gtk_widget_size_allocate (child->widget, &allocation);