xref: /trunk/main/sc/source/ui/unoobj/optuno.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <svl/itemprop.hxx>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <com/sun/star/util/Date.hpp>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include "optuno.hxx"
38*cdf0e10cSrcweir #include "miscuno.hxx"
39*cdf0e10cSrcweir #include "unonames.hxx"
40*cdf0e10cSrcweir #include "docoptio.hxx"
41*cdf0e10cSrcweir #include "unoguard.hxx"
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir using namespace com::sun::star;
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir //------------------------------------------------------------------------
46*cdf0e10cSrcweir // static
47*cdf0e10cSrcweir const SfxItemPropertyMapEntry* ScDocOptionsHelper::GetPropertyMap()
48*cdf0e10cSrcweir {
49*cdf0e10cSrcweir     static SfxItemPropertyMapEntry aMap[] =
50*cdf0e10cSrcweir     {
51*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CALCASSHOWN),  PROP_UNO_CALCASSHOWN ,  &getBooleanCppuType(),          0, 0},
52*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_DEFTABSTOP),   PROP_UNO_DEFTABSTOP  ,  &getCppuType((sal_Int16*)0),    0, 0},
53*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_IGNORECASE),   PROP_UNO_IGNORECASE  ,  &getBooleanCppuType(),          0, 0},
54*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_ITERENABLED),  PROP_UNO_ITERENABLED ,  &getBooleanCppuType(),          0, 0},
55*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_ITERCOUNT),    PROP_UNO_ITERCOUNT   ,  &getCppuType((sal_Int32*)0),    0, 0},
56*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_ITEREPSILON),  PROP_UNO_ITEREPSILON ,  &getCppuType((double*)0),       0, 0},
57*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_LOOKUPLABELS), PROP_UNO_LOOKUPLABELS,  &getBooleanCppuType(),          0, 0},
58*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_MATCHWHOLE),   PROP_UNO_MATCHWHOLE  ,  &getBooleanCppuType(),          0, 0},
59*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_NULLDATE),     PROP_UNO_NULLDATE    ,  &getCppuType((util::Date*)0),   0, 0},
60*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_SPELLONLINE),  PROP_UNO_SPELLONLINE ,  &getBooleanCppuType(),          0, 0},
61*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_STANDARDDEC),  PROP_UNO_STANDARDDEC ,  &getCppuType((sal_Int16*)0),    0, 0},
62*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_REGEXENABLED), PROP_UNO_REGEXENABLED,  &getBooleanCppuType(),          0, 0},
63*cdf0e10cSrcweir         {0,0,0,0,0,0}
64*cdf0e10cSrcweir     };
65*cdf0e10cSrcweir     return aMap;
66*cdf0e10cSrcweir }
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir // static
69*cdf0e10cSrcweir sal_Bool ScDocOptionsHelper::setPropertyValue( ScDocOptions& rOptions,
70*cdf0e10cSrcweir                 const SfxItemPropertyMap& rPropMap,
71*cdf0e10cSrcweir                 const rtl::OUString& aPropertyName, const uno::Any& aValue )
72*cdf0e10cSrcweir {
73*cdf0e10cSrcweir     //! use map (with new identifiers)
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir     const SfxItemPropertySimpleEntry* pEntry = rPropMap.getByName(aPropertyName );
76*cdf0e10cSrcweir     if( !pEntry || !pEntry->nWID )
77*cdf0e10cSrcweir         return sal_False;
78*cdf0e10cSrcweir     switch( pEntry->nWID )
79*cdf0e10cSrcweir     {
80*cdf0e10cSrcweir         case PROP_UNO_CALCASSHOWN :
81*cdf0e10cSrcweir             rOptions.SetCalcAsShown( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
82*cdf0e10cSrcweir         break;
83*cdf0e10cSrcweir         case PROP_UNO_DEFTABSTOP  :
84*cdf0e10cSrcweir         {
85*cdf0e10cSrcweir             sal_Int16 nIntVal = 0;
86*cdf0e10cSrcweir             if ( aValue >>= nIntVal )
87*cdf0e10cSrcweir                 rOptions.SetTabDistance( nIntVal );
88*cdf0e10cSrcweir         }
89*cdf0e10cSrcweir         break;
90*cdf0e10cSrcweir         case PROP_UNO_IGNORECASE  :
91*cdf0e10cSrcweir             rOptions.SetIgnoreCase( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
92*cdf0e10cSrcweir         break;
93*cdf0e10cSrcweir         case PROP_UNO_ITERENABLED:
94*cdf0e10cSrcweir             rOptions.SetIter( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
95*cdf0e10cSrcweir         break;
96*cdf0e10cSrcweir         case PROP_UNO_ITERCOUNT   :
97*cdf0e10cSrcweir         {
98*cdf0e10cSrcweir             sal_Int32 nIntVal = 0;
99*cdf0e10cSrcweir             if ( aValue >>= nIntVal )
100*cdf0e10cSrcweir                 rOptions.SetIterCount( (sal_uInt16)nIntVal );
101*cdf0e10cSrcweir         }
102*cdf0e10cSrcweir         break;
103*cdf0e10cSrcweir         case PROP_UNO_ITEREPSILON :
104*cdf0e10cSrcweir         {
105*cdf0e10cSrcweir             double fDoubleVal = 0;
106*cdf0e10cSrcweir             if ( aValue >>= fDoubleVal )
107*cdf0e10cSrcweir                 rOptions.SetIterEps( fDoubleVal );
108*cdf0e10cSrcweir         }
109*cdf0e10cSrcweir         break;
110*cdf0e10cSrcweir         case PROP_UNO_LOOKUPLABELS :
111*cdf0e10cSrcweir             rOptions.SetLookUpColRowNames( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
112*cdf0e10cSrcweir         break;
113*cdf0e10cSrcweir         case PROP_UNO_MATCHWHOLE  :
114*cdf0e10cSrcweir             rOptions.SetMatchWholeCell( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
115*cdf0e10cSrcweir         break;
116*cdf0e10cSrcweir         case PROP_UNO_NULLDATE:
117*cdf0e10cSrcweir         {
118*cdf0e10cSrcweir             util::Date aDate;
119*cdf0e10cSrcweir             if ( aValue >>= aDate )
120*cdf0e10cSrcweir                 rOptions.SetDate( aDate.Day, aDate.Month, aDate.Year );
121*cdf0e10cSrcweir         }
122*cdf0e10cSrcweir         break;
123*cdf0e10cSrcweir         case PROP_UNO_SPELLONLINE:
124*cdf0e10cSrcweir             rOptions.SetAutoSpell( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
125*cdf0e10cSrcweir         break;
126*cdf0e10cSrcweir         case PROP_UNO_STANDARDDEC:
127*cdf0e10cSrcweir         {
128*cdf0e10cSrcweir             sal_Int16 nIntVal = 0;
129*cdf0e10cSrcweir             if ( aValue >>= nIntVal )
130*cdf0e10cSrcweir                 rOptions.SetStdPrecision( nIntVal );
131*cdf0e10cSrcweir         }
132*cdf0e10cSrcweir         break;
133*cdf0e10cSrcweir         case PROP_UNO_REGEXENABLED:
134*cdf0e10cSrcweir             rOptions.SetFormulaRegexEnabled( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
135*cdf0e10cSrcweir         break;
136*cdf0e10cSrcweir         default:;
137*cdf0e10cSrcweir     }
138*cdf0e10cSrcweir     return sal_True;
139*cdf0e10cSrcweir }
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir // static
142*cdf0e10cSrcweir uno::Any ScDocOptionsHelper::getPropertyValue(
143*cdf0e10cSrcweir                 const ScDocOptions& rOptions,
144*cdf0e10cSrcweir                 const SfxItemPropertyMap& rPropMap,
145*cdf0e10cSrcweir                 const rtl::OUString& aPropertyName )
146*cdf0e10cSrcweir {
147*cdf0e10cSrcweir     uno::Any aRet;
148*cdf0e10cSrcweir     const SfxItemPropertySimpleEntry* pEntry = rPropMap.getByName( aPropertyName );
149*cdf0e10cSrcweir     if( !pEntry || !pEntry->nWID )
150*cdf0e10cSrcweir         return aRet;
151*cdf0e10cSrcweir     switch( pEntry->nWID )
152*cdf0e10cSrcweir     {
153*cdf0e10cSrcweir         case PROP_UNO_CALCASSHOWN :
154*cdf0e10cSrcweir             ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsCalcAsShown() );
155*cdf0e10cSrcweir         break;
156*cdf0e10cSrcweir         case PROP_UNO_DEFTABSTOP :
157*cdf0e10cSrcweir             aRet <<= (sal_Int16)( rOptions.GetTabDistance() );
158*cdf0e10cSrcweir         break;
159*cdf0e10cSrcweir         case PROP_UNO_IGNORECASE :
160*cdf0e10cSrcweir             ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsIgnoreCase() );
161*cdf0e10cSrcweir         break;
162*cdf0e10cSrcweir         case PROP_UNO_ITERENABLED:
163*cdf0e10cSrcweir         ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsIter() );
164*cdf0e10cSrcweir         break;
165*cdf0e10cSrcweir         case PROP_UNO_ITERCOUNT:
166*cdf0e10cSrcweir             aRet <<= (sal_Int32)( rOptions.GetIterCount() );
167*cdf0e10cSrcweir         break;
168*cdf0e10cSrcweir         case PROP_UNO_ITEREPSILON:
169*cdf0e10cSrcweir             aRet <<= (double)( rOptions.GetIterEps() );
170*cdf0e10cSrcweir         break;
171*cdf0e10cSrcweir         case PROP_UNO_LOOKUPLABELS:
172*cdf0e10cSrcweir             ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsLookUpColRowNames() );
173*cdf0e10cSrcweir         break;
174*cdf0e10cSrcweir         case PROP_UNO_MATCHWHOLE:
175*cdf0e10cSrcweir             ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsMatchWholeCell() );
176*cdf0e10cSrcweir         break;
177*cdf0e10cSrcweir         case PROP_UNO_NULLDATE:
178*cdf0e10cSrcweir         {
179*cdf0e10cSrcweir             sal_uInt16 nD, nM, nY;
180*cdf0e10cSrcweir             rOptions.GetDate( nD, nM, nY );
181*cdf0e10cSrcweir             util::Date aDate( nD, nM, nY );
182*cdf0e10cSrcweir             aRet <<= aDate;
183*cdf0e10cSrcweir         }
184*cdf0e10cSrcweir         break;
185*cdf0e10cSrcweir         case PROP_UNO_SPELLONLINE:
186*cdf0e10cSrcweir             ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsAutoSpell() );
187*cdf0e10cSrcweir         break;
188*cdf0e10cSrcweir         case PROP_UNO_STANDARDDEC :
189*cdf0e10cSrcweir             aRet <<= (sal_Int16)( rOptions.GetStdPrecision() );
190*cdf0e10cSrcweir         break;
191*cdf0e10cSrcweir         case PROP_UNO_REGEXENABLED:
192*cdf0e10cSrcweir             ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsFormulaRegexEnabled() );
193*cdf0e10cSrcweir         break;
194*cdf0e10cSrcweir         default:;
195*cdf0e10cSrcweir     }
196*cdf0e10cSrcweir     return aRet;
197*cdf0e10cSrcweir }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir //------------------------------------------------------------------------
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir ScDocOptionsObj::ScDocOptionsObj( const ScDocOptions& rOpt ) :
202*cdf0e10cSrcweir     ScModelObj( NULL ),
203*cdf0e10cSrcweir     aOptions( rOpt )
204*cdf0e10cSrcweir {
205*cdf0e10cSrcweir }
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir ScDocOptionsObj::~ScDocOptionsObj()
208*cdf0e10cSrcweir {
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir void SAL_CALL ScDocOptionsObj::setPropertyValue(
212*cdf0e10cSrcweir                         const rtl::OUString& aPropertyName, const uno::Any& aValue )
213*cdf0e10cSrcweir                 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
214*cdf0e10cSrcweir                         lang::IllegalArgumentException, lang::WrappedTargetException,
215*cdf0e10cSrcweir                         uno::RuntimeException)
216*cdf0e10cSrcweir {
217*cdf0e10cSrcweir     ScUnoGuard aGuard;
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir     sal_Bool bDone = ScDocOptionsHelper::setPropertyValue( aOptions, *GetPropertySet().getPropertyMap(), aPropertyName, aValue );
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir     if (!bDone)
222*cdf0e10cSrcweir         ScModelObj::setPropertyValue( aPropertyName, aValue );
223*cdf0e10cSrcweir }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir uno::Any SAL_CALL ScDocOptionsObj::getPropertyValue( const rtl::OUString& aPropertyName )
226*cdf0e10cSrcweir                 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
227*cdf0e10cSrcweir                         uno::RuntimeException)
228*cdf0e10cSrcweir {
229*cdf0e10cSrcweir     ScUnoGuard aGuard;
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir     uno::Any aRet(ScDocOptionsHelper::getPropertyValue( aOptions, *GetPropertySet().getPropertyMap(), aPropertyName ));
232*cdf0e10cSrcweir     if ( !aRet.hasValue() )
233*cdf0e10cSrcweir         aRet =  ScModelObj::getPropertyValue( aPropertyName );
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir     return aRet;
236*cdf0e10cSrcweir }
237*cdf0e10cSrcweir 
238