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 };
67 return aDocDefaultsMap_Impl;
68}
69
71
72SC_SIMPLE_SERVICE_INFO( ScDocDefaultsObj, "ScDocDefaultsObj", "com.sun.star.sheet.Defaults" )
73
75 pDocShell( pDocSh ),
76 aPropertyMap(lcl_GetDocDefaultsMap())
77{
78 pDocShell->GetDocument().AddUnoObject(*this);
79}
80
82{
84
85 if (pDocShell)
87}
88
90{
91 if ( rHint.GetId() == SfxHintId::Dying )
92 {
93 pDocShell = nullptr; // document gone
94 }
95}
96
98{
99 if (pDocShell)
100 {
102 const auto & rDoc = pDocShell->GetDocument();
103 pDocShell->PostPaint(ScRange(0, 0, 0, rDoc.MaxCol(), rDoc.MaxRow(), MAXTAB), PaintPartFlags::Grid);
104 }
105}
106
107// XPropertySet
108
109uno::Reference<beans::XPropertySetInfo> SAL_CALL ScDocDefaultsObj::getPropertySetInfo()
110{
111 SolarMutexGuard aGuard;
112 static uno::Reference<beans::XPropertySetInfo> aRef = new SfxItemPropertySetInfo(
113 aPropertyMap );
114 return aRef;
115}
116
118 const OUString& aPropertyName, const uno::Any& aValue )
119{
120 SolarMutexGuard aGuard;
121
122 if ( !pDocShell )
123 throw uno::RuntimeException();
124
125 const SfxItemPropertyMapEntry* pEntry = aPropertyMap.getByName( aPropertyName );
126 if ( !pEntry )
127 throw beans::UnknownPropertyException(aPropertyName);
128 if(!pEntry->nWID)
129 {
130 if(aPropertyName ==SC_UNO_STANDARDDEC)
131 {
133 ScDocOptions aDocOpt(rDoc.GetDocOptions());
134 sal_Int16 nValue = 0;
135 if (aValue >>= nValue)
136 {
137 aDocOpt.SetStdPrecision(static_cast<sal_uInt16> (nValue));
138 rDoc.SetDocOptions(aDocOpt);
139 }
140 }
141 else if (aPropertyName == SC_UNO_TABSTOPDIS)
142 {
144 ScDocOptions aDocOpt(rDoc.GetDocOptions());
145 sal_Int32 nValue = 0;
146 if (aValue >>= nValue)
147 {
149 rDoc.SetDocOptions(aDocOpt);
150 }
151 }
152 }
153 else if ( pEntry->nWID == ATTR_FONT_LANGUAGE ||
154 pEntry->nWID == ATTR_CJK_FONT_LANGUAGE ||
155 pEntry->nWID == ATTR_CTL_FONT_LANGUAGE )
156 {
157 // for getPropertyValue the PoolDefaults are sufficient,
158 // but setPropertyValue has to be handled differently
159
160 lang::Locale aLocale;
161 if ( aValue >>= aLocale )
162 {
163 LanguageType eNew;
164 if (!aLocale.Language.isEmpty() || !aLocale.Country.isEmpty())
165 eNew = LanguageTag::convertToLanguageType( aLocale, false);
166 else
167 eNew = LANGUAGE_NONE;
168
170 LanguageType eLatin, eCjk, eCtl;
171 rDoc.GetLanguage( eLatin, eCjk, eCtl );
172
173 if ( pEntry->nWID == ATTR_CJK_FONT_LANGUAGE )
174 eCjk = eNew;
175 else if ( pEntry->nWID == ATTR_CTL_FONT_LANGUAGE )
176 eCtl = eNew;
177 else
178 eLatin = eNew;
179
180 rDoc.SetLanguage( eLatin, eCjk, eCtl );
181 }
182 }
183 else
184 {
186 std::unique_ptr<SfxPoolItem> pNewItem(pPool->GetDefaultItem(pEntry->nWID).Clone());
187
188 if( !pNewItem->PutValue( aValue, pEntry->nMemberId ) )
189 throw lang::IllegalArgumentException();
190
191 pPool->SetPoolDefaultItem( *pNewItem );
192
193 ItemsChanged();
194 }
195}
196
197uno::Any SAL_CALL ScDocDefaultsObj::getPropertyValue( const OUString& aPropertyName )
198{
199 // use pool default if set
200
201 SolarMutexGuard aGuard;
202
203 if ( !pDocShell )
204 throw uno::RuntimeException();
205
206 uno::Any aRet;
207 const SfxItemPropertyMapEntry* pEntry = aPropertyMap.getByName( aPropertyName );
208 if ( !pEntry )
209 throw beans::UnknownPropertyException(aPropertyName);
210
211 if (!pEntry->nWID)
212 {
213 if(aPropertyName == SC_UNO_STANDARDDEC)
214 {
216 const ScDocOptions& aDocOpt = rDoc.GetDocOptions();
217 sal_uInt16 nPrec = aDocOpt.GetStdPrecision();
218 // the max value of unsigned 16-bit integer is used as the flag
219 // value for unlimited precision, c.f.
220 // SvNumberFormatter::UNLIMITED_PRECISION.
221 if (nPrec <= ::std::numeric_limits<sal_Int16>::max())
222 aRet <<= static_cast<sal_Int16> (nPrec);
223 }
224 else if (aPropertyName == SC_UNO_TABSTOPDIS)
225 {
227 const ScDocOptions& aDocOpt = rDoc.GetDocOptions();
228 sal_Int32 nValue (TwipsToEvenHMM(aDocOpt.GetTabDistance()));
229 aRet <<= nValue;
230 }
231 }
232 else
233 {
235 const SfxPoolItem& rItem = pPool->GetDefaultItem( pEntry->nWID );
236 rItem.QueryValue( aRet, pEntry->nMemberId );
237 }
238 return aRet;
239}
240
242
243// XPropertyState
244
245beans::PropertyState SAL_CALL ScDocDefaultsObj::getPropertyState( const OUString& aPropertyName )
246{
247 SolarMutexGuard aGuard;
248
249 if ( !pDocShell )
250 throw uno::RuntimeException();
251
252 const SfxItemPropertyMapEntry* pEntry = aPropertyMap.getByName( aPropertyName );
253 if ( !pEntry )
254 throw beans::UnknownPropertyException(aPropertyName);
255
256 beans::PropertyState eRet = beans::PropertyState_DEFAULT_VALUE;
257
258 sal_uInt16 nWID = pEntry->nWID;
259 if ( nWID == ATTR_FONT || nWID == ATTR_CJK_FONT || nWID == ATTR_CTL_FONT || !nWID )
260 {
261 // static default for font is system-dependent,
262 // so font default is always treated as "direct value".
263
264 eRet = beans::PropertyState_DIRECT_VALUE;
265 }
266 else
267 {
268 // check if pool default is set
269
270 ScDocumentPool* pPool = pDocShell->GetDocument().GetPool();
271 if ( pPool->GetPoolDefaultItem( nWID ) != nullptr )
272 eRet = beans::PropertyState_DIRECT_VALUE;
273 }
274
275 return eRet;
276}
277
278uno::Sequence<beans::PropertyState> SAL_CALL ScDocDefaultsObj::getPropertyStates(
279 const uno::Sequence<OUString>& aPropertyNames )
280{
281 // the simple way: call getPropertyState
282
283 SolarMutexGuard aGuard;
284 uno::Sequence<beans::PropertyState> aRet(aPropertyNames.getLength());
285 std::transform(aPropertyNames.begin(), aPropertyNames.end(), aRet.getArray(),
286 [this](const OUString& rName) -> beans::PropertyState { return getPropertyState(rName); });
287 return aRet;
288}
289
290void SAL_CALL ScDocDefaultsObj::setPropertyToDefault( const OUString& aPropertyName )
291{
292 SolarMutexGuard aGuard;
293
294 if ( !pDocShell )
295 throw uno::RuntimeException();
296
297 const SfxItemPropertyMapEntry* pEntry = aPropertyMap.getByName( aPropertyName );
298 if ( !pEntry )
299 throw beans::UnknownPropertyException(aPropertyName);
300
301 if (pEntry->nWID)
302 {
304 pPool->ResetPoolDefaultItem( pEntry->nWID );
305
306 ItemsChanged();
307 }
308}
309
310uno::Any SAL_CALL ScDocDefaultsObj::getPropertyDefault( const OUString& aPropertyName )
311{
312 // always use static default
313
314 SolarMutexGuard aGuard;
315
316 if ( !pDocShell )
317 throw uno::RuntimeException();
318
319 const SfxItemPropertyMapEntry* pEntry = aPropertyMap.getByName( aPropertyName );
320 if ( !pEntry )
321 throw beans::UnknownPropertyException(aPropertyName);
322
323 uno::Any aRet;
324 if (pEntry->nWID)
325 {
327 const SfxPoolItem* pItem = pPool->GetItem2Default( pEntry->nWID );
328 if (pItem)
329 pItem->QueryValue( aRet, pEntry->nMemberId );
330 }
331 return aRet;
332}
333
334/* 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:310
ScDocShell * pDocShell
Definition: defltuno.hxx:38
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: defltuno.cxx:89
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: defltuno.cxx:117
virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL getPropertyStates(const css::uno::Sequence< OUString > &aPropertyName) override
Definition: defltuno.cxx:278
virtual void SAL_CALL setPropertyToDefault(const OUString &PropertyName) override
Definition: defltuno.cxx:290
virtual ~ScDocDefaultsObj() override
Definition: defltuno.cxx:81
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: defltuno.cxx:197
SfxItemPropertyMap aPropertyMap
Definition: defltuno.hxx:39
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: defltuno.cxx:109
void ItemsChanged()
Definition: defltuno.cxx:97
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:6170
SC_DLLPUBLIC void SetDocOptions(const ScDocOptions &rOpt)
Definition: documen3.cxx:1958
void SetLanguage(LanguageType eLatin, LanguageType eCjk, LanguageType eCtl)
Definition: documen3.cxx:1986
SC_DLLPUBLIC void GetLanguage(LanguageType &rLatin, LanguageType &rCjk, LanguageType &rCtl) const
Definition: documen3.cxx:1979
void RemoveUnoObject(SfxListener &rObject)
Definition: documen3.cxx:915
SC_DLLPUBLIC const ScDocOptions & GetDocOptions() const
Definition: documen3.cxx:1952
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 o3tl::span< const SfxItemPropertyMapEntry > lcl_GetDocDefaultsMap()
Definition: defltuno.cxx:39
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:100
#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)
constexpr OUStringLiteral SC_UNO_CJK_CFFAMIL
Definition: unonames.hxx:79
constexpr OUStringLiteral SC_UNO_CJK_CFPITCH
Definition: unonames.hxx:81
constexpr OUStringLiteral SC_UNONAME_CFCHARS
Definition: unonames.hxx:72
constexpr OUStringLiteral SC_UNO_STANDARDDEC
Definition: unonames.hxx:515
constexpr OUStringLiteral SC_UNONAME_CLOCAL
Definition: unonames.hxx:64
constexpr OUStringLiteral SC_UNO_CJK_CFCHARS
Definition: unonames.hxx:80
constexpr OUStringLiteral SC_UNO_TABSTOPDIS
Definition: unonames.hxx:506
constexpr OUStringLiteral SC_UNO_CTL_CFNAME
Definition: unonames.hxx:87
constexpr OUStringLiteral SC_UNO_CTL_CFFAMIL
Definition: unonames.hxx:89
constexpr OUStringLiteral SC_UNONAME_CFFAMIL
Definition: unonames.hxx:71
constexpr OUStringLiteral SC_UNO_CJK_CFSTYLE
Definition: unonames.hxx:78
constexpr OUStringLiteral SC_UNO_CTL_CFPITCH
Definition: unonames.hxx:91
constexpr OUStringLiteral SC_UNO_CTL_CFCHARS
Definition: unonames.hxx:90
constexpr OUStringLiteral SC_UNONAME_CFNAME
Definition: unonames.hxx:69
constexpr OUStringLiteral SC_UNO_CTL_CLOCAL
Definition: unonames.hxx:95
constexpr OUStringLiteral SC_UNO_CJK_CHEIGHT
Definition: unonames.hxx:82
constexpr OUStringLiteral SC_UNO_CJK_CFNAME
Definition: unonames.hxx:77
constexpr OUStringLiteral SC_UNONAME_CFPITCH
Definition: unonames.hxx:73
constexpr OUStringLiteral SC_UNO_CTL_CHEIGHT
Definition: unonames.hxx:92
constexpr OUStringLiteral SC_UNONAME_CHEIGHT
Definition: unonames.hxx:53
constexpr OUStringLiteral SC_UNO_CTL_CFSTYLE
Definition: unonames.hxx:88
constexpr OUStringLiteral SC_UNONAME_CFSTYLE
Definition: unonames.hxx:70
constexpr OUStringLiteral SC_UNO_CJK_CLOCAL
Definition: unonames.hxx:85