Bugfixes and uprev of configure.in, release at-spi-1.7.11.
[platform/core/uifw/at-spi2-atk.git] / libspi / document.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 /* document.c: implements the Document interface */
25
26
27 #include <config.h>
28 #include <stdio.h>
29 #include <bonobo/bonobo-exception.h>
30 #include <libspi/document.h>
31 #include <libspi/spi-private.h>
32
33 SpiDocument *
34 spi_document_interface_new (AtkObject *obj)
35 {
36   SpiDocument *new_document = g_object_new (SPI_DOCUMENT_TYPE, NULL);
37
38   spi_base_construct (SPI_BASE (new_document), G_OBJECT(obj));
39
40   return new_document;
41
42 }
43
44 static AtkDocument *
45 get_document_from_servant (PortableServer_Servant servant)
46 {
47
48   SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
49
50   g_return_val_if_fail (object, NULL);
51   g_return_val_if_fail (ATK_IS_OBJECT (object->gobj), NULL);
52
53   return ATK_DOCUMENT (object->gobj);
54
55 }
56
57 static CORBA_string
58 impl_getLocale (PortableServer_Servant servant,
59                 CORBA_Environment *ev)
60 {
61   const gchar *lc;
62   AtkDocument *document = get_document_from_servant (servant);
63
64   g_return_val_if_fail (document != NULL, "");
65
66   lc = atk_document_get_locale (document);
67
68   if (lc)
69     return CORBA_string_dup (lc);
70   else
71       return CORBA_string_dup (""); /* Should we return 'C' by default? */
72 }
73
74 static CORBA_string 
75 impl_getAttributeValue (PortableServer_Servant servant,
76                         const CORBA_char *attributename,
77                         CORBA_Environment *ev){
78
79   const gchar *atr;
80   
81   AtkDocument *document = get_document_from_servant (servant);
82    
83   g_return_val_if_fail (document != NULL, "");
84
85   atr = atk_document_get_attribute_value (document, attributename);
86
87   if (atr)
88     return CORBA_string_dup (atr);
89   else
90     return CORBA_string_dup ("");
91 }
92
93
94 static Accessibility_AttributeSet*
95 impl_getAttributes (PortableServer_Servant servant,
96                     CORBA_Environment *ev){
97   
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;
103   gint i;
104   
105   g_return_val_if_fail (document != NULL, NULL);
106   
107   attributes = atk_document_get_attributes (document);
108   
109   bonobo_return_val_if_fail (attributes != NULL, NULL, ev);
110
111   bonobo_return_val_if_fail (attributes != NULL, NULL, ev);
112
113   /* according to atkobject.h, AtkAttributeSet is a GSList */
114   n_attributes = g_slist_length (attributes);
115     
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);
120   
121   for (i = 0; i < n_attributes; ++i)
122   {
123       attr = g_slist_nth_data (attributes, i);
124       retval->_buffer [i] = CORBA_string_dup (g_strconcat (attr->name, ":", attr->value, NULL));
125   }
126     
127   atk_attribute_set_free (attributes);
128
129   return retval;
130   
131 }
132
133
134 static void
135 spi_document_class_init (SpiDocumentClass *klass)
136 {
137
138  
139   POA_Accessibility_Document__epv *epv = &klass->epv;
140
141   epv->getLocale = impl_getLocale;
142   epv->getAttributeValue = impl_getAttributeValue;
143   epv->getAttributes = impl_getAttributes;
144
145 }
146
147 static void
148 spi_document_init (SpiDocument *document)
149 {
150 }
151 BONOBO_TYPE_FUNC_FULL (SpiDocument,
152                        Accessibility_Document,
153                        SPI_TYPE_BASE,
154                        spi_document)