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_PAGE_FITV, "EV_LINK_TYPE_PAGE_FITV", "page-fitv" },
76 { EV_LINK_TYPE_EXTERNAL_URI, "EV_LINK_TYPE_EXTERNAL_URI", "external" },
80 type = g_enum_register_static ("EvLinkType", values);
87 ev_link_get_title (EvLink *self)
89 g_return_val_if_fail (EV_IS_LINK (self), NULL);
91 return self->priv->title;
95 ev_link_get_uri (EvLink *self)
97 g_return_val_if_fail (EV_IS_LINK (self), NULL);
99 return self->priv->uri;
103 ev_link_get_link_type (EvLink *self)
105 g_return_val_if_fail (EV_IS_LINK (self), 0);
107 return self->priv->type;
111 ev_link_get_page (EvLink *self)
113 g_return_val_if_fail (EV_IS_LINK (self), 0);
115 return self->priv->page;
119 ev_link_get_top (EvLink *self)
121 g_return_val_if_fail (EV_IS_LINK (self), 0);
123 return self->priv->top;
127 ev_link_get_left (EvLink *self)
129 g_return_val_if_fail (EV_IS_LINK (self), 0);
131 return self->priv->left;
135 ev_link_get_zoom (EvLink *self)
137 g_return_val_if_fail (EV_IS_LINK (self), 0);
139 return self->priv->zoom;
143 ev_link_get_property (GObject *object, guint prop_id, GValue *value,
144 GParamSpec *param_spec)
148 self = EV_LINK (object);
152 g_value_set_string (value, self->priv->title);
155 g_value_set_string (value, self->priv->uri);
158 g_value_set_enum (value, self->priv->type);
161 g_value_set_int (value, self->priv->page);
164 g_value_set_double (value, self->priv->top);
167 g_value_set_double (value, self->priv->left);
170 g_value_set_double (value, self->priv->zoom);
173 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
181 ev_link_set_property (GObject *object, guint prop_id, const GValue *value,
182 GParamSpec *param_spec)
184 EvLink *link = EV_LINK (object);
188 link->priv->title = g_strdup (g_value_get_string (value));
191 link->priv->uri = g_strdup (g_value_get_string (value));
194 link->priv->type = g_value_get_enum (value);
197 link->priv->page = g_value_get_int (value);
200 link->priv->top = g_value_get_double (value);
203 link->priv->left = g_value_get_double (value);
206 link->priv->zoom = g_value_get_double (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);
236 G_OBJECT_CLASS (ev_link_parent_class)->dispose (object);
240 ev_link_init (EvLink *ev_link)
242 ev_link->priv = EV_LINK_GET_PRIVATE (ev_link);
244 ev_link->priv->type = EV_LINK_TYPE_TITLE;
248 ev_link_class_init (EvLinkClass *ev_window_class)
250 GObjectClass *g_object_class;
252 g_object_class = G_OBJECT_CLASS (ev_window_class);
253 g_object_class->dispose = ev_window_dispose;
254 g_object_class->set_property = ev_link_set_property;
255 g_object_class->get_property = ev_link_get_property;
257 g_type_class_add_private (g_object_class, sizeof (EvLinkPrivate));
259 g_object_class_install_property (g_object_class,
261 g_param_spec_string ("title",
266 G_PARAM_CONSTRUCT_ONLY));
267 g_object_class_install_property (g_object_class,
269 g_param_spec_string ("uri",
274 G_PARAM_CONSTRUCT_ONLY));
275 g_object_class_install_property (g_object_class,
277 g_param_spec_enum ("type",
283 G_PARAM_CONSTRUCT_ONLY));
284 g_object_class_install_property (g_object_class,
286 g_param_spec_int ("page",
293 G_PARAM_CONSTRUCT_ONLY));
294 g_object_class_install_property (g_object_class,
296 g_param_spec_double ("left",
298 "The left coordinate",
303 G_PARAM_CONSTRUCT_ONLY));
304 g_object_class_install_property (g_object_class,
306 g_param_spec_double ("top",
308 "The top coordinate",
313 G_PARAM_CONSTRUCT_ONLY));
314 g_object_class_install_property (g_object_class,
316 g_param_spec_double ("zoom",
323 G_PARAM_CONSTRUCT_ONLY));
327 ev_link_new_title (const char *title)
329 return EV_LINK (g_object_new (EV_TYPE_LINK,
331 "type", EV_LINK_TYPE_TITLE,
336 ev_link_new_page (const char *title, int page)
338 return EV_LINK (g_object_new (EV_TYPE_LINK,
341 "type", EV_LINK_TYPE_PAGE,
346 ev_link_new_page_xyz (const char *title,
352 return EV_LINK (g_object_new (EV_TYPE_LINK,
355 "type", EV_LINK_TYPE_PAGE_XYZ,
363 ev_link_new_page_fit (const char *title,
366 return EV_LINK (g_object_new (EV_TYPE_LINK,
369 "type", EV_LINK_TYPE_PAGE_FIT,
374 ev_link_new_page_fith (const char *title,
378 return EV_LINK (g_object_new (EV_TYPE_LINK,
381 "type", EV_LINK_TYPE_PAGE_FITH,
387 ev_link_new_page_fitv (const char *title,
391 return EV_LINK (g_object_new (EV_TYPE_LINK,
394 "type", EV_LINK_TYPE_PAGE_FITV,
400 ev_link_new_external (const char *title, const char *uri)
402 return EV_LINK (g_object_new (EV_TYPE_LINK,
405 "type", EV_LINK_TYPE_EXTERNAL_URI,
412 ev_link_mapping_free_foreach (EvLinkMapping *mapping)
414 g_object_unref (G_OBJECT (mapping->link));
419 ev_link_mapping_free (GList *link_mapping)
421 if (link_mapping == NULL)
424 g_list_foreach (link_mapping, (GFunc) (ev_link_mapping_free_foreach), NULL);
425 g_list_free (link_mapping);
430 ev_link_mapping_find (GList *link_mapping,
440 for (list = link_mapping; list; list = list->next) {
441 EvLinkMapping *mapping = list->data;
444 if ((x >= mapping->x1) &&
445 (y >= mapping->y1) &&
446 (x <= mapping->x2) &&
447 (y <= mapping->y2)) {
448 link = mapping->link;