[gtk+/treeview-style: 4/8] Make GtkCellRendererText use GtkStyleContext



commit fe3753f447673c68b8b924b91e35bbdf9d1a6dd2
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Jan 12 21:26:52 2011 +0100

    Make GtkCellRendererText use GtkStyleContext

 gtk/gtkcellrenderertext.c |   73 ++++++++++++++++++++++++---------------------
 1 files changed, 39 insertions(+), 34 deletions(-)
---
diff --git a/gtk/gtkcellrenderertext.c b/gtk/gtkcellrenderertext.c
index a54b274..85f3970 100644
--- a/gtk/gtkcellrenderertext.c
+++ b/gtk/gtkcellrenderertext.c
@@ -1690,12 +1690,17 @@ get_size (GtkCellRenderer    *cell,
 
   if (priv->calc_fixed_height)
     {
+      GtkStyleContext *style_context;
+      GtkStateFlags state;
       PangoContext *context;
       PangoFontMetrics *metrics;
       PangoFontDescription *font_desc;
       gint row_height;
 
-      font_desc = pango_font_description_copy_static (gtk_widget_get_style (widget)->font_desc);
+      style_context = gtk_widget_get_style_context (widget);
+      state = gtk_widget_get_state_flags (widget);
+
+      font_desc = pango_font_description_copy_static (gtk_style_context_get_font (style_context, state));
       pango_font_description_merge_static (font_desc, priv->font, TRUE);
 
       if (priv->scale_set)
@@ -1787,39 +1792,40 @@ gtk_cell_renderer_text_render (GtkCellRenderer      *cell,
 {
   GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (cell);
   GtkCellRendererTextPrivate *priv = celltext->priv;
+  GtkStyleContext *context;
   PangoLayout *layout;
-  GtkStateType state;
+  GtkStateFlags state = 0;
   gint x_offset = 0;
   gint y_offset = 0;
   gint xpad, ypad;
 
   layout = get_layout (celltext, widget, cell_area, flags);
   get_size (cell, widget, cell_area, layout, &x_offset, &y_offset, NULL, NULL);
+  context = gtk_widget_get_style_context (widget);
 
-  if (!gtk_cell_renderer_get_sensitive (cell))
-    {
-      state = GTK_STATE_INSENSITIVE;
-    }
-  else if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
-    {
-      if (gtk_widget_has_focus (widget))
-	state = GTK_STATE_SELECTED;
-      else
-	state = GTK_STATE_ACTIVE;
-    }
-  else if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT &&
-	   gtk_widget_get_state (widget) == GTK_STATE_PRELIGHT)
-    {
-      state = GTK_STATE_PRELIGHT;
-    }
+  gtk_style_context_save (context);
+
+  if (!gtk_widget_get_sensitive (widget) ||
+      !gtk_cell_renderer_get_sensitive (cell))
+    state |= GTK_STATE_FLAG_INSENSITIVE;
   else
     {
-      if (gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE)
-	state = GTK_STATE_INSENSITIVE;
-      else
-	state = GTK_STATE_NORMAL;
+      if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
+        {
+          if (gtk_widget_has_focus (widget))
+            state |= GTK_STATE_FLAG_FOCUSED;
+
+          state |= GTK_STATE_FLAG_SELECTED;
+        }
+
+      if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT &&
+          (gtk_widget_get_state_flags (widget) & GTK_STATE_FLAG_PRELIGHT) != 0)
+        state |= GTK_STATE_FLAG_PRELIGHT;
     }
 
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_CELL);
+  gtk_style_context_set_state (context, state);
+
   if (priv->background_set && 
       (flags & GTK_CELL_RENDERER_SELECTED) == 0)
     {
@@ -1841,15 +1847,12 @@ gtk_cell_renderer_text_render (GtkCellRenderer      *cell,
   gdk_cairo_rectangle (cr, cell_area);
   cairo_clip (cr);
 
-  gtk_paint_layout (gtk_widget_get_style (widget),
-                          cr,
-                          state,
-                          TRUE,
-                          widget,
-                          "cellrenderertext",
-                          cell_area->x + x_offset + xpad,
-                          cell_area->y + y_offset + ypad,
-                          layout);
+  gtk_render_layout (context, cr,
+                     cell_area->x + x_offset + xpad,
+                     cell_area->y + y_offset + ypad,
+                     layout);
+
+  gtk_style_context_restore (context);
 
   cairo_restore (cr);
 
@@ -2108,7 +2111,8 @@ gtk_cell_renderer_text_get_preferred_width (GtkCellRenderer *cell,
 {
   GtkCellRendererTextPrivate    *priv;
   GtkCellRendererText        *celltext;
-  GtkStyle                   *style;
+  GtkStyleContext            *style_context;
+  const PangoFontDescription *font_desc;
   PangoLayout                *layout;
   PangoContext               *context;
   PangoFontMetrics           *metrics;
@@ -2128,7 +2132,7 @@ gtk_cell_renderer_text_get_preferred_width (GtkCellRenderer *cell,
   celltext = GTK_CELL_RENDERER_TEXT (cell);
   priv = celltext->priv;
 
-  style = gtk_widget_get_style (widget);
+  style_context = gtk_widget_get_style_context (widget);
 
   gtk_cell_renderer_get_padding (cell, &xpad, NULL);
 
@@ -2141,7 +2145,8 @@ gtk_cell_renderer_text_get_preferred_width (GtkCellRenderer *cell,
 
   /* Fetch the average size of a charachter */
   context = pango_layout_get_context (layout);
-  metrics = pango_context_get_metrics (context, style->font_desc,
+  font_desc = gtk_style_context_get_font (style_context, 0);
+  metrics = pango_context_get_metrics (context, font_desc,
 				       pango_context_get_language (context));
   
   char_width = pango_font_metrics_get_approximate_char_width (metrics);



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