[gtk-css-engine] [style] Infrastructure for keeping auxiliary widget data in the engine.



commit c34f2e150ad74c2b7bdbd6c2e64817e52141ef23
Author: Robert Staudinger <robsta gnome org>
Date:   Mon Aug 17 10:26:03 2009 +0200

    [style] Infrastructure for keeping auxiliary widget data in the engine.
    
    Add a simple first use case tracking toplevel focus change.

 src/gce-style.c                   |   61 +++++++++++++++++++++++++++++++++++++
 themes/moblesse/gtk-2.0/gtkrc.css |   16 ++++++++++
 2 files changed, 77 insertions(+), 0 deletions(-)
---
diff --git a/src/gce-style.c b/src/gce-style.c
index 2ff5212..0ac1b41 100644
--- a/src/gce-style.c
+++ b/src/gce-style.c
@@ -28,6 +28,28 @@
 static GType          gce_style_type = 0;
 static GtkStyleClass *gce_style_parent_class = NULL;
 
+static GHashTable *_widget_aux_hash = NULL;
+
+static void
+has_toplevel_focus_notify (GtkWindow	*window,
+			   GParamSpec	*pspec,
+			   GtkWidget	*widget)
+{
+	gtk_widget_queue_draw_area (widget, 0, 0, G_MAXINT, G_MAXINT);
+}
+
+static void
+widget_destroy_cb (GtkWidget	 *widget,
+		   GtkWidget	 *watchee)
+{
+	gulong id;
+
+	id = g_hash_table_steal (_widget_aux_hash, widget);
+
+	if (g_signal_handler_is_connected (watchee, id))
+		g_signal_handler_disconnect (watchee, id);
+}
+
 static void
 rectangle (GceStyle		*self, 
 	   GceNode 		*node,
@@ -42,6 +64,7 @@ rectangle (GceStyle		*self,
 {
 	cairo_t		*cr;
 	ccss_style_t	*style = NULL;
+	char		*send_expose = NULL;
 
 	g_return_if_fail (self);
 	g_return_if_fail (self->stylesheet);
@@ -71,6 +94,36 @@ rectangle (GceStyle		*self,
 		/* FIXME: force 'background: none' by inserting/frobbing? */
 		ccss_cairo_style_draw_rectangle (style, cr, x, y, width, height);
 
+		/* Handle custom expose hooks, this is where it gets dirty. */
+		if (ccss_style_get_string (style, "gce-send-expose", &send_expose) &&
+		    0 == g_strcmp0 (send_expose, "toplevel-focus-change")) {
+
+			GtkWidget *toplevel = NULL;
+
+			/* Check if the widget is already hooked up. */
+			if (!g_hash_table_lookup (_widget_aux_hash, widget)) {
+				toplevel = gtk_widget_get_toplevel (widget);
+			}
+			if (toplevel &&
+			    GTK_WIDGET_TOPLEVEL (toplevel)) {
+
+				gulong id;
+				id = g_signal_connect (toplevel,
+						       "notify::has-toplevel-focus",
+						       G_CALLBACK (has_toplevel_focus_notify),
+						       widget);
+				/* FIXME: only one hook per widget this way.
+				 * If we need more we can insert a struct with
+				 * the IDs as value. */
+				g_hash_table_insert (_widget_aux_hash,
+						     widget,
+						     GUINT_TO_POINTER (id));
+				g_signal_connect (widget,
+						  "destroy",
+						  G_CALLBACK (widget_destroy_cb),
+						  toplevel);
+			}
+		}
 
 		cairo_destroy (cr), cr = NULL;
 		ccss_style_destroy (style), style = NULL;
@@ -780,6 +833,8 @@ finalize (GObject *instance)
 		self->selector = NULL;
 	}
 
+	g_hash_table_unref (_widget_aux_hash);
+
 	G_OBJECT_CLASS (gce_style_parent_class)->finalize (instance);
 }
 
@@ -788,6 +843,12 @@ instance_init (GceStyle *self)
 {
 	self->stylesheet = NULL;
 	self->selector = NULL;
+
+	if (_widget_aux_hash == NULL) {
+		_widget_aux_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
+	} else {
+		g_hash_table_ref (_widget_aux_hash);
+	}
 }
 
 static void 
diff --git a/themes/moblesse/gtk-2.0/gtkrc.css b/themes/moblesse/gtk-2.0/gtkrc.css
index c0c37da..2ba9f79 100644
--- a/themes/moblesse/gtk-2.0/gtkrc.css
+++ b/themes/moblesse/gtk-2.0/gtkrc.css
@@ -12,6 +12,10 @@
 	background-color: gtk-color(bg_color);
 	border-color: gtk-color(fg_color);
 	color: gtk-color(text_color);
+
+	/* Inherit expse hacks from widget to primitive. */
+	gce-send-expose: inherit;
+
 	/* Terminate recursion for properties inherited by the builtin stylesheet.
 	border-radius: none;
 	border-image: none;
@@ -240,6 +244,18 @@ GtkSeparatorMenuItem {
 	border-top: 1px dotted gtk-color(fg_color);
 }
 
+/* Experimental. */
+GtkToolbar {
+	gce-send-expose: toplevel-focus-change;
+}
+GtkWindow[has-toplevel-focus=true] GtkToolbar {
+	background: red;
+}
+GtkWindow[has-toplevel-focus=false] GtkToolbar {
+	background: blue;
+}
+/**/
+
 GtkToolbar[orientation=horizontal] > GtkSeparatorToolItem {
 	border-left: 1px dotted gtk-color(fg_color);
 }



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