]> www.fi.muni.cz Git - evince.git/blob - libdocument/ev-mapping.c
Bump GTK+ requirements to 2.20.0
[evince.git] / libdocument / ev-mapping.c
1 /* ev-mapping.c
2  *  this file is part of evince, a gnome document viewer
3  *
4  * Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
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-mapping.h"
22
23 EvMapping *
24 ev_mapping_list_find (GList         *mapping_list,
25                       gconstpointer  data)
26 {
27         GList *list;
28
29         for (list = mapping_list; list; list = list->next) {
30                 EvMapping *mapping = list->data;
31
32                 if (mapping->data == data)
33                         return mapping;
34         }
35
36         return NULL;
37 }
38
39 EvMapping *
40 ev_mapping_list_find_custom (GList         *mapping_list,
41                              gconstpointer  data,
42                              GCompareFunc   func)
43 {
44         GList *list;
45
46         for (list = mapping_list; list; list = list->next) {
47                 EvMapping *mapping = list->data;
48
49                 if (!func (mapping->data, data))
50                         return mapping;
51         }
52
53         return NULL;
54 }
55
56 gpointer
57 ev_mapping_list_get_data (GList   *mapping_list,
58                           gdouble  x,
59                           gdouble  y)
60 {
61         GList *list;
62
63         for (list = mapping_list; list; list = list->next) {
64                 EvMapping *mapping = list->data;
65
66                 if ((x >= mapping->area.x1) &&
67                     (y >= mapping->area.y1) &&
68                     (x <= mapping->area.x2) &&
69                     (y <= mapping->area.y2)) {
70                         return mapping->data;
71                 }
72         }
73
74         return NULL;
75 }
76
77 static void
78 mapping_list_free_foreach (EvMapping     *mapping,
79                            GDestroyNotify destroy_func)
80 {
81         destroy_func (mapping->data);
82         g_free (mapping);
83 }
84
85 void
86 ev_mapping_list_free (GList          *mapping_list,
87                       GDestroyNotify  destroy_func)
88 {
89         g_list_foreach (mapping_list,
90                         (GFunc)mapping_list_free_foreach,
91                         destroy_func);
92         g_list_free (mapping_list);
93 }