Added Document interface for gnome 2.16 release. Bug/RFE #326520, with
[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 CORBA_string
95 impl_getAttributes (PortableServer_Servant servant,
96                     CORBA_Environment *ev){
97   
98   AtkDocument *document = get_document_from_servant (servant);
99   AtkAttributeSet *attributes = NULL;
100   Accessibility_AttributeSet *retval;
101   gint n_attributes = 0;
102   gint i;
103   
104   g_return_val_if_fail (document != NULL, CORBA_string_dup (""));
105   
106   attributes = atk_document_get_attributes (document);
107   
108   bonobo_return_val_if_fail (attributes != NULL, NULL, ev);
109
110   bonobo_return_val_if_fail (attributes != NULL, NULL, ev);
111
112   /* according to atkobject.h, AtkAttributeSet is a GSList */
113   n_attributes = g_slist_length (attributes);
114     
115   retval = CORBA_sequence_CORBA_string__alloc ();
116   retval->_length = retval->_maximum = n_attributes;
117   retval->_buffer = CORBA_sequence_CORBA_string_allocbuf (n_attributes);
118   CORBA_sequence_set_release (retval, CORBA_TRUE);
119   
120   for (i = 0; i < n_attributes; ++i)
121   {
122       retval->_buffer[i] = CORBA_string_dup (g_slist_nth_data (attributes, i));
123   }
124     
125   atk_attribute_set_free (attributes);
126
127   return retval;
128   
129 }
130
131
132 static void
133 spi_document_class_init (SpiDocumentClass *klass)
134 {
135
136  
137   POA_Accessibility_Document__epv *epv = &klass->epv;
138
139   epv->getLocale = impl_getLocale;
140   epv->getAttributeValue = impl_getAttributeValue;
141   epv->getAttributes = impl_getAttributes;
142
143 }
144
145 static void
146 spi_document_init (SpiDocument *document)
147 {
148 }
149 BONOBO_TYPE_FUNC_FULL (SpiDocument,
150                        Accessibility_Document,
151                        SPI_TYPE_BASE,
152                        spi_document)