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, 2005 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-page-action.h"
33 #include "ev-sidebar.h"
34 #include "ev-sidebar-links.h"
35 #include "ev-sidebar-thumbnails.h"
37 #include "ev-page-view.h"
38 #include "ev-password.h"
39 #include "ev-password-view.h"
40 #include "ev-print-job.h"
41 #include "ev-document-find.h"
42 #include "ev-document-security.h"
43 #include "eggfindbar.h"
45 #include "pdf-document.h"
46 #include "pixbuf-document.h"
47 #include "ps-document.h"
49 #include <glib/gi18n.h>
52 #include <libgnomevfs/gnome-vfs-mime-utils.h>
53 #include <libgnomevfs/gnome-vfs-uri.h>
54 #include <libgnomeprintui/gnome-print-dialog.h>
56 #include <gconf/gconf-client.h>
60 #include "ev-application.h"
61 #include "ev-stock-icons.h"
64 PAGE_MODE_SINGLE_PAGE,
65 PAGE_MODE_CONTINUOUS_PAGE,
70 EV_CHROME_MENUBAR = 1 << 0,
71 EV_CHROME_TOOLBAR = 1 << 1,
72 EV_CHROME_SIDEBAR = 1 << 2,
73 EV_CHROME_FINDBAR = 1 << 3,
74 EV_CHROME_STATUSBAR = 1 << 4,
75 EV_CHROME_NORMAL = EV_CHROME_MENUBAR | EV_CHROME_TOOLBAR | EV_CHROME_SIDEBAR | EV_CHROME_STATUSBAR
78 struct _EvWindowPrivate {
81 GtkWidget *toolbar_dock;
85 GtkWidget *thumbs_sidebar;
87 GtkWidget *scrolled_window;
90 GtkWidget *password_view;
91 GtkActionGroup *action_group;
92 GtkUIManager *ui_manager;
94 guint help_message_cid;
95 guint view_message_cid;
96 GtkWidget *exit_fullscreen_popup;
97 GtkWidget *exit_fullscreen_toolbar;
100 EvDocument *document;
102 EvWindowPageMode page_mode;
103 /* These members are used temporarily when in PAGE_MODE_PASSWORD */
104 EvDocument *password_document;
105 GtkWidget *password_dialog;
109 gboolean fullscreen_mode;
112 static GtkTargetEntry ev_drop_types[] = {
113 { "text/uri-list", 0, 0 }
117 #define EV_WINDOW_GET_PRIVATE(object) \
118 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_WINDOW, EvWindowPrivate))
120 #define PAGE_SELECTOR_ACTION "PageSelector"
122 #define GCONF_CHROME_TOOLBAR "/apps/evince/show_toolbar"
123 #define GCONF_CHROME_SIDEBAR "/apps/evince/show_sidebar"
124 #define GCONF_CHROME_STATUSBAR "/apps/evince/show_statusbar"
126 static void ev_window_update_fullscreen_popup (EvWindow *window);
127 static void ev_window_set_page_mode (EvWindow *window,
128 EvWindowPageMode page_mode);
129 static gboolean start_loading_document (EvWindow *ev_window,
130 EvDocument *document,
134 G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
137 set_action_sensitive (EvWindow *ev_window,
141 GtkAction *action = gtk_action_group_get_action (ev_window->priv->action_group,
143 gtk_action_set_sensitive (action, sensitive);
147 update_action_sensitivity (EvWindow *ev_window)
149 EvDocument *document;
150 EvWindowPageMode page_mode;
153 document = ev_window->priv->document;
154 page_mode = ev_window->priv->page_mode;
156 view = EV_VIEW (ev_window->priv->view);
159 /* "FileOpen": always sensitive */
160 set_action_sensitive (ev_window, "FileSaveAs", document!=NULL);
161 set_action_sensitive (ev_window, "FilePrint", document!=NULL);
162 /* "FileCloseWindow": always sensitive */
165 set_action_sensitive (ev_window, "EditCopy", document!=NULL);
166 set_action_sensitive (ev_window, "EditSelectAll", document!=NULL);
169 set_action_sensitive (ev_window, "EditFind", EV_IS_DOCUMENT_FIND (document));
171 set_action_sensitive (ev_window, "EditFind", FALSE);
174 set_action_sensitive (ev_window, "ViewZoomIn", document!=NULL);
175 set_action_sensitive (ev_window, "ViewZoomOut", document!=NULL);
176 set_action_sensitive (ev_window, "ViewNormalSize", document!=NULL);
177 set_action_sensitive (ev_window, "ViewBestFit", document!=NULL);
178 set_action_sensitive (ev_window, "ViewPageWidth", document!=NULL);
185 page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
186 n_pages = ev_document_get_n_pages (document);
188 set_action_sensitive (ev_window, "GoPreviousPage", page > 1);
189 set_action_sensitive (ev_window, "GoNextPage", page < n_pages);
190 set_action_sensitive (ev_window, "GoFirstPage", page > 1);
191 set_action_sensitive (ev_window, "GoLastPage", page < n_pages);
193 set_action_sensitive (ev_window, "GoFirstPage", FALSE);
194 set_action_sensitive (ev_window, "GoPreviousPage", FALSE);
195 set_action_sensitive (ev_window, "GoNextPage", FALSE);
196 set_action_sensitive (ev_window, "GoLastPage", FALSE);
199 /* Page View radio group */
201 set_action_sensitive (ev_window, "SinglePage", page_mode != PAGE_MODE_PASSWORD);
202 set_action_sensitive (ev_window, "ContinuousPage", page_mode != PAGE_MODE_PASSWORD);
204 set_action_sensitive (ev_window, "SinglePage", FALSE);
205 set_action_sensitive (ev_window, "ContinuousPage", FALSE);
208 /* "HelpContents": always sensitive */
209 /* "HelpAbout": always sensitive */
211 /* Toolbar-specific actions: */
212 set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, document!=NULL);
216 update_chrome_visibility (EvWindow *window)
218 EvWindowPrivate *priv = window->priv;
219 gboolean menubar, toolbar, sidebar, findbar, statusbar;
221 menubar = (priv->chrome & EV_CHROME_MENUBAR) != 0 && !priv->fullscreen_mode;
222 toolbar = (priv->chrome & EV_CHROME_TOOLBAR) != 0;
223 sidebar = (priv->chrome & EV_CHROME_SIDEBAR) != 0;
224 findbar = (priv->chrome & EV_CHROME_FINDBAR) != 0;
225 statusbar = (priv->chrome & EV_CHROME_STATUSBAR) != 0 && !priv->fullscreen_mode;
227 g_object_set (priv->menubar, "visible", menubar, NULL);
228 g_object_set (priv->toolbar_dock, "visible", toolbar, NULL);
229 g_object_set (priv->sidebar, "visible", sidebar, NULL);
230 g_object_set (priv->find_bar, "visible", findbar, NULL);
231 g_object_set (priv->statusbar, "visible", statusbar, NULL);
233 g_object_set (priv->exit_fullscreen_toolbar, "visible", priv->fullscreen_mode, NULL);
234 if (priv->exit_fullscreen_popup != NULL) {
235 g_object_set (priv->exit_fullscreen_popup, "visible", !toolbar, NULL);
240 update_chrome_flag (EvWindow *window, EvChrome flag, const char *pref, gboolean active)
242 EvWindowPrivate *priv = window->priv;
246 priv->chrome |= flag;
249 priv->chrome &= ~flag;
253 client = gconf_client_get_default ();
254 gconf_client_set_bool (client, pref, active, NULL);
255 g_object_unref (client);
258 update_chrome_visibility (window);
262 ev_window_open_page (EvWindow *ev_window, int page)
264 ev_view_set_page (EV_VIEW (ev_window->priv->view), page);
268 ev_window_open_link (EvWindow *ev_window, EvLink *link)
270 ev_view_go_to_link (EV_VIEW (ev_window->priv->view), link);
274 ev_window_is_empty (const EvWindow *ev_window)
276 g_return_val_if_fail (EV_IS_WINDOW (ev_window), FALSE);
278 return ev_window->priv->document == NULL;
282 unable_to_load (EvWindow *ev_window,
283 const char *error_message)
287 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
288 GTK_DIALOG_DESTROY_WITH_PARENT,
291 _("Unable to open document"));
292 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
293 "%s", error_message);
294 gtk_dialog_run (GTK_DIALOG (dialog));
295 gtk_widget_destroy (dialog);
298 /* Would be nice to have this in gdk-pixbuf */
300 mime_type_supported_by_gdk_pixbuf (const gchar *mime_type)
302 GSList *formats, *list;
303 gboolean retval = FALSE;
305 formats = gdk_pixbuf_get_formats ();
309 GdkPixbufFormat *format = list->data;
313 if (gdk_pixbuf_format_is_disabled (format))
316 mime_types = gdk_pixbuf_format_get_mime_types (format);
318 for (i = 0; mime_types[i] != NULL; i++) {
319 if (strcmp (mime_types[i], mime_type) == 0) {
331 g_slist_free (formats);
337 update_window_title (EvDocument *document, GParamSpec *pspec, EvWindow *ev_window)
340 char *doc_title = NULL;
341 gboolean password_needed;
343 password_needed = (ev_window->priv->password_document != NULL);
346 doc_title = ev_document_get_title (document);
348 /* Make sure we get a valid title back */
350 if (doc_title[0] == '\000' ||
351 !g_utf8_validate (doc_title, -1, NULL)) {
357 if (doc_title == NULL && ev_window->priv->uri) {
358 doc_title = g_path_get_basename (ev_window->priv->uri);
361 if (password_needed) {
362 if (doc_title == NULL) {
363 title = g_strdup (_("Document Viewer - Password Required"));
365 title = g_strdup_printf (_("%s - Password Required"), doc_title);
368 if (doc_title == NULL) {
369 title = g_strdup (_("Document Viewer"));
371 title = g_strdup (doc_title);
375 gtk_window_set_title (GTK_WINDOW (ev_window), title);
382 update_total_pages (EvWindow *ev_window)
387 pages = ev_document_get_n_pages (ev_window->priv->document);
388 action = gtk_action_group_get_action
389 (ev_window->priv->action_group, PAGE_SELECTOR_ACTION);
390 ev_page_action_set_total_pages (EV_PAGE_ACTION (action), pages);
393 /* This function assumes that ev_window just had ev_window->document set.
396 ev_window_setup_document (EvWindow *ev_window)
398 EvDocument *document;
399 EvView *view = EV_VIEW (ev_window->priv->view);
400 //EvPageView *page_view = EV_PAGE_VIEW (ev_window->priv->page_view);
401 EvSidebar *sidebar = EV_SIDEBAR (ev_window->priv->sidebar);
403 document = ev_window->priv->document;
405 g_signal_connect_object (G_OBJECT (document),
407 G_CALLBACK (update_window_title),
410 ev_window_set_page_mode (ev_window, PAGE_MODE_SINGLE_PAGE);
412 ev_sidebar_set_document (sidebar, document);
413 ev_view_set_document (view, document);
414 //ev_page_view_set_document (page_view, document);
416 update_window_title (document, NULL, ev_window);
417 update_total_pages (ev_window);
418 update_action_sensitivity (ev_window);
422 password_dialog_response (GtkWidget *password_dialog,
428 if (response_id == GTK_RESPONSE_OK) {
429 EvDocument *document;
432 password = ev_password_dialog_get_password (password_dialog);
434 ev_document_security_set_password (EV_DOCUMENT_SECURITY (ev_window->priv->password_document),
438 document = ev_window->priv->password_document;
439 uri = ev_window->priv->password_uri;
441 ev_window->priv->password_document = NULL;
442 ev_window->priv->password_uri = NULL;
444 if (start_loading_document (ev_window, document, uri)) {
445 gtk_widget_destroy (password_dialog);
448 g_object_unref (document);
454 gtk_widget_set_sensitive (ev_window->priv->password_view, TRUE);
455 gtk_widget_destroy (password_dialog);
458 /* Called either by start_loading_document or by the "unlock" callback on the
459 * password_view page. It assumes that ev_window->priv->password_* has been set
460 * correctly. These are cleared by password_dialog_response() */
463 ev_window_popup_password_dialog (EvWindow *ev_window)
465 g_assert (ev_window->priv->password_document);
466 g_assert (ev_window->priv->password_uri);
468 gtk_widget_set_sensitive (ev_window->priv->password_view, FALSE);
470 update_window_title (ev_window->priv->password_document, NULL, ev_window);
471 if (ev_window->priv->password_dialog == NULL) {
474 file_name = g_path_get_basename (ev_window->priv->password_uri);
475 ev_window->priv->password_dialog =
476 ev_password_dialog_new (GTK_WIDGET (ev_window), file_name);
477 g_object_add_weak_pointer (G_OBJECT (ev_window->priv->password_dialog),
478 (gpointer *) &(ev_window->priv->password_dialog));
479 g_signal_connect (ev_window->priv->password_dialog,
481 G_CALLBACK (password_dialog_response),
484 gtk_widget_show (ev_window->priv->password_dialog);
486 ev_password_dialog_set_bad_pass (ev_window->priv->password_dialog);
490 /* This wil try to load the document. It might be called multiple times on the
491 * same document by the password dialog.
493 * Since the flow of the error dialog is very confusing, we assume that both
494 * document and uri will go away after this function is called, and thus we need
495 * to ref/dup them. Additionally, it needs to clear
496 * ev_window->priv->password_{uri,document}, and thus people who call this
497 * function should _not_ necessarily expect those to exist after being
500 start_loading_document (EvWindow *ev_window,
501 EvDocument *document,
505 GError *error = NULL;
508 g_assert (document != ev_window->priv->document);
510 if (ev_window->priv->password_document) {
511 g_object_unref (ev_window->priv->password_document);
512 ev_window->priv->password_document = NULL;
514 if (ev_window->priv->password_uri) {
515 g_free (ev_window->priv->password_uri);
516 ev_window->priv->password_uri = NULL;
519 result = ev_document_load (document, uri, &error);
523 if (ev_window->priv->document)
524 g_object_unref (ev_window->priv->document);
525 ev_window->priv->document = g_object_ref (document);
526 ev_window_setup_document (ev_window);
531 /* unable to load the document */
532 g_assert (error != NULL);
534 if (error->domain == EV_DOCUMENT_ERROR &&
535 error->code == EV_DOCUMENT_ERROR_ENCRYPTED) {
538 ev_window->priv->password_document = g_object_ref (document);
539 ev_window->priv->password_uri = g_strdup (uri);
541 file_name = g_path_get_basename (uri);
542 ev_password_view_set_file_name (EV_PASSWORD_VIEW (ev_window->priv->password_view),
545 ev_window_set_page_mode (ev_window, PAGE_MODE_PASSWORD);
547 ev_window_popup_password_dialog (ev_window);
549 unable_to_load (ev_window, error->message);
551 g_error_free (error);
557 is_file_supported (const gchar *mime_type)
559 static char *supported_types [] = {
561 "application/postscript",
562 "application/x-gzpostscript",
568 g_return_val_if_fail (mime_type != NULL, FALSE);
570 if (mime_type_supported_by_gdk_pixbuf (mime_type))
573 for (i = 0; supported_types[i] != NULL; i++) {
574 if (g_ascii_strcasecmp (mime_type, supported_types[i]) == 0)
582 ev_window_open (EvWindow *ev_window, const char *uri)
584 EvDocument *document = NULL;
587 g_free (ev_window->priv->uri);
588 ev_window->priv->uri = g_strdup (uri);
590 mime_type = gnome_vfs_get_mime_type (uri);
592 if (mime_type == NULL)
594 else if (!strcmp (mime_type, "application/pdf"))
595 document = g_object_new (PDF_TYPE_DOCUMENT, NULL);
596 else if (!strcmp (mime_type, "application/postscript") ||
597 !strcmp (mime_type, "application/x-gzpostscript") ||
598 !strcmp (mime_type, "image/x-eps"))
599 document = g_object_new (PS_TYPE_DOCUMENT, NULL);
600 else if (mime_type_supported_by_gdk_pixbuf (mime_type))
601 document = g_object_new (PIXBUF_TYPE_DOCUMENT, NULL);
604 start_loading_document (ev_window, document, uri);
605 /* See the comment on start_loading_document on ref counting.
606 * As the password dialog flow is confusing, we're very explicit
607 * on ref counting. */
608 g_object_unref (document);
612 error_message = g_strdup_printf (_("Unhandled MIME type: '%s'"),
613 mime_type?mime_type:"<Unknown MIME Type>");
614 unable_to_load (ev_window, error_message);
615 g_free (error_message);
622 ev_window_open_uri_list (EvWindow *ev_window, GList *uri_list)
625 gchar *uri, *mime_type;
627 g_return_if_fail (uri_list != NULL);
631 uri = gnome_vfs_uri_to_string (list->data, GNOME_VFS_URI_HIDE_NONE);
632 mime_type = gnome_vfs_get_mime_type (uri);
634 if (is_file_supported (mime_type)) {
635 if (ev_window_is_empty (EV_WINDOW (ev_window))) {
636 ev_window_open (ev_window, uri);
638 gtk_widget_show (GTK_WIDGET (ev_window));
640 EvWindow *new_window;
642 new_window = ev_application_new_window (EV_APP);
643 ev_window_open (new_window, uri);
645 gtk_widget_show (GTK_WIDGET (new_window));
652 list = g_list_next (list);
657 ev_window_cmd_file_open (GtkAction *action, EvWindow *ev_window)
659 ev_application_open (EV_APP, NULL);
664 overwrite_existing_file (GtkWindow *window, const gchar *file_name)
667 gchar *utf8_file_name;
671 utf8_file_name = g_filename_to_utf8 (file_name, -1, NULL, NULL, NULL);
672 msgbox = gtk_message_dialog_new (
674 (GtkDialogFlags)GTK_DIALOG_DESTROY_WITH_PARENT,
675 GTK_MESSAGE_QUESTION,
677 _("A file named \"%s\" already exists."),
679 g_free (utf8_file_name);
681 gtk_message_dialog_format_secondary_text (
682 GTK_MESSAGE_DIALOG (msgbox),
683 _("Do you want to replace it with the one you are saving?"));
685 gtk_dialog_add_button (GTK_DIALOG (msgbox),
686 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
688 gtk_dialog_add_button (GTK_DIALOG (msgbox),
689 _("_Replace"), GTK_RESPONSE_YES);
691 gtk_dialog_set_default_response (GTK_DIALOG (msgbox),
692 GTK_RESPONSE_CANCEL);
694 obj = gtk_widget_get_accessible (msgbox);
696 if (GTK_IS_ACCESSIBLE (obj))
697 atk_object_set_name (obj, _("Question"));
699 ret = gtk_dialog_run (GTK_DIALOG (msgbox));
700 gtk_widget_destroy (msgbox);
702 return (ret == GTK_RESPONSE_YES);
707 save_error_dialog (GtkWindow *window, const gchar *file_name)
709 GtkWidget *error_dialog;
711 error_dialog = gtk_message_dialog_new (
713 (GtkDialogFlags)GTK_DIALOG_DESTROY_WITH_PARENT,
716 _("The file could not be saved as \"%s\"."),
719 /* Easy way to make the text bold while keeping the string
720 * above free from pango markup (FIXME ?) */
721 gtk_message_dialog_format_secondary_text (
722 GTK_MESSAGE_DIALOG (error_dialog), " ");
724 gtk_dialog_run (GTK_DIALOG (error_dialog));
725 gtk_widget_destroy (error_dialog);
729 ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
732 GtkFileFilter *pdf_filter, *all_filter;
735 fc = gtk_file_chooser_dialog_new (
737 NULL, GTK_FILE_CHOOSER_ACTION_SAVE,
738 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
739 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
741 gtk_window_set_modal (GTK_WINDOW (fc), TRUE);
743 pdf_filter = gtk_file_filter_new ();
744 gtk_file_filter_set_name (pdf_filter, _("PDF Documents"));
745 gtk_file_filter_add_mime_type (pdf_filter, "application/pdf");
746 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fc), pdf_filter);
748 all_filter = gtk_file_filter_new ();
749 gtk_file_filter_set_name (all_filter, _("All Files"));
750 gtk_file_filter_add_pattern (all_filter, "*");
751 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fc), all_filter);
752 gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (fc), pdf_filter);
754 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
756 gtk_widget_show (fc);
758 while (gtk_dialog_run (GTK_DIALOG (fc)) == GTK_RESPONSE_OK) {
759 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
762 if (g_file_test (uri, G_FILE_TEST_EXISTS) &&
763 !overwrite_existing_file (GTK_WINDOW (fc), uri))
767 if (ev_document_save (ev_window->priv->document, uri, NULL))
770 save_error_dialog (GTK_WINDOW (fc), uri);
772 gtk_widget_destroy (fc);
776 using_postscript_printer (GnomePrintConfig *config)
778 const guchar *driver;
779 const guchar *transport;
781 driver = gnome_print_config_get (
782 config, (const guchar *)"Settings.Engine.Backend.Driver");
784 transport = gnome_print_config_get (
785 config, (const guchar *)"Settings.Transport.Backend");
788 if (!strcmp ((const gchar *)driver, "gnome-print-ps"))
792 } else if (transport) {
793 if (!strcmp ((const gchar *)transport, "CUPS"))
801 ev_window_print (EvWindow *ev_window)
803 GnomePrintConfig *config;
805 GtkWidget *print_dialog;
806 EvPrintJob *print_job = NULL;
808 g_return_if_fail (EV_IS_WINDOW (ev_window));
809 g_return_if_fail (ev_window->priv->document != NULL);
811 config = gnome_print_config_default ();
812 job = gnome_print_job_new (config);
814 print_dialog = gnome_print_dialog_new (job, _("Print"),
815 (GNOME_PRINT_DIALOG_RANGE |
816 GNOME_PRINT_DIALOG_COPIES));
817 gtk_dialog_set_response_sensitive (GTK_DIALOG (print_dialog),
818 GNOME_PRINT_DIALOG_RESPONSE_PREVIEW,
823 response = gtk_dialog_run (GTK_DIALOG (print_dialog));
825 if (response != GNOME_PRINT_DIALOG_RESPONSE_PRINT)
828 /* FIXME: Change this when we have the first backend
829 * that can print more than postscript
831 if (!using_postscript_printer (config)) {
834 dialog = gtk_message_dialog_new (
835 GTK_WINDOW (print_dialog), GTK_DIALOG_MODAL,
836 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
837 _("Printing is not supported on this printer."));
838 gtk_message_dialog_format_secondary_text (
839 GTK_MESSAGE_DIALOG (dialog),
840 _("You were trying to print to a printer using the \"%s\" driver. This program requires a PostScript printer driver."),
841 gnome_print_config_get (
842 config, "Settings.Engine.Backend.Driver"));
843 gtk_dialog_run (GTK_DIALOG (dialog));
844 gtk_widget_destroy (dialog);
849 print_job = g_object_new (EV_TYPE_PRINT_JOB,
850 "gnome_print_job", job,
851 "document", ev_window->priv->document,
852 "print_dialog", print_dialog,
857 gtk_widget_destroy (print_dialog);
859 if (print_job != NULL) {
860 ev_print_job_print (print_job, GTK_WINDOW (ev_window));
861 g_object_unref (print_job);
866 ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
868 ev_window_print (ev_window);
872 ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
874 g_return_if_fail (EV_IS_WINDOW (ev_window));
876 gtk_widget_destroy (GTK_WIDGET (ev_window));
880 find_not_supported_dialog (EvWindow *ev_window)
884 /* If you change this so it isn't modal, be sure you don't
885 * allow multiple copies of the dialog...
888 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
889 GTK_DIALOG_DESTROY_WITH_PARENT,
892 _("The \"Find\" feature will not work with this document"));
893 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
894 _("Searching for text is only supported for PDF documents."));
895 gtk_dialog_run (GTK_DIALOG (dialog));
896 gtk_widget_destroy (dialog);
900 ev_window_cmd_edit_select_all (GtkAction *action, EvWindow *ev_window)
902 g_return_if_fail (EV_IS_WINDOW (ev_window));
904 ev_view_select_all (EV_VIEW (ev_window->priv->view));
908 ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window)
910 g_return_if_fail (EV_IS_WINDOW (ev_window));
912 if (ev_window->priv->document == NULL) {
913 g_printerr ("We should have set the Find menu item insensitive since there's no document\n");
914 } else if (!EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
915 find_not_supported_dialog (ev_window);
917 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, NULL, TRUE);
919 egg_find_bar_grab_focus (EGG_FIND_BAR (ev_window->priv->find_bar));
924 ev_window_cmd_edit_copy (GtkAction *action, EvWindow *ev_window)
926 g_return_if_fail (EV_IS_WINDOW (ev_window));
928 ev_view_copy (EV_VIEW (ev_window->priv->view));
932 ev_window_update_fullscreen_popup (EvWindow *window)
934 GtkWidget *popup = window->priv->exit_fullscreen_popup;
935 int popup_width, popup_height;
936 GdkRectangle screen_rect;
938 g_return_if_fail (popup != NULL);
940 popup_width = popup->requisition.width;
941 popup_height = popup->requisition.height;
943 /* FIXME multihead */
944 gdk_screen_get_monitor_geometry (gdk_screen_get_default (),
945 gdk_screen_get_monitor_at_window
946 (gdk_screen_get_default (),
947 GTK_WIDGET (window)->window),
950 if (gtk_widget_get_direction (popup) == GTK_TEXT_DIR_RTL)
952 gtk_window_move (GTK_WINDOW (popup),
958 gtk_window_move (GTK_WINDOW (popup),
959 screen_rect.x + screen_rect.width - popup_width,
965 screen_size_changed_cb (GdkScreen *screen,
968 ev_window_update_fullscreen_popup (window);
972 destroy_exit_fullscreen_popup (EvWindow *window)
974 if (window->priv->exit_fullscreen_popup != NULL)
976 /* FIXME multihead */
977 g_signal_handlers_disconnect_by_func
978 (gdk_screen_get_default (),
979 G_CALLBACK (screen_size_changed_cb), window);
981 gtk_widget_destroy (window->priv->exit_fullscreen_popup);
982 window->priv->exit_fullscreen_popup = NULL;
987 exit_fullscreen_button_clicked_cb (GtkWidget *button, EvWindow *window)
991 action = gtk_action_group_get_action (window->priv->action_group, "ViewFullscreen");
992 g_return_if_fail (action != NULL);
994 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), FALSE);
998 fullscreen_popup_size_request_cb (GtkWidget *popup, GtkRequisition *req, EvWindow *window)
1000 ev_window_update_fullscreen_popup (window);
1004 ev_window_fullscreen (EvWindow *window)
1006 GtkWidget *popup, *button, *icon, *label, *hbox;
1008 window->priv->fullscreen_mode = TRUE;
1010 g_return_if_fail (window->priv->exit_fullscreen_popup == NULL);
1012 popup = gtk_window_new (GTK_WINDOW_POPUP);
1013 window->priv->exit_fullscreen_popup = popup;
1015 button = gtk_button_new ();
1016 g_signal_connect (button, "clicked",
1017 G_CALLBACK (exit_fullscreen_button_clicked_cb),
1019 gtk_widget_show (button);
1020 gtk_container_add (GTK_CONTAINER (popup), button);
1022 hbox = gtk_hbox_new (FALSE, 2);
1023 gtk_widget_show (hbox);
1024 gtk_container_add (GTK_CONTAINER (button), hbox);
1026 icon = gtk_image_new_from_stock (EV_STOCK_LEAVE_FULLSCREEN, GTK_ICON_SIZE_BUTTON);
1027 gtk_widget_show (icon);
1028 gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
1030 label = gtk_label_new (_("Leave Fullscreen"));
1031 gtk_widget_show (label);
1032 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1034 gtk_window_set_resizable (GTK_WINDOW (popup), FALSE);
1036 /* FIXME multihead */
1037 g_signal_connect (gdk_screen_get_default (), "size-changed",
1038 G_CALLBACK (screen_size_changed_cb), window);
1039 g_signal_connect (popup, "size_request",
1040 G_CALLBACK (fullscreen_popup_size_request_cb), window);
1042 update_chrome_visibility (window);
1044 ev_window_update_fullscreen_popup (window);
1048 ev_window_unfullscreen (EvWindow *window)
1050 window->priv->fullscreen_mode = FALSE;
1052 destroy_exit_fullscreen_popup (window);
1054 update_chrome_visibility (window);
1058 ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *ev_window)
1060 gboolean fullscreen;
1062 g_return_if_fail (EV_IS_WINDOW (ev_window));
1064 fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
1067 gtk_window_fullscreen (GTK_WINDOW (ev_window));
1069 gtk_window_unfullscreen (GTK_WINDOW (ev_window));
1074 ev_window_state_event_cb (GtkWidget *widget, GdkEventWindowState *event, EvWindow *window)
1076 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
1078 GtkActionGroup *action_group;
1080 gboolean fullscreen;
1082 fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
1086 ev_window_fullscreen (window);
1090 ev_window_unfullscreen (window);
1093 action_group = window->priv->action_group;
1095 action = gtk_action_group_get_action (action_group, "ViewFullscreen");
1096 g_signal_handlers_block_by_func
1097 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
1098 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), fullscreen);
1099 g_signal_handlers_unblock_by_func
1100 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
1108 ev_window_focus_in_event (GtkWidget *widget, GdkEventFocus *event)
1110 EvWindow *window = EV_WINDOW (widget);
1111 EvWindowPrivate *priv = window->priv;
1113 if (priv->exit_fullscreen_popup != NULL &&
1114 (priv->chrome & EV_CHROME_TOOLBAR) == 0)
1116 gtk_widget_show (priv->exit_fullscreen_popup);
1119 return GTK_WIDGET_CLASS (ev_window_parent_class)->focus_in_event (widget, event);
1123 ev_window_focus_out_event (GtkWidget *widget, GdkEventFocus *event)
1125 EvWindow *window = EV_WINDOW (widget);
1126 EvWindowPrivate *priv = window->priv;
1128 if (priv->exit_fullscreen_popup != NULL &&
1129 (priv->chrome & EV_CHROME_TOOLBAR) == 0)
1131 gtk_widget_hide (priv->exit_fullscreen_popup);
1134 return GTK_WIDGET_CLASS (ev_window_parent_class)->focus_out_event (widget, event);
1138 ev_window_set_page_mode (EvWindow *window,
1139 EvWindowPageMode page_mode)
1141 GtkWidget *child = NULL;
1142 GtkWidget *real_child;
1144 if (window->priv->page_mode == page_mode)
1147 window->priv->page_mode = page_mode;
1149 switch (page_mode) {
1150 case PAGE_MODE_SINGLE_PAGE:
1151 child = window->priv->view;
1153 case PAGE_MODE_PASSWORD:
1154 child = window->priv->password_view;
1156 case PAGE_MODE_CONTINUOUS_PAGE:
1157 child = window->priv->page_view;
1160 g_assert_not_reached ();
1163 real_child = gtk_bin_get_child (GTK_BIN (window->priv->scrolled_window));
1164 if (child != real_child) {
1165 gtk_container_remove (GTK_CONTAINER (window->priv->scrolled_window),
1167 gtk_container_add (GTK_CONTAINER (window->priv->scrolled_window),
1170 update_action_sensitivity (window);
1174 ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window)
1176 g_return_if_fail (EV_IS_WINDOW (ev_window));
1178 ev_view_zoom_in (EV_VIEW (ev_window->priv->view));
1182 ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window)
1184 g_return_if_fail (EV_IS_WINDOW (ev_window));
1186 ev_view_zoom_out (EV_VIEW (ev_window->priv->view));
1190 ev_window_cmd_view_normal_size (GtkAction *action, EvWindow *ev_window)
1192 g_return_if_fail (EV_IS_WINDOW (ev_window));
1194 ev_view_normal_size (EV_VIEW (ev_window->priv->view));
1198 ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
1200 g_return_if_fail (EV_IS_WINDOW (ev_window));
1202 ev_view_best_fit (EV_VIEW (ev_window->priv->view));
1206 ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
1208 g_return_if_fail (EV_IS_WINDOW (ev_window));
1210 ev_view_fit_width (EV_VIEW (ev_window->priv->view));
1214 ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
1216 g_return_if_fail (EV_IS_WINDOW (ev_window));
1218 ev_view_set_page (EV_VIEW (ev_window->priv->view),
1219 ev_view_get_page (EV_VIEW (ev_window->priv->view)) - 1);
1223 ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
1225 g_return_if_fail (EV_IS_WINDOW (ev_window));
1227 ev_view_set_page (EV_VIEW (ev_window->priv->view),
1228 ev_view_get_page (EV_VIEW (ev_window->priv->view)) + 1);
1232 ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
1234 g_return_if_fail (EV_IS_WINDOW (ev_window));
1236 ev_view_set_page (EV_VIEW (ev_window->priv->view), 1);
1240 ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
1242 g_return_if_fail (EV_IS_WINDOW (ev_window));
1244 ev_view_set_page (EV_VIEW (ev_window->priv->view), G_MAXINT);
1248 ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
1250 g_return_if_fail (EV_IS_WINDOW (ev_window));
1256 ev_window_cmd_leave_fullscreen (GtkAction *action, EvWindow *window)
1258 gtk_window_unfullscreen (GTK_WINDOW (window));
1262 ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
1264 const char *authors[] = {
1269 const char *documenters[] = {
1270 N_("Not so many..."),
1274 const char *license[] = {
1275 N_("Evince is free software; you can redistribute it and/or modify\n"
1276 "it under the terms of the GNU General Public License as published by\n"
1277 "the Free Software Foundation; either version 2 of the License, or\n"
1278 "(at your option) any later version.\n"),
1279 N_("Evince is distributed in the hope that it will be useful,\n"
1280 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1281 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1282 "GNU General Public License for more details.\n"),
1283 N_("You should have received a copy of the GNU General Public License\n"
1284 "along with Evince; if not, write to the Free Software Foundation, Inc.,\n"
1285 "59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n")
1288 char *license_trans;
1293 for (p = authors; *p; ++p)
1296 for (p = documenters; *p; ++p)
1300 license_trans = g_strconcat (_(license[0]), "\n", _(license[1]), "\n",
1301 _(license[2]), "\n", NULL);
1303 gtk_show_about_dialog (
1304 GTK_WINDOW (ev_window),
1305 "name", _("Evince"),
1308 _("\xc2\xa9 1996-2004 The Evince authors"),
1309 "license", license_trans,
1310 "website", "http://www.gnome.org/projects/evince",
1311 "comments", _("PostScript and PDF File Viewer."),
1313 "documenters", documenters,
1314 "translator-credits", _("translator-credits"),
1317 g_free (license_trans);
1321 ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window)
1323 update_chrome_flag (ev_window, EV_CHROME_TOOLBAR,
1324 GCONF_CHROME_TOOLBAR,
1325 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
1329 ev_window_view_statusbar_cb (GtkAction *action, EvWindow *ev_window)
1331 update_chrome_flag (ev_window, EV_CHROME_STATUSBAR,
1332 GCONF_CHROME_STATUSBAR,
1333 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
1337 ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window)
1339 update_chrome_flag (ev_window, EV_CHROME_SIDEBAR,
1340 GCONF_CHROME_SIDEBAR,
1341 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
1345 menu_item_select_cb (GtkMenuItem *proxy, EvWindow *ev_window)
1350 action = g_object_get_data (G_OBJECT (proxy), "gtk-action");
1351 g_return_if_fail (action != NULL);
1353 g_object_get (G_OBJECT (action), "tooltip", &message, NULL);
1355 gtk_statusbar_push (GTK_STATUSBAR (ev_window->priv->statusbar),
1356 ev_window->priv->help_message_cid, message);
1362 menu_item_deselect_cb (GtkMenuItem *proxy, EvWindow *ev_window)
1364 gtk_statusbar_pop (GTK_STATUSBAR (ev_window->priv->statusbar),
1365 ev_window->priv->help_message_cid);
1369 connect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
1370 GtkWidget *proxy, EvWindow *ev_window)
1372 if (GTK_IS_MENU_ITEM (proxy)) {
1373 g_signal_connect (proxy, "select",
1374 G_CALLBACK (menu_item_select_cb), ev_window);
1375 g_signal_connect (proxy, "deselect",
1376 G_CALLBACK (menu_item_deselect_cb),
1382 disconnect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
1383 GtkWidget *proxy, EvWindow *ev_window)
1385 if (GTK_IS_MENU_ITEM (proxy)) {
1386 g_signal_handlers_disconnect_by_func
1387 (proxy, G_CALLBACK (menu_item_select_cb), ev_window);
1388 g_signal_handlers_disconnect_by_func
1389 (proxy, G_CALLBACK (menu_item_deselect_cb), ev_window);
1394 update_current_page (EvWindow *ev_window,
1399 EvSidebarThumbnails *thumbs;
1401 thumbs = EV_SIDEBAR_THUMBNAILS (ev_window->priv->thumbs_sidebar);
1402 ev_sidebar_thumbnails_select_page (thumbs, ev_view_get_page (view));
1404 action = gtk_action_group_get_action
1405 (ev_window->priv->action_group, PAGE_SELECTOR_ACTION);
1407 page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
1408 ev_page_action_set_current_page (EV_PAGE_ACTION (action), page);
1412 view_page_changed_cb (EvView *view,
1413 EvWindow *ev_window)
1415 update_current_page (ev_window, view);
1416 update_action_sensitivity (ev_window);
1420 view_status_changed_cb (EvView *view,
1422 EvWindow *ev_window)
1424 const char *message;
1426 gtk_statusbar_pop (GTK_STATUSBAR (ev_window->priv->statusbar),
1427 ev_window->priv->view_message_cid);
1429 message = ev_view_get_status (view);
1431 gtk_statusbar_push (GTK_STATUSBAR (ev_window->priv->statusbar),
1432 ev_window->priv->view_message_cid, message);
1437 view_find_status_changed_cb (EvView *view,
1439 EvWindow *ev_window)
1443 text = ev_view_get_find_status (view);
1444 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
1449 find_bar_previous_cb (EggFindBar *find_bar,
1450 EvWindow *ev_window)
1452 ev_view_find_previous (EV_VIEW (ev_window->priv->view));
1456 find_bar_next_cb (EggFindBar *find_bar,
1457 EvWindow *ev_window)
1459 ev_view_find_next (EV_VIEW (ev_window->priv->view));
1463 find_bar_close_cb (EggFindBar *find_bar,
1464 EvWindow *ev_window)
1466 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, NULL, FALSE);
1470 ev_window_page_mode_cb (GtkRadioAction *action,
1471 GtkRadioAction *activated_action,
1476 mode = gtk_radio_action_get_current_value (action);
1478 g_assert (mode == PAGE_MODE_CONTINUOUS_PAGE ||
1479 mode == PAGE_MODE_SINGLE_PAGE);
1481 ev_window_set_page_mode (window, (EvWindowPageMode) mode);
1485 find_bar_search_changed_cb (EggFindBar *find_bar,
1487 EvWindow *ev_window)
1489 gboolean case_sensitive;
1491 const char *search_string;
1493 g_return_if_fail (EV_IS_WINDOW (ev_window));
1495 /* Either the string or case sensitivity could have changed,
1496 * we connect this callback to both. We also connect it
1497 * to ::visible so when the find bar is hidden, we should
1498 * pretend the search string is NULL/""
1501 case_sensitive = egg_find_bar_get_case_sensitive (find_bar);
1502 visible = GTK_WIDGET_VISIBLE (find_bar);
1503 search_string = egg_find_bar_get_search_string (find_bar);
1506 g_printerr ("search for '%s'\n", search_string ? search_string : "(nil)");
1509 if (ev_window->priv->document &&
1510 EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
1511 if (visible && search_string) {
1512 ev_document_find_begin (EV_DOCUMENT_FIND (ev_window->priv->document), search_string, case_sensitive);
1514 ev_document_find_cancel (EV_DOCUMENT_FIND (ev_window->priv->document));
1515 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
1517 gtk_widget_queue_draw (GTK_WIDGET (ev_window->priv->view));
1523 ev_window_dispose (GObject *object)
1525 EvWindow *window = EV_WINDOW (object);
1526 EvWindowPrivate *priv = window->priv;
1528 if (priv->ui_manager) {
1529 g_object_unref (priv->ui_manager);
1530 priv->ui_manager = NULL;
1533 if (priv->action_group) {
1534 g_object_unref (priv->action_group);
1535 priv->action_group = NULL;
1538 if (priv->document) {
1539 g_object_unref (priv->document);
1540 priv->document = NULL;
1544 g_object_unref (priv->view);
1548 if (priv->page_view) {
1549 g_object_unref (priv->page_view);
1550 priv->page_view = NULL;
1553 if (priv->password_document) {
1554 g_object_unref (priv->password_document);
1555 priv->password_document = NULL;
1558 if (priv->password_uri) {
1559 g_free (priv->password_uri);
1560 priv->password_uri = NULL;
1563 destroy_exit_fullscreen_popup (window);
1565 G_OBJECT_CLASS (ev_window_parent_class)->dispose (object);
1569 ev_window_class_init (EvWindowClass *ev_window_class)
1571 GObjectClass *g_object_class = G_OBJECT_CLASS (ev_window_class);
1572 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (ev_window_class);
1574 g_object_class->dispose = ev_window_dispose;
1576 widget_class->focus_in_event = ev_window_focus_in_event;
1577 widget_class->focus_out_event = ev_window_focus_out_event;
1579 g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
1583 static GtkActionEntry entries[] = {
1584 { "File", NULL, N_("_File") },
1585 { "Edit", NULL, N_("_Edit") },
1586 { "View", NULL, N_("_View") },
1587 { "Go", NULL, N_("_Go") },
1588 { "Help", NULL, N_("_Help") },
1591 { "FileOpen", GTK_STOCK_OPEN, NULL, "<control>O",
1592 N_("Open an existing document"),
1593 G_CALLBACK (ev_window_cmd_file_open) },
1594 { "FileSaveAs", GTK_STOCK_SAVE_AS, N_("_Save a Copy..."), NULL,
1595 N_("Save the current document with a new filename"),
1596 G_CALLBACK (ev_window_cmd_save_as) },
1597 { "FilePrint", GTK_STOCK_PRINT, NULL, "<control>P",
1598 N_("Print this document"),
1599 G_CALLBACK (ev_window_cmd_file_print) },
1600 { "FileCloseWindow", GTK_STOCK_CLOSE, NULL, "<control>W",
1601 N_("Close this window"),
1602 G_CALLBACK (ev_window_cmd_file_close_window) },
1605 { "EditCopy", GTK_STOCK_COPY, NULL, "<control>C",
1606 N_("Copy text from the document"),
1607 G_CALLBACK (ev_window_cmd_edit_copy) },
1608 { "EditSelectAll", NULL, N_("Select _All"), "<control>A",
1609 N_("Select the entire page"),
1610 G_CALLBACK (ev_window_cmd_edit_select_all) },
1611 { "EditFind", GTK_STOCK_FIND, NULL, "<control>F",
1612 N_("Find a word or phrase in the document"),
1613 G_CALLBACK (ev_window_cmd_edit_find) },
1616 { "ViewZoomIn", GTK_STOCK_ZOOM_IN, NULL, "<control>plus",
1617 N_("Enlarge the document"),
1618 G_CALLBACK (ev_window_cmd_view_zoom_in) },
1619 { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, NULL, "<control>minus",
1620 N_("Shrink the document"),
1621 G_CALLBACK (ev_window_cmd_view_zoom_out) },
1622 { "ViewNormalSize", GTK_STOCK_ZOOM_100, NULL, "<control>0",
1623 N_("Reset the zoom level to the defaul value"),
1624 G_CALLBACK (ev_window_cmd_view_normal_size) },
1625 { "ViewBestFit", EV_STOCK_ZOOM_PAGE, N_("_Best Fit"), NULL,
1626 N_("Make the current document fill the window"),
1627 G_CALLBACK (ev_window_cmd_view_best_fit) },
1628 { "ViewPageWidth", EV_STOCK_ZOOM_WIDTH, N_("Fit Page _Width"), NULL,
1629 N_("Make the current document fill the window width"),
1630 G_CALLBACK (ev_window_cmd_view_page_width) },
1633 { "GoPreviousPage", GTK_STOCK_GO_BACK, N_("_Previous Page"), "Page_Up",
1634 N_("Go to the previous page"),
1635 G_CALLBACK (ev_window_cmd_go_previous_page) },
1636 { "GoNextPage", GTK_STOCK_GO_FORWARD, N_("_Next Page"), "Page_Down",
1637 N_("Go to the next page"),
1638 G_CALLBACK (ev_window_cmd_go_next_page) },
1639 { "GoFirstPage", GTK_STOCK_GOTO_FIRST, N_("_First Page"), "<control>Home",
1640 N_("Go to the first page"),
1641 G_CALLBACK (ev_window_cmd_go_first_page) },
1642 { "GoLastPage", GTK_STOCK_GOTO_LAST, N_("_Last Page"), "<control>End",
1643 N_("Go to the last page"),
1644 G_CALLBACK (ev_window_cmd_go_last_page) },
1647 { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), NULL,
1648 N_("Display help for the viewer application"),
1649 G_CALLBACK (ev_window_cmd_help_contents) },
1651 { "HelpAbout", GTK_STOCK_ABOUT, N_("_About"), NULL,
1652 N_("Display credits for the document viewer creators"),
1653 G_CALLBACK (ev_window_cmd_help_about) },
1656 { "LeaveFullscreen", EV_STOCK_LEAVE_FULLSCREEN, N_("Leave Fullscreen"), "Escape",
1657 N_("Leave fullscreen mode"),
1658 G_CALLBACK (ev_window_cmd_leave_fullscreen) }
1662 static GtkToggleActionEntry toggle_entries[] = {
1664 { "ViewToolbar", NULL, N_("_Toolbar"), "<shift><control>T",
1665 N_("Show or hide the toolbar"),
1666 G_CALLBACK (ev_window_view_toolbar_cb), TRUE },
1667 { "ViewStatusbar", NULL, N_("_Statusbar"), NULL,
1668 N_("Show or hide the statusbar"),
1669 G_CALLBACK (ev_window_view_statusbar_cb), TRUE },
1670 { "ViewSidebar", NULL, N_("Side _pane"), "F9",
1671 N_("Show or hide the side pane"),
1672 G_CALLBACK (ev_window_view_sidebar_cb), TRUE },
1673 { "ViewFullscreen", NULL, N_("_Fullscreen"), "F11",
1674 N_("Expand the window to fill the screen"),
1675 G_CALLBACK (ev_window_cmd_view_fullscreen) },
1678 static GtkRadioActionEntry page_view_entries[] = {
1679 { "SinglePage", GTK_STOCK_DND, N_("Single"), NULL,
1680 N_("Show the document one page at a time"),
1681 PAGE_MODE_SINGLE_PAGE },
1682 { "ContinuousPage", GTK_STOCK_DND_MULTIPLE, N_("Multi"), NULL,
1683 N_("Show the full document at once"),
1684 PAGE_MODE_CONTINUOUS_PAGE }
1688 goto_page_cb (GtkAction *action, int page_number, EvWindow *ev_window)
1690 EvView *view = EV_VIEW (ev_window->priv->view);
1692 if (ev_view_get_page (view) != page_number) {
1693 ev_view_set_page (view, page_number);
1698 drag_data_received_cb (GtkWidget *widget, GdkDragContext *context,
1699 gint x, gint y, GtkSelectionData *selection_data,
1700 guint info, guint time, gpointer gdata)
1702 GList *uri_list = NULL;
1704 uri_list = gnome_vfs_uri_list_parse ((gchar *) selection_data->data);
1707 ev_window_open_uri_list (EV_WINDOW (widget), uri_list);
1709 gnome_vfs_uri_list_free (uri_list);
1711 gtk_drag_finish (context, TRUE, FALSE, time);
1716 register_custom_actions (EvWindow *window, GtkActionGroup *group)
1720 action = g_object_new (EV_TYPE_PAGE_ACTION,
1721 "name", PAGE_SELECTOR_ACTION,
1723 "tooltip", _("Select Page"),
1725 g_signal_connect (action, "goto_page",
1726 G_CALLBACK (goto_page_cb), window);
1727 gtk_action_group_add_action (group, action);
1728 g_object_unref (action);
1732 set_action_properties (GtkActionGroup *action_group)
1736 action = gtk_action_group_get_action (action_group, "GoPreviousPage");
1737 /*translators: this is the label for toolbar button*/
1738 g_object_set (action, "short_label", _("Previous"), NULL);
1739 g_object_set (action, "is-important", TRUE, NULL);
1740 action = gtk_action_group_get_action (action_group, "GoNextPage");
1741 /*translators: this is the label for toolbar button*/
1742 g_object_set (action, "is-important", TRUE, NULL);
1743 g_object_set (action, "short_label", _("Next"), NULL);
1744 action = gtk_action_group_get_action (action_group, "ViewPageWidth");
1745 /*translators: this is the label for toolbar button*/
1746 g_object_set (action, "short_label", _("Fit Width"), NULL);
1747 action = gtk_action_group_get_action (action_group, "ViewZoomIn");
1749 action = gtk_action_group_get_action (action_group, "LeaveFullscreen");
1750 g_object_set (action, "is-important", TRUE, NULL);
1754 set_chrome_actions (EvWindow *window)
1756 EvWindowPrivate *priv = window->priv;
1757 GtkActionGroup *action_group = priv->action_group;
1760 action= gtk_action_group_get_action (action_group, "ViewToolbar");
1761 g_signal_handlers_block_by_func
1762 (action, G_CALLBACK (ev_window_view_toolbar_cb), window);
1763 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
1764 (priv->chrome & EV_CHROME_TOOLBAR) != 0);
1765 g_signal_handlers_unblock_by_func
1766 (action, G_CALLBACK (ev_window_view_toolbar_cb), window);
1768 action= gtk_action_group_get_action (action_group, "ViewSidebar");
1769 g_signal_handlers_block_by_func
1770 (action, G_CALLBACK (ev_window_view_sidebar_cb), window);
1771 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
1772 (priv->chrome & EV_CHROME_SIDEBAR) != 0);
1773 g_signal_handlers_unblock_by_func
1774 (action, G_CALLBACK (ev_window_view_sidebar_cb), window);
1776 action= gtk_action_group_get_action (action_group, "ViewStatusbar");
1777 g_signal_handlers_block_by_func
1778 (action, G_CALLBACK (ev_window_view_statusbar_cb), window);
1779 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
1780 (priv->chrome & EV_CHROME_STATUSBAR) != 0);
1781 g_signal_handlers_unblock_by_func
1782 (action, G_CALLBACK (ev_window_view_statusbar_cb), window);
1788 GConfClient *client;
1790 EvChrome chrome = EV_CHROME_NORMAL;
1792 client = gconf_client_get_default ();
1794 value = gconf_client_get (client, GCONF_CHROME_TOOLBAR, NULL);
1795 if (value != NULL) {
1796 if (value->type == GCONF_VALUE_BOOL && !gconf_value_get_bool (value)) {
1797 chrome &= ~EV_CHROME_TOOLBAR;
1799 gconf_value_free (value);
1802 value = gconf_client_get (client, GCONF_CHROME_SIDEBAR, NULL);
1803 if (value != NULL) {
1804 if (value->type == GCONF_VALUE_BOOL && !gconf_value_get_bool (value)) {
1805 chrome &= ~EV_CHROME_SIDEBAR;
1807 gconf_value_free (value);
1810 value = gconf_client_get (client, GCONF_CHROME_STATUSBAR, NULL);
1811 if (value != NULL) {
1812 if (value->type == GCONF_VALUE_BOOL && !gconf_value_get_bool (value)) {
1813 chrome &= ~EV_CHROME_STATUSBAR;
1815 gconf_value_free (value);
1818 g_object_unref (client);
1824 ev_window_init (EvWindow *ev_window)
1826 GtkActionGroup *action_group;
1827 GtkAccelGroup *accel_group;
1828 GError *error = NULL;
1829 GtkWidget *sidebar_widget, *toolbar_dock;
1831 ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
1833 ev_window->priv->page_mode = PAGE_MODE_SINGLE_PAGE;
1834 update_window_title (NULL, NULL, ev_window);
1836 ev_window->priv->main_box = gtk_vbox_new (FALSE, 0);
1837 gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box);
1838 gtk_widget_show (ev_window->priv->main_box);
1840 action_group = gtk_action_group_new ("MenuActions");
1841 ev_window->priv->action_group = action_group;
1842 gtk_action_group_set_translation_domain (action_group, NULL);
1843 gtk_action_group_add_actions (action_group, entries,
1844 G_N_ELEMENTS (entries), ev_window);
1845 gtk_action_group_add_toggle_actions (action_group, toggle_entries,
1846 G_N_ELEMENTS (toggle_entries),
1848 gtk_action_group_add_radio_actions (action_group, page_view_entries,
1849 G_N_ELEMENTS (page_view_entries),
1850 ev_window->priv->page_mode,
1851 G_CALLBACK (ev_window_page_mode_cb),
1853 set_action_properties (action_group);
1854 register_custom_actions (ev_window, action_group);
1856 ev_window->priv->ui_manager = gtk_ui_manager_new ();
1857 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
1861 gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
1862 gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
1864 g_signal_connect (ev_window->priv->ui_manager, "connect_proxy",
1865 G_CALLBACK (connect_proxy_cb), ev_window);
1866 g_signal_connect (ev_window->priv->ui_manager, "disconnect_proxy",
1867 G_CALLBACK (disconnect_proxy_cb), ev_window);
1869 if (!gtk_ui_manager_add_ui_from_file (ev_window->priv->ui_manager,
1870 DATADIR"/evince-ui.xml",
1872 g_message ("building menus failed: %s", error->message);
1873 g_error_free (error);
1876 ev_window->priv->menubar =
1877 gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
1879 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
1880 ev_window->priv->menubar,
1883 /* This sucks, but there is no way to have a draw=no, expand=true separator
1884 * in a GtkUIManager-built toolbar. So, just add another toolbar.
1885 * See gtk+ bug 166489.
1887 toolbar_dock = ev_window->priv->toolbar_dock = gtk_hbox_new (FALSE, 0);
1888 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), toolbar_dock,
1890 gtk_widget_show (toolbar_dock);
1892 ev_window->priv->toolbar =
1893 gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
1895 gtk_box_pack_start (GTK_BOX (toolbar_dock), ev_window->priv->toolbar,
1897 gtk_widget_show (ev_window->priv->toolbar);
1899 ev_window->priv->exit_fullscreen_toolbar =
1900 gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
1901 "/LeaveFullscreenToolbar");
1902 gtk_box_pack_start (GTK_BOX (toolbar_dock),
1903 ev_window->priv->exit_fullscreen_toolbar,
1905 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (ev_window->priv->exit_fullscreen_toolbar),
1907 gtk_toolbar_set_style (GTK_TOOLBAR (ev_window->priv->exit_fullscreen_toolbar),
1908 GTK_TOOLBAR_BOTH_HORIZ);
1910 /* Add the main area */
1911 ev_window->priv->hpaned = gtk_hpaned_new ();
1912 gtk_widget_show (ev_window->priv->hpaned);
1913 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), ev_window->priv->hpaned,
1916 ev_window->priv->sidebar = ev_sidebar_new ();
1917 gtk_paned_add1 (GTK_PANED (ev_window->priv->hpaned),
1918 ev_window->priv->sidebar);
1920 /* Stub sidebar, for now */
1921 sidebar_widget = ev_sidebar_links_new ();
1922 gtk_widget_show (sidebar_widget);
1923 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
1928 ev_window->priv->thumbs_sidebar = ev_sidebar_thumbnails_new ();
1929 gtk_widget_show (ev_window->priv->thumbs_sidebar);
1930 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
1933 ev_window->priv->thumbs_sidebar);
1935 ev_window->priv->scrolled_window =
1936 GTK_WIDGET (g_object_new (GTK_TYPE_SCROLLED_WINDOW,
1937 "hscrollbar-policy", GTK_POLICY_AUTOMATIC,
1938 "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
1939 "shadow-type", GTK_SHADOW_IN,
1941 gtk_widget_show (ev_window->priv->scrolled_window);
1943 gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned),
1944 ev_window->priv->scrolled_window);
1946 ev_window->priv->view = ev_view_new ();
1947 //ev_window->priv->page_view = ev_page_view_new ();
1948 ev_window->priv->password_view = ev_password_view_new ();
1949 g_signal_connect_swapped (ev_window->priv->password_view,
1951 G_CALLBACK (ev_window_popup_password_dialog),
1953 gtk_widget_show (ev_window->priv->view);
1954 //gtk_widget_show (ev_window->priv->page_view);
1955 gtk_widget_show (ev_window->priv->password_view);
1957 /* We own a ref on these widgets, as we can swap them in and out */
1958 g_object_ref (ev_window->priv->view);
1959 //g_object_ref (ev_window->priv->page_view);
1960 g_object_ref (ev_window->priv->password_view);
1962 gtk_container_add (GTK_CONTAINER (ev_window->priv->scrolled_window),
1963 ev_window->priv->view);
1964 g_signal_connect (ev_window->priv->view,
1966 G_CALLBACK (view_page_changed_cb),
1968 g_signal_connect (ev_window->priv->view,
1969 "notify::find-status",
1970 G_CALLBACK (view_find_status_changed_cb),
1972 g_signal_connect (ev_window->priv->view,
1974 G_CALLBACK (view_status_changed_cb),
1977 ev_window->priv->statusbar = gtk_statusbar_new ();
1978 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
1979 ev_window->priv->statusbar,
1981 ev_window->priv->help_message_cid = gtk_statusbar_get_context_id
1982 (GTK_STATUSBAR (ev_window->priv->statusbar), "help_message");
1983 ev_window->priv->view_message_cid = gtk_statusbar_get_context_id
1984 (GTK_STATUSBAR (ev_window->priv->statusbar), "view_message");
1986 ev_window->priv->find_bar = egg_find_bar_new ();
1987 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
1988 ev_window->priv->find_bar,
1991 ev_window->priv->chrome = load_chrome ();
1992 set_chrome_actions (ev_window);
1993 update_chrome_visibility (ev_window);
1995 /* Connect to find bar signals */
1996 g_signal_connect (ev_window->priv->find_bar,
1998 G_CALLBACK (find_bar_previous_cb),
2000 g_signal_connect (ev_window->priv->find_bar,
2002 G_CALLBACK (find_bar_next_cb),
2004 g_signal_connect (ev_window->priv->find_bar,
2006 G_CALLBACK (find_bar_close_cb),
2008 g_signal_connect (ev_window->priv->find_bar,
2009 "notify::search-string",
2010 G_CALLBACK (find_bar_search_changed_cb),
2012 g_signal_connect (ev_window->priv->find_bar,
2013 "notify::case-sensitive",
2014 G_CALLBACK (find_bar_search_changed_cb),
2016 g_signal_connect (ev_window->priv->find_bar,
2018 G_CALLBACK (find_bar_search_changed_cb),
2021 g_signal_connect (ev_window, "window-state-event",
2022 G_CALLBACK (ev_window_state_event_cb),
2025 /* Give focus to the scrolled window */
2026 gtk_widget_grab_focus (ev_window->priv->scrolled_window);
2029 gtk_drag_dest_unset (GTK_WIDGET (ev_window));
2030 gtk_drag_dest_set (GTK_WIDGET (ev_window), GTK_DEST_DEFAULT_ALL, ev_drop_types,
2031 sizeof (ev_drop_types) / sizeof (ev_drop_types[0]),
2033 g_signal_connect (G_OBJECT (ev_window), "drag_data_received",
2034 G_CALLBACK (drag_data_received_cb), NULL);
2036 update_action_sensitivity (ev_window);