Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-link-dest.c
Go to the documentation of this file.
1 /* this file is part of evince, a gnome document viewer
2  *
3  * Copyright (C) 2006 Carlos Garcia Campos <carlosgc@gnome.org>
4  * Copyright (C) 2005 Red Hat, Inc.
5  *
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.
10  *
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.
15  *
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.
19  */
20 
21 #include <config.h>
22 
23 #include "ev-link-dest.h"
24 #include "ev-document-type-builtins.h"
25 
26 enum {
38 };
39 
40 typedef enum {
44 } EvDestChange;
45 
46 struct _EvLinkDest {
47  GObject base_instance;
48 
50 };
51 
53  GObjectClass base_class;
54 };
55 
58  int page;
59  double top;
60  double left;
61  double bottom;
62  double right;
63  double zoom;
65  gchar *named;
66  gchar *page_label;
67 };
68 
69 G_DEFINE_TYPE (EvLinkDest, ev_link_dest, G_TYPE_OBJECT)
70 
71 #define EV_LINK_DEST_GET_PRIVATE(object) \
72  (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_LINK_DEST, EvLinkDestPrivate))
73 
76 {
77  g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
78 
79  return self->priv->type;
80 }
81 
82 gint
84 {
85  g_return_val_if_fail (EV_IS_LINK_DEST (self), -1);
86 
87  return self->priv->page;
88 }
89 
90 gdouble
92  gboolean *change_top)
93 {
94  g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
95 
96  if (change_top)
97  *change_top = (self->priv->change & EV_DEST_CHANGE_TOP);
98 
99  return self->priv->top;
100 }
101 
102 gdouble
104  gboolean *change_left)
105 {
106  g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
107 
108  if (change_left)
109  *change_left = (self->priv->change & EV_DEST_CHANGE_LEFT);
110 
111  return self->priv->left;
112 }
113 
114 gdouble
116 {
117  g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
118 
119  return self->priv->bottom;
120 }
121 
122 gdouble
124 {
125  g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
126 
127  return self->priv->right;
128 }
129 
130 gdouble
132  gboolean *change_zoom)
133 {
134  g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
135 
136  if (change_zoom)
137  *change_zoom = (self->priv->change & EV_DEST_CHANGE_ZOOM);
138 
139  return self->priv->zoom;
140 }
141 
142 const gchar *
144 {
145  g_return_val_if_fail (EV_IS_LINK_DEST (self), NULL);
146 
147  return self->priv->named;
148 }
149 
150 const gchar *
152 {
153  g_return_val_if_fail (EV_IS_LINK_DEST (self), NULL);
154 
155  return self->priv->page_label;
156 }
157 
158 static void
159 ev_link_dest_get_property (GObject *object,
160  guint prop_id,
161  GValue *value,
162  GParamSpec *param_spec)
163 {
164  EvLinkDest *self;
165 
166  self = EV_LINK_DEST (object);
167 
168  switch (prop_id) {
169  case PROP_TYPE:
170  g_value_set_enum (value, self->priv->type);
171  break;
172  case PROP_PAGE:
173  g_value_set_int (value, self->priv->page);
174  break;
175  case PROP_TOP:
176  g_value_set_double (value, self->priv->top);
177  break;
178  case PROP_LEFT:
179  g_value_set_double (value, self->priv->left);
180  break;
181  case PROP_BOTTOM:
182  g_value_set_double (value, self->priv->bottom);
183  break;
184  case PROP_RIGHT:
185  g_value_set_double (value, self->priv->left);
186  break;
187  case PROP_ZOOM:
188  g_value_set_double (value, self->priv->zoom);
189  break;
190  case PROP_CHANGE:
191  g_value_set_uint (value, self->priv->change);
192  break;
193  case PROP_NAMED:
194  g_value_set_string (value, self->priv->named);
195  break;
196  case PROP_PAGE_LABEL:
197  g_value_set_string (value, self->priv->page_label);
198  break;
199  default:
200  G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
201  prop_id,
202  param_spec);
203  break;
204  }
205 }
206 
207 static void
208 ev_link_dest_set_property (GObject *object,
209  guint prop_id,
210  const GValue *value,
211  GParamSpec *param_spec)
212 {
213  EvLinkDest *self = EV_LINK_DEST (object);
214 
215  switch (prop_id) {
216  case PROP_TYPE:
217  self->priv->type = g_value_get_enum (value);
218  break;
219  case PROP_PAGE:
220  self->priv->page = g_value_get_int (value);
221  break;
222  case PROP_TOP:
223  self->priv->top = g_value_get_double (value);
224  break;
225  case PROP_LEFT:
226  self->priv->left = g_value_get_double (value);
227  break;
228  case PROP_BOTTOM:
229  self->priv->bottom = g_value_get_double (value);
230  break;
231  case PROP_RIGHT:
232  self->priv->right = g_value_get_double (value);
233  break;
234  case PROP_ZOOM:
235  self->priv->zoom = g_value_get_double (value);
236  break;
237  case PROP_CHANGE:
238  self->priv->change = g_value_get_uint (value);
239  break;
240  case PROP_NAMED:
241  self->priv->named = g_value_dup_string (value);
242  break;
243  case PROP_PAGE_LABEL:
244  self->priv->page_label = g_value_dup_string (value);
245  break;
246  default:
247  G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
248  prop_id,
249  param_spec);
250  break;
251  }
252 }
253 
254 static void
255 ev_link_dest_finalize (GObject *object)
256 {
257  EvLinkDestPrivate *priv;
258 
259  priv = EV_LINK_DEST (object)->priv;
260 
261  if (priv->named) {
262  g_free (priv->named);
263  priv->named = NULL;
264  }
265  if (priv->page_label) {
266  g_free (priv->page_label);
267  priv->page_label = NULL;
268  }
269 
270  G_OBJECT_CLASS (ev_link_dest_parent_class)->finalize (object);
271 }
272 
273 static void
275 {
276  ev_link_dest->priv = EV_LINK_DEST_GET_PRIVATE (ev_link_dest);
277 
278  ev_link_dest->priv->named = NULL;
279 }
280 
281 static void
283 {
284  GObjectClass *g_object_class;
285 
286  g_object_class = G_OBJECT_CLASS (ev_link_dest_class);
287 
288  g_object_class->set_property = ev_link_dest_set_property;
289  g_object_class->get_property = ev_link_dest_get_property;
290 
291  g_object_class->finalize = ev_link_dest_finalize;
292 
293  g_type_class_add_private (g_object_class, sizeof (EvLinkDestPrivate));
294 
295  g_object_class_install_property (g_object_class,
296  PROP_TYPE,
297  g_param_spec_enum ("type",
298  "Dest Type",
299  "The destination type",
300  EV_TYPE_LINK_DEST_TYPE,
302  G_PARAM_READWRITE |
303  G_PARAM_CONSTRUCT_ONLY |
304  G_PARAM_STATIC_STRINGS));
305  g_object_class_install_property (g_object_class,
306  PROP_PAGE,
307  g_param_spec_int ("page",
308  "Dest Page",
309  "The destination page",
310  -1,
311  G_MAXINT,
312  0,
313  G_PARAM_READWRITE |
314  G_PARAM_CONSTRUCT_ONLY |
315  G_PARAM_STATIC_STRINGS));
316  g_object_class_install_property (g_object_class,
317  PROP_LEFT,
318  g_param_spec_double ("left",
319  "Left coordinate",
320  "The left coordinate",
321  -G_MAXDOUBLE,
322  G_MAXDOUBLE,
323  0,
324  G_PARAM_READWRITE |
325  G_PARAM_CONSTRUCT_ONLY |
326  G_PARAM_STATIC_STRINGS));
327  g_object_class_install_property (g_object_class,
328  PROP_TOP,
329  g_param_spec_double ("top",
330  "Top coordinate",
331  "The top coordinate",
332  -G_MAXDOUBLE,
333  G_MAXDOUBLE,
334  0,
335  G_PARAM_READWRITE |
336  G_PARAM_CONSTRUCT_ONLY |
337  G_PARAM_STATIC_STRINGS));
338  g_object_class_install_property (g_object_class,
339  PROP_BOTTOM,
340  g_param_spec_double ("bottom",
341  "Bottom coordinate",
342  "The bottom coordinate",
343  -G_MAXDOUBLE,
344  G_MAXDOUBLE,
345  0,
346  G_PARAM_READWRITE |
347  G_PARAM_CONSTRUCT_ONLY |
348  G_PARAM_STATIC_STRINGS));
349  g_object_class_install_property (g_object_class,
350  PROP_RIGHT,
351  g_param_spec_double ("right",
352  "Right coordinate",
353  "The right coordinate",
354  -G_MAXDOUBLE,
355  G_MAXDOUBLE,
356  0,
357  G_PARAM_READWRITE |
358  G_PARAM_CONSTRUCT_ONLY |
359  G_PARAM_STATIC_STRINGS));
360 
361  g_object_class_install_property (g_object_class,
362  PROP_ZOOM,
363  g_param_spec_double ("zoom",
364  "Zoom",
365  "Zoom",
366  0,
367  G_MAXDOUBLE,
368  0,
369  G_PARAM_READWRITE |
370  G_PARAM_CONSTRUCT_ONLY |
371  G_PARAM_STATIC_STRINGS));
372  g_object_class_install_property (g_object_class,
373  PROP_CHANGE,
374  g_param_spec_uint ("change",
375  "Change",
376  "Wether top, left, and zoom should be changed",
377  0,
378  G_MAXUINT,
379  0,
380  G_PARAM_READWRITE |
381  G_PARAM_CONSTRUCT_ONLY |
382  G_PARAM_STATIC_STRINGS));
383  g_object_class_install_property (g_object_class,
384  PROP_NAMED,
385  g_param_spec_string ("named",
386  "Named destination",
387  "The named destination",
388  NULL,
389  G_PARAM_READWRITE |
390  G_PARAM_CONSTRUCT_ONLY |
391  G_PARAM_STATIC_STRINGS));
392  g_object_class_install_property (g_object_class,
394  g_param_spec_string ("page-label",
395  "Label of the page",
396  "The label of the destination page",
397  NULL,
398  G_PARAM_READWRITE |
399  G_PARAM_CONSTRUCT_ONLY |
400  G_PARAM_STATIC_STRINGS));
401 }
402 
403 EvLinkDest *
405 {
406  return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
407  "page", page,
408  "type", EV_LINK_DEST_TYPE_PAGE,
409  NULL));
410 }
411 
412 EvLinkDest *
414  gdouble left,
415  gdouble top,
416  gdouble zoom,
417  gboolean change_left,
418  gboolean change_top,
419  gboolean change_zoom)
420 {
421  EvDestChange change = 0;
422 
423  if (change_left)
424  change |= EV_DEST_CHANGE_LEFT;
425  if (change_top)
426  change |= EV_DEST_CHANGE_TOP;
427  if (change_zoom)
428  change |= EV_DEST_CHANGE_ZOOM;
429 
430  return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
431  "page", page,
432  "type", EV_LINK_DEST_TYPE_XYZ,
433  "left", left,
434  "top", top,
435  "zoom", zoom,
436  "change", change,
437  NULL));
438 }
439 
440 EvLinkDest *
442 {
443  return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
444  "page", page,
445  "type", EV_LINK_DEST_TYPE_FIT,
446  NULL));
447 }
448 
449 EvLinkDest *
451  gdouble top,
452  gboolean change_top)
453 {
454  EvDestChange change = 0;
455 
456  if (change_top)
457  change |= EV_DEST_CHANGE_TOP;
458 
459  return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
460  "page", page,
461  "type", EV_LINK_DEST_TYPE_FITH,
462  "top", top,
463  "change", change,
464  NULL));
465 }
466 
467 EvLinkDest *
469  gdouble left,
470  gboolean change_left)
471 {
472  EvDestChange change = 0;
473 
474  if (change_left)
475  change |= EV_DEST_CHANGE_LEFT;
476 
477  return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
478  "page", page,
479  "type", EV_LINK_DEST_TYPE_FITV,
480  "left", left,
481  "change", change,
482  NULL));
483 }
484 
485 EvLinkDest *
487  gdouble left,
488  gdouble bottom,
489  gdouble right,
490  gdouble top)
491 {
493 
494  return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
495  "page", page,
496  "type", EV_LINK_DEST_TYPE_FITR,
497  "left", left,
498  "bottom", bottom,
499  "right", right,
500  "top", top,
501  "change", change,
502  NULL));
503 }
504 
505 EvLinkDest *
506 ev_link_dest_new_named (const gchar *named_dest)
507 {
508  return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
509  "named", named_dest,
510  "type", EV_LINK_DEST_TYPE_NAMED,
511  NULL));
512 }
513 
514 EvLinkDest *
515 ev_link_dest_new_page_label (const gchar *page_label)
516 {
517  return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
518  "page_label", page_label,
520  NULL));
521 }
522 
534 gboolean
536  EvLinkDest *b)
537 {
538  g_return_val_if_fail (EV_IS_LINK_DEST (a), FALSE);
539  g_return_val_if_fail (EV_IS_LINK_DEST (b), FALSE);
540 
541  if (a == b)
542  return TRUE;
543 
544  if (a->priv->type != b->priv->type)
545  return FALSE;
546 
547  switch (a->priv->type) {
549  return a->priv->page == b->priv->page;
550 
552  return a->priv->page == b->priv->page &&
553  a->priv->left == b->priv->left &&
554  a->priv->top == b->priv->top &&
555  a->priv->zoom == b->priv->zoom &&
556  a->priv->change == b->priv->change;
557 
559  return a->priv->page == b->priv->page;
560 
562  return a->priv->page == b->priv->page &&
563  a->priv->top == b->priv->top &&
564  a->priv->change == b->priv->change;
565 
567  return a->priv->page == b->priv->page &&
568  a->priv->left == b->priv->left &&
569  a->priv->change == b->priv->change;
570 
572  return a->priv->page == b->priv->page &&
573  a->priv->left == b->priv->left &&
574  a->priv->top == b->priv->top &&
575  a->priv->right == b->priv->right &&
576  a->priv->bottom == b->priv->bottom &&
577  a->priv->change == b->priv->change;
578 
580  return !g_strcmp0 (a->priv->named, b->priv->named);
581 
583  return !g_strcmp0 (a->priv->page_label, b->priv->page_label);
584 
585  default:
586  return FALSE;
587  }
588 
589  return FALSE;
590 }