1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 #include "stdafx.h"
23 #include "UAccCOM2.h"
24 #include "AccValue.h"
25 #include "MAccessible.h"
26 #include <com/sun/star/accessibility/XAccessible.hpp>
27 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
28
29 using namespace com::sun::star::accessibility;
30 using namespace com::sun::star::uno;
31
32 /**
33 * Get current value.
34 * @param currentValue Variant that accepts current value.
35 * @return Result.
36 */
37
get_currentValue(VARIANT * currentValue)38 STDMETHODIMP CAccValue::get_currentValue(VARIANT * currentValue)
39 {
40
41 CHECK_ENABLE_INF
42
43 ENTER_PROTECTED_BLOCK
44
45 if (currentValue == NULL)
46 return E_INVALIDARG;
47 if ( !pRXVal.is() )
48 return E_FAIL;
49
50 // Get Any type value from UNO.
51 ::com::sun::star::uno::Any anyVal = GetXInterface()->getCurrentValue();
52 // Convert Any to VARIANT.
53 CMAccessible::ConvertAnyToVariant(anyVal, currentValue);
54
55 return S_OK;
56
57 LEAVE_PROTECTED_BLOCK
58 }
59
60 /**
61 * Set current value.
62 * @param Value New value should be set.
63 * @param success If the method is successfully called.
64 * @return Result.
65 */
setCurrentValue(VARIANT value)66 STDMETHODIMP CAccValue::setCurrentValue(VARIANT value)
67 {
68
69 CHECK_ENABLE_INF
70
71 ENTER_PROTECTED_BLOCK
72
73 if ( !pRXVal.is() )
74 return E_FAIL;
75
76 HRESULT hRet = S_OK;
77 ::com::sun::star::uno::Any anyVal;
78
79 // Set value according to value type.
80 switch(value.vt)
81 {
82 case VT_UI1:
83 {
84 ::com::sun::star::uno::Type typeInfo(TypeClass_CHAR, (sal_Char *)"char");
85 anyVal.setValue(&value.bVal, typeInfo);
86 }
87 break;
88
89 case VT_BOOL:
90 {
91 ::com::sun::star::uno::Type typeInfo(TypeClass_BOOLEAN, (sal_Char *)"bool");
92 anyVal.setValue(&value.boolVal, typeInfo);
93 }
94 break;
95
96 case VT_I2:
97 {
98 ::com::sun::star::uno::Type typeInfo(TypeClass_SHORT, (sal_Char *)"short");
99 anyVal.setValue(&value.iVal, typeInfo);
100 }
101 break;
102
103 case VT_I4:
104 {
105 ::com::sun::star::uno::Type typeInfo(TypeClass_LONG, (sal_Char *)"long");
106 anyVal.setValue(&value.lVal, typeInfo);
107 }
108 break;
109
110 case VT_R4:
111 {
112 ::com::sun::star::uno::Type typeInfo(TypeClass_FLOAT, (sal_Char *)"float");
113 anyVal.setValue(&value.fltVal, typeInfo);
114 }
115 break;
116
117 case VT_R8:
118 {
119 ::com::sun::star::uno::Type typeInfo(TypeClass_DOUBLE, (sal_Char *)"double");
120 anyVal.setValue(&value.dblVal, typeInfo);
121 }
122 break;
123
124 default:
125 {
126 // Unsupport type conversion.
127 hRet = E_FAIL;
128 }
129 break;
130 }
131
132 if(hRet == S_OK)
133 {
134 hRet = pRXVal->setCurrentValue(anyVal) ? S_OK : E_FAIL ;
135 }
136
137 return hRet;
138
139 LEAVE_PROTECTED_BLOCK
140 }
141
142 /**
143 * Get maximum value.
144 * @param maximumValue Variant that accepts maximum value.
145 * @return Result.
146 */
get_maximumValue(VARIANT * maximumValue)147 STDMETHODIMP CAccValue::get_maximumValue(VARIANT *maximumValue)
148 {
149
150 CHECK_ENABLE_INF
151
152 ENTER_PROTECTED_BLOCK
153
154 if (maximumValue == NULL)
155 return E_INVALIDARG;
156 if ( !pRXVal.is() )
157 return E_FAIL;
158
159 // Get Any type value from UNO.
160 ::com::sun::star::uno::Any anyVal = GetXInterface()->getMaximumValue();
161 // Convert Any to VARIANT.
162 CMAccessible::ConvertAnyToVariant(anyVal, maximumValue);
163
164 return S_OK;
165
166 LEAVE_PROTECTED_BLOCK
167 }
168
169 /**
170 * Get minimum value.
171 * @param mininumValue Variant that accepts minimum value.
172 * @return Result.
173 */
get_minimumValue(VARIANT * mininumValue)174 STDMETHODIMP CAccValue::get_minimumValue(VARIANT *mininumValue)
175 {
176
177 CHECK_ENABLE_INF
178
179 ENTER_PROTECTED_BLOCK
180
181 if (mininumValue == NULL)
182 return E_FAIL;
183 if ( !pRXVal.is() )
184 return E_FAIL;
185
186 // Get Any type value from UNO.
187 ::com::sun::star::uno::Any anyVal = GetXInterface()->getMinimumValue();
188 // Convert Any to VARIANT.
189 CMAccessible::ConvertAnyToVariant(anyVal, mininumValue);
190
191 return S_OK;
192
193 LEAVE_PROTECTED_BLOCK
194 }
195
196 /**
197 * Put valid UNO interface into com class.
198 * @param pXInterface UNO interface.
199 * @return Result.
200 */
put_XInterface(long pXInterface)201 STDMETHODIMP CAccValue::put_XInterface(long pXInterface)
202 {
203
204
205 ENTER_PROTECTED_BLOCK
206
207 CUNOXWrapper::put_XInterface(pXInterface);
208 //special query.
209 if(pUNOInterface == NULL)
210 return E_FAIL;
211 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
212 if( !pRContext.is() )
213 {
214 return E_FAIL;
215 }
216 Reference<XAccessibleValue> pRXI(pRContext,UNO_QUERY);
217 if( !pRXI.is() )
218 pRXVal = NULL;
219 else
220 pRXVal = pRXI.get();
221 return S_OK;
222
223 LEAVE_PROTECTED_BLOCK
224 }
225