Merge branch 'improve-documentation' into 'master'
[atk.git] / atk / atkdocument.c
blobff08ca8d56c842bd362e0960b78179562e0739c4
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: (virtual 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: (virtual 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 its 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: (virtual get_document_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: 2.7.90: Please use atk_object_get_object_locale() instead.
239 * Returns: a UTF-8 string indicating the POSIX-style LC_MESSAGES
240 * locale of the document content as a whole, or NULL if
241 * the document content does not specify a locale.
243 const gchar *
244 atk_document_get_locale (AtkDocument *document)
246 AtkDocumentIface *iface;
248 g_return_val_if_fail (ATK_IS_DOCUMENT (document), NULL);
250 iface = ATK_DOCUMENT_GET_IFACE (document);
252 if (iface->get_document_locale)
254 return (iface->get_document_locale) (document);
256 else
258 return NULL;
264 * atk_document_get_attributes: (virtual get_document_attributes)
265 * @document: a #GObject instance that implements AtkDocumentIface
267 * Gets an AtkAttributeSet which describes document-wide
268 * attributes as name-value pairs.
270 * Since: 1.12
272 * Returns: (transfer none): An AtkAttributeSet containing the explicitly
273 * set name-value-pair attributes associated with this document
274 * as a whole.
276 AtkAttributeSet *
277 atk_document_get_attributes (AtkDocument *document)
279 AtkDocumentIface *iface;
281 g_return_val_if_fail (ATK_IS_DOCUMENT (document), NULL);
283 iface = ATK_DOCUMENT_GET_IFACE (document);
285 if (iface->get_document_attributes)
287 return (iface->get_document_attributes) (document);
289 else
291 return NULL;
296 * atk_document_get_attribute_value: (virtual get_document_attribute_value)
297 * @document: a #GObject instance that implements AtkDocumentIface
298 * @attribute_name: a character string representing the name of the attribute
299 * whose value is being queried.
301 * Since: 1.12
303 * Returns: (nullable): a string value associated with the named
304 * attribute for this document, or NULL if a value for
305 * #attribute_name has not been specified for this document.
307 const gchar *
308 atk_document_get_attribute_value (AtkDocument *document,
309 const gchar *attribute_name)
311 AtkDocumentIface *iface;
313 g_return_val_if_fail (ATK_IS_DOCUMENT (document), NULL);
315 iface = ATK_DOCUMENT_GET_IFACE (document);
317 if (iface->get_document_attribute_value)
319 return (iface->get_document_attribute_value) (document, attribute_name);
321 else
323 return NULL;
328 * atk_document_set_attribute_value: (virtual set_document_attribute)
329 * @document: a #GObject instance that implements AtkDocumentIface
330 * @attribute_name: a character string representing the name of the attribute
331 * whose value is being set.
332 * @attribute_value: a string value to be associated with #attribute_name.
334 * Since: 1.12
336 * Returns: TRUE if #value is successfully associated with #attribute_name
337 * for this document, FALSE otherwise (e.g. if the document does not
338 * allow the attribute to be modified).
340 gboolean
341 atk_document_set_attribute_value (AtkDocument *document,
342 const gchar *attribute_name,
343 const gchar *attribute_value)
345 AtkDocumentIface *iface;
347 g_return_val_if_fail (ATK_IS_DOCUMENT (document), FALSE);
349 iface = ATK_DOCUMENT_GET_IFACE (document);
351 if (iface->set_document_attribute)
353 return (iface->set_document_attribute) (document, attribute_name, attribute_value);
355 else
357 return FALSE;
362 * atk_document_get_current_page_number:
363 * @document: the #AtkDocument
365 * Since: 2.12
367 * Returns: current page number inside @document. -1 if not
368 * implemented, not know by the implementor or irrelevant.
370 gint
371 atk_document_get_current_page_number (AtkDocument *document)
373 AtkDocumentIface *iface;
375 g_return_val_if_fail (ATK_IS_DOCUMENT (document), FALSE);
377 iface = ATK_DOCUMENT_GET_IFACE (document);
379 if (iface->get_current_page_number)
381 return (iface->get_current_page_number) (document);
383 else
385 return -1;
390 * atk_document_get_page_count:
391 * @document: the #AtkDocument
393 * Since: 2.12
395 * Returns: total page count of @document. -1 if not implemented, not
396 * know by the implementor or irrelevant.
398 gint
399 atk_document_get_page_count (AtkDocument *document)
401 AtkDocumentIface *iface;
403 g_return_val_if_fail (ATK_IS_DOCUMENT (document), FALSE);
405 iface = ATK_DOCUMENT_GET_IFACE (document);
407 if (iface->get_page_count)
409 return (iface->get_page_count) (document);
411 else
413 return -1;