[gtk+/extended-layout-jhs: 39/64] Also apply natural size, when there are no expandable children. Fix



commit 69981cab4ddecd7c95e81bc856deb54a283b05cb
Author: Mathias Hasselmann <mathias hasselmann gmx de>
Date:   Tue Jul 24 08:36:25 2007 +0000

    Also apply natural size, when there are no expandable children. Fix
    
    2007-07-24  Mathias Hasselmann  <mathias hasselmann gmx de>
    
    	* gtk/gtkhbox.c, gtk/gtktable.c, gtk/gtkvbox.c: Also apply natural
    	size, when there are no expandable children. Fix natural size
    	calculation for GtkVBox.
    	* tests/testextendedlayout.c: More extensive natural size testing.
    	Make sure that really all guide groups are tested. Add detail
    	to test case label in results page.
    
    svn path=/branches/extended-layout/; revision=18536

 ChangeLog.gtk-extended-layout |    9 ++
 gtk/gtkhbox.c                 |   27 +++--
 gtk/gtktable.c                |   12 +-
 gtk/gtkvbox.c                 |   31 ++++---
 tests/testextendedlayout.c    |  203 ++++++++++++++++++++++++++---------------
 5 files changed, 177 insertions(+), 105 deletions(-)
---
diff --git a/ChangeLog.gtk-extended-layout b/ChangeLog.gtk-extended-layout
index 8e1b7e7..d62d064 100644
--- a/ChangeLog.gtk-extended-layout
+++ b/ChangeLog.gtk-extended-layout
@@ -1,5 +1,14 @@
 2007-07-24  Mathias Hasselmann  <mathias hasselmann gmx de>
 
+	* gtk/gtkhbox.c, gtk/gtktable.c, gtk/gtkvbox.c: Also apply natural
+	size, when there are no expandable children. Fix natural size 
+	calculation for GtkVBox.
+	* tests/testextendedlayout.c: More extensive natural size testing.
+	Make sure that really all guide groups are tested. Add detail
+	to test case label in results page.
+
+2007-07-24  Mathias Hasselmann  <mathias hasselmann gmx de>
+
 	* gtk/gtktable.c, gtk/gtktable.h: Consider natural size to allocate 
 	widgets spanning a single, rename GtkTableRowCol::natural_size.
 	Remove some lost g_print statements.
diff --git a/gtk/gtkhbox.c b/gtk/gtkhbox.c
index 9ff3055..cdd83d7 100644
--- a/gtk/gtkhbox.c
+++ b/gtk/gtkhbox.c
@@ -345,19 +345,24 @@ gtk_hbox_size_allocate (GtkWidget     *widget,
 	  extra = available / nvis_children;
           natural = 0;
 	}
-      else if (nexpand_children > 0)
-	{
-	  available = (gint)allocation->width - widget->requisition.width;
-          natural = MAX (0, MIN (available, natural_width));
-          available -= natural;
-
-	  extra = MAX (0, available / nexpand_children);
-	}
       else
 	{
-	  available = 0;
-          natural = 0;
-	  extra = 0;
+          if (nexpand_children > 0 || natural_width > 0)
+            {
+              available = (gint)allocation->width - widget->requisition.width;
+              natural = MAX (0, MIN (available, natural_width));
+              available -= natural;
+            }
+          else
+            {
+              available = 0;
+              natural = 0;
+            }
+
+          if (nexpand_children > 0)
+	    extra = MAX (0, available / nexpand_children);
+          else
+            extra = 0;
 	}
 
       child_allocation.y = allocation->y + border_width;
diff --git a/gtk/gtktable.c b/gtk/gtktable.c
index e821df7..42963e4 100644
--- a/gtk/gtktable.c
+++ b/gtk/gtktable.c
@@ -1452,11 +1452,11 @@ gtk_table_size_allocate_pass1 (GtkTable *table)
       
       /* Check to see if we were allocated more width than we requested.
        */
-      if ((width < real_width) && (nexpand >= 1))
+      if ((width < real_width) && (nexpand >= 1 || natural_delta > 0))
 	{
 	  width = real_width - width;
-          natural_size = MIN (natural_delta, width);
-          width = MAX (0, width - natural_size);
+          natural_size = MAX (0, MIN (width, natural_delta));
+          width = width - natural_size;
 
 	  for (col = 0; col < table->ncols; col++)
             {
@@ -1560,11 +1560,11 @@ gtk_table_size_allocate_pass1 (GtkTable *table)
       
       /* Check to see if we were allocated more height than we requested.
        */
-      if ((height < real_height) && (nexpand >= 1))
+      if ((height < real_height) && (nexpand >= 1 || natural_delta > 0))
 	{
 	  height = real_height - height;
-          natural_size = MIN (natural_delta, height);
-          height = MAX (0, height - natural_size);
+          natural_size = MAX (0, MIN (height, natural_delta));
+          height = height - natural_size;
 
 	  for (row = 0; row < table->nrows; row++)
             {
diff --git a/gtk/gtkvbox.c b/gtk/gtkvbox.c
index 12a6f2b..987a16a 100644
--- a/gtk/gtkvbox.c
+++ b/gtk/gtkvbox.c
@@ -214,19 +214,24 @@ gtk_vbox_size_allocate (GtkWidget     *widget,
 	  extra = available / nvis_children;
           natural = 0;
 	}
-      else if (nexpand_children > 0)
-	{
-	  available = (gint)allocation->height - widget->requisition.height;
-          natural = MAX (0, MIN (available, natural_height));
-          available -= natural;
-
-	  extra = MAX (0, available / nexpand_children);
-	}
       else
 	{
-	  available = 0;
-          natural = 0;
-	  extra = 0;
+          if (nexpand_children > 0 || natural_height > 0)
+            {
+	      available = (gint)allocation->height - widget->requisition.height;
+              natural = MAX (0, MIN (available, natural_height));
+              available -= natural;
+            }
+          else
+            {
+              available = 0;
+              natural = 0;
+            }
+
+          if (nexpand_children > 0)
+	    extra = MAX (0, available / nexpand_children);
+          else
+            extra = 0;
 	}
 
       child_allocation.x = allocation->x + border_width;
@@ -345,8 +350,8 @@ gtk_vbox_extended_layout_get_natural_size (GtkExtendedLayout *layout,
           else
             gtk_widget_size_request (child->widget, &child_requisition);
 
-          requisition->width += MAX (child_requisition.width, requisition->width);
-          requisition->height = child_requisition.height;
+          requisition->width = MAX (child_requisition.width, requisition->width);
+          requisition->height += child_requisition.height;
 	}
     }
 }
diff --git a/tests/testextendedlayout.c b/tests/testextendedlayout.c
index ec2ae12..d17f57e 100644
--- a/tests/testextendedlayout.c
+++ b/tests/testextendedlayout.c
@@ -217,73 +217,120 @@ append_natural_size_box (TestCase           *test,
                          GtkWidget          *parent,
                          gboolean            vertical,
                          gboolean            table,
-                         const gchar        *caption,
-                         PangoEllipsizeMode  ellipsize)
+                         gboolean            ellipses)
 {
-  GtkWidget *container;
-  GtkWidget *button;
-  GtkWidget *label;
+  GtkWidget *container, *button, *label;
+  PangoEllipsizeMode ellipsize_mode;
+  gint i, j, k;
 
-  if (table)
+  for (i = 0; i < 6; ++i)
     {
-      container = gtk_table_new (vertical ? 2 : 1, vertical ? 1 : 2, FALSE);
-      gtk_table_set_col_spacings (GTK_TABLE (container), 12);
-      gtk_table_set_row_spacings (GTK_TABLE (container), 12);
-    }
-  else if (vertical)
-    container = gtk_vbox_new (FALSE, 12);
-  else
-    container = gtk_hbox_new (FALSE, 12);
+      ellipsize_mode = ellipses ?
+        PANGO_ELLIPSIZE_START + i/2 : 
+        PANGO_ELLIPSIZE_NONE;
 
-  label = gtk_label_new ("The small Button");
-  gtk_label_set_angle (GTK_LABEL (label), vertical ? 90 : 0);
-  gtk_label_set_ellipsize (GTK_LABEL (label), ellipsize);
+      if (!i || (ellipses && 0 == i % 2))
+        {
+          label = gtk_label_new (NULL);
 
-  button = gtk_button_new ();
-  gtk_container_add (GTK_CONTAINER (button), label);
+          switch(ellipsize_mode)
+            {
+              case PANGO_ELLIPSIZE_NONE:
+                gtk_label_set_markup (GTK_LABEL (label), "<b>No ellipses</b>");
+                break;
+              case PANGO_ELLIPSIZE_START:
+                gtk_label_set_markup (GTK_LABEL (label), "<b>Ellipses at start</b>");
+                break;
+              case PANGO_ELLIPSIZE_MIDDLE:
+                gtk_label_set_markup (GTK_LABEL (label), "<b>Ellipses in the middle</b>");
+                break;
+              case PANGO_ELLIPSIZE_END:
+                gtk_label_set_markup (GTK_LABEL (label), "<b>Ellipses at end</b>");
+                break;
+            }
 
-  if (table)
-    gtk_table_attach (GTK_TABLE (container), button, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
-  else
-    gtk_box_pack_start (GTK_BOX (container), button, FALSE, TRUE, 0);
+          if (vertical)
+            {
+              gtk_misc_set_alignment (GTK_MISC (label), 0.0, 1.0);
+              gtk_label_set_angle (GTK_LABEL (label), 90);
+            }
+          else
+            {
+              gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+              gtk_label_set_angle (GTK_LABEL (label), 0);
+            }
 
-  test_case_append_guide (test, button, GUIDE_EXTERIOUR_VERTICAL, 0);
-  test_case_append_guide (test, label, GUIDE_EXTERIOUR_VERTICAL, -1);
+          gtk_box_pack_start (GTK_BOX (parent), label, FALSE, TRUE, 0);
+        }
 
-  label = gtk_label_new ("The large Button");
-  gtk_label_set_angle (GTK_LABEL (label), vertical ? 90 : 0);
+      if (table)
+        {
+          k = 1 + i / 3 + i % 3;
 
-  button = gtk_button_new ();
-  gtk_container_add (GTK_CONTAINER (button), label);
+          container = gtk_table_new (vertical ? k : 1,
+                                     vertical ? 1 : k, FALSE);
 
-  if (table)
-    gtk_table_attach (GTK_TABLE (container), button,
-                      vertical ? 0 : 1, vertical ? 1 : 2,
-                      vertical ? 1 : 0, vertical ? 2 : 1,
-                      vertical ? GTK_FILL : GTK_FILL | GTK_EXPAND,
-                      vertical ? GTK_FILL | GTK_EXPAND : GTK_FILL,
-                      0, 0);
-  else
-    gtk_box_pack_start (GTK_BOX (container), button, TRUE, TRUE, 0);
+          gtk_table_set_col_spacings (GTK_TABLE (container), 6);
+          gtk_table_set_row_spacings (GTK_TABLE (container), 6);
+        }
+      else if (vertical)
+        container = gtk_vbox_new (FALSE, 6);
+      else
+        container = gtk_hbox_new (FALSE, 6);
 
-  test_case_append_guide (test, button, GUIDE_EXTERIOUR_VERTICAL, 1);
+      gtk_box_pack_start (GTK_BOX (parent), container, FALSE, TRUE, 0);
 
-  label = gtk_label_new (NULL);
-  gtk_label_set_markup (GTK_LABEL (label), caption); 
+      for (j = 0; j <= i / 3; ++j)
+        {
+          label = gtk_label_new ("Small Button");
+          gtk_label_set_angle (GTK_LABEL (label), vertical ? 90 : 0);
+          gtk_label_set_ellipsize (GTK_LABEL (label), ellipsize_mode);
+
+          button = gtk_button_new ();
+          set_widget_name (button, "small-%d-%d-%d", ellipses, i, j);
+          gtk_container_add (GTK_CONTAINER (button), label);
+
+          if (table)
+            gtk_table_attach (GTK_TABLE (container), button,
+                              vertical ? 0 : j, vertical ? 1 : j + 1,
+                              vertical ? j : 0, vertical ? j + 1 : 1,
+                              GTK_FILL, GTK_FILL, 0, 0);
+          else
+            gtk_box_pack_start (GTK_BOX (container), button, FALSE, TRUE, 0);
 
-  if (vertical)
-    {
-      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 1.0);
-      gtk_label_set_angle (GTK_LABEL (label), 90);
-    }
-  else
-    {
-      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-      gtk_label_set_angle (GTK_LABEL (label), 0);
-    }
+          test_case_append_guide (test, button,
+                                  vertical ? GUIDE_EXTERIOUR_HORIZONTAL 
+                                           : GUIDE_EXTERIOUR_VERTICAL,
+                                  j);
+        }
 
-  gtk_box_pack_start (GTK_BOX (parent), label, FALSE, TRUE, 0);
-  gtk_box_pack_start (GTK_BOX (parent), container, FALSE, TRUE, 0);
+      for (j = 0; j < i % 3; ++j)
+        {
+          label = gtk_label_new ("Large Button");
+          gtk_label_set_angle (GTK_LABEL (label), vertical ? 90 : 0);
+
+          button = gtk_button_new ();
+          set_widget_name (button, "large-%d-%d-%d", ellipses, i, j);
+          gtk_container_add (GTK_CONTAINER (button), label);
+
+          if (table)
+            gtk_table_attach (GTK_TABLE (container), button,
+                              vertical ? 0 : i/3 + j + 1, 
+                              vertical ? 1 : i/3 + j + 2,
+                              vertical ? i/3 + j + 1 : 0, 
+                              vertical ? i/3 + j + 2 : 1,
+                              vertical ? GTK_FILL : GTK_FILL | GTK_EXPAND,
+                              vertical ? GTK_FILL | GTK_EXPAND : GTK_FILL,
+                              0, 0);
+          else
+            gtk_box_pack_start (GTK_BOX (container), button, TRUE, TRUE, 0);
+
+          test_case_append_guide (test, button, 
+                                  vertical ? GUIDE_EXTERIOUR_HORIZONTAL 
+                                           : GUIDE_EXTERIOUR_VERTICAL,
+                                  1 + i + j);
+        }
+    }
 }
 
 static gboolean
@@ -352,14 +399,14 @@ create_natural_size_test (TestSuite *suite,
     {
       detail = table ? "GtkTable, vertical" : "GtkVBox";
       hint = gtk_alignment_new (0.5, 1.0, 1.0, 0.0);
-      box = gtk_hbox_new (FALSE, 12);
+      box = gtk_hbox_new (FALSE, 6);
       paned = gtk_vpaned_new ();
     }
   else
     {
       detail = table ? "GtkTable, horizontal" : "GtkHBox";
       hint = gtk_alignment_new (1.0, 0.5, 0.0, 1.0);
-      box = gtk_vbox_new (FALSE, 12);
+      box = gtk_vbox_new (FALSE, 6);
       paned = gtk_hpaned_new ();
     }
 
@@ -369,18 +416,8 @@ create_natural_size_test (TestSuite *suite,
   gtk_container_set_border_width (GTK_CONTAINER (box), 6);
   gtk_paned_pack1 (GTK_PANED (test->widget), box, TRUE, TRUE);
 
-  append_natural_size_box (test, box, vertical, table,
-                           "<b>No ellipsizing</b>",
-                           PANGO_ELLIPSIZE_NONE);
-  append_natural_size_box (test, box, vertical, table,
-                           "<b>Ellipsizing at start</b>",
-                           PANGO_ELLIPSIZE_START);
-  append_natural_size_box (test, box, vertical, table,
-                           "<b>Ellipsizing in the middle</b>",
-                           PANGO_ELLIPSIZE_MIDDLE);
-  append_natural_size_box (test, box, vertical, table,
-                           "<b>Ellipsizing at end</b>",
-                           PANGO_ELLIPSIZE_END);
+  append_natural_size_box (test, box, vertical, table, FALSE);
+  append_natural_size_box (test, box, vertical, table, TRUE);
 
   button = gtk_button_new_with_label ("Shrink to check ellipsing");
   g_signal_connect (button, "clicked", G_CALLBACK (shrink_paned), test->widget);
@@ -1274,23 +1311,40 @@ test_suite_run (TestSuite *self,
     {
       TestResult test_result = TEST_RESULT_SUCCESS;
       gint last_group = -1;
+      gchar *message;
       GList *oiter;
-      gint o;
+      gint o, group;
+
+      message = test->detail ?
+        g_strdup_printf ("%s (%s)", test->name, test->detail) :
+        g_strdup (test->name);
 
       test_suite_start (self);
-      test_suite_report (self, test->name, -1, TEST_RESULT_NONE);
+      test_suite_report (self, message, -1, TEST_RESULT_NONE);
+
+      g_free (message);
+
+      for (oiter = test->guides; oiter; oiter = oiter->next)
+        last_group = MAX (last_group, ((const Guide*)oiter->data)->group);
 
-      for(o = 0, oiter = test->guides; oiter; ++o, oiter = oiter->next)
+      for (group = 0; group <= last_group; ++group)
         {
-          const Guide *oguide = oiter->data;
-        
-          if (oguide->group > last_group)
+          const Guide *oguide;
+
+          for (o = 0, oiter = test->guides; oiter; ++o, oiter = oiter->next)
+            {
+              oguide = oiter->data;
+
+              if (oguide->group == group)
+                break;
+            }
+
+          if (oiter)
             {
               TestResult group_result = TEST_RESULT_SUCCESS;
               const gchar *widget_name;
               const gchar *type_name;
 
-              gchar *message;
               GList *iiter;
               gint i;
 
@@ -1336,7 +1390,6 @@ test_suite_run (TestSuite *self,
                 } 
 
               test_suite_report (self, NULL, oguide->group, group_result);
-              last_group = oguide->group;
             }
         }
 



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