Added support for atk object:bounds-changed signals (bug #135253).
[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 <glib/gmessages.h>
25 #include <glib/gslist.h>
26 #include <Accessibility.h>
27
28 #include "spi-private.h"
29
30 typedef struct {
31         GList **list;
32         GList  *iterator;
33 } Iteration;
34
35 static GSList *working_list = NULL; /* of Iteration */
36
37 static char *spi_atk_bridge_null_string = "";
38
39 /*
40  *   deletes an element from the list - in a re-entrant
41  * safe fashion; advances the element pointer to the next
42  * element.
43  */
44 void
45 spi_re_entrant_list_delete_link (GList * const *element_ptr)
46 {
47   GSList    *l;
48   GList     *next;
49   GList     *element;
50   gboolean   first_item;
51
52   g_return_if_fail (element_ptr != NULL);
53
54   element = *element_ptr;
55   g_return_if_fail (element != NULL);
56
57   next = element->next;
58   first_item = (element->prev == NULL);
59
60   g_list_remove_link (NULL, element);
61
62   for (l = working_list; l; l = l->next)
63     {
64        Iteration *i = l->data;
65
66        if (i->iterator == element)
67          {
68            i->iterator = next;
69          }
70
71        if (first_item && *(i->list) == element)
72          {
73            *(i->list) = next;
74          }
75     }
76
77   g_list_free_1 (element);
78 }
79
80 void
81 spi_re_entrant_list_foreach (GList         **list,
82                              SpiReEntrantFn  func,
83                              gpointer        user_data)
84 {
85         Iteration i;
86
87         if (!list || !*list)
88           {
89             return;
90           }
91
92         i.list = list;
93         i.iterator = *list;
94
95         working_list = g_slist_prepend (working_list, &i);
96
97         while (i.iterator) {
98                 GList *l = i.iterator;
99
100                 func (&i.iterator, user_data);
101
102                 if (i.iterator == l)
103                         i.iterator = i.iterator->next;
104         }
105
106         working_list = g_slist_remove (working_list, &i);
107 }
108
109 void 
110 spi_init_any_nil (CORBA_any *any)
111 {
112   any->_type = TC_null;
113   any->_value = NULL;
114   any->_release = FALSE;
115 }
116
117 void 
118 spi_init_any_object (CORBA_any *any, CORBA_Object *o)
119 {
120   CORBA_Environment ev;
121   CORBA_exception_init (&ev);
122   
123   any->_type = TC_CORBA_Object;
124   any->_value = o;
125   any->_release = FALSE;
126   CORBA_exception_free (&ev);
127 }
128
129 void
130 spi_init_any_string (CORBA_any *any, char **string_pointer)
131 {  
132   any->_type = (CORBA_TypeCode) TC_CORBA_string;
133   if (string_pointer && *string_pointer)
134     any->_value = string_pointer;
135   else
136     any->_value = &spi_atk_bridge_null_string;
137   any->_release = FALSE;
138 }
139
140 void
141 spi_init_any_rect (CORBA_any *any, AtkRectangle *rect)
142 {
143     Accessibility_BoundingBox *box = Accessibility_BoundingBox__alloc ();
144     box->x = rect->x;
145     box->y = rect->y;
146     box->width = rect->width;
147     box->height = rect->height;
148     any->_type = TC_Accessibility_BoundingBox;
149     any->_value = box;
150     any->_release = TRUE;
151 }