]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-dualscreen.c
[dualscreen] [presentation] make presentation control dscwindow, presentation ->...
[evince.git] / shell / ev-dualscreen.c
index 8fc6953a2c5a4d55b6244792fe31588fecdf42da..fdec315fe016aa5610a40df1a2486bf91c4a1a9c 100644 (file)
 #include "ev-dualscreen.h"
 #include "ev-window.h"
 #include "ev-view.h"
+#include "ev-view-presentation.h"
+#include "ev-utils.h"
+#include "ev-sidebar.h"
+#include "ev-sidebar-thumbnails.h"
 
 struct _EvDSCWindowPrivate {
        GtkWidget *main_box;
@@ -38,8 +42,9 @@ struct _EvDSCWindowPrivate {
 
        GtkWidget *overview_scrolled_window;
        GtkWidget *notesview_scrolled_window;
+       GtkWidget *presentation_window;
 
-       EvWindow *presentation_window;
+       EvViewPresentation *presentation_view;
        EvDocument * presentation_document;
        gint moveback_monitor;
 };
@@ -47,6 +52,7 @@ struct _EvDSCWindowPrivate {
 #define EV_DSCWINDOW_GET_PRIVATE(object) \
        (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_DSCWINDOW, EvDSCWindowPrivate))
 #define PAGE_CACHE_SIZE 52428800 /* 50MB */
+#define SIDEBAR_DEFAULT_SIZE    132
 
 /*static gpointer parent_class = NULL;*/
 
@@ -159,6 +165,72 @@ ev_dscwindow_get_control (void)
        return control;
 }
 
+/*TODO: Fix me!*/
+static void
+ev_dscwindow_window_placement (EvDSCWindow *ev_dscwindow)
+{
+       gint num_monitors = get_num_monitors (GTK_WINDOW (ev_dscwindow));
+       //if (num_monitors == 2) {
+               GtkWindow * presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window);
+               GdkScreen * screen = gtk_window_get_screen (presentation_window);
+               gint work_monitor = gdk_screen_get_monitor_at_window (screen,
+                       gtk_widget_get_window (GTK_WIDGET (presentation_window)));
+               gint presentation_monitor = (work_monitor + 1) % 2;
+               GdkRectangle coords;
+               gdk_screen_get_monitor_geometry (screen, presentation_monitor,
+                       &coords);
+
+               gtk_window_move (presentation_window, coords.x, coords.y);
+               //ev_window_run_presentation (ev_dscwindow->priv->presentation_window);
+               ev_dscwindow->priv->moveback_monitor = work_monitor;
+               gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
+       //}
+}
+/**
+ * ev_dscwindow_page_changed_cb: Callback to change page on all views
+ *
+ **/
+static void
+ev_dscwindow_page_changed_cb (EvDocumentModel *model,
+                          GParamSpec      *pspec,
+                          EvDSCWindow     *ev_dscwindow)
+{
+       gint page = ev_document_model_get_page (model);
+       if(page != ev_view_presentation_get_current_page (ev_dscwindow->priv->presentation_view))
+               ev_view_presentation_set_page (EV_VIEW_PRESENTATION(ev_dscwindow->priv->presentation_view), page);
+}
+static void
+ev_dscwindow_presentation_page_changed_cb (EvViewPresentation *pview,
+                          GParamSpec      *pspec,
+                          EvDSCWindow     *ev_dscwindow)
+{
+       gint page = ev_view_presentation_get_current_page (pview);
+       ev_document_model_set_page (ev_dscwindow->priv->model, page);
+}
+
+/**
+ * ev_dscwindow_set_presentation: Set presentation document
+ * @presentation_window: Main window we can reuse for presentation
+ **/
+void
+ev_dscwindow_set_presentation (EvDSCWindow *ev_dscwindow,
+       EvWindow *presentation_window, EvDocument *document, EvViewPresentation *pview)
+{
+       if (!EV_IS_WINDOW (presentation_window))
+               return;
+
+       ev_dscwindow->priv->presentation_window = GTK_WIDGET(presentation_window);
+       ev_dscwindow->priv->presentation_document = document;
+       ev_dscwindow->priv->presentation_view = EV_VIEW_PRESENTATION(pview);
+       ev_document_model_set_document(ev_dscwindow->priv->model,
+               document);
+       g_signal_connect (G_OBJECT(ev_dscwindow->priv->presentation_view),
+                         "notify::page",
+                         G_CALLBACK (ev_dscwindow_presentation_page_changed_cb),
+                         ev_dscwindow);
+       ev_dscwindow_window_placement (ev_dscwindow);
+}
+
 /**
  * ev_dscwindow_end: Stop presentation mode.
  */
@@ -169,12 +241,10 @@ ev_dscwindow_end (GtkWidget *widget, GdkEvent *event)
        return TRUE;
 }
 
-
-
 /**
 * ev_dscwindow_init: Initialize multihead presentation
 *
-* @self: EvDSCWindow.
+* @ev_dscwindow: EvDSCWindow.
 *
 * ev_dscwindow_set_presentation has to be called afterwards for loading in a document. TBD
 **/
@@ -190,23 +260,41 @@ ev_dscwindow_init (EvDSCWindow *ev_dscwindow)
        GtkWidget *h = gtk_hpaned_new ();
        GtkWidget *v = gtk_vbox_new (FALSE, 0);
 
-       ev_dscwindow->priv->overview_scrolled_window = GTK_WIDGET (g_object_new (
+       ev_dscwindow->priv->model = ev_document_model_new ();
+       g_signal_connect (G_OBJECT(ev_dscwindow->priv->model),
+                         "notify::page",
+                         G_CALLBACK (ev_dscwindow_page_changed_cb),
+                         ev_dscwindow);
+       ev_dscwindow->priv->overview = ev_sidebar_new ();
+       ev_sidebar_set_model (EV_SIDEBAR (ev_dscwindow->priv->overview),
+                             ev_dscwindow->priv->model);
+       gtk_box_pack_start (GTK_BOX (v), ev_dscwindow->priv->overview, TRUE , TRUE, 0);
+       gtk_widget_show (ev_dscwindow->priv->overview);
+
+       GtkWidget *sidebar_widget;
+       sidebar_widget = ev_sidebar_thumbnails_new ();
+       /*g_signal_connect (sidebar_widget,
+                         "notify::main-widget",
+                         G_CALLBACK (sidebar_page_main_widget_update_cb),
+                         ev_window);
+       sidebar_page_main_widget_update_cb (G_OBJECT (sidebar_widget), NULL, ev_window);*/
+       gtk_widget_show (sidebar_widget);
+       ev_sidebar_add_page (EV_SIDEBAR (ev_dscwindow->priv->overview),
+                            sidebar_widget);
+
+/*     ev_dscwindow->priv->overview_scrolled_window = GTK_WIDGET (g_object_new (
                        GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, NULL));
-       gtk_box_pack_start_defaults (GTK_BOX (v), ev_dscwindow->priv->overview_scrolled_window);
+       gtk_box_pack_start (GTK_BOX (v), ev_dscwindow->priv->overview_scrolled_window, TRUE, TRUE, 0);
+
 
-       ev_dscwindow->priv->model = ev_document_model_new ();
        ev_dscwindow->priv->overview = ev_view_new ();
        ev_view_set_page_cache_size (EV_VIEW (ev_dscwindow->priv->overview), PAGE_CACHE_SIZE);
-       ev_view_set_model (EV_VIEW (ev_dscwindow->priv->overview), ev_dscwindow->priv->model);
+       ev_view_set_model (EV_VIEW (ev_dscwindow->priv->overview), ev_dscwindow->priv->model);*/
+
        ev_document_model_set_continuous (ev_dscwindow->priv->model, TRUE);
        ev_document_model_set_dual_page (ev_dscwindow->priv->model, FALSE);
        ev_document_model_set_sizing_mode (ev_dscwindow->priv->model, EV_SIZING_BEST_FIT);
 
-
-       gtk_container_add (GTK_CONTAINER (priv->overview_scrolled_window),
-                                  priv->overview);
-
-
        GtkWidget *e = gtk_expander_new (_("Expensive features"));
        gtk_expander_set_expanded (GTK_EXPANDER (e), TRUE);
 
@@ -216,13 +304,13 @@ ev_dscwindow_init (EvDSCWindow *ev_dscwindow)
        gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_switch), "object-flip-horizontal");
        gtk_toolbar_insert (GTK_TOOLBAR (t), b_switch, -1);
        g_signal_connect (b_switch, "clicked",
-               G_CALLBACK (ev_dscwindow_switch_monitors), self);
+               G_CALLBACK (ev_dscwindow_switch_monitors), ev_dscwindow);
 
        GtkToolItem* b_notes = gtk_tool_button_new (NULL, _("Load notes ..."));
        gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_notes), "object-flip-horizontal");
        gtk_toolbar_insert (GTK_TOOLBAR (t), b_notes, -1);
        g_signal_connect (b_notes, "clicked",
-               G_CALLBACK (ev_dscwindow_notes_interaction), self);
+               G_CALLBACK (ev_dscwindow_notes_interaction), ev_dscwindow);
 
        GtkToolItem* b_close = gtk_tool_button_new (NULL, _("End presentation"));
        gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_close), "view-restore");
@@ -234,35 +322,21 @@ ev_dscwindow_init (EvDSCWindow *ev_dscwindow)
        gtk_box_pack_end (GTK_BOX (v), e, FALSE, TRUE, 0);
        gtk_paned_add1 (GTK_PANED (h), v);
 
-/*
-       priv->notesview_scrolled_window = GTK_WIDGET (g_object_new (
+       ev_dscwindow->priv->notesview_scrolled_window = GTK_WIDGET (g_object_new (
                GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, NULL));
-       gtk_paned_add2 (GTK_PANED (h), priv->notesview_scrolled_window);
-
-       priv->notesview = ev_view_new ();
-       g_object_ref (priv->notesview);
-       ev_view_set_screen_dpi (EV_VIEW (priv->notesview),
-                               get_screen_dpi (GTK_WINDOW (self)));
-+              gtk_container_add (GTK_CONTAINER (priv->notesview_scrolled_window),
-+                                 priv->notesview);
-+
-+              ev_view_set_continuous (EV_VIEW (priv->notesview), FALSE);
-+              ev_view_set_dual_page (EV_VIEW (priv->notesview), FALSE);
-+              ev_view_set_sizing_mode (EV_VIEW (priv->notesview), EV_SIZING_BEST_FIT);
-+      }
-+
-+      gtk_paned_set_position (GTK_PANED (h), 400);
-+      gtk_widget_show_all (h);
-+      gtk_container_add (GTK_CONTAINER (self), h);
-+
-+      /* fallback if we have >2 monitors (see window placement) */
+       gtk_paned_add2 (GTK_PANED (h), ev_dscwindow->priv->notesview_scrolled_window);
+
+       ev_dscwindow->priv->notesview = ev_view_new ();
+       g_object_ref (ev_dscwindow->priv->notesview);
+       gtk_container_add (GTK_CONTAINER (ev_dscwindow->priv->notesview_scrolled_window),
+               ev_dscwindow->priv->notesview);
+       ev_view_set_model (EV_VIEW (ev_dscwindow->priv->notesview), ev_dscwindow->priv->model);
+       gtk_widget_show_all (h);
+       gtk_container_add (GTK_CONTAINER (ev_dscwindow), h);
+
+/* fallback if we have >2 monitors (see window placement) */
 /*+    gtk_window_set_default_size (GTK_WINDOW (self), 800, 600);
 +
-+      g_signal_connect (h, "notify::position",
-+              G_CALLBACK (ev_dscwindow_handle_resized), self);
-+
-+      g_signal_connect (self, "size-allocate",
-+              G_CALLBACK (ev_dscwindow_handle_resized), self);
 +
 +      /* This would just open new windows. */
 /*+    gtk_drag_dest_unset (GTK_WIDGET (priv->notesview));
@@ -282,17 +356,18 @@ ev_dscwindow_dispose (GObject *obj)
        EvDSCWindow * ev_dscwindow = EV_DSCWINDOW (obj);
        EvDSCWindowPrivate *priv = ev_dscwindow->priv;
 
-/*     if (EV_IS_VIEW (priv->overview) {
-               ev_document_model_set_document (priv->model, NULL);
+//     if (EV_IS_VIEW (priv->overview) {
+//             ev_document_model_set_document (priv->model, NULL);
 
-+              ev_view_set_document (EV_VIEW (priv->overview),  NULL);
-+              g_object_unref (priv->overview);
-+      }
-+      if (EV_IS_VIEW (priv->notesview)) {
-+              ev_view_set_document (EV_VIEW (priv->notesview), NULL);
-+              g_object_unref (priv->notesview);
-+      }*/
-       ev_window_stop_presentation (priv->presentation_window);
+//             ev_view_set_document (EV_VIEW (priv->overview),  NULL);
+//             g_object_unref (priv->overview);
+//     }
+//     if (EV_IS_VIEW (priv->notesview)) {
+//             ev_view_set_document (EV_VIEW (priv->notesview), NULL);
+//             g_object_unref (priv->notesview);
+//     }
+/*TODO: save fulscreen state*/
+       ev_window_stop_presentation (EV_WINDOW(priv->presentation_window), 0);
 
        if (priv->moveback_monitor >= 0) {
                GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
@@ -305,24 +380,23 @@ ev_dscwindow_dispose (GObject *obj)
                gtk_window_move (presentation_window, coords.x, coords.y);
        }
 
-       G_OBJECT_CLASS (parent_class)->dispose (obj);
+       G_OBJECT_CLASS (ev_dscwindow_parent_class)->dispose (obj);
 }
 
-
 static void
-ev_dscwindow_class_init (EvDSCWindowClass * klass)
+ev_dscwindow_class_init (EvDSCWindowClass *ev_dscwindow_class)
 {
-       GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
-       parent_class = g_type_class_peek_parent (klass);
-       g_type_class_add_private (klass, sizeof (EvDSCWindowPrivate));
+       GObjectClass *g_object_class = G_OBJECT_CLASS (ev_dscwindow_class);
+       /*parent_class = g_type_class_peek_parent (ev_dscwindow_class);*/
+       g_type_class_add_private (g_object_class, sizeof (EvDSCWindowPrivate));
        g_object_class->dispose  = ev_dscwindow_dispose;
 }
 
 GtkWidget *
 ev_dscwindow_new (void)
 {
-       EvDSCWindow *dsc_window;
+       EvDSCWindow *ev_dscwindow;
 
-       dsc_window = g_object_new (EV_TYPE_DSCWINDOW, "type", GTK_WINDOW_TOPLEVEL, NULL);
-       return GTK_WIDGET (dsc_window);
+       ev_dscwindow = g_object_new (EV_TYPE_DSCWINDOW, "type", GTK_WINDOW_TOPLEVEL, NULL);
+       return GTK_WIDGET (ev_dscwindow);
 }