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"
39 #include "ev-presentation-timer.h"
41 struct _EvDSCWindowPrivate {
47 EvDocumentModel *model;
48 EvDocumentModel *notes_model;
49 EvDocument *presentation_document;
50 EvDocument *notes_document;
52 GtkWidget *presentation_window;
53 GtkWidget *overview_scrolled_window;
54 GtkWidget *notesview_scrolled_window;
56 EvViewPresentation *presentation_view;
57 gint moveback_monitor;
60 #define EV_DSCWINDOW_GET_PRIVATE(object) \
61 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_DSCWINDOW, EvDSCWindowPrivate))
62 #define PAGE_CACHE_SIZE 52428800 /* 50MB */
63 #define SIDEBAR_DEFAULT_SIZE 300
65 G_DEFINE_TYPE (EvDSCWindow, ev_dscwindow, GTK_TYPE_WINDOW)
69 ev_dscwindow_switch_monitors (GtkWidget *widget, EvDSCWindow *ev_dscwindow)
71 if (!EV_IS_DSCWINDOW (ev_dscwindow))
74 gint num_monitors = get_num_monitors (GTK_WINDOW (ev_dscwindow));
76 if (num_monitors == 2) {
77 GtkWindow *presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window);
78 GdkScreen *screen = gtk_window_get_screen (presentation_window);
80 gint monitor_1 = gdk_screen_get_monitor_at_window (screen,
81 gtk_widget_get_window (GTK_WIDGET (presentation_window)));
83 gint monitor_2 = (monitor_1 + 1) % 2;
86 gdk_screen_get_monitor_geometry (screen, monitor_2, &coords);
87 gtk_window_move (presentation_window, coords.x, coords.y);
88 ev_dscwindow->priv->moveback_monitor = monitor_1;
90 gdk_screen_get_monitor_geometry (screen, monitor_1, &coords);
91 gtk_window_unmaximize (GTK_WINDOW (ev_dscwindow));
92 gtk_window_move (GTK_WINDOW (ev_dscwindow), coords.x, coords.y);
93 gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
99 ev_dscwindow_sidebar_visibility(GtkWidget *sidebar)
101 gtk_widget_set_visible (sidebar, !(gtk_widget_get_visible(sidebar)));
105 ev_dscwindow_set_page (EvDSCWindow *ev_dscwindow, gint page)
107 if(page != ev_view_presentation_get_current_page (ev_dscwindow->priv->presentation_view)) {
108 ev_view_presentation_set_page (EV_VIEW_PRESENTATION(ev_dscwindow->priv->presentation_view), page);
109 if( ev_document_model_get_page (ev_dscwindow->priv->model) != page)
110 ev_document_model_set_page(ev_dscwindow->priv->model, page);
111 if( ev_document_model_get_page (ev_dscwindow->priv->notes_model) != page)
112 ev_document_model_set_page(ev_dscwindow->priv->notes_model, page);
114 ev_presentation_timer_set_page (EV_PRESENTATION_TIMER(ev_dscwindow->priv->timer), page);
118 ev_dscwindow_page_changed_cb (EvDocumentModel *model,
120 EvDSCWindow *ev_dscwindow)
122 ev_dscwindow_set_page (ev_dscwindow, ev_document_model_get_page (model));
126 ev_dscwindow_presentation_page_changed_cb (EvViewPresentation *pview,
128 EvDSCWindow *ev_dscwindow)
130 ev_dscwindow_set_page (ev_dscwindow, ev_view_presentation_get_current_page (pview));
134 ev_dscwindow_notes_interaction (GtkContainer *container, EvDSCWindow *ev_dscwindow)
138 dialog = gtk_file_chooser_dialog_new (
140 GTK_WINDOW (ev_dscwindow),
141 GTK_FILE_CHOOSER_ACTION_OPEN,
142 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
143 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
146 ev_document_factory_add_filters (dialog, NULL);
147 gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), FALSE);
148 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), TRUE);
150 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
152 char * uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
153 GError * error = NULL;
154 ev_view_set_loading (EV_VIEW (ev_dscwindow->priv->notesview), TRUE);
156 if (ev_dscwindow->priv->notes_document) {
157 ev_document_load (ev_dscwindow->priv->notes_document, uri, &error);
159 ev_dscwindow->priv->notes_document = ev_document_factory_get_document (uri,
164 ev_dscwindow->priv->notes_model = ev_document_model_new ();
165 ev_document_model_set_document (ev_dscwindow->priv->notes_model, ev_dscwindow->priv->notes_document);
166 ev_document_model_set_continuous (ev_dscwindow->priv->notes_model, FALSE);
167 ev_document_model_set_dual_page (ev_dscwindow->priv->notes_model, FALSE);
168 ev_document_model_set_sizing_mode (ev_dscwindow->priv->notes_model, EV_SIZING_BEST_FIT);
169 ev_document_model_set_page (ev_dscwindow->priv->notes_model,
170 ev_document_model_get_page (ev_dscwindow->priv->model));
171 ev_view_set_model(EV_VIEW(ev_dscwindow->priv->notesview),
172 ev_dscwindow->priv->notes_model);
173 g_signal_connect (G_OBJECT(ev_dscwindow->priv->notes_model),
175 G_CALLBACK (ev_dscwindow_page_changed_cb),
179 gtk_widget_destroy (dialog);
185 ev_dscwindow_get_control (void)
187 static EvDSCWindow * control = NULL;
189 if (!control || !EV_IS_DSCWINDOW (control)) {
190 control = EV_DSCWINDOW (g_object_new (EV_TYPE_DSCWINDOW, NULL));
197 ev_dscwindow_window_placement (EvDSCWindow *ev_dscwindow)
199 GtkWindow * presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window);
200 GdkScreen * screen = gtk_window_get_screen (presentation_window);
201 gint work_monitor = gdk_screen_get_monitor_at_window (screen,
202 gtk_widget_get_window (GTK_WIDGET (presentation_window)));
203 gint presentation_monitor = (work_monitor + 1) % 2;
205 gdk_screen_get_monitor_geometry (screen, presentation_monitor,
208 gtk_window_move (presentation_window, coords.x, coords.y);
209 ev_dscwindow->priv->moveback_monitor = work_monitor;
210 gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
214 ev_dscwindow_set_presentation (EvDSCWindow *ev_dscwindow,
215 EvWindow *presentation_window, EvDocument *document, EvViewPresentation *pview)
217 if (!EV_IS_WINDOW (presentation_window))
220 ev_dscwindow->priv->presentation_window = GTK_WIDGET(presentation_window);
221 ev_dscwindow->priv->presentation_document = document;
222 ev_dscwindow->priv->presentation_view = EV_VIEW_PRESENTATION(pview);
224 ev_document_model_set_document(ev_dscwindow->priv->model, document);
225 ev_document_model_set_page(ev_dscwindow->priv->model, ev_view_presentation_get_current_page (pview));
227 g_signal_connect_swapped (ev_dscwindow->priv->presentation_view,
229 G_CALLBACK (gtk_widget_destroy),
231 g_signal_connect (G_OBJECT(ev_dscwindow->priv->model),
233 G_CALLBACK (ev_dscwindow_page_changed_cb),
235 g_signal_connect (G_OBJECT(ev_dscwindow->priv->presentation_view),
237 G_CALLBACK (ev_dscwindow_presentation_page_changed_cb),
239 ev_presentation_timer_set_pages (EV_PRESENTATION_TIMER(ev_dscwindow->priv->timer), ev_document_get_n_pages (document));
241 ev_dscwindow_window_placement (ev_dscwindow);
245 ev_dscwindow_end (GtkWidget *widget, GdkEvent *event)
247 gtk_widget_destroy (GTK_WIDGET (ev_dscwindow_get_control ()));
252 ev_dscwindow_init (EvDSCWindow *ev_dscwindow)
255 ev_dscwindow->priv = EV_DSCWINDOW_GET_PRIVATE (ev_dscwindow);
256 ev_dscwindow->priv->moveback_monitor = -1;
257 ev_dscwindow->priv->notes_document = NULL;
259 gtk_window_set_title (GTK_WINDOW (ev_dscwindow), _("Presentation Control"));
261 GtkWidget *hpaned = gtk_hpaned_new ();
262 GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
264 ev_dscwindow->priv->model = ev_document_model_new ();
265 ev_document_model_set_continuous (ev_dscwindow->priv->model, FALSE);
266 ev_document_model_set_dual_page (ev_dscwindow->priv->model, FALSE);
267 ev_document_model_set_sizing_mode (ev_dscwindow->priv->model, EV_SIZING_BEST_FIT);
269 ev_dscwindow->priv->sidebar = ev_sidebar_new ();
270 ev_sidebar_set_model (EV_SIDEBAR (ev_dscwindow->priv->sidebar),
271 ev_dscwindow->priv->model);
273 GtkWidget *sidebar_widget;
274 sidebar_widget = ev_sidebar_thumbnails_new ();
275 ev_sidebar_add_page (EV_SIDEBAR (ev_dscwindow->priv->sidebar),
278 ev_dscwindow->priv->notesview_scrolled_window = GTK_WIDGET (
279 g_object_new (GTK_TYPE_SCROLLED_WINDOW,"shadow-type",
280 GTK_SHADOW_IN, NULL));
281 gtk_paned_pack1 (GTK_PANED (hpaned), ev_dscwindow->priv->sidebar, FALSE, TRUE);
282 gtk_paned_pack2 (GTK_PANED (hpaned), ev_dscwindow->priv->notesview_scrolled_window, TRUE, TRUE);
283 gtk_paned_set_position (GTK_PANED (hpaned), SIDEBAR_DEFAULT_SIZE);
285 ev_dscwindow->priv->notesview = ev_view_new ();
286 // g_object_ref (ev_dscwindow->priv->notesview);
287 gtk_container_add (GTK_CONTAINER (ev_dscwindow->priv->notesview_scrolled_window),
288 ev_dscwindow->priv->notesview);
290 ev_dscwindow->priv->notes_model = ev_dscwindow->priv->model;
291 ev_view_set_model (EV_VIEW (ev_dscwindow->priv->notesview), ev_dscwindow->priv->notes_model);
293 gtk_box_pack_start(GTK_BOX(vbox),hpaned,TRUE,TRUE,0);
295 GtkWidget *expander = gtk_expander_new (_("Expensive features"));
296 gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE);
297 GtkWidget *toolbar = gtk_toolbar_new ();
299 GtkToolItem *b_switch = gtk_tool_button_new (NULL, _("Switch monitors"));
300 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_switch), "object-flip-horizontal");
301 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_switch, -1);
302 g_signal_connect (b_switch, "clicked",
303 G_CALLBACK (ev_dscwindow_switch_monitors), ev_dscwindow);
305 GtkToolItem *b_notes = gtk_tool_button_new_from_stock (GTK_STOCK_OPEN);
306 gtk_tool_button_set_label (GTK_TOOL_BUTTON(b_notes), _("Load notes..."));
307 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_notes, -1);
308 g_signal_connect (b_notes, "clicked",
309 G_CALLBACK (ev_dscwindow_notes_interaction), ev_dscwindow);
311 GtkToolItem *b_close = gtk_tool_button_new_from_stock (GTK_STOCK_CLOSE);
312 gtk_tool_button_set_label (GTK_TOOL_BUTTON(b_close), _("End presentation"));
313 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_close, -1);
314 g_signal_connect (b_close, "clicked",
315 G_CALLBACK (ev_dscwindow_end), NULL);
317 GtkToolItem *b_sidebar = gtk_tool_button_new_from_stock (GTK_STOCK_PAGE_SETUP);
318 gtk_tool_button_set_label (GTK_TOOL_BUTTON(b_sidebar), _("Show sidebar"));
319 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_sidebar, -1);
320 g_signal_connect_swapped (b_sidebar, "clicked",
321 G_CALLBACK (ev_dscwindow_sidebar_visibility), ev_dscwindow->priv->sidebar);
323 gtk_container_add (GTK_CONTAINER (expander), toolbar);
325 GtkWidget *hpan = gtk_hpaned_new ();
326 gtk_paned_pack1 (GTK_PANED(hpan), expander, FALSE, TRUE);
327 ev_dscwindow->priv->timer = ev_presentation_timer_new ();
328 gtk_paned_pack2 (GTK_PANED(hpan),ev_dscwindow->priv->timer, TRUE, TRUE);
329 gtk_paned_set_position (GTK_PANED (hpan), SIDEBAR_DEFAULT_SIZE);
330 gtk_box_pack_end (GTK_BOX (vbox), hpan, FALSE, TRUE, 0);
331 gtk_container_add (GTK_CONTAINER (ev_dscwindow), vbox);
332 gtk_widget_show_all(vbox);
336 ev_dscwindow_dispose (GObject *obj)
338 EvDSCWindow * ev_dscwindow = EV_DSCWINDOW (obj);
339 EvDSCWindowPrivate *priv = ev_dscwindow->priv;
341 if (priv->moveback_monitor >= 0) {
342 GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
345 gdk_screen_get_monitor_geometry (
346 gtk_window_get_screen (presentation_window),
347 priv->moveback_monitor, &coords);
349 gtk_window_move (presentation_window, coords.x, coords.y);
351 ev_window_stop_presentation (EV_WINDOW(priv->presentation_window), TRUE);
352 /*if (priv->overview) {
353 g_object_unref (priv->overview);
354 priv->overview = NULL;
357 G_OBJECT_CLASS (ev_dscwindow_parent_class)->dispose (obj);
361 ev_dscwindow_class_init (EvDSCWindowClass *ev_dscwindow_class)
363 GObjectClass *g_object_class = G_OBJECT_CLASS (ev_dscwindow_class);
364 g_type_class_add_private (g_object_class, sizeof (EvDSCWindowPrivate));
365 g_object_class->dispose = ev_dscwindow_dispose;
369 ev_dscwindow_new (void)
371 EvDSCWindow *ev_dscwindow;
373 ev_dscwindow = g_object_new (EV_TYPE_DSCWINDOW, "type", GTK_WINDOW_TOPLEVEL, NULL);
374 return GTK_WIDGET (ev_dscwindow);