aboutsummaryrefslogtreecommitdiff
path: root/hildon/hildon-entry.c
blob: 2e32ca3857308946979c448bb186b70373773216 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
 * This file is a part of hildon
 *
 * Copyright (C) 2008, 2009 Nokia Corporation, all rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser Public License as published by
 * the Free Software Foundation; version 2 of the license.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser Public License for more details.
 *
 */

/**
 * SECTION:hildon-entry
 * @short_description: Text entry in the Hildon framework.
 *
 * #HildonEntry is text entry derived from the #GtkEntry widget but
 * with a slightly different appearance designed for the Hildon 2.2
 * framework.
 *
 * Text entries in Hildon 2.2 can have a placeholder text, set with
 * hildon_gtk_entry_set_placeholder_text(). This text will be shown if
 * the entry is empty and doesn't have the input focus, but it's
 * otherwise ignored. Thus, calls to gtk_entry_get_text() will never
 * return the placeholder text, not even when it's being displayed.
 *
 * <example>
 * <title>Creating a HildonEntry with a placeholder</title>
 * <programlisting>
 * GtkWidget *
 * create_entry (void)
 * {
 *     GtkWidget *entry;
 * <!-- -->
 *     entry = hildon_entry_new (HILDON_SIZE_AUTO);
 *     hildon_gtk_entry_set_placeholder_text (GTK_ENTRY (entry), "First name");
 * <!-- -->
 *     return entry;
 * }
 * </programlisting>
 * </example>
 */

#undef                                          HILDON_DISABLE_DEPRECATED

#include                                        "hildon-entry.h"

G_DEFINE_TYPE                                   (HildonEntry, hildon_entry, GTK_TYPE_ENTRY);

enum {
    PROP_SIZE = 1
};

static void
set_property                                    (GObject      *object,
                                                 guint         prop_id,
                                                 const GValue *value,
                                                 GParamSpec   *pspec)
{
    HildonSizeType size;

    switch (prop_id)
    {
    case PROP_SIZE:
	size = g_value_get_flags (value);
	/* If this is auto height, default to finger height. */
	if (!(size & (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_THUMB_HEIGHT)))
	  size |= HILDON_SIZE_FINGER_HEIGHT;
	hildon_gtk_widget_set_theme_size (GTK_WIDGET (object), size);
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        break;
    }
}

/**
 * hildon_entry_set_text:
 * @entry: a #HildonEntry
 * @text: the new text
 *
 * Sets the text in @entry to @text, replacing its current contents.
 *
 * Since: 2.2
 *
 * Deprecated: Use gtk_entry_set_text() instead
 */
void
hildon_entry_set_text                           (HildonEntry *entry,
                                                 const gchar *text)
{
    g_return_if_fail (HILDON_IS_ENTRY (entry) && text != NULL);
    gtk_entry_set_text (GTK_ENTRY (entry), text);
}

/**
 * hildon_entry_get_text:
 * @entry: a #HildonEntry
 *
 * Gets the current text in @entry.
 *
 * Note that the placeholder text (set using
 * hildon_gtk_entry_set_placeholder_text()) is never returned. Only
 * text set by gtk_entry_set_text() or typed by the user is
 * considered.
 *
 * Returns: the text in @entry. This text must not be modified or
 * freed.
 *
 * Since: 2.2
 *
 * Deprecated: Use gtk_entry_get_text() instead
 */
const gchar *
hildon_entry_get_text                           (HildonEntry *entry)
{
    g_return_val_if_fail (HILDON_IS_ENTRY (entry), NULL);
    return gtk_entry_get_text (GTK_ENTRY (entry));
}

/**
 * hildon_entry_set_placeholder:
 * @entry: a #HildonEntry
 * @text: the new text
 *
 * Sets the placeholder text in @entry to @text.
 *
 * Since: 2.2
 *
 * Deprecated: Use hildon_gtk_entry_set_placeholder_text() instead
 */
void
hildon_entry_set_placeholder                    (HildonEntry *entry,
                                                 const gchar *text)
{
    g_return_if_fail (HILDON_IS_ENTRY (entry) && text != NULL);
#ifdef MAEMO_GTK
    hildon_gtk_entry_set_placeholder_text (GTK_ENTRY (entry), text);
#endif
}

/**
 * hildon_entry_new:
 * @size: The size of the entry
 *
 * Creates a new entry.
 *
 * Returns: a new #HildonEntry
 *
 * Since: 2.2
 */
GtkWidget *
hildon_entry_new                                (HildonSizeType size)
{
    return g_object_new (HILDON_TYPE_ENTRY, "size", size, NULL);
}

static void
hildon_entry_class_init                         (HildonEntryClass *klass)
{
    GObjectClass *gobject_class = (GObjectClass *)klass;

    gobject_class->set_property = set_property;

    g_object_class_install_property (
        gobject_class,
        PROP_SIZE,
        g_param_spec_flags (
            "size",
            "Size",
            "Size request for the entry",
            HILDON_TYPE_SIZE_TYPE,
            HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
            G_PARAM_CONSTRUCT | G_PARAM_WRITABLE));
}

static void
hildon_entry_init                               (HildonEntry *self)
{
    self->priv = NULL;
}