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.
31 GObject base_instance;
36 GObjectClass base_class;
39 struct _EvLinkPrivate {
44 G_DEFINE_TYPE (EvLink, ev_link, G_TYPE_OBJECT)
46 #define EV_LINK_GET_PRIVATE(object) \
47 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_LINK, EvLinkPrivate))
50 ev_link_get_title (EvLink *self)
52 g_return_val_if_fail (EV_IS_LINK (self), NULL);
54 return self->priv->title;
58 ev_link_get_action (EvLink *self)
60 g_return_val_if_fail (EV_IS_LINK (self), NULL);
62 return self->priv->action;
66 ev_link_get_property (GObject *object,
69 GParamSpec *param_spec)
73 self = EV_LINK (object);
77 g_value_set_string (value, self->priv->title);
80 g_value_set_pointer (value, self->priv->action);
83 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
91 ev_link_set_property (GObject *object,
94 GParamSpec *param_spec)
96 EvLink *self = EV_LINK (object);
100 self->priv->title = g_value_dup_string (value);
103 self->priv->action = g_value_get_pointer (value);
106 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
114 ev_link_finalize (GObject *object)
118 priv = EV_LINK (object)->priv;
121 g_free (priv->title);
126 g_object_unref (priv->action);
130 G_OBJECT_CLASS (ev_link_parent_class)->finalize (object);
134 ev_link_init (EvLink *ev_link)
136 ev_link->priv = EV_LINK_GET_PRIVATE (ev_link);
138 ev_link->priv->title = NULL;
139 ev_link->priv->action = NULL;
143 ev_link_class_init (EvLinkClass *ev_window_class)
145 GObjectClass *g_object_class;
147 g_object_class = G_OBJECT_CLASS (ev_window_class);
149 g_object_class->set_property = ev_link_set_property;
150 g_object_class->get_property = ev_link_get_property;
152 g_object_class->finalize = ev_link_finalize;
154 g_type_class_add_private (g_object_class, sizeof (EvLinkPrivate));
156 g_object_class_install_property (g_object_class,
158 g_param_spec_string ("title",
163 G_PARAM_CONSTRUCT_ONLY));
164 g_object_class_install_property (g_object_class,
166 g_param_spec_pointer ("action",
170 G_PARAM_CONSTRUCT_ONLY));
174 ev_link_new (const char *title,
175 EvLinkAction *action)
177 return EV_LINK (g_object_new (EV_TYPE_LINK,
183 /* Link Mapping stuff */
185 ev_link_mapping_free_foreach (EvLinkMapping *mapping)
187 g_object_unref (G_OBJECT (mapping->link));
192 ev_link_mapping_free (GList *link_mapping)
194 if (link_mapping == NULL)
197 g_list_foreach (link_mapping, (GFunc) (ev_link_mapping_free_foreach), NULL);
198 g_list_free (link_mapping);
202 ev_link_mapping_find (GList *link_mapping,
212 for (list = link_mapping; list; list = list->next) {
213 EvLinkMapping *mapping = list->data;
216 if ((x >= mapping->x1) &&
217 (y >= mapping->y1) &&
218 (x <= mapping->x2) &&
219 (y <= mapping->y2)) {
220 link = mapping->link;
229 ev_link_mapping_get_area (GList *link_mapping,
235 for (list = link_mapping; list; list = list->next) {
236 EvLinkMapping *mapping = list->data;
238 if (mapping->link == link) {
239 area->x1 = mapping->x1;
240 area->y1 = mapping->y1;
241 area->x2 = mapping->x2;
242 area->y2 = mapping->y2;
250 ev_link_get_page (EvLink *link)
252 EvLinkAction *action;
255 action = ev_link_get_action (link);
259 if (ev_link_action_get_action_type (action) !=
260 EV_LINK_ACTION_TYPE_GOTO_DEST)
263 dest = ev_link_action_get_dest (action);
265 return ev_link_dest_get_page (dest);