1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: optuno.cxx,v $
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>
41 #include "miscuno.hxx"
42 #include "unonames.hxx"
43 #include "docoptio.hxx"
44 #include "unoguard.hxx"
46 using namespace com::sun::star
;
48 //------------------------------------------------------------------------
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},
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
)
81 switch( pEntry
->nWID
)
83 case PROP_UNO_CALCASSHOWN
:
84 rOptions
.SetCalcAsShown( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
86 case PROP_UNO_DEFTABSTOP
:
88 sal_Int16 nIntVal
= 0;
89 if ( aValue
>>= nIntVal
)
90 rOptions
.SetTabDistance( nIntVal
);
93 case PROP_UNO_IGNORECASE
:
94 rOptions
.SetIgnoreCase( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
96 case PROP_UNO_ITERENABLED
:
97 rOptions
.SetIter( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
99 case PROP_UNO_ITERCOUNT
:
101 sal_Int32 nIntVal
= 0;
102 if ( aValue
>>= nIntVal
)
103 rOptions
.SetIterCount( (USHORT
)nIntVal
);
106 case PROP_UNO_ITEREPSILON
:
108 double fDoubleVal
= 0;
109 if ( aValue
>>= fDoubleVal
)
110 rOptions
.SetIterEps( fDoubleVal
);
113 case PROP_UNO_LOOKUPLABELS
:
114 rOptions
.SetLookUpColRowNames( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
116 case PROP_UNO_MATCHWHOLE
:
117 rOptions
.SetMatchWholeCell( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
119 case PROP_UNO_NULLDATE
:
122 if ( aValue
>>= aDate
)
123 rOptions
.SetDate( aDate
.Day
, aDate
.Month
, aDate
.Year
);
126 case PROP_UNO_SPELLONLINE
:
127 rOptions
.SetAutoSpell( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
129 case PROP_UNO_STANDARDDEC
:
131 sal_Int16 nIntVal
= 0;
132 if ( aValue
>>= nIntVal
)
133 rOptions
.SetStdPrecision( nIntVal
);
136 case PROP_UNO_REGEXENABLED
:
137 rOptions
.SetFormulaRegexEnabled( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
145 uno::Any
ScDocOptionsHelper::getPropertyValue(
146 const ScDocOptions
& rOptions
,
147 const SfxItemPropertyMap
& rPropMap
,
148 const rtl::OUString
& aPropertyName
)
151 const SfxItemPropertySimpleEntry
* pEntry
= rPropMap
.getByName( aPropertyName
);
152 if( !pEntry
|| !pEntry
->nWID
)
154 switch( pEntry
->nWID
)
156 case PROP_UNO_CALCASSHOWN
:
157 ScUnoHelpFunctions::SetBoolInAny( aRet
, rOptions
.IsCalcAsShown() );
159 case PROP_UNO_DEFTABSTOP
:
160 aRet
<<= (sal_Int16
)( rOptions
.GetTabDistance() );
162 case PROP_UNO_IGNORECASE
:
163 ScUnoHelpFunctions::SetBoolInAny( aRet
, rOptions
.IsIgnoreCase() );
165 case PROP_UNO_ITERENABLED
:
166 ScUnoHelpFunctions::SetBoolInAny( aRet
, rOptions
.IsIter() );
168 case PROP_UNO_ITERCOUNT
:
169 aRet
<<= (sal_Int32
)( rOptions
.GetIterCount() );
171 case PROP_UNO_ITEREPSILON
:
172 aRet
<<= (double)( rOptions
.GetIterEps() );
174 case PROP_UNO_LOOKUPLABELS
:
175 ScUnoHelpFunctions::SetBoolInAny( aRet
, rOptions
.IsLookUpColRowNames() );
177 case PROP_UNO_MATCHWHOLE
:
178 ScUnoHelpFunctions::SetBoolInAny( aRet
, rOptions
.IsMatchWholeCell() );
180 case PROP_UNO_NULLDATE
:
183 rOptions
.GetDate( nD
, nM
, nY
);
184 util::Date
aDate( nD
, nM
, nY
);
188 case PROP_UNO_SPELLONLINE
:
189 ScUnoHelpFunctions::SetBoolInAny( aRet
, rOptions
.IsAutoSpell() );
191 case PROP_UNO_STANDARDDEC
:
192 aRet
<<= (sal_Int16
)( rOptions
.GetStdPrecision() );
194 case PROP_UNO_REGEXENABLED
:
195 ScUnoHelpFunctions::SetBoolInAny( aRet
, rOptions
.IsFormulaRegexEnabled() );
202 //------------------------------------------------------------------------
204 ScDocOptionsObj::ScDocOptionsObj( const ScDocOptions
& 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
)
222 BOOL bDone
= ScDocOptionsHelper::setPropertyValue( aOptions
, *GetPropertySet().getPropertyMap(), aPropertyName
, aValue
);
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
)
234 uno::Any
aRet(ScDocOptionsHelper::getPropertyValue( aOptions
, *GetPropertySet().getPropertyMap(), aPropertyName
));
235 if ( !aRet
.hasValue() )
236 aRet
= ScModelObj::getPropertyValue( aPropertyName
);