sync master with lastest vba changes
[ooovba.git] / sc / source / ui / unoobj / optuno.cxx
blobaa4a9ad54891daa804c60c42bf8c7b091708fe60
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 //------------------------------------------------------------------------
50 // static
51 const SfxItemPropertyMap* ScDocOptionsHelper::GetPropertyMap()
53 static SfxItemPropertyMap aMap[] =
55 {MAP_CHAR_LEN(SC_UNO_CALCASSHOWN), 0, &getBooleanCppuType(), 0, 0},
56 {MAP_CHAR_LEN(SC_UNO_DEFTABSTOP), 0, &getCppuType((sal_Int16*)0), 0, 0},
57 {MAP_CHAR_LEN(SC_UNO_IGNORECASE), 0, &getBooleanCppuType(), 0, 0},
58 {MAP_CHAR_LEN(SC_UNO_ITERENABLED), 0, &getBooleanCppuType(), 0, 0},
59 {MAP_CHAR_LEN(SC_UNO_ITERCOUNT), 0, &getCppuType((sal_Int32*)0), 0, 0},
60 {MAP_CHAR_LEN(SC_UNO_ITEREPSILON), 0, &getCppuType((double*)0), 0, 0},
61 {MAP_CHAR_LEN(SC_UNO_LOOKUPLABELS), 0, &getBooleanCppuType(), 0, 0},
62 {MAP_CHAR_LEN(SC_UNO_MATCHWHOLE), 0, &getBooleanCppuType(), 0, 0},
63 {MAP_CHAR_LEN(SC_UNO_NULLDATE), 0, &getCppuType((util::Date*)0), 0, 0},
64 {MAP_CHAR_LEN(SC_UNO_SPELLONLINE), 0, &getBooleanCppuType(), 0, 0},
65 {MAP_CHAR_LEN(SC_UNO_STANDARDDEC), 0, &getCppuType((sal_Int16*)0), 0, 0},
66 {MAP_CHAR_LEN(SC_UNO_REGEXENABLED), 0, &getBooleanCppuType(), 0, 0},
67 {0,0,0,0,0,0}
69 return aMap;
72 // static
73 sal_Bool ScDocOptionsHelper::setPropertyValue( ScDocOptions& rOptions,
74 const rtl::OUString& aPropertyName, const uno::Any& aValue )
76 //! use map (with new identifiers)
78 sal_Bool bKnown = sal_True;
79 String aString(aPropertyName);
81 if ( aString.EqualsAscii( SC_UNO_CALCASSHOWN ) )
82 rOptions.SetCalcAsShown( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
83 else if ( aString.EqualsAscii( SC_UNO_IGNORECASE ) )
84 rOptions.SetIgnoreCase( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
85 else if ( aString.EqualsAscii( SC_UNO_ITERENABLED ) )
86 rOptions.SetIter( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
87 else if ( aString.EqualsAscii( SC_UNO_REGEXENABLED ) )
88 rOptions.SetFormulaRegexEnabled( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
89 else if ( aString.EqualsAscii( SC_UNO_LOOKUPLABELS ) )
90 rOptions.SetLookUpColRowNames( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
91 else if ( aString.EqualsAscii( SC_UNO_MATCHWHOLE ) )
92 rOptions.SetMatchWholeCell( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
93 else if ( aString.EqualsAscii( SC_UNO_SPELLONLINE ) )
94 rOptions.SetAutoSpell( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
95 else if ( aString.EqualsAscii( SC_UNO_DEFTABSTOP ) )
97 sal_Int16 nIntVal = 0;
98 if ( aValue >>= nIntVal )
99 rOptions.SetTabDistance( nIntVal );
101 else if ( aString.EqualsAscii( SC_UNO_ITERCOUNT ) )
103 sal_Int32 nIntVal = 0;
104 if ( aValue >>= nIntVal )
105 rOptions.SetIterCount( (USHORT)nIntVal );
107 else if ( aString.EqualsAscii( SC_UNO_STANDARDDEC ) )
109 sal_Int16 nIntVal = 0;
110 if ( aValue >>= nIntVal )
111 rOptions.SetStdPrecision( nIntVal );
113 else if ( aString.EqualsAscii( SC_UNO_ITEREPSILON ) )
115 double fDoubleVal = 0;
116 if ( aValue >>= fDoubleVal )
117 rOptions.SetIterEps( fDoubleVal );
119 else if ( aString.EqualsAscii( SC_UNO_NULLDATE ) )
121 util::Date aDate;
122 if ( aValue >>= aDate )
123 rOptions.SetDate( aDate.Day, aDate.Month, aDate.Year );
125 else
126 bKnown = sal_False;
128 return bKnown;
131 // static
132 uno::Any ScDocOptionsHelper::getPropertyValue(
133 const ScDocOptions& rOptions, const rtl::OUString& aPropertyName )
135 //! use map (with new identifiers)
137 String aString(aPropertyName);
138 uno::Any aRet;
140 if ( aString.EqualsAscii( SC_UNO_CALCASSHOWN ) )
141 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsCalcAsShown() );
142 else if ( aString.EqualsAscii( SC_UNO_IGNORECASE ) )
143 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsIgnoreCase() );
144 else if ( aString.EqualsAscii( SC_UNO_ITERENABLED ) )
145 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsIter() );
146 else if ( aString.EqualsAscii( SC_UNO_REGEXENABLED ) )
147 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsFormulaRegexEnabled() );
148 else if ( aString.EqualsAscii( SC_UNO_LOOKUPLABELS ) )
149 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsLookUpColRowNames() );
150 else if ( aString.EqualsAscii( SC_UNO_MATCHWHOLE ) )
151 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsMatchWholeCell() );
152 else if ( aString.EqualsAscii( SC_UNO_SPELLONLINE ) )
153 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsAutoSpell() );
154 else if ( aString.EqualsAscii( SC_UNO_DEFTABSTOP ) )
155 aRet <<= (sal_Int16)( rOptions.GetTabDistance() );
156 else if ( aString.EqualsAscii( SC_UNO_ITERCOUNT ) )
157 aRet <<= (sal_Int32)( rOptions.GetIterCount() );
158 else if ( aString.EqualsAscii( SC_UNO_STANDARDDEC ) )
159 aRet <<= (sal_Int16)( rOptions.GetStdPrecision() );
160 else if ( aString.EqualsAscii( SC_UNO_ITEREPSILON ) )
161 aRet <<= (double)( rOptions.GetIterEps() );
162 else if ( aString.EqualsAscii( SC_UNO_NULLDATE ) )
164 USHORT nD, nM, nY;
165 rOptions.GetDate( nD, nM, nY );
166 util::Date aDate( nD, nM, nY );
167 aRet <<= aDate;
170 return aRet;
173 //------------------------------------------------------------------------
175 ScDocOptionsObj::ScDocOptionsObj( const ScDocOptions& rOpt ) :
176 ScModelObj( NULL ),
177 aOptions( rOpt )
181 ScDocOptionsObj::~ScDocOptionsObj()
185 void SAL_CALL ScDocOptionsObj::setPropertyValue(
186 const rtl::OUString& aPropertyName, const uno::Any& aValue )
187 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
188 lang::IllegalArgumentException, lang::WrappedTargetException,
189 uno::RuntimeException)
191 ScUnoGuard aGuard;
193 BOOL bDone = ScDocOptionsHelper::setPropertyValue( aOptions, aPropertyName, aValue );
195 if (!bDone)
196 ScModelObj::setPropertyValue( aPropertyName, aValue );
199 uno::Any SAL_CALL ScDocOptionsObj::getPropertyValue( const rtl::OUString& aPropertyName )
200 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
201 uno::RuntimeException)
203 ScUnoGuard aGuard;
205 uno::Any aRet(ScDocOptionsHelper::getPropertyValue( aOptions, aPropertyName ));
206 if ( !aRet.hasValue() )
207 aRet = ScModelObj::getPropertyValue( aPropertyName );
209 return aRet;