[egg-list-box/flow-box-enhancements] Avoid redundant bookkeeping



commit 7e7b602935820acd381fb940046540a52664da83
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Sep 28 14:40:21 2013 -0400

    Avoid redundant bookkeeping
    
    With EggFlowBoxChild now a proper widget, we don't need to
    keep its allocated area separately. We can just use the
    allocation.

 egg-flow-box.c |   77 ++++++++++++++++++++-----------------------------------
 1 files changed, 28 insertions(+), 49 deletions(-)
---
diff --git a/egg-flow-box.c b/egg-flow-box.c
index 6bbdd97..18c663b 100644
--- a/egg-flow-box.c
+++ b/egg-flow-box.c
@@ -153,7 +153,6 @@ typedef struct _EggFlowBoxChildPrivate EggFlowBoxChildPrivate;
 struct _EggFlowBoxChildPrivate
 {
   GSequenceIter *iter;
-  GdkRectangle   area;
   guint          selected : 1;
 };
 
@@ -1166,13 +1165,7 @@ egg_flow_box_size_allocate (GtkWidget     *widget,
       child_priv = egg_flow_box_child_get_instance_private (EGG_FLOW_BOX_CHILD (child));
 
       if (!child_is_visible (child))
-        {
-          child_priv->area.x = child_allocation.x;
-          child_priv->area.y = child_allocation.y;
-          child_priv->area.width = 0;
-          child_priv->area.height = 0;
-          continue;
-        }
+        continue;
 
       /* Get item position */
       position = i % line_length;
@@ -1275,10 +1268,6 @@ egg_flow_box_size_allocate (GtkWidget     *widget,
 
       if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
         child_allocation.x = allocation->x + allocation->width - (child_allocation.x - allocation->x) - 
child_allocation.width;
-      child_priv->area.x = child_allocation.x;
-      child_priv->area.y = child_allocation.y;
-      child_priv->area.width = child_allocation.width;
-      child_priv->area.height = child_allocation.height;
       gtk_widget_size_allocate (child, &child_allocation);
 
       item_offset += this_item_size;
@@ -2347,27 +2336,24 @@ egg_flow_box_find_child_at_pos (EggFlowBox *box,
                                 gint        y)
 {
   EggFlowBoxPrivate *priv = box->priv;
-  EggFlowBoxChild *child;
+  GtkWidget *child;
   GSequenceIter *iter;
-  EggFlowBoxChild *info;
-  EggFlowBoxChildPrivate *child_priv;
+  GtkAllocation allocation;
 
-  child = NULL;
   for (iter = g_sequence_get_begin_iter (priv->children);
        !g_sequence_iter_is_end (iter);
        iter = g_sequence_iter_next (iter))
     {
-      info = (EggFlowBoxChild *) g_sequence_get (iter);
-      child_priv = egg_flow_box_child_get_instance_private (info);
-      if (x >= child_priv->area.x && x < (child_priv->area.x + child_priv->area.width)
-          && y >= child_priv->area.y && y < (child_priv->area.y + child_priv->area.height))
-        {
-          child = info;
-          break;
-        }
+      child = g_sequence_get (iter);
+      if (!child_is_visible (child))
+        continue;
+      gtk_widget_get_allocation (child, &allocation);
+      if (x >= allocation.x && x < (allocation.x + allocation.width) &&
+          y >= allocation.y && y < (allocation.y + allocation.height))
+        return EGG_FLOW_BOX_CHILD (child);
     }
 
-  return child;
+  return NULL;
 }
 
 static void
@@ -2498,21 +2484,6 @@ egg_flow_box_button_press_event (GtkWidget      *widget,
   return FALSE;
 }
 
-static void
-egg_flow_box_queue_draw_child (EggFlowBox          *box,
-                               EggFlowBoxChild *child)
-{
-  EggFlowBoxChildPrivate *priv;
-  GdkRectangle rect;
-  GdkWindow *window;
-
-  priv = egg_flow_box_child_get_instance_private (child);
-  rect = priv->area;
-
-  window = gtk_widget_get_window (GTK_WIDGET (box));
-  gdk_window_invalidate_rect (window, &rect, TRUE);
-}
-
 static gboolean
 egg_flow_box_child_set_selected (EggFlowBoxChild *child,
                                  gboolean         selected)
@@ -3059,6 +3030,7 @@ egg_flow_box_move_cursor (EggFlowBox      *box,
   EggFlowBoxChild *prev;
   EggFlowBoxChild *next;
   EggFlowBoxChildPrivate *child_priv;
+  GtkAllocation allocation;
   gint page_size;
   GSequenceIter *iter;
   gint start_y;
@@ -3131,8 +3103,9 @@ egg_flow_box_move_cursor (EggFlowBox      *box,
 
       if (priv->cursor_child != NULL)
         {
+          gtk_widget_get_allocation (GTK_WIDGET (priv->cursor_child), &allocation);
           child_priv = egg_flow_box_child_get_instance_private (priv->cursor_child);
-          start_y = child_priv->area.y;
+          start_y = allocation.y;
           end_y = start_y;
           iter = child_priv->iter;
 
@@ -3152,9 +3125,12 @@ egg_flow_box_move_cursor (EggFlowBox      *box,
                   child_priv = egg_flow_box_child_get_instance_private (prev);
 
                   /* go up an even number of rows */
-                  if (i % priv->cur_children_per_line == 0
-                      && child_priv->area.y < start_y - page_size)
-                    break;
+                  if (i % priv->cur_children_per_line == 0)
+                    {
+                      gtk_widget_get_allocation (GTK_WIDGET (prev), &allocation);
+                      if (allocation.y < start_y - page_size)
+                        break;
+                    }
 
                   child = prev;
                   i++;
@@ -3174,16 +3150,19 @@ egg_flow_box_move_cursor (EggFlowBox      *box,
                   next = g_sequence_get (iter);
                   child_priv = egg_flow_box_child_get_instance_private (next);
 
-                  if (i % priv->cur_children_per_line == 0
-                      && child_priv->area.y > start_y + page_size)
-                    break;
+                  if (i % priv->cur_children_per_line == 0)
+                    {
+                      gtk_widget_get_allocation (GTK_WIDGET (next), &allocation);
+                      if (allocation.y > start_y + page_size)
+                        break;
+                    }
 
                   child = next;
                   i++;
                 }
             }
-          child_priv = egg_flow_box_child_get_instance_private (child);
-          end_y = child_priv->area.y;
+          gtk_widget_get_allocation (GTK_WIDGET (child), &allocation);
+          end_y = allocation.y;
         }
       break;
 


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