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
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
10 * Martin Kretzschmar <martink@gnome.org>
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.
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.
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.
31 #include "ev-window.h"
32 #include "ev-navigation-action.h"
33 #include "ev-page-action.h"
34 #include "ev-sidebar.h"
35 #include "ev-sidebar-bookmarks.h"
36 #include "ev-sidebar-thumbnails.h"
38 #include "ev-print-job.h"
39 #include "ev-document-find.h"
40 #include "eggfindbar.h"
42 #include "pdf-document.h"
43 #include "pixbuf-document.h"
44 #include "ps-document.h"
46 #include <glib/gi18n.h>
48 #include <libgnomevfs/gnome-vfs-mime-utils.h>
49 #include <libgnomeprintui/gnome-print-dialog.h>
53 #include "ev-application.h"
54 #include "ev-stock-icons.h"
66 struct _EvWindowPrivate {
72 GtkActionGroup *action_group;
73 GtkUIManager *ui_manager;
75 guint help_message_cid;
76 GtkWidget *exit_fullscreen_popup;
78 GtkAction *page_action;
82 gboolean fullscreen_mode;
86 /* enable these to add support for signals */
87 static guint ev_window_signals [N_SIGNALS] = { 0 };
90 static void update_fullscreen_popup (EvWindow *window);
92 static GObjectClass *parent_class = NULL;
94 G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
96 #define EV_WINDOW_GET_PRIVATE(object) \
97 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_WINDOW, EvWindowPrivate))
101 ev_window_get_attribute (EvWindow *self)
103 g_return_val_if_fail (self != NULL && EV_IS_WINDOW (self), NULL);
105 return self->priv->attribute;
109 ev_window_set_attribute (EvWindow* self, const char *attribute)
111 g_assert (self != NULL && EV_IS_WINDOW (self));
112 g_assert (attribute != NULL);
114 if (self->priv->attribute != NULL) {
115 g_free (self->priv->attribute);
118 self->priv->attribute = g_strdup (attribute);
120 g_object_notify (G_OBJECT (self), "attribute");
124 ev_window_get_property (GObject *object, guint prop_id, GValue *value,
125 GParamSpec *param_spec)
129 self = EV_WINDOW (object);
133 g_value_set_string (value, self->priv->attribute);
136 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
144 ev_window_set_property (GObject *object, guint prop_id, const GValue *value,
145 GParamSpec *param_spec)
149 self = EV_WINDOW (object);
153 ev_window_set_attribute (self, g_value_get_string (value));
156 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
165 set_action_sensitive (EvWindow *ev_window,
169 GtkAction *action = gtk_action_group_get_action (ev_window->priv->action_group,
171 gtk_action_set_sensitive (action, sensitive);
175 update_action_sensitivity (EvWindow *ev_window)
180 if (ev_window->priv->document)
181 n_pages = ev_document_get_n_pages (ev_window->priv->document);
185 page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
187 set_action_sensitive (ev_window, "GoFirstPage", page > 1);
188 set_action_sensitive (ev_window, "GoPageDown", page > 1);
189 set_action_sensitive (ev_window, "GoPageUp", page < n_pages);
190 set_action_sensitive (ev_window, "GoLastPage", page < n_pages);
194 ev_window_open_bookmark (EvWindow *ev_window, EvBookmark *bookmark)
196 ev_view_go_to_bookmark (EV_VIEW (ev_window->priv->view), bookmark);
200 ev_window_is_empty (const EvWindow *ev_window)
202 g_return_val_if_fail (EV_IS_WINDOW (ev_window), FALSE);
204 return ev_window->priv->document == NULL;
208 unable_to_load (EvWindow *ev_window,
209 const char *error_message)
213 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
214 GTK_DIALOG_DESTROY_WITH_PARENT,
217 _("Unable to open document"));
218 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
219 "%s", error_message);
220 gtk_dialog_run (GTK_DIALOG (dialog));
221 gtk_widget_destroy (dialog);
224 /* Would be nice to have this in gdk-pixbuf */
226 mime_type_supported_by_gdk_pixbuf (const gchar *mime_type)
228 GSList *formats, *list;
229 gboolean retval = FALSE;
231 formats = gdk_pixbuf_get_formats ();
235 GdkPixbufFormat *format = list->data;
239 if (gdk_pixbuf_format_is_disabled (format))
242 mime_types = gdk_pixbuf_format_get_mime_types (format);
244 for (i = 0; mime_types[i] != NULL; i++) {
245 if (strcmp (mime_types[i], mime_type) == 0) {
257 g_slist_free (formats);
263 update_window_title (EvDocument *document, GParamSpec *pspec, EvWindow *ev_window)
267 if (document == NULL) {
268 title = g_strdup (_("Document Viewer"));
270 title = ev_document_get_title (document);
273 title = g_path_get_basename (ev_window->priv->uri);
277 gtk_window_set_title (GTK_WINDOW (ev_window), title);
283 update_total_pages (EvWindow *ev_window)
285 EvPageAction *page_action;
288 pages = ev_document_get_n_pages (ev_window->priv->document);
289 page_action = EV_PAGE_ACTION (ev_window->priv->page_action);
290 ev_page_action_set_total_pages (page_action, pages);
294 ev_window_open (EvWindow *ev_window, const char *uri)
296 EvDocument *document = NULL;
299 g_free (ev_window->priv->uri);
300 ev_window->priv->uri = g_strdup (uri);
302 mime_type = gnome_vfs_get_mime_type (uri);
304 if (mime_type == NULL)
306 else if (!strcmp (mime_type, "application/pdf"))
307 document = g_object_new (PDF_TYPE_DOCUMENT, NULL);
308 else if (!strcmp (mime_type, "application/postscript"))
309 document = g_object_new (PS_TYPE_DOCUMENT, NULL);
310 else if (mime_type_supported_by_gdk_pixbuf (mime_type))
311 document = g_object_new (PIXBUF_TYPE_DOCUMENT, NULL);
314 GError *error = NULL;
316 g_signal_connect_object (G_OBJECT (document),
318 G_CALLBACK (update_window_title),
321 if (ev_document_load (document, uri, &error)) {
322 if (ev_window->priv->document)
323 g_object_unref (ev_window->priv->document);
324 ev_window->priv->document = document;
326 ev_view_set_document (EV_VIEW (ev_window->priv->view),
328 ev_sidebar_set_document (EV_SIDEBAR (ev_window->priv->sidebar),
331 update_total_pages (ev_window);
332 update_action_sensitivity (ev_window);
334 g_assert (error != NULL);
335 g_object_unref (document);
336 unable_to_load (ev_window, error->message);
337 g_error_free (error);
342 error_message = g_strdup_printf (_("Unhandled MIME type: '%s'"),
343 mime_type?mime_type:"<Unknown MIME Type>");
344 unable_to_load (ev_window, error_message);
345 g_free (error_message);
352 ev_window_cmd_file_open (GtkAction *action, EvWindow *ev_window)
354 ev_application_open (EV_APP, NULL);
359 overwrite_existing_file (GtkWindow *window, const gchar *file_name)
362 gchar *utf8_file_name;
366 utf8_file_name = g_filename_to_utf8 (file_name, -1, NULL, NULL, NULL);
367 msgbox = gtk_message_dialog_new (
369 (GtkDialogFlags)GTK_DIALOG_DESTROY_WITH_PARENT,
370 GTK_MESSAGE_QUESTION,
372 _("A file named \"%s\" already exists."),
374 g_free (utf8_file_name);
376 gtk_message_dialog_format_secondary_text (
377 GTK_MESSAGE_DIALOG (msgbox),
378 _("Do you want to replace it with the one you are saving?"));
380 gtk_dialog_add_button (GTK_DIALOG (msgbox),
381 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
383 gtk_dialog_add_button (GTK_DIALOG (msgbox),
384 _("_Replace"), GTK_RESPONSE_YES);
386 gtk_dialog_set_default_response (GTK_DIALOG (msgbox),
387 GTK_RESPONSE_CANCEL);
389 obj = gtk_widget_get_accessible (msgbox);
391 if (GTK_IS_ACCESSIBLE (obj))
392 atk_object_set_name (obj, _("Question"));
394 ret = gtk_dialog_run (GTK_DIALOG (msgbox));
395 gtk_widget_destroy (msgbox);
397 return (ret == GTK_RESPONSE_YES);
402 save_error_dialog (GtkWindow *window, const gchar *file_name)
404 GtkWidget *error_dialog;
406 error_dialog = gtk_message_dialog_new (
408 (GtkDialogFlags)GTK_DIALOG_DESTROY_WITH_PARENT,
411 _("The file could not be saved as \"%s\"."),
414 /* Easy way to make the text bold while keeping the string
415 * above free from pango markup (FIXME ?) */
416 gtk_message_dialog_format_secondary_text (
417 GTK_MESSAGE_DIALOG (error_dialog), " ");
419 gtk_dialog_run (GTK_DIALOG (error_dialog));
420 gtk_widget_destroy (error_dialog);
424 ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
427 GtkFileFilter *pdf_filter, *all_filter;
430 fc = gtk_file_chooser_dialog_new (
432 NULL, GTK_FILE_CHOOSER_ACTION_SAVE,
433 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
434 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
436 gtk_window_set_modal (GTK_WINDOW (fc), TRUE);
438 pdf_filter = gtk_file_filter_new ();
439 gtk_file_filter_set_name (pdf_filter, _("PDF Documents"));
440 gtk_file_filter_add_mime_type (pdf_filter, "application/pdf");
441 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fc), pdf_filter);
443 all_filter = gtk_file_filter_new ();
444 gtk_file_filter_set_name (all_filter, _("All Files"));
445 gtk_file_filter_add_pattern (all_filter, "*");
446 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fc), all_filter);
447 gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (fc), pdf_filter);
449 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
451 gtk_widget_show (fc);
453 while (gtk_dialog_run (GTK_DIALOG (fc)) == GTK_RESPONSE_OK) {
454 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
457 if (g_file_test (uri, G_FILE_TEST_EXISTS) &&
458 !overwrite_existing_file (GTK_WINDOW (fc), uri))
462 if (ev_document_save (ev_window->priv->document, uri, NULL))
465 save_error_dialog (GTK_WINDOW (fc), uri);
467 gtk_widget_destroy (fc);
471 using_postscript_printer (GnomePrintConfig *config)
473 const guchar *driver;
474 const guchar *transport;
476 driver = gnome_print_config_get (
477 config, (const guchar *)"Settings.Engine.Backend.Driver");
479 transport = gnome_print_config_get (
480 config, (const guchar *)"Settings.Transport.Backend");
483 if (!strcmp ((const gchar *)driver, "gnome-print-ps"))
487 } else if (transport) {
488 if (!strcmp ((const gchar *)transport, "CUPS"))
496 ev_window_print (EvWindow *ev_window)
498 GnomePrintConfig *config;
500 GtkWidget *print_dialog;
501 EvPrintJob *print_job = NULL;
503 g_return_if_fail (EV_IS_WINDOW (ev_window));
504 g_return_if_fail (ev_window->priv->document != NULL);
506 config = gnome_print_config_default ();
507 job = gnome_print_job_new (config);
509 print_dialog = gnome_print_dialog_new (job, _("Print"),
510 (GNOME_PRINT_DIALOG_RANGE |
511 GNOME_PRINT_DIALOG_COPIES));
512 gtk_dialog_set_response_sensitive (GTK_DIALOG (print_dialog),
513 GNOME_PRINT_DIALOG_RESPONSE_PREVIEW,
518 response = gtk_dialog_run (GTK_DIALOG (print_dialog));
520 if (response != GNOME_PRINT_DIALOG_RESPONSE_PRINT)
523 /* FIXME: Change this when we have the first backend
524 * that can print more than postscript
526 if (!using_postscript_printer (config)) {
529 dialog = gtk_message_dialog_new (
530 GTK_WINDOW (print_dialog), GTK_DIALOG_MODAL,
531 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
532 _("Printing is not supported on this printer."));
533 gtk_message_dialog_format_secondary_text (
534 GTK_MESSAGE_DIALOG (dialog),
535 _("You were trying to print to a printer using the \"%s\" driver. This program requires a PostScript printer driver."),
536 gnome_print_config_get (
537 config, "Settings.Engine.Backend.Driver"));
538 gtk_dialog_run (GTK_DIALOG (dialog));
539 gtk_widget_destroy (dialog);
544 print_job = g_object_new (EV_TYPE_PRINT_JOB,
545 "gnome_print_job", job,
546 "document", ev_window->priv->document,
547 "print_dialog", print_dialog,
552 gtk_widget_destroy (print_dialog);
554 if (print_job != NULL) {
555 ev_print_job_print (print_job, GTK_WINDOW (ev_window));
556 g_object_unref (print_job);
561 ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
563 ev_window_print (ev_window);
567 ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
569 g_return_if_fail (EV_IS_WINDOW (ev_window));
571 gtk_widget_destroy (GTK_WIDGET (ev_window));
575 find_not_supported_dialog (EvWindow *ev_window)
579 /* If you change this so it isn't modal, be sure you don't
580 * allow multiple copies of the dialog...
583 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
584 GTK_DIALOG_DESTROY_WITH_PARENT,
587 _("The \"Find\" feature will not work with this document"));
588 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
589 _("Searching for text is only supported for PDF documents."));
590 gtk_dialog_run (GTK_DIALOG (dialog));
591 gtk_widget_destroy (dialog);
595 ev_window_cmd_edit_select_all (GtkAction *action, EvWindow *ev_window)
597 g_return_if_fail (EV_IS_WINDOW (ev_window));
599 ev_view_select_all (EV_VIEW (ev_window->priv->view));
603 ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window)
605 g_return_if_fail (EV_IS_WINDOW (ev_window));
607 if (ev_window->priv->document == NULL) {
608 g_printerr ("We should have set the Find menu item insensitive since there's no document\n");
609 } else if (!EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
610 find_not_supported_dialog (ev_window);
612 gtk_widget_show (ev_window->priv->find_bar);
614 if (ev_window->priv->exit_fullscreen_popup)
615 update_fullscreen_popup (ev_window);
617 egg_find_bar_grab_focus (EGG_FIND_BAR (ev_window->priv->find_bar));
622 ev_window_cmd_edit_copy (GtkAction *action, EvWindow *ev_window)
624 g_return_if_fail (EV_IS_WINDOW (ev_window));
626 ev_view_copy (EV_VIEW (ev_window->priv->view));
630 update_fullscreen_popup (EvWindow *window)
632 GtkWidget *popup = window->priv->exit_fullscreen_popup;
633 int popup_width, popup_height;
634 GdkRectangle screen_rect;
636 g_return_if_fail (popup != NULL);
641 popup_width = popup->requisition.width;
642 popup_height = popup->requisition.height;
644 /* FIXME multihead */
645 gdk_screen_get_monitor_geometry (gdk_screen_get_default (),
646 gdk_screen_get_monitor_at_window
647 (gdk_screen_get_default (),
648 GTK_WIDGET (window)->window),
651 if (GTK_WIDGET_VISIBLE (window->priv->find_bar)) {
654 gtk_widget_size_request (window->priv->find_bar, &req);
656 screen_rect.height -= req.height;
659 if (gtk_widget_get_direction (popup) == GTK_TEXT_DIR_RTL)
661 gtk_window_move (GTK_WINDOW (popup),
662 screen_rect.x + screen_rect.width - popup_width,
663 screen_rect.height - popup_height);
667 gtk_window_move (GTK_WINDOW (popup),
668 screen_rect.x, screen_rect.height - popup_height);
673 screen_size_changed_cb (GdkScreen *screen,
676 update_fullscreen_popup (window);
680 destroy_exit_fullscreen_popup (EvWindow *window)
682 if (window->priv->exit_fullscreen_popup != NULL)
684 /* FIXME multihead */
685 g_signal_handlers_disconnect_by_func
686 (gdk_screen_get_default (),
687 G_CALLBACK (screen_size_changed_cb), window);
689 gtk_widget_destroy (window->priv->exit_fullscreen_popup);
690 window->priv->exit_fullscreen_popup = NULL;
695 exit_fullscreen_button_clicked_cb (GtkWidget *button, EvWindow *window)
699 action = gtk_action_group_get_action (window->priv->action_group, "ViewFullscreen");
700 g_return_if_fail (action != NULL);
702 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), FALSE);
706 fullscreen_popup_size_request_cb (GtkWidget *popup, GtkRequisition *req, EvWindow *window)
708 update_fullscreen_popup (window);
712 ev_window_fullscreen (EvWindow *window)
714 GtkWidget *popup, *button, *icon, *label, *hbox, *main_menu;
716 window->priv->fullscreen_mode = TRUE;
718 popup = gtk_window_new (GTK_WINDOW_POPUP);
719 window->priv->exit_fullscreen_popup = popup;
721 button = gtk_button_new ();
722 g_signal_connect (button, "clicked",
723 G_CALLBACK (exit_fullscreen_button_clicked_cb),
725 gtk_widget_show (button);
726 gtk_container_add (GTK_CONTAINER (popup), button);
728 hbox = gtk_hbox_new (FALSE, 2);
729 gtk_widget_show (hbox);
730 gtk_container_add (GTK_CONTAINER (button), hbox);
732 icon = gtk_image_new_from_stock (GTK_STOCK_QUIT, GTK_ICON_SIZE_BUTTON);
733 gtk_widget_show (icon);
734 gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
736 label = gtk_label_new (_("Exit Fullscreen"));
737 gtk_widget_show (label);
738 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
740 gtk_window_set_resizable (GTK_WINDOW (popup), FALSE);
742 /* FIXME multihead */
743 g_signal_connect (gdk_screen_get_default (), "size-changed",
744 G_CALLBACK (screen_size_changed_cb), window);
745 g_signal_connect (popup, "size_request",
746 G_CALLBACK (fullscreen_popup_size_request_cb), window);
748 main_menu = gtk_ui_manager_get_widget (window->priv->ui_manager, "/MainMenu");
749 gtk_widget_hide (main_menu);
750 gtk_widget_hide (window->priv->statusbar);
752 update_fullscreen_popup (window);
754 gtk_widget_show (popup);
758 ev_window_unfullscreen (EvWindow *window)
760 GtkWidget *main_menu;
762 window->priv->fullscreen_mode = FALSE;
764 main_menu = gtk_ui_manager_get_widget (window->priv->ui_manager, "/MainMenu");
765 gtk_widget_show (main_menu);
766 gtk_widget_show (window->priv->statusbar);
768 destroy_exit_fullscreen_popup (window);
772 ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *ev_window)
776 g_return_if_fail (EV_IS_WINDOW (ev_window));
778 fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
781 gtk_window_fullscreen (GTK_WINDOW (ev_window));
783 gtk_window_unfullscreen (GTK_WINDOW (ev_window));
788 ev_window_state_event_cb (GtkWidget *widget, GdkEventWindowState *event, EvWindow *window)
790 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
792 GtkActionGroup *action_group;
796 fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
800 ev_window_fullscreen (window);
804 ev_window_unfullscreen (window);
807 action_group = window->priv->action_group;
809 action = gtk_action_group_get_action (action_group, "ViewFullscreen");
810 g_signal_handlers_block_by_func
811 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
812 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), fullscreen);
813 g_signal_handlers_unblock_by_func
814 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
822 ev_window_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *ev_window)
824 gtk_window_unfullscreen (GTK_WINDOW (ev_window));
831 ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window)
833 g_return_if_fail (EV_IS_WINDOW (ev_window));
835 ev_view_zoom_in (EV_VIEW (ev_window->priv->view));
839 ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window)
841 g_return_if_fail (EV_IS_WINDOW (ev_window));
843 ev_view_zoom_out (EV_VIEW (ev_window->priv->view));
847 ev_window_cmd_view_normal_size (GtkAction *action, EvWindow *ev_window)
849 g_return_if_fail (EV_IS_WINDOW (ev_window));
851 ev_view_normal_size (EV_VIEW (ev_window->priv->view));
855 ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
857 g_return_if_fail (EV_IS_WINDOW (ev_window));
859 ev_view_best_fit (EV_VIEW (ev_window->priv->view));
863 ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
865 g_return_if_fail (EV_IS_WINDOW (ev_window));
867 ev_view_fit_width (EV_VIEW (ev_window->priv->view));
871 ev_window_cmd_go_back (GtkAction *action, EvWindow *ev_window)
873 g_return_if_fail (EV_IS_WINDOW (ev_window));
875 ev_view_go_back (EV_VIEW (ev_window->priv->view));
879 ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window)
881 g_return_if_fail (EV_IS_WINDOW (ev_window));
883 ev_view_go_forward (EV_VIEW (ev_window->priv->view));
887 ev_window_cmd_go_page_up (GtkAction *action, EvWindow *ev_window)
889 g_return_if_fail (EV_IS_WINDOW (ev_window));
891 ev_view_set_page (EV_VIEW (ev_window->priv->view),
892 ev_view_get_page (EV_VIEW (ev_window->priv->view)) - 1);
896 ev_window_cmd_go_page_down (GtkAction *action, EvWindow *ev_window)
898 g_return_if_fail (EV_IS_WINDOW (ev_window));
900 ev_view_set_page (EV_VIEW (ev_window->priv->view),
901 ev_view_get_page (EV_VIEW (ev_window->priv->view)) + 1);
905 ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
907 g_return_if_fail (EV_IS_WINDOW (ev_window));
909 ev_view_set_page (EV_VIEW (ev_window->priv->view), 1);
913 ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
915 g_return_if_fail (EV_IS_WINDOW (ev_window));
917 ev_view_set_page (EV_VIEW (ev_window->priv->view), G_MAXINT);
921 ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
923 g_return_if_fail (EV_IS_WINDOW (ev_window));
929 ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
931 const char *authors[] = {
936 const char *documenters[] = {
937 N_("Not so many..."),
941 const char *license[] = {
942 N_("Evince is free software; you can redistribute it and/or modify\n"
943 "it under the terms of the GNU General Public License as published by\n"
944 "the Free Software Foundation; either version 2 of the License, or\n"
945 "(at your option) any later version.\n"),
946 N_("Evince is distributed in the hope that it will be useful,\n"
947 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
948 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
949 "GNU General Public License for more details.\n"),
950 N_("You should have received a copy of the GNU General Public License\n"
951 "along with Evince; if not, write to the Free Software Foundation, Inc.,\n"
952 "59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n")
960 for (p = authors; *p; ++p)
963 for (p = documenters; *p; ++p)
967 license_trans = g_strconcat (_(license[0]), "\n", _(license[1]), "\n",
968 _(license[2]), "\n", NULL);
970 gtk_show_about_dialog (
971 GTK_WINDOW (ev_window),
975 _("\xc2\xa9 1996-2004 The Evince authors"),
976 "license", license_trans,
977 "website", "http://www.gnome.org/projects/evince",
978 "comments", _("PostScript and PDF File Viewer."),
980 "documenters", documenters,
981 "translator-credits", _("translator-credits"),
984 g_free (license_trans);
988 ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window)
991 G_OBJECT (gtk_ui_manager_get_widget (
992 ev_window->priv->ui_manager,
995 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
1000 ev_window_view_statusbar_cb (GtkAction *action, EvWindow *ev_window)
1003 ev_window->priv->statusbar,
1005 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
1010 ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window)
1013 ev_window->priv->sidebar,
1015 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
1020 menu_item_select_cb (GtkMenuItem *proxy, EvWindow *ev_window)
1025 action = g_object_get_data (G_OBJECT (proxy), "gtk-action");
1026 g_return_if_fail (action != NULL);
1028 g_object_get (G_OBJECT (action), "tooltip", &message, NULL);
1030 gtk_statusbar_push (GTK_STATUSBAR (ev_window->priv->statusbar),
1031 ev_window->priv->help_message_cid, message);
1037 menu_item_deselect_cb (GtkMenuItem *proxy, EvWindow *ev_window)
1039 gtk_statusbar_pop (GTK_STATUSBAR (ev_window->priv->statusbar),
1040 ev_window->priv->help_message_cid);
1044 connect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
1045 GtkWidget *proxy, EvWindow *ev_window)
1047 if (GTK_IS_MENU_ITEM (proxy)) {
1048 g_signal_connect (proxy, "select",
1049 G_CALLBACK (menu_item_select_cb), ev_window);
1050 g_signal_connect (proxy, "deselect",
1051 G_CALLBACK (menu_item_deselect_cb),
1057 disconnect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
1058 GtkWidget *proxy, EvWindow *ev_window)
1060 if (GTK_IS_MENU_ITEM (proxy)) {
1061 g_signal_handlers_disconnect_by_func
1062 (proxy, G_CALLBACK (menu_item_select_cb), ev_window);
1063 g_signal_handlers_disconnect_by_func
1064 (proxy, G_CALLBACK (menu_item_deselect_cb), ev_window);
1069 update_current_page (EvWindow *ev_window)
1071 EvPageAction *page_action;
1074 page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
1075 page_action = EV_PAGE_ACTION (ev_window->priv->page_action);
1076 ev_page_action_set_current_page (page_action, page);
1080 view_page_changed_cb (EvView *view,
1081 EvWindow *ev_window)
1083 update_current_page (ev_window);
1084 update_action_sensitivity (ev_window);
1088 view_find_status_changed_cb (EvView *view,
1089 EvWindow *ev_window)
1093 text = ev_view_get_find_status_message (view);
1095 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
1102 find_bar_previous_cb (EggFindBar *find_bar,
1103 EvWindow *ev_window)
1105 /* FIXME - highlight previous result */
1106 g_printerr ("Find Previous\n");
1111 find_bar_next_cb (EggFindBar *find_bar,
1112 EvWindow *ev_window)
1114 /* FIXME - highlight next result */
1115 g_printerr ("Find Next\n");
1119 find_bar_close_cb (EggFindBar *find_bar,
1120 EvWindow *ev_window)
1122 gtk_widget_hide (ev_window->priv->find_bar);
1124 if (ev_window->priv->exit_fullscreen_popup)
1125 update_fullscreen_popup (ev_window);
1129 find_bar_search_changed_cb (EggFindBar *find_bar,
1131 EvWindow *ev_window)
1133 gboolean case_sensitive;
1135 const char *search_string;
1137 g_return_if_fail (EV_IS_WINDOW (ev_window));
1139 /* Either the string or case sensitivity could have changed,
1140 * we connect this callback to both. We also connect it
1141 * to ::visible so when the find bar is hidden, we should
1142 * pretend the search string is NULL/""
1145 case_sensitive = egg_find_bar_get_case_sensitive (find_bar);
1146 visible = GTK_WIDGET_VISIBLE (find_bar);
1147 search_string = egg_find_bar_get_search_string (find_bar);
1150 g_printerr ("search for '%s'\n", search_string ? search_string : "(nil)");
1153 if (ev_window->priv->document &&
1154 EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
1155 if (visible && search_string) {
1156 ev_document_find_begin (EV_DOCUMENT_FIND (ev_window->priv->document), search_string, case_sensitive);
1158 ev_document_find_cancel (EV_DOCUMENT_FIND (ev_window->priv->document));
1159 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
1166 ev_window_dispose (GObject *object)
1168 EvWindowPrivate *priv;
1170 g_return_if_fail (object != NULL && EV_IS_WINDOW (object));
1172 priv = EV_WINDOW (object)->priv;
1174 if (priv->ui_manager) {
1175 g_object_unref (priv->ui_manager);
1176 priv->ui_manager = NULL;
1179 if (priv->action_group) {
1180 g_object_unref (priv->action_group);
1181 priv->action_group = NULL;
1184 G_OBJECT_CLASS (parent_class)->dispose (object);
1188 ev_window_class_init (EvWindowClass *ev_window_class)
1190 GObjectClass *g_object_class;
1192 parent_class = g_type_class_peek_parent (ev_window_class);
1194 g_object_class = G_OBJECT_CLASS (ev_window_class);
1195 g_object_class->dispose = ev_window_dispose;
1197 g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
1200 /* setting up signal system */
1201 ev_window_class->signal = ev_window_signal;
1203 ev_window_signals [SIGNAL] = g_signal_new (
1207 G_STRUCT_OFFSET (EvWindowClass,
1211 g_cclosure_marshal_VOID__STRING,
1214 /* setting up property system */
1215 g_object_class->set_property = ev_window_set_property;
1216 g_object_class->get_property = ev_window_get_property;
1218 g_object_class_install_property (
1221 g_param_spec_string ("attribute",
1223 "A simple unneccessary attribute that "
1224 "does nothing special except being a "
1225 "demonstration for the correct implem"
1226 "entation of a GObject property",
1228 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
1233 static GtkActionEntry entries[] = {
1234 { "File", NULL, N_("_File") },
1235 { "Edit", NULL, N_("_Edit") },
1236 { "View", NULL, N_("_View") },
1237 { "Go", NULL, N_("_Go") },
1238 { "Help", NULL, N_("_Help") },
1241 { "FileOpen", GTK_STOCK_OPEN, N_("_Open"), "<control>O",
1243 G_CALLBACK (ev_window_cmd_file_open) },
1244 { "FileSaveAs", GTK_STOCK_SAVE_AS, N_("_Save a Copy..."), NULL,
1245 N_("Save the current document with a new filename"),
1246 G_CALLBACK (ev_window_cmd_save_as) },
1247 { "FilePrint", GTK_STOCK_PRINT, N_("_Print"), "<control>P",
1248 N_("Print this document"),
1249 G_CALLBACK (ev_window_cmd_file_print) },
1250 { "FileCloseWindow", GTK_STOCK_CLOSE, N_("_Close"), "<control>W",
1251 N_("Close this window"),
1252 G_CALLBACK (ev_window_cmd_file_close_window) },
1255 { "EditCopy", GTK_STOCK_COPY, N_("_Copy"), "<control>C",
1256 N_("Copy text from the document"),
1257 G_CALLBACK (ev_window_cmd_edit_copy) },
1258 { "EditSelectAll", NULL, N_("Select _All"), "<control>A",
1259 N_("Select the entire page"),
1260 G_CALLBACK (ev_window_cmd_edit_select_all) },
1261 { "EditFind", GTK_STOCK_FIND, N_("_Find"), "<control>F",
1262 N_("Find a word or phrase in the document"),
1263 G_CALLBACK (ev_window_cmd_edit_find) },
1266 { "ViewZoomIn", GTK_STOCK_ZOOM_IN, N_("Zoom _In"), "<control>plus",
1267 N_("Enlarge the document"),
1268 G_CALLBACK (ev_window_cmd_view_zoom_in) },
1269 { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, N_("Zoom _Out"), "<control>minus",
1270 N_("Shrink the document"),
1271 G_CALLBACK (ev_window_cmd_view_zoom_out) },
1272 { "ViewNormalSize", GTK_STOCK_ZOOM_100, N_("_Normal Size"), "<control>0",
1273 N_("Zoom to the normal size"),
1274 G_CALLBACK (ev_window_cmd_view_normal_size) },
1275 { "ViewBestFit", GTK_STOCK_ZOOM_FIT, N_("_Best Fit"), NULL,
1276 N_("Zoom to fit the document to the current window"),
1277 G_CALLBACK (ev_window_cmd_view_best_fit) },
1278 { "ViewPageWidth", EV_STOCK_ZOOM_FIT_WIDTH, N_("Fit Page _Width"), NULL,
1279 N_("Zoom to fit the width of the current window "),
1280 G_CALLBACK (ev_window_cmd_view_page_width) },
1283 { "GoBack", GTK_STOCK_GO_BACK, N_("_Back"), "<mod1>Left",
1284 N_("Go to the page viewed before this one"),
1285 G_CALLBACK (ev_window_cmd_go_back) },
1286 { "GoForward", GTK_STOCK_GO_FORWARD, N_("Fo_rward"), "<mod1>Right",
1287 N_("Go to the page viewed before this one"),
1288 G_CALLBACK (ev_window_cmd_go_forward) },
1289 { "GoPageDown", GTK_STOCK_GO_UP, N_("_Page Up"), "<control>Page_Up",
1290 N_("Go to the previous page"),
1291 G_CALLBACK (ev_window_cmd_go_page_up) },
1292 { "GoPageUp", GTK_STOCK_GO_DOWN, N_("_Page Down"), "<control>Page_Down",
1293 N_("Go to the next page"),
1294 G_CALLBACK (ev_window_cmd_go_page_down) },
1295 { "GoFirstPage", GTK_STOCK_GOTO_FIRST, N_("_First Page"), "<control>Home",
1296 N_("Go to the first page"),
1297 G_CALLBACK (ev_window_cmd_go_first_page) },
1298 { "GoLastPage", GTK_STOCK_GOTO_LAST, N_("_Last Page"), "<control>End",
1299 N_("Go to the last page"),
1300 G_CALLBACK (ev_window_cmd_go_last_page) },
1303 { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), NULL,
1304 N_("Display help for the viewer application"),
1305 G_CALLBACK (ev_window_cmd_help_contents) },
1307 { "HelpAbout", GTK_STOCK_ABOUT, N_("_About"), NULL,
1308 N_("Display credits for the document viewer creators"),
1309 G_CALLBACK (ev_window_cmd_help_about) },
1313 static GtkToggleActionEntry toggle_entries[] = {
1315 { "ViewToolbar", NULL, N_("_Toolbar"), "<shift><control>T",
1316 N_("Show or hide toolbar"),
1317 G_CALLBACK (ev_window_view_toolbar_cb), TRUE },
1318 { "ViewStatusbar", NULL, N_("_Statusbar"), NULL,
1319 N_("Show or hide statusbar"),
1320 G_CALLBACK (ev_window_view_statusbar_cb), TRUE },
1321 { "ViewSidebar", NULL, N_("Side_bar"), "F9",
1322 N_("Show or hide sidebar"),
1323 G_CALLBACK (ev_window_view_sidebar_cb), TRUE },
1324 { "ViewFullscreen", NULL, N_("_Fullscreen"), "F11",
1325 N_("Expand the window to fill the screen"),
1326 G_CALLBACK (ev_window_cmd_view_fullscreen) },
1330 goto_page_cb (GtkAction *action, int page_number, EvWindow *ev_window)
1332 EvView *view = EV_VIEW (ev_window->priv->view);
1334 if (ev_view_get_page (view) != page_number) {
1335 ev_view_set_page (view, page_number);
1340 register_custom_actions (EvWindow *window, GtkActionGroup *group)
1344 action = g_object_new (EV_TYPE_NAVIGATION_ACTION,
1345 "name", "NavigationBack",
1347 "stock_id", GTK_STOCK_GO_BACK,
1348 "tooltip", _("Go back"),
1349 "arrow-tooltip", _("Back history"),
1350 "direction", EV_NAVIGATION_DIRECTION_BACK,
1351 "is_important", TRUE,
1353 g_signal_connect (action, "activate",
1354 G_CALLBACK (ev_window_cmd_go_back), window);
1355 gtk_action_group_add_action (group, action);
1356 g_object_unref (action);
1358 action = g_object_new (EV_TYPE_NAVIGATION_ACTION,
1359 "name", "NavigationForward",
1360 "label", _("Forward"),
1361 "stock_id", GTK_STOCK_GO_FORWARD,
1362 "tooltip", _("Go forward"),
1363 "arrow-tooltip", _("Forward history"),
1364 "direction", EV_NAVIGATION_DIRECTION_FORWARD,
1366 g_signal_connect (action, "activate",
1367 G_CALLBACK (ev_window_cmd_go_back), window);
1368 gtk_action_group_add_action (group, action);
1369 g_object_unref (action);
1371 action = g_object_new (EV_TYPE_PAGE_ACTION,
1372 "name", "PageSelector",
1374 "tooltip", _("Select Page"),
1376 g_signal_connect (action, "goto_page",
1377 G_CALLBACK (goto_page_cb), window);
1378 window->priv->page_action = action;
1379 gtk_action_group_add_action (group, action);
1380 g_object_unref (action);
1384 ev_window_init (EvWindow *ev_window)
1386 GtkActionGroup *action_group;
1387 GtkAccelGroup *accel_group;
1388 GError *error = NULL;
1389 GtkWidget *scrolled_window;
1392 GtkWidget *sidebar_widget;
1394 ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
1396 update_window_title (NULL, NULL, ev_window);
1398 ev_window->priv->main_box = gtk_vbox_new (FALSE, 0);
1399 gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box);
1400 gtk_widget_show (ev_window->priv->main_box);
1402 action_group = gtk_action_group_new ("MenuActions");
1403 ev_window->priv->action_group = action_group;
1404 gtk_action_group_set_translation_domain (action_group, NULL);
1405 gtk_action_group_add_actions (action_group, entries,
1406 G_N_ELEMENTS (entries), ev_window);
1407 gtk_action_group_add_toggle_actions (action_group, toggle_entries,
1408 G_N_ELEMENTS (toggle_entries),
1411 register_custom_actions (ev_window, action_group);
1413 ev_window->priv->ui_manager = gtk_ui_manager_new ();
1414 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
1418 gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
1419 gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
1421 g_signal_connect (ev_window->priv->ui_manager, "connect_proxy",
1422 G_CALLBACK (connect_proxy_cb), ev_window);
1423 g_signal_connect (ev_window->priv->ui_manager, "disconnect_proxy",
1424 G_CALLBACK (disconnect_proxy_cb), ev_window);
1426 if (!gtk_ui_manager_add_ui_from_file (ev_window->priv->ui_manager,
1427 DATADIR"/evince-ui.xml",
1429 g_message ("building menus failed: %s", error->message);
1430 g_error_free (error);
1433 menubar = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
1435 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), menubar,
1438 toolbar = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
1440 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), toolbar,
1443 /* Add the main area */
1444 ev_window->priv->hpaned = gtk_hpaned_new ();
1445 gtk_widget_show (ev_window->priv->hpaned);
1446 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), ev_window->priv->hpaned,
1449 ev_window->priv->sidebar = ev_sidebar_new ();
1450 gtk_widget_show (ev_window->priv->sidebar);
1451 gtk_paned_add1 (GTK_PANED (ev_window->priv->hpaned),
1452 ev_window->priv->sidebar);
1454 /* Stub sidebar, for now */
1455 sidebar_widget = ev_sidebar_bookmarks_new ();
1456 gtk_widget_show (sidebar_widget);
1457 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
1462 sidebar_widget = ev_sidebar_thumbnails_new ();
1463 gtk_widget_show (sidebar_widget);
1464 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
1469 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1470 gtk_widget_show (scrolled_window);
1471 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1472 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1474 gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned),
1477 ev_window->priv->view = ev_view_new ();
1478 gtk_widget_show (ev_window->priv->view);
1479 gtk_container_add (GTK_CONTAINER (scrolled_window),
1480 ev_window->priv->view);
1481 g_signal_connect (ev_window->priv->view,
1483 G_CALLBACK (view_page_changed_cb),
1485 g_signal_connect (ev_window->priv->view,
1486 "find-status-changed",
1487 G_CALLBACK (view_find_status_changed_cb),
1490 ev_window->priv->statusbar = gtk_statusbar_new ();
1491 gtk_widget_show (ev_window->priv->statusbar);
1492 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
1493 ev_window->priv->statusbar,
1495 ev_window->priv->help_message_cid = gtk_statusbar_get_context_id
1496 (GTK_STATUSBAR (ev_window->priv->statusbar), "help_message");
1498 ev_window->priv->find_bar = egg_find_bar_new ();
1499 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
1500 ev_window->priv->find_bar,
1503 /* Connect to find bar signals */
1504 g_signal_connect (ev_window->priv->find_bar,
1506 G_CALLBACK (find_bar_previous_cb),
1508 g_signal_connect (ev_window->priv->find_bar,
1510 G_CALLBACK (find_bar_next_cb),
1512 g_signal_connect (ev_window->priv->find_bar,
1514 G_CALLBACK (find_bar_close_cb),
1516 g_signal_connect (ev_window->priv->find_bar,
1517 "notify::search-string",
1518 G_CALLBACK (find_bar_search_changed_cb),
1520 g_signal_connect (ev_window->priv->find_bar,
1521 "notify::case-sensitive",
1522 G_CALLBACK (find_bar_search_changed_cb),
1524 g_signal_connect (ev_window->priv->find_bar,
1526 G_CALLBACK (find_bar_search_changed_cb),
1529 g_signal_connect (ev_window, "window-state-event",
1530 G_CALLBACK (ev_window_state_event_cb),
1532 g_signal_connect (ev_window, "focus_out_event",
1533 G_CALLBACK (ev_window_focus_out_cb),
1536 /* Give focus to the scrolled window */
1537 gtk_widget_grab_focus (scrolled_window);
1539 update_action_sensitivity (ev_window);