3ec52f57439835042a65647bbd19f99ec6cf724e
[platform/core/uifw/at-spi2-atk.git] / libspi / util.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001, 2002 Sun Microsystems Inc.,
6  * Copyright 2001, 2002 Ximian, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 #include <config.h>
25 #include <glib/gmessages.h>
26 #include <glib/gslist.h>
27 #include <Accessibility.h>
28
29 #include "spi-private.h"
30
31 typedef struct {
32         GList **list;
33         GList  *iterator;
34 } Iteration;
35
36 static GSList *working_list = NULL; /* of Iteration */
37
38 Accessibility_Role spi_accessible_role_from_atk_role (AtkRole role);
39
40 Accessibility_Role
41 spi_role_from_atk_role (AtkRole role)
42 {
43     return spi_accessible_role_from_atk_role (role);
44 }
45
46 /*
47  *   deletes an element from the list - in a re-entrant
48  * safe fashion; advances the element pointer to the next
49  * element.
50  */
51 void
52 spi_re_entrant_list_delete_link (GList * const *element_ptr)
53 {
54   GSList    *l;
55   GList     *next;
56   GList     *element;
57   gboolean   first_item;
58
59   g_return_if_fail (element_ptr != NULL);
60
61   element = *element_ptr;
62   g_return_if_fail (element != NULL);
63
64   next = element->next;
65   first_item = (element->prev == NULL);
66
67   g_list_remove_link (NULL, element);
68
69   for (l = working_list; l; l = l->next)
70     {
71        Iteration *i = l->data;
72
73        if (i->iterator == element)
74          {
75            i->iterator = next;
76          }
77
78        if (first_item && *(i->list) == element)
79          {
80            *(i->list) = next;
81          }
82     }
83
84   g_list_free_1 (element);
85 }
86
87 void
88 spi_re_entrant_list_foreach (GList         **list,
89                              SpiReEntrantFn  func,
90                              gpointer        user_data)
91 {
92         Iteration i;
93
94         if (!list || !*list)
95           {
96             return;
97           }
98
99         i.list = list;
100         i.iterator = *list;
101
102         working_list = g_slist_prepend (working_list, &i);
103
104         while (i.iterator) {
105                 GList *l = i.iterator;
106
107                 func (&i.iterator, user_data);
108
109                 if (i.iterator == l)
110                         i.iterator = i.iterator->next;
111         }
112
113         working_list = g_slist_remove (working_list, &i);
114 }