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_page_changed_cb: Callback to change page on all views
108 ev_dscwindow_page_changed_cb (EvDocumentModel *model,
110 EvDSCWindow *ev_dscwindow)
112 gint page = ev_document_model_get_page (model);
113 if(page != ev_view_presentation_get_current_page (ev_dscwindow->priv->presentation_view)) {
114 ev_view_presentation_set_page (EV_VIEW_PRESENTATION(ev_dscwindow->priv->presentation_view), page);
115 if( ev_document_model_get_page (ev_dscwindow->priv->model) != page)
116 ev_document_model_set_page(ev_dscwindow->priv->model, page);
117 if( ev_document_model_get_page (ev_dscwindow->priv->notes_model) != page)
118 ev_document_model_set_page(ev_dscwindow->priv->notes_model, page);
122 ev_dscwindow_presentation_page_changed_cb (EvViewPresentation *pview,
124 EvDSCWindow *ev_dscwindow)
126 gint page = ev_view_presentation_get_current_page (pview);
127 if( ev_document_model_get_page (ev_dscwindow->priv->model) != page)
128 ev_document_model_set_page(ev_dscwindow->priv->model, page);
129 if( ev_document_model_get_page (ev_dscwindow->priv->notes_model) != page)
130 ev_document_model_set_page(ev_dscwindow->priv->notes_model, page);
134 * ev_dscwindow_notes_interaction: User wants to load a different file as notes.
137 ev_dscwindow_notes_interaction (GtkContainer *container, EvDSCWindow *ev_dscwindow)
141 dialog = gtk_file_chooser_dialog_new (
143 GTK_WINDOW (ev_dscwindow),
144 GTK_FILE_CHOOSER_ACTION_OPEN,
145 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
146 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
149 ev_document_factory_add_filters (dialog, NULL);
150 gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), FALSE);
151 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), TRUE);
153 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
155 char * uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
156 GError * error = NULL;
157 ev_view_set_loading (EV_VIEW (ev_dscwindow->priv->notesview), TRUE);
159 if (ev_dscwindow->priv->notes_document) {
160 ev_document_load (ev_dscwindow->priv->notes_document, uri, &error);
162 ev_dscwindow->priv->notes_document = ev_document_factory_get_document (uri,
167 ev_dscwindow->priv->notes_model = ev_document_model_new ();
168 ev_document_model_set_document (ev_dscwindow->priv->notes_model, ev_dscwindow->priv->notes_document);
169 ev_document_model_set_continuous (ev_dscwindow->priv->notes_model, FALSE);
170 ev_document_model_set_dual_page (ev_dscwindow->priv->notes_model, FALSE);
171 ev_document_model_set_sizing_mode (ev_dscwindow->priv->notes_model, EV_SIZING_BEST_FIT);
172 ev_document_model_set_page (ev_dscwindow->priv->notes_model,
173 ev_document_model_get_page (ev_dscwindow->priv->model));
174 ev_view_set_model(EV_VIEW(ev_dscwindow->priv->notesview),
175 ev_dscwindow->priv->notes_model);
176 g_signal_connect (G_OBJECT(ev_dscwindow->priv->notes_model),
178 G_CALLBACK (ev_dscwindow_page_changed_cb),
182 gtk_widget_destroy (dialog);
188 * ev_dscwindow_get_control: Get the control instance.
190 * If there is none, create one.
192 * Returns: control instance
195 ev_dscwindow_get_control (void)
197 static EvDSCWindow * control = NULL;
199 if (!control || !EV_IS_DSCWINDOW (control)) {
200 control = EV_DSCWINDOW (g_object_new (EV_TYPE_DSCWINDOW, NULL));
207 ev_dscwindow_window_placement (EvDSCWindow *ev_dscwindow)
209 gint num_monitors = get_num_monitors (GTK_WINDOW (ev_dscwindow));
210 if (num_monitors == 2) {
211 GtkWindow * presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window);
212 GdkScreen * screen = gtk_window_get_screen (presentation_window);
213 gint work_monitor = gdk_screen_get_monitor_at_window (screen,
214 gtk_widget_get_window (GTK_WIDGET (presentation_window)));
215 gint presentation_monitor = (work_monitor + 1) % 2;
217 gdk_screen_get_monitor_geometry (screen, presentation_monitor,
220 gtk_window_move (presentation_window, coords.x, coords.y);
221 ev_dscwindow->priv->moveback_monitor = work_monitor;
222 gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
227 ev_dscwindow_notes_clicked (GtkWidget *widget, GdkEvent *event,
230 if (!self || !EV_IS_DSCWINDOW (self) || !event)
232 gint page = ev_document_model_get_page (self->priv->model);
234 if (event->type == GDK_2BUTTON_PRESS && ((GdkEventButton *)event)->button == 1) {
235 ev_dscwindow_notes_interaction (NULL, self);
236 } else if (event->type == GDK_BUTTON_PRESS && ((GdkEventButton *)event)->button == 1) {
237 ev_document_model_set_page (self->priv->model, page+1);
238 } else if (event->type == GDK_BUTTON_PRESS && ((GdkEventButton *)event)->button == 3) {
239 ev_document_model_set_page (self->priv->model, page-1);
245 * ev_dscwindow_set_presentation: Set presentation document
246 * @presentation_window: Main window we can reuse for presentation
249 ev_dscwindow_set_presentation (EvDSCWindow *ev_dscwindow,
250 EvWindow *presentation_window, EvDocument *document, EvViewPresentation *pview)
252 if (!EV_IS_WINDOW (presentation_window))
255 ev_dscwindow->priv->presentation_window = GTK_WIDGET(presentation_window);
256 ev_dscwindow->priv->presentation_document = document;
257 ev_dscwindow->priv->presentation_view = EV_VIEW_PRESENTATION(pview);
258 ev_document_model_set_document(ev_dscwindow->priv->model, document);
259 ev_document_model_set_page(ev_dscwindow->priv->model, ev_view_presentation_get_current_page (pview));
260 g_signal_connect_swapped (ev_dscwindow->priv->presentation_view,
262 G_CALLBACK (gtk_widget_destroy),
264 g_signal_connect (G_OBJECT(ev_dscwindow->priv->model),
266 G_CALLBACK (ev_dscwindow_page_changed_cb),
268 g_signal_connect (G_OBJECT(ev_dscwindow->priv->presentation_view),
270 G_CALLBACK (ev_dscwindow_presentation_page_changed_cb),
272 ev_dscwindow_window_placement (ev_dscwindow);
276 * ev_dscwindow_end: Destroy control window but keep presentation
279 ev_dscwindow_end (GtkWidget *widget, GdkEvent *event)
281 gtk_widget_destroy (GTK_WIDGET (ev_dscwindow_get_control ()));
286 * ev_dscwindow_init: Initialize multihead presentation
288 * @ev_dscwindow: EvDSCWindow.
290 * ev_dscwindow_set_presentation has to be called afterwards for loading in a document. TBD
293 ev_dscwindow_init (EvDSCWindow *ev_dscwindow)
297 ev_dscwindow->priv = EV_DSCWINDOW_GET_PRIVATE (ev_dscwindow);
298 ev_dscwindow->priv->moveback_monitor = -1;
299 ev_dscwindow->priv->notes_document = NULL;
301 gtk_window_set_title (GTK_WINDOW (ev_dscwindow), _("Presentation Control"));
303 GtkWidget *hpaned = gtk_hpaned_new ();
304 GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
306 ev_dscwindow->priv->model = ev_document_model_new ();
308 ev_dscwindow->priv->sidebar = ev_sidebar_new ();
309 ev_sidebar_set_model (EV_SIDEBAR (ev_dscwindow->priv->sidebar),
310 ev_dscwindow->priv->model);
311 GtkWidget *sidebar_widget;
312 sidebar_widget = ev_sidebar_thumbnails_new ();
313 gtk_widget_show (sidebar_widget);
314 ev_sidebar_add_page (EV_SIDEBAR (ev_dscwindow->priv->sidebar),
317 gtk_box_pack_start (GTK_BOX (vbox), ev_dscwindow->priv->sidebar, TRUE, TRUE, 0);
318 gtk_widget_show (ev_dscwindow->priv->sidebar);
320 ev_document_model_set_continuous (ev_dscwindow->priv->model, FALSE);
321 ev_document_model_set_dual_page (ev_dscwindow->priv->model, FALSE);
322 ev_document_model_set_sizing_mode (ev_dscwindow->priv->model, EV_SIZING_BEST_FIT);
324 GtkWidget *expander = gtk_expander_new (_("Expensive features"));
325 gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE);
327 GtkWidget *toolbar = gtk_toolbar_new ();
329 GtkToolItem* b_switch = gtk_tool_button_new (NULL, _("Switch monitors"));
330 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_switch), "object-flip-horizontal");
331 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_switch, -1);
332 g_signal_connect (b_switch, "clicked",
333 G_CALLBACK (ev_dscwindow_switch_monitors), ev_dscwindow);
335 GtkToolItem* b_notes = gtk_tool_button_new_from_stock (GTK_STOCK_OPEN);
336 gtk_tool_button_set_label (GTK_TOOL_BUTTON(b_notes), _("Load notes..."));
337 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_notes, -1);
338 g_signal_connect (b_notes, "clicked",
339 G_CALLBACK (ev_dscwindow_notes_interaction), ev_dscwindow);
341 GtkToolItem* b_close = gtk_tool_button_new (NULL, _("End presentation"));
342 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_close), "view-restore");
343 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_close, -1);
345 g_signal_connect (b_close, "clicked",
346 G_CALLBACK (ev_dscwindow_end), NULL);
348 gtk_container_add (GTK_CONTAINER (expander), toolbar);
349 gtk_box_pack_end (GTK_BOX (vbox), expander, FALSE, TRUE, 0);
350 gtk_paned_add1 (GTK_PANED (hpaned), vbox);
352 ev_dscwindow->priv->notesview_scrolled_window = GTK_WIDGET (g_object_new (
353 GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, NULL));
354 gtk_paned_add2 (GTK_PANED (hpaned), ev_dscwindow->priv->notesview_scrolled_window);
356 ev_dscwindow->priv->notesview = ev_view_new ();
357 g_object_ref (ev_dscwindow->priv->notesview);
358 gtk_container_add (GTK_CONTAINER (ev_dscwindow->priv->notesview_scrolled_window),
359 ev_dscwindow->priv->notesview);
360 ev_dscwindow->priv->notes_model = ev_dscwindow->priv->model;
361 ev_view_set_model (EV_VIEW (ev_dscwindow->priv->notesview), ev_dscwindow->priv->notes_model);
362 gtk_widget_show_all (hpaned);
363 gtk_container_add (GTK_CONTAINER (ev_dscwindow), hpaned);
365 gtk_drag_dest_unset (GTK_WIDGET (ev_dscwindow->priv->notesview));
366 gtk_drag_dest_unset (GTK_WIDGET (ev_dscwindow->priv->sidebar));
368 gint click = GDK_BUTTON1_MOTION_MASK | GDK_KEY_PRESS_MASK;
369 gtk_widget_add_events (GTK_WIDGET (ev_dscwindow->priv->sidebar), click);
370 /* TODO: actions, this part is broken...*/
371 /*g_signal_connect (ev_dscwindow->priv->notesview, "button-press-event",
372 G_CALLBACK (ev_dscwindow_notes_clicked), ev_dscwindow);*/
377 ev_dscwindow_dispose (GObject *obj)
379 EvDSCWindow * ev_dscwindow = EV_DSCWINDOW (obj);
380 EvDSCWindowPrivate *priv = ev_dscwindow->priv;
382 if (priv->moveback_monitor >= 0) {
383 GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
386 gdk_screen_get_monitor_geometry (
387 gtk_window_get_screen (presentation_window),
388 priv->moveback_monitor, &coords);
390 gtk_window_move (presentation_window, coords.x, coords.y);
392 ev_window_stop_presentation (EV_WINDOW(priv->presentation_window), TRUE);
393 /*if (priv->overview) {
394 g_object_unref (priv->overview);
395 priv->overview = NULL;
399 G_OBJECT_CLASS (ev_dscwindow_parent_class)->dispose (obj);
403 ev_dscwindow_class_init (EvDSCWindowClass *ev_dscwindow_class)
405 GObjectClass *g_object_class = G_OBJECT_CLASS (ev_dscwindow_class);
406 g_type_class_add_private (g_object_class, sizeof (EvDSCWindowPrivate));
407 g_object_class->dispose = ev_dscwindow_dispose;
411 ev_dscwindow_new (void)
413 EvDSCWindow *ev_dscwindow;
415 ev_dscwindow = g_object_new (EV_TYPE_DSCWINDOW, "type", GTK_WINDOW_TOPLEVEL, NULL);
416 return GTK_WIDGET (ev_dscwindow);