2 * this file is part of evince, a gnome document viewer
4 * Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
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.
21 #include "ev-mapping-list.h"
23 struct _EvMappingList {
26 GDestroyNotify data_destroy_func;
27 volatile gint ref_count;
31 ev_mapping_list_find (EvMappingList *mapping_list,
36 for (list = mapping_list->list; list; list = list->next) {
37 EvMapping *mapping = list->data;
39 if (mapping->data == data)
47 ev_mapping_list_find_custom (EvMappingList *mapping_list,
53 for (list = mapping_list->list; list; list = list->next) {
54 EvMapping *mapping = list->data;
56 if (!func (mapping->data, data))
64 ev_mapping_list_get_data (EvMappingList *mapping_list,
70 for (list = mapping_list->list; list; list = list->next) {
71 EvMapping *mapping = list->data;
73 if ((x >= mapping->area.x1) &&
74 (y >= mapping->area.y1) &&
75 (x <= mapping->area.x2) &&
76 (y <= mapping->area.y2)) {
85 ev_mapping_list_get_list (EvMappingList *mapping_list)
87 return mapping_list ? mapping_list->list : NULL;
91 ev_mapping_list_get_page (EvMappingList *mapping_list)
93 return mapping_list->page;
97 ev_mapping_list_new (guint page,
99 GDestroyNotify data_destroy_func)
101 EvMappingList *mapping_list;
103 g_return_val_if_fail (data_destroy_func != NULL, NULL);
105 mapping_list = g_slice_new (EvMappingList);
106 mapping_list->page = page;
107 mapping_list->list = list;
108 mapping_list->data_destroy_func = data_destroy_func;
109 mapping_list->ref_count = 1;
115 ev_mapping_list_ref (EvMappingList *mapping_list)
117 g_return_val_if_fail (mapping_list != NULL, NULL);
118 g_return_val_if_fail (mapping_list->ref_count > 0, mapping_list);
120 g_atomic_int_add (&mapping_list->ref_count, 1);
126 mapping_list_free_foreach (EvMapping *mapping,
127 GDestroyNotify destroy_func)
129 destroy_func (mapping->data);
134 ev_mapping_list_unref (EvMappingList *mapping_list)
136 g_return_if_fail (mapping_list != NULL);
137 g_return_if_fail (mapping_list->ref_count > 0);
139 if (g_atomic_int_exchange_and_add (&mapping_list->ref_count, -1) - 1 == 0) {
140 g_list_foreach (mapping_list->list,
141 (GFunc)mapping_list_free_foreach,
142 mapping_list->data_destroy_func);
143 g_list_free (mapping_list->list);
144 g_slice_free (EvMappingList, mapping_list);