source: trunk/src/gui/accessible/qaccessible.h@ 890

Last change on this file since 890 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 14.3 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this 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 have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QACCESSIBLE_H
43#define QACCESSIBLE_H
44
45#include <QtCore/qglobal.h>
46#include <QtCore/qobject.h>
47#include <QtCore/qrect.h>
48#include <QtCore/qset.h>
49#include <QtCore/qvector.h>
50#include <QtCore/qvariant.h>
51#include <QtGui/qcolor.h>
52#include <QtGui/qevent.h>
53
54QT_BEGIN_HEADER
55
56QT_BEGIN_NAMESPACE
57
58QT_MODULE(Gui)
59
60#ifndef QT_NO_ACCESSIBILITY
61
62class QAccessibleInterface;
63
64class Q_GUI_EXPORT QAccessible
65{
66public:
67 enum Event {
68 SoundPlayed = 0x0001,
69 Alert = 0x0002,
70 ForegroundChanged = 0x0003,
71 MenuStart = 0x0004,
72 MenuEnd = 0x0005,
73 PopupMenuStart = 0x0006,
74 PopupMenuEnd = 0x0007,
75 ContextHelpStart = 0x000C,
76 ContextHelpEnd = 0x000D,
77 DragDropStart = 0x000E,
78 DragDropEnd = 0x000F,
79 DialogStart = 0x0010,
80 DialogEnd = 0x0011,
81 ScrollingStart = 0x0012,
82 ScrollingEnd = 0x0013,
83
84 MenuCommand = 0x0018,
85
86 ObjectCreated = 0x8000,
87 ObjectDestroyed = 0x8001,
88 ObjectShow = 0x8002,
89 ObjectHide = 0x8003,
90 ObjectReorder = 0x8004,
91 Focus = 0x8005,
92 Selection = 0x8006,
93 SelectionAdd = 0x8007,
94 SelectionRemove = 0x8008,
95 SelectionWithin = 0x8009,
96 StateChanged = 0x800A,
97 LocationChanged = 0x800B,
98 NameChanged = 0x800C,
99 DescriptionChanged = 0x800D,
100 ValueChanged = 0x800E,
101 ParentChanged = 0x800F,
102 HelpChanged = 0x80A0,
103 DefaultActionChanged = 0x80B0,
104 AcceleratorChanged = 0x80C0
105 };
106
107 enum StateFlag {
108 Normal = 0x00000000,
109 Unavailable = 0x00000001,
110 Selected = 0x00000002,
111 Focused = 0x00000004,
112 Pressed = 0x00000008,
113 Checked = 0x00000010,
114 Mixed = 0x00000020,
115 ReadOnly = 0x00000040,
116 HotTracked = 0x00000080,
117 DefaultButton = 0x00000100,
118 Expanded = 0x00000200,
119 Collapsed = 0x00000400,
120 Busy = 0x00000800,
121 // Floating = 0x00001000,
122 Marqueed = 0x00002000,
123 Animated = 0x00004000,
124 Invisible = 0x00008000,
125 Offscreen = 0x00010000,
126 Sizeable = 0x00020000,
127 Movable = 0x00040000,
128#ifdef QT3_SUPPORT
129 Moveable = Movable,
130#endif
131 SelfVoicing = 0x00080000,
132 Focusable = 0x00100000,
133 Selectable = 0x00200000,
134 Linked = 0x00400000,
135 Traversed = 0x00800000,
136 MultiSelectable = 0x01000000,
137 ExtSelectable = 0x02000000,
138 //AlertLow = 0x04000000,
139 //AlertMedium = 0x08000000,
140 //AlertHigh = 0x10000000, /* reused for HasInvokeExtension */
141 Protected = 0x20000000,
142 HasPopup = 0x40000000,
143 Modal = 0x80000000,
144
145 HasInvokeExtension = 0x10000000 // internal
146 };
147 Q_DECLARE_FLAGS(State, StateFlag)
148
149 enum Role {
150 NoRole = 0x00000000,
151 TitleBar = 0x00000001,
152 MenuBar = 0x00000002,
153 ScrollBar = 0x00000003,
154 Grip = 0x00000004,
155 Sound = 0x00000005,
156 Cursor = 0x00000006,
157 Caret = 0x00000007,
158 AlertMessage = 0x00000008,
159 Window = 0x00000009,
160 Client = 0x0000000A,
161 PopupMenu = 0x0000000B,
162 MenuItem = 0x0000000C,
163 ToolTip = 0x0000000D,
164 Application = 0x0000000E,
165 Document = 0x0000000F,
166 Pane = 0x00000010,
167 Chart = 0x00000011,
168 Dialog = 0x00000012,
169 Border = 0x00000013,
170 Grouping = 0x00000014,
171 Separator = 0x00000015,
172 ToolBar = 0x00000016,
173 StatusBar = 0x00000017,
174 Table = 0x00000018,
175 ColumnHeader = 0x00000019,
176 RowHeader = 0x0000001A,
177 Column = 0x0000001B,
178 Row = 0x0000001C,
179 Cell = 0x0000001D,
180 Link = 0x0000001E,
181 HelpBalloon = 0x0000001F,
182 Assistant = 0x00000020,
183 List = 0x00000021,
184 ListItem = 0x00000022,
185 Tree = 0x00000023,
186 TreeItem = 0x00000024,
187 PageTab = 0x00000025,
188 PropertyPage = 0x00000026,
189 Indicator = 0x00000027,
190 Graphic = 0x00000028,
191 StaticText = 0x00000029,
192 EditableText = 0x0000002A, // Editable, selectable, etc.
193 PushButton = 0x0000002B,
194 CheckBox = 0x0000002C,
195 RadioButton = 0x0000002D,
196 ComboBox = 0x0000002E,
197 // DropList = 0x0000002F,
198 ProgressBar = 0x00000030,
199 Dial = 0x00000031,
200 HotkeyField = 0x00000032,
201 Slider = 0x00000033,
202 SpinBox = 0x00000034,
203 Canvas = 0x00000035,
204 Animation = 0x00000036,
205 Equation = 0x00000037,
206 ButtonDropDown = 0x00000038,
207 ButtonMenu = 0x00000039,
208 ButtonDropGrid = 0x0000003A,
209 Whitespace = 0x0000003B,
210 PageTabList = 0x0000003C,
211 Clock = 0x0000003D,
212 Splitter = 0x0000003E,
213 // Additional Qt roles where enum value does not map directly to MSAA:
214 LayeredPane = 0x0000003F,
215 UserRole = 0x0000ffff
216 };
217
218 enum Text {
219 Name = 0,
220 Description,
221 Value,
222 Help,
223 Accelerator,
224 UserText = 0x0000ffff
225 };
226
227 enum RelationFlag {
228 Unrelated = 0x00000000,
229 Self = 0x00000001,
230 Ancestor = 0x00000002,
231 Child = 0x00000004,
232 Descendent = 0x00000008,
233 Sibling = 0x00000010,
234 HierarchyMask = 0x000000ff,
235
236 Up = 0x00000100,
237 Down = 0x00000200,
238 Left = 0x00000400,
239 Right = 0x00000800,
240 Covers = 0x00001000,
241 Covered = 0x00002000,
242 GeometryMask = 0x0000ff00,
243
244 FocusChild = 0x00010000,
245 Label = 0x00020000,
246 Labelled = 0x00040000,
247 Controller = 0x00080000,
248 Controlled = 0x00100000,
249 LogicalMask = 0x00ff0000
250 };
251 Q_DECLARE_FLAGS(Relation, RelationFlag)
252
253 enum Action {
254 DefaultAction = 0,
255 Press = -1,
256 FirstStandardAction = Press,
257 SetFocus = -2,
258 Increase = -3,
259 Decrease = -4,
260 Accept = -5,
261 Cancel = -6,
262 Select = -7,
263 ClearSelection = -8,
264 RemoveSelection = -9,
265 ExtendSelection = -10,
266 AddToSelection = -11,
267 LastStandardAction = AddToSelection
268 };
269
270 enum Method {
271 ListSupportedMethods = 0,
272 SetCursorPosition = 1,
273 GetCursorPosition = 2,
274 ForegroundColor = 3,
275 BackgroundColor = 4
276 };
277
278 typedef QAccessibleInterface*(*InterfaceFactory)(const QString &key, QObject*);
279 typedef void(*UpdateHandler)(QObject*, int who, Event reason);
280 typedef void(*RootObjectHandler)(QObject*);
281
282 static void installFactory(InterfaceFactory);
283 static void removeFactory(InterfaceFactory);
284 static UpdateHandler installUpdateHandler(UpdateHandler);
285 static RootObjectHandler installRootObjectHandler(RootObjectHandler);
286
287 static QAccessibleInterface *queryAccessibleInterface(QObject *);
288 static void updateAccessibility(QObject *, int who, Event reason);
289 static bool isActive();
290 static void setRootObject(QObject*);
291
292 static void initialize();
293 static void cleanup();
294
295private:
296 static UpdateHandler updateHandler;
297 static RootObjectHandler rootObjectHandler;
298};
299
300Q_DECLARE_OPERATORS_FOR_FLAGS(QAccessible::State)
301Q_DECLARE_OPERATORS_FOR_FLAGS(QAccessible::Relation)
302QT_END_NAMESPACE
303Q_DECLARE_METATYPE(QSet<QAccessible::Method>)
304QT_BEGIN_NAMESPACE
305
306namespace QAccessible2
307{
308 enum InterfaceType
309 {
310 TextInterface,
311 EditableTextInterface,
312 ValueInterface,
313 TableInterface,
314 ActionInterface,
315 ImageInterface
316 };
317}
318
319class QAccessible2Interface;
320class QAccessibleTextInterface;
321class QAccessibleEditableTextInterface;
322class QAccessibleValueInterface;
323class QAccessibleTableInterface;
324class QAccessibleActionInterface;
325class QAccessibleImageInterface;
326
327class Q_GUI_EXPORT QAccessibleInterface : public QAccessible
328{
329public:
330 virtual ~QAccessibleInterface() {}
331 // check for valid pointers
332 virtual bool isValid() const = 0;
333 virtual QObject *object() const = 0;
334
335 // hierarchy
336 virtual int childCount() const = 0;
337 virtual int indexOfChild(const QAccessibleInterface *) const = 0;
338
339 // relations
340 virtual Relation relationTo(int child, const QAccessibleInterface *other,
341 int otherChild) const = 0;
342 virtual int childAt(int x, int y) const = 0;
343
344 // navigation
345 virtual int navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const = 0;
346
347 // properties and state
348 virtual QString text(Text t, int child) const = 0;
349 virtual void setText(Text t, int child, const QString &text) = 0;
350 virtual QRect rect(int child) const = 0;
351 virtual Role role(int child) const = 0;
352 virtual State state(int child) const = 0;
353
354 // action
355 virtual int userActionCount(int child) const = 0;
356 virtual QString actionText(int action, Text t, int child) const = 0;
357 virtual bool doAction(int action, int child, const QVariantList &params = QVariantList()) = 0;
358
359 QVariant invokeMethod(Method method, int child = 0,
360 const QVariantList &params = QVariantList());
361
362 inline QSet<Method> supportedMethods()
363 { return qvariant_cast<QSet<Method> >(invokeMethod(ListSupportedMethods)); }
364
365 inline QColor foregroundColor()
366 { return qvariant_cast<QColor>(invokeMethod(ForegroundColor)); }
367
368 inline QColor backgroundColor()
369 { return qvariant_cast<QColor>(invokeMethod(BackgroundColor)); }
370
371 inline QAccessibleTextInterface *textInterface()
372 { return reinterpret_cast<QAccessibleTextInterface *>(cast_helper(QAccessible2::TextInterface)); }
373
374 inline QAccessibleEditableTextInterface *editableTextInterface()
375 { return reinterpret_cast<QAccessibleEditableTextInterface *>(cast_helper(QAccessible2::EditableTextInterface)); }
376
377 inline QAccessibleValueInterface *valueInterface()
378 { return reinterpret_cast<QAccessibleValueInterface *>(cast_helper(QAccessible2::ValueInterface)); }
379
380 inline QAccessibleTableInterface *tableInterface()
381 { return reinterpret_cast<QAccessibleTableInterface *>(cast_helper(QAccessible2::TableInterface)); }
382
383 inline QAccessibleActionInterface *actionInterface()
384 { return reinterpret_cast<QAccessibleActionInterface *>(cast_helper(QAccessible2::ActionInterface)); }
385
386 inline QAccessibleImageInterface *imageInterface()
387 { return reinterpret_cast<QAccessibleImageInterface *>(cast_helper(QAccessible2::ImageInterface)); }
388
389private:
390 QAccessible2Interface *cast_helper(QAccessible2::InterfaceType);
391};
392
393class Q_GUI_EXPORT QAccessibleInterfaceEx: public QAccessibleInterface
394{
395public:
396 virtual QVariant invokeMethodEx(Method method, int child, const QVariantList &params) = 0;
397 virtual QVariant virtual_hook(const QVariant &data);
398 virtual QAccessible2Interface *interface_cast(QAccessible2::InterfaceType)
399 { return 0; }
400};
401
402
403class Q_GUI_EXPORT QAccessibleEvent : public QEvent
404{
405public:
406 inline QAccessibleEvent(Type type, int child);
407 inline int child() const { return c; }
408 inline QString value() const { return val; }
409 inline void setValue(const QString &aText) { val = aText; }
410
411private:
412 int c;
413 QString val;
414};
415
416inline QAccessibleEvent::QAccessibleEvent(Type atype, int achild)
417 : QEvent(atype), c(achild) {}
418
419#define QAccessibleInterface_iid "com.trolltech.Qt.QAccessibleInterface"
420Q_DECLARE_INTERFACE(QAccessibleInterface, QAccessibleInterface_iid)
421
422#endif // QT_NO_ACCESSIBILITY
423
424QT_END_NAMESPACE
425
426QT_END_HEADER
427
428#endif // QACCESSIBLE_H
Note: See TracBrowser for help on using the repository browser.