1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright IBM Corporation 2010. 6 * Copyright 2000, 2010 Oracle and/or its affiliates. 7 * 8 * OpenOffice.org - a multi-platform office productivity suite 9 * 10 * This file is part of OpenOffice.org. 11 * 12 * OpenOffice.org is free software: you can redistribute it and/or modify 13 * it under the terms of the GNU Lesser General Public License version 3 14 * only, as published by the Free Software Foundation. 15 * 16 * OpenOffice.org is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU Lesser General Public License version 3 for more details 20 * (a copy is included in the LICENSE file that accompanied this code). 21 * 22 * You should have received a copy of the GNU Lesser General Public License 23 * version 3 along with OpenOffice.org. If not, see 24 * <http://www.openoffice.org/license.html> 25 * for a copy of the LGPLv3 License. 26 * 27 ************************************************************************/ 28 29 #include "stdafx.h" 30 #include "UAccCOM2.h" 31 #include "AccValue.h" 32 #include "MAccessible.h" 33 #include <com/sun/star/accessibility/XAccessible.hpp> 34 #include <com/sun/star/accessibility/XAccessibleContext.hpp> 35 36 using namespace com::sun::star::accessibility; 37 using namespace com::sun::star::uno; 38 39 /** 40 * Get current value. 41 * @param currentValue Variant that accepts current value. 42 * @return Result. 43 */ 44 45 STDMETHODIMP CAccValue::get_currentValue(VARIANT * currentValue) 46 { 47 48 CHECK_ENABLE_INF 49 50 ENTER_PROTECTED_BLOCK 51 52 if (currentValue == NULL) 53 return E_INVALIDARG; 54 if ( !pRXVal.is() ) 55 return E_FAIL; 56 57 // Get Any type value from UNO. 58 ::com::sun::star::uno::Any anyVal = GetXInterface()->getCurrentValue(); 59 // Convert Any to VARIANT. 60 CMAccessible::ConvertAnyToVariant(anyVal, currentValue); 61 62 return S_OK; 63 64 LEAVE_PROTECTED_BLOCK 65 } 66 67 /** 68 * Set current value. 69 * @param Value New value should be set. 70 * @param success If the method is successfully called. 71 * @return Result. 72 */ 73 STDMETHODIMP CAccValue::setCurrentValue(VARIANT value) 74 { 75 76 CHECK_ENABLE_INF 77 78 ENTER_PROTECTED_BLOCK 79 80 if ( !pRXVal.is() ) 81 return E_FAIL; 82 83 HRESULT hRet = S_OK; 84 ::com::sun::star::uno::Any anyVal; 85 86 // Set value according to value type. 87 switch(value.vt) 88 { 89 case VT_UI1: 90 { 91 ::com::sun::star::uno::Type typeInfo(TypeClass_CHAR, (sal_Char *)"char"); 92 anyVal.setValue(&value.bVal, typeInfo); 93 } 94 break; 95 96 case VT_BOOL: 97 { 98 ::com::sun::star::uno::Type typeInfo(TypeClass_BOOLEAN, (sal_Char *)"bool"); 99 anyVal.setValue(&value.boolVal, typeInfo); 100 } 101 break; 102 103 case VT_I2: 104 { 105 ::com::sun::star::uno::Type typeInfo(TypeClass_SHORT, (sal_Char *)"short"); 106 anyVal.setValue(&value.iVal, typeInfo); 107 } 108 break; 109 110 case VT_I4: 111 { 112 ::com::sun::star::uno::Type typeInfo(TypeClass_LONG, (sal_Char *)"long"); 113 anyVal.setValue(&value.lVal, typeInfo); 114 } 115 break; 116 117 case VT_R4: 118 { 119 ::com::sun::star::uno::Type typeInfo(TypeClass_FLOAT, (sal_Char *)"float"); 120 anyVal.setValue(&value.fltVal, typeInfo); 121 } 122 break; 123 124 case VT_R8: 125 { 126 ::com::sun::star::uno::Type typeInfo(TypeClass_DOUBLE, (sal_Char *)"double"); 127 anyVal.setValue(&value.dblVal, typeInfo); 128 } 129 break; 130 131 default: 132 { 133 // Unsupport type conversion. 134 hRet = E_FAIL; 135 } 136 break; 137 } 138 139 if(hRet == S_OK) 140 { 141 hRet = pRXVal->setCurrentValue(anyVal) ? S_OK : E_FAIL ; 142 } 143 144 return hRet; 145 146 LEAVE_PROTECTED_BLOCK 147 } 148 149 /** 150 * Get maximum value. 151 * @param maximumValue Variant that accepts maximum value. 152 * @return Result. 153 */ 154 STDMETHODIMP CAccValue::get_maximumValue(VARIANT *maximumValue) 155 { 156 157 CHECK_ENABLE_INF 158 159 ENTER_PROTECTED_BLOCK 160 161 if (maximumValue == NULL) 162 return E_INVALIDARG; 163 if ( !pRXVal.is() ) 164 return E_FAIL; 165 166 // Get Any type value from UNO. 167 ::com::sun::star::uno::Any anyVal = GetXInterface()->getMaximumValue(); 168 // Convert Any to VARIANT. 169 CMAccessible::ConvertAnyToVariant(anyVal, maximumValue); 170 171 return S_OK; 172 173 LEAVE_PROTECTED_BLOCK 174 } 175 176 /** 177 * Get minimum value. 178 * @param mininumValue Variant that accepts minimum value. 179 * @return Result. 180 */ 181 STDMETHODIMP CAccValue::get_minimumValue(VARIANT *mininumValue) 182 { 183 184 CHECK_ENABLE_INF 185 186 ENTER_PROTECTED_BLOCK 187 188 if (mininumValue == NULL) 189 return E_FAIL; 190 if ( !pRXVal.is() ) 191 return E_FAIL; 192 193 // Get Any type value from UNO. 194 ::com::sun::star::uno::Any anyVal = GetXInterface()->getMinimumValue(); 195 // Convert Any to VARIANT. 196 CMAccessible::ConvertAnyToVariant(anyVal, mininumValue); 197 198 return S_OK; 199 200 LEAVE_PROTECTED_BLOCK 201 } 202 203 /** 204 * Put valid UNO interface into com class. 205 * @param pXInterface UNO interface. 206 * @return Result. 207 */ 208 STDMETHODIMP CAccValue::put_XInterface(long pXInterface) 209 { 210 211 212 ENTER_PROTECTED_BLOCK 213 214 CUNOXWrapper::put_XInterface(pXInterface); 215 //special query. 216 if(pUNOInterface == NULL) 217 return E_FAIL; 218 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext(); 219 if( !pRContext.is() ) 220 { 221 return E_FAIL; 222 } 223 Reference<XAccessibleValue> pRXI(pRContext,UNO_QUERY); 224 if( !pRXI.is() ) 225 pRXVal = NULL; 226 else 227 pRXVal = pRXI.get(); 228 return S_OK; 229 230 LEAVE_PROTECTED_BLOCK 231 } 232