]> Pileus Git - ~andy/gtk/blob - gtk/gtktable.c
Remove leaks.
[~andy/gtk] / gtk / gtktable.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #include "gtktable.h"
28 #include "gtkintl.h"
29
30 enum
31 {
32   PROP_0,
33   PROP_N_ROWS,
34   PROP_N_COLUMNS,
35   PROP_COLUMN_SPACING,
36   PROP_ROW_SPACING,
37   PROP_HOMOGENEOUS
38 };
39
40 enum
41 {
42   CHILD_ARG_0,
43   CHILD_ARG_LEFT_ATTACH,
44   CHILD_ARG_RIGHT_ATTACH,
45   CHILD_ARG_TOP_ATTACH,
46   CHILD_ARG_BOTTOM_ATTACH,
47   CHILD_ARG_X_OPTIONS,
48   CHILD_ARG_Y_OPTIONS,
49   CHILD_ARG_X_PADDING,
50   CHILD_ARG_Y_PADDING
51 };
52   
53
54 static void gtk_table_class_init    (GtkTableClass  *klass);
55 static void gtk_table_init          (GtkTable       *table);
56 static void gtk_table_finalize      (GObject        *object);
57 static void gtk_table_map           (GtkWidget      *widget);
58 static void gtk_table_unmap         (GtkWidget      *widget);
59 static void gtk_table_size_request  (GtkWidget      *widget,
60                                      GtkRequisition *requisition);
61 static void gtk_table_size_allocate (GtkWidget      *widget,
62                                      GtkAllocation  *allocation);
63 static void gtk_table_add           (GtkContainer   *container,
64                                      GtkWidget      *widget);
65 static void gtk_table_remove        (GtkContainer   *container,
66                                      GtkWidget      *widget);
67 static void gtk_table_forall        (GtkContainer   *container,
68                                      gboolean        include_internals,
69                                      GtkCallback     callback,
70                                      gpointer        callback_data);
71 static void gtk_table_get_property  (GObject         *object,
72                                      guint            prop_id,
73                                      GValue          *value,
74                                      GParamSpec      *pspec);
75 static void gtk_table_set_property  (GObject         *object,
76                                      guint            prop_id,
77                                      const GValue    *value,
78                                      GParamSpec      *pspec);
79 static void gtk_table_set_child_arg (GtkContainer   *container,
80                                      GtkWidget      *child,
81                                      GtkArg         *arg,
82                                      guint           arg_id);
83 static void gtk_table_get_child_arg (GtkContainer   *container,
84                                      GtkWidget      *child,
85                                      GtkArg         *arg,
86                                      guint           arg_id);
87 static GtkType gtk_table_child_type (GtkContainer   *container);
88
89
90 static void gtk_table_size_request_init  (GtkTable *table);
91 static void gtk_table_size_request_pass1 (GtkTable *table);
92 static void gtk_table_size_request_pass2 (GtkTable *table);
93 static void gtk_table_size_request_pass3 (GtkTable *table);
94
95 static void gtk_table_size_allocate_init  (GtkTable *table);
96 static void gtk_table_size_allocate_pass1 (GtkTable *table);
97 static void gtk_table_size_allocate_pass2 (GtkTable *table);
98
99
100 static GtkContainerClass *parent_class = NULL;
101
102
103 GtkType
104 gtk_table_get_type (void)
105 {
106   static GtkType table_type = 0;
107   
108   if (!table_type)
109     {
110       static const GtkTypeInfo table_info =
111       {
112         "GtkTable",
113         sizeof (GtkTable),
114         sizeof (GtkTableClass),
115         (GtkClassInitFunc) gtk_table_class_init,
116         (GtkObjectInitFunc) gtk_table_init,
117         /* reserved_1 */ NULL,
118         /* reserved_2 */ NULL,
119         (GtkClassInitFunc) NULL,
120       };
121       
122       table_type = gtk_type_unique (gtk_container_get_type (), &table_info);
123     }
124   
125   return table_type;
126 }
127
128 static void
129 gtk_table_class_init (GtkTableClass *class)
130 {
131   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
132   GtkObjectClass *object_class;
133   GtkWidgetClass *widget_class;
134   GtkContainerClass *container_class;
135   
136   object_class = (GtkObjectClass*) class;
137   widget_class = (GtkWidgetClass*) class;
138   container_class = (GtkContainerClass*) class;
139   
140   parent_class = gtk_type_class (gtk_container_get_type ());
141
142   gobject_class->finalize = gtk_table_finalize;
143
144   gobject_class->get_property = gtk_table_get_property;
145   gobject_class->set_property = gtk_table_set_property;
146   
147   widget_class->map = gtk_table_map;
148   widget_class->unmap = gtk_table_unmap;
149   widget_class->size_request = gtk_table_size_request;
150   widget_class->size_allocate = gtk_table_size_allocate;
151   
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;
158   
159
160   g_object_class_install_property (gobject_class,
161                                    PROP_N_ROWS,
162                                    g_param_spec_uint ("n_rows",
163                                                      _("Rows"),
164                                                      _("The number of rows in the table"),
165                                                      0,
166                                                      G_MAXUINT,
167                                                      0,
168                                                      G_PARAM_READWRITE));
169
170   g_object_class_install_property (gobject_class,
171                                    PROP_N_COLUMNS,
172                                    g_param_spec_uint ("n_columns",
173                                                      _("Columns"),
174                                                      _("The number of columns in the table"),
175                                                      0,
176                                                      G_MAXUINT,
177                                                      0,
178                                                      G_PARAM_READWRITE));
179
180   g_object_class_install_property (gobject_class,
181                                    PROP_ROW_SPACING,
182                                    g_param_spec_uint ("row_spacing",
183                                                      _("Row spacing"),
184                                                      _("The amount of space between two consecutive rows"),
185                                                      0,
186                                                      G_MAXUINT,
187                                                      0,
188                                                      G_PARAM_READWRITE));
189
190   g_object_class_install_property (gobject_class,
191                                    PROP_COLUMN_SPACING,
192                                    g_param_spec_uint ("column_spacing",
193                                                      _("Column spacing"),
194                                                      _("The amount of space between two consecutive columns"),
195                                                      0,
196                                                      G_MAXUINT,
197                                                      0,
198                                                      G_PARAM_READWRITE));
199
200   g_object_class_install_property (gobject_class,
201                                    PROP_HOMOGENEOUS,
202                                    g_param_spec_boolean ("homogeneous",
203                                                          _("Homogenous"),
204                                                          _("If TRUE this means the table cells are all the same width/height"),
205                                                          FALSE,
206                                                          G_PARAM_READWRITE));
207
208   gtk_container_add_child_arg_type ("GtkTable::left_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_LEFT_ATTACH);
209   gtk_container_add_child_arg_type ("GtkTable::right_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_RIGHT_ATTACH);
210   gtk_container_add_child_arg_type ("GtkTable::top_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_TOP_ATTACH);
211   gtk_container_add_child_arg_type ("GtkTable::bottom_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_BOTTOM_ATTACH);
212   gtk_container_add_child_arg_type ("GtkTable::x_options", GTK_TYPE_ATTACH_OPTIONS, GTK_ARG_READWRITE, CHILD_ARG_X_OPTIONS);
213   gtk_container_add_child_arg_type ("GtkTable::y_options", GTK_TYPE_ATTACH_OPTIONS, GTK_ARG_READWRITE, CHILD_ARG_Y_OPTIONS);
214   gtk_container_add_child_arg_type ("GtkTable::x_padding", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_X_PADDING);
215   gtk_container_add_child_arg_type ("GtkTable::y_padding", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_Y_PADDING);
216 }
217
218 static GtkType
219 gtk_table_child_type (GtkContainer   *container)
220 {
221   return GTK_TYPE_WIDGET;
222 }
223
224 static void
225 gtk_table_get_property (GObject      *object,
226                         guint         prop_id,
227                         GValue       *value,
228                         GParamSpec   *pspec)
229 {
230   GtkTable *table;
231
232   table = GTK_TABLE (object);
233
234   switch (prop_id)
235     {
236     case PROP_N_ROWS:
237       g_value_set_uint (value, table->nrows);
238       break;
239     case PROP_N_COLUMNS:
240       g_value_set_uint (value, table->ncols);
241       break;
242     case PROP_ROW_SPACING:
243       g_value_set_uint (value, table->row_spacing);
244       break;
245     case PROP_COLUMN_SPACING:
246       g_value_set_uint (value, table->column_spacing);
247       break;
248     case PROP_HOMOGENEOUS:
249       g_value_set_boolean (value, table->homogeneous);
250       break;
251     default:
252       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
253       break;
254     }
255 }
256
257 static void
258 gtk_table_set_property (GObject      *object,
259                         guint         prop_id,
260                         const GValue *value,
261                         GParamSpec   *pspec)
262 {
263   GtkTable *table;
264
265   table = GTK_TABLE (object);
266
267   switch (prop_id)
268     {
269     case PROP_N_ROWS:
270       gtk_table_resize (table, g_value_get_uint (value), table->ncols);
271       break;
272     case PROP_N_COLUMNS:
273       gtk_table_resize (table, table->nrows, g_value_get_uint (value));
274       break;
275     case PROP_ROW_SPACING:
276       gtk_table_set_row_spacings (table, g_value_get_uint (value));
277       break;
278     case PROP_COLUMN_SPACING:
279       gtk_table_set_col_spacings (table, g_value_get_uint (value));
280       break;
281     case PROP_HOMOGENEOUS:
282       gtk_table_set_homogeneous (table, g_value_get_boolean (value));
283       break;
284     default:
285       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
286       break;
287     }
288 }
289
290 static void
291 gtk_table_set_child_arg (GtkContainer   *container,
292                          GtkWidget      *child,
293                          GtkArg         *arg,
294                          guint           arg_id)
295 {
296   GtkTable *table;
297   GtkTableChild *table_child;
298   GList *list;
299
300   table = GTK_TABLE (container);
301   table_child = NULL;
302   for (list = table->children; list; list = list->next)
303     {
304       table_child = list->data;
305
306       if (table_child->widget == child)
307         break;
308     }
309   if (!list)
310     return;
311
312   switch (arg_id)
313     {
314     case CHILD_ARG_LEFT_ATTACH:
315       table_child->left_attach = GTK_VALUE_UINT (*arg);
316       if (table_child->right_attach <= table_child->left_attach)
317         table_child->right_attach = table_child->left_attach + 1;
318       if (table_child->right_attach >= table->ncols)
319         gtk_table_resize (table, table->ncols, table_child->right_attach);
320       break;
321     case CHILD_ARG_RIGHT_ATTACH:
322       if (GTK_VALUE_UINT (*arg) > 0)
323         {
324           table_child->right_attach = GTK_VALUE_UINT (*arg);
325           if (table_child->right_attach <= table_child->left_attach)
326             table_child->left_attach = table_child->right_attach - 1;
327           if (table_child->right_attach >= table->ncols)
328             gtk_table_resize (table, table->ncols, table_child->right_attach);
329         }
330       break;
331     case CHILD_ARG_TOP_ATTACH:
332       table_child->top_attach = GTK_VALUE_UINT (*arg);
333       if (table_child->bottom_attach <= table_child->top_attach)
334         table_child->bottom_attach = table_child->top_attach + 1;
335       if (table_child->bottom_attach >= table->nrows)
336         gtk_table_resize (table, table_child->bottom_attach, table->ncols);
337       break;
338     case CHILD_ARG_BOTTOM_ATTACH:
339       if (GTK_VALUE_UINT (*arg) > 0)
340         {
341           table_child->bottom_attach = GTK_VALUE_UINT (*arg);
342           if (table_child->bottom_attach <= table_child->top_attach)
343             table_child->top_attach = table_child->bottom_attach - 1;
344           if (table_child->bottom_attach >= table->nrows)
345             gtk_table_resize (table, table_child->bottom_attach, table->ncols);
346         }
347       break;
348     case CHILD_ARG_X_OPTIONS:
349       table_child->xexpand = (GTK_VALUE_FLAGS (*arg) & GTK_EXPAND) != 0;
350       table_child->xshrink = (GTK_VALUE_FLAGS (*arg) & GTK_SHRINK) != 0;
351       table_child->xfill = (GTK_VALUE_FLAGS (*arg) & GTK_FILL) != 0;
352       break;
353     case CHILD_ARG_Y_OPTIONS:
354       table_child->yexpand = (GTK_VALUE_FLAGS (*arg) & GTK_EXPAND) != 0;
355       table_child->yshrink = (GTK_VALUE_FLAGS (*arg) & GTK_SHRINK) != 0;
356       table_child->yfill = (GTK_VALUE_FLAGS (*arg) & GTK_FILL) != 0;
357       break;
358     case CHILD_ARG_X_PADDING:
359       table_child->xpadding = GTK_VALUE_UINT (*arg);
360       break;
361     case CHILD_ARG_Y_PADDING:
362       table_child->ypadding = GTK_VALUE_UINT (*arg);
363       break;
364     default:
365       break;
366     }
367   if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (table))
368     gtk_widget_queue_resize (child);
369 }
370
371 static void
372 gtk_table_get_child_arg (GtkContainer   *container,
373                          GtkWidget      *child,
374                          GtkArg         *arg,
375                          guint           arg_id)
376 {
377   GtkTable *table;
378   GtkTableChild *table_child;
379   GList *list;
380
381   table = GTK_TABLE (container);
382   table_child = NULL;
383   for (list = table->children; list; list = list->next)
384     {
385       table_child = list->data;
386
387       if (table_child->widget == child)
388         break;
389     }
390   if (!list)
391     return;
392
393   switch (arg_id)
394     {
395     case CHILD_ARG_LEFT_ATTACH:
396       GTK_VALUE_UINT (*arg) = table_child->left_attach;
397       break;
398     case CHILD_ARG_RIGHT_ATTACH:
399       GTK_VALUE_UINT (*arg) = table_child->right_attach;
400       break;
401     case CHILD_ARG_TOP_ATTACH:
402       GTK_VALUE_UINT (*arg) = table_child->top_attach;
403       break;
404     case CHILD_ARG_BOTTOM_ATTACH:
405       GTK_VALUE_UINT (*arg) = table_child->bottom_attach;
406       break;
407     case CHILD_ARG_X_OPTIONS:
408       GTK_VALUE_FLAGS (*arg) = (table_child->xexpand * GTK_EXPAND |
409                                 table_child->xshrink * GTK_SHRINK |
410                                 table_child->xfill * GTK_FILL);
411       break;
412     case CHILD_ARG_Y_OPTIONS:
413       GTK_VALUE_FLAGS (*arg) = (table_child->yexpand * GTK_EXPAND |
414                                 table_child->yshrink * GTK_SHRINK |
415                                 table_child->yfill * GTK_FILL);
416       break;
417     case CHILD_ARG_X_PADDING:
418       GTK_VALUE_UINT (*arg) = table_child->xpadding;
419       break;
420     case CHILD_ARG_Y_PADDING:
421       GTK_VALUE_UINT (*arg) = table_child->ypadding;
422       break;
423     default:
424       arg->type = GTK_TYPE_INVALID;
425       break;
426     }
427 }
428
429 static void
430 gtk_table_init (GtkTable *table)
431 {
432   GTK_WIDGET_SET_FLAGS (table, GTK_NO_WINDOW);
433   
434   table->children = NULL;
435   table->rows = NULL;
436   table->cols = NULL;
437   table->nrows = 0;
438   table->ncols = 0;
439   table->column_spacing = 0;
440   table->row_spacing = 0;
441   table->homogeneous = FALSE;
442
443   gtk_table_resize (table, 1, 1);
444 }
445
446 GtkWidget*
447 gtk_table_new (guint    rows,
448                guint    columns,
449                gboolean homogeneous)
450 {
451   GtkTable *table;
452
453   if (rows == 0)
454           rows = 1;
455   if (columns == 0)
456           columns = 1;
457   
458   table = gtk_type_new (gtk_table_get_type ());
459   
460   table->homogeneous = (homogeneous ? TRUE : FALSE);
461
462   gtk_table_resize (table, rows, columns);
463   
464   return GTK_WIDGET (table);
465 }
466
467 void
468 gtk_table_resize (GtkTable *table,
469                   guint     n_rows,
470                   guint     n_cols)
471 {
472   g_return_if_fail (table != NULL);
473   g_return_if_fail (GTK_IS_TABLE (table));
474
475   n_rows = MAX (n_rows, 1);
476   n_cols = MAX (n_cols, 1);
477   
478   if (n_rows != table->nrows ||
479       n_cols != table->ncols)
480     {
481       GList *list;
482       
483       for (list = table->children; list; list = list->next)
484         {
485           GtkTableChild *child;
486           
487           child = list->data;
488           
489           n_rows = MAX (n_rows, child->bottom_attach);
490           n_cols = MAX (n_cols, child->right_attach);
491         }
492       
493       if (n_rows != table->nrows)
494         {
495           guint i;
496
497           i = table->nrows;
498           table->nrows = n_rows;
499           table->rows = g_realloc (table->rows, table->nrows * sizeof (GtkTableRowCol));
500           
501           for (; i < table->nrows; i++)
502             {
503               table->rows[i].requisition = 0;
504               table->rows[i].allocation = 0;
505               table->rows[i].spacing = table->row_spacing;
506               table->rows[i].need_expand = 0;
507               table->rows[i].need_shrink = 0;
508               table->rows[i].expand = 0;
509               table->rows[i].shrink = 0;
510             }
511
512           g_object_notify (G_OBJECT (table), "n_rows");
513         }
514
515       if (n_cols != table->ncols)
516         {
517           guint i;
518
519           i = table->ncols;
520           table->ncols = n_cols;
521           table->cols = g_realloc (table->cols, table->ncols * sizeof (GtkTableRowCol));
522           
523           for (; i < table->ncols; i++)
524             {
525               table->cols[i].requisition = 0;
526               table->cols[i].allocation = 0;
527               table->cols[i].spacing = table->column_spacing;
528               table->cols[i].need_expand = 0;
529               table->cols[i].need_shrink = 0;
530               table->cols[i].expand = 0;
531               table->cols[i].shrink = 0;
532             }
533
534           g_object_notify (G_OBJECT (table), "n_columns");
535         }
536     }
537 }
538
539 void
540 gtk_table_attach (GtkTable        *table,
541                   GtkWidget       *child,
542                   guint            left_attach,
543                   guint            right_attach,
544                   guint            top_attach,
545                   guint            bottom_attach,
546                   GtkAttachOptions xoptions,
547                   GtkAttachOptions yoptions,
548                   guint            xpadding,
549                   guint            ypadding)
550 {
551   GtkTableChild *table_child;
552   
553   g_return_if_fail (table != NULL);
554   g_return_if_fail (GTK_IS_TABLE (table));
555   g_return_if_fail (child != NULL);
556   g_return_if_fail (GTK_IS_WIDGET (child));
557   g_return_if_fail (child->parent == NULL);
558   
559   /* g_return_if_fail (left_attach >= 0); */
560   g_return_if_fail (left_attach < right_attach);
561   /* g_return_if_fail (top_attach >= 0); */
562   g_return_if_fail (top_attach < bottom_attach);
563   
564   if (right_attach >= table->ncols)
565     gtk_table_resize (table, table->nrows, right_attach);
566   
567   if (bottom_attach >= table->nrows)
568     gtk_table_resize (table, bottom_attach, table->ncols);
569   
570   table_child = g_new (GtkTableChild, 1);
571   table_child->widget = child;
572   table_child->left_attach = left_attach;
573   table_child->right_attach = right_attach;
574   table_child->top_attach = top_attach;
575   table_child->bottom_attach = bottom_attach;
576   table_child->xexpand = (xoptions & GTK_EXPAND) != 0;
577   table_child->xshrink = (xoptions & GTK_SHRINK) != 0;
578   table_child->xfill = (xoptions & GTK_FILL) != 0;
579   table_child->xpadding = xpadding;
580   table_child->yexpand = (yoptions & GTK_EXPAND) != 0;
581   table_child->yshrink = (yoptions & GTK_SHRINK) != 0;
582   table_child->yfill = (yoptions & GTK_FILL) != 0;
583   table_child->ypadding = ypadding;
584   
585   table->children = g_list_prepend (table->children, table_child);
586   
587   gtk_widget_set_parent (child, GTK_WIDGET (table));
588   
589   if (GTK_WIDGET_REALIZED (child->parent))
590     gtk_widget_realize (child);
591
592   if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child))
593     {
594       if (GTK_WIDGET_MAPPED (child->parent))
595         gtk_widget_map (child);
596
597       gtk_widget_queue_resize (child);
598     }
599 }
600
601 void
602 gtk_table_attach_defaults (GtkTable  *table,
603                            GtkWidget *widget,
604                            guint      left_attach,
605                            guint      right_attach,
606                            guint      top_attach,
607                            guint      bottom_attach)
608 {
609   gtk_table_attach (table, widget,
610                     left_attach, right_attach,
611                     top_attach, bottom_attach,
612                     GTK_EXPAND | GTK_FILL,
613                     GTK_EXPAND | GTK_FILL,
614                     0, 0);
615 }
616
617 void
618 gtk_table_set_row_spacing (GtkTable *table,
619                            guint     row,
620                            guint     spacing)
621 {
622   g_return_if_fail (table != NULL);
623   g_return_if_fail (GTK_IS_TABLE (table));
624   g_return_if_fail (row < table->nrows);
625   
626   if (table->rows[row].spacing != spacing)
627     {
628       table->rows[row].spacing = spacing;
629       
630       if (GTK_WIDGET_VISIBLE (table))
631         gtk_widget_queue_resize (GTK_WIDGET (table));
632     }
633
634   g_object_notify (G_OBJECT (table), "row_spacing");
635 }
636
637 void
638 gtk_table_set_col_spacing (GtkTable *table,
639                            guint     column,
640                            guint     spacing)
641 {
642   g_return_if_fail (table != NULL);
643   g_return_if_fail (GTK_IS_TABLE (table));
644   g_return_if_fail (column < table->ncols);
645   
646   if (table->cols[column].spacing != spacing)
647     {
648       table->cols[column].spacing = spacing;
649       
650       if (GTK_WIDGET_VISIBLE (table))
651         gtk_widget_queue_resize (GTK_WIDGET (table));
652     }
653
654   g_object_notify (G_OBJECT (table), "column_spacing");
655 }
656
657 void
658 gtk_table_set_row_spacings (GtkTable *table,
659                             guint     spacing)
660 {
661   guint row;
662   
663   g_return_if_fail (table != NULL);
664   g_return_if_fail (GTK_IS_TABLE (table));
665   
666   table->row_spacing = spacing;
667   for (row = 0; row < table->nrows; row++)
668     table->rows[row].spacing = spacing;
669   
670   if (GTK_WIDGET_VISIBLE (table))
671     gtk_widget_queue_resize (GTK_WIDGET (table));
672 }
673
674 void
675 gtk_table_set_col_spacings (GtkTable *table,
676                             guint     spacing)
677 {
678   guint col;
679   
680   g_return_if_fail (table != NULL);
681   g_return_if_fail (GTK_IS_TABLE (table));
682   
683   table->column_spacing = spacing;
684   for (col = 0; col < table->ncols; col++)
685     table->cols[col].spacing = spacing;
686   
687   if (GTK_WIDGET_VISIBLE (table))
688     gtk_widget_queue_resize (GTK_WIDGET (table));
689 }
690
691 void
692 gtk_table_set_homogeneous (GtkTable *table,
693                            gboolean  homogeneous)
694 {
695   g_return_if_fail (table != NULL);
696   g_return_if_fail (GTK_IS_TABLE (table));
697
698   homogeneous = (homogeneous != 0);
699   if (homogeneous != table->homogeneous)
700     {
701       table->homogeneous = homogeneous;
702       
703       if (GTK_WIDGET_VISIBLE (table))
704         gtk_widget_queue_resize (GTK_WIDGET (table));
705     }
706 }
707
708 static void
709 gtk_table_finalize (GObject *object)
710 {
711   GtkTable *table;
712   
713   g_return_if_fail (GTK_IS_TABLE (object));
714   
715   table = GTK_TABLE (object);
716   
717   g_free (table->rows);
718   g_free (table->cols);
719   
720   G_OBJECT_CLASS (parent_class)->finalize (object);
721 }
722
723 static void
724 gtk_table_map (GtkWidget *widget)
725 {
726   GtkTable *table;
727   GtkTableChild *child;
728   GList *children;
729   
730   g_return_if_fail (widget != NULL);
731   g_return_if_fail (GTK_IS_TABLE (widget));
732   
733   table = GTK_TABLE (widget);
734   GTK_WIDGET_SET_FLAGS (table, GTK_MAPPED);
735   
736   children = table->children;
737   while (children)
738     {
739       child = children->data;
740       children = children->next;
741       
742       if (GTK_WIDGET_VISIBLE (child->widget) &&
743           !GTK_WIDGET_MAPPED (child->widget))
744         gtk_widget_map (child->widget);
745     }
746 }
747
748 static void
749 gtk_table_unmap (GtkWidget *widget)
750 {
751   GtkTable *table;
752   GtkTableChild *child;
753   GList *children;
754   
755   g_return_if_fail (widget != NULL);
756   g_return_if_fail (GTK_IS_TABLE (widget));
757   
758   table = GTK_TABLE (widget);
759   GTK_WIDGET_UNSET_FLAGS (table, GTK_MAPPED);
760   
761   children = table->children;
762   while (children)
763     {
764       child = children->data;
765       children = children->next;
766       
767       if (GTK_WIDGET_VISIBLE (child->widget) &&
768           GTK_WIDGET_MAPPED (child->widget))
769         gtk_widget_unmap (child->widget);
770     }
771 }
772
773 static void
774 gtk_table_size_request (GtkWidget      *widget,
775                         GtkRequisition *requisition)
776 {
777   GtkTable *table;
778   gint row, col;
779   
780   g_return_if_fail (widget != NULL);
781   g_return_if_fail (GTK_IS_TABLE (widget));
782   g_return_if_fail (requisition != NULL);
783   
784   table = GTK_TABLE (widget);
785   
786   requisition->width = 0;
787   requisition->height = 0;
788   
789   gtk_table_size_request_init (table);
790   gtk_table_size_request_pass1 (table);
791   gtk_table_size_request_pass2 (table);
792   gtk_table_size_request_pass3 (table);
793   gtk_table_size_request_pass2 (table);
794   
795   for (col = 0; col < table->ncols; col++)
796     requisition->width += table->cols[col].requisition;
797   for (col = 0; col + 1 < table->ncols; col++)
798     requisition->width += table->cols[col].spacing;
799   
800   for (row = 0; row < table->nrows; row++)
801     requisition->height += table->rows[row].requisition;
802   for (row = 0; row + 1 < table->nrows; row++)
803     requisition->height += table->rows[row].spacing;
804   
805   requisition->width += GTK_CONTAINER (table)->border_width * 2;
806   requisition->height += GTK_CONTAINER (table)->border_width * 2;
807 }
808
809 static void
810 gtk_table_size_allocate (GtkWidget     *widget,
811                          GtkAllocation *allocation)
812 {
813   GtkTable *table;
814   
815   g_return_if_fail (widget != NULL);
816   g_return_if_fail (GTK_IS_TABLE (widget));
817   g_return_if_fail (allocation != NULL);
818   
819   widget->allocation = *allocation;
820   table = GTK_TABLE (widget);
821   
822   gtk_table_size_allocate_init (table);
823   gtk_table_size_allocate_pass1 (table);
824   gtk_table_size_allocate_pass2 (table);
825 }
826
827 static void
828 gtk_table_add (GtkContainer *container,
829                GtkWidget    *widget)
830 {
831   g_return_if_fail (container != NULL);
832   g_return_if_fail (GTK_IS_TABLE (container));
833   g_return_if_fail (widget != NULL);
834   
835   gtk_table_attach_defaults (GTK_TABLE (container), widget, 0, 1, 0, 1);
836 }
837
838 static void
839 gtk_table_remove (GtkContainer *container,
840                   GtkWidget    *widget)
841 {
842   GtkTable *table;
843   GtkTableChild *child;
844   GList *children;
845   
846   g_return_if_fail (container != NULL);
847   g_return_if_fail (GTK_IS_TABLE (container));
848   g_return_if_fail (widget != NULL);
849   
850   table = GTK_TABLE (container);
851   children = table->children;
852   
853   while (children)
854     {
855       child = children->data;
856       children = children->next;
857       
858       if (child->widget == widget)
859         {
860           gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
861           
862           gtk_widget_unparent (widget);
863           
864           table->children = g_list_remove (table->children, child);
865           g_free (child);
866           
867           if (was_visible && GTK_WIDGET_VISIBLE (container))
868             gtk_container_queue_resize (container);
869           break;
870         }
871     }
872 }
873
874 static void
875 gtk_table_forall (GtkContainer *container,
876                   gboolean      include_internals,
877                   GtkCallback   callback,
878                   gpointer      callback_data)
879 {
880   GtkTable *table;
881   GtkTableChild *child;
882   GList *children;
883   
884   g_return_if_fail (container != NULL);
885   g_return_if_fail (GTK_IS_TABLE (container));
886   g_return_if_fail (callback != NULL);
887   
888   table = GTK_TABLE (container);
889   children = table->children;
890   
891   while (children)
892     {
893       child = children->data;
894       children = children->next;
895       
896       (* callback) (child->widget, callback_data);
897     }
898 }
899
900 static void
901 gtk_table_size_request_init (GtkTable *table)
902 {
903   GtkTableChild *child;
904   GList *children;
905   gint row, col;
906   
907   for (row = 0; row < table->nrows; row++)
908     table->rows[row].requisition = 0;
909   for (col = 0; col < table->ncols; col++)
910     table->cols[col].requisition = 0;
911   
912   children = table->children;
913   while (children)
914     {
915       child = children->data;
916       children = children->next;
917       
918       if (GTK_WIDGET_VISIBLE (child->widget))
919         gtk_widget_size_request (child->widget, NULL);
920     }
921 }
922
923 static void
924 gtk_table_size_request_pass1 (GtkTable *table)
925 {
926   GtkTableChild *child;
927   GList *children;
928   gint width;
929   gint height;
930   
931   children = table->children;
932   while (children)
933     {
934       child = children->data;
935       children = children->next;
936       
937       if (GTK_WIDGET_VISIBLE (child->widget))
938         {
939           GtkRequisition child_requisition;
940           gtk_widget_get_child_requisition (child->widget, &child_requisition);
941
942           /* Child spans a single column.
943            */
944           if (child->left_attach == (child->right_attach - 1))
945             {
946               width = child_requisition.width + child->xpadding * 2;
947               table->cols[child->left_attach].requisition = MAX (table->cols[child->left_attach].requisition, width);
948             }
949           
950           /* Child spans a single row.
951            */
952           if (child->top_attach == (child->bottom_attach - 1))
953             {
954               height = child_requisition.height + child->ypadding * 2;
955               table->rows[child->top_attach].requisition = MAX (table->rows[child->top_attach].requisition, height);
956             }
957         }
958     }
959 }
960
961 static void
962 gtk_table_size_request_pass2 (GtkTable *table)
963 {
964   gint max_width;
965   gint max_height;
966   gint row, col;
967   
968   if (table->homogeneous)
969     {
970       max_width = 0;
971       max_height = 0;
972       
973       for (col = 0; col < table->ncols; col++)
974         max_width = MAX (max_width, table->cols[col].requisition);
975       for (row = 0; row < table->nrows; row++)
976         max_height = MAX (max_height, table->rows[row].requisition);
977       
978       for (col = 0; col < table->ncols; col++)
979         table->cols[col].requisition = max_width;
980       for (row = 0; row < table->nrows; row++)
981         table->rows[row].requisition = max_height;
982     }
983 }
984
985 static void
986 gtk_table_size_request_pass3 (GtkTable *table)
987 {
988   GtkTableChild *child;
989   GList *children;
990   gint width, height;
991   gint row, col;
992   gint extra;
993   
994   children = table->children;
995   while (children)
996     {
997       child = children->data;
998       children = children->next;
999       
1000       if (GTK_WIDGET_VISIBLE (child->widget))
1001         {
1002           /* Child spans multiple columns.
1003            */
1004           if (child->left_attach != (child->right_attach - 1))
1005             {
1006               GtkRequisition child_requisition;
1007
1008               gtk_widget_get_child_requisition (child->widget, &child_requisition);
1009               
1010               /* Check and see if there is already enough space
1011                *  for the child.
1012                */
1013               width = 0;
1014               for (col = child->left_attach; col < child->right_attach; col++)
1015                 {
1016                   width += table->cols[col].requisition;
1017                   if ((col + 1) < child->right_attach)
1018                     width += table->cols[col].spacing;
1019                 }
1020               
1021               /* If we need to request more space for this child to fill
1022                *  its requisition, then divide up the needed space evenly
1023                *  amongst the columns it spans.
1024                */
1025               if (width < child_requisition.width + child->xpadding * 2)
1026                 {
1027                   width = child_requisition.width + child->xpadding * 2 - width;
1028                   
1029                   for (col = child->left_attach; col < child->right_attach; col++)
1030                     {
1031                       extra = width / (child->right_attach - col);
1032                       table->cols[col].requisition += extra;
1033                       width -= extra;
1034                     }
1035                 }
1036             }
1037           
1038           /* Child spans multiple rows.
1039            */
1040           if (child->top_attach != (child->bottom_attach - 1))
1041             {
1042               GtkRequisition child_requisition;
1043
1044               gtk_widget_get_child_requisition (child->widget, &child_requisition);
1045
1046               /* Check and see if there is already enough space
1047                *  for the child.
1048                */
1049               height = 0;
1050               for (row = child->top_attach; row < child->bottom_attach; row++)
1051                 {
1052                   height += table->rows[row].requisition;
1053                   if ((row + 1) < child->bottom_attach)
1054                     height += table->rows[row].spacing;
1055                 }
1056               
1057               /* If we need to request more space for this child to fill
1058                *  its requisition, then divide up the needed space evenly
1059                *  amongst the columns it spans.
1060                */
1061               if (height < child_requisition.height + child->ypadding * 2)
1062                 {
1063                   height = child_requisition.height + child->ypadding * 2 - height;
1064                   
1065                   for (row = child->top_attach; row < child->bottom_attach; row++)
1066                     {
1067                       extra = height / (child->bottom_attach - row);
1068                       table->rows[row].requisition += extra;
1069                       height -= extra;
1070                     }
1071                 }
1072             }
1073         }
1074     }
1075 }
1076
1077 static void
1078 gtk_table_size_allocate_init (GtkTable *table)
1079 {
1080   GtkTableChild *child;
1081   GList *children;
1082   gint row, col;
1083   gint has_expand;
1084   gint has_shrink;
1085   
1086   /* Initialize the rows and cols.
1087    *  By default, rows and cols do not expand and do shrink.
1088    *  Those values are modified by the children that occupy
1089    *  the rows and cols.
1090    */
1091   for (col = 0; col < table->ncols; col++)
1092     {
1093       table->cols[col].allocation = table->cols[col].requisition;
1094       table->cols[col].need_expand = FALSE;
1095       table->cols[col].need_shrink = TRUE;
1096       table->cols[col].expand = FALSE;
1097       table->cols[col].shrink = TRUE;
1098       table->cols[col].empty = TRUE;
1099     }
1100   for (row = 0; row < table->nrows; row++)
1101     {
1102       table->rows[row].allocation = table->rows[row].requisition;
1103       table->rows[row].need_expand = FALSE;
1104       table->rows[row].need_shrink = TRUE;
1105       table->rows[row].expand = FALSE;
1106       table->rows[row].shrink = TRUE;
1107       table->rows[row].empty = TRUE;
1108     }
1109   
1110   /* Loop over all the children and adjust the row and col values
1111    *  based on whether the children want to be allowed to expand
1112    *  or shrink. This loop handles children that occupy a single
1113    *  row or column.
1114    */
1115   children = table->children;
1116   while (children)
1117     {
1118       child = children->data;
1119       children = children->next;
1120       
1121       if (GTK_WIDGET_VISIBLE (child->widget))
1122         {
1123           if (child->left_attach == (child->right_attach - 1))
1124             {
1125               if (child->xexpand)
1126                 table->cols[child->left_attach].expand = TRUE;
1127               
1128               if (!child->xshrink)
1129                 table->cols[child->left_attach].shrink = FALSE;
1130               
1131               table->cols[child->left_attach].empty = FALSE;
1132             }
1133           
1134           if (child->top_attach == (child->bottom_attach - 1))
1135             {
1136               if (child->yexpand)
1137                 table->rows[child->top_attach].expand = TRUE;
1138               
1139               if (!child->yshrink)
1140                 table->rows[child->top_attach].shrink = FALSE;
1141
1142               table->rows[child->top_attach].empty = FALSE;
1143             }
1144         }
1145     }
1146   
1147   /* Loop over all the children again and this time handle children
1148    *  which span multiple rows or columns.
1149    */
1150   children = table->children;
1151   while (children)
1152     {
1153       child = children->data;
1154       children = children->next;
1155       
1156       if (GTK_WIDGET_VISIBLE (child->widget))
1157         {
1158           if (child->left_attach != (child->right_attach - 1))
1159             {
1160               for (col = child->left_attach; col < child->right_attach; col++)
1161                 table->cols[col].empty = FALSE;
1162
1163               if (child->xexpand)
1164                 {
1165                   has_expand = FALSE;
1166                   for (col = child->left_attach; col < child->right_attach; col++)
1167                     if (table->cols[col].expand)
1168                       {
1169                         has_expand = TRUE;
1170                         break;
1171                       }
1172                   
1173                   if (!has_expand)
1174                     for (col = child->left_attach; col < child->right_attach; col++)
1175                       table->cols[col].need_expand = TRUE;
1176                 }
1177               
1178               if (!child->xshrink)
1179                 {
1180                   has_shrink = TRUE;
1181                   for (col = child->left_attach; col < child->right_attach; col++)
1182                     if (!table->cols[col].shrink)
1183                       {
1184                         has_shrink = FALSE;
1185                         break;
1186                       }
1187                   
1188                   if (has_shrink)
1189                     for (col = child->left_attach; col < child->right_attach; col++)
1190                       table->cols[col].need_shrink = FALSE;
1191                 }
1192             }
1193           
1194           if (child->top_attach != (child->bottom_attach - 1))
1195             {
1196               for (row = child->top_attach; row < child->bottom_attach; row++)
1197                 table->rows[row].empty = FALSE;
1198
1199               if (child->yexpand)
1200                 {
1201                   has_expand = FALSE;
1202                   for (row = child->top_attach; row < child->bottom_attach; row++)
1203                     if (table->rows[row].expand)
1204                       {
1205                         has_expand = TRUE;
1206                         break;
1207                       }
1208                   
1209                   if (!has_expand)
1210                     for (row = child->top_attach; row < child->bottom_attach; row++)
1211                       table->rows[row].need_expand = TRUE;
1212                 }
1213               
1214               if (!child->yshrink)
1215                 {
1216                   has_shrink = TRUE;
1217                   for (row = child->top_attach; row < child->bottom_attach; row++)
1218                     if (!table->rows[row].shrink)
1219                       {
1220                         has_shrink = FALSE;
1221                         break;
1222                       }
1223                   
1224                   if (has_shrink)
1225                     for (row = child->top_attach; row < child->bottom_attach; row++)
1226                       table->rows[row].need_shrink = FALSE;
1227                 }
1228             }
1229         }
1230     }
1231   
1232   /* Loop over the columns and set the expand and shrink values
1233    *  if the column can be expanded or shrunk.
1234    */
1235   for (col = 0; col < table->ncols; col++)
1236     {
1237       if (table->cols[col].empty)
1238         {
1239           table->cols[col].expand = FALSE;
1240           table->cols[col].shrink = FALSE;
1241         }
1242       else
1243         {
1244           if (table->cols[col].need_expand)
1245             table->cols[col].expand = TRUE;
1246           if (!table->cols[col].need_shrink)
1247             table->cols[col].shrink = FALSE;
1248         }
1249     }
1250   
1251   /* Loop over the rows and set the expand and shrink values
1252    *  if the row can be expanded or shrunk.
1253    */
1254   for (row = 0; row < table->nrows; row++)
1255     {
1256       if (table->rows[row].empty)
1257         {
1258           table->rows[row].expand = FALSE;
1259           table->rows[row].shrink = FALSE;
1260         }
1261       else
1262         {
1263           if (table->rows[row].need_expand)
1264             table->rows[row].expand = TRUE;
1265           if (!table->rows[row].need_shrink)
1266             table->rows[row].shrink = FALSE;
1267         }
1268     }
1269 }
1270
1271 static void
1272 gtk_table_size_allocate_pass1 (GtkTable *table)
1273 {
1274   gint real_width;
1275   gint real_height;
1276   gint width, height;
1277   gint row, col;
1278   gint nexpand;
1279   gint nshrink;
1280   gint extra;
1281   
1282   /* If we were allocated more space than we requested
1283    *  then we have to expand any expandable rows and columns
1284    *  to fill in the extra space.
1285    */
1286   
1287   real_width = GTK_WIDGET (table)->allocation.width - GTK_CONTAINER (table)->border_width * 2;
1288   real_height = GTK_WIDGET (table)->allocation.height - GTK_CONTAINER (table)->border_width * 2;
1289   
1290   if (table->homogeneous)
1291     {
1292       nexpand = 0;
1293       for (col = 0; col < table->ncols; col++)
1294         if (table->cols[col].expand)
1295           {
1296             nexpand += 1;
1297             break;
1298           }
1299       
1300       if (nexpand > 0)
1301         {
1302           width = real_width;
1303           
1304           for (col = 0; col + 1 < table->ncols; col++)
1305             width -= table->cols[col].spacing;
1306           
1307           for (col = 0; col < table->ncols; col++)
1308             {
1309               extra = width / (table->ncols - col);
1310               table->cols[col].allocation = MAX (1, extra);
1311               width -= extra;
1312             }
1313         }
1314     }
1315   else
1316     {
1317       width = 0;
1318       nexpand = 0;
1319       nshrink = 0;
1320       
1321       for (col = 0; col < table->ncols; col++)
1322         {
1323           width += table->cols[col].requisition;
1324           if (table->cols[col].expand)
1325             nexpand += 1;
1326           if (table->cols[col].shrink)
1327             nshrink += 1;
1328         }
1329       for (col = 0; col + 1 < table->ncols; col++)
1330         width += table->cols[col].spacing;
1331       
1332       /* Check to see if we were allocated more width than we requested.
1333        */
1334       if ((width < real_width) && (nexpand >= 1))
1335         {
1336           width = real_width - width;
1337           
1338           for (col = 0; col < table->ncols; col++)
1339             if (table->cols[col].expand)
1340               {
1341                 extra = width / nexpand;
1342                 table->cols[col].allocation += extra;
1343                 
1344                 width -= extra;
1345                 nexpand -= 1;
1346               }
1347         }
1348       
1349       /* Check to see if we were allocated less width than we requested,
1350        * then shrink until we fit the size give.
1351        */
1352       if (width > real_width)
1353         {
1354           gint total_nshrink = nshrink;
1355
1356           extra = width - real_width;
1357           while (total_nshrink > 0 && extra > 0)
1358             {
1359               nshrink = total_nshrink;
1360               for (col = 0; col < table->ncols; col++)
1361                 if (table->cols[col].shrink)
1362                   {
1363                     gint allocation = table->cols[col].allocation;
1364
1365                     table->cols[col].allocation = MAX (1, (gint) table->cols[col].allocation - extra / nshrink);
1366                     extra -= allocation - table->cols[col].allocation;
1367                     nshrink -= 1;
1368                     if (table->cols[col].allocation < 2)
1369                       {
1370                         total_nshrink -= 1;
1371                         table->cols[col].shrink = FALSE;
1372                       }
1373                   }
1374             }
1375         }
1376     }
1377   
1378   if (table->homogeneous)
1379     {
1380       nexpand = 0;
1381       for (row = 0; row < table->nrows; row++)
1382         if (table->rows[row].expand)
1383           {
1384             nexpand += 1;
1385             break;
1386           }
1387       
1388       if (nexpand > 0)
1389         {
1390           height = real_height;
1391           
1392           for (row = 0; row + 1 < table->nrows; row++)
1393             height -= table->rows[row].spacing;
1394           
1395           
1396           for (row = 0; row < table->nrows; row++)
1397             {
1398               extra = height / (table->nrows - row);
1399               table->rows[row].allocation = MAX (1, extra);
1400               height -= extra;
1401             }
1402         }
1403     }
1404   else
1405     {
1406       height = 0;
1407       nexpand = 0;
1408       nshrink = 0;
1409       
1410       for (row = 0; row < table->nrows; row++)
1411         {
1412           height += table->rows[row].requisition;
1413           if (table->rows[row].expand)
1414             nexpand += 1;
1415           if (table->rows[row].shrink)
1416             nshrink += 1;
1417         }
1418       for (row = 0; row + 1 < table->nrows; row++)
1419         height += table->rows[row].spacing;
1420       
1421       /* Check to see if we were allocated more height than we requested.
1422        */
1423       if ((height < real_height) && (nexpand >= 1))
1424         {
1425           height = real_height - height;
1426           
1427           for (row = 0; row < table->nrows; row++)
1428             if (table->rows[row].expand)
1429               {
1430                 extra = height / nexpand;
1431                 table->rows[row].allocation += extra;
1432                 
1433                 height -= extra;
1434                 nexpand -= 1;
1435               }
1436         }
1437       
1438       /* Check to see if we were allocated less height than we requested.
1439        * then shrink until we fit the size give.
1440        */
1441       if (height > real_height)
1442         {
1443           gint total_nshrink = nshrink;
1444           
1445           extra = height - real_height;
1446           while (total_nshrink > 0 && extra > 0)
1447             {
1448               nshrink = total_nshrink;
1449               for (row = 0; row < table->nrows; row++)
1450                 if (table->rows[row].shrink)
1451                   {
1452                     gint allocation = table->rows[row].allocation;
1453                     
1454                     table->rows[row].allocation = MAX (1, (gint) table->rows[row].allocation - extra / nshrink);
1455                     extra -= allocation - table->rows[row].allocation;
1456                     nshrink -= 1;
1457                     if (table->rows[row].allocation < 2)
1458                       {
1459                         total_nshrink -= 1;
1460                         table->rows[row].shrink = FALSE;
1461                       }
1462                   }
1463             }
1464         }
1465     }
1466 }
1467
1468 static void
1469 gtk_table_size_allocate_pass2 (GtkTable *table)
1470 {
1471   GtkTableChild *child;
1472   GList *children;
1473   gint max_width;
1474   gint max_height;
1475   gint x, y;
1476   gint row, col;
1477   GtkAllocation allocation;
1478   GtkWidget *widget = GTK_WIDGET (table);
1479   
1480   children = table->children;
1481   while (children)
1482     {
1483       child = children->data;
1484       children = children->next;
1485       
1486       if (GTK_WIDGET_VISIBLE (child->widget))
1487         {
1488           GtkRequisition child_requisition;
1489           gtk_widget_get_child_requisition (child->widget, &child_requisition);
1490
1491           x = GTK_WIDGET (table)->allocation.x + GTK_CONTAINER (table)->border_width;
1492           y = GTK_WIDGET (table)->allocation.y + GTK_CONTAINER (table)->border_width;
1493           max_width = 0;
1494           max_height = 0;
1495           
1496           for (col = 0; col < child->left_attach; col++)
1497             {
1498               x += table->cols[col].allocation;
1499               x += table->cols[col].spacing;
1500             }
1501           
1502           for (col = child->left_attach; col < child->right_attach; col++)
1503             {
1504               max_width += table->cols[col].allocation;
1505               if ((col + 1) < child->right_attach)
1506                 max_width += table->cols[col].spacing;
1507             }
1508           
1509           for (row = 0; row < child->top_attach; row++)
1510             {
1511               y += table->rows[row].allocation;
1512               y += table->rows[row].spacing;
1513             }
1514           
1515           for (row = child->top_attach; row < child->bottom_attach; row++)
1516             {
1517               max_height += table->rows[row].allocation;
1518               if ((row + 1) < child->bottom_attach)
1519                 max_height += table->rows[row].spacing;
1520             }
1521           
1522           if (child->xfill)
1523             {
1524               allocation.width = MAX (1, max_width - (gint)child->xpadding * 2);
1525               allocation.x = x + (max_width - allocation.width) / 2;
1526             }
1527           else
1528             {
1529               allocation.width = child_requisition.width;
1530               allocation.x = x + (max_width - allocation.width) / 2;
1531             }
1532           
1533           if (child->yfill)
1534             {
1535               allocation.height = MAX (1, max_height - (gint)child->ypadding * 2);
1536               allocation.y = y + (max_height - allocation.height) / 2;
1537             }
1538           else
1539             {
1540               allocation.height = child_requisition.height;
1541               allocation.y = y + (max_height - allocation.height) / 2;
1542             }
1543
1544           if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1545             allocation.x = widget->allocation.x + widget->allocation.width
1546               - (allocation.x - widget->allocation.x) - allocation.width;
1547           
1548           gtk_widget_size_allocate (child->widget, &allocation);
1549         }
1550     }
1551 }