Add missing ChangeLog entry
[hildon] / hildon / hildon-entry.c
1 /*
2  * This file is a part of hildon
3  *
4  * Copyright (C) 2008, 2009 Nokia Corporation, all rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser Public License as published by
8  * the Free Software Foundation; version 2 of the license.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser Public License for more details.
14  *
15  */
16
17 /**
18  * SECTION:hildon-entry
19  * @short_description: Text entry in the Hildon framework.
20  *
21  * The #HildonEntry is text entry derived from the #GtkEntry widget providing
22  * additional commodities specific to the Hildon framework.
23  *
24  * A #HildonEntry can have a placeholder text. This text will be shown
25  * if the entry is empty and doesn't have the input focus, but it's
26  * otherwise ignored. Thus, calls to gtk_entry_get_text() will never
27  * return the placeholder text, not even when it's being displayed.
28  *
29  * <example>
30  * <title>Creating a HildonEntry with a placeholder</title>
31  * <programlisting>
32  * GtkWidget *
33  * create_entry (void)
34  * {
35  *     GtkWidget *entry;
36  * <!-- -->
37  *     entry = hildon_entry_new (HILDON_SIZE_AUTO);
38  *     hildon_gtk_entry_set_placeholder_text (GTK_ENTRY (entry), "First name");
39  * <!-- -->
40  *     return entry;
41  * }
42  * </programlisting>
43  * </example>
44  */
45
46 #include                                        "hildon-entry.h"
47
48 G_DEFINE_TYPE                                   (HildonEntry, hildon_entry, GTK_TYPE_ENTRY);
49
50 enum {
51     PROP_SIZE = 1
52 };
53
54 static void
55 set_property                                    (GObject      *object,
56                                                  guint         prop_id,
57                                                  const GValue *value,
58                                                  GParamSpec   *pspec)
59 {
60     HildonSizeType size;
61
62     switch (prop_id)
63     {
64     case PROP_SIZE:
65         size = g_value_get_flags (value);
66         /* If this is auto height, default to finger height. */
67         if (!(size & (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_THUMB_HEIGHT)))
68           size |= HILDON_SIZE_FINGER_HEIGHT;
69         hildon_gtk_widget_set_theme_size (GTK_WIDGET (object), size);
70         break;
71     default:
72         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
73         break;
74     }
75 }
76
77 /**
78  * hildon_entry_set_text:
79  * @entry: a #HildonEntry
80  * @text: the new text
81  *
82  * Sets the text in @entry to @text, replacing its current contents.
83  *
84  * Since: 2.2
85  *
86  * Deprecated: Use gtk_entry_set_text() instead
87  */
88 void
89 hildon_entry_set_text                           (HildonEntry *entry,
90                                                  const gchar *text)
91 {
92     g_return_if_fail (HILDON_IS_ENTRY (entry) && text != NULL);
93     gtk_entry_set_text (GTK_ENTRY (entry), text);
94 }
95
96 /**
97  * hildon_entry_get_text:
98  * @entry: a #HildonEntry
99  *
100  * Gets the current text in @entry.
101  *
102  * Note that the placeholder text (set using
103  * hildon_gtk_entry_set_placeholder_text()) is never returned. Only
104  * text set by gtk_entry_set_text() or typed by the user is
105  * considered.
106  *
107  * Returns: the text in @entry. This text must not be modified or
108  * freed.
109  *
110  * Since: 2.2
111  *
112  * Deprecated: Use gtk_entry_get_text() instead
113  */
114 const gchar *
115 hildon_entry_get_text                           (HildonEntry *entry)
116 {
117     g_return_val_if_fail (HILDON_IS_ENTRY (entry), NULL);
118     return gtk_entry_get_text (GTK_ENTRY (entry));
119 }
120
121 /**
122  * hildon_entry_set_placeholder:
123  * @entry: a #HildonEntry
124  * @text: the new text
125  *
126  * Sets the placeholder text in @entry to @text.
127  *
128  * Since: 2.2
129  *
130  * Deprecated: Use hildon_gtk_entry_set_placeholder_text() instead
131  */
132 void
133 hildon_entry_set_placeholder                    (HildonEntry *entry,
134                                                  const gchar *text)
135 {
136     g_return_if_fail (HILDON_IS_ENTRY (entry) && text != NULL);
137     hildon_gtk_entry_set_placeholder_text (GTK_ENTRY (entry), text);
138 }
139
140 /**
141  * hildon_entry_new:
142  * @size: The size of the entry
143  *
144  * Creates a new entry.
145  *
146  * Returns: a new #HildonEntry
147  *
148  * Since: 2.2
149  */
150 GtkWidget *
151 hildon_entry_new                                (HildonSizeType size)
152 {
153     return g_object_new (HILDON_TYPE_ENTRY, "size", size, NULL);
154 }
155
156 static void
157 hildon_entry_class_init                         (HildonEntryClass *klass)
158 {
159     GObjectClass *gobject_class = (GObjectClass *)klass;
160
161     gobject_class->set_property = set_property;
162
163     g_object_class_install_property (
164         gobject_class,
165         PROP_SIZE,
166         g_param_spec_flags (
167             "size",
168             "Size",
169             "Size request for the entry",
170             HILDON_TYPE_SIZE_TYPE,
171             HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
172             G_PARAM_CONSTRUCT | G_PARAM_WRITABLE));
173 }
174
175 static void
176 hildon_entry_init                               (HildonEntry *self)
177 {
178     self->priv = NULL;
179 }