2 * this file is part of evince, a gnome document viewer
4 * Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
5 * Copyright (C) 2007 IƱigo Martinez <inigomartinez@gmail.com>
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.
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.
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.
24 #include "ev-annotation.h"
27 static void ev_annotation_markup_iface_base_init (EvAnnotationMarkupIface *iface);
28 static void ev_annotation_text_markup_iface_init (EvAnnotationMarkupIface *iface);
38 G_DEFINE_ABSTRACT_TYPE (EvAnnotation, ev_annotation, G_TYPE_OBJECT)
40 ev_annotation_markup_get_type (void)
42 static volatile gsize g_define_type_id__volatile = 0;
44 if (g_once_init_enter (&g_define_type_id__volatile)) {
45 GType g_define_type_id;
46 const GTypeInfo our_info = {
47 sizeof (EvAnnotationMarkupIface),
48 (GBaseInitFunc) ev_annotation_markup_iface_base_init,
52 g_define_type_id = g_type_register_static (G_TYPE_INTERFACE,
54 &our_info, (GTypeFlags)0);
55 g_type_interface_add_prerequisite (g_define_type_id, EV_TYPE_ANNOTATION);
57 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
60 return g_define_type_id__volatile;
63 G_DEFINE_TYPE_WITH_CODE (EvAnnotationText, ev_annotation_text, EV_TYPE_ANNOTATION,
65 G_IMPLEMENT_INTERFACE (EV_TYPE_ANNOTATION_MARKUP,
66 ev_annotation_text_markup_iface_init);
71 ev_annotation_finalize (GObject *object)
73 EvAnnotation *annot = EV_ANNOTATION (object);
76 g_object_unref (annot->page);
80 if (annot->contents) {
81 g_free (annot->contents);
82 annot->contents = NULL;
90 if (annot->modified) {
91 g_free (annot->modified);
92 annot->modified = NULL;
95 G_OBJECT_CLASS (ev_annotation_parent_class)->finalize (object);
99 ev_annotation_init (EvAnnotation *annot)
104 ev_annotation_class_init (EvAnnotationClass *klass)
106 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
108 g_object_class->finalize = ev_annotation_finalize;
112 ev_annotation_text_new (EvPage *page)
116 annot = EV_ANNOTATION (g_object_new (EV_TYPE_ANNOTATION_TEXT, NULL));
117 annot->page = g_object_ref (page);
122 /* EvAnnotationMarkup */
127 EvRectangle *rectangle;
128 } EvAnnotationMarkupProps;
131 ev_annotation_markup_iface_base_init (EvAnnotationMarkupIface *iface)
133 static gboolean initialized = FALSE;
136 g_object_interface_install_property (iface,
137 g_param_spec_string ("label",
139 "Label of the markup annotation",
142 g_object_interface_install_property (iface,
143 g_param_spec_double ("opacity",
145 "Opacity of the markup annotation",
150 g_object_interface_install_property (iface,
151 g_param_spec_boxed ("rectangle",
153 "The Rectangle of the popup associated "
154 "to the markup annotation",
157 g_object_interface_install_property (iface,
158 g_param_spec_boolean ("is_open",
160 "Whether the popup associated to "
161 "the markup annotation is open",
169 ev_annotation_markup_props_free (EvAnnotationMarkupProps *props)
171 g_free (props->label);
172 ev_rectangle_free (props->rectangle);
173 g_slice_free (EvAnnotationMarkupProps, props);
176 static EvAnnotationMarkupProps *
177 ev_annotation_markup_get_properties (EvAnnotationMarkup *markup)
179 EvAnnotationMarkupProps *props;
180 static GQuark props_key = 0;
183 props_key = g_quark_from_static_string ("ev-annotation-markup-props");
185 props = g_object_get_qdata (G_OBJECT (markup), props_key);
187 props = g_slice_new0 (EvAnnotationMarkupProps);
188 g_object_set_qdata_full (G_OBJECT (markup),
190 (GDestroyNotify) ev_annotation_markup_props_free);
197 ev_annotation_markup_set_property (GObject *object,
202 EvAnnotationMarkupProps *props;
204 props = ev_annotation_markup_get_properties (EV_ANNOTATION_MARKUP (object));
208 g_free (props->label);
209 props->label = g_value_dup_string (value);
212 props->opacity = g_value_get_double (value);
215 ev_rectangle_free (props->rectangle);
216 props->rectangle = g_value_dup_boxed (value);
219 props->is_open = g_value_get_boolean (value);
222 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
227 ev_annotation_markup_get_property (GObject *object,
232 EvAnnotationMarkupProps *props;
234 props = ev_annotation_markup_get_properties (EV_ANNOTATION_MARKUP (object));
238 g_value_set_string (value, props->label);
241 g_value_set_double (value, props->opacity);
244 g_value_set_boxed (value, props->rectangle);
247 g_value_set_boolean (value, props->is_open);
250 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
255 ev_annotation_markup_class_install_properties (GObjectClass *klass)
257 klass->set_property = ev_annotation_markup_set_property;
258 klass->get_property = ev_annotation_markup_get_property;
260 g_object_class_override_property (klass, PROP_LABEL, "label");
261 g_object_class_override_property (klass, PROP_OPACITY, "opacity");
262 g_object_class_override_property (klass, PROP_RECTANGLE, "rectangle");
263 g_object_class_override_property (klass, PROP_IS_OPEN, "is_open");
267 ev_annotation_markup_get_label (EvAnnotationMarkup *markup)
271 g_return_val_if_fail (EV_IS_ANNOTATION_MARKUP (markup), NULL);
273 g_object_get (G_OBJECT (markup), "label", &retval, NULL);
279 ev_annotation_markup_set_label (EvAnnotationMarkup *markup,
282 g_return_if_fail (EV_IS_ANNOTATION_MARKUP (markup));
283 g_return_if_fail (label != NULL);
285 g_object_set (G_OBJECT (markup), "label", label, NULL);
289 ev_annotation_markup_get_opacity (EvAnnotationMarkup *markup)
293 g_return_val_if_fail (EV_IS_ANNOTATION_MARKUP (markup), 0.0);
295 g_object_get (G_OBJECT (markup), "opacity", &retval, NULL);
301 ev_annotation_markup_set_opacity (EvAnnotationMarkup *markup,
304 g_return_if_fail (EV_IS_ANNOTATION_MARKUP (markup));
306 g_object_set (G_OBJECT (markup), "opacity", opacity, NULL);
310 ev_annotation_markup_get_rectangle (EvAnnotationMarkup *markup,
311 EvRectangle *ev_rect)
315 g_return_if_fail (EV_IS_ANNOTATION_MARKUP (markup));
316 g_return_if_fail (ev_rect != NULL);
318 g_object_get (G_OBJECT (markup), "rectangle", &r, NULL);
323 ev_annotation_markup_get_is_open (EvAnnotationMarkup *markup)
327 g_return_val_if_fail (EV_IS_ANNOTATION_MARKUP (markup), FALSE);
329 g_object_get (G_OBJECT (markup), "is_open", &retval, NULL);
335 ev_annotation_markup_set_is_open (EvAnnotationMarkup *markup,
338 g_return_if_fail (EV_IS_ANNOTATION_MARKUP (markup));
340 g_object_set (G_OBJECT (markup), "is_open", is_open, NULL);
343 /* EvAnnotationText */
345 ev_annotation_text_init (EvAnnotationText *annot)
350 ev_annotation_text_class_init (EvAnnotationTextClass *klass)
352 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
354 ev_annotation_markup_class_install_properties (g_object_class);
358 ev_annotation_text_markup_iface_init (EvAnnotationMarkupIface *iface)
362 /* Annotation Mapping stuff */
364 ev_annotation_mapping_free_foreach (EvAnnotationMapping *mapping)
366 g_object_unref (mapping->annotation);
371 ev_annotation_mapping_free (GList *annotation_mapping)
373 if (!annotation_mapping)
376 g_list_foreach (annotation_mapping, (GFunc) ev_annotation_mapping_free_foreach, NULL);
377 g_list_free (annotation_mapping);
381 ev_annotation_mapping_find (GList *annotation_mapping,
387 for (list = annotation_mapping; list; list = list->next) {
388 EvAnnotationMapping *mapping = list->data;
390 if ((x >= mapping->x1) &&
391 (y >= mapping->y1) &&
392 (x <= mapping->x2) &&
393 (y <= mapping->y2)) {
394 return mapping->annotation;
402 ev_annotation_mapping_get_area (GList *annotation_mapping,
403 EvAnnotation *annotation,
408 for (list = annotation_mapping; list; list = list->next) {
409 EvAnnotationMapping *mapping = list->data;
411 if (mapping->annotation == annotation) {
412 area->x1 = mapping->x1;
413 area->y1 = mapping->y1;
414 area->x2 = mapping->x2;
415 area->y2 = mapping->y2;