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-password.h"
38 #include "ev-password-view.h"
39 #include "ev-print-job.h"
40 #include "ev-document-thumbnails.h"
41 #include "ev-document-links.h"
42 #include "ev-document-find.h"
43 #include "ev-document-security.h"
44 #include "ev-job-queue.h"
45 #include "eggfindbar.h"
47 #include "pdf-document.h"
48 #include "pixbuf-document.h"
49 #include "ps-document.h"
51 #include <glib/gi18n.h>
54 #include <libgnomevfs/gnome-vfs-mime-utils.h>
55 #include <libgnomevfs/gnome-vfs-uri.h>
56 #include <libgnomevfs/gnome-vfs-utils.h>
57 #include <libgnomeprintui/gnome-print-dialog.h>
59 #include <gconf/gconf-client.h>
63 #include "ev-application.h"
64 #include "ev-stock-icons.h"
73 PAGE_MODE_SINGLE_PAGE,
74 PAGE_MODE_CONTINUOUS_PAGE,
79 EV_CHROME_MENUBAR = 1 << 0,
80 EV_CHROME_TOOLBAR = 1 << 1,
81 EV_CHROME_SIDEBAR = 1 << 2,
82 EV_CHROME_FINDBAR = 1 << 3,
83 EV_CHROME_STATUSBAR = 1 << 4,
84 EV_CHROME_NORMAL = EV_CHROME_MENUBAR | EV_CHROME_TOOLBAR | EV_CHROME_SIDEBAR | EV_CHROME_STATUSBAR
87 struct _EvWindowPrivate {
90 GtkWidget *toolbar_dock;
94 GtkWidget *thumbs_sidebar;
96 GtkWidget *scrolled_window;
99 GtkWidget *password_view;
100 GtkActionGroup *action_group;
101 GtkUIManager *ui_manager;
102 GtkWidget *statusbar;
103 guint help_message_cid;
104 guint view_message_cid;
105 GtkWidget *fullscreen_toolbar;
106 GtkWidget *fullscreen_popup;
109 EvDocument *document;
110 EvPageCache *page_cache;
112 EvWindowPageMode page_mode;
113 /* These members are used temporarily when in PAGE_MODE_PASSWORD */
114 EvDocument *password_document;
115 GtkWidget *password_dialog;
119 gboolean fullscreen_mode;
120 EvSizingMode sizing_mode;
121 GSource *fullscreen_timeout_source;
124 static GtkTargetEntry ev_drop_types[] = {
125 { "text/uri-list", 0, 0 }
129 #define EV_WINDOW_GET_PRIVATE(object) \
130 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_WINDOW, EvWindowPrivate))
132 #define PAGE_SELECTOR_ACTION "PageSelector"
134 #define GCONF_CHROME_TOOLBAR "/apps/evince/show_toolbar"
135 #define GCONF_CHROME_SIDEBAR "/apps/evince/show_sidebar"
136 #define GCONF_CHROME_STATUSBAR "/apps/evince/show_statusbar"
138 #define GCONF_SIDEBAR_SIZE "/apps/evince/sidebar_size"
139 #define SIDEBAR_DEFAULT_SIZE 132
141 static void ev_window_update_fullscreen_popup (EvWindow *window);
142 static void ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar, GParamSpec *pspec,
143 EvWindow *ev_window);
144 static void ev_window_set_page_mode (EvWindow *window,
145 EvWindowPageMode page_mode);
146 static gboolean start_loading_document (EvWindow *ev_window,
147 EvDocument *document,
149 static void ev_window_set_sizing_mode (EvWindow *ev_window,
150 EvSizingMode sizing_mode);
152 G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
155 set_action_sensitive (EvWindow *ev_window,
159 GtkAction *action = gtk_action_group_get_action (ev_window->priv->action_group,
161 gtk_action_set_sensitive (action, sensitive);
165 update_action_sensitivity (EvWindow *ev_window)
167 EvDocument *document;
168 EvWindowPageMode page_mode;
171 document = ev_window->priv->document;
172 page_mode = ev_window->priv->page_mode;
173 view = EV_VIEW (ev_window->priv->view);
176 /* "FileOpen": always sensitive */
177 set_action_sensitive (ev_window, "FileSaveAs", document!=NULL);
178 set_action_sensitive (ev_window, "FilePrint", document!=NULL);
179 /* "FileCloseWindow": always sensitive */
182 set_action_sensitive (ev_window, "EditCopy", document!=NULL);
183 set_action_sensitive (ev_window, "EditSelectAll", document!=NULL);
186 set_action_sensitive (ev_window, "EditFind", EV_IS_DOCUMENT_FIND (document));
188 set_action_sensitive (ev_window, "EditFind", FALSE);
191 set_action_sensitive (ev_window, "ViewZoomIn", document!=NULL);
192 set_action_sensitive (ev_window, "ViewZoomOut", document!=NULL);
193 set_action_sensitive (ev_window, "ViewNormalSize", document!=NULL);
194 set_action_sensitive (ev_window, "ViewBestFit", document!=NULL);
195 set_action_sensitive (ev_window, "ViewPageWidth", document!=NULL);
196 set_action_sensitive (ev_window, "ViewReload", document!=NULL);
202 page = ev_page_cache_get_current_page (ev_window->priv->page_cache);
203 n_pages = ev_page_cache_get_n_pages (ev_window->priv->page_cache);
205 set_action_sensitive (ev_window, "GoPreviousPage", page > 0);
206 set_action_sensitive (ev_window, "GoNextPage", page < n_pages - 1);
207 set_action_sensitive (ev_window, "GoFirstPage", page > 0);
208 set_action_sensitive (ev_window, "GoLastPage", page < n_pages - 1);
210 set_action_sensitive (ev_window, "GoFirstPage", FALSE);
211 set_action_sensitive (ev_window, "GoPreviousPage", FALSE);
212 set_action_sensitive (ev_window, "GoNextPage", FALSE);
213 set_action_sensitive (ev_window, "GoLastPage", FALSE);
216 /* Page View radio group */
218 set_action_sensitive (ev_window, "SinglePage", page_mode != PAGE_MODE_PASSWORD);
219 set_action_sensitive (ev_window, "ContinuousPage", page_mode != PAGE_MODE_PASSWORD);
221 set_action_sensitive (ev_window, "SinglePage", FALSE);
222 set_action_sensitive (ev_window, "ContinuousPage", FALSE);
225 /* "HelpContents": always sensitive */
226 /* "HelpAbout": always sensitive */
228 /* Toolbar-specific actions: */
229 set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, document!=NULL);
233 set_widget_visibility (GtkWidget *widget, gboolean visible)
235 g_return_if_fail (GTK_IS_WIDGET (widget));
238 gtk_widget_show (widget);
240 gtk_widget_hide (widget);
244 update_chrome_visibility (EvWindow *window)
246 EvWindowPrivate *priv = window->priv;
247 gboolean menubar, toolbar, sidebar, findbar, statusbar, fullscreen_toolbar;
249 menubar = (priv->chrome & EV_CHROME_MENUBAR) != 0 && !priv->fullscreen_mode;
250 toolbar = (priv->chrome & EV_CHROME_TOOLBAR) != 0 && !priv->fullscreen_mode;
251 sidebar = (priv->chrome & EV_CHROME_SIDEBAR) != 0 && !priv->fullscreen_mode;
252 fullscreen_toolbar = (priv->chrome & EV_CHROME_TOOLBAR) != 0;
253 statusbar = (priv->chrome & EV_CHROME_STATUSBAR) != 0 && !priv->fullscreen_mode;
254 findbar = (priv->chrome & EV_CHROME_FINDBAR) != 0;
256 set_widget_visibility (priv->menubar, menubar);
257 set_widget_visibility (priv->toolbar_dock, toolbar);
258 set_widget_visibility (priv->sidebar, sidebar);
259 set_widget_visibility (priv->find_bar, findbar);
260 set_widget_visibility (priv->statusbar, statusbar);
261 set_widget_visibility (priv->fullscreen_toolbar, fullscreen_toolbar);
263 if (priv->fullscreen_popup != NULL) {
264 set_widget_visibility (priv->fullscreen_popup, priv->fullscreen_mode);
269 update_chrome_flag (EvWindow *window, EvChrome flag, const char *pref, gboolean active)
271 EvWindowPrivate *priv = window->priv;
275 priv->chrome |= flag;
278 priv->chrome &= ~flag;
282 client = gconf_client_get_default ();
283 gconf_client_set_bool (client, pref, active, NULL);
284 g_object_unref (client);
287 update_chrome_visibility (window);
291 ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
293 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
294 ev_window_set_sizing_mode (ev_window, EV_SIZING_BEST_FIT);
296 ev_window_set_sizing_mode (ev_window, EV_SIZING_FREE);
301 ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
303 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
304 ev_window_set_sizing_mode (ev_window, EV_SIZING_FIT_WIDTH);
306 ev_window_set_sizing_mode (ev_window, EV_SIZING_FREE);
311 update_sizing_buttons (EvWindow *window)
313 GtkActionGroup *action_group = window->priv->action_group;
315 gboolean best_fit, page_width;
317 switch (window->priv->sizing_mode) {
318 case EV_SIZING_BEST_FIT:
322 case EV_SIZING_FIT_WIDTH:
328 best_fit = page_width = FALSE;
332 action = gtk_action_group_get_action (action_group, "ViewBestFit");
333 g_signal_handlers_block_by_func
334 (action, G_CALLBACK (ev_window_cmd_view_best_fit), window);
335 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), best_fit);
336 g_signal_handlers_unblock_by_func
337 (action, G_CALLBACK (ev_window_cmd_view_best_fit), window);
339 action = gtk_action_group_get_action (action_group, "ViewPageWidth");
340 g_signal_handlers_block_by_func
341 (action, G_CALLBACK (ev_window_cmd_view_page_width), window);
342 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), page_width);
343 g_signal_handlers_unblock_by_func
344 (action, G_CALLBACK (ev_window_cmd_view_page_width), window);
348 ev_window_open_page (EvWindow *ev_window, int page)
350 if (ev_window->priv->page_cache)
351 ev_page_cache_set_current_page (ev_window->priv->page_cache, page);
355 ev_window_open_link (EvWindow *ev_window, EvLink *link)
357 ev_view_go_to_link (EV_VIEW (ev_window->priv->view), link);
361 ev_window_is_empty (const EvWindow *ev_window)
363 g_return_val_if_fail (EV_IS_WINDOW (ev_window), FALSE);
365 return ev_window->priv->document == NULL;
369 unable_to_load (EvWindow *ev_window,
370 const char *error_message)
374 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
375 GTK_DIALOG_DESTROY_WITH_PARENT,
378 _("Unable to open document"));
379 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
380 "%s", error_message);
381 gtk_dialog_run (GTK_DIALOG (dialog));
382 gtk_widget_destroy (dialog);
385 /* Would be nice to have this in gdk-pixbuf */
387 mime_type_supported_by_gdk_pixbuf (const gchar *mime_type)
389 GSList *formats, *list;
390 gboolean retval = FALSE;
392 formats = gdk_pixbuf_get_formats ();
396 GdkPixbufFormat *format = list->data;
400 if (gdk_pixbuf_format_is_disabled (format))
403 mime_types = gdk_pixbuf_format_get_mime_types (format);
405 for (i = 0; mime_types[i] != NULL; i++) {
406 if (strcmp (mime_types[i], mime_type) == 0) {
418 g_slist_free (formats);
424 update_window_title (EvDocument *document, GParamSpec *pspec, EvWindow *ev_window)
427 char *doc_title = NULL;
428 gboolean password_needed;
430 password_needed = (ev_window->priv->password_document != NULL);
432 doc_title = ev_page_cache_get_title (ev_window->priv->page_cache);
434 /* Make sure we get a valid title back */
436 if (doc_title[0] == '\000' ||
437 !g_utf8_validate (doc_title, -1, NULL)) {
447 for (p = doc_title; *p; ++p) {
448 /* an '\n' byte is always ASCII, no need for UTF-8 special casing */
454 if (doc_title == NULL && ev_window->priv->uri) {
457 basename = g_path_get_basename (ev_window->priv->uri);
458 doc_title = gnome_vfs_unescape_string_for_display (basename);
462 if (password_needed) {
463 if (doc_title == NULL) {
464 title = g_strdup (_("Document Viewer - Password Required"));
466 title = g_strdup_printf (_("%s - Password Required"), doc_title);
469 if (doc_title == NULL) {
470 title = g_strdup (_("Document Viewer"));
472 title = g_strdup (doc_title);
476 gtk_window_set_title (GTK_WINDOW (ev_window), title);
483 update_total_pages (EvWindow *ev_window)
488 pages = ev_page_cache_get_n_pages (ev_window->priv->page_cache);
489 action = gtk_action_group_get_action (ev_window->priv->action_group, PAGE_SELECTOR_ACTION);
490 ev_page_action_set_total_pages (EV_PAGE_ACTION (action), pages);
493 /* This function assumes that ev_window just had ev_window->document set.
496 document_supports_sidebar (EvDocument *document)
498 /* FIXME: Remove the (TRUE ||) after links are fixed in poppler-glib */
499 return (EV_IS_DOCUMENT_THUMBNAILS (document) && (EV_IS_DOCUMENT_LINKS (document)));
503 hide_sidebar_and_actions (EvWindow *ev_window)
506 /* Alsthough we update the hiddenness of the sidebar, we don't want to
508 g_signal_handlers_disconnect_by_func (ev_window->priv->sidebar,
509 ev_window_sidebar_visibility_changed_cb,
511 gtk_widget_hide (ev_window->priv->sidebar);
512 action = gtk_action_group_get_action (ev_window->priv->action_group, "ViewSidebar");
513 gtk_action_set_sensitive (action, FALSE);
518 page_changed_cb (EvPageCache *page_cache,
524 action = gtk_action_group_get_action
525 (ev_window->priv->action_group, PAGE_SELECTOR_ACTION);
527 ev_page_action_set_current_page (EV_PAGE_ACTION (action), page);
528 update_action_sensitivity (ev_window);
533 ev_window_setup_document (EvWindow *ev_window)
535 EvDocument *document;
536 EvView *view = EV_VIEW (ev_window->priv->view);
537 EvSidebar *sidebar = EV_SIDEBAR (ev_window->priv->sidebar);
539 document = ev_window->priv->document;
540 ev_window->priv->page_cache = ev_document_get_page_cache (ev_window->priv->document);
541 g_signal_connect (ev_window->priv->page_cache, "page-changed", G_CALLBACK (page_changed_cb), ev_window);
543 g_signal_connect_object (G_OBJECT (document),
545 G_CALLBACK (update_window_title),
548 ev_window_set_page_mode (ev_window, PAGE_MODE_SINGLE_PAGE);
550 if (document_supports_sidebar (document))
551 ev_sidebar_set_document (sidebar, document);
553 hide_sidebar_and_actions (ev_window);
555 ev_view_set_document (view, document);
557 update_window_title (document, NULL, ev_window);
558 update_total_pages (ev_window);
559 update_action_sensitivity (ev_window);
563 password_dialog_response (GtkWidget *password_dialog,
569 if (response_id == GTK_RESPONSE_OK) {
570 EvDocument *document;
573 password = ev_password_dialog_get_password (password_dialog);
575 g_mutex_lock (EV_DOC_MUTEX);
576 ev_document_security_set_password (EV_DOCUMENT_SECURITY (ev_window->priv->password_document),
578 g_mutex_unlock (EV_DOC_MUTEX);
582 document = ev_window->priv->password_document;
583 uri = ev_window->priv->password_uri;
585 ev_window->priv->password_document = NULL;
586 ev_window->priv->password_uri = NULL;
588 if (start_loading_document (ev_window, document, uri)) {
589 gtk_widget_destroy (password_dialog);
592 g_object_unref (document);
598 gtk_widget_set_sensitive (ev_window->priv->password_view, TRUE);
599 gtk_widget_destroy (password_dialog);
602 /* Called either by start_loading_document or by the "unlock" callback on the
603 * password_view page. It assumes that ev_window->priv->password_* has been set
604 * correctly. These are cleared by password_dialog_response() */
607 ev_window_popup_password_dialog (EvWindow *ev_window)
609 g_assert (ev_window->priv->password_document);
610 g_assert (ev_window->priv->password_uri);
612 gtk_widget_set_sensitive (ev_window->priv->password_view, FALSE);
614 update_window_title (ev_window->priv->password_document, NULL, ev_window);
615 if (ev_window->priv->password_dialog == NULL) {
616 gchar *basename, *file_name;
618 basename = g_path_get_basename (ev_window->priv->password_uri);
619 file_name = gnome_vfs_unescape_string_for_display (basename);
620 ev_window->priv->password_dialog =
621 ev_password_dialog_new (GTK_WIDGET (ev_window), file_name);
622 g_object_add_weak_pointer (G_OBJECT (ev_window->priv->password_dialog),
623 (gpointer *) &(ev_window->priv->password_dialog));
624 g_signal_connect (ev_window->priv->password_dialog,
626 G_CALLBACK (password_dialog_response),
630 gtk_widget_show (ev_window->priv->password_dialog);
632 ev_password_dialog_set_bad_pass (ev_window->priv->password_dialog);
636 /* This wil try to load the document. It might be called multiple times on the
637 * same document by the password dialog.
639 * Since the flow of the error dialog is very confusing, we assume that both
640 * document and uri will go away after this function is called, and thus we need
641 * to ref/dup them. Additionally, it needs to clear
642 * ev_window->priv->password_{uri,document}, and thus people who call this
643 * function should _not_ necessarily expect those to exist after being
646 start_loading_document (EvWindow *ev_window,
647 EvDocument *document,
651 GError *error = NULL;
654 g_assert (document != ev_window->priv->document);
656 if (ev_window->priv->password_document) {
657 g_object_unref (ev_window->priv->password_document);
658 ev_window->priv->password_document = NULL;
660 if (ev_window->priv->password_uri) {
661 g_free (ev_window->priv->password_uri);
662 ev_window->priv->password_uri = NULL;
665 result = ev_document_load (document, uri, &error);
669 if (ev_window->priv->document)
670 g_object_unref (ev_window->priv->document);
671 ev_window->priv->document = g_object_ref (document);
672 ev_window_setup_document (ev_window);
677 /* unable to load the document */
678 g_assert (error != NULL);
680 if (error->domain == EV_DOCUMENT_ERROR &&
681 error->code == EV_DOCUMENT_ERROR_ENCRYPTED) {
684 ev_window->priv->password_document = g_object_ref (document);
685 ev_window->priv->password_uri = g_strdup (uri);
687 file_name = g_path_get_basename (uri);
688 ev_password_view_set_file_name (EV_PASSWORD_VIEW (ev_window->priv->password_view),
691 ev_window_set_page_mode (ev_window, PAGE_MODE_PASSWORD);
693 ev_window_popup_password_dialog (ev_window);
695 unable_to_load (ev_window, error->message);
697 g_error_free (error);
703 is_file_supported (const gchar *mime_type)
705 static char *supported_types [] = {
707 "application/postscript",
708 "application/x-gzpostscript",
714 g_return_val_if_fail (mime_type != NULL, FALSE);
716 if (mime_type_supported_by_gdk_pixbuf (mime_type))
719 for (i = 0; supported_types[i] != NULL; i++) {
720 if (g_ascii_strcasecmp (mime_type, supported_types[i]) == 0)
728 ev_window_open (EvWindow *ev_window, const char *uri)
730 EvDocument *document = NULL;
733 g_free (ev_window->priv->uri);
734 ev_window->priv->uri = g_strdup (uri);
736 mime_type = gnome_vfs_get_mime_type (uri);
738 if (mime_type == NULL)
740 else if (!strcmp (mime_type, "application/pdf"))
741 document = g_object_new (PDF_TYPE_DOCUMENT, NULL);
742 else if (!strcmp (mime_type, "application/postscript") ||
743 !strcmp (mime_type, "application/x-gzpostscript") ||
744 !strcmp (mime_type, "image/x-eps"))
745 document = g_object_new (PS_TYPE_DOCUMENT, NULL);
746 else if (mime_type_supported_by_gdk_pixbuf (mime_type))
747 document = g_object_new (PIXBUF_TYPE_DOCUMENT, NULL);
750 start_loading_document (ev_window, document, uri);
751 /* See the comment on start_loading_document on ref counting.
752 * As the password dialog flow is confusing, we're very explicit
753 * on ref counting. */
754 g_object_unref (document);
758 error_message = g_strdup_printf (_("Unhandled MIME type: '%s'"),
759 mime_type?mime_type:"<Unknown MIME Type>");
760 unable_to_load (ev_window, error_message);
761 g_free (error_message);
768 ev_window_open_uri_list (EvWindow *ev_window, GList *uri_list)
771 gchar *uri, *mime_type;
773 g_return_if_fail (uri_list != NULL);
777 uri = gnome_vfs_uri_to_string (list->data, GNOME_VFS_URI_HIDE_NONE);
778 mime_type = gnome_vfs_get_mime_type (uri);
780 if (is_file_supported (mime_type)) {
781 if (ev_window_is_empty (EV_WINDOW (ev_window))) {
782 ev_window_open (ev_window, uri);
784 gtk_widget_show (GTK_WIDGET (ev_window));
786 EvWindow *new_window;
788 new_window = ev_application_new_window (EV_APP);
789 ev_window_open (new_window, uri);
791 gtk_widget_show (GTK_WIDGET (new_window));
798 list = g_list_next (list);
803 ev_window_cmd_file_open (GtkAction *action, EvWindow *ev_window)
805 ev_application_open (EV_APP, NULL);
810 overwrite_existing_file (GtkWindow *window, const gchar *file_name)
813 gchar *utf8_file_name;
817 utf8_file_name = g_filename_to_utf8 (file_name, -1, NULL, NULL, NULL);
818 msgbox = gtk_message_dialog_new (
820 (GtkDialogFlags)GTK_DIALOG_DESTROY_WITH_PARENT,
821 GTK_MESSAGE_QUESTION,
823 _("A file named \"%s\" already exists."),
825 g_free (utf8_file_name);
827 gtk_message_dialog_format_secondary_text (
828 GTK_MESSAGE_DIALOG (msgbox),
829 _("Do you want to replace it with the one you are saving?"));
831 gtk_dialog_add_button (GTK_DIALOG (msgbox),
832 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
834 gtk_dialog_add_button (GTK_DIALOG (msgbox),
835 _("_Replace"), GTK_RESPONSE_YES);
837 gtk_dialog_set_default_response (GTK_DIALOG (msgbox),
838 GTK_RESPONSE_CANCEL);
840 obj = gtk_widget_get_accessible (msgbox);
842 if (GTK_IS_ACCESSIBLE (obj))
843 atk_object_set_name (obj, _("Question"));
845 ret = gtk_dialog_run (GTK_DIALOG (msgbox));
846 gtk_widget_destroy (msgbox);
848 return (ret == GTK_RESPONSE_YES);
853 save_error_dialog (GtkWindow *window, const gchar *file_name)
855 GtkWidget *error_dialog;
857 error_dialog = gtk_message_dialog_new (
859 (GtkDialogFlags)GTK_DIALOG_DESTROY_WITH_PARENT,
862 _("The file could not be saved as \"%s\"."),
865 /* Easy way to make the text bold while keeping the string
866 * above free from pango markup (FIXME ?) */
867 gtk_message_dialog_format_secondary_text (
868 GTK_MESSAGE_DIALOG (error_dialog), " ");
870 gtk_dialog_run (GTK_DIALOG (error_dialog));
871 gtk_widget_destroy (error_dialog);
875 ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
878 GtkFileFilter *pdf_filter, *all_filter;
882 fc = gtk_file_chooser_dialog_new (
884 NULL, GTK_FILE_CHOOSER_ACTION_SAVE,
885 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
886 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
888 gtk_window_set_modal (GTK_WINDOW (fc), TRUE);
890 pdf_filter = gtk_file_filter_new ();
891 gtk_file_filter_set_name (pdf_filter, _("PDF Documents"));
892 gtk_file_filter_add_mime_type (pdf_filter, "application/pdf");
893 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fc), pdf_filter);
895 all_filter = gtk_file_filter_new ();
896 gtk_file_filter_set_name (all_filter, _("All Files"));
897 gtk_file_filter_add_pattern (all_filter, "*");
898 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fc), all_filter);
899 gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (fc), pdf_filter);
901 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
903 gtk_widget_show (fc);
905 while (gtk_dialog_run (GTK_DIALOG (fc)) == GTK_RESPONSE_OK) {
906 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
909 if (g_file_test (uri, G_FILE_TEST_EXISTS) &&
910 !overwrite_existing_file (GTK_WINDOW (fc), uri))
914 g_mutex_lock (EV_DOC_MUTEX);
915 success = ev_document_save (ev_window->priv->document, uri, NULL);
916 g_mutex_unlock (EV_DOC_MUTEX);
921 save_error_dialog (GTK_WINDOW (fc), uri);
923 gtk_widget_destroy (fc);
927 using_postscript_printer (GnomePrintConfig *config)
929 const guchar *driver;
930 const guchar *transport;
932 driver = gnome_print_config_get (
933 config, (const guchar *)"Settings.Engine.Backend.Driver");
935 transport = gnome_print_config_get (
936 config, (const guchar *)"Settings.Transport.Backend");
939 if (!strcmp ((const gchar *)driver, "gnome-print-ps"))
943 } else if (transport) {
944 if (!strcmp ((const gchar *)transport, "CUPS"))
952 ev_window_print (EvWindow *ev_window)
954 GnomePrintConfig *config;
956 GtkWidget *print_dialog;
957 EvPrintJob *print_job = NULL;
959 g_return_if_fail (EV_IS_WINDOW (ev_window));
960 g_return_if_fail (ev_window->priv->document != NULL);
962 config = gnome_print_config_default ();
963 job = gnome_print_job_new (config);
965 print_dialog = gnome_print_dialog_new (job, (guchar *) _("Print"),
966 (GNOME_PRINT_DIALOG_RANGE |
967 GNOME_PRINT_DIALOG_COPIES));
968 gtk_dialog_set_response_sensitive (GTK_DIALOG (print_dialog),
969 GNOME_PRINT_DIALOG_RESPONSE_PREVIEW,
974 response = gtk_dialog_run (GTK_DIALOG (print_dialog));
976 if (response != GNOME_PRINT_DIALOG_RESPONSE_PRINT)
979 /* FIXME: Change this when we have the first backend
980 * that can print more than postscript
982 if (!using_postscript_printer (config)) {
985 dialog = gtk_message_dialog_new (
986 GTK_WINDOW (print_dialog), GTK_DIALOG_MODAL,
987 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
988 _("Printing is not supported on this printer."));
989 gtk_message_dialog_format_secondary_text (
990 GTK_MESSAGE_DIALOG (dialog),
991 _("You were trying to print to a printer using the \"%s\" driver. This program requires a PostScript printer driver."),
992 gnome_print_config_get (
993 config, (guchar *)"Settings.Engine.Backend.Driver"));
994 gtk_dialog_run (GTK_DIALOG (dialog));
995 gtk_widget_destroy (dialog);
1000 print_job = g_object_new (EV_TYPE_PRINT_JOB,
1001 "gnome_print_job", job,
1002 "document", ev_window->priv->document,
1003 "print_dialog", print_dialog,
1008 gtk_widget_destroy (print_dialog);
1010 if (print_job != NULL) {
1011 ev_print_job_print (print_job, GTK_WINDOW (ev_window));
1012 g_object_unref (print_job);
1017 ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
1019 ev_window_print (ev_window);
1023 ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
1025 g_return_if_fail (EV_IS_WINDOW (ev_window));
1027 gtk_widget_destroy (GTK_WIDGET (ev_window));
1031 find_not_supported_dialog (EvWindow *ev_window)
1035 /* If you change this so it isn't modal, be sure you don't
1036 * allow multiple copies of the dialog...
1039 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
1040 GTK_DIALOG_DESTROY_WITH_PARENT,
1043 _("The \"Find\" feature will not work with this document"));
1044 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
1045 _("Searching for text is only supported for PDF documents."));
1046 gtk_dialog_run (GTK_DIALOG (dialog));
1047 gtk_widget_destroy (dialog);
1051 ev_window_cmd_edit_select_all (GtkAction *action, EvWindow *ev_window)
1053 g_return_if_fail (EV_IS_WINDOW (ev_window));
1055 ev_view_select_all (EV_VIEW (ev_window->priv->view));
1059 ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window)
1061 g_return_if_fail (EV_IS_WINDOW (ev_window));
1063 if (ev_window->priv->document == NULL) {
1064 g_printerr ("We should have set the Find menu item insensitive since there's no document\n");
1065 } else if (!EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
1066 find_not_supported_dialog (ev_window);
1068 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, NULL, TRUE);
1070 egg_find_bar_grab_focus (EGG_FIND_BAR (ev_window->priv->find_bar));
1075 ev_window_cmd_edit_copy (GtkAction *action, EvWindow *ev_window)
1077 g_return_if_fail (EV_IS_WINDOW (ev_window));
1079 ev_view_copy (EV_VIEW (ev_window->priv->view));
1083 ev_window_update_fullscreen_popup (EvWindow *window)
1085 GtkWidget *popup = window->priv->fullscreen_popup;
1086 int popup_width, popup_height;
1087 GdkRectangle screen_rect;
1090 g_return_if_fail (popup != NULL);
1092 toolbar = (window->priv->chrome & EV_CHROME_TOOLBAR) != 0;
1093 popup_width = popup->requisition.width;
1094 popup_height = popup->requisition.height;
1096 /* FIXME multihead */
1097 gdk_screen_get_monitor_geometry (gdk_screen_get_default (),
1098 gdk_screen_get_monitor_at_window
1099 (gdk_screen_get_default (),
1100 GTK_WIDGET (window)->window),
1103 gtk_widget_set_size_request (popup,
1106 gtk_window_move (GTK_WINDOW (popup),
1111 if (gtk_widget_get_direction (popup) == GTK_TEXT_DIR_RTL)
1113 gtk_window_move (GTK_WINDOW (popup),
1117 gtk_window_move (GTK_WINDOW (popup),
1118 screen_rect.x + screen_rect.width - popup_width,
1125 screen_size_changed_cb (GdkScreen *screen,
1128 ev_window_update_fullscreen_popup (window);
1132 ev_window_sidebar_position_change_cb (GObject *object, GParamSpec *pspec,
1133 EvWindow *ev_window)
1135 GConfClient *client;
1138 sidebar_size = gtk_paned_get_position (GTK_PANED (object));
1140 client = gconf_client_get_default ();
1141 gconf_client_set_int (client, GCONF_SIDEBAR_SIZE, sidebar_size, NULL);
1142 g_object_unref (client);
1146 destroy_fullscreen_popup (EvWindow *window)
1148 if (window->priv->fullscreen_popup != NULL)
1150 /* FIXME multihead */
1151 g_signal_handlers_disconnect_by_func
1152 (gdk_screen_get_default (),
1153 G_CALLBACK (screen_size_changed_cb), window);
1155 gtk_widget_destroy (window->priv->fullscreen_popup);
1156 window->priv->fullscreen_popup = NULL;
1161 exit_fullscreen_button_clicked_cb (GtkWidget *button, EvWindow *window)
1165 action = gtk_action_group_get_action (window->priv->action_group, "ViewFullscreen");
1166 g_return_if_fail (action != NULL);
1168 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), FALSE);
1172 fullscreen_popup_size_request_cb (GtkWidget *popup, GtkRequisition *req, EvWindow *window)
1174 ev_window_update_fullscreen_popup (window);
1178 fullscreen_timeout_cb (gpointer data)
1180 EvWindow *window = EV_WINDOW (data);
1182 g_object_set (window->priv->fullscreen_popup, "visible", FALSE, NULL);
1183 ev_view_hide_cursor (EV_VIEW (window->priv->view));
1184 window->priv->fullscreen_timeout_source = NULL;
1190 fullscreen_set_timeout (EvWindow *window)
1194 if (window->priv->fullscreen_timeout_source != NULL)
1195 g_source_destroy (window->priv->fullscreen_timeout_source);
1197 source = g_timeout_source_new (1000);
1198 g_source_set_callback (source, fullscreen_timeout_cb, window, NULL);
1199 g_source_attach (source, NULL);
1200 window->priv->fullscreen_timeout_source = source;
1204 fullscreen_clear_timeout (EvWindow *window)
1206 if (window->priv->fullscreen_timeout_source != NULL)
1207 g_source_destroy (window->priv->fullscreen_timeout_source);
1209 window->priv->fullscreen_timeout_source = NULL;
1210 ev_view_show_cursor (EV_VIEW (window->priv->view));
1214 fullscreen_motion_notify_cb (GtkWidget *widget,
1215 GdkEventMotion *event,
1218 EvWindow *window = EV_WINDOW (user_data);
1220 if (!GTK_WIDGET_VISIBLE (window->priv->fullscreen_popup)) {
1221 g_object_set (window->priv->fullscreen_popup, "visible", TRUE, NULL);
1222 ev_view_show_cursor (EV_VIEW (window->priv->view));
1225 fullscreen_set_timeout (window);
1231 fullscreen_leave_notify_cb (GtkWidget *widget,
1232 GdkEventCrossing *event,
1235 EvWindow *window = EV_WINDOW (user_data);
1237 fullscreen_clear_timeout (window);
1243 ev_window_get_exit_fullscreen_button (EvWindow *window)
1245 GtkWidget *button, *icon, *label, *hbox;
1247 button = gtk_button_new ();
1248 g_signal_connect (button, "clicked",
1249 G_CALLBACK (exit_fullscreen_button_clicked_cb),
1251 gtk_widget_show (button);
1253 hbox = gtk_hbox_new (FALSE, 2);
1254 gtk_widget_show (hbox);
1255 gtk_container_add (GTK_CONTAINER (button), hbox);
1257 icon = gtk_image_new_from_stock (EV_STOCK_LEAVE_FULLSCREEN, GTK_ICON_SIZE_BUTTON);
1258 gtk_widget_show (icon);
1259 gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
1261 label = gtk_label_new (_("Leave Fullscreen"));
1262 gtk_widget_show (label);
1263 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1269 ev_window_create_fullscreen_popup (EvWindow *window)
1275 popup = gtk_window_new (GTK_WINDOW_POPUP);
1276 hbox = gtk_hbox_new (FALSE, 0);
1277 button = ev_window_get_exit_fullscreen_button (window);
1279 gtk_container_add (GTK_CONTAINER (popup), hbox);
1280 gtk_box_pack_start (GTK_BOX (hbox), window->priv->fullscreen_toolbar,
1282 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
1284 gtk_widget_show (button);
1285 gtk_widget_show (hbox);
1287 gtk_window_set_resizable (GTK_WINDOW (popup), FALSE);
1289 /* FIXME multihead */
1290 g_signal_connect (gdk_screen_get_default (), "size-changed",
1291 G_CALLBACK (screen_size_changed_cb), window);
1292 g_signal_connect (popup, "size_request",
1293 G_CALLBACK (fullscreen_popup_size_request_cb), window);
1299 ev_window_fullscreen (EvWindow *window)
1301 window->priv->fullscreen_mode = TRUE;
1303 if (window->priv->fullscreen_popup == NULL)
1304 window->priv->fullscreen_popup
1305 = ev_window_create_fullscreen_popup (window);
1306 update_chrome_visibility (window);
1308 g_object_set (G_OBJECT (window->priv->scrolled_window),
1309 "shadow-type", GTK_SHADOW_NONE,
1312 g_signal_connect (window->priv->view,
1313 "motion-notify-event",
1314 G_CALLBACK (fullscreen_motion_notify_cb),
1316 g_signal_connect (window->priv->view,
1317 "leave-notify-event",
1318 G_CALLBACK (fullscreen_leave_notify_cb),
1320 fullscreen_set_timeout (window);
1322 gtk_widget_grab_focus (window->priv->view);
1324 ev_window_update_fullscreen_popup (window);
1328 ev_window_unfullscreen (EvWindow *window)
1330 window->priv->fullscreen_mode = FALSE;
1332 g_object_set (G_OBJECT (window->priv->scrolled_window),
1333 "shadow-type", GTK_SHADOW_IN,
1336 fullscreen_clear_timeout (window);
1338 g_signal_handlers_disconnect_by_func (window->priv->view,
1339 (gpointer) fullscreen_motion_notify_cb,
1342 // destroy_fullscreen_popup (window);
1344 update_chrome_visibility (window);
1348 ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *ev_window)
1350 gboolean fullscreen;
1352 g_return_if_fail (EV_IS_WINDOW (ev_window));
1354 fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
1357 gtk_window_fullscreen (GTK_WINDOW (ev_window));
1359 gtk_window_unfullscreen (GTK_WINDOW (ev_window));
1364 ev_window_state_event_cb (GtkWidget *widget, GdkEventWindowState *event, EvWindow *window)
1366 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
1368 GtkActionGroup *action_group;
1370 gboolean fullscreen;
1372 fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
1376 ev_window_fullscreen (window);
1380 ev_window_unfullscreen (window);
1383 action_group = window->priv->action_group;
1385 action = gtk_action_group_get_action (action_group, "ViewFullscreen");
1386 g_signal_handlers_block_by_func
1387 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
1388 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), fullscreen);
1389 g_signal_handlers_unblock_by_func
1390 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
1398 ev_window_focus_in_event (GtkWidget *widget, GdkEventFocus *event)
1400 EvWindow *window = EV_WINDOW (widget);
1401 EvWindowPrivate *priv = window->priv;
1403 if (priv->fullscreen_mode)
1405 gtk_widget_show (priv->fullscreen_popup);
1408 return GTK_WIDGET_CLASS (ev_window_parent_class)->focus_in_event (widget, event);
1412 ev_window_focus_out_event (GtkWidget *widget, GdkEventFocus *event)
1414 EvWindow *window = EV_WINDOW (widget);
1415 EvWindowPrivate *priv = window->priv;
1417 if (priv->fullscreen_mode)
1419 gtk_widget_hide (priv->fullscreen_popup);
1422 return GTK_WIDGET_CLASS (ev_window_parent_class)->focus_out_event (widget, event);
1426 ev_window_set_page_mode (EvWindow *window,
1427 EvWindowPageMode page_mode)
1429 GtkWidget *child = NULL;
1430 GtkWidget *real_child;
1432 if (window->priv->page_mode == page_mode)
1435 window->priv->page_mode = page_mode;
1437 switch (page_mode) {
1438 case PAGE_MODE_SINGLE_PAGE:
1439 child = window->priv->view;
1441 case PAGE_MODE_PASSWORD:
1442 child = window->priv->password_view;
1444 case PAGE_MODE_CONTINUOUS_PAGE:
1445 child = window->priv->page_view;
1448 g_assert_not_reached ();
1451 real_child = gtk_bin_get_child (GTK_BIN (window->priv->scrolled_window));
1452 if (child != real_child) {
1453 gtk_container_remove (GTK_CONTAINER (window->priv->scrolled_window),
1455 gtk_container_add (GTK_CONTAINER (window->priv->scrolled_window),
1458 update_action_sensitivity (window);
1462 ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window)
1464 g_return_if_fail (EV_IS_WINDOW (ev_window));
1466 ev_window_set_sizing_mode (ev_window, EV_SIZING_FREE);
1468 ev_view_zoom_in (EV_VIEW (ev_window->priv->view));
1472 ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window)
1474 g_return_if_fail (EV_IS_WINDOW (ev_window));
1476 ev_window_set_sizing_mode (ev_window, EV_SIZING_FREE);
1478 ev_view_zoom_out (EV_VIEW (ev_window->priv->view));
1482 ev_window_cmd_view_normal_size (GtkAction *action, EvWindow *ev_window)
1484 g_return_if_fail (EV_IS_WINDOW (ev_window));
1486 ev_view_set_size (EV_VIEW (ev_window->priv->view), -1, -1);
1490 ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
1492 g_return_if_fail (EV_IS_WINDOW (ev_window));
1494 ev_page_cache_prev_page (ev_window->priv->page_cache);
1498 ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
1500 g_return_if_fail (EV_IS_WINDOW (ev_window));
1502 ev_page_cache_next_page (ev_window->priv->page_cache);
1506 ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
1508 g_return_if_fail (EV_IS_WINDOW (ev_window));
1510 ev_page_cache_set_current_page (ev_window->priv->page_cache, 1);
1514 ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
1518 g_return_if_fail (EV_IS_WINDOW (ev_window));
1520 n_pages = ev_page_cache_get_n_pages (ev_window->priv->page_cache);
1521 ev_page_cache_set_current_page (ev_window->priv->page_cache, n_pages);
1525 ev_window_cmd_view_reload (GtkAction *action, EvWindow *ev_window)
1530 g_return_if_fail (EV_IS_WINDOW (ev_window));
1533 /* FIXME: uncomment when this is written.*/
1534 page = ev_page_cache_get_page (ev_window->priv->page_cache);
1538 uri = g_strdup (ev_window->priv->uri);
1540 ev_window_open (ev_window, uri);
1541 ev_window_open_page (ev_window, page);
1547 ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
1549 g_return_if_fail (EV_IS_WINDOW (ev_window));
1555 ev_window_cmd_leave_fullscreen (GtkAction *action, EvWindow *window)
1557 gtk_window_unfullscreen (GTK_WINDOW (window));
1561 update_view_size (EvWindow *window)
1564 GtkRequisition vsb_requisition;
1565 int scrollbar_spacing;
1567 width = window->priv->scrolled_window->allocation.width;
1568 height = window->priv->scrolled_window->allocation.height;
1570 /* the scrolled window has a GTK_SHADOW_IN */
1571 width -= 2 * window->priv->view->style->xthickness;
1572 height -= 2 * window->priv->view->style->ythickness;
1574 if (window->priv->sizing_mode == EV_SIZING_BEST_FIT) {
1575 ev_view_set_size (EV_VIEW (window->priv->view),
1576 MAX (1, width), MAX (1, height));
1577 } else if (window->priv->sizing_mode == EV_SIZING_FIT_WIDTH) {
1578 gtk_widget_size_request (GTK_SCROLLED_WINDOW (window->priv->scrolled_window)->vscrollbar,
1580 gtk_widget_style_get (window->priv->scrolled_window,
1581 "scrollbar_spacing", &scrollbar_spacing,
1583 ev_view_set_size (EV_VIEW (window->priv->view),
1584 width - vsb_requisition.width - scrollbar_spacing, -1);
1589 size_allocate_cb (GtkWidget *scrolled_window,
1590 GtkAllocation *allocation,
1593 update_view_size (window);
1597 ev_window_set_sizing_mode (EvWindow *ev_window,
1598 EvSizingMode sizing_mode)
1600 GtkWidget *scrolled_window;
1602 if (ev_window->priv->sizing_mode == sizing_mode)
1605 scrolled_window = ev_window->priv->scrolled_window;
1606 ev_window->priv->sizing_mode = sizing_mode;
1608 g_signal_handlers_disconnect_by_func (scrolled_window, size_allocate_cb, ev_window);
1610 update_view_size (ev_window);
1612 switch (sizing_mode) {
1613 case EV_SIZING_BEST_FIT:
1614 g_object_set (G_OBJECT (scrolled_window),
1615 "hscrollbar-policy", GTK_POLICY_NEVER,
1616 "vscrollbar-policy", GTK_POLICY_NEVER,
1618 g_signal_connect (scrolled_window, "size-allocate",
1619 G_CALLBACK (size_allocate_cb),
1622 case EV_SIZING_FIT_WIDTH:
1623 g_object_set (G_OBJECT (scrolled_window),
1624 "hscrollbar-policy", GTK_POLICY_NEVER,
1625 "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
1627 g_signal_connect (scrolled_window, "size-allocate",
1628 G_CALLBACK (size_allocate_cb),
1631 case EV_SIZING_FREE:
1632 g_object_set (G_OBJECT (scrolled_window),
1633 "hscrollbar-policy", GTK_POLICY_AUTOMATIC,
1634 "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
1639 update_sizing_buttons (ev_window);
1643 ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
1645 const char *authors[] = {
1650 const char *documenters[] = {
1651 N_("Not so many..."),
1655 const char *license[] = {
1656 N_("Evince is free software; you can redistribute it and/or modify\n"
1657 "it under the terms of the GNU General Public License as published by\n"
1658 "the Free Software Foundation; either version 2 of the License, or\n"
1659 "(at your option) any later version.\n"),
1660 N_("Evince is distributed in the hope that it will be useful,\n"
1661 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1662 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1663 "GNU General Public License for more details.\n"),
1664 N_("You should have received a copy of the GNU General Public License\n"
1665 "along with Evince; if not, write to the Free Software Foundation, Inc.,\n"
1666 "59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n")
1669 char *license_trans;
1674 for (p = authors; *p; ++p)
1677 for (p = documenters; *p; ++p)
1681 license_trans = g_strconcat (_(license[0]), "\n", _(license[1]), "\n",
1682 _(license[2]), "\n", NULL);
1684 gtk_show_about_dialog (
1685 GTK_WINDOW (ev_window),
1686 "name", _("Evince"),
1689 _("\xc2\xa9 1996-2004 The Evince authors"),
1690 "license", license_trans,
1691 "website", "http://www.gnome.org/projects/evince",
1692 "comments", _("PostScript and PDF File Viewer."),
1694 "documenters", documenters,
1695 "translator-credits", _("translator-credits"),
1698 g_free (license_trans);
1702 ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window)
1704 update_chrome_flag (ev_window, EV_CHROME_TOOLBAR,
1705 GCONF_CHROME_TOOLBAR,
1706 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
1710 ev_window_view_statusbar_cb (GtkAction *action, EvWindow *ev_window)
1712 update_chrome_flag (ev_window, EV_CHROME_STATUSBAR,
1713 GCONF_CHROME_STATUSBAR,
1714 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
1718 ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window)
1720 update_chrome_flag (ev_window, EV_CHROME_SIDEBAR,
1721 GCONF_CHROME_SIDEBAR,
1722 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
1726 ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar, GParamSpec *pspec,
1727 EvWindow *ev_window)
1732 visible = GTK_WIDGET_VISIBLE (ev_sidebar);
1734 /* In fullscreen mode the sidebar is not visible,
1735 * but we don't want to update the chrome
1737 if (ev_window->priv->fullscreen_mode)
1740 action = gtk_action_group_get_action (ev_window->priv->action_group, "ViewSidebar");
1742 g_signal_handlers_block_by_func
1743 (action, G_CALLBACK (ev_window_view_sidebar_cb), ev_window);
1744 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
1745 g_signal_handlers_unblock_by_func
1746 (action, G_CALLBACK (ev_window_view_sidebar_cb), ev_window);
1748 update_chrome_flag (ev_window, EV_CHROME_SIDEBAR,
1749 GCONF_CHROME_SIDEBAR, visible);
1753 menu_item_select_cb (GtkMenuItem *proxy, EvWindow *ev_window)
1758 action = g_object_get_data (G_OBJECT (proxy), "gtk-action");
1759 g_return_if_fail (action != NULL);
1761 g_object_get (G_OBJECT (action), "tooltip", &message, NULL);
1763 gtk_statusbar_push (GTK_STATUSBAR (ev_window->priv->statusbar),
1764 ev_window->priv->help_message_cid, message);
1770 menu_item_deselect_cb (GtkMenuItem *proxy, EvWindow *ev_window)
1772 gtk_statusbar_pop (GTK_STATUSBAR (ev_window->priv->statusbar),
1773 ev_window->priv->help_message_cid);
1777 connect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
1778 GtkWidget *proxy, EvWindow *ev_window)
1780 if (GTK_IS_MENU_ITEM (proxy)) {
1781 g_signal_connect (proxy, "select",
1782 G_CALLBACK (menu_item_select_cb), ev_window);
1783 g_signal_connect (proxy, "deselect",
1784 G_CALLBACK (menu_item_deselect_cb),
1790 disconnect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
1791 GtkWidget *proxy, EvWindow *ev_window)
1793 if (GTK_IS_MENU_ITEM (proxy)) {
1794 g_signal_handlers_disconnect_by_func
1795 (proxy, G_CALLBACK (menu_item_select_cb), ev_window);
1796 g_signal_handlers_disconnect_by_func
1797 (proxy, G_CALLBACK (menu_item_deselect_cb), ev_window);
1802 view_status_changed_cb (EvView *view,
1804 EvWindow *ev_window)
1806 const char *message;
1808 gtk_statusbar_pop (GTK_STATUSBAR (ev_window->priv->statusbar),
1809 ev_window->priv->view_message_cid);
1811 message = ev_view_get_status (view);
1813 gtk_statusbar_push (GTK_STATUSBAR (ev_window->priv->statusbar),
1814 ev_window->priv->view_message_cid, message);
1819 view_find_status_changed_cb (EvView *view,
1821 EvWindow *ev_window)
1825 text = ev_view_get_find_status (view);
1826 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
1831 find_bar_previous_cb (EggFindBar *find_bar,
1832 EvWindow *ev_window)
1834 ev_view_find_previous (EV_VIEW (ev_window->priv->view));
1838 find_bar_next_cb (EggFindBar *find_bar,
1839 EvWindow *ev_window)
1841 ev_view_find_next (EV_VIEW (ev_window->priv->view));
1845 find_bar_close_cb (EggFindBar *find_bar,
1846 EvWindow *ev_window)
1848 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, NULL, FALSE);
1852 ev_window_page_mode_cb (GtkRadioAction *action,
1853 GtkRadioAction *activated_action,
1858 mode = gtk_radio_action_get_current_value (action);
1860 g_assert (mode == PAGE_MODE_CONTINUOUS_PAGE ||
1861 mode == PAGE_MODE_SINGLE_PAGE);
1863 ev_window_set_page_mode (window, (EvWindowPageMode) mode);
1867 find_bar_search_changed_cb (EggFindBar *find_bar,
1869 EvWindow *ev_window)
1871 gboolean case_sensitive;
1873 const char *search_string;
1875 g_return_if_fail (EV_IS_WINDOW (ev_window));
1877 /* Either the string or case sensitivity could have changed,
1878 * we connect this callback to both. We also connect it
1879 * to ::visible so when the find bar is hidden, we should
1880 * pretend the search string is NULL/""
1883 case_sensitive = egg_find_bar_get_case_sensitive (find_bar);
1884 visible = GTK_WIDGET_VISIBLE (find_bar);
1885 search_string = egg_find_bar_get_search_string (find_bar);
1888 g_printerr ("search for '%s'\n", search_string ? search_string : "(nil)");
1891 if (ev_window->priv->document &&
1892 EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
1893 if (visible && search_string) {
1894 g_mutex_lock (EV_DOC_MUTEX);
1895 ev_document_find_begin (EV_DOCUMENT_FIND (ev_window->priv->document), search_string, case_sensitive);
1896 g_mutex_unlock (EV_DOC_MUTEX);
1898 g_mutex_lock (EV_DOC_MUTEX);
1899 ev_document_find_cancel (EV_DOCUMENT_FIND (ev_window->priv->document));
1900 g_mutex_unlock (EV_DOC_MUTEX);
1902 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
1904 gtk_widget_queue_draw (GTK_WIDGET (ev_window->priv->view));
1910 ev_window_dispose (GObject *object)
1912 EvWindow *window = EV_WINDOW (object);
1913 EvWindowPrivate *priv = window->priv;
1915 if (priv->ui_manager) {
1916 g_object_unref (priv->ui_manager);
1917 priv->ui_manager = NULL;
1920 if (priv->action_group) {
1921 g_object_unref (priv->action_group);
1922 priv->action_group = NULL;
1925 if (priv->document) {
1926 g_object_unref (priv->document);
1927 priv->document = NULL;
1931 g_object_unref (priv->view);
1935 if (priv->page_view) {
1936 g_object_unref (priv->page_view);
1937 priv->page_view = NULL;
1940 if (priv->password_document) {
1941 g_object_unref (priv->password_document);
1942 priv->password_document = NULL;
1945 if (priv->password_uri) {
1946 g_free (priv->password_uri);
1947 priv->password_uri = NULL;
1950 destroy_fullscreen_popup (window);
1952 G_OBJECT_CLASS (ev_window_parent_class)->dispose (object);
1956 ev_window_class_init (EvWindowClass *ev_window_class)
1958 GObjectClass *g_object_class = G_OBJECT_CLASS (ev_window_class);
1959 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (ev_window_class);
1961 g_object_class->dispose = ev_window_dispose;
1963 widget_class->focus_in_event = ev_window_focus_in_event;
1964 widget_class->focus_out_event = ev_window_focus_out_event;
1966 g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
1970 static GtkActionEntry entries[] = {
1971 { "File", NULL, N_("_File") },
1972 { "Edit", NULL, N_("_Edit") },
1973 { "View", NULL, N_("_View") },
1974 { "Go", NULL, N_("_Go") },
1975 { "Help", NULL, N_("_Help") },
1978 { "FileOpen", GTK_STOCK_OPEN, NULL, "<control>O",
1979 N_("Open an existing document"),
1980 G_CALLBACK (ev_window_cmd_file_open) },
1981 { "FileSaveAs", GTK_STOCK_SAVE_AS, N_("_Save a Copy..."), NULL,
1982 N_("Save the current document with a new filename"),
1983 G_CALLBACK (ev_window_cmd_save_as) },
1984 { "FilePrint", GTK_STOCK_PRINT, N_("Print..."), "<control>P",
1985 N_("Print this document"),
1986 G_CALLBACK (ev_window_cmd_file_print) },
1987 { "FileCloseWindow", GTK_STOCK_CLOSE, NULL, "<control>W",
1988 N_("Close this window"),
1989 G_CALLBACK (ev_window_cmd_file_close_window) },
1992 { "EditCopy", GTK_STOCK_COPY, NULL, "<control>C",
1993 N_("Copy text from the document"),
1994 G_CALLBACK (ev_window_cmd_edit_copy) },
1995 { "EditSelectAll", NULL, N_("Select _All"), "<control>A",
1996 N_("Select the entire page"),
1997 G_CALLBACK (ev_window_cmd_edit_select_all) },
1998 { "EditFind", GTK_STOCK_FIND, NULL, "<control>F",
1999 N_("Find a word or phrase in the document"),
2000 G_CALLBACK (ev_window_cmd_edit_find) },
2003 { "ViewZoomIn", GTK_STOCK_ZOOM_IN, NULL, "<control>plus",
2004 N_("Enlarge the document"),
2005 G_CALLBACK (ev_window_cmd_view_zoom_in) },
2006 { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, NULL, "<control>minus",
2007 N_("Shrink the document"),
2008 G_CALLBACK (ev_window_cmd_view_zoom_out) },
2009 { "ViewNormalSize", GTK_STOCK_ZOOM_100, NULL, "<control>0",
2010 N_("Reset the zoom level to the default value"),
2011 G_CALLBACK (ev_window_cmd_view_normal_size) },
2012 { "ViewReload", GTK_STOCK_REFRESH, N_("_Reload"), "<control>R",
2013 N_("Reload the document"),
2014 G_CALLBACK (ev_window_cmd_view_reload) },
2017 { "GoPreviousPage", GTK_STOCK_GO_BACK, N_("_Previous Page"), "Page_Up",
2018 N_("Go to the previous page"),
2019 G_CALLBACK (ev_window_cmd_go_previous_page) },
2020 { "GoNextPage", GTK_STOCK_GO_FORWARD, N_("_Next Page"), "Page_Down",
2021 N_("Go to the next page"),
2022 G_CALLBACK (ev_window_cmd_go_next_page) },
2023 { "GoFirstPage", GTK_STOCK_GOTO_FIRST, N_("_First Page"), "<control>Home",
2024 N_("Go to the first page"),
2025 G_CALLBACK (ev_window_cmd_go_first_page) },
2026 { "GoLastPage", GTK_STOCK_GOTO_LAST, N_("_Last Page"), "<control>End",
2027 N_("Go to the last page"),
2028 G_CALLBACK (ev_window_cmd_go_last_page) },
2031 { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), NULL,
2032 N_("Display help for the viewer application"),
2033 G_CALLBACK (ev_window_cmd_help_contents) },
2035 { "HelpAbout", GTK_STOCK_ABOUT, N_("_About"), NULL,
2036 N_("Display credits for the document viewer creators"),
2037 G_CALLBACK (ev_window_cmd_help_about) },
2040 { "LeaveFullscreen", EV_STOCK_LEAVE_FULLSCREEN, N_("Leave Fullscreen"), "Escape",
2041 N_("Leave fullscreen mode"),
2042 G_CALLBACK (ev_window_cmd_leave_fullscreen) }
2046 static GtkToggleActionEntry toggle_entries[] = {
2048 { "ViewToolbar", NULL, N_("_Toolbar"), "<shift><control>T",
2049 N_("Show or hide the toolbar"),
2050 G_CALLBACK (ev_window_view_toolbar_cb), TRUE },
2051 { "ViewStatusbar", NULL, N_("_Statusbar"), NULL,
2052 N_("Show or hide the statusbar"),
2053 G_CALLBACK (ev_window_view_statusbar_cb), TRUE },
2054 { "ViewSidebar", NULL, N_("Side _pane"), "F9",
2055 N_("Show or hide the side pane"),
2056 G_CALLBACK (ev_window_view_sidebar_cb), TRUE },
2057 { "ViewFullscreen", NULL, N_("_Fullscreen"), "F11",
2058 N_("Expand the window to fill the screen"),
2059 G_CALLBACK (ev_window_cmd_view_fullscreen) },
2060 { "ViewBestFit", EV_STOCK_ZOOM_PAGE, N_("_Best Fit"), NULL,
2061 N_("Make the current document fill the window"),
2062 G_CALLBACK (ev_window_cmd_view_best_fit) },
2063 { "ViewPageWidth", EV_STOCK_ZOOM_WIDTH, N_("Fit Page _Width"), NULL,
2064 N_("Make the current document fill the window width"),
2065 G_CALLBACK (ev_window_cmd_view_page_width) },
2068 static GtkRadioActionEntry page_view_entries[] = {
2069 { "SinglePage", GTK_STOCK_DND, N_("Single"), NULL,
2070 N_("Show the document one page at a time"),
2071 PAGE_MODE_SINGLE_PAGE },
2072 { "ContinuousPage", GTK_STOCK_DND_MULTIPLE, N_("Multi"), NULL,
2073 N_("Show the full document at once"),
2074 PAGE_MODE_CONTINUOUS_PAGE }
2078 goto_page_cb (GtkAction *action, int page_number, EvWindow *ev_window)
2080 ev_page_cache_set_current_page (ev_window->priv->page_cache,
2085 drag_data_received_cb (GtkWidget *widget, GdkDragContext *context,
2086 gint x, gint y, GtkSelectionData *selection_data,
2087 guint info, guint time, gpointer gdata)
2089 GList *uri_list = NULL;
2091 uri_list = gnome_vfs_uri_list_parse ((gchar *) selection_data->data);
2094 ev_window_open_uri_list (EV_WINDOW (widget), uri_list);
2096 gnome_vfs_uri_list_free (uri_list);
2098 gtk_drag_finish (context, TRUE, FALSE, time);
2103 register_custom_actions (EvWindow *window, GtkActionGroup *group)
2107 action = g_object_new (EV_TYPE_PAGE_ACTION,
2108 "name", PAGE_SELECTOR_ACTION,
2110 "tooltip", _("Select Page"),
2112 g_signal_connect (action, "goto_page",
2113 G_CALLBACK (goto_page_cb), window);
2114 gtk_action_group_add_action (group, action);
2115 g_object_unref (action);
2119 set_action_properties (GtkActionGroup *action_group)
2123 action = gtk_action_group_get_action (action_group, "GoPreviousPage");
2124 /*translators: this is the label for toolbar button*/
2125 g_object_set (action, "short_label", _("Previous"), NULL);
2126 g_object_set (action, "is-important", TRUE, NULL);
2127 action = gtk_action_group_get_action (action_group, "GoNextPage");
2128 /*translators: this is the label for toolbar button*/
2129 g_object_set (action, "is-important", TRUE, NULL);
2130 g_object_set (action, "short_label", _("Next"), NULL);
2131 action = gtk_action_group_get_action (action_group, "ViewPageWidth");
2132 /*translators: this is the label for toolbar button*/
2133 g_object_set (action, "short_label", _("Fit Width"), NULL);
2134 action = gtk_action_group_get_action (action_group, "ViewZoomIn");
2136 action = gtk_action_group_get_action (action_group, "LeaveFullscreen");
2137 g_object_set (action, "is-important", TRUE, NULL);
2141 set_chrome_actions (EvWindow *window)
2143 EvWindowPrivate *priv = window->priv;
2144 GtkActionGroup *action_group = priv->action_group;
2147 action= gtk_action_group_get_action (action_group, "ViewToolbar");
2148 g_signal_handlers_block_by_func
2149 (action, G_CALLBACK (ev_window_view_toolbar_cb), window);
2150 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
2151 (priv->chrome & EV_CHROME_TOOLBAR) != 0);
2152 g_signal_handlers_unblock_by_func
2153 (action, G_CALLBACK (ev_window_view_toolbar_cb), window);
2155 action= gtk_action_group_get_action (action_group, "ViewSidebar");
2156 g_signal_handlers_block_by_func
2157 (action, G_CALLBACK (ev_window_view_sidebar_cb), window);
2158 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
2159 (priv->chrome & EV_CHROME_SIDEBAR) != 0);
2160 g_signal_handlers_unblock_by_func
2161 (action, G_CALLBACK (ev_window_view_sidebar_cb), window);
2163 action= gtk_action_group_get_action (action_group, "ViewStatusbar");
2164 g_signal_handlers_block_by_func
2165 (action, G_CALLBACK (ev_window_view_statusbar_cb), window);
2166 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
2167 (priv->chrome & EV_CHROME_STATUSBAR) != 0);
2168 g_signal_handlers_unblock_by_func
2169 (action, G_CALLBACK (ev_window_view_statusbar_cb), window);
2175 EvChrome chrome = EV_CHROME_NORMAL;
2176 GConfClient *client;
2179 client = gconf_client_get_default ();
2181 value = gconf_client_get (client, GCONF_CHROME_TOOLBAR, NULL);
2182 if (value != NULL) {
2183 if (value->type == GCONF_VALUE_BOOL && !gconf_value_get_bool (value)) {
2184 chrome &= ~EV_CHROME_TOOLBAR;
2186 gconf_value_free (value);
2189 value = gconf_client_get (client, GCONF_CHROME_SIDEBAR, NULL);
2190 if (value != NULL) {
2191 if (value->type == GCONF_VALUE_BOOL && !gconf_value_get_bool (value)) {
2192 chrome &= ~EV_CHROME_SIDEBAR;
2194 gconf_value_free (value);
2197 value = gconf_client_get (client, GCONF_CHROME_STATUSBAR, NULL);
2198 if (value != NULL) {
2199 if (value->type == GCONF_VALUE_BOOL && !gconf_value_get_bool (value)) {
2200 chrome &= ~EV_CHROME_STATUSBAR;
2202 gconf_value_free (value);
2205 g_object_unref (client);
2211 ev_window_init (EvWindow *ev_window)
2213 GtkActionGroup *action_group;
2214 GtkAccelGroup *accel_group;
2215 GError *error = NULL;
2216 GtkWidget *sidebar_widget, *toolbar_dock;
2218 GConfClient *client;
2221 ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
2223 ev_window->priv->page_mode = PAGE_MODE_SINGLE_PAGE;
2224 update_window_title (NULL, NULL, ev_window);
2226 ev_window->priv->main_box = gtk_vbox_new (FALSE, 0);
2227 gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box);
2228 gtk_widget_show (ev_window->priv->main_box);
2230 action_group = gtk_action_group_new ("MenuActions");
2231 ev_window->priv->action_group = action_group;
2232 gtk_action_group_set_translation_domain (action_group, NULL);
2233 gtk_action_group_add_actions (action_group, entries,
2234 G_N_ELEMENTS (entries), ev_window);
2235 gtk_action_group_add_toggle_actions (action_group, toggle_entries,
2236 G_N_ELEMENTS (toggle_entries),
2238 gtk_action_group_add_radio_actions (action_group, page_view_entries,
2239 G_N_ELEMENTS (page_view_entries),
2240 ev_window->priv->page_mode,
2241 G_CALLBACK (ev_window_page_mode_cb),
2243 set_action_properties (action_group);
2244 register_custom_actions (ev_window, action_group);
2246 ev_window->priv->ui_manager = gtk_ui_manager_new ();
2247 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
2251 gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
2252 gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
2254 g_signal_connect (ev_window->priv->ui_manager, "connect_proxy",
2255 G_CALLBACK (connect_proxy_cb), ev_window);
2256 g_signal_connect (ev_window->priv->ui_manager, "disconnect_proxy",
2257 G_CALLBACK (disconnect_proxy_cb), ev_window);
2259 if (!gtk_ui_manager_add_ui_from_file (ev_window->priv->ui_manager,
2260 DATADIR"/evince-ui.xml",
2262 g_message ("building menus failed: %s", error->message);
2263 g_error_free (error);
2266 ev_window->priv->menubar =
2267 gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
2269 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
2270 ev_window->priv->menubar,
2273 /* This sucks, but there is no way to have a draw=no, expand=true separator
2274 * in a GtkUIManager-built toolbar. So, just add another toolbar.
2275 * See gtk+ bug 166489.
2277 toolbar_dock = ev_window->priv->toolbar_dock = gtk_hbox_new (FALSE, 0);
2278 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), toolbar_dock,
2280 gtk_widget_show (toolbar_dock);
2282 ev_window->priv->toolbar =
2283 gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
2285 gtk_box_pack_start (GTK_BOX (toolbar_dock), ev_window->priv->toolbar,
2287 gtk_widget_show (ev_window->priv->toolbar);
2289 ev_window->priv->fullscreen_toolbar =
2290 gtk_ui_manager_get_widget (ev_window->priv->ui_manager, "/LeaveFullscreenToolbar");
2291 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (ev_window->priv->fullscreen_toolbar), TRUE);
2292 gtk_toolbar_set_style (GTK_TOOLBAR (ev_window->priv->fullscreen_toolbar), GTK_TOOLBAR_BOTH_HORIZ);
2294 /* Add the main area */
2295 ev_window->priv->hpaned = gtk_hpaned_new ();
2296 g_signal_connect (ev_window->priv->hpaned,
2298 G_CALLBACK (ev_window_sidebar_position_change_cb),
2301 sidebar_size = SIDEBAR_DEFAULT_SIZE;
2302 client = gconf_client_get_default ();
2303 value = gconf_client_get (client, GCONF_SIDEBAR_SIZE, NULL);
2304 if (value != NULL) {
2305 if (value->type == GCONF_VALUE_INT) {
2306 sidebar_size = gconf_value_get_int (value);
2308 gconf_value_free (value);
2310 g_object_unref (client);
2311 gtk_paned_set_position (GTK_PANED (ev_window->priv->hpaned), sidebar_size);
2312 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), ev_window->priv->hpaned,
2314 gtk_widget_show (ev_window->priv->hpaned);
2316 ev_window->priv->sidebar = ev_sidebar_new ();
2317 gtk_paned_pack1 (GTK_PANED (ev_window->priv->hpaned),
2318 ev_window->priv->sidebar, FALSE, FALSE);
2319 gtk_widget_show (ev_window->priv->sidebar);
2321 /* Stub sidebar, for now */
2322 sidebar_widget = ev_sidebar_links_new ();
2323 gtk_widget_show (sidebar_widget);
2324 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
2329 ev_window->priv->thumbs_sidebar = ev_sidebar_thumbnails_new ();
2330 gtk_widget_show (ev_window->priv->thumbs_sidebar);
2331 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
2334 ev_window->priv->thumbs_sidebar);
2336 ev_window->priv->scrolled_window =
2337 GTK_WIDGET (g_object_new (GTK_TYPE_SCROLLED_WINDOW,
2338 "shadow-type", GTK_SHADOW_IN,
2340 gtk_widget_show (ev_window->priv->scrolled_window);
2342 gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned),
2343 ev_window->priv->scrolled_window);
2345 ev_window->priv->view = ev_view_new ();
2346 //ev_window->priv->page_view = ev_page_view_new ();
2347 ev_window->priv->password_view = ev_password_view_new ();
2348 g_signal_connect_swapped (ev_window->priv->password_view,
2350 G_CALLBACK (ev_window_popup_password_dialog),
2352 gtk_widget_show (ev_window->priv->view);
2353 //gtk_widget_show (ev_window->priv->page_view);
2354 gtk_widget_show (ev_window->priv->password_view);
2356 /* We own a ref on these widgets, as we can swap them in and out */
2357 g_object_ref (ev_window->priv->view);
2358 //g_object_ref (ev_window->priv->page_view);
2359 g_object_ref (ev_window->priv->password_view);
2361 gtk_container_add (GTK_CONTAINER (ev_window->priv->scrolled_window),
2362 ev_window->priv->view);
2363 g_signal_connect (ev_window->priv->view,
2364 "notify::find-status",
2365 G_CALLBACK (view_find_status_changed_cb),
2367 g_signal_connect (ev_window->priv->view,
2369 G_CALLBACK (view_status_changed_cb),
2372 ev_window->priv->statusbar = gtk_statusbar_new ();
2373 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
2374 ev_window->priv->statusbar,
2376 ev_window->priv->help_message_cid = gtk_statusbar_get_context_id
2377 (GTK_STATUSBAR (ev_window->priv->statusbar), "help_message");
2378 ev_window->priv->view_message_cid = gtk_statusbar_get_context_id
2379 (GTK_STATUSBAR (ev_window->priv->statusbar), "view_message");
2381 ev_window->priv->find_bar = egg_find_bar_new ();
2382 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
2383 ev_window->priv->find_bar,
2386 ev_window->priv->chrome = load_chrome ();
2387 set_chrome_actions (ev_window);
2388 update_chrome_visibility (ev_window);
2390 /* Connect sidebar signals */
2391 g_signal_connect (ev_window->priv->sidebar,
2393 G_CALLBACK (ev_window_sidebar_visibility_changed_cb),
2396 /* Connect to find bar signals */
2397 g_signal_connect (ev_window->priv->find_bar,
2399 G_CALLBACK (find_bar_previous_cb),
2401 g_signal_connect (ev_window->priv->find_bar,
2403 G_CALLBACK (find_bar_next_cb),
2405 g_signal_connect (ev_window->priv->find_bar,
2407 G_CALLBACK (find_bar_close_cb),
2409 g_signal_connect (ev_window->priv->find_bar,
2410 "notify::search-string",
2411 G_CALLBACK (find_bar_search_changed_cb),
2413 g_signal_connect (ev_window->priv->find_bar,
2414 "notify::case-sensitive",
2415 G_CALLBACK (find_bar_search_changed_cb),
2417 g_signal_connect (ev_window->priv->find_bar,
2419 G_CALLBACK (find_bar_search_changed_cb),
2422 g_signal_connect (ev_window, "window-state-event",
2423 G_CALLBACK (ev_window_state_event_cb),
2426 /* Give focus to the scrolled window */
2427 gtk_widget_grab_focus (ev_window->priv->scrolled_window);
2430 gtk_drag_dest_unset (GTK_WIDGET (ev_window));
2431 gtk_drag_dest_set (GTK_WIDGET (ev_window), GTK_DEST_DEFAULT_ALL, ev_drop_types,
2432 sizeof (ev_drop_types) / sizeof (ev_drop_types[0]),
2434 g_signal_connect (G_OBJECT (ev_window), "drag_data_received",
2435 G_CALLBACK (drag_data_received_cb), NULL);
2437 /* Set it to something random to force a change */
2438 ev_window->priv->sizing_mode = EV_SIZING_FREE;
2439 ev_window_set_sizing_mode (ev_window, EV_SIZING_FIT_WIDTH);
2440 update_action_sensitivity (ev_window);