Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <editeng/memberids.hrc>
30 : : #include <svl/smplhint.hxx>
31 : : #include <svl/itemprop.hxx>
32 : : #include <svx/unomid.hxx>
33 : : #include <vcl/svapp.hxx>
34 : : #include <i18npool/mslangid.hxx>
35 : :
36 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
37 : :
38 : : #include "scitems.hxx"
39 : : #include "defltuno.hxx"
40 : : #include "miscuno.hxx"
41 : : #include "docsh.hxx"
42 : : #include "docpool.hxx"
43 : : #include "unonames.hxx"
44 : : #include "docoptio.hxx"
45 : :
46 : : #include <limits>
47 : :
48 : : using namespace ::com::sun::star;
49 : :
50 : : //------------------------------------------------------------------------
51 : :
52 : 98 : const SfxItemPropertyMapEntry* lcl_GetDocDefaultsMap()
53 : : {
54 : : static SfxItemPropertyMapEntry aDocDefaultsMap_Impl[] =
55 : : {
56 [ + - ]: 27 : {MAP_CHAR_LEN(SC_UNONAME_CFCHARS), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET },
57 [ + - ]: 27 : {MAP_CHAR_LEN(SC_UNO_CJK_CFCHARS), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET },
58 [ + - ]: 27 : {MAP_CHAR_LEN(SC_UNO_CTL_CFCHARS), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET },
59 [ + - ]: 27 : {MAP_CHAR_LEN(SC_UNONAME_CFFAMIL), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY },
60 [ + - ]: 27 : {MAP_CHAR_LEN(SC_UNO_CJK_CFFAMIL), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY },
61 [ + - ]: 27 : {MAP_CHAR_LEN(SC_UNO_CTL_CFFAMIL), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY },
62 [ + - ]: 27 : {MAP_CHAR_LEN(SC_UNONAME_CFNAME), ATTR_FONT, &getCppuType((rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME },
63 [ + - ]: 27 : {MAP_CHAR_LEN(SC_UNO_CJK_CFNAME), ATTR_CJK_FONT, &getCppuType((rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME },
64 [ + - ]: 27 : {MAP_CHAR_LEN(SC_UNO_CTL_CFNAME), ATTR_CTL_FONT, &getCppuType((rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME },
65 [ + - ]: 27 : {MAP_CHAR_LEN(SC_UNONAME_CFPITCH), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH },
66 [ + - ]: 27 : {MAP_CHAR_LEN(SC_UNO_CJK_CFPITCH), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH },
67 [ + - ]: 27 : {MAP_CHAR_LEN(SC_UNO_CTL_CFPITCH), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH },
68 [ + - ]: 27 : {MAP_CHAR_LEN(SC_UNONAME_CFSTYLE), ATTR_FONT, &getCppuType((rtl::OUString*)0), 0, MID_FONT_STYLE_NAME },
69 [ + - ]: 27 : {MAP_CHAR_LEN(SC_UNO_CJK_CFSTYLE), ATTR_CJK_FONT, &getCppuType((rtl::OUString*)0), 0, MID_FONT_STYLE_NAME },
70 [ + - ]: 27 : {MAP_CHAR_LEN(SC_UNO_CTL_CFSTYLE), ATTR_CTL_FONT, &getCppuType((rtl::OUString*)0), 0, MID_FONT_STYLE_NAME },
71 [ + - ]: 27 : {MAP_CHAR_LEN(SC_UNONAME_CLOCAL), ATTR_FONT_LANGUAGE, &getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE },
72 [ + - ]: 27 : {MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL), ATTR_CJK_FONT_LANGUAGE, &getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE },
73 [ + - ]: 27 : {MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL), ATTR_CTL_FONT_LANGUAGE, &getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE },
74 [ + - ]: 27 : {MAP_CHAR_LEN(SC_UNO_STANDARDDEC), 0, &getCppuType((sal_Int16*)0), 0, 0 },
75 [ + - ]: 27 : {MAP_CHAR_LEN(SC_UNO_TABSTOPDIS), 0, &getCppuType((sal_Int32*)0), 0, 0 },
76 : : {0,0,0,0,0,0}
77 [ + + ][ + - ]: 125 : };
[ # # ]
78 : 98 : return aDocDefaultsMap_Impl;
79 : : }
80 : :
81 : : using sc::HMMToTwips;
82 : : using sc::TwipsToHMM;
83 : : using sc::TwipsToEvenHMM;
84 : :
85 : : //------------------------------------------------------------------------
86 : :
87 [ # # ]: 0 : SC_SIMPLE_SERVICE_INFO( ScDocDefaultsObj, "ScDocDefaultsObj", "com.sun.star.sheet.Defaults" )
88 : :
89 : : //------------------------------------------------------------------------
90 : :
91 : 98 : ScDocDefaultsObj::ScDocDefaultsObj(ScDocShell* pDocSh) :
92 : : pDocShell( pDocSh ),
93 [ + - ][ + - ]: 98 : aPropertyMap(lcl_GetDocDefaultsMap())
[ + - ]
94 : : {
95 [ + - ]: 98 : pDocShell->GetDocument()->AddUnoObject(*this);
96 : 98 : }
97 : :
98 [ + - ][ + - ]: 98 : ScDocDefaultsObj::~ScDocDefaultsObj()
99 : : {
100 [ + + ]: 98 : if (pDocShell)
101 [ + - ]: 97 : pDocShell->GetDocument()->RemoveUnoObject(*this);
102 [ - + ]: 196 : }
103 : :
104 : 65 : void ScDocDefaultsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
105 : : {
106 [ + - + + ]: 130 : if ( rHint.ISA( SfxSimpleHint ) &&
[ + + ]
107 : 65 : ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
108 : : {
109 : 1 : pDocShell = NULL; // document gone
110 : : }
111 : 65 : }
112 : :
113 : 1395 : void ScDocDefaultsObj::ItemsChanged()
114 : : {
115 [ + - ]: 1395 : if (pDocShell)
116 : : {
117 : : //! if not in XML import, adjust row heights
118 : :
119 [ + - ][ + - ]: 1395 : pDocShell->PostPaint(ScRange(0, 0, 0, MAXCOL, MAXROW, MAXTAB), PAINT_GRID);
[ + - ]
120 : : }
121 : 1395 : }
122 : :
123 : : // XPropertySet
124 : :
125 : 101 : uno::Reference<beans::XPropertySetInfo> SAL_CALL ScDocDefaultsObj::getPropertySetInfo()
126 : : throw(uno::RuntimeException)
127 : : {
128 [ + - ]: 101 : SolarMutexGuard aGuard;
129 : : static uno::Reference<beans::XPropertySetInfo> aRef = new SfxItemPropertySetInfo(
130 [ + + ][ + - ]: 101 : aPropertyMap );
[ + - ][ + - ]
[ + - ][ # # ]
131 [ + - ]: 101 : return aRef;
132 : : }
133 : :
134 : 1779 : void SAL_CALL ScDocDefaultsObj::setPropertyValue(
135 : : const rtl::OUString& aPropertyName, const uno::Any& aValue )
136 : : throw(beans::UnknownPropertyException, beans::PropertyVetoException,
137 : : lang::IllegalArgumentException, lang::WrappedTargetException,
138 : : uno::RuntimeException)
139 : : {
140 [ + - ]: 1779 : SolarMutexGuard aGuard;
141 : :
142 [ - + ]: 1779 : if ( !pDocShell )
143 [ # # ]: 0 : throw uno::RuntimeException();
144 : :
145 [ + - ]: 1779 : const SfxItemPropertySimpleEntry* pEntry = aPropertyMap.getByName( aPropertyName );
146 [ - + ]: 1779 : if ( !pEntry )
147 [ # # ]: 0 : throw beans::UnknownPropertyException();
148 [ + + ]: 1779 : if(!pEntry->nWID)
149 : : {
150 [ + + ]: 105 : if(aPropertyName.compareToAscii(SC_UNO_STANDARDDEC) == 0)
151 : : {
152 : 12 : ScDocument* pDoc = pDocShell->GetDocument();
153 [ + - ]: 12 : if (pDoc)
154 : : {
155 [ + - ][ + - ]: 12 : ScDocOptions aDocOpt(pDoc->GetDocOptions());
156 : 12 : sal_Int16 nValue = 0;
157 [ + - ]: 12 : if (aValue >>= nValue)
158 : : {
159 : 12 : aDocOpt.SetStdPrecision(static_cast<sal_uInt16> (nValue));
160 [ + - ]: 12 : pDoc->SetDocOptions(aDocOpt);
161 [ + - ]: 12 : }
162 : : }
163 : : else
164 [ # # ]: 0 : throw uno::RuntimeException();
165 : : }
166 [ + - ]: 93 : else if (aPropertyName.compareToAscii(SC_UNO_TABSTOPDIS) == 0)
167 : : {
168 : 93 : ScDocument* pDoc = pDocShell->GetDocument();
169 [ + - ]: 93 : if (pDoc)
170 : : {
171 [ + - ][ + - ]: 93 : ScDocOptions aDocOpt(pDoc->GetDocOptions());
172 : 93 : sal_Int32 nValue = 0;
173 [ + - ]: 93 : if (aValue >>= nValue)
174 : : {
175 : 93 : aDocOpt.SetTabDistance(static_cast<sal_uInt16>(HMMToTwips(nValue)));
176 [ + - ]: 93 : pDoc->SetDocOptions(aDocOpt);
177 [ + - ]: 93 : }
178 : : }
179 : : else
180 [ # # ]: 0 : throw uno::RuntimeException();
181 : : }
182 : : }
183 [ + + ][ + + ]: 1674 : else if ( pEntry->nWID == ATTR_FONT_LANGUAGE ||
[ + + ]
184 : : pEntry->nWID == ATTR_CJK_FONT_LANGUAGE ||
185 : : pEntry->nWID == ATTR_CTL_FONT_LANGUAGE )
186 : : {
187 : : // for getPropertyValue the PoolDefaults are sufficient,
188 : : // but setPropertyValue has to be handled differently
189 : :
190 : 279 : lang::Locale aLocale;
191 [ + - ][ + - ]: 279 : if ( aValue >>= aLocale )
192 : : {
193 : : LanguageType eNew;
194 [ + + ][ - + ]: 279 : if (!aLocale.Language.isEmpty() || !aLocale.Country.isEmpty())
[ + + ]
195 [ + - ]: 267 : eNew = MsLangId::convertLocaleToLanguage( aLocale );
196 : : else
197 : 12 : eNew = LANGUAGE_NONE;
198 : :
199 : 279 : ScDocument* pDoc = pDocShell->GetDocument();
200 : : LanguageType eLatin, eCjk, eCtl;
201 [ + - ]: 279 : pDoc->GetLanguage( eLatin, eCjk, eCtl );
202 : :
203 [ + + ]: 279 : if ( pEntry->nWID == ATTR_CJK_FONT_LANGUAGE )
204 : 93 : eCjk = eNew;
205 [ + + ]: 186 : else if ( pEntry->nWID == ATTR_CTL_FONT_LANGUAGE )
206 : 93 : eCtl = eNew;
207 : : else
208 : 93 : eLatin = eNew;
209 : :
210 [ + - ]: 279 : pDoc->SetLanguage( eLatin, eCjk, eCtl );
211 : 279 : }
212 : : }
213 : : else
214 : : {
215 [ + - ]: 1395 : ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
216 [ + - ][ + - ]: 1395 : SfxPoolItem* pNewItem = pPool->GetDefaultItem(pEntry->nWID).Clone();
217 : :
218 [ + - ][ - + ]: 1395 : if( !pNewItem->PutValue( aValue, pEntry->nMemberId ) )
219 [ # # ]: 0 : throw lang::IllegalArgumentException();
220 : :
221 [ + - ]: 1395 : pPool->SetPoolDefaultItem( *pNewItem );
222 [ + - ][ + - ]: 1395 : delete pNewItem; // copied in SetPoolDefaultItem
223 : :
224 [ + - ]: 1395 : ItemsChanged();
225 [ + - ]: 1779 : }
226 : 1779 : }
227 : :
228 : 80 : uno::Any SAL_CALL ScDocDefaultsObj::getPropertyValue( const rtl::OUString& aPropertyName )
229 : : throw(beans::UnknownPropertyException, lang::WrappedTargetException,
230 : : uno::RuntimeException)
231 : : {
232 : : // use pool default if set
233 : :
234 [ + - ]: 80 : SolarMutexGuard aGuard;
235 : :
236 [ - + ]: 80 : if ( !pDocShell )
237 [ # # ]: 0 : throw uno::RuntimeException();
238 : :
239 : 80 : uno::Any aRet;
240 [ + - ]: 80 : const SfxItemPropertySimpleEntry* pEntry = aPropertyMap.getByName( aPropertyName );
241 [ - + ]: 80 : if ( !pEntry )
242 [ # # ]: 0 : throw beans::UnknownPropertyException();
243 : :
244 [ + + ]: 80 : if (!pEntry->nWID)
245 : : {
246 [ + + ]: 8 : if(aPropertyName.compareToAscii(SC_UNO_STANDARDDEC) == 0)
247 : : {
248 : 4 : ScDocument* pDoc = pDocShell->GetDocument();
249 [ + - ]: 4 : if (pDoc)
250 : : {
251 [ + - ]: 4 : const ScDocOptions& aDocOpt = pDoc->GetDocOptions();
252 : 4 : sal_uInt16 nPrec = aDocOpt.GetStdPrecision();
253 : : // the max value of unsigned 16-bit integer is used as the flag
254 : : // value for unlimited precision, c.f.
255 : : // SvNumberFormatter::UNLIMITED_PRECISION.
256 [ - + ]: 4 : if (nPrec <= ::std::numeric_limits<sal_Int16>::max())
257 [ # # ]: 0 : aRet <<= static_cast<sal_Int16> (nPrec);
258 : : }
259 : : else
260 [ # # ]: 0 : throw uno::RuntimeException();
261 : : }
262 [ + - ]: 4 : else if (aPropertyName.compareToAscii(SC_UNO_TABSTOPDIS) == 0)
263 : : {
264 : 4 : ScDocument* pDoc = pDocShell->GetDocument();
265 [ + - ]: 4 : if (pDoc)
266 : : {
267 [ + - ]: 4 : const ScDocOptions& aDocOpt = pDoc->GetDocOptions();
268 : 4 : sal_Int32 nValue (TwipsToEvenHMM(aDocOpt.GetTabDistance()));
269 [ + - ]: 4 : aRet <<= nValue;
270 : : }
271 : : else
272 [ # # ]: 0 : throw uno::RuntimeException();
273 : : }
274 : : }
275 : : else
276 : : {
277 [ + - ]: 72 : ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
278 [ + - ]: 72 : const SfxPoolItem& rItem = pPool->GetDefaultItem( pEntry->nWID );
279 [ + - ]: 72 : rItem.QueryValue( aRet, pEntry->nMemberId );
280 : : }
281 [ + - ]: 80 : return aRet;
282 : : }
283 : :
284 : 0 : SC_IMPL_DUMMY_PROPERTY_LISTENER( ScDocDefaultsObj )
285 : :
286 : : // XPropertyState
287 : :
288 : 80 : beans::PropertyState SAL_CALL ScDocDefaultsObj::getPropertyState( const rtl::OUString& aPropertyName )
289 : : throw(beans::UnknownPropertyException, uno::RuntimeException)
290 : : {
291 [ + - ]: 80 : SolarMutexGuard aGuard;
292 : :
293 [ - + ]: 80 : if ( !pDocShell )
294 [ # # ]: 0 : throw uno::RuntimeException();
295 : :
296 [ + - ]: 80 : const SfxItemPropertySimpleEntry* pEntry = aPropertyMap.getByName( aPropertyName );
297 [ - + ]: 80 : if ( !pEntry )
298 [ # # ]: 0 : throw beans::UnknownPropertyException();
299 : :
300 : 80 : beans::PropertyState eRet = beans::PropertyState_DEFAULT_VALUE;
301 : :
302 : 80 : sal_uInt16 nWID = pEntry->nWID;
303 [ + + ][ + + ]: 80 : if ( nWID == ATTR_FONT || nWID == ATTR_CJK_FONT || nWID == ATTR_CTL_FONT || !nWID )
[ + + ][ + + ]
304 : : {
305 : : // static default for font is system-dependent,
306 : : // so font default is always treated as "direct value".
307 : :
308 : 68 : eRet = beans::PropertyState_DIRECT_VALUE;
309 : : }
310 : : else
311 : : {
312 : : // check if pool default is set
313 : :
314 [ + - ]: 12 : ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
315 [ + - ][ + - ]: 12 : if ( pPool->GetPoolDefaultItem( nWID ) != NULL )
316 : 12 : eRet = beans::PropertyState_DIRECT_VALUE;
317 : : }
318 : :
319 [ + - ]: 80 : return eRet;
320 : : }
321 : :
322 : 4 : uno::Sequence<beans::PropertyState> SAL_CALL ScDocDefaultsObj::getPropertyStates(
323 : : const uno::Sequence<rtl::OUString>& aPropertyNames )
324 : : throw(beans::UnknownPropertyException, uno::RuntimeException)
325 : : {
326 : : // the simple way: call getPropertyState
327 : :
328 [ + - ]: 4 : SolarMutexGuard aGuard;
329 : 4 : const rtl::OUString* pNames = aPropertyNames.getConstArray();
330 [ + - ]: 4 : uno::Sequence<beans::PropertyState> aRet(aPropertyNames.getLength());
331 [ + - ]: 4 : beans::PropertyState* pStates = aRet.getArray();
332 [ + + ]: 84 : for(sal_Int32 i = 0; i < aPropertyNames.getLength(); i++)
333 [ + - ]: 80 : pStates[i] = getPropertyState(pNames[i]);
334 [ + - ]: 4 : return aRet;
335 : : }
336 : :
337 : 0 : void SAL_CALL ScDocDefaultsObj::setPropertyToDefault( const rtl::OUString& aPropertyName )
338 : : throw(beans::UnknownPropertyException, uno::RuntimeException)
339 : : {
340 [ # # ]: 0 : SolarMutexGuard aGuard;
341 : :
342 [ # # ]: 0 : if ( !pDocShell )
343 [ # # ]: 0 : throw uno::RuntimeException();
344 : :
345 [ # # ]: 0 : const SfxItemPropertySimpleEntry* pEntry = aPropertyMap.getByName( aPropertyName );
346 [ # # ]: 0 : if ( !pEntry )
347 [ # # ]: 0 : throw beans::UnknownPropertyException();
348 : :
349 [ # # ]: 0 : if (pEntry->nWID)
350 : : {
351 [ # # ]: 0 : ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
352 [ # # ]: 0 : pPool->ResetPoolDefaultItem( pEntry->nWID );
353 : :
354 [ # # ]: 0 : ItemsChanged();
355 [ # # ]: 0 : }
356 : 0 : }
357 : :
358 : 0 : uno::Any SAL_CALL ScDocDefaultsObj::getPropertyDefault( const rtl::OUString& aPropertyName )
359 : : throw(beans::UnknownPropertyException, lang::WrappedTargetException,
360 : : uno::RuntimeException)
361 : : {
362 : : // always use static default
363 : :
364 [ # # ]: 0 : SolarMutexGuard aGuard;
365 : :
366 [ # # ]: 0 : if ( !pDocShell )
367 [ # # ]: 0 : throw uno::RuntimeException();
368 : :
369 [ # # ]: 0 : const SfxItemPropertySimpleEntry* pEntry = aPropertyMap.getByName( aPropertyName );
370 [ # # ]: 0 : if ( !pEntry )
371 [ # # ]: 0 : throw beans::UnknownPropertyException();
372 : :
373 : 0 : uno::Any aRet;
374 [ # # ]: 0 : if (pEntry->nWID)
375 : : {
376 [ # # ]: 0 : ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
377 [ # # ]: 0 : const SfxPoolItem* pItem = pPool->GetItem2( pEntry->nWID, SFX_ITEMS_DEFAULT );
378 [ # # ]: 0 : if (pItem)
379 [ # # ]: 0 : pItem->QueryValue( aRet, pEntry->nMemberId );
380 : : }
381 [ # # ]: 0 : return aRet;
382 : : }
383 : :
384 : :
385 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|