dba5452899bd97909040e15796febac32ecf0c09
[platform/upstream/atk.git] / atk / atkobject.h
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 Library 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  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library 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 #ifndef __ATK_OBJECT_H__
21 #define __ATK_OBJECT_H__
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif /* __cplusplus */
26
27 #include <glib-object.h>
28
29 /*
30  * AtkObject represents the minimum information all accessible objects
31  * return. This information includes accessible name, accessible
32  * description, role and state of the object, as well information about
33  * its parent and children. It is also possible to obtain more specific
34  * accessibility information about a component if it supports one or more
35  * of the following interfaces:
36  */
37 typedef enum
38 {
39   ATK_CHILD_ADDED,
40   ATK_CHILD_REMOVED,
41   ATK_CHILD_CHANGED
42 } AtkChildChangeType;
43
44 typedef enum
45 {
46   ATK_ROLE_INVALID,
47   /* Object is used to alert the user about something */
48   ATK_ROLE_ALERT,
49   /* Object that can be drawn into and is sued to trap events */
50   ATK_ROLE_CANVAS,
51   /*
52    * A choice that can be checked or unchecked and provides a separate
53    * indicator for the current state.
54    */
55   ATK_ROLE_CHECK_BOX,
56   /* A specialized dialog that lets the user choose a color. */
57   ATK_ROLE_COLOR_CHOOSER,
58   /* The header for a column of data */
59   ATK_ROLE_COLUMN_HEADER,
60   /* A list of choices the user can select from */
61   ATK_ROLE_COMBO_BOX,
62   /* An inconifed internal frame within a DESKTOP_PANE */
63   ATK_ROLE_DESKTOP_ICON,
64   /*
65    * A pane that supports internal frames and iconified versions of those
66    * internal frames.
67    */
68   ATK_ROLE_DESKTOP_FRAME,
69   /* A top level window with title bar and a border */
70   ATK_ROLE_DIALOG,
71   /*
72    * A pane that allows the user to navigate through and select the contents
73    * of a directory
74    */
75   ATK_ROLE_DIRECTORY_PANE,
76   /*
77    * A specialized dialog that displays the files in the directory and lets
78    * the user select a file, browse a different directory, or specify a
79    * filename.
80    */
81   ATK_ROLE_FILE_CHOOSER,
82   /*
83    * A object that fills up space in a user interface
84    */
85   ATK_ROLE_FILLER,
86   /* XXX Don't know sure about this. */
87   ATK_ROLE_FOCUS_TRAVERSABLE,
88   /* A top level window with a title bar, border, menubar, etc. */
89   ATK_ROLE_FRAME,
90   /* A pane that is guaranteed to be painted on top of all panes beneath it */
91   ATK_ROLE_GLASS_PANE,
92   /*
93    * A document container for HTML, whose children
94    * represent the document content.
95    */
96   ATK_ROLE_HTML_CONTAINER,
97   /* A small fixed size picture, typically used to decorate components */
98   ATK_ROLE_ICON,
99   /* A frame-like object that is clipped by a desktop pane. */
100   ATK_ROLE_INTERNAL_FRAME,
101   /* An object used to present an icon or short string in an interface */
102   ATK_ROLE_LABEL,
103   /*
104    * A specialized pane that allows its children to be drawn in layers,
105    * providing a form of stacking order.
106    */
107   ATK_ROLE_LAYERED_PANE,
108   /*
109    * An object that presents a list of objects to the user and allows the
110    * user to select one or more of them.
111    */
112   ATK_ROLE_LIST,
113    /* An object that represents an element of a list. */
114   ATK_ROLE_LIST_ITEM,
115   /*
116    * An object usually found inside a menu bar that contains a list of
117    * actions the user can choose from.
118    */
119   ATK_ROLE_MENU,
120   /*
121    * An object usually drawn at the top of the primary dialog box of an
122    * application that contains a list of menus the user can choose from.
123    */
124   ATK_ROLE_MENU_BAR,
125   /*
126    * An object usually contained in a menu that presents an action the
127    * user can choose.
128    */
129   ATK_ROLE_MENU_ITEM,
130   /* A specialized pane whose primary use is inside a DIALOG */
131   ATK_ROLE_OPTION_PANE,
132   /* An object that is a child of a page tab list */
133   ATK_ROLE_PAGE_TAB,
134   /*
135    * An object that presents a series of panels (or page tabs), one at a time,
136    * through some mechanism provided by the object.
137    */
138   ATK_ROLE_PAGE_TAB_LIST,
139   /* A generic container that is often used to group objects. */
140   ATK_ROLE_PANEL,
141   /*
142    * A text object uses for passwords, or other places where the text
143    * content is not shown visibly to the user.
144    */
145   ATK_ROLE_PASSWORD_TEXT,
146   /*
147    * A temporary window that is usually used to offer the user a list of
148    * choices, and then hides when the user selects one of those choices.
149    */
150   ATK_ROLE_POPUP_MENU,
151   /* An object used to indicate how much of a task has been completed. */
152   ATK_ROLE_PROGRESS_BAR,
153   /*
154    * An object the user can manipulate to tell the application to do
155    * something.
156    */
157   ATK_ROLE_PUSH_BUTTON,
158   /*
159    * A specialized check box that will cause other radio buttons in the
160    * same group to become uncghecked when this one is checked.
161    */
162   ATK_ROLE_RADIO_BUTTON,
163   /*
164    * A specialized pane that has a glass pane and a layered pane as its
165    * children.
166    */
167   ATK_ROLE_ROOT_PANE,
168   /* The header for a row of data */
169   ATK_ROLE_ROW_HEADER,
170   /*
171    * An object usually used to allow a user to incrementally view a large
172    * amount of data.
173    */
174   ATK_ROLE_SCROLL_BAR,
175   /*
176    * An object that allows a user to incrementally view a large amount
177    * of information.
178    */
179   ATK_ROLE_SCROLL_PANE,
180   /*
181    * An object usually contained in a menu to provide a visible and
182    * logical separation of the contents in a menu.
183    */
184   ATK_ROLE_SEPARATOR,
185   /* An object that allows the user to select from a bounded range */
186   ATK_ROLE_SLIDER,
187   /* A specialized panel that presents two other panels at the same time. */
188   ATK_ROLE_SPLIT_PANE,
189   /* An object used to rpesent information in terms of rows and columns. */
190   ATK_ROLE_TABLE,
191   ATK_ROLE_TABLE_CELL,
192   ATK_ROLE_TABLE_COLUMN_HEADER,
193   ATK_ROLE_TABLE_ROW_HEADER,
194   /* An object that presents text to the user */
195   ATK_ROLE_TEXT,
196   /*
197    * A specialized push button that can be checked or unchecked, but does
198    * not procide a separate indicator for the current state.
199    */
200   ATK_ROLE_TOGGLE_BUTTON,
201   /*
202    * A bar or palette usually composed of push buttons or toggle buttons
203    */
204   ATK_ROLE_TOOL_BAR,
205   /*
206    * An object that provides information about another object
207    */
208   ATK_ROLE_TOOL_TIP,
209   /* An object used to repsent hierarchical information to the user. */
210   ATK_ROLE_TREE,
211   /*
212    * The object contains some Accessible information, but its role is
213    * not known.
214    */
215   ATK_ROLE_UNKNOWN,
216   /* An object usually used in a scroll pane. */
217   ATK_ROLE_VIEWPORT,
218   /* A top level window with no title or border */
219   ATK_ROLE_WINDOW,
220   /* not a valid role, used for finding end of enumeration. */
221   ATK_ROLE_LAST_DEFINED
222 } AtkRole;
223
224 AtkRole                  atk_role_register        (gchar *name);
225
226 typedef enum
227 {
228   ATK_STATE_INVALID,
229   /* Indicates a window is currently the active window */
230   ATK_STATE_ACTIVE,
231   /* Indicates that the object is armed */
232   ATK_STATE_ARMED,
233   /* Indicates the current object is busy */
234   ATK_STATE_BUSY,
235   /* Indicates this object is currently checked */
236   ATK_STATE_CHECKED,
237   /* Indicates this object is collapsed */
238   ATK_STATE_COLLAPSED,
239   /* Indicates the user can change the contents of this object */
240   ATK_STATE_EDITABLE,
241   /* Indicates this object allows progressive disclosure of its children */
242   ATK_STATE_EXPANDABLE,
243   /* Indicates this object its expanded */
244   ATK_STATE_EXPANDED,
245   /*
246    * Indicates this object can accept keyboard focus, which means all
247    * events resulting from typing on the keyboard will normally be passed
248    * to it when it has focus
249    */
250   ATK_STATE_FOCUSABLE,
251   /* Indicates this object currently has the keyboard focus */
252   ATK_STATE_FOCUSED,
253   /* Indicates the orientation of thsi object is horizontal */
254   ATK_STATE_HORIZONTAL,
255   /* Indicates this object is minimized and is represented only by an icon */
256   ATK_STATE_ICONIFIED,
257   /*
258    * Indicates something must be done with this object before the user can
259    * interact with an object in a different window.
260    */
261   ATK_STATE_MODAL,
262   /* Indicates this (text) object can contain multiple lines of text */
263   ATK_STATE_MULTI_LINE,
264   /*
265    * Indicates this object allows more than one of its children to be
266    * selected at the same time
267    */
268   ATK_STATE_MULTISELECTABLE,
269   /* Indicates this object paints every pixel within its rectangular region. */
270   ATK_STATE_OPAQUE,
271   /* Indicates this object is currently pressed */
272   ATK_STATE_PRESSED,
273   /* Indicates the size of this object is not fixed */
274   ATK_STATE_RESIZABLE,
275   /*
276    * Indicates this object is the child of an object that allows its
277    * children to be selected and that this child is one of those children
278    * that can be selected.
279    */
280   ATK_STATE_SELECTABLE,
281   /*
282    * Indicates this object is the child of an object that allows its
283    * children to be selected and that this child is one of those children
284    * that has been selected.
285    */
286   ATK_STATE_SELECTED,
287   /* Indicates this object is sensitive */
288   ATK_STATE_SENSITIVE,
289   /*
290    * Indicates this object, the object's parent, the object's parent's
291    * parent, and so on, are all visible
292    */
293   ATK_STATE_SHOWING,
294   /* Indicates this (text) object can contain only a single line of text */
295   ATK_STATE_SINGLE_LINE,
296   /* Indicates this object is transient */
297   ATK_STATE_TRANSIENT,
298   /* Indicates the orientation of this object is vertical */
299   ATK_STATE_VERTICAL,
300   /* Indicates this object is visible */
301   ATK_STATE_VISIBLE,
302   ATK_STATE_LAST_DEFINED
303 } AtkStateType;
304
305 AtkStateType               atk_state_type_register      (gchar *name);
306
307
308 #define ATK_TYPE_OBJECT                           (atk_object_get_type ())
309 #define ATK_OBJECT(obj)                           (G_TYPE_CHECK_INSTANCE_CAST ((obj), ATK_TYPE_OBJECT, AtkObject))
310 #define ATK_OBJECT_CLASS(klass)                   (G_TYPE_CHECK_CLASS_CAST ((klass), ATK_TYPE_OBJECT, AtkObjectClass))
311 #define ATK_IS_OBJECT(obj)                        (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ATK_TYPE_OBJECT))
312 #define ATK_IS_OBJECT_CLASS(klass)                (G_TYPE_CHECK_CLASS_TYPE ((klass), ATK_TYPE_OBJECT))
313 #define ATK_OBJECT_GET_CLASS(obj)                 (G_TYPE_INSTANCE_GET_CLASS ((obj), ATK_TYPE_OBJECT, AtkObjectClass))
314
315 #define ATK_TYPE_OBJECT_IFACE                     (atk_object_iface_get_type ())
316 #define ATK_OBJECT_GET_IFACE(obj)                 (G_TYPE_INSTANCE_GET_INTERFACE ((obj), ATK_TYPE_OBJECT_IFACE, AtkObjectIface))
317
318
319 /* Forward declarations of interface structures */
320
321 typedef struct _AtkIfaceImplementor               AtkIfaceImplementor;
322
323 typedef struct _AtkObjectIface                    AtkObjectIface;
324
325 typedef struct _AtkActionIface                    AtkActionIface;
326 typedef struct _AtkComponentIface                 AtkComponentIface;
327 typedef struct _AtkEditableTextIface              AtkEditableTextIface;
328 typedef struct _AtkHypertextIface                 AtkHypertextIface;
329 typedef struct _AtkImageIface                     AtkImageIface;
330 typedef struct _AtkSelectionIface                 AtkSelectionIface;
331 typedef struct _AtkTableIface                     AtkTableIface;
332 typedef struct _AtkTextIface                      AtkTextIface;
333 typedef struct _AtkValueIface                     AtkValueIface;
334
335
336 typedef struct _AtkObject                         AtkObject;
337 typedef struct _AtkObjectClass                    AtkObjectClass;
338 typedef struct _AtkRelation                       AtkRelation;
339 typedef struct _AtkRelationSet                    AtkRelationSet;
340
341 typedef guint64                                 AtkStateMask;
342 typedef guint64                                 AtkState;
343
344 #define ATK_STATE(state_enum)                   ((AtkStateMask)(1 << ((guint64)(state_enum)%64)))
345
346 struct _AtkPropertyValues
347 {
348   gchar  *property_name;
349   GValue old_value;
350   GValue new_value;
351 };
352
353 typedef struct _AtkPropertyValues                AtkPropertyValues;
354
355 /*
356  * For most properties the old_value field of AtkPropertyValues will
357  * not contain a valid value.
358  *
359  * Currently, the only property for which old_value is used is
360  * accessible-state; for instance if there is a focus state the
361  * property change handler will be called for the object which lost the focus
362  * with the old_value containing an AtkState value corresponding to focused
363  * and the property change handler will be called for the object which
364  * received the focus with the new_value containing an AtkState value
365  * corresponding to focused.
366  */
367 typedef void (*AtkPropertyChangeHandler) (AtkObject*, AtkPropertyValues*);
368
369
370 struct _AtkObject
371 {
372   GObject parent;
373
374   gchar *description;
375   gchar *name;
376   AtkObject *accessible_parent;
377   AtkRole role;
378   AtkRelationSet *relation_set;
379 };
380
381 struct _AtkObjectClass
382 {
383   GObjectClass parent;
384
385   /*
386    * Gets the accessible name of the object
387    */
388   G_CONST_RETURN gchar*    (* get_name)            (AtkObject                *accessible);
389   /*
390    * Gets the accessible description of the object
391    */
392   G_CONST_RETURN gchar*    (* get_description)     (AtkObject                *accessible);
393   /*
394    * Gets the accessible parent of the object
395    */
396   AtkObject*               (*get_parent)           (AtkObject                *accessible);
397
398   /*
399    * Gets the number of accessible children of the object
400    */
401   gint                    (* get_n_children)       (AtkObject                *accessible);
402   /*
403    * Returns a reference to the specified accessible child of the object.
404    * The accessible children are 0-based so the first accessible child is
405    * at index 0, the second at index 1 and so on.
406    */
407   AtkObject*              (* ref_child)            (AtkObject                *accessible,
408                                                     gint                      i);
409   /*
410    * Gets the 0-based index of this object in its parent; returns -1 if the
411    * object does not have an accessible parent.
412    */
413   gint                    (* get_index_in_parent) (AtkObject                 *accessible);
414   /*
415    * Gets the RelationSet associated with the object
416    */
417   AtkRelationSet*         (* get_relation_set)    (AtkObject                 *accessible);
418   /*
419    * Gets the role of the object
420    */
421   AtkRole                 (* get_role)            (AtkObject                 *accessible);
422   /*
423    * Gets the state set of the object
424    */
425   AtkState                (* get_state)           (AtkObject                 *accessible);
426   /*
427    * Sets the accessible name of the object
428    */
429   void                    (* set_name)            (AtkObject                 *accessible,
430                                                    const gchar               *name);
431   /*
432    * Sets the accessible description of the object
433    */
434   void                    (* set_description)     (AtkObject                 *accessible,
435                                                    const gchar               *description);
436   /*
437    * Sets the accessible parent of the object
438    */
439   void                    (* set_parent)          (AtkObject                 *accessible,
440                                                    AtkObject                 *parent);
441   /*
442    * Sets the accessible role of the object
443    */
444   void                    (* set_role)            (AtkObject                 *accessible,
445                                                    AtkRole                   role);
446   /*
447    * Specifies a function to be called when a property changes value
448    */
449 guint                     (* connect_property_change_handler)    (AtkObject
450                  *accessible,
451                                                                   AtkPropertyChangeHandler       *handler);
452   /*
453    * Removes a property change handler which was specified using
454    * connect_property_change_handler
455    */
456 void                      (* remove_property_change_handler)     (AtkObject
457                 *accessible,
458                                                                   guint
459                 handler_id);
460   /*
461    * The signal handler which is executed when there is a change in the
462    * children of the object
463    */
464   void                    (* children_changed)    (AtkObject                  *accessible,
465                                                    AtkChildChangeType         change_type,
466                                                    AtkObject                  *changed_child);
467 };
468 GType            atk_object_get_type   (void);
469
470 struct _AtkObjectIface
471 {
472   GTypeInterface parent;
473
474   AtkObject*   (*ref_accessible) (AtkIfaceImplementor *accessible);
475 };
476 GType atk_object_iface_get_type (void);
477
478 /*
479  * This method uses the ref_accessible method in AtkObjectIface,
480  * if the object's class implements AtkObjectIface.
481  * Otherwise it returns %NULL.
482  *
483  * IMPORTANT:
484  * Note also that because this method may return flyweight objects,
485  * it increments the returned AtkObject's reference count.
486  * Therefore it is the responsibility of the calling
487  * program to unreference the object when no longer needed.
488  * (c.f. gtk_widget_get_accessible() where this is not the case).
489  */
490 AtkObject*              atk_object_ref_accessible                 (AtkIfaceImplementor *accessible);
491
492 /*
493  * Properties directly supported by AtkObject
494  */
495
496 G_CONST_RETURN gchar*   atk_object_get_name                       (AtkObject *accessible);
497 G_CONST_RETURN gchar*   atk_object_get_description                (AtkObject *accessible);
498 AtkObject*              atk_object_get_parent                     (AtkObject *accessible);
499 gint                    atk_object_get_n_accessible_children      (AtkObject *accessible);
500 AtkObject*              atk_object_ref_accessible_child           (AtkObject *accessible,
501                                                                    gint        i);
502 AtkRelationSet*         atk_object_get_relation_set               (AtkObject *accessible);
503 AtkRole                 atk_object_get_role                       (AtkObject *accessible);
504 AtkState                atk_object_get_state                      (AtkObject *accessible);
505 gint                    atk_object_get_index_in_parent            (AtkObject *accessible);
506 void                    atk_object_set_name                       (AtkObject *accessible,
507                                                                    const gchar *name);
508 void                    atk_object_set_description                (AtkObject *accessible,
509                                                                    const gchar *description);
510 void                    atk_object_set_parent                     (AtkObject *accessible,
511                                                                    AtkObject *parent);
512 void                    atk_object_set_role                       (AtkObject *accessible,
513                                                                    AtkRole   role);
514
515
516 /*
517  * to install property change listener, one must
518  * install signal handler for gobject "properties_changed" signal.
519  * (for single notifications of multiple changes).
520  * We could use the "notify" signal instead.
521  *
522  */
523 guint                atk_object_connect_property_change_handler  (AtkObject                      *accessible,
524                                                                   AtkPropertyChangeHandler       *handler);
525 void                 atk_object_remove_property_change_handler  (AtkObject                      *accessible,
526                                                                   guint                         handler_id);
527
528 /*
529  * Note: the properties which are registered with the GType
530  *   property registry, for type ATK_TYPE_OBJECT, are as follows:
531  *
532  *   "accessible-name"
533  *   "accessible-description"
534  *   "accessible-parent"
535  *   "accessible-child"
536  *   "accessible-role"
537  *   "accessible-state"
538  *
539  * accessibility property change listeners should use the
540  *   normal GObject property interfaces and "properties_changed"
541  *   signal handler semantics to interpret the property change
542  *   information relayed from AtkObject.
543  *   (AtkObject instances will connect to the "properties_changed"
544  *   signal in their host objects, and relay the signals when appropriate).
545  */
546
547 /* For other signals, see related interfaces
548  *
549  *    AtkActionIface,
550  *    AtkComponentIface,
551  *    AtkHypertextIface,
552  *    AtkImageIface,
553  *    AtkSelectionIface,
554  *    AtkTableIface,
555  *    AtkTextIface,
556  *    AtkValueIface.
557  *
558  *  The usage model for obtaining these interface instances is:
559  *    ATK_<interfacename>_GET_IFACE(GObject *accessible),
560  *    where accessible, though specified as a GObject, is
561  *    the AtkObject instance being queried.
562  *  More usually, the interface will be used via a cast to the
563  *    interface's corresponding "type":
564  *
565  *    AtkText textImpl = ATK_TEXT(accessible);
566  *    if (textImpl)
567  *      {
568  *        cpos = atk_text_get_caret_position(textImpl);
569  *      }
570  *
571  *  If it's known in advance that accessible implements AtkTextIface,
572  *    this is shortened to:
573  *
574  *    cpos = atk_text_get_caret_position (ATK_TEXT (accessible));
575  */
576
577 typedef enum
578 {
579   ATK_RELATION_NULL = 0,
580
581   ATK_RELATION_CONTROLLED_BY,
582   ATK_RELATION_CONTROLLER_FOR,
583   ATK_RELATION_LABEL_FOR,
584   ATK_RELATION_LABELLED_BY,
585   ATK_RELATION_MEMBER_OF,
586   ATK_RELATION_LAST_DEFINED
587 } AtkRelationType;
588
589 AtkRelationType atk_relation_type_register            (gchar *name);
590
591 /*
592  * Create a new relation for the specified key and the specified list
593  * of targets.
594  */
595 AtkRelation*    atk_relation_new                      (GArray          *target,
596                                                        AtkRelationType relationship);
597 /*
598  * Returns whether the relation set contains a relation that matches the
599  * specified type.
600  */
601 gboolean        atk_relation_set_contains             (AtkRelationSet  *set,
602                                                        AtkRelationType relationship);
603 /*
604  * Remove a relation from the from the relation set.
605  */
606 void            atk_relation_set_remove               (AtkRelationSet  *set,
607                                                        AtkRelation     *relation);
608 /*
609  * Add a new relation to the current relation set if it is not already
610  * present.
611  */
612 void            atk_relation_set_add                  (AtkRelationSet  *set,
613                                                        AtkRelation     *relation);
614 /*
615  * Returns the number of relations in a relation set.
616  */
617 gint            atk_relation_set_get_n_relations      (AtkRelationSet  *set);
618 /*
619  * Returns the relation at the specified position in the relation set.
620  */
621 AtkRelation*    atk_relation_set_get_relation         (AtkRelationSet  *set,
622                                                        gint            i);
623 /*
624  * Returns a relation that matches the specified type.
625  */
626 AtkRelation*    atk_relation_set_get_relation_by_type (AtkRelationSet  *set,
627                                                        AtkRelationType relationship);
628
629 /*
630  * Returns the type of a relation.
631  */
632 AtkRelationType atk_relation_get_type                 (AtkRelation     *relation);
633 /*
634  * Returns the target list of a relation.
635  */
636 GArray*         atk_relation_get_target               (AtkRelation     *relation);
637
638 gchar*          atk_state_mask_get_name                  (AtkStateMask    state);
639 AtkStateMask    atk_state_mask_for_name                  (gchar           *name);
640
641 #ifdef __cplusplus
642 }
643 #endif /* __cplusplus */
644
645
646 #endif /* __ATK_OBJECT_H__ */