1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* this file is part of evince, a gnome document viewer
4 * Copyright (C) 2004 Martin Kretzschmar
5 * Copyright (C) 2004 Red Hat, Inc.
6 * Copyright (C) 2000, 2001, 2002, 2003, 2004 Marco Pesenti Gritti
7 * Copyright (C) 2003, 2004 Christian Persch
10 * Martin Kretzschmar <martink@gnome.org>
12 * Evince is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * Evince is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
31 #include "ev-window.h"
32 #include "ev-navigation-action.h"
33 #include "ev-page-action.h"
34 #include "ev-sidebar.h"
35 #include "ev-sidebar-bookmarks.h"
36 #include "ev-sidebar-thumbnails.h"
38 #include "ev-print-job.h"
39 #include "ev-document-find.h"
40 #include "eggfindbar.h"
42 #include "pdf-document.h"
43 #include "pixbuf-document.h"
44 #include "ps-document.h"
46 #include <glib/gi18n.h>
48 #include <libgnomevfs/gnome-vfs-mime-utils.h>
49 #include <libgnomeprintui/gnome-print-dialog.h>
53 #include "ev-application.h"
54 #include "ev-stock-icons.h"
66 struct _EvWindowPrivate {
72 GtkActionGroup *action_group;
73 GtkUIManager *ui_manager;
75 guint help_message_cid;
76 GtkWidget *exit_fullscreen_popup;
78 GtkAction *page_action;
82 gboolean fullscreen_mode;
86 /* enable these to add support for signals */
87 static guint ev_window_signals [N_SIGNALS] = { 0 };
90 static void update_fullscreen_popup (EvWindow *window);
92 static GObjectClass *parent_class = NULL;
94 G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
96 #define EV_WINDOW_GET_PRIVATE(object) \
97 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_WINDOW, EvWindowPrivate))
101 ev_window_get_attribute (EvWindow *self)
103 g_return_val_if_fail (self != NULL && EV_IS_WINDOW (self), NULL);
105 return self->priv->attribute;
109 ev_window_set_attribute (EvWindow* self, const char *attribute)
111 g_assert (self != NULL && EV_IS_WINDOW (self));
112 g_assert (attribute != NULL);
114 if (self->priv->attribute != NULL) {
115 g_free (self->priv->attribute);
118 self->priv->attribute = g_strdup (attribute);
120 g_object_notify (G_OBJECT (self), "attribute");
124 ev_window_get_property (GObject *object, guint prop_id, GValue *value,
125 GParamSpec *param_spec)
129 self = EV_WINDOW (object);
133 g_value_set_string (value, self->priv->attribute);
136 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
144 ev_window_set_property (GObject *object, guint prop_id, const GValue *value,
145 GParamSpec *param_spec)
149 self = EV_WINDOW (object);
153 ev_window_set_attribute (self, g_value_get_string (value));
156 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
165 set_action_sensitive (EvWindow *ev_window,
169 GtkAction *action = gtk_action_group_get_action (ev_window->priv->action_group,
171 gtk_action_set_sensitive (action, sensitive);
175 update_action_sensitivity (EvWindow *ev_window)
180 if (ev_window->priv->document)
181 n_pages = ev_document_get_n_pages (ev_window->priv->document);
185 page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
187 set_action_sensitive (ev_window, "GoFirstPage", page > 1);
188 set_action_sensitive (ev_window, "GoPreviousPage", page > 1);
189 set_action_sensitive (ev_window, "GoNextPage", page < n_pages);
190 set_action_sensitive (ev_window, "GoLastPage", page < n_pages);
194 ev_window_is_empty (const EvWindow *ev_window)
196 g_return_val_if_fail (EV_IS_WINDOW (ev_window), FALSE);
198 return ev_window->priv->document == NULL;
202 unable_to_load (EvWindow *ev_window,
203 const char *error_message)
207 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
208 GTK_DIALOG_DESTROY_WITH_PARENT,
211 _("Unable to open document"));
212 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
213 "%s", error_message);
214 gtk_dialog_run (GTK_DIALOG (dialog));
215 gtk_widget_destroy (dialog);
218 /* Would be nice to have this in gdk-pixbuf */
220 mime_type_supported_by_gdk_pixbuf (const gchar *mime_type)
222 GSList *formats, *list;
223 gboolean retval = FALSE;
225 formats = gdk_pixbuf_get_formats ();
229 GdkPixbufFormat *format = list->data;
233 if (gdk_pixbuf_format_is_disabled (format))
236 mime_types = gdk_pixbuf_format_get_mime_types (format);
238 for (i = 0; mime_types[i] != NULL; i++) {
239 if (strcmp (mime_types[i], mime_type) == 0) {
251 g_slist_free (formats);
257 update_window_title (EvDocument *document, GParamSpec *pspec, EvWindow *ev_window)
261 if (document == NULL) {
262 title = g_strdup (_("Document Viewer"));
264 title = ev_document_get_title (document);
267 title = g_path_get_basename (ev_window->priv->uri);
271 gtk_window_set_title (GTK_WINDOW (ev_window), title);
277 update_total_pages (EvWindow *ev_window)
279 EvPageAction *page_action;
282 pages = ev_document_get_n_pages (ev_window->priv->document);
283 page_action = EV_PAGE_ACTION (ev_window->priv->page_action);
284 ev_page_action_set_total_pages (page_action, pages);
288 ev_window_open (EvWindow *ev_window, const char *uri)
290 EvDocument *document = NULL;
293 g_free (ev_window->priv->uri);
294 ev_window->priv->uri = g_strdup (uri);
296 mime_type = gnome_vfs_get_mime_type (uri);
298 if (mime_type == NULL)
300 else if (!strcmp (mime_type, "application/pdf"))
301 document = g_object_new (PDF_TYPE_DOCUMENT, NULL);
302 else if (!strcmp (mime_type, "application/postscript"))
303 document = g_object_new (PS_TYPE_DOCUMENT, NULL);
304 else if (mime_type_supported_by_gdk_pixbuf (mime_type))
305 document = g_object_new (PIXBUF_TYPE_DOCUMENT, NULL);
308 GError *error = NULL;
310 g_signal_connect_object (G_OBJECT (document),
312 G_CALLBACK (update_window_title),
315 if (ev_document_load (document, uri, &error)) {
316 if (ev_window->priv->document)
317 g_object_unref (ev_window->priv->document);
318 ev_window->priv->document = document;
320 ev_view_set_document (EV_VIEW (ev_window->priv->view),
322 ev_sidebar_set_document (EV_SIDEBAR (ev_window->priv->sidebar),
325 update_total_pages (ev_window);
326 update_action_sensitivity (ev_window);
328 g_assert (error != NULL);
329 g_object_unref (document);
330 unable_to_load (ev_window, error->message);
331 g_error_free (error);
336 error_message = g_strdup_printf (_("Unhandled MIME type: '%s'"),
337 mime_type?mime_type:"<Unknown MIME Type>");
338 unable_to_load (ev_window, error_message);
339 g_free (error_message);
346 ev_window_cmd_file_open (GtkAction *action, EvWindow *ev_window)
348 ev_application_open (EV_APP, NULL);
352 using_postscript_printer (GnomePrintConfig *config)
354 const guchar *driver;
355 const guchar *transport;
357 driver = gnome_print_config_get (
358 config, (const guchar *)"Settings.Engine.Backend.Driver");
360 transport = gnome_print_config_get (
361 config, (const guchar *)"Settings.Transport.Backend");
364 if (!strcmp ((const gchar *)driver, "gnome-print-ps"))
368 } else if (transport) {
369 if (!strcmp ((const gchar *)transport, "CUPS"))
377 ev_window_print (EvWindow *ev_window)
379 GnomePrintConfig *config;
381 GtkWidget *print_dialog;
382 EvPrintJob *print_job = NULL;
384 g_return_if_fail (EV_IS_WINDOW (ev_window));
385 g_return_if_fail (ev_window->priv->document != NULL);
387 config = gnome_print_config_default ();
388 job = gnome_print_job_new (config);
390 print_dialog = gnome_print_dialog_new (job, _("Print"),
391 (GNOME_PRINT_DIALOG_RANGE |
392 GNOME_PRINT_DIALOG_COPIES));
393 gtk_dialog_set_response_sensitive (GTK_DIALOG (print_dialog),
394 GNOME_PRINT_DIALOG_RESPONSE_PREVIEW,
399 response = gtk_dialog_run (GTK_DIALOG (print_dialog));
401 if (response != GNOME_PRINT_DIALOG_RESPONSE_PRINT)
404 /* FIXME: Change this when we have the first backend
405 * that can print more than postscript
407 if (!using_postscript_printer (config)) {
410 dialog = gtk_message_dialog_new (
411 GTK_WINDOW (print_dialog), GTK_DIALOG_MODAL,
412 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
413 _("Printing is not supported on this printer."));
414 gtk_message_dialog_format_secondary_text (
415 GTK_MESSAGE_DIALOG (dialog),
416 _("You were trying to print to a printer using the \"%s\" driver. This program requires a PostScript printer driver."),
417 gnome_print_config_get (
418 config, "Settings.Engine.Backend.Driver"));
419 gtk_dialog_run (GTK_DIALOG (dialog));
420 gtk_widget_destroy (dialog);
425 print_job = g_object_new (EV_TYPE_PRINT_JOB,
426 "gnome_print_job", job,
427 "document", ev_window->priv->document,
428 "print_dialog", print_dialog,
433 gtk_widget_destroy (print_dialog);
435 if (print_job != NULL)
436 ev_print_job_print (print_job, GTK_WINDOW (ev_window));
440 ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
442 ev_window_print (ev_window);
446 ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
448 g_return_if_fail (EV_IS_WINDOW (ev_window));
450 gtk_widget_destroy (GTK_WIDGET (ev_window));
454 find_not_supported_dialog (EvWindow *ev_window)
458 /* If you change this so it isn't modal, be sure you don't
459 * allow multiple copies of the dialog...
462 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
463 GTK_DIALOG_DESTROY_WITH_PARENT,
466 _("The \"Find\" feature will not work with this document"));
467 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
468 _("Searching for text is only supported for PDF documents."));
469 gtk_dialog_run (GTK_DIALOG (dialog));
470 gtk_widget_destroy (dialog);
474 ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window)
476 g_return_if_fail (EV_IS_WINDOW (ev_window));
478 if (ev_window->priv->document == NULL) {
479 g_printerr ("We should have set the Find menu item insensitive since there's no document\n");
480 } else if (!EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
481 find_not_supported_dialog (ev_window);
483 gtk_widget_show (ev_window->priv->find_bar);
485 if (ev_window->priv->exit_fullscreen_popup)
486 update_fullscreen_popup (ev_window);
488 egg_find_bar_grab_focus (EGG_FIND_BAR (ev_window->priv->find_bar));
493 ev_window_cmd_edit_copy (GtkAction *action, EvWindow *ev_window)
495 g_return_if_fail (EV_IS_WINDOW (ev_window));
501 update_fullscreen_popup (EvWindow *window)
503 GtkWidget *popup = window->priv->exit_fullscreen_popup;
504 int popup_width, popup_height;
505 GdkRectangle screen_rect;
507 g_return_if_fail (popup != NULL);
512 popup_width = popup->requisition.width;
513 popup_height = popup->requisition.height;
515 /* FIXME multihead */
516 gdk_screen_get_monitor_geometry (gdk_screen_get_default (),
517 gdk_screen_get_monitor_at_window
518 (gdk_screen_get_default (),
519 GTK_WIDGET (window)->window),
522 if (GTK_WIDGET_VISIBLE (window->priv->find_bar)) {
525 gtk_widget_size_request (window->priv->find_bar, &req);
527 screen_rect.height -= req.height;
530 if (gtk_widget_get_direction (popup) == GTK_TEXT_DIR_RTL)
532 gtk_window_move (GTK_WINDOW (popup),
533 screen_rect.x + screen_rect.width - popup_width,
534 screen_rect.height - popup_height);
538 gtk_window_move (GTK_WINDOW (popup),
539 screen_rect.x, screen_rect.height - popup_height);
544 screen_size_changed_cb (GdkScreen *screen,
547 update_fullscreen_popup (window);
551 destroy_exit_fullscreen_popup (EvWindow *window)
553 if (window->priv->exit_fullscreen_popup != NULL)
555 /* FIXME multihead */
556 g_signal_handlers_disconnect_by_func
557 (gdk_screen_get_default (),
558 G_CALLBACK (screen_size_changed_cb), window);
560 gtk_widget_destroy (window->priv->exit_fullscreen_popup);
561 window->priv->exit_fullscreen_popup = NULL;
566 exit_fullscreen_button_clicked_cb (GtkWidget *button, EvWindow *window)
570 action = gtk_action_group_get_action (window->priv->action_group, "ViewFullscreen");
571 g_return_if_fail (action != NULL);
573 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), FALSE);
577 fullscreen_popup_size_request_cb (GtkWidget *popup, GtkRequisition *req, EvWindow *window)
579 update_fullscreen_popup (window);
583 ev_window_fullscreen (EvWindow *window)
585 GtkWidget *popup, *button, *icon, *label, *hbox, *main_menu;
587 window->priv->fullscreen_mode = TRUE;
589 popup = gtk_window_new (GTK_WINDOW_POPUP);
590 window->priv->exit_fullscreen_popup = popup;
592 button = gtk_button_new ();
593 g_signal_connect (button, "clicked",
594 G_CALLBACK (exit_fullscreen_button_clicked_cb),
596 gtk_widget_show (button);
597 gtk_container_add (GTK_CONTAINER (popup), button);
599 hbox = gtk_hbox_new (FALSE, 2);
600 gtk_widget_show (hbox);
601 gtk_container_add (GTK_CONTAINER (button), hbox);
603 icon = gtk_image_new_from_stock (GTK_STOCK_QUIT, GTK_ICON_SIZE_BUTTON);
604 gtk_widget_show (icon);
605 gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
607 label = gtk_label_new (_("Exit Fullscreen"));
608 gtk_widget_show (label);
609 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
611 gtk_window_set_resizable (GTK_WINDOW (popup), FALSE);
613 /* FIXME multihead */
614 g_signal_connect (gdk_screen_get_default (), "size-changed",
615 G_CALLBACK (screen_size_changed_cb), window);
616 g_signal_connect (popup, "size_request",
617 G_CALLBACK (fullscreen_popup_size_request_cb), window);
619 main_menu = gtk_ui_manager_get_widget (window->priv->ui_manager, "/MainMenu");
620 gtk_widget_hide (main_menu);
621 gtk_widget_hide (window->priv->statusbar);
623 update_fullscreen_popup (window);
625 gtk_widget_show (popup);
629 ev_window_unfullscreen (EvWindow *window)
631 GtkWidget *main_menu;
633 window->priv->fullscreen_mode = FALSE;
635 main_menu = gtk_ui_manager_get_widget (window->priv->ui_manager, "/MainMenu");
636 gtk_widget_show (main_menu);
637 gtk_widget_show (window->priv->statusbar);
639 destroy_exit_fullscreen_popup (window);
643 ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *ev_window)
647 g_return_if_fail (EV_IS_WINDOW (ev_window));
649 fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
652 gtk_window_fullscreen (GTK_WINDOW (ev_window));
654 gtk_window_unfullscreen (GTK_WINDOW (ev_window));
659 ev_window_state_event_cb (GtkWidget *widget, GdkEventWindowState *event, EvWindow *window)
661 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
663 GtkActionGroup *action_group;
667 fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
671 ev_window_fullscreen (window);
675 ev_window_unfullscreen (window);
678 action_group = window->priv->action_group;
680 action = gtk_action_group_get_action (action_group, "ViewFullscreen");
681 g_signal_handlers_block_by_func
682 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
683 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), fullscreen);
684 g_signal_handlers_unblock_by_func
685 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
693 ev_window_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *ev_window)
695 gtk_window_unfullscreen (GTK_WINDOW (ev_window));
702 ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window)
704 g_return_if_fail (EV_IS_WINDOW (ev_window));
706 ev_view_zoom_in (EV_VIEW (ev_window->priv->view));
710 ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window)
712 g_return_if_fail (EV_IS_WINDOW (ev_window));
714 ev_view_zoom_out (EV_VIEW (ev_window->priv->view));
718 ev_window_cmd_view_normal_size (GtkAction *action, EvWindow *ev_window)
720 g_return_if_fail (EV_IS_WINDOW (ev_window));
722 ev_view_normal_size (EV_VIEW (ev_window->priv->view));
726 ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
728 g_return_if_fail (EV_IS_WINDOW (ev_window));
730 ev_view_best_fit (EV_VIEW (ev_window->priv->view));
734 ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
736 g_return_if_fail (EV_IS_WINDOW (ev_window));
738 ev_view_fit_width (EV_VIEW (ev_window->priv->view));
742 ev_window_cmd_go_back (GtkAction *action, EvWindow *ev_window)
744 g_return_if_fail (EV_IS_WINDOW (ev_window));
750 ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window)
752 g_return_if_fail (EV_IS_WINDOW (ev_window));
758 ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
760 g_return_if_fail (EV_IS_WINDOW (ev_window));
762 ev_view_set_page (EV_VIEW (ev_window->priv->view),
763 ev_view_get_page (EV_VIEW (ev_window->priv->view)) - 1);
767 ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
769 g_return_if_fail (EV_IS_WINDOW (ev_window));
771 ev_view_set_page (EV_VIEW (ev_window->priv->view),
772 ev_view_get_page (EV_VIEW (ev_window->priv->view)) + 1);
776 ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
778 g_return_if_fail (EV_IS_WINDOW (ev_window));
780 ev_view_set_page (EV_VIEW (ev_window->priv->view), 1);
784 ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
786 g_return_if_fail (EV_IS_WINDOW (ev_window));
788 ev_view_set_page (EV_VIEW (ev_window->priv->view), G_MAXINT);
792 ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
794 g_return_if_fail (EV_IS_WINDOW (ev_window));
800 ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
802 const char *authors[] = {
807 const char *documenters[] = {
808 N_("Not so many..."),
812 const char *license[] = {
813 N_("Evince is free software; you can redistribute it and/or modify\n"
814 "it under the terms of the GNU General Public License as published by\n"
815 "the Free Software Foundation; either version 2 of the License, or\n"
816 "(at your option) any later version.\n"),
817 N_("Evince is distributed in the hope that it will be useful,\n"
818 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
819 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
820 "GNU General Public License for more details.\n"),
821 N_("You should have received a copy of the GNU General Public License\n"
822 "along with Evince; if not, write to the Free Software Foundation, Inc.,\n"
823 "59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n")
831 for (p = authors; *p; ++p)
834 for (p = documenters; *p; ++p)
838 license_trans = g_strconcat (_(license[0]), "\n", _(license[1]), "\n",
839 _(license[2]), "\n", NULL);
841 gtk_show_about_dialog (
842 GTK_WINDOW (ev_window),
846 _("\xc2\xa9 1996-2004 The Evince authors"),
847 "license", license_trans,
848 "website", "http://www.gnome.org/projects/evince",
849 "comments", _("PostScript and PDF File Viewer."),
851 "documenters", documenters,
852 "translator-credits", _("translator-credits"),
855 g_free (license_trans);
859 ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window)
862 G_OBJECT (gtk_ui_manager_get_widget (
863 ev_window->priv->ui_manager,
866 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
871 ev_window_view_statusbar_cb (GtkAction *action, EvWindow *ev_window)
874 ev_window->priv->statusbar,
876 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
881 ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window)
884 ev_window->priv->sidebar,
886 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
891 menu_item_select_cb (GtkMenuItem *proxy, EvWindow *ev_window)
896 action = g_object_get_data (G_OBJECT (proxy), "gtk-action");
897 g_return_if_fail (action != NULL);
899 g_object_get (G_OBJECT (action), "tooltip", &message, NULL);
901 gtk_statusbar_push (GTK_STATUSBAR (ev_window->priv->statusbar),
902 ev_window->priv->help_message_cid, message);
908 menu_item_deselect_cb (GtkMenuItem *proxy, EvWindow *ev_window)
910 gtk_statusbar_pop (GTK_STATUSBAR (ev_window->priv->statusbar),
911 ev_window->priv->help_message_cid);
915 connect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
916 GtkWidget *proxy, EvWindow *ev_window)
918 if (GTK_IS_MENU_ITEM (proxy)) {
919 g_signal_connect (proxy, "select",
920 G_CALLBACK (menu_item_select_cb), ev_window);
921 g_signal_connect (proxy, "deselect",
922 G_CALLBACK (menu_item_deselect_cb),
928 disconnect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
929 GtkWidget *proxy, EvWindow *ev_window)
931 if (GTK_IS_MENU_ITEM (proxy)) {
932 g_signal_handlers_disconnect_by_func
933 (proxy, G_CALLBACK (menu_item_select_cb), ev_window);
934 g_signal_handlers_disconnect_by_func
935 (proxy, G_CALLBACK (menu_item_deselect_cb), ev_window);
940 update_current_page (EvWindow *ev_window)
942 EvPageAction *page_action;
945 page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
946 page_action = EV_PAGE_ACTION (ev_window->priv->page_action);
947 ev_page_action_set_current_page (page_action, page);
951 view_page_changed_cb (EvView *view,
954 update_current_page (ev_window);
955 update_action_sensitivity (ev_window);
959 view_find_status_changed_cb (EvView *view,
964 text = ev_view_get_find_status_message (view);
966 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
973 find_bar_previous_cb (EggFindBar *find_bar,
976 /* FIXME - highlight previous result */
977 g_printerr ("Find Previous\n");
982 find_bar_next_cb (EggFindBar *find_bar,
985 /* FIXME - highlight next result */
986 g_printerr ("Find Next\n");
990 find_bar_close_cb (EggFindBar *find_bar,
993 gtk_widget_hide (ev_window->priv->find_bar);
995 if (ev_window->priv->exit_fullscreen_popup)
996 update_fullscreen_popup (ev_window);
1000 find_bar_search_changed_cb (EggFindBar *find_bar,
1002 EvWindow *ev_window)
1004 gboolean case_sensitive;
1006 const char *search_string;
1008 g_return_if_fail (EV_IS_WINDOW (ev_window));
1010 /* Either the string or case sensitivity could have changed,
1011 * we connect this callback to both. We also connect it
1012 * to ::visible so when the find bar is hidden, we should
1013 * pretend the search string is NULL/""
1016 case_sensitive = egg_find_bar_get_case_sensitive (find_bar);
1017 visible = GTK_WIDGET_VISIBLE (find_bar);
1018 search_string = egg_find_bar_get_search_string (find_bar);
1021 g_printerr ("search for '%s'\n", search_string ? search_string : "(nil)");
1024 if (ev_window->priv->document &&
1025 EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
1026 if (visible && search_string) {
1027 ev_document_find_begin (EV_DOCUMENT_FIND (ev_window->priv->document), search_string, case_sensitive);
1029 ev_document_find_cancel (EV_DOCUMENT_FIND (ev_window->priv->document));
1030 egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
1037 ev_window_dispose (GObject *object)
1039 EvWindowPrivate *priv;
1041 g_return_if_fail (object != NULL && EV_IS_WINDOW (object));
1043 priv = EV_WINDOW (object)->priv;
1045 if (priv->ui_manager) {
1046 g_object_unref (priv->ui_manager);
1047 priv->ui_manager = NULL;
1050 if (priv->action_group) {
1051 g_object_unref (priv->action_group);
1052 priv->action_group = NULL;
1055 G_OBJECT_CLASS (parent_class)->dispose (object);
1059 ev_window_class_init (EvWindowClass *ev_window_class)
1061 GObjectClass *g_object_class;
1063 parent_class = g_type_class_peek_parent (ev_window_class);
1065 g_object_class = G_OBJECT_CLASS (ev_window_class);
1066 g_object_class->dispose = ev_window_dispose;
1068 g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
1071 /* setting up signal system */
1072 ev_window_class->signal = ev_window_signal;
1074 ev_window_signals [SIGNAL] = g_signal_new (
1078 G_STRUCT_OFFSET (EvWindowClass,
1082 g_cclosure_marshal_VOID__STRING,
1085 /* setting up property system */
1086 g_object_class->set_property = ev_window_set_property;
1087 g_object_class->get_property = ev_window_get_property;
1089 g_object_class_install_property (
1092 g_param_spec_string ("attribute",
1094 "A simple unneccessary attribute that "
1095 "does nothing special except being a "
1096 "demonstration for the correct implem"
1097 "entation of a GObject property",
1099 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
1104 static GtkActionEntry entries[] = {
1105 { "File", NULL, N_("_File") },
1106 { "Edit", NULL, N_("_Edit") },
1107 { "View", NULL, N_("_View") },
1108 { "Go", NULL, N_("_Go") },
1109 { "Help", NULL, N_("_Help") },
1112 { "FileOpen", GTK_STOCK_OPEN, N_("_Open"), "<control>O",
1114 G_CALLBACK (ev_window_cmd_file_open) },
1115 { "FilePrint", GTK_STOCK_PRINT, N_("_Print"), "<control>P",
1116 N_("Print this document"),
1117 G_CALLBACK (ev_window_cmd_file_print) },
1118 { "FileCloseWindow", GTK_STOCK_CLOSE, N_("_Close"), "<control>W",
1119 N_("Close this window"),
1120 G_CALLBACK (ev_window_cmd_file_close_window) },
1123 { "EditCopy", GTK_STOCK_COPY, N_("_Copy"), "<control>C",
1124 N_("Copy text from the document"),
1125 G_CALLBACK (ev_window_cmd_edit_copy) },
1127 { "EditFind", GTK_STOCK_FIND, N_("_Find"), "<control>F",
1128 N_("Find a word or phrase in the document"),
1129 G_CALLBACK (ev_window_cmd_edit_find) },
1132 { "ViewZoomIn", GTK_STOCK_ZOOM_IN, N_("Zoom _In"), "<control>plus",
1133 N_("Enlarge the document"),
1134 G_CALLBACK (ev_window_cmd_view_zoom_in) },
1135 { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, N_("Zoom _Out"), "<control>minus",
1136 N_("Shrink the document"),
1137 G_CALLBACK (ev_window_cmd_view_zoom_out) },
1138 { "ViewNormalSize", GTK_STOCK_ZOOM_100, N_("_Normal Size"), "<control>0",
1139 N_("Zoom to the normal size"),
1140 G_CALLBACK (ev_window_cmd_view_normal_size) },
1141 { "ViewBestFit", GTK_STOCK_ZOOM_FIT, N_("_Best Fit"), NULL,
1142 N_("Zoom to fit the document to the current window"),
1143 G_CALLBACK (ev_window_cmd_view_best_fit) },
1144 { "ViewPageWidth", EV_STOCK_ZOOM_FIT_WIDTH, N_("Fit Page _Width"), NULL,
1145 N_("Zoom to fit the width of the current window "),
1146 G_CALLBACK (ev_window_cmd_view_page_width) },
1149 { "GoBack", GTK_STOCK_GO_BACK, N_("_Back"), "<mod1>Left",
1150 N_("Go to the page viewed before this one"),
1151 G_CALLBACK (ev_window_cmd_go_back) },
1152 { "GoForward", GTK_STOCK_GO_FORWARD, N_("Fo_rward"), "<mod1>Right",
1153 N_("Go to the page viewed before this one"),
1154 G_CALLBACK (ev_window_cmd_go_forward) },
1155 { "GoPreviousPage", GTK_STOCK_GO_BACK, N_("_Previous Page"), "<control>Page_Up",
1156 N_("Go to the previous page"),
1157 G_CALLBACK (ev_window_cmd_go_previous_page) },
1158 { "GoNextPage", GTK_STOCK_GO_FORWARD, N_("_Next Page"), "<control>Page_Down",
1159 N_("Go to the next page"),
1160 G_CALLBACK (ev_window_cmd_go_next_page) },
1161 { "GoFirstPage", GTK_STOCK_GOTO_FIRST, N_("_First Page"), "<control>Home",
1162 N_("Go to the first page"),
1163 G_CALLBACK (ev_window_cmd_go_first_page) },
1164 { "GoLastPage", GTK_STOCK_GOTO_LAST, N_("_Last Page"), "<control>End",
1165 N_("Go to the last page"),
1166 G_CALLBACK (ev_window_cmd_go_last_page) },
1169 { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), NULL,
1170 N_("Display help for the viewer application"),
1171 G_CALLBACK (ev_window_cmd_help_contents) },
1173 { "HelpAbout", GTK_STOCK_ABOUT, N_("_About"), NULL,
1174 N_("Display credits for the document viewer creators"),
1175 G_CALLBACK (ev_window_cmd_help_about) },
1179 static GtkToggleActionEntry toggle_entries[] = {
1181 { "ViewToolbar", NULL, N_("_Toolbar"), "<shift><control>T",
1182 N_("Show or hide toolbar"),
1183 G_CALLBACK (ev_window_view_toolbar_cb), TRUE },
1184 { "ViewStatusbar", NULL, N_("_Statusbar"), NULL,
1185 N_("Show or hide statusbar"),
1186 G_CALLBACK (ev_window_view_statusbar_cb), TRUE },
1187 { "ViewSidebar", NULL, N_("Side_bar"), "F9",
1188 N_("Show or hide sidebar"),
1189 G_CALLBACK (ev_window_view_sidebar_cb), TRUE },
1190 { "ViewFullscreen", NULL, N_("_Fullscreen"), "F11",
1191 N_("Expand the window to fill the screen"),
1192 G_CALLBACK (ev_window_cmd_view_fullscreen) },
1196 goto_page_cb (GtkAction *action, int page_number, EvWindow *ev_window)
1199 ev_view_set_page (EV_VIEW (ev_window->priv->view), page_number);
1203 register_custom_actions (EvWindow *window, GtkActionGroup *group)
1207 action = g_object_new (EV_TYPE_NAVIGATION_ACTION,
1208 "name", "NavigationBack",
1210 "stock_id", GTK_STOCK_GO_BACK,
1211 "tooltip", _("Go back"),
1212 "arrow-tooltip", _("Back history"),
1213 "direction", EV_NAVIGATION_DIRECTION_BACK,
1214 "is_important", TRUE,
1216 gtk_action_group_add_action (group, action);
1217 g_object_unref (action);
1219 action = g_object_new (EV_TYPE_NAVIGATION_ACTION,
1220 "name", "NavigationForward",
1221 "label", _("Forward"),
1222 "stock_id", GTK_STOCK_GO_FORWARD,
1223 "tooltip", _("Go forward"),
1224 "arrow-tooltip", _("Forward history"),
1225 "direction", EV_NAVIGATION_DIRECTION_FORWARD,
1227 gtk_action_group_add_action (group, action);
1228 g_object_unref (action);
1230 action = g_object_new (EV_TYPE_PAGE_ACTION,
1231 "name", "PageSelector",
1233 "tooltip", _("Select Page"),
1235 g_signal_connect (action, "goto_page",
1236 G_CALLBACK (goto_page_cb), window);
1237 window->priv->page_action = action;
1238 gtk_action_group_add_action (group, action);
1239 g_object_unref (action);
1243 ev_window_init (EvWindow *ev_window)
1245 GtkActionGroup *action_group;
1246 GtkAccelGroup *accel_group;
1247 GError *error = NULL;
1248 GtkWidget *scrolled_window;
1251 GtkWidget *sidebar_widget;
1253 ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
1255 update_window_title (NULL, NULL, ev_window);
1257 ev_window->priv->main_box = gtk_vbox_new (FALSE, 0);
1258 gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box);
1259 gtk_widget_show (ev_window->priv->main_box);
1261 action_group = gtk_action_group_new ("MenuActions");
1262 ev_window->priv->action_group = action_group;
1263 gtk_action_group_set_translation_domain (action_group, NULL);
1264 gtk_action_group_add_actions (action_group, entries,
1265 G_N_ELEMENTS (entries), ev_window);
1266 gtk_action_group_add_toggle_actions (action_group, toggle_entries,
1267 G_N_ELEMENTS (toggle_entries),
1270 register_custom_actions (ev_window, action_group);
1272 ev_window->priv->ui_manager = gtk_ui_manager_new ();
1273 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
1277 gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
1278 gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
1280 g_signal_connect (ev_window->priv->ui_manager, "connect_proxy",
1281 G_CALLBACK (connect_proxy_cb), ev_window);
1282 g_signal_connect (ev_window->priv->ui_manager, "disconnect_proxy",
1283 G_CALLBACK (disconnect_proxy_cb), ev_window);
1285 if (!gtk_ui_manager_add_ui_from_file (ev_window->priv->ui_manager,
1286 DATADIR"/evince-ui.xml",
1288 g_message ("building menus failed: %s", error->message);
1289 g_error_free (error);
1292 menubar = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
1294 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), menubar,
1297 toolbar = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
1299 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), toolbar,
1302 /* Add the main area */
1303 ev_window->priv->hpaned = gtk_hpaned_new ();
1304 gtk_widget_show (ev_window->priv->hpaned);
1305 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), ev_window->priv->hpaned,
1308 ev_window->priv->sidebar = ev_sidebar_new ();
1309 gtk_widget_show (ev_window->priv->sidebar);
1310 gtk_paned_add1 (GTK_PANED (ev_window->priv->hpaned),
1311 ev_window->priv->sidebar);
1313 /* Stub sidebar, for now */
1314 sidebar_widget = ev_sidebar_bookmarks_new ();
1315 gtk_widget_show (sidebar_widget);
1316 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
1321 sidebar_widget = ev_sidebar_thumbnails_new ();
1322 gtk_widget_show (sidebar_widget);
1323 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
1328 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1329 gtk_widget_show (scrolled_window);
1330 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1331 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1333 gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned),
1336 ev_window->priv->view = ev_view_new ();
1337 gtk_widget_show (ev_window->priv->view);
1338 gtk_container_add (GTK_CONTAINER (scrolled_window),
1339 ev_window->priv->view);
1340 g_signal_connect (ev_window->priv->view,
1342 G_CALLBACK (view_page_changed_cb),
1344 g_signal_connect (ev_window->priv->view,
1345 "find-status-changed",
1346 G_CALLBACK (view_find_status_changed_cb),
1349 ev_window->priv->statusbar = gtk_statusbar_new ();
1350 gtk_widget_show (ev_window->priv->statusbar);
1351 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
1352 ev_window->priv->statusbar,
1354 ev_window->priv->help_message_cid = gtk_statusbar_get_context_id
1355 (GTK_STATUSBAR (ev_window->priv->statusbar), "help_message");
1357 ev_window->priv->find_bar = egg_find_bar_new ();
1358 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
1359 ev_window->priv->find_bar,
1362 /* Connect to find bar signals */
1363 g_signal_connect (ev_window->priv->find_bar,
1365 G_CALLBACK (find_bar_previous_cb),
1367 g_signal_connect (ev_window->priv->find_bar,
1369 G_CALLBACK (find_bar_next_cb),
1371 g_signal_connect (ev_window->priv->find_bar,
1373 G_CALLBACK (find_bar_close_cb),
1375 g_signal_connect (ev_window->priv->find_bar,
1376 "notify::search-string",
1377 G_CALLBACK (find_bar_search_changed_cb),
1379 g_signal_connect (ev_window->priv->find_bar,
1380 "notify::case-sensitive",
1381 G_CALLBACK (find_bar_search_changed_cb),
1383 g_signal_connect (ev_window->priv->find_bar,
1385 G_CALLBACK (find_bar_search_changed_cb),
1388 g_signal_connect (ev_window, "window-state-event",
1389 G_CALLBACK (ev_window_state_event_cb),
1391 g_signal_connect (ev_window, "focus_out_event",
1392 G_CALLBACK (ev_window_focus_out_cb),
1395 /* Give focus to the scrolled window */
1396 gtk_widget_grab_focus (scrolled_window);
1398 update_action_sensitivity (ev_window);