Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwindowsuiaselectionitemprovider.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 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#include <QtGui/qtguiglobal.h>
5#if QT_CONFIG(accessibility)
6
9#include "qwindowsuiautils.h"
10#include "qwindowscontext.h"
11
12#include <QtGui/qaccessible.h>
13#include <QtCore/qloggingcategory.h>
14#include <QtCore/qstring.h>
15
17
18using namespace QWindowsUiAutomation;
19
20
21QWindowsUiaSelectionItemProvider::QWindowsUiaSelectionItemProvider(QAccessible::Id id) :
22 QWindowsUiaBaseProvider(id)
23{
24}
25
26QWindowsUiaSelectionItemProvider::~QWindowsUiaSelectionItemProvider()
27{
28}
29
30// Selects the element (deselecting all others).
31HRESULT STDMETHODCALLTYPE QWindowsUiaSelectionItemProvider::Select()
32{
33 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
34
35 QAccessibleInterface *accessible = accessibleInterface();
36 if (!accessible)
37 return UIA_E_ELEMENTNOTAVAILABLE;
38
39 if (QAccessibleInterface *parent = accessible->parent()) {
40 if (QAccessibleSelectionInterface *selectionInterface = parent->selectionInterface()) {
41 selectionInterface->clear();
42 bool ok = selectionInterface->select(accessible);
43 return ok ? S_OK : S_FALSE;
44 }
45 }
46
47 QAccessibleActionInterface *actionInterface = accessible->actionInterface();
48 if (!actionInterface)
49 return UIA_E_ELEMENTNOTAVAILABLE;
50
51 if (accessible->role() == QAccessible::RadioButton || accessible->role() == QAccessible::PageTab) {
52 // For radio buttons/tabs we just invoke the selection action; others are automatically deselected.
53 actionInterface->doAction(QAccessibleActionInterface::pressAction());
54 } else {
55 // Toggle list item if not already selected. It must be done first to support all selection modes.
56 if (!accessible->state().selected) {
57 actionInterface->doAction(QAccessibleActionInterface::toggleAction());
58 }
59 // Toggle selected siblings.
60 if (QAccessibleInterface *parent = accessible->parent()) {
61 for (int i = 0; i < parent->childCount(); ++i) {
62 if (QAccessibleInterface *sibling = parent->child(i)) {
63 if ((sibling != accessible) && (sibling->state().selected)) {
64 if (QAccessibleActionInterface *siblingAction = sibling->actionInterface()) {
65 siblingAction->doAction(QAccessibleActionInterface::toggleAction());
66 }
67 }
68 }
69 }
70 }
71 }
72 return S_OK;
73}
74
75// Adds the element to the list of selected elements.
76HRESULT STDMETHODCALLTYPE QWindowsUiaSelectionItemProvider::AddToSelection()
77{
78 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
79
80 QAccessibleInterface *accessible = accessibleInterface();
81 if (!accessible)
82 return UIA_E_ELEMENTNOTAVAILABLE;
83
84 if (QAccessibleInterface *parent = accessible->parent()) {
85 if (QAccessibleSelectionInterface *selectionInterface = parent->selectionInterface()) {
86 bool ok = selectionInterface->select(accessible);
87 return ok ? S_OK : S_FALSE;
88 }
89 }
90
91 QAccessibleActionInterface *actionInterface = accessible->actionInterface();
92 if (!actionInterface)
93 return UIA_E_ELEMENTNOTAVAILABLE;
94
95 if (accessible->role() == QAccessible::RadioButton || accessible->role() == QAccessible::PageTab) {
96 // For radio buttons and tabs we invoke the selection action.
97 actionInterface->doAction(QAccessibleActionInterface::pressAction());
98 } else {
99 // Toggle list item if not already selected.
100 if (!accessible->state().selected) {
101 actionInterface->doAction(QAccessibleActionInterface::toggleAction());
102 }
103 }
104 return S_OK;
105}
106
107// Removes a list item from selection.
108HRESULT STDMETHODCALLTYPE QWindowsUiaSelectionItemProvider::RemoveFromSelection()
109{
110 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
111
112 QAccessibleInterface *accessible = accessibleInterface();
113 if (!accessible)
114 return UIA_E_ELEMENTNOTAVAILABLE;
115
116 if (QAccessibleInterface *parent = accessible->parent()) {
117 if (QAccessibleSelectionInterface *selectionInterface = parent->selectionInterface()) {
118 bool ok = selectionInterface->unselect(accessible);
119 return ok ? S_OK : S_FALSE;
120 }
121 }
122
123 QAccessibleActionInterface *actionInterface = accessible->actionInterface();
124 if (!actionInterface)
125 return UIA_E_ELEMENTNOTAVAILABLE;
126
127 if (accessible->role() != QAccessible::RadioButton && accessible->role() != QAccessible::PageTab) {
128 if (accessible->state().selected) {
129 actionInterface->doAction(QAccessibleActionInterface::toggleAction());
130 }
131 }
132
133 return S_OK;
134}
135
136// Returns true if element is currently selected.
137HRESULT STDMETHODCALLTYPE QWindowsUiaSelectionItemProvider::get_IsSelected(BOOL *pRetVal)
138{
139 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
140
141 if (!pRetVal)
142 return E_INVALIDARG;
143 *pRetVal = FALSE;
144
145 QAccessibleInterface *accessible = accessibleInterface();
146 if (!accessible)
147 return UIA_E_ELEMENTNOTAVAILABLE;
148
149 if (QAccessibleInterface *parent = accessible->parent()) {
150 if (QAccessibleSelectionInterface *selectionInterface = parent->selectionInterface()) {
151 bool selected = selectionInterface->isSelected(accessible);
152 *pRetVal = selected ? TRUE : FALSE;
153 return S_OK;
154 }
155 }
156
157 if (accessible->role() == QAccessible::RadioButton)
158 *pRetVal = accessible->state().checked;
159 else if (accessible->role() == QAccessible::PageTab)
160 *pRetVal = accessible->state().focused;
161 else
162 *pRetVal = accessible->state().selected;
163 return S_OK;
164}
165
166// Returns the provider for the container element (e.g., the list for the list item).
167HRESULT STDMETHODCALLTYPE QWindowsUiaSelectionItemProvider::get_SelectionContainer(IRawElementProviderSimple **pRetVal)
168{
169 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
170
171 if (!pRetVal)
172 return E_INVALIDARG;
173 *pRetVal = nullptr;
174
175 QAccessibleInterface *accessible = accessibleInterface();
176 if (!accessible)
177 return UIA_E_ELEMENTNOTAVAILABLE;
178
179 QAccessibleInterface *parent = accessible->parent();
180 if (parent && parent->selectionInterface()) {
181 *pRetVal = QWindowsUiaMainProvider::providerForAccessible(parent);
182 return S_OK;
183 }
184
185 QAccessibleActionInterface *actionInterface = accessible->actionInterface();
186 if (!actionInterface)
187 return UIA_E_ELEMENTNOTAVAILABLE;
188
189 // Radio buttons do not require a container.
190 if (parent) {
191 if ((accessible->role() == QAccessible::ListItem && parent->role() == QAccessible::List)
192 || (accessible->role() == QAccessible::PageTab && parent->role() == QAccessible::PageTabList)) {
193 *pRetVal = QWindowsUiaMainProvider::providerForAccessible(parent);
194 }
195 }
196 return S_OK;
197}
198
200
201#endif // QT_CONFIG(accessibility)
Combined button and popup list for selecting options.
#define qCDebug(category,...)
GLenum GLuint id
[7]
long HRESULT