HildonEntry/HildonTextView: add deprecation guards where needed
[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 #undef                                          HILDON_DISABLE_DEPRECATED
47
48 #include                                        "hildon-entry.h"
49
50 G_DEFINE_TYPE                                   (HildonEntry, hildon_entry, GTK_TYPE_ENTRY);
51
52 enum {
53     PROP_SIZE = 1
54 };
55
56 static void
57 set_property                                    (GObject      *object,
58                                                  guint         prop_id,
59                                                  const GValue *value,
60                                                  GParamSpec   *pspec)
61 {
62     HildonSizeType size;
63
64     switch (prop_id)
65     {
66     case PROP_SIZE:
67         size = g_value_get_flags (value);
68         /* If this is auto height, default to finger height. */
69         if (!(size & (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_THUMB_HEIGHT)))
70           size |= HILDON_SIZE_FINGER_HEIGHT;
71         hildon_gtk_widget_set_theme_size (GTK_WIDGET (object), size);
72         break;
73     default:
74         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
75         break;
76     }
77 }
78
79 /**
80  * hildon_entry_set_text:
81  * @entry: a #HildonEntry
82  * @text: the new text
83  *
84  * Sets the text in @entry to @text, replacing its current contents.
85  *
86  * Since: 2.2
87  *
88  * Deprecated: Use gtk_entry_set_text() instead
89  */
90 void
91 hildon_entry_set_text                           (HildonEntry *entry,
92                                                  const gchar *text)
93 {
94     g_return_if_fail (HILDON_IS_ENTRY (entry) && text != NULL);
95     gtk_entry_set_text (GTK_ENTRY (entry), text);
96 }
97
98 /**
99  * hildon_entry_get_text:
100  * @entry: a #HildonEntry
101  *
102  * Gets the current text in @entry.
103  *
104  * Note that the placeholder text (set using
105  * hildon_gtk_entry_set_placeholder_text()) is never returned. Only
106  * text set by gtk_entry_set_text() or typed by the user is
107  * considered.
108  *
109  * Returns: the text in @entry. This text must not be modified or
110  * freed.
111  *
112  * Since: 2.2
113  *
114  * Deprecated: Use gtk_entry_get_text() instead
115  */
116 const gchar *
117 hildon_entry_get_text                           (HildonEntry *entry)
118 {
119     g_return_val_if_fail (HILDON_IS_ENTRY (entry), NULL);
120     return gtk_entry_get_text (GTK_ENTRY (entry));
121 }
122
123 /**
124  * hildon_entry_set_placeholder:
125  * @entry: a #HildonEntry
126  * @text: the new text
127  *
128  * Sets the placeholder text in @entry to @text.
129  *
130  * Since: 2.2
131  *
132  * Deprecated: Use hildon_gtk_entry_set_placeholder_text() instead
133  */
134 void
135 hildon_entry_set_placeholder                    (HildonEntry *entry,
136                                                  const gchar *text)
137 {
138     g_return_if_fail (HILDON_IS_ENTRY (entry) && text != NULL);
139     hildon_gtk_entry_set_placeholder_text (GTK_ENTRY (entry), text);
140 }
141
142 /**
143  * hildon_entry_new:
144  * @size: The size of the entry
145  *
146  * Creates a new entry.
147  *
148  * Returns: a new #HildonEntry
149  *
150  * Since: 2.2
151  */
152 GtkWidget *
153 hildon_entry_new                                (HildonSizeType size)
154 {
155     return g_object_new (HILDON_TYPE_ENTRY, "size", size, NULL);
156 }
157
158 static void
159 hildon_entry_class_init                         (HildonEntryClass *klass)
160 {
161     GObjectClass *gobject_class = (GObjectClass *)klass;
162
163     gobject_class->set_property = set_property;
164
165     g_object_class_install_property (
166         gobject_class,
167         PROP_SIZE,
168         g_param_spec_flags (
169             "size",
170             "Size",
171             "Size request for the entry",
172             HILDON_TYPE_SIZE_TYPE,
173             HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
174             G_PARAM_CONSTRUCT | G_PARAM_WRITABLE));
175 }
176
177 static void
178 hildon_entry_init                               (HildonEntry *self)
179 {
180     self->priv = NULL;
181 }