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_is_empty (const EvWindow *ev_window)
196 g_return_val_if_fail (EV_IS_WINDOW (ev_window), FALSE);
198 return ev_window->priv->document == NULL;
202 unable_to_load (EvWindow *ev_window,
203 const char *error_message)
207 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
208 GTK_DIALOG_DESTROY_WITH_PARENT,
211 _("Unable to open document"));
212 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
213 "%s", error_message);
214 gtk_dialog_run (GTK_DIALOG (dialog));
215 gtk_widget_destroy (dialog);
218 /* Would be nice to have this in gdk-pixbuf */
220 mime_type_supported_by_gdk_pixbuf (const gchar *mime_type)
222 GSList *formats, *list;
223 gboolean retval = FALSE;
225 formats = gdk_pixbuf_get_formats ();
229 GdkPixbufFormat *format = list->data;
233 if (gdk_pixbuf_format_is_disabled (format))
236 mime_types = gdk_pixbuf_format_get_mime_types (format);
238 for (i = 0; mime_types[i] != NULL; i++) {
239 if (strcmp (mime_types[i], mime_type) == 0) {
251 g_slist_free (formats);
257 update_window_title (EvDocument *document, GParamSpec *pspec, EvWindow *ev_window)
261 if (document == NULL) {
262 title = g_strdup (_("Document Viewer"));
264 title = ev_document_get_title (document);
267 title = g_path_get_basename (ev_window->priv->uri);
271 gtk_window_set_title (GTK_WINDOW (ev_window), title);
277 update_total_pages (EvWindow *ev_window)
279 EvPageAction *page_action;
282 pages = ev_document_get_n_pages (ev_window->priv->document);
283 page_action = EV_PAGE_ACTION (ev_window->priv->page_action);
284 ev_page_action_set_total_pages (page_action, pages);
288 ev_window_open (EvWindow *ev_window, const char *uri)
290 EvDocument *document = NULL;
293 g_free (ev_window->priv->uri);
294 ev_window->priv->uri = g_strdup (uri);
296 mime_type = gnome_vfs_get_mime_type (uri);
298 if (mime_type == NULL)
300 else if (!strcmp (mime_type, "application/pdf"))
301 document = g_object_new (PDF_TYPE_DOCUMENT, NULL);
302 else if (!strcmp (mime_type, "application/postscript"))
303 document = g_object_new (PS_TYPE_DOCUMENT, NULL);
304 else if (mime_type_supported_by_gdk_pixbuf (mime_type))
305 document = g_object_new (PIXBUF_TYPE_DOCUMENT, NULL);
308 GError *error = NULL;
310 g_signal_connect_object (G_OBJECT (document),
312 G_CALLBACK (update_window_title),
315 if (ev_document_load (document, uri, &error)) {
316 if (ev_window->priv->document)
317 g_object_unref (ev_window->priv->document);
318 ev_window->priv->document = document;
320 ev_view_set_document (EV_VIEW (ev_window->priv->view),
322 ev_sidebar_set_document (EV_SIDEBAR (ev_window->priv->sidebar),
325 update_total_pages (ev_window);
326 update_action_sensitivity (ev_window);
328 g_assert (error != NULL);
329 g_object_unref (document);
330 unable_to_load (ev_window, error->message);
331 g_error_free (error);
336 error_message = g_strdup_printf (_("Unhandled MIME type: '%s'"),
337 mime_type?mime_type:"<Unknown MIME Type>");
338 unable_to_load (ev_window, error_message);
339 g_free (error_message);
346 ev_window_cmd_file_open (GtkAction *action, EvWindow *ev_window)
348 ev_application_open (EV_APP, NULL);
353 overwrite_existing_file (GtkWindow *window, const gchar *file_name)
356 gchar *utf8_file_name;
360 utf8_file_name = g_filename_to_utf8 (file_name, -1, NULL, NULL, NULL);
361 msgbox = gtk_message_dialog_new (
363 (GtkDialogFlags)GTK_DIALOG_DESTROY_WITH_PARENT,
364 GTK_MESSAGE_QUESTION,
366 _("A file named \"%s\" already exists."),
368 g_free (utf8_file_name);
370 gtk_message_dialog_format_secondary_text (
371 GTK_MESSAGE_DIALOG (msgbox),
372 _("Do you want to replace it with the one you are saving?"));
374 gtk_dialog_add_button (GTK_DIALOG (msgbox),
375 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
377 gtk_dialog_add_button (GTK_DIALOG (msgbox),
378 _("_Replace"), GTK_RESPONSE_YES);
380 gtk_dialog_set_default_response (GTK_DIALOG (msgbox),
381 GTK_RESPONSE_CANCEL);
383 obj = gtk_widget_get_accessible (msgbox);
385 if (GTK_IS_ACCESSIBLE (obj))
386 atk_object_set_name (obj, _("Question"));
388 ret = gtk_dialog_run (GTK_DIALOG (msgbox));
389 gtk_widget_destroy (msgbox);
391 return (ret == GTK_RESPONSE_YES);
396 save_error_dialog (GtkWindow *window, const gchar *file_name)
398 GtkWidget *error_dialog;
400 error_dialog = gtk_message_dialog_new (
402 (GtkDialogFlags)GTK_DIALOG_DESTROY_WITH_PARENT,
405 _("The file could not be saved as \"%s\"."),
408 /* Easy way to make the text bold while keeping the string
409 * above free from pango markup (FIXME ?) */
410 gtk_message_dialog_format_secondary_text (
411 GTK_MESSAGE_DIALOG (error_dialog), " ");
413 gtk_dialog_run (GTK_DIALOG (error_dialog));
414 gtk_widget_destroy (error_dialog);
418 ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
421 GtkFileFilter *pdf_filter, *all_filter;
424 fc = gtk_file_chooser_dialog_new (
426 NULL, GTK_FILE_CHOOSER_ACTION_SAVE,
427 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
428 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
430 gtk_window_set_modal (GTK_WINDOW (fc), TRUE);
432 pdf_filter = gtk_file_filter_new ();
433 gtk_file_filter_set_name (pdf_filter, _("PDF Documents"));
434 gtk_file_filter_add_mime_type (pdf_filter, "application/pdf");
435 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fc), pdf_filter);
437 all_filter = gtk_file_filter_new ();
438 gtk_file_filter_set_name (all_filter, _("All Files"));
439 gtk_file_filter_add_pattern (all_filter, "*");
440 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fc), all_filter);
441 gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (fc), pdf_filter);
443 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
445 gtk_widget_show (fc);
447 while (gtk_dialog_run (GTK_DIALOG (fc)) == GTK_RESPONSE_OK) {
448 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
451 if (g_file_test (uri, G_FILE_TEST_EXISTS) &&
452 !overwrite_existing_file (GTK_WINDOW (fc), uri))
456 if (ev_document_save (ev_window->priv->document, uri, NULL))
459 save_error_dialog (GTK_WINDOW (fc), uri);
461 gtk_widget_destroy (fc);
465 using_postscript_printer (GnomePrintConfig *config)
467 const guchar *driver;
468 const guchar *transport;
470 driver = gnome_print_config_get (
471 config, (const guchar *)"Settings.Engine.Backend.Driver");
473 transport = gnome_print_config_get (
474 config, (const guchar *)"Settings.Transport.Backend");
477 if (!strcmp ((const gchar *)driver, "gnome-print-ps"))
481 } else if (transport) {
482 if (!strcmp ((const gchar *)transport, "CUPS"))
490 ev_window_print (EvWindow *ev_window)
492 GnomePrintConfig *config;
494 GtkWidget *print_dialog;
495 EvPrintJob *print_job = NULL;
497 g_return_if_fail (EV_IS_WINDOW (ev_window));
498 g_return_if_fail (ev_window->priv->document != NULL);
500 config = gnome_print_config_default ();
501 job = gnome_print_job_new (config);
503 print_dialog = gnome_print_dialog_new (job, _("Print"),
504 (GNOME_PRINT_DIALOG_RANGE |
505 GNOME_PRINT_DIALOG_COPIES));
506 gtk_dialog_set_response_sensitive (GTK_DIALOG (print_dialog),
507 GNOME_PRINT_DIALOG_RESPONSE_PREVIEW,
512 response = gtk_dialog_run (GTK_DIALOG (print_dialog));
514 if (response != GNOME_PRINT_DIALOG_RESPONSE_PRINT)
517 /* FIXME: Change this when we have the first backend
518 * that can print more than postscript
520 if (!using_postscript_printer (config)) {
523 dialog = gtk_message_dialog_new (
524 GTK_WINDOW (print_dialog), GTK_DIALOG_MODAL,
525 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
526 _("Printing is not supported on this printer."));
527 gtk_message_dialog_format_secondary_text (
528 GTK_MESSAGE_DIALOG (dialog),
529 _("You were trying to print to a printer using the \"%s\" driver. This program requires a PostScript printer driver."),
530 gnome_print_config_get (
531 config, "Settings.Engine.Backend.Driver"));
532 gtk_dialog_run (GTK_DIALOG (dialog));
533 gtk_widget_destroy (dialog);
538 print_job = g_object_new (EV_TYPE_PRINT_JOB,
539 "gnome_print_job", job,
540 "document", ev_window->priv->document,
541 "print_dialog", print_dialog,
546 gtk_widget_destroy (print_dialog);
548 if (print_job != NULL)
549 ev_print_job_print (print_job, GTK_WINDOW (ev_window));
553 ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
555 ev_window_print (ev_window);
559 ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
561 g_return_if_fail (EV_IS_WINDOW (ev_window));
563 gtk_widget_destroy (GTK_WIDGET (ev_window));
567 find_not_supported_dialog (EvWindow *ev_window)
571 /* If you change this so it isn't modal, be sure you don't
572 * allow multiple copies of the dialog...
575 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
576 GTK_DIALOG_DESTROY_WITH_PARENT,
579 _("The \"Find\" feature will not work with this document"));
580 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
581 _("Searching for text is only supported for PDF documents."));
582 gtk_dialog_run (GTK_DIALOG (dialog));
583 gtk_widget_destroy (dialog);
587 ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window)
589 g_return_if_fail (EV_IS_WINDOW (ev_window));
591 if (ev_window->priv->document == NULL) {
592 g_printerr ("We should have set the Find menu item insensitive since there's no document\n");
593 } else if (!EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
594 find_not_supported_dialog (ev_window);
596 gtk_widget_show (ev_window->priv->find_bar);
598 if (ev_window->priv->exit_fullscreen_popup)
599 update_fullscreen_popup (ev_window);
601 egg_find_bar_grab_focus (EGG_FIND_BAR (ev_window->priv->find_bar));
606 ev_window_cmd_edit_copy (GtkAction *action, EvWindow *ev_window)
608 g_return_if_fail (EV_IS_WINDOW (ev_window));
614 update_fullscreen_popup (EvWindow *window)
616 GtkWidget *popup = window->priv->exit_fullscreen_popup;
617 int popup_width, popup_height;
618 GdkRectangle screen_rect;
620 g_return_if_fail (popup != NULL);
625 popup_width = popup->requisition.width;
626 popup_height = popup->requisition.height;
628 /* FIXME multihead */
629 gdk_screen_get_monitor_geometry (gdk_screen_get_default (),
630 gdk_screen_get_monitor_at_window
631 (gdk_screen_get_default (),
632 GTK_WIDGET (window)->window),
635 if (GTK_WIDGET_VISIBLE (window->priv->find_bar)) {
638 gtk_widget_size_request (window->priv->find_bar, &req);
640 screen_rect.height -= req.height;
643 if (gtk_widget_get_direction (popup) == GTK_TEXT_DIR_RTL)
645 gtk_window_move (GTK_WINDOW (popup),
646 screen_rect.x + screen_rect.width - popup_width,
647 screen_rect.height - popup_height);
651 gtk_window_move (GTK_WINDOW (popup),
652 screen_rect.x, screen_rect.height - popup_height);
657 screen_size_changed_cb (GdkScreen *screen,
660 update_fullscreen_popup (window);
664 destroy_exit_fullscreen_popup (EvWindow *window)
666 if (window->priv->exit_fullscreen_popup != NULL)
668 /* FIXME multihead */
669 g_signal_handlers_disconnect_by_func
670 (gdk_screen_get_default (),
671 G_CALLBACK (screen_size_changed_cb), window);
673 gtk_widget_destroy (window->priv->exit_fullscreen_popup);
674 window->priv->exit_fullscreen_popup = NULL;
679 exit_fullscreen_button_clicked_cb (GtkWidget *button, EvWindow *window)
683 action = gtk_action_group_get_action (window->priv->action_group, "ViewFullscreen");
684 g_return_if_fail (action != NULL);
686 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), FALSE);
690 fullscreen_popup_size_request_cb (GtkWidget *popup, GtkRequisition *req, EvWindow *window)
692 update_fullscreen_popup (window);
696 ev_window_fullscreen (EvWindow *window)
698 GtkWidget *popup, *button, *icon, *label, *hbox, *main_menu;
700 window->priv->fullscreen_mode = TRUE;
702 popup = gtk_window_new (GTK_WINDOW_POPUP);
703 window->priv->exit_fullscreen_popup = popup;
705 button = gtk_button_new ();
706 g_signal_connect (button, "clicked",
707 G_CALLBACK (exit_fullscreen_button_clicked_cb),
709 gtk_widget_show (button);
710 gtk_container_add (GTK_CONTAINER (popup), button);
712 hbox = gtk_hbox_new (FALSE, 2);
713 gtk_widget_show (hbox);
714 gtk_container_add (GTK_CONTAINER (button), hbox);
716 icon = gtk_image_new_from_stock (GTK_STOCK_QUIT, GTK_ICON_SIZE_BUTTON);
717 gtk_widget_show (icon);
718 gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
720 label = gtk_label_new (_("Exit Fullscreen"));
721 gtk_widget_show (label);
722 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
724 gtk_window_set_resizable (GTK_WINDOW (popup), FALSE);
726 /* FIXME multihead */
727 g_signal_connect (gdk_screen_get_default (), "size-changed",
728 G_CALLBACK (screen_size_changed_cb), window);
729 g_signal_connect (popup, "size_request",
730 G_CALLBACK (fullscreen_popup_size_request_cb), window);
732 main_menu = gtk_ui_manager_get_widget (window->priv->ui_manager, "/MainMenu");
733 gtk_widget_hide (main_menu);
734 gtk_widget_hide (window->priv->statusbar);
736 update_fullscreen_popup (window);
738 gtk_widget_show (popup);
742 ev_window_unfullscreen (EvWindow *window)
744 GtkWidget *main_menu;
746 window->priv->fullscreen_mode = FALSE;
748 main_menu = gtk_ui_manager_get_widget (window->priv->ui_manager, "/MainMenu");
749 gtk_widget_show (main_menu);
750 gtk_widget_show (window->priv->statusbar);
752 destroy_exit_fullscreen_popup (window);
756 ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *ev_window)
760 g_return_if_fail (EV_IS_WINDOW (ev_window));
762 fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
765 gtk_window_fullscreen (GTK_WINDOW (ev_window));
767 gtk_window_unfullscreen (GTK_WINDOW (ev_window));
772 ev_window_state_event_cb (GtkWidget *widget, GdkEventWindowState *event, EvWindow *window)
774 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
776 GtkActionGroup *action_group;
780 fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
784 ev_window_fullscreen (window);
788 ev_window_unfullscreen (window);
791 action_group = window->priv->action_group;
793 action = gtk_action_group_get_action (action_group, "ViewFullscreen");
794 g_signal_handlers_block_by_func
795 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
796 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), fullscreen);
797 g_signal_handlers_unblock_by_func
798 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
806 ev_window_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *ev_window)
808 gtk_window_unfullscreen (GTK_WINDOW (ev_window));
815 ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window)
817 g_return_if_fail (EV_IS_WINDOW (ev_window));
819 ev_view_zoom_in (EV_VIEW (ev_window->priv->view));
823 ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window)
825 g_return_if_fail (EV_IS_WINDOW (ev_window));
827 ev_view_zoom_out (EV_VIEW (ev_window->priv->view));
831 ev_window_cmd_view_normal_size (GtkAction *action, EvWindow *ev_window)
833 g_return_if_fail (EV_IS_WINDOW (ev_window));
835 ev_view_normal_size (EV_VIEW (ev_window->priv->view));
839 ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
841 g_return_if_fail (EV_IS_WINDOW (ev_window));
843 ev_view_best_fit (EV_VIEW (ev_window->priv->view));
847 ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
849 g_return_if_fail (EV_IS_WINDOW (ev_window));
851 ev_view_fit_width (EV_VIEW (ev_window->priv->view));
855 ev_window_cmd_go_back (GtkAction *action, EvWindow *ev_window)
857 g_return_if_fail (EV_IS_WINDOW (ev_window));
863 ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window)
865 g_return_if_fail (EV_IS_WINDOW (ev_window));
871 ev_window_cmd_go_page_up (GtkAction *action, EvWindow *ev_window)
873 g_return_if_fail (EV_IS_WINDOW (ev_window));
875 ev_view_set_page (EV_VIEW (ev_window->priv->view),
876 ev_view_get_page (EV_VIEW (ev_window->priv->view)) - 1);
880 ev_window_cmd_go_page_down (GtkAction *action, EvWindow *ev_window)
882 g_return_if_fail (EV_IS_WINDOW (ev_window));
884 ev_view_set_page (EV_VIEW (ev_window->priv->view),
885 ev_view_get_page (EV_VIEW (ev_window->priv->view)) + 1);
889 ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
891 g_return_if_fail (EV_IS_WINDOW (ev_window));
893 ev_view_set_page (EV_VIEW (ev_window->priv->view), 1);
897 ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
899 g_return_if_fail (EV_IS_WINDOW (ev_window));
901 ev_view_set_page (EV_VIEW (ev_window->priv->view), G_MAXINT);
905 ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
907 g_return_if_fail (EV_IS_WINDOW (ev_window));
913 ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
915 const char *authors[] = {
920 const char *documenters[] = {
921 N_("Not so many..."),
925 const char *license[] = {
926 N_("Evince is free software; you can redistribute it and/or modify\n"
927 "it under the terms of the GNU General Public License as published by\n"
928 "the Free Software Foundation; either version 2 of the License, or\n"
929 "(at your option) any later version.\n"),
930 N_("Evince is distributed in the hope that it will be useful,\n"
931 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
932 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
933 "GNU General Public License for more details.\n"),
934 N_("You should have received a copy of the GNU General Public License\n"
935 "along with Evince; if not, write to the Free Software Foundation, Inc.,\n"
936 "59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n")
944 for (p = authors; *p; ++p)
947 for (p = documenters; *p; ++p)
951 license_trans = g_strconcat (_(license[0]), "\n", _(license[1]), "\n",
952 _(license[2]), "\n", NULL);
954 gtk_show_about_dialog (
955 GTK_WINDOW (ev_window),
959 _("\xc2\xa9 1996-2004 The Evince authors"),
960 "license", license_trans,
961 "website", "http://www.gnome.org/projects/evince",
962 "comments", _("PostScript and PDF File Viewer."),
964 "documenters", documenters,
965 "translator-credits", _("translator-credits"),
968 g_free (license_trans);
972 ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window)
975 G_OBJECT (gtk_ui_manager_get_widget (
976 ev_window->priv->ui_manager,
979 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
984 ev_window_view_statusbar_cb (GtkAction *action, EvWindow *ev_window)
987 ev_window->priv->statusbar,
989 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
994 ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window)
997 ev_window->priv->sidebar,
999 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
1004 menu_item_select_cb (GtkMenuItem *proxy, EvWindow *ev_window)
1009 action = g_object_get_data (G_OBJECT (proxy), "gtk-action");
1010 g_return_if_fail (action != NULL);
1012 g_object_get (G_OBJECT (action), "tooltip", &message, NULL);
1014 gtk_statusbar_push (GTK_STATUSBAR (ev_window->priv->statusbar),
1015 ev_window->priv->help_message_cid, message);
1021 menu_item_deselect_cb (GtkMenuItem *proxy, EvWindow *ev_window)
1023 gtk_statusbar_pop (GTK_STATUSBAR (ev_window->priv->statusbar),
1024 ev_window->priv->help_message_cid);
1028 connect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
1029 GtkWidget *proxy, EvWindow *ev_window)
1031 if (GTK_IS_MENU_ITEM (proxy)) {
1032 g_signal_connect (proxy, "select",
1033 G_CALLBACK (menu_item_select_cb), ev_window);
1034 g_signal_connect (proxy, "deselect",
1035 G_CALLBACK (menu_item_deselect_cb),
1041 disconnect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
1042 GtkWidget *proxy, EvWindow *ev_window)
1044 if (GTK_IS_MENU_ITEM (proxy)) {
1045 g_signal_handlers_disconnect_by_func
1046 (proxy, G_CALLBACK (menu_item_select_cb), ev_window);
1047 g_signal_handlers_disconnect_by_func
1048 (proxy, G_CALLBACK (menu_item_deselect_cb), ev_window);
1053 update_current_page (EvWindow *ev_window)
1055 EvPageAction *page_action;
1058 page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
1059 page_action = EV_PAGE_ACTION (ev_window->priv->page_action);
1060 ev_page_action_set_current_page (page_action, page);
1064 view_page_changed_cb (EvView *view,
1065 EvWindow *ev_window)
1067 update_current_page (ev_window);
1068 update_action_sensitivity (ev_window);
1072 view_find_status_changed_cb (EvView *view,
1073 EvWindow *ev_window)
1077 text = ev_view_get_find_status_message (view);
1079 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
1086 find_bar_previous_cb (EggFindBar *find_bar,
1087 EvWindow *ev_window)
1089 /* FIXME - highlight previous result */
1090 g_printerr ("Find Previous\n");
1095 find_bar_next_cb (EggFindBar *find_bar,
1096 EvWindow *ev_window)
1098 /* FIXME - highlight next result */
1099 g_printerr ("Find Next\n");
1103 find_bar_close_cb (EggFindBar *find_bar,
1104 EvWindow *ev_window)
1106 gtk_widget_hide (ev_window->priv->find_bar);
1108 if (ev_window->priv->exit_fullscreen_popup)
1109 update_fullscreen_popup (ev_window);
1113 find_bar_search_changed_cb (EggFindBar *find_bar,
1115 EvWindow *ev_window)
1117 gboolean case_sensitive;
1119 const char *search_string;
1121 g_return_if_fail (EV_IS_WINDOW (ev_window));
1123 /* Either the string or case sensitivity could have changed,
1124 * we connect this callback to both. We also connect it
1125 * to ::visible so when the find bar is hidden, we should
1126 * pretend the search string is NULL/""
1129 case_sensitive = egg_find_bar_get_case_sensitive (find_bar);
1130 visible = GTK_WIDGET_VISIBLE (find_bar);
1131 search_string = egg_find_bar_get_search_string (find_bar);
1134 g_printerr ("search for '%s'\n", search_string ? search_string : "(nil)");
1137 if (ev_window->priv->document &&
1138 EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
1139 if (visible && search_string) {
1140 ev_document_find_begin (EV_DOCUMENT_FIND (ev_window->priv->document), search_string, case_sensitive);
1142 ev_document_find_cancel (EV_DOCUMENT_FIND (ev_window->priv->document));
1143 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
1150 ev_window_dispose (GObject *object)
1152 EvWindowPrivate *priv;
1154 g_return_if_fail (object != NULL && EV_IS_WINDOW (object));
1156 priv = EV_WINDOW (object)->priv;
1158 if (priv->ui_manager) {
1159 g_object_unref (priv->ui_manager);
1160 priv->ui_manager = NULL;
1163 if (priv->action_group) {
1164 g_object_unref (priv->action_group);
1165 priv->action_group = NULL;
1168 G_OBJECT_CLASS (parent_class)->dispose (object);
1172 ev_window_class_init (EvWindowClass *ev_window_class)
1174 GObjectClass *g_object_class;
1176 parent_class = g_type_class_peek_parent (ev_window_class);
1178 g_object_class = G_OBJECT_CLASS (ev_window_class);
1179 g_object_class->dispose = ev_window_dispose;
1181 g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
1184 /* setting up signal system */
1185 ev_window_class->signal = ev_window_signal;
1187 ev_window_signals [SIGNAL] = g_signal_new (
1191 G_STRUCT_OFFSET (EvWindowClass,
1195 g_cclosure_marshal_VOID__STRING,
1198 /* setting up property system */
1199 g_object_class->set_property = ev_window_set_property;
1200 g_object_class->get_property = ev_window_get_property;
1202 g_object_class_install_property (
1205 g_param_spec_string ("attribute",
1207 "A simple unneccessary attribute that "
1208 "does nothing special except being a "
1209 "demonstration for the correct implem"
1210 "entation of a GObject property",
1212 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
1217 static GtkActionEntry entries[] = {
1218 { "File", NULL, N_("_File") },
1219 { "Edit", NULL, N_("_Edit") },
1220 { "View", NULL, N_("_View") },
1221 { "Go", NULL, N_("_Go") },
1222 { "Help", NULL, N_("_Help") },
1225 { "FileOpen", GTK_STOCK_OPEN, N_("_Open"), "<control>O",
1227 G_CALLBACK (ev_window_cmd_file_open) },
1228 { "FileSaveAs", GTK_STOCK_SAVE_AS, N_("_Save a Copy..."), NULL,
1229 N_("Save the current document with a new filename"),
1230 G_CALLBACK (ev_window_cmd_save_as) },
1231 { "FilePrint", GTK_STOCK_PRINT, N_("_Print"), "<control>P",
1232 N_("Print this document"),
1233 G_CALLBACK (ev_window_cmd_file_print) },
1234 { "FileCloseWindow", GTK_STOCK_CLOSE, N_("_Close"), "<control>W",
1235 N_("Close this window"),
1236 G_CALLBACK (ev_window_cmd_file_close_window) },
1239 { "EditCopy", GTK_STOCK_COPY, N_("_Copy"), "<control>C",
1240 N_("Copy text from the document"),
1241 G_CALLBACK (ev_window_cmd_edit_copy) },
1243 { "EditFind", GTK_STOCK_FIND, N_("_Find"), "<control>F",
1244 N_("Find a word or phrase in the document"),
1245 G_CALLBACK (ev_window_cmd_edit_find) },
1248 { "ViewZoomIn", GTK_STOCK_ZOOM_IN, N_("Zoom _In"), "<control>plus",
1249 N_("Enlarge the document"),
1250 G_CALLBACK (ev_window_cmd_view_zoom_in) },
1251 { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, N_("Zoom _Out"), "<control>minus",
1252 N_("Shrink the document"),
1253 G_CALLBACK (ev_window_cmd_view_zoom_out) },
1254 { "ViewNormalSize", GTK_STOCK_ZOOM_100, N_("_Normal Size"), "<control>0",
1255 N_("Zoom to the normal size"),
1256 G_CALLBACK (ev_window_cmd_view_normal_size) },
1257 { "ViewBestFit", GTK_STOCK_ZOOM_FIT, N_("_Best Fit"), NULL,
1258 N_("Zoom to fit the document to the current window"),
1259 G_CALLBACK (ev_window_cmd_view_best_fit) },
1260 { "ViewPageWidth", EV_STOCK_ZOOM_FIT_WIDTH, N_("Fit Page _Width"), NULL,
1261 N_("Zoom to fit the width of the current window "),
1262 G_CALLBACK (ev_window_cmd_view_page_width) },
1265 { "GoBack", GTK_STOCK_GO_BACK, N_("_Back"), "<mod1>Left",
1266 N_("Go to the page viewed before this one"),
1267 G_CALLBACK (ev_window_cmd_go_back) },
1268 { "GoForward", GTK_STOCK_GO_FORWARD, N_("Fo_rward"), "<mod1>Right",
1269 N_("Go to the page viewed before this one"),
1270 G_CALLBACK (ev_window_cmd_go_forward) },
1271 { "GoPageDown", GTK_STOCK_GO_UP, N_("_Page Up"), "<control>Page_Up",
1272 N_("Go to the previous page"),
1273 G_CALLBACK (ev_window_cmd_go_page_up) },
1274 { "GoPageUp", GTK_STOCK_GO_DOWN, N_("_Page Down"), "<control>Page_Down",
1275 N_("Go to the next page"),
1276 G_CALLBACK (ev_window_cmd_go_page_down) },
1277 { "GoFirstPage", GTK_STOCK_GOTO_FIRST, N_("_First Page"), "<control>Home",
1278 N_("Go to the first page"),
1279 G_CALLBACK (ev_window_cmd_go_first_page) },
1280 { "GoLastPage", GTK_STOCK_GOTO_LAST, N_("_Last Page"), "<control>End",
1281 N_("Go to the last page"),
1282 G_CALLBACK (ev_window_cmd_go_last_page) },
1285 { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), NULL,
1286 N_("Display help for the viewer application"),
1287 G_CALLBACK (ev_window_cmd_help_contents) },
1289 { "HelpAbout", GTK_STOCK_ABOUT, N_("_About"), NULL,
1290 N_("Display credits for the document viewer creators"),
1291 G_CALLBACK (ev_window_cmd_help_about) },
1295 static GtkToggleActionEntry toggle_entries[] = {
1297 { "ViewToolbar", NULL, N_("_Toolbar"), "<shift><control>T",
1298 N_("Show or hide toolbar"),
1299 G_CALLBACK (ev_window_view_toolbar_cb), TRUE },
1300 { "ViewStatusbar", NULL, N_("_Statusbar"), NULL,
1301 N_("Show or hide statusbar"),
1302 G_CALLBACK (ev_window_view_statusbar_cb), TRUE },
1303 { "ViewSidebar", NULL, N_("Side_bar"), "F9",
1304 N_("Show or hide sidebar"),
1305 G_CALLBACK (ev_window_view_sidebar_cb), TRUE },
1306 { "ViewFullscreen", NULL, N_("_Fullscreen"), "F11",
1307 N_("Expand the window to fill the screen"),
1308 G_CALLBACK (ev_window_cmd_view_fullscreen) },
1312 goto_page_cb (GtkAction *action, int page_number, EvWindow *ev_window)
1315 ev_view_set_page (EV_VIEW (ev_window->priv->view), page_number);
1319 register_custom_actions (EvWindow *window, GtkActionGroup *group)
1323 action = g_object_new (EV_TYPE_NAVIGATION_ACTION,
1324 "name", "NavigationBack",
1326 "stock_id", GTK_STOCK_GO_BACK,
1327 "tooltip", _("Go back"),
1328 "arrow-tooltip", _("Back history"),
1329 "direction", EV_NAVIGATION_DIRECTION_BACK,
1330 "is_important", TRUE,
1332 gtk_action_group_add_action (group, action);
1333 g_object_unref (action);
1335 action = g_object_new (EV_TYPE_NAVIGATION_ACTION,
1336 "name", "NavigationForward",
1337 "label", _("Forward"),
1338 "stock_id", GTK_STOCK_GO_FORWARD,
1339 "tooltip", _("Go forward"),
1340 "arrow-tooltip", _("Forward history"),
1341 "direction", EV_NAVIGATION_DIRECTION_FORWARD,
1343 gtk_action_group_add_action (group, action);
1344 g_object_unref (action);
1346 action = g_object_new (EV_TYPE_PAGE_ACTION,
1347 "name", "PageSelector",
1349 "tooltip", _("Select Page"),
1351 g_signal_connect (action, "goto_page",
1352 G_CALLBACK (goto_page_cb), window);
1353 window->priv->page_action = action;
1354 gtk_action_group_add_action (group, action);
1355 g_object_unref (action);
1359 ev_window_init (EvWindow *ev_window)
1361 GtkActionGroup *action_group;
1362 GtkAccelGroup *accel_group;
1363 GError *error = NULL;
1364 GtkWidget *scrolled_window;
1367 GtkWidget *sidebar_widget;
1369 ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
1371 update_window_title (NULL, NULL, ev_window);
1373 ev_window->priv->main_box = gtk_vbox_new (FALSE, 0);
1374 gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box);
1375 gtk_widget_show (ev_window->priv->main_box);
1377 action_group = gtk_action_group_new ("MenuActions");
1378 ev_window->priv->action_group = action_group;
1379 gtk_action_group_set_translation_domain (action_group, NULL);
1380 gtk_action_group_add_actions (action_group, entries,
1381 G_N_ELEMENTS (entries), ev_window);
1382 gtk_action_group_add_toggle_actions (action_group, toggle_entries,
1383 G_N_ELEMENTS (toggle_entries),
1386 register_custom_actions (ev_window, action_group);
1388 ev_window->priv->ui_manager = gtk_ui_manager_new ();
1389 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
1393 gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
1394 gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
1396 g_signal_connect (ev_window->priv->ui_manager, "connect_proxy",
1397 G_CALLBACK (connect_proxy_cb), ev_window);
1398 g_signal_connect (ev_window->priv->ui_manager, "disconnect_proxy",
1399 G_CALLBACK (disconnect_proxy_cb), ev_window);
1401 if (!gtk_ui_manager_add_ui_from_file (ev_window->priv->ui_manager,
1402 DATADIR"/evince-ui.xml",
1404 g_message ("building menus failed: %s", error->message);
1405 g_error_free (error);
1408 menubar = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
1410 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), menubar,
1413 toolbar = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
1415 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), toolbar,
1418 /* Add the main area */
1419 ev_window->priv->hpaned = gtk_hpaned_new ();
1420 gtk_widget_show (ev_window->priv->hpaned);
1421 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), ev_window->priv->hpaned,
1424 ev_window->priv->sidebar = ev_sidebar_new ();
1425 gtk_widget_show (ev_window->priv->sidebar);
1426 gtk_paned_add1 (GTK_PANED (ev_window->priv->hpaned),
1427 ev_window->priv->sidebar);
1429 /* Stub sidebar, for now */
1430 sidebar_widget = ev_sidebar_bookmarks_new ();
1431 gtk_widget_show (sidebar_widget);
1432 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
1437 sidebar_widget = ev_sidebar_thumbnails_new ();
1438 gtk_widget_show (sidebar_widget);
1439 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
1444 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1445 gtk_widget_show (scrolled_window);
1446 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1447 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1449 gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned),
1452 ev_window->priv->view = ev_view_new ();
1453 gtk_widget_show (ev_window->priv->view);
1454 gtk_container_add (GTK_CONTAINER (scrolled_window),
1455 ev_window->priv->view);
1456 g_signal_connect (ev_window->priv->view,
1458 G_CALLBACK (view_page_changed_cb),
1460 g_signal_connect (ev_window->priv->view,
1461 "find-status-changed",
1462 G_CALLBACK (view_find_status_changed_cb),
1465 ev_window->priv->statusbar = gtk_statusbar_new ();
1466 gtk_widget_show (ev_window->priv->statusbar);
1467 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
1468 ev_window->priv->statusbar,
1470 ev_window->priv->help_message_cid = gtk_statusbar_get_context_id
1471 (GTK_STATUSBAR (ev_window->priv->statusbar), "help_message");
1473 ev_window->priv->find_bar = egg_find_bar_new ();
1474 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
1475 ev_window->priv->find_bar,
1478 /* Connect to find bar signals */
1479 g_signal_connect (ev_window->priv->find_bar,
1481 G_CALLBACK (find_bar_previous_cb),
1483 g_signal_connect (ev_window->priv->find_bar,
1485 G_CALLBACK (find_bar_next_cb),
1487 g_signal_connect (ev_window->priv->find_bar,
1489 G_CALLBACK (find_bar_close_cb),
1491 g_signal_connect (ev_window->priv->find_bar,
1492 "notify::search-string",
1493 G_CALLBACK (find_bar_search_changed_cb),
1495 g_signal_connect (ev_window->priv->find_bar,
1496 "notify::case-sensitive",
1497 G_CALLBACK (find_bar_search_changed_cb),
1499 g_signal_connect (ev_window->priv->find_bar,
1501 G_CALLBACK (find_bar_search_changed_cb),
1504 g_signal_connect (ev_window, "window-state-event",
1505 G_CALLBACK (ev_window_state_event_cb),
1507 g_signal_connect (ev_window, "focus_out_event",
1508 G_CALLBACK (ev_window_focus_out_cb),
1511 /* Give focus to the scrolled window */
1512 gtk_widget_grab_focus (scrolled_window);
1514 update_action_sensitivity (ev_window);