[gnumeric] Dead kittens: avoid deprecated gtk_style_context_get_background



commit 727dc27c207515cab6b01b90b25174f833aaa4e4
Author: Morten Welinder <terra gnome org>
Date:   Thu Jan 1 18:50:16 2015 -0500

    Dead kittens: avoid deprecated gtk_style_context_get_background

 ChangeLog         |    6 +++++
 src/gnm-pane.c    |   16 ++++++++-----
 src/item-cursor.c |   60 ++++++++++++++++++++++++++++++----------------------
 3 files changed, 51 insertions(+), 31 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index aa654c2..afcfcd5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2015-01-01  Morten Welinder  <terra gnome org>
+
+       * src/gnm-pane.c (update_control_point_colors): Avoid
+       gtk_style_context_get_background_color.
+       * src/item-cursor.c (ic_reload_style): Ditto.
+
 2014-12-30  Morten Welinder  <terra gnome org>
 
        * src/rendered-value.c (gnm_rendered_value_new):
diff --git a/src/gnm-pane.c b/src/gnm-pane.c
index 3a4498a..83e30d3 100644
--- a/src/gnm-pane.c
+++ b/src/gnm-pane.c
@@ -2757,12 +2757,16 @@ update_control_point_colors (GocItem *item, GtkStateFlags flags)
 {
        GtkStyleContext *context = goc_item_get_style_context (item);
        GOStyle *style = go_styled_object_get_style (GO_STYLED_OBJECT (item));
-       GdkRGBA rgba;
-
-       gtk_style_context_get_color (context, flags, &rgba);
-       go_color_from_gdk_rgba (&rgba, &style->line.color);
-       gtk_style_context_get_background_color (context, flags, &rgba);
-       go_color_from_gdk_rgba (&rgba, &style->fill.pattern.back);
+       GdkRGBA *fore, *back;
+
+       gtk_style_context_get (context, flags,
+                              "color", &fore,
+                              "background-color", &back,
+                              NULL);
+       go_color_from_gdk_rgba (fore, &style->line.color);
+       go_color_from_gdk_rgba (back, &style->fill.pattern.back);
+       gdk_rgba_free (fore);
+       gdk_rgba_free (back);
        goc_item_invalidate (item);
 }
 
diff --git a/src/item-cursor.c b/src/item-cursor.c
index 7fccddb..bc5153e 100644
--- a/src/item-cursor.c
+++ b/src/item-cursor.c
@@ -5,6 +5,7 @@
  * Author:
  *     Miguel de Icaza (miguel kernel org)
  *     Jody Goldberg   (jody gnome org)
+ *     Copyright 2015 by Morten Welinder (terra gnome org).
  */
 
 #include <gnumeric-config.h>
@@ -112,37 +113,46 @@ ic_reload_style (GnmItemCursor *ic)
        GocItem *item = GOC_ITEM (ic);
        GtkStyleContext *context = goc_item_get_style_context (item);
        GtkStateFlags state = GTK_STATE_FLAG_NORMAL;
+       struct {
+               const char *class;
+               int fore_offset, back_offset;
+       } substyles[] = {
+               { "normal",
+                 G_STRUCT_OFFSET (GnmItemCursor, normal_color),
+                 -1 },
+               { "ant",
+                 G_STRUCT_OFFSET (GnmItemCursor, ant_color),
+                 G_STRUCT_OFFSET (GnmItemCursor, ant_background_color) },
+               { "drag",
+                 G_STRUCT_OFFSET (GnmItemCursor, drag_color),
+                 G_STRUCT_OFFSET (GnmItemCursor, drag_background_color) },
+               { "autofill",
+                 G_STRUCT_OFFSET (GnmItemCursor, autofill_color),
+                 G_STRUCT_OFFSET (GnmItemCursor, autofill_background_color) }
+       };
+       unsigned ui;
+
+       for (ui = 0; ui < G_N_ELEMENTS (substyles); ui++) {
+               GdkRGBA *fore, *back;
+               gtk_style_context_save (context);
+               gtk_style_context_add_class (context, substyles[ui].class);
+               gtk_style_context_get (context, state,
+                                      "color", &fore,
+                                      "background-color", &back,
+                                      NULL);
+               *(GdkRGBA *)((char *)ic + substyles[ui].fore_offset) = *fore;
+               if (substyles[ui].back_offset >= 0)
+                       *(GdkRGBA *)((char *)ic + substyles[ui].back_offset) = *back;
+               gdk_rgba_free (fore);
+               gdk_rgba_free (back);
+               gtk_style_context_restore (context);
+       }
 
-       gtk_style_context_save (context);
-       gtk_style_context_add_class (context, "normal");
-       gtk_style_context_get_color (context, state, &ic->normal_color);
-       gtk_style_context_restore (context);
-
-       gtk_style_context_save (context);
-       gtk_style_context_add_class (context, "ant");
-       gtk_style_context_get_color (context, state, &ic->ant_color);
-       gtk_style_context_get_background_color (context, state,
-                                               &ic->ant_background_color);
-       gtk_style_context_restore (context);
        /*
         * Ensure we don't use transparency to avoid compositing issues
         * when redrawing the ants in the timer callback.
         */
        ic->ant_color.alpha = ic->ant_background_color.alpha = 1.;
-
-       gtk_style_context_save (context);
-       gtk_style_context_add_class (context, "drag");
-       gtk_style_context_get_color (context, state, &ic->drag_color);
-       gtk_style_context_get_background_color (context, state,
-                                               &ic->drag_background_color);
-       gtk_style_context_restore (context);
-
-       gtk_style_context_save (context);
-       gtk_style_context_add_class (context, "autofill");
-       gtk_style_context_get_color (context, state, &ic->autofill_color);
-       gtk_style_context_get_background_color (context, state,
-                                               &ic->autofill_background_color);
-       gtk_style_context_restore (context);
 }
 
 static int


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