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
qwindowsuiavalueprovider.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
8#include "qwindowsuiautils.h"
9#include "qwindowscontext.h"
10
11#include <QtGui/qaccessible.h>
12#include <QtCore/qloggingcategory.h>
13#include <QtCore/qstring.h>
14
16
17using namespace QWindowsUiAutomation;
18
19
20QWindowsUiaValueProvider::QWindowsUiaValueProvider(QAccessible::Id id) :
21 QWindowsUiaBaseProvider(id)
22{
23}
24
25QWindowsUiaValueProvider::~QWindowsUiaValueProvider()
26{
27}
28
29// Sets the value associated with the control.
30HRESULT STDMETHODCALLTYPE QWindowsUiaValueProvider::SetValue(LPCWSTR val)
31{
32 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
33
34 QAccessibleInterface *accessible = accessibleInterface();
35 if (!accessible)
36 return UIA_E_ELEMENTNOTAVAILABLE;
37
38 // First sets the value as a text.
39 QString strVal = QString::fromUtf16(reinterpret_cast<const char16_t *>(val));
40 accessible->setText(QAccessible::Value, strVal);
41
42 // Then, if the control supports the value interface (range value)
43 // and the supplied text can be converted to a number, and that number
44 // lies within the min/max limits, sets it as the control's current (numeric) value.
45 if (QAccessibleValueInterface *valueInterface = accessible->valueInterface()) {
46 bool ok = false;
47 double numval = strVal.toDouble(&ok);
48 if (ok) {
49 double minimum = valueInterface->minimumValue().toDouble();
50 double maximum = valueInterface->maximumValue().toDouble();
51 if ((numval >= minimum) && (numval <= maximum)) {
52 valueInterface->setCurrentValue(QVariant(numval));
53 }
54 }
55 }
56 return S_OK;
57}
58
59// True for read-only controls.
60HRESULT STDMETHODCALLTYPE QWindowsUiaValueProvider::get_IsReadOnly(BOOL *pRetVal)
61{
62 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
63
64 if (!pRetVal)
65 return E_INVALIDARG;
66 *pRetVal = FALSE;
67
68 QAccessibleInterface *accessible = accessibleInterface();
69 if (!accessible)
70 return UIA_E_ELEMENTNOTAVAILABLE;
71
72 *pRetVal = accessible->state().readOnly;
73 return S_OK;
74}
75
76// Returns the value in text form.
77HRESULT STDMETHODCALLTYPE QWindowsUiaValueProvider::get_Value(BSTR *pRetVal)
78{
79 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
80
81 if (!pRetVal)
82 return E_INVALIDARG;
83 *pRetVal = nullptr;
84
85 QAccessibleInterface *accessible = accessibleInterface();
86 if (!accessible)
87 return UIA_E_ELEMENTNOTAVAILABLE;
88
89 *pRetVal = bStrFromQString(accessible->text(QAccessible::Value));
90 return S_OK;
91}
92
94
95#endif // QT_CONFIG(accessibility)
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromUtf16(const char16_t *, qsizetype size=-1)
Definition qstring.cpp:6045
\inmodule QtCore
Definition qvariant.h:65
QVector3D minimum(const QVector3D &v1, const QVector3D &v2) Q_DECL_NOTHROW
Definition qssgutils_p.h:54
QVector3D maximum(const QVector3D &v1, const QVector3D &v2) Q_DECL_NOTHROW
Definition qssgutils_p.h:55
Combined button and popup list for selecting options.
#define qCDebug(category,...)
GLenum GLuint id
[7]
GLuint GLfloat * val
long HRESULT