[gtk+/extended-layout-jhs: 62/64] Test size-for-allocation for GtkTable. Add orientation property needed for



commit 84ab791ecf0daddb5d5fbd2f553ba8d1ac33b03b
Author: Mathias Hasselmann <mathias hasselmann gmx de>
Date:   Tue Aug 28 21:04:18 2007 +0000

    Test size-for-allocation for GtkTable. Add orientation property needed for
    
    2007-08-28  Mathias Hasselmann  <mathias hasselmann gmx de>
    
    	* tests/testextendedlayout.c: Test size-for-allocation for GtkTable.
    	* gtk/gtk.symbols, gtk/gtktable.c, gtk/gtktable.h: Add orientation
    	property needed for choosing a size-for-allocation strategy.
    
    svn path=/branches/extended-layout/; revision=18697

 ChangeLog.gtk-extended-layout |    6 +++
 gtk/gtk.symbols               |    2 +
 gtk/gtktable.c                |   79 +++++++++++++++++++++++++++++++++++++++-
 gtk/gtktable.h                |    3 ++
 tests/testextendedlayout.c    |   60 +++++++++++++++++++++++++------
 5 files changed, 136 insertions(+), 14 deletions(-)
---
diff --git a/ChangeLog.gtk-extended-layout b/ChangeLog.gtk-extended-layout
index ad4f559..f6ec163 100644
--- a/ChangeLog.gtk-extended-layout
+++ b/ChangeLog.gtk-extended-layout
@@ -1,5 +1,11 @@
 2007-08-28  Mathias Hasselmann  <mathias hasselmann gmx de>
 
+	* tests/testextendedlayout.c: Test size-for-allocation for GtkTable.
+	* gtk/gtk.symbols, gtk/gtktable.c, gtk/gtktable.h: Add orientation
+	property needed for choosing a size-for-allocation strategy.
+
+2007-08-28  Mathias Hasselmann  <mathias hasselmann gmx de>
+
 	* gtk/gtkhbox.c: Consider width-for-height information.
 	* gtk/gtkvbox.c, gtk/gtkprivate.h: Move GtkChildSizeRequest
 	to gtkprivate.h.
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index 1824706..40174e6 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -3495,6 +3495,7 @@ gtk_table_get_col_spacing
 gtk_table_get_default_col_spacing
 gtk_table_get_default_row_spacing
 gtk_table_get_homogeneous
+gtk_table_get_orientation
 gtk_table_get_row_spacing
 gtk_table_get_type G_GNUC_CONST
 gtk_table_new
@@ -3502,6 +3503,7 @@ gtk_table_resize
 gtk_table_set_col_spacing
 gtk_table_set_col_spacings
 gtk_table_set_homogeneous
+gtk_table_set_orientation
 gtk_table_set_row_spacing
 gtk_table_set_row_spacings
 #endif
diff --git a/gtk/gtktable.c b/gtk/gtktable.c
index 5f085d8..006fc4e 100644
--- a/gtk/gtktable.c
+++ b/gtk/gtktable.c
@@ -32,6 +32,10 @@
 #include "gtkintl.h"
 #include "gtkalias.h"
 
+#define GTK_TABLE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TABLE, GtkTablePrivate))
+
+typedef struct _GtkTablePrivate GtkTablePrivate;
+
 enum
 {
   PROP_0,
@@ -39,7 +43,8 @@ enum
   PROP_N_COLUMNS,
   PROP_COLUMN_SPACING,
   PROP_ROW_SPACING,
-  PROP_HOMOGENEOUS
+  PROP_HOMOGENEOUS,
+  PROP_ORIENTATION
 };
 
 enum
@@ -55,6 +60,10 @@ enum
   CHILD_PROP_Y_PADDING
 };
   
+struct _GtkTablePrivate
+{
+  GtkOrientation orientation;
+};
 
 static void gtk_table_finalize	    (GObject	    *object);
 static void gtk_table_size_request  (GtkWidget	    *widget,
@@ -126,7 +135,8 @@ gtk_table_class_init (GtkTableClass *class)
   container_class->child_type = gtk_table_child_type;
   container_class->set_child_property = gtk_table_set_child_property;
   container_class->get_child_property = gtk_table_get_child_property;
-  
+
+  g_type_class_add_private (class, sizeof (GtkTablePrivate));
 
   g_object_class_install_property (gobject_class,
                                    PROP_N_ROWS,
@@ -171,6 +181,14 @@ gtk_table_class_init (GtkTableClass *class)
 							 P_("If TRUE, the table cells are all the same width/height"),
 							 FALSE,
 							 GTK_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class,
+                                   PROP_ORIENTATION,
+                                   g_param_spec_enum ("orientation",
+						      P_("Orientation"),
+						      P_("The orientation used for child allocation"),
+						      GTK_TYPE_ORIENTATION,
+						      GTK_ORIENTATION_VERTICAL,
+						      GTK_PARAM_READWRITE));
 
   gtk_container_class_install_child_property (container_class,
 					      CHILD_PROP_LEFT_ATTACH,
@@ -263,6 +281,9 @@ gtk_table_get_property (GObject      *object,
     case PROP_HOMOGENEOUS:
       g_value_set_boolean (value, table->homogeneous);
       break;
+    case PROP_ORIENTATION:
+      g_value_set_enum (value, GTK_TABLE_GET_PRIVATE (table)->orientation);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -296,6 +317,9 @@ gtk_table_set_property (GObject      *object,
     case PROP_HOMOGENEOUS:
       gtk_table_set_homogeneous (table, g_value_get_boolean (value));
       break;
+    case PROP_ORIENTATION:
+      gtk_table_set_orientation (table, g_value_get_enum (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -445,6 +469,8 @@ gtk_table_get_child_property (GtkContainer    *container,
 static void
 gtk_table_init (GtkTable *table)
 {
+  GtkTablePrivate *priv;
+
   GTK_WIDGET_SET_FLAGS (table, GTK_NO_WINDOW);
   gtk_widget_set_redraw_on_allocate (GTK_WIDGET (table), FALSE);
   
@@ -457,6 +483,9 @@ gtk_table_init (GtkTable *table)
   table->row_spacing = 0;
   table->homogeneous = FALSE;
 
+  priv = GTK_TABLE_GET_PRIVATE (table);
+  priv->orientation = GTK_ORIENTATION_VERTICAL;
+
   gtk_table_resize (table, 1, 1);
 }
 
@@ -800,6 +829,52 @@ gtk_table_get_homogeneous (GtkTable *table)
   return table->homogeneous;
 }
 
+/**
+ * gtk_table_set_orientation:
+ * @table: a #GtkTable
+ * @orientation: the orientation to use
+ *
+ * Changes the orientation of the table. The orientation specifies if
+ * height-for-width or width-for-height is used for child allocation.
+ * With an orientation of #GTK_ORIENTATION_VERTICAL heigth-for-width
+ * and for #GTK_ORIENTATION_HORIZONTAL width-for-heigth is used.
+ **/
+void
+gtk_table_set_orientation (GtkTable       *table,
+			   GtkOrientation  orientation)
+{
+  GtkTablePrivate *priv;
+
+  g_return_if_fail (GTK_IS_TABLE (table));
+  priv = GTK_TABLE_GET_PRIVATE (table);
+
+  if (orientation != priv->orientation)
+    {
+      priv->orientation = orientation;
+      
+      if (GTK_WIDGET_VISIBLE (table))
+	gtk_widget_queue_resize (GTK_WIDGET (table));
+
+      g_object_notify (G_OBJECT (table), "orientation");
+    }
+}
+
+/**
+ * gtk_table_get_orientation:
+ * @table: a #GtkTable
+ *
+ * Returns whether the table prefers height-for-width or width-for-height
+ * for child allocation. (See gtk_table_set_orientation ())
+ *
+ * Return value: the orientation used
+ **/
+GtkOrientation
+gtk_table_get_orientation (GtkTable *table)
+{
+  g_return_val_if_fail (GTK_IS_TABLE (table), GTK_ORIENTATION_VERTICAL);
+  return GTK_TABLE_GET_PRIVATE (table)->orientation;
+}
+
 static void
 gtk_table_finalize (GObject *object)
 {
diff --git a/gtk/gtktable.h b/gtk/gtktable.h
index fb7cb3c..85ca9b0 100644
--- a/gtk/gtktable.h
+++ b/gtk/gtktable.h
@@ -140,6 +140,9 @@ void	   gtk_table_set_homogeneous  (GtkTable	       *table,
 				       gboolean		homogeneous);
 gboolean   gtk_table_get_homogeneous  (GtkTable        *table);
 
+void           gtk_table_set_orientation  (GtkTable       *table,
+					   GtkOrientation  orientation);
+GtkOrientation gtk_table_get_orientation  (GtkTable       *table);
 
 G_END_DECLS
 
diff --git a/tests/testextendedlayout.c b/tests/testextendedlayout.c
index 60a60dd..563124e 100644
--- a/tests/testextendedlayout.c
+++ b/tests/testextendedlayout.c
@@ -939,9 +939,10 @@ natural_size_test_misc_new (TestSuite *suite,
 
 static TestCase*
 size_for_allocation_test_new (TestSuite *suite,
-                              gboolean   vertical)
+                              gboolean   vertical,
+                              gboolean   table)
 {
-  GtkWidget *box, *child;
+  GtkWidget *container, *child;
   TestCase *test;
   int i;
 
@@ -949,10 +950,19 @@ size_for_allocation_test_new (TestSuite *suite,
     {
       test = test_case_new (suite,
                             "Size for Allocation", 
-                            "Height for Width", 
+                            table ? "Height for Width, GtkTable"
+                                  : "Height for Width, GtkVBox",
                             gtk_hpaned_new ());
 
-      box = gtk_vbox_new (FALSE, 6);
+      if (table)
+        {
+          container = gtk_table_new (4, 1, FALSE);
+          gtk_table_set_orientation (GTK_TABLE (container), 
+                                     GTK_ORIENTATION_VERTICAL);
+        }
+      else
+        container = gtk_vbox_new (FALSE, 6);
+
       child = gtk_label_new ("Move the handle to test\n"
                              "height-for-width requests");
 
@@ -962,19 +972,28 @@ size_for_allocation_test_new (TestSuite *suite,
     {
       test = test_case_new (suite,
                             "Size for Allocation", 
-                            "Width for Height",
+                            table ? "Width for Height, GtkTable"
+                                  : "Width for Height, GtkHBox",
                             gtk_vpaned_new ());
 
-      box = gtk_hbox_new (FALSE, 6);
+      if (table)
+        {
+          container = gtk_table_new (1, 4, FALSE);
+          gtk_table_set_orientation (GTK_TABLE (container), 
+                                     GTK_ORIENTATION_HORIZONTAL);
+        }
+      else
+        container = gtk_hbox_new (FALSE, 6);
+
       child = gtk_label_new ("Move the handle to test\n"
                              "width-for-height requests");
     }
 
   gtk_container_set_border_width (GTK_CONTAINER (test->widget), 6);
-  gtk_container_set_border_width (GTK_CONTAINER (box), 6);
+  gtk_container_set_border_width (GTK_CONTAINER (container), 6);
   gtk_misc_set_padding (GTK_MISC (child), 6, 6);
 
-  gtk_paned_pack1 (GTK_PANED (test->widget), box, TRUE, FALSE);
+  gtk_paned_pack1 (GTK_PANED (test->widget), container, TRUE, FALSE);
   gtk_paned_pack2 (GTK_PANED (test->widget), child, FALSE, FALSE);
 
   for (i = 0; i < 4; ++i)
@@ -986,7 +1005,15 @@ size_for_allocation_test_new (TestSuite *suite,
           gtk_label_set_use_markup (GTK_LABEL (child), TRUE);
           test_case_append_guide (test, child, GUIDE_EXTERIOUR_BOTH, -1);
           test_case_append_guide (test, child, GUIDE_INTERIOUR_BOTH, -1);
-          gtk_box_pack_start (GTK_BOX (box), child, FALSE, TRUE, 0);
+
+          if (!table)
+            gtk_box_pack_start (GTK_BOX (container), child, FALSE, TRUE, 0);
+          else if (vertical)
+            gtk_table_attach (GTK_TABLE (container), child, 0, 1, i, i + 1,
+                              GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0);
+          else
+            gtk_table_attach (GTK_TABLE (container), child, i, i + 1, 0, 1, 
+                              GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0);
 
           if (i > 0)
             gtk_label_set_full_size (GTK_LABEL (child), TRUE);
@@ -1007,8 +1034,15 @@ size_for_allocation_test_new (TestSuite *suite,
           gtk_container_add (GTK_CONTAINER (child),
                              gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO,
                                                        GTK_ICON_SIZE_DIALOG));
-          gtk_box_pack_start (GTK_BOX (box), child, TRUE, TRUE, 0);
 
+          if (!table)
+            gtk_box_pack_start (GTK_BOX (container), child, TRUE, TRUE, 0);
+          else if (vertical)
+            gtk_table_attach (GTK_TABLE (container), child, 0, 1, i, i + 1,
+                              GTK_EXPAND|GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0);
+          else
+            gtk_table_attach (GTK_TABLE (container), child, i, i + 1, 0, 1,
+                              GTK_EXPAND|GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0);
         }
     }
 
@@ -2498,8 +2532,10 @@ test_suite_new (gchar *arg0)
   test_suite_append (self, natural_size_test_new (self, FALSE, TRUE));
   test_suite_append (self, natural_size_test_new (self, TRUE, TRUE));
   test_suite_append (self, natural_size_test_misc_new (self, arg0));
-  test_suite_append (self, size_for_allocation_test_new (self, TRUE));
-  test_suite_append (self, size_for_allocation_test_new (self, FALSE));
+  test_suite_append (self, size_for_allocation_test_new (self, TRUE, FALSE));
+  test_suite_append (self, size_for_allocation_test_new (self, FALSE, FALSE));
+  test_suite_append (self, size_for_allocation_test_new (self, TRUE, TRUE));
+  test_suite_append (self, size_for_allocation_test_new (self, FALSE, TRUE));
   test_suite_append (self, baseline_test_new (self));
   test_suite_append (self, baseline_test_bin_new (self));
   test_suite_append (self, baseline_test_hbox_new (self, FALSE));



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]