]> www.fi.muni.cz Git - evince.git/blob - backend/ev-link-dest.c
2fd2f4d55c64fdbf916bcb615846f806e51e7bae
[evince.git] / backend / ev-link-dest.c
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 #include "ev-link-dest.h"
22
23 enum {
24         PROP_0,
25         PROP_TYPE,
26         PROP_PAGE,
27         PROP_LEFT,
28         PROP_TOP,
29         PROP_BOTTOM,
30         PROP_RIGHT,
31         PROP_ZOOM,
32         PROP_NAMED
33 };
34
35 struct _EvLinkDest {
36         GObject base_instance;
37         
38         EvLinkDestPrivate *priv;
39 };
40
41 struct _EvLinkDestClass {
42         GObjectClass base_class;
43 };
44
45 struct _EvLinkDestPrivate {
46         EvLinkDestType type;
47         int            page;
48         double         top;
49         double         left;
50         double         bottom;
51         double         right;
52         double         zoom;
53         gchar         *named;
54 };
55
56 G_DEFINE_TYPE (EvLinkDest, ev_link_dest, G_TYPE_OBJECT)
57
58 #define EV_LINK_DEST_GET_PRIVATE(object) \
59         (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_LINK_DEST, EvLinkDestPrivate))
60
61 GType
62 ev_link_dest_type_get_type (void)
63 {
64         static GType type = 0;
65
66         if (G_UNLIKELY (type == 0)) {
67                 static const GEnumValue values[] = {
68                         { EV_LINK_DEST_TYPE_PAGE, "EV_LINK_DEST_TYPE_PAGE", "page" },
69                         { EV_LINK_DEST_TYPE_XYZ, "EV_LINK_DEST_TYPE_XYZ", "xyz" },
70                         { EV_LINK_DEST_TYPE_FIT, "EV_LINK_DEST_TYPE_FIT", "fit" },
71                         { EV_LINK_DEST_TYPE_FITH, "EV_LINK_DEST_TYPE_FITH", "fith" },
72                         { EV_LINK_DEST_TYPE_FITV, "EV_LINK_DEST_TYPE_FITV", "fitv" },
73                         { EV_LINK_DEST_TYPE_FITR, "EV_LINK_DEST_TYPE_FITR", "fitr" },
74                         { EV_LINK_DEST_TYPE_NAMED, "EV_LINK_DEST_TYPE_NAMED", "named" },
75                         { EV_LINK_DEST_TYPE_UNKNOWN, "EV_LINK_DEST_TYPE_UNKNOWN", "unknown" },
76                         { 0, NULL, NULL }
77                 };
78
79                 type = g_enum_register_static ("EvLinkDestType", values);
80         }
81
82         return type;
83 }
84
85 EvLinkDestType
86 ev_link_dest_get_dest_type (EvLinkDest *self)
87 {
88         g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
89
90         return self->priv->type;
91 }
92
93 gint
94 ev_link_dest_get_page (EvLinkDest *self)
95 {
96         g_return_val_if_fail (EV_IS_LINK_DEST (self), -1);
97
98         return self->priv->page;
99 }
100
101 gdouble
102 ev_link_dest_get_top (EvLinkDest *self)
103 {
104         g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
105
106         return self->priv->top;
107 }
108
109 gdouble
110 ev_link_dest_get_left (EvLinkDest *self)
111 {
112         g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
113
114         return self->priv->left;
115 }
116
117 gdouble
118 ev_link_dest_get_bottom (EvLinkDest *self)
119 {
120         g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
121
122         return self->priv->bottom;
123 }
124
125 gdouble
126 ev_link_dest_get_right (EvLinkDest *self)
127 {
128         g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
129
130         return self->priv->right;
131 }
132
133 gdouble
134 ev_link_dest_get_zoom (EvLinkDest *self)
135 {
136         g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
137
138         return self->priv->zoom;
139 }
140
141 const gchar *
142 ev_link_dest_get_named_dest (EvLinkDest *self)
143 {
144         g_return_val_if_fail (EV_IS_LINK_DEST (self), NULL);
145
146         return self->priv->named;
147 }
148
149 static void
150 ev_link_dest_get_property (GObject    *object,
151                            guint       prop_id,
152                            GValue     *value,
153                            GParamSpec *param_spec)
154 {
155         EvLinkDest *self;
156
157         self = EV_LINK_DEST (object);
158
159         switch (prop_id) {
160                 case PROP_TYPE:
161                         g_value_set_enum (value, self->priv->type);
162                         break;
163                 case PROP_PAGE:
164                         g_value_set_int (value, self->priv->page);
165                         break;
166                 case PROP_TOP:
167                         g_value_set_double (value, self->priv->top);
168                         break;
169                 case PROP_LEFT:
170                         g_value_set_double (value, self->priv->left);
171                         break;
172                 case PROP_BOTTOM:
173                         g_value_set_double (value, self->priv->bottom);
174                         break;
175                 case PROP_RIGHT:
176                         g_value_set_double (value, self->priv->left);
177                         break;
178                 case PROP_ZOOM:
179                         g_value_set_double (value, self->priv->zoom);
180                         break;
181                 case PROP_NAMED:
182                         g_value_set_string (value, self->priv->named);
183                         break;
184                 default:
185                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
186                                                            prop_id,
187                                                            param_spec);
188                         break;
189         }
190 }
191
192 static void
193 ev_link_dest_set_property (GObject      *object,
194                            guint         prop_id,
195                            const GValue *value,
196                            GParamSpec   *param_spec)
197 {
198         EvLinkDest *self = EV_LINK_DEST (object);
199
200         switch (prop_id) {
201                 case PROP_TYPE:
202                         self->priv->type = g_value_get_enum (value);
203                         break;
204                 case PROP_PAGE:
205                         self->priv->page = g_value_get_int (value);
206                         break;
207                 case PROP_TOP:
208                         self->priv->top = g_value_get_double (value);
209                         break;
210                 case PROP_LEFT:
211                         self->priv->left = g_value_get_double (value);
212                         break;
213                 case PROP_BOTTOM:
214                         self->priv->bottom = g_value_get_double (value);
215                         break;
216                 case PROP_RIGHT:
217                         self->priv->right = g_value_get_double (value);
218                         break;
219                 case PROP_ZOOM:
220                         self->priv->zoom = g_value_get_double (value);
221                         break;
222                 case PROP_NAMED:
223                         self->priv->named = g_value_dup_string (value);
224                         break;
225                 default:
226                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
227                                                            prop_id,
228                                                            param_spec);
229                         break;
230         }
231 }
232
233 static void
234 ev_link_dest_finalize (GObject *object)
235 {
236         EvLinkDestPrivate *priv;
237
238         priv = EV_LINK_DEST (object)->priv;
239
240         if (priv->named) {
241                 g_free (priv->named);
242                 priv->named = NULL;
243         }
244
245         G_OBJECT_CLASS (ev_link_dest_parent_class)->finalize (object);
246 }
247
248 static void
249 ev_link_dest_init (EvLinkDest *ev_link_dest)
250 {
251         ev_link_dest->priv = EV_LINK_DEST_GET_PRIVATE (ev_link_dest);
252
253         ev_link_dest->priv->named = NULL;
254 }
255
256 static void
257 ev_link_dest_class_init (EvLinkDestClass *ev_link_dest_class)
258 {
259         GObjectClass *g_object_class;
260
261         g_object_class = G_OBJECT_CLASS (ev_link_dest_class);
262
263         g_object_class->set_property = ev_link_dest_set_property;
264         g_object_class->get_property = ev_link_dest_get_property;
265
266         g_object_class->finalize = ev_link_dest_finalize;
267
268         g_type_class_add_private (g_object_class, sizeof (EvLinkDestPrivate));
269
270         g_object_class_install_property (g_object_class,
271                                          PROP_TYPE,
272                                          g_param_spec_enum  ("type",
273                                                              "Dest Type",
274                                                              "The destination type",
275                                                              EV_TYPE_LINK_DEST_TYPE,
276                                                              EV_LINK_DEST_TYPE_UNKNOWN,
277                                                              G_PARAM_READWRITE |
278                                                              G_PARAM_CONSTRUCT_ONLY));
279         g_object_class_install_property (g_object_class,
280                                          PROP_PAGE,
281                                          g_param_spec_int ("page",
282                                                            "Dest Page",
283                                                            "The destination page",
284                                                            -1,
285                                                            G_MAXINT,
286                                                            0,
287                                                            G_PARAM_READWRITE |
288                                                            G_PARAM_CONSTRUCT_ONLY));
289         g_object_class_install_property (g_object_class,
290                                          PROP_LEFT,
291                                          g_param_spec_double ("left",
292                                                               "Left coordinate",
293                                                               "The left coordinate",
294                                                               -G_MAXDOUBLE,
295                                                               G_MAXDOUBLE,
296                                                               0,
297                                                               G_PARAM_READWRITE |
298                                                               G_PARAM_CONSTRUCT_ONLY));
299         g_object_class_install_property (g_object_class,
300                                          PROP_TOP,
301                                          g_param_spec_double ("top",
302                                                               "Top coordinate",
303                                                               "The top coordinate",
304                                                               -G_MAXDOUBLE,
305                                                               G_MAXDOUBLE,
306                                                               0,
307                                                               G_PARAM_READWRITE |
308                                                               G_PARAM_CONSTRUCT_ONLY));
309         g_object_class_install_property (g_object_class,
310                                          PROP_BOTTOM,
311                                          g_param_spec_double ("bottom",
312                                                               "Bottom coordinate",
313                                                               "The bottom coordinate",
314                                                               -G_MAXDOUBLE,
315                                                               G_MAXDOUBLE,
316                                                               0,
317                                                               G_PARAM_READWRITE |
318                                                               G_PARAM_CONSTRUCT_ONLY));
319         g_object_class_install_property (g_object_class,
320                                          PROP_RIGHT,
321                                          g_param_spec_double ("right",
322                                                               "Right coordinate",
323                                                               "The right coordinate",
324                                                               -G_MAXDOUBLE,
325                                                               G_MAXDOUBLE,
326                                                               0,
327                                                               G_PARAM_READWRITE |
328                                                               G_PARAM_CONSTRUCT_ONLY));
329
330         g_object_class_install_property (g_object_class,
331                                          PROP_ZOOM,
332                                          g_param_spec_double ("zoom",
333                                                               "Zoom",
334                                                               "Zoom",
335                                                               0,
336                                                               G_MAXDOUBLE,
337                                                               0,
338                                                               G_PARAM_READWRITE |
339                                                               G_PARAM_CONSTRUCT_ONLY));
340         g_object_class_install_property (g_object_class,
341                                          PROP_NAMED,
342                                          g_param_spec_string ("named",
343                                                               "Named destination",
344                                                               "The named destination",
345                                                               NULL,
346                                                               G_PARAM_READWRITE |
347                                                               G_PARAM_CONSTRUCT_ONLY));
348 }
349
350 EvLinkDest *
351 ev_link_dest_new_page (gint page)
352 {
353         return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
354                                            "page", page,
355                                            "type", EV_LINK_DEST_TYPE_PAGE,
356                                            NULL));
357 }
358
359 EvLinkDest *
360 ev_link_dest_new_xyz (gint    page,
361                       gdouble left,
362                       gdouble top,
363                       gdouble zoom)
364 {
365         return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
366                                            "page", page,
367                                            "type", EV_LINK_DEST_TYPE_XYZ,
368                                            "left", left,
369                                            "top", top,
370                                            "zoom", zoom,
371                                            NULL));
372 }
373
374 EvLinkDest *
375 ev_link_dest_new_fit (gint page)
376 {
377         return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
378                                            "page", page,
379                                            "type", EV_LINK_DEST_TYPE_FIT,
380                                            NULL));
381 }
382
383 EvLinkDest *
384 ev_link_dest_new_fith (gint    page,
385                        gdouble top)
386 {
387         return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
388                                            "page", page,
389                                            "type", EV_LINK_DEST_TYPE_FITH,
390                                            "top", top,
391                                            NULL));
392 }
393
394 EvLinkDest *
395 ev_link_dest_new_fitv (gint    page,
396                        gdouble left)
397 {
398         return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
399                                            "page", page,
400                                            "type", EV_LINK_DEST_TYPE_FITV,
401                                            "left", left,
402                                            NULL));
403 }
404
405 EvLinkDest *
406 ev_link_dest_new_fitr (gint    page,
407                        gdouble left,
408                        gdouble bottom,
409                        gdouble right,
410                        gdouble top)
411 {
412         return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
413                                            "page", page,
414                                            "type", EV_LINK_DEST_TYPE_FITR,
415                                            "left", left,
416                                            "bottom", bottom,
417                                            "right", right,
418                                            "top", top,
419                                            NULL));
420 }
421
422 EvLinkDest *
423 ev_link_dest_new_named (const gchar *named_dest)
424 {
425         return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
426                                            "named", named_dest,
427                                            "type", EV_LINK_DEST_TYPE_NAMED,
428                                            NULL));
429 }