1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sc.hxx" 30 31 32 33 #include <svl/itemprop.hxx> 34 35 #include <com/sun/star/util/Date.hpp> 36 37 #include "optuno.hxx" 38 #include "miscuno.hxx" 39 #include "unonames.hxx" 40 #include "docoptio.hxx" 41 #include "unoguard.hxx" 42 43 using namespace com::sun::star; 44 45 //------------------------------------------------------------------------ 46 // static 47 const SfxItemPropertyMapEntry* ScDocOptionsHelper::GetPropertyMap() 48 { 49 static SfxItemPropertyMapEntry aMap[] = 50 { 51 {MAP_CHAR_LEN(SC_UNO_CALCASSHOWN), PROP_UNO_CALCASSHOWN , &getBooleanCppuType(), 0, 0}, 52 {MAP_CHAR_LEN(SC_UNO_DEFTABSTOP), PROP_UNO_DEFTABSTOP , &getCppuType((sal_Int16*)0), 0, 0}, 53 {MAP_CHAR_LEN(SC_UNO_IGNORECASE), PROP_UNO_IGNORECASE , &getBooleanCppuType(), 0, 0}, 54 {MAP_CHAR_LEN(SC_UNO_ITERENABLED), PROP_UNO_ITERENABLED , &getBooleanCppuType(), 0, 0}, 55 {MAP_CHAR_LEN(SC_UNO_ITERCOUNT), PROP_UNO_ITERCOUNT , &getCppuType((sal_Int32*)0), 0, 0}, 56 {MAP_CHAR_LEN(SC_UNO_ITEREPSILON), PROP_UNO_ITEREPSILON , &getCppuType((double*)0), 0, 0}, 57 {MAP_CHAR_LEN(SC_UNO_LOOKUPLABELS), PROP_UNO_LOOKUPLABELS, &getBooleanCppuType(), 0, 0}, 58 {MAP_CHAR_LEN(SC_UNO_MATCHWHOLE), PROP_UNO_MATCHWHOLE , &getBooleanCppuType(), 0, 0}, 59 {MAP_CHAR_LEN(SC_UNO_NULLDATE), PROP_UNO_NULLDATE , &getCppuType((util::Date*)0), 0, 0}, 60 {MAP_CHAR_LEN(SC_UNO_SPELLONLINE), PROP_UNO_SPELLONLINE , &getBooleanCppuType(), 0, 0}, 61 {MAP_CHAR_LEN(SC_UNO_STANDARDDEC), PROP_UNO_STANDARDDEC , &getCppuType((sal_Int16*)0), 0, 0}, 62 {MAP_CHAR_LEN(SC_UNO_REGEXENABLED), PROP_UNO_REGEXENABLED, &getBooleanCppuType(), 0, 0}, 63 {0,0,0,0,0,0} 64 }; 65 return aMap; 66 } 67 68 // static 69 sal_Bool ScDocOptionsHelper::setPropertyValue( ScDocOptions& rOptions, 70 const SfxItemPropertyMap& rPropMap, 71 const rtl::OUString& aPropertyName, const uno::Any& aValue ) 72 { 73 //! use map (with new identifiers) 74 75 const SfxItemPropertySimpleEntry* pEntry = rPropMap.getByName(aPropertyName ); 76 if( !pEntry || !pEntry->nWID ) 77 return sal_False; 78 switch( pEntry->nWID ) 79 { 80 case PROP_UNO_CALCASSHOWN : 81 rOptions.SetCalcAsShown( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); 82 break; 83 case PROP_UNO_DEFTABSTOP : 84 { 85 sal_Int16 nIntVal = 0; 86 if ( aValue >>= nIntVal ) 87 rOptions.SetTabDistance( nIntVal ); 88 } 89 break; 90 case PROP_UNO_IGNORECASE : 91 rOptions.SetIgnoreCase( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); 92 break; 93 case PROP_UNO_ITERENABLED: 94 rOptions.SetIter( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); 95 break; 96 case PROP_UNO_ITERCOUNT : 97 { 98 sal_Int32 nIntVal = 0; 99 if ( aValue >>= nIntVal ) 100 rOptions.SetIterCount( (sal_uInt16)nIntVal ); 101 } 102 break; 103 case PROP_UNO_ITEREPSILON : 104 { 105 double fDoubleVal = 0; 106 if ( aValue >>= fDoubleVal ) 107 rOptions.SetIterEps( fDoubleVal ); 108 } 109 break; 110 case PROP_UNO_LOOKUPLABELS : 111 rOptions.SetLookUpColRowNames( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); 112 break; 113 case PROP_UNO_MATCHWHOLE : 114 rOptions.SetMatchWholeCell( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); 115 break; 116 case PROP_UNO_NULLDATE: 117 { 118 util::Date aDate; 119 if ( aValue >>= aDate ) 120 rOptions.SetDate( aDate.Day, aDate.Month, aDate.Year ); 121 } 122 break; 123 case PROP_UNO_SPELLONLINE: 124 rOptions.SetAutoSpell( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); 125 break; 126 case PROP_UNO_STANDARDDEC: 127 { 128 sal_Int16 nIntVal = 0; 129 if ( aValue >>= nIntVal ) 130 rOptions.SetStdPrecision( nIntVal ); 131 } 132 break; 133 case PROP_UNO_REGEXENABLED: 134 rOptions.SetFormulaRegexEnabled( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); 135 break; 136 default:; 137 } 138 return sal_True; 139 } 140 141 // static 142 uno::Any ScDocOptionsHelper::getPropertyValue( 143 const ScDocOptions& rOptions, 144 const SfxItemPropertyMap& rPropMap, 145 const rtl::OUString& aPropertyName ) 146 { 147 uno::Any aRet; 148 const SfxItemPropertySimpleEntry* pEntry = rPropMap.getByName( aPropertyName ); 149 if( !pEntry || !pEntry->nWID ) 150 return aRet; 151 switch( pEntry->nWID ) 152 { 153 case PROP_UNO_CALCASSHOWN : 154 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsCalcAsShown() ); 155 break; 156 case PROP_UNO_DEFTABSTOP : 157 aRet <<= (sal_Int16)( rOptions.GetTabDistance() ); 158 break; 159 case PROP_UNO_IGNORECASE : 160 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsIgnoreCase() ); 161 break; 162 case PROP_UNO_ITERENABLED: 163 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsIter() ); 164 break; 165 case PROP_UNO_ITERCOUNT: 166 aRet <<= (sal_Int32)( rOptions.GetIterCount() ); 167 break; 168 case PROP_UNO_ITEREPSILON: 169 aRet <<= (double)( rOptions.GetIterEps() ); 170 break; 171 case PROP_UNO_LOOKUPLABELS: 172 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsLookUpColRowNames() ); 173 break; 174 case PROP_UNO_MATCHWHOLE: 175 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsMatchWholeCell() ); 176 break; 177 case PROP_UNO_NULLDATE: 178 { 179 sal_uInt16 nD, nM, nY; 180 rOptions.GetDate( nD, nM, nY ); 181 util::Date aDate( nD, nM, nY ); 182 aRet <<= aDate; 183 } 184 break; 185 case PROP_UNO_SPELLONLINE: 186 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsAutoSpell() ); 187 break; 188 case PROP_UNO_STANDARDDEC : 189 aRet <<= (sal_Int16)( rOptions.GetStdPrecision() ); 190 break; 191 case PROP_UNO_REGEXENABLED: 192 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsFormulaRegexEnabled() ); 193 break; 194 default:; 195 } 196 return aRet; 197 } 198 199 //------------------------------------------------------------------------ 200 201 ScDocOptionsObj::ScDocOptionsObj( const ScDocOptions& rOpt ) : 202 ScModelObj( NULL ), 203 aOptions( rOpt ) 204 { 205 } 206 207 ScDocOptionsObj::~ScDocOptionsObj() 208 { 209 } 210 211 void SAL_CALL ScDocOptionsObj::setPropertyValue( 212 const rtl::OUString& aPropertyName, const uno::Any& aValue ) 213 throw(beans::UnknownPropertyException, beans::PropertyVetoException, 214 lang::IllegalArgumentException, lang::WrappedTargetException, 215 uno::RuntimeException) 216 { 217 ScUnoGuard aGuard; 218 219 sal_Bool bDone = ScDocOptionsHelper::setPropertyValue( aOptions, *GetPropertySet().getPropertyMap(), aPropertyName, aValue ); 220 221 if (!bDone) 222 ScModelObj::setPropertyValue( aPropertyName, aValue ); 223 } 224 225 uno::Any SAL_CALL ScDocOptionsObj::getPropertyValue( const rtl::OUString& aPropertyName ) 226 throw(beans::UnknownPropertyException, lang::WrappedTargetException, 227 uno::RuntimeException) 228 { 229 ScUnoGuard aGuard; 230 231 uno::Any aRet(ScDocOptionsHelper::getPropertyValue( aOptions, *GetPropertySet().getPropertyMap(), aPropertyName )); 232 if ( !aRet.hasValue() ) 233 aRet = ScModelObj::getPropertyValue( aPropertyName ); 234 235 return aRet; 236 } 237 238