2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
6 * Copyright 2001, 2002 Ximian, Inc.
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.
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.
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.
24 /* document.c: implements the Document interface */
29 #include <bonobo/bonobo-exception.h>
30 #include <libspi/document.h>
31 #include <libspi/spi-private.h>
34 spi_document_interface_new (AtkObject *obj)
36 SpiDocument *new_document = g_object_new (SPI_DOCUMENT_TYPE, NULL);
38 spi_base_construct (SPI_BASE (new_document), G_OBJECT(obj));
45 get_document_from_servant (PortableServer_Servant servant)
48 SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
50 g_return_val_if_fail (object, NULL);
51 g_return_val_if_fail (ATK_IS_OBJECT (object->gobj), NULL);
53 return ATK_DOCUMENT (object->gobj);
58 impl_getLocale (PortableServer_Servant servant,
59 CORBA_Environment *ev)
62 AtkDocument *document = get_document_from_servant (servant);
64 g_return_val_if_fail (document != NULL, "");
66 lc = atk_document_get_locale (document);
69 return CORBA_string_dup (lc);
71 return CORBA_string_dup (""); /* Should we return 'C' by default? */
75 impl_getAttributeValue (PortableServer_Servant servant,
76 const CORBA_char *attributename,
77 CORBA_Environment *ev){
81 AtkDocument *document = get_document_from_servant (servant);
83 g_return_val_if_fail (document != NULL, "");
85 atr = atk_document_get_attribute_value (document, attributename);
88 return CORBA_string_dup (atr);
90 return CORBA_string_dup ("");
94 static Accessibility_AttributeSet*
95 impl_getAttributes (PortableServer_Servant servant,
96 CORBA_Environment *ev){
98 AtkDocument *document = get_document_from_servant (servant);
99 AtkAttributeSet *attributes = NULL;
100 AtkAttribute *attr = NULL;
101 Accessibility_AttributeSet *retval;
102 gint n_attributes = 0;
105 g_return_val_if_fail (document != NULL, NULL);
107 attributes = atk_document_get_attributes (document);
109 bonobo_return_val_if_fail (attributes != NULL, NULL, ev);
111 bonobo_return_val_if_fail (attributes != NULL, NULL, ev);
113 /* according to atkobject.h, AtkAttributeSet is a GSList */
114 n_attributes = g_slist_length (attributes);
116 retval = CORBA_sequence_CORBA_string__alloc ();
117 retval->_length = retval->_maximum = n_attributes;
118 retval->_buffer = CORBA_sequence_CORBA_string_allocbuf (n_attributes);
119 CORBA_sequence_set_release (retval, CORBA_TRUE);
121 for (i = 0; i < n_attributes; ++i)
123 attr = g_slist_nth_data (attributes, i);
124 retval->_buffer [i] = CORBA_string_dup (g_strconcat (attr->name, ":", attr->value, NULL));
127 atk_attribute_set_free (attributes);
135 spi_document_class_init (SpiDocumentClass *klass)
139 POA_Accessibility_Document__epv *epv = &klass->epv;
141 epv->getLocale = impl_getLocale;
142 epv->getAttributeValue = impl_getAttributeValue;
143 epv->getAttributes = impl_getAttributes;
148 spi_document_init (SpiDocument *document)
151 BONOBO_TYPE_FUNC_FULL (SpiDocument,
152 Accessibility_Document,