Implement RFE #326532: remove BonoboStream usage from
[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 Accessibility_Role spi_accessible_role_from_atk_role (AtkRole role);
40
41 Accessibility_Role
42 spi_role_from_atk_role (AtkRole role)
43 {
44     return spi_accessible_role_from_atk_role (role);
45 }
46
47 /*
48  *   deletes an element from the list - in a re-entrant
49  * safe fashion; advances the element pointer to the next
50  * element.
51  */
52 void
53 spi_re_entrant_list_delete_link (GList * const *element_ptr)
54 {
55   GSList    *l;
56   GList     *next;
57   GList     *element;
58   gboolean   first_item;
59
60   g_return_if_fail (element_ptr != NULL);
61
62   element = *element_ptr;
63   g_return_if_fail (element != NULL);
64
65   next = element->next;
66   first_item = (element->prev == NULL);
67
68   g_list_remove_link (NULL, element);
69
70   for (l = working_list; l; l = l->next)
71     {
72        Iteration *i = l->data;
73
74        if (i->iterator == element)
75          {
76            i->iterator = next;
77          }
78
79        if (first_item && *(i->list) == element)
80          {
81            *(i->list) = next;
82          }
83     }
84
85   g_list_free_1 (element);
86 }
87
88 void
89 spi_re_entrant_list_foreach (GList         **list,
90                              SpiReEntrantFn  func,
91                              gpointer        user_data)
92 {
93         Iteration i;
94
95         if (!list || !*list)
96           {
97             return;
98           }
99
100         i.list = list;
101         i.iterator = *list;
102
103         working_list = g_slist_prepend (working_list, &i);
104
105         while (i.iterator) {
106                 GList *l = i.iterator;
107
108                 func (&i.iterator, user_data);
109
110                 if (i.iterator == l)
111                         i.iterator = i.iterator->next;
112         }
113
114         working_list = g_slist_remove (working_list, &i);
115 }
116
117 void 
118 spi_init_any_nil (CORBA_any *any_details, 
119                   Accessibility_Application app, 
120                   Accessibility_Role role,
121                   CORBA_string name)
122 {
123   Accessibility_EventDetails *details = Accessibility_EventDetails__alloc();
124
125   any_details->_type = TC_Accessibility_EventDetails;
126   any_details->_value = details;
127   any_details->_release = TRUE;
128
129   details->host_application = app;
130   details->source_role = role;
131   details->source_name = CORBA_string_dup (name);
132
133   details->any_data._type = TC_null;
134   details->any_data._value = NULL;
135   details->any_data._release = TRUE;
136 }
137
138 void 
139 spi_init_any_object (CORBA_any *any_details, Accessibility_Application app, 
140                      Accessibility_Role role,
141                      CORBA_string name, 
142                      CORBA_Object *o)
143 {
144   Accessibility_EventDetails *details = Accessibility_EventDetails__alloc();
145
146   any_details->_type = TC_Accessibility_EventDetails;
147   any_details->_value = details;
148   any_details->_release = TRUE;
149
150   details->host_application = app;
151   details->source_role = role;
152   details->source_name = CORBA_string_dup (name);
153   
154   details->any_data._type = TC_CORBA_Object;
155   details->any_data._value = o;
156   details->any_data._release = TRUE;
157 }
158
159 void
160 spi_init_any_string (CORBA_any *any_details, Accessibility_Application app, 
161                      Accessibility_Role role,
162                      CORBA_string name, 
163                      char **string_pointer)
164 {  
165   Accessibility_EventDetails *details = Accessibility_EventDetails__alloc();
166
167   any_details->_type = TC_Accessibility_EventDetails;
168   any_details->_value = details;
169   any_details->_release = TRUE;
170
171   details->host_application = app;
172   details->source_role = role;
173   details->source_name = CORBA_string_dup (name);
174   
175   details->any_data._type = (CORBA_TypeCode) TC_CORBA_string;
176   if (string_pointer && *string_pointer)
177     details->any_data._value = string_pointer;
178   else
179     details->any_data._value = &spi_atk_bridge_null_string;
180   details->any_data._release = FALSE;
181 }
182
183 void
184 spi_init_any_rect (CORBA_any *any_details, 
185                    Accessibility_Application app, 
186                    Accessibility_Role role,
187                    CORBA_string name, 
188                    AtkRectangle *rect)
189 {
190   Accessibility_EventDetails *details = Accessibility_EventDetails__alloc();
191   Accessibility_BoundingBox *box = Accessibility_BoundingBox__alloc ();
192
193   any_details->_type = TC_Accessibility_EventDetails;
194   any_details->_value = details;
195   any_details->_release = TRUE;
196
197   details->host_application = app;
198   details->source_role = role;
199   details->source_name = CORBA_string_dup (name);
200   
201   box->x = rect->x;
202   box->y = rect->y;
203   box->width = rect->width;
204   box->height = rect->height;
205   details->any_data._type = TC_Accessibility_BoundingBox;
206   details->any_data._value = box;
207   details->any_data._release = TRUE;
208 }