LibreOffice Module winaccessibility (master) 1
AccValue.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include "stdafx.h"
21#include <UAccCOM.h>
22#include "AccValue.h"
23#include "MAccessible.h"
24
25#include <vcl/svapp.hxx>
26
27#include <com/sun/star/accessibility/XAccessible.hpp>
28#include <com/sun/star/accessibility/XAccessibleContext.hpp>
29
30using namespace com::sun::star::accessibility;
31using namespace com::sun::star::uno;
32
39COM_DECLSPEC_NOTHROW STDMETHODIMP CAccValue::get_currentValue(VARIANT* currentValue)
40{
42
43 try
44 {
45 if (currentValue == nullptr)
46 return E_INVALIDARG;
47 if (!pRXVal.is())
48 return E_FAIL;
49
50 // Get Any type value from UNO.
51 css::uno::Any anyVal = GetXInterface()->getCurrentValue();
52 // Convert Any to VARIANT.
54
55 return S_OK;
56 }
57 catch (...)
58 {
59 return E_FAIL;
60 }
61}
62
69COM_DECLSPEC_NOTHROW STDMETHODIMP CAccValue::setCurrentValue(VARIANT value)
70{
72
73 try
74 {
75 if (!pRXVal.is())
76 return E_FAIL;
77
78 HRESULT hRet = S_OK;
79 css::uno::Any anyVal;
80
81 // Set value according to value type.
82 switch (value.vt)
83 {
84 case VT_UI1:
85 {
86 anyVal <<= sal_Unicode(value.bVal);
87 }
88 break;
89
90 case VT_BOOL:
91 {
92 css::uno::Type typeInfo(TypeClass_BOOLEAN, "bool");
93 anyVal.setValue(&value.boolVal, typeInfo);
94 }
95 break;
96
97 case VT_I2:
98 {
99 css::uno::Type typeInfo(TypeClass_SHORT, "short");
100 anyVal.setValue(&value.iVal, typeInfo);
101 }
102 break;
103
104 case VT_I4:
105 {
106 css::uno::Type typeInfo(TypeClass_LONG, "long");
107 anyVal.setValue(&value.lVal, typeInfo);
108 }
109 break;
110
111 case VT_R4:
112 {
113 css::uno::Type typeInfo(TypeClass_FLOAT, "float");
114 anyVal.setValue(&value.fltVal, typeInfo);
115 }
116 break;
117
118 case VT_R8:
119 {
120 css::uno::Type typeInfo(TypeClass_DOUBLE, "double");
121 anyVal.setValue(&value.dblVal, typeInfo);
122 }
123 break;
124
125 default:
126 {
127 // Unsupported type conversion.
128 hRet = E_FAIL;
129 }
130 break;
131 }
132
133 if (hRet == S_OK)
134 {
135 hRet = pRXVal->setCurrentValue(anyVal) ? S_OK : E_FAIL;
136 }
137
138 return hRet;
139 }
140 catch (...)
141 {
142 return E_FAIL;
143 }
144}
145
151COM_DECLSPEC_NOTHROW STDMETHODIMP CAccValue::get_maximumValue(VARIANT* maximumValue)
152{
154
155 try
156 {
157 if (maximumValue == nullptr)
158 return E_INVALIDARG;
159 if (!pRXVal.is())
160 return E_FAIL;
161
162 // Get Any type value from UNO.
163 css::uno::Any anyVal = GetXInterface()->getMaximumValue();
164 // Convert Any to VARIANT.
166
167 return S_OK;
168 }
169 catch (...)
170 {
171 return E_FAIL;
172 }
173}
174
180COM_DECLSPEC_NOTHROW STDMETHODIMP CAccValue::get_minimumValue(VARIANT* minimumValue)
181{
183
184 try
185 {
186 if (minimumValue == nullptr)
187 return E_FAIL;
188 if (!pRXVal.is())
189 return E_FAIL;
190
191 // Get Any type value from UNO.
192 css::uno::Any anyVal = GetXInterface()->getMinimumValue();
193 // Convert Any to VARIANT.
195
196 return S_OK;
197 }
198 catch (...)
199 {
200 return E_FAIL;
201 }
202}
203
209COM_DECLSPEC_NOTHROW STDMETHODIMP CAccValue::put_XInterface(hyper pXInterface)
210{
211 // internal IUNOXWrapper - no mutex meeded
212
213 try
214 {
215 CUNOXWrapper::put_XInterface(pXInterface);
216 //special query.
217 if (pUNOInterface == nullptr)
218 return E_FAIL;
219 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
220 if (!pRContext.is())
221 {
222 return E_FAIL;
223 }
224 Reference<XAccessibleValue> pRXI(pRContext, UNO_QUERY);
225 if (!pRXI.is())
226 pRXVal = nullptr;
227 else
228 pRXVal = pRXI.get();
229 return S_OK;
230 }
231 catch (...)
232 {
233 return E_FAIL;
234 }
235}
236
237/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
STDMETHOD() setCurrentValue(VARIANT value) override
Set current value.
Definition: AccValue.cxx:69
STDMETHOD() get_maximumValue(VARIANT *maximumValue) override
Get maximum value.
Definition: AccValue.cxx:151
STDMETHOD() get_minimumValue(VARIANT *minimumValue) override
Get minimum value.
Definition: AccValue.cxx:180
STDMETHOD() get_currentValue(VARIANT *currentValue) override
Get current value.
Definition: AccValue.cxx:39
STDMETHOD() put_XInterface(hyper pXInterface) override
Put valid UNO interface into com class.
Definition: AccValue.cxx:209
css::accessibility::XAccessibleValue * GetXInterface()
Definition: AccValue.h:95
css::uno::Reference< css::accessibility::XAccessibleValue > pRXVal
Definition: AccValue.h:93
static void ConvertAnyToVariant(const css::uno::Any &rAnyVal, VARIANT *pvData)
STDMETHOD() put_XInterface(hyper pXInterface) override
Definition: UNOXWrapper.cxx:27
css::accessibility::XAccessible * pUNOInterface
Definition: UNOXWrapper.h:34
Any value
VARIANT maximumValue
Returns the maximal value that can be represented by this object.
VARIANT minimumValue
Returns the minimal value that can be represented by this object.
VARIANT currentValue
Returns the value of this object as a number.
#define VT_R4
#define VT_R8
#define VT_BOOL
#define VT_I4
#define VT_UI1
#define VT_I2
sal_uInt16 sal_Unicode