]> www.fi.muni.cz Git - evince.git/blob - libdocument/ev-link-dest.c
[dualscreen] fix crash on ctrl+w and fix control window closing
[evince.git] / libdocument / 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., 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 {
27         PROP_0,
28         PROP_TYPE,
29         PROP_PAGE,
30         PROP_LEFT,
31         PROP_TOP,
32         PROP_BOTTOM,
33         PROP_RIGHT,
34         PROP_ZOOM,
35         PROP_CHANGE,
36         PROP_NAMED,
37         PROP_PAGE_LABEL
38 };
39
40 typedef enum {
41         EV_DEST_CHANGE_TOP    = 1 << 0,
42         EV_DEST_CHANGE_LEFT   = 1 << 1,
43         EV_DEST_CHANGE_ZOOM   = 1 << 2
44 } EvDestChange;
45
46 struct _EvLinkDest {
47         GObject base_instance;
48         
49         EvLinkDestPrivate *priv;
50 };
51
52 struct _EvLinkDestClass {
53         GObjectClass base_class;
54 };
55
56 struct _EvLinkDestPrivate {
57         EvLinkDestType type;
58         int            page;
59         double         top;
60         double         left;
61         double         bottom;
62         double         right;
63         double         zoom;
64         EvDestChange   change;
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
74 EvLinkDestType
75 ev_link_dest_get_dest_type (EvLinkDest *self)
76 {
77         g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
78
79         return self->priv->type;
80 }
81
82 gint
83 ev_link_dest_get_page (EvLinkDest *self)
84 {
85         g_return_val_if_fail (EV_IS_LINK_DEST (self), -1);
86
87         return self->priv->page;
88 }
89
90 gdouble
91 ev_link_dest_get_top (EvLinkDest *self,
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
103 ev_link_dest_get_left (EvLinkDest *self,
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
115 ev_link_dest_get_bottom (EvLinkDest *self)
116 {
117         g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
118
119         return self->priv->bottom;
120 }
121
122 gdouble
123 ev_link_dest_get_right (EvLinkDest *self)
124 {
125         g_return_val_if_fail (EV_IS_LINK_DEST (self), 0);
126
127         return self->priv->right;
128 }
129
130 gdouble
131 ev_link_dest_get_zoom (EvLinkDest *self,
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 *
143 ev_link_dest_get_named_dest (EvLinkDest *self)
144 {
145         g_return_val_if_fail (EV_IS_LINK_DEST (self), NULL);
146
147         return self->priv->named;
148 }
149
150 const gchar *
151 ev_link_dest_get_page_label (EvLinkDest *self)
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
274 ev_link_dest_init (EvLinkDest *ev_link_dest)
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
282 ev_link_dest_class_init (EvLinkDestClass *ev_link_dest_class)
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,
301                                                              EV_LINK_DEST_TYPE_UNKNOWN,
302                                                              G_PARAM_READWRITE |
303                                                              G_PARAM_CONSTRUCT_ONLY));
304         g_object_class_install_property (g_object_class,
305                                          PROP_PAGE,
306                                          g_param_spec_int ("page",
307                                                            "Dest Page",
308                                                            "The destination page",
309                                                            -1,
310                                                            G_MAXINT,
311                                                            0,
312                                                            G_PARAM_READWRITE |
313                                                            G_PARAM_CONSTRUCT_ONLY));
314         g_object_class_install_property (g_object_class,
315                                          PROP_LEFT,
316                                          g_param_spec_double ("left",
317                                                               "Left coordinate",
318                                                               "The left coordinate",
319                                                               -G_MAXDOUBLE,
320                                                               G_MAXDOUBLE,
321                                                               0,
322                                                               G_PARAM_READWRITE |
323                                                               G_PARAM_CONSTRUCT_ONLY));
324         g_object_class_install_property (g_object_class,
325                                          PROP_TOP,
326                                          g_param_spec_double ("top",
327                                                               "Top coordinate",
328                                                               "The top coordinate",
329                                                               -G_MAXDOUBLE,
330                                                               G_MAXDOUBLE,
331                                                               0,
332                                                               G_PARAM_READWRITE |
333                                                               G_PARAM_CONSTRUCT_ONLY));
334         g_object_class_install_property (g_object_class,
335                                          PROP_BOTTOM,
336                                          g_param_spec_double ("bottom",
337                                                               "Bottom coordinate",
338                                                               "The bottom coordinate",
339                                                               -G_MAXDOUBLE,
340                                                               G_MAXDOUBLE,
341                                                               0,
342                                                               G_PARAM_READWRITE |
343                                                               G_PARAM_CONSTRUCT_ONLY));
344         g_object_class_install_property (g_object_class,
345                                          PROP_RIGHT,
346                                          g_param_spec_double ("right",
347                                                               "Right coordinate",
348                                                               "The right coordinate",
349                                                               -G_MAXDOUBLE,
350                                                               G_MAXDOUBLE,
351                                                               0,
352                                                               G_PARAM_READWRITE |
353                                                               G_PARAM_CONSTRUCT_ONLY));
354
355         g_object_class_install_property (g_object_class,
356                                          PROP_ZOOM,
357                                          g_param_spec_double ("zoom",
358                                                               "Zoom",
359                                                               "Zoom",
360                                                               0,
361                                                               G_MAXDOUBLE,
362                                                               0,
363                                                               G_PARAM_READWRITE |
364                                                               G_PARAM_CONSTRUCT_ONLY));
365         g_object_class_install_property (g_object_class,
366                                          PROP_CHANGE,
367                                          g_param_spec_uint ("change",
368                                                             "Change",
369                                                             "Wether top, left, and zoom should be changed",
370                                                             0,
371                                                             G_MAXUINT,
372                                                             0,
373                                                             G_PARAM_READWRITE |
374                                                             G_PARAM_CONSTRUCT_ONLY));
375         g_object_class_install_property (g_object_class,
376                                          PROP_NAMED,
377                                          g_param_spec_string ("named",
378                                                               "Named destination",
379                                                               "The named destination",
380                                                               NULL,
381                                                               G_PARAM_READWRITE |
382                                                               G_PARAM_CONSTRUCT_ONLY));
383         g_object_class_install_property (g_object_class,
384                                          PROP_PAGE_LABEL,
385                                          g_param_spec_string ("page_label",
386                                                               "Label of the page",
387                                                               "The label of the destination page",
388                                                               NULL,
389                                                               G_PARAM_READWRITE |
390                                                               G_PARAM_CONSTRUCT_ONLY));
391 }
392
393 EvLinkDest *
394 ev_link_dest_new_page (gint page)
395 {
396         return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
397                                            "page", page,
398                                            "type", EV_LINK_DEST_TYPE_PAGE,
399                                            NULL));
400 }
401
402 EvLinkDest *
403 ev_link_dest_new_xyz (gint     page,
404                       gdouble  left,
405                       gdouble  top,
406                       gdouble  zoom,
407                       gboolean change_left,
408                       gboolean change_top,
409                       gboolean change_zoom)
410 {
411         EvDestChange change = 0;
412
413         if (change_left)
414                 change |= EV_DEST_CHANGE_LEFT;
415         if (change_top)
416                 change |= EV_DEST_CHANGE_TOP;
417         if (change_zoom)
418                 change |= EV_DEST_CHANGE_ZOOM;
419         
420         return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
421                                            "page", page,
422                                            "type", EV_LINK_DEST_TYPE_XYZ,
423                                            "left", left,
424                                            "top", top,
425                                            "zoom", zoom,
426                                            "change", change,
427                                            NULL));
428 }
429
430 EvLinkDest *
431 ev_link_dest_new_fit (gint page)
432 {
433         return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
434                                            "page", page,
435                                            "type", EV_LINK_DEST_TYPE_FIT,
436                                            NULL));
437 }
438
439 EvLinkDest *
440 ev_link_dest_new_fith (gint     page,
441                        gdouble  top,
442                        gboolean change_top)
443 {
444         EvDestChange change = 0;
445
446         if (change_top)
447                 change |= EV_DEST_CHANGE_TOP;
448         
449         return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
450                                            "page", page,
451                                            "type", EV_LINK_DEST_TYPE_FITH,
452                                            "top", top,
453                                            "change", change,
454                                            NULL));
455 }
456
457 EvLinkDest *
458 ev_link_dest_new_fitv (gint     page,
459                        gdouble  left,
460                        gboolean change_left)
461 {
462         EvDestChange change = 0;
463
464         if (change_left)
465                 change |= EV_DEST_CHANGE_LEFT;
466
467         return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
468                                            "page", page,
469                                            "type", EV_LINK_DEST_TYPE_FITV,
470                                            "left", left,
471                                            "change", change,
472                                            NULL));
473 }
474
475 EvLinkDest *
476 ev_link_dest_new_fitr (gint    page,
477                        gdouble left,
478                        gdouble bottom,
479                        gdouble right,
480                        gdouble top)
481 {
482         EvDestChange change = EV_DEST_CHANGE_TOP | EV_DEST_CHANGE_LEFT;
483         
484         return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
485                                            "page", page,
486                                            "type", EV_LINK_DEST_TYPE_FITR,
487                                            "left", left,
488                                            "bottom", bottom,
489                                            "right", right,
490                                            "top", top,
491                                            "change", change,
492                                            NULL));
493 }
494
495 EvLinkDest *
496 ev_link_dest_new_named (const gchar *named_dest)
497 {
498         return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST,
499                                            "named", named_dest,
500                                            "type", EV_LINK_DEST_TYPE_NAMED,
501                                            NULL));
502 }
503
504 EvLinkDest *
505 ev_link_dest_new_page_label (const gchar *page_label)
506 {
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,
510                                            NULL));
511 }