fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / unoobj / defltuno.cxx
blob9e3b939c03d1c022053d6394357d5bccd8fb634c
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 <editeng/memberids.hrc>
21 #include <svl/smplhint.hxx>
22 #include <svl/itemprop.hxx>
23 #include <svx/unomid.hxx>
24 #include <vcl/svapp.hxx>
25 #include <i18nlangtag/languagetag.hxx>
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include "scitems.hxx"
30 #include "defltuno.hxx"
31 #include "miscuno.hxx"
32 #include "docsh.hxx"
33 #include "docpool.hxx"
34 #include "unonames.hxx"
35 #include "docoptio.hxx"
37 #include <limits>
39 using namespace ::com::sun::star;
41 static const SfxItemPropertyMapEntry* lcl_GetDocDefaultsMap()
43 static const SfxItemPropertyMapEntry aDocDefaultsMap_Impl[] =
45 {OUString(SC_UNONAME_CFCHARS), ATTR_FONT, cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_CHAR_SET },
46 {OUString(SC_UNO_CJK_CFCHARS), ATTR_CJK_FONT, cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_CHAR_SET },
47 {OUString(SC_UNO_CTL_CFCHARS), ATTR_CTL_FONT, cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_CHAR_SET },
48 {OUString(SC_UNONAME_CFFAMIL), ATTR_FONT, cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_FAMILY },
49 {OUString(SC_UNO_CJK_CFFAMIL), ATTR_CJK_FONT, cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_FAMILY },
50 {OUString(SC_UNO_CTL_CFFAMIL), ATTR_CTL_FONT, cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_FAMILY },
51 {OUString(SC_UNONAME_CFNAME), ATTR_FONT, cppu::UnoType<OUString>::get(), 0, MID_FONT_FAMILY_NAME },
52 {OUString(SC_UNO_CJK_CFNAME), ATTR_CJK_FONT, cppu::UnoType<OUString>::get(), 0, MID_FONT_FAMILY_NAME },
53 {OUString(SC_UNO_CTL_CFNAME), ATTR_CTL_FONT, cppu::UnoType<OUString>::get(), 0, MID_FONT_FAMILY_NAME },
54 {OUString(SC_UNONAME_CFPITCH), ATTR_FONT, cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_PITCH },
55 {OUString(SC_UNO_CJK_CFPITCH), ATTR_CJK_FONT, cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_PITCH },
56 {OUString(SC_UNO_CTL_CFPITCH), ATTR_CTL_FONT, cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_PITCH },
57 {OUString(SC_UNONAME_CFSTYLE), ATTR_FONT, cppu::UnoType<OUString>::get(), 0, MID_FONT_STYLE_NAME },
58 {OUString(SC_UNO_CJK_CFSTYLE), ATTR_CJK_FONT, cppu::UnoType<OUString>::get(), 0, MID_FONT_STYLE_NAME },
59 {OUString(SC_UNO_CTL_CFSTYLE), ATTR_CTL_FONT, cppu::UnoType<OUString>::get(), 0, MID_FONT_STYLE_NAME },
60 {OUString(SC_UNONAME_CLOCAL), ATTR_FONT_LANGUAGE, cppu::UnoType<lang::Locale>::get(), 0, MID_LANG_LOCALE },
61 {OUString(SC_UNO_CJK_CLOCAL), ATTR_CJK_FONT_LANGUAGE, cppu::UnoType<lang::Locale>::get(), 0, MID_LANG_LOCALE },
62 {OUString(SC_UNO_CTL_CLOCAL), ATTR_CTL_FONT_LANGUAGE, cppu::UnoType<lang::Locale>::get(), 0, MID_LANG_LOCALE },
63 {OUString(SC_UNO_STANDARDDEC), 0, cppu::UnoType<sal_Int16>::get(), 0, 0 },
64 {OUString(SC_UNO_TABSTOPDIS), 0, cppu::UnoType<sal_Int32>::get(), 0, 0 },
65 { OUString(), 0, css::uno::Type(), 0, 0 }
67 return aDocDefaultsMap_Impl;
70 using sc::HMMToTwips;
71 using sc::TwipsToHMM;
72 using sc::TwipsToEvenHMM;
74 SC_SIMPLE_SERVICE_INFO( ScDocDefaultsObj, "ScDocDefaultsObj", "com.sun.star.sheet.Defaults" )
76 ScDocDefaultsObj::ScDocDefaultsObj(ScDocShell* pDocSh) :
77 pDocShell( pDocSh ),
78 aPropertyMap(lcl_GetDocDefaultsMap())
80 pDocShell->GetDocument().AddUnoObject(*this);
83 ScDocDefaultsObj::~ScDocDefaultsObj()
85 SolarMutexGuard g;
87 if (pDocShell)
88 pDocShell->GetDocument().RemoveUnoObject(*this);
91 void ScDocDefaultsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
93 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
94 if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DYING )
96 pDocShell = NULL; // document gone
100 void ScDocDefaultsObj::ItemsChanged()
102 if (pDocShell)
104 //! if not in XML import, adjust row heights
106 pDocShell->PostPaint(ScRange(0, 0, 0, MAXCOL, MAXROW, MAXTAB), PAINT_GRID);
110 // XPropertySet
112 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScDocDefaultsObj::getPropertySetInfo()
113 throw(uno::RuntimeException, std::exception)
115 SolarMutexGuard aGuard;
116 static uno::Reference<beans::XPropertySetInfo> aRef = new SfxItemPropertySetInfo(
117 aPropertyMap );
118 return aRef;
121 void SAL_CALL ScDocDefaultsObj::setPropertyValue(
122 const OUString& aPropertyName, const uno::Any& aValue )
123 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
124 lang::IllegalArgumentException, lang::WrappedTargetException,
125 uno::RuntimeException, std::exception)
127 SolarMutexGuard aGuard;
129 if ( !pDocShell )
130 throw uno::RuntimeException();
132 const SfxItemPropertySimpleEntry* pEntry = aPropertyMap.getByName( aPropertyName );
133 if ( !pEntry )
134 throw beans::UnknownPropertyException();
135 if(!pEntry->nWID)
137 if(aPropertyName ==SC_UNO_STANDARDDEC)
139 ScDocument& rDoc = pDocShell->GetDocument();
140 ScDocOptions aDocOpt(rDoc.GetDocOptions());
141 sal_Int16 nValue = 0;
142 if (aValue >>= nValue)
144 aDocOpt.SetStdPrecision(static_cast<sal_uInt16> (nValue));
145 rDoc.SetDocOptions(aDocOpt);
148 else if (aPropertyName == SC_UNO_TABSTOPDIS)
150 ScDocument& rDoc = pDocShell->GetDocument();
151 ScDocOptions aDocOpt(rDoc.GetDocOptions());
152 sal_Int32 nValue = 0;
153 if (aValue >>= nValue)
155 aDocOpt.SetTabDistance(static_cast<sal_uInt16>(HMMToTwips(nValue)));
156 rDoc.SetDocOptions(aDocOpt);
160 else if ( pEntry->nWID == ATTR_FONT_LANGUAGE ||
161 pEntry->nWID == ATTR_CJK_FONT_LANGUAGE ||
162 pEntry->nWID == ATTR_CTL_FONT_LANGUAGE )
164 // for getPropertyValue the PoolDefaults are sufficient,
165 // but setPropertyValue has to be handled differently
167 lang::Locale aLocale;
168 if ( aValue >>= aLocale )
170 LanguageType eNew;
171 if (!aLocale.Language.isEmpty() || !aLocale.Country.isEmpty())
172 eNew = LanguageTag::convertToLanguageType( aLocale, false);
173 else
174 eNew = LANGUAGE_NONE;
176 ScDocument& rDoc = pDocShell->GetDocument();
177 LanguageType eLatin, eCjk, eCtl;
178 rDoc.GetLanguage( eLatin, eCjk, eCtl );
180 if ( pEntry->nWID == ATTR_CJK_FONT_LANGUAGE )
181 eCjk = eNew;
182 else if ( pEntry->nWID == ATTR_CTL_FONT_LANGUAGE )
183 eCtl = eNew;
184 else
185 eLatin = eNew;
187 rDoc.SetLanguage( eLatin, eCjk, eCtl );
190 else
192 ScDocumentPool* pPool = pDocShell->GetDocument().GetPool();
193 SfxPoolItem* pNewItem = pPool->GetDefaultItem(pEntry->nWID).Clone();
195 if( !pNewItem->PutValue( aValue, pEntry->nMemberId ) )
196 throw lang::IllegalArgumentException();
198 pPool->SetPoolDefaultItem( *pNewItem );
199 delete pNewItem; // copied in SetPoolDefaultItem
201 ItemsChanged();
205 uno::Any SAL_CALL ScDocDefaultsObj::getPropertyValue( const OUString& aPropertyName )
206 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
207 uno::RuntimeException, std::exception)
209 // use pool default if set
211 SolarMutexGuard aGuard;
213 if ( !pDocShell )
214 throw uno::RuntimeException();
216 uno::Any aRet;
217 const SfxItemPropertySimpleEntry* pEntry = aPropertyMap.getByName( aPropertyName );
218 if ( !pEntry )
219 throw beans::UnknownPropertyException();
221 if (!pEntry->nWID)
223 if(aPropertyName == SC_UNO_STANDARDDEC)
225 ScDocument& rDoc = pDocShell->GetDocument();
226 const ScDocOptions& aDocOpt = rDoc.GetDocOptions();
227 sal_uInt16 nPrec = aDocOpt.GetStdPrecision();
228 // the max value of unsigned 16-bit integer is used as the flag
229 // value for unlimited precision, c.f.
230 // SvNumberFormatter::UNLIMITED_PRECISION.
231 if (nPrec <= ::std::numeric_limits<sal_Int16>::max())
232 aRet <<= static_cast<sal_Int16> (nPrec);
234 else if (aPropertyName == SC_UNO_TABSTOPDIS)
236 ScDocument& rDoc = pDocShell->GetDocument();
237 const ScDocOptions& aDocOpt = rDoc.GetDocOptions();
238 sal_Int32 nValue (TwipsToEvenHMM(aDocOpt.GetTabDistance()));
239 aRet <<= nValue;
242 else
244 ScDocumentPool* pPool = pDocShell->GetDocument().GetPool();
245 const SfxPoolItem& rItem = pPool->GetDefaultItem( pEntry->nWID );
246 rItem.QueryValue( aRet, pEntry->nMemberId );
248 return aRet;
251 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScDocDefaultsObj )
253 // XPropertyState
255 beans::PropertyState SAL_CALL ScDocDefaultsObj::getPropertyState( const OUString& aPropertyName )
256 throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
258 SolarMutexGuard aGuard;
260 if ( !pDocShell )
261 throw uno::RuntimeException();
263 const SfxItemPropertySimpleEntry* pEntry = aPropertyMap.getByName( aPropertyName );
264 if ( !pEntry )
265 throw beans::UnknownPropertyException();
267 beans::PropertyState eRet = beans::PropertyState_DEFAULT_VALUE;
269 sal_uInt16 nWID = pEntry->nWID;
270 if ( nWID == ATTR_FONT || nWID == ATTR_CJK_FONT || nWID == ATTR_CTL_FONT || !nWID )
272 // static default for font is system-dependent,
273 // so font default is always treated as "direct value".
275 eRet = beans::PropertyState_DIRECT_VALUE;
277 else
279 // check if pool default is set
281 ScDocumentPool* pPool = pDocShell->GetDocument().GetPool();
282 if ( pPool->GetPoolDefaultItem( nWID ) != NULL )
283 eRet = beans::PropertyState_DIRECT_VALUE;
286 return eRet;
289 uno::Sequence<beans::PropertyState> SAL_CALL ScDocDefaultsObj::getPropertyStates(
290 const uno::Sequence<OUString>& aPropertyNames )
291 throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
293 // the simple way: call getPropertyState
295 SolarMutexGuard aGuard;
296 const OUString* pNames = aPropertyNames.getConstArray();
297 uno::Sequence<beans::PropertyState> aRet(aPropertyNames.getLength());
298 beans::PropertyState* pStates = aRet.getArray();
299 for(sal_Int32 i = 0; i < aPropertyNames.getLength(); i++)
300 pStates[i] = getPropertyState(pNames[i]);
301 return aRet;
304 void SAL_CALL ScDocDefaultsObj::setPropertyToDefault( const OUString& aPropertyName )
305 throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
307 SolarMutexGuard aGuard;
309 if ( !pDocShell )
310 throw uno::RuntimeException();
312 const SfxItemPropertySimpleEntry* pEntry = aPropertyMap.getByName( aPropertyName );
313 if ( !pEntry )
314 throw beans::UnknownPropertyException();
316 if (pEntry->nWID)
318 ScDocumentPool* pPool = pDocShell->GetDocument().GetPool();
319 pPool->ResetPoolDefaultItem( pEntry->nWID );
321 ItemsChanged();
325 uno::Any SAL_CALL ScDocDefaultsObj::getPropertyDefault( const OUString& aPropertyName )
326 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
327 uno::RuntimeException, std::exception)
329 // always use static default
331 SolarMutexGuard aGuard;
333 if ( !pDocShell )
334 throw uno::RuntimeException();
336 const SfxItemPropertySimpleEntry* pEntry = aPropertyMap.getByName( aPropertyName );
337 if ( !pEntry )
338 throw beans::UnknownPropertyException();
340 uno::Any aRet;
341 if (pEntry->nWID)
343 ScDocumentPool* pPool = pDocShell->GetDocument().GetPool();
344 const SfxPoolItem* pItem = pPool->GetItem2Default( pEntry->nWID );
345 if (pItem)
346 pItem->QueryValue( aRet, pEntry->nMemberId );
348 return aRet;
351 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */