Release 2.15.1
[atk.git] / atk / atkdocument.c
blobdc56eae780409ec0e6697e4cd6eba013ad13141a
1 /* ATK - Accessibility Toolkit
2 * Copyright 2001 Sun Microsystems Inc.
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.
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.
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.
20 #include "config.h"
22 #include "atkdocument.h"
24 /**
25 * SECTION:atkdocument
26 * @Short_description: The ATK interface which represents the toplevel
27 * container for document content.
28 * @Title:AtkDocument
30 * The AtkDocument interface should be supported by any object whose
31 * content is a representation or view of a document. The AtkDocument
32 * interface should appear on the toplevel container for the document
33 * content; however AtkDocument instances may be nested (i.e. an
34 * AtkDocument may be a descendant of another AtkDocument) in those
35 * cases where one document contains "embedded content" which can
36 * reasonably be considered a document in its own right.
40 enum {
41 LOAD_COMPLETE,
42 RELOAD,
43 LOAD_STOPPED,
44 PAGE_CHANGED,
45 LAST_SIGNAL
48 static void atk_document_base_init (AtkDocumentIface *class);
50 static guint atk_document_signals[LAST_SIGNAL] = {0};
52 GType
53 atk_document_get_type (void)
55 static GType type = 0;
57 if (!type) {
58 static const GTypeInfo tinfo =
60 sizeof (AtkDocumentIface),
61 (GBaseInitFunc) atk_document_base_init,
62 (GBaseFinalizeFunc) NULL,
66 type = g_type_register_static (G_TYPE_INTERFACE, "AtkDocument", &tinfo, 0);
69 return type;
72 static void
73 atk_document_base_init (AtkDocumentIface *class)
75 static gboolean initialized = FALSE;
76 if (!initialized)
78 /**
79 * AtkDocument::load-complete:
80 * @atkdocument: the object which received the signal.
82 * The 'load-complete' signal is emitted when a pending load of
83 * a static document has completed. This signal is to be
84 * expected by ATK clients if and when AtkDocument implementors
85 * expose ATK_STATE_BUSY. If the state of an AtkObject which
86 * implements AtkDocument does not include ATK_STATE_BUSY, it
87 * should be safe for clients to assume that the AtkDocument's
88 * static contents are fully loaded into the container.
89 * (Dynamic document contents should be exposed via other
90 * signals.)
92 atk_document_signals[LOAD_COMPLETE] =
93 g_signal_new ("load_complete",
94 ATK_TYPE_DOCUMENT,
95 G_SIGNAL_RUN_LAST,
97 (GSignalAccumulator) NULL, NULL,
98 g_cclosure_marshal_VOID__VOID,
99 G_TYPE_NONE, 0);
101 * AtkDocument::reload:
102 * @atkdocument: the object which received the signal.
104 * The 'reload' signal is emitted when the contents of a
105 * document is refreshed from its source. Once 'reload' has
106 * been emitted, a matching 'load-complete' or 'load-stopped'
107 * signal should follow, which clients may await before
108 * interrogating ATK for the latest document content.
110 atk_document_signals[RELOAD] =
111 g_signal_new ("reload",
112 ATK_TYPE_DOCUMENT,
113 G_SIGNAL_RUN_LAST,
115 (GSignalAccumulator) NULL, NULL,
116 g_cclosure_marshal_VOID__VOID,
117 G_TYPE_NONE, 0);
120 * AtkDocument::load-stopped:
121 * @atkdocument: the object which received the signal.
123 * The 'load-stopped' signal is emitted when a pending load of
124 * document contents is cancelled, paused, or otherwise
125 * interrupted by the user or application logic. It should not
126 * however be emitted while waiting for a resource (for instance
127 * while blocking on a file or network read) unless a
128 * user-significant timeout has occurred.
130 atk_document_signals[LOAD_STOPPED] =
131 g_signal_new ("load_stopped",
132 ATK_TYPE_DOCUMENT,
133 G_SIGNAL_RUN_LAST,
135 (GSignalAccumulator) NULL, NULL,
136 g_cclosure_marshal_VOID__VOID,
137 G_TYPE_NONE, 0);
140 * AtkDocument::page-changed:
141 * @atkdocument: the object on which the signal was emitted
142 * @page_number: the new page number. If this value is unknown
143 * or not applicable, -1 should be provided.
145 * The 'page-changed' signal is emitted when the current page of
146 * a document changes, e.g. pressing page up/down in a document
147 * viewer.
149 * Since: 2.12
151 atk_document_signals[PAGE_CHANGED] =
152 g_signal_new ("page_changed",
153 ATK_TYPE_DOCUMENT,
154 G_SIGNAL_RUN_LAST,
156 (GSignalAccumulator) NULL, NULL,
157 g_cclosure_marshal_VOID__INT,
158 G_TYPE_NONE, 1, G_TYPE_INT);
160 initialized = TRUE;
165 * atk_document_get_document_type:
166 * @document: a #GObject instance that implements AtkDocumentIface
168 * Gets a string indicating the document type.
170 * Deprecated: Since 2.12. Please use atk_document_get_attributes() to
171 * ask for the document type if it applies.
173 * Returns: a string indicating the document type
175 const gchar*
176 atk_document_get_document_type (AtkDocument *document)
178 AtkDocumentIface *iface;
180 g_return_val_if_fail (ATK_IS_DOCUMENT (document), NULL);
182 iface = ATK_DOCUMENT_GET_IFACE (document);
184 if (iface->get_document_type)
186 return (iface->get_document_type) (document);
188 else
190 return NULL;
195 * atk_document_get_document:
196 * @document: a #GObject instance that implements AtkDocumentIface
198 * Gets a %gpointer that points to an instance of the DOM. It is
199 * up to the caller to check atk_document_get_type to determine
200 * how to cast this pointer.
202 * Deprecated: Since 2.12. @document is already a representation of
203 * the document. Use it directly, or one of his children, as an
204 * instance of the DOM.
206 * Returns: (transfer none): a %gpointer that points to an instance of the DOM.
208 gpointer
209 atk_document_get_document (AtkDocument *document)
211 AtkDocumentIface *iface;
213 g_return_val_if_fail (ATK_IS_DOCUMENT (document), NULL);
215 iface = ATK_DOCUMENT_GET_IFACE (document);
217 if (iface->get_document)
219 return (iface->get_document) (document);
221 else
223 return NULL;
228 * atk_document_get_locale:
229 * @document: a #GObject instance that implements AtkDocumentIface
231 * Gets a UTF-8 string indicating the POSIX-style LC_MESSAGES locale
232 * of the content of this document instance. Individual
233 * text substrings or images within this document may have
234 * a different locale, see atk_text_get_attributes and
235 * atk_image_get_image_locale.
237 * Deprecated: This method is deprecated since ATK version
238 * 2.7.90. Please use atk_object_get_object_locale() instead.
240 * Returns: a UTF-8 string indicating the POSIX-style LC_MESSAGES
241 * locale of the document content as a whole, or NULL if
242 * the document content does not specify a locale.
244 const gchar *
245 atk_document_get_locale (AtkDocument *document)
247 AtkDocumentIface *iface;
249 g_return_val_if_fail (ATK_IS_DOCUMENT (document), NULL);
251 iface = ATK_DOCUMENT_GET_IFACE (document);
253 if (iface->get_document_locale)
255 return (iface->get_document_locale) (document);
257 else
259 return NULL;
265 * atk_document_get_attributes:
266 * @document: a #GObject instance that implements AtkDocumentIface
268 * Gets an AtkAttributeSet which describes document-wide
269 * attributes as name-value pairs.
271 * Since: 1.12
273 * Returns: (transfer none): An AtkAttributeSet containing the explicitly
274 * set name-value-pair attributes associated with this document
275 * as a whole.
277 AtkAttributeSet *
278 atk_document_get_attributes (AtkDocument *document)
280 AtkDocumentIface *iface;
282 g_return_val_if_fail (ATK_IS_DOCUMENT (document), NULL);
284 iface = ATK_DOCUMENT_GET_IFACE (document);
286 if (iface->get_document_attributes)
288 return (iface->get_document_attributes) (document);
290 else
292 return NULL;
297 * atk_document_get_attribute_value:
298 * @document: a #GObject instance that implements AtkDocumentIface
299 * @attribute_name: a character string representing the name of the attribute
300 * whose value is being queried.
302 * Since: 1.12
304 * Returns: (nullable): a string value associated with the named
305 * attribute for this document, or NULL if a value for
306 * #attribute_name has not been specified for this document.
308 const gchar *
309 atk_document_get_attribute_value (AtkDocument *document,
310 const gchar *attribute_name)
312 AtkDocumentIface *iface;
314 g_return_val_if_fail (ATK_IS_DOCUMENT (document), NULL);
316 iface = ATK_DOCUMENT_GET_IFACE (document);
318 if (iface->get_document_attribute_value)
320 return (iface->get_document_attribute_value) (document, attribute_name);
322 else
324 return NULL;
329 * atk_document_set_attribute_value:
330 * @document: a #GObject instance that implements AtkDocumentIface
331 * @attribute_name: a character string representing the name of the attribute
332 * whose value is being set.
333 * @attribute_value: a string value to be associated with #attribute_name.
335 * Since: 1.12
337 * Returns: TRUE if #value is successfully associated with #attribute_name
338 * for this document, FALSE otherwise (e.g. if the document does not
339 * allow the attribute to be modified).
341 gboolean
342 atk_document_set_attribute_value (AtkDocument *document,
343 const gchar *attribute_name,
344 const gchar *attribute_value)
346 AtkDocumentIface *iface;
348 g_return_val_if_fail (ATK_IS_DOCUMENT (document), FALSE);
350 iface = ATK_DOCUMENT_GET_IFACE (document);
352 if (iface->set_document_attribute)
354 return (iface->set_document_attribute) (document, attribute_name, attribute_value);
356 else
358 return FALSE;
363 * atk_document_get_current_page_number:
364 * @document: the #AtkDocument
366 * Since: 2.12
368 * Returns: current page number inside @document. -1 if not
369 * implemented, not know by the implementor or irrelevant.
371 gint
372 atk_document_get_current_page_number (AtkDocument *document)
374 AtkDocumentIface *iface;
376 g_return_val_if_fail (ATK_IS_DOCUMENT (document), FALSE);
378 iface = ATK_DOCUMENT_GET_IFACE (document);
380 if (iface->get_current_page_number)
382 return (iface->get_current_page_number) (document);
384 else
386 return -1;
391 * atk_document_get_page_count:
392 * @document: the #AtkDocument
394 * Since: 2.12
396 * Returns: total page count of @document. -1 if not implemented, not
397 * know by the implementor or irrelevant.
399 gint
400 atk_document_get_page_count (AtkDocument *document)
402 AtkDocumentIface *iface;
404 g_return_val_if_fail (ATK_IS_DOCUMENT (document), FALSE);
406 iface = ATK_DOCUMENT_GET_IFACE (document);
408 if (iface->get_page_count)
410 return (iface->get_page_count) (document);
412 else
414 return -1;