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
5 * Evince is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * Evince is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include <glib/gi18n.h>
27 #include "ev-dualscreen.h"
28 #include "ev-window.h"
30 #include "ev-view-presentation.h"
32 #include "ev-sidebar.h"
33 #include "ev-sidebar-thumbnails.h"
35 struct _EvDSCWindowPrivate {
40 EvDocumentModel *model;
41 EvDocument * notesdocument;
43 GtkWidget *overview_scrolled_window;
44 GtkWidget *notesview_scrolled_window;
45 GtkWidget *presentation_window;
47 EvViewPresentation *presentation_view;
48 EvDocument * presentation_document;
49 gint moveback_monitor;
52 #define EV_DSCWINDOW_GET_PRIVATE(object) \
53 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_DSCWINDOW, EvDSCWindowPrivate))
54 #define PAGE_CACHE_SIZE 52428800 /* 50MB */
55 #define SIDEBAR_DEFAULT_SIZE 132
57 /*static gpointer parent_class = NULL;*/
59 G_DEFINE_TYPE (EvDSCWindow, ev_dscwindow, GTK_TYPE_WINDOW)
62 * ev_dscwindow_switch_monitors: Bring the presentation window and the control window each on the other monitor.
64 * @widget: Callback widget
68 ev_dscwindow_switch_monitors (GtkWidget *widget, EvDSCWindow *self)
71 + if (!EV_IS_DSCWINDOW (self))
74 + EvDSCWindowPrivate *priv = EV_DSCWINDOW_GET_PRIVATE (self);
76 + gint num_monitors = get_num_monitors (GTK_WINDOW (self));
78 + if (num_monitors == 2) {
79 + GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
80 + GdkScreen * screen = gtk_window_get_screen (presentation_window);
82 + gint monitor_1 = gdk_screen_get_monitor_at_window (screen,
83 + GTK_WIDGET (presentation_window)->window);
85 + gint monitor_2 = (monitor_1 + 1) % 2;
87 + GdkRectangle coords;
88 + gdk_screen_get_monitor_geometry (screen, monitor_2, &coords);
89 + ev_window_stop_presentation (priv->presentation_window);
90 + gtk_window_move (presentation_window, coords.x, coords.y);
91 + ev_window_run_presentation (priv->presentation_window);
92 + priv->moveback_monitor = monitor_1;
94 + gdk_screen_get_monitor_geometry (screen, monitor_1, &coords);
95 + gtk_window_unmaximize (GTK_WINDOW (self));
96 + gtk_window_move (GTK_WINDOW (self), coords.x, coords.y);
97 + gtk_window_maximize (GTK_WINDOW (self));
103 * ev_dscwindow_notes_interaction: User wants to load a different file as notes.
106 ev_dscwindow_notes_interaction (GtkContainer *container, EvDSCWindow *self)
109 + EvDSCWindowPrivate *priv = EV_DSCWINDOW_GET_PRIVATE (self);
112 + dialog = gtk_file_chooser_dialog_new (
113 + _("Open Document"),
115 + GTK_FILE_CHOOSER_ACTION_OPEN,
116 + GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
117 + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
120 + ev_document_factory_add_filters (dialog, NULL);
121 + gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), FALSE);
122 + gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), TRUE);
124 + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
126 + char * uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
127 + GError * error = NULL;
128 + ev_view_set_loading (EV_VIEW (priv->notesview), TRUE);
130 + if (priv->notesdocument) {
131 + ev_document_load (priv->notesdocument, uri, &error);
133 + priv->notesdocument = ev_document_factory_get_document (uri,
137 + if (error == NULL){
138 + ev_view_set_document (EV_VIEW (priv->notesview),
139 + priv->notesdocument);
140 + /* TODO: go to the same page that is open at the moment, or
141 + * move the presentation to the beginning. *//*
144 + gtk_widget_destroy (dialog);
150 * ev_dscwindow_get_control: Get the control instance.
152 * If there is none, create one.
154 * Returns: control instance
157 ev_dscwindow_get_control (void)
159 static EvDSCWindow * control = NULL;
161 if (!control || !EV_IS_DSCWINDOW (control)) {
162 control = EV_DSCWINDOW (g_object_new (EV_TYPE_DSCWINDOW, NULL));
170 ev_dscwindow_window_placement (EvDSCWindow *ev_dscwindow)
172 gint num_monitors = get_num_monitors (GTK_WINDOW (ev_dscwindow));
173 g_printf ("num_monitors: %d \n",num_monitors);
174 //if (num_monitors == 2) {
175 GtkWindow * presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window);
176 GdkScreen * screen = gtk_window_get_screen (presentation_window);
177 gint work_monitor = gdk_screen_get_monitor_at_window (screen,
178 gtk_widget_get_window (GTK_WIDGET (presentation_window)));
179 gint presentation_monitor = (work_monitor + 1) % 2;
181 gdk_screen_get_monitor_geometry (screen, presentation_monitor,
184 gtk_window_move (presentation_window, coords.x, coords.y);
185 //ev_window_run_presentation (ev_dscwindow->priv->presentation_window);
186 ev_dscwindow->priv->moveback_monitor = work_monitor;
187 gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
191 * ev_dscwindow_page_changed_cb: Callback to change page on all views
195 ev_dscwindow_page_changed_cb (EvDocumentModel *model,
197 EvDSCWindow *ev_dscwindow)
199 gint page = ev_document_model_get_page (model);
200 g_printf("m_page:%d\n",page);
201 if(page != ev_view_presentation_get_current_page (ev_dscwindow->priv->presentation_view))
202 ev_view_presentation_set_page (EV_VIEW_PRESENTATION(ev_dscwindow->priv->presentation_view), page);
205 ev_dscwindow_presentation_page_changed_cb (EvViewPresentation *pview,
207 EvDSCWindow *ev_dscwindow)
209 gint page = ev_view_presentation_get_current_page (pview);
210 g_printf("p_page:%d\n",page);
211 ev_document_model_set_page (ev_dscwindow->priv->model, page);
215 * ev_dscwindow_set_presentation: Set presentation document
216 * @presentation_window: Main window we can reuse for presentation
219 ev_dscwindow_set_presentation (EvDSCWindow *ev_dscwindow,
220 EvWindow *presentation_window, EvDocument *document, EvViewPresentation *pview)
222 if (!EV_IS_WINDOW (presentation_window))
225 ev_dscwindow->priv->presentation_window = GTK_WIDGET(presentation_window);
226 ev_dscwindow->priv->presentation_document = document;
227 ev_dscwindow->priv->presentation_view = EV_VIEW_PRESENTATION(pview);
228 ev_document_model_set_document(ev_dscwindow->priv->model,
230 g_signal_connect (ev_dscwindow->priv->presentation_view,
231 "notify::current_page",
232 G_CALLBACK (ev_dscwindow_presentation_page_changed_cb),
234 ev_dscwindow_window_placement (ev_dscwindow);
238 * ev_dscwindow_end: Stop presentation mode.
241 ev_dscwindow_end (GtkWidget *widget, GdkEvent *event)
243 gtk_widget_destroy (GTK_WIDGET (ev_dscwindow_get_control ()));
248 * ev_dscwindow_init: Initialize multihead presentation
250 * @ev_dscwindow: EvDSCWindow.
252 * ev_dscwindow_set_presentation has to be called afterwards for loading in a document. TBD
255 ev_dscwindow_init (EvDSCWindow *ev_dscwindow)
257 ev_dscwindow->priv = EV_DSCWINDOW_GET_PRIVATE (ev_dscwindow);
258 ev_dscwindow->priv->moveback_monitor = -1;
259 ev_dscwindow->priv->notesdocument = NULL;
261 gtk_window_set_title (GTK_WINDOW (ev_dscwindow), _("Presentation Control"));
263 GtkWidget *h = gtk_hpaned_new ();
264 GtkWidget *v = gtk_vbox_new (FALSE, 0);
266 ev_dscwindow->priv->model = ev_document_model_new ();
267 g_signal_connect (ev_dscwindow->priv->model,
269 G_CALLBACK (ev_dscwindow_page_changed_cb),
271 ev_dscwindow->priv->overview = ev_sidebar_new ();
272 ev_sidebar_set_model (EV_SIDEBAR (ev_dscwindow->priv->overview),
273 ev_dscwindow->priv->model);
274 gtk_box_pack_start (GTK_BOX (v), ev_dscwindow->priv->overview, TRUE , TRUE, 0);
275 gtk_widget_show (ev_dscwindow->priv->overview);
277 GtkWidget *sidebar_widget;
278 sidebar_widget = ev_sidebar_thumbnails_new ();
279 /*g_signal_connect (sidebar_widget,
280 "notify::main-widget",
281 G_CALLBACK (sidebar_page_main_widget_update_cb),
283 sidebar_page_main_widget_update_cb (G_OBJECT (sidebar_widget), NULL, ev_window);*/
284 gtk_widget_show (sidebar_widget);
285 ev_sidebar_add_page (EV_SIDEBAR (ev_dscwindow->priv->overview),
288 /* ev_dscwindow->priv->overview_scrolled_window = GTK_WIDGET (g_object_new (
289 GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, NULL));
290 gtk_box_pack_start (GTK_BOX (v), ev_dscwindow->priv->overview_scrolled_window, TRUE, TRUE, 0);
293 ev_dscwindow->priv->overview = ev_view_new ();
294 ev_view_set_page_cache_size (EV_VIEW (ev_dscwindow->priv->overview), PAGE_CACHE_SIZE);
295 ev_view_set_model (EV_VIEW (ev_dscwindow->priv->overview), ev_dscwindow->priv->model);*/
297 ev_document_model_set_continuous (ev_dscwindow->priv->model, TRUE);
298 ev_document_model_set_dual_page (ev_dscwindow->priv->model, FALSE);
299 ev_document_model_set_sizing_mode (ev_dscwindow->priv->model, EV_SIZING_BEST_FIT);
301 GtkWidget *e = gtk_expander_new (_("Expensive features"));
302 gtk_expander_set_expanded (GTK_EXPANDER (e), TRUE);
304 GtkWidget *t = gtk_toolbar_new ();
306 GtkToolItem* b_switch = gtk_tool_button_new (NULL, _("Switch monitors"));
307 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_switch), "object-flip-horizontal");
308 gtk_toolbar_insert (GTK_TOOLBAR (t), b_switch, -1);
309 g_signal_connect (b_switch, "clicked",
310 G_CALLBACK (ev_dscwindow_switch_monitors), ev_dscwindow);
312 GtkToolItem* b_notes = gtk_tool_button_new (NULL, _("Load notes ..."));
313 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_notes), "object-flip-horizontal");
314 gtk_toolbar_insert (GTK_TOOLBAR (t), b_notes, -1);
315 g_signal_connect (b_notes, "clicked",
316 G_CALLBACK (ev_dscwindow_notes_interaction), ev_dscwindow);
318 GtkToolItem* b_close = gtk_tool_button_new (NULL, _("End presentation"));
319 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_close), "view-restore");
320 gtk_toolbar_insert (GTK_TOOLBAR (t), b_close, -1);
321 g_signal_connect (b_close, "clicked",
322 G_CALLBACK (ev_dscwindow_end), NULL);
324 gtk_container_add (GTK_CONTAINER (e), t);
325 gtk_box_pack_end (GTK_BOX (v), e, FALSE, TRUE, 0);
326 gtk_paned_add1 (GTK_PANED (h), v);
328 ev_dscwindow->priv->notesview_scrolled_window = GTK_WIDGET (g_object_new (
329 GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, NULL));
330 gtk_paned_add2 (GTK_PANED (h), ev_dscwindow->priv->notesview_scrolled_window);
332 ev_dscwindow->priv->notesview = ev_view_new ();
333 g_object_ref (ev_dscwindow->priv->notesview);
334 gtk_container_add (GTK_CONTAINER (ev_dscwindow->priv->notesview_scrolled_window),
335 ev_dscwindow->priv->notesview);
336 ev_view_set_model (EV_VIEW (ev_dscwindow->priv->notesview), ev_dscwindow->priv->model);
337 gtk_widget_show_all (h);
338 gtk_container_add (GTK_CONTAINER (ev_dscwindow), h);
340 /* fallback if we have >2 monitors (see window placement) */
341 /*+ gtk_window_set_default_size (GTK_WINDOW (self), 800, 600);
344 + /* This would just open new windows. */
345 /*+ gtk_drag_dest_unset (GTK_WIDGET (priv->notesview));
346 + gtk_drag_dest_unset (GTK_WIDGET (priv->overview));
348 + gint click = GDK_BUTTON1_MOTION_MASK | GDK_KEY_PRESS_MASK;
349 + gtk_widget_add_events (GTK_WIDGET (priv->overview), click);
350 + g_signal_connect (priv->notesview, "button-press-event",
351 + G_CALLBACK (ev_dscwindow_notes_clicked), self);
357 ev_dscwindow_dispose (GObject *obj)
359 EvDSCWindow * ev_dscwindow = EV_DSCWINDOW (obj);
360 EvDSCWindowPrivate *priv = ev_dscwindow->priv;
362 // if (EV_IS_VIEW (priv->overview) {
363 // ev_document_model_set_document (priv->model, NULL);
365 // ev_view_set_document (EV_VIEW (priv->overview), NULL);
366 // g_object_unref (priv->overview);
368 // if (EV_IS_VIEW (priv->notesview)) {
369 // ev_view_set_document (EV_VIEW (priv->notesview), NULL);
370 // g_object_unref (priv->notesview);
372 /*TODO: save fulscreen state*/
373 ev_window_stop_presentation (EV_WINDOW(priv->presentation_window), 0);
375 if (priv->moveback_monitor >= 0) {
376 GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
379 gdk_screen_get_monitor_geometry (
380 gtk_window_get_screen (presentation_window),
381 priv->moveback_monitor, &coords);
383 gtk_window_move (presentation_window, coords.x, coords.y);
386 G_OBJECT_CLASS (ev_dscwindow_parent_class)->dispose (obj);
390 ev_dscwindow_class_init (EvDSCWindowClass *ev_dscwindow_class)
392 GObjectClass *g_object_class = G_OBJECT_CLASS (ev_dscwindow_class);
393 /*parent_class = g_type_class_peek_parent (ev_dscwindow_class);*/
394 g_type_class_add_private (g_object_class, sizeof (EvDSCWindowPrivate));
395 g_object_class->dispose = ev_dscwindow_dispose;
399 ev_dscwindow_new (void)
401 EvDSCWindow *ev_dscwindow;
403 ev_dscwindow = g_object_new (EV_TYPE_DSCWINDOW, "type", GTK_WINDOW_TOPLEVEL, NULL);
404 return GTK_WIDGET (ev_dscwindow);