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));
550 g_object_unref (print_job);
555 ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
557 ev_window_print (ev_window);
561 ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
563 g_return_if_fail (EV_IS_WINDOW (ev_window));
565 gtk_widget_destroy (GTK_WIDGET (ev_window));
569 find_not_supported_dialog (EvWindow *ev_window)
573 /* If you change this so it isn't modal, be sure you don't
574 * allow multiple copies of the dialog...
577 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
578 GTK_DIALOG_DESTROY_WITH_PARENT,
581 _("The \"Find\" feature will not work with this document"));
582 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
583 _("Searching for text is only supported for PDF documents."));
584 gtk_dialog_run (GTK_DIALOG (dialog));
585 gtk_widget_destroy (dialog);
589 ev_window_cmd_edit_select_all (GtkAction *action, EvWindow *ev_window)
591 g_return_if_fail (EV_IS_WINDOW (ev_window));
593 ev_view_select_all (EV_VIEW (ev_window->priv->view));
597 ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window)
599 g_return_if_fail (EV_IS_WINDOW (ev_window));
601 if (ev_window->priv->document == NULL) {
602 g_printerr ("We should have set the Find menu item insensitive since there's no document\n");
603 } else if (!EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
604 find_not_supported_dialog (ev_window);
606 gtk_widget_show (ev_window->priv->find_bar);
608 if (ev_window->priv->exit_fullscreen_popup)
609 update_fullscreen_popup (ev_window);
611 egg_find_bar_grab_focus (EGG_FIND_BAR (ev_window->priv->find_bar));
616 ev_window_cmd_edit_copy (GtkAction *action, EvWindow *ev_window)
618 g_return_if_fail (EV_IS_WINDOW (ev_window));
620 ev_view_copy (EV_VIEW (ev_window->priv->view));
624 update_fullscreen_popup (EvWindow *window)
626 GtkWidget *popup = window->priv->exit_fullscreen_popup;
627 int popup_width, popup_height;
628 GdkRectangle screen_rect;
630 g_return_if_fail (popup != NULL);
635 popup_width = popup->requisition.width;
636 popup_height = popup->requisition.height;
638 /* FIXME multihead */
639 gdk_screen_get_monitor_geometry (gdk_screen_get_default (),
640 gdk_screen_get_monitor_at_window
641 (gdk_screen_get_default (),
642 GTK_WIDGET (window)->window),
645 if (GTK_WIDGET_VISIBLE (window->priv->find_bar)) {
648 gtk_widget_size_request (window->priv->find_bar, &req);
650 screen_rect.height -= req.height;
653 if (gtk_widget_get_direction (popup) == GTK_TEXT_DIR_RTL)
655 gtk_window_move (GTK_WINDOW (popup),
656 screen_rect.x + screen_rect.width - popup_width,
657 screen_rect.height - popup_height);
661 gtk_window_move (GTK_WINDOW (popup),
662 screen_rect.x, screen_rect.height - popup_height);
667 screen_size_changed_cb (GdkScreen *screen,
670 update_fullscreen_popup (window);
674 destroy_exit_fullscreen_popup (EvWindow *window)
676 if (window->priv->exit_fullscreen_popup != NULL)
678 /* FIXME multihead */
679 g_signal_handlers_disconnect_by_func
680 (gdk_screen_get_default (),
681 G_CALLBACK (screen_size_changed_cb), window);
683 gtk_widget_destroy (window->priv->exit_fullscreen_popup);
684 window->priv->exit_fullscreen_popup = NULL;
689 exit_fullscreen_button_clicked_cb (GtkWidget *button, EvWindow *window)
693 action = gtk_action_group_get_action (window->priv->action_group, "ViewFullscreen");
694 g_return_if_fail (action != NULL);
696 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), FALSE);
700 fullscreen_popup_size_request_cb (GtkWidget *popup, GtkRequisition *req, EvWindow *window)
702 update_fullscreen_popup (window);
706 ev_window_fullscreen (EvWindow *window)
708 GtkWidget *popup, *button, *icon, *label, *hbox, *main_menu;
710 window->priv->fullscreen_mode = TRUE;
712 popup = gtk_window_new (GTK_WINDOW_POPUP);
713 window->priv->exit_fullscreen_popup = popup;
715 button = gtk_button_new ();
716 g_signal_connect (button, "clicked",
717 G_CALLBACK (exit_fullscreen_button_clicked_cb),
719 gtk_widget_show (button);
720 gtk_container_add (GTK_CONTAINER (popup), button);
722 hbox = gtk_hbox_new (FALSE, 2);
723 gtk_widget_show (hbox);
724 gtk_container_add (GTK_CONTAINER (button), hbox);
726 icon = gtk_image_new_from_stock (GTK_STOCK_QUIT, GTK_ICON_SIZE_BUTTON);
727 gtk_widget_show (icon);
728 gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
730 label = gtk_label_new (_("Exit Fullscreen"));
731 gtk_widget_show (label);
732 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
734 gtk_window_set_resizable (GTK_WINDOW (popup), FALSE);
736 /* FIXME multihead */
737 g_signal_connect (gdk_screen_get_default (), "size-changed",
738 G_CALLBACK (screen_size_changed_cb), window);
739 g_signal_connect (popup, "size_request",
740 G_CALLBACK (fullscreen_popup_size_request_cb), window);
742 main_menu = gtk_ui_manager_get_widget (window->priv->ui_manager, "/MainMenu");
743 gtk_widget_hide (main_menu);
744 gtk_widget_hide (window->priv->statusbar);
746 update_fullscreen_popup (window);
748 gtk_widget_show (popup);
752 ev_window_unfullscreen (EvWindow *window)
754 GtkWidget *main_menu;
756 window->priv->fullscreen_mode = FALSE;
758 main_menu = gtk_ui_manager_get_widget (window->priv->ui_manager, "/MainMenu");
759 gtk_widget_show (main_menu);
760 gtk_widget_show (window->priv->statusbar);
762 destroy_exit_fullscreen_popup (window);
766 ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *ev_window)
770 g_return_if_fail (EV_IS_WINDOW (ev_window));
772 fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
775 gtk_window_fullscreen (GTK_WINDOW (ev_window));
777 gtk_window_unfullscreen (GTK_WINDOW (ev_window));
782 ev_window_state_event_cb (GtkWidget *widget, GdkEventWindowState *event, EvWindow *window)
784 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
786 GtkActionGroup *action_group;
790 fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
794 ev_window_fullscreen (window);
798 ev_window_unfullscreen (window);
801 action_group = window->priv->action_group;
803 action = gtk_action_group_get_action (action_group, "ViewFullscreen");
804 g_signal_handlers_block_by_func
805 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
806 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), fullscreen);
807 g_signal_handlers_unblock_by_func
808 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
816 ev_window_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *ev_window)
818 gtk_window_unfullscreen (GTK_WINDOW (ev_window));
825 ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window)
827 g_return_if_fail (EV_IS_WINDOW (ev_window));
829 ev_view_zoom_in (EV_VIEW (ev_window->priv->view));
833 ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window)
835 g_return_if_fail (EV_IS_WINDOW (ev_window));
837 ev_view_zoom_out (EV_VIEW (ev_window->priv->view));
841 ev_window_cmd_view_normal_size (GtkAction *action, EvWindow *ev_window)
843 g_return_if_fail (EV_IS_WINDOW (ev_window));
845 ev_view_normal_size (EV_VIEW (ev_window->priv->view));
849 ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
851 g_return_if_fail (EV_IS_WINDOW (ev_window));
853 ev_view_best_fit (EV_VIEW (ev_window->priv->view));
857 ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
859 g_return_if_fail (EV_IS_WINDOW (ev_window));
861 ev_view_fit_width (EV_VIEW (ev_window->priv->view));
865 ev_window_cmd_go_back (GtkAction *action, EvWindow *ev_window)
867 g_return_if_fail (EV_IS_WINDOW (ev_window));
873 ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window)
875 g_return_if_fail (EV_IS_WINDOW (ev_window));
881 ev_window_cmd_go_page_up (GtkAction *action, EvWindow *ev_window)
883 g_return_if_fail (EV_IS_WINDOW (ev_window));
885 ev_view_set_page (EV_VIEW (ev_window->priv->view),
886 ev_view_get_page (EV_VIEW (ev_window->priv->view)) - 1);
890 ev_window_cmd_go_page_down (GtkAction *action, EvWindow *ev_window)
892 g_return_if_fail (EV_IS_WINDOW (ev_window));
894 ev_view_set_page (EV_VIEW (ev_window->priv->view),
895 ev_view_get_page (EV_VIEW (ev_window->priv->view)) + 1);
899 ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
901 g_return_if_fail (EV_IS_WINDOW (ev_window));
903 ev_view_set_page (EV_VIEW (ev_window->priv->view), 1);
907 ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
909 g_return_if_fail (EV_IS_WINDOW (ev_window));
911 ev_view_set_page (EV_VIEW (ev_window->priv->view), G_MAXINT);
915 ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
917 g_return_if_fail (EV_IS_WINDOW (ev_window));
923 ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
925 const char *authors[] = {
930 const char *documenters[] = {
931 N_("Not so many..."),
935 const char *license[] = {
936 N_("Evince is free software; you can redistribute it and/or modify\n"
937 "it under the terms of the GNU General Public License as published by\n"
938 "the Free Software Foundation; either version 2 of the License, or\n"
939 "(at your option) any later version.\n"),
940 N_("Evince is distributed in the hope that it will be useful,\n"
941 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
942 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
943 "GNU General Public License for more details.\n"),
944 N_("You should have received a copy of the GNU General Public License\n"
945 "along with Evince; if not, write to the Free Software Foundation, Inc.,\n"
946 "59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n")
954 for (p = authors; *p; ++p)
957 for (p = documenters; *p; ++p)
961 license_trans = g_strconcat (_(license[0]), "\n", _(license[1]), "\n",
962 _(license[2]), "\n", NULL);
964 gtk_show_about_dialog (
965 GTK_WINDOW (ev_window),
969 _("\xc2\xa9 1996-2004 The Evince authors"),
970 "license", license_trans,
971 "website", "http://www.gnome.org/projects/evince",
972 "comments", _("PostScript and PDF File Viewer."),
974 "documenters", documenters,
975 "translator-credits", _("translator-credits"),
978 g_free (license_trans);
982 ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window)
985 G_OBJECT (gtk_ui_manager_get_widget (
986 ev_window->priv->ui_manager,
989 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
994 ev_window_view_statusbar_cb (GtkAction *action, EvWindow *ev_window)
997 ev_window->priv->statusbar,
999 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
1004 ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window)
1007 ev_window->priv->sidebar,
1009 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
1014 menu_item_select_cb (GtkMenuItem *proxy, EvWindow *ev_window)
1019 action = g_object_get_data (G_OBJECT (proxy), "gtk-action");
1020 g_return_if_fail (action != NULL);
1022 g_object_get (G_OBJECT (action), "tooltip", &message, NULL);
1024 gtk_statusbar_push (GTK_STATUSBAR (ev_window->priv->statusbar),
1025 ev_window->priv->help_message_cid, message);
1031 menu_item_deselect_cb (GtkMenuItem *proxy, EvWindow *ev_window)
1033 gtk_statusbar_pop (GTK_STATUSBAR (ev_window->priv->statusbar),
1034 ev_window->priv->help_message_cid);
1038 connect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
1039 GtkWidget *proxy, EvWindow *ev_window)
1041 if (GTK_IS_MENU_ITEM (proxy)) {
1042 g_signal_connect (proxy, "select",
1043 G_CALLBACK (menu_item_select_cb), ev_window);
1044 g_signal_connect (proxy, "deselect",
1045 G_CALLBACK (menu_item_deselect_cb),
1051 disconnect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
1052 GtkWidget *proxy, EvWindow *ev_window)
1054 if (GTK_IS_MENU_ITEM (proxy)) {
1055 g_signal_handlers_disconnect_by_func
1056 (proxy, G_CALLBACK (menu_item_select_cb), ev_window);
1057 g_signal_handlers_disconnect_by_func
1058 (proxy, G_CALLBACK (menu_item_deselect_cb), ev_window);
1063 update_current_page (EvWindow *ev_window)
1065 EvPageAction *page_action;
1068 page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
1069 page_action = EV_PAGE_ACTION (ev_window->priv->page_action);
1070 ev_page_action_set_current_page (page_action, page);
1074 view_page_changed_cb (EvView *view,
1075 EvWindow *ev_window)
1077 update_current_page (ev_window);
1078 update_action_sensitivity (ev_window);
1082 view_find_status_changed_cb (EvView *view,
1083 EvWindow *ev_window)
1087 text = ev_view_get_find_status_message (view);
1089 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
1096 find_bar_previous_cb (EggFindBar *find_bar,
1097 EvWindow *ev_window)
1099 /* FIXME - highlight previous result */
1100 g_printerr ("Find Previous\n");
1105 find_bar_next_cb (EggFindBar *find_bar,
1106 EvWindow *ev_window)
1108 /* FIXME - highlight next result */
1109 g_printerr ("Find Next\n");
1113 find_bar_close_cb (EggFindBar *find_bar,
1114 EvWindow *ev_window)
1116 gtk_widget_hide (ev_window->priv->find_bar);
1118 if (ev_window->priv->exit_fullscreen_popup)
1119 update_fullscreen_popup (ev_window);
1123 find_bar_search_changed_cb (EggFindBar *find_bar,
1125 EvWindow *ev_window)
1127 gboolean case_sensitive;
1129 const char *search_string;
1131 g_return_if_fail (EV_IS_WINDOW (ev_window));
1133 /* Either the string or case sensitivity could have changed,
1134 * we connect this callback to both. We also connect it
1135 * to ::visible so when the find bar is hidden, we should
1136 * pretend the search string is NULL/""
1139 case_sensitive = egg_find_bar_get_case_sensitive (find_bar);
1140 visible = GTK_WIDGET_VISIBLE (find_bar);
1141 search_string = egg_find_bar_get_search_string (find_bar);
1144 g_printerr ("search for '%s'\n", search_string ? search_string : "(nil)");
1147 if (ev_window->priv->document &&
1148 EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
1149 if (visible && search_string) {
1150 ev_document_find_begin (EV_DOCUMENT_FIND (ev_window->priv->document), search_string, case_sensitive);
1152 ev_document_find_cancel (EV_DOCUMENT_FIND (ev_window->priv->document));
1153 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
1160 ev_window_dispose (GObject *object)
1162 EvWindowPrivate *priv;
1164 g_return_if_fail (object != NULL && EV_IS_WINDOW (object));
1166 priv = EV_WINDOW (object)->priv;
1168 if (priv->ui_manager) {
1169 g_object_unref (priv->ui_manager);
1170 priv->ui_manager = NULL;
1173 if (priv->action_group) {
1174 g_object_unref (priv->action_group);
1175 priv->action_group = NULL;
1178 G_OBJECT_CLASS (parent_class)->dispose (object);
1182 ev_window_class_init (EvWindowClass *ev_window_class)
1184 GObjectClass *g_object_class;
1186 parent_class = g_type_class_peek_parent (ev_window_class);
1188 g_object_class = G_OBJECT_CLASS (ev_window_class);
1189 g_object_class->dispose = ev_window_dispose;
1191 g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
1194 /* setting up signal system */
1195 ev_window_class->signal = ev_window_signal;
1197 ev_window_signals [SIGNAL] = g_signal_new (
1201 G_STRUCT_OFFSET (EvWindowClass,
1205 g_cclosure_marshal_VOID__STRING,
1208 /* setting up property system */
1209 g_object_class->set_property = ev_window_set_property;
1210 g_object_class->get_property = ev_window_get_property;
1212 g_object_class_install_property (
1215 g_param_spec_string ("attribute",
1217 "A simple unneccessary attribute that "
1218 "does nothing special except being a "
1219 "demonstration for the correct implem"
1220 "entation of a GObject property",
1222 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
1227 static GtkActionEntry entries[] = {
1228 { "File", NULL, N_("_File") },
1229 { "Edit", NULL, N_("_Edit") },
1230 { "View", NULL, N_("_View") },
1231 { "Go", NULL, N_("_Go") },
1232 { "Help", NULL, N_("_Help") },
1235 { "FileOpen", GTK_STOCK_OPEN, N_("_Open"), "<control>O",
1237 G_CALLBACK (ev_window_cmd_file_open) },
1238 { "FileSaveAs", GTK_STOCK_SAVE_AS, N_("_Save a Copy..."), NULL,
1239 N_("Save the current document with a new filename"),
1240 G_CALLBACK (ev_window_cmd_save_as) },
1241 { "FilePrint", GTK_STOCK_PRINT, N_("_Print"), "<control>P",
1242 N_("Print this document"),
1243 G_CALLBACK (ev_window_cmd_file_print) },
1244 { "FileCloseWindow", GTK_STOCK_CLOSE, N_("_Close"), "<control>W",
1245 N_("Close this window"),
1246 G_CALLBACK (ev_window_cmd_file_close_window) },
1249 { "EditCopy", GTK_STOCK_COPY, N_("_Copy"), "<control>C",
1250 N_("Copy text from the document"),
1251 G_CALLBACK (ev_window_cmd_edit_copy) },
1252 { "EditSelectAll", NULL, N_("Select _All"), "<control>A",
1253 N_("Select the entire page"),
1254 G_CALLBACK (ev_window_cmd_edit_select_all) },
1255 { "EditFind", GTK_STOCK_FIND, N_("_Find"), "<control>F",
1256 N_("Find a word or phrase in the document"),
1257 G_CALLBACK (ev_window_cmd_edit_find) },
1260 { "ViewZoomIn", GTK_STOCK_ZOOM_IN, N_("Zoom _In"), "<control>plus",
1261 N_("Enlarge the document"),
1262 G_CALLBACK (ev_window_cmd_view_zoom_in) },
1263 { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, N_("Zoom _Out"), "<control>minus",
1264 N_("Shrink the document"),
1265 G_CALLBACK (ev_window_cmd_view_zoom_out) },
1266 { "ViewNormalSize", GTK_STOCK_ZOOM_100, N_("_Normal Size"), "<control>0",
1267 N_("Zoom to the normal size"),
1268 G_CALLBACK (ev_window_cmd_view_normal_size) },
1269 { "ViewBestFit", GTK_STOCK_ZOOM_FIT, N_("_Best Fit"), NULL,
1270 N_("Zoom to fit the document to the current window"),
1271 G_CALLBACK (ev_window_cmd_view_best_fit) },
1272 { "ViewPageWidth", EV_STOCK_ZOOM_FIT_WIDTH, N_("Fit Page _Width"), NULL,
1273 N_("Zoom to fit the width of the current window "),
1274 G_CALLBACK (ev_window_cmd_view_page_width) },
1277 { "GoBack", GTK_STOCK_GO_BACK, N_("_Back"), "<mod1>Left",
1278 N_("Go to the page viewed before this one"),
1279 G_CALLBACK (ev_window_cmd_go_back) },
1280 { "GoForward", GTK_STOCK_GO_FORWARD, N_("Fo_rward"), "<mod1>Right",
1281 N_("Go to the page viewed before this one"),
1282 G_CALLBACK (ev_window_cmd_go_forward) },
1283 { "GoPageDown", GTK_STOCK_GO_UP, N_("_Page Up"), "<control>Page_Up",
1284 N_("Go to the previous page"),
1285 G_CALLBACK (ev_window_cmd_go_page_up) },
1286 { "GoPageUp", GTK_STOCK_GO_DOWN, N_("_Page Down"), "<control>Page_Down",
1287 N_("Go to the next page"),
1288 G_CALLBACK (ev_window_cmd_go_page_down) },
1289 { "GoFirstPage", GTK_STOCK_GOTO_FIRST, N_("_First Page"), "<control>Home",
1290 N_("Go to the first page"),
1291 G_CALLBACK (ev_window_cmd_go_first_page) },
1292 { "GoLastPage", GTK_STOCK_GOTO_LAST, N_("_Last Page"), "<control>End",
1293 N_("Go to the last page"),
1294 G_CALLBACK (ev_window_cmd_go_last_page) },
1297 { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), NULL,
1298 N_("Display help for the viewer application"),
1299 G_CALLBACK (ev_window_cmd_help_contents) },
1301 { "HelpAbout", GTK_STOCK_ABOUT, N_("_About"), NULL,
1302 N_("Display credits for the document viewer creators"),
1303 G_CALLBACK (ev_window_cmd_help_about) },
1307 static GtkToggleActionEntry toggle_entries[] = {
1309 { "ViewToolbar", NULL, N_("_Toolbar"), "<shift><control>T",
1310 N_("Show or hide toolbar"),
1311 G_CALLBACK (ev_window_view_toolbar_cb), TRUE },
1312 { "ViewStatusbar", NULL, N_("_Statusbar"), NULL,
1313 N_("Show or hide statusbar"),
1314 G_CALLBACK (ev_window_view_statusbar_cb), TRUE },
1315 { "ViewSidebar", NULL, N_("Side_bar"), "F9",
1316 N_("Show or hide sidebar"),
1317 G_CALLBACK (ev_window_view_sidebar_cb), TRUE },
1318 { "ViewFullscreen", NULL, N_("_Fullscreen"), "F11",
1319 N_("Expand the window to fill the screen"),
1320 G_CALLBACK (ev_window_cmd_view_fullscreen) },
1324 goto_page_cb (GtkAction *action, int page_number, EvWindow *ev_window)
1327 ev_view_set_page (EV_VIEW (ev_window->priv->view), page_number);
1331 register_custom_actions (EvWindow *window, GtkActionGroup *group)
1335 action = g_object_new (EV_TYPE_NAVIGATION_ACTION,
1336 "name", "NavigationBack",
1338 "stock_id", GTK_STOCK_GO_BACK,
1339 "tooltip", _("Go back"),
1340 "arrow-tooltip", _("Back history"),
1341 "direction", EV_NAVIGATION_DIRECTION_BACK,
1342 "is_important", TRUE,
1344 gtk_action_group_add_action (group, action);
1345 g_object_unref (action);
1347 action = g_object_new (EV_TYPE_NAVIGATION_ACTION,
1348 "name", "NavigationForward",
1349 "label", _("Forward"),
1350 "stock_id", GTK_STOCK_GO_FORWARD,
1351 "tooltip", _("Go forward"),
1352 "arrow-tooltip", _("Forward history"),
1353 "direction", EV_NAVIGATION_DIRECTION_FORWARD,
1355 gtk_action_group_add_action (group, action);
1356 g_object_unref (action);
1358 action = g_object_new (EV_TYPE_PAGE_ACTION,
1359 "name", "PageSelector",
1361 "tooltip", _("Select Page"),
1363 g_signal_connect (action, "goto_page",
1364 G_CALLBACK (goto_page_cb), window);
1365 window->priv->page_action = action;
1366 gtk_action_group_add_action (group, action);
1367 g_object_unref (action);
1371 ev_window_init (EvWindow *ev_window)
1373 GtkActionGroup *action_group;
1374 GtkAccelGroup *accel_group;
1375 GError *error = NULL;
1376 GtkWidget *scrolled_window;
1379 GtkWidget *sidebar_widget;
1381 ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
1383 update_window_title (NULL, NULL, ev_window);
1385 ev_window->priv->main_box = gtk_vbox_new (FALSE, 0);
1386 gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box);
1387 gtk_widget_show (ev_window->priv->main_box);
1389 action_group = gtk_action_group_new ("MenuActions");
1390 ev_window->priv->action_group = action_group;
1391 gtk_action_group_set_translation_domain (action_group, NULL);
1392 gtk_action_group_add_actions (action_group, entries,
1393 G_N_ELEMENTS (entries), ev_window);
1394 gtk_action_group_add_toggle_actions (action_group, toggle_entries,
1395 G_N_ELEMENTS (toggle_entries),
1398 register_custom_actions (ev_window, action_group);
1400 ev_window->priv->ui_manager = gtk_ui_manager_new ();
1401 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
1405 gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
1406 gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
1408 g_signal_connect (ev_window->priv->ui_manager, "connect_proxy",
1409 G_CALLBACK (connect_proxy_cb), ev_window);
1410 g_signal_connect (ev_window->priv->ui_manager, "disconnect_proxy",
1411 G_CALLBACK (disconnect_proxy_cb), ev_window);
1413 if (!gtk_ui_manager_add_ui_from_file (ev_window->priv->ui_manager,
1414 DATADIR"/evince-ui.xml",
1416 g_message ("building menus failed: %s", error->message);
1417 g_error_free (error);
1420 menubar = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
1422 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), menubar,
1425 toolbar = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
1427 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), toolbar,
1430 /* Add the main area */
1431 ev_window->priv->hpaned = gtk_hpaned_new ();
1432 gtk_widget_show (ev_window->priv->hpaned);
1433 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), ev_window->priv->hpaned,
1436 ev_window->priv->sidebar = ev_sidebar_new ();
1437 gtk_widget_show (ev_window->priv->sidebar);
1438 gtk_paned_add1 (GTK_PANED (ev_window->priv->hpaned),
1439 ev_window->priv->sidebar);
1441 /* Stub sidebar, for now */
1442 sidebar_widget = ev_sidebar_bookmarks_new ();
1443 gtk_widget_show (sidebar_widget);
1444 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
1449 sidebar_widget = ev_sidebar_thumbnails_new ();
1450 gtk_widget_show (sidebar_widget);
1451 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
1456 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1457 gtk_widget_show (scrolled_window);
1458 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1459 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1461 gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned),
1464 ev_window->priv->view = ev_view_new ();
1465 gtk_widget_show (ev_window->priv->view);
1466 gtk_container_add (GTK_CONTAINER (scrolled_window),
1467 ev_window->priv->view);
1468 g_signal_connect (ev_window->priv->view,
1470 G_CALLBACK (view_page_changed_cb),
1472 g_signal_connect (ev_window->priv->view,
1473 "find-status-changed",
1474 G_CALLBACK (view_find_status_changed_cb),
1477 ev_window->priv->statusbar = gtk_statusbar_new ();
1478 gtk_widget_show (ev_window->priv->statusbar);
1479 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
1480 ev_window->priv->statusbar,
1482 ev_window->priv->help_message_cid = gtk_statusbar_get_context_id
1483 (GTK_STATUSBAR (ev_window->priv->statusbar), "help_message");
1485 ev_window->priv->find_bar = egg_find_bar_new ();
1486 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
1487 ev_window->priv->find_bar,
1490 /* Connect to find bar signals */
1491 g_signal_connect (ev_window->priv->find_bar,
1493 G_CALLBACK (find_bar_previous_cb),
1495 g_signal_connect (ev_window->priv->find_bar,
1497 G_CALLBACK (find_bar_next_cb),
1499 g_signal_connect (ev_window->priv->find_bar,
1501 G_CALLBACK (find_bar_close_cb),
1503 g_signal_connect (ev_window->priv->find_bar,
1504 "notify::search-string",
1505 G_CALLBACK (find_bar_search_changed_cb),
1507 g_signal_connect (ev_window->priv->find_bar,
1508 "notify::case-sensitive",
1509 G_CALLBACK (find_bar_search_changed_cb),
1511 g_signal_connect (ev_window->priv->find_bar,
1513 G_CALLBACK (find_bar_search_changed_cb),
1516 g_signal_connect (ev_window, "window-state-event",
1517 G_CALLBACK (ev_window_state_event_cb),
1519 g_signal_connect (ev_window, "focus_out_event",
1520 G_CALLBACK (ev_window_focus_out_cb),
1523 /* Give focus to the scrolled window */
1524 gtk_widget_grab_focus (scrolled_window);
1526 update_action_sensitivity (ev_window);