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