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-sidebar.h"
33 #include "ev-sidebar-bookmarks.h"
34 #include "ev-sidebar-thumbnails.h"
36 #include "ev-print-job.h"
37 #include "eggfindbar.h"
39 #include "pdf-document.h"
40 #include "pixbuf-document.h"
43 #include <glib/gi18n.h>
45 #include <libgnomevfs/gnome-vfs-mime-utils.h>
46 #include <libgnomeprintui/gnome-print-dialog.h>
50 #include "ev-application.h"
51 #include "ev-stock-icons.h"
63 struct _EvWindowPrivate {
69 GtkActionGroup *action_group;
70 GtkUIManager *ui_manager;
72 guint help_message_cid;
73 GtkWidget *exit_fullscreen_popup;
77 gboolean fullscreen_mode;
81 /* enable these to add support for signals */
82 static guint ev_window_signals [N_SIGNALS] = { 0 };
85 static void update_fullscreen_popup (EvWindow *window);
87 static GObjectClass *parent_class = NULL;
89 G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
91 #define EV_WINDOW_GET_PRIVATE(object) \
92 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_WINDOW, EvWindowPrivate))
96 ev_window_get_attribute (EvWindow *self)
98 g_return_val_if_fail (self != NULL && EV_IS_WINDOW (self), NULL);
100 return self->priv->attribute;
104 ev_window_set_attribute (EvWindow* self, const char *attribute)
106 g_assert (self != NULL && EV_IS_WINDOW (self));
107 g_assert (attribute != NULL);
109 if (self->priv->attribute != NULL) {
110 g_free (self->priv->attribute);
113 self->priv->attribute = g_strdup (attribute);
115 g_object_notify (G_OBJECT (self), "attribute");
119 ev_window_get_property (GObject *object, guint prop_id, GValue *value,
120 GParamSpec *param_spec)
124 self = EV_WINDOW (object);
128 g_value_set_string (value, self->priv->attribute);
131 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
139 ev_window_set_property (GObject *object, guint prop_id, const GValue *value,
140 GParamSpec *param_spec)
144 self = EV_WINDOW (object);
148 ev_window_set_attribute (self, g_value_get_string (value));
151 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
160 set_action_sensitive (EvWindow *ev_window,
164 GtkAction *action = gtk_action_group_get_action (ev_window->priv->action_group,
166 gtk_action_set_sensitive (action, sensitive);
170 update_action_sensitivity (EvWindow *ev_window)
175 if (ev_window->priv->document)
176 n_pages = ev_document_get_n_pages (ev_window->priv->document);
180 page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
182 set_action_sensitive (ev_window, "GoFirstPage", page > 1);
183 set_action_sensitive (ev_window, "GoPreviousPage", page > 1);
184 set_action_sensitive (ev_window, "GoNextPage", page < n_pages);
185 set_action_sensitive (ev_window, "GoLastPage", page < n_pages);
189 ev_window_is_empty (const EvWindow *ev_window)
191 g_return_val_if_fail (EV_IS_WINDOW (ev_window), FALSE);
193 return ev_window->priv->document == NULL;
197 unable_to_load (EvWindow *ev_window,
198 const char *error_message)
202 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
203 GTK_DIALOG_DESTROY_WITH_PARENT,
206 _("Unable to open document"));
207 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
208 "%s", error_message);
209 gtk_dialog_run (GTK_DIALOG (dialog));
210 gtk_widget_destroy (dialog);
213 /* Would be nice to have this in gdk-pixbuf */
215 mime_type_supported_by_gdk_pixbuf (const gchar *mime_type)
217 GSList *formats, *list;
218 gboolean retval = FALSE;
220 formats = gdk_pixbuf_get_formats ();
224 GdkPixbufFormat *format = list->data;
228 if (gdk_pixbuf_format_is_disabled (format))
231 mime_types = gdk_pixbuf_format_get_mime_types (format);
233 for (i = 0; mime_types[i] != NULL; i++) {
234 if (strcmp (mime_types[i], mime_type) == 0) {
246 g_slist_free (formats);
252 ev_window_open (EvWindow *ev_window, const char *uri)
254 EvDocument *document = NULL;
257 mime_type = gnome_vfs_get_mime_type (uri);
259 if (!strcmp (mime_type, "application/pdf"))
260 document = g_object_new (PDF_TYPE_DOCUMENT, NULL);
261 else if (!strcmp (mime_type, "application/postscript"))
262 document = g_object_new (GTK_GS_TYPE, NULL);
263 else if (mime_type_supported_by_gdk_pixbuf (mime_type))
264 document = g_object_new (PIXBUF_TYPE_DOCUMENT, NULL);
267 GError *error = NULL;
269 if (ev_document_load (document, uri, &error)) {
270 if (ev_window->priv->document)
271 g_object_unref (ev_window->priv->document);
272 ev_window->priv->document = document;
274 ev_view_set_document (EV_VIEW (ev_window->priv->view),
276 ev_sidebar_set_document (EV_SIDEBAR (ev_window->priv->sidebar),
279 update_action_sensitivity (ev_window);
282 g_assert (error != NULL);
283 g_object_unref (document);
284 unable_to_load (ev_window, error->message);
285 g_error_free (error);
290 error_message = g_strdup_printf (_("Unhandled MIME type: '%s'"),
292 unable_to_load (ev_window, error_message);
293 g_free (error_message);
300 ev_window_cmd_file_open (GtkAction *action, EvWindow *ev_window)
302 ev_application_open (EV_APP, NULL);
306 using_postscript_printer (GnomePrintConfig *config)
308 const guchar *driver;
309 const guchar *transport;
311 driver = gnome_print_config_get (
312 config, (const guchar *)"Settings.Engine.Backend.Driver");
314 transport = gnome_print_config_get (
315 config, (const guchar *)"Settings.Transport.Backend");
318 if (!strcmp ((const gchar *)driver, "gnome-print-ps"))
322 } else if (transport) {
323 if (!strcmp ((const gchar *)transport, "CUPS"))
331 ev_window_print (EvWindow *ev_window)
333 GnomePrintConfig *config;
335 GtkWidget *print_dialog;
336 EvPrintJob *print_job = NULL;
338 g_return_if_fail (EV_IS_WINDOW (ev_window));
339 g_return_if_fail (ev_window->priv->document != NULL);
341 config = gnome_print_config_default ();
342 job = gnome_print_job_new (config);
344 print_dialog = gnome_print_dialog_new (job, _("Print"),
345 (GNOME_PRINT_DIALOG_RANGE |
346 GNOME_PRINT_DIALOG_COPIES));
347 gtk_dialog_set_response_sensitive (GTK_DIALOG (print_dialog),
348 GNOME_PRINT_DIALOG_RESPONSE_PREVIEW,
353 response = gtk_dialog_run (GTK_DIALOG (print_dialog));
355 if (response != GNOME_PRINT_DIALOG_RESPONSE_PRINT)
358 /* FIXME: Change this when we have the first backend
359 * that can print more than postscript
361 if (!using_postscript_printer (config)) {
364 dialog = gtk_message_dialog_new (
365 GTK_WINDOW (print_dialog), GTK_DIALOG_MODAL,
366 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
367 _("Printing is not supported on this printer."));
368 gtk_message_dialog_format_secondary_text (
369 GTK_MESSAGE_DIALOG (dialog),
370 _("You were trying to print to a printer using the \"%s\" driver. This program requires a PostScript printer driver."),
371 gnome_print_config_get (
372 config, "Settings.Engine.Backend.Driver"));
373 gtk_dialog_run (GTK_DIALOG (dialog));
374 gtk_widget_destroy (dialog);
379 print_job = g_object_new (EV_TYPE_PRINT_JOB,
380 "document", ev_window->priv->document,
381 "print-dialog", print_dialog,
386 gtk_widget_destroy (print_dialog);
388 if (print_job != NULL)
389 ev_print_job_print (print_job, GTK_WINDOW (ev_window));
393 ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
395 ev_window_print (ev_window);
399 ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
401 g_return_if_fail (EV_IS_WINDOW (ev_window));
403 gtk_widget_destroy (GTK_WIDGET (ev_window));
407 ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window)
409 g_return_if_fail (EV_IS_WINDOW (ev_window));
411 gtk_widget_show (ev_window->priv->find_bar);
413 if (ev_window->priv->exit_fullscreen_popup)
414 update_fullscreen_popup (ev_window);
416 egg_find_bar_grab_focus (EGG_FIND_BAR (ev_window->priv->find_bar));
420 ev_window_cmd_edit_copy (GtkAction *action, EvWindow *ev_window)
422 g_return_if_fail (EV_IS_WINDOW (ev_window));
428 update_fullscreen_popup (EvWindow *window)
430 GtkWidget *popup = window->priv->exit_fullscreen_popup;
431 int popup_width, popup_height;
432 GdkRectangle screen_rect;
434 g_return_if_fail (popup != NULL);
439 popup_width = popup->requisition.width;
440 popup_height = popup->requisition.height;
442 /* FIXME multihead */
443 gdk_screen_get_monitor_geometry (gdk_screen_get_default (),
444 gdk_screen_get_monitor_at_window
445 (gdk_screen_get_default (),
446 GTK_WIDGET (window)->window),
449 if (GTK_WIDGET_VISIBLE (window->priv->find_bar)) {
452 gtk_widget_size_request (window->priv->find_bar, &req);
454 screen_rect.height -= req.height;
457 if (gtk_widget_get_direction (popup) == GTK_TEXT_DIR_RTL)
459 gtk_window_move (GTK_WINDOW (popup),
460 screen_rect.x + screen_rect.width - popup_width,
461 screen_rect.height - popup_height);
465 gtk_window_move (GTK_WINDOW (popup),
466 screen_rect.x, screen_rect.height - popup_height);
471 screen_size_changed_cb (GdkScreen *screen,
474 update_fullscreen_popup (window);
478 destroy_exit_fullscreen_popup (EvWindow *window)
480 if (window->priv->exit_fullscreen_popup != NULL)
482 /* FIXME multihead */
483 g_signal_handlers_disconnect_by_func
484 (gdk_screen_get_default (),
485 G_CALLBACK (screen_size_changed_cb), window);
487 gtk_widget_destroy (window->priv->exit_fullscreen_popup);
488 window->priv->exit_fullscreen_popup = NULL;
493 exit_fullscreen_button_clicked_cb (GtkWidget *button, EvWindow *window)
497 action = gtk_action_group_get_action (window->priv->action_group, "ViewFullscreen");
498 g_return_if_fail (action != NULL);
500 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), FALSE);
504 fullscreen_popup_size_request_cb (GtkWidget *popup, GtkRequisition *req, EvWindow *window)
506 update_fullscreen_popup (window);
510 ev_window_fullscreen (EvWindow *window)
512 GtkWidget *popup, *button, *icon, *label, *hbox, *main_menu;
514 window->priv->fullscreen_mode = TRUE;
516 popup = gtk_window_new (GTK_WINDOW_POPUP);
517 window->priv->exit_fullscreen_popup = popup;
519 button = gtk_button_new ();
520 g_signal_connect (button, "clicked",
521 G_CALLBACK (exit_fullscreen_button_clicked_cb),
523 gtk_widget_show (button);
524 gtk_container_add (GTK_CONTAINER (popup), button);
526 hbox = gtk_hbox_new (FALSE, 2);
527 gtk_widget_show (hbox);
528 gtk_container_add (GTK_CONTAINER (button), hbox);
530 icon = gtk_image_new_from_stock (GTK_STOCK_QUIT, GTK_ICON_SIZE_BUTTON);
531 gtk_widget_show (icon);
532 gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
534 label = gtk_label_new (_("Exit Fullscreen"));
535 gtk_widget_show (label);
536 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
538 gtk_window_set_resizable (GTK_WINDOW (popup), FALSE);
540 /* FIXME multihead */
541 g_signal_connect (gdk_screen_get_default (), "size-changed",
542 G_CALLBACK (screen_size_changed_cb), window);
543 g_signal_connect (popup, "size_request",
544 G_CALLBACK (fullscreen_popup_size_request_cb), window);
546 main_menu = gtk_ui_manager_get_widget (window->priv->ui_manager, "/MainMenu");
547 gtk_widget_hide (main_menu);
548 gtk_widget_hide (window->priv->statusbar);
550 update_fullscreen_popup (window);
552 gtk_widget_show (popup);
556 ev_window_unfullscreen (EvWindow *window)
558 GtkWidget *main_menu;
560 window->priv->fullscreen_mode = FALSE;
562 main_menu = gtk_ui_manager_get_widget (window->priv->ui_manager, "/MainMenu");
563 gtk_widget_show (main_menu);
564 gtk_widget_show (window->priv->statusbar);
566 destroy_exit_fullscreen_popup (window);
570 ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *ev_window)
574 g_return_if_fail (EV_IS_WINDOW (ev_window));
576 fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
579 gtk_window_fullscreen (GTK_WINDOW (ev_window));
581 gtk_window_unfullscreen (GTK_WINDOW (ev_window));
586 ev_window_state_event_cb (GtkWidget *widget, GdkEventWindowState *event, EvWindow *window)
588 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
590 GtkActionGroup *action_group;
594 fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
598 ev_window_fullscreen (window);
602 ev_window_unfullscreen (window);
605 action_group = window->priv->action_group;
607 action = gtk_action_group_get_action (action_group, "ViewFullscreen");
608 g_signal_handlers_block_by_func
609 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
610 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), fullscreen);
611 g_signal_handlers_unblock_by_func
612 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
620 ev_window_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *ev_window)
622 gtk_window_unfullscreen (GTK_WINDOW (ev_window));
629 ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window)
631 g_return_if_fail (EV_IS_WINDOW (ev_window));
633 ev_view_zoom_in (EV_VIEW (ev_window->priv->view));
637 ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window)
639 g_return_if_fail (EV_IS_WINDOW (ev_window));
641 ev_view_zoom_out (EV_VIEW (ev_window->priv->view));
645 ev_window_cmd_view_normal_size (GtkAction *action, EvWindow *ev_window)
647 g_return_if_fail (EV_IS_WINDOW (ev_window));
649 ev_view_normal_size (EV_VIEW (ev_window->priv->view));
653 ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
655 g_return_if_fail (EV_IS_WINDOW (ev_window));
657 ev_view_best_fit (EV_VIEW (ev_window->priv->view));
661 ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
663 g_return_if_fail (EV_IS_WINDOW (ev_window));
665 ev_view_fit_width (EV_VIEW (ev_window->priv->view));
669 ev_window_cmd_go_back (GtkAction *action, EvWindow *ev_window)
671 g_return_if_fail (EV_IS_WINDOW (ev_window));
677 ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window)
679 g_return_if_fail (EV_IS_WINDOW (ev_window));
685 ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
687 g_return_if_fail (EV_IS_WINDOW (ev_window));
689 ev_view_set_page (EV_VIEW (ev_window->priv->view),
690 ev_view_get_page (EV_VIEW (ev_window->priv->view)) - 1);
694 ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
696 g_return_if_fail (EV_IS_WINDOW (ev_window));
698 ev_view_set_page (EV_VIEW (ev_window->priv->view),
699 ev_view_get_page (EV_VIEW (ev_window->priv->view)) + 1);
703 ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
705 g_return_if_fail (EV_IS_WINDOW (ev_window));
707 ev_view_set_page (EV_VIEW (ev_window->priv->view), 1);
711 ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
713 g_return_if_fail (EV_IS_WINDOW (ev_window));
715 ev_view_set_page (EV_VIEW (ev_window->priv->view), G_MAXINT);
719 ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
721 g_return_if_fail (EV_IS_WINDOW (ev_window));
727 ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
729 const char *authors[] = {
734 const char *documenters[] = {
735 N_("Not so many..."),
739 const char *license[] = {
740 N_("Evince is free software; you can redistribute it and/or modify\n"
741 "it under the terms of the GNU General Public License as published by\n"
742 "the Free Software Foundation; either version 2 of the License, or\n"
743 "(at your option) any later version.\n"),
744 N_("Evince is distributed in the hope that it will be useful,\n"
745 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
746 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
747 "GNU General Public License for more details.\n"),
748 N_("You should have received a copy of the GNU General Public License\n"
749 "along with Evince; if not, write to the Free Software Foundation, Inc.,\n"
750 "59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n")
758 for (p = authors; *p; ++p)
761 for (p = documenters; *p; ++p)
765 license_trans = g_strconcat (_(license[0]), "\n", _(license[1]), "\n",
766 _(license[2]), "\n", NULL);
768 gtk_show_about_dialog (
769 GTK_WINDOW (ev_window),
773 _("\xc2\xa9 1996-2004 The Evince authors"),
774 "license", license_trans,
775 "website", "http://www.gnome.org/projects/evince",
776 "comments", _("PostScript and PDF File Viewer."),
778 "documenters", documenters,
779 "translator-credits", _("translator-credits"),
782 g_free (license_trans);
786 ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window)
789 G_OBJECT (gtk_ui_manager_get_widget (
790 ev_window->priv->ui_manager,
793 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
798 ev_window_view_statusbar_cb (GtkAction *action, EvWindow *ev_window)
801 ev_window->priv->statusbar,
803 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
808 ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window)
814 menu_item_select_cb (GtkMenuItem *proxy, EvWindow *ev_window)
819 action = g_object_get_data (G_OBJECT (proxy), "gtk-action");
820 g_return_if_fail (action != NULL);
822 g_object_get (G_OBJECT (action), "tooltip", &message, NULL);
824 gtk_statusbar_push (GTK_STATUSBAR (ev_window->priv->statusbar),
825 ev_window->priv->help_message_cid, message);
831 menu_item_deselect_cb (GtkMenuItem *proxy, EvWindow *ev_window)
833 gtk_statusbar_pop (GTK_STATUSBAR (ev_window->priv->statusbar),
834 ev_window->priv->help_message_cid);
838 connect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
839 GtkWidget *proxy, EvWindow *ev_window)
841 if (GTK_IS_MENU_ITEM (proxy)) {
842 g_signal_connect (proxy, "select",
843 G_CALLBACK (menu_item_select_cb), ev_window);
844 g_signal_connect (proxy, "deselect",
845 G_CALLBACK (menu_item_deselect_cb),
851 disconnect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
852 GtkWidget *proxy, EvWindow *ev_window)
854 if (GTK_IS_MENU_ITEM (proxy)) {
855 g_signal_handlers_disconnect_by_func
856 (proxy, G_CALLBACK (menu_item_select_cb), ev_window);
857 g_signal_handlers_disconnect_by_func
858 (proxy, G_CALLBACK (menu_item_deselect_cb), ev_window);
863 view_page_changed_cb (EvView *view,
866 update_action_sensitivity (ev_window);
870 find_bar_previous_cb (EggFindBar *find_bar,
873 /* FIXME - highlight previous result */
874 g_printerr ("Find Previous\n");
879 find_bar_next_cb (EggFindBar *find_bar,
882 /* FIXME - highlight next result */
883 g_printerr ("Find Next\n");
887 find_bar_close_cb (EggFindBar *find_bar,
890 gtk_widget_hide (ev_window->priv->find_bar);
892 if (ev_window->priv->exit_fullscreen_popup)
893 update_fullscreen_popup (ev_window);
897 find_bar_search_changed_cb (EggFindBar *find_bar,
901 gboolean case_sensitive;
903 const char *search_string;
905 g_return_if_fail (EV_IS_WINDOW (ev_window));
907 /* Either the string or case sensitivity could have changed,
908 * we connect this callback to both. We also connect it
909 * to ::visible so when the find bar is hidden, we should
910 * pretend the search string is NULL/""
913 case_sensitive = egg_find_bar_get_case_sensitive (find_bar);
914 visible = GTK_WIDGET_VISIBLE (find_bar);
915 search_string = egg_find_bar_get_search_string (find_bar);
918 g_printerr ("search for '%s'\n", search_string ? search_string : "(nil)");
921 /* We don't require begin/end find calls to be matched up, it's really
922 * start_find and cancel_any_find_that_may_not_be_finished
924 if (visible && search_string) {
925 ev_document_begin_find (ev_window->priv->document, search_string, case_sensitive);
927 ev_document_end_find (ev_window->priv->document);
932 ev_window_dispose (GObject *object)
934 EvWindowPrivate *priv;
936 g_return_if_fail (object != NULL && EV_IS_WINDOW (object));
938 priv = EV_WINDOW (object)->priv;
940 if (priv->ui_manager) {
941 g_object_unref (priv->ui_manager);
942 priv->ui_manager = NULL;
945 if (priv->action_group) {
946 g_object_unref (priv->action_group);
947 priv->action_group = NULL;
950 G_OBJECT_CLASS (parent_class)->dispose (object);
954 ev_window_class_init (EvWindowClass *ev_window_class)
956 GObjectClass *g_object_class;
958 parent_class = g_type_class_peek_parent (ev_window_class);
960 g_object_class = G_OBJECT_CLASS (ev_window_class);
961 g_object_class->dispose = ev_window_dispose;
963 g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
966 /* setting up signal system */
967 ev_window_class->signal = ev_window_signal;
969 ev_window_signals [SIGNAL] = g_signal_new (
973 G_STRUCT_OFFSET (EvWindowClass,
977 g_cclosure_marshal_VOID__STRING,
980 /* setting up property system */
981 g_object_class->set_property = ev_window_set_property;
982 g_object_class->get_property = ev_window_get_property;
984 g_object_class_install_property (
987 g_param_spec_string ("attribute",
989 "A simple unneccessary attribute that "
990 "does nothing special except being a "
991 "demonstration for the correct implem"
992 "entation of a GObject property",
994 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
999 static GtkActionEntry entries[] = {
1000 { "File", NULL, N_("_File") },
1001 { "Edit", NULL, N_("_Edit") },
1002 { "View", NULL, N_("_View") },
1003 { "Go", NULL, N_("_Go") },
1004 { "Help", NULL, N_("_Help") },
1007 { "FileOpen", GTK_STOCK_OPEN, N_("_Open"), "<control>O",
1009 G_CALLBACK (ev_window_cmd_file_open) },
1010 { "FilePrint", GTK_STOCK_PRINT, N_("_Print"), "<control>P",
1011 N_("Print this document"),
1012 G_CALLBACK (ev_window_cmd_file_print) },
1013 { "FileCloseWindow", GTK_STOCK_CLOSE, N_("_Close"), "<control>W",
1014 N_("Close this window"),
1015 G_CALLBACK (ev_window_cmd_file_close_window) },
1018 { "EditCopy", GTK_STOCK_COPY, N_("_Copy"), "<control>C",
1019 N_("Copy text from the document"),
1020 G_CALLBACK (ev_window_cmd_edit_copy) },
1022 { "EditFind", GTK_STOCK_FIND, N_("_Find"), "<control>F",
1023 N_("Find a word or phrase in the document"),
1024 G_CALLBACK (ev_window_cmd_edit_find) },
1027 { "ViewZoomIn", GTK_STOCK_ZOOM_IN, N_("Zoom _In"), "<control>plus",
1028 N_("Enlarge the document"),
1029 G_CALLBACK (ev_window_cmd_view_zoom_in) },
1030 { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, N_("Zoom _Out"), "<control>minus",
1031 N_("Shrink the document"),
1032 G_CALLBACK (ev_window_cmd_view_zoom_out) },
1033 { "ViewNormalSize", GTK_STOCK_ZOOM_100, N_("_Normal Size"), "<control>0",
1034 N_("Zoom to the normal size"),
1035 G_CALLBACK (ev_window_cmd_view_normal_size) },
1036 { "ViewBestFit", GTK_STOCK_ZOOM_FIT, N_("_Best Fit"), NULL,
1037 N_("Zoom to fit the document to the current window"),
1038 G_CALLBACK (ev_window_cmd_view_best_fit) },
1039 { "ViewPageWidth", EV_STOCK_ZOOM_FIT_WIDTH, N_("Fit Page _Width"), NULL,
1040 N_("Zoom to fit the width of the current window "),
1041 G_CALLBACK (ev_window_cmd_view_page_width) },
1044 { "GoBack", GTK_STOCK_GO_BACK, N_("_Back"), "<mod1>Left",
1045 N_("Go to the page viewed before this one"),
1046 G_CALLBACK (ev_window_cmd_go_back) },
1047 { "GoForward", GTK_STOCK_GO_FORWARD, N_("Fo_rward"), "<mod1>Right",
1048 N_("Go to the page viewed before this one"),
1049 G_CALLBACK (ev_window_cmd_go_forward) },
1050 { "GoPreviousPage", GTK_STOCK_GO_BACK, N_("_Previous Page"), "<control>Page_Up",
1051 N_("Go to the previous page"),
1052 G_CALLBACK (ev_window_cmd_go_previous_page) },
1053 { "GoNextPage", GTK_STOCK_GO_FORWARD, N_("_Next Page"), "<control>Page_Down",
1054 N_("Go to the next page"),
1055 G_CALLBACK (ev_window_cmd_go_next_page) },
1056 { "GoFirstPage", GTK_STOCK_GOTO_FIRST, N_("_First Page"), "<control>Home",
1057 N_("Go to the first page"),
1058 G_CALLBACK (ev_window_cmd_go_first_page) },
1059 { "GoLastPage", GTK_STOCK_GOTO_LAST, N_("_Last Page"), "<control>End",
1060 N_("Go to the last page"),
1061 G_CALLBACK (ev_window_cmd_go_last_page) },
1064 { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), NULL,
1065 N_("Display help for the viewer application"),
1066 G_CALLBACK (ev_window_cmd_help_contents) },
1068 { "HelpAbout", GTK_STOCK_ABOUT, N_("_About"), NULL,
1069 N_("Display credits for the document viewer creators"),
1070 G_CALLBACK (ev_window_cmd_help_about) },
1074 static GtkToggleActionEntry toggle_entries[] = {
1076 { "ViewToolbar", NULL, N_("_Toolbar"), "<shift><control>T",
1077 N_("Show or hide toolbar"),
1078 G_CALLBACK (ev_window_view_toolbar_cb), TRUE },
1079 { "ViewStatusbar", NULL, N_("_Statusbar"), NULL,
1080 N_("Show or hide statusbar"),
1081 G_CALLBACK (ev_window_view_statusbar_cb), TRUE },
1082 { "ViewSidebar", NULL, N_("Side_bar"), "F9",
1083 N_("Show or hide sidebar"),
1084 G_CALLBACK (ev_window_view_sidebar_cb), FALSE },
1085 { "ViewFullscreen", NULL, N_("_Fullscreen"), "F11",
1086 N_("Expand the window to fill the screen"),
1087 G_CALLBACK (ev_window_cmd_view_fullscreen) },
1091 ev_window_init (EvWindow *ev_window)
1093 GtkActionGroup *action_group;
1094 GtkAccelGroup *accel_group;
1095 GError *error = NULL;
1096 GtkWidget *scrolled_window;
1099 GtkWidget *sidebar_widget;
1101 ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
1103 gtk_window_set_title (GTK_WINDOW (ev_window), _("Document Viewer"));
1105 ev_window->priv->main_box = gtk_vbox_new (FALSE, 0);
1106 gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box);
1107 gtk_widget_show (ev_window->priv->main_box);
1109 action_group = gtk_action_group_new ("MenuActions");
1110 ev_window->priv->action_group = action_group;
1111 gtk_action_group_set_translation_domain (action_group, NULL);
1112 gtk_action_group_add_actions (action_group, entries,
1113 G_N_ELEMENTS (entries), ev_window);
1114 gtk_action_group_add_toggle_actions (action_group, toggle_entries,
1115 G_N_ELEMENTS (toggle_entries),
1118 ev_window->priv->ui_manager = gtk_ui_manager_new ();
1119 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
1123 gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
1124 gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
1126 g_signal_connect (ev_window->priv->ui_manager, "connect_proxy",
1127 G_CALLBACK (connect_proxy_cb), ev_window);
1128 g_signal_connect (ev_window->priv->ui_manager, "disconnect_proxy",
1129 G_CALLBACK (disconnect_proxy_cb), ev_window);
1131 if (!gtk_ui_manager_add_ui_from_file (ev_window->priv->ui_manager,
1132 DATADIR"/evince-ui.xml",
1134 g_message ("building menus failed: %s", error->message);
1135 g_error_free (error);
1138 menubar = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
1140 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), menubar,
1143 toolbar = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
1145 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), toolbar,
1148 /* Add the main area */
1149 ev_window->priv->hpaned = gtk_hpaned_new ();
1150 gtk_widget_show (ev_window->priv->hpaned);
1151 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), ev_window->priv->hpaned,
1154 ev_window->priv->sidebar = ev_sidebar_new ();
1155 gtk_widget_show (ev_window->priv->sidebar);
1156 gtk_paned_add1 (GTK_PANED (ev_window->priv->hpaned),
1157 ev_window->priv->sidebar);
1159 /* Stub sidebar, for now */
1160 sidebar_widget = ev_sidebar_bookmarks_new ();
1161 gtk_widget_show (sidebar_widget);
1162 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
1167 sidebar_widget = ev_sidebar_thumbnails_new ();
1168 gtk_widget_show (sidebar_widget);
1169 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
1174 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1175 gtk_widget_show (scrolled_window);
1176 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1177 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1179 gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned),
1182 ev_window->priv->view = ev_view_new ();
1183 gtk_widget_show (ev_window->priv->view);
1184 gtk_container_add (GTK_CONTAINER (scrolled_window),
1185 ev_window->priv->view);
1186 g_signal_connect (ev_window->priv->view,
1188 G_CALLBACK (view_page_changed_cb),
1191 ev_window->priv->statusbar = gtk_statusbar_new ();
1192 gtk_widget_show (ev_window->priv->statusbar);
1193 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
1194 ev_window->priv->statusbar,
1196 ev_window->priv->help_message_cid = gtk_statusbar_get_context_id
1197 (GTK_STATUSBAR (ev_window->priv->statusbar), "help_message");
1199 ev_window->priv->find_bar = egg_find_bar_new ();
1200 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
1201 ev_window->priv->find_bar,
1204 /* Connect to find bar signals */
1205 g_signal_connect (ev_window->priv->find_bar,
1207 G_CALLBACK (find_bar_previous_cb),
1209 g_signal_connect (ev_window->priv->find_bar,
1211 G_CALLBACK (find_bar_next_cb),
1213 g_signal_connect (ev_window->priv->find_bar,
1215 G_CALLBACK (find_bar_close_cb),
1217 g_signal_connect (ev_window->priv->find_bar,
1218 "notify::search-string",
1219 G_CALLBACK (find_bar_search_changed_cb),
1221 g_signal_connect (ev_window->priv->find_bar,
1222 "notify::case-sensitive",
1223 G_CALLBACK (find_bar_search_changed_cb),
1225 g_signal_connect (ev_window->priv->find_bar,
1227 G_CALLBACK (find_bar_search_changed_cb),
1230 g_signal_connect (ev_window, "window-state-event",
1231 G_CALLBACK (ev_window_state_event_cb),
1233 g_signal_connect (ev_window, "focus_out_event",
1234 G_CALLBACK (ev_window_focus_out_cb),
1237 /* Give focus to the scrolled window */
1238 gtk_widget_grab_focus (scrolled_window);
1240 update_action_sensitivity (ev_window);