]> www.fi.muni.cz Git - evince.git/blob - shell/ev-dualscreen.c
[dualscreen] widget placement
[evince.git] / shell / ev-dualscreen.c
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
3  *
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <glib/gi18n.h>
25 #include <gtk/gtk.h>
26
27 #include "ev-dualscreen.h"
28 #include "ev-window.h"
29 #include "ev-view.h"
30 #include "ev-utils.h"
31 #include "ev-sidebar.h"
32 #include "ev-sidebar-thumbnails.h"
33
34 struct _EvDSCWindowPrivate {
35         GtkWidget *main_box;
36         GtkWidget *menubar;
37         GtkWidget *overview;
38         GtkWidget *notesview;
39         EvDocumentModel *model;
40         EvDocument * notesdocument;
41
42         GtkWidget *overview_scrolled_window;
43         GtkWidget *notesview_scrolled_window;
44
45         EvWindow *presentation_window;
46         EvDocument * presentation_document;
47         gint moveback_monitor;
48 };
49
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 */
53
54 /*static gpointer parent_class = NULL;*/
55
56 G_DEFINE_TYPE (EvDSCWindow, ev_dscwindow, GTK_TYPE_WINDOW)
57
58 /**
59  * ev_dscwindow_switch_monitors: Bring the presentation window and the control window each on the other monitor.
60  *
61  * @widget: Callback widget
62  * @self: EvDSCWindow
63  **/
64 static gboolean
65 ev_dscwindow_switch_monitors (GtkWidget *widget, EvDSCWindow *self)
66 {
67 /*
68 +       if (!EV_IS_DSCWINDOW (self))
69 +               return FALSE;
70 +
71 +       EvDSCWindowPrivate *priv = EV_DSCWINDOW_GET_PRIVATE (self);
72 +
73 +       gint num_monitors = get_num_monitors (GTK_WINDOW (self));
74 +
75 +       if (num_monitors == 2) {
76 +               GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
77 +               GdkScreen * screen = gtk_window_get_screen (presentation_window);
78 +
79 +               gint monitor_1 = gdk_screen_get_monitor_at_window (screen,
80 +                       GTK_WIDGET (presentation_window)->window);
81 +
82 +               gint monitor_2 = (monitor_1 + 1) % 2;
83 +
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;
90 +
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));
95 +       }*/
96         return TRUE;
97 }
98
99 /**
100  * ev_dscwindow_notes_interaction: User wants to load a different file as notes.
101  **/
102 static gboolean
103 ev_dscwindow_notes_interaction (GtkContainer *container, EvDSCWindow *self)
104 {
105 /*
106 +       EvDSCWindowPrivate *priv = EV_DSCWINDOW_GET_PRIVATE (self);
107 +       GtkWidget *dialog;
108 +
109 +       dialog = gtk_file_chooser_dialog_new (
110 +               _("Open Document"),
111 +               GTK_WINDOW (self),
112 +               GTK_FILE_CHOOSER_ACTION_OPEN,
113 +               GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
114 +               GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
115 +               NULL);
116 +
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);
120 +
121 +       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
122 +       {
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);
126 +
127 +               if (priv->notesdocument) {
128 +                       ev_document_load (priv->notesdocument, uri, &error);
129 +               } else {
130 +                       priv->notesdocument = ev_document_factory_get_document (uri,
131 +                               &error);
132 +               }
133 +               g_free (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. *//*
139 +               }
140 +       }
141 +       gtk_widget_destroy (dialog);
142 */
143         return TRUE;
144 }
145
146 /**
147  * ev_dscwindow_get_control: Get the control instance.
148  *
149  * If there is none, create one.
150  *
151  * Returns: control instance
152  **/
153 EvDSCWindow *
154 ev_dscwindow_get_control (void)
155 {
156         static EvDSCWindow * control = NULL;
157
158         if (!control || !EV_IS_DSCWINDOW (control)) {
159                 control = EV_DSCWINDOW (g_object_new (EV_TYPE_DSCWINDOW, NULL));
160         }
161
162         return control;
163 }
164
165 /*TODO: Fix me!*/
166 static void
167 ev_dscwindow_window_placement (EvDSCWindow *ev_dscwindow)
168 {
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);
173
174                 gint work_monitor = gdk_screen_get_monitor_at_window (screen,
175                         gtk_widget_get_window (GTK_WIDGET (presentation_window)));
176
177                 gint presentation_monitor = (work_monitor + 1) % 2;
178
179                 GdkRectangle coords;
180                 gdk_screen_get_monitor_geometry (screen, presentation_monitor,
181                         &coords);
182
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;
186
187                 gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
188         }
189 }
190
191
192 /**
193  * ev_dscwindow_set_presentation: Set presentation document
194  * @presentation_window: Main window we can reuse for presentation
195  **/
196 void
197 ev_dscwindow_set_presentation (EvDSCWindow *ev_dscwindow,
198         EvWindow *presentation_window, EvDocument *document)
199 {
200         if (!EV_IS_WINDOW (presentation_window))
201                 return;
202
203         ev_dscwindow->priv->presentation_window = presentation_window;
204         ev_dscwindow->priv->presentation_document = document;
205
206         ev_document_model_set_document(ev_dscwindow->priv->model,
207                 document);
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);
212         */
213 }
214
215 /**
216  * ev_dscwindow_end: Stop presentation mode.
217  */
218 static gboolean
219 ev_dscwindow_end (GtkWidget *widget, GdkEvent *event)
220 {
221         gtk_widget_destroy (GTK_WIDGET (ev_dscwindow_get_control ()));
222         return TRUE;
223 }
224
225 /**
226 * ev_dscwindow_init: Initialize multihead presentation
227 *
228 * @self: EvDSCWindow.
229 *
230 * ev_dscwindow_set_presentation has to be called afterwards for loading in a document. TBD
231 **/
232 static void
233 ev_dscwindow_init (EvDSCWindow *ev_dscwindow)
234 {
235         ev_dscwindow->priv = EV_DSCWINDOW_GET_PRIVATE (ev_dscwindow);
236         ev_dscwindow->priv->moveback_monitor = -1;
237         ev_dscwindow->priv->notesdocument = NULL;
238
239         gtk_window_set_title (GTK_WINDOW (ev_dscwindow), _("Presentation Control"));
240
241         GtkWidget *h = gtk_hpaned_new ();
242         GtkWidget *v = gtk_vbox_new (FALSE, 0);
243
244         ev_dscwindow->priv->model = ev_document_model_new ();
245
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_box_pack_start (GTK_BOX (v), ev_dscwindow->priv->overview, TRUE, TRUE, 0);
252         gtk_widget_show (ev_dscwindow->priv->overview);
253
254         /* Stub sidebar, for now */
255
256         GtkWidget *sidebar_widget;
257         sidebar_widget = ev_sidebar_thumbnails_new ();
258         /*ev_window->priv->sidebar_thumbs = sidebar_widget;*/
259         /*g_signal_connect (sidebar_widget,
260                           "notify::main-widget",
261                           G_CALLBACK (sidebar_page_main_widget_update_cb),
262                           ev_window);
263         sidebar_page_main_widget_update_cb (G_OBJECT (sidebar_widget), NULL, ev_window);*/
264         gtk_widget_show (sidebar_widget);
265         ev_sidebar_add_page (EV_SIDEBAR (ev_dscwindow->priv->overview),
266                              sidebar_widget);
267
268 /*      ev_dscwindow->priv->overview_scrolled_window = GTK_WIDGET (g_object_new (
269                         GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, NULL));
270         gtk_box_pack_start (GTK_BOX (v), ev_dscwindow->priv->overview_scrolled_window, TRUE, TRUE, 0);
271
272
273         ev_dscwindow->priv->overview = ev_view_new ();
274         ev_view_set_page_cache_size (EV_VIEW (ev_dscwindow->priv->overview), PAGE_CACHE_SIZE);
275         ev_view_set_model (EV_VIEW (ev_dscwindow->priv->overview), ev_dscwindow->priv->model);*/
276
277         ev_document_model_set_continuous (ev_dscwindow->priv->model, TRUE);
278         ev_document_model_set_dual_page (ev_dscwindow->priv->model, FALSE);
279         ev_document_model_set_sizing_mode (ev_dscwindow->priv->model, EV_SIZING_BEST_FIT);
280
281
282 /*      gtk_container_add (GTK_CONTAINER (ev_dscwindow->priv->overview_scrolled_window),
283                                    ev_dscwindow->priv->overview);
284         */
285
286         GtkWidget *e = gtk_expander_new (_("Expensive features"));
287         gtk_expander_set_expanded (GTK_EXPANDER (e), TRUE);
288
289         GtkWidget *t = gtk_toolbar_new ();
290
291         GtkToolItem* b_switch = gtk_tool_button_new (NULL, _("Switch monitors"));
292         gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_switch), "object-flip-horizontal");
293         gtk_toolbar_insert (GTK_TOOLBAR (t), b_switch, -1);
294         g_signal_connect (b_switch, "clicked",
295                 G_CALLBACK (ev_dscwindow_switch_monitors), ev_dscwindow);
296
297         GtkToolItem* b_notes = gtk_tool_button_new (NULL, _("Load notes ..."));
298         gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_notes), "object-flip-horizontal");
299         gtk_toolbar_insert (GTK_TOOLBAR (t), b_notes, -1);
300         g_signal_connect (b_notes, "clicked",
301                 G_CALLBACK (ev_dscwindow_notes_interaction), ev_dscwindow);
302
303         GtkToolItem* b_close = gtk_tool_button_new (NULL, _("End presentation"));
304         gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_close), "view-restore");
305         gtk_toolbar_insert (GTK_TOOLBAR (t), b_close, -1);
306         g_signal_connect (b_close, "clicked",
307                 G_CALLBACK (ev_dscwindow_end), NULL);
308
309         gtk_container_add (GTK_CONTAINER (e), t);
310         gtk_box_pack_end (GTK_BOX (v), e, FALSE, TRUE, 0);
311         gtk_paned_add1 (GTK_PANED (h), v);
312
313         ev_dscwindow->priv->notesview_scrolled_window = GTK_WIDGET (g_object_new (
314                 GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, NULL));
315         gtk_paned_add2 (GTK_PANED (h), ev_dscwindow->priv->notesview_scrolled_window);
316
317         ev_dscwindow->priv->notesview = ev_view_new ();
318         g_object_ref (ev_dscwindow->priv->notesview);
319         gtk_container_add (GTK_CONTAINER (ev_dscwindow->priv->notesview_scrolled_window),
320                 ev_dscwindow->priv->notesview);
321         ev_view_set_model (EV_VIEW (ev_dscwindow->priv->notesview), ev_dscwindow->priv->model);
322
323         gtk_paned_set_position (GTK_PANED (h), 400);
324         gtk_widget_show_all (h);
325         gtk_container_add (GTK_CONTAINER (ev_dscwindow), h);
326
327 /* fallback if we have >2 monitors (see window placement) */
328 /*+     gtk_window_set_default_size (GTK_WINDOW (self), 800, 600);
329 +
330 +       g_signal_connect (h, "notify::position",
331 +               G_CALLBACK (ev_dscwindow_handle_resized), self);
332 +
333 +       g_signal_connect (self, "size-allocate",
334 +               G_CALLBACK (ev_dscwindow_handle_resized), self);
335 +
336 +       /* This would just open new windows. */
337 /*+     gtk_drag_dest_unset (GTK_WIDGET (priv->notesview));
338 +       gtk_drag_dest_unset (GTK_WIDGET (priv->overview));
339 +
340 +       gint click = GDK_BUTTON1_MOTION_MASK | GDK_KEY_PRESS_MASK;
341 +       gtk_widget_add_events (GTK_WIDGET (priv->overview), click);
342 +       g_signal_connect (priv->notesview, "button-press-event",
343 +                         G_CALLBACK (ev_dscwindow_notes_clicked), self);
344 */
345 }
346
347
348 static void
349 ev_dscwindow_dispose (GObject *obj)
350 {
351         EvDSCWindow * ev_dscwindow = EV_DSCWINDOW (obj);
352         EvDSCWindowPrivate *priv = ev_dscwindow->priv;
353
354 /*      if (EV_IS_VIEW (priv->overview) {
355                 ev_document_model_set_document (priv->model, NULL);
356
357 +               ev_view_set_document (EV_VIEW (priv->overview),  NULL);
358 +               g_object_unref (priv->overview);
359 +       }
360 +       if (EV_IS_VIEW (priv->notesview)) {
361 +               ev_view_set_document (EV_VIEW (priv->notesview), NULL);
362 +               g_object_unref (priv->notesview);
363 +       }*/
364 /*TODO: save fulscreen state*/
365         ev_window_stop_presentation (priv->presentation_window, 0);
366
367         if (priv->moveback_monitor >= 0) {
368                 GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
369                 GdkRectangle coords;
370
371                 gdk_screen_get_monitor_geometry (
372                         gtk_window_get_screen (presentation_window),
373                         priv->moveback_monitor, &coords);
374
375                 gtk_window_move (presentation_window, coords.x, coords.y);
376         }
377
378         G_OBJECT_CLASS (ev_dscwindow_parent_class)->dispose (obj);
379 }
380
381
382 static void
383 ev_dscwindow_class_init (EvDSCWindowClass *ev_dscwindow_class)
384 {
385         GObjectClass *g_object_class = G_OBJECT_CLASS (ev_dscwindow_class);
386         /*parent_class = g_type_class_peek_parent (ev_dscwindow_class);*/
387         g_type_class_add_private (g_object_class, sizeof (EvDSCWindowPrivate));
388         g_object_class->dispose  = ev_dscwindow_dispose;
389 }
390
391 GtkWidget *
392 ev_dscwindow_new (void)
393 {
394         EvDSCWindow *ev_dscwindow;
395
396         ev_dscwindow = g_object_new (EV_TYPE_DSCWINDOW, "type", GTK_WINDOW_TOPLEVEL, NULL);
397         return GTK_WIDGET (ev_dscwindow);
398 }