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.
42 GObject base_instance;
47 GObjectClass base_class;
50 struct _EvLinkPrivate {
62 G_DEFINE_TYPE (EvLink, ev_link, G_TYPE_OBJECT)
64 #define EV_LINK_GET_PRIVATE(object) \
65 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_LINK, EvLinkPrivate))
68 ev_link_type_get_type (void)
70 static GType type = 0;
72 if (G_UNLIKELY (type == 0)) {
73 static const GEnumValue values[] = {
74 { EV_LINK_TYPE_TITLE, "EV_LINK_TYPE_TITLE", "title" },
75 { EV_LINK_TYPE_PAGE, "EV_LINK_TYPE_PAGE", "page" },
76 { EV_LINK_TYPE_PAGE_XYZ, "EV_LINK_TYPE_PAGE_XYZ", "page-xyz" },
77 { EV_LINK_TYPE_PAGE_FIT, "EV_LINK_TYPE_PAGE_FIT", "page-fit" },
78 { EV_LINK_TYPE_PAGE_FITH, "EV_LINK_TYPE_PAGE_FITH", "page-fith" },
79 { EV_LINK_TYPE_PAGE_FITV, "EV_LINK_TYPE_PAGE_FITV", "page-fitv" },
80 { EV_LINK_TYPE_PAGE_FITR, "EV_LINK_TYPE_PAGE_FITR", "page-fitr" },
81 { EV_LINK_TYPE_EXTERNAL_URI, "EV_LINK_TYPE_EXTERNAL_URI", "external" },
85 type = g_enum_register_static ("EvLinkType", values);
92 ev_link_get_title (EvLink *self)
94 g_return_val_if_fail (EV_IS_LINK (self), NULL);
96 return self->priv->title;
100 ev_link_get_uri (EvLink *self)
102 g_return_val_if_fail (EV_IS_LINK (self), NULL);
104 return self->priv->uri;
108 ev_link_get_link_type (EvLink *self)
110 g_return_val_if_fail (EV_IS_LINK (self), 0);
112 return self->priv->type;
116 ev_link_get_page (EvLink *self)
118 g_return_val_if_fail (EV_IS_LINK (self), 0);
120 return self->priv->page;
124 ev_link_get_top (EvLink *self)
126 g_return_val_if_fail (EV_IS_LINK (self), 0);
128 return self->priv->top;
132 ev_link_get_left (EvLink *self)
134 g_return_val_if_fail (EV_IS_LINK (self), 0);
136 return self->priv->left;
140 ev_link_get_bottom (EvLink *self)
142 g_return_val_if_fail (EV_IS_LINK (self), 0);
144 return self->priv->bottom;
148 ev_link_get_right (EvLink *self)
150 g_return_val_if_fail (EV_IS_LINK (self), 0);
152 return self->priv->right;
156 ev_link_get_zoom (EvLink *self)
158 g_return_val_if_fail (EV_IS_LINK (self), 0);
160 return self->priv->zoom;
164 ev_link_get_property (GObject *object, guint prop_id, GValue *value,
165 GParamSpec *param_spec)
169 self = EV_LINK (object);
173 g_value_set_string (value, self->priv->title);
176 g_value_set_string (value, self->priv->uri);
179 g_value_set_enum (value, self->priv->type);
182 g_value_set_int (value, self->priv->page);
185 g_value_set_double (value, self->priv->top);
188 g_value_set_double (value, self->priv->left);
191 g_value_set_double (value, self->priv->bottom);
194 g_value_set_double (value, self->priv->left);
197 g_value_set_double (value, self->priv->zoom);
200 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
208 ev_link_set_property (GObject *object, guint prop_id, const GValue *value,
209 GParamSpec *param_spec)
211 EvLink *link = EV_LINK (object);
215 link->priv->title = g_strdup (g_value_get_string (value));
218 link->priv->uri = g_strdup (g_value_get_string (value));
221 link->priv->type = g_value_get_enum (value);
224 link->priv->page = g_value_get_int (value);
227 link->priv->top = g_value_get_double (value);
230 link->priv->left = g_value_get_double (value);
233 link->priv->bottom = g_value_get_double (value);
236 link->priv->right = g_value_get_double (value);
239 link->priv->zoom = g_value_get_double (value);
243 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
251 ev_window_dispose (GObject *object)
255 g_return_if_fail (EV_IS_LINK (object));
257 priv = EV_LINK (object)->priv;
260 g_free (priv->title);
269 G_OBJECT_CLASS (ev_link_parent_class)->dispose (object);
273 ev_link_init (EvLink *ev_link)
275 ev_link->priv = EV_LINK_GET_PRIVATE (ev_link);
277 ev_link->priv->type = EV_LINK_TYPE_TITLE;
281 ev_link_class_init (EvLinkClass *ev_window_class)
283 GObjectClass *g_object_class;
285 g_object_class = G_OBJECT_CLASS (ev_window_class);
286 g_object_class->dispose = ev_window_dispose;
287 g_object_class->set_property = ev_link_set_property;
288 g_object_class->get_property = ev_link_get_property;
290 g_type_class_add_private (g_object_class, sizeof (EvLinkPrivate));
292 g_object_class_install_property (g_object_class,
294 g_param_spec_string ("title",
299 G_PARAM_CONSTRUCT_ONLY));
300 g_object_class_install_property (g_object_class,
302 g_param_spec_string ("uri",
307 G_PARAM_CONSTRUCT_ONLY));
308 g_object_class_install_property (g_object_class,
310 g_param_spec_enum ("type",
316 G_PARAM_CONSTRUCT_ONLY));
317 g_object_class_install_property (g_object_class,
319 g_param_spec_int ("page",
326 G_PARAM_CONSTRUCT_ONLY));
327 g_object_class_install_property (g_object_class,
329 g_param_spec_double ("left",
331 "The left coordinate",
336 G_PARAM_CONSTRUCT_ONLY));
337 g_object_class_install_property (g_object_class,
339 g_param_spec_double ("top",
341 "The top coordinate",
346 G_PARAM_CONSTRUCT_ONLY));
347 g_object_class_install_property (g_object_class,
349 g_param_spec_double ("bottom",
351 "The bottom coordinate",
356 G_PARAM_CONSTRUCT_ONLY));
357 g_object_class_install_property (g_object_class,
359 g_param_spec_double ("right",
361 "The right coordinate",
366 G_PARAM_CONSTRUCT_ONLY));
368 g_object_class_install_property (g_object_class,
370 g_param_spec_double ("zoom",
377 G_PARAM_CONSTRUCT_ONLY));
381 ev_link_new_title (const char *title)
383 return EV_LINK (g_object_new (EV_TYPE_LINK,
385 "type", EV_LINK_TYPE_TITLE,
390 ev_link_new_page (const char *title, int page)
392 return EV_LINK (g_object_new (EV_TYPE_LINK,
395 "type", EV_LINK_TYPE_PAGE,
400 ev_link_new_page_xyz (const char *title,
406 return EV_LINK (g_object_new (EV_TYPE_LINK,
409 "type", EV_LINK_TYPE_PAGE_XYZ,
417 ev_link_new_page_fit (const char *title,
420 return EV_LINK (g_object_new (EV_TYPE_LINK,
423 "type", EV_LINK_TYPE_PAGE_FIT,
428 ev_link_new_page_fith (const char *title,
432 return EV_LINK (g_object_new (EV_TYPE_LINK,
435 "type", EV_LINK_TYPE_PAGE_FITH,
441 ev_link_new_page_fitv (const char *title,
445 return EV_LINK (g_object_new (EV_TYPE_LINK,
448 "type", EV_LINK_TYPE_PAGE_FITV,
454 ev_link_new_page_fitr (const char *title,
461 return EV_LINK (g_object_new (EV_TYPE_LINK,
464 "type", EV_LINK_TYPE_PAGE_FITR,
473 ev_link_new_external (const char *title, const char *uri)
475 return EV_LINK (g_object_new (EV_TYPE_LINK,
478 "type", EV_LINK_TYPE_EXTERNAL_URI,
485 ev_link_mapping_free_foreach (EvLinkMapping *mapping)
487 g_object_unref (G_OBJECT (mapping->link));
492 ev_link_mapping_free (GList *link_mapping)
494 if (link_mapping == NULL)
497 g_list_foreach (link_mapping, (GFunc) (ev_link_mapping_free_foreach), NULL);
498 g_list_free (link_mapping);
503 ev_link_mapping_find (GList *link_mapping,
513 for (list = link_mapping; list; list = list->next) {
514 EvLinkMapping *mapping = list->data;
517 if ((x >= mapping->x1) &&
518 (y >= mapping->y1) &&
519 (x <= mapping->x2) &&
520 (y <= mapping->y2)) {
521 link = mapping->link;