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.
40 GObject base_instance;
45 GObjectClass base_class;
48 struct _EvLinkPrivate {
58 G_DEFINE_TYPE (EvLink, ev_link, G_TYPE_OBJECT)
60 #define EV_LINK_GET_PRIVATE(object) \
61 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_LINK, EvLinkPrivate))
64 ev_link_type_get_type (void)
66 static GType type = 0;
68 if (G_UNLIKELY (type == 0)) {
69 static const GEnumValue values[] = {
70 { EV_LINK_TYPE_TITLE, "EV_LINK_TYPE_TITLE", "title" },
71 { EV_LINK_TYPE_PAGE, "EV_LINK_TYPE_PAGE", "page" },
72 { EV_LINK_TYPE_PAGE_XYZ, "EV_LINK_TYPE_PAGE_XYZ", "page-xyz" },
73 { EV_LINK_TYPE_EXTERNAL_URI, "EV_LINK_TYPE_EXTERNAL_URI", "external" },
77 type = g_enum_register_static ("EvLinkType", values);
84 ev_link_get_title (EvLink *self)
86 g_return_val_if_fail (EV_IS_LINK (self), NULL);
88 return self->priv->title;
92 ev_link_get_uri (EvLink *self)
94 g_return_val_if_fail (EV_IS_LINK (self), NULL);
96 return self->priv->uri;
100 ev_link_get_link_type (EvLink *self)
102 g_return_val_if_fail (EV_IS_LINK (self), 0);
104 return self->priv->type;
108 ev_link_get_page (EvLink *self)
110 g_return_val_if_fail (EV_IS_LINK (self), 0);
112 return self->priv->page;
116 ev_link_get_top (EvLink *self)
118 g_return_val_if_fail (EV_IS_LINK (self), 0);
120 return self->priv->top;
124 ev_link_get_left (EvLink *self)
126 g_return_val_if_fail (EV_IS_LINK (self), 0);
128 return self->priv->left;
132 ev_link_get_zoom (EvLink *self)
134 g_return_val_if_fail (EV_IS_LINK (self), 0);
136 return self->priv->zoom;
140 ev_link_get_property (GObject *object, guint prop_id, GValue *value,
141 GParamSpec *param_spec)
145 self = EV_LINK (object);
149 g_value_set_string (value, self->priv->title);
152 g_value_set_string (value, self->priv->uri);
155 g_value_set_enum (value, self->priv->type);
158 g_value_set_int (value, self->priv->page);
161 g_value_set_double (value, self->priv->top);
164 g_value_set_double (value, self->priv->left);
167 g_value_set_double (value, self->priv->zoom);
170 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
178 ev_link_set_property (GObject *object, guint prop_id, const GValue *value,
179 GParamSpec *param_spec)
181 EvLink *link = EV_LINK (object);
185 link->priv->title = g_strdup (g_value_get_string (value));
188 link->priv->uri = g_strdup (g_value_get_string (value));
191 link->priv->type = g_value_get_enum (value);
194 link->priv->page = g_value_get_int (value);
197 link->priv->top = g_value_get_double (value);
200 link->priv->left = g_value_get_double (value);
203 link->priv->zoom = g_value_get_double (value);
207 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
215 ev_window_dispose (GObject *object)
219 g_return_if_fail (EV_IS_LINK (object));
221 priv = EV_LINK (object)->priv;
224 g_free (priv->title);
233 G_OBJECT_CLASS (ev_link_parent_class)->dispose (object);
237 ev_link_init (EvLink *ev_link)
239 ev_link->priv = EV_LINK_GET_PRIVATE (ev_link);
241 ev_link->priv->type = EV_LINK_TYPE_TITLE;
245 ev_link_class_init (EvLinkClass *ev_window_class)
247 GObjectClass *g_object_class;
249 g_object_class = G_OBJECT_CLASS (ev_window_class);
250 g_object_class->dispose = ev_window_dispose;
251 g_object_class->set_property = ev_link_set_property;
252 g_object_class->get_property = ev_link_get_property;
254 g_type_class_add_private (g_object_class, sizeof (EvLinkPrivate));
256 g_object_class_install_property (g_object_class,
258 g_param_spec_string ("title",
263 G_PARAM_CONSTRUCT_ONLY));
264 g_object_class_install_property (g_object_class,
266 g_param_spec_string ("uri",
271 G_PARAM_CONSTRUCT_ONLY));
272 g_object_class_install_property (g_object_class,
274 g_param_spec_enum ("type",
280 G_PARAM_CONSTRUCT_ONLY));
281 g_object_class_install_property (g_object_class,
283 g_param_spec_int ("page",
290 G_PARAM_CONSTRUCT_ONLY));
291 g_object_class_install_property (g_object_class,
293 g_param_spec_double ("left",
295 "The left coordinate",
300 G_PARAM_CONSTRUCT_ONLY));
301 g_object_class_install_property (g_object_class,
303 g_param_spec_double ("top",
305 "The top coordinate",
310 G_PARAM_CONSTRUCT_ONLY));
311 g_object_class_install_property (g_object_class,
313 g_param_spec_double ("zoom",
320 G_PARAM_CONSTRUCT_ONLY));
324 ev_link_new_title (const char *title)
326 return EV_LINK (g_object_new (EV_TYPE_LINK,
328 "type", EV_LINK_TYPE_TITLE,
333 ev_link_new_page (const char *title, int page)
335 return EV_LINK (g_object_new (EV_TYPE_LINK,
338 "type", EV_LINK_TYPE_PAGE,
343 ev_link_new_page_xyz (const char *title,
349 return EV_LINK (g_object_new (EV_TYPE_LINK,
352 "type", EV_LINK_TYPE_PAGE_XYZ,
360 ev_link_new_external (const char *title, const char *uri)
362 return EV_LINK (g_object_new (EV_TYPE_LINK,
365 "type", EV_LINK_TYPE_EXTERNAL_URI,
372 ev_link_mapping_free_foreach (EvLinkMapping *mapping)
374 g_object_unref (G_OBJECT (mapping->link));
379 ev_link_mapping_free (GList *link_mapping)
381 if (link_mapping == NULL)
384 g_list_foreach (link_mapping, (GFunc) (ev_link_mapping_free_foreach), NULL);
385 g_list_free (link_mapping);
390 ev_link_mapping_find (GList *link_mapping,
400 for (list = link_mapping; list; list = list->next) {
401 EvLinkMapping *mapping = list->data;
404 if ((x >= mapping->x1) &&
405 (y >= mapping->y1) &&
406 (x <= mapping->x2) &&
407 (y <= mapping->y2)) {
408 link = mapping->link;