fix issues with hint text

Add a "hint_visible" private variable to keep track of when the hint text
is visible. Use this to determine whether to return the text from the
internal ClutterText or whether to return an empty string.

Fixes: http://bugzilla.moblin.org/show_bug.cgi?id=6837
       http://bugzilla.moblin.org/show_bug.cgi?id=6836

https://bugzilla.gnome.org/show_bug.cgi?id=611095
This commit is contained in:
Thomas Wood 2009-10-20 14:22:17 +01:00 committed by Florian Müllner
parent d2bf7ec66c
commit d593877548

View File

@ -97,6 +97,8 @@ struct _StEntryPrivate
ClutterActor *secondary_icon; ClutterActor *secondary_icon;
gfloat spacing; gfloat spacing;
gboolean hint_visible;
}; };
static guint entry_signals[LAST_SIGNAL] = { 0, }; static guint entry_signals[LAST_SIGNAL] = { 0, };
@ -375,9 +377,10 @@ clutter_text_focus_in_cb (ClutterText *text,
StEntryPrivate *priv = ST_ENTRY_PRIV (actor); StEntryPrivate *priv = ST_ENTRY_PRIV (actor);
/* remove the hint if visible */ /* remove the hint if visible */
if (priv->hint if (priv->hint && priv->hint_visible)
&& !strcmp (clutter_text_get_text (text), priv->hint))
{ {
priv->hint_visible = FALSE;
clutter_text_set_text (text, ""); clutter_text_set_text (text, "");
} }
st_widget_set_style_pseudo_class (ST_WIDGET (actor), "focus"); st_widget_set_style_pseudo_class (ST_WIDGET (actor), "focus");
@ -393,6 +396,8 @@ clutter_text_focus_out_cb (ClutterText *text,
/* add a hint if the entry is empty */ /* add a hint if the entry is empty */
if (priv->hint && !strcmp (clutter_text_get_text (text), "")) if (priv->hint && !strcmp (clutter_text_get_text (text), ""))
{ {
priv->hint_visible = TRUE;
clutter_text_set_text (text, priv->hint); clutter_text_set_text (text, priv->hint);
st_widget_set_style_pseudo_class (ST_WIDGET (actor), "indeterminate"); st_widget_set_style_pseudo_class (ST_WIDGET (actor), "indeterminate");
} }
@ -705,6 +710,9 @@ st_entry_get_text (StEntry *entry)
{ {
g_return_val_if_fail (ST_IS_ENTRY (entry), NULL); g_return_val_if_fail (ST_IS_ENTRY (entry), NULL);
if (entry->priv->hint_visible)
return "";
else
return clutter_text_get_text (CLUTTER_TEXT (entry->priv->entry)); return clutter_text_get_text (CLUTTER_TEXT (entry->priv->entry));
} }
@ -731,6 +739,7 @@ st_entry_set_text (StEntry *entry,
&& !HAS_FOCUS (priv->entry)) && !HAS_FOCUS (priv->entry))
{ {
text = priv->hint; text = priv->hint;
priv->hint_visible = TRUE;
st_widget_set_style_pseudo_class (ST_WIDGET (entry), "indeterminate"); st_widget_set_style_pseudo_class (ST_WIDGET (entry), "indeterminate");
} }
else else
@ -739,6 +748,8 @@ st_entry_set_text (StEntry *entry,
st_widget_set_style_pseudo_class (ST_WIDGET (entry), "focus"); st_widget_set_style_pseudo_class (ST_WIDGET (entry), "focus");
else else
st_widget_set_style_pseudo_class (ST_WIDGET (entry), NULL); st_widget_set_style_pseudo_class (ST_WIDGET (entry), NULL);
priv->hint_visible = FALSE;
} }
clutter_text_set_text (CLUTTER_TEXT (priv->entry), text); clutter_text_set_text (CLUTTER_TEXT (priv->entry), text);
@ -786,8 +797,11 @@ st_entry_set_hint_text (StEntry *entry,
priv->hint = g_strdup (text); priv->hint = g_strdup (text);
if (!strcmp (clutter_text_get_text (CLUTTER_TEXT (priv->entry)), "")) if (!strcmp (clutter_text_get_text (CLUTTER_TEXT (priv->entry)), "")
&& !HAS_FOCUS (priv->entry))
{ {
priv->hint_visible = TRUE;
clutter_text_set_text (CLUTTER_TEXT (priv->entry), priv->hint); clutter_text_set_text (CLUTTER_TEXT (priv->entry), priv->hint);
st_widget_set_style_pseudo_class (ST_WIDGET (entry), "indeterminate"); st_widget_set_style_pseudo_class (ST_WIDGET (entry), "indeterminate");
} }