source: trunk/src/gui/accessible/qaccessible.cpp@ 64

Last change on this file since 64 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 40.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qaccessible.h"
43
44#ifndef QT_NO_ACCESSIBILITY
45
46#include "qaccessibleplugin.h"
47#include "qaccessiblewidget.h"
48#include "qapplication.h"
49#include "qhash.h"
50#include "qmetaobject.h"
51#include "qmutex.h"
52#include <private/qfactoryloader_p.h>
53
54#include "qwidget.h"
55
56QT_BEGIN_NAMESPACE
57
58/*!
59 \class QAccessible
60 \brief The QAccessible class provides enums and static functions
61 relating to accessibility.
62
63 \ingroup accessibility
64 \mainclass
65
66 Accessible applications can be used by people who are not able to
67 use applications by conventional means.
68
69 The functions in this class are used for communication between
70 accessible applications (also called AT Servers) and
71 accessibility tools (AT Clients), such as screen readers and
72 braille displays. Clients and servers communicate in the following way:
73
74 \list
75 \o \e{AT Servers} notify the clients about events through calls to the
76 updateAccessibility() function.
77
78 \o \e{AT Clients} request information about the objects in the server.
79 The QAccessibleInterface class is the core interface, and encapsulates
80 this information in a pure virtual API. Implementations of the interface
81 are provided by Qt through the queryAccessibleInterface() API.
82 \endlist
83
84 The communication between servers and clients is initialized by
85 the setRootObject() function. Function pointers can be installed
86 to replace or extend the default behavior of the static functions
87 in QAccessible.
88
89 Qt supports Microsoft Active Accessibility (MSAA), Mac OS X
90 Accessibility, and the Unix/X11 AT-SPI standard. Other backends
91 can be supported using QAccessibleBridge.
92
93 In addition to QAccessible's static functions, Qt offers one
94 generic interface, QAccessibleInterface, that can be used to wrap
95 all widgets and objects (e.g., QPushButton). This single
96 interface provides all the metadata necessary for the assistive
97 technologies. Qt provides implementations of this interface for
98 its built-in widgets as plugins.
99
100 When you develop custom widgets, you can create custom subclasses
101 of QAccessibleInterface and distribute them as plugins (using
102 QAccessiblePlugin) or compile them into the application.
103 Likewise, Qt's predefined accessibility support can be built as
104 plugin (the default) or directly into the Qt library. The main
105 advantage of using plugins is that the accessibility classes are
106 only loaded into memory if they are actually used; they don't
107 slow down the common case where no assistive technology is being
108 used.
109
110 Qt also includes two convenience classes, QAccessibleObject and
111 QAccessibleWidget, that inherit from QAccessibleInterface and
112 provide the lowest common denominator of metadata (e.g., widget
113 geometry, window title, basic help text). You can use them as
114 base classes when wrapping your custom QObject or QWidget
115 subclasses.
116
117 \sa QAccessibleInterface
118*/
119
120/*!
121 \enum QAccessible::Action
122
123 This enum describes the possible types of action that can occur.
124
125 \value DefaultAction
126 \value Press
127 \value SetFocus
128 \value Increase
129 \value Decrease
130 \value Accept
131 \value Cancel
132 \value Select
133 \value ClearSelection
134 \value RemoveSelection
135 \value ExtendSelection
136 \value AddToSelection
137
138 \value FirstStandardAction
139 \value LastStandardAction
140*/
141
142/*!
143 \enum QAccessible::Method
144
145 This enum describes the possible types of methods that can be
146 invoked on an accessible object.
147
148 \value ListSupportedMethods
149 \value SetCursorPosition
150 \value GetCursorPosition
151
152 \omitvalue ForegroundColor
153 \omitvalue BackgroundColor
154
155 \sa QAccessibleInterface::invokeMethod()
156*/
157
158/*!
159 \fn QSet<Method> QAccessibleInterface::supportedMethods()
160 \since 4.3
161
162 Returns a QSet of \l{QAccessible::}{Method}s that are supported by this
163 accessible interface.
164
165 \sa QAccessible::Method invokeMethod()
166*/
167
168/*!
169 \enum QAccessible::StateFlag
170
171 This enum type defines bit flags that can be combined to indicate
172 the state of an accessible object. The values are:
173
174 \value Animated The object's appearance changes frequently.
175 \value Busy The object cannot accept input at the moment.
176 \value Checked The object's check box is checked.
177 \value Collapsed The object is collapsed, e.g. a closed listview item, or an iconified window.
178 \value DefaultButton The object represents the default button in a dialog.
179 \value Expanded The object is expandable, and currently the children are visible.
180 \value ExtSelectable The object supports extended selection.
181 \value Focusable The object can receive focus. Only objects in the active window can receive focus.
182 \value Focused The object has keyboard focus.
183 \value HasPopup The object opens a popup.
184 \value HotTracked The object's appearance is sensitive to the mouse cursor position.
185 \value Invisible The object is not visible to the user.
186 \value Linked The object is linked to another object, e.g. a hyperlink.
187 \value Marqueed The object displays scrolling contents, e.g. a log view.
188 \value Mixed The state of the object is not determined, e.g. a tri-state check box that is neither checked nor unchecked.
189 \value Modal The object blocks input from other objects.
190 \value Movable The object can be moved.
191 \value MultiSelectable The object supports multiple selected items.
192 \value Normal The normal state.
193 \value Offscreen The object is clipped by the visible area. Objects that are off screen are also invisible.
194 \value Pressed The object is pressed.
195 \value Protected The object is password protected, e.g. a line edit for entering a Password.
196 \value ReadOnly The object can usually be edited, but is explicitly set to read-only.
197 \value Selectable The object is selectable.
198 \value Selected The object is selected.
199 \value SelfVoicing The object describes itself through speech or sound.
200 \value Sizeable The object can be resized, e.g. top-level windows.
201 \value Traversed The object is linked and has been visited.
202 \value Unavailable The object is unavailable to the user, e.g. a disabled widget.
203 \omitvalue Moveable
204 \omitvalue HasInvokeExtension
205
206 Implementations of QAccessibleInterface::state() return a combination
207 of these flags.
208*/
209
210/*!
211 \enum QAccessible::Event
212
213 This enum type defines accessible event types.
214
215 \value AcceleratorChanged
216 \value Alert A system alert (e.g., a message from a QMessageBox)
217 \value ContextHelpEnd Context help (QWhatsThis) for an object is finished.
218 \value ContextHelpStart Context help (QWhatsThis) for an object is initiated.
219 \value DefaultActionChanged The default QAccessible::Action for the accessible object changed
220 \value DescriptionChanged The objects QAccessible::Description changed.
221 \value DialogEnd A dialog (QDialog) is been hidden
222 \value DialogStart A dialog (QDialog) has been set visible.
223 \value DragDropEnd A Drag & Drop operation is about to finished.
224 \value DragDropStart A Drag & Drop operation is about to be initiated.
225 \value Focus An object has gained keyboard focus.
226 \value ForegroundChanged A window has been activated (i.e., a new window has gained focus on the desktop)
227 \value HelpChanged The QAccessible::Help text property of an object has changed
228 \value LocationChanged An objects location on the screen changed
229 \value MenuCommand A menu item is triggered.
230 \value MenuEnd A menu has been closed (Qt uses PopupMenuEnd for all menus)
231 \value MenuStart A menu has been opened on the menubar (Qt uses PopupMenuStart for all menus)
232 \value NameChanged The QAccessible::Name property of an object has changed
233 \value ObjectCreated A new object is created.
234 \value ObjectDestroyed An object is deleted.
235 \value ObjectHide An object is hidden (i.e., with QWidget::hide()). Any children the object that is hidden has do not send this event.
236 It is not send when an object is hidden as it is being obcured by others.
237 \value ObjectReorder A layout or item view has added, removed, or moved an object (Qt does not use this event).
238 \value ObjectShow An object is displayed (i.e., with QWidget::show()).
239 \value ParentChanged An objects parent object changed.
240 \value PopupMenuEnd A popup menu has closed.
241 \value PopupMenuStart A popupmenu has opened.
242 \value ScrollingEnd A scrollbar scroll operation has ended (the mouse has released the slider handle)
243 \value ScrollingStart A scrollbar scroll operation is about to start (i.e., the mouse has pressed on the slider handle)
244 \value Selection The selection has changed in a menu or item view.
245 \value SelectionAdd An item has been added to the selection in an item view.
246 \value SelectionRemove An item has been removed from an item view selection.
247 \value SelectionWithin Several changes to a selection has occurred in an item view.
248 \value SoundPlayed A sound has been played by an object
249 \value StateChanged The QAccessible::State of an object has changed.
250 \value ValueChanged The QAccessible::Value of an object has changed.
251*/
252
253/*!
254 \enum QAccessible::Role
255
256 This enum defines the role of an accessible object. The roles are:
257
258 \value AlertMessage An object that is used to alert the user.
259 \value Animation An object that displays an animation.
260 \value Application The application's main window.
261 \value Assistant An object that provids interactive help.
262 \value Border An object that represents a border.
263 \value ButtonDropDown A button that drops down a list of items.
264 \value ButtonDropGrid A button that drops down a grid.
265 \value ButtonMenu A button that drops down a menu.
266 \value Canvas An object that displays graphics that the user can interact with.
267 \value Caret An object that represents the system caret (text cursor).
268 \value Cell A cell in a table.
269 \value Chart An object that displays a graphical representation of data.
270 \value CheckBox An object that represents an option that can be checked or unchecked. Some options provide a "mixed" state, e.g. neither checked nor unchecked.
271 \value Client The client area in a window.
272 \value Clock A clock displaying time.
273 \value Column A column of cells, usually within a table.
274 \value ColumnHeader A header for a column of data.
275 \value ComboBox A list of choices that the user can select from.
276 \value Cursor An object that represents the mouse cursor.
277 \value Dial An object that represents a dial or knob.
278 \value Dialog A dialog box.
279 \value Document A document window, usually in an MDI environment.
280 \value EditableText Editable text
281 \value Equation An object that represents a mathematical equation.
282 \value Graphic A graphic or picture, e.g. an icon.
283 \value Grip A grip that the user can drag to change the size of widgets.
284 \value Grouping An object that represents a logical grouping of other objects.
285 \value HelpBalloon An object that displays help in a separate, short lived window.
286 \value HotkeyField A hotkey field that allows the user to enter a key sequence.
287 \value Indicator An indicator that represents a current value or item.
288 \value LayeredPane An object that can contain layered children, e.g. in a stack.
289 \value Link A link to something else.
290 \value List A list of items, from which the user can select one or more items.
291 \value ListItem An item in a list of items.
292 \value MenuBar A menu bar from which menus are opened by the user.
293 \value MenuItem An item in a menu or menu bar.
294 \value NoRole The object has no role. This usually indicates an invalid object.
295 \value PageTab A page tab that the user can select to switch to a different page in a dialog.
296 \value PageTabList A list of page tabs.
297 \value Pane A generic container.
298 \value PopupMenu A menu which lists options that the user can select to perform an action.
299 \value ProgressBar The object displays the progress of an operation in progress.
300 \value PropertyPage A property page where the user can change options and settings.
301 \value PushButton A button.
302 \value RadioButton An object that represents an option that is mutually exclusive with other options.
303 \value Row A row of cells, usually within a table.
304 \value RowHeader A header for a row of data.
305 \value ScrollBar A scroll bar, which allows the user to scroll the visible area.
306 \value Separator A separator that divides space into logical areas.
307 \value Slider A slider that allows the user to select a value within a given range.
308 \value Sound An object that represents a sound.
309 \value SpinBox A spin box widget that allows the user to enter a value within a given range.
310 \value Splitter A splitter distributing available space between its child widgets.
311 \value StaticText Static text, such as labels for other widgets.
312 \value StatusBar A status bar.
313 \value Table A table representing data in a grid of rows and columns.
314 \value TitleBar The title bar caption of a window.
315 \value ToolBar A tool bar, which groups widgets that the user accesses frequently.
316 \value ToolTip A tool tip which provides information about other objects.
317 \value Tree A list of items in a tree structure.
318 \value TreeItem An item in a tree structure.
319 \value UserRole The first value to be used for user defined roles.
320 \value Whitespace Blank space between other objects.
321 \value Window A top level window.
322*/
323
324/*!
325 \enum QAccessible::RelationFlag
326
327 This enum type defines bit flags that can be combined to indicate
328 the relationship between two accessible objects.
329
330 \value Unrelated The objects are unrelated.
331 \value Self The objects are the same.
332 \value Ancestor The first object is a parent of the second object.
333 \value Child The first object is a direct child of the second object.
334 \value Descendent The first object is an indirect child of the second object.
335 \value Sibling The objects are siblings.
336
337 \value Up The first object is above the second object.
338 \value Down The first object is below the second object.
339 \value Left The first object is left of the second object.
340 \value Right The first object is right of the second object.
341 \value Covers The first object covers the second object.
342 \value Covered The first object is covered by the second object.
343
344 \value FocusChild The first object is the second object's focus child.
345 \value Label The first object is the label of the second object.
346 \value Labelled The first object is labelled by the second object.
347 \value Controller The first object controls the second object.
348 \value Controlled The first object is controlled by the second object.
349
350 \omitvalue HierarchyMask
351 \omitvalue GeometryMask
352 \omitvalue LogicalMask
353
354 Implementations of relationTo() return a combination of these flags.
355 Some values are mutually exclusive.
356
357 Implementations of navigate() can accept only one distinct value.
358*/
359
360/*!
361 \enum QAccessible::Text
362
363 This enum specifies string information that an accessible object
364 returns.
365
366 \value Name The name of the object. This can be used both
367 as an identifier or a short description by
368 accessible clients.
369 \value Description A short text describing the object.
370 \value Value The value of the object.
371 \value Help A longer text giving information about how to use the object.
372 \value Accelerator The keyboard shortcut that executes the object's default action.
373 \value UserText The first value to be used for user defined text.
374*/
375
376/*!
377 \fn QAccessibleInterface::~QAccessibleInterface()
378
379 Destroys the object.
380*/
381
382/*!
383 \fn void QAccessible::initialize()
384 \internal
385*/
386
387/*!
388 \fn void QAccessible::cleanup()
389 \internal
390*/
391
392#if !defined(QT_NO_LIBRARY) && (!defined(QT_NO_SETTINGS) || !defined(Q_OS_WIN))
393Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
394 (QAccessibleFactoryInterface_iid, QLatin1String("/accessible")))
395#endif
396
397Q_GLOBAL_STATIC(QList<QAccessible::InterfaceFactory>, qAccessibleFactories);
398
399QAccessible::UpdateHandler QAccessible::updateHandler = 0;
400QAccessible::RootObjectHandler QAccessible::rootObjectHandler = 0;
401
402static bool accessibility_active = false;
403static bool cleanupAdded = false;
404static void qAccessibleCleanup()
405{
406 qAccessibleFactories()->clear();
407}
408
409/*!
410 \typedef QAccessible::InterfaceFactory
411
412 A function pointer type. Use a function with this prototype to install
413 interface factories with installFactory().
414
415 The function receives a QObject pointer. If the QObject
416 provides a QAccessibleInterface, it sets the second parameter to
417 point to the corresponding QAccessibleInterface, and returns true;
418 otherwise returns false.
419
420 Installed factories are called by queryAccessibilityInterface() until
421 one provides an interface.
422*/
423
424/*!
425 \typedef QAccessible::UpdateHandler
426
427 \internal
428
429 A function pointer type. Use a function with this prototype to install
430 your own update function.
431
432 The function is called by updateAccessibility().
433*/
434
435/*!
436 \typedef QAccessible::RootObjectHandler
437
438 \internal
439
440 A function pointer type. Use a function with this prototype to install
441 your own root object handler.
442
443 The function is called by setRootObject().
444*/
445
446/*!
447 Installs the InterfaceFactory \a factory. The last factory added
448 is the first one used by queryAccessibleInterface().
449*/
450void QAccessible::installFactory(InterfaceFactory factory)
451{
452 if (!factory)
453 return;
454
455 if (!cleanupAdded) {
456 qAddPostRoutine(qAccessibleCleanup);
457 cleanupAdded = true;
458 }
459 if (qAccessibleFactories()->contains(factory))
460 return;
461 qAccessibleFactories()->append(factory);
462}
463
464/*!
465 Removes \a factory from the list of installed InterfaceFactories.
466*/
467void QAccessible::removeFactory(InterfaceFactory factory)
468{
469 qAccessibleFactories()->removeAll(factory);
470}
471
472/*!
473 \internal
474
475 Installs the given \a handler as the function to be used by
476 updateAccessibility(), and returns the previously installed
477 handler.
478*/
479QAccessible::UpdateHandler QAccessible::installUpdateHandler(UpdateHandler handler)
480{
481 UpdateHandler old = updateHandler;
482 updateHandler = handler;
483 return old;
484}
485
486/*!
487 Installs the given \a handler as the function to be used by setRootObject(),
488 and returns the previously installed handler.
489*/
490QAccessible::RootObjectHandler QAccessible::installRootObjectHandler(RootObjectHandler handler)
491{
492 RootObjectHandler old = rootObjectHandler;
493 rootObjectHandler = handler;
494 return old;
495}
496
497/*!
498 If a QAccessibleInterface implementation exists for the given \a object,
499 this function returns a pointer to the implementation; otherwise it
500 returns 0.
501
502 The function calls all installed factory functions (from most
503 recently installed to least recently installed) until one is found
504 that provides an interface for the class of \a object. If no
505 factory can provide an accessibility implementation for the class
506 the function loads installed accessibility plugins, and tests if
507 any of the plugins can provide the implementation.
508
509 If no implementation for the object's class is available, the
510 function tries to find an implementation for the object's parent
511 class, using the above strategy.
512
513 \warning The caller is responsible for deleting the returned
514 interface after use.
515*/
516QAccessibleInterface *QAccessible::queryAccessibleInterface(QObject *object)
517{
518 accessibility_active = true;
519 QAccessibleInterface *iface = 0;
520 if (!object)
521 return 0;
522
523 QEvent e(QEvent::AccessibilityPrepare);
524 QApplication::sendEvent(object, &e);
525
526 const QMetaObject *mo = object->metaObject();
527 while (mo) {
528 const QLatin1String cn(mo->className());
529 for (int i = qAccessibleFactories()->count(); i > 0; --i) {
530 InterfaceFactory factory = qAccessibleFactories()->at(i - 1);
531 iface = factory(cn, object);
532 if (iface)
533 return iface;
534 }
535#if !defined(QT_NO_LIBRARY) && (!defined(QT_NO_SETTINGS) || !defined(Q_OS_WIN))
536 QAccessibleFactoryInterface *factory = qobject_cast<QAccessibleFactoryInterface*>(loader()->instance(cn));
537 if (factory) {
538 iface = factory->create(cn, object);
539 if (iface)
540 return iface;
541 }
542#endif
543 mo = mo->superClass();
544 }
545
546 QWidget *widget = qobject_cast<QWidget*>(object);
547 if (widget)
548 return new QAccessibleWidget(widget);
549 else if (object == qApp)
550 return new QAccessibleApplication();
551
552 return 0;
553}
554
555/*!
556 Returns true if an accessibility implementation has been requested
557 during the runtime of the application; otherwise returns false.
558
559 Use this function to prevent potentially expensive notifications via
560 updateAccessibility().
561*/
562bool QAccessible::isActive()
563{
564 return accessibility_active;
565}
566
567/*!
568 \fn void QAccessible::setRootObject(QObject *object)
569
570 Sets the root accessible object of this application to \a object.
571 All other accessible objects in the application can be reached by the
572 client using object navigation.
573
574 You should never need to call this function. Qt sets the QApplication
575 object as the root object immediately before the event loop is entered
576 in QApplication::exec().
577
578 Use QAccessible::installRootObjectHandler() to redirect the function
579 call to a customized handler function.
580
581 \sa queryAccessibleInterface()
582*/
583
584/*!
585 \fn void QAccessible::updateAccessibility(QObject *object, int child, Event reason)
586
587 Notifies accessibility clients about a change in \a object's
588 accessibility information.
589
590 \a reason specifies the cause of the change, for example,
591 \c ValueChange when the position of a slider has been changed. \a
592 child is the (1-based) index of the child element that has changed.
593 When \a child is 0, the object itself has changed.
594
595 Call this function whenever the state of your accessible object or
596 one of its sub-elements has been changed either programmatically
597 (e.g. by calling QLabel::setText()) or by user interaction.
598
599 If there are no accessibility tools listening to this event, the
600 performance penalty for calling this function is small, but if determining
601 the parameters of the call is expensive you can test isActive() to
602 avoid unnecessary computations.
603*/
604
605
606/*!
607 \class QAccessibleInterface
608 \brief The QAccessibleInterface class defines an interface that exposes information
609 about accessible objects.
610
611 \ingroup accessibility
612
613 Accessibility tools (also called AT Clients), such as screen readers
614 or braille displays, require high-level information about
615 accessible objects in an application. Accessible objects provide
616 specialized input and output methods, making it possible for users
617 to use accessibility tools with enabled applications (AT Servers).
618
619 Every element that the user needs to interact with or react to is
620 an accessible object, and should provide this information. These
621 are mainly visual objects, such as widgets and widget elements, but
622 can also be content, such as sounds.
623
624 The AT client uses three basic concepts to acquire information
625 about any accessible object in an application:
626 \list
627 \i \e Properties The client can read information about
628 accessible objects. In some cases the client can also modify these
629 properties; such as text in a line edit.
630 \i \e Actions The client can invoke actions like pressing a button
631 or .
632 \i \e{Relationships and Navigation} The client can traverse from one
633 accessible object to another, using the relationships between objects.
634 \endlist
635
636 The QAccessibleInterface defines the API for these three concepts.
637
638 \section1 Relationships and Navigation
639
640 The functions childCount() and indexOfChild() return the number of
641 children of an accessible object and the index a child object has
642 in its parent. The childAt() function returns the index of a child
643 at a given position.
644
645 The relationTo() function provides information about how two
646 different objects relate to each other, and navigate() allows
647 traversing from one object to another object with a given
648 relationship.
649
650 \section1 Properties
651
652 The central property of an accessible objects is what role() it
653 has. Different objects can have the same role, e.g. both the "Add
654 line" element in a scroll bar and the \c OK button in a dialog have
655 the same role, "button". The role implies what kind of
656 interaction the user can perform with the user interface element.
657
658 An object's state() property is a combination of different state
659 flags and can describe both how the object's state differs from a
660 "normal" state, e.g. it might be unavailable, and also how it
661 behaves, e.g. it might be selectable.
662
663 The text() property provides textual information about the object.
664 An object usually has a name, but can provide extended information
665 such as a description, help text, or information about any
666 keyboard accelerators it provides. Some objects allow changing the
667 text() property through the setText() function, but this
668 information is in most cases read-only.
669
670 The rect() property provides information about the geometry of an
671 accessible object. This information is usually only available for
672 visual objects.
673
674 \section1 Actions and Selection
675
676 To enable the user to interact with an accessible object the
677 object must expose information about the actions that it can
678 perform. userActionCount() returns the number of actions supported by
679 an accessible object, and actionText() returns textual information
680 about those actions. doAction() invokes an action.
681
682 Objects that support selections can define actions to change the selection.
683
684 \section2 Objects and children
685
686 A QAccessibleInterface provides information about the accessible
687 object, and can also provide information for the children of that
688 object if those children don't provide a QAccessibleInterface
689 implementation themselves. This is practical if the object has
690 many similar children (e.g. items in a list view), or if the
691 children are an integral part of the object itself, for example, the
692 different sections in a scroll bar.
693
694 If an accessible object provides information about its children
695 through one QAccessibleInterface, the children are referenced
696 using indexes. The index is 1-based for the children, i.e. 0
697 refers to the object itself, 1 to the first child, 2 to the second
698 child, and so on.
699
700 All functions in QAccessibleInterface that take a child index
701 relate to the object itself if the index is 0, or to the child
702 specified. If a child provides its own interface implementation
703 (which can be retrieved through navigation) asking the parent for
704 information about that child will usually not succeed.
705
706 \sa QAccessible
707*/
708
709/*!
710 \fn bool QAccessibleInterface::isValid() const
711
712 Returns true if all the data necessary to use this interface
713 implementation is valid (e.g. all pointers are non-null);
714 otherwise returns false.
715
716 \sa object()
717*/
718
719/*!
720 \fn QObject *QAccessibleInterface::object() const
721
722 Returns a pointer to the QObject this interface implementation provides
723 information for.
724
725 \sa isValid()
726*/
727
728/*!
729 \fn int QAccessibleInterface::childCount() const
730
731 Returns the number of children that belong to this object. A child
732 can provide accessibility information on its own (e.g. a child
733 widget), or be a sub-element of this accessible object.
734
735 All objects provide this information.
736
737 \sa indexOfChild()
738*/
739
740/*!
741 \fn int QAccessibleInterface::indexOfChild(const QAccessibleInterface *child) const
742
743 Returns the 1-based index of the object \a child in this object's
744 children list, or -1 if \a child is not a child of this object. 0
745 is not a possible return value.
746
747 All objects provide this information about their children.
748
749 \sa childCount()
750*/
751
752/*!
753 \fn QAccessible::Relation QAccessibleInterface::relationTo(int child,
754const QAccessibleInterface *other, int otherChild) const
755
756 Returns the relationship between this object's \a child and the \a
757 other object's \a otherChild. If \a child is 0 the object's own relation
758 is returned.
759
760 The returned value indicates the relation of the called object to
761 the \a other object, e.g. if this object is a child of \a other
762 the return value will be \c Child.
763
764 The return value is a combination of the bit flags in the
765 QAccessible::Relation enumeration.
766
767 All objects provide this information.
768
769 \sa indexOfChild(), navigate()
770*/
771
772/*!
773 \fn int QAccessibleInterface::childAt(int x, int y) const
774
775 Returns the 1-based index of the child that contains the screen
776 coordinates (\a x, \a y). This function returns 0 if the point is
777 positioned on the object itself. If the tested point is outside
778 the boundaries of the object this function returns -1.
779
780 This function is only relyable for visible objects (invisible
781 object might not be laid out correctly).
782
783 All visual objects provide this information.
784
785 \sa rect()
786*/
787
788/*!
789 \fn int QAccessibleInterface::navigate(RelationFlag relation, int entry, QAccessibleInterface
790**target) const
791
792 Navigates from this object to an object that has a relationship
793 \a relation to this object, and returns the respective object in
794 \a target. It is the caller's responsibility to delete *\a target
795 after use.
796
797 If an object is found, \a target is set to point to the object, and
798 the index of the child of \a target is returned. The return value
799 is 0 if \a target itself is the requested object. \a target is set
800 to null if this object is the target object (i.e. the requested
801 object is a handled by this object).
802
803 If no object is found \a target is set to null, and the return
804 value is -1.
805
806 The \a entry parameter has two different meanings:
807 \list
808 \i \e{Hierarchical and Logical relationships} -- if multiple objects with
809 the requested relationship exist \a entry specifies which one to
810 return. \a entry is 1-based, e.g. use 1 to get the first (and
811 possibly only) object with the requested relationship.
812
813 The following code demonstrates how to use this function to
814 navigate to the first child of an object:
815
816 \snippet doc/src/snippets/code/src_gui_accessible_qaccessible.cpp 0
817
818 \i \e{Geometric relationships} -- the index of the child from
819 which to start navigating in the specified direction. \a entry
820 can be 0 to navigate to a sibling of this object, or non-null to
821 navigate within contained children that don't provide their own
822 accessible information.
823 \endlist
824
825 Note that the \c Descendent value for \a relation is not supported.
826
827 All objects support navigation.
828
829 \sa relationTo(), childCount()
830*/
831
832/*!
833 \fn QString QAccessibleInterface::text(Text t, int child) const
834
835 Returns the value of the text property \a t of the object, or of
836 the object's child if \a child is not 0.
837
838 The \l Name is a string used by clients to identify, find, or
839 announce an accessible object for the user. All objects must have
840 a name that is unique within their container. The name can be
841 used differently by clients, so the name should both give a
842 short description of the object and be unique.
843
844 An accessible object's \l Description provides textual information
845 about an object's visual appearance. The description is primarily
846 used to provide greater context for vision-impaired users, but is
847 also used for context searching or other applications. Not all
848 objects have a description. An "OK" button would not need a
849 description, but a tool button that shows a picture of a smiley
850 would.
851
852 The \l Value of an accessible object represents visual information
853 contained by the object, e.g. the text in a line edit. Usually,
854 the value can be modified by the user. Not all objects have a
855 value, e.g. static text labels don't, and some objects have a
856 state that already is the value, e.g. toggle buttons.
857
858 The \l Help text provides information about the function and
859 usage of an accessible object. Not all objects provide this
860 information.
861
862 The \l Accelerator is a keyboard shortcut that activates the
863 object's default action. A keyboard shortcut is the underlined
864 character in the text of a menu, menu item or widget, and is
865 either the character itself, or a combination of this character
866 and a modifier key like Alt, Ctrl or Shift. Command controls like
867 tool buttons also have shortcut keys and usually display them in
868 their tooltip.
869
870 All objects provide a string for \l Name.
871
872 \sa role(), state()
873*/
874
875/*!
876 \fn void QAccessibleInterface::setText(Text t, int child, const QString &text)
877
878 Sets the text property \a t of the object, or of the object's
879 child if \a child is not 0, to \a text.
880
881 Note that the text properties of most objects are read-only.
882
883 \sa text()
884*/
885
886/*!
887 \fn QRect QAccessibleInterface::rect(int child) const
888
889 Returns the geometry of the object, or of the object's child if \a child
890 is not 0. The geometry is in screen coordinates.
891
892 This function is only reliable for visible objects (invisible
893 objects might not be laid out correctly).
894
895 All visual objects provide this information.
896
897 \sa childAt()
898*/
899
900/*!
901 \fn QAccessible::Role QAccessibleInterface::role(int child) const
902
903 Returns the role of the object, or of the object's child if \a child
904 is not 0. The role of an object is usually static.
905
906 All accessible objects have a role.
907
908 \sa text(), state()
909*/
910
911/*!
912 \fn QAccessible::State QAccessibleInterface::state(int child) const
913
914 Returns the current state of the object, or of the object's child if
915 \a child is not 0. The returned value is a combination of the flags in
916 the QAccessible::StateFlag enumeration.
917
918 All accessible objects have a state.
919
920 \sa text(), role()
921*/
922
923/*!
924 \fn int QAccessibleInterface::userActionCount(int child) const
925
926 Returns the number of custom actions of the object, or of the
927 object's child if \a child is not 0.
928
929 The \c Action type enumerates predefined actions: these
930 are not included in the returned value.
931
932 \sa actionText(), doAction()
933*/
934
935/*!
936 \fn QString QAccessibleInterface::actionText(int action, Text t, int child) const
937
938 Returns the text property \a t of the action \a action supported by
939 the object, or of the object's child if \a child is not 0.
940
941 \sa text(), userActionCount()
942*/
943
944/*!
945 \fn bool QAccessibleInterface::doAction(int action, int child, const QVariantList &params)
946
947 Asks the object, or the object's \a child if \a child is not 0, to
948 execute \a action using the parameters, \a params. Returns true if
949 the action could be executed; otherwise returns false.
950
951 \a action can be a predefined or a custom action.
952
953 \sa userActionCount(), actionText()
954*/
955
956/*!
957 \fn QColor QAccessibleInterface::backgroundColor()
958 \internal
959*/
960
961/*!
962 \fn QAccessibleEditableTextInterface *QAccessibleInterface::editableTextInterface()
963 \internal
964*/
965
966/*!
967 \fn QColor QAccessibleInterface::foregroundColor()
968 \internal
969*/
970
971/*!
972 \fn QAccessibleTextInterface *QAccessibleInterface::textInterface()
973 \internal
974*/
975
976/*!
977 \fn QAccessibleValueInterface *QAccessibleInterface::valueInterface()
978 \internal
979*/
980
981/*!
982 \fn QAccessibleTableInterface *QAccessibleInterface::tableInterface()
983 \internal
984*/
985
986/*!
987 \class QAccessibleEvent
988 \brief The QAccessibleEvent class is used to query addition
989 accessibility information about complex widgets.
990
991 The event can be of type QEvent::AccessibilityDescription or
992 QEvent::AccessibilityHelp.
993
994 Some QAccessibleInterface implementations send QAccessibleEvents
995 to the widget they wrap to obtain the description or help text of
996 a widget or of its children. The widget can answer by calling
997 setValue() with the requested information.
998
999 The default QWidget::event() implementation simply sets the text
1000 to be the widget's \l{QWidget::toolTip}{tooltip} (for \l
1001 AccessibilityDescription event) or its
1002 \l{QWidget::whatsThis}{"What's This?" text} (for \l
1003 AccessibilityHelp event).
1004
1005 \ingroup accessibility
1006 \ingroup events
1007*/
1008
1009/*!
1010 \fn QAccessibleEvent::QAccessibleEvent(Type type, int child)
1011
1012 Constructs an accessibility event of the given \a type, which
1013 must be QEvent::AccessibilityDescription or
1014 QEvent::AccessibilityHelp.
1015
1016 \a child is the (1-based) index of the child to which the request
1017 applies. If \a child is 0, the request is for the widget itself.
1018
1019 \sa child()
1020*/
1021
1022/*!
1023 \fn int QAccessibleEvent::child() const
1024
1025 Returns the (1-based) index of the child to which the request
1026 applies. If the child is 0, the request is for the widget itself.
1027*/
1028
1029/*!
1030 \fn QString QAccessibleEvent::value() const
1031
1032 Returns the text set using setValue().
1033
1034 \sa setValue()
1035*/
1036
1037/*!
1038 \fn void QAccessibleEvent::setValue(const QString &text)
1039
1040 Set the description or help text for the given child() to \a
1041 text, thereby answering the request.
1042
1043 \sa value()
1044*/
1045
1046/*!
1047 \since 4.2
1048
1049 Invokes a \a method on \a child with the given parameters \a params
1050 and returns the result of the operation as QVariant.
1051
1052 Note that the type of the returned QVariant depends on the action.
1053
1054 Returns an invalid QVariant if the object doesn't support the action.
1055*/
1056QVariant QAccessibleInterface::invokeMethod(Method method, int child, const QVariantList &params)
1057{
1058 if (!(state(0) & HasInvokeExtension))
1059 return QVariant();
1060
1061 return static_cast<QAccessibleInterfaceEx *>(this)->invokeMethodEx(method, child, params);
1062}
1063
1064QVariant QAccessibleInterfaceEx::virtual_hook(const QVariant &)
1065{
1066 return QVariant();
1067}
1068
1069/*! \internal */
1070QAccessible2Interface *QAccessibleInterface::cast_helper(QAccessible2::InterfaceType t)
1071{
1072 if (state(0) & HasInvokeExtension)
1073 return static_cast<QAccessibleInterfaceEx *>(this)->interface_cast(t);
1074 return 0;
1075}
1076
1077QT_END_NAMESPACE
1078
1079#endif
Note: See TracBrowser for help on using the repository browser.