2 * Copyright © 2002 Jorn Baayen <jorn@nl.linux.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * $Id: ephy-search-entry.c 6952 2007-03-11 19:42:02Z chpe $
23 #include <gtk/gtklabel.h>
24 #include <glib/gi18n.h>
27 #include "ephy-search-entry.h"
29 static void ephy_search_entry_class_init (EphySearchEntryClass
*klass
);
30 static void ephy_search_entry_init (EphySearchEntry
*entry
);
32 #define EPHY_SEARCH_ENTRY_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_SEARCH_ENTRY, EphySearchEntryPrivate))
34 struct _EphySearchEntryPrivate
47 static GObjectClass
*parent_class
= NULL
;
49 static guint ephy_search_entry_signals
[LAST_SIGNAL
] = { 0 };
52 ephy_search_entry_get_type (void)
54 static GType type
= 0;
56 if (G_UNLIKELY (type
== 0))
58 const GTypeInfo our_info
=
60 sizeof (EphySearchEntryClass
),
63 (GClassInitFunc
) ephy_search_entry_class_init
,
66 sizeof (EphySearchEntry
),
68 (GInstanceInitFunc
) ephy_search_entry_init
71 type
= g_type_register_static (GTK_TYPE_ENTRY
,
80 ephy_search_entry_class_init (EphySearchEntryClass
*klass
)
82 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
84 parent_class
= g_type_class_peek_parent (klass
);
86 ephy_search_entry_signals
[SEARCH
] =
87 g_signal_new ("search",
88 G_OBJECT_CLASS_TYPE (object_class
),
90 G_STRUCT_OFFSET (EphySearchEntryClass
, search
),
92 g_cclosure_marshal_VOID__STRING
,
97 g_type_class_add_private (object_class
, sizeof (EphySearchEntryPrivate
));
101 ephy_search_entry_timeout_cb (EphySearchEntry
*entry
)
103 g_signal_emit (G_OBJECT (entry
), ephy_search_entry_signals
[SEARCH
], 0,
104 gtk_entry_get_text (GTK_ENTRY (entry
)));
105 entry
->priv
->timeout
= 0;
111 ephy_search_entry_changed_cb (GtkEditable
*editable
,
112 EphySearchEntry
*entry
)
114 if (entry
->priv
->clearing
== TRUE
)
117 if (entry
->priv
->timeout
!= 0)
119 g_source_remove (entry
->priv
->timeout
);
120 entry
->priv
->timeout
= 0;
123 entry
->priv
->timeout
= g_timeout_add (300, (GSourceFunc
) ephy_search_entry_timeout_cb
, entry
);
127 ephy_search_entry_destroy_cb (GtkEditable
*editable
,
128 EphySearchEntry
*entry
)
130 if (entry
->priv
->timeout
)
132 g_source_remove (entry
->priv
->timeout
);
133 entry
->priv
->timeout
= 0;
138 ephy_search_entry_init (EphySearchEntry
*entry
)
140 entry
->priv
= EPHY_SEARCH_ENTRY_GET_PRIVATE (entry
);
142 g_signal_connect (G_OBJECT (entry
),
144 G_CALLBACK (ephy_search_entry_destroy_cb
),
146 g_signal_connect (G_OBJECT (entry
),
148 G_CALLBACK (ephy_search_entry_changed_cb
),
153 ephy_search_entry_new (void)
157 entry
= GTK_WIDGET (g_object_new (EPHY_TYPE_SEARCH_ENTRY
,
164 ephy_search_entry_clear (EphySearchEntry
*entry
)
166 if (entry
->priv
->timeout
!= 0)
168 g_source_remove (entry
->priv
->timeout
);
169 entry
->priv
->timeout
= 0;
172 entry
->priv
->clearing
= TRUE
;
174 gtk_entry_set_text (GTK_ENTRY (entry
), "");
176 entry
->priv
->clearing
= FALSE
;