[gtk+/rendering-cleanup: 58/142] treeview: Convert GtkTreeViewColumn rendering to Cairo



commit eb341bd229242395cad1b46df2938aa02aebc4c6
Author: Benjamin Otte <otte redhat com>
Date:   Tue Aug 24 15:45:41 2010 +0200

    treeview: Convert GtkTreeViewColumn rendering to Cairo

 gtk/gtktreeprivate.h    |    6 +--
 gtk/gtktreeview.c       |   41 ++++++++++++++-----------
 gtk/gtktreeviewcolumn.c |   77 ++++++++++++++++++++++-------------------------
 3 files changed, 61 insertions(+), 63 deletions(-)
---
diff --git a/gtk/gtktreeprivate.h b/gtk/gtktreeprivate.h
index 2c35956..8b18e7f 100644
--- a/gtk/gtktreeprivate.h
+++ b/gtk/gtktreeprivate.h
@@ -439,10 +439,9 @@ gboolean          _gtk_tree_selection_row_is_selectable  (GtkTreeSelection *sele
 							  GtkTreePath      *path);
 
 void		  _gtk_tree_view_column_cell_render      (GtkTreeViewColumn  *tree_column,
-							  GdkWindow          *window,
+							  cairo_t            *cr,
 							  const GdkRectangle *background_area,
 							  const GdkRectangle *cell_area,
-							  const GdkRectangle *expose_area,
 							  guint               flags);
 void		  _gtk_tree_view_column_get_focus_area   (GtkTreeViewColumn  *tree_column,
 							  const GdkRectangle *background_area,
@@ -453,10 +452,9 @@ gboolean	  _gtk_tree_view_column_cell_focus       (GtkTreeViewColumn  *tree_colu
 							  gboolean            left,
 							  gboolean            right);
 void		  _gtk_tree_view_column_cell_draw_focus  (GtkTreeViewColumn  *tree_column,
-							  GdkWindow          *window,
+							  cairo_t            *cr,
 							  const GdkRectangle *background_area,
 							  const GdkRectangle *cell_area,
-							  const GdkRectangle *expose_area,
 							  guint               flags);
 void		  _gtk_tree_view_column_cell_set_dirty	 (GtkTreeViewColumn  *tree_column,
 							  gboolean            install_handler);
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index e535943..246d358 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -4388,6 +4388,7 @@ gtk_tree_view_bin_expose (GtkWidget      *widget,
   gint grid_line_width;
   gboolean got_pointer = FALSE;
   gboolean draw_vgrid_lines, draw_hgrid_lines;
+  cairo_t *cr;
 
   rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
 
@@ -4408,6 +4409,10 @@ gtk_tree_view_bin_expose (GtkWidget      *widget,
   if (event->area.height < 0)
     return TRUE;
 
+  cr = gdk_cairo_create (event->window);
+  gdk_cairo_region (cr, event->region);
+  cairo_clip (cr);
+
   validate_visible_area (tree_view);
 
   style = gtk_widget_get_style (widget);
@@ -4435,7 +4440,10 @@ gtk_tree_view_bin_expose (GtkWidget      *widget,
     }
 
   if (node == NULL)
-    return TRUE;
+    {
+      cairo_destroy (cr);
+      return TRUE;
+    }
 
   /* find the path for the node */
   path = _gtk_tree_view_find_path ((GtkTreeView *)widget,
@@ -4729,10 +4737,9 @@ gtk_tree_view_bin_expose (GtkWidget      *widget,
 				 cell_area.y + cell_area.height / 2);
 	      else
 		_gtk_tree_view_column_cell_render (column,
-						   event->window,
+						   cr,
 						   &background_area,
 						   &cell_area,
-						   &event->area,
 						   flags);
 	      if (TREE_VIEW_DRAW_EXPANDERS(tree_view)
 		  && (node->flags & GTK_RBNODE_IS_PARENT) == GTK_RBNODE_IS_PARENT)
@@ -4764,10 +4771,9 @@ gtk_tree_view_bin_expose (GtkWidget      *widget,
 				 cell_area.y + cell_area.height / 2);
 	      else
 		_gtk_tree_view_column_cell_render (column,
-						   event->window,
+						   cr,
 						   &background_area,
 						   &cell_area,
-						   &event->area,
 						   flags);
 	    }
 
@@ -4867,10 +4873,9 @@ gtk_tree_view_bin_expose (GtkWidget      *widget,
 	       (column == tree_view->priv->edited_column)))
 	    {
 	      _gtk_tree_view_column_cell_draw_focus (column,
-						     event->window,
+						     cr,
 						     &background_area,
 						     &cell_area,
-						     &event->area,
 						     flags);
 	    }
 
@@ -5057,6 +5062,8 @@ done:
   if (drag_dest_path)
     gtk_tree_path_free (drag_dest_path);
 
+  cairo_destroy (cr);
+
   return FALSE;
 }
 
@@ -13877,21 +13884,19 @@ gtk_tree_view_create_row_drag_icon (GtkTreeView  *tree_view,
       if (gtk_tree_view_column_cell_is_visible (column))
 	{
 	  if (is_separator)
-	    gtk_paint_hline (style,
-			     drawable,
-			     GTK_STATE_NORMAL,
-			     &cell_area,
-			     widget,
-			     NULL,
-			     cell_area.x,
-			     cell_area.x + cell_area.width,
-			     cell_area.y + cell_area.height / 2);
+	    gtk_cairo_paint_hline (style,
+                                   cr,
+                                   GTK_STATE_NORMAL,
+                                   widget,
+                                   NULL,
+                                   cell_area.x,
+                                   cell_area.x + cell_area.width,
+                                   cell_area.y + cell_area.height / 2);
 	  else
 	    _gtk_tree_view_column_cell_render (column,
-					       drawable,
+                                               cr,
 					       &background_area,
 					       &cell_area,
-					       &expose_area,
 					       0);
 	}
       cell_offset += column->width;
diff --git a/gtk/gtktreeviewcolumn.c b/gtk/gtktreeviewcolumn.c
index ebc054d..b920376 100644
--- a/gtk/gtktreeviewcolumn.c
+++ b/gtk/gtktreeviewcolumn.c
@@ -2670,12 +2670,11 @@ enum {
 
 static gboolean
 gtk_tree_view_column_cell_process_action (GtkTreeViewColumn  *tree_column,
-					  GdkWindow          *window,
+					  cairo_t            *cr,
 					  const GdkRectangle *background_area,
 					  const GdkRectangle *cell_area,
 					  guint               flags,
 					  gint                action,
-					  const GdkRectangle *expose_area,     /* RENDER */
 					  GdkRectangle       *focus_rectangle, /* FOCUS  */
 					  GtkCellEditable   **editable_widget, /* EVENT  */
 					  GdkEvent           *event,           /* EVENT  */
@@ -2684,7 +2683,6 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn  *tree_column,
   GList *list;
   GdkRectangle real_cell_area;
   GdkRectangle real_background_area;
-  GdkRectangle real_expose_area = *cell_area;
   gint depth = 0;
   gint expand_cell_count = 0;
   gint full_requested_width = 0;
@@ -2828,13 +2826,12 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn  *tree_column,
       /* RENDER */
       if (action == CELL_ACTION_RENDER)
 	{
-	  gtk_cell_renderer_render (info->cell,
-				    window,
-				    tree_column->tree_view,
-				    &rtl_background_area,
-				    &rtl_cell_area,
-				    &real_expose_area, 
-				    flags);
+	  gtk_cell_renderer_render_cairo (info->cell,
+                                          cr,
+                                          tree_column->tree_view,
+                                          &rtl_background_area,
+                                          &rtl_cell_area,
+                                          flags);
 	}
       /* FOCUS */
       else if (action == CELL_ACTION_FOCUS)
@@ -2993,13 +2990,12 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn  *tree_column,
       /* RENDER */
       if (action == CELL_ACTION_RENDER)
 	{
-	  gtk_cell_renderer_render (info->cell,
-				    window,
-				    tree_column->tree_view,
-				    &rtl_background_area,
-				    &rtl_cell_area,
-				    &real_expose_area,
-				    flags);
+	  gtk_cell_renderer_render_cairo (info->cell,
+                                          cr,
+                                          tree_column->tree_view,
+                                          &rtl_background_area,
+                                          &rtl_cell_area,
+                                          flags);
 	}
       /* FOCUS */
       else if (action == CELL_ACTION_FOCUS)
@@ -3139,10 +3135,9 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn  *tree_column,
 /**
  * gtk_tree_view_column_cell_render:
  * @tree_column: A #GtkTreeViewColumn.
- * @window: a #GdkDrawable to draw to
+ * @cr: cairo context to draw to
  * @background_area: entire cell area (including tree expanders and maybe padding on the sides)
  * @cell_area: area normally rendered by a cell renderer
- * @expose_area: area that actually needs updating
  * @flags: flags that affect rendering
  * 
  * Renders the cell contained by #tree_column. This is used primarily by the
@@ -3150,25 +3145,27 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn  *tree_column,
  **/
 void
 _gtk_tree_view_column_cell_render (GtkTreeViewColumn  *tree_column,
-				   GdkWindow          *window,
+				   cairo_t            *cr,
 				   const GdkRectangle *background_area,
 				   const GdkRectangle *cell_area,
-				   const GdkRectangle *expose_area,
 				   guint               flags)
 {
   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
+  g_return_if_fail (cr != NULL);
   g_return_if_fail (background_area != NULL);
   g_return_if_fail (cell_area != NULL);
-  g_return_if_fail (expose_area != NULL);
+
+  cairo_save (cr);
 
   gtk_tree_view_column_cell_process_action (tree_column,
-					    window,
+					    cr,
 					    background_area,
 					    cell_area,
 					    flags,
 					    CELL_ACTION_RENDER,
-					    expose_area,
 					    NULL, NULL, NULL, NULL);
+
+  cairo_restore (cr);
 }
 
 gboolean
@@ -3183,12 +3180,12 @@ _gtk_tree_view_column_cell_event (GtkTreeViewColumn  *tree_column,
   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
 
   return gtk_tree_view_column_cell_process_action (tree_column,
-						   NULL,
+                                                   NULL,
 						   background_area,
 						   cell_area,
 						   flags,
 						   CELL_ACTION_EVENT,
-						   NULL, NULL,
+						   NULL,
 						   editable_widget,
 						   event,
 						   path_string);
@@ -3206,7 +3203,6 @@ _gtk_tree_view_column_get_focus_area (GtkTreeViewColumn  *tree_column,
 					    cell_area,
 					    0,
 					    CELL_ACTION_FOCUS,
-					    NULL,
 					    focus_area,
 					    NULL, NULL, NULL);
 }
@@ -3462,16 +3458,17 @@ _gtk_tree_view_column_cell_focus (GtkTreeViewColumn *tree_column,
 
 void
 _gtk_tree_view_column_cell_draw_focus (GtkTreeViewColumn  *tree_column,
-				       GdkWindow          *window,
+				       cairo_t            *cr,
 				       const GdkRectangle *background_area,
 				       const GdkRectangle *cell_area,
-				       const GdkRectangle *expose_area,
 				       guint               flags)
 {
   gint focus_line_width;
   GtkStateType cell_state;
   
   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
+  g_return_if_fail (cr != NULL);
+
   gtk_widget_style_get (GTK_WIDGET (tree_column->tree_view),
 			"focus-line-width", &focus_line_width, NULL);
   if (tree_column->editable_widget)
@@ -3495,28 +3492,26 @@ _gtk_tree_view_column_cell_draw_focus (GtkTreeViewColumn  *tree_column,
     {
       GdkRectangle focus_rectangle;
       gtk_tree_view_column_cell_process_action (tree_column,
-						window,
+						cr,
 						background_area,
 						cell_area,
 						flags,
 						CELL_ACTION_FOCUS,
-						expose_area,
 						&focus_rectangle,
 						NULL, NULL, NULL);
 
       cell_state = flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
 	      (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
 	      (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL));
-      gtk_paint_focus (gtk_widget_get_style (tree_column->tree_view),
-		       window,
-		       cell_state,
-		       cell_area,
-		       tree_column->tree_view,
-		       "treeview",
-		       focus_rectangle.x,
-		       focus_rectangle.y,
-		       focus_rectangle.width,
-		       focus_rectangle.height);
+      gtk_cairo_paint_focus (gtk_widget_get_style (tree_column->tree_view),
+                             cr,
+                             cell_state,
+                             tree_column->tree_view,
+                             "treeview",
+                             focus_rectangle.x,
+                             focus_rectangle.y,
+                             focus_rectangle.width,
+                             focus_rectangle.height);
     }
 }
 



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