]> www.fi.muni.cz Git - evince.git/blob - shell/ev-window.c
b23a1a6e8bb714d3fdd7f35139c76f4e308aa9d1
[evince.git] / shell / ev-window.c
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
3  *
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
8  *
9  *  Author:
10  *    Martin Kretzschmar <martink@gnome.org>
11  *
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.
16  *
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.
21  *
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.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include "ev-window.h"
32 #include "ev-sidebar.h"
33 #include "ev-sidebar-bookmarks.h"
34 #include "ev-sidebar-thumbnails.h"
35 #include "ev-view.h"
36 #include "eggfindbar.h"
37
38 #include "pdf-document.h"
39 #include "gtkgs.h"
40
41 #include <glib/gi18n.h>
42 #include <gtk/gtk.h>
43 #include <libgnomevfs/gnome-vfs-mime-utils.h>
44
45 #include <string.h>
46
47 #include "ev-application.h"
48 #include "ev-stock-icons.h"
49
50 enum {
51         PROP_0,
52         PROP_ATTRIBUTE
53 };
54
55 enum {
56         SIGNAL,
57         N_SIGNALS
58 };
59
60 struct _EvWindowPrivate {
61         GtkWidget *main_box;
62         GtkWidget *hpaned;
63         GtkWidget *sidebar;
64         GtkWidget *find_bar;
65         GtkWidget *view;
66         GtkActionGroup *action_group;
67         GtkUIManager *ui_manager;
68         GtkWidget *statusbar;
69         guint help_message_cid;
70         GtkWidget *exit_fullscreen_popup;
71
72         EvDocument *document;
73
74         gboolean fullscreen_mode;
75 };
76
77 #if 0
78 /* enable these to add support for signals */
79 static guint ev_window_signals [N_SIGNALS] = { 0 };
80 #endif
81
82 static GObjectClass *parent_class = NULL;
83
84 G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
85
86 #define EV_WINDOW_GET_PRIVATE(object) \
87         (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_WINDOW, EvWindowPrivate))
88
89 #if 0
90 const char *
91 ev_window_get_attribute (EvWindow *self)
92 {
93         g_return_val_if_fail (self != NULL && EV_IS_WINDOW (self), NULL);
94         
95         return self->priv->attribute;
96 }
97
98 void
99 ev_window_set_attribute (EvWindow* self, const char *attribute)
100 {
101         g_assert (self != NULL && EV_IS_WINDOW (self));
102         g_assert (attribute != NULL);
103
104         if (self->priv->attribute != NULL) {
105                 g_free (self->priv->attribute);
106         }
107
108         self->priv->attribute = g_strdup (attribute);
109
110         g_object_notify (G_OBJECT (self), "attribute");
111 }
112
113 static void
114 ev_window_get_property (GObject *object, guint prop_id, GValue *value,
115                         GParamSpec *param_spec)
116 {
117         EvWindow *self;
118
119         self = EV_WINDOW (object);
120
121         switch (prop_id) {
122         case PROP_ATTRIBUTE:
123                 g_value_set_string (value, self->priv->attribute);
124                 break;
125         default:
126                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
127                                                    prop_id,
128                                                    param_spec);
129                 break;
130         }
131 }
132
133 static void
134 ev_window_set_property (GObject *object, guint prop_id, const GValue *value,
135                         GParamSpec *param_spec)
136 {
137         EvWindow *self;
138         
139         self = EV_WINDOW (object);
140         
141         switch (prop_id) {
142         case PROP_ATTRIBUTE:
143                 ev_window_set_attribute (self, g_value_get_string (value));
144                 break;
145         default:
146                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
147                                                    prop_id,
148                                                    param_spec);
149                 break;
150         }
151 }
152 #endif
153
154 static void
155 set_action_sensitive (EvWindow   *ev_window,
156                       const char *name,
157                       gboolean    sensitive)
158 {
159         GtkAction *action = gtk_action_group_get_action (ev_window->priv->action_group,
160                                                          name);
161         gtk_action_set_sensitive (action, sensitive);
162 }
163
164 static void
165 update_action_sensitivity (EvWindow *ev_window)
166 {
167         int n_pages;
168         int page;
169
170         if (ev_window->priv->document)
171                 n_pages = ev_document_get_n_pages (ev_window->priv->document);
172         else
173                 n_pages = 1;
174
175         page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
176
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);
181 }
182
183 gboolean
184 ev_window_is_empty (const EvWindow *ev_window)
185 {
186         g_return_val_if_fail (EV_IS_WINDOW (ev_window), FALSE);
187         
188         return ev_window->priv->document == NULL;
189 }
190
191 static void
192 unable_to_load (EvWindow   *ev_window,
193                 const char *error_message)
194 {
195         GtkWidget *dialog;
196
197         dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
198                                          GTK_DIALOG_DESTROY_WITH_PARENT,
199                                          GTK_MESSAGE_ERROR,
200                                          GTK_BUTTONS_CLOSE,
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);
206 }
207
208 void
209 ev_window_open (EvWindow *ev_window, const char *uri)
210 {
211         EvDocument *document = NULL;
212         char *mime_type;
213
214         mime_type = gnome_vfs_get_mime_type (uri);
215
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);
220
221         if (document) {
222                 GError *error = NULL;
223
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;
228
229                         ev_view_set_document (EV_VIEW (ev_window->priv->view),
230                                               document);
231
232                         update_action_sensitivity (ev_window);
233                 
234                 } else {
235                         g_assert (error != NULL);
236                         g_object_unref (document);
237                         unable_to_load (ev_window, error->message);
238                         g_error_free (error);
239                 }
240         } else {
241                 char *error_message;
242
243                 error_message = g_strdup_printf (_("Unhandled MIME type: '%s'"),
244                                                  mime_type);
245                 unable_to_load (ev_window, error_message);
246                 g_free (error_message);
247         }
248
249         g_free (mime_type);
250 }
251
252 static void
253 ev_window_cmd_file_open (GtkAction *action, EvWindow *ev_window)
254 {
255         ev_application_open (EV_APP, NULL);
256 }
257
258 static void
259 ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
260 {
261         g_return_if_fail (EV_IS_WINDOW (ev_window));
262         /* FIXME */
263 }
264
265 static void
266 ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
267 {
268         g_return_if_fail (EV_IS_WINDOW (ev_window));
269
270         gtk_widget_destroy (GTK_WIDGET (ev_window));
271 }
272
273 static void
274 ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window)
275 {
276         g_return_if_fail (EV_IS_WINDOW (ev_window));
277
278         gtk_widget_show (ev_window->priv->find_bar);
279         egg_find_bar_grab_focus (EGG_FIND_BAR (ev_window->priv->find_bar));
280 }
281
282 static void
283 ev_window_cmd_edit_copy (GtkAction *action, EvWindow *ev_window)
284 {
285         g_return_if_fail (EV_IS_WINDOW (ev_window));
286
287         /* FIXME */
288 }
289
290 static void
291 update_fullscreen_popup (EvWindow *window)
292 {
293         GtkWidget *popup = window->priv->exit_fullscreen_popup;
294         int popup_width, popup_height;
295         GdkRectangle screen_rect;
296
297         g_return_if_fail (popup != NULL);
298
299         popup_width = popup->requisition.width;
300         popup_height = popup->requisition.height;
301
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),
307                          &screen_rect);
308
309         if (gtk_widget_get_direction (popup) == GTK_TEXT_DIR_RTL)
310         {
311                 gtk_window_move (GTK_WINDOW (popup),
312                                  screen_rect.x + screen_rect.width - popup_width,
313                                  screen_rect.height - popup_height);
314         }
315         else
316         {
317                 gtk_window_move (GTK_WINDOW (popup),
318                                 screen_rect.x, screen_rect.height - popup_height);
319         }
320 }
321
322 static void
323 screen_size_changed_cb (GdkScreen *screen,
324                         EvWindow *window)
325 {
326         update_fullscreen_popup (window);
327 }
328
329 static void
330 destroy_exit_fullscreen_popup (EvWindow *window)
331 {
332         if (window->priv->exit_fullscreen_popup != NULL)
333         {
334                 /* FIXME multihead */
335                 g_signal_handlers_disconnect_by_func
336                         (gdk_screen_get_default (),
337                          G_CALLBACK (screen_size_changed_cb), window);
338
339                 gtk_widget_destroy (window->priv->exit_fullscreen_popup);
340                 window->priv->exit_fullscreen_popup = NULL;
341         }
342 }
343
344 static void
345 exit_fullscreen_button_clicked_cb (GtkWidget *button, EvWindow *window)
346 {
347         GtkAction *action;
348
349         action = gtk_action_group_get_action (window->priv->action_group, "ViewFullscreen");
350         g_return_if_fail (action != NULL);
351
352         gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), FALSE);
353 }
354
355 static void
356 fullscreen_popup_size_request_cb (GtkWidget *popup, GtkRequisition *req, EvWindow *window)
357 {
358         update_fullscreen_popup (window);
359 }
360
361 static void
362 ev_window_fullscreen (EvWindow *window)
363 {
364         GtkWidget *popup, *button, *icon, *label, *hbox;
365
366         window->priv->fullscreen_mode = TRUE;
367
368         popup = gtk_window_new (GTK_WINDOW_POPUP);
369         window->priv->exit_fullscreen_popup = popup;
370
371         button = gtk_button_new ();
372         g_signal_connect (button, "clicked",
373                           G_CALLBACK (exit_fullscreen_button_clicked_cb),
374                           window);
375         gtk_widget_show (button);
376         gtk_container_add (GTK_CONTAINER (popup), button);
377
378         hbox = gtk_hbox_new (FALSE, 2);
379         gtk_widget_show (hbox);
380         gtk_container_add (GTK_CONTAINER (button), hbox);
381
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);
385
386         label = gtk_label_new (_("Exit Fullscreen"));
387         gtk_widget_show (label);
388         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
389
390         gtk_window_set_resizable (GTK_WINDOW (popup), FALSE);
391
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);
397
398         update_fullscreen_popup (window);
399
400         gtk_widget_show (popup);
401 }
402
403 static void
404 ev_window_unfullscreen (EvWindow *window)
405 {
406         window->priv->fullscreen_mode = FALSE;
407
408         destroy_exit_fullscreen_popup (window);
409 }
410  
411 static void
412 ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *ev_window)
413 {
414         gboolean fullscreen;
415         
416         g_return_if_fail (EV_IS_WINDOW (ev_window));
417
418         fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
419
420         if (fullscreen) {
421                 gtk_window_fullscreen (GTK_WINDOW (ev_window));
422         } else {
423                 gtk_window_unfullscreen (GTK_WINDOW (ev_window));
424         }
425 }
426
427 static gboolean
428 ev_window_state_event_cb (GtkWidget *widget, GdkEventWindowState *event, EvWindow *window)
429 {
430         if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
431         {
432                 GtkActionGroup *action_group;
433                 GtkAction *action;
434                 GtkWidget *main_menu;
435                 gboolean fullscreen;
436
437                 fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
438
439                 if (fullscreen)
440                 {
441                         ev_window_fullscreen (window);
442                 }
443                 else
444                 {
445                         ev_window_unfullscreen (window);
446                 }
447
448                 action_group = window->priv->action_group;
449
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);
456
457                 main_menu = gtk_ui_manager_get_widget (window->priv->ui_manager, "/MainMenu");
458                 g_object_set (main_menu, "visible", !fullscreen, NULL);
459         }
460
461         return FALSE;
462 }
463
464 static void
465 ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window)
466 {
467         g_return_if_fail (EV_IS_WINDOW (ev_window));
468
469         ev_view_zoom_in (EV_VIEW (ev_window->priv->view));
470 }
471
472 static void
473 ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window)
474 {
475         g_return_if_fail (EV_IS_WINDOW (ev_window));
476
477         ev_view_zoom_out (EV_VIEW (ev_window->priv->view));
478 }
479
480 static void
481 ev_window_cmd_view_normal_size (GtkAction *action, EvWindow *ev_window)
482 {
483         g_return_if_fail (EV_IS_WINDOW (ev_window));
484
485         ev_view_normal_size (EV_VIEW (ev_window->priv->view));
486 }
487
488 static void
489 ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
490 {
491         g_return_if_fail (EV_IS_WINDOW (ev_window));
492
493         ev_view_best_fit (EV_VIEW (ev_window->priv->view));
494 }
495
496 static void
497 ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
498 {
499         g_return_if_fail (EV_IS_WINDOW (ev_window));
500
501         ev_view_fit_width (EV_VIEW (ev_window->priv->view));
502 }
503
504 static void
505 ev_window_cmd_go_back (GtkAction *action, EvWindow *ev_window)
506 {
507         g_return_if_fail (EV_IS_WINDOW (ev_window));
508
509         /* FIXME */
510 }
511
512 static void
513 ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window)
514 {
515         g_return_if_fail (EV_IS_WINDOW (ev_window));
516
517         /* FIXME */
518 }
519
520 static void
521 ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
522 {
523         g_return_if_fail (EV_IS_WINDOW (ev_window));
524
525         ev_view_set_page (EV_VIEW (ev_window->priv->view),
526                           ev_view_get_page (EV_VIEW (ev_window->priv->view)) - 1);
527 }
528
529 static void
530 ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
531 {
532         g_return_if_fail (EV_IS_WINDOW (ev_window));
533
534         ev_view_set_page (EV_VIEW (ev_window->priv->view),
535                           ev_view_get_page (EV_VIEW (ev_window->priv->view)) + 1);
536 }
537
538 static void
539 ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
540 {
541         g_return_if_fail (EV_IS_WINDOW (ev_window));
542
543         ev_view_set_page (EV_VIEW (ev_window->priv->view), 1);
544 }
545
546 static void
547 ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
548 {
549         g_return_if_fail (EV_IS_WINDOW (ev_window));
550
551         ev_view_set_page (EV_VIEW (ev_window->priv->view), G_MAXINT);
552 }
553
554 static void
555 ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
556 {
557         g_return_if_fail (EV_IS_WINDOW (ev_window));
558
559         /* FIXME */
560 }
561
562 static void
563 ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
564 {
565         const char *authors[] = {
566                 N_("Many..."),
567                 NULL
568         };
569
570         const char *documenters[] = {
571                 N_("Not so many..."),
572                 NULL
573         };
574
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")
587         };
588
589         char *license_trans;
590
591 #ifdef ENABLE_NLS
592         const char **p;
593
594         for (p = authors; *p; ++p)
595                 *p = _(*p);
596
597         for (p = documenters; *p; ++p)
598                 *p = _(*p);
599 #endif
600
601         license_trans = g_strconcat (_(license[0]), "\n", _(license[1]), "\n",
602                                      _(license[2]), "\n", NULL);
603
604         gtk_show_about_dialog (
605                 GTK_WINDOW (ev_window),
606                 "name", _("Evince"),
607                 "version", VERSION,
608                 "copyright",
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."),
613                 "authors", authors,
614                 "documenters", documenters,
615                 "translator-credits", _("translator-credits"),
616                 NULL);
617
618         g_free (license_trans);
619 }
620
621 static void
622 ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window)
623 {
624         g_object_set (
625                 G_OBJECT (gtk_ui_manager_get_widget (
626                                   ev_window->priv->ui_manager,
627                                   "/ToolBar")),
628                 "visible",
629                 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
630                 NULL);
631 }
632
633 static void
634 ev_window_view_statusbar_cb (GtkAction *action, EvWindow *ev_window)
635 {
636         g_object_set (
637                 ev_window->priv->statusbar,
638                 "visible",
639                 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
640                 NULL);
641 }
642
643 static void
644 ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window)
645 {
646         /* FIXME */
647 }
648
649 static void
650 menu_item_select_cb (GtkMenuItem *proxy, EvWindow *ev_window)
651 {
652         GtkAction *action;
653         char *message;
654
655         action = g_object_get_data (G_OBJECT (proxy), "gtk-action");
656         g_return_if_fail (action != NULL);
657         
658         g_object_get (G_OBJECT (action), "tooltip", &message, NULL);
659         if (message) {
660                 gtk_statusbar_push (GTK_STATUSBAR (ev_window->priv->statusbar),
661                                     ev_window->priv->help_message_cid, message);
662                 g_free (message);
663         }
664 }
665
666 static void
667 menu_item_deselect_cb (GtkMenuItem *proxy, EvWindow *ev_window)
668 {
669         gtk_statusbar_pop (GTK_STATUSBAR (ev_window->priv->statusbar),
670                            ev_window->priv->help_message_cid);
671 }
672
673 static void
674 connect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
675                   GtkWidget *proxy, EvWindow *ev_window)
676 {
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),
682                                   ev_window);
683         }
684 }
685
686 static void
687 disconnect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
688                      GtkWidget *proxy, EvWindow *ev_window)
689 {
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);
695         }
696 }
697
698 static void
699 view_page_changed_cb (EvView   *view,
700                       EvWindow *ev_window)
701 {
702         update_action_sensitivity (ev_window);
703 }
704
705 static void
706 find_bar_previous_cb (EggFindBar *find_bar,
707                       EvWindow   *ev_window)
708 {
709         /* FIXME - highlight previous result */
710         g_printerr ("Find Previous\n");
711
712 }
713
714 static void
715 find_bar_next_cb (EggFindBar *find_bar,
716                   EvWindow   *ev_window)
717 {
718         /* FIXME - highlight next result */
719         g_printerr ("Find Next\n");
720 }
721
722 static void
723 find_bar_close_cb (EggFindBar *find_bar,
724                    EvWindow   *ev_window)
725 {
726         gtk_widget_hide (ev_window->priv->find_bar);
727 }
728
729 static void
730 find_bar_search_changed_cb (EggFindBar *find_bar,
731                             GParamSpec *param,
732                             EvWindow   *ev_window)
733 {
734         gboolean case_sensitive;
735         gboolean visible;
736         const char *search_string;
737
738         g_return_if_fail (EV_IS_WINDOW (ev_window));
739         
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/""
744          */
745
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);
749         
750 #if 0
751         g_printerr ("search for '%s'\n", search_string ? search_string : "(nil)");
752 #endif
753
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
756          */
757         if (visible && search_string) {
758                 ev_document_begin_find (ev_window->priv->document, search_string, case_sensitive);
759         } else {
760                 ev_document_end_find (ev_window->priv->document);
761         }
762 }
763
764 static void
765 ev_window_dispose (GObject *object)
766 {
767         EvWindowPrivate *priv;
768
769         g_return_if_fail (object != NULL && EV_IS_WINDOW (object));
770
771         priv = EV_WINDOW (object)->priv;
772
773         if (priv->ui_manager) {
774                 g_object_unref (priv->ui_manager);
775                 priv->ui_manager = NULL;
776         }
777
778         if (priv->action_group) {
779                 g_object_unref (priv->action_group);
780                 priv->action_group = NULL;
781         }
782         
783         G_OBJECT_CLASS (parent_class)->dispose (object);
784 }
785
786 static void
787 ev_window_class_init (EvWindowClass *ev_window_class)
788 {
789         GObjectClass *g_object_class;
790
791         parent_class = g_type_class_peek_parent (ev_window_class);
792
793         g_object_class = G_OBJECT_CLASS (ev_window_class);
794         g_object_class->dispose = ev_window_dispose;
795
796         g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
797
798 #if 0
799         /* setting up signal system */
800         ev_window_class->signal = ev_window_signal;
801
802         ev_window_signals [SIGNAL] = g_signal_new (
803                 "signal",
804                 EV_TYPE_WINDOW,
805                 G_SIGNAL_RUN_LAST,
806                 G_STRUCT_OFFSET (EvWindowClass,
807                                  signal),
808                 NULL,
809                 NULL,
810                 g_cclosure_marshal_VOID__STRING,
811                 G_TYPE_NONE,
812                 0);
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;
816
817         g_object_class_install_property (
818                 g_object_class,
819                 PROP_ATTRIBUTE,
820                 g_param_spec_string ("attribute",
821                                      "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",
826                                      "default_value",
827                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
828 #endif
829 }
830
831 /* Normal items */
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") },
838
839         /* File menu */
840         { "FileOpen", GTK_STOCK_OPEN, N_("_Open"), "<control>O",
841           N_("Open a file"),
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) },
849
850         /* Edit menu */
851         { "EditCopy", GTK_STOCK_COPY, N_("_Copy"), "<control>C",
852           N_("Copy text from the document"),
853           G_CALLBACK (ev_window_cmd_edit_copy) },
854         
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) },
858
859         /* View menu */
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) },
875
876         /* Go menu */
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) },
895         
896         /* Help menu */
897         { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), NULL,
898           N_("Display help for the viewer application"),
899           G_CALLBACK (ev_window_cmd_help_contents) },
900         
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) },
904 };
905
906 /* Toggle items */
907 static GtkToggleActionEntry toggle_entries[] = {
908         /* View Menu */
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) },
921 };
922
923 static void
924 ev_window_init (EvWindow *ev_window)
925 {
926         GtkActionGroup *action_group;
927         GtkAccelGroup *accel_group;
928         GError *error = NULL;
929         GtkWidget *scrolled_window;
930         GtkWidget *menubar;
931         GtkWidget *toolbar;
932         GtkWidget *sidebar_widget;
933
934         ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
935
936         gtk_window_set_title (GTK_WINDOW (ev_window), _("Document Viewer"));
937
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);
941         
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),
949                                              ev_window);
950
951         ev_window->priv->ui_manager = gtk_ui_manager_new ();
952         gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
953                                             action_group, 0);
954
955         accel_group =
956                 gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
957         gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
958
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);
963
964         if (!gtk_ui_manager_add_ui_from_file (ev_window->priv->ui_manager,
965                                               DATADIR"/evince-ui.xml",
966                                               &error)) {
967                 g_message ("building menus failed: %s", error->message);
968                 g_error_free (error);
969         }
970
971         menubar = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
972                                              "/MainMenu");
973         gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), menubar,
974                             FALSE, FALSE, 0);
975
976         toolbar = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
977                                              "/ToolBar");
978         gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), toolbar,
979                             FALSE, FALSE, 0);
980
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,
985                             TRUE, TRUE, 0);
986
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);
991
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),
996                              "bookmarks",
997                              _("Bookmarks"),
998                              sidebar_widget);
999
1000         sidebar_widget = ev_sidebar_thumbnails_new ();
1001         gtk_widget_show (sidebar_widget);
1002         ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
1003                              "thumbnails",
1004                              _("Thumbnails"),
1005                              sidebar_widget);
1006         
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);
1011
1012         gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned),
1013                         scrolled_window);
1014
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,
1020                           "page-changed",
1021                           G_CALLBACK (view_page_changed_cb),
1022                           ev_window);
1023
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,
1028                           FALSE, TRUE, 0);
1029         ev_window->priv->help_message_cid = gtk_statusbar_get_context_id
1030                 (GTK_STATUSBAR (ev_window->priv->statusbar), "help_message");
1031
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,
1035                           FALSE, TRUE, 0);
1036         
1037         /* Connect to find bar signals */
1038         g_signal_connect (ev_window->priv->find_bar,
1039                           "previous",
1040                           G_CALLBACK (find_bar_previous_cb),
1041                           ev_window);
1042         g_signal_connect (ev_window->priv->find_bar,
1043                           "next",
1044                           G_CALLBACK (find_bar_next_cb),
1045                           ev_window);
1046         g_signal_connect (ev_window->priv->find_bar,
1047                           "close",
1048                           G_CALLBACK (find_bar_close_cb),
1049                           ev_window);
1050         g_signal_connect (ev_window->priv->find_bar,
1051                           "notify::search-string",
1052                           G_CALLBACK (find_bar_search_changed_cb),
1053                           ev_window);
1054         g_signal_connect (ev_window->priv->find_bar,
1055                           "notify::case-sensitive",
1056                           G_CALLBACK (find_bar_search_changed_cb),
1057                           ev_window);
1058         g_signal_connect (ev_window->priv->find_bar,
1059                           "notify::visible",
1060                           G_CALLBACK (find_bar_search_changed_cb),
1061                           ev_window);
1062
1063         g_signal_connect (ev_window, "window-state-event",
1064                           G_CALLBACK (ev_window_state_event_cb),
1065                           ev_window);
1066         
1067         /* Give focus to the scrolled window */
1068         gtk_widget_grab_focus (scrolled_window);
1069         
1070         update_action_sensitivity (ev_window);
1071