Clarified behavior of atk_text_get_text_... interfaces
[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
38 typedef enum
39 {
40   ATK_ROLE_INVALID,
41   /* A label which represents an accelerator */
42   ATK_ROLE_ACCEL_LABEL,
43   /* An object is used to alert the user about something */
44   ATK_ROLE_ALERT,
45   /* An object which is an animated image */
46   ATK_ROLE_ANIMATION,
47   /* An arrow in one of the four cardinal directoions */
48   ATK_ROLE_ARROW,
49   /* An object that displays a calendar and allows the user to select a date */
50   ATK_ROLE_CALENDAR,
51   /* An object that can be drawn into and is used to trap events */
52   ATK_ROLE_CANVAS,
53   /*
54    * A choice that can be checked or unchecked and provides a separate
55    * indicator for the current state.
56    */
57   ATK_ROLE_CHECK_BOX,
58   /* A menu item with a check box */
59   ATK_ROLE_CHECK_MENU_ITEM,
60   /* A specialized dialog that lets the user choose a color. */
61   ATK_ROLE_COLOR_CHOOSER,
62   /* The header for a column of data */
63   ATK_ROLE_COLUMN_HEADER,
64   /* A list of choices the user can select from */
65   ATK_ROLE_COMBO_BOX,
66   /* An object whose purpose is to allow a user to edit a date */
67   ATK_ROLE_DATE_EDITOR,
68   /* An inconifed internal frame within a DESKTOP_PANE */
69   ATK_ROLE_DESKTOP_ICON,
70   /*
71    * A pane that supports internal frames and iconified versions of those
72    * internal frames.
73    */
74   ATK_ROLE_DESKTOP_FRAME,
75   /* An object whose purpose is to allow a user to set a value */
76   ATK_ROLE_DIAL,
77   /* A top level window with title bar and a border */
78   ATK_ROLE_DIALOG,
79   /*
80    * A pane that allows the user to navigate through and select the contents
81    * of a directory
82    */
83   ATK_ROLE_DIRECTORY_PANE,
84   /*
85    * A specialized dialog that displays the files in the directory and lets
86    * the user select a file, browse a different directory, or specify a
87    * filename.
88    */
89   /* An object used for drawing custom user interface elements */
90   ATK_ROLE_DRAWING_AREA,
91   /* A specialized dialog that lets the user choose a file. */
92   ATK_ROLE_FILE_CHOOSER,
93   /* A object that fills up space in a user interface */
94   ATK_ROLE_FILLER,
95   /* A specialized dialog that lets the user choose a font. */
96   ATK_ROLE_FONT_CHOOSER,
97   /* A top level window with a title bar, border, menubar, etc. */
98   ATK_ROLE_FRAME,
99   /* A pane that is guaranteed to be painted on top of all panes beneath it */
100   ATK_ROLE_GLASS_PANE,
101   /*
102    * A document container for HTML, whose children
103    * represent the document content.
104    */
105   ATK_ROLE_HTML_CONTAINER,
106   /* A small fixed size picture, typically used to decorate components */
107   ATK_ROLE_ICON,
108   /* An object whose primary purpose is to display an image */
109   ATK_ROLE_IMAGE,
110   /* A frame-like object that is clipped by a desktop pane. */
111   ATK_ROLE_INTERNAL_FRAME,
112   /* An object used to present an icon or short string in an interface */
113   ATK_ROLE_LABEL,
114   /*
115    * A specialized pane that allows its children to be drawn in layers,
116    * providing a form of stacking order.
117    */
118   ATK_ROLE_LAYERED_PANE,
119   /*
120    * An object that presents a list of objects to the user and allows the
121    * user to select one or more of them.
122    */
123   ATK_ROLE_LIST,
124    /* An object that represents an element of a list. */
125   ATK_ROLE_LIST_ITEM,
126   /*
127    * An object usually found inside a menu bar that contains a list of
128    * actions the user can choose from.
129    */
130   ATK_ROLE_MENU,
131   /*
132    * An object usually drawn at the top of the primary dialog box of an
133    * application that contains a list of menus the user can choose from.
134    */
135   ATK_ROLE_MENU_BAR,
136   /*
137    * An object usually contained in a menu that presents an action the
138    * user can choose.
139    */
140   ATK_ROLE_MENU_ITEM,
141   /* A specialized pane whose primary use is inside a DIALOG */
142   ATK_ROLE_OPTION_PANE,
143   /* An object that is a child of a page tab list */
144   ATK_ROLE_PAGE_TAB,
145   /*
146    * An object that presents a series of panels (or page tabs), one at a time,
147    * through some mechanism provided by the object.
148    */
149   ATK_ROLE_PAGE_TAB_LIST,
150   /* A generic container that is often used to group objects. */
151   ATK_ROLE_PANEL,
152   /*
153    * A text object uses for passwords, or other places where the text
154    * content is not shown visibly to the user.
155    */
156   ATK_ROLE_PASSWORD_TEXT,
157   /*
158    * A temporary window that is usually used to offer the user a list of
159    * choices, and then hides when the user selects one of those choices.
160    */
161   ATK_ROLE_POPUP_MENU,
162   /* An object used to indicate how much of a task has been completed. */
163   ATK_ROLE_PROGRESS_BAR,
164   /*
165    * An object the user can manipulate to tell the application to do
166    * something.
167    */
168   ATK_ROLE_PUSH_BUTTON,
169   /*
170    * A specialized check box that will cause other radio buttons in the
171    * same group to become uncghecked when this one is checked.
172    */
173   ATK_ROLE_RADIO_BUTTON,
174   /* 
175    * A check menu item which belongs to a group. At each instant exactly 
176    * one of the radio menu items from a group is selected
177    */
178   ATK_ROLE_RADIO_MENU_ITEM,
179   /*
180    * A specialized pane that has a glass pane and a layered pane as its
181    * children.
182    */
183   ATK_ROLE_ROOT_PANE,
184   /* The header for a row of data */
185   ATK_ROLE_ROW_HEADER,
186   /*
187    * An object usually used to allow a user to incrementally view a large
188    * amount of data.
189    */
190   ATK_ROLE_SCROLL_BAR,
191   /*
192    * An object that allows a user to incrementally view a large amount
193    * of information.
194    */
195   ATK_ROLE_SCROLL_PANE,
196   /*
197    * An object usually contained in a menu to provide a visible and
198    * logical separation of the contents in a menu.
199    */
200   ATK_ROLE_SEPARATOR,
201   /* An object that allows the user to select from a bounded range */
202   ATK_ROLE_SLIDER,
203   /* A specialized panel that presents two other panels at the same time. */
204   ATK_ROLE_SPLIT_PANE,
205   /* An object used to get an integer or floating point number from the user */
206   ATK_ROLE_SPIN_BUTTON,
207   /* An object which reports messages of minor importance to the user */
208   ATK_ROLE_STATUSBAR,
209   /* An object used to represent information in terms of rows and columns. */
210   ATK_ROLE_TABLE,
211   ATK_ROLE_TABLE_CELL,
212   ATK_ROLE_TABLE_COLUMN_HEADER,
213   ATK_ROLE_TABLE_ROW_HEADER,
214   /* A menu item used to tear off and reattach its menu */
215   ATK_ROLE_TEAR_OFF_MENU_ITEM,
216   /* An object that presents text to the user */
217   ATK_ROLE_TEXT,
218   /*
219    * A specialized push button that can be checked or unchecked, but does
220    * not procide a separate indicator for the current state.
221    */
222   ATK_ROLE_TOGGLE_BUTTON,
223   /*
224    * A bar or palette usually composed of push buttons or toggle buttons
225    */
226   ATK_ROLE_TOOL_BAR,
227   /*
228    * An object that provides information about another object
229    */
230   ATK_ROLE_TOOL_TIP,
231   /* An object used to repsent hierarchical information to the user. */
232   ATK_ROLE_TREE,
233   /*
234    * The object contains some Accessible information, but its role is
235    * not known.
236    */
237   ATK_ROLE_UNKNOWN,
238   /* An object usually used in a scroll pane. */
239   ATK_ROLE_VIEWPORT,
240   /* A top level window with no title or border */
241   ATK_ROLE_WINDOW,
242   /* not a valid role, used for finding end of enumeration. */
243   ATK_ROLE_LAST_DEFINED
244 } AtkRole;
245
246 AtkRole                  atk_role_register        (const gchar *name);
247
248
249 #define ATK_TYPE_OBJECT                           (atk_object_get_type ())
250 #define ATK_OBJECT(obj)                           (G_TYPE_CHECK_INSTANCE_CAST ((obj), ATK_TYPE_OBJECT, AtkObject))
251 #define ATK_OBJECT_CLASS(klass)                   (G_TYPE_CHECK_CLASS_CAST ((klass), ATK_TYPE_OBJECT, AtkObjectClass))
252 #define ATK_IS_OBJECT(obj)                        (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ATK_TYPE_OBJECT))
253 #define ATK_IS_OBJECT_CLASS(klass)                (G_TYPE_CHECK_CLASS_TYPE ((klass), ATK_TYPE_OBJECT))
254 #define ATK_OBJECT_GET_CLASS(obj)                 (G_TYPE_INSTANCE_GET_CLASS ((obj), ATK_TYPE_OBJECT, AtkObjectClass))
255
256 #define ATK_TYPE_IMPLEMENTOR                      (atk_implementor_get_type ())
257 #define ATK_IS_IMPLEMENTOR(obj)                   G_TYPE_CHECK_INSTANCE_TYPE ((obj), ATK_TYPE_IMPLEMENTOR)
258 #define ATK_IMPLEMENTOR(obj)                      G_TYPE_CHECK_INSTANCE_CAST ((obj), ATK_TYPE_IMPLEMENTOR, AtkImplementor)
259 #define ATK_IMPLEMENTOR_GET_IFACE(obj)            (G_TYPE_INSTANCE_GET_INTERFACE ((obj), ATK_TYPE_IMPLEMENTOR, AtkImplementorIface))
260
261
262 typedef struct _AtkImplementor            AtkImplementor; /* dummy typedef */
263 typedef struct _AtkImplementorIface       AtkImplementorIface;
264
265
266 typedef struct _AtkObject                 AtkObject;
267 typedef struct _AtkObjectClass            AtkObjectClass;
268 typedef struct _AtkRelationSet            AtkRelationSet;
269 typedef struct _AtkStateSet               AtkStateSet;
270
271 struct _AtkPropertyValues
272 {
273   gchar  *property_name;
274   GValue old_value;
275   GValue new_value;
276 };
277
278 typedef struct _AtkPropertyValues        AtkPropertyValues;
279
280 /*
281  * For most properties the old_value field of AtkPropertyValues will
282  * not contain a valid value.
283  *
284  * Currently, the only property for which old_value is used is
285  * accessible-state; for instance if there is a focus state the
286  * property change handler will be called for the object which lost the focus
287  * with the old_value containing an AtkState value corresponding to focused
288  * and the property change handler will be called for the object which
289  * received the focus with the new_value containing an AtkState value
290  * corresponding to focused.
291  */
292 typedef void (*AtkPropertyChangeHandler) (AtkObject*, AtkPropertyValues*);
293
294
295 struct _AtkObject
296 {
297   GObject parent;
298
299   gchar *description;
300   gchar *name;
301   AtkObject *accessible_parent;
302   AtkRole role;
303   AtkRelationSet *relation_set;
304 };
305
306 struct _AtkObjectClass
307 {
308   GObjectClass parent;
309
310   /*
311    * Gets the accessible name of the object
312    */
313   G_CONST_RETURN gchar*    (* get_name)            (AtkObject                *accessible);
314   /*
315    * Gets the accessible description of the object
316    */
317   G_CONST_RETURN gchar*    (* get_description)     (AtkObject                *accessible);
318   /*
319    * Gets the accessible parent of the object
320    */
321   AtkObject*               (*get_parent)           (AtkObject                *accessible);
322
323   /*
324    * Gets the number of accessible children of the object
325    */
326   gint                    (* get_n_children)       (AtkObject                *accessible);
327   /*
328    * Returns a reference to the specified accessible child of the object.
329    * The accessible children are 0-based so the first accessible child is
330    * at index 0, the second at index 1 and so on.
331    */
332   AtkObject*              (* ref_child)            (AtkObject                *accessible,
333                                                     gint                      i);
334   /*
335    * Gets the 0-based index of this object in its parent; returns -1 if the
336    * object does not have an accessible parent.
337    */
338   gint                    (* get_index_in_parent) (AtkObject                 *accessible);
339   /*
340    * Gets the RelationSet associated with the object
341    */
342   AtkRelationSet*         (* ref_relation_set)    (AtkObject                 *accessible);
343   /*
344    * Gets the role of the object
345    */
346   AtkRole                 (* get_role)            (AtkObject                 *accessible);
347   /*
348    * Gets the state set of the object
349    */
350   AtkStateSet*            (* ref_state_set)       (AtkObject                 *accessible);
351   /*
352    * Sets the accessible name of the object
353    */
354   void                    (* set_name)            (AtkObject                 *accessible,
355                                                    const gchar               *name);
356   /*
357    * Sets the accessible description of the object
358    */
359   void                    (* set_description)     (AtkObject                 *accessible,
360                                                    const gchar               *description);
361   /*
362    * Sets the accessible parent of the object
363    */
364   void                    (* set_parent)          (AtkObject                 *accessible,
365                                                    AtkObject                 *parent);
366   /*
367    * Sets the accessible role of the object
368    */
369   void                    (* set_role)            (AtkObject                 *accessible,
370                                                    AtkRole                   role);
371   /*
372    * Specifies a function to be called when a property changes value
373    */
374 guint                     (* connect_property_change_handler)    (AtkObject
375                  *accessible,
376                                                                   AtkPropertyChangeHandler       *handler);
377   /*
378    * Removes a property change handler which was specified using
379    * connect_property_change_handler
380    */
381 void                      (* remove_property_change_handler)     (AtkObject
382                 *accessible,
383                                                                   guint
384                 handler_id);
385   /*
386    * The signal handler which is executed when there is a change in the
387    * children of the object
388    */
389   void                    (* children_changed)    (AtkObject                  *accessible,
390                                                    gint                       change_index,
391                                                    AtkObject                  *changed_child);
392   /*
393    * The signal handler which is executed  when there is a focus event
394    * for an object.
395    */
396   void                    (*focus_event)          (AtkObject                  *accessible,
397                                                    gboolean                   focus_in);
398 };
399
400 GType            atk_object_get_type   (void);
401
402 struct _AtkImplementorIface
403 {
404   GTypeInterface parent;
405
406   AtkObject*   (*ref_accessible) (AtkImplementor *implementor);
407 };
408 GType atk_implementor_get_type (void);
409
410 /*
411  * This method uses the ref_accessible method in AtkImplementorIface,
412  * if the object's class implements AtkImplementorIface.
413  * Otherwise it returns %NULL.
414  *
415  * IMPORTANT:
416  * Note also that because this method may return flyweight objects,
417  * it increments the returned AtkObject's reference count.
418  * Therefore it is the responsibility of the calling
419  * program to unreference the object when no longer needed.
420  * (c.f. gtk_widget_get_accessible() where this is not the case).
421  */
422 AtkObject*              atk_implementor_ref_accessible            (AtkImplementor *implementor);
423
424 /*
425  * Properties directly supported by AtkObject
426  */
427
428 G_CONST_RETURN gchar*   atk_object_get_name                       (AtkObject *accessible);
429 G_CONST_RETURN gchar*   atk_object_get_description                (AtkObject *accessible);
430 AtkObject*              atk_object_get_parent                     (AtkObject *accessible);
431 gint                    atk_object_get_n_accessible_children      (AtkObject *accessible);
432 AtkObject*              atk_object_ref_accessible_child           (AtkObject *accessible,
433                                                                    gint        i);
434 AtkRelationSet*         atk_object_ref_relation_set               (AtkObject *accessible);
435 AtkRole                 atk_object_get_role                       (AtkObject *accessible);
436 AtkStateSet*            atk_object_ref_state_set                  (AtkObject *accessible);
437 gint                    atk_object_get_index_in_parent            (AtkObject *accessible);
438 void                    atk_object_set_name                       (AtkObject *accessible,
439                                                                    const gchar *name);
440 void                    atk_object_set_description                (AtkObject *accessible,
441                                                                    const gchar *description);
442 void                    atk_object_set_parent                     (AtkObject *accessible,
443                                                                    AtkObject *parent);
444 void                    atk_object_set_role                       (AtkObject *accessible,
445                                                                    AtkRole   role);
446
447
448 /*
449  * to install property change listener, one must
450  * install signal handler for gobject "properties_changed" signal.
451  * (for single notifications of multiple changes).
452  * We could use the "notify" signal instead.
453  *
454  */
455 guint                atk_object_connect_property_change_handler  (AtkObject                      *accessible,
456                                                                   AtkPropertyChangeHandler       *handler);
457 void                 atk_object_remove_property_change_handler  (AtkObject                      *accessible,
458                                                                   guint                         handler_id);
459
460 /*
461  * Note: the properties which are registered with the GType
462  *   property registry, for type ATK_TYPE_OBJECT, are as follows:
463  *
464  *   "accessible-name"
465  *   "accessible-description"
466  *   "accessible-parent"
467  *   "accessible-child"
468  *   "accessible-role"
469  *   "accessible-state"
470  *
471  * accessibility property change listeners should use the
472  *   normal GObject property interfaces and "properties_changed"
473  *   signal handler semantics to interpret the property change
474  *   information relayed from AtkObject.
475  *   (AtkObject instances will connect to the "properties_changed"
476  *   signal in their host objects, and relay the signals when appropriate).
477  */
478
479 /* For other signals, see related interfaces
480  *
481  *    AtkActionIface,
482  *    AtkComponentIface,
483  *    AtkHypertextIface,
484  *    AtkImageIface,
485  *    AtkSelectionIface,
486  *    AtkTableIface,
487  *    AtkTextIface,
488  *    AtkValueIface.
489  *
490  *  The usage model for obtaining these interface instances is:
491  *    ATK_<interfacename>_GET_IFACE(GObject *accessible),
492  *    where accessible, though specified as a GObject, is
493  *    the AtkObject instance being queried.
494  *  More usually, the interface will be used via a cast to the
495  *    interface's corresponding "type":
496  *
497  *    AtkText textImpl = ATK_TEXT(accessible);
498  *    if (textImpl)
499  *      {
500  *        cpos = atk_text_get_caret_position(textImpl);
501  *      }
502  *
503  *  If it's known in advance that accessible implements AtkTextIface,
504  *    this is shortened to:
505  *
506  *    cpos = atk_text_get_caret_position (ATK_TEXT (accessible));
507  */
508
509 #ifdef __cplusplus
510 }
511 #endif /* __cplusplus */
512
513
514 #endif /* __ATK_OBJECT_H__ */