g_object_get_data (G_OBJECT (entry), "sokoke_has_default"));
if (has_default)
{
- gtk_entry_set_text (entry, "");
g_object_set_data (G_OBJECT (entry), "sokoke_has_default",
GINT_TO_POINTER (0));
+ gtk_entry_set_text (entry, "");
sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
PANGO_STYLE_NORMAL);
}
{
const gchar* default_text = (const gchar*)g_object_get_data (
G_OBJECT (entry), "sokoke_default_text");
- gtk_entry_set_text (entry, default_text);
g_object_set_data (G_OBJECT (entry),
"sokoke_has_default", GINT_TO_POINTER (1));
+ gtk_entry_set_text (entry, default_text);
sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
PANGO_STYLE_ITALIC);
}
/* Note: The default text initially overwrites any previous text */
gchar* old_value = g_object_get_data (G_OBJECT (entry),
"sokoke_default_text");
+ g_object_set_data (G_OBJECT (entry), "sokoke_default_text",
+ (gpointer)default_text);
+
if (!old_value)
{
g_object_set_data (G_OBJECT (entry), "sokoke_has_default",
PANGO_STYLE_ITALIC);
}
}
- g_object_set_data (G_OBJECT (entry), "sokoke_default_text",
- (gpointer)default_text);
+}
+
+const gchar*
+gtk_entry_get_placeholder_text (GtkEntry* entry)
+{
+ return g_object_get_data (G_OBJECT (entry), "sokoke_default_text");
}
#endif
#if !GTK_CHECK_VERSION (3, 2, 0) && defined (HAVE_HILDON_2_2)
#define gtk_entry_set_placeholder_text hildon_gtk_entry_set_placeholder_text
+ #define gtk_entry_get_placeholder_text hildon_gtk_entry_get_placeholder_text
#elif !GTK_CHECK_VERSION (3, 2, 0)
- #define gtk_entry_set_placeholder_text sokoke_entry_set_default_text
+ void gtk_entry_set_placeholder_text (GtkEntry* entry, const gchar* text);
+ const gchar* gtk_entry_get_placeholder_text (GtkEntry* entry);
#endif
#if !GTK_CHECK_VERSION(2, 12, 0)
return g_string_free (tooltip, FALSE);
}
+static gboolean
+sokoke_entry_has_placeholder_text (GtkEntry* entry)
+{
+ const gchar* text = gtk_entry_get_text (entry);
+ const gchar* hint = gtk_entry_get_placeholder_text (entry);
+ if (!gtk_widget_has_focus (GTK_WIDGET (entry))
+ && hint != NULL
+ && (text == NULL || !strcmp (text, hint)))
+ return TRUE;
+ return FALSE;
+}
+
static void
sokoke_entry_changed_cb (GtkEditable* editable,
GtkEntry* entry)
{
- const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
- gboolean visible = text && *text;
+ const gchar* text = gtk_entry_get_text (entry);
+ gboolean visible = text && *text
+ && ! sokoke_entry_has_placeholder_text (entry);
gtk_icon_entry_set_icon_from_stock (
GTK_ICON_ENTRY (entry),
GTK_ICON_ENTRY_SECONDARY,
visible ? GTK_STOCK_CLEAR : NULL);
}
+static gboolean
+sokoke_entry_focus_out_event_cb (GtkEditable* editable,
+ GdkEventFocus* event,
+ GtkEntry* entry)
+{
+ sokoke_entry_changed_cb (editable, entry);
+ return FALSE;
+}
+
static void
sokoke_entry_icon_released_cb (GtkEntry* entry,
GtkIconEntryPosition icon_pos,
g_object_connect (entry,
"signal::icon-release",
G_CALLBACK (sokoke_entry_icon_released_cb), NULL,
+ "signal::focus-in-event",
+ G_CALLBACK (sokoke_entry_focus_out_event_cb), entry,
+ "signal::focus-out-event",
+ G_CALLBACK (sokoke_entry_focus_out_event_cb), entry,
"signal::changed",
G_CALLBACK (sokoke_entry_changed_cb), entry, NULL);
- g_signal_emit_by_name (G_OBJECT (entry), "changed");
+ sokoke_entry_changed_cb ((GtkEditable*)entry, entry);
}
else
{
g_object_disconnect (entry,
"any_signal::icon-release",
G_CALLBACK (sokoke_entry_icon_released_cb), NULL,
+ "any_signal::focus-in-event",
+ G_CALLBACK (sokoke_entry_focus_out_event_cb), entry,
+ "any_signal::focus-out-event",
+ G_CALLBACK (sokoke_entry_focus_out_event_cb), entry,
"any_signal::changed",
G_CALLBACK (sokoke_entry_changed_cb), entry, NULL);
+ gtk_icon_entry_set_icon_from_stock (
+ GTK_ICON_ENTRY (entry), GTK_ICON_ENTRY_SECONDARY, NULL);
}
}