xref: /trunk/main/sc/source/ui/unoobj/defltuno.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 #include <editeng/memberids.hrc>
33*cdf0e10cSrcweir #include <svl/smplhint.hxx>
34*cdf0e10cSrcweir #include <svl/itemprop.hxx>
35*cdf0e10cSrcweir #include <svx/unomid.hxx>
36*cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include "scitems.hxx"
41*cdf0e10cSrcweir #include "defltuno.hxx"
42*cdf0e10cSrcweir #include "miscuno.hxx"
43*cdf0e10cSrcweir #include "docsh.hxx"
44*cdf0e10cSrcweir #include "docpool.hxx"
45*cdf0e10cSrcweir #include "unoguard.hxx"
46*cdf0e10cSrcweir #include "unonames.hxx"
47*cdf0e10cSrcweir #include "docoptio.hxx"
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir #include <limits>
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir using namespace ::com::sun::star;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir //------------------------------------------------------------------------
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir const SfxItemPropertyMapEntry* lcl_GetDocDefaultsMap()
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir     static SfxItemPropertyMapEntry aDocDefaultsMap_Impl[] =
58*cdf0e10cSrcweir     {
59*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CFCHARS),  ATTR_FONT,          &getCppuType((sal_Int16*)0),        0, MID_FONT_CHAR_SET },
60*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CJK_CFCHARS),  ATTR_CJK_FONT,      &getCppuType((sal_Int16*)0),        0, MID_FONT_CHAR_SET },
61*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CTL_CFCHARS),  ATTR_CTL_FONT,      &getCppuType((sal_Int16*)0),        0, MID_FONT_CHAR_SET },
62*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CFFAMIL),  ATTR_FONT,          &getCppuType((sal_Int16*)0),        0, MID_FONT_FAMILY },
63*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CJK_CFFAMIL),  ATTR_CJK_FONT,      &getCppuType((sal_Int16*)0),        0, MID_FONT_FAMILY },
64*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CTL_CFFAMIL),  ATTR_CTL_FONT,      &getCppuType((sal_Int16*)0),        0, MID_FONT_FAMILY },
65*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CFNAME),   ATTR_FONT,          &getCppuType((rtl::OUString*)0),    0, MID_FONT_FAMILY_NAME },
66*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CJK_CFNAME),   ATTR_CJK_FONT,      &getCppuType((rtl::OUString*)0),    0, MID_FONT_FAMILY_NAME },
67*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CTL_CFNAME),   ATTR_CTL_FONT,      &getCppuType((rtl::OUString*)0),    0, MID_FONT_FAMILY_NAME },
68*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CFPITCH),  ATTR_FONT,          &getCppuType((sal_Int16*)0),        0, MID_FONT_PITCH },
69*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CJK_CFPITCH),  ATTR_CJK_FONT,      &getCppuType((sal_Int16*)0),        0, MID_FONT_PITCH },
70*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CTL_CFPITCH),  ATTR_CTL_FONT,      &getCppuType((sal_Int16*)0),        0, MID_FONT_PITCH },
71*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CFSTYLE),  ATTR_FONT,          &getCppuType((rtl::OUString*)0),    0, MID_FONT_STYLE_NAME },
72*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CJK_CFSTYLE),  ATTR_CJK_FONT,      &getCppuType((rtl::OUString*)0),    0, MID_FONT_STYLE_NAME },
73*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CTL_CFSTYLE),  ATTR_CTL_FONT,      &getCppuType((rtl::OUString*)0),    0, MID_FONT_STYLE_NAME },
74*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CLOCAL),   ATTR_FONT_LANGUAGE, &getCppuType((lang::Locale*)0),     0, MID_LANG_LOCALE },
75*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL),   ATTR_CJK_FONT_LANGUAGE, &getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE },
76*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL),   ATTR_CTL_FONT_LANGUAGE, &getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE },
77*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_STANDARDDEC),              0,      &getCppuType((sal_Int16*)0),        0, 0 },
78*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_TABSTOPDIS),               0,      &getCppuType((sal_Int32*)0),        0, 0 },
79*cdf0e10cSrcweir         {0,0,0,0,0,0}
80*cdf0e10cSrcweir     };
81*cdf0e10cSrcweir     return aDocDefaultsMap_Impl;
82*cdf0e10cSrcweir }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir inline long TwipsToHMM(long nTwips) { return (nTwips * 127 + 36) / 72; }
85*cdf0e10cSrcweir inline long HMMToTwips(long nHMM)   { return (nHMM * 72 + 63) / 127; }
86*cdf0e10cSrcweir inline long TwipsToEvenHMM(long nTwips) { return ( (nTwips * 127 + 72) / 144 ) * 2; }
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir //------------------------------------------------------------------------
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScDocDefaultsObj, "ScDocDefaultsObj", "com.sun.star.sheet.Defaults" )
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir //------------------------------------------------------------------------
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir ScDocDefaultsObj::ScDocDefaultsObj(ScDocShell* pDocSh) :
95*cdf0e10cSrcweir     pDocShell( pDocSh ),
96*cdf0e10cSrcweir     aPropertyMap(lcl_GetDocDefaultsMap())
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir     pDocShell->GetDocument()->AddUnoObject(*this);
99*cdf0e10cSrcweir }
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir ScDocDefaultsObj::~ScDocDefaultsObj()
102*cdf0e10cSrcweir {
103*cdf0e10cSrcweir     if (pDocShell)
104*cdf0e10cSrcweir         pDocShell->GetDocument()->RemoveUnoObject(*this);
105*cdf0e10cSrcweir }
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir void ScDocDefaultsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
108*cdf0e10cSrcweir {
109*cdf0e10cSrcweir     if ( rHint.ISA( SfxSimpleHint ) &&
110*cdf0e10cSrcweir             ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
111*cdf0e10cSrcweir     {
112*cdf0e10cSrcweir         pDocShell = NULL;       // document gone
113*cdf0e10cSrcweir     }
114*cdf0e10cSrcweir }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir void ScDocDefaultsObj::ItemsChanged()
117*cdf0e10cSrcweir {
118*cdf0e10cSrcweir     if (pDocShell)
119*cdf0e10cSrcweir     {
120*cdf0e10cSrcweir         //! if not in XML import, adjust row heights
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir         pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID );
123*cdf0e10cSrcweir     }
124*cdf0e10cSrcweir }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir // XPropertySet
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir uno::Reference<beans::XPropertySetInfo> SAL_CALL ScDocDefaultsObj::getPropertySetInfo()
129*cdf0e10cSrcweir                                                         throw(uno::RuntimeException)
130*cdf0e10cSrcweir {
131*cdf0e10cSrcweir     ScUnoGuard aGuard;
132*cdf0e10cSrcweir     static uno::Reference<beans::XPropertySetInfo> aRef = new SfxItemPropertySetInfo(
133*cdf0e10cSrcweir                                                                         &aPropertyMap );
134*cdf0e10cSrcweir     return aRef;
135*cdf0e10cSrcweir }
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir void SAL_CALL ScDocDefaultsObj::setPropertyValue(
138*cdf0e10cSrcweir                         const rtl::OUString& aPropertyName, const uno::Any& aValue )
139*cdf0e10cSrcweir                 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
140*cdf0e10cSrcweir                         lang::IllegalArgumentException, lang::WrappedTargetException,
141*cdf0e10cSrcweir                         uno::RuntimeException)
142*cdf0e10cSrcweir {
143*cdf0e10cSrcweir     ScUnoGuard aGuard;
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir     if ( !pDocShell )
146*cdf0e10cSrcweir         throw uno::RuntimeException();
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir     const SfxItemPropertySimpleEntry* pEntry = aPropertyMap.getByName( aPropertyName );
149*cdf0e10cSrcweir     if ( !pEntry )
150*cdf0e10cSrcweir         throw beans::UnknownPropertyException();
151*cdf0e10cSrcweir     if(!pEntry->nWID)
152*cdf0e10cSrcweir     {
153*cdf0e10cSrcweir         if(aPropertyName.compareToAscii(SC_UNO_STANDARDDEC) == 0)
154*cdf0e10cSrcweir         {
155*cdf0e10cSrcweir             ScDocument* pDoc = pDocShell->GetDocument();
156*cdf0e10cSrcweir             if (pDoc)
157*cdf0e10cSrcweir             {
158*cdf0e10cSrcweir                 ScDocOptions aDocOpt(pDoc->GetDocOptions());
159*cdf0e10cSrcweir                 sal_Int16 nValue = 0;
160*cdf0e10cSrcweir                 if (aValue >>= nValue)
161*cdf0e10cSrcweir                 {
162*cdf0e10cSrcweir                     aDocOpt.SetStdPrecision(static_cast<sal_uInt16> (nValue));
163*cdf0e10cSrcweir                     pDoc->SetDocOptions(aDocOpt);
164*cdf0e10cSrcweir                 }
165*cdf0e10cSrcweir             }
166*cdf0e10cSrcweir             else
167*cdf0e10cSrcweir                 throw uno::RuntimeException();
168*cdf0e10cSrcweir         }
169*cdf0e10cSrcweir         else if (aPropertyName.compareToAscii(SC_UNO_TABSTOPDIS) == 0)
170*cdf0e10cSrcweir         {
171*cdf0e10cSrcweir             ScDocument* pDoc = pDocShell->GetDocument();
172*cdf0e10cSrcweir             if (pDoc)
173*cdf0e10cSrcweir             {
174*cdf0e10cSrcweir                 ScDocOptions aDocOpt(pDoc->GetDocOptions());
175*cdf0e10cSrcweir                 sal_Int32 nValue = 0;
176*cdf0e10cSrcweir                 if (aValue >>= nValue)
177*cdf0e10cSrcweir                 {
178*cdf0e10cSrcweir                     aDocOpt.SetTabDistance(static_cast<sal_uInt16>(HMMToTwips(nValue)));
179*cdf0e10cSrcweir                     pDoc->SetDocOptions(aDocOpt);
180*cdf0e10cSrcweir                 }
181*cdf0e10cSrcweir             }
182*cdf0e10cSrcweir             else
183*cdf0e10cSrcweir                 throw uno::RuntimeException();
184*cdf0e10cSrcweir         }
185*cdf0e10cSrcweir     }
186*cdf0e10cSrcweir     else if ( pEntry->nWID == ATTR_FONT_LANGUAGE ||
187*cdf0e10cSrcweir               pEntry->nWID == ATTR_CJK_FONT_LANGUAGE ||
188*cdf0e10cSrcweir               pEntry->nWID == ATTR_CTL_FONT_LANGUAGE )
189*cdf0e10cSrcweir     {
190*cdf0e10cSrcweir         //  for getPropertyValue the PoolDefaults are sufficient,
191*cdf0e10cSrcweir         //  but setPropertyValue has to be handled differently
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir         lang::Locale aLocale;
194*cdf0e10cSrcweir         if ( aValue >>= aLocale )
195*cdf0e10cSrcweir         {
196*cdf0e10cSrcweir             LanguageType eNew;
197*cdf0e10cSrcweir             if (aLocale.Language.getLength() || aLocale.Country.getLength())
198*cdf0e10cSrcweir                 eNew = MsLangId::convertLocaleToLanguage( aLocale );
199*cdf0e10cSrcweir             else
200*cdf0e10cSrcweir                 eNew = LANGUAGE_NONE;
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir             ScDocument* pDoc = pDocShell->GetDocument();
203*cdf0e10cSrcweir             LanguageType eLatin, eCjk, eCtl;
204*cdf0e10cSrcweir             pDoc->GetLanguage( eLatin, eCjk, eCtl );
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir             if ( pEntry->nWID == ATTR_CJK_FONT_LANGUAGE )
207*cdf0e10cSrcweir                 eCjk = eNew;
208*cdf0e10cSrcweir             else if ( pEntry->nWID == ATTR_CTL_FONT_LANGUAGE )
209*cdf0e10cSrcweir                 eCtl = eNew;
210*cdf0e10cSrcweir             else
211*cdf0e10cSrcweir                 eLatin = eNew;
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir             pDoc->SetLanguage( eLatin, eCjk, eCtl );
214*cdf0e10cSrcweir         }
215*cdf0e10cSrcweir     }
216*cdf0e10cSrcweir     else
217*cdf0e10cSrcweir     {
218*cdf0e10cSrcweir         ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
219*cdf0e10cSrcweir         SfxPoolItem* pNewItem = pPool->GetDefaultItem(pEntry->nWID).Clone();
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir         if( !pNewItem->PutValue( aValue, pEntry->nMemberId ) )
222*cdf0e10cSrcweir             throw lang::IllegalArgumentException();
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir         pPool->SetPoolDefaultItem( *pNewItem );
225*cdf0e10cSrcweir         delete pNewItem;    // copied in SetPoolDefaultItem
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir         ItemsChanged();
228*cdf0e10cSrcweir     }
229*cdf0e10cSrcweir }
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir uno::Any SAL_CALL ScDocDefaultsObj::getPropertyValue( const rtl::OUString& aPropertyName )
232*cdf0e10cSrcweir                 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
233*cdf0e10cSrcweir                         uno::RuntimeException)
234*cdf0e10cSrcweir {
235*cdf0e10cSrcweir     //  use pool default if set
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir     ScUnoGuard aGuard;
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir     if ( !pDocShell )
240*cdf0e10cSrcweir         throw uno::RuntimeException();
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir     uno::Any aRet;
243*cdf0e10cSrcweir     const SfxItemPropertySimpleEntry* pEntry = aPropertyMap.getByName( aPropertyName );
244*cdf0e10cSrcweir     if ( !pEntry )
245*cdf0e10cSrcweir         throw beans::UnknownPropertyException();
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir     if (!pEntry->nWID)
248*cdf0e10cSrcweir     {
249*cdf0e10cSrcweir         if(aPropertyName.compareToAscii(SC_UNO_STANDARDDEC) == 0)
250*cdf0e10cSrcweir         {
251*cdf0e10cSrcweir             ScDocument* pDoc = pDocShell->GetDocument();
252*cdf0e10cSrcweir             if (pDoc)
253*cdf0e10cSrcweir             {
254*cdf0e10cSrcweir                 const ScDocOptions& aDocOpt = pDoc->GetDocOptions();
255*cdf0e10cSrcweir                 sal_uInt16 nPrec = aDocOpt.GetStdPrecision();
256*cdf0e10cSrcweir                 // the max value of unsigned 16-bit integer is used as the flag
257*cdf0e10cSrcweir                 // value for unlimited precision, c.f.
258*cdf0e10cSrcweir                 // SvNumberFormatter::UNLIMITED_PRECISION.
259*cdf0e10cSrcweir                 if (nPrec <= ::std::numeric_limits<sal_Int16>::max())
260*cdf0e10cSrcweir                     aRet <<= static_cast<sal_Int16> (nPrec);
261*cdf0e10cSrcweir             }
262*cdf0e10cSrcweir             else
263*cdf0e10cSrcweir                 throw uno::RuntimeException();
264*cdf0e10cSrcweir         }
265*cdf0e10cSrcweir         else if (aPropertyName.compareToAscii(SC_UNO_TABSTOPDIS) == 0)
266*cdf0e10cSrcweir         {
267*cdf0e10cSrcweir             ScDocument* pDoc = pDocShell->GetDocument();
268*cdf0e10cSrcweir             if (pDoc)
269*cdf0e10cSrcweir             {
270*cdf0e10cSrcweir                 const ScDocOptions& aDocOpt = pDoc->GetDocOptions();
271*cdf0e10cSrcweir                 sal_Int32 nValue (TwipsToEvenHMM(aDocOpt.GetTabDistance()));
272*cdf0e10cSrcweir                 aRet <<= nValue;
273*cdf0e10cSrcweir             }
274*cdf0e10cSrcweir             else
275*cdf0e10cSrcweir                 throw uno::RuntimeException();
276*cdf0e10cSrcweir         }
277*cdf0e10cSrcweir     }
278*cdf0e10cSrcweir     else
279*cdf0e10cSrcweir     {
280*cdf0e10cSrcweir         ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
281*cdf0e10cSrcweir         const SfxPoolItem& rItem = pPool->GetDefaultItem( pEntry->nWID );
282*cdf0e10cSrcweir         rItem.QueryValue( aRet, pEntry->nMemberId );
283*cdf0e10cSrcweir     }
284*cdf0e10cSrcweir     return aRet;
285*cdf0e10cSrcweir }
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir SC_IMPL_DUMMY_PROPERTY_LISTENER( ScDocDefaultsObj )
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir // XPropertyState
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir beans::PropertyState SAL_CALL ScDocDefaultsObj::getPropertyState( const rtl::OUString& aPropertyName )
292*cdf0e10cSrcweir                                 throw(beans::UnknownPropertyException, uno::RuntimeException)
293*cdf0e10cSrcweir {
294*cdf0e10cSrcweir     ScUnoGuard aGuard;
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir     if ( !pDocShell )
297*cdf0e10cSrcweir         throw uno::RuntimeException();
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir     const SfxItemPropertySimpleEntry* pEntry = aPropertyMap.getByName( aPropertyName );
300*cdf0e10cSrcweir     if ( !pEntry )
301*cdf0e10cSrcweir         throw beans::UnknownPropertyException();
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir     beans::PropertyState eRet = beans::PropertyState_DEFAULT_VALUE;
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir     sal_uInt16 nWID = pEntry->nWID;
306*cdf0e10cSrcweir     if ( nWID == ATTR_FONT || nWID == ATTR_CJK_FONT || nWID == ATTR_CTL_FONT || !nWID )
307*cdf0e10cSrcweir     {
308*cdf0e10cSrcweir         //  static default for font is system-dependent,
309*cdf0e10cSrcweir         //  so font default is always treated as "direct value".
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir         eRet = beans::PropertyState_DIRECT_VALUE;
312*cdf0e10cSrcweir     }
313*cdf0e10cSrcweir     else
314*cdf0e10cSrcweir     {
315*cdf0e10cSrcweir         //  check if pool default is set
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir         ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
318*cdf0e10cSrcweir         if ( pPool->GetPoolDefaultItem( nWID ) != NULL )
319*cdf0e10cSrcweir             eRet = beans::PropertyState_DIRECT_VALUE;
320*cdf0e10cSrcweir     }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir     return eRet;
323*cdf0e10cSrcweir }
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir uno::Sequence<beans::PropertyState> SAL_CALL ScDocDefaultsObj::getPropertyStates(
326*cdf0e10cSrcweir                             const uno::Sequence<rtl::OUString>& aPropertyNames )
327*cdf0e10cSrcweir                     throw(beans::UnknownPropertyException, uno::RuntimeException)
328*cdf0e10cSrcweir {
329*cdf0e10cSrcweir     //  the simple way: call getPropertyState
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir     ScUnoGuard aGuard;
332*cdf0e10cSrcweir     const rtl::OUString* pNames = aPropertyNames.getConstArray();
333*cdf0e10cSrcweir     uno::Sequence<beans::PropertyState> aRet(aPropertyNames.getLength());
334*cdf0e10cSrcweir     beans::PropertyState* pStates = aRet.getArray();
335*cdf0e10cSrcweir     for(sal_Int32 i = 0; i < aPropertyNames.getLength(); i++)
336*cdf0e10cSrcweir         pStates[i] = getPropertyState(pNames[i]);
337*cdf0e10cSrcweir     return aRet;
338*cdf0e10cSrcweir }
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir void SAL_CALL ScDocDefaultsObj::setPropertyToDefault( const rtl::OUString& aPropertyName )
341*cdf0e10cSrcweir                             throw(beans::UnknownPropertyException, uno::RuntimeException)
342*cdf0e10cSrcweir {
343*cdf0e10cSrcweir     ScUnoGuard aGuard;
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir     if ( !pDocShell )
346*cdf0e10cSrcweir         throw uno::RuntimeException();
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir     const SfxItemPropertySimpleEntry* pEntry = aPropertyMap.getByName( aPropertyName );
349*cdf0e10cSrcweir     if ( !pEntry )
350*cdf0e10cSrcweir         throw beans::UnknownPropertyException();
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir     if (pEntry->nWID)
353*cdf0e10cSrcweir     {
354*cdf0e10cSrcweir         ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
355*cdf0e10cSrcweir         pPool->ResetPoolDefaultItem( pEntry->nWID );
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir         ItemsChanged();
358*cdf0e10cSrcweir     }
359*cdf0e10cSrcweir }
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir uno::Any SAL_CALL ScDocDefaultsObj::getPropertyDefault( const rtl::OUString& aPropertyName )
362*cdf0e10cSrcweir                             throw(beans::UnknownPropertyException, lang::WrappedTargetException,
363*cdf0e10cSrcweir                                     uno::RuntimeException)
364*cdf0e10cSrcweir {
365*cdf0e10cSrcweir     //  always use static default
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir     ScUnoGuard aGuard;
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir     if ( !pDocShell )
370*cdf0e10cSrcweir         throw uno::RuntimeException();
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir     const SfxItemPropertySimpleEntry* pEntry = aPropertyMap.getByName( aPropertyName );
373*cdf0e10cSrcweir     if ( !pEntry )
374*cdf0e10cSrcweir         throw beans::UnknownPropertyException();
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir     uno::Any aRet;
377*cdf0e10cSrcweir     if (pEntry->nWID)
378*cdf0e10cSrcweir     {
379*cdf0e10cSrcweir         ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
380*cdf0e10cSrcweir         const SfxPoolItem* pItem = pPool->GetItem2( pEntry->nWID, SFX_ITEMS_DEFAULT );
381*cdf0e10cSrcweir         if (pItem)
382*cdf0e10cSrcweir             pItem->QueryValue( aRet, pEntry->nMemberId );
383*cdf0e10cSrcweir     }
384*cdf0e10cSrcweir     return aRet;
385*cdf0e10cSrcweir }
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir 
388