atk: Use const instead G_CONST_RETURN
[platform/upstream/atk.git] / atk / atkdocument.c
1 /* ATK -  Accessibility Toolkit
2  * Copyright 2001 Sun Microsystems Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "atkdocument.h"
21
22 enum {
23   LOAD_COMPLETE,
24   RELOAD,
25   LOAD_STOPPED,
26   LAST_SIGNAL
27 };
28
29 static void atk_document_base_init (AtkDocumentIface *class);
30
31 static guint atk_document_signals[LAST_SIGNAL] = {0};
32
33 GType
34 atk_document_get_type (void)
35 {
36   static GType type = 0;
37
38   if (!type) {
39     static const GTypeInfo tinfo =
40     {
41       sizeof (AtkDocumentIface),
42       (GBaseInitFunc) atk_document_base_init,
43       (GBaseFinalizeFunc) NULL,
44
45     };
46
47     type = g_type_register_static (G_TYPE_INTERFACE, "AtkDocument", &tinfo, 0);
48   }
49
50   return type;
51 }
52
53 static void
54 atk_document_base_init (AtkDocumentIface *class)
55 {
56   static gboolean initialized = FALSE;
57   if (!initialized)
58     {
59       atk_document_signals[LOAD_COMPLETE] =
60         g_signal_new ("load_complete",
61                       ATK_TYPE_DOCUMENT,
62                       G_SIGNAL_RUN_LAST,
63                       0,
64                       (GSignalAccumulator) NULL, NULL,
65                       g_cclosure_marshal_VOID__VOID,
66                       G_TYPE_NONE, 0);
67       atk_document_signals[RELOAD] =
68         g_signal_new ("reload",
69                       ATK_TYPE_DOCUMENT,
70                       G_SIGNAL_RUN_LAST,
71                       0,
72                       (GSignalAccumulator) NULL, NULL,
73                       g_cclosure_marshal_VOID__VOID,
74                       G_TYPE_NONE, 0);
75       atk_document_signals[LOAD_STOPPED] =
76         g_signal_new ("load_stopped",
77                       ATK_TYPE_DOCUMENT,
78                       G_SIGNAL_RUN_LAST,
79                       0,
80                       (GSignalAccumulator) NULL, NULL,
81                       g_cclosure_marshal_VOID__VOID,
82                       G_TYPE_NONE, 0);
83
84       initialized = TRUE;
85     }
86 }
87
88 /**
89  * atk_document_get_document_type:
90  * @document: a #GObject instance that implements AtkDocumentIface
91  *
92  * Gets a string indicating the document type.
93  *
94  * Returns: a string indicating the document type
95  **/
96 const gchar*
97 atk_document_get_document_type (AtkDocument *document)
98 {
99   AtkDocumentIface *iface;
100
101   g_return_val_if_fail (ATK_IS_DOCUMENT (document), NULL);
102
103   iface = ATK_DOCUMENT_GET_IFACE (document);
104
105   if (iface->get_document_type)
106     {
107       return (iface->get_document_type) (document);
108     }
109   else
110     {
111       return NULL;
112     }
113 }
114
115 /**
116  * atk_document_get_document:
117  * @document: a #GObject instance that implements AtkDocumentIface
118  *
119  * Gets a %gpointer that points to an instance of the DOM.  It is
120  * up to the caller to check atk_document_get_type to determine
121  * how to cast this pointer.
122  *
123  * Returns: (transfer none): a %gpointer that points to an instance of the DOM.
124  **/
125 gpointer 
126 atk_document_get_document (AtkDocument *document)
127 {
128   AtkDocumentIface *iface;
129
130   g_return_val_if_fail (ATK_IS_DOCUMENT (document), NULL);
131
132   iface = ATK_DOCUMENT_GET_IFACE (document);
133
134   if (iface->get_document)
135     {
136       return (iface->get_document) (document);
137     }
138   else
139     {
140       return NULL;
141     }
142 }
143
144 /**
145  * atk_document_get_locale:
146  * @document: a #GObject instance that implements AtkDocumentIface
147  *
148  * Gets a UTF-8 string indicating the POSIX-style LC_MESSAGES locale
149  *          of the content of this document instance.  Individual
150  *          text substrings or images within this document may have
151  *          a different locale, see atk_text_get_attributes and
152  *          atk_image_get_image_locale.
153  *
154  * Returns: a UTF-8 string indicating the POSIX-style LC_MESSAGES
155  *          locale of the document content as a whole, or NULL if
156  *          the document content does not specify a locale.
157  **/
158 const gchar *
159 atk_document_get_locale (AtkDocument *document)
160 {
161   AtkDocumentIface *iface;
162
163   g_return_val_if_fail (ATK_IS_DOCUMENT (document), NULL);
164
165   iface = ATK_DOCUMENT_GET_IFACE (document);
166
167   if (iface->get_document_locale)
168     {
169       return (iface->get_document_locale) (document);
170     }
171   else
172     {
173       return NULL;
174     }
175 }
176
177
178 /**
179  * atk_document_get_attributes:
180  * @document: a #GObject instance that implements AtkDocumentIface
181  *
182  * Gets an AtkAttributeSet which describes document-wide
183  *          attributes as name-value pairs.
184  *
185  * Since: 1.12
186  *
187  * Returns: (transfer none): An AtkAttributeSet containing the explicitly
188  *          set name-value-pair attributes associated with this document
189  *          as a whole.
190  **/
191 AtkAttributeSet *
192 atk_document_get_attributes (AtkDocument *document)
193 {
194   AtkDocumentIface *iface;
195
196   g_return_val_if_fail (ATK_IS_DOCUMENT (document), NULL);
197
198   iface = ATK_DOCUMENT_GET_IFACE (document);
199
200   if (iface->get_document_attributes)
201     {
202       return (iface->get_document_attributes) (document);
203     }
204   else
205     {
206       return NULL;
207     }
208 }
209
210 /**
211  * atk_document_get_attribute_value:
212  * @document: a #GObject instance that implements AtkDocumentIface
213  * @attribute_name: a character string representing the name of the attribute
214  *            whose value is being queried.
215  *
216  * Since: 1.12
217  *
218  * Returns: a string value associated with the named attribute for this
219  *    document, or NULL if a value for #attribute_name has not been specified
220  *    for this document.
221  */
222 const gchar *
223 atk_document_get_attribute_value (AtkDocument *document, 
224                                   const gchar *attribute_name)
225 {
226   AtkDocumentIface *iface;
227
228   g_return_val_if_fail (ATK_IS_DOCUMENT (document), NULL);
229
230   iface = ATK_DOCUMENT_GET_IFACE (document);
231
232   if (iface->get_document_attribute_value)
233     {
234       return (iface->get_document_attribute_value) (document, attribute_name);
235     }
236   else
237     {
238       return NULL;
239     }
240 }
241
242 /**
243  * atk_document_set_attribute_value:
244  * @document: a #GObject instance that implements AtkDocumentIface
245  * @attribute_name: a character string representing the name of the attribute
246  *            whose value is being set.
247  * @attribute_value: a string value to be associated with #attribute_name.
248  *
249  * Since: 1.12
250  *
251  * Returns: TRUE if #value is successfully associated with #attribute_name
252  *          for this document, FALSE otherwise (e.g. if the document does not
253  *          allow the attribute to be modified).
254  */
255 gboolean
256 atk_document_set_attribute_value (AtkDocument *document, 
257                                   const gchar *attribute_name,
258                                   const gchar *attribute_value)
259 {
260   AtkDocumentIface *iface;
261
262   g_return_val_if_fail (ATK_IS_DOCUMENT (document), FALSE);
263
264   iface = ATK_DOCUMENT_GET_IFACE (document);
265
266   if (iface->set_document_attribute)
267     {
268       return (iface->set_document_attribute) (document, attribute_name, attribute_value);
269     }
270   else
271     {
272       return FALSE;
273     }
274 }