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"
31 struct _EvDSCWindowPrivate {
36 EvDocumentModel *model;
37 EvDocument * notesdocument;
39 GtkWidget *overview_scrolled_window;
40 GtkWidget *notesview_scrolled_window;
42 EvWindow *presentation_window;
43 EvDocument * presentation_document;
44 gint moveback_monitor;
47 #define EV_DSCWINDOW_GET_PRIVATE(object) \
48 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_DSCWINDOW, EvDSCWindowPrivate))
49 #define PAGE_CACHE_SIZE 52428800 /* 50MB */
51 /*static gpointer parent_class = NULL;*/
53 G_DEFINE_TYPE (EvDSCWindow, ev_dscwindow, GTK_TYPE_WINDOW)
56 * ev_dscwindow_switch_monitors: Bring the presentation window and the control window each on the other monitor.
58 * @widget: Callback widget
62 ev_dscwindow_switch_monitors (GtkWidget *widget, EvDSCWindow *self)
65 + if (!EV_IS_DSCWINDOW (self))
68 + EvDSCWindowPrivate *priv = EV_DSCWINDOW_GET_PRIVATE (self);
70 + gint num_monitors = get_num_monitors (GTK_WINDOW (self));
72 + if (num_monitors == 2) {
73 + GtkWindow * presentation_window = GTK_WINDOW (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 (presentation_window)->window);
79 + gint monitor_2 = (monitor_1 + 1) % 2;
81 + GdkRectangle coords;
82 + gdk_screen_get_monitor_geometry (screen, monitor_2, &coords);
83 + ev_window_stop_presentation (priv->presentation_window);
84 + gtk_window_move (presentation_window, coords.x, coords.y);
85 + ev_window_run_presentation (priv->presentation_window);
86 + priv->moveback_monitor = monitor_1;
88 + gdk_screen_get_monitor_geometry (screen, monitor_1, &coords);
89 + gtk_window_unmaximize (GTK_WINDOW (self));
90 + gtk_window_move (GTK_WINDOW (self), coords.x, coords.y);
91 + gtk_window_maximize (GTK_WINDOW (self));
97 * ev_dscwindow_notes_interaction: User wants to load a different file as notes.
100 ev_dscwindow_notes_interaction (GtkContainer *container, EvDSCWindow *self)
103 + EvDSCWindowPrivate *priv = EV_DSCWINDOW_GET_PRIVATE (self);
106 + dialog = gtk_file_chooser_dialog_new (
107 + _("Open Document"),
109 + GTK_FILE_CHOOSER_ACTION_OPEN,
110 + GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
111 + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
114 + ev_document_factory_add_filters (dialog, NULL);
115 + gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), FALSE);
116 + gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), TRUE);
118 + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
120 + char * uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
121 + GError * error = NULL;
122 + ev_view_set_loading (EV_VIEW (priv->notesview), TRUE);
124 + if (priv->notesdocument) {
125 + ev_document_load (priv->notesdocument, uri, &error);
127 + priv->notesdocument = ev_document_factory_get_document (uri,
131 + if (error == NULL){
132 + ev_view_set_document (EV_VIEW (priv->notesview),
133 + priv->notesdocument);
134 + /* TODO: go to the same page that is open at the moment, or
135 + * move the presentation to the beginning. *//*
138 + gtk_widget_destroy (dialog);
144 * ev_dscwindow_get_control: Get the control instance.
146 * If there is none, create one.
148 * Returns: control instance
151 ev_dscwindow_get_control (void)
153 static EvDSCWindow * control = NULL;
155 if (!control || !EV_IS_DSCWINDOW (control)) {
156 control = EV_DSCWINDOW (g_object_new (EV_TYPE_DSCWINDOW, NULL));
163 ev_dscwindow_window_placement (EvDSCWindow *ev_dscwindow)
165 gint num_monitors = get_num_monitors (GTK_WINDOW (ev_dscwindow));
166 if (num_monitors == 2) {
167 GtkWindow * presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window);
168 GdkScreen * screen = gtk_window_get_screen (presentation_window);
170 gint work_monitor = gdk_screen_get_monitor_at_window (screen,
171 GTK_WIDGET (presentation_window)->window);
173 gint presentation_monitor = (work_monitor + 1) % 2;
176 gdk_screen_get_monitor_geometry (screen, presentation_monitor,
179 gtk_window_move (presentation_window, coords.x, coords.y);
180 ev_window_run_presentation (ev_dscwindow->priv->presentation_window);
181 ev_dscwindow->priv->moveback_monitor = work_monitor;
183 gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
189 * ev_dscwindow_set_presentation: Set presentation document
190 * @presentation_window: Main window we can reuse for presentation
193 ev_dscwindow_set_presentation (EvDSCWindow *ev_dscwindow,
194 EvWindow *presentation_window)
196 if (!EV_IS_WINDOW (presentation_window))
199 ev_dscwindow->priv->presentation_window = presentation_window;
200 ev_dscwindow->priv->presentation_document = document;
202 ev_document_model_set_document(ev_dscwindow->priv->model,
203 presentation_window->priv->document);
204 /* ev_view_set_document (EV_VIEW (priv->notesview),
205 priv->presentation_document);
206 ev_dscwindow_window_placement (self);
207 ev_dscwindow_handle_resized (NULL, NULL, self);
212 * ev_dscwindow_end: Stop presentation mode.
215 ev_dscwindow_end (GtkWidget *widget, GdkEvent *event)
217 gtk_widget_destroy (GTK_WIDGET (ev_dscwindow_get_control ()));
222 * ev_dscwindow_init: Initialize multihead presentation
224 * @self: EvDSCWindow.
226 * ev_dscwindow_set_presentation has to be called afterwards for loading in a document. TBD
229 ev_dscwindow_init (EvDSCWindow *ev_dscwindow)
231 ev_dscwindow->priv = EV_DSCWINDOW_GET_PRIVATE (ev_dscwindow);
232 ev_dscwindow->priv->moveback_monitor = -1;
233 ev_dscwindow->priv->notesdocument = NULL;
235 gtk_window_set_title (GTK_WINDOW (ev_dscwindow), _("Presentation Control"));
237 GtkWidget *h = gtk_hpaned_new ();
238 GtkWidget *v = gtk_vbox_new (FALSE, 0);
240 ev_dscwindow->priv->overview_scrolled_window = GTK_WIDGET (g_object_new (
241 GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, NULL));
242 gtk_box_pack_start (GTK_BOX (v), ev_dscwindow->priv->overview_scrolled_window, TRUE, TRUE, 0);
244 ev_dscwindow->priv->model = ev_document_model_new ();
245 ev_dscwindow->priv->overview = ev_view_new ();
246 ev_view_set_page_cache_size (EV_VIEW (ev_dscwindow->priv->overview), PAGE_CACHE_SIZE);
247 ev_view_set_model (EV_VIEW (ev_dscwindow->priv->overview), ev_dscwindow->priv->model);
248 ev_document_model_set_continuous (ev_dscwindow->priv->model, TRUE);
249 ev_document_model_set_dual_page (ev_dscwindow->priv->model, FALSE);
250 ev_document_model_set_sizing_mode (ev_dscwindow->priv->model, EV_SIZING_BEST_FIT);
253 gtk_container_add (GTK_CONTAINER (ev_dscwindow->priv->overview_scrolled_window),
254 ev_dscwindow->priv->overview);
257 GtkWidget *e = gtk_expander_new (_("Expensive features"));
258 gtk_expander_set_expanded (GTK_EXPANDER (e), TRUE);
260 GtkWidget *t = gtk_toolbar_new ();
262 GtkToolItem* b_switch = gtk_tool_button_new (NULL, _("Switch monitors"));
263 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_switch), "object-flip-horizontal");
264 gtk_toolbar_insert (GTK_TOOLBAR (t), b_switch, -1);
265 g_signal_connect (b_switch, "clicked",
266 G_CALLBACK (ev_dscwindow_switch_monitors), ev_dscwindow);
268 GtkToolItem* b_notes = gtk_tool_button_new (NULL, _("Load notes ..."));
269 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_notes), "object-flip-horizontal");
270 gtk_toolbar_insert (GTK_TOOLBAR (t), b_notes, -1);
271 g_signal_connect (b_notes, "clicked",
272 G_CALLBACK (ev_dscwindow_notes_interaction), ev_dscwindow);
274 GtkToolItem* b_close = gtk_tool_button_new (NULL, _("End presentation"));
275 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_close), "view-restore");
276 gtk_toolbar_insert (GTK_TOOLBAR (t), b_close, -1);
277 g_signal_connect (b_close, "clicked",
278 G_CALLBACK (ev_dscwindow_end), NULL);
280 gtk_container_add (GTK_CONTAINER (e), t);
281 gtk_box_pack_end (GTK_BOX (v), e, FALSE, TRUE, 0);
282 gtk_paned_add1 (GTK_PANED (h), v);
285 priv->notesview_scrolled_window = GTK_WIDGET (g_object_new (
286 GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, NULL));
287 gtk_paned_add2 (GTK_PANED (h), priv->notesview_scrolled_window);
289 priv->notesview = ev_view_new ();
290 g_object_ref (priv->notesview);
291 ev_view_set_screen_dpi (EV_VIEW (priv->notesview),
292 get_screen_dpi (GTK_WINDOW (self)));
293 + gtk_container_add (GTK_CONTAINER (priv->notesview_scrolled_window),
296 + ev_view_set_continuous (EV_VIEW (priv->notesview), FALSE);
297 + ev_view_set_dual_page (EV_VIEW (priv->notesview), FALSE);
298 + ev_view_set_sizing_mode (EV_VIEW (priv->notesview), EV_SIZING_BEST_FIT);
301 + gtk_paned_set_position (GTK_PANED (h), 400);
302 + gtk_widget_show_all (h);
303 + gtk_container_add (GTK_CONTAINER (self), h);
305 + /* fallback if we have >2 monitors (see window placement) */
306 /*+ gtk_window_set_default_size (GTK_WINDOW (self), 800, 600);
308 + g_signal_connect (h, "notify::position",
309 + G_CALLBACK (ev_dscwindow_handle_resized), self);
311 + g_signal_connect (self, "size-allocate",
312 + G_CALLBACK (ev_dscwindow_handle_resized), self);
314 + /* This would just open new windows. */
315 /*+ gtk_drag_dest_unset (GTK_WIDGET (priv->notesview));
316 + gtk_drag_dest_unset (GTK_WIDGET (priv->overview));
318 + gint click = GDK_BUTTON1_MOTION_MASK | GDK_KEY_PRESS_MASK;
319 + gtk_widget_add_events (GTK_WIDGET (priv->overview), click);
320 + g_signal_connect (priv->notesview, "button-press-event",
321 + G_CALLBACK (ev_dscwindow_notes_clicked), self);
327 ev_dscwindow_dispose (GObject *obj)
329 EvDSCWindow * ev_dscwindow = EV_DSCWINDOW (obj);
330 EvDSCWindowPrivate *priv = ev_dscwindow->priv;
332 /* if (EV_IS_VIEW (priv->overview) {
333 ev_document_model_set_document (priv->model, NULL);
335 + ev_view_set_document (EV_VIEW (priv->overview), NULL);
336 + g_object_unref (priv->overview);
338 + if (EV_IS_VIEW (priv->notesview)) {
339 + ev_view_set_document (EV_VIEW (priv->notesview), NULL);
340 + g_object_unref (priv->notesview);
342 /*TODO: save fulscreen state*/
343 ev_window_stop_presentation (priv->presentation_window, 0);
345 if (priv->moveback_monitor >= 0) {
346 GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
349 gdk_screen_get_monitor_geometry (
350 gtk_window_get_screen (presentation_window),
351 priv->moveback_monitor, &coords);
353 gtk_window_move (presentation_window, coords.x, coords.y);
356 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 /*parent_class = g_type_class_peek_parent (ev_dscwindow_class);*/
365 g_type_class_add_private (g_object_class, sizeof (EvDSCWindowPrivate));
366 g_object_class->dispose = ev_dscwindow_dispose;
370 ev_dscwindow_new (void)
372 EvDSCWindow *ev_dscwindow;
374 ev_dscwindow = g_object_new (EV_TYPE_DSCWINDOW, "type", GTK_WINDOW_TOPLEVEL, NULL);
375 return GTK_WIDGET (ev_dscwindow);