1 /****************************************************************************
2 **
3 ** Copyright (C) 2017 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #include <QtGui/qtguiglobal.h>
41 #if QT_CONFIG(accessibility)
42 
43 #include "qwindowsuiarangevalueprovider.h"
44 #include "qwindowsuiautils.h"
45 #include "qwindowscontext.h"
46 
47 #include <QtGui/qaccessible.h>
48 #include <QtCore/qloggingcategory.h>
49 #include <QtCore/qstring.h>
50 
51 QT_BEGIN_NAMESPACE
52 
53 using namespace QWindowsUiAutomation;
54 
55 
QWindowsUiaRangeValueProvider(QAccessible::Id id)56 QWindowsUiaRangeValueProvider::QWindowsUiaRangeValueProvider(QAccessible::Id id) :
57     QWindowsUiaBaseProvider(id)
58 {
59 }
60 
~QWindowsUiaRangeValueProvider()61 QWindowsUiaRangeValueProvider::~QWindowsUiaRangeValueProvider()
62 {
63 }
64 
SetValue(double val)65 HRESULT STDMETHODCALLTYPE QWindowsUiaRangeValueProvider::SetValue(double val)
66 {
67     qCDebug(lcQpaUiAutomation) << __FUNCTION__;
68 
69     QAccessibleInterface *accessible = accessibleInterface();
70     if (!accessible)
71         return UIA_E_ELEMENTNOTAVAILABLE;
72 
73     QAccessibleValueInterface *valueInterface = accessible->valueInterface();
74     if (!valueInterface)
75         return UIA_E_ELEMENTNOTAVAILABLE;
76 
77     double minimum = valueInterface->minimumValue().toDouble();
78     double maximum = valueInterface->maximumValue().toDouble();
79     if ((val < minimum) || (val > maximum))
80         return E_INVALIDARG;
81 
82     valueInterface->setCurrentValue(QVariant(val));
83     return S_OK;
84 }
85 
get_Value(double * pRetVal)86 HRESULT STDMETHODCALLTYPE QWindowsUiaRangeValueProvider::get_Value(double *pRetVal)
87 {
88     qCDebug(lcQpaUiAutomation) << __FUNCTION__;
89 
90     if (!pRetVal)
91         return E_INVALIDARG;
92 
93     QAccessibleInterface *accessible = accessibleInterface();
94     if (!accessible)
95         return UIA_E_ELEMENTNOTAVAILABLE;
96 
97     QAccessibleValueInterface *valueInterface = accessible->valueInterface();
98     if (!valueInterface)
99         return UIA_E_ELEMENTNOTAVAILABLE;
100 
101     QVariant varValue = valueInterface->currentValue();
102     *pRetVal = varValue.toDouble();
103     return S_OK;
104 }
105 
get_IsReadOnly(BOOL * pRetVal)106 HRESULT STDMETHODCALLTYPE QWindowsUiaRangeValueProvider::get_IsReadOnly(BOOL *pRetVal)
107 {
108     qCDebug(lcQpaUiAutomation) << __FUNCTION__;
109 
110     if (!pRetVal)
111         return E_INVALIDARG;
112 
113     QAccessibleInterface *accessible = accessibleInterface();
114     if (!accessible)
115         return UIA_E_ELEMENTNOTAVAILABLE;
116 
117     *pRetVal = accessible->state().readOnly;
118     return S_OK;
119 }
120 
get_Maximum(double * pRetVal)121 HRESULT STDMETHODCALLTYPE QWindowsUiaRangeValueProvider::get_Maximum(double *pRetVal)
122 {
123     qCDebug(lcQpaUiAutomation) << __FUNCTION__;
124 
125     if (!pRetVal)
126         return E_INVALIDARG;
127 
128     QAccessibleInterface *accessible = accessibleInterface();
129     if (!accessible)
130         return UIA_E_ELEMENTNOTAVAILABLE;
131 
132     QAccessibleValueInterface *valueInterface = accessible->valueInterface();
133     if (!valueInterface)
134         return UIA_E_ELEMENTNOTAVAILABLE;
135 
136     QVariant varValue = valueInterface->maximumValue();
137     *pRetVal = varValue.toDouble();
138     return S_OK;
139 }
140 
get_Minimum(double * pRetVal)141 HRESULT STDMETHODCALLTYPE QWindowsUiaRangeValueProvider::get_Minimum(double *pRetVal)
142 {
143     qCDebug(lcQpaUiAutomation) << __FUNCTION__;
144 
145     if (!pRetVal)
146         return E_INVALIDARG;
147 
148     QAccessibleInterface *accessible = accessibleInterface();
149     if (!accessible)
150         return UIA_E_ELEMENTNOTAVAILABLE;
151 
152     QAccessibleValueInterface *valueInterface = accessible->valueInterface();
153     if (!valueInterface)
154         return UIA_E_ELEMENTNOTAVAILABLE;
155 
156     QVariant varValue = valueInterface->minimumValue();
157     *pRetVal = varValue.toDouble();
158     return S_OK;
159 }
160 
get_LargeChange(double * pRetVal)161 HRESULT STDMETHODCALLTYPE QWindowsUiaRangeValueProvider::get_LargeChange(double *pRetVal)
162 {
163     qCDebug(lcQpaUiAutomation) << __FUNCTION__;
164     return get_SmallChange(pRetVal);
165 }
166 
get_SmallChange(double * pRetVal)167 HRESULT STDMETHODCALLTYPE QWindowsUiaRangeValueProvider::get_SmallChange(double *pRetVal)
168 {
169     qCDebug(lcQpaUiAutomation) << __FUNCTION__;
170 
171     if (!pRetVal)
172         return E_INVALIDARG;
173 
174     QAccessibleInterface *accessible = accessibleInterface();
175     if (!accessible)
176         return UIA_E_ELEMENTNOTAVAILABLE;
177 
178     QAccessibleValueInterface *valueInterface = accessible->valueInterface();
179     if (!valueInterface)
180         return UIA_E_ELEMENTNOTAVAILABLE;
181 
182     QVariant varValue = valueInterface->minimumStepSize();
183     *pRetVal = varValue.toDouble();
184     return S_OK;
185 }
186 
187 QT_END_NAMESPACE
188 
189 #endif // QT_CONFIG(accessibility)
190