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