]> www.fi.muni.cz Git - evince.git/blob - shell/ev-window.c
fb3570a65dd5e18835e5a46a100b1a306f88536d
[evince.git] / shell / ev-window.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* this file is part of evince, a gnome document viewer
3  *
4  *  Copyright (C) 2004 Martin Kretzschmar
5  *  Copyright (C) 2004 Red Hat, Inc.
6  *  Copyright (C) 2000, 2001, 2002, 2003, 2004 Marco Pesenti Gritti
7  *  Copyright (C) 2003, 2004 Christian Persch
8  *
9  *  Author:
10  *    Martin Kretzschmar <martink@gnome.org>
11  *
12  * Evince is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * Evince is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include "ev-window.h"
32 #include "ev-sidebar.h"
33 #include "ev-sidebar-bookmarks.h"
34 #include "ev-sidebar-thumbnails.h"
35 #include "ev-view.h"
36 #include "eggfindbar.h"
37
38 #include "pdf-document.h"
39
40 #include <glib/gi18n.h>
41 #include <gtk/gtk.h>
42 #include <libgnomevfs/gnome-vfs-mime-utils.h>
43
44 #include <string.h>
45
46 #include "ev-application.h"
47 #include "ev-stock-icons.h"
48
49 enum {
50         PROP_0,
51         PROP_ATTRIBUTE
52 };
53
54 enum {
55         SIGNAL,
56         N_SIGNALS
57 };
58
59 struct _EvWindowPrivate {
60         GtkWidget *main_box;
61         GtkWidget *hpaned;
62         GtkWidget *sidebar;
63         GtkWidget *find_bar;
64         GtkWidget *view;
65         GtkActionGroup *action_group;
66         GtkUIManager *ui_manager;
67         GtkWidget *statusbar;
68         guint help_message_cid;
69         GtkWidget *exit_fullscreen_popup;
70
71         EvDocument *document;
72
73         gboolean fullscreen_mode;
74 };
75
76 #if 0
77 /* enable these to add support for signals */
78 static guint ev_window_signals [N_SIGNALS] = { 0 };
79 #endif
80
81 static GObjectClass *parent_class = NULL;
82
83 G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
84
85 #define EV_WINDOW_GET_PRIVATE(object) \
86         (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_WINDOW, EvWindowPrivate))
87
88 #if 0
89 const char *
90 ev_window_get_attribute (EvWindow *self)
91 {
92         g_return_val_if_fail (self != NULL && EV_IS_WINDOW (self), NULL);
93         
94         return self->priv->attribute;
95 }
96
97 void
98 ev_window_set_attribute (EvWindow* self, const char *attribute)
99 {
100         g_assert (self != NULL && EV_IS_WINDOW (self));
101         g_assert (attribute != NULL);
102
103         if (self->priv->attribute != NULL) {
104                 g_free (self->priv->attribute);
105         }
106
107         self->priv->attribute = g_strdup (attribute);
108
109         g_object_notify (G_OBJECT (self), "attribute");
110 }
111
112 static void
113 ev_window_get_property (GObject *object, guint prop_id, GValue *value,
114                         GParamSpec *param_spec)
115 {
116         EvWindow *self;
117
118         self = EV_WINDOW (object);
119
120         switch (prop_id) {
121         case PROP_ATTRIBUTE:
122                 g_value_set_string (value, self->priv->attribute);
123                 break;
124         default:
125                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
126                                                    prop_id,
127                                                    param_spec);
128                 break;
129         }
130 }
131
132 static void
133 ev_window_set_property (GObject *object, guint prop_id, const GValue *value,
134                         GParamSpec *param_spec)
135 {
136         EvWindow *self;
137         
138         self = EV_WINDOW (object);
139         
140         switch (prop_id) {
141         case PROP_ATTRIBUTE:
142                 ev_window_set_attribute (self, g_value_get_string (value));
143                 break;
144         default:
145                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
146                                                    prop_id,
147                                                    param_spec);
148                 break;
149         }
150 }
151 #endif
152
153 static void
154 set_action_sensitive (EvWindow   *ev_window,
155                       const char *name,
156                       gboolean    sensitive)
157 {
158         GtkAction *action = gtk_action_group_get_action (ev_window->priv->action_group,
159                                                          name);
160         gtk_action_set_sensitive (action, sensitive);
161 }
162
163 static void
164 update_action_sensitivity (EvWindow *ev_window)
165 {
166         int n_pages;
167         int page;
168
169         if (ev_window->priv->document)
170                 n_pages = ev_document_get_n_pages (ev_window->priv->document);
171         else
172                 n_pages = 1;
173
174         page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
175
176         set_action_sensitive (ev_window, "GoFirstPage", page > 1);
177         set_action_sensitive (ev_window, "GoPreviousPage", page > 1);
178         set_action_sensitive (ev_window, "GoNextPage", page < n_pages);
179         set_action_sensitive (ev_window, "GoLastPage", page < n_pages);
180 }
181
182 gboolean
183 ev_window_is_empty (const EvWindow *ev_window)
184 {
185         g_return_val_if_fail (EV_IS_WINDOW (ev_window), FALSE);
186         
187         return ev_window->priv->document == NULL;
188 }
189
190 static void
191 unable_to_load (EvWindow   *ev_window,
192                 const char *error_message)
193 {
194         GtkWidget *dialog;
195
196         dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
197                                          GTK_DIALOG_DESTROY_WITH_PARENT,
198                                          GTK_MESSAGE_ERROR,
199                                          GTK_BUTTONS_CLOSE,
200                                          _("Unable to open document"));
201         gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
202                                                   "%s", error_message);
203         gtk_dialog_run (GTK_DIALOG (dialog));
204         gtk_widget_destroy (dialog);
205 }
206
207 void
208 ev_window_open (EvWindow *ev_window, const char *uri)
209 {
210         EvDocument *document = NULL;
211         char *mime_type;
212
213         mime_type = gnome_vfs_get_mime_type (uri);
214
215         if (!strcmp (mime_type, "application/pdf"))
216                 document = g_object_new (PDF_TYPE_DOCUMENT, NULL);
217
218         if (document) {
219                 GError *error = NULL;
220
221                 if (ev_document_load (document, uri, &error)) {
222                         if (ev_window->priv->document)
223                                 g_object_unref (ev_window->priv->document);
224                         ev_window->priv->document = document;
225
226                         ev_view_set_document (EV_VIEW (ev_window->priv->view),
227                                               document);
228
229                         update_action_sensitivity (ev_window);
230                 
231                 } else {
232                         g_assert (error != NULL);
233                         g_object_unref (document);
234                         unable_to_load (ev_window, error->message);
235                         g_error_free (error);
236                 }
237         } else {
238                 char *error_message;
239
240                 error_message = g_strdup_printf (_("Unhandled MIME type: '%s'"),
241                                                  mime_type);
242                 unable_to_load (ev_window, error_message);
243                 g_free (error_message);
244         }
245
246         g_free (mime_type);
247 }
248
249 static void
250 ev_window_cmd_file_open (GtkAction *action, EvWindow *ev_window)
251 {
252         ev_application_open (EV_APP, NULL);
253 }
254
255 static void
256 ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
257 {
258         g_return_if_fail (EV_IS_WINDOW (ev_window));
259         /* FIXME */
260 }
261
262 static void
263 ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
264 {
265         g_return_if_fail (EV_IS_WINDOW (ev_window));
266
267         gtk_widget_destroy (GTK_WIDGET (ev_window));
268 }
269
270 static void
271 ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window)
272 {
273         g_return_if_fail (EV_IS_WINDOW (ev_window));
274
275         gtk_widget_show (ev_window->priv->find_bar);
276         egg_find_bar_grab_focus (EGG_FIND_BAR (ev_window->priv->find_bar));
277 }
278
279 static void
280 ev_window_cmd_edit_copy (GtkAction *action, EvWindow *ev_window)
281 {
282         g_return_if_fail (EV_IS_WINDOW (ev_window));
283
284         /* FIXME */
285 }
286
287 static void
288 update_fullscreen_popup (EvWindow *window)
289 {
290         GtkWidget *popup = window->priv->exit_fullscreen_popup;
291         int popup_width, popup_height;
292         GdkRectangle screen_rect;
293
294         g_return_if_fail (popup != NULL);
295
296         popup_width = popup->requisition.width;
297         popup_height = popup->requisition.height;
298
299         /* FIXME multihead */
300         gdk_screen_get_monitor_geometry (gdk_screen_get_default (),
301                         gdk_screen_get_monitor_at_window
302                         (gdk_screen_get_default (),
303                          GTK_WIDGET (window)->window),
304                          &screen_rect);
305
306         if (gtk_widget_get_direction (popup) == GTK_TEXT_DIR_RTL)
307         {
308                 gtk_window_move (GTK_WINDOW (popup),
309                                  screen_rect.x + screen_rect.width - popup_width,
310                                  screen_rect.height - popup_height);
311         }
312         else
313         {
314                 gtk_window_move (GTK_WINDOW (popup),
315                                 screen_rect.x, screen_rect.height - popup_height);
316         }
317 }
318
319 static void
320 screen_size_changed_cb (GdkScreen *screen,
321                         EvWindow *window)
322 {
323         update_fullscreen_popup (window);
324 }
325
326 static void
327 destroy_exit_fullscreen_popup (EvWindow *window)
328 {
329         if (window->priv->exit_fullscreen_popup != NULL)
330         {
331                 /* FIXME multihead */
332                 g_signal_handlers_disconnect_by_func
333                         (gdk_screen_get_default (),
334                          G_CALLBACK (screen_size_changed_cb), window);
335
336                 gtk_widget_destroy (window->priv->exit_fullscreen_popup);
337                 window->priv->exit_fullscreen_popup = NULL;
338         }
339 }
340
341 static void
342 exit_fullscreen_button_clicked_cb (GtkWidget *button, EvWindow *window)
343 {
344         GtkAction *action;
345
346         action = gtk_action_group_get_action (window->priv->action_group, "ViewFullscreen");
347         g_return_if_fail (action != NULL);
348
349         gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), FALSE);
350 }
351
352 static void
353 fullscreen_popup_size_request_cb (GtkWidget *popup, GtkRequisition *req, EvWindow *window)
354 {
355         update_fullscreen_popup (window);
356 }
357
358 static void
359 ev_window_fullscreen (EvWindow *window)
360 {
361         GtkWidget *popup, *button, *icon, *label, *hbox;
362
363         window->priv->fullscreen_mode = TRUE;
364
365         popup = gtk_window_new (GTK_WINDOW_POPUP);
366         window->priv->exit_fullscreen_popup = popup;
367
368         button = gtk_button_new ();
369         g_signal_connect (button, "clicked",
370                           G_CALLBACK (exit_fullscreen_button_clicked_cb),
371                           window);
372         gtk_widget_show (button);
373         gtk_container_add (GTK_CONTAINER (popup), button);
374
375         hbox = gtk_hbox_new (FALSE, 2);
376         gtk_widget_show (hbox);
377         gtk_container_add (GTK_CONTAINER (button), hbox);
378
379         icon = gtk_image_new_from_stock (GTK_STOCK_QUIT, GTK_ICON_SIZE_BUTTON);
380         gtk_widget_show (icon);
381         gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
382
383         label = gtk_label_new (_("Exit Fullscreen"));
384         gtk_widget_show (label);
385         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
386
387         gtk_window_set_resizable (GTK_WINDOW (popup), FALSE);
388
389         /* FIXME multihead */
390         g_signal_connect (gdk_screen_get_default (), "size-changed",
391                           G_CALLBACK (screen_size_changed_cb), window);
392         g_signal_connect (popup, "size_request",
393                           G_CALLBACK (fullscreen_popup_size_request_cb), window);
394
395         update_fullscreen_popup (window);
396
397         gtk_widget_show (popup);
398 }
399
400 static void
401 ev_window_unfullscreen (EvWindow *window)
402 {
403         window->priv->fullscreen_mode = FALSE;
404
405         destroy_exit_fullscreen_popup (window);
406 }
407  
408 static void
409 ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *ev_window)
410 {
411         gboolean fullscreen;
412         
413         g_return_if_fail (EV_IS_WINDOW (ev_window));
414
415         fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
416
417         if (fullscreen) {
418                 gtk_window_fullscreen (GTK_WINDOW (ev_window));
419         } else {
420                 gtk_window_unfullscreen (GTK_WINDOW (ev_window));
421         }
422 }
423
424 static gboolean
425 ev_window_state_event_cb (GtkWidget *widget, GdkEventWindowState *event, EvWindow *window)
426 {
427         if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
428         {
429                 GtkActionGroup *action_group;
430                 GtkAction *action;
431                 GtkWidget *main_menu;
432                 gboolean fullscreen;
433
434                 fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
435
436                 if (fullscreen)
437                 {
438                         ev_window_fullscreen (window);
439                 }
440                 else
441                 {
442                         ev_window_unfullscreen (window);
443                 }
444
445                 action_group = window->priv->action_group;
446
447                 action = gtk_action_group_get_action (action_group, "ViewFullscreen");
448                 g_signal_handlers_block_by_func
449                         (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
450                 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), fullscreen);
451                 g_signal_handlers_unblock_by_func
452                         (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
453
454                 main_menu = gtk_ui_manager_get_widget (window->priv->ui_manager, "/MainMenu");
455                 g_object_set (main_menu, "visible", !fullscreen, NULL);
456         }
457
458         return FALSE;
459 }
460
461 static void
462 ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window)
463 {
464         g_return_if_fail (EV_IS_WINDOW (ev_window));
465
466         ev_view_zoom_in (EV_VIEW (ev_window->priv->view));
467 }
468
469 static void
470 ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window)
471 {
472         g_return_if_fail (EV_IS_WINDOW (ev_window));
473
474         ev_view_zoom_out (EV_VIEW (ev_window->priv->view));
475 }
476
477 static void
478 ev_window_cmd_view_normal_size (GtkAction *action, EvWindow *ev_window)
479 {
480         g_return_if_fail (EV_IS_WINDOW (ev_window));
481
482         ev_view_normal_size (EV_VIEW (ev_window->priv->view));
483 }
484
485 static void
486 ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
487 {
488         g_return_if_fail (EV_IS_WINDOW (ev_window));
489
490         ev_view_best_fit (EV_VIEW (ev_window->priv->view));
491 }
492
493 static void
494 ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
495 {
496         g_return_if_fail (EV_IS_WINDOW (ev_window));
497
498         ev_view_fit_width (EV_VIEW (ev_window->priv->view));
499 }
500
501 static void
502 ev_window_cmd_go_back (GtkAction *action, EvWindow *ev_window)
503 {
504         g_return_if_fail (EV_IS_WINDOW (ev_window));
505
506         /* FIXME */
507 }
508
509 static void
510 ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window)
511 {
512         g_return_if_fail (EV_IS_WINDOW (ev_window));
513
514         /* FIXME */
515 }
516
517 static void
518 ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
519 {
520         g_return_if_fail (EV_IS_WINDOW (ev_window));
521
522         ev_view_set_page (EV_VIEW (ev_window->priv->view),
523                           ev_view_get_page (EV_VIEW (ev_window->priv->view)) - 1);
524 }
525
526 static void
527 ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
528 {
529         g_return_if_fail (EV_IS_WINDOW (ev_window));
530
531         ev_view_set_page (EV_VIEW (ev_window->priv->view),
532                           ev_view_get_page (EV_VIEW (ev_window->priv->view)) + 1);
533 }
534
535 static void
536 ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
537 {
538         g_return_if_fail (EV_IS_WINDOW (ev_window));
539
540         ev_view_set_page (EV_VIEW (ev_window->priv->view), 1);
541 }
542
543 static void
544 ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
545 {
546         g_return_if_fail (EV_IS_WINDOW (ev_window));
547
548         ev_view_set_page (EV_VIEW (ev_window->priv->view), G_MAXINT);
549 }
550
551 static void
552 ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
553 {
554         g_return_if_fail (EV_IS_WINDOW (ev_window));
555
556         /* FIXME */
557 }
558
559 static void
560 ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
561 {
562         const char *authors[] = {
563                 N_("Many..."),
564                 NULL
565         };
566
567         const char *documenters[] = {
568                 N_("Not so many..."),
569                 NULL
570         };
571
572         const char *license[] = {
573                 N_("Evince is free software; you can redistribute it and/or modify\n"
574                    "it under the terms of the GNU General Public License as published by\n"
575                    "the Free Software Foundation; either version 2 of the License, or\n"
576                    "(at your option) any later version.\n"),            
577                 N_("Evince is distributed in the hope that it will be useful,\n"
578                    "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
579                    "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
580                    "GNU General Public License for more details.\n"),
581                 N_("You should have received a copy of the GNU General Public License\n"
582                    "along with Evince; if not, write to the Free Software Foundation, Inc.,\n"
583                    "59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n")
584         };
585
586         char *license_trans;
587
588 #ifdef ENABLE_NLS
589         const char **p;
590
591         for (p = authors; *p; ++p)
592                 *p = _(*p);
593
594         for (p = documenters; *p; ++p)
595                 *p = _(*p);
596 #endif
597
598         license_trans = g_strconcat (_(license[0]), "\n", _(license[1]), "\n",
599                                      _(license[2]), "\n", NULL);
600
601         gtk_show_about_dialog (
602                 GTK_WINDOW (ev_window),
603                 "name", _("Evince"),
604                 "version", VERSION,
605                 "copyright",
606                 _("\xc2\xa9 1996-2004 The Evince authors"),
607                 "license", license_trans,
608                 "website", "http://www.gnome.org/projects/evince",
609                 "comments", _("PostScript and PDF File Viewer."),
610                 "authors", authors,
611                 "documenters", documenters,
612                 "translator-credits", _("translator-credits"),
613                 NULL);
614
615         g_free (license_trans);
616 }
617
618 static void
619 ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window)
620 {
621         g_object_set (
622                 G_OBJECT (gtk_ui_manager_get_widget (
623                                   ev_window->priv->ui_manager,
624                                   "/ToolBar")),
625                 "visible",
626                 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
627                 NULL);
628 }
629
630 static void
631 ev_window_view_statusbar_cb (GtkAction *action, EvWindow *ev_window)
632 {
633         g_object_set (
634                 ev_window->priv->statusbar,
635                 "visible",
636                 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
637                 NULL);
638 }
639
640 static void
641 ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window)
642 {
643         /* FIXME */
644 }
645
646 static void
647 menu_item_select_cb (GtkMenuItem *proxy, EvWindow *ev_window)
648 {
649         GtkAction *action;
650         char *message;
651
652         action = g_object_get_data (G_OBJECT (proxy), "gtk-action");
653         g_return_if_fail (action != NULL);
654         
655         g_object_get (G_OBJECT (action), "tooltip", &message, NULL);
656         if (message) {
657                 gtk_statusbar_push (GTK_STATUSBAR (ev_window->priv->statusbar),
658                                     ev_window->priv->help_message_cid, message);
659                 g_free (message);
660         }
661 }
662
663 static void
664 menu_item_deselect_cb (GtkMenuItem *proxy, EvWindow *ev_window)
665 {
666         gtk_statusbar_pop (GTK_STATUSBAR (ev_window->priv->statusbar),
667                            ev_window->priv->help_message_cid);
668 }
669
670 static void
671 connect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
672                   GtkWidget *proxy, EvWindow *ev_window)
673 {
674         if (GTK_IS_MENU_ITEM (proxy)) {
675                 g_signal_connect (proxy, "select",
676                                   G_CALLBACK (menu_item_select_cb), ev_window);
677                 g_signal_connect (proxy, "deselect",
678                                   G_CALLBACK (menu_item_deselect_cb),
679                                   ev_window);
680         }
681 }
682
683 static void
684 disconnect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
685                      GtkWidget *proxy, EvWindow *ev_window)
686 {
687         if (GTK_IS_MENU_ITEM (proxy)) {
688                 g_signal_handlers_disconnect_by_func
689                         (proxy, G_CALLBACK (menu_item_select_cb), ev_window);
690                 g_signal_handlers_disconnect_by_func
691                         (proxy, G_CALLBACK (menu_item_deselect_cb), ev_window);
692         }
693 }
694
695 static void
696 view_page_changed_cb (EvView   *view,
697                       EvWindow *ev_window)
698 {
699         update_action_sensitivity (ev_window);
700 }
701
702 static void
703 find_bar_previous_cb (EggFindBar *find_bar,
704                       EvWindow   *ev_window)
705 {
706         /* FIXME - highlight previous result */
707         g_printerr ("Find Previous\n");
708
709 }
710
711 static void
712 find_bar_next_cb (EggFindBar *find_bar,
713                   EvWindow   *ev_window)
714 {
715         /* FIXME - highlight next result */
716         g_printerr ("Find Next\n");
717 }
718
719 static void
720 find_bar_close_cb (EggFindBar *find_bar,
721                    EvWindow   *ev_window)
722 {
723         gtk_widget_hide (ev_window->priv->find_bar);
724 }
725
726 static void
727 find_bar_search_changed_cb (EggFindBar *find_bar,
728                             GParamSpec *param,
729                             EvWindow   *ev_window)
730 {
731         gboolean case_sensitive;
732         gboolean visible;
733         const char *search_string;
734
735         g_return_if_fail (EV_IS_WINDOW (ev_window));
736         
737         /* Either the string or case sensitivity could have changed,
738          * we connect this callback to both. We also connect it
739          * to ::visible so when the find bar is hidden, we should
740          * pretend the search string is NULL/""
741          */
742
743         case_sensitive = egg_find_bar_get_case_sensitive (find_bar);
744         visible = GTK_WIDGET_VISIBLE (find_bar);
745         search_string = egg_find_bar_get_search_string (find_bar);
746         
747 #if 0
748         g_printerr ("search for '%s'\n", search_string ? search_string : "(nil)");
749 #endif
750
751         /* We don't require begin/end find calls to be matched up, it's really
752          * start_find and cancel_any_find_that_may_not_be_finished
753          */
754         if (visible && search_string) {
755                 ev_document_begin_find (ev_window->priv->document, search_string, case_sensitive);
756         } else {
757                 ev_document_end_find (ev_window->priv->document);
758         }
759 }
760
761 static void
762 ev_window_dispose (GObject *object)
763 {
764         EvWindowPrivate *priv;
765
766         g_return_if_fail (object != NULL && EV_IS_WINDOW (object));
767
768         priv = EV_WINDOW (object)->priv;
769
770         if (priv->ui_manager) {
771                 g_object_unref (priv->ui_manager);
772                 priv->ui_manager = NULL;
773         }
774
775         if (priv->action_group) {
776                 g_object_unref (priv->action_group);
777                 priv->action_group = NULL;
778         }
779         
780         G_OBJECT_CLASS (parent_class)->dispose (object);
781 }
782
783 static void
784 ev_window_class_init (EvWindowClass *ev_window_class)
785 {
786         GObjectClass *g_object_class;
787
788         parent_class = g_type_class_peek_parent (ev_window_class);
789
790         g_object_class = G_OBJECT_CLASS (ev_window_class);
791         g_object_class->dispose = ev_window_dispose;
792
793         g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
794
795 #if 0
796         /* setting up signal system */
797         ev_window_class->signal = ev_window_signal;
798
799         ev_window_signals [SIGNAL] = g_signal_new (
800                 "signal",
801                 EV_TYPE_WINDOW,
802                 G_SIGNAL_RUN_LAST,
803                 G_STRUCT_OFFSET (EvWindowClass,
804                                  signal),
805                 NULL,
806                 NULL,
807                 g_cclosure_marshal_VOID__STRING,
808                 G_TYPE_NONE,
809                 0);
810         /* setting up property system */
811         g_object_class->set_property = ev_window_set_property;
812         g_object_class->get_property = ev_window_get_property;
813
814         g_object_class_install_property (
815                 g_object_class,
816                 PROP_ATTRIBUTE,
817                 g_param_spec_string ("attribute",
818                                      "Attribute",
819                                      "A simple unneccessary attribute that "
820                                      "does nothing special except being a "
821                                      "demonstration for the correct implem"
822                                      "entation of a GObject property",
823                                      "default_value",
824                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
825 #endif
826 }
827
828 /* Normal items */
829 static GtkActionEntry entries[] = {
830         { "File", NULL, N_("_File") },
831         { "Edit", NULL, N_("_Edit") },
832         { "View", NULL, N_("_View") },
833         { "Go", NULL, N_("_Go") },
834         { "Help", NULL, N_("_Help") },
835
836         /* File menu */
837         { "FileOpen", GTK_STOCK_OPEN, N_("_Open"), "<control>O",
838           N_("Open a file"),
839           G_CALLBACK (ev_window_cmd_file_open) },
840         { "FilePrint", GTK_STOCK_PRINT, N_("_Print"), "<control>P",
841           N_("Print this document"),
842           G_CALLBACK (ev_window_cmd_file_print) },
843         { "FileCloseWindow", GTK_STOCK_CLOSE, N_("_Close"), "<control>W",
844           N_("Close this window"),
845           G_CALLBACK (ev_window_cmd_file_close_window) },
846
847         /* Edit menu */
848         { "EditCopy", GTK_STOCK_COPY, N_("_Copy"), "<control>C",
849           N_("Copy text from the document"),
850           G_CALLBACK (ev_window_cmd_edit_copy) },
851         
852         { "EditFind", GTK_STOCK_FIND, N_("_Find"), "<control>F",
853           N_("Find a word or phrase in the document"),
854           G_CALLBACK (ev_window_cmd_edit_find) },
855
856         /* View menu */
857         { "ViewZoomIn", GTK_STOCK_ZOOM_IN, N_("Zoom _In"), "<control>plus",
858           N_("Enlarge the document"),
859           G_CALLBACK (ev_window_cmd_view_zoom_in) },
860         { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, N_("Zoom _Out"), "<control>minus",
861           N_("Shrink the document"),
862           G_CALLBACK (ev_window_cmd_view_zoom_out) },
863         { "ViewNormalSize", GTK_STOCK_ZOOM_100, N_("_Normal Size"), "<control>0",
864           N_("Zoom to the normal size"),
865           G_CALLBACK (ev_window_cmd_view_normal_size) },
866         { "ViewBestFit", GTK_STOCK_ZOOM_FIT, N_("_Best Fit"), NULL,
867           N_("Zoom to fit the document to the current window"),
868           G_CALLBACK (ev_window_cmd_view_best_fit) },
869         { "ViewPageWidth", EV_STOCK_ZOOM_FIT_WIDTH, N_("Fit Page _Width"), NULL,
870           N_("Zoom to fit the width of the current window "),
871           G_CALLBACK (ev_window_cmd_view_page_width) },
872
873         /* Go menu */
874         { "GoBack", GTK_STOCK_GO_BACK, N_("_Back"), "<mod1>Left",
875           N_("Go to the page viewed before this one"),
876           G_CALLBACK (ev_window_cmd_go_back) },
877         { "GoForward", GTK_STOCK_GO_FORWARD, N_("Fo_rward"), "<mod1>Right",
878           N_("Go to the page viewed before this one"),
879           G_CALLBACK (ev_window_cmd_go_forward) },
880         { "GoPreviousPage", GTK_STOCK_GO_BACK, N_("_Previous Page"), "<control>Page_Up",
881           N_("Go to the previous page"),
882           G_CALLBACK (ev_window_cmd_go_previous_page) },
883         { "GoNextPage", GTK_STOCK_GO_FORWARD, N_("_Next Page"), "<control>Page_Down",
884           N_("Go to the next page"),
885           G_CALLBACK (ev_window_cmd_go_next_page) },
886         { "GoFirstPage", GTK_STOCK_GOTO_FIRST, N_("_First Page"), "<control>Home",
887           N_("Go to the first page"),
888           G_CALLBACK (ev_window_cmd_go_first_page) },        
889         { "GoLastPage", GTK_STOCK_GOTO_LAST, N_("_Last Page"), "<control>End",
890           N_("Go to the last page"),
891           G_CALLBACK (ev_window_cmd_go_last_page) },
892         
893         /* Help menu */
894         { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), NULL,
895           N_("Display help for the viewer application"),
896           G_CALLBACK (ev_window_cmd_help_contents) },
897         
898         { "HelpAbout", GTK_STOCK_ABOUT, N_("_About"), NULL,
899           N_("Display credits for the document viewer creators"),
900           G_CALLBACK (ev_window_cmd_help_about) },
901 };
902
903 /* Toggle items */
904 static GtkToggleActionEntry toggle_entries[] = {
905         /* View Menu */
906         { "ViewToolbar", NULL, N_("_Toolbar"), "<shift><control>T",
907           N_("Show or hide toolbar"),
908           G_CALLBACK (ev_window_view_toolbar_cb), TRUE },
909         { "ViewStatusbar", NULL, N_("_Statusbar"), NULL,
910           N_("Show or hide statusbar"),
911           G_CALLBACK (ev_window_view_statusbar_cb), TRUE },
912         { "ViewSidebar", NULL, N_("Side_bar"), "F9",
913           N_("Show or hide sidebar"),
914           G_CALLBACK (ev_window_view_sidebar_cb), FALSE },
915         { "ViewFullscreen", NULL, N_("_Fullscreen"), "F11",
916           N_("Expand the window to fill the screen"),
917           G_CALLBACK (ev_window_cmd_view_fullscreen) },
918 };
919
920 static void
921 ev_window_init (EvWindow *ev_window)
922 {
923         GtkActionGroup *action_group;
924         GtkAccelGroup *accel_group;
925         GError *error = NULL;
926         GtkWidget *scrolled_window;
927         GtkWidget *menubar;
928         GtkWidget *toolbar;
929         GtkWidget *sidebar_widget;
930
931         ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
932
933         gtk_window_set_title (GTK_WINDOW (ev_window), _("Document Viewer"));
934
935         ev_window->priv->main_box = gtk_vbox_new (FALSE, 0);
936         gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box);
937         gtk_widget_show (ev_window->priv->main_box);
938         
939         action_group = gtk_action_group_new ("MenuActions");
940         ev_window->priv->action_group = action_group;
941         gtk_action_group_set_translation_domain (action_group, NULL);
942         gtk_action_group_add_actions (action_group, entries,
943                                       G_N_ELEMENTS (entries), ev_window);
944         gtk_action_group_add_toggle_actions (action_group, toggle_entries,
945                                              G_N_ELEMENTS (toggle_entries),
946                                              ev_window);
947
948         ev_window->priv->ui_manager = gtk_ui_manager_new ();
949         gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
950                                             action_group, 0);
951
952         accel_group =
953                 gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
954         gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
955
956         g_signal_connect (ev_window->priv->ui_manager, "connect_proxy",
957                           G_CALLBACK (connect_proxy_cb), ev_window);
958         g_signal_connect (ev_window->priv->ui_manager, "disconnect_proxy",
959                           G_CALLBACK (disconnect_proxy_cb), ev_window);
960
961         if (!gtk_ui_manager_add_ui_from_file (ev_window->priv->ui_manager,
962                                               DATADIR"/evince-ui.xml",
963                                               &error)) {
964                 g_message ("building menus failed: %s", error->message);
965                 g_error_free (error);
966         }
967
968         menubar = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
969                                              "/MainMenu");
970         gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), menubar,
971                             FALSE, FALSE, 0);
972
973         toolbar = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
974                                              "/ToolBar");
975         gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), toolbar,
976                             FALSE, FALSE, 0);
977
978         /* Add the main area */
979         ev_window->priv->hpaned = gtk_hpaned_new ();
980         gtk_widget_show (ev_window->priv->hpaned);
981         gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), ev_window->priv->hpaned,
982                             TRUE, TRUE, 0);
983
984         ev_window->priv->sidebar = ev_sidebar_new ();
985         gtk_widget_show (ev_window->priv->sidebar);
986         gtk_paned_add1 (GTK_PANED (ev_window->priv->hpaned),
987                         ev_window->priv->sidebar);
988
989         /* Stub sidebar, for now */
990         sidebar_widget = ev_sidebar_bookmarks_new ();
991         gtk_widget_show (sidebar_widget);
992         ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
993                              "bookmarks",
994                              _("Bookmarks"),
995                              sidebar_widget);
996
997         sidebar_widget = ev_sidebar_thumbnails_new ();
998         gtk_widget_show (sidebar_widget);
999         ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
1000                              "thumbnails",
1001                              _("Thumbnails"),
1002                              sidebar_widget);
1003         
1004         scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1005         gtk_widget_show (scrolled_window);
1006         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1007                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1008
1009         gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned),
1010                         scrolled_window);
1011
1012         ev_window->priv->view = ev_view_new ();
1013         gtk_widget_show (ev_window->priv->view);
1014         gtk_container_add (GTK_CONTAINER (scrolled_window),
1015                            ev_window->priv->view);
1016         g_signal_connect (ev_window->priv->view,
1017                           "page-changed",
1018                           G_CALLBACK (view_page_changed_cb),
1019                           ev_window);
1020
1021         ev_window->priv->statusbar = gtk_statusbar_new ();
1022         gtk_widget_show (ev_window->priv->statusbar);
1023         gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
1024                           ev_window->priv->statusbar,
1025                           FALSE, TRUE, 0);
1026         ev_window->priv->help_message_cid = gtk_statusbar_get_context_id
1027                 (GTK_STATUSBAR (ev_window->priv->statusbar), "help_message");
1028
1029         ev_window->priv->find_bar = egg_find_bar_new ();
1030         gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
1031                           ev_window->priv->find_bar,
1032                           FALSE, TRUE, 0);
1033         
1034         /* Connect to find bar signals */
1035         g_signal_connect (ev_window->priv->find_bar,
1036                           "previous",
1037                           G_CALLBACK (find_bar_previous_cb),
1038                           ev_window);
1039         g_signal_connect (ev_window->priv->find_bar,
1040                           "next",
1041                           G_CALLBACK (find_bar_next_cb),
1042                           ev_window);
1043         g_signal_connect (ev_window->priv->find_bar,
1044                           "close",
1045                           G_CALLBACK (find_bar_close_cb),
1046                           ev_window);
1047         g_signal_connect (ev_window->priv->find_bar,
1048                           "notify::search-string",
1049                           G_CALLBACK (find_bar_search_changed_cb),
1050                           ev_window);
1051         g_signal_connect (ev_window->priv->find_bar,
1052                           "notify::case-sensitive",
1053                           G_CALLBACK (find_bar_search_changed_cb),
1054                           ev_window);
1055         g_signal_connect (ev_window->priv->find_bar,
1056                           "notify::visible",
1057                           G_CALLBACK (find_bar_search_changed_cb),
1058                           ev_window);
1059
1060         g_signal_connect (ev_window, "window-state-event",
1061                           G_CALLBACK (ev_window_state_event_cb),
1062                           ev_window);
1063         
1064         /* Give focus to the scrolled window */
1065         gtk_widget_grab_focus (scrolled_window);
1066         
1067         update_action_sensitivity (ev_window);
1068