1 /* this file is part of evince, a gnome document viewer
3 * Copyright (C) 2006 Carlos Garcia Campos <carlosgc@gnome.org>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "ev-link-dest.h"
24 #include "ev-document-type-builtins.h"
41 EV_DEST_CHANGE_TOP = 1 << 0,
42 EV_DEST_CHANGE_LEFT = 1 << 1,
43 EV_DEST_CHANGE_ZOOM = 1 << 2
47 GObject base_instance;
49 EvLinkDestPrivate *priv;
52 struct _EvLinkDestClass {
53 GObjectClass base_class;
56 struct _EvLinkDestPrivate {
69 G_DEFINE_TYPE (EvLinkDest, ev_link_dest, G_TYPE_OBJECT)
71 #define EV_LINK_DEST_GET_PRIVATE(object) \
72 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_LINK_DEST, EvLinkDestPrivate))
75 ev_link_dest_get_dest_type (EvLinkDest *self)
77 g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
79 return self->priv->type;
83 ev_link_dest_get_page (EvLinkDest *self)
85 g_return_val_if_fail (EV_IS_LINK_DEST (self), -1);
87 return self->priv->page;
91 ev_link_dest_get_top (EvLinkDest *self,
94 g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
97 *change_top = (self->priv->change & EV_DEST_CHANGE_TOP);
99 return self->priv->top;
103 ev_link_dest_get_left (EvLinkDest *self,
104 gboolean *change_left)
106 g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
109 *change_left = (self->priv->change & EV_DEST_CHANGE_LEFT);
111 return self->priv->left;
115 ev_link_dest_get_bottom (EvLinkDest *self)
117 g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
119 return self->priv->bottom;
123 ev_link_dest_get_right (EvLinkDest *self)
125 g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
127 return self->priv->right;
131 ev_link_dest_get_zoom (EvLinkDest *self,
132 gboolean *change_zoom)
134 g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
137 *change_zoom = (self->priv->change & EV_DEST_CHANGE_ZOOM);
139 return self->priv->zoom;
143 ev_link_dest_get_named_dest (EvLinkDest *self)
145 g_return_val_if_fail (EV_IS_LINK_DEST (self), NULL);
147 return self->priv->named;
151 ev_link_dest_get_page_label (EvLinkDest *self)
153 g_return_val_if_fail (EV_IS_LINK_DEST (self), NULL);
155 return self->priv->page_label;
159 ev_link_dest_get_property (GObject *object,
162 GParamSpec *param_spec)
166 self = EV_LINK_DEST (object);
170 g_value_set_enum (value, self->priv->type);
173 g_value_set_int (value, self->priv->page);
176 g_value_set_double (value, self->priv->top);
179 g_value_set_double (value, self->priv->left);
182 g_value_set_double (value, self->priv->bottom);
185 g_value_set_double (value, self->priv->left);
188 g_value_set_double (value, self->priv->zoom);
191 g_value_set_uint (value, self->priv->change);
194 g_value_set_string (value, self->priv->named);
196 case PROP_PAGE_LABEL:
197 g_value_set_string (value, self->priv->page_label);
200 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
208 ev_link_dest_set_property (GObject *object,
211 GParamSpec *param_spec)
213 EvLinkDest *self = EV_LINK_DEST (object);
217 self->priv->type = g_value_get_enum (value);
220 self->priv->page = g_value_get_int (value);
223 self->priv->top = g_value_get_double (value);
226 self->priv->left = g_value_get_double (value);
229 self->priv->bottom = g_value_get_double (value);
232 self->priv->right = g_value_get_double (value);
235 self->priv->zoom = g_value_get_double (value);
238 self->priv->change = g_value_get_uint (value);
241 self->priv->named = g_value_dup_string (value);
243 case PROP_PAGE_LABEL:
244 self->priv->page_label = g_value_dup_string (value);
247 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
255 ev_link_dest_finalize (GObject *object)
257 EvLinkDestPrivate *priv;
259 priv = EV_LINK_DEST (object)->priv;
262 g_free (priv->named);
265 if (priv->page_label) {
266 g_free (priv->page_label);
267 priv->page_label = NULL;
270 G_OBJECT_CLASS (ev_link_dest_parent_class)->finalize (object);
274 ev_link_dest_init (EvLinkDest *ev_link_dest)
276 ev_link_dest->priv = EV_LINK_DEST_GET_PRIVATE (ev_link_dest);
278 ev_link_dest->priv->named = NULL;
282 ev_link_dest_class_init (EvLinkDestClass *ev_link_dest_class)
284 GObjectClass *g_object_class;
286 g_object_class = G_OBJECT_CLASS (ev_link_dest_class);
288 g_object_class->set_property = ev_link_dest_set_property;
289 g_object_class->get_property = ev_link_dest_get_property;
291 g_object_class->finalize = ev_link_dest_finalize;
293 g_type_class_add_private (g_object_class, sizeof (EvLinkDestPrivate));
295 g_object_class_install_property (g_object_class,
297 g_param_spec_enum ("type",
299 "The destination type",
300 EV_TYPE_LINK_DEST_TYPE,
301 EV_LINK_DEST_TYPE_UNKNOWN,
303 G_PARAM_CONSTRUCT_ONLY));
304 g_object_class_install_property (g_object_class,
306 g_param_spec_int ("page",
308 "The destination page",
313 G_PARAM_CONSTRUCT_ONLY));
314 g_object_class_install_property (g_object_class,
316 g_param_spec_double ("left",
318 "The left coordinate",
323 G_PARAM_CONSTRUCT_ONLY));
324 g_object_class_install_property (g_object_class,
326 g_param_spec_double ("top",
328 "The top coordinate",
333 G_PARAM_CONSTRUCT_ONLY));
334 g_object_class_install_property (g_object_class,
336 g_param_spec_double ("bottom",
338 "The bottom coordinate",
343 G_PARAM_CONSTRUCT_ONLY));
344 g_object_class_install_property (g_object_class,
346 g_param_spec_double ("right",
348 "The right coordinate",
353 G_PARAM_CONSTRUCT_ONLY));
355 g_object_class_install_property (g_object_class,
357 g_param_spec_double ("zoom",
364 G_PARAM_CONSTRUCT_ONLY));
365 g_object_class_install_property (g_object_class,
367 g_param_spec_uint ("change",
369 "Wether top, left, and zoom should be changed",
374 G_PARAM_CONSTRUCT_ONLY));
375 g_object_class_install_property (g_object_class,
377 g_param_spec_string ("named",
379 "The named destination",
382 G_PARAM_CONSTRUCT_ONLY));
383 g_object_class_install_property (g_object_class,
385 g_param_spec_string ("page_label",
387 "The label of the destination page",
390 G_PARAM_CONSTRUCT_ONLY));
394 ev_link_dest_new_page (gint page)
396 return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
398 "type", EV_LINK_DEST_TYPE_PAGE,
403 ev_link_dest_new_xyz (gint page,
407 gboolean change_left,
409 gboolean change_zoom)
411 EvDestChange change = 0;
414 change |= EV_DEST_CHANGE_LEFT;
416 change |= EV_DEST_CHANGE_TOP;
418 change |= EV_DEST_CHANGE_ZOOM;
420 return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
422 "type", EV_LINK_DEST_TYPE_XYZ,
431 ev_link_dest_new_fit (gint page)
433 return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
435 "type", EV_LINK_DEST_TYPE_FIT,
440 ev_link_dest_new_fith (gint page,
444 EvDestChange change = 0;
447 change |= EV_DEST_CHANGE_TOP;
449 return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
451 "type", EV_LINK_DEST_TYPE_FITH,
458 ev_link_dest_new_fitv (gint page,
460 gboolean change_left)
462 EvDestChange change = 0;
465 change |= EV_DEST_CHANGE_LEFT;
467 return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
469 "type", EV_LINK_DEST_TYPE_FITV,
476 ev_link_dest_new_fitr (gint page,
482 EvDestChange change = EV_DEST_CHANGE_TOP | EV_DEST_CHANGE_LEFT;
484 return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
486 "type", EV_LINK_DEST_TYPE_FITR,
496 ev_link_dest_new_named (const gchar *named_dest)
498 return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
500 "type", EV_LINK_DEST_TYPE_NAMED,
505 ev_link_dest_new_page_label (const gchar *page_label)
507 return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
508 "page_label", page_label,
509 "type", EV_LINK_DEST_TYPE_PAGE_LABEL,