Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / winaccessibility / source / UAccCOM / AccValue.cxx
blob8465fb5718f7ccd5e66c44fa0e0bdda92093e9b9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "stdafx.h"
21 #include <UAccCOM.h>
22 #include "AccValue.h"
23 #include "MAccessible.h"
25 #include <vcl/svapp.hxx>
27 #include <com/sun/star/accessibility/XAccessible.hpp>
28 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
30 using namespace com::sun::star::accessibility;
31 using namespace com::sun::star::uno;
33 /**
34 * Get current value.
35 * @param currentValue Variant that accepts current value.
36 * @return Result.
39 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccValue::get_currentValue(VARIANT* currentValue)
41 SolarMutexGuard g;
43 try
45 if (currentValue == nullptr)
46 return E_INVALIDARG;
47 if (!pRXVal.is())
48 return E_FAIL;
50 // Get Any type value from UNO.
51 css::uno::Any anyVal = GetXInterface()->getCurrentValue();
52 // Convert Any to VARIANT.
53 CMAccessible::ConvertAnyToVariant(anyVal, currentValue);
55 return S_OK;
57 catch (...)
59 return E_FAIL;
63 /**
64 * Set current value.
65 * @param Value New value should be set.
66 * @param success If the method is successfully called.
67 * @return Result.
69 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccValue::setCurrentValue(VARIANT value)
71 SolarMutexGuard g;
73 try
75 if (!pRXVal.is())
76 return E_FAIL;
78 HRESULT hRet = S_OK;
79 css::uno::Any anyVal;
81 // Set value according to value type.
82 switch (value.vt)
84 case VT_UI1:
86 anyVal <<= sal_Unicode(value.bVal);
88 break;
90 case VT_BOOL:
92 css::uno::Type typeInfo(TypeClass_BOOLEAN, "bool");
93 anyVal.setValue(&value.boolVal, typeInfo);
95 break;
97 case VT_I2:
99 css::uno::Type typeInfo(TypeClass_SHORT, "short");
100 anyVal.setValue(&value.iVal, typeInfo);
102 break;
104 case VT_I4:
106 css::uno::Type typeInfo(TypeClass_LONG, "long");
107 anyVal.setValue(&value.lVal, typeInfo);
109 break;
111 case VT_R4:
113 css::uno::Type typeInfo(TypeClass_FLOAT, "float");
114 anyVal.setValue(&value.fltVal, typeInfo);
116 break;
118 case VT_R8:
120 css::uno::Type typeInfo(TypeClass_DOUBLE, "double");
121 anyVal.setValue(&value.dblVal, typeInfo);
123 break;
125 default:
127 // Unsupported type conversion.
128 hRet = E_FAIL;
130 break;
133 if (hRet == S_OK)
135 hRet = pRXVal->setCurrentValue(anyVal) ? S_OK : E_FAIL;
138 return hRet;
140 catch (...)
142 return E_FAIL;
147 * Get maximum value.
148 * @param maximumValue Variant that accepts maximum value.
149 * @return Result.
151 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccValue::get_maximumValue(VARIANT* maximumValue)
153 SolarMutexGuard g;
157 if (maximumValue == nullptr)
158 return E_INVALIDARG;
159 if (!pRXVal.is())
160 return E_FAIL;
162 // Get Any type value from UNO.
163 css::uno::Any anyVal = GetXInterface()->getMaximumValue();
164 // Convert Any to VARIANT.
165 CMAccessible::ConvertAnyToVariant(anyVal, maximumValue);
167 return S_OK;
169 catch (...)
171 return E_FAIL;
176 * Get minimum value.
177 * @param minimumValue Variant that accepts minimum value.
178 * @return Result.
180 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccValue::get_minimumValue(VARIANT* minimumValue)
182 SolarMutexGuard g;
186 if (minimumValue == nullptr)
187 return E_FAIL;
188 if (!pRXVal.is())
189 return E_FAIL;
191 // Get Any type value from UNO.
192 css::uno::Any anyVal = GetXInterface()->getMinimumValue();
193 // Convert Any to VARIANT.
194 CMAccessible::ConvertAnyToVariant(anyVal, minimumValue);
196 return S_OK;
198 catch (...)
200 return E_FAIL;
205 * Put valid UNO interface into com class.
206 * @param pXInterface UNO interface.
207 * @return Result.
209 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccValue::put_XInterface(hyper pXInterface)
211 // internal IUNOXWrapper - no mutex meeded
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())
222 return E_FAIL;
224 Reference<XAccessibleValue> pRXI(pRContext, UNO_QUERY);
225 if (!pRXI.is())
226 pRXVal = nullptr;
227 else
228 pRXVal = pRXI.get();
229 return S_OK;
231 catch (...)
233 return E_FAIL;
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */