Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / winaccessibility / source / UAccCOM / AccValue.cxx
blobb0b24650aa06e79be605f5eefaad640fc560bc2d
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 "AccValue.h"
22 #include "MAccessible.h"
24 #if defined __clang__
25 #pragma clang diagnostic push
26 #pragma clang diagnostic ignored "-Wnon-virtual-dtor"
27 #endif
28 #include <UAccCOM.h>
29 #if defined __clang__
30 #pragma clang diagnostic pop
31 #endif
33 #include <vcl/svapp.hxx>
35 #include <com/sun/star/accessibility/XAccessible.hpp>
36 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
38 using namespace com::sun::star::accessibility;
39 using namespace com::sun::star::uno;
41 /**
42 * Get current value.
43 * @param currentValue Variant that accepts current value.
44 * @return Result.
47 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccValue::get_currentValue(VARIANT * currentValue)
49 SolarMutexGuard g;
51 ENTER_PROTECTED_BLOCK
53 if (currentValue == nullptr)
54 return E_INVALIDARG;
55 if ( !pRXVal.is() )
56 return E_FAIL;
58 // Get Any type value from UNO.
59 css::uno::Any anyVal = GetXInterface()->getCurrentValue();
60 // Convert Any to VARIANT.
61 CMAccessible::ConvertAnyToVariant(anyVal, currentValue);
63 return S_OK;
65 LEAVE_PROTECTED_BLOCK
68 /**
69 * Set current value.
70 * @param Value New value should be set.
71 * @param success If the method is successfully called.
72 * @return Result.
74 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccValue::setCurrentValue(VARIANT value)
76 SolarMutexGuard g;
78 ENTER_PROTECTED_BLOCK
80 if ( !pRXVal.is() )
81 return E_FAIL;
83 HRESULT hRet = S_OK;
84 css::uno::Any anyVal;
86 // Set value according to value type.
87 switch(value.vt)
89 case VT_UI1:
91 anyVal <<= sal_Unicode(value.bVal);
93 break;
95 case VT_BOOL:
97 css::uno::Type typeInfo(TypeClass_BOOLEAN, "bool");
98 anyVal.setValue(&value.boolVal, typeInfo);
100 break;
102 case VT_I2:
104 css::uno::Type typeInfo(TypeClass_SHORT, "short");
105 anyVal.setValue(&value.iVal, typeInfo);
107 break;
109 case VT_I4:
111 css::uno::Type typeInfo(TypeClass_LONG, "long");
112 anyVal.setValue(&value.lVal, typeInfo);
114 break;
116 case VT_R4:
118 css::uno::Type typeInfo(TypeClass_FLOAT, "float");
119 anyVal.setValue(&value.fltVal, typeInfo);
121 break;
123 case VT_R8:
125 css::uno::Type typeInfo(TypeClass_DOUBLE, "double");
126 anyVal.setValue(&value.dblVal, typeInfo);
128 break;
130 default:
132 // Unsupported type conversion.
133 hRet = E_FAIL;
135 break;
138 if(hRet == S_OK)
140 hRet = pRXVal->setCurrentValue(anyVal) ? S_OK : E_FAIL ;
143 return hRet;
145 LEAVE_PROTECTED_BLOCK
149 * Get maximum value.
150 * @param maximumValue Variant that accepts maximum value.
151 * @return Result.
153 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccValue::get_maximumValue(VARIANT *maximumValue)
155 SolarMutexGuard g;
157 ENTER_PROTECTED_BLOCK
159 if (maximumValue == nullptr)
160 return E_INVALIDARG;
161 if ( !pRXVal.is() )
162 return E_FAIL;
164 // Get Any type value from UNO.
165 css::uno::Any anyVal = GetXInterface()->getMaximumValue();
166 // Convert Any to VARIANT.
167 CMAccessible::ConvertAnyToVariant(anyVal, maximumValue);
169 return S_OK;
171 LEAVE_PROTECTED_BLOCK
175 * Get minimum value.
176 * @param mininumValue Variant that accepts minimum value.
177 * @return Result.
179 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccValue::get_minimumValue(VARIANT *mininumValue)
181 SolarMutexGuard g;
183 ENTER_PROTECTED_BLOCK
185 if (mininumValue == nullptr)
186 return E_FAIL;
187 if ( !pRXVal.is() )
188 return E_FAIL;
190 // Get Any type value from UNO.
191 css::uno::Any anyVal = GetXInterface()->getMinimumValue();
192 // Convert Any to VARIANT.
193 CMAccessible::ConvertAnyToVariant(anyVal, mininumValue);
195 return S_OK;
197 LEAVE_PROTECTED_BLOCK
201 * Put valid UNO interface into com class.
202 * @param pXInterface UNO interface.
203 * @return Result.
205 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccValue::put_XInterface(hyper pXInterface)
207 // internal IUNOXWrapper - no mutex meeded
209 ENTER_PROTECTED_BLOCK
211 CUNOXWrapper::put_XInterface(pXInterface);
212 //special query.
213 if(pUNOInterface == nullptr)
214 return E_FAIL;
215 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
216 if( !pRContext.is() )
218 return E_FAIL;
220 Reference<XAccessibleValue> pRXI(pRContext,UNO_QUERY);
221 if( !pRXI.is() )
222 pRXVal = nullptr;
223 else
224 pRXVal = pRXI.get();
225 return S_OK;
227 LEAVE_PROTECTED_BLOCK
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */