Qt 6.x
The Qt SDK
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)
38
39 QAccessibleActionInterface *actionInterface = accessible->actionInterface();
40 if (!actionInterface)
42
43 if (accessible->role() == QAccessible::RadioButton || accessible->role() == QAccessible::PageTab) {
44 // For radio buttons/tabs we just invoke the selection action; others are automatically deselected.
45 actionInterface->doAction(QAccessibleActionInterface::pressAction());
46 } else {
47 // Toggle list item if not already selected. It must be done first to support all selection modes.
48 if (!accessible->state().selected) {
49 actionInterface->doAction(QAccessibleActionInterface::toggleAction());
50 }
51 // Toggle selected siblings.
52 if (QAccessibleInterface *parent = accessible->parent()) {
53 for (int i = 0; i < parent->childCount(); ++i) {
54 if (QAccessibleInterface *sibling = parent->child(i)) {
55 if ((sibling != accessible) && (sibling->state().selected)) {
56 if (QAccessibleActionInterface *siblingAction = sibling->actionInterface()) {
57 siblingAction->doAction(QAccessibleActionInterface::toggleAction());
58 }
59 }
60 }
61 }
62 }
63 }
64 return S_OK;
65}
66
67// Adds the element to the list of selected elements.
68HRESULT STDMETHODCALLTYPE QWindowsUiaSelectionItemProvider::AddToSelection()
69{
70 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
71
72 QAccessibleInterface *accessible = accessibleInterface();
73 if (!accessible)
75
76 QAccessibleActionInterface *actionInterface = accessible->actionInterface();
77 if (!actionInterface)
79
80 if (accessible->role() == QAccessible::RadioButton || accessible->role() == QAccessible::PageTab) {
81 // For radio buttons and tabs we invoke the selection action.
82 actionInterface->doAction(QAccessibleActionInterface::pressAction());
83 } else {
84 // Toggle list item if not already selected.
85 if (!accessible->state().selected) {
86 actionInterface->doAction(QAccessibleActionInterface::toggleAction());
87 }
88 }
89 return S_OK;
90}
91
92// Removes a list item from selection.
93HRESULT STDMETHODCALLTYPE QWindowsUiaSelectionItemProvider::RemoveFromSelection()
94{
95 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
96
97 QAccessibleInterface *accessible = accessibleInterface();
98 if (!accessible)
100
101 QAccessibleActionInterface *actionInterface = accessible->actionInterface();
102 if (!actionInterface)
104
105 if (accessible->role() != QAccessible::RadioButton && accessible->role() != QAccessible::PageTab) {
106 if (accessible->state().selected) {
107 actionInterface->doAction(QAccessibleActionInterface::toggleAction());
108 }
109 }
110
111 return S_OK;
112}
113
114// Returns true if element is currently selected.
115HRESULT STDMETHODCALLTYPE QWindowsUiaSelectionItemProvider::get_IsSelected(BOOL *pRetVal)
116{
117 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
118
119 if (!pRetVal)
120 return E_INVALIDARG;
121 *pRetVal = FALSE;
122
123 QAccessibleInterface *accessible = accessibleInterface();
124 if (!accessible)
126
127 if (accessible->role() == QAccessible::RadioButton)
128 *pRetVal = accessible->state().checked;
129 else if (accessible->role() == QAccessible::PageTab)
130 *pRetVal = accessible->state().focused;
131 else
132 *pRetVal = accessible->state().selected;
133 return S_OK;
134}
135
136// Returns the provider for the container element (e.g., the list for the list item).
137HRESULT STDMETHODCALLTYPE QWindowsUiaSelectionItemProvider::get_SelectionContainer(IRawElementProviderSimple **pRetVal)
138{
139 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
140
141 if (!pRetVal)
142 return E_INVALIDARG;
143 *pRetVal = nullptr;
144
145 QAccessibleInterface *accessible = accessibleInterface();
146 if (!accessible)
148
149 QAccessibleActionInterface *actionInterface = accessible->actionInterface();
150 if (!actionInterface)
152
153 // Radio buttons do not require a container.
154 if (QAccessibleInterface *parent = accessible->parent()) {
155 if ((accessible->role() == QAccessible::ListItem && parent->role() == QAccessible::List)
156 || (accessible->role() == QAccessible::PageTab && parent->role() == QAccessible::PageTabList)) {
157 *pRetVal = QWindowsUiaMainProvider::providerForAccessible(parent);
158 }
159 }
160 return S_OK;
161}
162
164
165#endif // QT_CONFIG(accessibility)
Combined button and popup list for selecting options.
#define qCDebug(category,...)
GLenum GLuint id
[7]
long HRESULT
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent
#define UIA_E_ELEMENTNOTAVAILABLE
IRawElementProviderFragment __RPC__deref_out_opt IRawElementProviderFragment ** pRetVal