* gtk_entry_get_text() and gtk_entry_set_text() must never be used to
* get/set the text in this widget. hildon_entry_get_text() and
* hildon_entry_set_text() must be used instead.
+ *
+ * <example>
+ * <title>Creating a HildonEntry with a placeholder</title>
+ * <programlisting>
+ * GtkWidget *
+ * create_entry (void)
+ * {
+ * GtkWidget *entry;
+ * <!-- -->
+ * entry = hildon_entry_new (HILDON_SIZE_AUTO);
+ * hildon_entry_set_placeholder (HILDON_ENTRY (entry), "First name");
+ * <!-- -->
+ * return entry;
+ * }
+ * </programlisting>
+ * </example>
*/
#include "hildon-entry.h"
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
HILDON_TYPE_ENTRY, HildonEntryPrivate));
-typedef struct _HildonEntryPrivate HildonEntryPrivate;
-
struct _HildonEntryPrivate
{
gchar *placeholder;
static void
hildon_entry_refresh_contents (GtkWidget *entry)
{
- HildonEntryPrivate *priv = HILDON_ENTRY_GET_PRIVATE (entry);
+ HildonEntryPrivate *priv = HILDON_ENTRY (entry)->priv;
gboolean showing_placeholder, entry_has_focus;
showing_placeholder = g_str_equal (gtk_widget_get_name (entry), placeholder_widget_name);
/* Show the placeholder when the widget is empty and has no focus */
const gchar *text = gtk_entry_get_text (GTK_ENTRY (entry));
if (text[0] == '\0' && !entry_has_focus) {
- if (priv->placeholder) {
+ if (priv->placeholder[0] != '\0') {
gtk_widget_set_name (entry, placeholder_widget_name);
gtk_entry_set_text (GTK_ENTRY (entry), priv->placeholder);
}
hildon_entry_set_placeholder (HildonEntry *entry,
const gchar *text)
{
- HildonEntryPrivate *priv;
-
g_return_if_fail (HILDON_IS_ENTRY (entry) && text != NULL);
- priv = HILDON_ENTRY_GET_PRIVATE (entry);
-
- g_free (priv->placeholder);
- priv->placeholder = g_strdup (text);
+ g_free (entry->priv->placeholder);
+ entry->priv->placeholder = g_strdup (text);
hildon_entry_refresh_contents (GTK_WIDGET (entry));
}
static void
hildon_entry_finalize (GObject *object)
{
- HildonEntryPrivate *priv = HILDON_ENTRY_GET_PRIVATE (object);
+ HildonEntryPrivate *priv = HILDON_ENTRY (object)->priv;
g_free (priv->placeholder);
static void
hildon_entry_init (HildonEntry *self)
{
- HildonEntryPrivate *priv = HILDON_ENTRY_GET_PRIVATE (self);
-
- priv->placeholder = NULL;
+ self->priv = HILDON_ENTRY_GET_PRIVATE (self);
+ self->priv->placeholder = g_strdup ("");
}