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 #include "ev-sidebar.h"
32 #include "ev-sidebar-thumbnails.h"
34 struct _EvDSCWindowPrivate {
39 EvDocumentModel *model;
40 EvDocument * notesdocument;
42 GtkWidget *overview_scrolled_window;
43 GtkWidget *notesview_scrolled_window;
45 EvWindow *presentation_window;
46 EvDocument * presentation_document;
47 gint moveback_monitor;
50 #define EV_DSCWINDOW_GET_PRIVATE(object) \
51 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_DSCWINDOW, EvDSCWindowPrivate))
52 #define PAGE_CACHE_SIZE 52428800 /* 50MB */
54 /*static gpointer parent_class = NULL;*/
56 G_DEFINE_TYPE (EvDSCWindow, ev_dscwindow, GTK_TYPE_WINDOW)
59 * ev_dscwindow_switch_monitors: Bring the presentation window and the control window each on the other monitor.
61 * @widget: Callback widget
65 ev_dscwindow_switch_monitors (GtkWidget *widget, EvDSCWindow *self)
68 + if (!EV_IS_DSCWINDOW (self))
71 + EvDSCWindowPrivate *priv = EV_DSCWINDOW_GET_PRIVATE (self);
73 + gint num_monitors = get_num_monitors (GTK_WINDOW (self));
75 + if (num_monitors == 2) {
76 + GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
77 + GdkScreen * screen = gtk_window_get_screen (presentation_window);
79 + gint monitor_1 = gdk_screen_get_monitor_at_window (screen,
80 + GTK_WIDGET (presentation_window)->window);
82 + gint monitor_2 = (monitor_1 + 1) % 2;
84 + GdkRectangle coords;
85 + gdk_screen_get_monitor_geometry (screen, monitor_2, &coords);
86 + ev_window_stop_presentation (priv->presentation_window);
87 + gtk_window_move (presentation_window, coords.x, coords.y);
88 + ev_window_run_presentation (priv->presentation_window);
89 + priv->moveback_monitor = monitor_1;
91 + gdk_screen_get_monitor_geometry (screen, monitor_1, &coords);
92 + gtk_window_unmaximize (GTK_WINDOW (self));
93 + gtk_window_move (GTK_WINDOW (self), coords.x, coords.y);
94 + gtk_window_maximize (GTK_WINDOW (self));
100 * ev_dscwindow_notes_interaction: User wants to load a different file as notes.
103 ev_dscwindow_notes_interaction (GtkContainer *container, EvDSCWindow *self)
106 + EvDSCWindowPrivate *priv = EV_DSCWINDOW_GET_PRIVATE (self);
109 + dialog = gtk_file_chooser_dialog_new (
110 + _("Open Document"),
112 + GTK_FILE_CHOOSER_ACTION_OPEN,
113 + GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
114 + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
117 + ev_document_factory_add_filters (dialog, NULL);
118 + gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), FALSE);
119 + gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), TRUE);
121 + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
123 + char * uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
124 + GError * error = NULL;
125 + ev_view_set_loading (EV_VIEW (priv->notesview), TRUE);
127 + if (priv->notesdocument) {
128 + ev_document_load (priv->notesdocument, uri, &error);
130 + priv->notesdocument = ev_document_factory_get_document (uri,
134 + if (error == NULL){
135 + ev_view_set_document (EV_VIEW (priv->notesview),
136 + priv->notesdocument);
137 + /* TODO: go to the same page that is open at the moment, or
138 + * move the presentation to the beginning. *//*
141 + gtk_widget_destroy (dialog);
147 * ev_dscwindow_get_control: Get the control instance.
149 * If there is none, create one.
151 * Returns: control instance
154 ev_dscwindow_get_control (void)
156 static EvDSCWindow * control = NULL;
158 if (!control || !EV_IS_DSCWINDOW (control)) {
159 control = EV_DSCWINDOW (g_object_new (EV_TYPE_DSCWINDOW, NULL));
167 ev_dscwindow_window_placement (EvDSCWindow *ev_dscwindow)
169 gint num_monitors = get_num_monitors (GTK_WINDOW (ev_dscwindow));
170 if (num_monitors == 2) {
171 GtkWindow * presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window);
172 GdkScreen * screen = gtk_window_get_screen (presentation_window);
174 gint work_monitor = gdk_screen_get_monitor_at_window (screen,
175 gtk_widget_get_window (GTK_WIDGET (presentation_window)));
177 gint presentation_monitor = (work_monitor + 1) % 2;
180 gdk_screen_get_monitor_geometry (screen, presentation_monitor,
183 gtk_window_move (presentation_window, coords.x, coords.y);
184 ev_window_run_presentation (ev_dscwindow->priv->presentation_window);
185 ev_dscwindow->priv->moveback_monitor = work_monitor;
187 gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
193 * ev_dscwindow_set_presentation: Set presentation document
194 * @presentation_window: Main window we can reuse for presentation
197 ev_dscwindow_set_presentation (EvDSCWindow *ev_dscwindow,
198 EvWindow *presentation_window, EvDocument *document)
200 if (!EV_IS_WINDOW (presentation_window))
203 ev_dscwindow->priv->presentation_window = presentation_window;
204 ev_dscwindow->priv->presentation_document = document;
206 ev_document_model_set_document(ev_dscwindow->priv->model,
208 /* ev_view_set_document (EV_VIEW (priv->notesview),
209 priv->presentation_document);*/
210 ev_dscwindow_window_placement (ev_dscwindow);
211 /*ev_dscwindow_handle_resized (NULL, NULL, self);
216 * ev_dscwindow_end: Stop presentation mode.
219 ev_dscwindow_end (GtkWidget *widget, GdkEvent *event)
221 gtk_widget_destroy (GTK_WIDGET (ev_dscwindow_get_control ()));
226 * ev_dscwindow_init: Initialize multihead presentation
228 * @self: EvDSCWindow.
230 * ev_dscwindow_set_presentation has to be called afterwards for loading in a document. TBD
233 ev_dscwindow_init (EvDSCWindow *ev_dscwindow)
235 ev_dscwindow->priv = EV_DSCWINDOW_GET_PRIVATE (ev_dscwindow);
236 ev_dscwindow->priv->moveback_monitor = -1;
237 ev_dscwindow->priv->notesdocument = NULL;
239 gtk_window_set_title (GTK_WINDOW (ev_dscwindow), _("Presentation Control"));
241 GtkWidget *h = gtk_hpaned_new ();
242 GtkWidget *v = gtk_vbox_new (FALSE, 0);
244 ev_dscwindow->priv->model = ev_document_model_new ();
246 ev_dscwindow->priv->overview = ev_sidebar_new ();
247 ev_sidebar_set_model (EV_SIDEBAR (ev_dscwindow->priv->overview),
248 ev_dscwindow->priv->model);
249 gtk_paned_pack1 (GTK_PANED (h),
250 ev_dscwindow->priv->overview, FALSE, FALSE);
251 gtk_widget_show (ev_dscwindow->priv->overview);
253 /* Stub sidebar, for now */
255 GtkWidget *sidebar_widget;
256 sidebar_widget = ev_sidebar_thumbnails_new ();
257 /*ev_window->priv->sidebar_thumbs = sidebar_widget;*/
258 /*g_signal_connect (sidebar_widget,
259 "notify::main-widget",
260 G_CALLBACK (sidebar_page_main_widget_update_cb),
262 sidebar_page_main_widget_update_cb (G_OBJECT (sidebar_widget), NULL, ev_window);*/
263 gtk_widget_show (sidebar_widget);
264 ev_sidebar_add_page (EV_SIDEBAR (ev_dscwindow->priv->overview),
267 /* ev_dscwindow->priv->overview_scrolled_window = GTK_WIDGET (g_object_new (
268 GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, NULL));
269 gtk_box_pack_start (GTK_BOX (v), ev_dscwindow->priv->overview_scrolled_window, TRUE, TRUE, 0);
272 ev_dscwindow->priv->overview = ev_view_new ();
273 ev_view_set_page_cache_size (EV_VIEW (ev_dscwindow->priv->overview), PAGE_CACHE_SIZE);
274 ev_view_set_model (EV_VIEW (ev_dscwindow->priv->overview), ev_dscwindow->priv->model);*/
276 ev_document_model_set_continuous (ev_dscwindow->priv->model, TRUE);
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);
281 /* gtk_container_add (GTK_CONTAINER (ev_dscwindow->priv->overview_scrolled_window),
282 ev_dscwindow->priv->overview);
285 GtkWidget *e = gtk_expander_new (_("Expensive features"));
286 gtk_expander_set_expanded (GTK_EXPANDER (e), TRUE);
288 GtkWidget *t = gtk_toolbar_new ();
290 GtkToolItem* b_switch = gtk_tool_button_new (NULL, _("Switch monitors"));
291 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_switch), "object-flip-horizontal");
292 gtk_toolbar_insert (GTK_TOOLBAR (t), b_switch, -1);
293 g_signal_connect (b_switch, "clicked",
294 G_CALLBACK (ev_dscwindow_switch_monitors), ev_dscwindow);
296 GtkToolItem* b_notes = gtk_tool_button_new (NULL, _("Load notes ..."));
297 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_notes), "object-flip-horizontal");
298 gtk_toolbar_insert (GTK_TOOLBAR (t), b_notes, -1);
299 g_signal_connect (b_notes, "clicked",
300 G_CALLBACK (ev_dscwindow_notes_interaction), ev_dscwindow);
302 GtkToolItem* b_close = gtk_tool_button_new (NULL, _("End presentation"));
303 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_close), "view-restore");
304 gtk_toolbar_insert (GTK_TOOLBAR (t), b_close, -1);
305 g_signal_connect (b_close, "clicked",
306 G_CALLBACK (ev_dscwindow_end), NULL);
308 gtk_container_add (GTK_CONTAINER (e), t);
309 gtk_box_pack_end (GTK_BOX (v), e, FALSE, TRUE, 0);
310 gtk_paned_add1 (GTK_PANED (h), v);
312 ev_dscwindow->priv->notesview_scrolled_window = GTK_WIDGET (g_object_new (
313 GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, NULL));
314 gtk_paned_add2 (GTK_PANED (h), ev_dscwindow->priv->notesview_scrolled_window);
316 ev_dscwindow->priv->notesview = ev_view_new ();
317 g_object_ref (ev_dscwindow->priv->notesview);
318 gtk_container_add (GTK_CONTAINER (ev_dscwindow->priv->notesview_scrolled_window),
319 ev_dscwindow->priv->notesview);
320 ev_view_set_model (EV_VIEW (ev_dscwindow->priv->notesview), ev_dscwindow->priv->model);
322 gtk_paned_set_position (GTK_PANED (h), 400);
323 gtk_widget_show_all (h);
324 gtk_container_add (GTK_CONTAINER (ev_dscwindow), h);
326 /* fallback if we have >2 monitors (see window placement) */
327 /*+ gtk_window_set_default_size (GTK_WINDOW (self), 800, 600);
329 + g_signal_connect (h, "notify::position",
330 + G_CALLBACK (ev_dscwindow_handle_resized), self);
332 + g_signal_connect (self, "size-allocate",
333 + G_CALLBACK (ev_dscwindow_handle_resized), self);
335 + /* This would just open new windows. */
336 /*+ gtk_drag_dest_unset (GTK_WIDGET (priv->notesview));
337 + gtk_drag_dest_unset (GTK_WIDGET (priv->overview));
339 + gint click = GDK_BUTTON1_MOTION_MASK | GDK_KEY_PRESS_MASK;
340 + gtk_widget_add_events (GTK_WIDGET (priv->overview), click);
341 + g_signal_connect (priv->notesview, "button-press-event",
342 + G_CALLBACK (ev_dscwindow_notes_clicked), self);
348 ev_dscwindow_dispose (GObject *obj)
350 EvDSCWindow * ev_dscwindow = EV_DSCWINDOW (obj);
351 EvDSCWindowPrivate *priv = ev_dscwindow->priv;
353 /* if (EV_IS_VIEW (priv->overview) {
354 ev_document_model_set_document (priv->model, NULL);
356 + ev_view_set_document (EV_VIEW (priv->overview), NULL);
357 + g_object_unref (priv->overview);
359 + if (EV_IS_VIEW (priv->notesview)) {
360 + ev_view_set_document (EV_VIEW (priv->notesview), NULL);
361 + g_object_unref (priv->notesview);
363 /*TODO: save fulscreen state*/
364 ev_window_stop_presentation (priv->presentation_window, 0);
366 if (priv->moveback_monitor >= 0) {
367 GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
370 gdk_screen_get_monitor_geometry (
371 gtk_window_get_screen (presentation_window),
372 priv->moveback_monitor, &coords);
374 gtk_window_move (presentation_window, coords.x, coords.y);
377 G_OBJECT_CLASS (ev_dscwindow_parent_class)->dispose (obj);
382 ev_dscwindow_class_init (EvDSCWindowClass *ev_dscwindow_class)
384 GObjectClass *g_object_class = G_OBJECT_CLASS (ev_dscwindow_class);
385 /*parent_class = g_type_class_peek_parent (ev_dscwindow_class);*/
386 g_type_class_add_private (g_object_class, sizeof (EvDSCWindowPrivate));
387 g_object_class->dispose = ev_dscwindow_dispose;
391 ev_dscwindow_new (void)
393 EvDSCWindow *ev_dscwindow;
395 ev_dscwindow = g_object_new (EV_TYPE_DSCWINDOW, "type", GTK_WINDOW_TOPLEVEL, NULL);
396 return GTK_WIDGET (ev_dscwindow);