Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / unoobj / optuno.cxx
blob6dae636f87bb1021e9e08b03474c3d2fb98a6e47
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svl/itemprop.hxx>
22 #include <com/sun/star/util/Date.hpp>
24 #include "optuno.hxx"
25 #include "miscuno.hxx"
26 #include "unonames.hxx"
27 #include "docoptio.hxx"
29 using namespace com::sun::star;
31 //------------------------------------------------------------------------
32 const SfxItemPropertyMapEntry* ScDocOptionsHelper::GetPropertyMap()
34 static const SfxItemPropertyMapEntry aMap[] =
36 {MAP_CHAR_LEN(SC_UNO_CALCASSHOWN), PROP_UNO_CALCASSHOWN , &getBooleanCppuType(), 0, 0},
37 {MAP_CHAR_LEN(SC_UNO_DEFTABSTOP), PROP_UNO_DEFTABSTOP , &getCppuType((sal_Int16*)0), 0, 0},
38 {MAP_CHAR_LEN(SC_UNO_IGNORECASE), PROP_UNO_IGNORECASE , &getBooleanCppuType(), 0, 0},
39 {MAP_CHAR_LEN(SC_UNO_ITERENABLED), PROP_UNO_ITERENABLED , &getBooleanCppuType(), 0, 0},
40 {MAP_CHAR_LEN(SC_UNO_ITERCOUNT), PROP_UNO_ITERCOUNT , &getCppuType((sal_Int32*)0), 0, 0},
41 {MAP_CHAR_LEN(SC_UNO_ITEREPSILON), PROP_UNO_ITEREPSILON , &getCppuType((double*)0), 0, 0},
42 {MAP_CHAR_LEN(SC_UNO_LOOKUPLABELS), PROP_UNO_LOOKUPLABELS, &getBooleanCppuType(), 0, 0},
43 {MAP_CHAR_LEN(SC_UNO_MATCHWHOLE), PROP_UNO_MATCHWHOLE , &getBooleanCppuType(), 0, 0},
44 {MAP_CHAR_LEN(SC_UNO_NULLDATE), PROP_UNO_NULLDATE , &getCppuType((util::Date*)0), 0, 0},
45 {MAP_CHAR_LEN(SC_UNO_SPELLONLINE), PROP_UNO_SPELLONLINE , &getBooleanCppuType(), 0, 0},
46 {MAP_CHAR_LEN(SC_UNO_STANDARDDEC), PROP_UNO_STANDARDDEC , &getCppuType((sal_Int16*)0), 0, 0},
47 {MAP_CHAR_LEN(SC_UNO_REGEXENABLED), PROP_UNO_REGEXENABLED, &getBooleanCppuType(), 0, 0},
48 {0,0,0,0,0,0}
50 return aMap;
53 sal_Bool ScDocOptionsHelper::setPropertyValue( ScDocOptions& rOptions,
54 const SfxItemPropertyMap& rPropMap,
55 const OUString& aPropertyName, const uno::Any& aValue )
57 //! use map (with new identifiers)
59 const SfxItemPropertySimpleEntry* pEntry = rPropMap.getByName(aPropertyName );
60 if( !pEntry || !pEntry->nWID )
61 return false;
62 switch( pEntry->nWID )
64 case PROP_UNO_CALCASSHOWN :
65 rOptions.SetCalcAsShown( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
66 break;
67 case PROP_UNO_DEFTABSTOP :
69 sal_Int16 nIntVal = 0;
70 if ( aValue >>= nIntVal )
71 rOptions.SetTabDistance( nIntVal );
73 break;
74 case PROP_UNO_IGNORECASE :
75 rOptions.SetIgnoreCase( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
76 break;
77 case PROP_UNO_ITERENABLED:
78 rOptions.SetIter( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
79 break;
80 case PROP_UNO_ITERCOUNT :
82 sal_Int32 nIntVal = 0;
83 if ( aValue >>= nIntVal )
84 rOptions.SetIterCount( (sal_uInt16)nIntVal );
86 break;
87 case PROP_UNO_ITEREPSILON :
89 double fDoubleVal = 0;
90 if ( aValue >>= fDoubleVal )
91 rOptions.SetIterEps( fDoubleVal );
93 break;
94 case PROP_UNO_LOOKUPLABELS :
95 rOptions.SetLookUpColRowNames( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
96 break;
97 case PROP_UNO_MATCHWHOLE :
98 rOptions.SetMatchWholeCell( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
99 break;
100 case PROP_UNO_NULLDATE:
102 util::Date aDate;
103 if ( aValue >>= aDate )
104 rOptions.SetDate( aDate.Day, aDate.Month, aDate.Year );
106 break;
107 case PROP_UNO_SPELLONLINE:
108 rOptions.SetAutoSpell( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
109 break;
110 case PROP_UNO_STANDARDDEC:
112 sal_Int16 nIntVal = 0;
113 if ( aValue >>= nIntVal )
114 rOptions.SetStdPrecision( nIntVal );
116 break;
117 case PROP_UNO_REGEXENABLED:
118 rOptions.SetFormulaRegexEnabled( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
119 break;
120 default:;
122 return sal_True;
125 uno::Any ScDocOptionsHelper::getPropertyValue(
126 const ScDocOptions& rOptions,
127 const SfxItemPropertyMap& rPropMap,
128 const OUString& aPropertyName )
130 uno::Any aRet;
131 const SfxItemPropertySimpleEntry* pEntry = rPropMap.getByName( aPropertyName );
132 if( !pEntry || !pEntry->nWID )
133 return aRet;
134 switch( pEntry->nWID )
136 case PROP_UNO_CALCASSHOWN :
137 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsCalcAsShown() );
138 break;
139 case PROP_UNO_DEFTABSTOP :
140 aRet <<= (sal_Int16)( rOptions.GetTabDistance() );
141 break;
142 case PROP_UNO_IGNORECASE :
143 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsIgnoreCase() );
144 break;
145 case PROP_UNO_ITERENABLED:
146 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsIter() );
147 break;
148 case PROP_UNO_ITERCOUNT:
149 aRet <<= (sal_Int32)( rOptions.GetIterCount() );
150 break;
151 case PROP_UNO_ITEREPSILON:
152 aRet <<= (double)( rOptions.GetIterEps() );
153 break;
154 case PROP_UNO_LOOKUPLABELS:
155 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsLookUpColRowNames() );
156 break;
157 case PROP_UNO_MATCHWHOLE:
158 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsMatchWholeCell() );
159 break;
160 case PROP_UNO_NULLDATE:
162 sal_uInt16 nD, nM, nY;
163 rOptions.GetDate( nD, nM, nY );
164 util::Date aDate( nD, nM, nY );
165 aRet <<= aDate;
167 break;
168 case PROP_UNO_SPELLONLINE:
169 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsAutoSpell() );
170 break;
171 case PROP_UNO_STANDARDDEC :
172 aRet <<= (sal_Int16)( rOptions.GetStdPrecision() );
173 break;
174 case PROP_UNO_REGEXENABLED:
175 ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsFormulaRegexEnabled() );
176 break;
177 default:;
179 return aRet;
182 //------------------------------------------------------------------------
184 ScDocOptionsObj::ScDocOptionsObj( const ScDocOptions& rOpt ) :
185 ScModelObj( NULL ),
186 aOptions( rOpt )
190 ScDocOptionsObj::~ScDocOptionsObj()
194 void SAL_CALL ScDocOptionsObj::setPropertyValue(
195 const OUString& aPropertyName, const uno::Any& aValue )
196 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
197 lang::IllegalArgumentException, lang::WrappedTargetException,
198 uno::RuntimeException)
200 SolarMutexGuard aGuard;
202 sal_Bool bDone = ScDocOptionsHelper::setPropertyValue( aOptions, GetPropertySet().getPropertyMap(), aPropertyName, aValue );
204 if (!bDone)
205 ScModelObj::setPropertyValue( aPropertyName, aValue );
208 uno::Any SAL_CALL ScDocOptionsObj::getPropertyValue( const OUString& aPropertyName )
209 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
210 uno::RuntimeException)
212 SolarMutexGuard aGuard;
214 uno::Any aRet(ScDocOptionsHelper::getPropertyValue( aOptions, GetPropertySet().getPropertyMap(), aPropertyName ));
215 if ( !aRet.hasValue() )
216 aRet = ScModelObj::getPropertyValue( aPropertyName );
218 return aRet;
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */