]> www.fi.muni.cz Git - evince.git/blob - backend/ev-document.c
51099692635da14e8afd04cecbc70510c11703e6
[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 #include "ev-backend-marshalers.h"
25
26 static void ev_document_class_init (gpointer g_class);
27
28 enum
29 {
30         PAGE_CHANGED,
31         SCALE_CHANGED,
32         LAST_SIGNAL
33 };
34
35 static guint signals[LAST_SIGNAL] = { 0 };
36
37 GType
38 ev_document_get_type (void)
39 {
40         static GType type = 0;
41
42         if (G_UNLIKELY (type == 0))
43         {
44                 static const GTypeInfo our_info =
45                 {
46                         sizeof (EvDocumentIface),
47                         NULL,
48                         NULL,
49                         (GClassInitFunc)ev_document_class_init
50                 };
51
52                 type = g_type_register_static (G_TYPE_INTERFACE,
53                                                "EvDocument",
54                                                &our_info, (GTypeFlags)0);
55         }
56
57         return type;
58 }
59
60 GQuark
61 ev_document_error_quark (void)
62 {
63   static GQuark q = 0;
64   if (q == 0)
65     q = g_quark_from_static_string ("ev-document-error-quark");
66
67   return q;
68 }
69
70 static void
71 ev_document_class_init (gpointer g_class)
72 {
73         signals[PAGE_CHANGED] =
74                 g_signal_new ("page_changed",
75                               EV_TYPE_DOCUMENT,
76                               G_SIGNAL_RUN_LAST,
77                               G_STRUCT_OFFSET (EvDocumentIface, page_changed),
78                               NULL, NULL,
79                               g_cclosure_marshal_VOID__VOID,
80                               G_TYPE_NONE,
81                               0);
82
83         signals[SCALE_CHANGED] =
84                 g_signal_new ("scale_changed",
85                               EV_TYPE_DOCUMENT,
86                               G_SIGNAL_RUN_LAST,
87                               G_STRUCT_OFFSET (EvDocumentIface, scale_changed),
88                               NULL, NULL,
89                               g_cclosure_marshal_VOID__VOID,
90                               G_TYPE_NONE,
91                               0);
92
93         g_object_interface_install_property (g_class,
94                                 g_param_spec_string ("title",
95                                                      "Document Title",
96                                                      "The title of the document",
97                                                      NULL,
98                                                      G_PARAM_READABLE));
99 }
100
101 gboolean
102 ev_document_load (EvDocument  *document,
103                   const char  *uri,
104                   GError     **error)
105 {
106         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
107         return iface->load (document, uri, error);
108 }
109
110 gboolean
111 ev_document_save (EvDocument  *document,
112                   const char  *uri,
113                   GError     **error)
114 {
115         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
116         return iface->save (document, uri, error);
117 }
118
119 char *
120 ev_document_get_title (EvDocument  *document)
121 {
122         char *title;
123
124         g_object_get (document, "title", &title, NULL);
125
126         return title;
127 }
128
129 int
130 ev_document_get_n_pages (EvDocument  *document)
131 {
132         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
133         return iface->get_n_pages (document);
134 }
135
136 void
137 ev_document_set_page (EvDocument  *document,
138                       int          page)
139 {
140         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
141         iface->set_page (document, page);
142 }
143
144 int
145 ev_document_get_page (EvDocument *document)
146 {
147         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
148         return iface->get_page (document);
149 }
150
151 void
152 ev_document_set_target (EvDocument  *document,
153                         GdkDrawable *target)
154 {
155         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
156         iface->set_target (document, target);
157 }
158
159 void
160 ev_document_set_scale (EvDocument   *document,
161                        double        scale)
162 {
163         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
164         iface->set_scale (document, scale);
165 }
166
167 void
168 ev_document_set_page_offset (EvDocument  *document,
169                              int          x,
170                              int          y)
171 {
172         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
173         iface->set_page_offset (document, x, y);
174 }
175
176 void
177 ev_document_get_page_size   (EvDocument   *document,
178                              int           page,
179                              int          *width,
180                              int          *height)
181 {
182         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
183         iface->get_page_size (document, page, width, height);
184 }
185
186 char *
187 ev_document_get_text (EvDocument   *document,
188                       GdkRectangle *rect)
189 {
190         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
191         return iface->get_text (document, rect);
192 }
193
194 EvLink *
195 ev_document_get_link (EvDocument   *document,
196                       int           x,
197                       int           y)
198 {
199         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
200         return iface->get_link (document, x, y);
201 }
202
203 void
204 ev_document_render (EvDocument  *document,
205                     int          clip_x,
206                     int          clip_y,
207                     int          clip_width,
208                     int          clip_height)
209 {
210         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
211         iface->render (document, clip_x, clip_y, clip_width, clip_height);
212 }
213
214 void
215 ev_document_page_changed (EvDocument *document)
216 {
217         g_signal_emit (G_OBJECT (document), signals[PAGE_CHANGED], 0);
218 }
219
220 void
221 ev_document_scale_changed (EvDocument *document)
222 {
223         g_signal_emit (G_OBJECT (document), signals[SCALE_CHANGED], 0);
224 }