[glade/glade-3-12] Draw bg for windowless widgets used as toplevels. Added custom stype provider to setip bg color to @



commit 5afe1e90afb1d30d767bb63aacb930a9b5d5fd4d
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date:   Wed Apr 25 13:15:48 2012 -0300

    Draw bg for windowless widgets used as toplevels.
    Added custom stype provider to setip bg color to @base_color.
    Symplyfied glade_design_layout_style_updated() using gtk_style_context_lookup_color()

 gladeui/glade-design-layout.c |   66 ++++++++++++++++++++---------------------
 1 files changed, 32 insertions(+), 34 deletions(-)
---
diff --git a/gladeui/glade-design-layout.c b/gladeui/glade-design-layout.c
index 6814d53..a6ad5c5 100644
--- a/gladeui/glade-design-layout.c
+++ b/gladeui/glade-design-layout.c
@@ -85,6 +85,7 @@ struct _GladeDesignLayoutPrivate
 
   /* Colors */
   GdkRGBA fg_color;
+  GdkRGBA bg_color;
   GdkRGBA frame_color[2];
   GdkRGBA frame_color_active[2];
 
@@ -1472,7 +1473,16 @@ glade_design_layout_draw (GtkWidget *widget, cairo_t *cr)
           gint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
           gboolean selected = FALSE;
           GList *l;
-          
+
+		  /* Draw bg for windowless widgets */
+		  if (!gtk_widget_get_has_window (child))
+			{
+			  gdk_cairo_set_source_rgba (cr, &priv->bg_color);
+			  cairo_rectangle (cr, priv->child_offset, priv->child_offset,
+			                   priv->current_width, priv->current_height);
+			  cairo_fill (cr);
+			}
+		  
           /* draw offscreen widgets */
           gdk_cairo_set_source_window (cr, priv->offscreen_window,
                                        priv->child_offset, priv->child_offset);
@@ -1739,46 +1749,22 @@ static void
 glade_design_layout_style_updated (GtkWidget *widget)
 {
   GladeDesignLayoutPrivate *priv = GLADE_DESIGN_LAYOUT_GET_PRIVATE (widget);
-  GtkStyleContext *context = gtk_style_context_new ();
-  GtkWidgetPath *path = gtk_widget_path_new ();
-  GdkRGBA bg_color;
+  GtkStyleContext *context = gtk_widget_get_style_context (widget);
 
-  g_type_class_ref (GTK_TYPE_TREE_VIEW);
-  gtk_widget_path_append_type (path, GTK_TYPE_WIDGET);
-  gtk_style_context_set_path (context, path);
-  gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
-  gtk_widget_path_free (path);
+  gtk_style_context_lookup_color (context, "fg_color", &priv->fg_color);
+  gtk_style_context_lookup_color (context, "bg_color", &priv->frame_color[0]);
+  gtk_style_context_lookup_color (context, "selected_bg_color", &priv->frame_color_active[0]);
+  gtk_style_context_lookup_color (context, "selected_fg_color", &priv->frame_color_active[1]);
 
-  gtk_style_context_get_background_color (context,
-                                          GTK_STATE_FLAG_NORMAL,
-                                          &bg_color);
-  gtk_style_context_get_color (context,
-                               GTK_STATE_FLAG_NORMAL,
-                               &priv->fg_color);
-  
-  gtk_style_context_get_background_color (context, GTK_STATE_FLAG_SELECTED,
-                                          &priv->frame_color[0]);
-  gtk_style_context_get_color (context, GTK_STATE_FLAG_SELECTED,
-                               &priv->frame_color[1]);
-  
-  gtk_style_context_get_background_color (context,
-                                          GTK_STATE_FLAG_SELECTED |
-                                          GTK_STATE_FLAG_FOCUSED,
-                                          &priv->frame_color_active[0]);
-  gtk_style_context_get_color (context,
-                               GTK_STATE_FLAG_SELECTED |
-                               GTK_STATE_FLAG_FOCUSED,
-                               &priv->frame_color_active[1]);
-  
-  gtk_widget_override_background_color (widget, GTK_STATE_FLAG_NORMAL, &bg_color);
-
-  g_object_unref (context);
+  priv->frame_color[1] = priv->fg_color;
+  priv->bg_color = priv->frame_color[0];
 }
 
 static void
 glade_design_layout_init (GladeDesignLayout *layout)
 {
   GladeDesignLayoutPrivate *priv;
+  GtkCssProvider *provider;
   gint i;
   
   layout->priv = priv = GLADE_DESIGN_LAYOUT_GET_PRIVATE (layout);
@@ -1796,6 +1782,16 @@ glade_design_layout_init (GladeDesignLayout *layout)
   priv->south.height = PADDING + OUTLINE_WIDTH;
 
   gtk_widget_set_has_window (GTK_WIDGET (layout), TRUE);
+
+  provider = gtk_css_provider_new ();
+  gtk_css_provider_load_from_data (provider,
+                                   "GladeDesignLayout {\n"
+                                   "  background-color : @base_color;\n"
+                                   "  }", -1, NULL);
+
+  gtk_style_context_add_provider (gtk_widget_get_style_context (GTK_WIDGET (layout)),
+                                  GTK_STYLE_PROVIDER (provider),
+                                  GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
 }
 
 static void
@@ -1899,7 +1895,9 @@ glade_design_layout_constructor (GType                  type,
                     "selection-changed",
                     G_CALLBACK (on_project_selection_changed),
                     GLADE_DESIGN_LAYOUT (object));
-                    
+
+  glade_design_layout_style_updated (GTK_WIDGET (object));
+
   return object;
 }
 



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