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.
8 * Martin Kretzschmar <martink@gnome.org>
10 * Evince is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * Evince is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
29 #include "ev-window.h"
30 #include "ev-sidebar.h"
32 #include <glib/gi18n.h>
34 #include <libgnomevfs/gnome-vfs-mime-utils.h>
38 #include "ev-application.h"
50 struct _EvWindowPrivate {
54 GtkWidget *bonobo_widget;
55 GtkUIManager *ui_manager;
57 guint help_message_cid;
61 /* enable these to add support for signals */
62 static guint ev_window_signals [N_SIGNALS] = { 0 };
65 static GObjectClass *parent_class = NULL;
67 G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
69 #define EV_WINDOW_GET_PRIVATE(object) \
70 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_WINDOW, EvWindowPrivate))
74 ev_window_get_attribute (EvWindow *self)
76 g_return_val_if_fail (self != NULL && EV_IS_WINDOW (self), NULL);
78 return self->priv->attribute;
82 ev_window_set_attribute (EvWindow* self, const char *attribute)
84 g_assert (self != NULL && EV_IS_WINDOW (self));
85 g_assert (attribute != NULL);
87 if (self->priv->attribute != NULL) {
88 g_free (self->priv->attribute);
91 self->priv->attribute = g_strdup (attribute);
93 g_object_notify (G_OBJECT (self), "attribute");
97 ev_window_get_property (GObject *object, guint prop_id, GValue *value,
98 GParamSpec *param_spec)
102 self = EV_WINDOW (object);
106 g_value_set_string (value, self->priv->attribute);
109 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
117 ev_window_set_property (GObject *object, guint prop_id, const GValue *value,
118 GParamSpec *param_spec)
122 self = EV_WINDOW (object);
126 ev_window_set_attribute (self, g_value_get_string (value));
129 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
138 ev_window_is_empty (const EvWindow *ev_window)
140 g_return_val_if_fail (EV_IS_WINDOW (ev_window), FALSE);
142 return ev_window->priv->bonobo_widget == NULL;
146 ev_window_open (EvWindow *ev_window, const char *uri)
150 BonoboObject *bonobo_control;
151 CORBA_Environment ev;
152 Bonobo_PersistFile pf;
154 mime_type = gnome_vfs_get_mime_type (uri);
156 g_return_if_fail (mime_type != NULL); /* FIXME set error */
158 if (!strcmp (mime_type, "application/pdf")) {
159 bonobo_control = create_gpdf_control ();
160 } else if (!strcmp (mime_type, "application/postscript")) {
161 bonobo_control = create_ggv_control ();
162 } else if (!strcmp (mime_type, "application/x-gzip")) {
163 g_message ("Cannot open gzip-compressed file %s.", uri);
165 } else if (!strcmp (mime_type, "application/x-bzip")) {
166 g_message ("Cannot open bzip2-compressed file %s.", uri);
169 g_warning ("Don't know how to open %s file %s.",
170 mime_type, uri); /* FIXME set error */
174 ev_window->priv->bonobo_widget = bonobo_widget_new_control_from_objref (
175 bonobo_object_corba_objref (bonobo_control), CORBA_OBJECT_NIL);
176 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
177 ev_window->priv->bonobo_widget,
179 CORBA_exception_init (&ev);
180 pf = bonobo_object_query_interface (
181 bonobo_control, "IDL:Bonobo/PersistFile:1.0", &ev);
182 Bonobo_PersistFile_load (pf, uri, &ev);
183 gtk_widget_show (ev_window->priv->bonobo_widget);
184 bonobo_object_release_unref (pf, &ev);
185 bonobo_object_unref (bonobo_control);
186 CORBA_exception_free (&ev);
194 ev_window_cmd_file_open (GtkAction *action, EvWindow *ev_window)
196 ev_application_open (EV_APP, NULL);
200 ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
202 g_return_if_fail (EV_IS_WINDOW (ev_window));
207 ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
209 g_return_if_fail (EV_IS_WINDOW (ev_window));
211 gtk_widget_destroy (GTK_WIDGET (ev_window));
215 ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window)
217 g_return_if_fail (EV_IS_WINDOW (ev_window));
223 ev_window_cmd_edit_copy (GtkAction *action, EvWindow *ev_window)
225 g_return_if_fail (EV_IS_WINDOW (ev_window));
231 ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *ev_window)
233 g_return_if_fail (EV_IS_WINDOW (ev_window));
239 ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window)
241 g_return_if_fail (EV_IS_WINDOW (ev_window));
247 ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window)
249 g_return_if_fail (EV_IS_WINDOW (ev_window));
255 ev_window_cmd_view_normal_size (GtkAction *action, EvWindow *ev_window)
257 g_return_if_fail (EV_IS_WINDOW (ev_window));
263 ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
265 g_return_if_fail (EV_IS_WINDOW (ev_window));
271 ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
273 g_return_if_fail (EV_IS_WINDOW (ev_window));
279 ev_window_cmd_go_back (GtkAction *action, EvWindow *ev_window)
281 g_return_if_fail (EV_IS_WINDOW (ev_window));
287 ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window)
289 g_return_if_fail (EV_IS_WINDOW (ev_window));
295 ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
297 g_return_if_fail (EV_IS_WINDOW (ev_window));
303 ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
305 g_return_if_fail (EV_IS_WINDOW (ev_window));
311 ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
313 g_return_if_fail (EV_IS_WINDOW (ev_window));
319 ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
321 g_return_if_fail (EV_IS_WINDOW (ev_window));
327 ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
329 g_return_if_fail (EV_IS_WINDOW (ev_window));
335 ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
337 const char *authors[] = {
342 const char *documenters[] = {
343 N_("Not so many..."),
347 const char *license[] = {
348 N_("Evince is free software; you can redistribute it and/or modify\n"
349 "it under the terms of the GNU General Public License as published by\n"
350 "the Free Software Foundation; either version 2 of the License, or\n"
351 "(at your option) any later version.\n"),
352 N_("Evince is distributed in the hope that it will be useful,\n"
353 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
354 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
355 "GNU General Public License for more details.\n"),
356 N_("You should have received a copy of the GNU General Public License\n"
357 "along with Evince; if not, write to the Free Software Foundation, Inc.,\n"
358 "59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n")
366 for (p = authors; *p; ++p)
369 for (p = documenters; *p; ++p)
373 license_trans = g_strconcat (_(license[0]), "\n", _(license[1]), "\n",
374 _(license[2]), "\n", NULL);
376 gtk_show_about_dialog (
377 GTK_WINDOW (ev_window),
381 _("\xc2\xa9 1996-2004 The Evince authors"),
382 "license", license_trans,
383 "website", "http://www.gnome.org/projects/evince",
384 "comments", _("PostScript and PDF File Viewer."),
386 "documenters", documenters,
387 "translator-credits", _("translator-credits"),
390 g_free (license_trans);
394 ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window)
397 G_OBJECT (gtk_ui_manager_get_widget (
398 ev_window->priv->ui_manager,
401 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
406 ev_window_view_statusbar_cb (GtkAction *action, EvWindow *ev_window)
409 ev_window->priv->statusbar,
411 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
416 ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window)
422 menu_item_select_cb (GtkMenuItem *proxy, EvWindow *ev_window)
427 action = g_object_get_data (G_OBJECT (proxy), "gtk-action");
428 g_return_if_fail (action != NULL);
430 g_object_get (G_OBJECT (action), "tooltip", &message, NULL);
432 gtk_statusbar_push (GTK_STATUSBAR (ev_window->priv->statusbar),
433 ev_window->priv->help_message_cid, message);
439 menu_item_deselect_cb (GtkMenuItem *proxy, EvWindow *ev_window)
441 gtk_statusbar_pop (GTK_STATUSBAR (ev_window->priv->statusbar),
442 ev_window->priv->help_message_cid);
446 connect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
447 GtkWidget *proxy, EvWindow *ev_window)
449 if (GTK_IS_MENU_ITEM (proxy)) {
450 g_signal_connect (proxy, "select",
451 G_CALLBACK (menu_item_select_cb), ev_window);
452 g_signal_connect (proxy, "deselect",
453 G_CALLBACK (menu_item_deselect_cb),
459 disconnect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
460 GtkWidget *proxy, EvWindow *ev_window)
462 if (GTK_IS_MENU_ITEM (proxy)) {
463 g_signal_handlers_disconnect_by_func
464 (proxy, G_CALLBACK (menu_item_select_cb), ev_window);
465 g_signal_handlers_disconnect_by_func
466 (proxy, G_CALLBACK (menu_item_deselect_cb), ev_window);
471 ev_window_dispose (GObject *object)
473 EvWindowPrivate *priv;
475 g_return_if_fail (object != NULL && EV_IS_WINDOW (object));
477 priv = EV_WINDOW (object)->priv;
479 if (priv->ui_manager) {
480 g_object_unref (priv->ui_manager);
481 priv->ui_manager = NULL;
484 G_OBJECT_CLASS (parent_class)->dispose (object);
488 ev_window_class_init (EvWindowClass *ev_window_class)
490 GObjectClass *g_object_class;
492 parent_class = g_type_class_peek_parent (ev_window_class);
494 g_object_class = G_OBJECT_CLASS (ev_window_class);
495 g_object_class->dispose = ev_window_dispose;
497 g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
500 /* setting up signal system */
501 ev_window_class->signal = ev_window_signal;
503 ev_window_signals [SIGNAL] = g_signal_new (
507 G_STRUCT_OFFSET (EvWindowClass,
511 g_cclosure_marshal_VOID__STRING,
514 /* setting up property system */
515 g_object_class->set_property = ev_window_set_property;
516 g_object_class->get_property = ev_window_get_property;
518 g_object_class_install_property (
521 g_param_spec_string ("attribute",
523 "A simple unneccessary attribute that "
524 "does nothing special except being a "
525 "demonstration for the correct implem"
526 "entation of a GObject property",
528 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
533 static GtkActionEntry entries[] = {
534 { "File", NULL, N_("_File") },
535 { "Edit", NULL, N_("_Edit") },
536 { "View", NULL, N_("_View") },
537 { "Go", NULL, N_("_Go") },
538 { "Help", NULL, N_("_Help") },
541 { "FileOpen", GTK_STOCK_OPEN, N_("_Open"), "<control>O",
543 G_CALLBACK (ev_window_cmd_file_open) },
544 { "FilePrint", GTK_STOCK_PRINT, N_("_Print"), "<control>P",
545 N_("Print this document"),
546 G_CALLBACK (ev_window_cmd_file_print) },
547 { "FileCloseWindow", GTK_STOCK_CLOSE, N_("_Close"), "<control>W",
548 N_("Close this window"),
549 G_CALLBACK (ev_window_cmd_file_close_window) },
552 { "EditCopy", GTK_STOCK_COPY, N_("_Copy"), "<control>C",
553 N_("Copy text from the document"),
554 G_CALLBACK (ev_window_cmd_edit_copy) },
556 { "EditFind", GTK_STOCK_FIND, N_("_Find"), "<control>F",
557 N_("Find a word or phrase in the document"),
558 G_CALLBACK (ev_window_cmd_edit_find) },
561 { "ViewFullscreen", NULL, N_("_Fullscreen"), "F11",
562 N_("Expand the window to fill the screen"),
563 G_CALLBACK (ev_window_cmd_view_fullscreen) },
564 { "ViewZoomIn", GTK_STOCK_ZOOM_IN, N_("Zoom _In"), "<control>plus",
565 N_("Enlarge the document"),
566 G_CALLBACK (ev_window_cmd_view_zoom_in) },
567 { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, N_("Zoom _Out"), "<control>minus",
568 N_("Shrink the document"),
569 G_CALLBACK (ev_window_cmd_view_zoom_out) },
570 { "ViewNormalSize", GTK_STOCK_ZOOM_100, N_("_Normal Size"), "<control>0",
571 N_("Zoom to the normal size"),
572 G_CALLBACK (ev_window_cmd_view_normal_size) },
573 { "ViewBestFit", GTK_STOCK_ZOOM_FIT, N_("_Best Fit"), NULL,
574 N_("Zoom to fit the document to the current window"),
575 G_CALLBACK (ev_window_cmd_view_best_fit) },
576 { "ViewPageWidth", NULL, N_("Fit Page _Width"), NULL,
577 N_("Zoom to fit the width of the current window "),
578 G_CALLBACK (ev_window_cmd_view_page_width) },
581 { "GoBack", GTK_STOCK_GO_BACK, N_("_Back"), "<mod1>Left",
582 N_("Go to the page viewed before this one"),
583 G_CALLBACK (ev_window_cmd_go_back) },
584 { "GoForward", GTK_STOCK_GO_FORWARD, N_("Fo_rward"), "<mod1>Right",
585 N_("Go to the page viewed before this one"),
586 G_CALLBACK (ev_window_cmd_go_forward) },
587 { "GoPreviousPage", GTK_STOCK_GO_BACK, N_("_Previous Page"), "<control>Page_Up",
588 N_("Go to the previous page"),
589 G_CALLBACK (ev_window_cmd_go_previous_page) },
590 { "GoNextPage", GTK_STOCK_GO_FORWARD, N_("_Next Page"), "<control>Page_Down",
591 N_("Go to the next page"),
592 G_CALLBACK (ev_window_cmd_go_next_page) },
593 { "GoFirstPage", GTK_STOCK_GOTO_FIRST, N_("_First Page"), "<control>Home",
594 N_("Go to the first page"),
595 G_CALLBACK (ev_window_cmd_go_first_page) },
596 { "GoLastPage", GTK_STOCK_GOTO_LAST, N_("_Last Page"), "<control>End",
597 N_("Go to the last page"),
598 G_CALLBACK (ev_window_cmd_go_last_page) },
601 { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), NULL,
602 N_("Display help for the viewer application"),
603 G_CALLBACK (ev_window_cmd_help_contents) },
605 { "HelpAbout", GTK_STOCK_ABOUT, N_("_About"), NULL,
606 N_("Display credits for the document viewer creators"),
607 G_CALLBACK (ev_window_cmd_help_about) },
611 static GtkToggleActionEntry toggle_entries[] = {
613 { "ViewToolbar", NULL, N_("_Toolbar"), "<shift><control>T",
614 N_("Show or hide toolbar"),
615 G_CALLBACK (ev_window_view_toolbar_cb), TRUE },
616 { "ViewStatusbar", NULL, N_("_Statusbar"), NULL,
617 N_("Show or hide statusbar"),
618 G_CALLBACK (ev_window_view_statusbar_cb), TRUE },
619 { "ViewSidebar", NULL, N_("Side_bar"), "F9",
620 N_("Show or hide sidebar"),
621 G_CALLBACK (ev_window_view_sidebar_cb), FALSE },
625 ev_window_init (EvWindow *ev_window)
627 GtkActionGroup *action_group;
628 GtkAccelGroup *accel_group;
629 GError *error = NULL;
634 ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
636 gtk_window_set_title (GTK_WINDOW (ev_window), _("Document Viewer"));
638 ev_window->priv->main_box = gtk_vbox_new (FALSE, 0);
639 gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box);
640 gtk_widget_show (ev_window->priv->main_box);
642 action_group = gtk_action_group_new ("MenuActions");
643 gtk_action_group_set_translation_domain (action_group, NULL);
644 gtk_action_group_add_actions (action_group, entries,
645 G_N_ELEMENTS (entries), ev_window);
646 gtk_action_group_add_toggle_actions (action_group, toggle_entries,
647 G_N_ELEMENTS (toggle_entries),
650 ev_window->priv->ui_manager = gtk_ui_manager_new ();
651 gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
655 gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
656 gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
658 g_signal_connect (ev_window->priv->ui_manager, "connect_proxy",
659 G_CALLBACK (connect_proxy_cb), ev_window);
660 g_signal_connect (ev_window->priv->ui_manager, "disconnect_proxy",
661 G_CALLBACK (disconnect_proxy_cb), ev_window);
663 if (!gtk_ui_manager_add_ui_from_file (ev_window->priv->ui_manager,
664 DATADIR"/evince-ui.xml",
666 g_message ("building menus failed: %s", error->message);
667 g_error_free (error);
670 menubar = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
672 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), menubar,
675 toolbar = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
677 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), toolbar,
680 /* Add the main area */
681 ev_window->priv->hpaned = gtk_hpaned_new ();
682 gtk_widget_show (ev_window->priv->hpaned);
683 gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), ev_window->priv->hpaned,
686 ev_window->priv->sidebar = ev_sidebar_new ();
687 gtk_widget_show (ev_window->priv->sidebar);
688 gtk_paned_add1 (GTK_PANED (ev_window->priv->hpaned),
689 ev_window->priv->sidebar);
691 /* Stub widget, for now */
692 darea = gtk_drawing_area_new ();
693 gtk_widget_show (darea);
694 gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned),
698 ev_window->priv->statusbar = gtk_statusbar_new ();
699 gtk_widget_show (ev_window->priv->statusbar);
700 gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
701 ev_window->priv->statusbar,
703 ev_window->priv->help_message_cid = gtk_statusbar_get_context_id
704 (GTK_STATUSBAR (ev_window->priv->statusbar), "help_message");