Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant reason:default
4
5#include <QtGui/qtguiglobal.h>
6#if QT_CONFIG(accessibility)
7
8#include "qwindowsuiavalueprovider.h"
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
16QT_BEGIN_NAMESPACE
17
18using namespace QWindowsUiAutomation;
19
20
21QWindowsUiaValueProvider::QWindowsUiaValueProvider(QAccessible::Id id) :
22 QWindowsUiaBaseProvider(id)
23{
24}
25
26QWindowsUiaValueProvider::~QWindowsUiaValueProvider()
27{
28}
29
30// Sets the value associated with the control.
31HRESULT STDMETHODCALLTYPE QWindowsUiaValueProvider::SetValue(LPCWSTR val)
32{
33 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
34
35 QAccessibleInterface *accessible = accessibleInterface();
36 if (!accessible)
37 return UIA_E_ELEMENTNOTAVAILABLE;
38
39 // First sets the value as a text.
40 QString strVal = QString::fromUtf16(reinterpret_cast<const char16_t *>(val));
41 accessible->setText(QAccessible::Value, strVal);
42
43 // Then, if the control supports the value interface (range value)
44 // and the supplied text can be converted to a number, and that number
45 // lies within the min/max limits, sets it as the control's current (numeric) value.
46 if (QAccessibleValueInterface *valueInterface = accessible->valueInterface()) {
47 bool ok = false;
48 double numval = strVal.toDouble(&ok);
49 if (ok) {
50 double minimum = valueInterface->minimumValue().toDouble();
51 double maximum = valueInterface->maximumValue().toDouble();
52 if ((numval >= minimum) && (numval <= maximum)) {
53 valueInterface->setCurrentValue(QVariant(numval));
54 }
55 }
56 }
57 return S_OK;
58}
59
60// True for read-only controls.
61HRESULT STDMETHODCALLTYPE QWindowsUiaValueProvider::get_IsReadOnly(BOOL *pRetVal)
62{
63 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
64
65 if (!pRetVal)
66 return E_INVALIDARG;
67 *pRetVal = FALSE;
68
69 QAccessibleInterface *accessible = accessibleInterface();
70 if (!accessible)
71 return UIA_E_ELEMENTNOTAVAILABLE;
72
73 *pRetVal = accessible->state().readOnly;
74 return S_OK;
75}
76
77// Returns the value in text form.
78HRESULT STDMETHODCALLTYPE QWindowsUiaValueProvider::get_Value(BSTR *pRetVal)
79{
80 qCDebug(lcQpaUiAutomation) << __FUNCTION__;
81
82 if (!pRetVal)
83 return E_INVALIDARG;
84 *pRetVal = nullptr;
85
86 QAccessibleInterface *accessible = accessibleInterface();
87 if (!accessible)
88 return UIA_E_ELEMENTNOTAVAILABLE;
89
90 *pRetVal = QBStr(accessible->text(QAccessible::Value)).release();
91 return S_OK;
92}
93
94QT_END_NAMESPACE
95
96#endif // QT_CONFIG(accessibility)