~ubuntu-branches/debian/squeeze/galeon/squeeze

« back to all changes in this revision

Viewing changes to embed/find-dialog.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Howard
  • Date: 2004-06-06 09:02:01 UTC
  • Revision ID: james.westby@ubuntu.com-20040606090201-yhx6ruhq8um7ggs2
Tags: upstream-1.3.15
ImportĀ upstreamĀ versionĀ 1.3.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2002 Jorn Baayen
 
3
 *
 
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)
 
7
 *  any later version.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 */
 
18
 
 
19
#ifdef HAVE_CONFIG_H
 
20
#include <config.h>
 
21
#endif
 
22
 
 
23
#include "find-dialog.h"
 
24
#include "prefs-strings.h"
 
25
#include "galeon-embed.h"
 
26
#include <gdk/gdkkeysyms.h>
 
27
 
 
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"
 
31
 
 
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);
 
36
 
 
37
 
 
38
/* Glade callbacks */
 
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);
 
46
 
 
47
static GObjectClass *parent_class = NULL;
 
48
 
 
49
struct FindDialogPrivate
 
50
{
 
51
        GaleonEmbed *old_embed;
 
52
};
 
53
 
 
54
enum
 
55
{
 
56
        MATCH_CASE_PROP,
 
57
        AUTOWRAP_PROP,
 
58
        WORD_PROP,
 
59
        BACK_BUTTON,
 
60
        FORWARD_BUTTON
 
61
};
 
62
 
 
63
static const
 
64
GaleonDialogProperty properties [] =
 
65
{
 
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 },
 
71
        { -1, NULL, NULL }
 
72
};
 
73
 
 
74
GType 
 
75
find_dialog_get_type (void)
 
76
{
 
77
        static GType find_dialog_type = 0;
 
78
 
 
79
        if (find_dialog_type == 0)
 
80
        {
 
81
                static const GTypeInfo our_info =
 
82
                {
 
83
                        sizeof (FindDialogClass),
 
84
                        NULL, /* base_init */
 
85
                        NULL, /* base_finalize */
 
86
                        (GClassInitFunc) find_dialog_class_init,
 
87
                        NULL,
 
88
                        NULL, /* class_data */
 
89
                        sizeof (FindDialog),
 
90
                        0, /* n_preallocs */
 
91
                        (GInstanceInitFunc) find_dialog_init
 
92
                };
 
93
 
 
94
                find_dialog_type = g_type_register_static (GALEON_EMBED_DIALOG_TYPE,
 
95
                                                           "FindDialog",
 
96
                                                           &our_info, 0);
 
97
        }
 
98
 
 
99
        return find_dialog_type;
 
100
 
 
101
}
 
102
 
 
103
static void
 
104
impl_show (GaleonDialog *dialog)
 
105
{
 
106
        GALEON_DIALOG_CLASS (parent_class)->show (dialog);
 
107
 
 
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.
 
111
         */
 
112
        gtk_widget_grab_focus (galeon_dialog_get_control (dialog, WORD_PROP));
 
113
}
 
114
 
 
115
static void
 
116
find_dialog_class_init (FindDialogClass *klass)
 
117
{
 
118
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
119
        GaleonDialogClass *galeon_dialog_class;
 
120
        
 
121
        parent_class = g_type_class_peek_parent (klass);
 
122
        galeon_dialog_class = GALEON_DIALOG_CLASS (klass);
 
123
        
 
124
        object_class->finalize = find_dialog_finalize;
 
125
 
 
126
        galeon_dialog_class->show = impl_show;
 
127
}
 
128
 
 
129
static void
 
130
update_navigation_controls (FindDialog *dialog, gboolean prev, gboolean next)
 
131
{
 
132
        GtkWidget *button;
 
133
 
 
134
        button = galeon_dialog_get_control (GALEON_DIALOG (dialog), BACK_BUTTON);
 
135
        gtk_widget_set_sensitive (button, prev);
 
136
 
 
137
        button = galeon_dialog_get_control (GALEON_DIALOG (dialog), FORWARD_BUTTON);
 
138
        gtk_widget_set_sensitive (button, next);
 
139
}
 
140
 
 
141
static void
 
142
set_properties (FindDialog *find_dialog)
 
143
{
 
144
        char *search_string;
 
145
        GValue word = {0, };
 
146
        GValue match_case = {0, };
 
147
        GValue wrap = {0, };
 
148
        GaleonDialog *dialog = GALEON_DIALOG (find_dialog);
 
149
        gboolean b_match_case;
 
150
        gboolean b_wrap;
 
151
        GaleonEmbed *embed;
 
152
 
 
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);
 
157
                
 
158
        /* don't do null searches */
 
159
        if (search_string == NULL || search_string[0] == '\0')
 
160
        {
 
161
                update_navigation_controls (find_dialog, FALSE, FALSE);
 
162
                g_free (search_string);
 
163
                return;
 
164
        }
 
165
 
 
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);
 
169
 
 
170
        galeon_dialog_get_value (dialog, AUTOWRAP_PROP, &wrap);
 
171
        b_wrap = g_value_get_boolean (&wrap);
 
172
        g_value_unset (&wrap);
 
173
 
 
174
        embed = galeon_embed_dialog_get_embed (GALEON_EMBED_DIALOG(dialog));
 
175
        g_return_if_fail (embed != NULL);
 
176
 
 
177
        galeon_embed_find_set_properties (embed, search_string,
 
178
                                        b_match_case, b_wrap);
 
179
 
 
180
        g_free (search_string);
 
181
}
 
182
 
 
183
static void
 
184
sync_page_change (GaleonEmbed *embed, FindDialog *dialog)
 
185
{
 
186
        g_return_if_fail (IS_GALEON_EMBED (embed));
 
187
        g_return_if_fail (IS_FIND_DIALOG (dialog));
 
188
 
 
189
        update_navigation_controls (dialog, TRUE, TRUE);
 
190
        set_properties (dialog);
 
191
}
 
192
 
 
193
static void
 
194
unset_old_embed (FindDialog *dialog)
 
195
{
 
196
        if (dialog->priv->old_embed == NULL) return;
 
197
 
 
198
        g_signal_handlers_disconnect_by_func (dialog->priv->old_embed,
 
199
                                              G_CALLBACK (sync_page_change),
 
200
                                              dialog);
 
201
        g_object_remove_weak_pointer (G_OBJECT (dialog->priv->old_embed),
 
202
                                      (gpointer *)&dialog->priv->old_embed);
 
203
        
 
204
        dialog->priv->old_embed = NULL;
 
205
}
 
206
 
 
207
static void
 
208
sync_embed (FindDialog *dialog, GParamSpec *pspec, gpointer data)
 
209
{
 
210
        GaleonEmbed *embed;
 
211
 
 
212
        unset_old_embed (dialog);
 
213
 
 
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;
 
217
 
 
218
        g_signal_connect (G_OBJECT (embed), "ge_location",
 
219
                          G_CALLBACK (sync_page_change), dialog);
 
220
 
 
221
        g_object_add_weak_pointer (G_OBJECT (embed),
 
222
                                   (gpointer *)&dialog->priv->old_embed);
 
223
 
 
224
        update_navigation_controls (dialog, TRUE, TRUE);
 
225
        set_properties (dialog);
 
226
}
 
227
 
 
228
static void
 
229
find_dialog_init (FindDialog *dialog)
 
230
{       
 
231
        dialog->priv = g_new0 (FindDialogPrivate, 1);
 
232
 
 
233
        dialog->priv->old_embed = NULL;
 
234
 
 
235
        galeon_dialog_construct (GALEON_DIALOG(dialog),
 
236
                                 properties,
 
237
                                 "galeon.glade", 
 
238
                                 "find_dialog");
 
239
 
 
240
        g_signal_connect_object (dialog, "notify::GaleonEmbed",
 
241
                                 G_CALLBACK (sync_embed), NULL, 0);
 
242
        update_navigation_controls (dialog, TRUE, TRUE);
 
243
}
 
244
 
 
245
static void
 
246
find_dialog_finalize (GObject *object)
 
247
{
 
248
        FindDialog *dialog;
 
249
 
 
250
        g_return_if_fail (object != NULL);
 
251
        g_return_if_fail (IS_FIND_DIALOG (object));
 
252
 
 
253
        dialog = FIND_DIALOG (object);
 
254
 
 
255
        g_signal_handlers_disconnect_by_func (dialog, G_CALLBACK (sync_embed), NULL);
 
256
        unset_old_embed (FIND_DIALOG (dialog));
 
257
 
 
258
        g_return_if_fail (dialog->priv != NULL);
 
259
 
 
260
        g_free (dialog->priv);
 
261
 
 
262
        G_OBJECT_CLASS (parent_class)->finalize (object);
 
263
}
 
264
 
 
265
GaleonDialog *
 
266
find_dialog_new (GaleonEmbed *embed)
 
267
{
 
268
        FindDialog *dialog;
 
269
        
 
270
        dialog = FIND_DIALOG (g_object_new (FIND_DIALOG_TYPE, 
 
271
                                     "GaleonEmbed", embed,
 
272
                                     NULL));
 
273
 
 
274
        return GALEON_DIALOG(dialog);
 
275
}
 
276
 
 
277
GaleonDialog *
 
278
find_dialog_new_with_parent (GtkWidget *window,
 
279
                             GaleonEmbed *embed)
 
280
{
 
281
        FindDialog *dialog;
 
282
        
 
283
        dialog = FIND_DIALOG (g_object_new (FIND_DIALOG_TYPE, 
 
284
                                     "GaleonEmbed", embed,
 
285
                                     "ParentWindow", window, 
 
286
                                     NULL));
 
287
 
 
288
        return GALEON_DIALOG(dialog);
 
289
}
 
290
 
 
291
static void
 
292
find_dialog_go_next (FindDialog *dialog)
 
293
{
 
294
        gresult result;
 
295
        GaleonEmbed *embed;
 
296
 
 
297
        g_return_if_fail (IS_FIND_DIALOG (dialog));
 
298
 
 
299
        embed = galeon_embed_dialog_get_embed (GALEON_EMBED_DIALOG(dialog));
 
300
        g_return_if_fail (embed != NULL);
 
301
 
 
302
        set_properties (dialog);
 
303
        result = galeon_embed_find_next (embed, FALSE);
 
304
 
 
305
        if (result == G_OK)
 
306
        {
 
307
                update_navigation_controls (dialog, TRUE, TRUE);
 
308
        }
 
309
        else
 
310
        {
 
311
                update_navigation_controls (dialog, TRUE, FALSE);
 
312
        }
 
313
}
 
314
 
 
315
static void
 
316
find_dialog_go_prev (FindDialog *dialog)
 
317
{
 
318
        gresult result;
 
319
        GaleonEmbed *embed;
 
320
 
 
321
        g_return_if_fail (IS_FIND_DIALOG (dialog));
 
322
 
 
323
        embed = galeon_embed_dialog_get_embed (GALEON_EMBED_DIALOG(dialog));
 
324
        g_return_if_fail (embed != NULL);
 
325
 
 
326
        set_properties (dialog);
 
327
        result = galeon_embed_find_next (embed, TRUE);
 
328
 
 
329
        if (result == G_OK)
 
330
        {
 
331
                update_navigation_controls (dialog, TRUE, TRUE);
 
332
        }
 
333
        else
 
334
        {
 
335
                update_navigation_controls (dialog, FALSE, TRUE);
 
336
        }
 
337
}
 
338
 
 
339
void
 
340
find_close_button_clicked_cb (GtkWidget *button, 
 
341
                              GaleonDialog *dialog) 
 
342
{
 
343
        galeon_dialog_destruct (GALEON_DIALOG (dialog));
 
344
        g_object_unref (dialog);
 
345
}
 
346
 
 
347
gboolean
 
348
find_key_press_event_cb (GtkWidget *widget, GdkEventKey *event, GaleonDialog *dialog)
 
349
{
 
350
        if( event->keyval == GDK_Escape )
 
351
        {
 
352
                galeon_dialog_destruct (GALEON_DIALOG (dialog));
 
353
                g_object_unref (dialog);
 
354
                return TRUE;
 
355
        }
 
356
        return FALSE;
 
357
}
 
358
 
 
359
void find_next_button_clicked_cb (GtkWidget *button, 
 
360
                                  GaleonDialog *dialog)
 
361
{
 
362
        find_dialog_go_next (FIND_DIALOG(dialog));
 
363
}
 
364
 
 
365
void
 
366
find_prev_button_clicked_cb (GtkWidget *button, 
 
367
                             GaleonDialog *dialog)
 
368
{
 
369
        find_dialog_go_prev (FIND_DIALOG(dialog));
 
370
}
 
371
 
 
372
void
 
373
find_entry_changed_cb  (GtkWidget *editable, 
 
374
                        GaleonDialog *dialog)
 
375
{
 
376
        FindDialog *find_dialog = FIND_DIALOG(dialog);
 
377
        update_navigation_controls (find_dialog, TRUE, TRUE);
 
378
}
 
379
 
 
380
void 
 
381
find_check_toggled_cb (GtkWidget *toggle,
 
382
                       GaleonDialog *dialog)
 
383
{
 
384
        FindDialog *find_dialog = FIND_DIALOG(dialog);
 
385
        update_navigation_controls (find_dialog, TRUE, TRUE);
 
386
}