]> www.fi.muni.cz Git - evince.git/blob - libdocument/ev-annotation.c
[build] Include git.mk in all Makefiles
[evince.git] / libdocument / ev-annotation.c
1 /* ev-annotation.c
2  *  this file is part of evince, a gnome document viewer
3  *
4  * Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
5  * Copyright (C) 2007 IƱigo Martinez <inigomartinez@gmail.com>
6  *
7  * Evince is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * Evince is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20  */
21
22 #include "config.h"
23
24 #include "ev-annotation.h"
25
26
27 static void ev_annotation_markup_iface_base_init (EvAnnotationMarkupIface *iface);
28 static void ev_annotation_text_markup_iface_init (EvAnnotationMarkupIface *iface);
29
30 enum {
31         PROP_0,
32         PROP_LABEL,
33         PROP_OPACITY,
34         PROP_HAS_POPUP,
35         PROP_RECTANGLE,
36         PROP_IS_OPEN
37 };
38
39 G_DEFINE_ABSTRACT_TYPE (EvAnnotation, ev_annotation, G_TYPE_OBJECT)
40 GType
41 ev_annotation_markup_get_type (void)
42 {
43         static volatile gsize g_define_type_id__volatile = 0;
44
45         if (g_once_init_enter (&g_define_type_id__volatile)) {
46                 GType g_define_type_id;
47                 const GTypeInfo our_info = {
48                         sizeof (EvAnnotationMarkupIface),
49                         (GBaseInitFunc) ev_annotation_markup_iface_base_init,
50                         NULL,
51                 };
52
53                 g_define_type_id = g_type_register_static (G_TYPE_INTERFACE,
54                                                            "EvAnnotationMarkup",
55                                                            &our_info, (GTypeFlags)0);
56                 g_type_interface_add_prerequisite (g_define_type_id, EV_TYPE_ANNOTATION);
57
58                 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
59         }
60
61         return g_define_type_id__volatile;
62 }
63
64 G_DEFINE_TYPE_WITH_CODE (EvAnnotationText, ev_annotation_text, EV_TYPE_ANNOTATION,
65          {
66                  G_IMPLEMENT_INTERFACE (EV_TYPE_ANNOTATION_MARKUP,
67                                         ev_annotation_text_markup_iface_init);
68          });
69
70 /* EvAnnotation */
71 static void
72 ev_annotation_finalize (GObject *object)
73 {
74         EvAnnotation *annot = EV_ANNOTATION (object);
75
76         if (annot->page) {
77                 g_object_unref (annot->page);
78                 annot->page = NULL;
79         }
80
81         if (annot->contents) {
82                 g_free (annot->contents);
83                 annot->contents = NULL;
84         }
85
86         if (annot->name) {
87                 g_free (annot->name);
88                 annot->name = NULL;
89         }
90
91         if (annot->modified) {
92                 g_free (annot->modified);
93                 annot->modified = NULL;
94         }
95
96         G_OBJECT_CLASS (ev_annotation_parent_class)->finalize (object);
97 }
98
99 static void
100 ev_annotation_init (EvAnnotation *annot)
101 {
102 }
103
104 static void
105 ev_annotation_class_init (EvAnnotationClass *klass)
106 {
107         GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
108
109         g_object_class->finalize = ev_annotation_finalize;
110 }
111
112 EvAnnotation *
113 ev_annotation_text_new (EvPage *page)
114 {
115         EvAnnotation *annot;
116
117         annot = EV_ANNOTATION (g_object_new (EV_TYPE_ANNOTATION_TEXT, NULL));
118         annot->page = g_object_ref (page);
119
120         return annot;
121 }
122
123 /* EvAnnotationMarkup */
124 typedef struct {
125         gchar   *label;
126         gdouble  opacity;
127         gboolean has_popup;
128         gboolean is_open;
129         EvRectangle *rectangle;
130 } EvAnnotationMarkupProps;
131
132 static void
133 ev_annotation_markup_iface_base_init (EvAnnotationMarkupIface *iface)
134 {
135         static gboolean initialized = FALSE;
136
137         if (!initialized) {
138                 g_object_interface_install_property (iface,
139                                                      g_param_spec_string ("label",
140                                                                           "Label",
141                                                                           "Label of the markup annotation",
142                                                                           NULL,
143                                                                           G_PARAM_READWRITE));
144                 g_object_interface_install_property (iface,
145                                                      g_param_spec_double ("opacity",
146                                                                           "Opacity",
147                                                                           "Opacity of the markup annotation",
148                                                                           0,
149                                                                           G_MAXDOUBLE,
150                                                                           0,
151                                                                           G_PARAM_READWRITE));
152                 g_object_interface_install_property (iface,
153                                                      g_param_spec_boolean ("has_popup",
154                                                                            "Has popup",
155                                                                            "Whether the markup annotation has "
156                                                                            "a popup window associated",
157                                                                            TRUE,
158                                                                            G_PARAM_READWRITE));
159                 g_object_interface_install_property (iface,
160                                                      g_param_spec_boxed ("rectangle",
161                                                                          "Rectangle",
162                                                                          "The Rectangle of the popup associated "
163                                                                          "to the markup annotation",
164                                                                          EV_TYPE_RECTANGLE,
165                                                                          G_PARAM_READWRITE));
166                 g_object_interface_install_property (iface,
167                                                      g_param_spec_boolean ("is_open",
168                                                                            "Is open",
169                                                                            "Whether the popup associated to "
170                                                                            "the markup annotation is open",
171                                                                            FALSE,
172                                                                            G_PARAM_READWRITE));
173                 initialized = TRUE;
174         }
175 }
176
177 static void
178 ev_annotation_markup_props_free (EvAnnotationMarkupProps *props)
179 {
180         g_free (props->label);
181         ev_rectangle_free (props->rectangle);
182         g_slice_free (EvAnnotationMarkupProps, props);
183 }
184
185 static EvAnnotationMarkupProps *
186 ev_annotation_markup_get_properties (EvAnnotationMarkup *markup)
187 {
188         EvAnnotationMarkupProps *props;
189         static GQuark props_key = 0;
190
191         if (!props_key)
192                 props_key = g_quark_from_static_string ("ev-annotation-markup-props");
193
194         props = g_object_get_qdata (G_OBJECT (markup), props_key);
195         if (!props) {
196                 props = g_slice_new0 (EvAnnotationMarkupProps);
197                 g_object_set_qdata_full (G_OBJECT (markup),
198                                          props_key, props,
199                                          (GDestroyNotify) ev_annotation_markup_props_free);
200         }
201
202         return props;
203 }
204
205 static void
206 ev_annotation_markup_set_property (GObject      *object,
207                                    guint         prop_id,
208                                    const GValue *value,
209                                    GParamSpec   *pspec)
210 {
211         EvAnnotationMarkupProps *props;
212
213         props = ev_annotation_markup_get_properties (EV_ANNOTATION_MARKUP (object));
214
215         switch (prop_id) {
216         case PROP_LABEL:
217                 g_free (props->label);
218                 props->label = g_value_dup_string (value);
219                 break;
220         case PROP_OPACITY:
221                 props->opacity = g_value_get_double (value);
222                 break;
223         case PROP_HAS_POPUP:
224                 props->has_popup = g_value_get_boolean (value);
225                 break;
226         case PROP_RECTANGLE:
227                 ev_rectangle_free (props->rectangle);
228                 props->rectangle = g_value_dup_boxed (value);
229                 break;
230         case PROP_IS_OPEN:
231                 props->is_open = g_value_get_boolean (value);
232                 break;
233         default:
234                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
235         }
236 }
237
238 static void
239 ev_annotation_markup_get_property (GObject    *object,
240                                    guint       prop_id,
241                                    GValue     *value,
242                                    GParamSpec *pspec)
243 {
244         EvAnnotationMarkupProps *props;
245
246         props = ev_annotation_markup_get_properties (EV_ANNOTATION_MARKUP (object));
247
248         switch (prop_id) {
249         case PROP_LABEL:
250                 g_value_set_string (value, props->label);
251                 break;
252         case PROP_OPACITY:
253                 g_value_set_double (value, props->opacity);
254                 break;
255         case PROP_HAS_POPUP:
256                 g_value_set_boolean (value, props->has_popup);
257                 break;
258         case PROP_RECTANGLE:
259                 g_value_set_boxed (value, props->rectangle);
260                 break;
261         case PROP_IS_OPEN:
262                 g_value_set_boolean (value, props->is_open);
263                 break;
264         default:
265                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
266         }
267 }
268
269 static void
270 ev_annotation_markup_class_install_properties (GObjectClass *klass)
271 {
272         klass->set_property = ev_annotation_markup_set_property;
273         klass->get_property = ev_annotation_markup_get_property;
274
275         g_object_class_override_property (klass, PROP_LABEL, "label");
276         g_object_class_override_property (klass, PROP_OPACITY, "opacity");
277         g_object_class_override_property (klass, PROP_HAS_POPUP, "has_popup");
278         g_object_class_override_property (klass, PROP_RECTANGLE, "rectangle");
279         g_object_class_override_property (klass, PROP_IS_OPEN, "is_open");
280 }
281
282 gchar *
283 ev_annotation_markup_get_label (EvAnnotationMarkup *markup)
284 {
285         gchar *retval;
286
287         g_return_val_if_fail (EV_IS_ANNOTATION_MARKUP (markup), NULL);
288
289         g_object_get (G_OBJECT (markup), "label", &retval, NULL);
290
291         return retval;
292 }
293
294 void
295 ev_annotation_markup_set_label (EvAnnotationMarkup *markup,
296                                 const gchar        *label)
297 {
298         g_return_if_fail (EV_IS_ANNOTATION_MARKUP (markup));
299         g_return_if_fail (label != NULL);
300
301         g_object_set (G_OBJECT (markup), "label", label, NULL);
302 }
303
304 gdouble
305 ev_annotation_markup_get_opacity (EvAnnotationMarkup *markup)
306 {
307         gdouble retval;
308
309         g_return_val_if_fail (EV_IS_ANNOTATION_MARKUP (markup), 0.0);
310
311         g_object_get (G_OBJECT (markup), "opacity", &retval, NULL);
312
313         return retval;
314 }
315
316 void
317 ev_annotation_markup_set_opacity (EvAnnotationMarkup *markup,
318                                   gdouble             opacity)
319 {
320         g_return_if_fail (EV_IS_ANNOTATION_MARKUP (markup));
321
322         g_object_set (G_OBJECT (markup), "opacity", opacity, NULL);
323 }
324
325 gboolean
326 ev_annotation_markup_has_popup (EvAnnotationMarkup *markup)
327 {
328         gboolean retval;
329
330         g_return_val_if_fail (EV_IS_ANNOTATION_MARKUP (markup), FALSE);
331
332         g_object_get (G_OBJECT (markup), "has_popup", &retval, NULL);
333
334         return retval;
335 }
336
337 void
338 ev_annotation_markup_get_rectangle (EvAnnotationMarkup *markup,
339                                     EvRectangle        *ev_rect)
340 {
341         EvRectangle *r;
342
343         g_return_if_fail (EV_IS_ANNOTATION_MARKUP (markup));
344         g_return_if_fail (ev_rect != NULL);
345
346         g_object_get (G_OBJECT (markup), "rectangle", &r, NULL);
347         *ev_rect = *r;
348 }
349
350 gboolean
351 ev_annotation_markup_get_is_open (EvAnnotationMarkup *markup)
352 {
353         gboolean retval;
354
355         g_return_val_if_fail (EV_IS_ANNOTATION_MARKUP (markup), FALSE);
356
357         g_object_get (G_OBJECT (markup), "is_open", &retval, NULL);
358
359         return retval;
360 }
361
362 void
363 ev_annotation_markup_set_is_open (EvAnnotationMarkup *markup,
364                                   gboolean            is_open)
365 {
366         g_return_if_fail (EV_IS_ANNOTATION_MARKUP (markup));
367
368         g_object_set (G_OBJECT (markup), "is_open", is_open, NULL);
369 }
370
371 /* EvAnnotationText */
372 static void
373 ev_annotation_text_init (EvAnnotationText *annot)
374 {
375 }
376
377 static void
378 ev_annotation_text_class_init (EvAnnotationTextClass *klass)
379 {
380         GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
381
382         ev_annotation_markup_class_install_properties (g_object_class);
383 }
384
385 static void
386 ev_annotation_text_markup_iface_init (EvAnnotationMarkupIface *iface)
387 {
388 }
389