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

« back to all changes in this revision

Viewing changes to src/ppview-toolbar.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 Marco Pesenti Gritti
 
3
 *  Copyright (C) 2003 Philip Langdale (Egg port)
 
4
 *
 
5
 *  This program is free software; you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation; either version 2, or (at your option)
 
8
 *  any later version.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 */
 
19
 
 
20
 
 
21
#ifdef HAVE_CONFIG_H
 
22
#include <config.h>
 
23
#endif
 
24
 
 
25
#include "ppview-toolbar.h"
 
26
#include "galeon-window.h"
 
27
#include "gul-string.h"
 
28
#include "gul-gui.h"
 
29
#include "galeon-debug.h"
 
30
 
 
31
#include <string.h>
 
32
#include <glib/gi18n.h>
 
33
#include <gtk/gtkentry.h>
 
34
#include <gtk/gtkmenu.h>
 
35
#include <gtk/gtkaction.h>
 
36
#include <gtk/gtkactiongroup.h>
 
37
#include "egg-dock.h"
 
38
 
 
39
#define ACTION_ITEM(name) gtk_action_group_get_action(t->priv->action_group, name)
 
40
 
 
41
#define PPV_GOTO_FIRST_ACTION "PPVGotoFirstAction"
 
42
#define PPV_GOTO_LAST_ACTION "PPVGotoLastAction"
 
43
#define PPV_GO_BACK_ACTION "PPVGoBackAction"
 
44
#define PPV_GO_FORWARD_ACTION "PPVGoForwardAction"
 
45
#define PPV_PRINT_ACTION "PPVPrintAction"
 
46
 
 
47
 
 
48
static void ppview_toolbar_class_init(PPViewToolbarClass *klass);
 
49
static void ppview_toolbar_init(PPViewToolbar *t);
 
50
static void ppview_toolbar_finalize(GObject *object);
 
51
static void ppview_toolbar_set_window(PPViewToolbar *t, GaleonWindow *window);
 
52
static void
 
53
ppview_toolbar_set_property(GObject *object,
 
54
                            guint prop_id,
 
55
                            const GValue *value,
 
56
                            GParamSpec *pspec);
 
57
static void
 
58
ppview_toolbar_get_property(GObject *object,
 
59
                            guint prop_id,
 
60
                            GValue *value,
 
61
                            GParamSpec *pspec);
 
62
 
 
63
enum
 
64
{
 
65
        PROP_0,
 
66
        PROP_GALEON_WINDOW,
 
67
        PROP_DOCK_ITEM
 
68
};
 
69
 
 
70
enum
 
71
{
 
72
        PRINT,
 
73
        LAST_SIGNAL
 
74
};
 
75
 
 
76
static guint signals[LAST_SIGNAL] = { 0 };
 
77
 
 
78
static GObjectClass *parent_class = NULL;
 
79
 
 
80
struct PPViewToolbarPrivate
 
81
{
 
82
        GaleonWindow *window;
 
83
        EggDockItem *dock_item;
 
84
        GtkActionGroup *action_group;
 
85
        gboolean visibility;
 
86
        EmbedChromeMask old_chrome;
 
87
        int current_page;
 
88
        GaleonEmbed *embed;
 
89
};
 
90
 
 
91
static void 
 
92
toolbar_cmd_ppv_goto_first(GtkAction *action, 
 
93
                           PPViewToolbar *t);
 
94
 
 
95
static void 
 
96
toolbar_cmd_ppv_goto_last(GtkAction *action, 
 
97
                          PPViewToolbar *t);
 
98
 
 
99
static void 
 
100
toolbar_cmd_ppv_go_back(GtkAction *action, 
 
101
                        PPViewToolbar *t);
 
102
 
 
103
static void 
 
104
toolbar_cmd_ppv_go_forward(GtkAction *action,
 
105
                           PPViewToolbar *t);
 
106
 
 
107
static void 
 
108
toolbar_cmd_ppv_close(GtkAction *action,
 
109
                      PPViewToolbar *t);
 
110
 
 
111
static void 
 
112
toolbar_cmd_ppv_print(GtkAction *action,
 
113
                      PPViewToolbar *t);
 
114
 
 
115
static GtkActionEntry ppv_entries[] = {
 
116
        { "PPVGotoFirstAction", GTK_STOCK_GOTO_FIRST, N_("First"), NULL,
 
117
          N_("Go to the first page"), G_CALLBACK(toolbar_cmd_ppv_goto_first) },
 
118
        { "PPVGoBackAction", GTK_STOCK_GO_BACK, N_("Previous"), NULL,
 
119
          N_("Go to the previous page"), G_CALLBACK(toolbar_cmd_ppv_go_back) },
 
120
        { "PPVGoForwardAction", GTK_STOCK_GO_FORWARD, N_("Next"), NULL,
 
121
          N_("Go to the next page"), G_CALLBACK(toolbar_cmd_ppv_go_forward) },
 
122
        { "PPVGotoLastAction", GTK_STOCK_GOTO_LAST, N_("Last"), NULL,
 
123
          N_("Go to the last page"), G_CALLBACK(toolbar_cmd_ppv_goto_last) },
 
124
        { "PPVCloseAction", GTK_STOCK_CLOSE, N_("Close"), NULL,
 
125
          N_("Leave print preview mode"), G_CALLBACK(toolbar_cmd_ppv_close) },
 
126
        { "PPVPrintAction", GTK_STOCK_PRINT, N_("Print"), NULL,
 
127
          N_("Print the current page"), G_CALLBACK(toolbar_cmd_ppv_print) }
 
128
};
 
129
static guint n_ppv_entries = G_N_ELEMENTS(ppv_entries);
 
130
 
 
131
GType 
 
132
ppview_toolbar_get_type (void)
 
133
{
 
134
        static GType ppview_toolbar_type = 0;
 
135
 
 
136
        if (ppview_toolbar_type == 0)
 
137
        {
 
138
                static const GTypeInfo our_info =
 
139
                {
 
140
                        sizeof (PPViewToolbarClass),
 
141
                        NULL, /* base_init */
 
142
                        NULL, /* base_finalize */
 
143
                        (GClassInitFunc) ppview_toolbar_class_init,
 
144
                        NULL,
 
145
                        NULL, /* class_data */
 
146
                        sizeof (PPViewToolbar),
 
147
                        0, /* n_preallocs */
 
148
                        (GInstanceInitFunc) ppview_toolbar_init
 
149
                };
 
150
 
 
151
                ppview_toolbar_type = g_type_register_static (G_TYPE_OBJECT,
 
152
                                                       "PPViewToolbar",
 
153
                                                       &our_info, 0);
 
154
        }
 
155
 
 
156
        return ppview_toolbar_type;
 
157
 
 
158
}
 
159
 
 
160
static void
 
161
ppview_toolbar_class_init (PPViewToolbarClass *klass)
 
162
{
 
163
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
164
 
 
165
        parent_class = g_type_class_peek_parent (klass);
 
166
 
 
167
        object_class->finalize = ppview_toolbar_finalize;
 
168
 
 
169
        object_class->set_property = ppview_toolbar_set_property;
 
170
        object_class->get_property = ppview_toolbar_get_property;
 
171
 
 
172
        g_object_class_install_property (object_class,
 
173
                                         PROP_GALEON_WINDOW,
 
174
                                         g_param_spec_object ("GaleonWindow",
 
175
                                                              "GaleonWindow",
 
176
                                                              "Parent window",
 
177
                                                              GALEON_WINDOW_TYPE,
 
178
                                                              G_PARAM_READWRITE));
 
179
        g_object_class_install_property (object_class,
 
180
                                         PROP_DOCK_ITEM,
 
181
                                         g_param_spec_object ("EggDockItem",
 
182
                                                              "EggDockItem",
 
183
                                                              "Egg Dock item",
 
184
                                                              EGG_TYPE_DOCK_ITEM,
 
185
                                                              G_PARAM_READWRITE));
 
186
 
 
187
 
 
188
        signals[PRINT] =
 
189
                g_signal_new ("print",
 
190
                        G_OBJECT_CLASS_TYPE (klass),
 
191
                        G_SIGNAL_RUN_FIRST,
 
192
                        G_STRUCT_OFFSET (PPViewToolbarClass, print),
 
193
                        NULL, NULL,
 
194
                        g_cclosure_marshal_VOID__VOID,
 
195
                        G_TYPE_NONE,
 
196
                        0);
 
197
}
 
198
 
 
199
static void
 
200
ppview_toolbar_set_property (GObject *object,
 
201
                      guint prop_id,
 
202
                      const GValue *value,
 
203
                      GParamSpec *pspec)
 
204
{
 
205
        PPViewToolbar *t = PPVIEW_TOOLBAR (object);
 
206
 
 
207
        switch (prop_id)
 
208
        {
 
209
                case PROP_GALEON_WINDOW:
 
210
                        ppview_toolbar_set_window (t, g_value_get_object (value));
 
211
                        break;
 
212
                case PROP_DOCK_ITEM:
 
213
                        ppview_toolbar_set_dock_item (t, g_value_get_object (value));
 
214
                        break;
 
215
        }
 
216
}
 
217
 
 
218
static void
 
219
ppview_toolbar_get_property (GObject *object,
 
220
                      guint prop_id,
 
221
                      GValue *value,
 
222
                      GParamSpec *pspec)
 
223
{
 
224
        PPViewToolbar *t = PPVIEW_TOOLBAR (object);
 
225
 
 
226
        switch (prop_id)
 
227
        {
 
228
                case PROP_GALEON_WINDOW:
 
229
                        g_value_set_object (value, t->priv->window);
 
230
                        break;
 
231
                case PROP_DOCK_ITEM:
 
232
                        g_value_set_object (value, t->priv->dock_item);
 
233
                        break;
 
234
        }
 
235
}
 
236
 
 
237
void
 
238
ppview_toolbar_set_dock_item (PPViewToolbar *t, EggDockItem *item)
 
239
{
 
240
        t->priv->dock_item = item;
 
241
}
 
242
 
 
243
static void
 
244
ppview_toolbar_set_window (PPViewToolbar *t, GaleonWindow *window)
 
245
{
 
246
        g_return_if_fail (t->priv->window == NULL);
 
247
 
 
248
        LOG ("ppview_toolbar_set_window");
 
249
 
 
250
        t->priv->window = window;
 
251
 
 
252
        t->priv->action_group = gtk_action_group_new("PPVActions");
 
253
        gtk_action_group_set_translation_domain (t->priv->action_group, NULL);
 
254
 
 
255
        gtk_action_group_add_actions(t->priv->action_group, ppv_entries,
 
256
                                     n_ppv_entries, t);
 
257
 
 
258
        gtk_ui_manager_insert_action_group(window->merge,
 
259
                                           t->priv->action_group, 0);
 
260
}
 
261
 
 
262
static void
 
263
ppview_toolbar_init (PPViewToolbar *t)
 
264
{
 
265
        t->priv = g_new0 (PPViewToolbarPrivate, 1);
 
266
 
 
267
        t->priv->window = NULL;
 
268
        t->priv->dock_item = NULL;
 
269
        t->priv->visibility = TRUE;
 
270
        t->priv->action_group = NULL;
 
271
}
 
272
 
 
273
static void
 
274
ppview_toolbar_finalize (GObject *object)
 
275
{
 
276
        PPViewToolbar *t;
 
277
 
 
278
        g_return_if_fail (object != NULL);
 
279
        g_return_if_fail (IS_PPVIEW_TOOLBAR (object));
 
280
 
 
281
        t = PPVIEW_TOOLBAR (object);
 
282
 
 
283
        g_return_if_fail (t->priv != NULL);
 
284
 
 
285
        g_object_unref(t->priv->action_group);
 
286
 
 
287
        g_free (t->priv);
 
288
 
 
289
        G_OBJECT_CLASS (parent_class)->finalize (object);
 
290
}
 
291
 
 
292
PPViewToolbar *
 
293
ppview_toolbar_new (GaleonWindow *window)
 
294
{
 
295
        PPViewToolbar *t;
 
296
 
 
297
        t = PPVIEW_TOOLBAR (g_object_new (PPVIEW_TOOLBAR_TYPE, 
 
298
                                          "GaleonWindow", window,
 
299
                                          NULL));
 
300
 
 
301
        return t;
 
302
}
 
303
 
 
304
void
 
305
ppview_toolbar_set_old_chrome (PPViewToolbar *t, 
 
306
                               EmbedChromeMask chrome)
 
307
{
 
308
        t->priv->old_chrome = chrome;
 
309
}
 
310
 
 
311
static void
 
312
toolbar_update_sensitivity (PPViewToolbar *t)
 
313
{
 
314
        int pages = 0, c_page = 0;
 
315
        GaleonEmbed *embed = t->priv->embed;;
 
316
        
 
317
        if (embed)
 
318
        {
 
319
                galeon_embed_print_preview_num_pages (embed, &pages);
 
320
                c_page = t->priv->current_page;
 
321
        }
 
322
 
 
323
        g_object_set(G_OBJECT(ACTION_ITEM(PPV_GO_BACK_ACTION)),
 
324
                     "sensitive", c_page > 1, NULL);
 
325
        g_object_set(G_OBJECT(ACTION_ITEM(PPV_GOTO_FIRST_ACTION)),
 
326
                     "sensitive", c_page > 1, NULL);
 
327
        g_object_set(G_OBJECT(ACTION_ITEM(PPV_GO_FORWARD_ACTION)),
 
328
                     "sensitive", c_page < pages, NULL);
 
329
        g_object_set(G_OBJECT(ACTION_ITEM(PPV_GOTO_LAST_ACTION)),
 
330
                     "sensitive", c_page < pages, NULL);
 
331
}
 
332
 
 
333
static void
 
334
ppview_toolbar_close (PPViewToolbar *t)
 
335
{
 
336
        GaleonWindow *window = t->priv->window;
 
337
        GaleonEmbed *embed = t->priv->embed;
 
338
 
 
339
        g_return_if_fail (IS_GALEON_WINDOW (window));
 
340
        g_return_if_fail (IS_GALEON_EMBED (embed));
 
341
 
 
342
        /* This will call _set_visibility, and clear the embed */
 
343
        galeon_window_set_chrome (window, t->priv->old_chrome);
 
344
        
 
345
        galeon_embed_print_preview_close (embed);
 
346
 
 
347
        toolbar_update_sensitivity (t);
 
348
}
 
349
 
 
350
static gboolean
 
351
window_delete_event_cb (GaleonWindow *window, GdkEventAny *event, 
 
352
                        PPViewToolbar *t)
 
353
{
 
354
        g_return_val_if_fail (t->priv->visibility, FALSE);
 
355
 
 
356
        /* We need to do this in any case, due to:
 
357
         * http://bugzilla.mozilla.org/show_bug.cgi?id=241809 */
 
358
        ppview_toolbar_close (t);
 
359
 
 
360
        return TRUE;
 
361
}
 
362
 
 
363
void
 
364
ppview_toolbar_set_visibility (PPViewToolbar *t, gboolean visibility)
 
365
{
 
366
        if (visibility == t->priv->visibility) return;
 
367
        
 
368
        t->priv->visibility = visibility;
 
369
 
 
370
        g_return_if_fail (GTK_IS_WIDGET (t->priv->dock_item));
 
371
 
 
372
        if (visibility)
 
373
        {
 
374
                t->priv->current_page = 1;
 
375
                t->priv->embed = galeon_window_get_active_embed (t->priv->window);
 
376
 
 
377
                toolbar_update_sensitivity (t);
 
378
 
 
379
                g_signal_connect (t->priv->window, "delete-event",
 
380
                                  G_CALLBACK (window_delete_event_cb), t);
 
381
 
 
382
                gtk_widget_show(GTK_WIDGET(t->priv->dock_item));
 
383
        }
 
384
        else
 
385
        {
 
386
                t->priv->embed = NULL;
 
387
 
 
388
                g_signal_handlers_disconnect_matched (t->priv->window,
 
389
                         G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, t);
 
390
 
 
391
                gtk_widget_hide(GTK_WIDGET(t->priv->dock_item));
 
392
        }
 
393
 
 
394
}
 
395
 
 
396
static void 
 
397
toolbar_cmd_ppv_goto_first(GtkAction *action, 
 
398
                           PPViewToolbar *t)
 
399
{
 
400
        g_return_if_fail (IS_GALEON_EMBED (t->priv->embed));
 
401
 
 
402
        galeon_embed_print_preview_navigate (t->priv->embed,
 
403
                                             PRINTPREVIEW_HOME, 0);
 
404
 
 
405
        t->priv->current_page = 1;
 
406
 
 
407
        toolbar_update_sensitivity (t);
 
408
}
 
409
 
 
410
static void 
 
411
toolbar_cmd_ppv_goto_last(GtkAction *action, 
 
412
                          PPViewToolbar *t)
 
413
{
 
414
        g_return_if_fail (IS_GALEON_EMBED (t->priv->embed));
 
415
 
 
416
        galeon_embed_print_preview_navigate (t->priv->embed, 
 
417
                                             PRINTPREVIEW_END, 
 
418
                                             0);
 
419
 
 
420
        galeon_embed_print_preview_num_pages (t->priv->embed, 
 
421
                                              &t->priv->current_page);
 
422
 
 
423
        toolbar_update_sensitivity (t);
 
424
}
 
425
 
 
426
static void 
 
427
toolbar_cmd_ppv_go_back(GtkAction *action, 
 
428
                        PPViewToolbar *t)
 
429
{
 
430
        g_return_if_fail (IS_GALEON_EMBED (t->priv->embed));
 
431
 
 
432
        t->priv->current_page --;
 
433
 
 
434
        galeon_embed_print_preview_navigate (t->priv->embed, 
 
435
                                             PRINTPREVIEW_GOTO_PAGENUM,
 
436
                                             t->priv->current_page);
 
437
        toolbar_update_sensitivity (t);
 
438
}
 
439
 
 
440
static void 
 
441
toolbar_cmd_ppv_go_forward(GtkAction *action, 
 
442
                           PPViewToolbar *t)
 
443
{
 
444
        g_return_if_fail (IS_GALEON_EMBED (t->priv->embed));
 
445
        
 
446
        t->priv->current_page ++;
 
447
 
 
448
        galeon_embed_print_preview_navigate (t->priv->embed,
 
449
                                             PRINTPREVIEW_GOTO_PAGENUM,
 
450
                                             t->priv->current_page);
 
451
        toolbar_update_sensitivity (t);
 
452
}
 
453
 
 
454
static void 
 
455
toolbar_cmd_ppv_close(GtkAction *action, 
 
456
                      PPViewToolbar *t)
 
457
{
 
458
        ppview_toolbar_close (t);
 
459
}
 
460
 
 
461
static void 
 
462
toolbar_cmd_ppv_print(GtkAction *action,
 
463
                      PPViewToolbar *t)
 
464
{
 
465
        ppview_toolbar_close (t);
 
466
 
 
467
        g_signal_emit (G_OBJECT (t), signals[PRINT], 0);
 
468
}