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 */
62 G_DEFINE_TYPE (EvDSCWindow, ev_dscwindow, GTK_TYPE_WINDOW)
65 ev_dscwindow_switch_monitors (GtkWidget *widget, EvDSCWindow *ev_dscwindow)
67 if (!EV_IS_DSCWINDOW (ev_dscwindow))
70 gint num_monitors = get_num_monitors (GTK_WINDOW (ev_dscwindow));
72 if (num_monitors == 2) {
73 GtkWindow *presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window);
74 GdkScreen *screen = gtk_window_get_screen (presentation_window);
76 gint monitor_1 = gdk_screen_get_monitor_at_window (screen,
77 gtk_widget_get_window (GTK_WIDGET (presentation_window)));
79 gint monitor_2 = (monitor_1 + 1) % 2;
82 gdk_screen_get_monitor_geometry (screen, monitor_2, &coords);
83 gtk_window_move (presentation_window, coords.x, coords.y);
84 ev_dscwindow->priv->moveback_monitor = monitor_1;
86 gdk_screen_get_monitor_geometry (screen, monitor_1, &coords);
87 gtk_window_unmaximize (GTK_WINDOW (ev_dscwindow));
88 gtk_window_move (GTK_WINDOW (ev_dscwindow), coords.x, coords.y);
89 gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
95 ev_dscwindow_sidebar_visibility(GtkWidget *sidebar)
97 gtk_widget_set_visible (sidebar, !(gtk_widget_get_visible(sidebar)));
101 ev_dscwindow_page_changed_cb (EvDocumentModel *model,
103 EvDSCWindow *ev_dscwindow)
105 gint page = ev_document_model_get_page (model);
106 if(page != ev_view_presentation_get_current_page (ev_dscwindow->priv->presentation_view)) {
107 ev_view_presentation_set_page (EV_VIEW_PRESENTATION(ev_dscwindow->priv->presentation_view), page);
108 if( ev_document_model_get_page (ev_dscwindow->priv->model) != page)
109 ev_document_model_set_page(ev_dscwindow->priv->model, page);
110 if( ev_document_model_get_page (ev_dscwindow->priv->notes_model) != page)
111 ev_document_model_set_page(ev_dscwindow->priv->notes_model, page);
116 ev_dscwindow_presentation_page_changed_cb (EvViewPresentation *pview,
118 EvDSCWindow *ev_dscwindow)
120 gint page = ev_view_presentation_get_current_page (pview);
121 if( ev_document_model_get_page (ev_dscwindow->priv->model) != page)
122 ev_document_model_set_page(ev_dscwindow->priv->model, page);
123 if( ev_document_model_get_page (ev_dscwindow->priv->notes_model) != page)
124 ev_document_model_set_page(ev_dscwindow->priv->notes_model, page);
128 ev_dscwindow_notes_interaction (GtkContainer *container, EvDSCWindow *ev_dscwindow)
132 dialog = gtk_file_chooser_dialog_new (
134 GTK_WINDOW (ev_dscwindow),
135 GTK_FILE_CHOOSER_ACTION_OPEN,
136 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
137 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
140 ev_document_factory_add_filters (dialog, NULL);
141 gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), FALSE);
142 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), TRUE);
144 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
146 char * uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
147 GError * error = NULL;
148 ev_view_set_loading (EV_VIEW (ev_dscwindow->priv->notesview), TRUE);
150 if (ev_dscwindow->priv->notes_document) {
151 ev_document_load (ev_dscwindow->priv->notes_document, uri, &error);
153 ev_dscwindow->priv->notes_document = ev_document_factory_get_document (uri,
158 ev_dscwindow->priv->notes_model = ev_document_model_new ();
159 ev_document_model_set_document (ev_dscwindow->priv->notes_model, ev_dscwindow->priv->notes_document);
160 ev_document_model_set_continuous (ev_dscwindow->priv->notes_model, FALSE);
161 ev_document_model_set_dual_page (ev_dscwindow->priv->notes_model, FALSE);
162 ev_document_model_set_sizing_mode (ev_dscwindow->priv->notes_model, EV_SIZING_BEST_FIT);
163 ev_document_model_set_page (ev_dscwindow->priv->notes_model,
164 ev_document_model_get_page (ev_dscwindow->priv->model));
165 ev_view_set_model(EV_VIEW(ev_dscwindow->priv->notesview),
166 ev_dscwindow->priv->notes_model);
167 g_signal_connect (G_OBJECT(ev_dscwindow->priv->notes_model),
169 G_CALLBACK (ev_dscwindow_page_changed_cb),
173 gtk_widget_destroy (dialog);
179 ev_dscwindow_get_control (void)
181 static EvDSCWindow * control = NULL;
183 if (!control || !EV_IS_DSCWINDOW (control)) {
184 control = EV_DSCWINDOW (g_object_new (EV_TYPE_DSCWINDOW, NULL));
191 ev_dscwindow_window_placement (EvDSCWindow *ev_dscwindow)
193 gint num_monitors = get_num_monitors (GTK_WINDOW (ev_dscwindow));
194 if (num_monitors == 2) {
195 GtkWindow * presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window);
196 GdkScreen * screen = gtk_window_get_screen (presentation_window);
197 gint work_monitor = gdk_screen_get_monitor_at_window (screen,
198 gtk_widget_get_window (GTK_WIDGET (presentation_window)));
199 gint presentation_monitor = (work_monitor + 1) % 2;
201 gdk_screen_get_monitor_geometry (screen, presentation_monitor,
204 gtk_window_move (presentation_window, coords.x, coords.y);
205 ev_dscwindow->priv->moveback_monitor = work_monitor;
206 gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
211 ev_dscwindow_notes_clicked (GtkWidget *widget, GdkEvent *event,
214 if (!self || !EV_IS_DSCWINDOW (self) || !event)
216 gint page = ev_document_model_get_page (self->priv->model);
218 if (event->type == GDK_2BUTTON_PRESS && ((GdkEventButton *)event)->button == 1) {
219 ev_dscwindow_notes_interaction (NULL, self);
220 } else if (event->type == GDK_BUTTON_PRESS && ((GdkEventButton *)event)->button == 1) {
221 ev_document_model_set_page (self->priv->model, page+1);
222 } else if (event->type == GDK_BUTTON_PRESS && ((GdkEventButton *)event)->button == 3) {
223 ev_document_model_set_page (self->priv->model, page-1);
229 ev_dscwindow_set_presentation (EvDSCWindow *ev_dscwindow,
230 EvWindow *presentation_window, EvDocument *document, EvViewPresentation *pview)
232 if (!EV_IS_WINDOW (presentation_window))
235 ev_dscwindow->priv->presentation_window = GTK_WIDGET(presentation_window);
236 ev_dscwindow->priv->presentation_document = document;
237 ev_dscwindow->priv->presentation_view = EV_VIEW_PRESENTATION(pview);
238 ev_document_model_set_document(ev_dscwindow->priv->model, document);
239 ev_document_model_set_page(ev_dscwindow->priv->model, ev_view_presentation_get_current_page (pview));
240 g_signal_connect_swapped (ev_dscwindow->priv->presentation_view,
242 G_CALLBACK (gtk_widget_destroy),
244 g_signal_connect (G_OBJECT(ev_dscwindow->priv->model),
246 G_CALLBACK (ev_dscwindow_page_changed_cb),
248 g_signal_connect (G_OBJECT(ev_dscwindow->priv->presentation_view),
250 G_CALLBACK (ev_dscwindow_presentation_page_changed_cb),
252 ev_dscwindow_window_placement (ev_dscwindow);
256 ev_dscwindow_end (GtkWidget *widget, GdkEvent *event)
258 gtk_widget_destroy (GTK_WIDGET (ev_dscwindow_get_control ()));
263 ev_dscwindow_init (EvDSCWindow *ev_dscwindow)
266 ev_dscwindow->priv = EV_DSCWINDOW_GET_PRIVATE (ev_dscwindow);
267 ev_dscwindow->priv->moveback_monitor = -1;
268 ev_dscwindow->priv->notes_document = NULL;
270 gtk_window_set_title (GTK_WINDOW (ev_dscwindow), _("Presentation Control"));
272 GtkWidget *hpaned = gtk_hpaned_new ();
273 GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
275 ev_dscwindow->priv->model = ev_document_model_new ();
276 ev_document_model_set_continuous (ev_dscwindow->priv->model, FALSE);
277 ev_document_model_set_dual_page (ev_dscwindow->priv->model, FALSE);
278 ev_document_model_set_sizing_mode (ev_dscwindow->priv->model, EV_SIZING_BEST_FIT);
280 ev_dscwindow->priv->sidebar = ev_sidebar_new ();
281 ev_sidebar_set_model (EV_SIDEBAR (ev_dscwindow->priv->sidebar),
282 ev_dscwindow->priv->model);
283 GtkWidget *sidebar_widget;
284 sidebar_widget = ev_sidebar_thumbnails_new ();
285 gtk_widget_show (sidebar_widget);
286 ev_sidebar_add_page (EV_SIDEBAR (ev_dscwindow->priv->sidebar),
288 gtk_widget_show (ev_dscwindow->priv->sidebar);
289 gtk_paned_add1(GTK_PANED(hpaned), ev_dscwindow->priv->sidebar);
291 ev_dscwindow->priv->notesview_scrolled_window = GTK_WIDGET (
292 g_object_new (GTK_TYPE_SCROLLED_WINDOW,"shadow-type",
293 GTK_SHADOW_IN, NULL));
294 gtk_paned_add2 (GTK_PANED (hpaned), ev_dscwindow->priv->notesview_scrolled_window);
296 ev_dscwindow->priv->notesview = ev_view_new ();
297 g_object_ref (ev_dscwindow->priv->notesview);
298 gtk_container_add (GTK_CONTAINER (ev_dscwindow->priv->notesview_scrolled_window),
299 ev_dscwindow->priv->notesview);
300 ev_dscwindow->priv->notes_model = ev_dscwindow->priv->model;
301 ev_view_set_model (EV_VIEW (ev_dscwindow->priv->notesview), ev_dscwindow->priv->notes_model);
302 gtk_widget_show_all (hpaned);
303 gtk_box_pack_start(GTK_BOX(vbox),hpaned,TRUE,TRUE,0);
305 GtkWidget *expander = gtk_expander_new (_("Expensive features"));
306 gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE);
307 GtkWidget *toolbar = gtk_toolbar_new ();
309 GtkToolItem *b_switch = gtk_tool_button_new (NULL, _("Switch monitors"));
310 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_switch), "object-flip-horizontal");
311 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_switch, -1);
312 g_signal_connect (b_switch, "clicked",
313 G_CALLBACK (ev_dscwindow_switch_monitors), ev_dscwindow);
315 GtkToolItem *b_notes = gtk_tool_button_new_from_stock (GTK_STOCK_OPEN);
316 gtk_tool_button_set_label (GTK_TOOL_BUTTON(b_notes), _("Load notes..."));
317 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_notes, -1);
318 g_signal_connect (b_notes, "clicked",
319 G_CALLBACK (ev_dscwindow_notes_interaction), ev_dscwindow);
321 GtkToolItem *b_close = gtk_tool_button_new_from_stock (GTK_STOCK_CLOSE);
322 gtk_tool_button_set_label (GTK_TOOL_BUTTON(b_close), _("End presentation"));
323 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_close, -1);
324 g_signal_connect (b_close, "clicked",
325 G_CALLBACK (ev_dscwindow_end), NULL);
327 GtkToolItem *b_sidebar = gtk_tool_button_new_from_stock (GTK_STOCK_PAGE_SETUP);
328 gtk_tool_button_set_label (GTK_TOOL_BUTTON(b_sidebar), _("Show sidebar"));
329 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_sidebar, -1);
330 g_signal_connect_swapped (b_sidebar, "clicked",
331 G_CALLBACK (ev_dscwindow_sidebar_visibility), ev_dscwindow->priv->sidebar);
333 gtk_container_add (GTK_CONTAINER (expander), toolbar);
334 gtk_box_pack_end (GTK_BOX (vbox), expander, FALSE, TRUE, 0);
336 // gtk_drag_dest_unset (GTK_WIDGET (ev_dscwindow->priv->notesview));
337 // gtk_drag_dest_unset (GTK_WIDGET (ev_dscwindow->priv->sidebar));
339 // gint click = GDK_BUTTON1_MOTION_MASK | GDK_KEY_PRESS_MASK;
340 // gtk_widget_add_events (GTK_WIDGET (ev_dscwindow->priv->sidebar), click);
341 /* TODO: actions, this part is broken...*/
342 /*g_signal_connect (ev_dscwindow->priv->notesview, "button-press-event",
343 G_CALLBACK (ev_dscwindow_notes_clicked), ev_dscwindow);*/
345 gtk_widget_show_all(vbox);
346 gtk_container_add (GTK_CONTAINER (ev_dscwindow), vbox);
351 ev_dscwindow_dispose (GObject *obj)
353 EvDSCWindow * ev_dscwindow = EV_DSCWINDOW (obj);
354 EvDSCWindowPrivate *priv = ev_dscwindow->priv;
356 if (priv->moveback_monitor >= 0) {
357 GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
360 gdk_screen_get_monitor_geometry (
361 gtk_window_get_screen (presentation_window),
362 priv->moveback_monitor, &coords);
364 gtk_window_move (presentation_window, coords.x, coords.y);
366 ev_window_stop_presentation (EV_WINDOW(priv->presentation_window), TRUE);
367 /*if (priv->overview) {
368 g_object_unref (priv->overview);
369 priv->overview = NULL;
373 G_OBJECT_CLASS (ev_dscwindow_parent_class)->dispose (obj);
377 ev_dscwindow_class_init (EvDSCWindowClass *ev_dscwindow_class)
379 GObjectClass *g_object_class = G_OBJECT_CLASS (ev_dscwindow_class);
380 g_type_class_add_private (g_object_class, sizeof (EvDSCWindowPrivate));
381 g_object_class->dispose = ev_dscwindow_dispose;
385 ev_dscwindow_new (void)
387 EvDSCWindow *ev_dscwindow;
389 ev_dscwindow = g_object_new (EV_TYPE_DSCWINDOW, "type", GTK_WINDOW_TOPLEVEL, NULL);
390 return GTK_WIDGET (ev_dscwindow);