[tasks] koto-hint-entry: update when the style changes



commit 39d3abe5a182359671dc3cfa56d2b9676fa0fb22
Author: Ross Burton <ross linux intel com>
Date:   Wed May 26 10:17:42 2010 +0100

    koto-hint-entry: update when the style changes

 libkoto/koto-hint-entry.c |   36 +++++++++++++++++++++++++++++++++---
 1 files changed, 33 insertions(+), 3 deletions(-)
---
diff --git a/libkoto/koto-hint-entry.c b/libkoto/koto-hint-entry.c
index 213cce5..2256b5d 100644
--- a/libkoto/koto-hint-entry.c
+++ b/libkoto/koto-hint-entry.c
@@ -40,6 +40,29 @@ typedef struct {
  * Private methods.
  */
 
+static void koto_hint_entry_style_set (GtkWidget *widget, GtkStyle *old_style, gpointer user_data);
+
+static void
+change_style (KotoHintEntry *entry)
+{
+  KotoHintEntryPrivate *priv = GET_PRIVATE (entry);
+
+  g_signal_handlers_block_by_func (entry, koto_hint_entry_style_set, NULL);
+
+  switch (priv->state) {
+  case STATE_ENTRY:
+    gtk_widget_modify_text ((GtkWidget*) entry, GTK_STATE_NORMAL, NULL);
+    break;
+  case STATE_HINTING:
+    gtk_widget_modify_text ((GtkWidget*) entry,
+                            GTK_STATE_NORMAL,
+                            &gtk_widget_get_style ((GtkWidget*) entry)->text[GTK_STATE_INSENSITIVE]);
+    break;
+  }
+
+  g_signal_handlers_unblock_by_func (entry, koto_hint_entry_style_set, NULL);
+}
+
 static void
 update (KotoHintEntry *entry)
 {
@@ -57,15 +80,14 @@ update (KotoHintEntry *entry)
   if (gtk_widget_has_focus (GTK_WIDGET (entry))) {
     if (priv->state == STATE_HINTING) {
       priv->state = STATE_ENTRY;
-      gtk_widget_modify_text (widget, GTK_STATE_NORMAL, NULL);
       gtk_entry_set_text (GTK_ENTRY (entry), "");
+      change_style (entry);
     }
   } else {
     if (text == NULL || text[0] == '\0') {
       priv->state = STATE_HINTING;
       gtk_entry_set_text (GTK_ENTRY (entry), priv->hint);
-      gtk_widget_modify_text (widget, GTK_STATE_NORMAL,
-                              &gtk_widget_get_style (widget)->text[GTK_STATE_INSENSITIVE]);
+      change_style (entry);
     } else {
       priv->state = STATE_ENTRY;
     }
@@ -81,6 +103,12 @@ enum {
   PROP_HINT,
 };
 
+static void
+koto_hint_entry_style_set (GtkWidget *widget, GtkStyle *old_style, gpointer user_data)
+{
+  change_style (KOTO_HINT_ENTRY (widget));
+}
+
 static gboolean
 focus_in_event (GtkWidget *widget, GdkEventFocus *event)
 {
@@ -177,6 +205,8 @@ koto_hint_entry_class_init (KotoHintEntryClass *klass)
 static void
 koto_hint_entry_init (KotoHintEntry *self)
 {
+  /* Do this here instead of overriding the callback so we can't block ourself */
+  g_signal_connect (self, "style-set", G_CALLBACK (koto_hint_entry_style_set), NULL);
 }
 
 



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