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 | |
26 | QT_BEGIN_NAMESPACE |
27 | |
28 | class QTextEdit; |
29 | class QStackedWidget; |
30 | class QToolBox; |
31 | class QMdiArea; |
32 | class QMdiSubWindow; |
33 | class QRubberBand; |
34 | class QTextBrowser; |
35 | class QCalendarWidget; |
36 | class QAbstractItemView; |
37 | class QDockWidget; |
38 | class QDockWidgetLayout; |
39 | class QMainWindow; |
40 | class QPlainTextEdit; |
41 | class QTextCursor; |
42 | class QTextDocument; |
43 | |
44 | #ifndef QT_NO_CURSOR |
45 | class QAccessibleTextWidget : public QAccessibleWidget, |
46 | public QAccessibleTextInterface, |
47 | public QAccessibleEditableTextInterface |
48 | { |
49 | public: |
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 | |
89 | protected: |
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) |
100 | class QAccessiblePlainTextEdit : public QAccessibleTextWidget |
101 | { |
102 | public: |
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 | |
116 | protected: |
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 | |
126 | class QAccessibleTextEdit : public QAccessibleTextWidget |
127 | { |
128 | public: |
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 | |
142 | protected: |
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 | |
154 | class QAccessibleStackedWidget : public QAccessibleWidget |
155 | { |
156 | public: |
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 | |
164 | protected: |
165 | QStackedWidget *stackedWidget() const; |
166 | }; |
167 | |
168 | class QAccessibleToolBox : public QAccessibleWidget |
169 | { |
170 | public: |
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 | |
179 | protected: |
180 | QToolBox *toolBox() const; |
181 | }; |
182 | |
183 | #if QT_CONFIG(mdiarea) |
184 | class QAccessibleMdiArea : public QAccessibleWidget |
185 | { |
186 | public: |
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 | |
193 | protected: |
194 | QMdiArea *mdiArea() const; |
195 | }; |
196 | |
197 | class QAccessibleMdiSubWindow : public QAccessibleWidget |
198 | { |
199 | public: |
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 | |
210 | protected: |
211 | QMdiSubWindow *mdiSubWindow() const; |
212 | }; |
213 | #endif // QT_CONFIG(mdiarea) |
214 | |
215 | #if QT_CONFIG(dialogbuttonbox) |
216 | class QAccessibleDialogButtonBox : public QAccessibleWidget |
217 | { |
218 | public: |
219 | explicit QAccessibleDialogButtonBox(QWidget *widget); |
220 | }; |
221 | #endif |
222 | |
223 | #if QT_CONFIG(textbrowser) && !defined(QT_NO_CURSOR) |
224 | class QAccessibleTextBrowser : public QAccessibleTextEdit |
225 | { |
226 | public: |
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) |
234 | class QAccessibleCalendarWidget : public QAccessibleWidget |
235 | { |
236 | public: |
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 | |
244 | protected: |
245 | QCalendarWidget *calendarWidget() const; |
246 | |
247 | private: |
248 | QAbstractItemView *calendarView() const; |
249 | QWidget *navigationBar() const; |
250 | }; |
251 | #endif // QT_CONFIG(calendarwidget) |
252 | |
253 | #if QT_CONFIG(dockwidget) |
254 | class QAccessibleDockWidget: public QAccessibleWidget |
255 | { |
256 | public: |
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; |
265 | protected: |
266 | QDockWidgetLayout *dockWidgetLayout() const; |
267 | }; |
268 | |
269 | #endif // QT_CONFIG(dockwidget) |
270 | |
271 | #if QT_CONFIG(mainwindow) |
272 | class QAccessibleMainWindow : public QAccessibleWidget |
273 | { |
274 | public: |
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 | |
288 | QT_END_NAMESPACE |
289 | |
290 | #endif // QACESSIBLEWIDGETS_H |
291 | |