1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
3 * Copyright (C) 2004 Marco Pesenti Gritti
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)
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.
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.
23 #include "ev-document.h"
25 #include "ev-backend-marshalers.h"
26 #include "ev-job-queue.h"
28 static void ev_document_class_init (gpointer g_class);
37 static guint signals[LAST_SIGNAL] = { 0 };
38 GMutex *ev_doc_mutex = NULL;
43 ev_document_get_type (void)
45 static GType type = 0;
47 if (G_UNLIKELY (type == 0))
49 static const GTypeInfo our_info =
51 sizeof (EvDocumentIface),
54 (GClassInitFunc)ev_document_class_init
57 type = g_type_register_static (G_TYPE_INTERFACE,
59 &our_info, (GTypeFlags)0);
66 ev_document_error_quark (void)
70 q = g_quark_from_static_string ("ev-document-error-quark");
76 ev_document_class_init (gpointer g_class)
78 signals[PAGE_CHANGED] =
79 g_signal_new ("page_changed",
82 G_STRUCT_OFFSET (EvDocumentIface, page_changed),
84 g_cclosure_marshal_VOID__VOID,
88 signals[SCALE_CHANGED] =
89 g_signal_new ("scale_changed",
92 G_STRUCT_OFFSET (EvDocumentIface, scale_changed),
94 g_cclosure_marshal_VOID__VOID,
98 g_object_interface_install_property (g_class,
99 g_param_spec_string ("title",
101 "The title of the document",
106 #define PAGE_CACHE_STRING "ev-page-cache"
109 ev_document_get_page_cache (EvDocument *document)
111 EvPageCache *page_cache;
113 g_return_val_if_fail (EV_IS_DOCUMENT (document), NULL);
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);
125 ev_document_get_doc_mutex (void)
127 if (ev_doc_mutex == NULL) {
128 ev_doc_mutex = g_mutex_new ();
135 ev_document_load (EvDocument *document,
139 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
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);
149 ev_document_save (EvDocument *document,
153 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
156 LOG ("ev_document_save");
157 retval = iface->save (document, uri, error);
163 ev_document_get_title (EvDocument *document)
167 LOG ("ev_document_get_title");
168 g_object_get (document, "title", &title, NULL);
174 ev_document_get_n_pages (EvDocument *document)
176 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
179 LOG ("ev_document_get_n_pages");
180 retval = iface->get_n_pages (document);
186 ev_document_set_page (EvDocument *document,
189 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
191 LOG ("ev_document_set_page");
192 iface->set_page (document, page);
196 ev_document_get_page (EvDocument *document)
198 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
201 LOG ("ev_document_get_page");
202 retval = iface->get_page (document);
208 ev_document_set_target (EvDocument *document,
211 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
213 LOG ("ev_document_set_target");
214 iface->set_target (document, target);
218 ev_document_set_scale (EvDocument *document,
221 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
223 LOG ("ev_document_set_scale");
224 iface->set_scale (document, scale);
228 ev_document_set_page_offset (EvDocument *document,
232 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
234 LOG ("ev_document_set_page_offset");
235 iface->set_page_offset (document, x, y);
239 ev_document_get_page_size (EvDocument *document,
244 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
246 LOG ("ev_document_get_page_size");
247 iface->get_page_size (document, page, width, height);
251 ev_document_get_text (EvDocument *document,
254 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
257 LOG ("ev_document_get_text");
258 retval = iface->get_text (document, rect);
264 ev_document_get_link (EvDocument *document,
268 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
271 LOG ("ev_document_get_link");
272 retval = iface->get_link (document, x, y);
278 ev_document_render (EvDocument *document,
284 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
286 LOG ("ev_document_render");
287 iface->render (document, clip_x, clip_y, clip_width, clip_height);
292 ev_document_render_pixbuf (EvDocument *document)
294 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
297 LOG ("ev_document_render_pixbuf");
298 g_assert (iface->render_pixbuf);
300 retval = iface->render_pixbuf (document);
307 ev_document_page_changed (EvDocument *document)
309 g_signal_emit (G_OBJECT (document), signals[PAGE_CHANGED], 0);
313 ev_document_scale_changed (EvDocument *document)
315 g_signal_emit (G_OBJECT (document), signals[SCALE_CHANGED], 0);