]> www.fi.muni.cz Git - evince.git/blob - shell/ev-dualscreen.c
0f94912e7d9f2bcc918326d711a3315765ac1122
[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
31 struct _EvDSCWindowPrivate {
32         GtkWidget *main_box;
33         GtkWidget *menubar;
34         GtkWidget *overview;
35         GtkWidget *notesview;
36         EvDocumentModel *model;
37         EvDocument * notesdocument;
38
39         GtkWidget *overview_scrolled_window;
40         GtkWidget *notesview_scrolled_window;
41
42         EvWindow *presentation_window;
43         EvDocument * presentation_document;
44         gint moveback_monitor;
45 } EvDSCWindowPrivate;
46
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 */
50
51 /*static gpointer parent_class = NULL;*/
52
53 G_DEFINE_TYPE (EvDSCWindow, ev_dscwindow, GTK_TYPE_WINDOW)
54
55 /**
56  * ev_dscwindow_switch_monitors: Bring the presentation window and the control window each on the other monitor.
57  *
58  * @widget: Callback widget
59  * @self: EvDSCWindow
60  **/
61 static gboolean
62 ev_dscwindow_switch_monitors (GtkWidget *widget, EvDSCWindow *self)
63 {
64 /*
65 +       if (!EV_IS_DSCWINDOW (self))
66 +               return FALSE;
67 +
68 +       EvDSCWindowPrivate *priv = EV_DSCWINDOW_GET_PRIVATE (self);
69 +
70 +       gint num_monitors = get_num_monitors (GTK_WINDOW (self));
71 +
72 +       if (num_monitors == 2) {
73 +               GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
74 +               GdkScreen * screen = gtk_window_get_screen (presentation_window);
75 +
76 +               gint monitor_1 = gdk_screen_get_monitor_at_window (screen,
77 +                       GTK_WIDGET (presentation_window)->window);
78 +
79 +               gint monitor_2 = (monitor_1 + 1) % 2;
80 +
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;
87 +
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));
92 +       }*/
93         return TRUE;
94 }
95
96 /**
97  * ev_dscwindow_notes_interaction: User wants to load a different file as notes.
98  **/
99 static gboolean
100 ev_dscwindow_notes_interaction (GtkContainer *container, EvDSCWindow *self)
101 {
102 /*
103 +       EvDSCWindowPrivate *priv = EV_DSCWINDOW_GET_PRIVATE (self);
104 +       GtkWidget *dialog;
105 +
106 +       dialog = gtk_file_chooser_dialog_new (
107 +               _("Open Document"),
108 +               GTK_WINDOW (self),
109 +               GTK_FILE_CHOOSER_ACTION_OPEN,
110 +               GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
111 +               GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
112 +               NULL);
113 +
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);
117 +
118 +       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
119 +       {
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);
123 +
124 +               if (priv->notesdocument) {
125 +                       ev_document_load (priv->notesdocument, uri, &error);
126 +               } else {
127 +                       priv->notesdocument = ev_document_factory_get_document (uri,
128 +                               &error);
129 +               }
130 +               g_free (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. *//*
136 +               }
137 +       }
138 +       gtk_widget_destroy (dialog);
139 */
140         return TRUE;
141 }
142
143 /**
144  * ev_dscwindow_end: Stop presentation mode.
145  */
146 static gboolean
147 ev_dscwindow_end (GtkWidget *widget, GdkEvent *event)
148 {
149         gtk_widget_destroy (GTK_WIDGET (ev_dscwindow_get_control ()));
150         return TRUE;
151 }
152
153
154
155 /**
156 * ev_dscwindow_init: Initialize multihead presentation
157 *
158 * @self: EvDSCWindow.
159 *
160 * ev_dscwindow_set_presentation has to be called afterwards for loading in a document. TBD
161 **/
162 static void
163 ev_dscwindow_init (EvDSCWindow *ev_dscwindow)
164 {
165         ev_dscwindow->priv = EV_DSCWINDOW_GET_PRIVATE (ev_dscwindow);
166         ev_dscwindow->priv->moveback_monitor = -1;
167         ev_dscwindow->priv->notesdocument = NULL;
168
169         gtk_window_set_title (GTK_WINDOW (self), _("Presentation Control"));
170
171         GtkWidget *h = gtk_hpaned_new ();
172         GtkWidget *v = gtk_vbox_new (FALSE, 0);
173
174         ev_dscwindow->priv->overview_scrolled_window = GTK_WIDGET (g_object_new (
175                         GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, NULL));
176         gtk_box_pack_start_defaults (GTK_BOX (v), priv->overview_scrolled_window);
177
178         ev_dscwindow->priv->model = ev_document_model_new ();
179         ev_dscwindow->priv->overview = ev_view_new ();
180         ev_view_set_page_cache_size (EV_VIEW (ev_dscwindow->priv->overview), PAGE_CACHE_SIZE);
181         ev_view_set_model (EV_VIEW (ev_dscwindow->priv->overview), ev_dscwindow->priv->model);
182         ev_document_model_set_continuous (ev_dscwindow->priv->model, TRUE);
183         ev_document_model_set_dual_page (ev_dscwindow->priv->model, FALSE);
184         ev_document_model_set_sizing_mode (ev_dscwindow->priv->model, EV_SIZING_BEST_FIT);
185
186
187         gtk_container_add (GTK_CONTAINER (priv->overview_scrolled_window),
188                                    priv->overview);
189
190
191         GtkWidget *e = gtk_expander_new (_("Expensive features"));
192         gtk_expander_set_expanded (GTK_EXPANDER (e), TRUE);
193
194         GtkWidget *t = gtk_toolbar_new ();
195
196         GtkToolItem* b_switch = gtk_tool_button_new (NULL, _("Switch monitors"));
197         gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_switch), "object-flip-horizontal");
198         gtk_toolbar_insert (GTK_TOOLBAR (t), b_switch, -1);
199         g_signal_connect (b_switch, "clicked",
200                 G_CALLBACK (ev_dscwindow_switch_monitors), self);
201
202         GtkToolItem* b_notes = gtk_tool_button_new (NULL, _("Load notes ..."));
203         gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_notes), "object-flip-horizontal");
204         gtk_toolbar_insert (GTK_TOOLBAR (t), b_notes, -1);
205         g_signal_connect (b_notes, "clicked",
206                 G_CALLBACK (ev_dscwindow_notes_interaction), self);
207
208         GtkToolItem* b_close = gtk_tool_button_new (NULL, _("End presentation"));
209         gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_close), "view-restore");
210         gtk_toolbar_insert (GTK_TOOLBAR (t), b_close, -1);
211         g_signal_connect (b_close, "clicked",
212                 G_CALLBACK (ev_dscwindow_end), NULL);
213
214         gtk_container_add (GTK_CONTAINER (e), t);
215         gtk_box_pack_end (GTK_BOX (v), e, FALSE, TRUE, 0);
216         gtk_paned_add1 (GTK_PANED (h), v);
217
218 /*
219         priv->notesview_scrolled_window = GTK_WIDGET (g_object_new (
220                 GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, NULL));
221         gtk_paned_add2 (GTK_PANED (h), priv->notesview_scrolled_window);
222
223         priv->notesview = ev_view_new ();
224         g_object_ref (priv->notesview);
225         ev_view_set_screen_dpi (EV_VIEW (priv->notesview),
226                                 get_screen_dpi (GTK_WINDOW (self)));
227 +               gtk_container_add (GTK_CONTAINER (priv->notesview_scrolled_window),
228 +                                  priv->notesview);
229 +
230 +               ev_view_set_continuous (EV_VIEW (priv->notesview), FALSE);
231 +               ev_view_set_dual_page (EV_VIEW (priv->notesview), FALSE);
232 +               ev_view_set_sizing_mode (EV_VIEW (priv->notesview), EV_SIZING_BEST_FIT);
233 +       }
234 +
235 +       gtk_paned_set_position (GTK_PANED (h), 400);
236 +       gtk_widget_show_all (h);
237 +       gtk_container_add (GTK_CONTAINER (self), h);
238 +
239 +       /* fallback if we have >2 monitors (see window placement) */
240 /*+     gtk_window_set_default_size (GTK_WINDOW (self), 800, 600);
241 +
242 +       g_signal_connect (h, "notify::position",
243 +               G_CALLBACK (ev_dscwindow_handle_resized), self);
244 +
245 +       g_signal_connect (self, "size-allocate",
246 +               G_CALLBACK (ev_dscwindow_handle_resized), self);
247 +
248 +       /* This would just open new windows. */
249 /*+     gtk_drag_dest_unset (GTK_WIDGET (priv->notesview));
250 +       gtk_drag_dest_unset (GTK_WIDGET (priv->overview));
251 +
252 +       gint click = GDK_BUTTON1_MOTION_MASK | GDK_KEY_PRESS_MASK;
253 +       gtk_widget_add_events (GTK_WIDGET (priv->overview), click);
254 +       g_signal_connect (priv->notesview, "button-press-event",
255 +                         G_CALLBACK (ev_dscwindow_notes_clicked), self);
256 */
257 }
258
259
260 static void
261 ev_dscwindow_dispose (GObject *obj)
262 {
263         EvDSCWindow * self = EV_DSCWINDOW (obj);
264         EvDSCWindowPrivate *priv = ev_dscwindow->priv;
265
266 /*      if (EV_IS_VIEW (priv->overview) {
267                 ev_document_model_set_document (priv->model, NULL);
268
269 +               ev_view_set_document (EV_VIEW (priv->overview),  NULL);
270 +               g_object_unref (priv->overview);
271 +       }
272 +       if (EV_IS_VIEW (priv->notesview)) {
273 +               ev_view_set_document (EV_VIEW (priv->notesview), NULL);
274 +               g_object_unref (priv->notesview);
275 +       }*/
276         ev_window_stop_presentation (priv->presentation_window);
277
278         if (priv->moveback_monitor >= 0) {
279                 GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
280                 GdkRectangle coords;
281
282                 gdk_screen_get_monitor_geometry (
283                         gtk_window_get_screen (presentation_window),
284                         priv->moveback_monitor, &coords);
285
286                 gtk_window_move (presentation_window, coords.x, coords.y);
287         }
288
289         G_OBJECT_CLASS (parent_class)->dispose (obj);
290 }
291
292
293 static void
294 ev_dscwindow_class_init (EvDSCWindowClass * klass)
295 {
296 /*      GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
297  *      parent_class = g_type_class_peek_parent (klass);
298  *      g_type_class_add_private (klass, sizeof (EvDSCWindowPrivate));
299  *      g_object_class->dispose  = ev_dscwindow_dispose;
300  */
301 }
302
303 GtkWidget *
304 ev_dscwindow_new (void)
305 {
306         EvDSCWindow *dsc_window;
307
308         dsc_window = g_object_new (EV_TYPE_DSCWINDOW, "type", GTK_WINDOW_TOPLEVEL, NULL);
309         return GTK_WIDGET (dsc_window);
310 }