1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QACCESSIBLEWIDGETS_H
5#define QACCESSIBLEWIDGETS_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtWidgets/private/qtwidgetsglobal_p.h>
19#include <QtWidgets/qaccessiblewidget.h>
20
21#if QT_CONFIG(accessibility)
22
23#include <QtCore/QPointer>
24#include <QtCore/QPair>
25
26QT_BEGIN_NAMESPACE
27
28class QTextEdit;
29class QStackedWidget;
30class QToolBox;
31class QMdiArea;
32class QMdiSubWindow;
33class QRubberBand;
34class QTextBrowser;
35class QCalendarWidget;
36class QAbstractItemView;
37class QDockWidget;
38class QDockWidgetLayout;
39class QMainWindow;
40class QPlainTextEdit;
41class QTextCursor;
42class QTextDocument;
43
44#ifndef QT_NO_CURSOR
45class QAccessibleTextWidget : public QAccessibleWidget,
46 public QAccessibleTextInterface,
47 public QAccessibleEditableTextInterface
48{
49public:
50 QAccessibleTextWidget(QWidget *o, QAccessible::Role r = QAccessible::EditableText, const QString &name = QString());
51
52 QAccessible::State state() const override;
53
54 // QAccessibleTextInterface
55 // selection
56 void selection(int selectionIndex, int *startOffset, int *endOffset) const override;
57 int selectionCount() const override;
58 void addSelection(int startOffset, int endOffset) override;
59 void removeSelection(int selectionIndex) override;
60 void setSelection(int selectionIndex, int startOffset, int endOffset) override;
61
62 // cursor
63 int cursorPosition() const override;
64 void setCursorPosition(int position) override;
65
66 // text
67 QString text(int startOffset, int endOffset) const override;
68 QString textBeforeOffset(int offset, QAccessible::TextBoundaryType boundaryType,
69 int *startOffset, int *endOffset) const override;
70 QString textAfterOffset(int offset, QAccessible::TextBoundaryType boundaryType,
71 int *startOffset, int *endOffset) const override;
72 QString textAtOffset(int offset, QAccessible::TextBoundaryType boundaryType,
73 int *startOffset, int *endOffset) const override;
74 int characterCount() const override;
75
76 // character <-> geometry
77 QRect characterRect(int offset) const override;
78 int offsetAtPoint(const QPoint &point) const override;
79
80 QString attributes(int offset, int *startOffset, int *endOffset) const override;
81
82 // QAccessibleEditableTextInterface
83 void deleteText(int startOffset, int endOffset) override;
84 void insertText(int offset, const QString &text) override;
85 void replaceText(int startOffset, int endOffset, const QString &text) override;
86
87 using QAccessibleWidget::text;
88
89protected:
90 QTextCursor textCursorForRange(int startOffset, int endOffset) const;
91 virtual QPoint scrollBarPosition() const;
92 // return the current text cursor at the caret position including a potential selection
93 virtual QTextCursor textCursor() const = 0;
94 virtual void setTextCursor(const QTextCursor &) = 0;
95 virtual QTextDocument *textDocument() const = 0;
96 virtual QWidget *viewport() const = 0;
97};
98
99#if QT_CONFIG(textedit)
100class QAccessiblePlainTextEdit : public QAccessibleTextWidget
101{
102public:
103 explicit QAccessiblePlainTextEdit(QWidget *o);
104
105 QString text(QAccessible::Text t) const override;
106 void setText(QAccessible::Text t, const QString &text) override;
107 QAccessible::State state() const override;
108
109 void *interface_cast(QAccessible::InterfaceType t) override;
110
111 // QAccessibleTextInterface
112 void scrollToSubstring(int startIndex, int endIndex) override;
113
114 using QAccessibleTextWidget::text;
115
116protected:
117 QPlainTextEdit *plainTextEdit() const;
118
119 QPoint scrollBarPosition() const override;
120 QTextCursor textCursor() const override;
121 void setTextCursor(const QTextCursor &textCursor) override;
122 QTextDocument *textDocument() const override;
123 QWidget *viewport() const override;
124};
125
126class QAccessibleTextEdit : public QAccessibleTextWidget
127{
128public:
129 explicit QAccessibleTextEdit(QWidget *o);
130
131 QString text(QAccessible::Text t) const override;
132 void setText(QAccessible::Text t, const QString &text) override;
133 QAccessible::State state() const override;
134
135 void *interface_cast(QAccessible::InterfaceType t) override;
136
137 // QAccessibleTextInterface
138 void scrollToSubstring(int startIndex, int endIndex) override;
139
140 using QAccessibleTextWidget::text;
141
142protected:
143 QTextEdit *textEdit() const;
144
145 QPoint scrollBarPosition() const override;
146 QTextCursor textCursor() const override;
147 void setTextCursor(const QTextCursor &textCursor) override;
148 QTextDocument *textDocument() const override;
149 QWidget *viewport() const override;
150};
151#endif // QT_CONFIG(textedit)
152#endif //QT_NO_CURSOR
153
154class QAccessibleStackedWidget : public QAccessibleWidget
155{
156public:
157 explicit QAccessibleStackedWidget(QWidget *widget);
158
159 QAccessibleInterface *childAt(int x, int y) const override;
160 int childCount() const override;
161 int indexOfChild(const QAccessibleInterface *child) const override;
162 QAccessibleInterface *child(int index) const override;
163
164protected:
165 QStackedWidget *stackedWidget() const;
166};
167
168class QAccessibleToolBox : public QAccessibleWidget
169{
170public:
171 explicit QAccessibleToolBox(QWidget *widget);
172
173// FIXME we currently expose the toolbox but it is not keyboard navigatable
174// and the accessible hierarchy is not exactly beautiful.
175// int childCount() const;
176// QAccessibleInterface *child(int index) const;
177// int indexOfChild(const QAccessibleInterface *child) const;
178
179protected:
180 QToolBox *toolBox() const;
181};
182
183#if QT_CONFIG(mdiarea)
184class QAccessibleMdiArea : public QAccessibleWidget
185{
186public:
187 explicit QAccessibleMdiArea(QWidget *widget);
188
189 int childCount() const override;
190 QAccessibleInterface *child(int index) const override;
191 int indexOfChild(const QAccessibleInterface *child) const override;
192
193protected:
194 QMdiArea *mdiArea() const;
195};
196
197class QAccessibleMdiSubWindow : public QAccessibleWidget
198{
199public:
200 explicit QAccessibleMdiSubWindow(QWidget *widget);
201
202 QString text(QAccessible::Text textType) const override;
203 void setText(QAccessible::Text textType, const QString &text) override;
204 QAccessible::State state() const override;
205 int childCount() const override;
206 QAccessibleInterface *child(int index) const override;
207 int indexOfChild(const QAccessibleInterface *child) const override;
208 QRect rect() const override;
209
210protected:
211 QMdiSubWindow *mdiSubWindow() const;
212};
213#endif // QT_CONFIG(mdiarea)
214
215#if QT_CONFIG(dialogbuttonbox)
216class QAccessibleDialogButtonBox : public QAccessibleWidget
217{
218public:
219 explicit QAccessibleDialogButtonBox(QWidget *widget);
220};
221#endif
222
223#if QT_CONFIG(textbrowser) && !defined(QT_NO_CURSOR)
224class QAccessibleTextBrowser : public QAccessibleTextEdit
225{
226public:
227 explicit QAccessibleTextBrowser(QWidget *widget);
228
229 QAccessible::Role role() const override;
230};
231#endif // QT_CONFIG(textbrowser) && QT_NO_CURSOR
232
233#if QT_CONFIG(calendarwidget)
234class QAccessibleCalendarWidget : public QAccessibleWidget
235{
236public:
237 explicit QAccessibleCalendarWidget(QWidget *widget);
238
239 int childCount() const override;
240 int indexOfChild(const QAccessibleInterface *child) const override;
241
242 QAccessibleInterface *child(int index) const override;
243
244protected:
245 QCalendarWidget *calendarWidget() const;
246
247private:
248 QAbstractItemView *calendarView() const;
249 QWidget *navigationBar() const;
250};
251#endif // QT_CONFIG(calendarwidget)
252
253#if QT_CONFIG(dockwidget)
254class QAccessibleDockWidget: public QAccessibleWidget
255{
256public:
257 explicit QAccessibleDockWidget(QWidget *widget);
258 QAccessibleInterface *child(int index) const override;
259 int indexOfChild(const QAccessibleInterface *child) const override;
260 int childCount() const override;
261 QRect rect () const override;
262 QString text(QAccessible::Text t) const override;
263
264 QDockWidget *dockWidget() const;
265protected:
266 QDockWidgetLayout *dockWidgetLayout() const;
267};
268
269#endif // QT_CONFIG(dockwidget)
270
271#if QT_CONFIG(mainwindow)
272class QAccessibleMainWindow : public QAccessibleWidget
273{
274public:
275 explicit QAccessibleMainWindow(QWidget *widget);
276
277 QAccessibleInterface *child(int index) const override;
278 int childCount() const override;
279 int indexOfChild(const QAccessibleInterface *iface) const override;
280 QAccessibleInterface *childAt(int x, int y) const override;
281 QMainWindow *mainWindow() const;
282
283};
284#endif // QT_CONFIG(mainwindow)
285
286#endif // QT_CONFIG(accessibility)
287
288QT_END_NAMESPACE
289
290#endif // QACESSIBLEWIDGETS_H
291

source code of qtbase/src/widgets/accessible/qaccessiblewidgets_p.h