2
* Copyright (C) 2002 Jorn Baayen
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, or (at your option)
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
#include "find-dialog.h"
24
#include "prefs-strings.h"
25
#include "galeon-embed.h"
26
#include <gdk/gdkkeysyms.h>
28
#define CONF_FIND_MATCH_CASE "/apps/galeon/Browsing/Find/match_case"
29
#define CONF_FIND_AUTOWRAP "/apps/galeon/Browsing/Find/autowrap"
30
#define CONF_FIND_WORD "/apps/galeon/Browsing/Find/word"
32
static void find_dialog_class_init (FindDialogClass *klass);
33
static void find_dialog_init (FindDialog *dialog);
34
static void find_dialog_finalize (GObject *object);
35
static void impl_show (GaleonDialog *dialog);
39
gboolean find_key_press_event_cb (GtkWidget *widget, GdkEventKey *event,
40
GaleonDialog *dialog);
41
void find_close_button_clicked_cb (GtkWidget *button, GaleonDialog *dialog);
42
void find_next_button_clicked_cb (GtkWidget *button, GaleonDialog *dialog);
43
void find_prev_button_clicked_cb (GtkWidget *button, GaleonDialog *dialog);
44
void find_entry_changed_cb (GtkWidget *editable, GaleonDialog *dialog);
45
void find_check_toggled_cb (GtkWidget *toggle, GaleonDialog *dialog);
47
static GObjectClass *parent_class = NULL;
49
struct FindDialogPrivate
51
GaleonEmbed *old_embed;
64
GaleonDialogProperty properties [] =
66
{ MATCH_CASE_PROP, "case_check", CONF_FIND_MATCH_CASE, PT_NORMAL, NULL },
67
{ AUTOWRAP_PROP, "wrap_check", CONF_FIND_AUTOWRAP, PT_NORMAL, NULL },
68
{ WORD_PROP, "find_entry", CONF_FIND_WORD, PT_NORMAL, NULL },
69
{ BACK_BUTTON, "back_button", NULL, PT_NORMAL, NULL },
70
{ FORWARD_BUTTON, "forward_button", NULL, PT_NORMAL, NULL },
75
find_dialog_get_type (void)
77
static GType find_dialog_type = 0;
79
if (find_dialog_type == 0)
81
static const GTypeInfo our_info =
83
sizeof (FindDialogClass),
85
NULL, /* base_finalize */
86
(GClassInitFunc) find_dialog_class_init,
88
NULL, /* class_data */
91
(GInstanceInitFunc) find_dialog_init
94
find_dialog_type = g_type_register_static (GALEON_EMBED_DIALOG_TYPE,
99
return find_dialog_type;
104
impl_show (GaleonDialog *dialog)
106
GALEON_DIALOG_CLASS (parent_class)->show (dialog);
108
/* Focus the text entry. This will correctly select or leave
109
* unselected the existing text in the entry depending on the
110
* 'gtk-entry-select-on-focus = 0 / 1' setting in user's gtkrc.
112
gtk_widget_grab_focus (galeon_dialog_get_control (dialog, WORD_PROP));
116
find_dialog_class_init (FindDialogClass *klass)
118
GObjectClass *object_class = G_OBJECT_CLASS (klass);
119
GaleonDialogClass *galeon_dialog_class;
121
parent_class = g_type_class_peek_parent (klass);
122
galeon_dialog_class = GALEON_DIALOG_CLASS (klass);
124
object_class->finalize = find_dialog_finalize;
126
galeon_dialog_class->show = impl_show;
130
update_navigation_controls (FindDialog *dialog, gboolean prev, gboolean next)
134
button = galeon_dialog_get_control (GALEON_DIALOG (dialog), BACK_BUTTON);
135
gtk_widget_set_sensitive (button, prev);
137
button = galeon_dialog_get_control (GALEON_DIALOG (dialog), FORWARD_BUTTON);
138
gtk_widget_set_sensitive (button, next);
142
set_properties (FindDialog *find_dialog)
146
GValue match_case = {0, };
148
GaleonDialog *dialog = GALEON_DIALOG (find_dialog);
149
gboolean b_match_case;
153
/* get the search string from the entry field */
154
galeon_dialog_get_value (dialog, WORD_PROP, &word);
155
search_string = g_strdup(g_value_get_string (&word));
156
g_value_unset (&word);
158
/* don't do null searches */
159
if (search_string == NULL || search_string[0] == '\0')
161
update_navigation_controls (find_dialog, FALSE, FALSE);
162
g_free (search_string);
166
galeon_dialog_get_value (dialog, MATCH_CASE_PROP, &match_case);
167
b_match_case = g_value_get_boolean (&match_case);
168
g_value_unset (&match_case);
170
galeon_dialog_get_value (dialog, AUTOWRAP_PROP, &wrap);
171
b_wrap = g_value_get_boolean (&wrap);
172
g_value_unset (&wrap);
174
embed = galeon_embed_dialog_get_embed (GALEON_EMBED_DIALOG(dialog));
175
g_return_if_fail (embed != NULL);
177
galeon_embed_find_set_properties (embed, search_string,
178
b_match_case, b_wrap);
180
g_free (search_string);
184
sync_page_change (GaleonEmbed *embed, FindDialog *dialog)
186
g_return_if_fail (IS_GALEON_EMBED (embed));
187
g_return_if_fail (IS_FIND_DIALOG (dialog));
189
update_navigation_controls (dialog, TRUE, TRUE);
190
set_properties (dialog);
194
unset_old_embed (FindDialog *dialog)
196
if (dialog->priv->old_embed == NULL) return;
198
g_signal_handlers_disconnect_by_func (dialog->priv->old_embed,
199
G_CALLBACK (sync_page_change),
201
g_object_remove_weak_pointer (G_OBJECT (dialog->priv->old_embed),
202
(gpointer *)&dialog->priv->old_embed);
204
dialog->priv->old_embed = NULL;
208
sync_embed (FindDialog *dialog, GParamSpec *pspec, gpointer data)
212
unset_old_embed (dialog);
214
embed = galeon_embed_dialog_get_embed (GALEON_EMBED_DIALOG (dialog));
215
g_return_if_fail (IS_GALEON_EMBED (embed));
216
dialog->priv->old_embed = embed;
218
g_signal_connect (G_OBJECT (embed), "ge_location",
219
G_CALLBACK (sync_page_change), dialog);
221
g_object_add_weak_pointer (G_OBJECT (embed),
222
(gpointer *)&dialog->priv->old_embed);
224
update_navigation_controls (dialog, TRUE, TRUE);
225
set_properties (dialog);
229
find_dialog_init (FindDialog *dialog)
231
dialog->priv = g_new0 (FindDialogPrivate, 1);
233
dialog->priv->old_embed = NULL;
235
galeon_dialog_construct (GALEON_DIALOG(dialog),
240
g_signal_connect_object (dialog, "notify::GaleonEmbed",
241
G_CALLBACK (sync_embed), NULL, 0);
242
update_navigation_controls (dialog, TRUE, TRUE);
246
find_dialog_finalize (GObject *object)
250
g_return_if_fail (object != NULL);
251
g_return_if_fail (IS_FIND_DIALOG (object));
253
dialog = FIND_DIALOG (object);
255
g_signal_handlers_disconnect_by_func (dialog, G_CALLBACK (sync_embed), NULL);
256
unset_old_embed (FIND_DIALOG (dialog));
258
g_return_if_fail (dialog->priv != NULL);
260
g_free (dialog->priv);
262
G_OBJECT_CLASS (parent_class)->finalize (object);
266
find_dialog_new (GaleonEmbed *embed)
270
dialog = FIND_DIALOG (g_object_new (FIND_DIALOG_TYPE,
271
"GaleonEmbed", embed,
274
return GALEON_DIALOG(dialog);
278
find_dialog_new_with_parent (GtkWidget *window,
283
dialog = FIND_DIALOG (g_object_new (FIND_DIALOG_TYPE,
284
"GaleonEmbed", embed,
285
"ParentWindow", window,
288
return GALEON_DIALOG(dialog);
292
find_dialog_go_next (FindDialog *dialog)
297
g_return_if_fail (IS_FIND_DIALOG (dialog));
299
embed = galeon_embed_dialog_get_embed (GALEON_EMBED_DIALOG(dialog));
300
g_return_if_fail (embed != NULL);
302
set_properties (dialog);
303
result = galeon_embed_find_next (embed, FALSE);
307
update_navigation_controls (dialog, TRUE, TRUE);
311
update_navigation_controls (dialog, TRUE, FALSE);
316
find_dialog_go_prev (FindDialog *dialog)
321
g_return_if_fail (IS_FIND_DIALOG (dialog));
323
embed = galeon_embed_dialog_get_embed (GALEON_EMBED_DIALOG(dialog));
324
g_return_if_fail (embed != NULL);
326
set_properties (dialog);
327
result = galeon_embed_find_next (embed, TRUE);
331
update_navigation_controls (dialog, TRUE, TRUE);
335
update_navigation_controls (dialog, FALSE, TRUE);
340
find_close_button_clicked_cb (GtkWidget *button,
341
GaleonDialog *dialog)
343
galeon_dialog_destruct (GALEON_DIALOG (dialog));
344
g_object_unref (dialog);
348
find_key_press_event_cb (GtkWidget *widget, GdkEventKey *event, GaleonDialog *dialog)
350
if( event->keyval == GDK_Escape )
352
galeon_dialog_destruct (GALEON_DIALOG (dialog));
353
g_object_unref (dialog);
359
void find_next_button_clicked_cb (GtkWidget *button,
360
GaleonDialog *dialog)
362
find_dialog_go_next (FIND_DIALOG(dialog));
366
find_prev_button_clicked_cb (GtkWidget *button,
367
GaleonDialog *dialog)
369
find_dialog_go_prev (FIND_DIALOG(dialog));
373
find_entry_changed_cb (GtkWidget *editable,
374
GaleonDialog *dialog)
376
FindDialog *find_dialog = FIND_DIALOG(dialog);
377
update_navigation_controls (find_dialog, TRUE, TRUE);
381
find_check_toggled_cb (GtkWidget *toggle,
382
GaleonDialog *dialog)
384
FindDialog *find_dialog = FIND_DIALOG(dialog);
385
update_navigation_controls (find_dialog, TRUE, TRUE);