Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qwindowsuiaselectionprovider.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#include <QtCore/qlist.h>
16
18
19using namespace QWindowsUiAutomation;
20
21
22QWindowsUiaSelectionProvider::QWindowsUiaSelectionProvider(QAccessible::Id id) :
23 QWindowsUiaBaseProvider(id)
24{
25}
26
27QWindowsUiaSelectionProvider::~QWindowsUiaSelectionProvider()
28{
29}
30
31// Returns an array of providers with the selected items.
32HRESULT STDMETHODCALLTYPE QWindowsUiaSelectionProvider::GetSelection(SAFEARRAY **pRetVal)
33{
34 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
35
36 if (!pRetVal)
37 return E_INVALIDARG;
38 *pRetVal = nullptr;
39
40 QAccessibleInterface *accessible = accessibleInterface();
41 if (!accessible)
43
44 // First put selected items in a list, then build a safe array with the right size.
46 for (int i = 0; i < accessible->childCount(); ++i) {
47 if (QAccessibleInterface *child = accessible->child(i)) {
48 if (accessible->role() == QAccessible::PageTabList) {
49 if (child->role() == QAccessible::PageTab && child->state().focused) {
50 selectedList.append(child);
51 }
52 } else {
53 if (child->state().selected) {
54 selectedList.append(child);
55 }
56 }
57 }
58 }
59
60 if ((*pRetVal = SafeArrayCreateVector(VT_UNKNOWN, 0, selectedList.size()))) {
61 for (LONG i = 0; i < selectedList.size(); ++i) {
62 if (QWindowsUiaMainProvider *childProvider = QWindowsUiaMainProvider::providerForAccessible(selectedList.at(i))) {
63 SafeArrayPutElement(*pRetVal, &i, static_cast<IRawElementProviderSimple *>(childProvider));
64 childProvider->Release();
65 }
66 }
67 }
68 return S_OK;
69}
70
71HRESULT STDMETHODCALLTYPE QWindowsUiaSelectionProvider::get_CanSelectMultiple(BOOL *pRetVal)
72{
73 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
74
75 if (!pRetVal)
76 return E_INVALIDARG;
77 *pRetVal = FALSE;
78
79 QAccessibleInterface *accessible = accessibleInterface();
80 if (!accessible)
82
83 *pRetVal = accessible->state().multiSelectable;
84 return S_OK;
85}
86
87HRESULT STDMETHODCALLTYPE QWindowsUiaSelectionProvider::get_IsSelectionRequired(BOOL *pRetVal)
88{
89 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
90
91 if (!pRetVal)
92 return E_INVALIDARG;
93 *pRetVal = FALSE;
94
95 QAccessibleInterface *accessible = accessibleInterface();
96 if (!accessible)
98
99 if (accessible->role() == QAccessible::PageTabList) {
100 *pRetVal = TRUE;
101 } else {
102
103 // Initially returns false if none are selected. After the first selection, it may be required.
104 bool anySelected = false;
105 for (int i = 0; i < accessible->childCount(); ++i) {
106 if (QAccessibleInterface *child = accessible->child(i)) {
107 if (child->state().selected) {
108 anySelected = true;
109 break;
110 }
111 }
112 }
113
114 *pRetVal = anySelected && !accessible->state().multiSelectable && !accessible->state().extSelectable;
115 }
116 return S_OK;
117}
118
120
121#endif // QT_CONFIG(accessibility)
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
void append(parameter_type t)
Definition qlist.h:441
Combined button and popup list for selecting options.
#define qCDebug(category,...)
GLenum GLuint id
[7]
long HRESULT
QLayoutItem * child
[0]
#define UIA_E_ELEMENTNOTAVAILABLE
IRawElementProviderFragment __RPC__deref_out_opt IRawElementProviderFragment ** pRetVal