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 "eggfindbar.h"
46 #include "pdf-document.h"
47 #include "pixbuf-document.h"
48 #include "ps-document.h"
50 #include <glib/gi18n.h>
53 #include <libgnomevfs/gnome-vfs-mime-utils.h>
54 #include <libgnomevfs/gnome-vfs-uri.h>
55 #include <libgnomevfs/gnome-vfs-utils.h>
56 #include <libgnomeprintui/gnome-print-dialog.h>
58 #include <gconf/gconf-client.h>
62 #include "ev-application.h"
63 #include "ev-stock-icons.h"
72 PAGE_MODE_SINGLE_PAGE,
73 PAGE_MODE_CONTINUOUS_PAGE,
78 EV_CHROME_MENUBAR = 1 << 0,
79 EV_CHROME_TOOLBAR = 1 << 1,
80 EV_CHROME_SIDEBAR = 1 << 2,
81 EV_CHROME_FINDBAR = 1 << 3,
82 EV_CHROME_STATUSBAR = 1 << 4,
83 EV_CHROME_NORMAL = EV_CHROME_MENUBAR | EV_CHROME_TOOLBAR | EV_CHROME_SIDEBAR | EV_CHROME_STATUSBAR
86 struct _EvWindowPrivate {
89 GtkWidget *toolbar_dock;
93 GtkWidget *thumbs_sidebar;
95 GtkWidget *scrolled_window;
98 GtkWidget *password_view;
99 GtkActionGroup *action_group;
100 GtkUIManager *ui_manager;
101 GtkWidget *statusbar;
102 guint help_message_cid;
103 guint view_message_cid;
104 GtkWidget *fullscreen_toolbar;
105 GtkWidget *fullscreen_popup;
108 EvDocument *document;
110 EvWindowPageMode page_mode;
111 /* These members are used temporarily when in PAGE_MODE_PASSWORD */
112 EvDocument *password_document;
113 GtkWidget *password_dialog;
117 gboolean fullscreen_mode;
118 EvSizingMode sizing_mode;
119 GSource *fullscreen_timeout_source;
122 static GtkTargetEntry ev_drop_types[] = {
123 { "text/uri-list", 0, 0 }
127 #define EV_WINDOW_GET_PRIVATE(object) \
128 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_WINDOW, EvWindowPrivate))
130 #define PAGE_SELECTOR_ACTION "PageSelector"
132 #define GCONF_CHROME_TOOLBAR "/apps/evince/show_toolbar"
133 #define GCONF_CHROME_SIDEBAR "/apps/evince/show_sidebar"
134 #define GCONF_CHROME_STATUSBAR "/apps/evince/show_statusbar"
136 #define GCONF_SIDEBAR_SIZE "/apps/evince/sidebar_size"
137 #define SIDEBAR_DEFAULT_SIZE 132
139 static void ev_window_update_fullscreen_popup (EvWindow *window);
140 static void ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar, GParamSpec *pspec,
141 EvWindow *ev_window);
142 static void ev_window_set_page_mode (EvWindow *window,
143 EvWindowPageMode page_mode);
144 static gboolean start_loading_document (EvWindow *ev_window,
145 EvDocument *document,
147 static void ev_window_set_sizing_mode (EvWindow *ev_window,
148 EvSizingMode sizing_mode);
150 G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
153 set_action_sensitive (EvWindow *ev_window,
157 GtkAction *action = gtk_action_group_get_action (ev_window->priv->action_group,
159 gtk_action_set_sensitive (action, sensitive);
163 update_action_sensitivity (EvWindow *ev_window)
165 EvDocument *document;
166 EvWindowPageMode page_mode;
169 document = ev_window->priv->document;
170 page_mode = ev_window->priv->page_mode;
172 view = EV_VIEW (ev_window->priv->view);
175 /* "FileOpen": always sensitive */
176 set_action_sensitive (ev_window, "FileSaveAs", document!=NULL);
177 set_action_sensitive (ev_window, "FilePrint", document!=NULL);
178 /* "FileCloseWindow": always sensitive */
181 set_action_sensitive (ev_window, "EditCopy", document!=NULL);
182 set_action_sensitive (ev_window, "EditSelectAll", document!=NULL);
185 set_action_sensitive (ev_window, "EditFind", EV_IS_DOCUMENT_FIND (document));
187 set_action_sensitive (ev_window, "EditFind", FALSE);
190 set_action_sensitive (ev_window, "ViewZoomIn", document!=NULL);
191 set_action_sensitive (ev_window, "ViewZoomOut", document!=NULL);
192 set_action_sensitive (ev_window, "ViewNormalSize", document!=NULL);
193 set_action_sensitive (ev_window, "ViewBestFit", document!=NULL);
194 set_action_sensitive (ev_window, "ViewPageWidth", document!=NULL);
195 set_action_sensitive (ev_window, "ViewReload", document!=NULL);
202 page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
203 n_pages = ev_document_get_n_pages (document);
205 set_action_sensitive (ev_window, "GoPreviousPage", page > 1);
206 set_action_sensitive (ev_window, "GoNextPage", page < n_pages);
207 set_action_sensitive (ev_window, "GoFirstPage", page > 1);
208 set_action_sensitive (ev_window, "GoLastPage", page < n_pages);
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 ev_view_set_page (EV_VIEW (ev_window->priv->view), page);
354 ev_window_open_link (EvWindow *ev_window, EvLink *link)
356 ev_view_go_to_link (EV_VIEW (ev_window->priv->view), link);
360 ev_window_is_empty (const EvWindow *ev_window)
362 g_return_val_if_fail (EV_IS_WINDOW (ev_window), FALSE);
364 return ev_window->priv->document == NULL;
368 unable_to_load (EvWindow *ev_window,
369 const char *error_message)
373 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
374 GTK_DIALOG_DESTROY_WITH_PARENT,
377 _("Unable to open document"));
378 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
379 "%s", error_message);
380 gtk_dialog_run (GTK_DIALOG (dialog));
381 gtk_widget_destroy (dialog);
384 /* Would be nice to have this in gdk-pixbuf */
386 mime_type_supported_by_gdk_pixbuf (const gchar *mime_type)
388 GSList *formats, *list;
389 gboolean retval = FALSE;
391 formats = gdk_pixbuf_get_formats ();
395 GdkPixbufFormat *format = list->data;
399 if (gdk_pixbuf_format_is_disabled (format))
402 mime_types = gdk_pixbuf_format_get_mime_types (format);
404 for (i = 0; mime_types[i] != NULL; i++) {
405 if (strcmp (mime_types[i], mime_type) == 0) {
417 g_slist_free (formats);
423 update_window_title (EvDocument *document, GParamSpec *pspec, EvWindow *ev_window)
426 char *doc_title = NULL;
427 gboolean password_needed;
429 password_needed = (ev_window->priv->password_document != NULL);
432 doc_title = ev_document_get_title (document);
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_document_get_n_pages (ev_window->priv->document);
489 action = gtk_action_group_get_action
490 (ev_window->priv->action_group, PAGE_SELECTOR_ACTION);
491 ev_page_action_set_total_pages (EV_PAGE_ACTION (action), pages);
494 /* This function assumes that ev_window just had ev_window->document set.
497 document_supports_sidebar (EvDocument *document)
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 ev_window_setup_document (EvWindow *ev_window)
520 EvDocument *document;
521 EvView *view = EV_VIEW (ev_window->priv->view);
522 EvSidebar *sidebar = EV_SIDEBAR (ev_window->priv->sidebar);
524 document = ev_window->priv->document;
526 g_signal_connect_object (G_OBJECT (document),
528 G_CALLBACK (update_window_title),
531 ev_window_set_page_mode (ev_window, PAGE_MODE_SINGLE_PAGE);
533 if (document_supports_sidebar (document))
534 ev_sidebar_set_document (sidebar, document);
536 hide_sidebar_and_actions (ev_window);
537 ev_view_set_document (view, document);
539 update_window_title (document, NULL, ev_window);
540 update_total_pages (ev_window);
541 update_action_sensitivity (ev_window);
545 password_dialog_response (GtkWidget *password_dialog,
551 if (response_id == GTK_RESPONSE_OK) {
552 EvDocument *document;
555 password = ev_password_dialog_get_password (password_dialog);
557 ev_document_security_set_password (EV_DOCUMENT_SECURITY (ev_window->priv->password_document),
561 document = ev_window->priv->password_document;
562 uri = ev_window->priv->password_uri;
564 ev_window->priv->password_document = NULL;
565 ev_window->priv->password_uri = NULL;
567 if (start_loading_document (ev_window, document, uri)) {
568 gtk_widget_destroy (password_dialog);
571 g_object_unref (document);
577 gtk_widget_set_sensitive (ev_window->priv->password_view, TRUE);
578 gtk_widget_destroy (password_dialog);
581 /* Called either by start_loading_document or by the "unlock" callback on the
582 * password_view page. It assumes that ev_window->priv->password_* has been set
583 * correctly. These are cleared by password_dialog_response() */
586 ev_window_popup_password_dialog (EvWindow *ev_window)
588 g_assert (ev_window->priv->password_document);
589 g_assert (ev_window->priv->password_uri);
591 gtk_widget_set_sensitive (ev_window->priv->password_view, FALSE);
593 update_window_title (ev_window->priv->password_document, NULL, ev_window);
594 if (ev_window->priv->password_dialog == NULL) {
595 gchar *basename, *file_name;
597 basename = g_path_get_basename (ev_window->priv->password_uri);
598 file_name = gnome_vfs_unescape_string_for_display (basename);
599 ev_window->priv->password_dialog =
600 ev_password_dialog_new (GTK_WIDGET (ev_window), file_name);
601 g_object_add_weak_pointer (G_OBJECT (ev_window->priv->password_dialog),
602 (gpointer *) &(ev_window->priv->password_dialog));
603 g_signal_connect (ev_window->priv->password_dialog,
605 G_CALLBACK (password_dialog_response),
609 gtk_widget_show (ev_window->priv->password_dialog);
611 ev_password_dialog_set_bad_pass (ev_window->priv->password_dialog);
615 /* This wil try to load the document. It might be called multiple times on the
616 * same document by the password dialog.
618 * Since the flow of the error dialog is very confusing, we assume that both
619 * document and uri will go away after this function is called, and thus we need
620 * to ref/dup them. Additionally, it needs to clear
621 * ev_window->priv->password_{uri,document}, and thus people who call this
622 * function should _not_ necessarily expect those to exist after being
625 start_loading_document (EvWindow *ev_window,
626 EvDocument *document,
630 GError *error = NULL;
633 g_assert (document != ev_window->priv->document);
635 if (ev_window->priv->password_document) {
636 g_object_unref (ev_window->priv->password_document);
637 ev_window->priv->password_document = NULL;
639 if (ev_window->priv->password_uri) {
640 g_free (ev_window->priv->password_uri);
641 ev_window->priv->password_uri = NULL;
644 result = ev_document_load (document, uri, &error);
648 if (ev_window->priv->document)
649 g_object_unref (ev_window->priv->document);
650 ev_window->priv->document = g_object_ref (document);
651 ev_window_setup_document (ev_window);
656 /* unable to load the document */
657 g_assert (error != NULL);
659 if (error->domain == EV_DOCUMENT_ERROR &&
660 error->code == EV_DOCUMENT_ERROR_ENCRYPTED) {
663 ev_window->priv->password_document = g_object_ref (document);
664 ev_window->priv->password_uri = g_strdup (uri);
666 file_name = g_path_get_basename (uri);
667 ev_password_view_set_file_name (EV_PASSWORD_VIEW (ev_window->priv->password_view),
670 ev_window_set_page_mode (ev_window, PAGE_MODE_PASSWORD);
672 ev_window_popup_password_dialog (ev_window);
674 unable_to_load (ev_window, error->message);
676 g_error_free (error);
682 is_file_supported (const gchar *mime_type)
684 static char *supported_types [] = {
686 "application/postscript",
687 "application/x-gzpostscript",
693 g_return_val_if_fail (mime_type != NULL, FALSE);
695 if (mime_type_supported_by_gdk_pixbuf (mime_type))
698 for (i = 0; supported_types[i] != NULL; i++) {
699 if (g_ascii_strcasecmp (mime_type, supported_types[i]) == 0)
707 ev_window_open (EvWindow *ev_window, const char *uri)
709 EvDocument *document = NULL;
712 g_free (ev_window->priv->uri);
713 ev_window->priv->uri = g_strdup (uri);
715 mime_type = gnome_vfs_get_mime_type (uri);
717 if (mime_type == NULL)
719 else if (!strcmp (mime_type, "application/pdf"))
720 document = g_object_new (PDF_TYPE_DOCUMENT, NULL);
721 else if (!strcmp (mime_type, "application/postscript") ||
722 !strcmp (mime_type, "application/x-gzpostscript") ||
723 !strcmp (mime_type, "image/x-eps"))
724 document = g_object_new (PS_TYPE_DOCUMENT, NULL);
725 else if (mime_type_supported_by_gdk_pixbuf (mime_type))
726 document = g_object_new (PIXBUF_TYPE_DOCUMENT, NULL);
729 start_loading_document (ev_window, document, uri);
730 /* See the comment on start_loading_document on ref counting.
731 * As the password dialog flow is confusing, we're very explicit
732 * on ref counting. */
733 g_object_unref (document);
737 error_message = g_strdup_printf (_("Unhandled MIME type: '%s'"),
738 mime_type?mime_type:"<Unknown MIME Type>");
739 unable_to_load (ev_window, error_message);
740 g_free (error_message);
747 ev_window_open_uri_list (EvWindow *ev_window, GList *uri_list)
750 gchar *uri, *mime_type;
752 g_return_if_fail (uri_list != NULL);
756 uri = gnome_vfs_uri_to_string (list->data, GNOME_VFS_URI_HIDE_NONE);
757 mime_type = gnome_vfs_get_mime_type (uri);
759 if (is_file_supported (mime_type)) {
760 if (ev_window_is_empty (EV_WINDOW (ev_window))) {
761 ev_window_open (ev_window, uri);
763 gtk_widget_show (GTK_WIDGET (ev_window));
765 EvWindow *new_window;
767 new_window = ev_application_new_window (EV_APP);
768 ev_window_open (new_window, uri);
770 gtk_widget_show (GTK_WIDGET (new_window));
777 list = g_list_next (list);
782 ev_window_cmd_file_open (GtkAction *action, EvWindow *ev_window)
784 ev_application_open (EV_APP, NULL);
789 overwrite_existing_file (GtkWindow *window, const gchar *file_name)
792 gchar *utf8_file_name;
796 utf8_file_name = g_filename_to_utf8 (file_name, -1, NULL, NULL, NULL);
797 msgbox = gtk_message_dialog_new (
799 (GtkDialogFlags)GTK_DIALOG_DESTROY_WITH_PARENT,
800 GTK_MESSAGE_QUESTION,
802 _("A file named \"%s\" already exists."),
804 g_free (utf8_file_name);
806 gtk_message_dialog_format_secondary_text (
807 GTK_MESSAGE_DIALOG (msgbox),
808 _("Do you want to replace it with the one you are saving?"));
810 gtk_dialog_add_button (GTK_DIALOG (msgbox),
811 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
813 gtk_dialog_add_button (GTK_DIALOG (msgbox),
814 _("_Replace"), GTK_RESPONSE_YES);
816 gtk_dialog_set_default_response (GTK_DIALOG (msgbox),
817 GTK_RESPONSE_CANCEL);
819 obj = gtk_widget_get_accessible (msgbox);
821 if (GTK_IS_ACCESSIBLE (obj))
822 atk_object_set_name (obj, _("Question"));
824 ret = gtk_dialog_run (GTK_DIALOG (msgbox));
825 gtk_widget_destroy (msgbox);
827 return (ret == GTK_RESPONSE_YES);
832 save_error_dialog (GtkWindow *window, const gchar *file_name)
834 GtkWidget *error_dialog;
836 error_dialog = gtk_message_dialog_new (
838 (GtkDialogFlags)GTK_DIALOG_DESTROY_WITH_PARENT,
841 _("The file could not be saved as \"%s\"."),
844 /* Easy way to make the text bold while keeping the string
845 * above free from pango markup (FIXME ?) */
846 gtk_message_dialog_format_secondary_text (
847 GTK_MESSAGE_DIALOG (error_dialog), " ");
849 gtk_dialog_run (GTK_DIALOG (error_dialog));
850 gtk_widget_destroy (error_dialog);
854 ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
857 GtkFileFilter *pdf_filter, *all_filter;
860 fc = gtk_file_chooser_dialog_new (
862 NULL, GTK_FILE_CHOOSER_ACTION_SAVE,
863 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
864 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
866 gtk_window_set_modal (GTK_WINDOW (fc), TRUE);
868 pdf_filter = gtk_file_filter_new ();
869 gtk_file_filter_set_name (pdf_filter, _("PDF Documents"));
870 gtk_file_filter_add_mime_type (pdf_filter, "application/pdf");
871 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fc), pdf_filter);
873 all_filter = gtk_file_filter_new ();
874 gtk_file_filter_set_name (all_filter, _("All Files"));
875 gtk_file_filter_add_pattern (all_filter, "*");
876 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fc), all_filter);
877 gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (fc), pdf_filter);
879 gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
881 gtk_widget_show (fc);
883 while (gtk_dialog_run (GTK_DIALOG (fc)) == GTK_RESPONSE_OK) {
884 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
887 if (g_file_test (uri, G_FILE_TEST_EXISTS) &&
888 !overwrite_existing_file (GTK_WINDOW (fc), uri))
892 if (ev_document_save (ev_window->priv->document, uri, NULL))
895 save_error_dialog (GTK_WINDOW (fc), uri);
897 gtk_widget_destroy (fc);
901 using_postscript_printer (GnomePrintConfig *config)
903 const guchar *driver;
904 const guchar *transport;
906 driver = gnome_print_config_get (
907 config, (const guchar *)"Settings.Engine.Backend.Driver");
909 transport = gnome_print_config_get (
910 config, (const guchar *)"Settings.Transport.Backend");
913 if (!strcmp ((const gchar *)driver, "gnome-print-ps"))
917 } else if (transport) {
918 if (!strcmp ((const gchar *)transport, "CUPS"))
926 ev_window_print (EvWindow *ev_window)
928 GnomePrintConfig *config;
930 GtkWidget *print_dialog;
931 EvPrintJob *print_job = NULL;
933 g_return_if_fail (EV_IS_WINDOW (ev_window));
934 g_return_if_fail (ev_window->priv->document != NULL);
936 config = gnome_print_config_default ();
937 job = gnome_print_job_new (config);
939 print_dialog = gnome_print_dialog_new (job, _("Print"),
940 (GNOME_PRINT_DIALOG_RANGE |
941 GNOME_PRINT_DIALOG_COPIES));
942 gtk_dialog_set_response_sensitive (GTK_DIALOG (print_dialog),
943 GNOME_PRINT_DIALOG_RESPONSE_PREVIEW,
948 response = gtk_dialog_run (GTK_DIALOG (print_dialog));
950 if (response != GNOME_PRINT_DIALOG_RESPONSE_PRINT)
953 /* FIXME: Change this when we have the first backend
954 * that can print more than postscript
956 if (!using_postscript_printer (config)) {
959 dialog = gtk_message_dialog_new (
960 GTK_WINDOW (print_dialog), GTK_DIALOG_MODAL,
961 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
962 _("Printing is not supported on this printer."));
963 gtk_message_dialog_format_secondary_text (
964 GTK_MESSAGE_DIALOG (dialog),
965 _("You were trying to print to a printer using the \"%s\" driver. This program requires a PostScript printer driver."),
966 gnome_print_config_get (
967 config, "Settings.Engine.Backend.Driver"));
968 gtk_dialog_run (GTK_DIALOG (dialog));
969 gtk_widget_destroy (dialog);
974 print_job = g_object_new (EV_TYPE_PRINT_JOB,
975 "gnome_print_job", job,
976 "document", ev_window->priv->document,
977 "print_dialog", print_dialog,
982 gtk_widget_destroy (print_dialog);
984 if (print_job != NULL) {
985 ev_print_job_print (print_job, GTK_WINDOW (ev_window));
986 g_object_unref (print_job);
991 ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
993 ev_window_print (ev_window);
997 ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
999 g_return_if_fail (EV_IS_WINDOW (ev_window));
1001 gtk_widget_destroy (GTK_WIDGET (ev_window));
1005 find_not_supported_dialog (EvWindow *ev_window)
1009 /* If you change this so it isn't modal, be sure you don't
1010 * allow multiple copies of the dialog...
1013 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
1014 GTK_DIALOG_DESTROY_WITH_PARENT,
1017 _("The \"Find\" feature will not work with this document"));
1018 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
1019 _("Searching for text is only supported for PDF documents."));
1020 gtk_dialog_run (GTK_DIALOG (dialog));
1021 gtk_widget_destroy (dialog);
1025 ev_window_cmd_edit_select_all (GtkAction *action, EvWindow *ev_window)
1027 g_return_if_fail (EV_IS_WINDOW (ev_window));
1029 ev_view_select_all (EV_VIEW (ev_window->priv->view));
1033 ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window)
1035 g_return_if_fail (EV_IS_WINDOW (ev_window));
1037 if (ev_window->priv->document == NULL) {
1038 g_printerr ("We should have set the Find menu item insensitive since there's no document\n");
1039 } else if (!EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
1040 find_not_supported_dialog (ev_window);
1042 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, NULL, TRUE);
1044 egg_find_bar_grab_focus (EGG_FIND_BAR (ev_window->priv->find_bar));
1049 ev_window_cmd_edit_copy (GtkAction *action, EvWindow *ev_window)
1051 g_return_if_fail (EV_IS_WINDOW (ev_window));
1053 ev_view_copy (EV_VIEW (ev_window->priv->view));
1057 ev_window_update_fullscreen_popup (EvWindow *window)
1059 GtkWidget *popup = window->priv->fullscreen_popup;
1060 int popup_width, popup_height;
1061 GdkRectangle screen_rect;
1064 g_return_if_fail (popup != NULL);
1066 toolbar = (window->priv->chrome & EV_CHROME_TOOLBAR) != 0;
1067 popup_width = popup->requisition.width;
1068 popup_height = popup->requisition.height;
1070 /* FIXME multihead */
1071 gdk_screen_get_monitor_geometry (gdk_screen_get_default (),
1072 gdk_screen_get_monitor_at_window
1073 (gdk_screen_get_default (),
1074 GTK_WIDGET (window)->window),
1077 gtk_widget_set_size_request (popup,
1080 gtk_window_move (GTK_WINDOW (popup),
1085 if (gtk_widget_get_direction (popup) == GTK_TEXT_DIR_RTL)
1087 gtk_window_move (GTK_WINDOW (popup),
1091 gtk_window_move (GTK_WINDOW (popup),
1092 screen_rect.x + screen_rect.width - popup_width,
1099 screen_size_changed_cb (GdkScreen *screen,
1102 ev_window_update_fullscreen_popup (window);
1106 ev_window_sidebar_position_change_cb (GObject *object, GParamSpec *pspec,
1107 EvWindow *ev_window)
1109 GConfClient *client;
1112 sidebar_size = gtk_paned_get_position (GTK_PANED (object));
1114 client = gconf_client_get_default ();
1115 gconf_client_set_int (client, GCONF_SIDEBAR_SIZE, sidebar_size, NULL);
1116 g_object_unref (client);
1120 destroy_fullscreen_popup (EvWindow *window)
1122 if (window->priv->fullscreen_popup != NULL)
1124 /* FIXME multihead */
1125 g_signal_handlers_disconnect_by_func
1126 (gdk_screen_get_default (),
1127 G_CALLBACK (screen_size_changed_cb), window);
1129 gtk_widget_destroy (window->priv->fullscreen_popup);
1130 window->priv->fullscreen_popup = NULL;
1135 exit_fullscreen_button_clicked_cb (GtkWidget *button, EvWindow *window)
1139 action = gtk_action_group_get_action (window->priv->action_group, "ViewFullscreen");
1140 g_return_if_fail (action != NULL);
1142 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), FALSE);
1146 fullscreen_popup_size_request_cb (GtkWidget *popup, GtkRequisition *req, EvWindow *window)
1148 ev_window_update_fullscreen_popup (window);
1152 fullscreen_timeout_cb (gpointer data)
1154 EvWindow *window = EV_WINDOW (data);
1156 g_object_set (window->priv->fullscreen_popup, "visible", FALSE, NULL);
1157 ev_view_hide_cursor (EV_VIEW (window->priv->view));
1158 window->priv->fullscreen_timeout_source = NULL;
1164 fullscreen_set_timeout (EvWindow *window)
1168 if (window->priv->fullscreen_timeout_source != NULL)
1169 g_source_destroy (window->priv->fullscreen_timeout_source);
1171 source = g_timeout_source_new (1000);
1172 g_source_set_callback (source, fullscreen_timeout_cb, window, NULL);
1173 g_source_attach (source, NULL);
1174 window->priv->fullscreen_timeout_source = source;
1178 fullscreen_clear_timeout (EvWindow *window)
1180 if (window->priv->fullscreen_timeout_source != NULL)
1181 g_source_destroy (window->priv->fullscreen_timeout_source);
1183 window->priv->fullscreen_timeout_source = NULL;
1184 ev_view_show_cursor (EV_VIEW (window->priv->view));
1188 fullscreen_motion_notify_cb (GtkWidget *widget,
1189 GdkEventMotion *event,
1192 EvWindow *window = EV_WINDOW (user_data);
1194 if (!GTK_WIDGET_VISIBLE (window->priv->fullscreen_popup)) {
1195 g_object_set (window->priv->fullscreen_popup, "visible", TRUE, NULL);
1196 ev_view_show_cursor (EV_VIEW (window->priv->view));
1199 fullscreen_set_timeout (window);
1205 fullscreen_leave_notify_cb (GtkWidget *widget,
1206 GdkEventCrossing *event,
1209 EvWindow *window = EV_WINDOW (user_data);
1211 fullscreen_clear_timeout (window);
1217 ev_window_get_exit_fullscreen_button (EvWindow *window)
1219 GtkWidget *button, *icon, *label, *hbox;
1221 button = gtk_button_new ();
1222 g_signal_connect (button, "clicked",
1223 G_CALLBACK (exit_fullscreen_button_clicked_cb),
1225 gtk_widget_show (button);
1227 hbox = gtk_hbox_new (FALSE, 2);
1228 gtk_widget_show (hbox);
1229 gtk_container_add (GTK_CONTAINER (button), hbox);
1231 icon = gtk_image_new_from_stock (EV_STOCK_LEAVE_FULLSCREEN, GTK_ICON_SIZE_BUTTON);
1232 gtk_widget_show (icon);
1233 gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
1235 label = gtk_label_new (_("Leave Fullscreen"));
1236 gtk_widget_show (label);
1237 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1243 ev_window_create_fullscreen_popup (EvWindow *window)
1249 popup = gtk_window_new (GTK_WINDOW_POPUP);
1250 hbox = gtk_hbox_new (FALSE, 0);
1251 button = ev_window_get_exit_fullscreen_button (window);
1253 gtk_container_add (GTK_CONTAINER (popup), hbox);
1254 gtk_box_pack_start (GTK_BOX (hbox), window->priv->fullscreen_toolbar,
1256 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
1258 gtk_widget_show (button);
1259 gtk_widget_show (hbox);
1261 gtk_window_set_resizable (GTK_WINDOW (popup), FALSE);
1263 /* FIXME multihead */
1264 g_signal_connect (gdk_screen_get_default (), "size-changed",
1265 G_CALLBACK (screen_size_changed_cb), window);
1266 g_signal_connect (popup, "size_request",
1267 G_CALLBACK (fullscreen_popup_size_request_cb), window);
1273 ev_window_fullscreen (EvWindow *window)
1275 window->priv->fullscreen_mode = TRUE;
1277 if (window->priv->fullscreen_popup == NULL)
1278 window->priv->fullscreen_popup
1279 = ev_window_create_fullscreen_popup (window);
1280 update_chrome_visibility (window);
1282 g_object_set (G_OBJECT (window->priv->scrolled_window),
1283 "shadow-type", GTK_SHADOW_NONE,
1286 g_signal_connect (window->priv->view,
1287 "motion-notify-event",
1288 G_CALLBACK (fullscreen_motion_notify_cb),
1290 g_signal_connect (window->priv->view,
1291 "leave-notify-event",
1292 G_CALLBACK (fullscreen_leave_notify_cb),
1294 fullscreen_set_timeout (window);
1296 gtk_widget_grab_focus (window->priv->view);
1298 ev_window_update_fullscreen_popup (window);
1302 ev_window_unfullscreen (EvWindow *window)
1304 window->priv->fullscreen_mode = FALSE;
1306 g_object_set (G_OBJECT (window->priv->scrolled_window),
1307 "shadow-type", GTK_SHADOW_IN,
1310 fullscreen_clear_timeout (window);
1312 g_signal_handlers_disconnect_by_func (window->priv->view,
1313 (gpointer) fullscreen_motion_notify_cb,
1316 // destroy_fullscreen_popup (window);
1318 update_chrome_visibility (window);
1322 ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *ev_window)
1324 gboolean fullscreen;
1326 g_return_if_fail (EV_IS_WINDOW (ev_window));
1328 fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
1331 gtk_window_fullscreen (GTK_WINDOW (ev_window));
1333 gtk_window_unfullscreen (GTK_WINDOW (ev_window));
1338 ev_window_state_event_cb (GtkWidget *widget, GdkEventWindowState *event, EvWindow *window)
1340 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
1342 GtkActionGroup *action_group;
1344 gboolean fullscreen;
1346 fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
1350 ev_window_fullscreen (window);
1354 ev_window_unfullscreen (window);
1357 action_group = window->priv->action_group;
1359 action = gtk_action_group_get_action (action_group, "ViewFullscreen");
1360 g_signal_handlers_block_by_func
1361 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
1362 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), fullscreen);
1363 g_signal_handlers_unblock_by_func
1364 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
1372 ev_window_focus_in_event (GtkWidget *widget, GdkEventFocus *event)
1374 EvWindow *window = EV_WINDOW (widget);
1375 EvWindowPrivate *priv = window->priv;
1377 if (priv->fullscreen_mode)
1379 gtk_widget_show (priv->fullscreen_popup);
1382 return GTK_WIDGET_CLASS (ev_window_parent_class)->focus_in_event (widget, event);
1386 ev_window_focus_out_event (GtkWidget *widget, GdkEventFocus *event)
1388 EvWindow *window = EV_WINDOW (widget);
1389 EvWindowPrivate *priv = window->priv;
1391 if (priv->fullscreen_mode)
1393 gtk_widget_hide (priv->fullscreen_popup);
1396 return GTK_WIDGET_CLASS (ev_window_parent_class)->focus_out_event (widget, event);
1400 ev_window_set_page_mode (EvWindow *window,
1401 EvWindowPageMode page_mode)
1403 GtkWidget *child = NULL;
1404 GtkWidget *real_child;
1406 if (window->priv->page_mode == page_mode)
1409 window->priv->page_mode = page_mode;
1411 switch (page_mode) {
1412 case PAGE_MODE_SINGLE_PAGE:
1413 child = window->priv->view;
1415 case PAGE_MODE_PASSWORD:
1416 child = window->priv->password_view;
1418 case PAGE_MODE_CONTINUOUS_PAGE:
1419 child = window->priv->page_view;
1422 g_assert_not_reached ();
1425 real_child = gtk_bin_get_child (GTK_BIN (window->priv->scrolled_window));
1426 if (child != real_child) {
1427 gtk_container_remove (GTK_CONTAINER (window->priv->scrolled_window),
1429 gtk_container_add (GTK_CONTAINER (window->priv->scrolled_window),
1432 update_action_sensitivity (window);
1436 ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window)
1438 g_return_if_fail (EV_IS_WINDOW (ev_window));
1440 ev_window_set_sizing_mode (ev_window, EV_SIZING_FREE);
1442 ev_view_zoom_in (EV_VIEW (ev_window->priv->view));
1446 ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window)
1448 g_return_if_fail (EV_IS_WINDOW (ev_window));
1450 ev_window_set_sizing_mode (ev_window, EV_SIZING_FREE);
1452 ev_view_zoom_out (EV_VIEW (ev_window->priv->view));
1456 ev_window_cmd_view_normal_size (GtkAction *action, EvWindow *ev_window)
1458 g_return_if_fail (EV_IS_WINDOW (ev_window));
1460 ev_view_set_size (EV_VIEW (ev_window->priv->view), -1, -1);
1464 ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
1466 g_return_if_fail (EV_IS_WINDOW (ev_window));
1468 ev_view_set_page (EV_VIEW (ev_window->priv->view),
1469 ev_view_get_page (EV_VIEW (ev_window->priv->view)) - 1);
1473 ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
1475 g_return_if_fail (EV_IS_WINDOW (ev_window));
1477 ev_view_set_page (EV_VIEW (ev_window->priv->view),
1478 ev_view_get_page (EV_VIEW (ev_window->priv->view)) + 1);
1482 ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
1484 g_return_if_fail (EV_IS_WINDOW (ev_window));
1486 ev_view_set_page (EV_VIEW (ev_window->priv->view), 1);
1490 ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
1492 g_return_if_fail (EV_IS_WINDOW (ev_window));
1494 ev_view_set_page (EV_VIEW (ev_window->priv->view), G_MAXINT);
1498 ev_window_cmd_view_reload (GtkAction *action, EvWindow *ev_window)
1503 g_return_if_fail (EV_IS_WINDOW (ev_window));
1505 page = ev_document_get_page (ev_window->priv->document);
1506 uri = g_strdup (ev_window->priv->uri);
1508 ev_window_open (ev_window, uri);
1509 ev_window_open_page (ev_window, page);
1515 ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
1517 g_return_if_fail (EV_IS_WINDOW (ev_window));
1523 ev_window_cmd_leave_fullscreen (GtkAction *action, EvWindow *window)
1525 gtk_window_unfullscreen (GTK_WINDOW (window));
1529 update_view_size (EvWindow *window)
1532 GtkRequisition vsb_requisition;
1533 int scrollbar_spacing;
1535 width = window->priv->scrolled_window->allocation.width;
1536 height = window->priv->scrolled_window->allocation.height;
1538 /* the scrolled window has a GTK_SHADOW_IN */
1539 width -= 2 * window->priv->view->style->xthickness;
1540 height -= 2 * window->priv->view->style->ythickness;
1542 if (window->priv->sizing_mode == EV_SIZING_BEST_FIT) {
1543 ev_view_set_size (EV_VIEW (window->priv->view),
1544 MAX (1, width), MAX (1, height));
1545 } else if (window->priv->sizing_mode == EV_SIZING_FIT_WIDTH) {
1546 gtk_widget_size_request (GTK_SCROLLED_WINDOW (window->priv->scrolled_window)->vscrollbar,
1548 gtk_widget_style_get (window->priv->scrolled_window,
1549 "scrollbar_spacing", &scrollbar_spacing,
1551 ev_view_set_size (EV_VIEW (window->priv->view),
1552 width - vsb_requisition.width - scrollbar_spacing, -1);
1557 size_allocate_cb (GtkWidget *scrolled_window,
1558 GtkAllocation *allocation,
1561 update_view_size (window);
1565 ev_window_set_sizing_mode (EvWindow *ev_window,
1566 EvSizingMode sizing_mode)
1568 GtkWidget *scrolled_window;
1570 if (ev_window->priv->sizing_mode == sizing_mode)
1573 scrolled_window = ev_window->priv->scrolled_window;
1574 ev_window->priv->sizing_mode = sizing_mode;
1576 g_signal_handlers_disconnect_by_func (scrolled_window, size_allocate_cb, ev_window);
1578 update_view_size (ev_window);
1580 switch (sizing_mode) {
1581 case EV_SIZING_BEST_FIT:
1582 g_object_set (G_OBJECT (scrolled_window),
1583 "hscrollbar-policy", GTK_POLICY_NEVER,
1584 "vscrollbar-policy", GTK_POLICY_NEVER,
1586 g_signal_connect (scrolled_window, "size-allocate",
1587 G_CALLBACK (size_allocate_cb),
1590 case EV_SIZING_FIT_WIDTH:
1591 g_object_set (G_OBJECT (scrolled_window),
1592 "hscrollbar-policy", GTK_POLICY_NEVER,
1593 "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
1595 g_signal_connect (scrolled_window, "size-allocate",
1596 G_CALLBACK (size_allocate_cb),
1599 case EV_SIZING_FREE:
1600 g_object_set (G_OBJECT (scrolled_window),
1601 "hscrollbar-policy", GTK_POLICY_AUTOMATIC,
1602 "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
1607 update_sizing_buttons (ev_window);
1611 ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
1613 const char *authors[] = {
1618 const char *documenters[] = {
1619 N_("Not so many..."),
1623 const char *license[] = {
1624 N_("Evince is free software; you can redistribute it and/or modify\n"
1625 "it under the terms of the GNU General Public License as published by\n"
1626 "the Free Software Foundation; either version 2 of the License, or\n"
1627 "(at your option) any later version.\n"),
1628 N_("Evince is distributed in the hope that it will be useful,\n"
1629 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1630 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1631 "GNU General Public License for more details.\n"),
1632 N_("You should have received a copy of the GNU General Public License\n"
1633 "along with Evince; if not, write to the Free Software Foundation, Inc.,\n"
1634 "59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n")
1637 char *license_trans;
1642 for (p = authors; *p; ++p)
1645 for (p = documenters; *p; ++p)
1649 license_trans = g_strconcat (_(license[0]), "\n", _(license[1]), "\n",
1650 _(license[2]), "\n", NULL);
1652 gtk_show_about_dialog (
1653 GTK_WINDOW (ev_window),
1654 "name", _("Evince"),
1657 _("\xc2\xa9 1996-2004 The Evince authors"),
1658 "license", license_trans,
1659 "website", "http://www.gnome.org/projects/evince",
1660 "comments", _("PostScript and PDF File Viewer."),
1662 "documenters", documenters,
1663 "translator-credits", _("translator-credits"),
1666 g_free (license_trans);
1670 ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window)
1672 update_chrome_flag (ev_window, EV_CHROME_TOOLBAR,
1673 GCONF_CHROME_TOOLBAR,
1674 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
1678 ev_window_view_statusbar_cb (GtkAction *action, EvWindow *ev_window)
1680 update_chrome_flag (ev_window, EV_CHROME_STATUSBAR,
1681 GCONF_CHROME_STATUSBAR,
1682 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
1686 ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window)
1688 update_chrome_flag (ev_window, EV_CHROME_SIDEBAR,
1689 GCONF_CHROME_SIDEBAR,
1690 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
1694 ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar, GParamSpec *pspec,
1695 EvWindow *ev_window)
1700 visible = GTK_WIDGET_VISIBLE (ev_sidebar);
1702 /* In fullscreen mode the sidebar is not visible,
1703 * but we don't want to update the chrome
1705 if (ev_window->priv->fullscreen_mode)
1708 action = gtk_action_group_get_action (ev_window->priv->action_group, "ViewSidebar");
1710 g_signal_handlers_block_by_func
1711 (action, G_CALLBACK (ev_window_view_sidebar_cb), ev_window);
1712 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
1713 g_signal_handlers_unblock_by_func
1714 (action, G_CALLBACK (ev_window_view_sidebar_cb), ev_window);
1716 update_chrome_flag (ev_window, EV_CHROME_SIDEBAR,
1717 GCONF_CHROME_SIDEBAR, visible);
1721 menu_item_select_cb (GtkMenuItem *proxy, EvWindow *ev_window)
1726 action = g_object_get_data (G_OBJECT (proxy), "gtk-action");
1727 g_return_if_fail (action != NULL);
1729 g_object_get (G_OBJECT (action), "tooltip", &message, NULL);
1731 gtk_statusbar_push (GTK_STATUSBAR (ev_window->priv->statusbar),
1732 ev_window->priv->help_message_cid, message);
1738 menu_item_deselect_cb (GtkMenuItem *proxy, EvWindow *ev_window)
1740 gtk_statusbar_pop (GTK_STATUSBAR (ev_window->priv->statusbar),
1741 ev_window->priv->help_message_cid);
1745 connect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
1746 GtkWidget *proxy, EvWindow *ev_window)
1748 if (GTK_IS_MENU_ITEM (proxy)) {
1749 g_signal_connect (proxy, "select",
1750 G_CALLBACK (menu_item_select_cb), ev_window);
1751 g_signal_connect (proxy, "deselect",
1752 G_CALLBACK (menu_item_deselect_cb),
1758 disconnect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
1759 GtkWidget *proxy, EvWindow *ev_window)
1761 if (GTK_IS_MENU_ITEM (proxy)) {
1762 g_signal_handlers_disconnect_by_func
1763 (proxy, G_CALLBACK (menu_item_select_cb), ev_window);
1764 g_signal_handlers_disconnect_by_func
1765 (proxy, G_CALLBACK (menu_item_deselect_cb), ev_window);
1770 update_current_page (EvWindow *ev_window,
1775 EvSidebarThumbnails *thumbs;
1777 thumbs = EV_SIDEBAR_THUMBNAILS (ev_window->priv->thumbs_sidebar);
1778 ev_sidebar_thumbnails_select_page (thumbs, ev_view_get_page (view));
1780 action = gtk_action_group_get_action
1781 (ev_window->priv->action_group, PAGE_SELECTOR_ACTION);
1783 page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
1784 ev_page_action_set_current_page (EV_PAGE_ACTION (action), page);
1788 view_page_changed_cb (EvView *view,
1789 EvWindow *ev_window)
1791 update_current_page (ev_window, view);
1792 update_action_sensitivity (ev_window);
1796 view_status_changed_cb (EvView *view,
1798 EvWindow *ev_window)
1800 const char *message;
1802 gtk_statusbar_pop (GTK_STATUSBAR (ev_window->priv->statusbar),
1803 ev_window->priv->view_message_cid);
1805 message = ev_view_get_status (view);
1807 gtk_statusbar_push (GTK_STATUSBAR (ev_window->priv->statusbar),
1808 ev_window->priv->view_message_cid, message);
1813 view_find_status_changed_cb (EvView *view,
1815 EvWindow *ev_window)
1819 text = ev_view_get_find_status (view);
1820 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
1825 find_bar_previous_cb (EggFindBar *find_bar,
1826 EvWindow *ev_window)
1828 ev_view_find_previous (EV_VIEW (ev_window->priv->view));
1832 find_bar_next_cb (EggFindBar *find_bar,
1833 EvWindow *ev_window)
1835 ev_view_find_next (EV_VIEW (ev_window->priv->view));
1839 find_bar_close_cb (EggFindBar *find_bar,
1840 EvWindow *ev_window)
1842 update_chrome_flag (ev_window, EV_CHROME_FINDBAR, NULL, FALSE);
1846 ev_window_page_mode_cb (GtkRadioAction *action,
1847 GtkRadioAction *activated_action,
1852 mode = gtk_radio_action_get_current_value (action);
1854 g_assert (mode == PAGE_MODE_CONTINUOUS_PAGE ||
1855 mode == PAGE_MODE_SINGLE_PAGE);
1857 ev_window_set_page_mode (window, (EvWindowPageMode) mode);
1861 find_bar_search_changed_cb (EggFindBar *find_bar,
1863 EvWindow *ev_window)
1865 gboolean case_sensitive;
1867 const char *search_string;
1869 g_return_if_fail (EV_IS_WINDOW (ev_window));
1871 /* Either the string or case sensitivity could have changed,
1872 * we connect this callback to both. We also connect it
1873 * to ::visible so when the find bar is hidden, we should
1874 * pretend the search string is NULL/""
1877 case_sensitive = egg_find_bar_get_case_sensitive (find_bar);
1878 visible = GTK_WIDGET_VISIBLE (find_bar);
1879 search_string = egg_find_bar_get_search_string (find_bar);
1882 g_printerr ("search for '%s'\n", search_string ? search_string : "(nil)");
1885 if (ev_window->priv->document &&
1886 EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
1887 if (visible && search_string) {
1888 ev_document_find_begin (EV_DOCUMENT_FIND (ev_window->priv->document), search_string, case_sensitive);
1890 ev_document_find_cancel (EV_DOCUMENT_FIND (ev_window->priv->document));
1891 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
1893 gtk_widget_queue_draw (GTK_WIDGET (ev_window->priv->view));
1899 ev_window_dispose (GObject *object)
1901 EvWindow *window = EV_WINDOW (object);
1902 EvWindowPrivate *priv = window->priv;
1904 if (priv->ui_manager) {
1905 g_object_unref (priv->ui_manager);
1906 priv->ui_manager = NULL;
1909 if (priv->action_group) {
1910 g_object_unref (priv->action_group);
1911 priv->action_group = NULL;
1914 if (priv->document) {
1915 g_object_unref (priv->document);
1916 priv->document = NULL;
1920 g_object_unref (priv->view);
1924 if (priv->page_view) {
1925 g_object_unref (priv->page_view);
1926 priv->page_view = NULL;
1929 if (priv->password_document) {
1930 g_object_unref (priv->password_document);
1931 priv->password_document = NULL;
1934 if (priv->password_uri) {
1935 g_free (priv->password_uri);
1936 priv->password_uri = NULL;
1939 destroy_fullscreen_popup (window);
1941 G_OBJECT_CLASS (ev_window_parent_class)->dispose (object);
1945 ev_window_class_init (EvWindowClass *ev_window_class)
1947 GObjectClass *g_object_class = G_OBJECT_CLASS (ev_window_class);
1948 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (ev_window_class);
1950 g_object_class->dispose = ev_window_dispose;
1952 widget_class->focus_in_event = ev_window_focus_in_event;
1953 widget_class->focus_out_event = ev_window_focus_out_event;
1955 g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
1959 static GtkActionEntry entries[] = {
1960 { "File", NULL, N_("_File") },
1961 { "Edit", NULL, N_("_Edit") },
1962 { "View", NULL, N_("_View") },
1963 { "Go", NULL, N_("_Go") },
1964 { "Help", NULL, N_("_Help") },
1967 { "FileOpen", GTK_STOCK_OPEN, NULL, "<control>O",
1968 N_("Open an existing document"),
1969 G_CALLBACK (ev_window_cmd_file_open) },
1970 { "FileSaveAs", GTK_STOCK_SAVE_AS, N_("_Save a Copy..."), NULL,
1971 N_("Save the current document with a new filename"),
1972 G_CALLBACK (ev_window_cmd_save_as) },
1973 { "FilePrint", GTK_STOCK_PRINT, N_("Print..."), "<control>P",
1974 N_("Print this document"),
1975 G_CALLBACK (ev_window_cmd_file_print) },
1976 { "FileCloseWindow", GTK_STOCK_CLOSE, NULL, "<control>W",
1977 N_("Close this window"),
1978 G_CALLBACK (ev_window_cmd_file_close_window) },
1981 { "EditCopy", GTK_STOCK_COPY, NULL, "<control>C",
1982 N_("Copy text from the document"),
1983 G_CALLBACK (ev_window_cmd_edit_copy) },
1984 { "EditSelectAll", NULL, N_("Select _All"), "<control>A",
1985 N_("Select the entire page"),
1986 G_CALLBACK (ev_window_cmd_edit_select_all) },
1987 { "EditFind", GTK_STOCK_FIND, NULL, "<control>F",
1988 N_("Find a word or phrase in the document"),
1989 G_CALLBACK (ev_window_cmd_edit_find) },
1992 { "ViewZoomIn", GTK_STOCK_ZOOM_IN, NULL, "<control>plus",
1993 N_("Enlarge the document"),
1994 G_CALLBACK (ev_window_cmd_view_zoom_in) },
1995 { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, NULL, "<control>minus",
1996 N_("Shrink the document"),
1997 G_CALLBACK (ev_window_cmd_view_zoom_out) },
1998 { "ViewNormalSize", GTK_STOCK_ZOOM_100, NULL, "<control>0",
1999 N_("Reset the zoom level to the default value"),
2000 G_CALLBACK (ev_window_cmd_view_normal_size) },
2001 { "ViewReload", GTK_STOCK_REFRESH, N_("_Reload"), "<control>R",
2002 N_("Reload the document"),
2003 G_CALLBACK (ev_window_cmd_view_reload) },
2006 { "GoPreviousPage", GTK_STOCK_GO_BACK, N_("_Previous Page"), "Page_Up",
2007 N_("Go to the previous page"),
2008 G_CALLBACK (ev_window_cmd_go_previous_page) },
2009 { "GoNextPage", GTK_STOCK_GO_FORWARD, N_("_Next Page"), "Page_Down",
2010 N_("Go to the next page"),
2011 G_CALLBACK (ev_window_cmd_go_next_page) },
2012 { "GoFirstPage", GTK_STOCK_GOTO_FIRST, N_("_First Page"), "<control>Home",
2013 N_("Go to the first page"),
2014 G_CALLBACK (ev_window_cmd_go_first_page) },
2015 { "GoLastPage", GTK_STOCK_GOTO_LAST, N_("_Last Page"), "<control>End",
2016 N_("Go to the last page"),
2017 G_CALLBACK (ev_window_cmd_go_last_page) },
2020 { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), NULL,
2021 N_("Display help for the viewer application"),
2022 G_CALLBACK (ev_window_cmd_help_contents) },
2024 { "HelpAbout", GTK_STOCK_ABOUT, N_("_About"), NULL,
2025 N_("Display credits for the document viewer creators"),
2026 G_CALLBACK (ev_window_cmd_help_about) },
2029 { "LeaveFullscreen", EV_STOCK_LEAVE_FULLSCREEN, N_("Leave Fullscreen"), "Escape",
2030 N_("Leave fullscreen mode"),
2031 G_CALLBACK (ev_window_cmd_leave_fullscreen) }
2035 static GtkToggleActionEntry toggle_entries[] = {
2037 { "ViewToolbar", NULL, N_("_Toolbar"), "<shift><control>T",
2038 N_("Show or hide the toolbar"),
2039 G_CALLBACK (ev_window_view_toolbar_cb), TRUE },
2040 { "ViewStatusbar", NULL, N_("_Statusbar"), NULL,
2041 N_("Show or hide the statusbar"),
2042 G_CALLBACK (ev_window_view_statusbar_cb), TRUE },
2043 { "ViewSidebar", NULL, N_("Side _pane"), "F9",
2044 N_("Show or hide the side pane"),
2045 G_CALLBACK (ev_window_view_sidebar_cb), TRUE },
2046 { "ViewFullscreen", NULL, N_("_Fullscreen"), "F11",
2047 N_("Expand the window to fill the screen"),
2048 G_CALLBACK (ev_window_cmd_view_fullscreen) },
2049 { "ViewBestFit", EV_STOCK_ZOOM_PAGE, N_("_Best Fit"), NULL,
2050 N_("Make the current document fill the window"),
2051 G_CALLBACK (ev_window_cmd_view_best_fit) },
2052 { "ViewPageWidth", EV_STOCK_ZOOM_WIDTH, N_("Fit Page _Width"), NULL,
2053 N_("Make the current document fill the window width"),
2054 G_CALLBACK (ev_window_cmd_view_page_width) },
2057 static GtkRadioActionEntry page_view_entries[] = {
2058 { "SinglePage", GTK_STOCK_DND, N_("Single"), NULL,
2059 N_("Show the document one page at a time"),
2060 PAGE_MODE_SINGLE_PAGE },
2061 { "ContinuousPage", GTK_STOCK_DND_MULTIPLE, N_("Multi"), NULL,
2062 N_("Show the full document at once"),
2063 PAGE_MODE_CONTINUOUS_PAGE }
2067 goto_page_cb (GtkAction *action, int page_number, EvWindow *ev_window)
2069 EvView *view = EV_VIEW (ev_window->priv->view);
2071 if (ev_view_get_page (view) != page_number) {
2072 ev_view_set_page (view, page_number);
2077 drag_data_received_cb (GtkWidget *widget, GdkDragContext *context,
2078 gint x, gint y, GtkSelectionData *selection_data,
2079 guint info, guint time, gpointer gdata)
2081 GList *uri_list = NULL;
2083 uri_list = gnome_vfs_uri_list_parse ((gchar *) selection_data->data);
2086 ev_window_open_uri_list (EV_WINDOW (widget), uri_list);
2088 gnome_vfs_uri_list_free (uri_list);
2090 gtk_drag_finish (context, TRUE, FALSE, time);
2095 register_custom_actions (EvWindow *window, GtkActionGroup *group)
2099 action = g_object_new (EV_TYPE_PAGE_ACTION,
2100 "name", PAGE_SELECTOR_ACTION,
2102 "tooltip", _("Select Page"),
2104 g_signal_connect (action, "goto_page",
2105 G_CALLBACK (goto_page_cb), window);
2106 gtk_action_group_add_action (group, action);
2107 g_object_unref (action);
2111 set_action_properties (GtkActionGroup *action_group)
2115 action = gtk_action_group_get_action (action_group, "GoPreviousPage");
2116 /*translators: this is the label for toolbar button*/
2117 g_object_set (action, "short_label", _("Previous"), NULL);
2118 g_object_set (action, "is-important", TRUE, NULL);
2119 action = gtk_action_group_get_action (action_group, "GoNextPage");
2120 /*translators: this is the label for toolbar button*/
2121 g_object_set (action, "is-important", TRUE, NULL);
2122 g_object_set (action, "short_label", _("Next"), NULL);
2123 action = gtk_action_group_get_action (action_group, "ViewPageWidth");
2124 /*translators: this is the label for toolbar button*/
2125 g_object_set (action, "short_label", _("Fit Width"), NULL);
2126 action = gtk_action_group_get_action (action_group, "ViewZoomIn");
2128 action = gtk_action_group_get_action (action_group, "LeaveFullscreen");
2129 g_object_set (action, "is-important", TRUE, NULL);
2133 set_chrome_actions (EvWindow *window)
2135 EvWindowPrivate *priv = window->priv;
2136 GtkActionGroup *action_group = priv->action_group;
2139 action= gtk_action_group_get_action (action_group, "ViewToolbar");
2140 g_signal_handlers_block_by_func
2141 (action, G_CALLBACK (ev_window_view_toolbar_cb), window);
2142 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
2143 (priv->chrome & EV_CHROME_TOOLBAR) != 0);
2144 g_signal_handlers_unblock_by_func
2145 (action, G_CALLBACK (ev_window_view_toolbar_cb), window);
2147 action= gtk_action_group_get_action (action_group, "ViewSidebar");
2148 g_signal_handlers_block_by_func
2149 (action, G_CALLBACK (ev_window_view_sidebar_cb), window);
2150 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
2151 (priv->chrome & EV_CHROME_SIDEBAR) != 0);
2152 g_signal_handlers_unblock_by_func
2153 (action, G_CALLBACK (ev_window_view_sidebar_cb), window);
2155 action= gtk_action_group_get_action (action_group, "ViewStatusbar");
2156 g_signal_handlers_block_by_func
2157 (action, G_CALLBACK (ev_window_view_statusbar_cb), window);
2158 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
2159 (priv->chrome & EV_CHROME_STATUSBAR) != 0);
2160 g_signal_handlers_unblock_by_func
2161 (action, G_CALLBACK (ev_window_view_statusbar_cb), window);
2167 EvChrome chrome = EV_CHROME_NORMAL;
2168 GConfClient *client;
2171 client = gconf_client_get_default ();
2173 value = gconf_client_get (client, GCONF_CHROME_TOOLBAR, NULL);
2174 if (value != NULL) {
2175 if (value->type == GCONF_VALUE_BOOL && !gconf_value_get_bool (value)) {
2176 chrome &= ~EV_CHROME_TOOLBAR;
2178 gconf_value_free (value);
2181 value = gconf_client_get (client, GCONF_CHROME_SIDEBAR, NULL);
2182 if (value != NULL) {
2183 if (value->type == GCONF_VALUE_BOOL && !gconf_value_get_bool (value)) {
2184 chrome &= ~EV_CHROME_SIDEBAR;
2186 gconf_value_free (value);
2189 value = gconf_client_get (client, GCONF_CHROME_STATUSBAR, NULL);
2190 if (value != NULL) {
2191 if (value->type == GCONF_VALUE_BOOL && !gconf_value_get_bool (value)) {
2192 chrome &= ~EV_CHROME_STATUSBAR;
2194 gconf_value_free (value);
2197 g_object_unref (client);
2203 ev_window_init (EvWindow *ev_window)
2205 GtkActionGroup *action_group;
2206 GtkAccelGroup *accel_group;
2207 GError *error = NULL;
2208 GtkWidget *sidebar_widget, *toolbar_dock;
2210 GConfClient *client;
2213 ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
2215 ev_window->priv->page_mode = PAGE_MODE_SINGLE_PAGE;
2216 update_window_title (NULL, NULL, ev_window);
2218 ev_window->priv->main_box = gtk_vbox_new (FALSE, 0);
2219 gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box);
2220 gtk_widget_show (ev_window->priv->main_box);
2222 action_group = gtk_action_group_new ("MenuActions");
2223 ev_window->priv->action_group = action_group;
2224 gtk_action_group_set_translation_domain (action_group, NULL);
2225 gtk_action_group_add_actions (action_group, entries,
2226 G_N_ELEMENTS (entries), ev_window);
2227 gtk_action_group_add_toggle_actions (action_group, toggle_entries,
2228 G_N_ELEMENTS (toggle_entries),
2230 gtk_action_group_add_radio_actions (action_group, page_view_entries,
2231 G_N_ELEMENTS (page_view_entries),
2232 ev_window->priv->page_mode,
2233 G_CALLBACK (ev_window_page_mode_cb),
2235 set_action_properties (action_group);
2236 register_custom_actions (ev_window, action_group);
2238 ev_window->priv->ui_manager = gtk_ui_manager_new ();
2239 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
2243 gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
2244 gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
2246 g_signal_connect (ev_window->priv->ui_manager, "connect_proxy",
2247 G_CALLBACK (connect_proxy_cb), ev_window);
2248 g_signal_connect (ev_window->priv->ui_manager, "disconnect_proxy",
2249 G_CALLBACK (disconnect_proxy_cb), ev_window);
2251 if (!gtk_ui_manager_add_ui_from_file (ev_window->priv->ui_manager,
2252 DATADIR"/evince-ui.xml",
2254 g_message ("building menus failed: %s", error->message);
2255 g_error_free (error);
2258 ev_window->priv->menubar =
2259 gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
2261 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
2262 ev_window->priv->menubar,
2265 /* This sucks, but there is no way to have a draw=no, expand=true separator
2266 * in a GtkUIManager-built toolbar. So, just add another toolbar.
2267 * See gtk+ bug 166489.
2269 toolbar_dock = ev_window->priv->toolbar_dock = gtk_hbox_new (FALSE, 0);
2270 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), toolbar_dock,
2272 gtk_widget_show (toolbar_dock);
2274 ev_window->priv->toolbar =
2275 gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
2277 gtk_box_pack_start (GTK_BOX (toolbar_dock), ev_window->priv->toolbar,
2279 gtk_widget_show (ev_window->priv->toolbar);
2281 ev_window->priv->fullscreen_toolbar =
2282 gtk_ui_manager_get_widget (ev_window->priv->ui_manager, "/LeaveFullscreenToolbar");
2283 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (ev_window->priv->fullscreen_toolbar), TRUE);
2284 gtk_toolbar_set_style (GTK_TOOLBAR (ev_window->priv->fullscreen_toolbar), GTK_TOOLBAR_BOTH_HORIZ);
2286 /* Add the main area */
2287 ev_window->priv->hpaned = gtk_hpaned_new ();
2288 g_signal_connect (ev_window->priv->hpaned,
2290 G_CALLBACK (ev_window_sidebar_position_change_cb),
2293 sidebar_size = SIDEBAR_DEFAULT_SIZE;
2294 client = gconf_client_get_default ();
2295 value = gconf_client_get (client, GCONF_SIDEBAR_SIZE, NULL);
2296 if (value != NULL) {
2297 if (value->type == GCONF_VALUE_INT) {
2298 sidebar_size = gconf_value_get_int (value);
2300 gconf_value_free (value);
2302 g_object_unref (client);
2303 gtk_paned_set_position (GTK_PANED (ev_window->priv->hpaned), sidebar_size);
2304 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), ev_window->priv->hpaned,
2306 gtk_widget_show (ev_window->priv->hpaned);
2308 ev_window->priv->sidebar = ev_sidebar_new ();
2309 gtk_paned_pack1 (GTK_PANED (ev_window->priv->hpaned),
2310 ev_window->priv->sidebar, FALSE, FALSE);
2311 gtk_widget_show (ev_window->priv->sidebar);
2313 /* Stub sidebar, for now */
2314 sidebar_widget = ev_sidebar_links_new ();
2315 gtk_widget_show (sidebar_widget);
2316 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
2321 ev_window->priv->thumbs_sidebar = ev_sidebar_thumbnails_new ();
2322 gtk_widget_show (ev_window->priv->thumbs_sidebar);
2323 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
2326 ev_window->priv->thumbs_sidebar);
2328 ev_window->priv->scrolled_window =
2329 GTK_WIDGET (g_object_new (GTK_TYPE_SCROLLED_WINDOW,
2330 "shadow-type", GTK_SHADOW_IN,
2332 gtk_widget_show (ev_window->priv->scrolled_window);
2334 gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned),
2335 ev_window->priv->scrolled_window);
2337 ev_window->priv->view = ev_view_new ();
2338 //ev_window->priv->page_view = ev_page_view_new ();
2339 ev_window->priv->password_view = ev_password_view_new ();
2340 g_signal_connect_swapped (ev_window->priv->password_view,
2342 G_CALLBACK (ev_window_popup_password_dialog),
2344 gtk_widget_show (ev_window->priv->view);
2345 //gtk_widget_show (ev_window->priv->page_view);
2346 gtk_widget_show (ev_window->priv->password_view);
2348 /* We own a ref on these widgets, as we can swap them in and out */
2349 g_object_ref (ev_window->priv->view);
2350 //g_object_ref (ev_window->priv->page_view);
2351 g_object_ref (ev_window->priv->password_view);
2353 gtk_container_add (GTK_CONTAINER (ev_window->priv->scrolled_window),
2354 ev_window->priv->view);
2355 g_signal_connect (ev_window->priv->view,
2357 G_CALLBACK (view_page_changed_cb),
2359 g_signal_connect (ev_window->priv->view,
2360 "notify::find-status",
2361 G_CALLBACK (view_find_status_changed_cb),
2363 g_signal_connect (ev_window->priv->view,
2365 G_CALLBACK (view_status_changed_cb),
2368 ev_window->priv->statusbar = gtk_statusbar_new ();
2369 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
2370 ev_window->priv->statusbar,
2372 ev_window->priv->help_message_cid = gtk_statusbar_get_context_id
2373 (GTK_STATUSBAR (ev_window->priv->statusbar), "help_message");
2374 ev_window->priv->view_message_cid = gtk_statusbar_get_context_id
2375 (GTK_STATUSBAR (ev_window->priv->statusbar), "view_message");
2377 ev_window->priv->find_bar = egg_find_bar_new ();
2378 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
2379 ev_window->priv->find_bar,
2382 ev_window->priv->chrome = load_chrome ();
2383 set_chrome_actions (ev_window);
2384 update_chrome_visibility (ev_window);
2386 /* Connect sidebar signals */
2387 g_signal_connect (ev_window->priv->sidebar,
2389 G_CALLBACK (ev_window_sidebar_visibility_changed_cb),
2392 /* Connect to find bar signals */
2393 g_signal_connect (ev_window->priv->find_bar,
2395 G_CALLBACK (find_bar_previous_cb),
2397 g_signal_connect (ev_window->priv->find_bar,
2399 G_CALLBACK (find_bar_next_cb),
2401 g_signal_connect (ev_window->priv->find_bar,
2403 G_CALLBACK (find_bar_close_cb),
2405 g_signal_connect (ev_window->priv->find_bar,
2406 "notify::search-string",
2407 G_CALLBACK (find_bar_search_changed_cb),
2409 g_signal_connect (ev_window->priv->find_bar,
2410 "notify::case-sensitive",
2411 G_CALLBACK (find_bar_search_changed_cb),
2413 g_signal_connect (ev_window->priv->find_bar,
2415 G_CALLBACK (find_bar_search_changed_cb),
2418 g_signal_connect (ev_window, "window-state-event",
2419 G_CALLBACK (ev_window_state_event_cb),
2422 /* Give focus to the scrolled window */
2423 gtk_widget_grab_focus (ev_window->priv->scrolled_window);
2426 gtk_drag_dest_unset (GTK_WIDGET (ev_window));
2427 gtk_drag_dest_set (GTK_WIDGET (ev_window), GTK_DEST_DEFAULT_ALL, ev_drop_types,
2428 sizeof (ev_drop_types) / sizeof (ev_drop_types[0]),
2430 g_signal_connect (G_OBJECT (ev_window), "drag_data_received",
2431 G_CALLBACK (drag_data_received_cb), NULL);
2433 /* Set it to something random to force a change */
2434 ev_window->priv->sizing_mode = EV_SIZING_FREE;
2435 ev_window_set_sizing_mode (ev_window, EV_SIZING_FIT_WIDTH);
2436 update_action_sensitivity (ev_window);