]> www.fi.muni.cz Git - evince.git/blob - libdocument/ev-document.h
Use g_type_module_add_interface instead of g_type_add_interface_static.
[evince.git] / libdocument / ev-document.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /*
3  *  Copyright (C) 2000-2003 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  *  $Id$
20  */
21
22 #ifndef EV_DOCUMENT_H
23 #define EV_DOCUMENT_H
24
25 #include <glib-object.h>
26 #include <glib.h>
27 #include <gdk/gdk.h>
28 #include <cairo.h>
29
30 #include "ev-document-info.h"
31 #include "ev-render-context.h"
32
33 G_BEGIN_DECLS
34
35 #define EV_TYPE_DOCUMENT            (ev_document_get_type ())
36 #define EV_DOCUMENT(o)              (G_TYPE_CHECK_INSTANCE_CAST ((o), EV_TYPE_DOCUMENT, EvDocument))
37 #define EV_DOCUMENT_IFACE(k)        (G_TYPE_CHECK_CLASS_CAST((k), EV_TYPE_DOCUMENT, EvDocumentIface))
38 #define EV_IS_DOCUMENT(o)           (G_TYPE_CHECK_INSTANCE_TYPE ((o), EV_TYPE_DOCUMENT))
39 #define EV_IS_DOCUMENT_IFACE(k)     (G_TYPE_CHECK_CLASS_TYPE ((k), EV_TYPE_DOCUMENT))
40 #define EV_DOCUMENT_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), EV_TYPE_DOCUMENT, EvDocumentIface))
41
42 typedef struct _EvDocument        EvDocument;
43 typedef struct _EvDocumentIface   EvDocumentIface;
44 typedef struct _EvPageCache       EvPageCache;
45 typedef struct _EvPageCacheClass  EvPageCacheClass;
46
47 #define EV_DOCUMENT_ERROR ev_document_error_quark ()
48 #define EV_DOC_MUTEX_LOCK (ev_document_doc_mutex_lock ())
49 #define EV_DOC_MUTEX_UNLOCK (ev_document_doc_mutex_unlock ())
50
51 typedef enum
52 {
53         EV_DOCUMENT_ERROR_INVALID,
54         EV_DOCUMENT_ERROR_ENCRYPTED
55 } EvDocumentError;
56
57 typedef struct {
58         double x;
59         double y;
60 } EvPoint;
61
62 typedef struct {
63         double x1;
64         double y1;
65         double x2;
66         double y2;
67 } EvRectangle;
68
69 struct _EvDocumentIface
70 {
71         GTypeInterface base_iface;
72
73         /* Methods  */
74         gboolean          (* load)            (EvDocument      *document,
75                                                const char      *uri,
76                                                GError         **error);
77         gboolean          (* save)            (EvDocument      *document,
78                                                const char      *uri,
79                                                GError         **error);
80         int               (* get_n_pages)     (EvDocument      *document);
81         void              (* get_page_size)   (EvDocument      *document,
82                                                int              page,
83                                                double          *width,
84                                                double          *height);
85         char            * (* get_page_label)  (EvDocument      *document,
86                                                int              page);
87         gboolean          (* has_attachments) (EvDocument      *document);
88         GList           * (* get_attachments) (EvDocument      *document);
89         cairo_surface_t * (* render)          (EvDocument      *document,
90                                                EvRenderContext *rc);
91         EvDocumentInfo *  (* get_info)        (EvDocument      *document);
92 };
93
94 GType            ev_document_get_type         (void) G_GNUC_CONST;
95 GQuark           ev_document_error_quark      (void);
96
97 /* Document mutex */
98 GMutex          *ev_document_get_doc_mutex    (void);
99 void             ev_document_doc_mutex_lock   (void);
100 void             ev_document_doc_mutex_unlock (void);
101
102 /* FontConfig mutex */
103 GMutex          *ev_document_get_fc_mutex     (void);
104 void             ev_document_fc_mutex_lock    (void);
105 void             ev_document_fc_mutex_unlock  (void);
106
107 EvDocumentInfo  *ev_document_get_info         (EvDocument      *document);
108 gboolean         ev_document_load             (EvDocument      *document,
109                                                const char      *uri,
110                                                GError         **error);
111 gboolean         ev_document_save             (EvDocument      *document,
112                                                const char      *uri,
113                                                GError         **error);
114 int              ev_document_get_n_pages      (EvDocument      *document);
115 void             ev_document_get_page_size    (EvDocument      *document,
116                                                int              page,
117                                                double          *width,
118                                                double          *height);
119 char            *ev_document_get_page_label   (EvDocument      *document,
120                                                int              page);
121 gboolean         ev_document_has_attachments  (EvDocument      *document);
122 GList           *ev_document_get_attachments  (EvDocument      *document);
123 cairo_surface_t *ev_document_render           (EvDocument      *document,
124                                                EvRenderContext *rc);
125
126 gint            ev_rect_cmp                   (EvRectangle     *a,
127                                                EvRectangle     *b);
128
129 /* convenience macro to ease interface addition in the CODE
130  * section of EV_BACKEND_REGISTER_WITH_CODE (this macro relies on
131  * the g_define_type_id present within EV_BACKEND_REGISTER_WITH_CODE()).
132  * usage example:
133  * EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document,
134  *                          EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
135  *                                                 pdf_document_document_thumbnails_iface_init));
136  */
137 #define EV_BACKEND_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) {                \
138         const GInterfaceInfo g_implement_interface_info = {                     \
139                 (GInterfaceInitFunc) iface_init, NULL, NULL                     \
140         };                                                                      \
141         g_type_module_add_interface (module,                                    \
142                                      g_define_type_id,                          \
143                                      TYPE_IFACE,                                \
144                                      &g_implement_interface_info);              \
145 }
146
147 /*
148  * Utility macro used to register backends
149  *
150  * use: EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE)
151  */
152 #define EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE)          \
153                                                                                 \
154 static GType g_define_type_id = 0;                                              \
155                                                                                 \
156 GType                                                                           \
157 backend_name##_get_type (void)                                                  \
158 {                                                                               \
159         return g_define_type_id;                                                \
160 }                                                                               \
161                                                                                 \
162 static void     backend_name##_init              (BackendName        *self);    \
163 static void     backend_name##_class_init        (BackendName##Class *klass);   \
164 static gpointer backend_name##_parent_class = NULL;                             \
165 static void     backend_name##_class_intern_init (gpointer klass)               \
166 {                                                                               \
167         backend_name##_parent_class = g_type_class_peek_parent (klass);         \
168         backend_name##_class_init ((BackendName##Class *) klass);               \
169 }                                                                               \
170                                                                                 \
171 G_MODULE_EXPORT GType                                                           \
172 register_evince_backend (GTypeModule *module)                                   \
173 {                                                                               \
174         static const GTypeInfo our_info = {                                     \
175                 sizeof (BackendName##Class),                                    \
176                 NULL, /* base_init */                                           \
177                 NULL, /* base_finalize */                                       \
178                 (GClassInitFunc) backend_name##_class_intern_init,              \
179                 NULL,                                                           \
180                 NULL, /* class_data */                                          \
181                 sizeof (BackendName),                                           \
182                 0, /* n_preallocs */                                            \
183                 (GInstanceInitFunc) backend_name##_init                         \
184         };                                                                      \
185                                                                                 \
186         /* Initialise the i18n stuff */                                         \
187         bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);                       \
188         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");                     \
189                                                                                 \
190         g_define_type_id = g_type_module_register_type (module,                 \
191                                             G_TYPE_OBJECT,                      \
192                                             #BackendName,                       \
193                                             &our_info,                          \
194                                            (GTypeFlags)0);                      \
195                                                                                 \
196         EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,                       \
197                                backend_name##_document_iface_init);             \
198                                                                                 \
199         CODE                                                                    \
200                                                                                 \
201         return g_define_type_id;                                                \
202 }
203
204 /*
205  * Utility macro used to register backend
206  *
207  * use: EV_BACKEND_REGISTER(BackendName, backend_name)
208  */
209 #define EV_BACKEND_REGISTER(BackendName, backend_name)                  \
210         EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, ;)
211
212 G_END_DECLS
213
214 #endif /* EV_DOCUMENT_H */