]> www.fi.muni.cz Git - evince.git/blob - backend/ev-document.c
6238ac54b93d01f6e8d0b0c31adfb303f5ca3150
[evince.git] / backend / ev-document.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /*
3  *  Copyright (C) 2004 Marco Pesenti Gritti
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  */
20
21 #include "config.h"
22
23 #include "ev-document.h"
24
25 #include "ev-backend-marshalers.h"
26 #include "ev-job-queue.h"
27
28 static void ev_document_class_init (gpointer g_class);
29
30 enum
31 {
32         PAGE_CHANGED,
33         SCALE_CHANGED,
34         LAST_SIGNAL
35 };
36
37 static guint signals[LAST_SIGNAL] = { 0 };
38 GMutex *ev_doc_mutex = NULL;
39
40
41 #define LOG(x) 
42 GType
43 ev_document_get_type (void)
44 {
45         static GType type = 0;
46
47         if (G_UNLIKELY (type == 0))
48         {
49                 static const GTypeInfo our_info =
50                 {
51                         sizeof (EvDocumentIface),
52                         NULL,
53                         NULL,
54                         (GClassInitFunc)ev_document_class_init
55                 };
56
57                 type = g_type_register_static (G_TYPE_INTERFACE,
58                                                "EvDocument",
59                                                &our_info, (GTypeFlags)0);
60         }
61
62         return type;
63 }
64
65 GQuark
66 ev_document_error_quark (void)
67 {
68   static GQuark q = 0;
69   if (q == 0)
70     q = g_quark_from_static_string ("ev-document-error-quark");
71
72   return q;
73 }
74
75 static void
76 ev_document_class_init (gpointer g_class)
77 {
78         signals[PAGE_CHANGED] =
79                 g_signal_new ("page_changed",
80                               EV_TYPE_DOCUMENT,
81                               G_SIGNAL_RUN_LAST,
82                               G_STRUCT_OFFSET (EvDocumentIface, page_changed),
83                               NULL, NULL,
84                               g_cclosure_marshal_VOID__VOID,
85                               G_TYPE_NONE,
86                               0);
87
88         signals[SCALE_CHANGED] =
89                 g_signal_new ("scale_changed",
90                               EV_TYPE_DOCUMENT,
91                               G_SIGNAL_RUN_LAST,
92                               G_STRUCT_OFFSET (EvDocumentIface, scale_changed),
93                               NULL, NULL,
94                               g_cclosure_marshal_VOID__VOID,
95                               G_TYPE_NONE,
96                               0);
97
98         g_object_interface_install_property (g_class,
99                                 g_param_spec_string ("title",
100                                                      "Document Title",
101                                                      "The title of the document",
102                                                      NULL,
103                                                      G_PARAM_READABLE));
104 }
105
106 #define PAGE_CACHE_STRING "ev-page-cache"
107
108 EvPageCache *
109 ev_document_get_page_cache (EvDocument *document)
110 {
111         EvPageCache *page_cache;
112
113         g_return_val_if_fail (EV_IS_DOCUMENT (document), NULL);
114
115         page_cache = g_object_get_data (G_OBJECT (document), PAGE_CACHE_STRING);
116         if (page_cache == NULL) {
117                 page_cache = _ev_page_cache_new (document);
118                 g_object_set_data_full (G_OBJECT (document), PAGE_CACHE_STRING, page_cache, g_object_unref);
119         }
120
121         return page_cache;
122 }
123
124 GMutex *
125 ev_document_get_doc_mutex (void)
126 {
127         if (ev_doc_mutex == NULL) {
128                 ev_doc_mutex = g_mutex_new ();
129         }
130         return ev_doc_mutex;
131 }
132
133
134 gboolean
135 ev_document_load (EvDocument  *document,
136                   const char  *uri,
137                   GError     **error)
138 {
139         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
140         gboolean retval;
141         LOG ("ev_document_load");
142         retval = iface->load (document, uri, error);
143         /* Call this to make the initial cached copy */
144         ev_document_get_page_cache (document);
145         return retval;
146 }
147
148 gboolean
149 ev_document_save (EvDocument  *document,
150                   const char  *uri,
151                   GError     **error)
152 {
153         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
154         gboolean retval;
155
156         LOG ("ev_document_save");
157         retval = iface->save (document, uri, error);
158
159         return retval;
160 }
161
162 char *
163 ev_document_get_title (EvDocument  *document)
164 {
165         char *title;
166
167         LOG ("ev_document_get_title");
168         g_object_get (document, "title", &title, NULL);
169
170         return title;
171 }
172
173 int
174 ev_document_get_n_pages (EvDocument  *document)
175 {
176         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
177         gint retval;
178
179         LOG ("ev_document_get_n_pages");
180         retval = iface->get_n_pages (document);
181
182         return retval;
183 }
184
185 void
186 ev_document_set_page (EvDocument  *document,
187                       int          page)
188 {
189         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
190
191         LOG ("ev_document_set_page");
192         iface->set_page (document, page);
193 }
194
195 int
196 ev_document_get_page (EvDocument *document)
197 {
198         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
199         int retval;
200
201         LOG ("ev_document_get_page");
202         retval = iface->get_page (document);
203
204         return retval;
205 }
206
207 void
208 ev_document_set_target (EvDocument  *document,
209                         GdkDrawable *target)
210 {
211         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
212
213         LOG ("ev_document_set_target");
214         iface->set_target (document, target);
215 }
216
217 void
218 ev_document_set_scale (EvDocument   *document,
219                        double        scale)
220 {
221         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
222
223         LOG ("ev_document_set_scale");
224         iface->set_scale (document, scale);
225 }
226
227 void
228 ev_document_set_page_offset (EvDocument  *document,
229                              int          x,
230                              int          y)
231 {
232         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
233
234         LOG ("ev_document_set_page_offset");
235         iface->set_page_offset (document, x, y);
236 }
237
238 void
239 ev_document_get_page_size   (EvDocument   *document,
240                              int           page,
241                              int          *width,
242                              int          *height)
243 {
244         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
245
246         LOG ("ev_document_get_page_size");
247         iface->get_page_size (document, page, width, height);
248 }
249
250 char *
251 ev_document_get_text (EvDocument   *document,
252                       GdkRectangle *rect)
253 {
254         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
255         char *retval;
256
257         LOG ("ev_document_get_text");
258         retval = iface->get_text (document, rect);
259
260         return retval;
261 }
262
263 EvLink *
264 ev_document_get_link (EvDocument   *document,
265                       int           x,
266                       int           y)
267 {
268         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
269         EvLink *retval;
270
271         LOG ("ev_document_get_link");
272         retval = iface->get_link (document, x, y);
273
274         return retval;
275 }
276
277 void
278 ev_document_render (EvDocument  *document,
279                     int          clip_x,
280                     int          clip_y,
281                     int          clip_width,
282                     int          clip_height)
283 {
284         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
285
286         LOG ("ev_document_render");
287         iface->render (document, clip_x, clip_y, clip_width, clip_height);
288 }
289
290
291 GdkPixbuf *
292 ev_document_render_pixbuf (EvDocument *document)
293 {
294         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
295         GdkPixbuf *retval;
296
297         LOG ("ev_document_render_pixbuf");
298         g_assert (iface->render_pixbuf);
299
300         retval = iface->render_pixbuf (document);
301
302         return retval;
303 }
304
305
306 void
307 ev_document_page_changed (EvDocument *document)
308 {
309         g_signal_emit (G_OBJECT (document), signals[PAGE_CHANGED], 0);
310 }
311
312 void
313 ev_document_scale_changed (EvDocument *document)
314 {
315         g_signal_emit (G_OBJECT (document), signals[SCALE_CHANGED], 0);
316 }