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_iface_base_init (EvAnnotationMarkupIface *iface);
28 static void ev_annotation_text_markup_iface_init (EvAnnotationMarkupIface *iface);
29 static void ev_annotation_attachment_markup_iface_init (EvAnnotationMarkupIface *iface);
40 G_DEFINE_ABSTRACT_TYPE (EvAnnotation, ev_annotation, G_TYPE_OBJECT)
42 ev_annotation_markup_get_type (void)
44 static volatile gsize g_define_type_id__volatile = 0;
46 if (g_once_init_enter (&g_define_type_id__volatile)) {
47 GType g_define_type_id;
48 const GTypeInfo our_info = {
49 sizeof (EvAnnotationMarkupIface),
50 (GBaseInitFunc) ev_annotation_markup_iface_base_init,
54 g_define_type_id = g_type_register_static (G_TYPE_INTERFACE,
56 &our_info, (GTypeFlags)0);
57 g_type_interface_add_prerequisite (g_define_type_id, EV_TYPE_ANNOTATION);
59 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
62 return g_define_type_id__volatile;
65 G_DEFINE_TYPE_WITH_CODE (EvAnnotationText, ev_annotation_text, EV_TYPE_ANNOTATION,
67 G_IMPLEMENT_INTERFACE (EV_TYPE_ANNOTATION_MARKUP,
68 ev_annotation_text_markup_iface_init);
70 G_DEFINE_TYPE_WITH_CODE (EvAnnotationAttachment, ev_annotation_attachment, EV_TYPE_ANNOTATION,
72 G_IMPLEMENT_INTERFACE (EV_TYPE_ANNOTATION_MARKUP,
73 ev_annotation_attachment_markup_iface_init);
78 ev_annotation_finalize (GObject *object)
80 EvAnnotation *annot = EV_ANNOTATION (object);
83 g_object_unref (annot->page);
87 if (annot->contents) {
88 g_free (annot->contents);
89 annot->contents = NULL;
97 if (annot->modified) {
98 g_free (annot->modified);
99 annot->modified = NULL;
102 G_OBJECT_CLASS (ev_annotation_parent_class)->finalize (object);
106 ev_annotation_init (EvAnnotation *annot)
111 ev_annotation_class_init (EvAnnotationClass *klass)
113 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
115 g_object_class->finalize = ev_annotation_finalize;
118 /* EvAnnotationMarkup */
124 EvRectangle *rectangle;
125 } EvAnnotationMarkupProps;
128 ev_annotation_markup_iface_base_init (EvAnnotationMarkupIface *iface)
130 static gboolean initialized = FALSE;
133 g_object_interface_install_property (iface,
134 g_param_spec_string ("label",
136 "Label of the markup annotation",
139 g_object_interface_install_property (iface,
140 g_param_spec_double ("opacity",
142 "Opacity of the markup annotation",
147 g_object_interface_install_property (iface,
148 g_param_spec_boolean ("has_popup",
150 "Whether the markup annotation has "
151 "a popup window associated",
154 g_object_interface_install_property (iface,
155 g_param_spec_boxed ("rectangle",
157 "The Rectangle of the popup associated "
158 "to the markup annotation",
161 g_object_interface_install_property (iface,
162 g_param_spec_boolean ("is_open",
164 "Whether the popup associated to "
165 "the markup annotation is open",
173 ev_annotation_markup_props_free (EvAnnotationMarkupProps *props)
175 g_free (props->label);
176 ev_rectangle_free (props->rectangle);
177 g_slice_free (EvAnnotationMarkupProps, props);
180 static EvAnnotationMarkupProps *
181 ev_annotation_markup_get_properties (EvAnnotationMarkup *markup)
183 EvAnnotationMarkupProps *props;
184 static GQuark props_key = 0;
187 props_key = g_quark_from_static_string ("ev-annotation-markup-props");
189 props = g_object_get_qdata (G_OBJECT (markup), props_key);
191 props = g_slice_new0 (EvAnnotationMarkupProps);
192 g_object_set_qdata_full (G_OBJECT (markup),
194 (GDestroyNotify) ev_annotation_markup_props_free);
201 ev_annotation_markup_set_property (GObject *object,
206 EvAnnotationMarkupProps *props;
208 props = ev_annotation_markup_get_properties (EV_ANNOTATION_MARKUP (object));
212 g_free (props->label);
213 props->label = g_value_dup_string (value);
216 props->opacity = g_value_get_double (value);
219 props->has_popup = g_value_get_boolean (value);
222 ev_rectangle_free (props->rectangle);
223 props->rectangle = g_value_dup_boxed (value);
226 props->is_open = g_value_get_boolean (value);
229 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
234 ev_annotation_markup_get_property (GObject *object,
239 EvAnnotationMarkupProps *props;
241 props = ev_annotation_markup_get_properties (EV_ANNOTATION_MARKUP (object));
245 g_value_set_string (value, props->label);
248 g_value_set_double (value, props->opacity);
251 g_value_set_boolean (value, props->has_popup);
254 g_value_set_boxed (value, props->rectangle);
257 g_value_set_boolean (value, props->is_open);
260 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
265 ev_annotation_markup_class_install_properties (GObjectClass *klass)
267 klass->set_property = ev_annotation_markup_set_property;
268 klass->get_property = ev_annotation_markup_get_property;
270 g_object_class_override_property (klass, PROP_LABEL, "label");
271 g_object_class_override_property (klass, PROP_OPACITY, "opacity");
272 g_object_class_override_property (klass, PROP_HAS_POPUP, "has_popup");
273 g_object_class_override_property (klass, PROP_RECTANGLE, "rectangle");
274 g_object_class_override_property (klass, PROP_IS_OPEN, "is_open");
278 ev_annotation_markup_get_label (EvAnnotationMarkup *markup)
282 g_return_val_if_fail (EV_IS_ANNOTATION_MARKUP (markup), NULL);
284 g_object_get (G_OBJECT (markup), "label", &retval, NULL);
290 ev_annotation_markup_set_label (EvAnnotationMarkup *markup,
293 g_return_if_fail (EV_IS_ANNOTATION_MARKUP (markup));
294 g_return_if_fail (label != NULL);
296 g_object_set (G_OBJECT (markup), "label", label, NULL);
300 ev_annotation_markup_get_opacity (EvAnnotationMarkup *markup)
304 g_return_val_if_fail (EV_IS_ANNOTATION_MARKUP (markup), 0.0);
306 g_object_get (G_OBJECT (markup), "opacity", &retval, NULL);
312 ev_annotation_markup_set_opacity (EvAnnotationMarkup *markup,
315 g_return_if_fail (EV_IS_ANNOTATION_MARKUP (markup));
317 g_object_set (G_OBJECT (markup), "opacity", opacity, NULL);
321 ev_annotation_markup_has_popup (EvAnnotationMarkup *markup)
325 g_return_val_if_fail (EV_IS_ANNOTATION_MARKUP (markup), FALSE);
327 g_object_get (G_OBJECT (markup), "has_popup", &retval, NULL);
333 ev_annotation_markup_get_rectangle (EvAnnotationMarkup *markup,
334 EvRectangle *ev_rect)
338 g_return_if_fail (EV_IS_ANNOTATION_MARKUP (markup));
339 g_return_if_fail (ev_rect != NULL);
341 g_object_get (G_OBJECT (markup), "rectangle", &r, NULL);
346 ev_annotation_markup_get_is_open (EvAnnotationMarkup *markup)
350 g_return_val_if_fail (EV_IS_ANNOTATION_MARKUP (markup), FALSE);
352 g_object_get (G_OBJECT (markup), "is_open", &retval, NULL);
358 ev_annotation_markup_set_is_open (EvAnnotationMarkup *markup,
361 g_return_if_fail (EV_IS_ANNOTATION_MARKUP (markup));
363 g_object_set (G_OBJECT (markup), "is_open", is_open, NULL);
366 /* EvAnnotationText */
368 ev_annotation_text_init (EvAnnotationText *annot)
373 ev_annotation_text_class_init (EvAnnotationTextClass *klass)
375 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
377 ev_annotation_markup_class_install_properties (g_object_class);
381 ev_annotation_text_markup_iface_init (EvAnnotationMarkupIface *iface)
386 ev_annotation_text_new (EvPage *page)
390 annot = EV_ANNOTATION (g_object_new (EV_TYPE_ANNOTATION_TEXT, NULL));
391 annot->page = g_object_ref (page);
396 /* EvAnnotationAttachment */
398 ev_annotation_attachment_finalize (GObject *object)
400 EvAnnotationAttachment *annot = EV_ANNOTATION_ATTACHMENT (object);
402 if (annot->attachment) {
403 g_object_unref (annot->attachment);
404 annot->attachment = NULL;
407 G_OBJECT_CLASS (ev_annotation_attachment_parent_class)->finalize (object);
411 ev_annotation_attachment_init (EvAnnotationAttachment *annot)
416 ev_annotation_attachment_class_init (EvAnnotationAttachmentClass *klass)
418 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
420 ev_annotation_markup_class_install_properties (g_object_class);
422 g_object_class->finalize = ev_annotation_attachment_finalize;
426 ev_annotation_attachment_markup_iface_init (EvAnnotationMarkupIface *iface)
431 ev_annotation_attachment_new (EvPage *page,
432 EvAttachment *attachment)
436 g_return_val_if_fail (EV_IS_ATTACHMENT (attachment), NULL);
438 annot = EV_ANNOTATION (g_object_new (EV_TYPE_ANNOTATION_ATTACHMENT, NULL));
439 annot->page = g_object_ref (page);
440 EV_ANNOTATION_ATTACHMENT (annot)->attachment = g_object_ref (attachment);