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
4#include <QtGui/qtguiglobal.h>
5#if QT_CONFIG(accessibility)
6
7#include "qwindowsuiavalueprovider.h"
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
15QT_BEGIN_NAMESPACE
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 = QBStr(accessible->text(QAccessible::Value)).release();
90 return S_OK;
91}
92
93QT_END_NAMESPACE
94
95#endif // QT_CONFIG(accessibility)