]> www.fi.muni.cz Git - evince.git/blob - shell/ev-window.c
a1e86548c70aeeeef44e892d8650d98f72e38edf
[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 "ev-print-job.h"
37 #include "ev-document-find.h"
38 #include "eggfindbar.h"
39
40 #include "pdf-document.h"
41 #include "pixbuf-document.h"
42 #include "ps-document.h"
43
44 #include <glib/gi18n.h>
45 #include <gtk/gtk.h>
46 #include <libgnomevfs/gnome-vfs-mime-utils.h>
47 #include <libgnomeprintui/gnome-print-dialog.h>
48
49 #include <string.h>
50
51 #include "ev-application.h"
52 #include "ev-stock-icons.h"
53
54 enum {
55         PROP_0,
56         PROP_ATTRIBUTE
57 };
58
59 enum {
60         SIGNAL,
61         N_SIGNALS
62 };
63
64 struct _EvWindowPrivate {
65         GtkWidget *main_box;
66         GtkWidget *hpaned;
67         GtkWidget *sidebar;
68         GtkWidget *find_bar;
69         GtkWidget *view;
70         GtkActionGroup *action_group;
71         GtkUIManager *ui_manager;
72         GtkWidget *statusbar;
73         guint help_message_cid;
74         GtkWidget *exit_fullscreen_popup;
75         char *uri;
76
77         EvDocument *document;
78
79         gboolean fullscreen_mode;
80 };
81
82 #if 0
83 /* enable these to add support for signals */
84 static guint ev_window_signals [N_SIGNALS] = { 0 };
85 #endif
86
87 static void update_fullscreen_popup (EvWindow *window);
88
89 static GObjectClass *parent_class = NULL;
90
91 G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
92
93 #define EV_WINDOW_GET_PRIVATE(object) \
94         (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_WINDOW, EvWindowPrivate))
95
96 #if 0
97 const char *
98 ev_window_get_attribute (EvWindow *self)
99 {
100         g_return_val_if_fail (self != NULL && EV_IS_WINDOW (self), NULL);
101         
102         return self->priv->attribute;
103 }
104
105 void
106 ev_window_set_attribute (EvWindow* self, const char *attribute)
107 {
108         g_assert (self != NULL && EV_IS_WINDOW (self));
109         g_assert (attribute != NULL);
110
111         if (self->priv->attribute != NULL) {
112                 g_free (self->priv->attribute);
113         }
114
115         self->priv->attribute = g_strdup (attribute);
116
117         g_object_notify (G_OBJECT (self), "attribute");
118 }
119
120 static void
121 ev_window_get_property (GObject *object, guint prop_id, GValue *value,
122                         GParamSpec *param_spec)
123 {
124         EvWindow *self;
125
126         self = EV_WINDOW (object);
127
128         switch (prop_id) {
129         case PROP_ATTRIBUTE:
130                 g_value_set_string (value, self->priv->attribute);
131                 break;
132         default:
133                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
134                                                    prop_id,
135                                                    param_spec);
136                 break;
137         }
138 }
139
140 static void
141 ev_window_set_property (GObject *object, guint prop_id, const GValue *value,
142                         GParamSpec *param_spec)
143 {
144         EvWindow *self;
145         
146         self = EV_WINDOW (object);
147         
148         switch (prop_id) {
149         case PROP_ATTRIBUTE:
150                 ev_window_set_attribute (self, g_value_get_string (value));
151                 break;
152         default:
153                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
154                                                    prop_id,
155                                                    param_spec);
156                 break;
157         }
158 }
159 #endif
160
161 static void
162 set_action_sensitive (EvWindow   *ev_window,
163                       const char *name,
164                       gboolean    sensitive)
165 {
166         GtkAction *action = gtk_action_group_get_action (ev_window->priv->action_group,
167                                                          name);
168         gtk_action_set_sensitive (action, sensitive);
169 }
170
171 static void
172 update_action_sensitivity (EvWindow *ev_window)
173 {
174         int n_pages;
175         int page;
176
177         if (ev_window->priv->document)
178                 n_pages = ev_document_get_n_pages (ev_window->priv->document);
179         else
180                 n_pages = 1;
181
182         page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
183
184         set_action_sensitive (ev_window, "GoFirstPage", page > 1);
185         set_action_sensitive (ev_window, "GoPreviousPage", page > 1);
186         set_action_sensitive (ev_window, "GoNextPage", page < n_pages);
187         set_action_sensitive (ev_window, "GoLastPage", page < n_pages);
188 }
189
190 gboolean
191 ev_window_is_empty (const EvWindow *ev_window)
192 {
193         g_return_val_if_fail (EV_IS_WINDOW (ev_window), FALSE);
194         
195         return ev_window->priv->document == NULL;
196 }
197
198 static void
199 unable_to_load (EvWindow   *ev_window,
200                 const char *error_message)
201 {
202         GtkWidget *dialog;
203
204         dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
205                                          GTK_DIALOG_DESTROY_WITH_PARENT,
206                                          GTK_MESSAGE_ERROR,
207                                          GTK_BUTTONS_CLOSE,
208                                          _("Unable to open document"));
209         gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
210                                                   "%s", error_message);
211         gtk_dialog_run (GTK_DIALOG (dialog));
212         gtk_widget_destroy (dialog);
213 }
214
215 /* Would be nice to have this in gdk-pixbuf */
216 static gboolean
217 mime_type_supported_by_gdk_pixbuf (const gchar *mime_type)
218 {
219         GSList *formats, *list;
220         gboolean retval = FALSE;
221         
222         formats = gdk_pixbuf_get_formats ();
223         
224         list = formats;
225         while (list) {
226                 GdkPixbufFormat *format = list->data;
227                 int i;
228                 gchar **mime_types;
229                 
230                 if (gdk_pixbuf_format_is_disabled (format))
231                         continue;
232
233                 mime_types = gdk_pixbuf_format_get_mime_types (format);
234                 
235                 for (i = 0; mime_types[i] != NULL; i++) {
236                         if (strcmp (mime_types[i], mime_type) == 0) {
237                                 retval = TRUE;
238                                 break;
239                         }
240                 }
241                 
242                 if (retval)
243                         break;
244                 
245                 list = list->next;
246         }
247         
248         g_slist_free (formats);
249
250         return retval;
251 }
252
253 static void
254 update_window_title (EvDocument *document, GParamSpec *pspec, EvWindow *ev_window)
255 {
256         char *title = NULL;
257
258         if (document == NULL) {
259                 title = g_strdup (_("Document Viewer"));
260         } else {
261                 title = ev_document_get_title (document);
262
263                 if (title == NULL) {
264                         title = g_path_get_basename (ev_window->priv->uri);
265                 }
266         }
267
268         gtk_window_set_title (GTK_WINDOW (ev_window), title);
269
270         g_free (title);
271 }
272
273 void
274 ev_window_open (EvWindow *ev_window, const char *uri)
275 {
276         EvDocument *document = NULL;
277         char *mime_type;
278         
279         g_free (ev_window->priv->uri);
280         ev_window->priv->uri = g_strdup (uri);
281
282         mime_type = gnome_vfs_get_mime_type (uri);
283
284         if (mime_type == NULL)
285                 document = NULL;
286         else if (!strcmp (mime_type, "application/pdf"))
287                 document = g_object_new (PDF_TYPE_DOCUMENT, NULL);
288         else if (!strcmp (mime_type, "application/postscript"))
289                 document = g_object_new (PS_TYPE_DOCUMENT, NULL);
290         else if (mime_type_supported_by_gdk_pixbuf (mime_type))
291                 document = g_object_new (PIXBUF_TYPE_DOCUMENT, NULL);
292         
293         if (document) {
294                 GError *error = NULL;
295
296                 g_signal_connect_object (G_OBJECT (document),
297                                          "notify::title",
298                                          G_CALLBACK (update_window_title),
299                                          ev_window, 0);
300
301                 if (ev_document_load (document, uri, &error)) {
302                         if (ev_window->priv->document)
303                                 g_object_unref (ev_window->priv->document);
304                         ev_window->priv->document = document;
305
306                         ev_view_set_document (EV_VIEW (ev_window->priv->view),
307                                               document);
308                         ev_sidebar_set_document (EV_SIDEBAR (ev_window->priv->sidebar),
309                                                  document);
310
311                         update_action_sensitivity (ev_window);
312                 
313                 } else {
314                         g_assert (error != NULL);
315                         g_object_unref (document);
316                         unable_to_load (ev_window, error->message);
317                         g_error_free (error);
318                 }
319         } else {
320                 char *error_message;
321
322                 error_message = g_strdup_printf (_("Unhandled MIME type: '%s'"),
323                                                  mime_type?mime_type:"<Unknown MIME Type>");
324                 unable_to_load (ev_window, error_message);
325                 g_free (error_message);
326         }
327
328         g_free (mime_type);
329 }
330
331 static void
332 ev_window_cmd_file_open (GtkAction *action, EvWindow *ev_window)
333 {
334         ev_application_open (EV_APP, NULL);
335 }
336
337 static gboolean
338 using_postscript_printer (GnomePrintConfig *config)
339 {
340         const guchar *driver;
341         const guchar *transport;
342
343         driver = gnome_print_config_get (
344                 config, (const guchar *)"Settings.Engine.Backend.Driver");
345         
346         transport = gnome_print_config_get (
347                 config, (const guchar *)"Settings.Transport.Backend");
348         
349         if (driver) {
350                 if (!strcmp ((const gchar *)driver, "gnome-print-ps"))
351                         return TRUE;
352                 else 
353                         return FALSE;
354         } else  if (transport) {
355                 if (!strcmp ((const gchar *)transport, "CUPS"))
356                         return TRUE;
357         }
358         
359         return FALSE;
360 }
361
362 static void
363 ev_window_print (EvWindow *ev_window)
364 {
365         GnomePrintConfig *config;
366         GnomePrintJob *job;
367         GtkWidget *print_dialog;
368         EvPrintJob *print_job = NULL;
369
370         g_return_if_fail (EV_IS_WINDOW (ev_window));
371         g_return_if_fail (ev_window->priv->document != NULL);
372
373         config = gnome_print_config_default ();
374         job = gnome_print_job_new (config);
375
376         print_dialog = gnome_print_dialog_new (job, _("Print"),
377                                                (GNOME_PRINT_DIALOG_RANGE |
378                                                 GNOME_PRINT_DIALOG_COPIES));
379         gtk_dialog_set_response_sensitive (GTK_DIALOG (print_dialog),
380                                            GNOME_PRINT_DIALOG_RESPONSE_PREVIEW,
381                                            FALSE);
382         
383         while (TRUE) {
384                 int response;
385                 response = gtk_dialog_run (GTK_DIALOG (print_dialog));
386                 
387                 if (response != GNOME_PRINT_DIALOG_RESPONSE_PRINT)
388                         break;
389
390                 /* FIXME: Change this when we have the first backend
391                  * that can print more than postscript
392                  */
393                 if (!using_postscript_printer (config)) {
394                         GtkWidget *dialog;
395                         
396                         dialog = gtk_message_dialog_new (
397                                 GTK_WINDOW (print_dialog), GTK_DIALOG_MODAL,
398                                 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
399                                 _("Printing is not supported on this printer."));
400                         gtk_message_dialog_format_secondary_text (
401                                 GTK_MESSAGE_DIALOG (dialog),
402                                 _("You were trying to print to a printer using the \"%s\" driver. This program requires a PostScript printer driver."),
403                                 gnome_print_config_get (
404                                         config, "Settings.Engine.Backend.Driver"));
405                         gtk_dialog_run (GTK_DIALOG (dialog));
406                         gtk_widget_destroy (dialog);
407
408                         continue;
409                 }
410
411                 print_job = g_object_new (EV_TYPE_PRINT_JOB,
412                                           "gnome_print_job", job,
413                                           "document", ev_window->priv->document,
414                                           "print_dialog", print_dialog,
415                                           NULL);
416                 break;
417         }
418                                 
419         gtk_widget_destroy (print_dialog);
420
421         if (print_job != NULL)
422                 ev_print_job_print (print_job, GTK_WINDOW (ev_window));
423 }
424
425 static void
426 ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
427 {
428         ev_window_print (ev_window);
429 }
430
431 static void
432 ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
433 {
434         g_return_if_fail (EV_IS_WINDOW (ev_window));
435
436         gtk_widget_destroy (GTK_WIDGET (ev_window));
437 }
438
439 static void
440 find_not_supported_dialog (EvWindow   *ev_window)
441 {
442         GtkWidget *dialog;
443
444         /* If you change this so it isn't modal, be sure you don't
445          * allow multiple copies of the dialog...
446          */
447         
448         dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
449                                          GTK_DIALOG_DESTROY_WITH_PARENT,
450                                          GTK_MESSAGE_ERROR,
451                                          GTK_BUTTONS_CLOSE,
452                                          _("The \"Find\" feature will not work with this document"));
453         gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
454                                                   _("Searching for text is only supported for PDF documents."));
455         gtk_dialog_run (GTK_DIALOG (dialog));
456         gtk_widget_destroy (dialog);
457 }
458
459 static void
460 ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window)
461 {
462         g_return_if_fail (EV_IS_WINDOW (ev_window));
463
464         if (ev_window->priv->document == NULL) {
465                 g_printerr ("We should have set the Find menu item insensitive since there's no document\n");
466         } else if (!EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
467                 find_not_supported_dialog (ev_window);
468         } else {
469                 gtk_widget_show (ev_window->priv->find_bar);
470
471                 if (ev_window->priv->exit_fullscreen_popup) 
472                         update_fullscreen_popup (ev_window);
473         
474                 egg_find_bar_grab_focus (EGG_FIND_BAR (ev_window->priv->find_bar));
475         }
476 }
477
478 static void
479 ev_window_cmd_edit_copy (GtkAction *action, EvWindow *ev_window)
480 {
481         g_return_if_fail (EV_IS_WINDOW (ev_window));
482
483         /* FIXME */
484 }
485
486 static void
487 update_fullscreen_popup (EvWindow *window)
488 {
489         GtkWidget *popup = window->priv->exit_fullscreen_popup;
490         int popup_width, popup_height;
491         GdkRectangle screen_rect;
492
493         g_return_if_fail (popup != NULL);
494
495         if (!popup)
496                 return;
497         
498         popup_width = popup->requisition.width;
499         popup_height = popup->requisition.height;
500
501         /* FIXME multihead */
502         gdk_screen_get_monitor_geometry (gdk_screen_get_default (),
503                         gdk_screen_get_monitor_at_window
504                         (gdk_screen_get_default (),
505                          GTK_WIDGET (window)->window),
506                          &screen_rect);
507
508         if (GTK_WIDGET_VISIBLE (window->priv->find_bar)) {
509                 GtkRequisition req;
510
511                 gtk_widget_size_request (window->priv->find_bar, &req);
512                 
513                 screen_rect.height -= req.height;
514         }
515         
516         if (gtk_widget_get_direction (popup) == GTK_TEXT_DIR_RTL)
517         {
518                 gtk_window_move (GTK_WINDOW (popup),
519                                  screen_rect.x + screen_rect.width - popup_width,
520                                  screen_rect.height - popup_height);
521         }
522         else
523         {
524                 gtk_window_move (GTK_WINDOW (popup),
525                                 screen_rect.x, screen_rect.height - popup_height);
526         }
527 }
528
529 static void
530 screen_size_changed_cb (GdkScreen *screen,
531                         EvWindow *window)
532 {
533         update_fullscreen_popup (window);
534 }
535
536 static void
537 destroy_exit_fullscreen_popup (EvWindow *window)
538 {
539         if (window->priv->exit_fullscreen_popup != NULL)
540         {
541                 /* FIXME multihead */
542                 g_signal_handlers_disconnect_by_func
543                         (gdk_screen_get_default (),
544                          G_CALLBACK (screen_size_changed_cb), window);
545
546                 gtk_widget_destroy (window->priv->exit_fullscreen_popup);
547                 window->priv->exit_fullscreen_popup = NULL;
548         }
549 }
550
551 static void
552 exit_fullscreen_button_clicked_cb (GtkWidget *button, EvWindow *window)
553 {
554         GtkAction *action;
555
556         action = gtk_action_group_get_action (window->priv->action_group, "ViewFullscreen");
557         g_return_if_fail (action != NULL);
558
559         gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), FALSE);
560 }
561
562 static void
563 fullscreen_popup_size_request_cb (GtkWidget *popup, GtkRequisition *req, EvWindow *window)
564 {
565         update_fullscreen_popup (window);
566 }
567
568 static void
569 ev_window_fullscreen (EvWindow *window)
570 {
571         GtkWidget *popup, *button, *icon, *label, *hbox, *main_menu;
572
573         window->priv->fullscreen_mode = TRUE;
574
575         popup = gtk_window_new (GTK_WINDOW_POPUP);
576         window->priv->exit_fullscreen_popup = popup;
577
578         button = gtk_button_new ();
579         g_signal_connect (button, "clicked",
580                           G_CALLBACK (exit_fullscreen_button_clicked_cb),
581                           window);
582         gtk_widget_show (button);
583         gtk_container_add (GTK_CONTAINER (popup), button);
584
585         hbox = gtk_hbox_new (FALSE, 2);
586         gtk_widget_show (hbox);
587         gtk_container_add (GTK_CONTAINER (button), hbox);
588
589         icon = gtk_image_new_from_stock (GTK_STOCK_QUIT, GTK_ICON_SIZE_BUTTON);
590         gtk_widget_show (icon);
591         gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
592
593         label = gtk_label_new (_("Exit Fullscreen"));
594         gtk_widget_show (label);
595         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
596
597         gtk_window_set_resizable (GTK_WINDOW (popup), FALSE);
598
599         /* FIXME multihead */
600         g_signal_connect (gdk_screen_get_default (), "size-changed",
601                           G_CALLBACK (screen_size_changed_cb), window);
602         g_signal_connect (popup, "size_request",
603                           G_CALLBACK (fullscreen_popup_size_request_cb), window);
604
605         main_menu = gtk_ui_manager_get_widget (window->priv->ui_manager, "/MainMenu");
606         gtk_widget_hide (main_menu);
607         gtk_widget_hide (window->priv->statusbar);
608         
609         update_fullscreen_popup (window);
610
611         gtk_widget_show (popup);
612 }
613
614 static void
615 ev_window_unfullscreen (EvWindow *window)
616 {
617         GtkWidget *main_menu;
618         
619         window->priv->fullscreen_mode = FALSE;
620
621         main_menu = gtk_ui_manager_get_widget (window->priv->ui_manager, "/MainMenu");
622         gtk_widget_show (main_menu);
623         gtk_widget_show (window->priv->statusbar);
624         
625         destroy_exit_fullscreen_popup (window);
626 }
627  
628 static void
629 ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *ev_window)
630 {
631         gboolean fullscreen;
632         
633         g_return_if_fail (EV_IS_WINDOW (ev_window));
634
635         fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
636
637         if (fullscreen) {
638                 gtk_window_fullscreen (GTK_WINDOW (ev_window));
639         } else {
640                 gtk_window_unfullscreen (GTK_WINDOW (ev_window));
641         }
642 }
643
644 static gboolean
645 ev_window_state_event_cb (GtkWidget *widget, GdkEventWindowState *event, EvWindow *window)
646 {
647         if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
648         {
649                 GtkActionGroup *action_group;
650                 GtkAction *action;
651                 gboolean fullscreen;
652
653                 fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
654
655                 if (fullscreen)
656                 {
657                         ev_window_fullscreen (window);
658                 }
659                 else
660                 {
661                         ev_window_unfullscreen (window);
662                 }
663
664                 action_group = window->priv->action_group;
665
666                 action = gtk_action_group_get_action (action_group, "ViewFullscreen");
667                 g_signal_handlers_block_by_func
668                         (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
669                 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), fullscreen);
670                 g_signal_handlers_unblock_by_func
671                         (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window);
672
673         }
674
675         return FALSE;
676 }
677
678 static gboolean
679 ev_window_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *ev_window)
680 {
681         gtk_window_unfullscreen (GTK_WINDOW (ev_window));
682         
683         return FALSE;
684 }
685
686
687 static void
688 ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window)
689 {
690         g_return_if_fail (EV_IS_WINDOW (ev_window));
691
692         ev_view_zoom_in (EV_VIEW (ev_window->priv->view));
693 }
694
695 static void
696 ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window)
697 {
698         g_return_if_fail (EV_IS_WINDOW (ev_window));
699
700         ev_view_zoom_out (EV_VIEW (ev_window->priv->view));
701 }
702
703 static void
704 ev_window_cmd_view_normal_size (GtkAction *action, EvWindow *ev_window)
705 {
706         g_return_if_fail (EV_IS_WINDOW (ev_window));
707
708         ev_view_normal_size (EV_VIEW (ev_window->priv->view));
709 }
710
711 static void
712 ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
713 {
714         g_return_if_fail (EV_IS_WINDOW (ev_window));
715
716         ev_view_best_fit (EV_VIEW (ev_window->priv->view));
717 }
718
719 static void
720 ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
721 {
722         g_return_if_fail (EV_IS_WINDOW (ev_window));
723
724         ev_view_fit_width (EV_VIEW (ev_window->priv->view));
725 }
726
727 static void
728 ev_window_cmd_go_back (GtkAction *action, EvWindow *ev_window)
729 {
730         g_return_if_fail (EV_IS_WINDOW (ev_window));
731
732         /* FIXME */
733 }
734
735 static void
736 ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window)
737 {
738         g_return_if_fail (EV_IS_WINDOW (ev_window));
739
740         /* FIXME */
741 }
742
743 static void
744 ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
745 {
746         g_return_if_fail (EV_IS_WINDOW (ev_window));
747
748         ev_view_set_page (EV_VIEW (ev_window->priv->view),
749                           ev_view_get_page (EV_VIEW (ev_window->priv->view)) - 1);
750 }
751
752 static void
753 ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
754 {
755         g_return_if_fail (EV_IS_WINDOW (ev_window));
756
757         ev_view_set_page (EV_VIEW (ev_window->priv->view),
758                           ev_view_get_page (EV_VIEW (ev_window->priv->view)) + 1);
759 }
760
761 static void
762 ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
763 {
764         g_return_if_fail (EV_IS_WINDOW (ev_window));
765
766         ev_view_set_page (EV_VIEW (ev_window->priv->view), 1);
767 }
768
769 static void
770 ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
771 {
772         g_return_if_fail (EV_IS_WINDOW (ev_window));
773
774         ev_view_set_page (EV_VIEW (ev_window->priv->view), G_MAXINT);
775 }
776
777 static void
778 ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
779 {
780         g_return_if_fail (EV_IS_WINDOW (ev_window));
781
782         /* FIXME */
783 }
784
785 static void
786 ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
787 {
788         const char *authors[] = {
789                 N_("Many..."),
790                 NULL
791         };
792
793         const char *documenters[] = {
794                 N_("Not so many..."),
795                 NULL
796         };
797
798         const char *license[] = {
799                 N_("Evince is free software; you can redistribute it and/or modify\n"
800                    "it under the terms of the GNU General Public License as published by\n"
801                    "the Free Software Foundation; either version 2 of the License, or\n"
802                    "(at your option) any later version.\n"),            
803                 N_("Evince is distributed in the hope that it will be useful,\n"
804                    "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
805                    "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
806                    "GNU General Public License for more details.\n"),
807                 N_("You should have received a copy of the GNU General Public License\n"
808                    "along with Evince; if not, write to the Free Software Foundation, Inc.,\n"
809                    "59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n")
810         };
811
812         char *license_trans;
813
814 #ifdef ENABLE_NLS
815         const char **p;
816
817         for (p = authors; *p; ++p)
818                 *p = _(*p);
819
820         for (p = documenters; *p; ++p)
821                 *p = _(*p);
822 #endif
823
824         license_trans = g_strconcat (_(license[0]), "\n", _(license[1]), "\n",
825                                      _(license[2]), "\n", NULL);
826
827         gtk_show_about_dialog (
828                 GTK_WINDOW (ev_window),
829                 "name", _("Evince"),
830                 "version", VERSION,
831                 "copyright",
832                 _("\xc2\xa9 1996-2004 The Evince authors"),
833                 "license", license_trans,
834                 "website", "http://www.gnome.org/projects/evince",
835                 "comments", _("PostScript and PDF File Viewer."),
836                 "authors", authors,
837                 "documenters", documenters,
838                 "translator-credits", _("translator-credits"),
839                 NULL);
840
841         g_free (license_trans);
842 }
843
844 static void
845 ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window)
846 {
847         g_object_set (
848                 G_OBJECT (gtk_ui_manager_get_widget (
849                                   ev_window->priv->ui_manager,
850                                   "/ToolBar")),
851                 "visible",
852                 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
853                 NULL);
854 }
855
856 static void
857 ev_window_view_statusbar_cb (GtkAction *action, EvWindow *ev_window)
858 {
859         g_object_set (
860                 ev_window->priv->statusbar,
861                 "visible",
862                 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
863                 NULL);
864 }
865
866 static void
867 ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window)
868 {
869         g_object_set (
870                 ev_window->priv->sidebar,
871                 "visible",
872                 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)),
873                 NULL);
874 }
875
876 static void
877 menu_item_select_cb (GtkMenuItem *proxy, EvWindow *ev_window)
878 {
879         GtkAction *action;
880         char *message;
881
882         action = g_object_get_data (G_OBJECT (proxy), "gtk-action");
883         g_return_if_fail (action != NULL);
884         
885         g_object_get (G_OBJECT (action), "tooltip", &message, NULL);
886         if (message) {
887                 gtk_statusbar_push (GTK_STATUSBAR (ev_window->priv->statusbar),
888                                     ev_window->priv->help_message_cid, message);
889                 g_free (message);
890         }
891 }
892
893 static void
894 menu_item_deselect_cb (GtkMenuItem *proxy, EvWindow *ev_window)
895 {
896         gtk_statusbar_pop (GTK_STATUSBAR (ev_window->priv->statusbar),
897                            ev_window->priv->help_message_cid);
898 }
899
900 static void
901 connect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
902                   GtkWidget *proxy, EvWindow *ev_window)
903 {
904         if (GTK_IS_MENU_ITEM (proxy)) {
905                 g_signal_connect (proxy, "select",
906                                   G_CALLBACK (menu_item_select_cb), ev_window);
907                 g_signal_connect (proxy, "deselect",
908                                   G_CALLBACK (menu_item_deselect_cb),
909                                   ev_window);
910         }
911 }
912
913 static void
914 disconnect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
915                      GtkWidget *proxy, EvWindow *ev_window)
916 {
917         if (GTK_IS_MENU_ITEM (proxy)) {
918                 g_signal_handlers_disconnect_by_func
919                         (proxy, G_CALLBACK (menu_item_select_cb), ev_window);
920                 g_signal_handlers_disconnect_by_func
921                         (proxy, G_CALLBACK (menu_item_deselect_cb), ev_window);
922         }
923 }
924
925 static void
926 view_page_changed_cb (EvView   *view,
927                       EvWindow *ev_window)
928 {
929         update_action_sensitivity (ev_window);
930 }
931
932 static void
933 view_find_status_changed_cb (EvView   *view,
934                              EvWindow *ev_window)
935 {
936         char *text;
937
938         text = ev_view_get_find_status_message (view);
939
940         egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
941                                       text);
942
943         g_free (text);
944 }
945
946 static void
947 find_bar_previous_cb (EggFindBar *find_bar,
948                       EvWindow   *ev_window)
949 {
950         /* FIXME - highlight previous result */
951         g_printerr ("Find Previous\n");
952
953 }
954
955 static void
956 find_bar_next_cb (EggFindBar *find_bar,
957                   EvWindow   *ev_window)
958 {
959         /* FIXME - highlight next result */
960         g_printerr ("Find Next\n");
961 }
962
963 static void
964 find_bar_close_cb (EggFindBar *find_bar,
965                    EvWindow   *ev_window)
966 {
967         gtk_widget_hide (ev_window->priv->find_bar);
968
969         if (ev_window->priv->exit_fullscreen_popup)
970                 update_fullscreen_popup (ev_window);
971 }
972
973 static void
974 find_bar_search_changed_cb (EggFindBar *find_bar,
975                             GParamSpec *param,
976                             EvWindow   *ev_window)
977 {
978         gboolean case_sensitive;
979         gboolean visible;
980         const char *search_string;
981
982         g_return_if_fail (EV_IS_WINDOW (ev_window));
983         
984         /* Either the string or case sensitivity could have changed,
985          * we connect this callback to both. We also connect it
986          * to ::visible so when the find bar is hidden, we should
987          * pretend the search string is NULL/""
988          */
989
990         case_sensitive = egg_find_bar_get_case_sensitive (find_bar);
991         visible = GTK_WIDGET_VISIBLE (find_bar);
992         search_string = egg_find_bar_get_search_string (find_bar);
993         
994 #if 0
995         g_printerr ("search for '%s'\n", search_string ? search_string : "(nil)");
996 #endif
997
998         if (ev_window->priv->document &&
999             EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
1000                 if (visible && search_string) {
1001                         ev_document_find_begin (EV_DOCUMENT_FIND (ev_window->priv->document), search_string, case_sensitive);
1002                 } else {
1003                         ev_document_find_cancel (EV_DOCUMENT_FIND (ev_window->priv->document));
1004                         egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
1005                                                       NULL);
1006                 }
1007         }
1008 }
1009
1010 static void
1011 ev_window_dispose (GObject *object)
1012 {
1013         EvWindowPrivate *priv;
1014
1015         g_return_if_fail (object != NULL && EV_IS_WINDOW (object));
1016
1017         priv = EV_WINDOW (object)->priv;
1018
1019         if (priv->ui_manager) {
1020                 g_object_unref (priv->ui_manager);
1021                 priv->ui_manager = NULL;
1022         }
1023
1024         if (priv->action_group) {
1025                 g_object_unref (priv->action_group);
1026                 priv->action_group = NULL;
1027         }
1028         
1029         G_OBJECT_CLASS (parent_class)->dispose (object);
1030 }
1031
1032 static void
1033 ev_window_class_init (EvWindowClass *ev_window_class)
1034 {
1035         GObjectClass *g_object_class;
1036
1037         parent_class = g_type_class_peek_parent (ev_window_class);
1038
1039         g_object_class = G_OBJECT_CLASS (ev_window_class);
1040         g_object_class->dispose = ev_window_dispose;
1041
1042         g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
1043
1044 #if 0
1045         /* setting up signal system */
1046         ev_window_class->signal = ev_window_signal;
1047
1048         ev_window_signals [SIGNAL] = g_signal_new (
1049                 "signal",
1050                 EV_TYPE_WINDOW,
1051                 G_SIGNAL_RUN_LAST,
1052                 G_STRUCT_OFFSET (EvWindowClass,
1053                                  signal),
1054                 NULL,
1055                 NULL,
1056                 g_cclosure_marshal_VOID__STRING,
1057                 G_TYPE_NONE,
1058                 0);
1059         /* setting up property system */
1060         g_object_class->set_property = ev_window_set_property;
1061         g_object_class->get_property = ev_window_get_property;
1062
1063         g_object_class_install_property (
1064                 g_object_class,
1065                 PROP_ATTRIBUTE,
1066                 g_param_spec_string ("attribute",
1067                                      "Attribute",
1068                                      "A simple unneccessary attribute that "
1069                                      "does nothing special except being a "
1070                                      "demonstration for the correct implem"
1071                                      "entation of a GObject property",
1072                                      "default_value",
1073                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
1074 #endif
1075 }
1076
1077 /* Normal items */
1078 static GtkActionEntry entries[] = {
1079         { "File", NULL, N_("_File") },
1080         { "Edit", NULL, N_("_Edit") },
1081         { "View", NULL, N_("_View") },
1082         { "Go", NULL, N_("_Go") },
1083         { "Help", NULL, N_("_Help") },
1084
1085         /* File menu */
1086         { "FileOpen", GTK_STOCK_OPEN, N_("_Open"), "<control>O",
1087           N_("Open a file"),
1088           G_CALLBACK (ev_window_cmd_file_open) },
1089         { "FilePrint", GTK_STOCK_PRINT, N_("_Print"), "<control>P",
1090           N_("Print this document"),
1091           G_CALLBACK (ev_window_cmd_file_print) },
1092         { "FileCloseWindow", GTK_STOCK_CLOSE, N_("_Close"), "<control>W",
1093           N_("Close this window"),
1094           G_CALLBACK (ev_window_cmd_file_close_window) },
1095
1096         /* Edit menu */
1097         { "EditCopy", GTK_STOCK_COPY, N_("_Copy"), "<control>C",
1098           N_("Copy text from the document"),
1099           G_CALLBACK (ev_window_cmd_edit_copy) },
1100         
1101         { "EditFind", GTK_STOCK_FIND, N_("_Find"), "<control>F",
1102           N_("Find a word or phrase in the document"),
1103           G_CALLBACK (ev_window_cmd_edit_find) },
1104
1105         /* View menu */
1106         { "ViewZoomIn", GTK_STOCK_ZOOM_IN, N_("Zoom _In"), "<control>plus",
1107           N_("Enlarge the document"),
1108           G_CALLBACK (ev_window_cmd_view_zoom_in) },
1109         { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, N_("Zoom _Out"), "<control>minus",
1110           N_("Shrink the document"),
1111           G_CALLBACK (ev_window_cmd_view_zoom_out) },
1112         { "ViewNormalSize", GTK_STOCK_ZOOM_100, N_("_Normal Size"), "<control>0",
1113           N_("Zoom to the normal size"),
1114           G_CALLBACK (ev_window_cmd_view_normal_size) },
1115         { "ViewBestFit", GTK_STOCK_ZOOM_FIT, N_("_Best Fit"), NULL,
1116           N_("Zoom to fit the document to the current window"),
1117           G_CALLBACK (ev_window_cmd_view_best_fit) },
1118         { "ViewPageWidth", EV_STOCK_ZOOM_FIT_WIDTH, N_("Fit Page _Width"), NULL,
1119           N_("Zoom to fit the width of the current window "),
1120           G_CALLBACK (ev_window_cmd_view_page_width) },
1121
1122         /* Go menu */
1123         { "GoBack", GTK_STOCK_GO_BACK, N_("_Back"), "<mod1>Left",
1124           N_("Go to the page viewed before this one"),
1125           G_CALLBACK (ev_window_cmd_go_back) },
1126         { "GoForward", GTK_STOCK_GO_FORWARD, N_("Fo_rward"), "<mod1>Right",
1127           N_("Go to the page viewed before this one"),
1128           G_CALLBACK (ev_window_cmd_go_forward) },
1129         { "GoPreviousPage", GTK_STOCK_GO_BACK, N_("_Previous Page"), "<control>Page_Up",
1130           N_("Go to the previous page"),
1131           G_CALLBACK (ev_window_cmd_go_previous_page) },
1132         { "GoNextPage", GTK_STOCK_GO_FORWARD, N_("_Next Page"), "<control>Page_Down",
1133           N_("Go to the next page"),
1134           G_CALLBACK (ev_window_cmd_go_next_page) },
1135         { "GoFirstPage", GTK_STOCK_GOTO_FIRST, N_("_First Page"), "<control>Home",
1136           N_("Go to the first page"),
1137           G_CALLBACK (ev_window_cmd_go_first_page) },        
1138         { "GoLastPage", GTK_STOCK_GOTO_LAST, N_("_Last Page"), "<control>End",
1139           N_("Go to the last page"),
1140           G_CALLBACK (ev_window_cmd_go_last_page) },
1141         
1142         /* Help menu */
1143         { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), NULL,
1144           N_("Display help for the viewer application"),
1145           G_CALLBACK (ev_window_cmd_help_contents) },
1146         
1147         { "HelpAbout", GTK_STOCK_ABOUT, N_("_About"), NULL,
1148           N_("Display credits for the document viewer creators"),
1149           G_CALLBACK (ev_window_cmd_help_about) },
1150 };
1151
1152 /* Toggle items */
1153 static GtkToggleActionEntry toggle_entries[] = {
1154         /* View Menu */
1155         { "ViewToolbar", NULL, N_("_Toolbar"), "<shift><control>T",
1156           N_("Show or hide toolbar"),
1157           G_CALLBACK (ev_window_view_toolbar_cb), TRUE },
1158         { "ViewStatusbar", NULL, N_("_Statusbar"), NULL,
1159           N_("Show or hide statusbar"),
1160           G_CALLBACK (ev_window_view_statusbar_cb), TRUE },
1161         { "ViewSidebar", NULL, N_("Side_bar"), "F9",
1162           N_("Show or hide sidebar"),
1163           G_CALLBACK (ev_window_view_sidebar_cb), TRUE },
1164         { "ViewFullscreen", NULL, N_("_Fullscreen"), "F11",
1165           N_("Expand the window to fill the screen"),
1166           G_CALLBACK (ev_window_cmd_view_fullscreen) },
1167 };
1168
1169 static void
1170 ev_window_init (EvWindow *ev_window)
1171 {
1172         GtkActionGroup *action_group;
1173         GtkAccelGroup *accel_group;
1174         GError *error = NULL;
1175         GtkWidget *scrolled_window;
1176         GtkWidget *menubar;
1177         GtkWidget *toolbar;
1178         GtkWidget *sidebar_widget;
1179
1180         ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
1181
1182         update_window_title (NULL, NULL, ev_window);
1183
1184         ev_window->priv->main_box = gtk_vbox_new (FALSE, 0);
1185         gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box);
1186         gtk_widget_show (ev_window->priv->main_box);
1187         
1188         action_group = gtk_action_group_new ("MenuActions");
1189         ev_window->priv->action_group = action_group;
1190         gtk_action_group_set_translation_domain (action_group, NULL);
1191         gtk_action_group_add_actions (action_group, entries,
1192                                       G_N_ELEMENTS (entries), ev_window);
1193         gtk_action_group_add_toggle_actions (action_group, toggle_entries,
1194                                              G_N_ELEMENTS (toggle_entries),
1195                                              ev_window);
1196
1197         ev_window->priv->ui_manager = gtk_ui_manager_new ();
1198         gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
1199                                             action_group, 0);
1200
1201         accel_group =
1202                 gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
1203         gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
1204
1205         g_signal_connect (ev_window->priv->ui_manager, "connect_proxy",
1206                           G_CALLBACK (connect_proxy_cb), ev_window);
1207         g_signal_connect (ev_window->priv->ui_manager, "disconnect_proxy",
1208                           G_CALLBACK (disconnect_proxy_cb), ev_window);
1209
1210         if (!gtk_ui_manager_add_ui_from_file (ev_window->priv->ui_manager,
1211                                               DATADIR"/evince-ui.xml",
1212                                               &error)) {
1213                 g_message ("building menus failed: %s", error->message);
1214                 g_error_free (error);
1215         }
1216
1217         menubar = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
1218                                              "/MainMenu");
1219         gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), menubar,
1220                             FALSE, FALSE, 0);
1221
1222         toolbar = gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
1223                                              "/ToolBar");
1224         gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), toolbar,
1225                             FALSE, FALSE, 0);
1226
1227         /* Add the main area */
1228         ev_window->priv->hpaned = gtk_hpaned_new ();
1229         gtk_widget_show (ev_window->priv->hpaned);
1230         gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), ev_window->priv->hpaned,
1231                             TRUE, TRUE, 0);
1232
1233         ev_window->priv->sidebar = ev_sidebar_new ();
1234         gtk_widget_show (ev_window->priv->sidebar);
1235         gtk_paned_add1 (GTK_PANED (ev_window->priv->hpaned),
1236                         ev_window->priv->sidebar);
1237
1238         /* Stub sidebar, for now */
1239         sidebar_widget = ev_sidebar_bookmarks_new ();
1240         gtk_widget_show (sidebar_widget);
1241         ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
1242                              "bookmarks",
1243                              _("Bookmarks"),
1244                              sidebar_widget);
1245
1246         sidebar_widget = ev_sidebar_thumbnails_new ();
1247         gtk_widget_show (sidebar_widget);
1248         ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
1249                              "thumbnails",
1250                              _("Thumbnails"),
1251                              sidebar_widget);
1252         
1253         scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1254         gtk_widget_show (scrolled_window);
1255         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1256                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1257
1258         gtk_paned_add2 (GTK_PANED (ev_window->priv->hpaned),
1259                         scrolled_window);
1260
1261         ev_window->priv->view = ev_view_new ();
1262         gtk_widget_show (ev_window->priv->view);
1263         gtk_container_add (GTK_CONTAINER (scrolled_window),
1264                            ev_window->priv->view);
1265         g_signal_connect (ev_window->priv->view,
1266                           "page-changed",
1267                           G_CALLBACK (view_page_changed_cb),
1268                           ev_window);
1269         g_signal_connect (ev_window->priv->view,
1270                           "find-status-changed",
1271                           G_CALLBACK (view_find_status_changed_cb),
1272                           ev_window);
1273         
1274         ev_window->priv->statusbar = gtk_statusbar_new ();
1275         gtk_widget_show (ev_window->priv->statusbar);
1276         gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
1277                           ev_window->priv->statusbar,
1278                           FALSE, TRUE, 0);
1279         ev_window->priv->help_message_cid = gtk_statusbar_get_context_id
1280                 (GTK_STATUSBAR (ev_window->priv->statusbar), "help_message");
1281
1282         ev_window->priv->find_bar = egg_find_bar_new ();
1283         gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),
1284                           ev_window->priv->find_bar,
1285                           FALSE, TRUE, 0);
1286         
1287         /* Connect to find bar signals */
1288         g_signal_connect (ev_window->priv->find_bar,
1289                           "previous",
1290                           G_CALLBACK (find_bar_previous_cb),
1291                           ev_window);
1292         g_signal_connect (ev_window->priv->find_bar,
1293                           "next",
1294                           G_CALLBACK (find_bar_next_cb),
1295                           ev_window);
1296         g_signal_connect (ev_window->priv->find_bar,
1297                           "close",
1298                           G_CALLBACK (find_bar_close_cb),
1299                           ev_window);
1300         g_signal_connect (ev_window->priv->find_bar,
1301                           "notify::search-string",
1302                           G_CALLBACK (find_bar_search_changed_cb),
1303                           ev_window);
1304         g_signal_connect (ev_window->priv->find_bar,
1305                           "notify::case-sensitive",
1306                           G_CALLBACK (find_bar_search_changed_cb),
1307                           ev_window);
1308         g_signal_connect (ev_window->priv->find_bar,
1309                           "notify::visible",
1310                           G_CALLBACK (find_bar_search_changed_cb),
1311                           ev_window);
1312
1313         g_signal_connect (ev_window, "window-state-event",
1314                           G_CALLBACK (ev_window_state_event_cb),
1315                           ev_window);
1316         g_signal_connect (ev_window, "focus_out_event",
1317                           G_CALLBACK (ev_window_focus_out_cb),
1318                           ev_window);
1319         
1320         /* Give focus to the scrolled window */
1321         gtk_widget_grab_focus (scrolled_window);
1322         
1323         update_action_sensitivity (ev_window);
1324