[gtk+/combo-refactor] Fixing GtkCellAreaBox at render time to consider height-for-width when stacked vertically



commit 82fe7becd029306554a499738a4f0a41732b1660
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Fri Nov 26 23:41:39 2010 +0900

    Fixing GtkCellAreaBox at render time to consider height-for-width when stacked vertically
    
    Also bullet-proofing GtkCellAreaBoxContext at allocate time.

 gtk/gtkcellareabox.c        |   34 ++++++++++++++++++++++------------
 gtk/gtkcellareaboxcontext.c |   24 +++++++++++-------------
 2 files changed, 33 insertions(+), 25 deletions(-)
---
diff --git a/gtk/gtkcellareabox.c b/gtk/gtkcellareabox.c
index 522c397..42bb934 100644
--- a/gtk/gtkcellareabox.c
+++ b/gtk/gtkcellareabox.c
@@ -583,7 +583,8 @@ allocate_cells_manually (GtkCellAreaBox        *box,
   gint                      i;
   gint                      nvisible = 0, nexpand = 0, group_expand;
   gint                      avail_size, extra_size, extra_extra;
-  gint                      position = 0;
+  gint                      position = 0, for_size;
+
 
   if (!priv->cells)
     return NULL;
@@ -606,9 +607,15 @@ allocate_cells_manually (GtkCellAreaBox        *box,
     }
 
   if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
-    avail_size = width;
+    {
+      avail_size = width;
+      for_size   = height;
+    }
   else
-    avail_size = height;
+    {
+      avail_size = height;
+      for_size   = width;
+    }
 
   /* Go ahead and collect the requests on the fly */
   sizes = g_new0 (GtkRequestedSize, nvisible);
@@ -619,14 +626,11 @@ allocate_cells_manually (GtkCellAreaBox        *box,
       if (!gtk_cell_renderer_get_visible (info->renderer))
 	continue;
 
-      if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
-	gtk_cell_renderer_get_preferred_width_for_height (info->renderer, widget, height, 
-							  &sizes[i].minimum_size,
-							  &sizes[i].natural_size);
-      else
-	gtk_cell_renderer_get_preferred_height_for_width (info->renderer, widget, width, 
-							  &sizes[i].minimum_size,
-							  &sizes[i].natural_size);
+      gtk_cell_area_request_renderer (GTK_CELL_AREA (box), info->renderer,
+				      priv->orientation,
+				      widget, for_size,
+				      &sizes[i].minimum_size,
+				      &sizes[i].natural_size);
 
       avail_size -= sizes[i].minimum_size;
 
@@ -697,11 +701,17 @@ get_allocated_cells (GtkCellAreaBox        *box,
   GList                    *cell_list;
   GSList                   *allocated_cells = NULL;
   gint                      i, j, n_allocs;
+  gint                      for_size;
 
   group_allocs = gtk_cell_area_box_context_get_orientation_allocs (context, &n_allocs);
   if (!group_allocs)
     return allocate_cells_manually (box, widget, width, height);
 
+  if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+    for_size = height;
+  else
+    for_size = width;
+
   for (i = 0; i < n_allocs; i++)
     {
       /* We dont always allocate all groups, sometimes the requested group has only invisible
@@ -748,7 +758,7 @@ get_allocated_cells (GtkCellAreaBox        *box,
 
 	      gtk_cell_area_request_renderer (area, info->renderer,
 					      priv->orientation,
-					      widget, -1,
+					      widget, for_size,
 					      &sizes[j].minimum_size,
 					      &sizes[j].natural_size);
 
diff --git a/gtk/gtkcellareaboxcontext.c b/gtk/gtkcellareaboxcontext.c
index aa7efd8..056e4ec 100644
--- a/gtk/gtkcellareaboxcontext.c
+++ b/gtk/gtkcellareaboxcontext.c
@@ -495,21 +495,19 @@ gtk_cell_area_box_context_allocate (GtkCellAreaContext *context,
   orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (area));
   spacing     = gtk_cell_area_box_get_spacing (GTK_CELL_AREA_BOX (area));
 
+  g_free (priv->orientation_allocs);
+  priv->orientation_allocs   = NULL;
+  priv->n_orientation_allocs = 0;
+
   if (orientation == GTK_ORIENTATION_HORIZONTAL && width > 0)
-    {
-      g_free (priv->orientation_allocs);
-      priv->orientation_allocs = allocate_for_orientation (box_context, orientation, 
-							   spacing, width, height,
-							   &priv->n_orientation_allocs);
-    }
+    priv->orientation_allocs = allocate_for_orientation (box_context, orientation, 
+							 spacing, width, height,
+							 &priv->n_orientation_allocs);
   else if (orientation == GTK_ORIENTATION_VERTICAL && height > 0)
-    {
-      g_free (priv->orientation_allocs);
-      priv->orientation_allocs = allocate_for_orientation (box_context, orientation, 
-							   spacing, height, width,
-							   &priv->n_orientation_allocs);
-    }
-
+    priv->orientation_allocs = allocate_for_orientation (box_context, orientation, 
+							 spacing, height, width,
+							 &priv->n_orientation_allocs);
+  
   GTK_CELL_AREA_CONTEXT_CLASS (gtk_cell_area_box_context_parent_class)->allocate (context, width, height);
 }
 



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