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 "eggfindbar.h"
38 #include "pdf-document.h"
41 #include <glib/gi18n.h>
43 #include <libgnomevfs/gnome-vfs-mime-utils.h>
47 #include "ev-application.h"
48 #include "ev-stock-icons.h"
60 struct _EvWindowPrivate {
66 GtkActionGroup *action_group;
67 GtkUIManager *ui_manager;
69 guint help_message_cid;
70 GtkWidget *exit_fullscreen_popup;
74 gboolean fullscreen_mode;
78 /* enable these to add support for signals */
79 static guint ev_window_signals [N_SIGNALS] = { 0 };
82 static GObjectClass *parent_class = NULL;
84 G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
86 #define EV_WINDOW_GET_PRIVATE(object) \
87 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_WINDOW, EvWindowPrivate))
91 ev_window_get_attribute (EvWindow *self)
93 g_return_val_if_fail (self != NULL && EV_IS_WINDOW (self), NULL);
95 return self->priv->attribute;
99 ev_window_set_attribute (EvWindow* self, const char *attribute)
101 g_assert (self != NULL && EV_IS_WINDOW (self));
102 g_assert (attribute != NULL);
104 if (self->priv->attribute != NULL) {
105 g_free (self->priv->attribute);
108 self->priv->attribute = g_strdup (attribute);
110 g_object_notify (G_OBJECT (self), "attribute");
114 ev_window_get_property (GObject *object, guint prop_id, GValue *value,
115 GParamSpec *param_spec)
119 self = EV_WINDOW (object);
123 g_value_set_string (value, self->priv->attribute);
126 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
134 ev_window_set_property (GObject *object, guint prop_id, const GValue *value,
135 GParamSpec *param_spec)
139 self = EV_WINDOW (object);
143 ev_window_set_attribute (self, g_value_get_string (value));
146 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
155 set_action_sensitive (EvWindow *ev_window,
159 GtkAction *action = gtk_action_group_get_action (ev_window->priv->action_group,
161 gtk_action_set_sensitive (action, sensitive);
165 update_action_sensitivity (EvWindow *ev_window)
170 if (ev_window->priv->document)
171 n_pages = ev_document_get_n_pages (ev_window->priv->document);
175 page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
177 set_action_sensitive (ev_window, "GoFirstPage", page > 1);
178 set_action_sensitive (ev_window, "GoPreviousPage", page > 1);
179 set_action_sensitive (ev_window, "GoNextPage", page < n_pages);
180 set_action_sensitive (ev_window, "GoLastPage", page < n_pages);
184 ev_window_is_empty (const EvWindow *ev_window)
186 g_return_val_if_fail (EV_IS_WINDOW (ev_window), FALSE);
188 return ev_window->priv->document == NULL;
192 unable_to_load (EvWindow *ev_window,
193 const char *error_message)
197 dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
198 GTK_DIALOG_DESTROY_WITH_PARENT,
201 _("Unable to open document"));
202 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
203 "%s", error_message);
204 gtk_dialog_run (GTK_DIALOG (dialog));
205 gtk_widget_destroy (dialog);
209 ev_window_open (EvWindow *ev_window, const char *uri)
211 EvDocument *document = NULL;
214 mime_type = gnome_vfs_get_mime_type (uri);
216 if (!strcmp (mime_type, "application/pdf"))
217 document = g_object_new (PDF_TYPE_DOCUMENT, NULL);
218 else if (!strcmp (mime_type, "application/postscript"))
219 document = g_object_new (GTK_GS_TYPE, NULL);
222 GError *error = NULL;
224 if (ev_document_load (document, uri, &error)) {
225 if (ev_window->priv->document)
226 g_object_unref (ev_window->priv->document);
227 ev_window->priv->document = document;
229 ev_view_set_document (EV_VIEW (ev_window->priv->view),
232 update_action_sensitivity (ev_window);
235 g_assert (error != NULL);
236 g_object_unref (document);
237 unable_to_load (ev_window, error->message);
238 g_error_free (error);
243 error_message = g_strdup_printf (_("Unhandled MIME type: '%s'"),
245 unable_to_load (ev_window, error_message);
246 g_free (error_message);
253 ev_window_cmd_file_open (GtkAction *action, EvWindow *ev_window)
255 ev_application_open (EV_APP, NULL);
259 ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
261 g_return_if_fail (EV_IS_WINDOW (ev_window));
266 ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
268 g_return_if_fail (EV_IS_WINDOW (ev_window));
270 gtk_widget_destroy (GTK_WIDGET (ev_window));
274 ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window)
276 g_return_if_fail (EV_IS_WINDOW (ev_window));
278 gtk_widget_show (ev_window->priv->find_bar);
279 egg_find_bar_grab_focus (EGG_FIND_BAR (ev_window->priv->find_bar));
283 ev_window_cmd_edit_copy (GtkAction *action, EvWindow *ev_window)
285 g_return_if_fail (EV_IS_WINDOW (ev_window));
291 update_fullscreen_popup (EvWindow *window)
293 GtkWidget *popup = window->priv->exit_fullscreen_popup;
294 int popup_width, popup_height;
295 GdkRectangle screen_rect;
297 g_return_if_fail (popup != NULL);
299 popup_width = popup->requisition.width;
300 popup_height = popup->requisition.height;
302 /* FIXME multihead */
303 gdk_screen_get_monitor_geometry (gdk_screen_get_default (),
304 gdk_screen_get_monitor_at_window
305 (gdk_screen_get_default (),
306 GTK_WIDGET (window)->window),
309 if (gtk_widget_get_direction (popup) == GTK_TEXT_DIR_RTL)
311 gtk_window_move (GTK_WINDOW (popup),
312 screen_rect.x + screen_rect.width - popup_width,
313 screen_rect.height - popup_height);
317 gtk_window_move (GTK_WINDOW (popup),
318 screen_rect.x, screen_rect.height - popup_height);
323 screen_size_changed_cb (GdkScreen *screen,
326 update_fullscreen_popup (window);
330 destroy_exit_fullscreen_popup (EvWindow *window)
332 if (window->priv->exit_fullscreen_popup != NULL)
334 /* FIXME multihead */
335 g_signal_handlers_disconnect_by_func
336 (gdk_screen_get_default (),
337 G_CALLBACK (screen_size_changed_cb), window);
339 gtk_widget_destroy (window->priv->exit_fullscreen_popup);
340 window->priv->exit_fullscreen_popup = NULL;
345 exit_fullscreen_button_clicked_cb (GtkWidget *button, EvWindow *window)
349 action = gtk_action_group_get_action (window->priv->action_group, "ViewFullscreen");
350 g_return_if_fail (action != NULL);
352 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), FALSE);
356 fullscreen_popup_size_request_cb (GtkWidget *popup, GtkRequisition *req, EvWindow *window)
358 update_fullscreen_popup (window);
362 ev_window_fullscreen (EvWindow *window)
364 GtkWidget *popup, *button, *icon, *label, *hbox;
366 window->priv->fullscreen_mode = TRUE;
368 popup = gtk_window_new (GTK_WINDOW_POPUP);
369 window->priv->exit_fullscreen_popup = popup;
371 button = gtk_button_new ();
372 g_signal_connect (button, "clicked",
373 G_CALLBACK (exit_fullscreen_button_clicked_cb),
375 gtk_widget_show (button);
376 gtk_container_add (GTK_CONTAINER (popup), button);
378 hbox = gtk_hbox_new (FALSE, 2);
379 gtk_widget_show (hbox);
380 gtk_container_add (GTK_CONTAINER (button), hbox);
382 icon = gtk_image_new_from_stock (GTK_STOCK_QUIT, GTK_ICON_SIZE_BUTTON);
383 gtk_widget_show (icon);
384 gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
386 label = gtk_label_new (_("Exit Fullscreen"));
387 gtk_widget_show (label);
388 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
390 gtk_window_set_resizable (GTK_WINDOW (popup), FALSE);
392 /* FIXME multihead */
393 g_signal_connect (gdk_screen_get_default (), "size-changed",
394 G_CALLBACK (screen_size_changed_cb), window);
395 g_signal_connect (popup, "size_request",
396 G_CALLBACK (fullscreen_popup_size_request_cb), window);
398 update_fullscreen_popup (window);
400 gtk_widget_show (popup);
404 ev_window_unfullscreen (EvWindow *window)
406 window->priv->fullscreen_mode = FALSE;
408 destroy_exit_fullscreen_popup (window);
412 ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *ev_window)
416 g_return_if_fail (EV_IS_WINDOW (ev_window));
418 fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
421 gtk_window_fullscreen (GTK_WINDOW (ev_window));
423 gtk_window_unfullscreen (GTK_WINDOW (ev_window));
428 ev_window_state_event_cb (GtkWidget *widget, GdkEventWindowState *event, EvWindow *window)
430 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
432 GtkActionGroup *action_group;
434 GtkWidget *main_menu;
437 fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
441 ev_window_fullscreen (window);
445 ev_window_unfullscreen (window);
448 action_group = window->priv->action_group;
450 action = gtk_action_group_get_action (action_group, "ViewFullscreen");
451 g_signal_handlers_block_by_func
452 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
453 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), fullscreen);
454 g_signal_handlers_unblock_by_func
455 (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
457 main_menu = gtk_ui_manager_get_widget (window->priv->ui_manager, "/MainMenu");
458 g_object_set (main_menu, "visible", !fullscreen, NULL);
465 ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window)
467 g_return_if_fail (EV_IS_WINDOW (ev_window));
469 ev_view_zoom_in (EV_VIEW (ev_window->priv->view));
473 ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window)
475 g_return_if_fail (EV_IS_WINDOW (ev_window));
477 ev_view_zoom_out (EV_VIEW (ev_window->priv->view));
481 ev_window_cmd_view_normal_size (GtkAction *action, EvWindow *ev_window)
483 g_return_if_fail (EV_IS_WINDOW (ev_window));
485 ev_view_normal_size (EV_VIEW (ev_window->priv->view));
489 ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
491 g_return_if_fail (EV_IS_WINDOW (ev_window));
493 ev_view_best_fit (EV_VIEW (ev_window->priv->view));
497 ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
499 g_return_if_fail (EV_IS_WINDOW (ev_window));
501 ev_view_fit_width (EV_VIEW (ev_window->priv->view));
505 ev_window_cmd_go_back (GtkAction *action, EvWindow *ev_window)
507 g_return_if_fail (EV_IS_WINDOW (ev_window));
513 ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window)
515 g_return_if_fail (EV_IS_WINDOW (ev_window));
521 ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
523 g_return_if_fail (EV_IS_WINDOW (ev_window));
525 ev_view_set_page (EV_VIEW (ev_window->priv->view),
526 ev_view_get_page (EV_VIEW (ev_window->priv->view)) - 1);
530 ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
532 g_return_if_fail (EV_IS_WINDOW (ev_window));
534 ev_view_set_page (EV_VIEW (ev_window->priv->view),
535 ev_view_get_page (EV_VIEW (ev_window->priv->view)) + 1);
539 ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
541 g_return_if_fail (EV_IS_WINDOW (ev_window));
543 ev_view_set_page (EV_VIEW (ev_window->priv->view), 1);
547 ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
549 g_return_if_fail (EV_IS_WINDOW (ev_window));
551 ev_view_set_page (EV_VIEW (ev_window->priv->view), G_MAXINT);
555 ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
557 g_return_if_fail (EV_IS_WINDOW (ev_window));
563 ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
565 const char *authors[] = {
570 const char *documenters[] = {
571 N_("Not so many..."),
575 const char *license[] = {
576 N_("Evince is free software; you can redistribute it and/or modify\n"
577 "it under the terms of the GNU General Public License as published by\n"
578 "the Free Software Foundation; either version 2 of the License, or\n"
579 "(at your option) any later version.\n"),
580 N_("Evince is distributed in the hope that it will be useful,\n"
581 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
582 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
583 "GNU General Public License for more details.\n"),
584 N_("You should have received a copy of the GNU General Public License\n"
585 "along with Evince; if not, write to the Free Software Foundation, Inc.,\n"
586 "59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n")
594 for (p = authors; *p; ++p)
597 for (p = documenters; *p; ++p)
601 license_trans = g_strconcat (_(license[0]), "\n", _(license[1]), "\n",
602 _(license[2]), "\n", NULL);
604 gtk_show_about_dialog (
605 GTK_WINDOW (ev_window),
609 _("\xc2\xa9 1996-2004 The Evince authors"),
610 "license", license_trans,
611 "website", "http://www.gnome.org/projects/evince",
612 "comments", _("PostScript and PDF File Viewer."),
614 "documenters", documenters,
615 "translator-credits", _("translator-credits"),
618 g_free (license_trans);
622 ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window)
625 G_OBJECT (gtk_ui_manager_get_widget (
626 ev_window->priv->ui_manager,
629 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
634 ev_window_view_statusbar_cb (GtkAction *action, EvWindow *ev_window)
637 ev_window->priv->statusbar,
639 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
644 ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window)
650 menu_item_select_cb (GtkMenuItem *proxy, EvWindow *ev_window)
655 action = g_object_get_data (G_OBJECT (proxy), "gtk-action");
656 g_return_if_fail (action != NULL);
658 g_object_get (G_OBJECT (action), "tooltip", &message, NULL);
660 gtk_statusbar_push (GTK_STATUSBAR (ev_window->priv->statusbar),
661 ev_window->priv->help_message_cid, message);
667 menu_item_deselect_cb (GtkMenuItem *proxy, EvWindow *ev_window)
669 gtk_statusbar_pop (GTK_STATUSBAR (ev_window->priv->statusbar),
670 ev_window->priv->help_message_cid);
674 connect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
675 GtkWidget *proxy, EvWindow *ev_window)
677 if (GTK_IS_MENU_ITEM (proxy)) {
678 g_signal_connect (proxy, "select",
679 G_CALLBACK (menu_item_select_cb), ev_window);
680 g_signal_connect (proxy, "deselect",
681 G_CALLBACK (menu_item_deselect_cb),
687 disconnect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
688 GtkWidget *proxy, EvWindow *ev_window)
690 if (GTK_IS_MENU_ITEM (proxy)) {
691 g_signal_handlers_disconnect_by_func
692 (proxy, G_CALLBACK (menu_item_select_cb), ev_window);
693 g_signal_handlers_disconnect_by_func
694 (proxy, G_CALLBACK (menu_item_deselect_cb), ev_window);
699 view_page_changed_cb (EvView *view,
702 update_action_sensitivity (ev_window);
706 find_bar_previous_cb (EggFindBar *find_bar,
709 /* FIXME - highlight previous result */
710 g_printerr ("Find Previous\n");
715 find_bar_next_cb (EggFindBar *find_bar,
718 /* FIXME - highlight next result */
719 g_printerr ("Find Next\n");
723 find_bar_close_cb (EggFindBar *find_bar,
726 gtk_widget_hide (ev_window->priv->find_bar);
730 find_bar_search_changed_cb (EggFindBar *find_bar,
734 gboolean case_sensitive;
736 const char *search_string;
738 g_return_if_fail (EV_IS_WINDOW (ev_window));
740 /* Either the string or case sensitivity could have changed,
741 * we connect this callback to both. We also connect it
742 * to ::visible so when the find bar is hidden, we should
743 * pretend the search string is NULL/""
746 case_sensitive = egg_find_bar_get_case_sensitive (find_bar);
747 visible = GTK_WIDGET_VISIBLE (find_bar);
748 search_string = egg_find_bar_get_search_string (find_bar);
751 g_printerr ("search for '%s'\n", search_string ? search_string : "(nil)");
754 /* We don't require begin/end find calls to be matched up, it's really
755 * start_find and cancel_any_find_that_may_not_be_finished
757 if (visible && search_string) {
758 ev_document_begin_find (ev_window->priv->document, search_string, case_sensitive);
760 ev_document_end_find (ev_window->priv->document);
765 ev_window_dispose (GObject *object)
767 EvWindowPrivate *priv;
769 g_return_if_fail (object != NULL && EV_IS_WINDOW (object));
771 priv = EV_WINDOW (object)->priv;
773 if (priv->ui_manager) {
774 g_object_unref (priv->ui_manager);
775 priv->ui_manager = NULL;
778 if (priv->action_group) {
779 g_object_unref (priv->action_group);
780 priv->action_group = NULL;
783 G_OBJECT_CLASS (parent_class)->dispose (object);
787 ev_window_class_init (EvWindowClass *ev_window_class)
789 GObjectClass *g_object_class;
791 parent_class = g_type_class_peek_parent (ev_window_class);
793 g_object_class = G_OBJECT_CLASS (ev_window_class);
794 g_object_class->dispose = ev_window_dispose;
796 g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
799 /* setting up signal system */
800 ev_window_class->signal = ev_window_signal;
802 ev_window_signals [SIGNAL] = g_signal_new (
806 G_STRUCT_OFFSET (EvWindowClass,
810 g_cclosure_marshal_VOID__STRING,
813 /* setting up property system */
814 g_object_class->set_property = ev_window_set_property;
815 g_object_class->get_property = ev_window_get_property;
817 g_object_class_install_property (
820 g_param_spec_string ("attribute",
822 "A simple unneccessary attribute that "
823 "does nothing special except being a "
824 "demonstration for the correct implem"
825 "entation of a GObject property",
827 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
832 static GtkActionEntry entries[] = {
833 { "File", NULL, N_("_File") },
834 { "Edit", NULL, N_("_Edit") },
835 { "View", NULL, N_("_View") },
836 { "Go", NULL, N_("_Go") },
837 { "Help", NULL, N_("_Help") },
840 { "FileOpen", GTK_STOCK_OPEN, N_("_Open"), "<control>O",
842 G_CALLBACK (ev_window_cmd_file_open) },
843 { "FilePrint", GTK_STOCK_PRINT, N_("_Print"), "<control>P",
844 N_("Print this document"),
845 G_CALLBACK (ev_window_cmd_file_print) },
846 { "FileCloseWindow", GTK_STOCK_CLOSE, N_("_Close"), "<control>W",
847 N_("Close this window"),
848 G_CALLBACK (ev_window_cmd_file_close_window) },
851 { "EditCopy", GTK_STOCK_COPY, N_("_Copy"), "<control>C",
852 N_("Copy text from the document"),
853 G_CALLBACK (ev_window_cmd_edit_copy) },
855 { "EditFind", GTK_STOCK_FIND, N_("_Find"), "<control>F",
856 N_("Find a word or phrase in the document"),
857 G_CALLBACK (ev_window_cmd_edit_find) },
860 { "ViewZoomIn", GTK_STOCK_ZOOM_IN, N_("Zoom _In"), "<control>plus",
861 N_("Enlarge the document"),
862 G_CALLBACK (ev_window_cmd_view_zoom_in) },
863 { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, N_("Zoom _Out"), "<control>minus",
864 N_("Shrink the document"),
865 G_CALLBACK (ev_window_cmd_view_zoom_out) },
866 { "ViewNormalSize", GTK_STOCK_ZOOM_100, N_("_Normal Size"), "<control>0",
867 N_("Zoom to the normal size"),
868 G_CALLBACK (ev_window_cmd_view_normal_size) },
869 { "ViewBestFit", GTK_STOCK_ZOOM_FIT, N_("_Best Fit"), NULL,
870 N_("Zoom to fit the document to the current window"),
871 G_CALLBACK (ev_window_cmd_view_best_fit) },
872 { "ViewPageWidth", EV_STOCK_ZOOM_FIT_WIDTH, N_("Fit Page _Width"), NULL,
873 N_("Zoom to fit the width of the current window "),
874 G_CALLBACK (ev_window_cmd_view_page_width) },
877 { "GoBack", GTK_STOCK_GO_BACK, N_("_Back"), "<mod1>Left",
878 N_("Go to the page viewed before this one"),
879 G_CALLBACK (ev_window_cmd_go_back) },
880 { "GoForward", GTK_STOCK_GO_FORWARD, N_("Fo_rward"), "<mod1>Right",
881 N_("Go to the page viewed before this one"),
882 G_CALLBACK (ev_window_cmd_go_forward) },
883 { "GoPreviousPage", GTK_STOCK_GO_BACK, N_("_Previous Page"), "<control>Page_Up",
884 N_("Go to the previous page"),
885 G_CALLBACK (ev_window_cmd_go_previous_page) },
886 { "GoNextPage", GTK_STOCK_GO_FORWARD, N_("_Next Page"), "<control>Page_Down",
887 N_("Go to the next page"),
888 G_CALLBACK (ev_window_cmd_go_next_page) },
889 { "GoFirstPage", GTK_STOCK_GOTO_FIRST, N_("_First Page"), "<control>Home",
890 N_("Go to the first page"),
891 G_CALLBACK (ev_window_cmd_go_first_page) },
892 { "GoLastPage", GTK_STOCK_GOTO_LAST, N_("_Last Page"), "<control>End",
893 N_("Go to the last page"),
894 G_CALLBACK (ev_window_cmd_go_last_page) },
897 { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), NULL,
898 N_("Display help for the viewer application"),
899 G_CALLBACK (ev_window_cmd_help_contents) },
901 { "HelpAbout", GTK_STOCK_ABOUT, N_("_About"), NULL,
902 N_("Display credits for the document viewer creators"),
903 G_CALLBACK (ev_window_cmd_help_about) },
907 static GtkToggleActionEntry toggle_entries[] = {
909 { "ViewToolbar", NULL, N_("_Toolbar"), "<shift><control>T",
910 N_("Show or hide toolbar"),
911 G_CALLBACK (ev_window_view_toolbar_cb), TRUE },
912 { "ViewStatusbar", NULL, N_("_Statusbar"), NULL,
913 N_("Show or hide statusbar"),
914 G_CALLBACK (ev_window_view_statusbar_cb), TRUE },
915 { "ViewSidebar", NULL, N_("Side_bar"), "F9",
916 N_("Show or hide sidebar"),
917 G_CALLBACK (ev_window_view_sidebar_cb), FALSE },
918 { "ViewFullscreen", NULL, N_("_Fullscreen"), "F11",
919 N_("Expand the window to fill the screen"),
920 G_CALLBACK (ev_window_cmd_view_fullscreen) },
924 ev_window_init (EvWindow *ev_window)
926 GtkActionGroup *action_group;
927 GtkAccelGroup *accel_group;
928 GError *error = NULL;
929 GtkWidget *scrolled_window;
932 GtkWidget *sidebar_widget;
934 ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
936 gtk_window_set_title (GTK_WINDOW (ev_window), _("Document Viewer"));
938 ev_window->priv->main_box = gtk_vbox_new (FALSE, 0);
939 gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box);
940 gtk_widget_show (ev_window->priv->main_box);
942 action_group = gtk_action_group_new ("MenuActions");
943 ev_window->priv->action_group = action_group;
944 gtk_action_group_set_translation_domain (action_group, NULL);
945 gtk_action_group_add_actions (action_group, entries,
946 G_N_ELEMENTS (entries), ev_window);
947 gtk_action_group_add_toggle_actions (action_group, toggle_entries,
948 G_N_ELEMENTS (toggle_entries),
951 ev_window->priv->ui_manager = gtk_ui_manager_new ();
952 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
956 gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
957 gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
959 g_signal_connect (ev_window->priv->ui_manager, "connect_proxy",
960 G_CALLBACK (connect_proxy_cb), ev_window);
961 g_signal_connect (ev_window->priv->ui_manager, "disconnect_proxy",
962 G_CALLBACK (disconnect_proxy_cb), ev_window);
964 if (!gtk_ui_manager_add_ui_from_file (ev_window->priv->ui_manager,
965 DATADIR"/evince-ui.xml",
967 g_message ("building menus failed: %s", error->message);
968 g_error_free (error);
971 menubar = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
973 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), menubar,
976 toolbar = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
978 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), toolbar,
981 /* Add the main area */
982 ev_window->priv->hpaned = gtk_hpaned_new ();
983 gtk_widget_show (ev_window->priv->hpaned);
984 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), ev_window->priv->hpaned,
987 ev_window->priv->sidebar = ev_sidebar_new ();
988 gtk_widget_show (ev_window->priv->sidebar);
989 gtk_paned_add1 (GTK_PANED (ev_window->priv->hpaned),
990 ev_window->priv->sidebar);
992 /* Stub sidebar, for now */
993 sidebar_widget = ev_sidebar_bookmarks_new ();
994 gtk_widget_show (sidebar_widget);
995 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
1000 sidebar_widget = ev_sidebar_thumbnails_new ();
1001 gtk_widget_show (sidebar_widget);
1002 ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
1007 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1008 gtk_widget_show (scrolled_window);
1009 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1010 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1012 gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned),
1015 ev_window->priv->view = ev_view_new ();
1016 gtk_widget_show (ev_window->priv->view);
1017 gtk_container_add (GTK_CONTAINER (scrolled_window),
1018 ev_window->priv->view);
1019 g_signal_connect (ev_window->priv->view,
1021 G_CALLBACK (view_page_changed_cb),
1024 ev_window->priv->statusbar = gtk_statusbar_new ();
1025 gtk_widget_show (ev_window->priv->statusbar);
1026 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
1027 ev_window->priv->statusbar,
1029 ev_window->priv->help_message_cid = gtk_statusbar_get_context_id
1030 (GTK_STATUSBAR (ev_window->priv->statusbar), "help_message");
1032 ev_window->priv->find_bar = egg_find_bar_new ();
1033 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
1034 ev_window->priv->find_bar,
1037 /* Connect to find bar signals */
1038 g_signal_connect (ev_window->priv->find_bar,
1040 G_CALLBACK (find_bar_previous_cb),
1042 g_signal_connect (ev_window->priv->find_bar,
1044 G_CALLBACK (find_bar_next_cb),
1046 g_signal_connect (ev_window->priv->find_bar,
1048 G_CALLBACK (find_bar_close_cb),
1050 g_signal_connect (ev_window->priv->find_bar,
1051 "notify::search-string",
1052 G_CALLBACK (find_bar_search_changed_cb),
1054 g_signal_connect (ev_window->priv->find_bar,
1055 "notify::case-sensitive",
1056 G_CALLBACK (find_bar_search_changed_cb),
1058 g_signal_connect (ev_window->priv->find_bar,
1060 G_CALLBACK (find_bar_search_changed_cb),
1063 g_signal_connect (ev_window, "window-state-event",
1064 G_CALLBACK (ev_window_state_event_cb),
1067 /* Give focus to the scrolled window */
1068 gtk_widget_grab_focus (scrolled_window);
1070 update_action_sensitivity (ev_window);