]> www.fi.muni.cz Git - evince.git/commitdiff
[shell] Use the new EvViewPresentation for presentation mode
authorCarlos Garcia Campos <carlosgc@gnome.org>
Sun, 3 Jan 2010 17:46:21 +0000 (18:46 +0100)
committerCarlos Garcia Campos <carlosgc@gnome.org>
Sun, 3 Jan 2010 20:14:13 +0000 (21:14 +0100)
shell/ev-window.c

index d83d43fa8daf7f9d72c315692e6d44d09ae4bbfa..d7565fffe46562bd568a290b07c6d5765f2a8302 100644 (file)
@@ -86,6 +86,7 @@
 #include "ev-utils.h"
 #include "ev-keyring.h"
 #include "ev-view.h"
+#include "ev-view-presentation.h"
 #include "ev-view-type-builtins.h"
 #include "ev-window.h"
 #include "ev-window-title.h"
@@ -134,6 +135,7 @@ struct _EvWindowPrivate {
        GtkWidget *find_bar;
        GtkWidget *scrolled_window;
        GtkWidget *view;
+       GtkWidget *presentation_view;
        GtkWidget *message_area;
        GtkWidget *password_view;
        GtkWidget *sidebar_thumbs;
@@ -165,9 +167,6 @@ struct _EvWindowPrivate {
        /* Fullscreen mode */
        GtkWidget *fullscreen_toolbar;
 
-       /* Presentation mode */
-       guint      presentation_timeout_id;
-
        /* Popup view */
        GtkWidget *view_popup;
        EvLink    *link;
@@ -216,6 +215,8 @@ struct _EvWindowPrivate {
 #define EV_WINDOW_GET_PRIVATE(object) \
        (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_WINDOW, EvWindowPrivate))
 
+#define EV_WINDOW_IS_PRESENTATION(w) (w->priv->presentation_view != NULL)
+
 #define PAGE_SELECTOR_ACTION   "PageSelector"
 #define ZOOM_CONTROL_ACTION    "ViewZoom"
 #define NAVIGATION_ACTION      "Navigation"
@@ -226,8 +227,6 @@ struct _EvWindowPrivate {
 #define GCONF_LOCKDOWN_PRINT        "/desktop/gnome/lockdown/disable_printing"
 #define GCONF_LOCKDOWN_PRINT_SETUP  "/desktop/gnome/lockdown/disable_print_setup"
 
-#define PRESENTATION_TIMEOUT 5
-
 #define SIDEBAR_DEFAULT_SIZE    132
 #define LINKS_SIDEBAR_ID "links"
 #define THUMBNAILS_SIDEBAR_ID "thumbnails"
@@ -468,7 +467,7 @@ ev_window_update_actions (EvWindow *ev_window)
         ev_window_set_action_sensitive (ev_window, "F3",
                                         has_pages && can_find_in_page);
 
-       presentation_mode = ev_view_get_presentation (view);
+       presentation_mode = EV_WINDOW_IS_PRESENTATION (ev_window);
        
        ev_window_set_action_sensitive (ev_window, "ViewZoomIn",
                                        has_pages &&
@@ -556,7 +555,7 @@ update_chrome_visibility (EvWindow *window)
        gboolean menubar, toolbar, findbar, fullscreen_toolbar, sidebar;
        gboolean fullscreen_mode, presentation, fullscreen;
 
-       presentation = ev_view_get_presentation (EV_VIEW (priv->view));
+       presentation = EV_WINDOW_IS_PRESENTATION (window);
        fullscreen = ev_document_model_get_fullscreen (priv->model);
        fullscreen_mode = fullscreen || presentation;
 
@@ -1247,7 +1246,10 @@ ev_window_setup_document (EvWindow *ev_window)
        info = ev_document_get_info (document);
        update_document_mode (ev_window, info->mode);
 
-       gtk_widget_grab_focus (ev_window->priv->view);
+       if (EV_WINDOW_IS_PRESENTATION (ev_window))
+               gtk_widget_grab_focus (ev_window->priv->presentation_view);
+       else
+               gtk_widget_grab_focus (ev_window->priv->view);
 
        return FALSE;
 }
@@ -3477,7 +3479,6 @@ fullscreen_toolbar_remove_shadow (GtkWidget *toolbar)
 static void
 ev_window_run_fullscreen (EvWindow *window)
 {
-       EvView  *view = EV_VIEW (window->priv->view);
        gboolean fullscreen_window = TRUE;
 
        if (ev_document_model_get_fullscreen (window->priv->model))
@@ -3500,7 +3501,7 @@ ev_window_run_fullscreen (EvWindow *window)
                                       window->priv->fullscreen_toolbar, 1);
        }
 
-       if (ev_view_get_presentation (view)) {
+       if (EV_WINDOW_IS_PRESENTATION (window)) {
                ev_window_stop_presentation (window, FALSE);
                fullscreen_window = FALSE;
        }
@@ -3562,70 +3563,6 @@ ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *window)
        }
 }
 
-static gboolean
-presentation_timeout_cb (EvWindow *window)
-{
-       EvView *view = EV_VIEW (window->priv->view);
-
-       if (!view || !ev_view_get_presentation (EV_VIEW (view)))
-               return FALSE;
-
-       ev_view_hide_cursor (EV_VIEW (window->priv->view));
-       window->priv->presentation_timeout_id = 0;
-
-       return FALSE;
-}
-
-static void
-presentation_set_timeout (EvWindow *window)
-{
-       if (window->priv->presentation_timeout_id > 0) {
-               g_source_remove (window->priv->presentation_timeout_id);
-       }
-
-       window->priv->presentation_timeout_id =
-               g_timeout_add_seconds (PRESENTATION_TIMEOUT,
-                                      (GSourceFunc)presentation_timeout_cb, window);
-
-       ev_view_show_cursor (EV_VIEW (window->priv->view));
-}
-
-static void
-presentation_clear_timeout (EvWindow *window)
-{
-       if (window->priv->presentation_timeout_id > 0) {
-               g_source_remove (window->priv->presentation_timeout_id);
-       }
-       
-       window->priv->presentation_timeout_id = 0;
-
-       ev_view_show_cursor (EV_VIEW (window->priv->view));
-}
-
-static gboolean
-presentation_motion_notify_cb (GtkWidget *widget,
-                              GdkEventMotion *event,
-                              gpointer user_data)
-{
-       EvWindow *window = EV_WINDOW (user_data);
-
-       presentation_set_timeout (window);
-
-       return FALSE;
-}
-
-static gboolean
-presentation_leave_notify_cb (GtkWidget *widget,
-                             GdkEventCrossing *event,
-                             gpointer user_data)
-{
-       EvWindow *window = EV_WINDOW (user_data);
-
-       presentation_clear_timeout (window);
-
-       return FALSE;
-}
-
 static void
 ev_window_update_presentation_action (EvWindow *window)
 {
@@ -3635,7 +3572,7 @@ ev_window_update_presentation_action (EvWindow *window)
        g_signal_handlers_block_by_func
                (action, G_CALLBACK (ev_window_cmd_view_presentation), window);
        gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
-                                     ev_view_get_presentation (EV_VIEW (window->priv->view)));
+                                     EV_WINDOW_IS_PRESENTATION (window));
        g_signal_handlers_unblock_by_func
                (action, G_CALLBACK (ev_window_cmd_view_presentation), window);
 }
@@ -3643,42 +3580,37 @@ ev_window_update_presentation_action (EvWindow *window)
 static void
 ev_window_run_presentation (EvWindow *window)
 {
-       EvView  *view = EV_VIEW (window->priv->view);
        gboolean fullscreen_window = TRUE;
+       guint    current_page;
+       guint    rotation;
 
-       if (ev_view_get_presentation (view))
+       if (EV_WINDOW_IS_PRESENTATION (window))
                return;
 
        if (ev_document_model_get_fullscreen (window->priv->model)) {
                ev_window_stop_fullscreen (window, FALSE);
                fullscreen_window = FALSE;
        }
-       
-       g_object_set (G_OBJECT (window->priv->scrolled_window),
-                     "shadow-type", GTK_SHADOW_NONE,
-                     NULL);
 
-       ev_view_set_presentation (view, TRUE);
-       ev_window_update_presentation_action (window);
+       current_page = ev_document_model_get_page (window->priv->model);
+       rotation = ev_document_model_get_rotation (window->priv->model);
+       window->priv->presentation_view =
+               ev_view_presentation_new (window->priv->document, current_page, rotation);
 
+       gtk_box_pack_start (GTK_BOX (window->priv->main_box),
+                           window->priv->presentation_view,
+                           FALSE, FALSE, 0);
+       gtk_widget_show (window->priv->presentation_view);
+
+       ev_window_update_presentation_action (window);
        update_chrome_visibility (window);
-       
-       gtk_widget_grab_focus (window->priv->view);
+
+       gtk_widget_grab_focus (window->priv->presentation_view);
        if (fullscreen_window)
                gtk_window_fullscreen (GTK_WINDOW (window));
 
-       g_signal_connect (window->priv->view,
-                         "motion-notify-event",
-                         G_CALLBACK (presentation_motion_notify_cb),
-                         window);
-       g_signal_connect (window->priv->view,
-                         "leave-notify-event",
-                         G_CALLBACK (presentation_leave_notify_cb),
-                         window);
-       presentation_set_timeout (window);
-
        ev_application_screensaver_disable (EV_APP);
-       
+
        if (window->priv->metadata && !ev_window_is_empty (window))
                ev_metadata_set_boolean (window->priv->metadata, "presentation", TRUE);
 }
@@ -3687,28 +3619,24 @@ static void
 ev_window_stop_presentation (EvWindow *window,
                             gboolean  unfullscreen_window)
 {
-       EvView *view = EV_VIEW (window->priv->view);
-       
-       if (!ev_view_get_presentation (view))
+       guint current_page;
+
+       if (!EV_WINDOW_IS_PRESENTATION (window))
                return;
 
-       g_object_set (G_OBJECT (window->priv->scrolled_window),
-                     "shadow-type", GTK_SHADOW_IN,
-                     NULL);
+       current_page = ev_view_presentation_get_current_page (EV_VIEW_PRESENTATION (window->priv->presentation_view));
+       ev_document_model_set_page (window->priv->model, current_page);
+
+       gtk_container_remove (GTK_CONTAINER (window->priv->main_box),
+                             window->priv->presentation_view);
+       window->priv->presentation_view = NULL;
 
-       ev_view_set_presentation (EV_VIEW (window->priv->view), FALSE);
        ev_window_update_presentation_action (window);
        update_chrome_visibility (window);
        if (unfullscreen_window)
                gtk_window_unfullscreen (GTK_WINDOW (window));
 
-       g_signal_handlers_disconnect_by_func (window->priv->view,
-                                             (gpointer) presentation_motion_notify_cb,
-                                             window);
-       g_signal_handlers_disconnect_by_func (window->priv->view,
-                                             (gpointer) presentation_leave_notify_cb,
-                                             window);
-       presentation_clear_timeout (window);
+       gtk_widget_grab_focus (window->priv->view);
 
        ev_application_screensaver_enable (EV_APP);
 
@@ -3784,7 +3712,6 @@ ev_window_state_event (GtkWidget           *widget,
                       GdkEventWindowState *event)
 {
        EvWindow *window = EV_WINDOW (widget);
-       EvView   *view = EV_VIEW (window->priv->view);
 
        if (GTK_WIDGET_CLASS (ev_window_parent_class)->window_state_event) {
                GTK_WIDGET_CLASS (ev_window_parent_class)->window_state_event (widget, event);
@@ -3794,14 +3721,14 @@ ev_window_state_event (GtkWidget           *widget,
                return FALSE;
 
        if (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) {
-               if (ev_document_model_get_fullscreen (window->priv->model) || ev_view_get_presentation (view))
+               if (ev_document_model_get_fullscreen (window->priv->model) || EV_WINDOW_IS_PRESENTATION (window))
                        return FALSE;
                
                ev_window_run_fullscreen (window);
        } else {
                if (ev_document_model_get_fullscreen (window->priv->model))
                        ev_window_stop_fullscreen (window, FALSE);
-               else if (ev_view_get_presentation (view))
+               else if (EV_WINDOW_IS_PRESENTATION (window))
                        ev_window_stop_presentation (window, FALSE);
        }
 
@@ -4056,23 +3983,19 @@ ev_window_cmd_escape (GtkAction *action, EvWindow *window)
                gtk_widget_grab_focus (window->priv->view);
        } else {
                gboolean fullscreen;
-               gboolean presentation;
 
                fullscreen = ev_document_model_get_fullscreen (window->priv->model);
-               g_object_get (window->priv->view,
-                             "presentation", &presentation,
-                             NULL);
 
                if (fullscreen) {
                        ev_window_stop_fullscreen (window, TRUE);
-               } else if (presentation) {
+               } else if (EV_WINDOW_IS_PRESENTATION (window)) {
                        ev_window_stop_presentation (window, TRUE);
                        gtk_widget_grab_focus (window->priv->view);
                } else {
                        gtk_widget_grab_focus (window->priv->view);
                }
 
-               if (fullscreen && presentation)
+               if (fullscreen && EV_WINDOW_IS_PRESENTATION (window))
                        g_warning ("Both fullscreen and presentation set somehow");
        }
 }
@@ -4354,7 +4277,7 @@ ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window)
 static void
 ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window)
 {
-       if (ev_view_get_presentation (EV_VIEW (ev_window->priv->view)))
+       if (EV_WINDOW_IS_PRESENTATION (ev_window))
                return;
            
        update_chrome_flag (ev_window, EV_CHROME_SIDEBAR,
@@ -4395,12 +4318,11 @@ ev_window_sidebar_visibility_changed_cb (EvSidebar  *ev_sidebar,
                                         GParamSpec *pspec,
                                         EvWindow   *ev_window)
 {
-       EvView *view = EV_VIEW (ev_window->priv->view);
        GtkAction *action;
 
        action = gtk_action_group_get_action (ev_window->priv->action_group, "ViewSidebar");
 
-       if (!ev_view_get_presentation (view)) {
+       if (!EV_WINDOW_IS_PRESENTATION (ev_window)) {
                gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
                                              GTK_WIDGET_VISIBLE (ev_sidebar));
 
@@ -4982,11 +4904,6 @@ ev_window_dispose (GObject *object)
                priv->history = NULL;
        }
 
-       if (priv->presentation_timeout_id > 0) {
-               g_source_remove (priv->presentation_timeout_id);
-               priv->presentation_timeout_id = 0;
-       }
-
        if (priv->print_queue) {
                g_queue_free (priv->print_queue);
                priv->print_queue = NULL;
@@ -5027,7 +4944,7 @@ ev_window_key_press_event (GtkWidget   *widget,
                g_object_unref (priv->view);
        }
 
-       if (!handled && !ev_view_get_presentation (EV_VIEW (priv->view))) {
+       if (!handled && !EV_WINDOW_IS_PRESENTATION (ev_window)) {
                guint modifier = event->state & gtk_accelerator_get_default_mod_mask ();
 
                if (priv->menubar_accel_keyval != 0 &&