[glade] Fix use of GTK+ style context APIs



commit 0c076cc8828cd80f1f156a08569199675bf35165
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Dec 11 15:23:54 2015 -0500

    Fix use of GTK+ style context APIs
    
    Make sure to save the style context before querying
    with other states. This stops GTK+ from warning, and
    makes things work.

 gladeui/glade-design-view.c |   10 +++++++---
 gladeui/glade-placeholder.c |    6 +++++-
 2 files changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/gladeui/glade-design-view.c b/gladeui/glade-design-view.c
index 598579b..3dc18bf 100644
--- a/gladeui/glade-design-view.c
+++ b/gladeui/glade-design-view.c
@@ -332,11 +332,12 @@ glade_design_view_draw (GtkWidget *widget, cairo_t *cr)
   GdkWindow *window = gtk_widget_get_window (widget);
   gboolean should_draw = gtk_cairo_should_draw_window (cr, window);
   gboolean sw_visible = gtk_widget_get_visible (priv->scrolled_window);
+  GtkStyleContext *context = gtk_widget_get_style_context (widget);
 
   if (should_draw)
     {
       if (sw_visible)
-        gtk_render_background (gtk_widget_get_style_context (widget),
+        gtk_render_background (context,
                                cr, 0, 0,
                                gtk_widget_get_allocated_width (widget),
                                gtk_widget_get_allocated_height (widget));
@@ -348,11 +349,14 @@ glade_design_view_draw (GtkWidget *widget, cairo_t *cr)
 
   if (should_draw && sw_visible && priv->drag_highlight)
     {
-      GtkStyleContext *context = gtk_widget_get_style_context (widget);
       GdkRGBA c;
 
-      gtk_style_context_get_background_color (context, GTK_STATE_FLAG_SELECTED |
+      gtk_style_context_save (context);
+      gtk_style_context_get_background_color (context,
+                                              gtk_style_context_get_state (context) |
+                                              GTK_STATE_FLAG_SELECTED |
                                               GTK_STATE_FLAG_FOCUSED, &c);
+      gtk_style_context_restore (context);
 
       cairo_set_line_width (cr, 2);
       gdk_cairo_set_source_rgba (cr, &c);
diff --git a/gladeui/glade-placeholder.c b/gladeui/glade-placeholder.c
index 5fcee12..09d6e81 100644
--- a/gladeui/glade-placeholder.c
+++ b/gladeui/glade-placeholder.c
@@ -333,8 +333,12 @@ glade_placeholder_draw (GtkWidget *widget, cairo_t *cr)
       GdkRGBA c;
 
       context = gtk_widget_get_style_context (widget);
-      gtk_style_context_get_background_color (context, GTK_STATE_FLAG_SELECTED |
+      gtk_style_context_save (context);
+      gtk_style_context_get_background_color (context,
+                                              gtk_style_context_get_state (context) |
+                                              GTK_STATE_FLAG_SELECTED |
                                               GTK_STATE_FLAG_FOCUSED, &c);
+      gtk_style_context_restore (context);
 
       ww = w/2.0;
       hh = h/2.0;


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