2 * This file is a part of hildon
4 * Copyright (C) 2008 Nokia Corporation, all rights reserved.
6 * Contact: Karl Lattimer <karl.lattimer@nokia.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser Public License as published by
10 * the Free Software Foundation; version 2 of the license.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser Public License for more details.
20 * SECTION:hildon-entry
21 * @short_description: Widget representing a text entry in the Hildon framework.
23 * The #HildonEntry is a GTK widget which represents a text entry. It
24 * is derived from the #GtkEntry widget and provides additional
25 * commodities specific to the Hildon framework.
27 * Besides all the features inherited from #GtkEntry, a #HildonEntry
28 * can also have a placeholder text. This text will be shown if the
29 * entry is empty and doesn't have the input focus, but it's otherwise
30 * ignored. Thus, calls to hildon_entry_get_text() will never return
31 * the placeholder text, not even when it's being displayed.
33 * Although #HildonEntry is derived from #GtkEntry,
34 * gtk_entry_get_text() and gtk_entry_set_text() must never be used to
35 * get/set the text in this widget. hildon_entry_get_text() and
36 * hildon_entry_set_text() must be used instead.
39 #include "hildon-entry.h"
41 G_DEFINE_TYPE (HildonEntry, hildon_entry, GTK_TYPE_ENTRY);
43 static const gchar *placeholder_widget_name = "hildon-entry-placeholder";
46 * hildon_entry_set_text:
47 * @entry: a #HildonEntry
50 * Sets the text in @entry to @text, replacing its current contents.
52 * Note that you must never use gtk_entry_set_text() to set the text
56 hildon_entry_set_text (HildonEntry *entry,
59 g_return_if_fail (HILDON_IS_ENTRY (entry));
61 gtk_entry_set_text (GTK_ENTRY (entry), text);
63 gtk_widget_set_name (GTK_WIDGET (entry), NULL);
67 * hildon_entry_get_text:
68 * @entry: a #HildonEntry
70 * Gets the current text in @entry.
72 * Note that you must never use gtk_entry_get_text() to get the text
73 * from a #HildonEntry.
75 * Also note that placeholder text (set using
76 * hildon_entry_set_placeholder()) is never returned. Only text set by
77 * hildon_entry_set_text() or typed by the user is considered.
79 * Returns: the text in @entry. This text must not be modified or
83 hildon_entry_get_text (HildonEntry *entry)
85 g_return_val_if_fail (HILDON_IS_ENTRY (entry), NULL);
87 if (g_str_equal (gtk_widget_get_name (GTK_WIDGET (entry)), placeholder_widget_name)) {
91 return gtk_entry_get_text (GTK_ENTRY (entry));
95 * hildon_entry_set_placeholder:
96 * @entry: a #HildonEntry
99 * Sets the placeholder text in @entry to @text.
102 hildon_entry_set_placeholder (HildonEntry *entry,
105 g_return_if_fail (HILDON_IS_ENTRY (entry));
107 gtk_widget_set_name (GTK_WIDGET (entry), placeholder_widget_name);
109 gtk_entry_set_text (GTK_ENTRY (entry), text);
114 * @size: The size of the entry
116 * Creates a new entry.
118 * Returns: a new #HildonEntry
121 hildon_entry_new (HildonSizeType size)
123 GtkWidget *entry = g_object_new (HILDON_TYPE_ENTRY, NULL);
125 hildon_gtk_widget_set_theme_size (entry, size);
131 hildon_entry_focus_in_event (GtkWidget *widget,
132 GdkEventFocus *event)
134 if (g_str_equal (gtk_widget_get_name (widget), placeholder_widget_name)) {
135 hildon_entry_set_text (HILDON_ENTRY (widget), "");
137 if (GTK_WIDGET_CLASS (hildon_entry_parent_class)->focus_in_event) {
138 return GTK_WIDGET_CLASS (hildon_entry_parent_class)->focus_in_event (widget, event);
145 hildon_entry_class_init (HildonEntryClass *klass)
147 GtkWidgetClass *widget_class = (GtkWidgetClass *)klass;
149 widget_class->focus_in_event = hildon_entry_focus_in_event;
153 hildon_entry_init (HildonEntry *self)