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
4 * Copyright (C) 2007 Johannes Buchner
7 * Johannes Buchner <buchner.johannes@gmx.at>
8 * Lukas Bezdicka <255993@mail.muni.cz>
10 * Evince is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * Evince is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 #include <glib/gi18n.h>
32 #include "ev-dualscreen.h"
33 #include "ev-window.h"
35 #include "ev-view-presentation.h"
37 #include "ev-sidebar.h"
38 #include "ev-sidebar-thumbnails.h"
40 struct _EvDSCWindowPrivate {
45 EvDocumentModel *model;
46 EvDocumentModel *notes_model;
47 EvDocument *presentation_document;
48 EvDocument *notes_document;
50 GtkWidget *presentation_window;
51 GtkWidget *overview_scrolled_window;
52 GtkWidget *notesview_scrolled_window;
54 EvViewPresentation *presentation_view;
55 gint moveback_monitor;
58 #define EV_DSCWINDOW_GET_PRIVATE(object) \
59 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_DSCWINDOW, EvDSCWindowPrivate))
60 #define PAGE_CACHE_SIZE 52428800 /* 50MB */
61 #define SIDEBAR_DEFAULT_SIZE 132
64 G_DEFINE_TYPE (EvDSCWindow, ev_dscwindow, GTK_TYPE_WINDOW)
67 * ev_dscwindow_switch_monitors: Bring the presentation window and the control window each on the other monitor.
69 * @widget: Callback widget
73 ev_dscwindow_switch_monitors (GtkWidget *widget, EvDSCWindow *ev_dscwindow)
76 if (!EV_IS_DSCWINDOW (ev_dscwindow))
79 gint num_monitors = get_num_monitors (GTK_WINDOW (ev_dscwindow));
81 if (num_monitors == 2) {
82 GtkWindow *presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window);
83 GdkScreen *screen = gtk_window_get_screen (presentation_window);
85 gint monitor_1 = gdk_screen_get_monitor_at_window (screen,
86 gtk_widget_get_window (GTK_WIDGET (presentation_window)));
88 gint monitor_2 = (monitor_1 + 1) % 2;
91 gdk_screen_get_monitor_geometry (screen, monitor_2, &coords);
92 gtk_window_move (presentation_window, coords.x, coords.y);
93 ev_dscwindow->priv->moveback_monitor = monitor_1;
95 gdk_screen_get_monitor_geometry (screen, monitor_1, &coords);
96 gtk_window_unmaximize (GTK_WINDOW (ev_dscwindow));
97 gtk_window_move (GTK_WINDOW (ev_dscwindow), coords.x, coords.y);
98 gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
104 * ev_dscwindow_notes_interaction: User wants to load a different file as notes.
107 ev_dscwindow_notes_interaction (GtkContainer *container, EvDSCWindow *self)
110 + EvDSCWindowPrivate *priv = EV_DSCWINDOW_GET_PRIVATE (self);
113 + dialog = gtk_file_chooser_dialog_new (
114 + _("Open Document"),
116 + GTK_FILE_CHOOSER_ACTION_OPEN,
117 + GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
118 + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
121 + ev_document_factory_add_filters (dialog, NULL);
122 + gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), FALSE);
123 + gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), TRUE);
125 + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
127 + char * uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
128 + GError * error = NULL;
129 + ev_view_set_loading (EV_VIEW (priv->notesview), TRUE);
131 + if (priv->notesdocument) {
132 + ev_document_load (priv->notesdocument, uri, &error);
134 + priv->notesdocument = ev_document_factory_get_document (uri,
138 + if (error == NULL){
139 + ev_view_set_document (EV_VIEW (priv->notesview),
140 + priv->notesdocument);
141 + /* TODO: go to the same page that is open at the moment, or
142 + * move the presentation to the beginning. *//*
145 + gtk_widget_destroy (dialog);
151 * ev_dscwindow_get_control: Get the control instance.
153 * If there is none, create one.
155 * Returns: control instance
158 ev_dscwindow_get_control (void)
160 static EvDSCWindow * control = NULL;
162 if (!control || !EV_IS_DSCWINDOW (control)) {
163 control = EV_DSCWINDOW (g_object_new (EV_TYPE_DSCWINDOW, NULL));
171 ev_dscwindow_window_placement (EvDSCWindow *ev_dscwindow)
173 gint num_monitors = get_num_monitors (GTK_WINDOW (ev_dscwindow));
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 if(page != ev_view_presentation_get_current_page (ev_dscwindow->priv->presentation_view))
201 ev_view_presentation_set_page (EV_VIEW_PRESENTATION(ev_dscwindow->priv->presentation_view), page);
204 ev_dscwindow_presentation_page_changed_cb (EvViewPresentation *pview,
206 EvDSCWindow *ev_dscwindow)
208 gint page = ev_view_presentation_get_current_page (pview);
209 ev_document_model_set_page (ev_dscwindow->priv->model, page);
213 ev_dscwindow_notes_clicked (GtkWidget *widget, GdkEvent *event,
216 if (!self || !EV_IS_DSCWINDOW (self) || !event)
218 gint page = ev_document_model_get_page (self->priv->model);
220 if (event->type == GDK_2BUTTON_PRESS && ((GdkEventButton *)event)->button == 1) {
221 ev_dscwindow_notes_interaction (NULL, self);
222 } else if (event->type == GDK_BUTTON_PRESS && ((GdkEventButton *)event)->button == 1) {
223 ev_document_model_set_page (self->priv->model, page+1);
224 } else if (event->type == GDK_BUTTON_PRESS && ((GdkEventButton *)event)->button == 3) {
225 ev_document_model_set_page (self->priv->model, page-1);
231 * ev_dscwindow_set_presentation: Set presentation document
232 * @presentation_window: Main window we can reuse for presentation
235 ev_dscwindow_set_presentation (EvDSCWindow *ev_dscwindow,
236 EvWindow *presentation_window, EvDocument *document, EvViewPresentation *pview)
238 if (!EV_IS_WINDOW (presentation_window))
241 ev_dscwindow->priv->presentation_window = GTK_WIDGET(presentation_window);
242 ev_dscwindow->priv->presentation_document = document;
243 ev_dscwindow->priv->presentation_view = EV_VIEW_PRESENTATION(pview);
244 ev_document_model_set_document(ev_dscwindow->priv->model,
246 g_signal_connect_swapped (ev_dscwindow->priv->presentation_view,
248 G_CALLBACK (gtk_widget_destroy),
250 g_signal_connect (G_OBJECT(ev_dscwindow->priv->presentation_view),
252 G_CALLBACK (ev_dscwindow_presentation_page_changed_cb),
254 ev_dscwindow_window_placement (ev_dscwindow);
258 * ev_dscwindow_end: Destroy control window but keep presentation
261 ev_dscwindow_end (GtkWidget *widget, GdkEvent *event)
263 gtk_widget_destroy (GTK_WIDGET (ev_dscwindow_get_control ()));
268 * ev_dscwindow_init: Initialize multihead presentation
270 * @ev_dscwindow: EvDSCWindow.
272 * ev_dscwindow_set_presentation has to be called afterwards for loading in a document. TBD
275 ev_dscwindow_init (EvDSCWindow *ev_dscwindow)
277 ev_dscwindow->priv = EV_DSCWINDOW_GET_PRIVATE (ev_dscwindow);
278 ev_dscwindow->priv->moveback_monitor = -1;
279 ev_dscwindow->priv->notes_document = NULL;
281 gtk_window_set_title (GTK_WINDOW (ev_dscwindow), _("Presentation Control"));
283 GtkWidget *h = gtk_hpaned_new ();
284 GtkWidget *v = gtk_vbox_new (FALSE, 0);
286 ev_dscwindow->priv->model = ev_document_model_new ();
287 g_signal_connect (G_OBJECT(ev_dscwindow->priv->model),
289 G_CALLBACK (ev_dscwindow_page_changed_cb),
291 ev_dscwindow->priv->sidebar = ev_sidebar_new ();
292 ev_sidebar_set_model (EV_SIDEBAR (ev_dscwindow->priv->sidebar),
293 ev_dscwindow->priv->model);
294 gtk_box_pack_start (GTK_BOX (v), ev_dscwindow->priv->sidebar, TRUE , TRUE, 0);
295 gtk_widget_show (ev_dscwindow->priv->sidebar);
297 GtkWidget *sidebar_widget;
298 sidebar_widget = ev_sidebar_thumbnails_new ();
300 gtk_widget_show (sidebar_widget);
301 ev_sidebar_add_page (EV_SIDEBAR (ev_dscwindow->priv->sidebar),
304 ev_document_model_set_continuous (ev_dscwindow->priv->model, FALSE);
305 ev_document_model_set_dual_page (ev_dscwindow->priv->model, FALSE);
306 ev_document_model_set_sizing_mode (ev_dscwindow->priv->model, EV_SIZING_BEST_FIT);
308 GtkWidget *e = gtk_expander_new (_("Expensive features"));
309 gtk_expander_set_expanded (GTK_EXPANDER (e), TRUE);
311 GtkWidget *t = gtk_toolbar_new ();
313 GtkToolItem* b_switch = gtk_tool_button_new (NULL, _("Switch monitors"));
314 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_switch), "object-flip-horizontal");
315 gtk_toolbar_insert (GTK_TOOLBAR (t), b_switch, -1);
316 g_signal_connect (b_switch, "clicked",
317 G_CALLBACK (ev_dscwindow_switch_monitors), ev_dscwindow);
319 GtkToolItem* b_notes = gtk_tool_button_new (NULL, _("Load notes ..."));
320 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_notes), "object-flip-horizontal");
321 gtk_toolbar_insert (GTK_TOOLBAR (t), b_notes, -1);
322 g_signal_connect (b_notes, "clicked",
323 G_CALLBACK (ev_dscwindow_notes_interaction), ev_dscwindow);
325 GtkToolItem* b_close = gtk_tool_button_new (NULL, _("End presentation"));
326 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_close), "view-restore");
327 gtk_toolbar_insert (GTK_TOOLBAR (t), b_close, -1);
328 /*TODO: rework close*/
329 g_signal_connect (b_close, "clicked",
330 G_CALLBACK (ev_dscwindow_end), NULL);
332 gtk_container_add (GTK_CONTAINER (e), t);
333 gtk_box_pack_end (GTK_BOX (v), e, FALSE, TRUE, 0);
334 gtk_paned_add1 (GTK_PANED (h), v);
336 ev_dscwindow->priv->notesview_scrolled_window = GTK_WIDGET (g_object_new (
337 GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, NULL));
338 gtk_paned_add2 (GTK_PANED (h), ev_dscwindow->priv->notesview_scrolled_window);
340 ev_dscwindow->priv->notesview = ev_view_new ();
341 g_object_ref (ev_dscwindow->priv->notesview);
342 gtk_container_add (GTK_CONTAINER (ev_dscwindow->priv->notesview_scrolled_window),
343 ev_dscwindow->priv->notesview);
344 ev_view_set_model (EV_VIEW (ev_dscwindow->priv->notesview), ev_dscwindow->priv->model);
345 gtk_widget_show_all (h);
346 gtk_container_add (GTK_CONTAINER (ev_dscwindow), h);
348 gtk_drag_dest_unset (GTK_WIDGET (ev_dscwindow->priv->notesview));
349 gtk_drag_dest_unset (GTK_WIDGET (ev_dscwindow->priv->sidebar));
351 gint click = GDK_BUTTON1_MOTION_MASK | GDK_KEY_PRESS_MASK;
352 gtk_widget_add_events (GTK_WIDGET (ev_dscwindow->priv->sidebar), click);
354 g_signal_connect (ev_dscwindow->priv->notesview, "button-press-event",
355 G_CALLBACK (ev_dscwindow_notes_clicked), ev_dscwindow);
360 ev_dscwindow_dispose (GObject *obj)
362 EvDSCWindow * ev_dscwindow = EV_DSCWINDOW (obj);
363 EvDSCWindowPrivate *priv = ev_dscwindow->priv;
365 if (priv->moveback_monitor >= 0) {
366 GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
369 gdk_screen_get_monitor_geometry (
370 gtk_window_get_screen (presentation_window),
371 priv->moveback_monitor, &coords);
373 gtk_window_move (presentation_window, coords.x, coords.y);
375 ev_window_stop_presentation (EV_WINDOW(priv->presentation_window), TRUE);
376 /*if (priv->overview) {
377 g_object_unref (priv->overview);
378 priv->overview = NULL;
382 G_OBJECT_CLASS (ev_dscwindow_parent_class)->dispose (obj);
386 ev_dscwindow_class_init (EvDSCWindowClass *ev_dscwindow_class)
388 GObjectClass *g_object_class = G_OBJECT_CLASS (ev_dscwindow_class);
389 g_type_class_add_private (g_object_class, sizeof (EvDSCWindowPrivate));
390 g_object_class->dispose = ev_dscwindow_dispose;
394 ev_dscwindow_new (void)
396 EvDSCWindow *ev_dscwindow;
398 ev_dscwindow = g_object_new (EV_TYPE_DSCWINDOW, "type", GTK_WINDOW_TOPLEVEL, NULL);
399 return GTK_WIDGET (ev_dscwindow);