1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* this file is part of evince, a gnome document viewer
4 * Copyright (C) 2005 Red Hat, Inc.
6 * Evince is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Evince is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
37 GObject base_instance;
42 GObjectClass base_class;
45 struct _EvLinkPrivate {
52 G_DEFINE_TYPE (EvLink, ev_link, G_TYPE_OBJECT)
54 #define EV_LINK_GET_PRIVATE(object) \
55 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_LINK, EvLinkPrivate))
58 ev_link_type_get_type (void)
60 static GType type = 0;
62 if (G_UNLIKELY (type == 0)) {
63 static const GEnumValue values[] = {
64 { EV_LINK_TYPE_TITLE, "EV_LINK_TYPE_TITLE", "title" },
65 { EV_LINK_TYPE_PAGE, "EV_LINK_TYPE_PAGE", "page" },
66 { EV_LINK_TYPE_EXTERNAL_URI, "EV_LINK_TYPE_EXTERNAL_URI", "external" },
70 type = g_enum_register_static ("EvLinkType", values);
77 ev_link_get_title (EvLink *self)
79 g_return_val_if_fail (EV_IS_LINK (self), NULL);
81 return self->priv->title;
85 ev_link_set_title (EvLink* self, const char *title)
87 g_assert (EV_IS_LINK (self));
89 if (self->priv->title != NULL) {
90 g_free (self->priv->title);
93 self->priv->title = g_strdup (title);
95 self->priv->title = NULL;
97 g_object_notify (G_OBJECT (self), "title");
101 ev_link_get_uri (EvLink *self)
103 g_return_val_if_fail (EV_IS_LINK (self), NULL);
105 return self->priv->uri;
109 ev_link_set_uri (EvLink* self, const char *uri)
111 g_assert (EV_IS_LINK (self));
112 g_assert (uri != NULL);
114 if (self->priv->uri != NULL) {
115 g_free (self->priv->uri);
118 self->priv->uri = g_strdup (uri);
120 g_object_notify (G_OBJECT (self), "uri");
124 ev_link_get_link_type (EvLink *self)
126 g_return_val_if_fail (EV_IS_LINK (self), 0);
128 return self->priv->type;
132 ev_link_set_link_type (EvLink* self, EvLinkType type)
134 g_assert (EV_IS_LINK (self));
136 self->priv->type = type;
138 g_object_notify (G_OBJECT (self), "type");
142 ev_link_get_page (EvLink *self)
144 g_return_val_if_fail (EV_IS_LINK (self), 0);
146 return self->priv->page;
150 ev_link_set_page (EvLink* self, int page)
152 g_assert (EV_IS_LINK (self));
154 self->priv->page = page;
156 g_object_notify (G_OBJECT (self), "page");
160 ev_link_get_property (GObject *object, guint prop_id, GValue *value,
161 GParamSpec *param_spec)
165 self = EV_LINK (object);
169 g_value_set_string (value, self->priv->title);
172 g_value_set_string (value, self->priv->uri);
175 g_value_set_enum (value, self->priv->type);
178 g_value_set_int (value, self->priv->page);
181 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
189 ev_link_set_property (GObject *object, guint prop_id, const GValue *value,
190 GParamSpec *param_spec)
194 self = EV_LINK (object);
198 ev_link_set_title (self, g_value_get_string (value));
201 ev_link_set_uri (self, g_value_get_string (value));
204 ev_link_set_link_type (self, g_value_get_enum (value));
207 ev_link_set_page (self, g_value_get_int (value));
210 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
218 ev_window_dispose (GObject *object)
222 g_return_if_fail (EV_IS_LINK (object));
224 priv = EV_LINK (object)->priv;
227 g_free (priv->title);
231 G_OBJECT_CLASS (ev_link_parent_class)->dispose (object);
235 ev_link_init (EvLink *ev_link)
237 ev_link->priv = EV_LINK_GET_PRIVATE (ev_link);
239 ev_link->priv->type = EV_LINK_TYPE_TITLE;
243 ev_link_class_init (EvLinkClass *ev_window_class)
245 GObjectClass *g_object_class;
247 g_object_class = G_OBJECT_CLASS (ev_window_class);
248 g_object_class->dispose = ev_window_dispose;
249 g_object_class->set_property = ev_link_set_property;
250 g_object_class->get_property = ev_link_get_property;
252 g_type_class_add_private (g_object_class, sizeof (EvLinkPrivate));
254 g_object_class_install_property (g_object_class,
256 g_param_spec_string ("title",
262 g_object_class_install_property (g_object_class,
264 g_param_spec_string ("uri",
270 g_object_class_install_property (g_object_class,
272 g_param_spec_enum ("type",
279 g_object_class_install_property (g_object_class,
281 g_param_spec_int ("page",
291 ev_link_new_title (const char *title)
293 return EV_LINK (g_object_new (EV_TYPE_LINK,
295 "type", EV_LINK_TYPE_TITLE,
300 ev_link_new_page (const char *title, int page)
302 return EV_LINK (g_object_new (EV_TYPE_LINK,
305 "type", EV_LINK_TYPE_PAGE,
310 ev_link_new_external (const char *title, const char *uri)
312 return EV_LINK (g_object_new (EV_TYPE_LINK,
315 "type", EV_LINK_TYPE_EXTERNAL_URI,
322 ev_link_mapping_free_foreach (EvLinkMapping *mapping)
324 g_object_unref (G_OBJECT (mapping->link));
329 ev_link_mapping_free (GList *link_mapping)
331 if (link_mapping == NULL)
334 g_list_foreach (link_mapping, (GFunc) (ev_link_mapping_free_foreach), NULL);
335 g_list_free (link_mapping);
340 ev_link_mapping_find (GList *link_mapping,
350 for (list = link_mapping; list; list = list->next) {
351 EvLinkMapping *mapping = list->data;
354 if ((x >= mapping->x1) &&
355 (y >= mapping->y1) &&
356 (x <= mapping->x2) &&
357 (y <= mapping->y2)) {
358 link = mapping->link;