LibreOffice Module sc (master) 1
defltuno.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <editeng/memberids.h>
21#include <svl/hint.hxx>
22#include <svl/itemprop.hxx>
23#include <vcl/svapp.hxx>
25
26#include <scitems.hxx>
27#include <defltuno.hxx>
28#include <miscuno.hxx>
29#include <docsh.hxx>
30#include <docpool.hxx>
31#include <unonames.hxx>
32#include <docoptio.hxx>
33
34#include <limits>
35
36class SvxFontItem;
37using namespace ::com::sun::star;
38
40{
41 static const SfxItemPropertyMapEntry aDocDefaultsMap_Impl[] =
42 {
66 { u"", 0, css::uno::Type(), 0, 0 }
67 };
68 return aDocDefaultsMap_Impl;
69}
70
72
73SC_SIMPLE_SERVICE_INFO( ScDocDefaultsObj, "ScDocDefaultsObj", "com.sun.star.sheet.Defaults" )
74
76 pDocShell( pDocSh ),
77 aPropertyMap(lcl_GetDocDefaultsMap())
78{
79 pDocShell->GetDocument().AddUnoObject(*this);
80}
81
83{
85
86 if (pDocShell)
88}
89
91{
92 if ( rHint.GetId() == SfxHintId::Dying )
93 {
94 pDocShell = nullptr; // document gone
95 }
96}
97
99{
100 if (pDocShell)
101 {
103 const auto & rDoc = pDocShell->GetDocument();
104 pDocShell->PostPaint(ScRange(0, 0, 0, rDoc.MaxCol(), rDoc.MaxRow(), MAXTAB), PaintPartFlags::Grid);
105 }
106}
107
108// XPropertySet
109
110uno::Reference<beans::XPropertySetInfo> SAL_CALL ScDocDefaultsObj::getPropertySetInfo()
111{
112 SolarMutexGuard aGuard;
113 static uno::Reference<beans::XPropertySetInfo> aRef = new SfxItemPropertySetInfo(
114 aPropertyMap );
115 return aRef;
116}
117
119 const OUString& aPropertyName, const uno::Any& aValue )
120{
121 SolarMutexGuard aGuard;
122
123 if ( !pDocShell )
124 throw uno::RuntimeException();
125
126 const SfxItemPropertyMapEntry* pEntry = aPropertyMap.getByName( aPropertyName );
127 if ( !pEntry )
128 throw beans::UnknownPropertyException(aPropertyName);
129 if(!pEntry->nWID)
130 {
131 if(aPropertyName ==SC_UNO_STANDARDDEC)
132 {
134 ScDocOptions aDocOpt(rDoc.GetDocOptions());
135 sal_Int16 nValue = 0;
136 if (aValue >>= nValue)
137 {
138 aDocOpt.SetStdPrecision(static_cast<sal_uInt16> (nValue));
139 rDoc.SetDocOptions(aDocOpt);
140 }
141 }
142 else if (aPropertyName == SC_UNO_TABSTOPDIS)
143 {
145 ScDocOptions aDocOpt(rDoc.GetDocOptions());
146 sal_Int32 nValue = 0;
147 if (aValue >>= nValue)
148 {
150 rDoc.SetDocOptions(aDocOpt);
151 }
152 }
153 }
154 else if ( pEntry->nWID == ATTR_FONT_LANGUAGE ||
155 pEntry->nWID == ATTR_CJK_FONT_LANGUAGE ||
156 pEntry->nWID == ATTR_CTL_FONT_LANGUAGE )
157 {
158 // for getPropertyValue the PoolDefaults are sufficient,
159 // but setPropertyValue has to be handled differently
160
161 lang::Locale aLocale;
162 if ( aValue >>= aLocale )
163 {
164 LanguageType eNew;
165 if (!aLocale.Language.isEmpty() || !aLocale.Country.isEmpty())
166 eNew = LanguageTag::convertToLanguageType( aLocale, false);
167 else
168 eNew = LANGUAGE_NONE;
169
171 LanguageType eLatin, eCjk, eCtl;
172 rDoc.GetLanguage( eLatin, eCjk, eCtl );
173
174 if ( pEntry->nWID == ATTR_CJK_FONT_LANGUAGE )
175 eCjk = eNew;
176 else if ( pEntry->nWID == ATTR_CTL_FONT_LANGUAGE )
177 eCtl = eNew;
178 else
179 eLatin = eNew;
180
181 rDoc.SetLanguage( eLatin, eCjk, eCtl );
182 }
183 }
184 else
185 {
187 std::unique_ptr<SfxPoolItem> pNewItem(pPool->GetDefaultItem(pEntry->nWID).Clone());
188
189 if( !pNewItem->PutValue( aValue, pEntry->nMemberId ) )
190 throw lang::IllegalArgumentException();
191
192 pPool->SetPoolDefaultItem( *pNewItem );
193
194 ItemsChanged();
195 }
196}
197
198uno::Any SAL_CALL ScDocDefaultsObj::getPropertyValue( const OUString& aPropertyName )
199{
200 // use pool default if set
201
202 SolarMutexGuard aGuard;
203
204 if ( !pDocShell )
205 throw uno::RuntimeException();
206
207 uno::Any aRet;
208 const SfxItemPropertyMapEntry* pEntry = aPropertyMap.getByName( aPropertyName );
209 if ( !pEntry )
210 throw beans::UnknownPropertyException(aPropertyName);
211
212 if (!pEntry->nWID)
213 {
214 if(aPropertyName == SC_UNO_STANDARDDEC)
215 {
217 const ScDocOptions& aDocOpt = rDoc.GetDocOptions();
218 sal_uInt16 nPrec = aDocOpt.GetStdPrecision();
219 // the max value of unsigned 16-bit integer is used as the flag
220 // value for unlimited precision, c.f.
221 // SvNumberFormatter::UNLIMITED_PRECISION.
222 if (nPrec <= ::std::numeric_limits<sal_Int16>::max())
223 aRet <<= static_cast<sal_Int16> (nPrec);
224 }
225 else if (aPropertyName == SC_UNO_TABSTOPDIS)
226 {
228 const ScDocOptions& aDocOpt = rDoc.GetDocOptions();
229 sal_Int32 nValue (TwipsToEvenHMM(aDocOpt.GetTabDistance()));
230 aRet <<= nValue;
231 }
232 }
233 else
234 {
236 const SfxPoolItem& rItem = pPool->GetDefaultItem( pEntry->nWID );
237 rItem.QueryValue( aRet, pEntry->nMemberId );
238 }
239 return aRet;
240}
241
243
244// XPropertyState
245
246beans::PropertyState SAL_CALL ScDocDefaultsObj::getPropertyState( const OUString& aPropertyName )
247{
248 SolarMutexGuard aGuard;
249
250 if ( !pDocShell )
251 throw uno::RuntimeException();
252
253 const SfxItemPropertyMapEntry* pEntry = aPropertyMap.getByName( aPropertyName );
254 if ( !pEntry )
255 throw beans::UnknownPropertyException(aPropertyName);
256
257 beans::PropertyState eRet = beans::PropertyState_DEFAULT_VALUE;
258
259 sal_uInt16 nWID = pEntry->nWID;
260 if ( nWID == ATTR_FONT || nWID == ATTR_CJK_FONT || nWID == ATTR_CTL_FONT || !nWID )
261 {
262 // static default for font is system-dependent,
263 // so font default is always treated as "direct value".
264
265 eRet = beans::PropertyState_DIRECT_VALUE;
266 }
267 else
268 {
269 // check if pool default is set
270
271 ScDocumentPool* pPool = pDocShell->GetDocument().GetPool();
272 if ( pPool->GetPoolDefaultItem( nWID ) != nullptr )
273 eRet = beans::PropertyState_DIRECT_VALUE;
274 }
275
276 return eRet;
277}
278
279uno::Sequence<beans::PropertyState> SAL_CALL ScDocDefaultsObj::getPropertyStates(
280 const uno::Sequence<OUString>& aPropertyNames )
281{
282 // the simple way: call getPropertyState
283
284 SolarMutexGuard aGuard;
285 uno::Sequence<beans::PropertyState> aRet(aPropertyNames.getLength());
286 std::transform(aPropertyNames.begin(), aPropertyNames.end(), aRet.getArray(),
287 [this](const OUString& rName) -> beans::PropertyState { return getPropertyState(rName); });
288 return aRet;
289}
290
291void SAL_CALL ScDocDefaultsObj::setPropertyToDefault( const OUString& aPropertyName )
292{
293 SolarMutexGuard aGuard;
294
295 if ( !pDocShell )
296 throw uno::RuntimeException();
297
298 const SfxItemPropertyMapEntry* pEntry = aPropertyMap.getByName( aPropertyName );
299 if ( !pEntry )
300 throw beans::UnknownPropertyException(aPropertyName);
301
302 if (pEntry->nWID)
303 {
305 pPool->ResetPoolDefaultItem( pEntry->nWID );
306
307 ItemsChanged();
308 }
309}
310
311uno::Any SAL_CALL ScDocDefaultsObj::getPropertyDefault( const OUString& aPropertyName )
312{
313 // always use static default
314
315 SolarMutexGuard aGuard;
316
317 if ( !pDocShell )
318 throw uno::RuntimeException();
319
320 const SfxItemPropertyMapEntry* pEntry = aPropertyMap.getByName( aPropertyName );
321 if ( !pEntry )
322 throw beans::UnknownPropertyException(aPropertyName);
323
324 uno::Any aRet;
325 if (pEntry->nWID)
326 {
328 const SfxPoolItem* pItem = pPool->GetItem2Default( pEntry->nWID );
329 if (pItem)
330 pItem->QueryValue( aRet, pEntry->nMemberId );
331 }
332 return aRet;
333}
334
335/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SCTAB MAXTAB
Definition: address.hxx:70
static LanguageType convertToLanguageType(const css::lang::Locale &rLocale, bool bResolveSystem=true)
virtual css::uno::Any SAL_CALL getPropertyDefault(const OUString &aPropertyName) override
Definition: defltuno.cxx:311
ScDocShell * pDocShell
Definition: defltuno.hxx:38
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: defltuno.cxx:90
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: defltuno.cxx:118
virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL getPropertyStates(const css::uno::Sequence< OUString > &aPropertyName) override
Definition: defltuno.cxx:279
virtual void SAL_CALL setPropertyToDefault(const OUString &PropertyName) override
Definition: defltuno.cxx:291
virtual ~ScDocDefaultsObj() override
Definition: defltuno.cxx:82
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: defltuno.cxx:198
SfxItemPropertyMap aPropertyMap
Definition: defltuno.hxx:39
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: defltuno.cxx:110
void ItemsChanged()
Definition: defltuno.cxx:98
void SetTabDistance(sal_uInt16 nTabDist)
Definition: docoptio.hxx:71
sal_uInt16 GetTabDistance() const
Definition: docoptio.hxx:70
sal_uInt16 GetStdPrecision() const
Definition: docoptio.hxx:78
void SetStdPrecision(sal_uInt16 n)
Definition: docoptio.hxx:79
const ScDocument & GetDocument() const
Definition: docsh.hxx:220
void PostPaint(SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, PaintPartFlags nPart, sal_uInt16 nExtFlags=0)
Definition: docsh3.cxx:101
SC_DLLPUBLIC ScDocumentPool * GetPool()
Definition: document.cxx:6163
SC_DLLPUBLIC void SetDocOptions(const ScDocOptions &rOpt)
Definition: documen3.cxx:1952
void SetLanguage(LanguageType eLatin, LanguageType eCjk, LanguageType eCtl)
Definition: documen3.cxx:1980
SC_DLLPUBLIC void GetLanguage(LanguageType &rLatin, LanguageType &rCjk, LanguageType &rCtl) const
Definition: documen3.cxx:1973
void RemoveUnoObject(SfxListener &rObject)
Definition: documen3.cxx:909
SC_DLLPUBLIC const ScDocOptions & GetDocOptions() const
Definition: documen3.cxx:1946
SfxHintId GetId() const
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
void ResetPoolDefaultItem(sal_uInt16 nWhich)
const SfxPoolItem * GetPoolDefaultItem(sal_uInt16 nWhich) const
void SetPoolDefaultItem(const SfxPoolItem &)
const SfxPoolItem * GetItem2Default(sal_uInt16 nWhich) const
const SfxItemPropertyMapEntry * getByName(std::u16string_view rName) const
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const=0
css::uno::Type const & get()
static const SfxItemPropertyMapEntry * lcl_GetDocDefaultsMap()
Definition: defltuno.cxx:39
float u
sal_Int16 nValue
#define LANGUAGE_NONE
#define MID_LANG_LOCALE
#define MID_FONT_PITCH
#define MID_FONT_CHAR_SET
#define MID_FONTHEIGHT
#define MID_FONT_FAMILY
#define MID_FONT_FAMILY_NAME
#define MID_FONT_STYLE_NAME
#define SC_SIMPLE_SERVICE_INFO(ClassName, ClassNameAscii, ServiceAscii)
Definition: miscuno.hxx:63
#define SC_IMPL_DUMMY_PROPERTY_LISTENER(ClassName)
Definition: miscuno.hxx:72
constexpr auto toTwips(N number, Length from)
constexpr ::tools::Long TwipsToEvenHMM(::tools::Long nTwips)
Definition: global.hxx:99
#define CONVERT_TWIPS
constexpr TypedWhichId< SvxFontHeightItem > ATTR_FONT_HEIGHT(101)
constexpr TypedWhichId< SvxFontItem > ATTR_CJK_FONT(111)
constexpr TypedWhichId< SvxFontItem > ATTR_CTL_FONT(116)
constexpr TypedWhichId< SvxFontHeightItem > ATTR_CJK_FONT_HEIGHT(112)
constexpr TypedWhichId< SvxLanguageItem > ATTR_CTL_FONT_LANGUAGE(120)
constexpr TypedWhichId< SvxFontItem > ATTR_FONT(100)
constexpr TypedWhichId< SvxLanguageItem > ATTR_FONT_LANGUAGE(110)
constexpr TypedWhichId< SvxLanguageItem > ATTR_CJK_FONT_LANGUAGE(115)
constexpr TypedWhichId< SvxFontHeightItem > ATTR_CTL_FONT_HEIGHT(117)
#define SC_UNO_CTL_CFNAME
Definition: unonames.hxx:87
#define SC_UNO_CJK_CFPITCH
Definition: unonames.hxx:81
#define SC_UNONAME_CLOCAL
Definition: unonames.hxx:64
#define SC_UNO_CJK_CFSTYLE
Definition: unonames.hxx:78
#define SC_UNO_CJK_CFCHARS
Definition: unonames.hxx:80
#define SC_UNONAME_CFSTYLE
Definition: unonames.hxx:70
#define SC_UNO_TABSTOPDIS
Definition: unonames.hxx:506
#define SC_UNO_CJK_CHEIGHT
Definition: unonames.hxx:82
#define SC_UNONAME_CFCHARS
Definition: unonames.hxx:72
#define SC_UNO_CTL_CFSTYLE
Definition: unonames.hxx:88
#define SC_UNO_CTL_CLOCAL
Definition: unonames.hxx:95
#define SC_UNO_CJK_CFFAMIL
Definition: unonames.hxx:79
#define SC_UNO_CJK_CFNAME
Definition: unonames.hxx:77
#define SC_UNO_CTL_CFFAMIL
Definition: unonames.hxx:89
#define SC_UNONAME_CHEIGHT
Definition: unonames.hxx:53
#define SC_UNONAME_CFFAMIL
Definition: unonames.hxx:71
#define SC_UNO_CTL_CFCHARS
Definition: unonames.hxx:90
#define SC_UNONAME_CFNAME
Definition: unonames.hxx:69
#define SC_UNO_STANDARDDEC
Definition: unonames.hxx:515
#define SC_UNO_CTL_CHEIGHT
Definition: unonames.hxx:92
#define SC_UNO_CTL_CFPITCH
Definition: unonames.hxx:91
#define SC_UNO_CJK_CLOCAL
Definition: unonames.hxx:85
#define SC_UNONAME_CFPITCH
Definition: unonames.hxx:73