Add HildonAppMenu::changed signal
[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  * #HildonEntry is text entry derived from the #GtkEntry widget but
22  * with a slightly different appearance designed for the Hildon 2.2
23  * framework.
24  *
25  * Text entries in Hildon 2.2 can have a placeholder text, set with
26  * hildon_gtk_entry_set_placeholder_text(). This text will be shown if
27  * the entry is empty and doesn't have the input focus, but it's
28  * otherwise ignored. Thus, calls to gtk_entry_get_text() will never
29  * return the placeholder text, not even when it's being displayed.
30  *
31  * <example>
32  * <title>Creating a HildonEntry with a placeholder</title>
33  * <programlisting>
34  * GtkWidget *
35  * create_entry (void)
36  * {
37  *     GtkWidget *entry;
38  * <!-- -->
39  *     entry = hildon_entry_new (HILDON_SIZE_AUTO);
40  *     hildon_gtk_entry_set_placeholder_text (GTK_ENTRY (entry), "First name");
41  * <!-- -->
42  *     return entry;
43  * }
44  * </programlisting>
45  * </example>
46  */
47
48 #undef                                          HILDON_DISABLE_DEPRECATED
49
50 #include                                        "hildon-entry.h"
51
52 G_DEFINE_TYPE                                   (HildonEntry, hildon_entry, GTK_TYPE_ENTRY);
53
54 enum {
55     PROP_SIZE = 1
56 };
57
58 static void
59 set_property                                    (GObject      *object,
60                                                  guint         prop_id,
61                                                  const GValue *value,
62                                                  GParamSpec   *pspec)
63 {
64     HildonSizeType size;
65
66     switch (prop_id)
67     {
68     case PROP_SIZE:
69         size = g_value_get_flags (value);
70         /* If this is auto height, default to finger height. */
71         if (!(size & (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_THUMB_HEIGHT)))
72           size |= HILDON_SIZE_FINGER_HEIGHT;
73         hildon_gtk_widget_set_theme_size (GTK_WIDGET (object), size);
74         break;
75     default:
76         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
77         break;
78     }
79 }
80
81 /**
82  * hildon_entry_set_text:
83  * @entry: a #HildonEntry
84  * @text: the new text
85  *
86  * Sets the text in @entry to @text, replacing its current contents.
87  *
88  * Since: 2.2
89  *
90  * Deprecated: Use gtk_entry_set_text() instead
91  */
92 void
93 hildon_entry_set_text                           (HildonEntry *entry,
94                                                  const gchar *text)
95 {
96     g_return_if_fail (HILDON_IS_ENTRY (entry) && text != NULL);
97     gtk_entry_set_text (GTK_ENTRY (entry), text);
98 }
99
100 /**
101  * hildon_entry_get_text:
102  * @entry: a #HildonEntry
103  *
104  * Gets the current text in @entry.
105  *
106  * Note that the placeholder text (set using
107  * hildon_gtk_entry_set_placeholder_text()) is never returned. Only
108  * text set by gtk_entry_set_text() or typed by the user is
109  * considered.
110  *
111  * Returns: the text in @entry. This text must not be modified or
112  * freed.
113  *
114  * Since: 2.2
115  *
116  * Deprecated: Use gtk_entry_get_text() instead
117  */
118 const gchar *
119 hildon_entry_get_text                           (HildonEntry *entry)
120 {
121     g_return_val_if_fail (HILDON_IS_ENTRY (entry), NULL);
122     return gtk_entry_get_text (GTK_ENTRY (entry));
123 }
124
125 /**
126  * hildon_entry_set_placeholder:
127  * @entry: a #HildonEntry
128  * @text: the new text
129  *
130  * Sets the placeholder text in @entry to @text.
131  *
132  * Since: 2.2
133  *
134  * Deprecated: Use hildon_gtk_entry_set_placeholder_text() instead
135  */
136 void
137 hildon_entry_set_placeholder                    (HildonEntry *entry,
138                                                  const gchar *text)
139 {
140     g_return_if_fail (HILDON_IS_ENTRY (entry) && text != NULL);
141     hildon_gtk_entry_set_placeholder_text (GTK_ENTRY (entry), text);
142 }
143
144 /**
145  * hildon_entry_new:
146  * @size: The size of the entry
147  *
148  * Creates a new entry.
149  *
150  * Returns: a new #HildonEntry
151  *
152  * Since: 2.2
153  */
154 GtkWidget *
155 hildon_entry_new                                (HildonSizeType size)
156 {
157     return g_object_new (HILDON_TYPE_ENTRY, "size", size, NULL);
158 }
159
160 static void
161 hildon_entry_class_init                         (HildonEntryClass *klass)
162 {
163     GObjectClass *gobject_class = (GObjectClass *)klass;
164
165     gobject_class->set_property = set_property;
166
167     g_object_class_install_property (
168         gobject_class,
169         PROP_SIZE,
170         g_param_spec_flags (
171             "size",
172             "Size",
173             "Size request for the entry",
174             HILDON_TYPE_SIZE_TYPE,
175             HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
176             G_PARAM_CONSTRUCT | G_PARAM_WRITABLE));
177 }
178
179 static void
180 hildon_entry_init                               (HildonEntry *self)
181 {
182     self->priv = NULL;
183 }