1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2012 Red Hat, Inc.
5 * - Bastien Nocera <bnocera@redhat.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library 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 GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
22 * Modified by the GTK+ Team and others 2012. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 #include "gtksearchentry.h"
33 * SECTION:gtksearchentry
34 * @Short_description: An entry which shows a search icon
35 * @Title: GtkSearchEntry
37 * #GtkSearchEntry is a subclass of #GtkEntry that has
38 * been tailored for use as a search entry.
40 * It will show an inactive symbolic "find" icon when the
41 * search entry is empty, and a symbolic "clear" icon when
42 * there is text. Clicking on the "clear" icon will empty
45 * Note that the search/clear icon is shown using a secondary
46 * icon, and thus does not work if you are using the secondary
47 * icon position for some other purpose.
52 G_DEFINE_TYPE (GtkSearchEntry, gtk_search_entry, GTK_TYPE_ENTRY)
55 gtk_search_entry_class_init (GtkSearchEntryClass *klass)
60 search_entry_clear_cb (GtkEntry *entry,
63 gtk_entry_set_text (entry, "");
67 search_entry_changed_cb (GtkEntry *entry,
70 const char *str, *icon_name;
73 str = gtk_entry_get_text (entry);
75 if (str == NULL || *str == '\0')
77 icon_name = "edit-find-symbolic";
82 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
83 icon_name = "edit-clear-rtl-symbolic";
85 icon_name = "edit-clear-symbolic";
90 "secondary-icon-name", icon_name,
91 "secondary-icon-activatable", active,
92 "secondary-icon-sensitive", active,
97 gtk_search_entry_init (GtkSearchEntry *entry)
99 g_signal_connect (entry, "changed",
100 G_CALLBACK (search_entry_changed_cb), NULL);
101 g_signal_connect (entry, "icon-release",
102 G_CALLBACK (search_entry_clear_cb), NULL);
104 search_entry_changed_cb (GTK_ENTRY (entry), NULL);
108 * gtk_search_entry_new:
110 * Creates a #GtkSearchEntry, with a find icon when the search field is
111 * empty, and a clear icon when it isn't.
113 * Return value: a new #GtkSearchEntry
118 gtk_search_entry_new (void)
120 return GTK_WIDGET (g_object_new (GTK_TYPE_SEARCH_ENTRY, NULL));