1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b3f79822SAndrew Rist * distributed with this work for additional information
6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10*b3f79822SAndrew Rist *
11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist *
13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17*b3f79822SAndrew Rist * specific language governing permissions and limitations
18*b3f79822SAndrew Rist * under the License.
19*b3f79822SAndrew Rist *
20*b3f79822SAndrew Rist *************************************************************/
21*b3f79822SAndrew Rist
22*b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <svl/itemprop.hxx>
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <com/sun/star/util/Date.hpp>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include "optuno.hxx"
34cdf0e10cSrcweir #include "miscuno.hxx"
35cdf0e10cSrcweir #include "unonames.hxx"
36cdf0e10cSrcweir #include "docoptio.hxx"
37cdf0e10cSrcweir #include "unoguard.hxx"
38cdf0e10cSrcweir
39cdf0e10cSrcweir using namespace com::sun::star;
40cdf0e10cSrcweir
41cdf0e10cSrcweir //------------------------------------------------------------------------
42cdf0e10cSrcweir // static
GetPropertyMap()43cdf0e10cSrcweir const SfxItemPropertyMapEntry* ScDocOptionsHelper::GetPropertyMap()
44cdf0e10cSrcweir {
45cdf0e10cSrcweir static SfxItemPropertyMapEntry aMap[] =
46cdf0e10cSrcweir {
47cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_CALCASSHOWN), PROP_UNO_CALCASSHOWN , &getBooleanCppuType(), 0, 0},
48cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_DEFTABSTOP), PROP_UNO_DEFTABSTOP , &getCppuType((sal_Int16*)0), 0, 0},
49cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_IGNORECASE), PROP_UNO_IGNORECASE , &getBooleanCppuType(), 0, 0},
50cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_ITERENABLED), PROP_UNO_ITERENABLED , &getBooleanCppuType(), 0, 0},
51cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_ITERCOUNT), PROP_UNO_ITERCOUNT , &getCppuType((sal_Int32*)0), 0, 0},
52cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_ITEREPSILON), PROP_UNO_ITEREPSILON , &getCppuType((double*)0), 0, 0},
53cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_LOOKUPLABELS), PROP_UNO_LOOKUPLABELS, &getBooleanCppuType(), 0, 0},
54cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_MATCHWHOLE), PROP_UNO_MATCHWHOLE , &getBooleanCppuType(), 0, 0},
55cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_NULLDATE), PROP_UNO_NULLDATE , &getCppuType((util::Date*)0), 0, 0},
56cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_SPELLONLINE), PROP_UNO_SPELLONLINE , &getBooleanCppuType(), 0, 0},
57cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_STANDARDDEC), PROP_UNO_STANDARDDEC , &getCppuType((sal_Int16*)0), 0, 0},
58cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_REGEXENABLED), PROP_UNO_REGEXENABLED, &getBooleanCppuType(), 0, 0},
59cdf0e10cSrcweir {0,0,0,0,0,0}
60cdf0e10cSrcweir };
61cdf0e10cSrcweir return aMap;
62cdf0e10cSrcweir }
63cdf0e10cSrcweir
64cdf0e10cSrcweir // static
setPropertyValue(ScDocOptions & rOptions,const SfxItemPropertyMap & rPropMap,const rtl::OUString & aPropertyName,const uno::Any & aValue)65cdf0e10cSrcweir sal_Bool ScDocOptionsHelper::setPropertyValue( ScDocOptions& rOptions,
66cdf0e10cSrcweir const SfxItemPropertyMap& rPropMap,
67cdf0e10cSrcweir const rtl::OUString& aPropertyName, const uno::Any& aValue )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir //! use map (with new identifiers)
70cdf0e10cSrcweir
71cdf0e10cSrcweir const SfxItemPropertySimpleEntry* pEntry = rPropMap.getByName(aPropertyName );
72cdf0e10cSrcweir if( !pEntry || !pEntry->nWID )
73cdf0e10cSrcweir return sal_False;
74cdf0e10cSrcweir switch( pEntry->nWID )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir case PROP_UNO_CALCASSHOWN :
77cdf0e10cSrcweir rOptions.SetCalcAsShown( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
78cdf0e10cSrcweir break;
79cdf0e10cSrcweir case PROP_UNO_DEFTABSTOP :
80cdf0e10cSrcweir {
81cdf0e10cSrcweir sal_Int16 nIntVal = 0;
82cdf0e10cSrcweir if ( aValue >>= nIntVal )
83cdf0e10cSrcweir rOptions.SetTabDistance( nIntVal );
84cdf0e10cSrcweir }
85cdf0e10cSrcweir break;
86cdf0e10cSrcweir case PROP_UNO_IGNORECASE :
87cdf0e10cSrcweir rOptions.SetIgnoreCase( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
88cdf0e10cSrcweir break;
89cdf0e10cSrcweir case PROP_UNO_ITERENABLED:
90cdf0e10cSrcweir rOptions.SetIter( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
91cdf0e10cSrcweir break;
92cdf0e10cSrcweir case PROP_UNO_ITERCOUNT :
93cdf0e10cSrcweir {
94cdf0e10cSrcweir sal_Int32 nIntVal = 0;
95cdf0e10cSrcweir if ( aValue >>= nIntVal )
96cdf0e10cSrcweir rOptions.SetIterCount( (sal_uInt16)nIntVal );
97cdf0e10cSrcweir }
98cdf0e10cSrcweir break;
99cdf0e10cSrcweir case PROP_UNO_ITEREPSILON :
100cdf0e10cSrcweir {
101cdf0e10cSrcweir double fDoubleVal = 0;
102cdf0e10cSrcweir if ( aValue >>= fDoubleVal )
103cdf0e10cSrcweir rOptions.SetIterEps( fDoubleVal );
104cdf0e10cSrcweir }
105cdf0e10cSrcweir break;
106cdf0e10cSrcweir case PROP_UNO_LOOKUPLABELS :
107cdf0e10cSrcweir rOptions.SetLookUpColRowNames( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
108cdf0e10cSrcweir break;
109cdf0e10cSrcweir case PROP_UNO_MATCHWHOLE :
110cdf0e10cSrcweir rOptions.SetMatchWholeCell( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
111cdf0e10cSrcweir break;
112cdf0e10cSrcweir case PROP_UNO_NULLDATE:
113cdf0e10cSrcweir {
114cdf0e10cSrcweir util::Date aDate;
115cdf0e10cSrcweir if ( aValue >>= aDate )
116cdf0e10cSrcweir rOptions.SetDate( aDate.Day, aDate.Month, aDate.Year );
117cdf0e10cSrcweir }
118cdf0e10cSrcweir break;
119cdf0e10cSrcweir case PROP_UNO_SPELLONLINE:
120cdf0e10cSrcweir rOptions.SetAutoSpell( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
121cdf0e10cSrcweir break;
122cdf0e10cSrcweir case PROP_UNO_STANDARDDEC:
123cdf0e10cSrcweir {
124cdf0e10cSrcweir sal_Int16 nIntVal = 0;
125cdf0e10cSrcweir if ( aValue >>= nIntVal )
126cdf0e10cSrcweir rOptions.SetStdPrecision( nIntVal );
127cdf0e10cSrcweir }
128cdf0e10cSrcweir break;
129cdf0e10cSrcweir case PROP_UNO_REGEXENABLED:
130cdf0e10cSrcweir rOptions.SetFormulaRegexEnabled( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
131cdf0e10cSrcweir break;
132cdf0e10cSrcweir default:;
133cdf0e10cSrcweir }
134cdf0e10cSrcweir return sal_True;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir
137cdf0e10cSrcweir // static
getPropertyValue(const ScDocOptions & rOptions,const SfxItemPropertyMap & rPropMap,const rtl::OUString & aPropertyName)138cdf0e10cSrcweir uno::Any ScDocOptionsHelper::getPropertyValue(
139cdf0e10cSrcweir const ScDocOptions& rOptions,
140cdf0e10cSrcweir const SfxItemPropertyMap& rPropMap,
141cdf0e10cSrcweir const rtl::OUString& aPropertyName )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir uno::Any aRet;
144cdf0e10cSrcweir const SfxItemPropertySimpleEntry* pEntry = rPropMap.getByName( aPropertyName );
145cdf0e10cSrcweir if( !pEntry || !pEntry->nWID )
146cdf0e10cSrcweir return aRet;
147cdf0e10cSrcweir switch( pEntry->nWID )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir case PROP_UNO_CALCASSHOWN :
150cdf0e10cSrcweir ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsCalcAsShown() );
151cdf0e10cSrcweir break;
152cdf0e10cSrcweir case PROP_UNO_DEFTABSTOP :
153cdf0e10cSrcweir aRet <<= (sal_Int16)( rOptions.GetTabDistance() );
154cdf0e10cSrcweir break;
155cdf0e10cSrcweir case PROP_UNO_IGNORECASE :
156cdf0e10cSrcweir ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsIgnoreCase() );
157cdf0e10cSrcweir break;
158cdf0e10cSrcweir case PROP_UNO_ITERENABLED:
159cdf0e10cSrcweir ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsIter() );
160cdf0e10cSrcweir break;
161cdf0e10cSrcweir case PROP_UNO_ITERCOUNT:
162cdf0e10cSrcweir aRet <<= (sal_Int32)( rOptions.GetIterCount() );
163cdf0e10cSrcweir break;
164cdf0e10cSrcweir case PROP_UNO_ITEREPSILON:
165cdf0e10cSrcweir aRet <<= (double)( rOptions.GetIterEps() );
166cdf0e10cSrcweir break;
167cdf0e10cSrcweir case PROP_UNO_LOOKUPLABELS:
168cdf0e10cSrcweir ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsLookUpColRowNames() );
169cdf0e10cSrcweir break;
170cdf0e10cSrcweir case PROP_UNO_MATCHWHOLE:
171cdf0e10cSrcweir ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsMatchWholeCell() );
172cdf0e10cSrcweir break;
173cdf0e10cSrcweir case PROP_UNO_NULLDATE:
174cdf0e10cSrcweir {
175cdf0e10cSrcweir sal_uInt16 nD, nM, nY;
176cdf0e10cSrcweir rOptions.GetDate( nD, nM, nY );
177cdf0e10cSrcweir util::Date aDate( nD, nM, nY );
178cdf0e10cSrcweir aRet <<= aDate;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir break;
181cdf0e10cSrcweir case PROP_UNO_SPELLONLINE:
182cdf0e10cSrcweir ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsAutoSpell() );
183cdf0e10cSrcweir break;
184cdf0e10cSrcweir case PROP_UNO_STANDARDDEC :
185cdf0e10cSrcweir aRet <<= (sal_Int16)( rOptions.GetStdPrecision() );
186cdf0e10cSrcweir break;
187cdf0e10cSrcweir case PROP_UNO_REGEXENABLED:
188cdf0e10cSrcweir ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsFormulaRegexEnabled() );
189cdf0e10cSrcweir break;
190cdf0e10cSrcweir default:;
191cdf0e10cSrcweir }
192cdf0e10cSrcweir return aRet;
193cdf0e10cSrcweir }
194cdf0e10cSrcweir
195cdf0e10cSrcweir //------------------------------------------------------------------------
196cdf0e10cSrcweir
ScDocOptionsObj(const ScDocOptions & rOpt)197cdf0e10cSrcweir ScDocOptionsObj::ScDocOptionsObj( const ScDocOptions& rOpt ) :
198cdf0e10cSrcweir ScModelObj( NULL ),
199cdf0e10cSrcweir aOptions( rOpt )
200cdf0e10cSrcweir {
201cdf0e10cSrcweir }
202cdf0e10cSrcweir
~ScDocOptionsObj()203cdf0e10cSrcweir ScDocOptionsObj::~ScDocOptionsObj()
204cdf0e10cSrcweir {
205cdf0e10cSrcweir }
206cdf0e10cSrcweir
setPropertyValue(const rtl::OUString & aPropertyName,const uno::Any & aValue)207cdf0e10cSrcweir void SAL_CALL ScDocOptionsObj::setPropertyValue(
208cdf0e10cSrcweir const rtl::OUString& aPropertyName, const uno::Any& aValue )
209cdf0e10cSrcweir throw(beans::UnknownPropertyException, beans::PropertyVetoException,
210cdf0e10cSrcweir lang::IllegalArgumentException, lang::WrappedTargetException,
211cdf0e10cSrcweir uno::RuntimeException)
212cdf0e10cSrcweir {
213cdf0e10cSrcweir ScUnoGuard aGuard;
214cdf0e10cSrcweir
215cdf0e10cSrcweir sal_Bool bDone = ScDocOptionsHelper::setPropertyValue( aOptions, *GetPropertySet().getPropertyMap(), aPropertyName, aValue );
216cdf0e10cSrcweir
217cdf0e10cSrcweir if (!bDone)
218cdf0e10cSrcweir ScModelObj::setPropertyValue( aPropertyName, aValue );
219cdf0e10cSrcweir }
220cdf0e10cSrcweir
getPropertyValue(const rtl::OUString & aPropertyName)221cdf0e10cSrcweir uno::Any SAL_CALL ScDocOptionsObj::getPropertyValue( const rtl::OUString& aPropertyName )
222cdf0e10cSrcweir throw(beans::UnknownPropertyException, lang::WrappedTargetException,
223cdf0e10cSrcweir uno::RuntimeException)
224cdf0e10cSrcweir {
225cdf0e10cSrcweir ScUnoGuard aGuard;
226cdf0e10cSrcweir
227cdf0e10cSrcweir uno::Any aRet(ScDocOptionsHelper::getPropertyValue( aOptions, *GetPropertySet().getPropertyMap(), aPropertyName ));
228cdf0e10cSrcweir if ( !aRet.hasValue() )
229cdf0e10cSrcweir aRet = ScModelObj::getPropertyValue( aPropertyName );
230cdf0e10cSrcweir
231cdf0e10cSrcweir return aRet;
232cdf0e10cSrcweir }
233cdf0e10cSrcweir
234