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_PAGE_FIT, "EV_LINK_TYPE_PAGE_FIT", "page-fit" },
74 { EV_LINK_TYPE_PAGE_FITH, "EV_LINK_TYPE_PAGE_FITH", "page-fith" },
75 { EV_LINK_TYPE_EXTERNAL_URI, "EV_LINK_TYPE_EXTERNAL_URI", "external" },
79 type = g_enum_register_static ("EvLinkType", values);
86 ev_link_get_title (EvLink *self)
88 g_return_val_if_fail (EV_IS_LINK (self), NULL);
90 return self->priv->title;
94 ev_link_get_uri (EvLink *self)
96 g_return_val_if_fail (EV_IS_LINK (self), NULL);
98 return self->priv->uri;
102 ev_link_get_link_type (EvLink *self)
104 g_return_val_if_fail (EV_IS_LINK (self), 0);
106 return self->priv->type;
110 ev_link_get_page (EvLink *self)
112 g_return_val_if_fail (EV_IS_LINK (self), 0);
114 return self->priv->page;
118 ev_link_get_top (EvLink *self)
120 g_return_val_if_fail (EV_IS_LINK (self), 0);
122 return self->priv->top;
126 ev_link_get_left (EvLink *self)
128 g_return_val_if_fail (EV_IS_LINK (self), 0);
130 return self->priv->left;
134 ev_link_get_zoom (EvLink *self)
136 g_return_val_if_fail (EV_IS_LINK (self), 0);
138 return self->priv->zoom;
142 ev_link_get_property (GObject *object, guint prop_id, GValue *value,
143 GParamSpec *param_spec)
147 self = EV_LINK (object);
151 g_value_set_string (value, self->priv->title);
154 g_value_set_string (value, self->priv->uri);
157 g_value_set_enum (value, self->priv->type);
160 g_value_set_int (value, self->priv->page);
163 g_value_set_double (value, self->priv->top);
166 g_value_set_double (value, self->priv->left);
169 g_value_set_double (value, self->priv->zoom);
172 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
180 ev_link_set_property (GObject *object, guint prop_id, const GValue *value,
181 GParamSpec *param_spec)
183 EvLink *link = EV_LINK (object);
187 link->priv->title = g_strdup (g_value_get_string (value));
190 link->priv->uri = g_strdup (g_value_get_string (value));
193 link->priv->type = g_value_get_enum (value);
196 link->priv->page = g_value_get_int (value);
199 link->priv->top = g_value_get_double (value);
202 link->priv->left = g_value_get_double (value);
205 link->priv->zoom = g_value_get_double (value);
209 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
217 ev_window_dispose (GObject *object)
221 g_return_if_fail (EV_IS_LINK (object));
223 priv = EV_LINK (object)->priv;
226 g_free (priv->title);
235 G_OBJECT_CLASS (ev_link_parent_class)->dispose (object);
239 ev_link_init (EvLink *ev_link)
241 ev_link->priv = EV_LINK_GET_PRIVATE (ev_link);
243 ev_link->priv->type = EV_LINK_TYPE_TITLE;
247 ev_link_class_init (EvLinkClass *ev_window_class)
249 GObjectClass *g_object_class;
251 g_object_class = G_OBJECT_CLASS (ev_window_class);
252 g_object_class->dispose = ev_window_dispose;
253 g_object_class->set_property = ev_link_set_property;
254 g_object_class->get_property = ev_link_get_property;
256 g_type_class_add_private (g_object_class, sizeof (EvLinkPrivate));
258 g_object_class_install_property (g_object_class,
260 g_param_spec_string ("title",
265 G_PARAM_CONSTRUCT_ONLY));
266 g_object_class_install_property (g_object_class,
268 g_param_spec_string ("uri",
273 G_PARAM_CONSTRUCT_ONLY));
274 g_object_class_install_property (g_object_class,
276 g_param_spec_enum ("type",
282 G_PARAM_CONSTRUCT_ONLY));
283 g_object_class_install_property (g_object_class,
285 g_param_spec_int ("page",
292 G_PARAM_CONSTRUCT_ONLY));
293 g_object_class_install_property (g_object_class,
295 g_param_spec_double ("left",
297 "The left coordinate",
302 G_PARAM_CONSTRUCT_ONLY));
303 g_object_class_install_property (g_object_class,
305 g_param_spec_double ("top",
307 "The top coordinate",
312 G_PARAM_CONSTRUCT_ONLY));
313 g_object_class_install_property (g_object_class,
315 g_param_spec_double ("zoom",
322 G_PARAM_CONSTRUCT_ONLY));
326 ev_link_new_title (const char *title)
328 return EV_LINK (g_object_new (EV_TYPE_LINK,
330 "type", EV_LINK_TYPE_TITLE,
335 ev_link_new_page (const char *title, int page)
337 return EV_LINK (g_object_new (EV_TYPE_LINK,
340 "type", EV_LINK_TYPE_PAGE,
345 ev_link_new_page_xyz (const char *title,
351 return EV_LINK (g_object_new (EV_TYPE_LINK,
354 "type", EV_LINK_TYPE_PAGE_XYZ,
362 ev_link_new_page_fit (const char *title,
365 return EV_LINK (g_object_new (EV_TYPE_LINK,
368 "type", EV_LINK_TYPE_PAGE_FIT,
373 ev_link_new_page_fith (const char *title,
377 return EV_LINK (g_object_new (EV_TYPE_LINK,
380 "type", EV_LINK_TYPE_PAGE_FITH,
386 ev_link_new_external (const char *title, const char *uri)
388 return EV_LINK (g_object_new (EV_TYPE_LINK,
391 "type", EV_LINK_TYPE_EXTERNAL_URI,
398 ev_link_mapping_free_foreach (EvLinkMapping *mapping)
400 g_object_unref (G_OBJECT (mapping->link));
405 ev_link_mapping_free (GList *link_mapping)
407 if (link_mapping == NULL)
410 g_list_foreach (link_mapping, (GFunc) (ev_link_mapping_free_foreach), NULL);
411 g_list_free (link_mapping);
416 ev_link_mapping_find (GList *link_mapping,
426 for (list = link_mapping; list; list = list->next) {
427 EvLinkMapping *mapping = list->data;
430 if ((x >= mapping->x1) &&
431 (y >= mapping->y1) &&
432 (x <= mapping->x2) &&
433 (y <= mapping->y2)) {
434 link = mapping->link;