]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtktable.c
Merge branch 'master' into toolpalette
[~andy/gtk] / gtk / gtktable.c
index 8d7a64dd3c252b18d674942622fa8b6bbbddc3c1..a5d4b95f640f10a081b787e5f3e9129b5d9eb325 100644 (file)
@@ -2,55 +2,59 @@
  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ */
+
+#include "config.h"
 #include "gtktable.h"
+#include "gtkprivate.h"
+#include "gtkintl.h"
+#include "gtkalias.h"
 
 enum
 {
-  ARG_0,
-  ARG_N_ROWS,
-  ARG_N_COLUMNS,
-  ARG_COLUMN_SPACING,
-  ARG_ROW_SPACING,
-  ARG_HOMOGENEOUS,
+  PROP_0,
+  PROP_N_ROWS,
+  PROP_N_COLUMNS,
+  PROP_COLUMN_SPACING,
+  PROP_ROW_SPACING,
+  PROP_HOMOGENEOUS
 };
 
 enum
 {
-  CHILD_ARG_0,
-  CHILD_ARG_LEFT_ATTACH,
-  CHILD_ARG_RIGHT_ATTACH,
-  CHILD_ARG_TOP_ATTACH,
-  CHILD_ARG_BOTTOM_ATTACH,
-  CHILD_ARG_X_OPTIONS,
-  CHILD_ARG_Y_OPTIONS,
-  CHILD_ARG_X_PADDING,
-  CHILD_ARG_Y_PADDING
+  CHILD_PROP_0,
+  CHILD_PROP_LEFT_ATTACH,
+  CHILD_PROP_RIGHT_ATTACH,
+  CHILD_PROP_TOP_ATTACH,
+  CHILD_PROP_BOTTOM_ATTACH,
+  CHILD_PROP_X_OPTIONS,
+  CHILD_PROP_Y_OPTIONS,
+  CHILD_PROP_X_PADDING,
+  CHILD_PROP_Y_PADDING
 };
   
 
-static void gtk_table_class_init    (GtkTableClass  *klass);
-static void gtk_table_init         (GtkTable       *table);
-static void gtk_table_finalize     (GtkObject      *object);
-static void gtk_table_map          (GtkWidget      *widget);
-static void gtk_table_unmap        (GtkWidget      *widget);
-static void gtk_table_draw         (GtkWidget      *widget,
-                                    GdkRectangle   *area);
-static gint gtk_table_expose       (GtkWidget      *widget,
-                                    GdkEventExpose *event);
+static void gtk_table_finalize     (GObject        *object);
 static void gtk_table_size_request  (GtkWidget     *widget,
                                     GtkRequisition *requisition);
 static void gtk_table_size_allocate (GtkWidget     *widget,
@@ -59,24 +63,29 @@ static void gtk_table_add       (GtkContainer   *container,
                                     GtkWidget      *widget);
 static void gtk_table_remove       (GtkContainer   *container,
                                     GtkWidget      *widget);
-static void gtk_table_foreach      (GtkContainer   *container,
+static void gtk_table_forall       (GtkContainer   *container,
+                                    gboolean        include_internals,
                                     GtkCallback     callback,
                                     gpointer        callback_data);
-static void gtk_table_get_arg       (GtkObject      *object,
-                                    GtkArg         *arg,
-                                    guint           arg_id);
-static void gtk_table_set_arg       (GtkObject      *object,
-                                    GtkArg         *arg,
-                                    guint           arg_id);
-static void gtk_table_set_child_arg (GtkContainer   *container,
-                                    GtkWidget      *child,
-                                    GtkArg         *arg,
-                                    guint           arg_id);
-static void gtk_table_get_child_arg (GtkContainer   *container,
-                                    GtkWidget      *child,
-                                    GtkArg         *arg,
-                                    guint           arg_id);
-static GtkType gtk_table_child_type (GtkContainer   *container);
+static void gtk_table_get_property  (GObject         *object,
+                                    guint            prop_id,
+                                    GValue          *value,
+                                    GParamSpec      *pspec);
+static void gtk_table_set_property  (GObject         *object,
+                                    guint            prop_id,
+                                    const GValue    *value,
+                                    GParamSpec      *pspec);
+static void gtk_table_set_child_property (GtkContainer    *container,
+                                         GtkWidget       *child,
+                                         guint            property_id,
+                                         const GValue    *value,
+                                         GParamSpec      *pspec);
+static void gtk_table_get_child_property (GtkContainer    *container,
+                                         GtkWidget       *child,
+                                         guint            property_id,
+                                         GValue          *value,
+                                         GParamSpec      *pspec);
+static GType gtk_table_child_type   (GtkContainer   *container);
 
 
 static void gtk_table_size_request_init         (GtkTable *table);
@@ -89,157 +98,216 @@ static void gtk_table_size_allocate_pass1 (GtkTable *table);
 static void gtk_table_size_allocate_pass2 (GtkTable *table);
 
 
-static GtkContainerClass *parent_class = NULL;
-
-
-GtkType
-gtk_table_get_type (void)
-{
-  static GtkType table_type = 0;
-  
-  if (!table_type)
-    {
-      GtkTypeInfo table_info =
-      {
-       "GtkTable",
-       sizeof (GtkTable),
-       sizeof (GtkTableClass),
-       (GtkClassInitFunc) gtk_table_class_init,
-       (GtkObjectInitFunc) gtk_table_init,
-       gtk_table_set_arg,
-       gtk_table_get_arg,
-      };
-      
-      table_type = gtk_type_unique (gtk_container_get_type (), &table_info);
-    }
-  
-  return table_type;
-}
+G_DEFINE_TYPE (GtkTable, gtk_table, GTK_TYPE_CONTAINER)
 
 static void
 gtk_table_class_init (GtkTableClass *class)
 {
-  GtkObjectClass *object_class;
-  GtkWidgetClass *widget_class;
-  GtkContainerClass *container_class;
+  GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+  GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
   
-  object_class = (GtkObjectClass*) class;
-  widget_class = (GtkWidgetClass*) class;
-  container_class = (GtkContainerClass*) class;
-  
-  parent_class = gtk_type_class (gtk_container_get_type ());
-  
-  gtk_object_add_arg_type ("GtkTable::n_rows", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_N_ROWS);
-  gtk_object_add_arg_type ("GtkTable::n_columns", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_N_COLUMNS);
-  gtk_object_add_arg_type ("GtkTable::row_spacing", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_ROW_SPACING);
-  gtk_object_add_arg_type ("GtkTable::column_spacing", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_COLUMN_SPACING);
-  gtk_object_add_arg_type ("GtkTable::homogeneous", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_HOMOGENEOUS);
-  gtk_container_add_child_arg_type ("GtkTable::left_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_LEFT_ATTACH);
-  gtk_container_add_child_arg_type ("GtkTable::right_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_RIGHT_ATTACH);
-  gtk_container_add_child_arg_type ("GtkTable::top_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_TOP_ATTACH);
-  gtk_container_add_child_arg_type ("GtkTable::bottom_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_BOTTOM_ATTACH);
-  gtk_container_add_child_arg_type ("GtkTable::x_options", GTK_TYPE_ATTACH_OPTIONS, GTK_ARG_READWRITE, CHILD_ARG_X_OPTIONS);
-  gtk_container_add_child_arg_type ("GtkTable::y_options", GTK_TYPE_ATTACH_OPTIONS, GTK_ARG_READWRITE, CHILD_ARG_Y_OPTIONS);
-  gtk_container_add_child_arg_type ("GtkTable::x_padding", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_X_PADDING);
-  gtk_container_add_child_arg_type ("GtkTable::y_padding", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_Y_PADDING);
-
-  object_class->finalize = gtk_table_finalize;
+  gobject_class->finalize = gtk_table_finalize;
+
+  gobject_class->get_property = gtk_table_get_property;
+  gobject_class->set_property = gtk_table_set_property;
   
-  widget_class->map = gtk_table_map;
-  widget_class->unmap = gtk_table_unmap;
-  widget_class->draw = gtk_table_draw;
-  widget_class->expose_event = gtk_table_expose;
   widget_class->size_request = gtk_table_size_request;
   widget_class->size_allocate = gtk_table_size_allocate;
   
   container_class->add = gtk_table_add;
   container_class->remove = gtk_table_remove;
-  container_class->foreach = gtk_table_foreach;
+  container_class->forall = gtk_table_forall;
   container_class->child_type = gtk_table_child_type;
-  container_class->set_child_arg = gtk_table_set_child_arg;
-  container_class->get_child_arg = gtk_table_get_child_arg;
+  container_class->set_child_property = gtk_table_set_child_property;
+  container_class->get_child_property = gtk_table_get_child_property;
+  
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_N_ROWS,
+                                   g_param_spec_uint ("n-rows",
+                                                    P_("Rows"),
+                                                    P_("The number of rows in the table"),
+                                                    1,
+                                                    65535,
+                                                    1,
+                                                    GTK_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class,
+                                   PROP_N_COLUMNS,
+                                   g_param_spec_uint ("n-columns",
+                                                    P_("Columns"),
+                                                    P_("The number of columns in the table"),
+                                                    1,
+                                                    65535,
+                                                    1,
+                                                    GTK_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class,
+                                   PROP_ROW_SPACING,
+                                   g_param_spec_uint ("row-spacing",
+                                                    P_("Row spacing"),
+                                                    P_("The amount of space between two consecutive rows"),
+                                                    0,
+                                                    65535,
+                                                    0,
+                                                    GTK_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class,
+                                   PROP_COLUMN_SPACING,
+                                   g_param_spec_uint ("column-spacing",
+                                                    P_("Column spacing"),
+                                                    P_("The amount of space between two consecutive columns"),
+                                                    0,
+                                                    65535,
+                                                    0,
+                                                    GTK_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class,
+                                   PROP_HOMOGENEOUS,
+                                   g_param_spec_boolean ("homogeneous",
+                                                        P_("Homogeneous"),
+                                                        P_("If TRUE, the table cells are all the same width/height"),
+                                                        FALSE,
+                                                        GTK_PARAM_READWRITE));
+
+  gtk_container_class_install_child_property (container_class,
+                                             CHILD_PROP_LEFT_ATTACH,
+                                             g_param_spec_uint ("left-attach", 
+                                                                P_("Left attachment"), 
+                                                                P_("The column number to attach the left side of the child to"),
+                                                                0, 65535, 0,
+                                                                GTK_PARAM_READWRITE));
+  gtk_container_class_install_child_property (container_class,
+                                             CHILD_PROP_RIGHT_ATTACH,
+                                             g_param_spec_uint ("right-attach", 
+                                                                P_("Right attachment"), 
+                                                                P_("The column number to attach the right side of a child widget to"),
+                                                                1, 65535, 1,
+                                                                GTK_PARAM_READWRITE));
+  gtk_container_class_install_child_property (container_class,
+                                             CHILD_PROP_TOP_ATTACH,
+                                             g_param_spec_uint ("top-attach", 
+                                                                P_("Top attachment"), 
+                                                                P_("The row number to attach the top of a child widget to"),
+                                                                0, 65535, 0,
+                                                                GTK_PARAM_READWRITE));
+  gtk_container_class_install_child_property (container_class,
+                                             CHILD_PROP_BOTTOM_ATTACH,
+                                             g_param_spec_uint ("bottom-attach",
+                                                                P_("Bottom attachment"), 
+                                                                P_("The row number to attach the bottom of the child to"),
+                                                                1, 65535, 1,
+                                                                GTK_PARAM_READWRITE));
+  gtk_container_class_install_child_property (container_class,
+                                             CHILD_PROP_X_OPTIONS,
+                                             g_param_spec_flags ("x-options", 
+                                                                 P_("Horizontal options"), 
+                                                                 P_("Options specifying the horizontal behaviour of the child"),
+                                                                 GTK_TYPE_ATTACH_OPTIONS, GTK_EXPAND | GTK_FILL,
+                                                                 GTK_PARAM_READWRITE));
+  gtk_container_class_install_child_property (container_class,
+                                             CHILD_PROP_Y_OPTIONS,
+                                             g_param_spec_flags ("y-options", 
+                                                                 P_("Vertical options"), 
+                                                                 P_("Options specifying the vertical behaviour of the child"),
+                                                                 GTK_TYPE_ATTACH_OPTIONS, GTK_EXPAND | GTK_FILL,
+                                                                 GTK_PARAM_READWRITE));
+  gtk_container_class_install_child_property (container_class,
+                                             CHILD_PROP_X_PADDING,
+                                             g_param_spec_uint ("x-padding", 
+                                                                P_("Horizontal padding"), 
+                                                                P_("Extra space to put between the child and its left and right neighbors, in pixels"),
+                                                                0, 65535, 0,
+                                                                GTK_PARAM_READWRITE));
+  gtk_container_class_install_child_property (container_class,
+                                             CHILD_PROP_Y_PADDING,
+                                             g_param_spec_uint ("y-padding", 
+                                                                P_("Vertical padding"), 
+                                                                P_("Extra space to put between the child and its upper and lower neighbors, in pixels"),
+                                                                0, 65535, 0,
+                                                                GTK_PARAM_READWRITE));
 }
 
-static GtkType
+static GType
 gtk_table_child_type (GtkContainer   *container)
 {
   return GTK_TYPE_WIDGET;
 }
 
 static void
-gtk_table_get_arg (GtkObject      *object,
-                  GtkArg         *arg,
-                  guint           arg_id)
+gtk_table_get_property (GObject      *object,
+                       guint         prop_id,
+                       GValue       *value,
+                       GParamSpec   *pspec)
 {
   GtkTable *table;
 
   table = GTK_TABLE (object);
 
-  switch (arg_id)
+  switch (prop_id)
     {
-    case ARG_N_ROWS:
-      GTK_VALUE_UINT (*arg) = table->nrows;
+    case PROP_N_ROWS:
+      g_value_set_uint (value, table->nrows);
       break;
-    case ARG_N_COLUMNS:
-      GTK_VALUE_UINT (*arg) = table->ncols;
+    case PROP_N_COLUMNS:
+      g_value_set_uint (value, table->ncols);
       break;
-    case ARG_ROW_SPACING:
-      GTK_VALUE_UINT (*arg) = table->row_spacing;
+    case PROP_ROW_SPACING:
+      g_value_set_uint (value, table->row_spacing);
       break;
-    case ARG_COLUMN_SPACING:
-      GTK_VALUE_UINT (*arg) = table->column_spacing;
+    case PROP_COLUMN_SPACING:
+      g_value_set_uint (value, table->column_spacing);
       break;
-    case ARG_HOMOGENEOUS:
-      GTK_VALUE_BOOL (*arg) = table->homogeneous;
+    case PROP_HOMOGENEOUS:
+      g_value_set_boolean (value, table->homogeneous);
       break;
     default:
-      arg->type = GTK_TYPE_INVALID;
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
     }
 }
 
 static void
-gtk_table_set_arg (GtkObject      *object,
-                  GtkArg         *arg,
-                  guint           arg_id)
+gtk_table_set_property (GObject      *object,
+                       guint         prop_id,
+                       const GValue *value,
+                       GParamSpec   *pspec)
 {
   GtkTable *table;
 
   table = GTK_TABLE (object);
 
-  switch (arg_id)
+  switch (prop_id)
     {
-    case ARG_N_ROWS:
-      gtk_table_resize (table, GTK_VALUE_UINT (*arg), table->ncols);
+    case PROP_N_ROWS:
+      gtk_table_resize (table, g_value_get_uint (value), table->ncols);
       break;
-    case ARG_N_COLUMNS:
-      gtk_table_resize (table, table->nrows, GTK_VALUE_UINT (*arg));
+    case PROP_N_COLUMNS:
+      gtk_table_resize (table, table->nrows, g_value_get_uint (value));
       break;
-    case ARG_ROW_SPACING:
-      gtk_table_set_row_spacings (table, GTK_VALUE_UINT (*arg));
+    case PROP_ROW_SPACING:
+      gtk_table_set_row_spacings (table, g_value_get_uint (value));
       break;
-    case ARG_COLUMN_SPACING:
-      gtk_table_set_col_spacings (table, GTK_VALUE_UINT (*arg));
+    case PROP_COLUMN_SPACING:
+      gtk_table_set_col_spacings (table, g_value_get_uint (value));
       break;
-    case ARG_HOMOGENEOUS:
-      gtk_table_set_homogeneous (table, GTK_VALUE_BOOL (*arg));
+    case PROP_HOMOGENEOUS:
+      gtk_table_set_homogeneous (table, g_value_get_boolean (value));
       break;
     default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
     }
 }
 
 static void
-gtk_table_set_child_arg (GtkContainer   *container,
-                        GtkWidget      *child,
-                        GtkArg         *arg,
-                        guint           arg_id)
+gtk_table_set_child_property (GtkContainer    *container,
+                             GtkWidget       *child,
+                             guint            property_id,
+                             const GValue    *value,
+                             GParamSpec      *pspec)
 {
-  GtkTable *table;
+  GtkTable *table = GTK_TABLE (container);
   GtkTableChild *table_child;
   GList *list;
 
-  table = GTK_TABLE (container);
   table_child = NULL;
   for (list = table->children; list; list = list->next)
     {
@@ -249,64 +317,76 @@ gtk_table_set_child_arg (GtkContainer   *container,
        break;
     }
   if (!list)
-    return;
+    {
+      GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
+      return;
+    }
 
-  switch (arg_id)
+  switch (property_id)
     {
-    case CHILD_ARG_LEFT_ATTACH:
-      if (GTK_VALUE_UINT (*arg) < table_child->right_attach)
-       table_child->left_attach = GTK_VALUE_UINT (*arg);
+    case CHILD_PROP_LEFT_ATTACH:
+      table_child->left_attach = g_value_get_uint (value);
+      if (table_child->right_attach <= table_child->left_attach)
+       table_child->right_attach = table_child->left_attach + 1;
+      if (table_child->right_attach >= table->ncols)
+       gtk_table_resize (table, table->nrows, table_child->right_attach);
       break;
-    case CHILD_ARG_RIGHT_ATTACH:
-      if (GTK_VALUE_UINT (*arg) > table_child->left_attach)
-       table_child->right_attach = GTK_VALUE_UINT (*arg);
+    case CHILD_PROP_RIGHT_ATTACH:
+      table_child->right_attach = g_value_get_uint (value);
+      if (table_child->right_attach <= table_child->left_attach)
+       table_child->left_attach = table_child->right_attach - 1;
       if (table_child->right_attach >= table->ncols)
-       gtk_table_resize (table, table->ncols, table_child->right_attach + 1);
+       gtk_table_resize (table, table->nrows, table_child->right_attach);
       break;
-    case CHILD_ARG_TOP_ATTACH:
-      if (GTK_VALUE_UINT (*arg) < table_child->bottom_attach)
-       table_child->top_attach = GTK_VALUE_UINT (*arg);
+    case CHILD_PROP_TOP_ATTACH:
+      table_child->top_attach = g_value_get_uint (value);
+      if (table_child->bottom_attach <= table_child->top_attach)
+       table_child->bottom_attach = table_child->top_attach + 1;
+      if (table_child->bottom_attach >= table->nrows)
+       gtk_table_resize (table, table_child->bottom_attach, table->ncols);
       break;
-    case CHILD_ARG_BOTTOM_ATTACH:
-      if (GTK_VALUE_UINT (*arg) > table_child->top_attach)
-       table_child->bottom_attach = GTK_VALUE_UINT (*arg);
+    case CHILD_PROP_BOTTOM_ATTACH:
+      table_child->bottom_attach = g_value_get_uint (value);
+      if (table_child->bottom_attach <= table_child->top_attach)
+       table_child->top_attach = table_child->bottom_attach - 1;
       if (table_child->bottom_attach >= table->nrows)
-       gtk_table_resize (table, table_child->bottom_attach + 1, table->ncols);
+       gtk_table_resize (table, table_child->bottom_attach, table->ncols);
       break;
-    case CHILD_ARG_X_OPTIONS:
-      table_child->xexpand = (GTK_VALUE_FLAGS (*arg) & GTK_EXPAND) != 0;
-      table_child->xshrink = (GTK_VALUE_FLAGS (*arg) & GTK_SHRINK) != 0;
-      table_child->xfill = (GTK_VALUE_FLAGS (*arg) & GTK_FILL) != 0;
+    case CHILD_PROP_X_OPTIONS:
+      table_child->xexpand = (g_value_get_flags (value) & GTK_EXPAND) != 0;
+      table_child->xshrink = (g_value_get_flags (value) & GTK_SHRINK) != 0;
+      table_child->xfill = (g_value_get_flags (value) & GTK_FILL) != 0;
       break;
-    case CHILD_ARG_Y_OPTIONS:
-      table_child->yexpand = (GTK_VALUE_FLAGS (*arg) & GTK_EXPAND) != 0;
-      table_child->yshrink = (GTK_VALUE_FLAGS (*arg) & GTK_SHRINK) != 0;
-      table_child->yfill = (GTK_VALUE_FLAGS (*arg) & GTK_FILL) != 0;
+    case CHILD_PROP_Y_OPTIONS:
+      table_child->yexpand = (g_value_get_flags (value) & GTK_EXPAND) != 0;
+      table_child->yshrink = (g_value_get_flags (value) & GTK_SHRINK) != 0;
+      table_child->yfill = (g_value_get_flags (value) & GTK_FILL) != 0;
       break;
-    case CHILD_ARG_X_PADDING:
-      table_child->xpadding = GTK_VALUE_UINT (*arg);
+    case CHILD_PROP_X_PADDING:
+      table_child->xpadding = g_value_get_uint (value);
       break;
-    case CHILD_ARG_Y_PADDING:
-      table_child->ypadding = GTK_VALUE_UINT (*arg);
+    case CHILD_PROP_Y_PADDING:
+      table_child->ypadding = g_value_get_uint (value);
       break;
     default:
+      GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
       break;
     }
   if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (table))
-    gtk_widget_queue_resize (GTK_WIDGET (table));
+    gtk_widget_queue_resize (child);
 }
 
 static void
-gtk_table_get_child_arg (GtkContainer   *container,
-                        GtkWidget      *child,
-                        GtkArg         *arg,
-                        guint           arg_id)
+gtk_table_get_child_property (GtkContainer    *container,
+                             GtkWidget       *child,
+                             guint            property_id,
+                             GValue          *value,
+                             GParamSpec      *pspec)
 {
-  GtkTable *table;
+  GtkTable *table = GTK_TABLE (container);
   GtkTableChild *table_child;
   GList *list;
 
-  table = GTK_TABLE (container);
   table_child = NULL;
   for (list = table->children; list; list = list->next)
     {
@@ -316,40 +396,43 @@ gtk_table_get_child_arg (GtkContainer   *container,
        break;
     }
   if (!list)
-    return;
+    {
+      GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
+      return;
+    }
 
-  switch (arg_id)
+  switch (property_id)
     {
-    case CHILD_ARG_LEFT_ATTACH:
-      GTK_VALUE_UINT (*arg) = table_child->left_attach;
+    case CHILD_PROP_LEFT_ATTACH:
+      g_value_set_uint (value, table_child->left_attach);
       break;
-    case CHILD_ARG_RIGHT_ATTACH:
-      GTK_VALUE_UINT (*arg) = table_child->right_attach;
+    case CHILD_PROP_RIGHT_ATTACH:
+      g_value_set_uint (value, table_child->right_attach);
       break;
-    case CHILD_ARG_TOP_ATTACH:
-      GTK_VALUE_UINT (*arg) = table_child->top_attach;
+    case CHILD_PROP_TOP_ATTACH:
+      g_value_set_uint (value, table_child->top_attach);
       break;
-    case CHILD_ARG_BOTTOM_ATTACH:
-      GTK_VALUE_UINT (*arg) = table_child->bottom_attach;
+    case CHILD_PROP_BOTTOM_ATTACH:
+      g_value_set_uint (value, table_child->bottom_attach);
       break;
-    case CHILD_ARG_X_OPTIONS:
-      GTK_VALUE_FLAGS (*arg) = (table_child->xexpand * GTK_EXPAND |
-                               table_child->xshrink * GTK_SHRINK |
-                               table_child->xfill * GTK_FILL);
+    case CHILD_PROP_X_OPTIONS:
+      g_value_set_flags (value, (table_child->xexpand * GTK_EXPAND |
+                                table_child->xshrink * GTK_SHRINK |
+                                table_child->xfill * GTK_FILL));
       break;
-    case CHILD_ARG_Y_OPTIONS:
-      GTK_VALUE_FLAGS (*arg) = (table_child->yexpand * GTK_EXPAND |
-                               table_child->yshrink * GTK_SHRINK |
-                               table_child->yfill * GTK_FILL);
+    case CHILD_PROP_Y_OPTIONS:
+      g_value_set_flags (value, (table_child->yexpand * GTK_EXPAND |
+                                table_child->yshrink * GTK_SHRINK |
+                                table_child->yfill * GTK_FILL));
       break;
-    case CHILD_ARG_X_PADDING:
-      GTK_VALUE_UINT (*arg) = table_child->xpadding;
+    case CHILD_PROP_X_PADDING:
+      g_value_set_uint (value, table_child->xpadding);
       break;
-    case CHILD_ARG_Y_PADDING:
-      GTK_VALUE_UINT (*arg) = table_child->ypadding;
+    case CHILD_PROP_Y_PADDING:
+      g_value_set_uint (value, table_child->ypadding);
       break;
     default:
-      arg->type = GTK_TYPE_INVALID;
+      GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
       break;
     }
 }
@@ -357,7 +440,8 @@ gtk_table_get_child_arg (GtkContainer   *container,
 static void
 gtk_table_init (GtkTable *table)
 {
-  GTK_WIDGET_SET_FLAGS (table, GTK_NO_WINDOW | GTK_BASIC);
+  GTK_WIDGET_SET_FLAGS (table, GTK_NO_WINDOW);
+  gtk_widget_set_redraw_on_allocate (GTK_WIDGET (table), FALSE);
   
   table->children = NULL;
   table->rows = NULL;
@@ -367,6 +451,8 @@ gtk_table_init (GtkTable *table)
   table->column_spacing = 0;
   table->row_spacing = 0;
   table->homogeneous = FALSE;
+
+  gtk_table_resize (table, 1, 1);
 }
 
 GtkWidget*
@@ -376,10 +462,12 @@ gtk_table_new (guint      rows,
 {
   GtkTable *table;
 
-  g_return_val_if_fail (rows >= 1, NULL);
-  g_return_val_if_fail (columns >= 1, NULL);
+  if (rows == 0)
+    rows = 1;
+  if (columns == 0)
+    columns = 1;
   
-  table = gtk_type_new (gtk_table_get_type ());
+  table = g_object_new (GTK_TYPE_TABLE, NULL);
   
   table->homogeneous = (homogeneous ? TRUE : FALSE);
 
@@ -393,12 +481,13 @@ gtk_table_resize (GtkTable *table,
                  guint     n_rows,
                  guint     n_cols)
 {
-  g_return_if_fail (table != NULL);
   g_return_if_fail (GTK_IS_TABLE (table));
+  g_return_if_fail (n_rows > 0 && n_rows <= 65535);
+  g_return_if_fail (n_cols > 0 && n_cols <= 65535);
 
   n_rows = MAX (n_rows, 1);
   n_cols = MAX (n_cols, 1);
-  
+
   if (n_rows != table->nrows ||
       n_cols != table->ncols)
     {
@@ -410,8 +499,8 @@ gtk_table_resize (GtkTable *table,
          
          child = list->data;
          
-         n_rows = MAX (n_rows, child->bottom_attach + 1);
-         n_cols = MAX (n_cols, child->right_attach + 1);
+         n_rows = MAX (n_rows, child->bottom_attach);
+         n_cols = MAX (n_cols, child->right_attach);
        }
       
       if (n_rows != table->nrows)
@@ -432,6 +521,8 @@ gtk_table_resize (GtkTable *table,
              table->rows[i].expand = 0;
              table->rows[i].shrink = 0;
            }
+
+         g_object_notify (G_OBJECT (table), "n-rows");
        }
 
       if (n_cols != table->ncols)
@@ -452,6 +543,8 @@ gtk_table_resize (GtkTable *table,
              table->cols[i].expand = 0;
              table->cols[i].shrink = 0;
            }
+
+         g_object_notify (G_OBJECT (table), "n-columns");
        }
     }
 }
@@ -470,9 +563,7 @@ gtk_table_attach (GtkTable    *table,
 {
   GtkTableChild *table_child;
   
-  g_return_if_fail (table != NULL);
   g_return_if_fail (GTK_IS_TABLE (table));
-  g_return_if_fail (child != NULL);
   g_return_if_fail (GTK_IS_WIDGET (child));
   g_return_if_fail (child->parent == NULL);
   
@@ -482,10 +573,10 @@ gtk_table_attach (GtkTable          *table,
   g_return_if_fail (top_attach < bottom_attach);
   
   if (right_attach >= table->ncols)
-    gtk_table_resize (table, table->nrows, right_attach + 1);
+    gtk_table_resize (table, table->nrows, right_attach);
   
   if (bottom_attach >= table->nrows)
-    gtk_table_resize (table, bottom_attach + 1, table->ncols);
+    gtk_table_resize (table, bottom_attach, table->ncols);
   
   table_child = g_new (GtkTableChild, 1);
   table_child->widget = child;
@@ -505,20 +596,6 @@ gtk_table_attach (GtkTable   *table,
   table->children = g_list_prepend (table->children, table_child);
   
   gtk_widget_set_parent (child, GTK_WIDGET (table));
-  
-  if (GTK_WIDGET_VISIBLE (GTK_WIDGET (table)))
-    {
-      if (GTK_WIDGET_REALIZED (GTK_WIDGET (table)) &&
-         !GTK_WIDGET_REALIZED (child))
-       gtk_widget_realize (child);
-      
-      if (GTK_WIDGET_MAPPED (GTK_WIDGET (table)) &&
-         !GTK_WIDGET_MAPPED (child))
-       gtk_widget_map (child);
-    }
-  
-  if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (table))
-    gtk_widget_queue_resize (GTK_WIDGET (table));
 }
 
 void
@@ -542,10 +619,8 @@ gtk_table_set_row_spacing (GtkTable *table,
                           guint     row,
                           guint     spacing)
 {
-  g_return_if_fail (table != NULL);
   g_return_if_fail (GTK_IS_TABLE (table));
-  /* g_return_if_fail ((row >= 0) && (row < (table->nrows - 1))); */
-  g_return_if_fail (row < table->nrows - 1);
+  g_return_if_fail (row < table->nrows);
   
   if (table->rows[row].spacing != spacing)
     {
@@ -556,15 +631,33 @@ gtk_table_set_row_spacing (GtkTable *table,
     }
 }
 
+/**
+ * gtk_table_get_row_spacing:
+ * @table: a #GtkTable
+ * @row: a row in the table, 0 indicates the first row
+ *
+ * Gets the amount of space between row @row, and
+ * row @row + 1. See gtk_table_set_row_spacing().
+ *
+ * Return value: the row spacing
+ **/
+guint
+gtk_table_get_row_spacing (GtkTable *table,
+                          guint     row)
+{
+  g_return_val_if_fail (GTK_IS_TABLE (table), 0);
+  g_return_val_if_fail (row < table->nrows - 1, 0);
+  return table->rows[row].spacing;
+}
+
 void
 gtk_table_set_col_spacing (GtkTable *table,
                           guint     column,
                           guint     spacing)
 {
-  g_return_if_fail (table != NULL);
   g_return_if_fail (GTK_IS_TABLE (table));
-  /* g_return_if_fail ((column >= 0) && (column < (table->ncols - 1))); */
-  g_return_if_fail (column < table->ncols - 1);
+  g_return_if_fail (column < table->ncols);
   
   if (table->cols[column].spacing != spacing)
     {
@@ -575,21 +668,60 @@ gtk_table_set_col_spacing (GtkTable *table,
     }
 }
 
+/**
+ * gtk_table_get_col_spacing:
+ * @table: a #GtkTable
+ * @column: a column in the table, 0 indicates the first column
+ *
+ * Gets the amount of space between column @col, and
+ * column @col + 1. See gtk_table_set_col_spacing().
+ *
+ * Return value: the column spacing
+ **/
+guint
+gtk_table_get_col_spacing (GtkTable *table,
+                          guint     column)
+{
+  g_return_val_if_fail (GTK_IS_TABLE (table), 0);
+  g_return_val_if_fail (column < table->ncols, 0);
+
+  return table->cols[column].spacing;
+}
+
 void
 gtk_table_set_row_spacings (GtkTable *table,
                            guint     spacing)
 {
   guint row;
   
-  g_return_if_fail (table != NULL);
   g_return_if_fail (GTK_IS_TABLE (table));
   
   table->row_spacing = spacing;
-  for (row = 0; row < table->nrows - 1; row++)
+  for (row = 0; row < table->nrows; row++)
     table->rows[row].spacing = spacing;
   
   if (GTK_WIDGET_VISIBLE (table))
     gtk_widget_queue_resize (GTK_WIDGET (table));
+
+  g_object_notify (G_OBJECT (table), "row-spacing");
+}
+
+/**
+ * gtk_table_get_default_row_spacing:
+ * @table: a #GtkTable
+ *
+ * Gets the default row spacing for the table. This is
+ * the spacing that will be used for newly added rows.
+ * (See gtk_table_set_row_spacings())
+ *
+ * Return value: the default row spacing
+ **/
+guint
+gtk_table_get_default_row_spacing (GtkTable *table)
+{
+  g_return_val_if_fail (GTK_IS_TABLE (table), 0);
+
+  return table->row_spacing;
 }
 
 void
@@ -598,22 +730,40 @@ gtk_table_set_col_spacings (GtkTable *table,
 {
   guint col;
   
-  g_return_if_fail (table != NULL);
   g_return_if_fail (GTK_IS_TABLE (table));
   
   table->column_spacing = spacing;
-  for (col = 0; col < table->ncols - 1; col++)
+  for (col = 0; col < table->ncols; col++)
     table->cols[col].spacing = spacing;
   
   if (GTK_WIDGET_VISIBLE (table))
     gtk_widget_queue_resize (GTK_WIDGET (table));
+
+  g_object_notify (G_OBJECT (table), "column-spacing");
+}
+
+/**
+ * gtk_table_get_default_col_spacing:
+ * @table: a #GtkTable
+ *
+ * Gets the default column spacing for the table. This is
+ * the spacing that will be used for newly added columns.
+ * (See gtk_table_set_col_spacings())
+ *
+ * Return value: the default column spacing
+ **/
+guint
+gtk_table_get_default_col_spacing (GtkTable *table)
+{
+  g_return_val_if_fail (GTK_IS_TABLE (table), 0);
+
+  return table->column_spacing;
 }
 
 void
 gtk_table_set_homogeneous (GtkTable *table,
                           gboolean  homogeneous)
 {
-  g_return_if_fail (table != NULL);
   g_return_if_fail (GTK_IS_TABLE (table));
 
   homogeneous = (homogeneous != 0);
@@ -623,149 +773,46 @@ gtk_table_set_homogeneous (GtkTable *table,
       
       if (GTK_WIDGET_VISIBLE (table))
        gtk_widget_queue_resize (GTK_WIDGET (table));
+
+      g_object_notify (G_OBJECT (table), "homogeneous");
     }
 }
 
-static void
-gtk_table_finalize (GtkObject *object)
+/**
+ * gtk_table_get_homogeneous:
+ * @table: a #GtkTable
+ *
+ * Returns whether the table cells are all constrained to the same
+ * width and height. (See gtk_table_set_homogenous ())
+ *
+ * Return value: %TRUE if the cells are all constrained to the same size
+ **/
+gboolean
+gtk_table_get_homogeneous (GtkTable *table)
 {
-  GtkTable *table;
-  
-  g_return_if_fail (object != NULL);
-  g_return_if_fail (GTK_IS_TABLE (object));
-  
-  table = GTK_TABLE (object);
-  
-  g_free (table->rows);
-  g_free (table->cols);
-  
-  (* GTK_OBJECT_CLASS (parent_class)->finalize) (object);
-}
+  g_return_val_if_fail (GTK_IS_TABLE (table), FALSE);
 
-static void
-gtk_table_map (GtkWidget *widget)
-{
-  GtkTable *table;
-  GtkTableChild *child;
-  GList *children;
-  
-  g_return_if_fail (widget != NULL);
-  g_return_if_fail (GTK_IS_TABLE (widget));
-  
-  table = GTK_TABLE (widget);
-  GTK_WIDGET_SET_FLAGS (table, GTK_MAPPED);
-  
-  children = table->children;
-  while (children)
-    {
-      child = children->data;
-      children = children->next;
-      
-      if (GTK_WIDGET_VISIBLE (child->widget) &&
-         !GTK_WIDGET_MAPPED (child->widget))
-       gtk_widget_map (child->widget);
-    }
+  return table->homogeneous;
 }
 
 static void
-gtk_table_unmap (GtkWidget *widget)
+gtk_table_finalize (GObject *object)
 {
-  GtkTable *table;
-  GtkTableChild *child;
-  GList *children;
-  
-  g_return_if_fail (widget != NULL);
-  g_return_if_fail (GTK_IS_TABLE (widget));
-  
-  table = GTK_TABLE (widget);
-  GTK_WIDGET_UNSET_FLAGS (table, GTK_MAPPED);
-  
-  children = table->children;
-  while (children)
-    {
-      child = children->data;
-      children = children->next;
-      
-      if (GTK_WIDGET_VISIBLE (child->widget) &&
-         GTK_WIDGET_MAPPED (child->widget))
-       gtk_widget_unmap (child->widget);
-    }
-}
+  GtkTable *table = GTK_TABLE (object);
 
-static void
-gtk_table_draw (GtkWidget    *widget,
-               GdkRectangle *area)
-{
-  GtkTable *table;
-  GtkTableChild *child;
-  GList *children;
-  GdkRectangle child_area;
-  
-  g_return_if_fail (widget != NULL);
-  g_return_if_fail (GTK_IS_TABLE (widget));
-  
-  if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget))
-    {
-      table = GTK_TABLE (widget);
-      
-      children = table->children;
-      while (children)
-       {
-         child = children->data;
-         children = children->next;
-         
-         if (gtk_widget_intersect (child->widget, area, &child_area))
-           gtk_widget_draw (child->widget, &child_area);
-       }
-    }
-}
-
-static gint
-gtk_table_expose (GtkWidget     *widget,
-                 GdkEventExpose *event)
-{
-  GtkTable *table;
-  GtkTableChild *child;
-  GList *children;
-  GdkEventExpose child_event;
-  
-  g_return_val_if_fail (widget != NULL, FALSE);
-  g_return_val_if_fail (GTK_IS_TABLE (widget), FALSE);
-  
-  if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget))
-    {
-      table = GTK_TABLE (widget);
-      
-      child_event = *event;
-      
-      children = table->children;
-      while (children)
-       {
-         child = children->data;
-         children = children->next;
-         
-         if (GTK_WIDGET_NO_WINDOW (child->widget) &&
-             gtk_widget_intersect (child->widget, &event->area, &child_event.area))
-           gtk_widget_event (child->widget, (GdkEvent*) &child_event);
-       }
-    }
+  g_free (table->rows);
+  g_free (table->cols);
   
-  return FALSE;
+  G_OBJECT_CLASS (gtk_table_parent_class)->finalize (object);
 }
 
 static void
 gtk_table_size_request (GtkWidget      *widget,
                        GtkRequisition *requisition)
 {
-  GtkTable *table;
+  GtkTable *table = GTK_TABLE (widget);
   gint row, col;
-  
-  g_return_if_fail (widget != NULL);
-  g_return_if_fail (GTK_IS_TABLE (widget));
-  g_return_if_fail (requisition != NULL);
-  
-  table = GTK_TABLE (widget);
-  
+
   requisition->width = 0;
   requisition->height = 0;
   
@@ -777,12 +824,12 @@ gtk_table_size_request (GtkWidget      *widget,
   
   for (col = 0; col < table->ncols; col++)
     requisition->width += table->cols[col].requisition;
-  for (col = 0; col < table->ncols - 1; col++)
+  for (col = 0; col + 1 < table->ncols; col++)
     requisition->width += table->cols[col].spacing;
   
   for (row = 0; row < table->nrows; row++)
     requisition->height += table->rows[row].requisition;
-  for (row = 0; row < table->nrows - 1; row++)
+  for (row = 0; row + 1 < table->nrows; row++)
     requisition->height += table->rows[row].spacing;
   
   requisition->width += GTK_CONTAINER (table)->border_width * 2;
@@ -793,15 +840,10 @@ static void
 gtk_table_size_allocate (GtkWidget     *widget,
                         GtkAllocation *allocation)
 {
-  GtkTable *table;
-  
-  g_return_if_fail (widget != NULL);
-  g_return_if_fail (GTK_IS_TABLE (widget));
-  g_return_if_fail (allocation != NULL);
-  
+  GtkTable *table = GTK_TABLE (widget);
+
   widget->allocation = *allocation;
-  table = GTK_TABLE (widget);
-  
+
   gtk_table_size_allocate_init (table);
   gtk_table_size_allocate_pass1 (table);
   gtk_table_size_allocate_pass2 (table);
@@ -811,10 +853,6 @@ static void
 gtk_table_add (GtkContainer *container,
               GtkWidget    *widget)
 {
-  g_return_if_fail (container != NULL);
-  g_return_if_fail (GTK_IS_TABLE (container));
-  g_return_if_fail (widget != NULL);
-  
   gtk_table_attach_defaults (GTK_TABLE (container), widget, 0, 1, 0, 1);
 }
 
@@ -822,15 +860,10 @@ static void
 gtk_table_remove (GtkContainer *container,
                  GtkWidget    *widget)
 {
-  GtkTable *table;
+  GtkTable *table = GTK_TABLE (container);
   GtkTableChild *child;
   GList *children;
-  
-  g_return_if_fail (container != NULL);
-  g_return_if_fail (GTK_IS_TABLE (container));
-  g_return_if_fail (widget != NULL);
-  
-  table = GTK_TABLE (container);
+
   children = table->children;
   
   while (children)
@@ -855,19 +888,15 @@ gtk_table_remove (GtkContainer *container,
 }
 
 static void
-gtk_table_foreach (GtkContainer *container,
-                  GtkCallback     callback,
-                  gpointer        callback_data)
+gtk_table_forall (GtkContainer *container,
+                 gboolean      include_internals,
+                 GtkCallback   callback,
+                 gpointer      callback_data)
 {
-  GtkTable *table;
+  GtkTable *table = GTK_TABLE (container);
   GtkTableChild *child;
   GList *children;
-  
-  g_return_if_fail (container != NULL);
-  g_return_if_fail (GTK_IS_TABLE (container));
-  g_return_if_fail (callback != NULL);
-  
-  table = GTK_TABLE (container);
+
   children = table->children;
   
   while (children)
@@ -887,9 +916,15 @@ gtk_table_size_request_init (GtkTable *table)
   gint row, col;
   
   for (row = 0; row < table->nrows; row++)
-    table->rows[row].requisition = 0;
+    {
+      table->rows[row].requisition = 0;
+      table->rows[row].expand = FALSE;
+    }
   for (col = 0; col < table->ncols; col++)
-    table->cols[col].requisition = 0;
+    {
+      table->cols[col].requisition = 0;
+      table->cols[col].expand = FALSE;
+    }
   
   children = table->children;
   while (children)
@@ -898,7 +933,13 @@ gtk_table_size_request_init (GtkTable *table)
       children = children->next;
       
       if (GTK_WIDGET_VISIBLE (child->widget))
-       gtk_widget_size_request (child->widget, &child->widget->requisition);
+       gtk_widget_size_request (child->widget, NULL);
+
+      if (child->left_attach == (child->right_attach - 1) && child->xexpand)
+       table->cols[child->left_attach].expand = TRUE;
+      
+      if (child->top_attach == (child->bottom_attach - 1) && child->yexpand)
+       table->rows[child->top_attach].expand = TRUE;
     }
 }
 
@@ -918,11 +959,14 @@ gtk_table_size_request_pass1 (GtkTable *table)
       
       if (GTK_WIDGET_VISIBLE (child->widget))
        {
+         GtkRequisition child_requisition;
+         gtk_widget_get_child_requisition (child->widget, &child_requisition);
+
          /* Child spans a single column.
           */
          if (child->left_attach == (child->right_attach - 1))
            {
-             width = child->widget->requisition.width + child->xpadding * 2;
+             width = child_requisition.width + child->xpadding * 2;
              table->cols[child->left_attach].requisition = MAX (table->cols[child->left_attach].requisition, width);
            }
          
@@ -930,7 +974,7 @@ gtk_table_size_request_pass1 (GtkTable *table)
           */
          if (child->top_attach == (child->bottom_attach - 1))
            {
-             height = child->widget->requisition.height + child->ypadding * 2;
+             height = child_requisition.height + child->ypadding * 2;
              table->rows[child->top_attach].requisition = MAX (table->rows[child->top_attach].requisition, height);
            }
        }
@@ -982,6 +1026,10 @@ gtk_table_size_request_pass3 (GtkTable *table)
           */
          if (child->left_attach != (child->right_attach - 1))
            {
+             GtkRequisition child_requisition;
+
+             gtk_widget_get_child_requisition (child->widget, &child_requisition);
+             
              /* Check and see if there is already enough space
               *  for the child.
               */
@@ -994,19 +1042,34 @@ gtk_table_size_request_pass3 (GtkTable *table)
                }
              
              /* If we need to request more space for this child to fill
-              *  its requisition, then divide up the needed space evenly
-              *  amongst the columns it spans.
+              *  its requisition, then divide up the needed space amongst the
+              *  columns it spans, favoring expandable columns if any.
               */
-             if (width < child->widget->requisition.width + child->xpadding * 2)
+             if (width < child_requisition.width + child->xpadding * 2)
                {
-                 width = child->widget->requisition.width + child->xpadding * 2 - width;
+                 gint n_expand = 0;
+                 gboolean force_expand = FALSE;
                  
+                 width = child_requisition.width + child->xpadding * 2 - width;
+
                  for (col = child->left_attach; col < child->right_attach; col++)
+                   if (table->cols[col].expand)
+                     n_expand++;
+
+                 if (n_expand == 0)
                    {
-                     extra = width / (child->right_attach - col);
-                     table->cols[col].requisition += extra;
-                     width -= extra;
+                     n_expand = (child->right_attach - child->left_attach);
+                     force_expand = TRUE;
                    }
+                   
+                 for (col = child->left_attach; col < child->right_attach; col++)
+                   if (force_expand || table->cols[col].expand)
+                     {
+                       extra = width / n_expand;
+                       table->cols[col].requisition += extra;
+                       width -= extra;
+                       n_expand--;
+                     }
                }
            }
          
@@ -1014,6 +1077,10 @@ gtk_table_size_request_pass3 (GtkTable *table)
           */
          if (child->top_attach != (child->bottom_attach - 1))
            {
+             GtkRequisition child_requisition;
+
+             gtk_widget_get_child_requisition (child->widget, &child_requisition);
+
              /* Check and see if there is already enough space
               *  for the child.
               */
@@ -1026,19 +1093,36 @@ gtk_table_size_request_pass3 (GtkTable *table)
                }
              
              /* If we need to request more space for this child to fill
-              *  its requisition, then divide up the needed space evenly
-              *  amongst the columns it spans.
+              *  its requisition, then divide up the needed space amongst the
+              *  rows it spans, favoring expandable rows if any.
               */
-             if (height < child->widget->requisition.height + child->ypadding * 2)
+             if (height < child_requisition.height + child->ypadding * 2)
                {
-                 height = child->widget->requisition.height + child->ypadding * 2 - height;
+                 gint n_expand = 0;
+                 gboolean force_expand = FALSE;
+                 
+                 height = child_requisition.height + child->ypadding * 2 - height;
                  
                  for (row = child->top_attach; row < child->bottom_attach; row++)
                    {
-                     extra = height / (child->bottom_attach - row);
-                     table->rows[row].requisition += extra;
-                     height -= extra;
+                     if (table->rows[row].expand)
+                       n_expand++;
                    }
+
+                 if (n_expand == 0)
+                   {
+                     n_expand = (child->bottom_attach - child->top_attach);
+                     force_expand = TRUE;
+                   }
+                   
+                 for (row = child->top_attach; row < child->bottom_attach; row++)
+                   if (force_expand || table->rows[row].expand)
+                     {
+                       extra = height / n_expand;
+                       table->rows[row].requisition += extra;
+                       height -= extra;
+                       n_expand--;
+                     }
                }
            }
        }
@@ -1066,6 +1150,7 @@ gtk_table_size_allocate_init (GtkTable *table)
       table->cols[col].need_shrink = TRUE;
       table->cols[col].expand = FALSE;
       table->cols[col].shrink = TRUE;
+      table->cols[col].empty = TRUE;
     }
   for (row = 0; row < table->nrows; row++)
     {
@@ -1074,6 +1159,7 @@ gtk_table_size_allocate_init (GtkTable *table)
       table->rows[row].need_shrink = TRUE;
       table->rows[row].expand = FALSE;
       table->rows[row].shrink = TRUE;
+      table->rows[row].empty = TRUE;
     }
   
   /* Loop over all the children and adjust the row and col values
@@ -1096,6 +1182,8 @@ gtk_table_size_allocate_init (GtkTable *table)
              
              if (!child->xshrink)
                table->cols[child->left_attach].shrink = FALSE;
+             
+             table->cols[child->left_attach].empty = FALSE;
            }
          
          if (child->top_attach == (child->bottom_attach - 1))
@@ -1105,6 +1193,8 @@ gtk_table_size_allocate_init (GtkTable *table)
              
              if (!child->yshrink)
                table->rows[child->top_attach].shrink = FALSE;
+
+             table->rows[child->top_attach].empty = FALSE;
            }
        }
     }
@@ -1122,6 +1212,9 @@ gtk_table_size_allocate_init (GtkTable *table)
        {
          if (child->left_attach != (child->right_attach - 1))
            {
+             for (col = child->left_attach; col < child->right_attach; col++)
+               table->cols[col].empty = FALSE;
+
              if (child->xexpand)
                {
                  has_expand = FALSE;
@@ -1155,6 +1248,9 @@ gtk_table_size_allocate_init (GtkTable *table)
          
          if (child->top_attach != (child->bottom_attach - 1))
            {
+             for (row = child->top_attach; row < child->bottom_attach; row++)
+               table->rows[row].empty = FALSE;
+
              if (child->yexpand)
                {
                  has_expand = FALSE;
@@ -1193,10 +1289,18 @@ gtk_table_size_allocate_init (GtkTable *table)
    */
   for (col = 0; col < table->ncols; col++)
     {
-      if (table->cols[col].need_expand)
-       table->cols[col].expand = TRUE;
-      if (!table->cols[col].need_shrink)
-       table->cols[col].shrink = FALSE;
+      if (table->cols[col].empty)
+       {
+         table->cols[col].expand = FALSE;
+         table->cols[col].shrink = FALSE;
+       }
+      else
+       {
+         if (table->cols[col].need_expand)
+           table->cols[col].expand = TRUE;
+         if (!table->cols[col].need_shrink)
+           table->cols[col].shrink = FALSE;
+       }
     }
   
   /* Loop over the rows and set the expand and shrink values
@@ -1204,10 +1308,18 @@ gtk_table_size_allocate_init (GtkTable *table)
    */
   for (row = 0; row < table->nrows; row++)
     {
-      if (table->rows[row].need_expand)
-       table->rows[row].expand = TRUE;
-      if (!table->rows[row].need_shrink)
-       table->rows[row].shrink = FALSE;
+      if (table->rows[row].empty)
+       {
+         table->rows[row].expand = FALSE;
+         table->rows[row].shrink = FALSE;
+       }
+      else
+       {
+         if (table->rows[row].need_expand)
+           table->rows[row].expand = TRUE;
+         if (!table->rows[row].need_shrink)
+           table->rows[row].shrink = FALSE;
+       }
     }
 }
 
@@ -1232,19 +1344,22 @@ gtk_table_size_allocate_pass1 (GtkTable *table)
   
   if (table->homogeneous)
     {
-      nexpand = 0;
-      for (col = 0; col < table->ncols; col++)
-       if (table->cols[col].expand)
-         {
-           nexpand += 1;
-           break;
-         }
-      
-      if (nexpand > 0)
+      if (!table->children)
+       nexpand = 1;
+      else
+       {
+         nexpand = 0;
+         for (col = 0; col < table->ncols; col++)
+           if (table->cols[col].expand)
+             {
+               nexpand += 1;
+               break;
+             }
+       }
+      if (nexpand)
        {
          width = real_width;
-         
-         for (col = 0; col < table->ncols - 1; col++)
+         for (col = 0; col + 1 < table->ncols; col++)
            width -= table->cols[col].spacing;
          
          for (col = 0; col < table->ncols; col++)
@@ -1269,7 +1384,7 @@ gtk_table_size_allocate_pass1 (GtkTable *table)
          if (table->cols[col].shrink)
            nshrink += 1;
        }
-      for (col = 0; col < table->ncols - 1; col++)
+      for (col = 0; col + 1 < table->ncols; col++)
        width += table->cols[col].spacing;
       
       /* Check to see if we were allocated more width than we requested.
@@ -1289,39 +1404,54 @@ gtk_table_size_allocate_pass1 (GtkTable *table)
              }
        }
       
-      /* Check to see if we were allocated less width than we requested.
+      /* Check to see if we were allocated less width than we requested,
+       * then shrink until we fit the size give.
        */
-      if ((width > real_width) && (nshrink >= 1))
+      if (width > real_width)
        {
-         width = width - real_width;
-         
-         for (col = 0; col < table->ncols; col++)
-           if (table->cols[col].shrink)
-             {
-               extra = width / nshrink;
-               table->cols[col].allocation = MAX (1, table->cols[col].allocation - extra);
-               
-               width -= extra;
-               nshrink -= 1;
-             }
+         gint total_nshrink = nshrink;
+
+         extra = width - real_width;
+         while (total_nshrink > 0 && extra > 0)
+           {
+             nshrink = total_nshrink;
+             for (col = 0; col < table->ncols; col++)
+               if (table->cols[col].shrink)
+                 {
+                   gint allocation = table->cols[col].allocation;
+
+                   table->cols[col].allocation = MAX (1, (gint) table->cols[col].allocation - extra / nshrink);
+                   extra -= allocation - table->cols[col].allocation;
+                   nshrink -= 1;
+                   if (table->cols[col].allocation < 2)
+                     {
+                       total_nshrink -= 1;
+                       table->cols[col].shrink = FALSE;
+                     }
+                 }
+           }
        }
     }
   
   if (table->homogeneous)
     {
-      nexpand = 0;
-      for (row = 0; row < table->nrows; row++)
-       if (table->rows[row].expand)
-         {
-           nexpand += 1;
-           break;
-         }
-      
-      if (nexpand > 0)
+      if (!table->children)
+       nexpand = 1;
+      else
+       {
+         nexpand = 0;
+         for (row = 0; row < table->nrows; row++)
+           if (table->rows[row].expand)
+             {
+               nexpand += 1;
+               break;
+             }
+       }
+      if (nexpand)
        {
          height = real_height;
          
-         for (row = 0; row < table->nrows - 1; row++)
+         for (row = 0; row + 1 < table->nrows; row++)
            height -= table->rows[row].spacing;
          
          
@@ -1347,7 +1477,7 @@ gtk_table_size_allocate_pass1 (GtkTable *table)
          if (table->rows[row].shrink)
            nshrink += 1;
        }
-      for (row = 0; row < table->nrows - 1; row++)
+      for (row = 0; row + 1 < table->nrows; row++)
        height += table->rows[row].spacing;
       
       /* Check to see if we were allocated more height than we requested.
@@ -1368,20 +1498,31 @@ gtk_table_size_allocate_pass1 (GtkTable *table)
        }
       
       /* Check to see if we were allocated less height than we requested.
+       * then shrink until we fit the size give.
        */
-      if ((height > real_height) && (nshrink >= 1))
+      if (height > real_height)
        {
-         height = height - real_height;
+         gint total_nshrink = nshrink;
          
-         for (row = 0; row < table->nrows; row++)
-           if (table->rows[row].shrink)
-             {
-               extra = height / nshrink;
-               table->rows[row].allocation = MAX (1, table->rows[row].allocation - extra);
-               
-               height -= extra;
-               nshrink -= 1;
-             }
+         extra = height - real_height;
+         while (total_nshrink > 0 && extra > 0)
+           {
+             nshrink = total_nshrink;
+             for (row = 0; row < table->nrows; row++)
+               if (table->rows[row].shrink)
+                 {
+                   gint allocation = table->rows[row].allocation;
+                   
+                   table->rows[row].allocation = MAX (1, (gint) table->rows[row].allocation - extra / nshrink);
+                   extra -= allocation - table->rows[row].allocation;
+                   nshrink -= 1;
+                   if (table->rows[row].allocation < 2)
+                     {
+                       total_nshrink -= 1;
+                       table->rows[row].shrink = FALSE;
+                     }
+                 }
+           }
        }
     }
 }
@@ -1396,6 +1537,7 @@ gtk_table_size_allocate_pass2 (GtkTable *table)
   gint x, y;
   gint row, col;
   GtkAllocation allocation;
+  GtkWidget *widget = GTK_WIDGET (table);
   
   children = table->children;
   while (children)
@@ -1405,6 +1547,9 @@ gtk_table_size_allocate_pass2 (GtkTable *table)
       
       if (GTK_WIDGET_VISIBLE (child->widget))
        {
+         GtkRequisition child_requisition;
+         gtk_widget_get_child_requisition (child->widget, &child_requisition);
+
          x = GTK_WIDGET (table)->allocation.x + GTK_CONTAINER (table)->border_width;
          y = GTK_WIDGET (table)->allocation.y + GTK_CONTAINER (table)->border_width;
          max_width = 0;
@@ -1438,27 +1583,34 @@ gtk_table_size_allocate_pass2 (GtkTable *table)
          
          if (child->xfill)
            {
-             allocation.width = MAX (1, max_width - child->xpadding * 2);
+             allocation.width = MAX (1, max_width - (gint)child->xpadding * 2);
              allocation.x = x + (max_width - allocation.width) / 2;
            }
          else
            {
-             allocation.width = child->widget->requisition.width;
+             allocation.width = child_requisition.width;
              allocation.x = x + (max_width - allocation.width) / 2;
            }
          
          if (child->yfill)
            {
-             allocation.height = MAX (1, max_height - child->ypadding * 2);
+             allocation.height = MAX (1, max_height - (gint)child->ypadding * 2);
              allocation.y = y + (max_height - allocation.height) / 2;
            }
          else
            {
-             allocation.height = child->widget->requisition.height;
+             allocation.height = child_requisition.height;
              allocation.y = y + (max_height - allocation.height) / 2;
            }
+
+         if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+           allocation.x = widget->allocation.x + widget->allocation.width
+             - (allocation.x - widget->allocation.x) - allocation.width;
          
          gtk_widget_size_allocate (child->widget, &allocation);
        }
     }
 }
+
+#define __GTK_TABLE_C__
+#include "gtkaliasdef.c"