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);
39 G_DEFINE_ABSTRACT_TYPE (EvAnnotation, ev_annotation, G_TYPE_OBJECT)
41 ev_annotation_markup_get_type (void)
43 static volatile gsize g_define_type_id__volatile = 0;
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,
53 g_define_type_id = g_type_register_static (G_TYPE_INTERFACE,
55 &our_info, (GTypeFlags)0);
56 g_type_interface_add_prerequisite (g_define_type_id, EV_TYPE_ANNOTATION);
58 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
61 return g_define_type_id__volatile;
64 G_DEFINE_TYPE_WITH_CODE (EvAnnotationText, ev_annotation_text, EV_TYPE_ANNOTATION,
66 G_IMPLEMENT_INTERFACE (EV_TYPE_ANNOTATION_MARKUP,
67 ev_annotation_text_markup_iface_init);
72 ev_annotation_finalize (GObject *object)
74 EvAnnotation *annot = EV_ANNOTATION (object);
77 g_object_unref (annot->page);
81 if (annot->contents) {
82 g_free (annot->contents);
83 annot->contents = NULL;
91 if (annot->modified) {
92 g_free (annot->modified);
93 annot->modified = NULL;
96 G_OBJECT_CLASS (ev_annotation_parent_class)->finalize (object);
100 ev_annotation_init (EvAnnotation *annot)
105 ev_annotation_class_init (EvAnnotationClass *klass)
107 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
109 g_object_class->finalize = ev_annotation_finalize;
113 ev_annotation_text_new (EvPage *page)
117 annot = EV_ANNOTATION (g_object_new (EV_TYPE_ANNOTATION_TEXT, NULL));
118 annot->page = g_object_ref (page);
123 /* EvAnnotationMarkup */
129 EvRectangle *rectangle;
130 } EvAnnotationMarkupProps;
133 ev_annotation_markup_iface_base_init (EvAnnotationMarkupIface *iface)
135 static gboolean initialized = FALSE;
138 g_object_interface_install_property (iface,
139 g_param_spec_string ("label",
141 "Label of the markup annotation",
144 g_object_interface_install_property (iface,
145 g_param_spec_double ("opacity",
147 "Opacity of the markup annotation",
152 g_object_interface_install_property (iface,
153 g_param_spec_boolean ("has_popup",
155 "Whether the markup annotation has "
156 "a popup window associated",
159 g_object_interface_install_property (iface,
160 g_param_spec_boxed ("rectangle",
162 "The Rectangle of the popup associated "
163 "to the markup annotation",
166 g_object_interface_install_property (iface,
167 g_param_spec_boolean ("is_open",
169 "Whether the popup associated to "
170 "the markup annotation is open",
178 ev_annotation_markup_props_free (EvAnnotationMarkupProps *props)
180 g_free (props->label);
181 ev_rectangle_free (props->rectangle);
182 g_slice_free (EvAnnotationMarkupProps, props);
185 static EvAnnotationMarkupProps *
186 ev_annotation_markup_get_properties (EvAnnotationMarkup *markup)
188 EvAnnotationMarkupProps *props;
189 static GQuark props_key = 0;
192 props_key = g_quark_from_static_string ("ev-annotation-markup-props");
194 props = g_object_get_qdata (G_OBJECT (markup), props_key);
196 props = g_slice_new0 (EvAnnotationMarkupProps);
197 g_object_set_qdata_full (G_OBJECT (markup),
199 (GDestroyNotify) ev_annotation_markup_props_free);
206 ev_annotation_markup_set_property (GObject *object,
211 EvAnnotationMarkupProps *props;
213 props = ev_annotation_markup_get_properties (EV_ANNOTATION_MARKUP (object));
217 g_free (props->label);
218 props->label = g_value_dup_string (value);
221 props->opacity = g_value_get_double (value);
224 props->has_popup = g_value_get_boolean (value);
227 ev_rectangle_free (props->rectangle);
228 props->rectangle = g_value_dup_boxed (value);
231 props->is_open = g_value_get_boolean (value);
234 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
239 ev_annotation_markup_get_property (GObject *object,
244 EvAnnotationMarkupProps *props;
246 props = ev_annotation_markup_get_properties (EV_ANNOTATION_MARKUP (object));
250 g_value_set_string (value, props->label);
253 g_value_set_double (value, props->opacity);
256 g_value_set_boolean (value, props->has_popup);
259 g_value_set_boxed (value, props->rectangle);
262 g_value_set_boolean (value, props->is_open);
265 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
270 ev_annotation_markup_class_install_properties (GObjectClass *klass)
272 klass->set_property = ev_annotation_markup_set_property;
273 klass->get_property = ev_annotation_markup_get_property;
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");
283 ev_annotation_markup_get_label (EvAnnotationMarkup *markup)
287 g_return_val_if_fail (EV_IS_ANNOTATION_MARKUP (markup), NULL);
289 g_object_get (G_OBJECT (markup), "label", &retval, NULL);
295 ev_annotation_markup_set_label (EvAnnotationMarkup *markup,
298 g_return_if_fail (EV_IS_ANNOTATION_MARKUP (markup));
299 g_return_if_fail (label != NULL);
301 g_object_set (G_OBJECT (markup), "label", label, NULL);
305 ev_annotation_markup_get_opacity (EvAnnotationMarkup *markup)
309 g_return_val_if_fail (EV_IS_ANNOTATION_MARKUP (markup), 0.0);
311 g_object_get (G_OBJECT (markup), "opacity", &retval, NULL);
317 ev_annotation_markup_set_opacity (EvAnnotationMarkup *markup,
320 g_return_if_fail (EV_IS_ANNOTATION_MARKUP (markup));
322 g_object_set (G_OBJECT (markup), "opacity", opacity, NULL);
326 ev_annotation_markup_has_popup (EvAnnotationMarkup *markup)
330 g_return_val_if_fail (EV_IS_ANNOTATION_MARKUP (markup), FALSE);
332 g_object_get (G_OBJECT (markup), "has_popup", &retval, NULL);
338 ev_annotation_markup_get_rectangle (EvAnnotationMarkup *markup,
339 EvRectangle *ev_rect)
343 g_return_if_fail (EV_IS_ANNOTATION_MARKUP (markup));
344 g_return_if_fail (ev_rect != NULL);
346 g_object_get (G_OBJECT (markup), "rectangle", &r, NULL);
351 ev_annotation_markup_get_is_open (EvAnnotationMarkup *markup)
355 g_return_val_if_fail (EV_IS_ANNOTATION_MARKUP (markup), FALSE);
357 g_object_get (G_OBJECT (markup), "is_open", &retval, NULL);
363 ev_annotation_markup_set_is_open (EvAnnotationMarkup *markup,
366 g_return_if_fail (EV_IS_ANNOTATION_MARKUP (markup));
368 g_object_set (G_OBJECT (markup), "is_open", is_open, NULL);
371 /* EvAnnotationText */
373 ev_annotation_text_init (EvAnnotationText *annot)
378 ev_annotation_text_class_init (EvAnnotationTextClass *klass)
380 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
382 ev_annotation_markup_class_install_properties (g_object_class);
386 ev_annotation_text_markup_iface_init (EvAnnotationMarkupIface *iface)