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_draw (GtkWidget *widget,
60 static gint gtk_table_expose (GtkWidget *widget,
61 GdkEventExpose *event);
62 static void gtk_table_size_request (GtkWidget *widget,
63 GtkRequisition *requisition);
64 static void gtk_table_size_allocate (GtkWidget *widget,
65 GtkAllocation *allocation);
66 static void gtk_table_add (GtkContainer *container,
68 static void gtk_table_remove (GtkContainer *container,
70 static void gtk_table_forall (GtkContainer *container,
71 gboolean include_internals,
73 gpointer callback_data);
74 static void gtk_table_get_arg (GtkObject *object,
77 static void gtk_table_set_arg (GtkObject *object,
80 static void gtk_table_set_child_arg (GtkContainer *container,
84 static void gtk_table_get_child_arg (GtkContainer *container,
88 static GtkType gtk_table_child_type (GtkContainer *container);
91 static void gtk_table_size_request_init (GtkTable *table);
92 static void gtk_table_size_request_pass1 (GtkTable *table);
93 static void gtk_table_size_request_pass2 (GtkTable *table);
94 static void gtk_table_size_request_pass3 (GtkTable *table);
96 static void gtk_table_size_allocate_init (GtkTable *table);
97 static void gtk_table_size_allocate_pass1 (GtkTable *table);
98 static void gtk_table_size_allocate_pass2 (GtkTable *table);
101 static GtkContainerClass *parent_class = NULL;
105 gtk_table_get_type (void)
107 static GtkType table_type = 0;
111 static const GtkTypeInfo table_info =
115 sizeof (GtkTableClass),
116 (GtkClassInitFunc) gtk_table_class_init,
117 (GtkObjectInitFunc) gtk_table_init,
118 /* reserved_1 */ NULL,
119 /* reserved_2 */ NULL,
120 (GtkClassInitFunc) NULL,
123 table_type = gtk_type_unique (gtk_container_get_type (), &table_info);
130 gtk_table_class_init (GtkTableClass *class)
132 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
133 GtkObjectClass *object_class;
134 GtkWidgetClass *widget_class;
135 GtkContainerClass *container_class;
137 object_class = (GtkObjectClass*) class;
138 widget_class = (GtkWidgetClass*) class;
139 container_class = (GtkContainerClass*) class;
141 parent_class = gtk_type_class (gtk_container_get_type ());
143 gobject_class->finalize = gtk_table_finalize;
145 object_class->get_arg = gtk_table_get_arg;
146 object_class->set_arg = gtk_table_set_arg;
148 widget_class->map = gtk_table_map;
149 widget_class->unmap = gtk_table_unmap;
150 widget_class->draw = gtk_table_draw;
151 widget_class->expose_event = gtk_table_expose;
152 widget_class->size_request = gtk_table_size_request;
153 widget_class->size_allocate = gtk_table_size_allocate;
155 container_class->add = gtk_table_add;
156 container_class->remove = gtk_table_remove;
157 container_class->forall = gtk_table_forall;
158 container_class->child_type = gtk_table_child_type;
159 container_class->set_child_arg = gtk_table_set_child_arg;
160 container_class->get_child_arg = gtk_table_get_child_arg;
162 gtk_object_add_arg_type ("GtkTable::n_rows", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_N_ROWS);
163 gtk_object_add_arg_type ("GtkTable::n_columns", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_N_COLUMNS);
164 gtk_object_add_arg_type ("GtkTable::row_spacing", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_ROW_SPACING);
165 gtk_object_add_arg_type ("GtkTable::column_spacing", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_COLUMN_SPACING);
166 gtk_object_add_arg_type ("GtkTable::homogeneous", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_HOMOGENEOUS);
167 gtk_container_add_child_arg_type ("GtkTable::left_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_LEFT_ATTACH);
168 gtk_container_add_child_arg_type ("GtkTable::right_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_RIGHT_ATTACH);
169 gtk_container_add_child_arg_type ("GtkTable::top_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_TOP_ATTACH);
170 gtk_container_add_child_arg_type ("GtkTable::bottom_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_BOTTOM_ATTACH);
171 gtk_container_add_child_arg_type ("GtkTable::x_options", GTK_TYPE_ATTACH_OPTIONS, GTK_ARG_READWRITE, CHILD_ARG_X_OPTIONS);
172 gtk_container_add_child_arg_type ("GtkTable::y_options", GTK_TYPE_ATTACH_OPTIONS, GTK_ARG_READWRITE, CHILD_ARG_Y_OPTIONS);
173 gtk_container_add_child_arg_type ("GtkTable::x_padding", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_X_PADDING);
174 gtk_container_add_child_arg_type ("GtkTable::y_padding", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_Y_PADDING);
178 gtk_table_child_type (GtkContainer *container)
180 return GTK_TYPE_WIDGET;
184 gtk_table_get_arg (GtkObject *object,
190 table = GTK_TABLE (object);
195 GTK_VALUE_UINT (*arg) = table->nrows;
198 GTK_VALUE_UINT (*arg) = table->ncols;
200 case ARG_ROW_SPACING:
201 GTK_VALUE_UINT (*arg) = table->row_spacing;
203 case ARG_COLUMN_SPACING:
204 GTK_VALUE_UINT (*arg) = table->column_spacing;
206 case ARG_HOMOGENEOUS:
207 GTK_VALUE_BOOL (*arg) = table->homogeneous;
210 arg->type = GTK_TYPE_INVALID;
216 gtk_table_set_arg (GtkObject *object,
222 table = GTK_TABLE (object);
227 gtk_table_resize (table, GTK_VALUE_UINT (*arg), table->ncols);
230 gtk_table_resize (table, table->nrows, GTK_VALUE_UINT (*arg));
232 case ARG_ROW_SPACING:
233 gtk_table_set_row_spacings (table, GTK_VALUE_UINT (*arg));
235 case ARG_COLUMN_SPACING:
236 gtk_table_set_col_spacings (table, GTK_VALUE_UINT (*arg));
238 case ARG_HOMOGENEOUS:
239 gtk_table_set_homogeneous (table, GTK_VALUE_BOOL (*arg));
247 gtk_table_set_child_arg (GtkContainer *container,
253 GtkTableChild *table_child;
256 table = GTK_TABLE (container);
258 for (list = table->children; list; list = list->next)
260 table_child = list->data;
262 if (table_child->widget == child)
270 case CHILD_ARG_LEFT_ATTACH:
271 table_child->left_attach = GTK_VALUE_UINT (*arg);
272 if (table_child->right_attach <= table_child->left_attach)
273 table_child->right_attach = table_child->left_attach + 1;
274 if (table_child->right_attach >= table->ncols)
275 gtk_table_resize (table, table->ncols, table_child->right_attach);
277 case CHILD_ARG_RIGHT_ATTACH:
278 if (GTK_VALUE_UINT (*arg) > 0)
280 table_child->right_attach = GTK_VALUE_UINT (*arg);
281 if (table_child->right_attach <= table_child->left_attach)
282 table_child->left_attach = table_child->right_attach - 1;
283 if (table_child->right_attach >= table->ncols)
284 gtk_table_resize (table, table->ncols, table_child->right_attach);
287 case CHILD_ARG_TOP_ATTACH:
288 table_child->top_attach = GTK_VALUE_UINT (*arg);
289 if (table_child->bottom_attach <= table_child->top_attach)
290 table_child->bottom_attach = table_child->top_attach + 1;
291 if (table_child->bottom_attach >= table->nrows)
292 gtk_table_resize (table, table_child->bottom_attach, table->ncols);
294 case CHILD_ARG_BOTTOM_ATTACH:
295 if (GTK_VALUE_UINT (*arg) > 0)
297 table_child->bottom_attach = GTK_VALUE_UINT (*arg);
298 if (table_child->bottom_attach <= table_child->top_attach)
299 table_child->top_attach = table_child->bottom_attach - 1;
300 if (table_child->bottom_attach >= table->nrows)
301 gtk_table_resize (table, table_child->bottom_attach, table->ncols);
304 case CHILD_ARG_X_OPTIONS:
305 table_child->xexpand = (GTK_VALUE_FLAGS (*arg) & GTK_EXPAND) != 0;
306 table_child->xshrink = (GTK_VALUE_FLAGS (*arg) & GTK_SHRINK) != 0;
307 table_child->xfill = (GTK_VALUE_FLAGS (*arg) & GTK_FILL) != 0;
309 case CHILD_ARG_Y_OPTIONS:
310 table_child->yexpand = (GTK_VALUE_FLAGS (*arg) & GTK_EXPAND) != 0;
311 table_child->yshrink = (GTK_VALUE_FLAGS (*arg) & GTK_SHRINK) != 0;
312 table_child->yfill = (GTK_VALUE_FLAGS (*arg) & GTK_FILL) != 0;
314 case CHILD_ARG_X_PADDING:
315 table_child->xpadding = GTK_VALUE_UINT (*arg);
317 case CHILD_ARG_Y_PADDING:
318 table_child->ypadding = GTK_VALUE_UINT (*arg);
323 if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (table))
324 gtk_widget_queue_resize (child);
328 gtk_table_get_child_arg (GtkContainer *container,
334 GtkTableChild *table_child;
337 table = GTK_TABLE (container);
339 for (list = table->children; list; list = list->next)
341 table_child = list->data;
343 if (table_child->widget == child)
351 case CHILD_ARG_LEFT_ATTACH:
352 GTK_VALUE_UINT (*arg) = table_child->left_attach;
354 case CHILD_ARG_RIGHT_ATTACH:
355 GTK_VALUE_UINT (*arg) = table_child->right_attach;
357 case CHILD_ARG_TOP_ATTACH:
358 GTK_VALUE_UINT (*arg) = table_child->top_attach;
360 case CHILD_ARG_BOTTOM_ATTACH:
361 GTK_VALUE_UINT (*arg) = table_child->bottom_attach;
363 case CHILD_ARG_X_OPTIONS:
364 GTK_VALUE_FLAGS (*arg) = (table_child->xexpand * GTK_EXPAND |
365 table_child->xshrink * GTK_SHRINK |
366 table_child->xfill * GTK_FILL);
368 case CHILD_ARG_Y_OPTIONS:
369 GTK_VALUE_FLAGS (*arg) = (table_child->yexpand * GTK_EXPAND |
370 table_child->yshrink * GTK_SHRINK |
371 table_child->yfill * GTK_FILL);
373 case CHILD_ARG_X_PADDING:
374 GTK_VALUE_UINT (*arg) = table_child->xpadding;
376 case CHILD_ARG_Y_PADDING:
377 GTK_VALUE_UINT (*arg) = table_child->ypadding;
380 arg->type = GTK_TYPE_INVALID;
386 gtk_table_init (GtkTable *table)
388 GTK_WIDGET_SET_FLAGS (table, GTK_NO_WINDOW);
390 table->children = NULL;
395 table->column_spacing = 0;
396 table->row_spacing = 0;
397 table->homogeneous = FALSE;
399 gtk_table_resize (table, 1, 1);
403 gtk_table_new (guint rows,
405 gboolean homogeneous)
414 table = gtk_type_new (gtk_table_get_type ());
416 table->homogeneous = (homogeneous ? TRUE : FALSE);
418 gtk_table_resize (table, rows, columns);
420 return GTK_WIDGET (table);
424 gtk_table_resize (GtkTable *table,
428 g_return_if_fail (table != NULL);
429 g_return_if_fail (GTK_IS_TABLE (table));
431 n_rows = MAX (n_rows, 1);
432 n_cols = MAX (n_cols, 1);
434 if (n_rows != table->nrows ||
435 n_cols != table->ncols)
439 for (list = table->children; list; list = list->next)
441 GtkTableChild *child;
445 n_rows = MAX (n_rows, child->bottom_attach);
446 n_cols = MAX (n_cols, child->right_attach);
449 if (n_rows != table->nrows)
454 table->nrows = n_rows;
455 table->rows = g_realloc (table->rows, table->nrows * sizeof (GtkTableRowCol));
457 for (; i < table->nrows; i++)
459 table->rows[i].requisition = 0;
460 table->rows[i].allocation = 0;
461 table->rows[i].spacing = table->row_spacing;
462 table->rows[i].need_expand = 0;
463 table->rows[i].need_shrink = 0;
464 table->rows[i].expand = 0;
465 table->rows[i].shrink = 0;
469 if (n_cols != table->ncols)
474 table->ncols = n_cols;
475 table->cols = g_realloc (table->cols, table->ncols * sizeof (GtkTableRowCol));
477 for (; i < table->ncols; i++)
479 table->cols[i].requisition = 0;
480 table->cols[i].allocation = 0;
481 table->cols[i].spacing = table->column_spacing;
482 table->cols[i].need_expand = 0;
483 table->cols[i].need_shrink = 0;
484 table->cols[i].expand = 0;
485 table->cols[i].shrink = 0;
492 gtk_table_attach (GtkTable *table,
498 GtkAttachOptions xoptions,
499 GtkAttachOptions yoptions,
503 GtkTableChild *table_child;
505 g_return_if_fail (table != NULL);
506 g_return_if_fail (GTK_IS_TABLE (table));
507 g_return_if_fail (child != NULL);
508 g_return_if_fail (GTK_IS_WIDGET (child));
509 g_return_if_fail (child->parent == NULL);
511 /* g_return_if_fail (left_attach >= 0); */
512 g_return_if_fail (left_attach < right_attach);
513 /* g_return_if_fail (top_attach >= 0); */
514 g_return_if_fail (top_attach < bottom_attach);
516 if (right_attach >= table->ncols)
517 gtk_table_resize (table, table->nrows, right_attach);
519 if (bottom_attach >= table->nrows)
520 gtk_table_resize (table, bottom_attach, table->ncols);
522 table_child = g_new (GtkTableChild, 1);
523 table_child->widget = child;
524 table_child->left_attach = left_attach;
525 table_child->right_attach = right_attach;
526 table_child->top_attach = top_attach;
527 table_child->bottom_attach = bottom_attach;
528 table_child->xexpand = (xoptions & GTK_EXPAND) != 0;
529 table_child->xshrink = (xoptions & GTK_SHRINK) != 0;
530 table_child->xfill = (xoptions & GTK_FILL) != 0;
531 table_child->xpadding = xpadding;
532 table_child->yexpand = (yoptions & GTK_EXPAND) != 0;
533 table_child->yshrink = (yoptions & GTK_SHRINK) != 0;
534 table_child->yfill = (yoptions & GTK_FILL) != 0;
535 table_child->ypadding = ypadding;
537 table->children = g_list_prepend (table->children, table_child);
539 gtk_widget_set_parent (child, GTK_WIDGET (table));
541 if (GTK_WIDGET_REALIZED (child->parent))
542 gtk_widget_realize (child);
544 if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child))
546 if (GTK_WIDGET_MAPPED (child->parent))
547 gtk_widget_map (child);
549 gtk_widget_queue_resize (child);
554 gtk_table_attach_defaults (GtkTable *table,
561 gtk_table_attach (table, widget,
562 left_attach, right_attach,
563 top_attach, bottom_attach,
564 GTK_EXPAND | GTK_FILL,
565 GTK_EXPAND | GTK_FILL,
570 gtk_table_set_row_spacing (GtkTable *table,
574 g_return_if_fail (table != NULL);
575 g_return_if_fail (GTK_IS_TABLE (table));
576 g_return_if_fail (row + 1 < table->nrows);
578 if (table->rows[row].spacing != spacing)
580 table->rows[row].spacing = spacing;
582 if (GTK_WIDGET_VISIBLE (table))
583 gtk_widget_queue_resize (GTK_WIDGET (table));
588 gtk_table_set_col_spacing (GtkTable *table,
592 g_return_if_fail (table != NULL);
593 g_return_if_fail (GTK_IS_TABLE (table));
594 g_return_if_fail (column + 1 < table->ncols);
596 if (table->cols[column].spacing != spacing)
598 table->cols[column].spacing = spacing;
600 if (GTK_WIDGET_VISIBLE (table))
601 gtk_widget_queue_resize (GTK_WIDGET (table));
606 gtk_table_set_row_spacings (GtkTable *table,
611 g_return_if_fail (table != NULL);
612 g_return_if_fail (GTK_IS_TABLE (table));
614 table->row_spacing = spacing;
615 for (row = 0; row + 1 < table->nrows; row++)
616 table->rows[row].spacing = spacing;
618 if (GTK_WIDGET_VISIBLE (table))
619 gtk_widget_queue_resize (GTK_WIDGET (table));
623 gtk_table_set_col_spacings (GtkTable *table,
628 g_return_if_fail (table != NULL);
629 g_return_if_fail (GTK_IS_TABLE (table));
631 table->column_spacing = spacing;
632 for (col = 0; col + 1 < table->ncols; col++)
633 table->cols[col].spacing = spacing;
635 if (GTK_WIDGET_VISIBLE (table))
636 gtk_widget_queue_resize (GTK_WIDGET (table));
640 gtk_table_set_homogeneous (GtkTable *table,
641 gboolean homogeneous)
643 g_return_if_fail (table != NULL);
644 g_return_if_fail (GTK_IS_TABLE (table));
646 homogeneous = (homogeneous != 0);
647 if (homogeneous != table->homogeneous)
649 table->homogeneous = homogeneous;
651 if (GTK_WIDGET_VISIBLE (table))
652 gtk_widget_queue_resize (GTK_WIDGET (table));
657 gtk_table_finalize (GObject *object)
661 g_return_if_fail (GTK_IS_TABLE (object));
663 table = GTK_TABLE (object);
665 g_free (table->rows);
666 g_free (table->cols);
668 G_OBJECT_CLASS (parent_class)->finalize (object);
672 gtk_table_map (GtkWidget *widget)
675 GtkTableChild *child;
678 g_return_if_fail (widget != NULL);
679 g_return_if_fail (GTK_IS_TABLE (widget));
681 table = GTK_TABLE (widget);
682 GTK_WIDGET_SET_FLAGS (table, GTK_MAPPED);
684 children = table->children;
687 child = children->data;
688 children = children->next;
690 if (GTK_WIDGET_VISIBLE (child->widget) &&
691 !GTK_WIDGET_MAPPED (child->widget))
692 gtk_widget_map (child->widget);
697 gtk_table_unmap (GtkWidget *widget)
700 GtkTableChild *child;
703 g_return_if_fail (widget != NULL);
704 g_return_if_fail (GTK_IS_TABLE (widget));
706 table = GTK_TABLE (widget);
707 GTK_WIDGET_UNSET_FLAGS (table, GTK_MAPPED);
709 children = table->children;
712 child = children->data;
713 children = children->next;
715 if (GTK_WIDGET_VISIBLE (child->widget) &&
716 GTK_WIDGET_MAPPED (child->widget))
717 gtk_widget_unmap (child->widget);
722 gtk_table_draw (GtkWidget *widget,
726 GtkTableChild *child;
728 GdkRectangle child_area;
730 g_return_if_fail (widget != NULL);
731 g_return_if_fail (GTK_IS_TABLE (widget));
733 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget))
735 table = GTK_TABLE (widget);
737 children = table->children;
740 child = children->data;
741 children = children->next;
743 if (gtk_widget_intersect (child->widget, area, &child_area))
744 gtk_widget_draw (child->widget, &child_area);
750 gtk_table_expose (GtkWidget *widget,
751 GdkEventExpose *event)
754 GtkTableChild *child;
756 GdkEventExpose child_event;
758 g_return_val_if_fail (widget != NULL, FALSE);
759 g_return_val_if_fail (GTK_IS_TABLE (widget), FALSE);
761 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget))
763 table = GTK_TABLE (widget);
765 child_event = *event;
767 children = table->children;
770 child = children->data;
771 children = children->next;
773 if (GTK_WIDGET_NO_WINDOW (child->widget) &&
774 gtk_widget_intersect (child->widget, &event->area, &child_event.area))
775 gtk_widget_event (child->widget, (GdkEvent*) &child_event);
783 gtk_table_size_request (GtkWidget *widget,
784 GtkRequisition *requisition)
789 g_return_if_fail (widget != NULL);
790 g_return_if_fail (GTK_IS_TABLE (widget));
791 g_return_if_fail (requisition != NULL);
793 table = GTK_TABLE (widget);
795 requisition->width = 0;
796 requisition->height = 0;
798 gtk_table_size_request_init (table);
799 gtk_table_size_request_pass1 (table);
800 gtk_table_size_request_pass2 (table);
801 gtk_table_size_request_pass3 (table);
802 gtk_table_size_request_pass2 (table);
804 for (col = 0; col < table->ncols; col++)
805 requisition->width += table->cols[col].requisition;
806 for (col = 0; col + 1 < table->ncols; col++)
807 requisition->width += table->cols[col].spacing;
809 for (row = 0; row < table->nrows; row++)
810 requisition->height += table->rows[row].requisition;
811 for (row = 0; row + 1 < table->nrows; row++)
812 requisition->height += table->rows[row].spacing;
814 requisition->width += GTK_CONTAINER (table)->border_width * 2;
815 requisition->height += GTK_CONTAINER (table)->border_width * 2;
819 gtk_table_size_allocate (GtkWidget *widget,
820 GtkAllocation *allocation)
824 g_return_if_fail (widget != NULL);
825 g_return_if_fail (GTK_IS_TABLE (widget));
826 g_return_if_fail (allocation != NULL);
828 widget->allocation = *allocation;
829 table = GTK_TABLE (widget);
831 gtk_table_size_allocate_init (table);
832 gtk_table_size_allocate_pass1 (table);
833 gtk_table_size_allocate_pass2 (table);
837 gtk_table_add (GtkContainer *container,
840 g_return_if_fail (container != NULL);
841 g_return_if_fail (GTK_IS_TABLE (container));
842 g_return_if_fail (widget != NULL);
844 gtk_table_attach_defaults (GTK_TABLE (container), widget, 0, 1, 0, 1);
848 gtk_table_remove (GtkContainer *container,
852 GtkTableChild *child;
855 g_return_if_fail (container != NULL);
856 g_return_if_fail (GTK_IS_TABLE (container));
857 g_return_if_fail (widget != NULL);
859 table = GTK_TABLE (container);
860 children = table->children;
864 child = children->data;
865 children = children->next;
867 if (child->widget == widget)
869 gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
871 gtk_widget_unparent (widget);
873 table->children = g_list_remove (table->children, child);
876 if (was_visible && GTK_WIDGET_VISIBLE (container))
877 gtk_container_queue_resize (container);
884 gtk_table_forall (GtkContainer *container,
885 gboolean include_internals,
886 GtkCallback callback,
887 gpointer callback_data)
890 GtkTableChild *child;
893 g_return_if_fail (container != NULL);
894 g_return_if_fail (GTK_IS_TABLE (container));
895 g_return_if_fail (callback != NULL);
897 table = GTK_TABLE (container);
898 children = table->children;
902 child = children->data;
903 children = children->next;
905 (* callback) (child->widget, callback_data);
910 gtk_table_size_request_init (GtkTable *table)
912 GtkTableChild *child;
916 for (row = 0; row < table->nrows; row++)
917 table->rows[row].requisition = 0;
918 for (col = 0; col < table->ncols; col++)
919 table->cols[col].requisition = 0;
921 children = table->children;
924 child = children->data;
925 children = children->next;
927 if (GTK_WIDGET_VISIBLE (child->widget))
928 gtk_widget_size_request (child->widget, NULL);
933 gtk_table_size_request_pass1 (GtkTable *table)
935 GtkTableChild *child;
940 children = table->children;
943 child = children->data;
944 children = children->next;
946 if (GTK_WIDGET_VISIBLE (child->widget))
948 GtkRequisition child_requisition;
949 gtk_widget_get_child_requisition (child->widget, &child_requisition);
951 /* Child spans a single column.
953 if (child->left_attach == (child->right_attach - 1))
955 width = child_requisition.width + child->xpadding * 2;
956 table->cols[child->left_attach].requisition = MAX (table->cols[child->left_attach].requisition, width);
959 /* Child spans a single row.
961 if (child->top_attach == (child->bottom_attach - 1))
963 height = child_requisition.height + child->ypadding * 2;
964 table->rows[child->top_attach].requisition = MAX (table->rows[child->top_attach].requisition, height);
971 gtk_table_size_request_pass2 (GtkTable *table)
977 if (table->homogeneous)
982 for (col = 0; col < table->ncols; col++)
983 max_width = MAX (max_width, table->cols[col].requisition);
984 for (row = 0; row < table->nrows; row++)
985 max_height = MAX (max_height, table->rows[row].requisition);
987 for (col = 0; col < table->ncols; col++)
988 table->cols[col].requisition = max_width;
989 for (row = 0; row < table->nrows; row++)
990 table->rows[row].requisition = max_height;
995 gtk_table_size_request_pass3 (GtkTable *table)
997 GtkTableChild *child;
1003 children = table->children;
1006 child = children->data;
1007 children = children->next;
1009 if (GTK_WIDGET_VISIBLE (child->widget))
1011 /* Child spans multiple columns.
1013 if (child->left_attach != (child->right_attach - 1))
1015 GtkRequisition child_requisition;
1017 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1019 /* Check and see if there is already enough space
1023 for (col = child->left_attach; col < child->right_attach; col++)
1025 width += table->cols[col].requisition;
1026 if ((col + 1) < child->right_attach)
1027 width += table->cols[col].spacing;
1030 /* If we need to request more space for this child to fill
1031 * its requisition, then divide up the needed space evenly
1032 * amongst the columns it spans.
1034 if (width < child_requisition.width + child->xpadding * 2)
1036 width = child_requisition.width + child->xpadding * 2 - width;
1038 for (col = child->left_attach; col < child->right_attach; col++)
1040 extra = width / (child->right_attach - col);
1041 table->cols[col].requisition += extra;
1047 /* Child spans multiple rows.
1049 if (child->top_attach != (child->bottom_attach - 1))
1051 GtkRequisition child_requisition;
1053 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1055 /* Check and see if there is already enough space
1059 for (row = child->top_attach; row < child->bottom_attach; row++)
1061 height += table->rows[row].requisition;
1062 if ((row + 1) < child->bottom_attach)
1063 height += table->rows[row].spacing;
1066 /* If we need to request more space for this child to fill
1067 * its requisition, then divide up the needed space evenly
1068 * amongst the columns it spans.
1070 if (height < child_requisition.height + child->ypadding * 2)
1072 height = child_requisition.height + child->ypadding * 2 - height;
1074 for (row = child->top_attach; row < child->bottom_attach; row++)
1076 extra = height / (child->bottom_attach - row);
1077 table->rows[row].requisition += extra;
1087 gtk_table_size_allocate_init (GtkTable *table)
1089 GtkTableChild *child;
1095 /* Initialize the rows and cols.
1096 * By default, rows and cols do not expand and do shrink.
1097 * Those values are modified by the children that occupy
1098 * the rows and cols.
1100 for (col = 0; col < table->ncols; col++)
1102 table->cols[col].allocation = table->cols[col].requisition;
1103 table->cols[col].need_expand = FALSE;
1104 table->cols[col].need_shrink = TRUE;
1105 table->cols[col].expand = FALSE;
1106 table->cols[col].shrink = TRUE;
1107 table->cols[col].empty = TRUE;
1109 for (row = 0; row < table->nrows; row++)
1111 table->rows[row].allocation = table->rows[row].requisition;
1112 table->rows[row].need_expand = FALSE;
1113 table->rows[row].need_shrink = TRUE;
1114 table->rows[row].expand = FALSE;
1115 table->rows[row].shrink = TRUE;
1116 table->rows[row].empty = TRUE;
1119 /* Loop over all the children and adjust the row and col values
1120 * based on whether the children want to be allowed to expand
1121 * or shrink. This loop handles children that occupy a single
1124 children = table->children;
1127 child = children->data;
1128 children = children->next;
1130 if (GTK_WIDGET_VISIBLE (child->widget))
1132 if (child->left_attach == (child->right_attach - 1))
1135 table->cols[child->left_attach].expand = TRUE;
1137 if (!child->xshrink)
1138 table->cols[child->left_attach].shrink = FALSE;
1140 table->cols[child->left_attach].empty = FALSE;
1143 if (child->top_attach == (child->bottom_attach - 1))
1146 table->rows[child->top_attach].expand = TRUE;
1148 if (!child->yshrink)
1149 table->rows[child->top_attach].shrink = FALSE;
1151 table->rows[child->top_attach].empty = FALSE;
1156 /* Loop over all the children again and this time handle children
1157 * which span multiple rows or columns.
1159 children = table->children;
1162 child = children->data;
1163 children = children->next;
1165 if (GTK_WIDGET_VISIBLE (child->widget))
1167 if (child->left_attach != (child->right_attach - 1))
1169 for (col = child->left_attach; col < child->right_attach; col++)
1170 table->cols[col].empty = FALSE;
1175 for (col = child->left_attach; col < child->right_attach; col++)
1176 if (table->cols[col].expand)
1183 for (col = child->left_attach; col < child->right_attach; col++)
1184 table->cols[col].need_expand = TRUE;
1187 if (!child->xshrink)
1190 for (col = child->left_attach; col < child->right_attach; col++)
1191 if (!table->cols[col].shrink)
1198 for (col = child->left_attach; col < child->right_attach; col++)
1199 table->cols[col].need_shrink = FALSE;
1203 if (child->top_attach != (child->bottom_attach - 1))
1205 for (row = child->top_attach; row < child->bottom_attach; row++)
1206 table->rows[row].empty = FALSE;
1211 for (row = child->top_attach; row < child->bottom_attach; row++)
1212 if (table->rows[row].expand)
1219 for (row = child->top_attach; row < child->bottom_attach; row++)
1220 table->rows[row].need_expand = TRUE;
1223 if (!child->yshrink)
1226 for (row = child->top_attach; row < child->bottom_attach; row++)
1227 if (!table->rows[row].shrink)
1234 for (row = child->top_attach; row < child->bottom_attach; row++)
1235 table->rows[row].need_shrink = FALSE;
1241 /* Loop over the columns and set the expand and shrink values
1242 * if the column can be expanded or shrunk.
1244 for (col = 0; col < table->ncols; col++)
1246 if (table->cols[col].empty)
1248 table->cols[col].expand = FALSE;
1249 table->cols[col].shrink = FALSE;
1253 if (table->cols[col].need_expand)
1254 table->cols[col].expand = TRUE;
1255 if (!table->cols[col].need_shrink)
1256 table->cols[col].shrink = FALSE;
1260 /* Loop over the rows and set the expand and shrink values
1261 * if the row can be expanded or shrunk.
1263 for (row = 0; row < table->nrows; row++)
1265 if (table->rows[row].empty)
1267 table->rows[row].expand = FALSE;
1268 table->rows[row].shrink = FALSE;
1272 if (table->rows[row].need_expand)
1273 table->rows[row].expand = TRUE;
1274 if (!table->rows[row].need_shrink)
1275 table->rows[row].shrink = FALSE;
1281 gtk_table_size_allocate_pass1 (GtkTable *table)
1291 /* If we were allocated more space than we requested
1292 * then we have to expand any expandable rows and columns
1293 * to fill in the extra space.
1296 real_width = GTK_WIDGET (table)->allocation.width - GTK_CONTAINER (table)->border_width * 2;
1297 real_height = GTK_WIDGET (table)->allocation.height - GTK_CONTAINER (table)->border_width * 2;
1299 if (table->homogeneous)
1302 for (col = 0; col < table->ncols; col++)
1303 if (table->cols[col].expand)
1313 for (col = 0; col + 1 < table->ncols; col++)
1314 width -= table->cols[col].spacing;
1316 for (col = 0; col < table->ncols; col++)
1318 extra = width / (table->ncols - col);
1319 table->cols[col].allocation = MAX (1, extra);
1330 for (col = 0; col < table->ncols; col++)
1332 width += table->cols[col].requisition;
1333 if (table->cols[col].expand)
1335 if (table->cols[col].shrink)
1338 for (col = 0; col + 1 < table->ncols; col++)
1339 width += table->cols[col].spacing;
1341 /* Check to see if we were allocated more width than we requested.
1343 if ((width < real_width) && (nexpand >= 1))
1345 width = real_width - width;
1347 for (col = 0; col < table->ncols; col++)
1348 if (table->cols[col].expand)
1350 extra = width / nexpand;
1351 table->cols[col].allocation += extra;
1358 /* Check to see if we were allocated less width than we requested,
1359 * then shrink until we fit the size give.
1361 if (width > real_width)
1363 gint total_nshrink = nshrink;
1365 extra = width - real_width;
1366 while (total_nshrink > 0 && extra > 0)
1368 nshrink = total_nshrink;
1369 for (col = 0; col < table->ncols; col++)
1370 if (table->cols[col].shrink)
1372 gint allocation = table->cols[col].allocation;
1374 table->cols[col].allocation = MAX (1, (gint) table->cols[col].allocation - extra / nshrink);
1375 extra -= allocation - table->cols[col].allocation;
1377 if (table->cols[col].allocation < 2)
1380 table->cols[col].shrink = FALSE;
1387 if (table->homogeneous)
1390 for (row = 0; row < table->nrows; row++)
1391 if (table->rows[row].expand)
1399 height = real_height;
1401 for (row = 0; row + 1 < table->nrows; row++)
1402 height -= table->rows[row].spacing;
1405 for (row = 0; row < table->nrows; row++)
1407 extra = height / (table->nrows - row);
1408 table->rows[row].allocation = MAX (1, extra);
1419 for (row = 0; row < table->nrows; row++)
1421 height += table->rows[row].requisition;
1422 if (table->rows[row].expand)
1424 if (table->rows[row].shrink)
1427 for (row = 0; row + 1 < table->nrows; row++)
1428 height += table->rows[row].spacing;
1430 /* Check to see if we were allocated more height than we requested.
1432 if ((height < real_height) && (nexpand >= 1))
1434 height = real_height - height;
1436 for (row = 0; row < table->nrows; row++)
1437 if (table->rows[row].expand)
1439 extra = height / nexpand;
1440 table->rows[row].allocation += extra;
1447 /* Check to see if we were allocated less height than we requested.
1448 * then shrink until we fit the size give.
1450 if (height > real_height)
1452 gint total_nshrink = nshrink;
1454 extra = height - real_height;
1455 while (total_nshrink > 0 && extra > 0)
1457 nshrink = total_nshrink;
1458 for (row = 0; row < table->nrows; row++)
1459 if (table->rows[row].shrink)
1461 gint allocation = table->rows[row].allocation;
1463 table->rows[row].allocation = MAX (1, (gint) table->rows[row].allocation - extra / nshrink);
1464 extra -= allocation - table->rows[row].allocation;
1466 if (table->rows[row].allocation < 2)
1469 table->rows[row].shrink = FALSE;
1478 gtk_table_size_allocate_pass2 (GtkTable *table)
1480 GtkTableChild *child;
1486 GtkAllocation allocation;
1487 GtkWidget *widget = GTK_WIDGET (table);
1489 children = table->children;
1492 child = children->data;
1493 children = children->next;
1495 if (GTK_WIDGET_VISIBLE (child->widget))
1497 GtkRequisition child_requisition;
1498 gtk_widget_get_child_requisition (child->widget, &child_requisition);
1500 x = GTK_WIDGET (table)->allocation.x + GTK_CONTAINER (table)->border_width;
1501 y = GTK_WIDGET (table)->allocation.y + GTK_CONTAINER (table)->border_width;
1505 for (col = 0; col < child->left_attach; col++)
1507 x += table->cols[col].allocation;
1508 x += table->cols[col].spacing;
1511 for (col = child->left_attach; col < child->right_attach; col++)
1513 max_width += table->cols[col].allocation;
1514 if ((col + 1) < child->right_attach)
1515 max_width += table->cols[col].spacing;
1518 for (row = 0; row < child->top_attach; row++)
1520 y += table->rows[row].allocation;
1521 y += table->rows[row].spacing;
1524 for (row = child->top_attach; row < child->bottom_attach; row++)
1526 max_height += table->rows[row].allocation;
1527 if ((row + 1) < child->bottom_attach)
1528 max_height += table->rows[row].spacing;
1533 allocation.width = MAX (1, max_width - (gint)child->xpadding * 2);
1534 allocation.x = x + (max_width - allocation.width) / 2;
1538 allocation.width = child_requisition.width;
1539 allocation.x = x + (max_width - allocation.width) / 2;
1544 allocation.height = MAX (1, max_height - (gint)child->ypadding * 2);
1545 allocation.y = y + (max_height - allocation.height) / 2;
1549 allocation.height = child_requisition.height;
1550 allocation.y = y + (max_height - allocation.height) / 2;
1553 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1554 allocation.x = widget->allocation.x + widget->allocation.width
1555 - (allocation.x - widget->allocation.x) - allocation.width;
1557 gtk_widget_size_allocate (child->widget, &allocation);