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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "ev-annotation.h"
27 static void ev_annotation_markup_default_init (EvAnnotationMarkupInterface *iface);
28 static void ev_annotation_text_markup_iface_init (EvAnnotationMarkupInterface *iface);
29 static void ev_annotation_attachment_markup_iface_init (EvAnnotationMarkupInterface *iface);
40 G_DEFINE_ABSTRACT_TYPE (EvAnnotation, ev_annotation, G_TYPE_OBJECT)
41 G_DEFINE_INTERFACE (EvAnnotationMarkup, ev_annotation_markup, EV_TYPE_ANNOTATION)
42 G_DEFINE_TYPE_WITH_CODE (EvAnnotationText, ev_annotation_text, EV_TYPE_ANNOTATION,
44 G_IMPLEMENT_INTERFACE (EV_TYPE_ANNOTATION_MARKUP,
45 ev_annotation_text_markup_iface_init);
47 G_DEFINE_TYPE_WITH_CODE (EvAnnotationAttachment, ev_annotation_attachment, EV_TYPE_ANNOTATION,
49 G_IMPLEMENT_INTERFACE (EV_TYPE_ANNOTATION_MARKUP,
50 ev_annotation_attachment_markup_iface_init);
55 ev_annotation_finalize (GObject *object)
57 EvAnnotation *annot = EV_ANNOTATION (object);
60 g_object_unref (annot->page);
64 if (annot->contents) {
65 g_free (annot->contents);
66 annot->contents = NULL;
74 if (annot->modified) {
75 g_free (annot->modified);
76 annot->modified = NULL;
79 G_OBJECT_CLASS (ev_annotation_parent_class)->finalize (object);
83 ev_annotation_init (EvAnnotation *annot)
88 ev_annotation_class_init (EvAnnotationClass *klass)
90 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
92 g_object_class->finalize = ev_annotation_finalize;
95 /* EvAnnotationMarkup */
101 EvRectangle *rectangle;
102 } EvAnnotationMarkupProps;
105 ev_annotation_markup_default_init (EvAnnotationMarkupInterface *iface)
107 static gboolean initialized = FALSE;
110 g_object_interface_install_property (iface,
111 g_param_spec_string ("label",
113 "Label of the markup annotation",
116 g_object_interface_install_property (iface,
117 g_param_spec_double ("opacity",
119 "Opacity of the markup annotation",
124 g_object_interface_install_property (iface,
125 g_param_spec_boolean ("has_popup",
127 "Whether the markup annotation has "
128 "a popup window associated",
131 g_object_interface_install_property (iface,
132 g_param_spec_boxed ("rectangle",
134 "The Rectangle of the popup associated "
135 "to the markup annotation",
138 g_object_interface_install_property (iface,
139 g_param_spec_boolean ("is_open",
141 "Whether the popup associated to "
142 "the markup annotation is open",
150 ev_annotation_markup_props_free (EvAnnotationMarkupProps *props)
152 g_free (props->label);
153 ev_rectangle_free (props->rectangle);
154 g_slice_free (EvAnnotationMarkupProps, props);
157 static EvAnnotationMarkupProps *
158 ev_annotation_markup_get_properties (EvAnnotationMarkup *markup)
160 EvAnnotationMarkupProps *props;
161 static GQuark props_key = 0;
164 props_key = g_quark_from_static_string ("ev-annotation-markup-props");
166 props = g_object_get_qdata (G_OBJECT (markup), props_key);
168 props = g_slice_new0 (EvAnnotationMarkupProps);
169 g_object_set_qdata_full (G_OBJECT (markup),
171 (GDestroyNotify) ev_annotation_markup_props_free);
178 ev_annotation_markup_set_property (GObject *object,
183 EvAnnotationMarkupProps *props;
185 props = ev_annotation_markup_get_properties (EV_ANNOTATION_MARKUP (object));
189 g_free (props->label);
190 props->label = g_value_dup_string (value);
193 props->opacity = g_value_get_double (value);
196 props->has_popup = g_value_get_boolean (value);
199 ev_rectangle_free (props->rectangle);
200 props->rectangle = g_value_dup_boxed (value);
203 props->is_open = g_value_get_boolean (value);
206 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
211 ev_annotation_markup_get_property (GObject *object,
216 EvAnnotationMarkupProps *props;
218 props = ev_annotation_markup_get_properties (EV_ANNOTATION_MARKUP (object));
222 g_value_set_string (value, props->label);
225 g_value_set_double (value, props->opacity);
228 g_value_set_boolean (value, props->has_popup);
231 g_value_set_boxed (value, props->rectangle);
234 g_value_set_boolean (value, props->is_open);
237 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
242 ev_annotation_markup_class_install_properties (GObjectClass *klass)
244 klass->set_property = ev_annotation_markup_set_property;
245 klass->get_property = ev_annotation_markup_get_property;
247 g_object_class_override_property (klass, PROP_LABEL, "label");
248 g_object_class_override_property (klass, PROP_OPACITY, "opacity");
249 g_object_class_override_property (klass, PROP_HAS_POPUP, "has_popup");
250 g_object_class_override_property (klass, PROP_RECTANGLE, "rectangle");
251 g_object_class_override_property (klass, PROP_IS_OPEN, "is_open");
255 ev_annotation_markup_get_label (EvAnnotationMarkup *markup)
259 g_return_val_if_fail (EV_IS_ANNOTATION_MARKUP (markup), NULL);
261 g_object_get (G_OBJECT (markup), "label", &retval, NULL);
267 ev_annotation_markup_set_label (EvAnnotationMarkup *markup,
270 g_return_if_fail (EV_IS_ANNOTATION_MARKUP (markup));
271 g_return_if_fail (label != NULL);
273 g_object_set (G_OBJECT (markup), "label", label, NULL);
277 ev_annotation_markup_get_opacity (EvAnnotationMarkup *markup)
281 g_return_val_if_fail (EV_IS_ANNOTATION_MARKUP (markup), 0.0);
283 g_object_get (G_OBJECT (markup), "opacity", &retval, NULL);
289 ev_annotation_markup_set_opacity (EvAnnotationMarkup *markup,
292 g_return_if_fail (EV_IS_ANNOTATION_MARKUP (markup));
294 g_object_set (G_OBJECT (markup), "opacity", opacity, NULL);
298 ev_annotation_markup_has_popup (EvAnnotationMarkup *markup)
302 g_return_val_if_fail (EV_IS_ANNOTATION_MARKUP (markup), FALSE);
304 g_object_get (G_OBJECT (markup), "has_popup", &retval, 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 (EvAnnotationMarkupInterface *iface)
363 ev_annotation_text_new (EvPage *page)
367 annot = EV_ANNOTATION (g_object_new (EV_TYPE_ANNOTATION_TEXT, NULL));
368 annot->page = g_object_ref (page);
373 /* EvAnnotationAttachment */
375 ev_annotation_attachment_finalize (GObject *object)
377 EvAnnotationAttachment *annot = EV_ANNOTATION_ATTACHMENT (object);
379 if (annot->attachment) {
380 g_object_unref (annot->attachment);
381 annot->attachment = NULL;
384 G_OBJECT_CLASS (ev_annotation_attachment_parent_class)->finalize (object);
388 ev_annotation_attachment_init (EvAnnotationAttachment *annot)
393 ev_annotation_attachment_class_init (EvAnnotationAttachmentClass *klass)
395 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
397 ev_annotation_markup_class_install_properties (g_object_class);
399 g_object_class->finalize = ev_annotation_attachment_finalize;
403 ev_annotation_attachment_markup_iface_init (EvAnnotationMarkupInterface *iface)
408 ev_annotation_attachment_new (EvPage *page,
409 EvAttachment *attachment)
413 g_return_val_if_fail (EV_IS_ATTACHMENT (attachment), NULL);
415 annot = EV_ANNOTATION (g_object_new (EV_TYPE_ANNOTATION_ATTACHMENT, NULL));
416 annot->page = g_object_ref (page);
417 EV_ANNOTATION_ATTACHMENT (annot)->attachment = g_object_ref (attachment);