LibreOffice Module sw (master) 1
unostyle.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 <sal/config.h>
21
22#include <o3tl/safeint.hxx>
23#include <o3tl/string_view.hxx>
25#include <hintids.hxx>
26#include <utility>
27#include <vcl/svapp.hxx>
28#include <svl/hint.hxx>
29#include <svtools/ctrltool.hxx>
30#include <svl/style.hxx>
31#include <svl/itemiter.hxx>
32#include <svl/listener.hxx>
33#include <svl/numformat.hxx>
34#include <svl/zforlist.hxx>
35#include <svl/zformat.hxx>
36#include <svx/pageitem.hxx>
37#include <editeng/colritem.hxx>
40#include <editeng/fontitem.hxx>
41#include <editeng/sizeitem.hxx>
42#include <editeng/udlnitem.hxx>
43#include <editeng/ulspitem.hxx>
44#include <editeng/lrspitem.hxx>
45#include <editeng/boxitem.hxx>
46#include <editeng/postitem.hxx>
47#include <editeng/shdditem.hxx>
48#include <editeng/brushitem.hxx>
49#include <editeng/flstitem.hxx>
50#include <editeng/fhgtitem.hxx>
51#include <editeng/paperinf.hxx>
52#include <editeng/wghtitem.hxx>
53#include <pagedesc.hxx>
54#include <doc.hxx>
55#include <IDocumentUndoRedo.hxx>
58#include <docary.hxx>
59#include <charfmt.hxx>
60#include <cmdid.h>
61#include <unomid.h>
62#include <unomap.hxx>
63#include <unostyle.hxx>
64#include <unosett.hxx>
65#include <docsh.hxx>
66#include <paratr.hxx>
67#include <unoprnms.hxx>
68#include <shellio.hxx>
69#include <docstyle.hxx>
70#include <unotextbodyhf.hxx>
71#include <fmthdft.hxx>
72#include <fmtpdsc.hxx>
73#include <strings.hrc>
74#include <poolfmt.hxx>
75#include <unoevent.hxx>
76#include <fmtruby.hxx>
77#include <SwStyleNameMapper.hxx>
78#include <sfx2/printer.hxx>
79#include <com/sun/star/frame/XModel.hpp>
80#include <com/sun/star/io/IOException.hpp>
81#include <com/sun/star/style/ParagraphStyleCategory.hpp>
82#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
83#include <com/sun/star/beans/PropertyAttribute.hpp>
84#include <com/sun/star/beans/NamedValue.hpp>
85#include <com/sun/star/drawing/BitmapMode.hpp>
86#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
87#include <com/sun/star/lang/IllegalArgumentException.hpp>
88#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
89#include <com/sun/star/document/XEventsSupplier.hpp>
90#include <com/sun/star/io/XInputStream.hpp>
91#include <istyleaccess.hxx>
92#include <fmtfsize.hxx>
93#include <numrule.hxx>
94#include <tblafmt.hxx>
95#include <frameformats.hxx>
96
102#include <sal/log.hxx>
103
104#include <svl/stylepool.hxx>
106#include <editeng/unoipset.hxx>
107#include <editeng/memberids.h>
108#include <svx/unomid.hxx>
109#include <svx/unoshape.hxx>
110#include <svx/xflbstit.hxx>
111#include <svx/xflbmtit.hxx>
112#include <swunohelper.hxx>
113#include <svx/xbtmpit.hxx>
114
115#include <ccoll.hxx>
116#include <hints.hxx>
117#include <uiitems.hxx>
118
119#include <cassert>
120#include <memory>
121#include <set>
122#include <string_view>
123#include <limits>
124
125using namespace css;
126using namespace css::io;
127using namespace css::lang;
128using namespace css::uno;
129
130namespace {
131
132 // these should really be constexprs, but MSVC still is apparently too stupid for them
133 #define nPoolChrNormalRange (RES_POOLCHR_NORMAL_END - RES_POOLCHR_NORMAL_BEGIN)
134 #define nPoolChrHtmlRange (RES_POOLCHR_HTML_END - RES_POOLCHR_HTML_BEGIN)
135 #define nPoolCollTextRange ( RES_POOLCOLL_TEXT_END - RES_POOLCOLL_TEXT_BEGIN)
136 #define nPoolCollListsRange ( RES_POOLCOLL_LISTS_END - RES_POOLCOLL_LISTS_BEGIN)
137 #define nPoolCollExtraRange ( RES_POOLCOLL_EXTRA_END - RES_POOLCOLL_EXTRA_BEGIN)
138 #define nPoolCollRegisterRange ( RES_POOLCOLL_REGISTER_END - RES_POOLCOLL_REGISTER_BEGIN)
139 #define nPoolCollDocRange ( RES_POOLCOLL_DOC_END - RES_POOLCOLL_DOC_BEGIN)
140 #define nPoolCollHtmlRange ( RES_POOLCOLL_HTML_END - RES_POOLCOLL_HTML_BEGIN)
141 #define nPoolFrameRange ( RES_POOLFRM_END - RES_POOLFRM_BEGIN)
142 #define nPoolPageRange ( RES_POOLPAGE_END - RES_POOLPAGE_BEGIN)
143 #define nPoolNumRange ( RES_POOLNUMRULE_END - RES_POOLNUMRULE_BEGIN)
144 #define nPoolCollListsStackedStart ( nPoolCollTextRange)
145 #define nPoolCollExtraStackedStart ( nPoolCollListsStackedStart + nPoolCollListsRange)
146 #define nPoolCollRegisterStackedStart ( nPoolCollExtraStackedStart + nPoolCollExtraRange)
147 #define nPoolCollDocStackedStart ( nPoolCollRegisterStackedStart + nPoolCollRegisterRange)
148 #define nPoolCollHtmlStackedStart ( nPoolCollDocStackedStart + nPoolCollDocRange)
149 using paragraphstyle_t = std::remove_const<decltype(style::ParagraphStyleCategory::TEXT)>::type;
150 using collectionbits_t = sal_uInt16;
151 struct ParagraphStyleCategoryEntry
152 {
153 paragraphstyle_t m_eCategory;
154 SfxStyleSearchBits m_nSwStyleBits;
155 collectionbits_t m_nCollectionBits;
156 constexpr ParagraphStyleCategoryEntry(paragraphstyle_t eCategory, SfxStyleSearchBits nSwStyleBits, collectionbits_t nCollectionBits)
157 : m_eCategory(eCategory)
158 , m_nSwStyleBits(nSwStyleBits)
159 , m_nCollectionBits(nCollectionBits)
160 { }
161 };
162
163constexpr ParagraphStyleCategoryEntry sParagraphStyleCategoryEntries[]
164{
165 { style::ParagraphStyleCategory::TEXT, SfxStyleSearchBits::SwText, COLL_TEXT_BITS },
166 { style::ParagraphStyleCategory::CHAPTER, SfxStyleSearchBits::SwChapter, COLL_DOC_BITS },
167 { style::ParagraphStyleCategory::LIST, SfxStyleSearchBits::SwList, COLL_LISTS_BITS },
168 { style::ParagraphStyleCategory::INDEX, SfxStyleSearchBits::SwIndex, COLL_REGISTER_BITS },
169 { style::ParagraphStyleCategory::EXTRA, SfxStyleSearchBits::SwExtra, COLL_EXTRA_BITS },
170 { style::ParagraphStyleCategory::HTML, SfxStyleSearchBits::SwHtml, COLL_HTML_BITS }
171};
172
173class StyleFamilyEntry
174{
175public:
176 template <SfxStyleFamily f> static StyleFamilyEntry Create(sal_uInt16 nPropMapType, SwGetPoolIdFromName aPoolId, OUString sName, TranslateId pResId)
177 {
178 return StyleFamilyEntry(f, nPropMapType, aPoolId, sName, pResId, GetCountOrName<f>, CreateStyle<f>, TranslateIndex<f>);
179 }
180
181 SfxStyleFamily family() const { return m_eFamily; }
182 sal_uInt16 propMapType() const { return m_nPropMapType; }
183 const uno::Reference<beans::XPropertySetInfo>& xPSInfo() const { return m_xPSInfo; }
184 SwGetPoolIdFromName poolId() const { return m_aPoolId; }
185 const OUString& name() const { return m_sName; }
186 const TranslateId& resId() const { return m_pResId; }
187
188 sal_Int32 getCountOrName(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex) const { return m_fGetCountOrName(rDoc, pString, nIndex); }
189 css::uno::Reference<css::style::XStyle> createStyle(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName) const { return m_fCreateStyle(pBasePool, pDocShell, sStyleName); }
190 sal_uInt16 translateIndex(const sal_uInt16 nIndex) const { return m_fTranslateIndex(nIndex); }
191
192private:
193 using GetCountOrName_t = sal_Int32 (*)(const SwDoc&, OUString*, sal_Int32);
194 using CreateStyle_t = uno::Reference<css::style::XStyle>(*)(SfxStyleSheetBasePool*, SwDocShell*, const OUString&);
195 using TranslateIndex_t = sal_uInt16(*)(const sal_uInt16);
196 SfxStyleFamily m_eFamily;
197 sal_uInt16 m_nPropMapType;
198 uno::Reference<beans::XPropertySetInfo> m_xPSInfo;
199 SwGetPoolIdFromName m_aPoolId;
200 OUString m_sName;
201 TranslateId m_pResId;
202 GetCountOrName_t m_fGetCountOrName;
203 CreateStyle_t m_fCreateStyle;
204 TranslateIndex_t m_fTranslateIndex;
205 StyleFamilyEntry(SfxStyleFamily eFamily, sal_uInt16 nPropMapType, SwGetPoolIdFromName aPoolId, OUString sName, TranslateId pResId, GetCountOrName_t fGetCountOrName, CreateStyle_t fCreateStyle, TranslateIndex_t fTranslateIndex)
206 : m_eFamily(eFamily)
207 , m_nPropMapType(nPropMapType)
208 , m_xPSInfo(aSwMapProvider.GetPropertySet(nPropMapType)->getPropertySetInfo())
209 , m_aPoolId(aPoolId)
210 , m_sName(std::move(sName))
211 , m_pResId(pResId)
212 , m_fGetCountOrName(fGetCountOrName)
213 , m_fCreateStyle(fCreateStyle)
214 , m_fTranslateIndex(fTranslateIndex)
215 { }
216 template<SfxStyleFamily> static inline sal_Int32 GetCountOrName(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex);
217 template<SfxStyleFamily> static inline css::uno::Reference<css::style::XStyle> CreateStyle(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName);
218 template<SfxStyleFamily> static inline sal_uInt16 TranslateIndex(const sal_uInt16 nIndex) { return nIndex; }
219};
220
221template<>
222sal_Int32 StyleFamilyEntry::GetCountOrName<SfxStyleFamily::Char>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex)
223{
224 const sal_uInt16 nBaseCount = nPoolChrHtmlRange + nPoolChrNormalRange;
225 nIndex -= nBaseCount;
226 sal_Int32 nCount = 0;
227 for(auto pFormat : *rDoc.GetCharFormats())
228 {
229 if(pFormat->IsDefault() && pFormat != rDoc.GetDfltCharFormat())
230 continue;
231 if(!IsPoolUserFormat(pFormat->GetPoolFormatId()))
232 continue;
233 if(nIndex == nCount)
234 {
235 // the default character format needs to be set to "Default!"
236 if(rDoc.GetDfltCharFormat() == pFormat)
237 *pString = SwResId(STR_POOLCHR_STANDARD);
238 else
239 *pString = pFormat->GetName();
240 break;
241 }
242 ++nCount;
243 }
244 return nCount + nBaseCount;
245}
246
247template<>
248sal_Int32 StyleFamilyEntry::GetCountOrName<SfxStyleFamily::Para>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex)
249{
250 const sal_uInt16 nBaseCount = nPoolCollHtmlStackedStart + nPoolCollHtmlRange;
251 nIndex -= nBaseCount;
252 sal_Int32 nCount = 0;
253 for(auto pColl : *rDoc.GetTextFormatColls())
254 {
255 if(pColl->IsDefault())
256 continue;
257 if(!IsPoolUserFormat(pColl->GetPoolFormatId()))
258 continue;
259 if(nIndex == nCount)
260 {
261 *pString = pColl->GetName();
262 break;
263 }
264 ++nCount;
265 }
266 return nCount + nBaseCount;
267}
268
269template<>
270sal_Int32 StyleFamilyEntry::GetCountOrName<SfxStyleFamily::Frame>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex)
271{
273 sal_Int32 nCount = 0;
274 for(const auto pFormat : *rDoc.GetFrameFormats())
275 {
276 if(pFormat->IsDefault() || pFormat->IsAuto())
277 continue;
278 if(!IsPoolUserFormat(pFormat->GetPoolFormatId()))
279 continue;
280 if(nIndex == nCount)
281 {
282 *pString = pFormat->GetName();
283 break;
284 }
285 ++nCount;
286 }
287 return nCount + nPoolFrameRange;
288}
289
290template<>
291sal_Int32 StyleFamilyEntry::GetCountOrName<SfxStyleFamily::Page>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex)
292{
294 sal_Int32 nCount = 0;
295 const size_t nArrLen = rDoc.GetPageDescCnt();
296 for(size_t i = 0; i < nArrLen; ++i)
297 {
298 const SwPageDesc& rDesc = rDoc.GetPageDesc(i);
300 continue;
301 if(nIndex == nCount)
302 {
303 *pString = rDesc.GetName();
304 break;
305 }
306 ++nCount;
307 }
309 return nCount;
310}
311
312template<>
313sal_Int32 StyleFamilyEntry::GetCountOrName<SfxStyleFamily::Pseudo>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex)
314{
316 sal_Int32 nCount = 0;
317 for(const auto pRule : rDoc.GetNumRuleTable())
318 {
319 if(pRule->IsAutoRule())
320 continue;
321 if(!IsPoolUserFormat(pRule->GetPoolFormatId()))
322 continue;
323 if(nIndex == nCount)
324 {
325 *pString = pRule->GetName();
326 break;
327 }
328 ++nCount;
329 }
330 return nCount + nPoolNumRange;
331}
332
333template<>
334sal_Int32 StyleFamilyEntry::GetCountOrName<SfxStyleFamily::Table>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex)
335{
336 if (!rDoc.HasTableStyles())
337 return 0;
338
339 const auto pAutoFormats = &rDoc.GetTableStyles();
340 const sal_Int32 nCount = pAutoFormats->size();
341 if (0 <= nIndex && nIndex < nCount)
342 *pString = pAutoFormats->operator[](nIndex).GetName();
343
344 return nCount;
345}
346
347template<>
348sal_Int32 StyleFamilyEntry::GetCountOrName<SfxStyleFamily::Cell>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex)
349{
350 const auto& rAutoFormats = rDoc.GetTableStyles();
351 const auto& rTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap();
352 const sal_Int32 nUsedCellStylesCount = rAutoFormats.size() * rTableTemplateMap.size();
353 const sal_Int32 nCount = nUsedCellStylesCount + rDoc.GetCellStyles().size();
354 if (0 <= nIndex && nIndex < nCount)
355 {
356 if (nUsedCellStylesCount > nIndex)
357 {
358 const sal_Int32 nAutoFormat = nIndex / rTableTemplateMap.size();
359 const sal_Int32 nBoxFormat = rTableTemplateMap[nIndex % rTableTemplateMap.size()];
360 const SwTableAutoFormat& rTableFormat = rAutoFormats[nAutoFormat];
362 *pString += rTableFormat.GetTableTemplateCellSubName(rTableFormat.GetBoxFormat(nBoxFormat));
363 }
364 else
365 *pString = rDoc.GetCellStyles()[nIndex-nUsedCellStylesCount].GetName();
366 }
367 return nCount;
368}
369
370template<>
371sal_uInt16 StyleFamilyEntry::TranslateIndex<SfxStyleFamily::Char>(const sal_uInt16 nIndex)
372{
373 static_assert(nPoolChrNormalRange > 0 && nPoolChrHtmlRange > 0, "invalid pool range");
374 if (nIndex < nPoolChrNormalRange)
376 else if (nIndex < (nPoolChrHtmlRange + nPoolChrNormalRange))
378 throw lang::IndexOutOfBoundsException();
379}
380
381template<>
382sal_uInt16 StyleFamilyEntry::TranslateIndex<SfxStyleFamily::Para>(const sal_uInt16 nIndex)
383{
384 static_assert(nPoolCollTextRange > 0 && nPoolCollListsRange > 0 && nPoolCollExtraRange > 0 && nPoolCollRegisterRange > 0 && nPoolCollDocRange > 0 && nPoolCollHtmlRange > 0, "weird pool range");
385 if (nIndex < nPoolCollListsStackedStart)
387 else if (nIndex < nPoolCollExtraStackedStart)
389 else if (nIndex < nPoolCollRegisterStackedStart)
391 else if (nIndex < nPoolCollDocStackedStart)
393 else if (nIndex < nPoolCollHtmlStackedStart)
397 throw lang::IndexOutOfBoundsException();
398}
399
400template<>
401sal_uInt16 StyleFamilyEntry::TranslateIndex<SfxStyleFamily::Page>(const sal_uInt16 nIndex)
402{
403 if (nIndex < nPoolPageRange)
404 return nIndex + RES_POOLPAGE_BEGIN;
405 throw lang::IndexOutOfBoundsException();
406}
407
408template<>
409sal_uInt16 StyleFamilyEntry::TranslateIndex<SfxStyleFamily::Frame>(const sal_uInt16 nIndex)
410{
411 if (nIndex < nPoolFrameRange)
412 return nIndex + RES_POOLFRM_BEGIN;
413 throw lang::IndexOutOfBoundsException();
414}
415
416template<>
417sal_uInt16 StyleFamilyEntry::TranslateIndex<SfxStyleFamily::Pseudo>(const sal_uInt16 nIndex)
418{
419 if (nIndex < nPoolNumRange)
421 throw lang::IndexOutOfBoundsException();
422}
423
424const std::vector<StyleFamilyEntry>& lcl_GetStyleFamilyEntries()
425{
426 static const std::vector<StyleFamilyEntry> our_pStyleFamilyEntries{
427 StyleFamilyEntry::Create<SfxStyleFamily::Char> (PROPERTY_MAP_CHAR_STYLE, SwGetPoolIdFromName::ChrFmt, "CharacterStyles", STR_STYLE_FAMILY_CHARACTER),
428 StyleFamilyEntry::Create<SfxStyleFamily::Para> (PROPERTY_MAP_PARA_STYLE, SwGetPoolIdFromName::TxtColl, "ParagraphStyles", STR_STYLE_FAMILY_PARAGRAPH),
429 StyleFamilyEntry::Create<SfxStyleFamily::Page> (PROPERTY_MAP_PAGE_STYLE, SwGetPoolIdFromName::PageDesc, "PageStyles", STR_STYLE_FAMILY_PAGE),
430 StyleFamilyEntry::Create<SfxStyleFamily::Frame> (PROPERTY_MAP_FRAME_STYLE, SwGetPoolIdFromName::FrmFmt, "FrameStyles", STR_STYLE_FAMILY_FRAME),
431 StyleFamilyEntry::Create<SfxStyleFamily::Pseudo>(PROPERTY_MAP_NUM_STYLE, SwGetPoolIdFromName::NumRule, "NumberingStyles", STR_STYLE_FAMILY_NUMBERING),
432 StyleFamilyEntry::Create<SfxStyleFamily::Table> (PROPERTY_MAP_TABLE_STYLE, SwGetPoolIdFromName::TabStyle, "TableStyles", STR_STYLE_FAMILY_TABLE),
433 StyleFamilyEntry::Create<SfxStyleFamily::Cell> (PROPERTY_MAP_CELL_STYLE, SwGetPoolIdFromName::CellStyle, "CellStyles", STR_STYLE_FAMILY_CELL),
434 };
435 return our_pStyleFamilyEntries;
436}
437
438class SwStyleBase_Impl
439{
440private:
441 SwDoc& m_rDoc;
442 const SwPageDesc* m_pOldPageDesc;
444 SfxItemSet* m_pItemSet;
445 std::unique_ptr<SfxItemSet> m_pMyItemSet;
446 OUString m_rStyleName;
447 const SwAttrSet* m_pParentStyle;
448public:
449 SwStyleBase_Impl(SwDoc& rSwDoc, OUString aName, const SwAttrSet* pParentStyle)
450 : m_rDoc(rSwDoc)
451 , m_pOldPageDesc(nullptr)
452 , m_pItemSet(nullptr)
453 , m_rStyleName(std::move(aName))
454 , m_pParentStyle(pParentStyle)
455 { }
456
458 {
459 return m_xNewBase;
460 }
461
462 void setNewBase(SwDocStyleSheet* pNew)
463 {
464 m_xNewBase = pNew;
465 }
466
467 bool HasItemSet() const
468 {
469 return m_xNewBase.is();
470 }
471
473 {
474 assert(m_xNewBase.is());
475 if(!m_pItemSet)
476 {
477 m_pMyItemSet.reset(new SfxItemSet(m_xNewBase->GetItemSet()));
478 m_pItemSet = m_pMyItemSet.get();
479
480 // set parent style to have the correct XFillStyle setting as XFILL_NONE
481 if(!m_pItemSet->GetParent() && m_pParentStyle)
482 m_pItemSet->SetParent(m_pParentStyle);
483 }
484 return *m_pItemSet;
485 }
486
487 const SwPageDesc* GetOldPageDesc();
488
489 // still a hack, but a bit more explicit and with a proper scope
490 struct ItemSetOverrider
491 {
492 SwStyleBase_Impl& m_rStyleBase;
493 SfxItemSet* m_pOldSet;
494 ItemSetOverrider(SwStyleBase_Impl& rStyleBase, SfxItemSet* pTemp)
495 : m_rStyleBase(rStyleBase)
496 , m_pOldSet(m_rStyleBase.m_pItemSet)
497 { m_rStyleBase.m_pItemSet = pTemp; }
498 ~ItemSetOverrider()
499 { m_rStyleBase.m_pItemSet = m_pOldSet; };
500 };
501};
502
503class SwStyleProperties_Impl;
504class SwXStyle : public cppu::WeakImplHelper
505 <
506 css::style::XStyle,
507 css::beans::XPropertySet,
508 css::beans::XMultiPropertySet,
509 css::lang::XServiceInfo,
510 css::lang::XUnoTunnel,
511 css::beans::XPropertyState,
512 css::beans::XMultiPropertyStates
513 >
514 , public SfxListener
515 , public SvtListener
516{
517 SwDoc* m_pDoc;
518 OUString m_sStyleName;
519 const StyleFamilyEntry& m_rEntry;
520 bool m_bIsDescriptor;
521 bool m_bIsConditional;
522 OUString m_sParentStyleName;
523
524protected:
525 SfxStyleSheetBasePool* m_pBasePool;
526 std::unique_ptr<SwStyleProperties_Impl> m_pPropertiesImpl;
527 css::uno::Reference<css::container::XNameAccess> m_xStyleFamily;
528 css::uno::Reference<css::beans::XPropertySet> m_xStyleData;
529
530 template<sal_uInt16>
531 void SetPropertyValue(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const uno::Any&, SwStyleBase_Impl&);
532 void SetPropertyValues_Impl( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& aValues );
533 SfxStyleSheetBase* GetStyleSheetBase();
534 void PrepareStyleBase(SwStyleBase_Impl& rBase);
535 template<sal_uInt16>
536 uno::Any GetStyleProperty(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase);
537 uno::Any GetStyleProperty_Impl(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase);
538 uno::Any GetPropertyValue_Impl(const SfxItemPropertySet* pPropSet, SwStyleBase_Impl& rBase, const OUString& rPropertyName);
539
540public:
541 SwXStyle(SwDoc* pDoc, SfxStyleFamily eFam, bool bConditional = false);
542 SwXStyle(SfxStyleSheetBasePool* pPool, SfxStyleFamily eFamily, SwDoc* pDoc, const OUString& rStyleName);
543 virtual ~SwXStyle() override;
544
545
546 static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId();
547
548 //XUnoTunnel
549 virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
550
551 //XNamed
552 virtual OUString SAL_CALL getName() override;
553 virtual void SAL_CALL setName(const OUString& Name_) override;
554
555 //XStyle
556 virtual sal_Bool SAL_CALL isUserDefined() override;
557 virtual sal_Bool SAL_CALL isInUse() override;
558 virtual OUString SAL_CALL getParentStyle() override;
559 virtual void SAL_CALL setParentStyle(const OUString& aParentStyle) override;
560
561 //XPropertySet
562 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
563 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
564 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
565 virtual void SAL_CALL addPropertyChangeListener( const OUString&, const css::uno::Reference< css::beans::XPropertyChangeListener >& ) override
566 { OSL_FAIL("not implemented"); };
567 virtual void SAL_CALL removePropertyChangeListener( const OUString&, const css::uno::Reference< css::beans::XPropertyChangeListener >& ) override
568 { OSL_FAIL("not implemented"); };
569 virtual void SAL_CALL addVetoableChangeListener( const OUString&, const css::uno::Reference< css::beans::XVetoableChangeListener >& ) override
570 { OSL_FAIL("not implemented"); };
571 virtual void SAL_CALL removeVetoableChangeListener( const OUString&, const css::uno::Reference< css::beans::XVetoableChangeListener >& ) override
572 { OSL_FAIL("not implemented"); };
573
574 //XMultiPropertySet
575 virtual void SAL_CALL setPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& aValues ) override;
576 virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames ) override;
577 virtual void SAL_CALL addPropertiesChangeListener( const css::uno::Sequence< OUString >&, const css::uno::Reference< css::beans::XPropertiesChangeListener >& ) override
578 {};
579 virtual void SAL_CALL removePropertiesChangeListener( const css::uno::Reference< css::beans::XPropertiesChangeListener >& ) override
580 {};
581 virtual void SAL_CALL firePropertiesChangeEvent( const css::uno::Sequence< OUString >&, const css::uno::Reference< css::beans::XPropertiesChangeListener >& ) override
582 {};
583
584 //XPropertyState
585 virtual css::beans::PropertyState SAL_CALL getPropertyState( const OUString& PropertyName ) override;
586 virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL getPropertyStates( const css::uno::Sequence< OUString >& aPropertyName ) override;
587 virtual void SAL_CALL setPropertyToDefault( const OUString& PropertyName ) override;
588 virtual css::uno::Any SAL_CALL getPropertyDefault( const OUString& aPropertyName ) override;
589
590 //XMultiPropertyStates
591 virtual void SAL_CALL setAllPropertiesToDefault( ) override;
592 virtual void SAL_CALL setPropertiesToDefault( const css::uno::Sequence< OUString >& aPropertyNames ) override;
593 virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPropertyDefaults( const css::uno::Sequence< OUString >& aPropertyNames ) override;
594
595 //XServiceInfo
596 virtual OUString SAL_CALL getImplementationName() override
597 { return {"SwXStyle"}; };
598 virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override
599 { return cppu::supportsService(this, rServiceName); };
600 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
601
602 //SfxListener
603 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
604 //SvtListener
605 virtual void Notify(const SfxHint&) override;
606 const OUString& GetStyleName() const { return m_sStyleName;}
607 SfxStyleFamily GetFamily() const {return m_rEntry.family();}
608
609 bool IsDescriptor() const {return m_bIsDescriptor;}
610 bool IsConditional() const { return m_bIsConditional;}
611 const OUString& GetParentStyleName() const { return m_sParentStyleName;}
612 void SetDoc(SwDoc* pDc, SfxStyleSheetBasePool* pPool)
613 {
614 m_bIsDescriptor = false; m_pDoc = pDc;
615 m_pBasePool = pPool;
616 SfxListener::StartListening(*m_pBasePool);
617 }
618 SwDoc* GetDoc() const { return m_pDoc; }
619 void Invalidate();
620 void ApplyDescriptorProperties();
621 void SetStyleName(const OUString& rSet){ m_sStyleName = rSet;}
626 void SetStyleProperty(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase);
627 void PutItemToSet(const SvxSetItem* pSetItem, const SfxItemPropertySet& rPropSet, const SfxItemPropertyMapEntry& rEntry, const uno::Any& rVal, SwStyleBase_Impl& rBaseImpl);
628};
629
630typedef cppu::ImplInheritanceHelper< SwXStyle, css::document::XEventsSupplier> SwXFrameStyle_Base;
631class SwXFrameStyle
632 : public SwXFrameStyle_Base
633 , public sw::ICoreFrameStyle
634{
635public:
636 SwXFrameStyle(SfxStyleSheetBasePool& rPool,
637 SwDoc* pDoc,
638 const OUString& rStyleName) :
639 SwXFrameStyle_Base(&rPool, SfxStyleFamily::Frame, pDoc, rStyleName){}
640 explicit SwXFrameStyle(SwDoc *pDoc);
641
642 virtual css::uno::Reference< css::container::XNameReplace > SAL_CALL getEvents( ) override;
643
644 //ICoreStyle
645 virtual void SetItem(sal_uInt16 eAtr, const SfxPoolItem& rItem) override;
646 virtual const SfxPoolItem* GetItem(sal_uInt16 eAtr) override;
647 virtual css::document::XEventsSupplier& GetEventsSupplier() override
648 { return *this; };
649};
650
651class SwXPageStyle
652 : public SwXStyle
653{
654protected:
655 void SetPropertyValues_Impl( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& aValues );
656 css::uno::Sequence< css::uno::Any > GetPropertyValues_Impl( const css::uno::Sequence< OUString >& aPropertyNames );
657
658public:
659 SwXPageStyle(SfxStyleSheetBasePool& rPool, SwDocShell* pDocSh, const OUString& rStyleName);
660 explicit SwXPageStyle(SwDocShell* pDocSh);
661
662 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
663 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
664
665 virtual void SAL_CALL setPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& aValues ) override;
666 virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames ) override;
667};
668
669class SwStyleProperties_Impl
670{
671 const SfxItemPropertyMap& mrMap;
672 std::map<OUString, uno::Any> m_vPropertyValues;
673public:
674 explicit SwStyleProperties_Impl(const SfxItemPropertyMap& rMap)
675 : mrMap(rMap)
676 { }
677
678 bool AllowsKey(std::u16string_view rName)
679 {
680 return mrMap.hasPropertyByName(rName);
681 }
682 bool SetProperty(const OUString& rName, const uno::Any& rValue)
683 {
684 if(!AllowsKey(rName))
685 return false;
686 m_vPropertyValues[rName] = rValue;
687 return true;
688 }
689 void GetProperty(const OUString& rName, const uno::Any*& pAny)
690 {
691 if(!AllowsKey(rName))
692 {
693 pAny = nullptr;
694 return;
695 }
696 pAny = &m_vPropertyValues[rName];
697 return;
698 }
699 bool ClearProperty( const OUString& rName )
700 {
701 if(!AllowsKey(rName))
702 return false;
703 m_vPropertyValues[rName] = uno::Any();
704 return true;
705 }
706 void ClearAllProperties( )
707 { m_vPropertyValues.clear(); }
708 void Apply(SwXStyle& rStyle)
709 {
710 for(const auto& rPropertyPair : m_vPropertyValues)
711 {
712 if(rPropertyPair.second.hasValue())
713 rStyle.setPropertyValue(rPropertyPair.first, rPropertyPair.second);
714 }
715 }
716};
717
718template<SfxStyleFamily eFamily>
719css::uno::Reference<css::style::XStyle> StyleFamilyEntry::CreateStyle(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName)
720{
721 return pBasePool ? new SwXStyle(pBasePool, eFamily, pDocShell->GetDoc(), sStyleName) : new SwXStyle(pDocShell->GetDoc(), eFamily, false);
722}
723
724template<>
725css::uno::Reference<css::style::XStyle> StyleFamilyEntry::CreateStyle<SfxStyleFamily::Frame>(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName)
726{
727 return pBasePool ? new SwXFrameStyle(*pBasePool, pDocShell->GetDoc(), sStyleName) : new SwXFrameStyle(pDocShell->GetDoc());
728}
729
730template<>
731css::uno::Reference<css::style::XStyle> StyleFamilyEntry::CreateStyle<SfxStyleFamily::Page>(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName)
732{
733 return pBasePool ? new SwXPageStyle(*pBasePool, pDocShell, sStyleName) : new SwXPageStyle(pDocShell);
734}
735
736template<>
737css::uno::Reference<css::style::XStyle> StyleFamilyEntry::CreateStyle<SfxStyleFamily::Table>(SfxStyleSheetBasePool* /*pBasePool*/, SwDocShell* pDocShell, const OUString& sStyleName)
738{
739 return SwXTextTableStyle::CreateXTextTableStyle(pDocShell, sStyleName);
740}
741
742template<>
743css::uno::Reference<css::style::XStyle> StyleFamilyEntry::CreateStyle<SfxStyleFamily::Cell>(SfxStyleSheetBasePool* /*pBasePool*/, SwDocShell* pDocShell, const OUString& sStyleName)
744{
745 return SwXTextCellStyle::CreateXTextCellStyle(pDocShell, sStyleName);
746}
747
748class XStyleFamily : public cppu::WeakImplHelper
749<
750 container::XNameContainer,
751 lang::XServiceInfo,
752 container::XIndexAccess,
753 beans::XPropertySet
754>
755, public SfxListener
756{
757 const StyleFamilyEntry& m_rEntry;
758 SfxStyleSheetBasePool* m_pBasePool;
759 SwDocShell* m_pDocShell;
760
761 SwXStyle* FindStyle(std::u16string_view rStyleName) const;
762 sal_Int32 GetCountOrName(OUString* pString, sal_Int32 nIndex = SAL_MAX_INT32)
763 { return m_rEntry.getCountOrName(*m_pDocShell->GetDoc(), pString, nIndex); };
764 static const StyleFamilyEntry& InitEntry(SfxStyleFamily eFamily)
765 {
766 auto& entries = lcl_GetStyleFamilyEntries();
767 const auto pEntry = std::find_if(entries.begin(), entries.end(),
768 [eFamily] (const StyleFamilyEntry& e) { return e.family() == eFamily; });
769 assert(pEntry != entries.end());
770 return *pEntry;
771 }
772public:
773 XStyleFamily(SwDocShell* pDocShell, const SfxStyleFamily eFamily)
774 : m_rEntry(InitEntry(eFamily))
775 , m_pBasePool(pDocShell->GetStyleSheetPool())
776 , m_pDocShell(pDocShell)
777 {
778 if (m_pBasePool) //tdf#124142 html docs can have no styles
779 StartListening(*m_pBasePool);
780 }
781
782 //XIndexAccess
783 virtual sal_Int32 SAL_CALL getCount() override
784 {
785 SolarMutexGuard aGuard;
786 return GetCountOrName(nullptr);
787 };
788 virtual uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override;
789
790 //XElementAccess
791 virtual uno::Type SAL_CALL getElementType( ) override
793 virtual sal_Bool SAL_CALL hasElements( ) override
794 {
795 if(!m_pBasePool)
796 throw uno::RuntimeException();
797 return true;
798 }
799
800 //XNameAccess
801 virtual uno::Any SAL_CALL getByName(const OUString& Name) override;
802 virtual uno::Sequence< OUString > SAL_CALL getElementNames() override;
803 virtual sal_Bool SAL_CALL hasByName(const OUString& Name) override;
804
805 //XNameContainer
806 virtual void SAL_CALL insertByName(const OUString& Name, const uno::Any& Element) override;
807 virtual void SAL_CALL replaceByName(const OUString& Name, const uno::Any& Element) override;
808 virtual void SAL_CALL removeByName(const OUString& Name) override;
809
810 //XPropertySet
811 virtual uno::Reference< beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override
812 { return {}; };
813 virtual void SAL_CALL setPropertyValue( const OUString&, const uno::Any&) override
814 { SAL_WARN("sw.uno", "###unexpected!"); };
815 virtual uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
816 virtual void SAL_CALL addPropertyChangeListener( const OUString&, const uno::Reference<beans::XPropertyChangeListener>&) override
817 { SAL_WARN("sw.uno", "###unexpected!"); };
818 virtual void SAL_CALL removePropertyChangeListener( const OUString&, const uno::Reference<beans::XPropertyChangeListener>&) override
819 { SAL_WARN("sw.uno", "###unexpected!"); };
820 virtual void SAL_CALL addVetoableChangeListener(const OUString&, const uno::Reference<beans::XVetoableChangeListener>&) override
821 { SAL_WARN("sw.uno", "###unexpected!"); };
822 virtual void SAL_CALL removeVetoableChangeListener(const OUString&, const uno::Reference<beans::XVetoableChangeListener>&) override
823 { SAL_WARN("sw.uno", "###unexpected!"); };
824
825 //SfxListener
826 virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override
827 {
828 if(rHint.GetId() == SfxHintId::Dying)
829 {
830 m_pBasePool = nullptr;
831 m_pDocShell = nullptr;
832 EndListening(rBC);
833 }
834 }
835
836 //XServiceInfo
837 virtual OUString SAL_CALL getImplementationName() override
838 { return {"XStyleFamily"}; };
839 virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override
840 { return cppu::supportsService(this, rServiceName); };
841 virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
842 { return { "com.sun.star.style.StyleFamily" }; }
843};
844}
845
847 { return {"SwXStyleFamilies"}; }
848
849sal_Bool SwXStyleFamilies::supportsService(const OUString& rServiceName)
850{
851 return cppu::supportsService(this, rServiceName);
852}
853
855 { return { "com.sun.star.style.StyleFamilies" }; }
856
858 SwUnoCollection(rDocShell.GetDoc()),
859 m_pDocShell(&rDocShell)
860 { }
861
863 { }
864
865uno::Any SAL_CALL SwXStyleFamilies::getByName(const OUString& Name)
866{
867 SolarMutexGuard aGuard;
868 if(!IsValid())
869 throw uno::RuntimeException();
870 auto& entries(lcl_GetStyleFamilyEntries());
871 const auto pEntry = std::find_if(entries.begin(), entries.end(),
872 [&Name] (const StyleFamilyEntry& e) { return e.name() == Name; });
873 if(pEntry == entries.end())
874 throw container::NoSuchElementException();
875 return getByIndex(pEntry - entries.begin());
876}
877
878uno::Sequence< OUString > SwXStyleFamilies::getElementNames()
879{
880 auto& entries(lcl_GetStyleFamilyEntries());
881 uno::Sequence<OUString> aNames(entries.size());
882 std::transform(entries.begin(), entries.end(),
883 aNames.getArray(), [] (const StyleFamilyEntry& e) { return e.name(); });
884 return aNames;
885}
886
888{
889 auto& entries(lcl_GetStyleFamilyEntries());
890 return std::any_of(entries.begin(), entries.end(),
891 [&Name] (const StyleFamilyEntry& e) { return e.name() == Name; });
892}
893
895{
896 return lcl_GetStyleFamilyEntries().size();
897}
898
900{
901 auto& entries(lcl_GetStyleFamilyEntries());
902 SolarMutexGuard aGuard;
903 if(nIndex < 0 || o3tl::make_unsigned(nIndex) >= entries.size())
904 throw lang::IndexOutOfBoundsException();
905 if(!IsValid())
906 throw uno::RuntimeException();
907 auto eFamily = entries[nIndex].family();
908 assert(eFamily != SfxStyleFamily::All);
909 auto& rxFamily = m_vFamilies[eFamily];
910 if(!rxFamily.is())
911 rxFamily = new XStyleFamily(m_pDocShell, eFamily);
912 return uno::Any(rxFamily);
913}
914
916{
918}
919
921 { return true; }
922
923void SwXStyleFamilies::loadStylesFromURL(const OUString& rURL,
924 const uno::Sequence< beans::PropertyValue >& aOptions)
925{
926 SolarMutexGuard aGuard;
927 if(!IsValid() || rURL.isEmpty())
928 throw uno::RuntimeException();
929 SwgReaderOption aOpt;
930 aOpt.SetFrameFormats(true);
931 aOpt.SetTextFormats(true);
932 aOpt.SetPageDescs(true);
933 aOpt.SetNumRules(true);
934 aOpt.SetMerge(false);
935 for(const auto& rProperty: aOptions)
936 {
937 bool bValue = false;
938 if(rProperty.Value.getValueType() == cppu::UnoType<bool>::get())
939 bValue = rProperty.Value.get<bool>();
940
941 if(rProperty.Name == UNO_NAME_OVERWRITE_STYLES)
942 aOpt.SetMerge(!bValue);
943 else if(rProperty.Name == UNO_NAME_LOAD_NUMBERING_STYLES)
944 aOpt.SetNumRules(bValue);
945 else if(rProperty.Name == UNO_NAME_LOAD_PAGE_STYLES)
946 aOpt.SetPageDescs(bValue);
947 else if(rProperty.Name == UNO_NAME_LOAD_FRAME_STYLES)
948 aOpt.SetFrameFormats(bValue);
949 else if(rProperty.Name == UNO_NAME_LOAD_TEXT_STYLES)
950 aOpt.SetTextFormats(bValue);
951 else if(rProperty.Name == "InputStream")
952 {
953 Reference<XInputStream> xInputStream;
954 if (!(rProperty.Value >>= xInputStream))
955 throw IllegalArgumentException("Parameter 'InputStream' could not be converted to "
956 "type 'com::sun::star::io::XInputStream'",
957 nullptr, 0);
958
959 aOpt.SetInputStream(xInputStream);
960
961 }
962 }
963 const ErrCode nErr = m_pDocShell->LoadStylesFromFile( rURL, aOpt, true );
964 if(nErr)
965 throw io::IOException();
966}
967
968uno::Sequence< beans::PropertyValue > SwXStyleFamilies::getStyleLoaderOptions()
969{
970 const uno::Any aVal(true);
977 });
978}
979
981 SfxItemSet const& rSet, std::u16string_view rPropName, bool const bFooter,
982 SvxSetItem const*& o_rpItem)
983{
984 o_rpItem = rSet.GetItemIfSet(
985 bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET,
986 false);
987 if (!o_rpItem &&
988 rPropName == UNO_NAME_FIRST_IS_SHARED)
989 { // fdo#79269 header may not exist, check footer then
990 o_rpItem = rSet.GetItemIfSet(
991 (!bFooter) ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET,
992 false);
993 }
994 return o_rpItem;
995}
996
997uno::Reference<css::style::XStyle> SwXStyleFamilies::CreateStyle(SfxStyleFamily eFamily, SwDoc& rDoc)
998{
999 auto& entries(lcl_GetStyleFamilyEntries());
1000 const auto pEntry = std::find_if(entries.begin(), entries.end(),
1001 [eFamily] (const StyleFamilyEntry& e) { return e.family() == eFamily; });
1002 return pEntry == entries.end() ? nullptr : pEntry->createStyle(nullptr, rDoc.GetDocShell(), "");
1003}
1004
1005// FIXME: Ugly special casing that should die.
1006uno::Reference<css::style::XStyle> SwXStyleFamilies::CreateStyleCondParagraph(SwDoc& rDoc)
1007 { return new SwXStyle(&rDoc, SfxStyleFamily::Para, true); };
1008
1009uno::Any XStyleFamily::getByIndex(sal_Int32 nIndex)
1010{
1011 SolarMutexGuard aGuard;
1012 if(nIndex < 0)
1013 throw lang::IndexOutOfBoundsException();
1014 if(!m_pBasePool)
1015 throw uno::RuntimeException();
1016 OUString sStyleName;
1017 try
1018 {
1019 SwStyleNameMapper::FillUIName(m_rEntry.translateIndex(nIndex), sStyleName);
1020 } catch(...) {}
1021 if (sStyleName.isEmpty())
1022 GetCountOrName(&sStyleName, nIndex);
1023 if(sStyleName.isEmpty())
1024 throw lang::IndexOutOfBoundsException();
1025 return getByName(sStyleName);
1026}
1027
1028uno::Any XStyleFamily::getByName(const OUString& rName)
1029{
1030 SolarMutexGuard aGuard;
1031 OUString sStyleName;
1032 SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.poolId());
1033 if(!m_pBasePool)
1034 throw uno::RuntimeException();
1035 SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName, m_rEntry.family());
1036 if(!pBase)
1037 throw container::NoSuchElementException(rName);
1038 uno::Reference<style::XStyle> xStyle = FindStyle(sStyleName);
1039 if(!xStyle.is())
1040 xStyle = m_rEntry.createStyle(m_pBasePool, m_pDocShell, m_rEntry.family() == SfxStyleFamily::Frame ? pBase->GetName() : sStyleName);
1041 return uno::Any(xStyle);
1042}
1043
1044uno::Sequence<OUString> XStyleFamily::getElementNames()
1045{
1046 SolarMutexGuard aGuard;
1047 if(!m_pBasePool)
1048 throw uno::RuntimeException();
1049 std::vector<OUString> vRet;
1050 std::unique_ptr<SfxStyleSheetIterator> pIt = m_pBasePool->CreateIterator(m_rEntry.family());
1051 for (SfxStyleSheetBase* pStyle = pIt->First(); pStyle; pStyle = pIt->Next())
1052 {
1053 OUString sName;
1054 SwStyleNameMapper::FillProgName(pStyle->GetName(), sName, m_rEntry.poolId());
1055 vRet.push_back(sName);
1056 }
1058}
1059
1060sal_Bool XStyleFamily::hasByName(const OUString& rName)
1061{
1062 SolarMutexGuard aGuard;
1063 if(!m_pBasePool)
1064 throw uno::RuntimeException();
1065 OUString sStyleName;
1066 SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.poolId());
1067 SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName, m_rEntry.family());
1068 return nullptr != pBase;
1069}
1070
1071void XStyleFamily::insertByName(const OUString& rName, const uno::Any& rElement)
1072{
1073 SolarMutexGuard aGuard;
1074 if(!m_pBasePool)
1075 throw uno::RuntimeException();
1076 OUString sStyleName;
1077 SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.poolId());
1078 SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName, m_rEntry.family());
1079 SfxStyleSheetBase* pUINameBase = m_pBasePool->Find(sStyleName, m_rEntry.family());
1080 if(pBase || pUINameBase)
1081 throw container::ElementExistException();
1082 if(rElement.getValueType().getTypeClass() != uno::TypeClass_INTERFACE)
1083 throw lang::IllegalArgumentException();
1084 if (SwGetPoolIdFromName::CellStyle == m_rEntry.poolId())
1085 {
1086 // handle cell style
1087 uno::Reference<style::XStyle> xStyle = rElement.get<uno::Reference<style::XStyle>>();
1088 SwXTextCellStyle* pNewStyle = dynamic_cast<SwXTextCellStyle*>(xStyle.get());
1089 if (!pNewStyle)
1090 throw lang::IllegalArgumentException();
1091
1092 pNewStyle->setName(sStyleName); // insertByName sets the element name
1093 m_pDocShell->GetDoc()->GetCellStyles().AddBoxFormat(*pNewStyle->GetBoxFormat(), sStyleName);
1094 pNewStyle->SetPhysical();
1095 }
1096 else if (SwGetPoolIdFromName::TabStyle == m_rEntry.poolId())
1097 {
1098 // handle table style
1099 uno::Reference<style::XStyle> xStyle = rElement.get<uno::Reference<style::XStyle>>();
1100 SwXTextTableStyle* pNewStyle = dynamic_cast<SwXTextTableStyle*>(xStyle.get());
1101 if (!pNewStyle)
1102 throw lang::IllegalArgumentException();
1103
1104 pNewStyle->setName(sStyleName); // insertByName sets the element name
1105 m_pDocShell->GetDoc()->GetTableStyles().AddAutoFormat(*pNewStyle->GetTableFormat());
1106 pNewStyle->SetPhysical();
1107 }
1108 else
1109 {
1110 uno::Reference<lang::XUnoTunnel> xStyleTunnel = rElement.get<uno::Reference<lang::XUnoTunnel>>();
1111 SwXStyle* pNewStyle = comphelper::getFromUnoTunnel<SwXStyle>(xStyleTunnel);
1112 if (!pNewStyle || !pNewStyle->IsDescriptor() || pNewStyle->GetFamily() != m_rEntry.family())
1113 throw lang::IllegalArgumentException();
1114
1115 SfxStyleSearchBits nMask = SfxStyleSearchBits::All;
1116 if(m_rEntry.family() == SfxStyleFamily::Para && !pNewStyle->IsConditional())
1117 nMask &= ~SfxStyleSearchBits::SwCondColl;
1118 m_pBasePool->Make(sStyleName, m_rEntry.family(), nMask);
1119 pNewStyle->SetDoc(m_pDocShell->GetDoc(), m_pBasePool);
1120 pNewStyle->SetStyleName(sStyleName);
1121 const OUString sParentStyleName(pNewStyle->GetParentStyleName());
1122 if (!sParentStyleName.isEmpty())
1123 {
1124 SfxStyleSheetBase* pParentBase = m_pBasePool->Find(sParentStyleName, m_rEntry.family());
1125 if(pParentBase && pParentBase->GetFamily() == m_rEntry.family() &&
1126 pParentBase->GetPool() == m_pBasePool)
1127 m_pBasePool->SetParent(m_rEntry.family(), sStyleName, sParentStyleName);
1128 }
1129 // after all, we still need to apply the properties of the descriptor
1130 pNewStyle->ApplyDescriptorProperties();
1131 }
1132}
1133
1134void XStyleFamily::replaceByName(const OUString& rName, const uno::Any& rElement)
1135{
1136 SolarMutexGuard aGuard;
1137 if(!m_pBasePool)
1138 throw uno::RuntimeException();
1139 OUString sStyleName;
1140 SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.poolId());
1141 SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName, m_rEntry.family());
1142 // replacements only for userdefined styles
1143 if(!pBase)
1144 throw container::NoSuchElementException();
1145 if (SwGetPoolIdFromName::CellStyle == m_rEntry.poolId())
1146 {
1147 // handle cell styles, don't call on assigned cell styles (TableStyle child)
1148 OUString sParent;
1149 SwBoxAutoFormat* pBoxAutoFormat = SwXTextCellStyle::GetBoxAutoFormat(m_pDocShell, sStyleName, &sParent);
1150 if (pBoxAutoFormat && sParent.isEmpty())// if parent exists then this style is assigned to a table style. Don't replace.
1151 {
1152 uno::Reference<style::XStyle> xStyle = rElement.get<uno::Reference<style::XStyle>>();
1153 SwXTextCellStyle* pStyleToReplaceWith = dynamic_cast<SwXTextCellStyle*>(xStyle.get());
1154 if (!pStyleToReplaceWith)
1155 throw lang::IllegalArgumentException();
1156
1157 pStyleToReplaceWith->setName(sStyleName);
1158 *pBoxAutoFormat = *pStyleToReplaceWith->GetBoxFormat();
1159 pStyleToReplaceWith->SetPhysical();
1160 }
1161 }
1162 else if (SwGetPoolIdFromName::TabStyle == m_rEntry.poolId())
1163 {
1164 // handle table styles
1165 SwTableAutoFormat* pTableAutoFormat = SwXTextTableStyle::GetTableAutoFormat(m_pDocShell, sStyleName);
1166 if (pTableAutoFormat)
1167 {
1168 uno::Reference<style::XStyle> xStyle = rElement.get<uno::Reference<style::XStyle>>();
1169 SwXTextTableStyle* pStyleToReplaceWith = dynamic_cast<SwXTextTableStyle*>(xStyle.get());
1170 if (!pStyleToReplaceWith)
1171 throw lang::IllegalArgumentException();
1172
1173 pStyleToReplaceWith->setName(sStyleName);
1174 *pTableAutoFormat = *pStyleToReplaceWith->GetTableFormat();
1175 pStyleToReplaceWith->SetPhysical();
1176 }
1177 }
1178 else
1179 {
1180 if(!pBase->IsUserDefined())
1181 throw lang::IllegalArgumentException();
1182 //if there's an object available to this style then it must be invalidated
1183 uno::Reference<style::XStyle> xStyle = FindStyle(pBase->GetName());
1184 if(xStyle.is())
1185 {
1186 SwXStyle* pStyle = comphelper::getFromUnoTunnel<SwXStyle>(xStyle);
1187 if(pStyle)
1188 pStyle->Invalidate();
1189 }
1190 m_pBasePool->Remove(pBase);
1191 insertByName(rName, rElement);
1192 }
1193}
1194
1195void XStyleFamily::removeByName(const OUString& rName)
1196{
1197 SolarMutexGuard aGuard;
1198 if(!m_pBasePool)
1199 throw uno::RuntimeException();
1200 OUString sName;
1201 SwStyleNameMapper::FillUIName(rName, sName, m_rEntry.poolId());
1202 SfxStyleSheetBase* pBase = m_pBasePool->Find(sName, m_rEntry.family());
1203 if(!pBase)
1204 throw container::NoSuchElementException();
1205 if (SwGetPoolIdFromName::CellStyle == m_rEntry.poolId())
1206 {
1207 // handle cell style
1208 m_pDocShell->GetDoc()->GetCellStyles().RemoveBoxFormat(rName);
1209 }
1210 else if (SwGetPoolIdFromName::TabStyle == m_rEntry.poolId())
1211 {
1212 // handle table style
1213 m_pDocShell->GetDoc()->GetTableStyles().EraseAutoFormat(rName);
1214 }
1215 else
1216 m_pBasePool->Remove(pBase);
1217}
1218
1219uno::Any SAL_CALL XStyleFamily::getPropertyValue( const OUString& sPropertyName )
1220{
1221 if(sPropertyName != "DisplayName")
1222 throw beans::UnknownPropertyException( "unknown property: " + sPropertyName, static_cast<OWeakObject *>(this) );
1223 SolarMutexGuard aGuard;
1224 return uno::Any(SwResId(m_rEntry.resId()));
1225}
1226
1227
1228SwXStyle* XStyleFamily::FindStyle(std::u16string_view rStyleName) const
1229{
1230 const size_t nLCount = m_pBasePool->GetSizeOfVector();
1231 for(size_t i = 0; i < nLCount; ++i)
1232 {
1233 SfxListener* pListener = m_pBasePool->GetListener(i);
1234 SwXStyle* pTempStyle = dynamic_cast<SwXStyle*>(pListener);
1235 if(pTempStyle && pTempStyle->GetFamily() == m_rEntry.family() && pTempStyle->GetStyleName() == rStyleName)
1236 return pTempStyle;
1237 }
1238 return nullptr;
1239}
1240
1242{
1243 auto& entries(lcl_GetStyleFamilyEntries());
1244 const auto pEntry = std::find_if(entries.begin(), entries.end(),
1245 [eFamily] (const StyleFamilyEntry& e) { return e.family() == eFamily; });
1246 if(pEntry != entries.end())
1247 return pEntry->poolId();
1248 SAL_WARN("sw.uno", "someone asking for all styles in unostyle.cxx!" );
1250}
1251
1252const uno::Sequence<sal_Int8>& SwXStyle::getUnoTunnelId()
1253{
1254 static const comphelper::UnoIdInit theSwXStyleUnoTunnelId;
1255 return theSwXStyleUnoTunnelId.getSeq();
1256}
1257
1258sal_Int64 SAL_CALL SwXStyle::getSomething(const uno::Sequence<sal_Int8>& rId)
1259{
1260 return comphelper::getSomethingImpl(rId, this);
1261}
1262
1263
1264uno::Sequence< OUString > SwXStyle::getSupportedServiceNames()
1265{
1266 tools::Long nCount = 1;
1267 if(SfxStyleFamily::Para == m_rEntry.family())
1268 {
1269 nCount = 5;
1270 if(m_bIsConditional)
1271 nCount++;
1272 }
1273 else if(SfxStyleFamily::Char == m_rEntry.family())
1274 nCount = 5;
1275 else if(SfxStyleFamily::Page == m_rEntry.family())
1276 nCount = 3;
1277 uno::Sequence< OUString > aRet(nCount);
1278 OUString* pArray = aRet.getArray();
1279 pArray[0] = "com.sun.star.style.Style";
1280 switch(m_rEntry.family())
1281 {
1282 case SfxStyleFamily::Char:
1283 pArray[1] = "com.sun.star.style.CharacterStyle";
1284 pArray[2] = "com.sun.star.style.CharacterProperties";
1285 pArray[3] = "com.sun.star.style.CharacterPropertiesAsian";
1286 pArray[4] = "com.sun.star.style.CharacterPropertiesComplex";
1287 break;
1288 case SfxStyleFamily::Page:
1289 pArray[1] = "com.sun.star.style.PageStyle";
1290 pArray[2] = "com.sun.star.style.PageProperties";
1291 break;
1292 case SfxStyleFamily::Para:
1293 pArray[1] = "com.sun.star.style.ParagraphStyle";
1294 pArray[2] = "com.sun.star.style.ParagraphProperties";
1295 pArray[3] = "com.sun.star.style.ParagraphPropertiesAsian";
1296 pArray[4] = "com.sun.star.style.ParagraphPropertiesComplex";
1297 if(m_bIsConditional)
1298 pArray[5] = "com.sun.star.style.ConditionalParagraphStyle";
1299 break;
1300
1301 default:
1302 ;
1303 }
1304 return aRet;
1305}
1306
1307static uno::Reference<beans::XPropertySet> lcl_InitStandardStyle(const SfxStyleFamily eFamily, uno::Reference<container::XNameAccess> const & rxStyleFamily)
1308{
1309 using return_t = decltype(lcl_InitStandardStyle(eFamily, rxStyleFamily));
1310 if(eFamily != SfxStyleFamily::Para && eFamily != SfxStyleFamily::Page)
1311 return {};
1312 auto aResult(rxStyleFamily->getByName("Standard"));
1313 if(!aResult.has<return_t>())
1314 return {};
1315 return aResult.get<return_t>();
1316}
1317
1318static uno::Reference<container::XNameAccess> lcl_InitStyleFamily(SwDoc* pDoc, const StyleFamilyEntry& rEntry)
1319{
1320 using return_t = decltype(lcl_InitStyleFamily(pDoc, rEntry));
1321 if(rEntry.family() != SfxStyleFamily::Char
1322 && rEntry.family() != SfxStyleFamily::Para
1323 && rEntry.family() != SfxStyleFamily::Page)
1324 return {};
1325 auto xModel(pDoc->GetDocShell()->GetBaseModel());
1326 uno::Reference<style::XStyleFamiliesSupplier> xFamilySupplier(xModel, uno::UNO_QUERY);
1327 auto xFamilies = xFamilySupplier->getStyleFamilies();
1328 auto aResult(xFamilies->getByName(rEntry.name()));
1329 if(!aResult.has<return_t>())
1330 return {};
1331 return aResult.get<return_t>();
1332}
1333
1334static bool lcl_InitConditional(SfxStyleSheetBasePool* pBasePool, const SfxStyleFamily eFamily, const OUString& rStyleName)
1335{
1336 if(!pBasePool || eFamily != SfxStyleFamily::Para)
1337 return false;
1338 SfxStyleSheetBase* pBase = pBasePool->Find(rStyleName, eFamily);
1339 SAL_WARN_IF(!pBase, "sw.uno", "where is the style?" );
1340 if(!pBase)
1341 return false;
1343 if(nId != USHRT_MAX)
1345 return RES_CONDTXTFMTCOLL == static_cast<SwDocStyleSheet*>(pBase)->GetCollection()->Which();
1346}
1347
1348static const StyleFamilyEntry& lcl_GetStyleEntry(const SfxStyleFamily eFamily)
1349{
1350 auto& entries = lcl_GetStyleFamilyEntries();
1351 const auto pEntry = std::find_if(entries.begin(), entries.end(),
1352 [eFamily] (const StyleFamilyEntry& e) { return e.family() == eFamily; });
1353 assert(pEntry != entries.end());
1354 return *pEntry;
1355}
1356
1357SwXStyle::SwXStyle(SwDoc* pDoc, SfxStyleFamily eFamily, bool bConditional)
1358 : m_pDoc(pDoc)
1359 , m_rEntry(lcl_GetStyleEntry(eFamily))
1360 , m_bIsDescriptor(true)
1361 , m_bIsConditional(bConditional)
1362 , m_pBasePool(nullptr)
1363 , m_xStyleFamily(lcl_InitStyleFamily(pDoc, m_rEntry))
1364 , m_xStyleData(lcl_InitStandardStyle(eFamily, m_xStyleFamily))
1365{
1366 assert(!m_bIsConditional || m_rEntry.family() == SfxStyleFamily::Para); // only paragraph styles are conditional
1367 // Register ourselves as a listener to the document (via the page descriptor)
1369 m_pPropertiesImpl = std::make_unique<SwStyleProperties_Impl>(
1370 aSwMapProvider.GetPropertySet(m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.propMapType())->getPropertyMap());
1371}
1372
1373SwXStyle::SwXStyle(SfxStyleSheetBasePool* pPool, SfxStyleFamily eFamily, SwDoc* pDoc, const OUString& rStyleName)
1374 : m_pDoc(pDoc)
1375 , m_sStyleName(rStyleName)
1376 , m_rEntry(lcl_GetStyleEntry(eFamily))
1377 , m_bIsDescriptor(false)
1378 , m_bIsConditional(lcl_InitConditional(pPool, eFamily, rStyleName))
1379 , m_pBasePool(pPool)
1380{ }
1381
1382SwXStyle::~SwXStyle()
1383{
1384 SolarMutexGuard aGuard;
1385 if(m_pBasePool)
1386 SfxListener::EndListening(*m_pBasePool);
1387 m_pPropertiesImpl.reset();
1389}
1390
1391void SwXStyle::Notify(const SfxHint& rHint)
1392{
1393 if(rHint.GetId() == SfxHintId::Dying)
1394 {
1395 m_pDoc = nullptr;
1396 m_xStyleData.clear();
1397 m_xStyleFamily.clear();
1398 }
1399}
1400
1401OUString SwXStyle::getName()
1402{
1403 SolarMutexGuard aGuard;
1404 if(!m_pBasePool)
1405 return m_sStyleName;
1406 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName, m_rEntry.family());
1407 SAL_WARN_IF(!pBase, "sw.uno", "where is the style?");
1408 if(!pBase)
1409 throw uno::RuntimeException();
1410 OUString aString;
1411 SwStyleNameMapper::FillProgName(pBase->GetName(), aString, lcl_GetSwEnumFromSfxEnum ( m_rEntry.family()));
1412 return aString;
1413}
1414
1415void SwXStyle::setName(const OUString& rName)
1416{
1417 SolarMutexGuard aGuard;
1418 if(!m_pBasePool)
1419 {
1420 m_sStyleName = rName;
1421 return;
1422 }
1423 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName, m_rEntry.family());
1424 SAL_WARN_IF(!pBase, "sw.uno", "where is the style?");
1425 if(!pBase || !pBase->IsUserDefined())
1426 throw uno::RuntimeException();
1427 rtl::Reference<SwDocStyleSheet> xTmp(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
1428 if(!xTmp->SetName(rName))
1429 throw uno::RuntimeException();
1430 m_sStyleName = rName;
1431}
1432
1433sal_Bool SwXStyle::isUserDefined()
1434{
1435 SolarMutexGuard aGuard;
1436 if(!m_pBasePool)
1437 throw uno::RuntimeException();
1438 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName, m_rEntry.family());
1439 //if it is not found it must be non user defined
1440 return pBase && pBase->IsUserDefined();
1441}
1442
1443sal_Bool SwXStyle::isInUse()
1444{
1445 SolarMutexGuard aGuard;
1446 if(!m_pBasePool)
1447 throw uno::RuntimeException();
1448 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName, m_rEntry.family(), SfxStyleSearchBits::Used);
1449 return pBase && pBase->IsUsed();
1450}
1451
1452OUString SwXStyle::getParentStyle()
1453{
1454 SolarMutexGuard aGuard;
1455 if(!m_pBasePool)
1456 {
1457 if(!m_bIsDescriptor)
1458 throw uno::RuntimeException();
1459 return m_sParentStyleName;
1460 }
1461 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName, m_rEntry.family());
1462 OUString aString;
1463 if(pBase)
1464 aString = pBase->GetParent();
1465 SwStyleNameMapper::FillProgName(aString, aString, lcl_GetSwEnumFromSfxEnum(m_rEntry.family()));
1466 return aString;
1467}
1468
1469void SwXStyle::setParentStyle(const OUString& rParentStyle)
1470{
1471 SolarMutexGuard aGuard;
1472 OUString sParentStyle;
1473 SwStyleNameMapper::FillUIName(rParentStyle, sParentStyle, lcl_GetSwEnumFromSfxEnum ( m_rEntry.family()) );
1474 if(!m_pBasePool)
1475 {
1476 if(!m_bIsDescriptor)
1477 throw uno::RuntimeException();
1478 m_sParentStyleName = sParentStyle;
1479 try
1480 {
1481 const auto aAny = m_xStyleFamily->getByName(sParentStyle);
1482 m_xStyleData = aAny.get<decltype(m_xStyleData)>();
1483 }
1484 catch(...)
1485 { }
1486 return;
1487 }
1488 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName, m_rEntry.family());
1489 if(!pBase)
1490 throw uno::RuntimeException();
1491 rtl::Reference<SwDocStyleSheet> xBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
1492 //make it a 'real' style - necessary for pooled styles
1493 xBase->GetItemSet();
1494 if(xBase->GetParent() != sParentStyle)
1495 {
1496 if(!xBase->SetParent(sParentStyle))
1497 throw uno::RuntimeException();
1498 }
1499}
1500
1501uno::Reference<beans::XPropertySetInfo> SwXStyle::getPropertySetInfo()
1502{
1503 if(m_bIsConditional)
1504 {
1505 assert(m_rEntry.family() == SfxStyleFamily::Para);
1507 return xCondParaRef;
1508 }
1509 return m_rEntry.xPSInfo();
1510}
1511
1512void SwXStyle::ApplyDescriptorProperties()
1513{
1514 m_bIsDescriptor = false;
1515 m_xStyleData.clear();
1516 m_xStyleFamily.clear();
1517 m_pPropertiesImpl->Apply(*this);
1518}
1519
1520namespace {
1522 {
1523 // Page styles
1524 STR_POOLPAGE_STANDARD,
1525 STR_POOLPAGE_FIRST,
1526 STR_POOLPAGE_LEFT,
1527 STR_POOLPAGE_RIGHT,
1528 STR_POOLPAGE_ENVELOPE,
1529 STR_POOLPAGE_REGISTER,
1530 STR_POOLPAGE_HTML,
1531 STR_POOLPAGE_FOOTNOTE,
1532 STR_POOLPAGE_ENDNOTE,
1533 STR_POOLPAGE_LANDSCAPE
1534 };
1535}
1536
1537const SwPageDesc* SwStyleBase_Impl::GetOldPageDesc()
1538{
1539 if(!m_pOldPageDesc)
1540 {
1541 SwPageDesc *pd = m_rDoc.FindPageDesc(m_rStyleName);
1542 if(pd)
1543 m_pOldPageDesc = pd;
1544
1545 if(!m_pOldPageDesc)
1546 {
1547 for (size_t i = 0; i < SAL_N_ELEMENTS(STR_POOLPAGE_ARY); ++i)
1548 {
1549 if (SwResId(STR_POOLPAGE_ARY[i]) == m_rStyleName)
1550 {
1552 break;
1553 }
1554 }
1555 }
1556 }
1557 return m_pOldPageDesc;
1558}
1559
1560
1561
1563{
1564 // check for needed metric translation
1565 if(!(rEntry.nMoreFlags & PropertyMoreFlags::METRIC_ITEM))
1566 return rEntry.nMemberId;
1567 // exception: If these ItemTypes are used, do not convert when these are negative
1568 // since this means they are intended as percent values
1569 if((XATTR_FILLBMP_SIZEX == rEntry.nWID || XATTR_FILLBMP_SIZEY == rEntry.nWID)
1570 && o_aValue.has<sal_Int32>()
1571 && o_aValue.get<sal_Int32>() < 0)
1572 return rEntry.nMemberId;
1573 if(!pDoc)
1574 return rEntry.nMemberId;
1575
1576 const SfxItemPool& rPool = pDoc->GetAttrPool();
1577 const MapUnit eMapUnit(rPool.GetMetric(rEntry.nWID));
1578 if(eMapUnit != MapUnit::Map100thMM)
1579 SvxUnoConvertFromMM(eMapUnit, o_aValue);
1580 return rEntry.nMemberId;
1581}
1582template<>
1583void SwXStyle::SetPropertyValue<HINT_BEGIN>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1584{
1585 // default ItemSet handling
1586 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet();
1587 SfxItemSet aSet(*rStyleSet.GetPool(), rEntry.nWID, rEntry.nWID);
1588 aSet.SetParent(&rStyleSet);
1589 rPropSet.setPropertyValue(rEntry, rValue, aSet);
1590 rStyleSet.Put(aSet);
1591}
1592template<>
1593void SwXStyle::SetPropertyValue<FN_UNO_HIDDEN>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1594{
1595 bool bHidden = false;
1596 if(rValue >>= bHidden)
1597 {
1598 //make it a 'real' style - necessary for pooled styles
1599 o_rStyleBase.getNewBase()->GetItemSet();
1600 o_rStyleBase.getNewBase()->SetHidden(bHidden);
1601 }
1602 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, rValue, o_rStyleBase);
1603}
1604template<>
1605void SwXStyle::SetPropertyValue<FN_UNO_STYLE_INTEROP_GRAB_BAG>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1606{
1607 o_rStyleBase.getNewBase()->GetItemSet();
1608 o_rStyleBase.getNewBase()->SetGrabBagItem(rValue);
1609 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, rValue, o_rStyleBase);
1610}
1611template<>
1612void SwXStyle::SetPropertyValue<sal_uInt16(XATTR_FILLGRADIENT)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1613{
1614 uno::Any aValue(rValue);
1615 const auto nMemberId(lcl_TranslateMetric(rEntry, m_pDoc, aValue));
1616 if(MID_NAME == nMemberId)
1617 {
1618 // add set commands for FillName items
1619 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet();
1620 if(!aValue.has<OUString>())
1621 throw lang::IllegalArgumentException();
1622 SvxShape::SetFillAttribute(rEntry.nWID, aValue.get<OUString>(), rStyleSet);
1623 }
1624 else if(MID_BITMAP == nMemberId)
1625 {
1626 if(sal_uInt16(XATTR_FILLBITMAP) == rEntry.nWID)
1627 {
1628 Graphic aNullGraphic;
1629 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet();
1630 XFillBitmapItem aXFillBitmapItem(std::move(aNullGraphic));
1631 aXFillBitmapItem.PutValue(aValue, nMemberId);
1632 rStyleSet.Put(aXFillBitmapItem);
1633 }
1634 }
1635 else
1636 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, aValue, o_rStyleBase);
1637}
1638template<>
1639void SwXStyle::SetPropertyValue<sal_uInt16(RES_BACKGROUND)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1640{
1641 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet();
1642 const std::unique_ptr<SvxBrushItem> aOriginalBrushItem(getSvxBrushItemFromSourceSet(rStyleSet, RES_BACKGROUND, true, m_pDoc->IsInXMLImport()));
1643 std::unique_ptr<SvxBrushItem> aChangedBrushItem(aOriginalBrushItem->Clone());
1644
1645 uno::Any aValue(rValue);
1646 const auto nMemberId(lcl_TranslateMetric(rEntry, m_pDoc, aValue));
1647 aChangedBrushItem->PutValue(aValue, nMemberId);
1648
1649 // 0xff is already the default - but if BackTransparent is set
1650 // to true, it must be applied in the item set on ODF import
1651 // to potentially override parent style, which is unknown yet
1652 if(*aChangedBrushItem == *aOriginalBrushItem && (MID_GRAPHIC_TRANSPARENT != nMemberId || !aValue.has<bool>() || !aValue.get<bool>()))
1653 return;
1654
1655 setSvxBrushItemAsFillAttributesToTargetSet(*aChangedBrushItem, rStyleSet);
1656}
1657template<>
1658void SwXStyle::SetPropertyValue<OWN_ATTR_FILLBMP_MODE>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1659{
1660 drawing::BitmapMode eMode;
1661 if(!(rValue >>= eMode))
1662 {
1663 if(!rValue.has<sal_Int32>())
1664 throw lang::IllegalArgumentException();
1665 eMode = static_cast<drawing::BitmapMode>(rValue.get<sal_Int32>());
1666 }
1667 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet();
1668 rStyleSet.Put(XFillBmpStretchItem(drawing::BitmapMode_STRETCH == eMode));
1669 rStyleSet.Put(XFillBmpTileItem(drawing::BitmapMode_REPEAT == eMode));
1670}
1671template<>
1672void SwXStyle::SetPropertyValue<sal_uInt16(RES_PAPER_BIN)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1673{
1674 if(!rValue.has<OUString>())
1675 throw lang::IllegalArgumentException();
1676 SfxPrinter* pPrinter = m_pDoc->getIDocumentDeviceAccess().getPrinter(true);
1677 OUString sValue(rValue.get<OUString>());
1678 using printeridx_t = decltype(pPrinter->GetPaperBinCount());
1679 printeridx_t nBin = std::numeric_limits<printeridx_t>::max();
1680 if(sValue == "[From printer settings]")
1681 nBin = std::numeric_limits<printeridx_t>::max()-1;
1682 else if(pPrinter)
1683 {
1684 for(sal_uInt16 i=0, nEnd = pPrinter->GetPaperBinCount(); i < nEnd; ++i)
1685 {
1686 if (sValue == pPrinter->GetPaperBinName(i))
1687 {
1688 nBin = i;
1689 break;
1690 }
1691 }
1692 }
1693 if(nBin == std::numeric_limits<printeridx_t>::max())
1694 throw lang::IllegalArgumentException();
1695 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet();
1696 SfxItemSet aSet(*rStyleSet.GetPool(), rEntry.nWID, rEntry.nWID);
1697 aSet.SetParent(&rStyleSet);
1698 rPropSet.setPropertyValue(rEntry, uno::Any(static_cast<sal_Int8>(nBin == std::numeric_limits<printeridx_t>::max()-1 ? -1 : nBin)), aSet);
1699 rStyleSet.Put(aSet);
1700}
1701template<>
1702void SwXStyle::SetPropertyValue<FN_UNO_NUM_RULES>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1703{
1704 auto xNumberTunnel(rValue.get<uno::Reference<container::XIndexReplace>>());
1705 if(!xNumberTunnel)
1706 throw lang::IllegalArgumentException();
1707 SwXNumberingRules* pSwXRules = dynamic_cast<SwXNumberingRules*>(xNumberTunnel.get());
1708 if(!pSwXRules)
1709 return;
1710 SwNumRule aSetRule(*pSwXRules->GetNumRule());
1711 for(sal_uInt16 i = 0; i < MAXLEVEL; ++i)
1712 {
1713 const SwNumFormat* pFormat = aSetRule.GetNumFormat(i);
1714 if(!pFormat)
1715 continue;
1716 SwNumFormat aFormat(*pFormat);
1717 const auto& rCharName(pSwXRules->GetNewCharStyleNames()[i]);
1718 if(!rCharName.isEmpty()
1720 && (!pFormat->GetCharFormat() || pFormat->GetCharFormat()->GetName() != rCharName))
1721 {
1722 auto pCharFormatIt(std::find_if(m_pDoc->GetCharFormats()->begin(), m_pDoc->GetCharFormats()->end(),
1723 [&rCharName] (SwCharFormat* pF) { return pF->GetName() == rCharName; }));
1724 if(pCharFormatIt != m_pDoc->GetCharFormats()->end())
1725 aFormat.SetCharFormat(*pCharFormatIt);
1726 else if(m_pBasePool)
1727 {
1728 auto pBase(m_pBasePool->Find(rCharName, SfxStyleFamily::Char));
1729 if(!pBase)
1730 pBase = &m_pBasePool->Make(rCharName, SfxStyleFamily::Char);
1731 aFormat.SetCharFormat(static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat());
1732 }
1733 else
1734 aFormat.SetCharFormat(nullptr);
1735 }
1736 // same for fonts:
1737 const auto& rBulletName(pSwXRules->GetBulletFontNames()[i]);
1738 if(!rBulletName.isEmpty()
1739 && !SwXNumberingRules::isInvalidStyle(rBulletName)
1740 && (!pFormat->GetBulletFont() || pFormat->GetBulletFont()->GetFamilyName() != rBulletName))
1741 {
1742 const auto pFontListItem(static_cast<const SvxFontListItem*>(m_pDoc->GetDocShell()->GetItem(SID_ATTR_CHAR_FONTLIST)));
1743 const auto pList(pFontListItem->GetFontList());
1744 FontMetric aFontInfo(pList->Get(rBulletName, WEIGHT_NORMAL, ITALIC_NONE));
1745 vcl::Font aFont(aFontInfo);
1746 aFormat.SetBulletFont(&aFont);
1747 }
1748 aSetRule.Set(i, &aFormat);
1749 }
1750 o_rStyleBase.getNewBase()->SetNumRule(aSetRule);
1751}
1752template<>
1753void SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_OUTLINELEVEL)>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1754{
1755 if(!rValue.has<sal_Int16>())
1756 return;
1757 const auto nLevel(rValue.get<sal_Int16>());
1758 if(0 <= nLevel && nLevel <= MAXLEVEL)
1759 o_rStyleBase.getNewBase()->GetCollection()->SetAttrOutlineLevel(nLevel);
1760}
1761template<>
1762void SwXStyle::SetPropertyValue<FN_UNO_FOLLOW_STYLE>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1763{
1764 if(!rValue.has<OUString>())
1765 return;
1766 const auto sValue(rValue.get<OUString>());
1767 OUString aString;
1768 SwStyleNameMapper::FillUIName(sValue, aString, m_rEntry.poolId());
1769 o_rStyleBase.getNewBase()->SetFollow(aString);
1770}
1771
1772template <>
1773void SwXStyle::SetPropertyValue<FN_UNO_LINK_STYLE>(const SfxItemPropertyMapEntry&,
1774 const SfxItemPropertySet&,
1775 const uno::Any& rValue,
1776 SwStyleBase_Impl& o_rStyleBase)
1777{
1778 if (!rValue.has<OUString>())
1779 return;
1780 const auto sValue(rValue.get<OUString>());
1781 OUString aString;
1782 SwStyleNameMapper::FillUIName(sValue, aString, m_rEntry.poolId());
1783 o_rStyleBase.getNewBase()->SetLink(aString);
1784}
1785
1786template<>
1787void SwXStyle::SetPropertyValue<sal_uInt16(RES_PAGEDESC)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1788{
1790 {
1791 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, rValue, o_rStyleBase);
1792 return;
1793 }
1794 if(!rValue.has<OUString>())
1795 throw lang::IllegalArgumentException();
1796 // special handling for RES_PAGEDESC
1797 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet();
1798 std::unique_ptr<SwFormatPageDesc> pNewDesc;
1799 if(const SwFormatPageDesc* pItem = rStyleSet.GetItemIfSet(RES_PAGEDESC))
1800 pNewDesc.reset(new SwFormatPageDesc(*pItem));
1801 else
1802 pNewDesc.reset(new SwFormatPageDesc);
1803 const auto sValue(rValue.get<OUString>());
1804 OUString sDescName;
1806 if(pNewDesc->GetPageDesc() && pNewDesc->GetPageDesc()->GetName() == sDescName)
1807 return;
1808 if(sDescName.isEmpty())
1809 {
1810 rStyleSet.ClearItem(RES_BREAK);
1811 rStyleSet.Put(SwFormatPageDesc());
1812 }
1813 else
1814 {
1815 SwPageDesc* pPageDesc(SwPageDesc::GetByName(*m_pDoc, sDescName));
1816 if(!pPageDesc)
1817 throw lang::IllegalArgumentException();
1818 pNewDesc->RegisterToPageDesc(*pPageDesc);
1819 rStyleSet.Put(std::move(pNewDesc));
1820 }
1821}
1822template<>
1823void SwXStyle::SetPropertyValue<sal_uInt16(RES_TEXT_VERT_ADJUST)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1824{
1825 if(m_rEntry.family() != SfxStyleFamily::Page)
1826 {
1827 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, rValue, o_rStyleBase);
1828 return;
1829 }
1830 if(!m_pDoc || !rValue.has<drawing::TextVerticalAdjust>() || !o_rStyleBase.GetOldPageDesc())
1831 return;
1832 SwPageDesc* pPageDesc = m_pDoc->FindPageDesc(o_rStyleBase.GetOldPageDesc()->GetName());
1833 if(pPageDesc)
1834 pPageDesc->SetVerticalAdjustment(rValue.get<drawing::TextVerticalAdjust>());
1835}
1836template<>
1837void SwXStyle::SetPropertyValue<FN_UNO_IS_AUTO_UPDATE>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1838{
1839 if(!rValue.has<bool>())
1840 throw lang::IllegalArgumentException();
1841 const bool bAuto(rValue.get<bool>());
1842 if(SfxStyleFamily::Para == m_rEntry.family())
1843 o_rStyleBase.getNewBase()->GetCollection()->SetAutoUpdateOnDirectFormat(bAuto);
1844 else if(SfxStyleFamily::Frame == m_rEntry.family())
1845 o_rStyleBase.getNewBase()->GetFrameFormat()->SetAutoUpdateOnDirectFormat(bAuto);
1846}
1847template<>
1848void SwXStyle::SetPropertyValue<FN_UNO_PARA_STYLE_CONDITIONS>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1849{
1850 static_assert(COND_COMMAND_COUNT == 28, "invalid size of command count?");
1851 using expectedarg_t = uno::Sequence<beans::NamedValue>;
1852 if(!rValue.has<expectedarg_t>() || !m_pBasePool)
1853 throw lang::IllegalArgumentException();
1854 SwCondCollItem aCondItem;
1855 const auto aNamedValues = rValue.get<expectedarg_t>();
1856 for(const auto& rNamedValue : aNamedValues)
1857 {
1858 if(!rNamedValue.Value.has<OUString>())
1859 throw lang::IllegalArgumentException();
1860
1861 const OUString sValue(rNamedValue.Value.get<OUString>());
1862 // get UI style name from programmatic style name
1863 OUString aStyleName;
1864 SwStyleNameMapper::FillUIName(sValue, aStyleName, lcl_GetSwEnumFromSfxEnum(m_rEntry.family()));
1865
1866 // check for correct context and style name
1867 const auto nIdx(GetCommandContextIndex(rNamedValue.Name));
1868 if (nIdx == -1)
1869 throw lang::IllegalArgumentException();
1870 bool bStyleFound = false;
1871 for(auto pBase = m_pBasePool->First(SfxStyleFamily::Para); pBase; pBase = m_pBasePool->Next())
1872 {
1873 bStyleFound = pBase->GetName() == aStyleName;
1874 if (bStyleFound)
1875 break;
1876 }
1877 if (!bStyleFound)
1878 throw lang::IllegalArgumentException();
1879 aCondItem.SetStyle(&aStyleName, nIdx);
1880 }
1881 o_rStyleBase.GetItemSet().Put(aCondItem);
1882}
1883template<>
1884void SwXStyle::SetPropertyValue<FN_UNO_CATEGORY>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1885{
1886 if(!o_rStyleBase.getNewBase()->IsUserDefined() || !rValue.has<paragraphstyle_t>())
1887 throw lang::IllegalArgumentException();
1888 static const std::map<paragraphstyle_t, SfxStyleSearchBits> aUnoToCore = []{
1889 std::map<paragraphstyle_t, SfxStyleSearchBits> map;
1890 std::transform(std::begin(sParagraphStyleCategoryEntries), std::end(sParagraphStyleCategoryEntries), std::inserter(map, map.end()),
1891 [] (const ParagraphStyleCategoryEntry& rEntry) { return std::make_pair(rEntry.m_eCategory, rEntry.m_nSwStyleBits); });
1892 return map;
1893 }();
1894 const auto pUnoToCoreIt(aUnoToCore.find(rValue.get<paragraphstyle_t>()));
1895 if (pUnoToCoreIt == aUnoToCore.end())
1896 throw lang::IllegalArgumentException();
1897 o_rStyleBase.getNewBase()->SetMask( pUnoToCoreIt->second|SfxStyleSearchBits::UserDefined );
1898}
1899template<>
1900void SwXStyle::SetPropertyValue<SID_SWREGISTER_COLLECTION>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1901{
1902 OUString sName;
1903 rValue >>= sName;
1904 SwRegisterItem aReg(!sName.isEmpty());
1905 aReg.SetWhich(SID_SWREGISTER_MODE);
1906 o_rStyleBase.GetItemSet().Put(aReg);
1907 OUString aString;
1909 o_rStyleBase.GetItemSet().Put(SfxStringItem(SID_SWREGISTER_COLLECTION, aString ) );
1910}
1911template<>
1912void SwXStyle::SetPropertyValue<sal_uInt16(RES_TXTATR_CJK_RUBY)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1913{
1914 if(MID_RUBY_CHARSTYLE != rEntry.nMemberId)
1915 return;
1916 if(!rValue.has<OUString>())
1917 throw lang::IllegalArgumentException();
1918 const auto sValue(rValue.get<OUString>());
1919 SfxItemSet& rStyleSet(o_rStyleBase.GetItemSet());
1920 std::unique_ptr<SwFormatRuby> pRuby;
1921 if(const SwFormatRuby* pRubyItem = rStyleSet.GetItemIfSet(RES_TXTATR_CJK_RUBY))
1922 pRuby.reset(new SwFormatRuby(*pRubyItem));
1923 else
1924 pRuby.reset(new SwFormatRuby(OUString()));
1925 OUString sStyle;
1927 pRuby->SetCharFormatName(sValue);
1928 pRuby->SetCharFormatId(0);
1929 if(!sValue.isEmpty())
1930 {
1932 pRuby->SetCharFormatId(nId);
1933 }
1934 rStyleSet.Put(std::move(pRuby));
1935 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, rValue, o_rStyleBase);
1936}
1937template<>
1938void SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_DROP)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1939{
1941 {
1942 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, rValue, o_rStyleBase);
1943 return;
1944 }
1945 if(!rValue.has<OUString>())
1946 throw lang::IllegalArgumentException();
1947 SfxItemSet& rStyleSet(o_rStyleBase.GetItemSet());
1948 std::unique_ptr<SwFormatDrop> pDrop;
1949 if(const SwFormatDrop* pDropItem = rStyleSet.GetItemIfSet(RES_PARATR_DROP))
1950 pDrop.reset(new SwFormatDrop(*pDropItem));
1951 else
1952 pDrop.reset(new SwFormatDrop);
1953 const auto sValue(rValue.get<OUString>());
1954 OUString sStyle;
1956 auto pStyle(static_cast<SwDocStyleSheet*>(m_pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle, SfxStyleFamily::Char)));
1957 //default character style must not be set as default format
1958 if(!pStyle || pStyle->GetCharFormat() == m_pDoc->GetDfltCharFormat() )
1959 {
1960 throw lang::IllegalArgumentException();
1961 }
1962 pDrop->SetCharFormat(pStyle->GetCharFormat());
1963 rStyleSet.Put(std::move(pDrop));
1964}
1965template<>
1966void SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_NUMRULE)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1967{
1968 uno::Any aValue(rValue);
1969 lcl_TranslateMetric(rEntry, m_pDoc, aValue);
1970 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, aValue, o_rStyleBase);
1971 // --> OD 2006-10-18 #i70223#
1972 if(SfxStyleFamily::Para == m_rEntry.family() &&
1973 o_rStyleBase.getNewBase().is() && o_rStyleBase.getNewBase()->GetCollection() &&
1974 //rBase.getNewBase()->GetCollection()->GetOutlineLevel() < MAXLEVEL /* assigned to list level of outline style */) //#outline level,removed by zhaojianwei
1975 o_rStyleBase.getNewBase()->GetCollection()->IsAssignedToListLevelOfOutlineStyle())
1976 {
1977 OUString sNewNumberingRuleName;
1978 aValue >>= sNewNumberingRuleName;
1979 if(sNewNumberingRuleName.isEmpty() || sNewNumberingRuleName != m_pDoc->GetOutlineNumRule()->GetName())
1980 o_rStyleBase.getNewBase()->GetCollection()->DeleteAssignmentToListLevelOfOutlineStyle();
1981 }
1982}
1983
1984void SwXStyle::SetStyleProperty(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase)
1985{
1986 using propertytype_t = decltype(rEntry.nWID);
1987 using coresetter_t = std::function<void(SwXStyle&, const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const uno::Any&, SwStyleBase_Impl&)>;
1988 static const std::map<propertytype_t, coresetter_t> aUnoToCore{
1989 // these explicit std::mem_fn() calls shouldn't be needed, but apparently MSVC is currently too stupid for C++11 again
1990 { FN_UNO_HIDDEN, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_HIDDEN>) },
1991 { FN_UNO_STYLE_INTEROP_GRAB_BAG, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_STYLE_INTEROP_GRAB_BAG>) },
1992 { XATTR_FILLGRADIENT, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(XATTR_FILLGRADIENT)>) },
1993 { XATTR_FILLHATCH, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(XATTR_FILLGRADIENT)>) },
1994 { XATTR_FILLBITMAP, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(XATTR_FILLGRADIENT)>) },
1995 { XATTR_FILLFLOATTRANSPARENCE, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(XATTR_FILLGRADIENT)>) },
1996 { RES_BACKGROUND, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_BACKGROUND)>) },
1997 { OWN_ATTR_FILLBMP_MODE, std::mem_fn(&SwXStyle::SetPropertyValue<OWN_ATTR_FILLBMP_MODE>) },
1998 { RES_PAPER_BIN, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_PAPER_BIN)>) },
1999 { FN_UNO_NUM_RULES, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_NUM_RULES>) },
2001 { FN_UNO_FOLLOW_STYLE, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_FOLLOW_STYLE>) },
2002 { FN_UNO_LINK_STYLE, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_LINK_STYLE>) },
2003 { RES_PAGEDESC, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_PAGEDESC)>) },
2005 { FN_UNO_IS_AUTO_UPDATE, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_IS_AUTO_UPDATE>) },
2006 { FN_UNO_PARA_STYLE_CONDITIONS, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_PARA_STYLE_CONDITIONS>) },
2007 { FN_UNO_CATEGORY, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_CATEGORY>) },
2008 { SID_SWREGISTER_COLLECTION, std::mem_fn(&SwXStyle::SetPropertyValue<SID_SWREGISTER_COLLECTION>) },
2010 { RES_PARATR_DROP, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_DROP)>) },
2012 };
2013 const auto pUnoToCoreIt(aUnoToCore.find(rEntry.nWID));
2014 if(pUnoToCoreIt != aUnoToCore.end())
2015 pUnoToCoreIt->second(*this, rEntry, rPropSet, rValue, rBase);
2016 else
2017 {
2018 // adapted switch logic to a more readable state; removed goto's and made
2019 // execution of standard setting of property in ItemSet dependent of this variable
2020 uno::Any aValue(rValue);
2021 lcl_TranslateMetric(rEntry, m_pDoc, aValue);
2022 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, aValue, rBase);
2023 }
2024}
2025
2026void SwXStyle::SetPropertyValues_Impl(const uno::Sequence<OUString>& rPropertyNames, const uno::Sequence<uno::Any>& rValues)
2027{
2028 if(!m_pDoc)
2029 throw uno::RuntimeException();
2030 sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.propMapType();
2031 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
2032 const SfxItemPropertyMap &rMap = pPropSet->getPropertyMap();
2033 if(rPropertyNames.getLength() != rValues.getLength())
2034 throw lang::IllegalArgumentException();
2035
2036 SwStyleBase_Impl aBaseImpl(*m_pDoc, m_sStyleName, &GetDoc()->GetDfltTextFormatColl()->GetAttrSet()); // add pDfltTextFormatColl as parent
2037 if(m_pBasePool)
2038 {
2039 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName, m_rEntry.family());
2040 SAL_WARN_IF(!pBase, "sw.uno", "where is the style?");
2041 if(!pBase)
2042 throw uno::RuntimeException();
2043 aBaseImpl.setNewBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2044 }
2045 if(!aBaseImpl.getNewBase().is() && !m_bIsDescriptor)
2046 throw uno::RuntimeException();
2047
2048 const OUString* pNames = rPropertyNames.getConstArray();
2049 const uno::Any* pValues = rValues.getConstArray();
2050 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp)
2051 {
2052 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(pNames[nProp]);
2053 if(!pEntry || (!m_bIsConditional && pNames[nProp] == UNO_NAME_PARA_STYLE_CONDITIONS))
2054 throw beans::UnknownPropertyException("Unknown property: " + pNames[nProp], static_cast<cppu::OWeakObject*>(this));
2055 if(pEntry->nFlags & beans::PropertyAttribute::READONLY)
2056 throw beans::PropertyVetoException ("Property is read-only: " + pNames[nProp], static_cast<cppu::OWeakObject*>(this));
2057 if(aBaseImpl.getNewBase().is())
2058 SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl);
2059 else if(!m_pPropertiesImpl->SetProperty(pNames[nProp], pValues[nProp]))
2060 throw lang::IllegalArgumentException();
2061 }
2062
2063 if(aBaseImpl.HasItemSet())
2064 aBaseImpl.getNewBase()->SetItemSet(aBaseImpl.GetItemSet());
2065}
2066
2067void SwXStyle::setPropertyValues(const uno::Sequence<OUString>& rPropertyNames, const uno::Sequence<uno::Any>& rValues)
2068{
2069 SolarMutexGuard aGuard;
2070 // workaround for bad designed API
2071 try
2072 {
2073 SetPropertyValues_Impl( rPropertyNames, rValues );
2074 }
2075 catch (const beans::UnknownPropertyException &rException)
2076 {
2077 // wrap the original (here not allowed) exception in
2078 // a lang::WrappedTargetException that gets thrown instead.
2079 lang::WrappedTargetException aWExc;
2080 aWExc.TargetException <<= rException;
2081 throw aWExc;
2082 }
2083}
2084
2085SfxStyleSheetBase* SwXStyle::GetStyleSheetBase()
2086{
2087 if(!m_pBasePool)
2088 return nullptr;
2089 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName, m_rEntry.family());
2090 return pBase;
2091}
2092void SwXStyle::PrepareStyleBase(SwStyleBase_Impl& rBase)
2093{
2094 SfxStyleSheetBase* pBase(GetStyleSheetBase());
2095 if(!pBase)
2096 throw uno::RuntimeException();
2097 if(!rBase.getNewBase().is())
2098 rBase.setNewBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2099}
2100
2101template<>
2102uno::Any SwXStyle::GetStyleProperty<HINT_BEGIN>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase);
2103template<>
2104uno::Any SwXStyle::GetStyleProperty<FN_UNO_IS_PHYSICAL>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl&)
2105{
2106 SfxStyleSheetBase* pBase(GetStyleSheetBase());
2107 if(!pBase)
2108 return uno::Any(false);
2109 bool bPhys = static_cast<SwDocStyleSheet*>(pBase)->IsPhysical();
2110 // The standard character format is not existing physically
2111 if( bPhys && SfxStyleFamily::Char == GetFamily() &&
2112 static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat() &&
2113 static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat()->IsDefault() )
2114 bPhys = false;
2115 return uno::Any(bool(bPhys));
2116}
2117template<>
2118uno::Any SwXStyle::GetStyleProperty<FN_UNO_HIDDEN>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl&)
2119{
2120 SfxStyleSheetBase* pBase(GetStyleSheetBase());
2121 if(!pBase)
2122 return uno::Any(false);
2123 rtl::Reference<SwDocStyleSheet> xBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2124 return uno::Any(xBase->IsHidden());
2125}
2126template<>
2127uno::Any SwXStyle::GetStyleProperty<FN_UNO_STYLE_INTEROP_GRAB_BAG>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl&)
2128{
2129 SfxStyleSheetBase* pBase(GetStyleSheetBase());
2130 if(!pBase)
2131 return uno::Any();
2132 uno::Any aRet;
2133 rtl::Reference<SwDocStyleSheet> xBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2134 xBase->GetGrabBagItem(aRet);
2135 return aRet;
2136}
2137template<>
2138uno::Any SwXStyle::GetStyleProperty<sal_uInt16(RES_PAPER_BIN)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase)
2139{
2140 PrepareStyleBase(rBase);
2141 SfxItemSet& rSet = rBase.GetItemSet();
2142 uno::Any aValue;
2143 rPropSet.getPropertyValue(rEntry, rSet, aValue);
2144 sal_Int8 nBin(aValue.get<sal_Int8>());
2145 if(nBin == -1)
2146 return uno::Any(OUString("[From printer settings]"));
2147 SfxPrinter* pPrinter = GetDoc()->getIDocumentDeviceAccess().getPrinter(false);
2148 if(!pPrinter)
2149 return uno::Any();
2150 return uno::Any(pPrinter->GetPaperBinName(nBin));
2151}
2152template<>
2153uno::Any SwXStyle::GetStyleProperty<FN_UNO_NUM_RULES>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2154{
2155 PrepareStyleBase(rBase);
2156 const SwNumRule* pRule = rBase.getNewBase()->GetNumRule();
2157 assert(pRule && "Where is the NumRule?");
2158 uno::Reference<container::XIndexReplace> xRules(new SwXNumberingRules(*pRule, GetDoc()));
2159 return uno::Any(xRules);
2160}
2161template<>
2162uno::Any SwXStyle::GetStyleProperty<sal_uInt16(RES_PARATR_OUTLINELEVEL)>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2163{
2164 PrepareStyleBase(rBase);
2165 SAL_WARN_IF(SfxStyleFamily::Para != GetFamily(), "sw.uno", "only paras");
2166 return uno::Any(sal_Int16(rBase.getNewBase()->GetCollection()->GetAttrOutlineLevel()));
2167}
2168template<>
2169uno::Any SwXStyle::GetStyleProperty<FN_UNO_FOLLOW_STYLE>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2170{
2171 PrepareStyleBase(rBase);
2172 OUString aString;
2173 SwStyleNameMapper::FillProgName(rBase.getNewBase()->GetFollow(), aString, lcl_GetSwEnumFromSfxEnum(GetFamily()));
2174 return uno::Any(aString);
2175}
2176
2177template <>
2178uno::Any SwXStyle::GetStyleProperty<FN_UNO_LINK_STYLE>(const SfxItemPropertyMapEntry&,
2179 const SfxItemPropertySet&,
2180 SwStyleBase_Impl& rBase)
2181{
2182 PrepareStyleBase(rBase);
2183 OUString aString;
2184 SwStyleNameMapper::FillProgName(rBase.getNewBase()->GetLink(), aString,
2185 lcl_GetSwEnumFromSfxEnum(GetFamily()));
2186 return uno::Any(aString);
2187}
2188
2189template<>
2190uno::Any SwXStyle::GetStyleProperty<sal_uInt16(RES_PAGEDESC)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase)
2191{
2192 PrepareStyleBase(rBase);
2194 return GetStyleProperty<HINT_BEGIN>(rEntry, rPropSet, rBase);
2195 // special handling for RES_PAGEDESC
2196 const SwFormatPageDesc* pItem =
2197 rBase.GetItemSet().GetItemIfSet(RES_PAGEDESC);
2198 if(!pItem)
2199 return uno::Any();
2200 const SwPageDesc* pDesc = pItem->GetPageDesc();
2201 if(!pDesc)
2202 return uno::Any();
2203 OUString aString;
2205 return uno::Any(aString);
2206}
2207template<>
2208uno::Any SwXStyle::GetStyleProperty<FN_UNO_IS_AUTO_UPDATE>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2209{
2210 PrepareStyleBase(rBase);
2211 switch(GetFamily())
2212 {
2213 case SfxStyleFamily::Para : return uno::Any(rBase.getNewBase()->GetCollection()->IsAutoUpdateOnDirectFormat());
2214 case SfxStyleFamily::Frame: return uno::Any(rBase.getNewBase()->GetFrameFormat()->IsAutoUpdateOnDirectFormat());
2215 default: return uno::Any();
2216 }
2217}
2218template<>
2219uno::Any SwXStyle::GetStyleProperty<FN_UNO_DISPLAY_NAME>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2220{
2221 PrepareStyleBase(rBase);
2222 return uno::Any(rBase.getNewBase()->GetName());
2223}
2224template<>
2225uno::Any SwXStyle::GetStyleProperty<FN_UNO_PARA_STYLE_CONDITIONS>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2226{
2227 PrepareStyleBase(rBase);
2228 static_assert(COND_COMMAND_COUNT == 28, "invalid size of command count?");
2229 uno::Sequence<beans::NamedValue> aSeq(COND_COMMAND_COUNT);
2230 sal_uInt16 nIndex = 0;
2231 for(auto& rNV : asNonConstRange(aSeq))
2232 {
2233 rNV.Name = GetCommandContextByIndex(nIndex++);
2234 rNV.Value <<= OUString();
2235 }
2236 SwFormat* pFormat = static_cast<SwDocStyleSheet*>(GetStyleSheetBase())->GetCollection();
2237 if(pFormat && RES_CONDTXTFMTCOLL == pFormat->Which())
2238 {
2239 const CommandStruct* pCmds = SwCondCollItem::GetCmds();
2240 beans::NamedValue* pSeq = aSeq.getArray();
2241 for(sal_uInt16 n = 0; n < COND_COMMAND_COUNT; ++n)
2242 {
2243 const SwCollCondition* pCond = static_cast<SwConditionTextFormatColl*>(pFormat)->HasCondition(SwCollCondition(nullptr, pCmds[n].nCnd, pCmds[n].nSubCond));
2244 if(!pCond || !pCond->GetTextFormatColl())
2245 continue;
2246 // get programmatic style name from UI style name
2247 OUString aStyleName = pCond->GetTextFormatColl()->GetName();
2248 SwStyleNameMapper::FillProgName(aStyleName, aStyleName, lcl_GetSwEnumFromSfxEnum(GetFamily()));
2249 pSeq[n].Value <<= aStyleName;
2250 }
2251 }
2252 return uno::Any(aSeq);
2253}
2254template<>
2255uno::Any SwXStyle::GetStyleProperty<FN_UNO_CATEGORY>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2256{
2257 PrepareStyleBase(rBase);
2258 static const std::map<collectionbits_t, paragraphstyle_t> aUnoToCore = []{
2259 std::map<collectionbits_t, paragraphstyle_t> map;
2260 std::transform(std::begin(sParagraphStyleCategoryEntries), std::end(sParagraphStyleCategoryEntries), std::inserter(map, map.end()),
2261 [] (const ParagraphStyleCategoryEntry& rEntry) { return std::make_pair(rEntry.m_nCollectionBits, rEntry.m_eCategory); });
2262 return map;
2263 }();
2264 const sal_uInt16 nPoolId = rBase.getNewBase()->GetCollection()->GetPoolFormatId();
2265 const auto pUnoToCoreIt(aUnoToCore.find(COLL_GET_RANGE_BITS & nPoolId));
2266 if(pUnoToCoreIt == aUnoToCore.end())
2267 return uno::Any(sal_Int16(-1));
2268 return uno::Any(pUnoToCoreIt->second);
2269}
2270template<>
2271uno::Any SwXStyle::GetStyleProperty<SID_SWREGISTER_COLLECTION>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2272{
2273 PrepareStyleBase(rBase);
2274 const SwPageDesc *pPageDesc = rBase.getNewBase()->GetPageDesc();
2275 if(!pPageDesc)
2276 return uno::Any(OUString());
2277 const SwTextFormatColl* pCol = pPageDesc->GetRegisterFormatColl();
2278 if(!pCol)
2279 return uno::Any(OUString());
2280 OUString aName;
2282 return uno::Any(aName);
2283}
2284template<>
2285uno::Any SwXStyle::GetStyleProperty<sal_uInt16(RES_BACKGROUND)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2286{
2287 PrepareStyleBase(rBase);
2288 const SfxItemSet& rSet = rBase.GetItemSet();
2289 const std::unique_ptr<SvxBrushItem> aOriginalBrushItem(getSvxBrushItemFromSourceSet(rSet, RES_BACKGROUND));
2290 uno::Any aResult;
2291 if(!aOriginalBrushItem->QueryValue(aResult, rEntry.nMemberId))
2292 SAL_WARN("sw.uno", "error getting attribute from RES_BACKGROUND.");
2293 return aResult;
2294}
2295template<>
2296uno::Any SwXStyle::GetStyleProperty<OWN_ATTR_FILLBMP_MODE>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2297{
2298 PrepareStyleBase(rBase);
2299 const SfxItemSet& rSet = rBase.GetItemSet();
2300 if (rSet.Get(XATTR_FILLBMP_TILE).GetValue())
2301 return uno::Any(drawing::BitmapMode_REPEAT);
2302 if (rSet.Get(XATTR_FILLBMP_STRETCH).GetValue())
2303 return uno::Any(drawing::BitmapMode_STRETCH);
2304 return uno::Any(drawing::BitmapMode_NO_REPEAT);
2305}
2306template<>
2307uno::Any SwXStyle::GetStyleProperty<HINT_BEGIN>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase)
2308{
2309 PrepareStyleBase(rBase);
2310 SfxItemSet& rSet = rBase.GetItemSet();
2311 uno::Any aResult;
2312 rPropSet.getPropertyValue(rEntry, rSet, aResult);
2313 //
2314 // since the sfx uint16 item now exports a sal_Int32, we may have to fix this here
2315 if(rEntry.aType == cppu::UnoType<sal_Int16>::get() && aResult.getValueType() == cppu::UnoType<sal_Int32>::get())
2316 aResult <<= static_cast<sal_Int16>(aResult.get<sal_Int32>());
2317 // check for needed metric translation
2318 if(rEntry.nMoreFlags & PropertyMoreFlags::METRIC_ITEM && GetDoc())
2319 {
2320 const SfxItemPool& rPool = GetDoc()->GetAttrPool();
2321 const MapUnit eMapUnit(rPool.GetMetric(rEntry.nWID));
2322 bool bAllowedConvert(true);
2323 // exception: If these ItemTypes are used, do not convert when these are negative
2324 // since this means they are intended as percent values
2325 if(XATTR_FILLBMP_SIZEX == rEntry.nWID || XATTR_FILLBMP_SIZEY == rEntry.nWID)
2326 bAllowedConvert = !aResult.has<sal_Int32>() || aResult.get<sal_Int32>() > 0;
2327 if(eMapUnit != MapUnit::Map100thMM && bAllowedConvert)
2328 SvxUnoConvertToMM(eMapUnit, aResult);
2329 }
2330 return aResult;
2331}
2332
2333uno::Any SwXStyle::GetStyleProperty_Impl(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase)
2334{
2335 using propertytype_t = decltype(rEntry.nWID);
2336 using coresetter_t = std::function<uno::Any(SwXStyle&, const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl&)>;
2337 static const std::map<propertytype_t, coresetter_t> aUnoToCore{
2338 // these explicit std::mem_fn() calls shouldn't be needed, but apparently MSVC is currently too stupid for C++11 again
2339 { FN_UNO_IS_PHYSICAL, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_IS_PHYSICAL>) },
2340 { FN_UNO_HIDDEN, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_HIDDEN>) },
2341 { FN_UNO_STYLE_INTEROP_GRAB_BAG, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_STYLE_INTEROP_GRAB_BAG>) },
2342 { RES_PAPER_BIN, std::mem_fn(&SwXStyle::GetStyleProperty<sal_uInt16(RES_PAPER_BIN)>) },
2343 { FN_UNO_NUM_RULES, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_NUM_RULES>) },
2344 { RES_PARATR_OUTLINELEVEL, std::mem_fn(&SwXStyle::GetStyleProperty<sal_uInt16(RES_PARATR_OUTLINELEVEL)>) },
2345 { FN_UNO_FOLLOW_STYLE, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_FOLLOW_STYLE>) },
2346 { FN_UNO_LINK_STYLE, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_LINK_STYLE>) },
2347 { RES_PAGEDESC, std::mem_fn(&SwXStyle::GetStyleProperty<sal_uInt16(RES_PAGEDESC)>) },
2348 { FN_UNO_IS_AUTO_UPDATE, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_IS_AUTO_UPDATE>) },
2349 { FN_UNO_DISPLAY_NAME, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_DISPLAY_NAME>) },
2350 { FN_UNO_PARA_STYLE_CONDITIONS, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_PARA_STYLE_CONDITIONS>) },
2351 { FN_UNO_CATEGORY, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_CATEGORY>) },
2352 { SID_SWREGISTER_COLLECTION, std::mem_fn(&SwXStyle::GetStyleProperty<SID_SWREGISTER_COLLECTION>) },
2353 { RES_BACKGROUND, std::mem_fn(&SwXStyle::GetStyleProperty<sal_uInt16(RES_BACKGROUND)>) },
2354 { OWN_ATTR_FILLBMP_MODE, std::mem_fn(&SwXStyle::GetStyleProperty<OWN_ATTR_FILLBMP_MODE>) }
2355 };
2356 const auto pUnoToCoreIt(aUnoToCore.find(rEntry.nWID));
2357 if(pUnoToCoreIt != aUnoToCore.end())
2358 return pUnoToCoreIt->second(*this, rEntry, rPropSet, rBase);
2359 return GetStyleProperty<HINT_BEGIN>(rEntry, rPropSet, rBase);
2360}
2361
2362uno::Any SwXStyle::GetPropertyValue_Impl(const SfxItemPropertySet* pPropSet, SwStyleBase_Impl& rBase, const OUString& rPropertyName)
2363{
2364 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
2365 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(rPropertyName);
2366 if(!pEntry || (!m_bIsConditional && rPropertyName == UNO_NAME_PARA_STYLE_CONDITIONS))
2367 throw beans::UnknownPropertyException("Unknown property: " + rPropertyName, static_cast<cppu::OWeakObject*>(this));
2368 if(m_pBasePool)
2369 return GetStyleProperty_Impl(*pEntry, *pPropSet, rBase);
2370 const uno::Any* pAny = nullptr;
2371 m_pPropertiesImpl->GetProperty(rPropertyName, pAny);
2372 if(pAny->hasValue())
2373 return *pAny;
2374 uno::Any aValue;
2375 switch(m_rEntry.family())
2376 {
2377 case SfxStyleFamily::Pseudo:
2378 throw uno::RuntimeException("No default value for: " + rPropertyName);
2379 break;
2380 case SfxStyleFamily::Para:
2381 case SfxStyleFamily::Page:
2382 aValue = m_xStyleData->getPropertyValue(rPropertyName);
2383 break;
2384 case SfxStyleFamily::Char:
2385 case SfxStyleFamily::Frame:
2386 {
2387 if(pEntry->nWID < POOLATTR_BEGIN || pEntry->nWID >= RES_UNKNOWNATR_END)
2388 throw uno::RuntimeException("No default value for: " + rPropertyName);
2389 SwFormat* pFormat;
2390 if(m_rEntry.family() == SfxStyleFamily::Char)
2391 pFormat = m_pDoc->GetDfltCharFormat();
2392 else
2393 pFormat = m_pDoc->GetDfltFrameFormat();
2394 const SwAttrPool* pPool = pFormat->GetAttrSet().GetPool();
2395 const SfxPoolItem& rItem = pPool->GetDefaultItem(pEntry->nWID);
2396 rItem.QueryValue(aValue, pEntry->nMemberId);
2397 }
2398 break;
2399 default:
2400 ;
2401 }
2402 return aValue;
2403}
2404
2405uno::Any SwXStyle::getPropertyValue(const OUString& rPropertyName)
2406{
2407 SolarMutexGuard aGuard;
2408 if(!m_pDoc)
2409 throw uno::RuntimeException();
2410 if(!m_pBasePool && !m_bIsDescriptor)
2411 throw uno::RuntimeException();
2412 sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.propMapType();
2413 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
2414 SwStyleBase_Impl aBase(*m_pDoc, m_sStyleName, &m_pDoc->GetDfltTextFormatColl()->GetAttrSet()); // add pDfltTextFormatColl as parent
2415 return GetPropertyValue_Impl(pPropSet, aBase, rPropertyName);
2416}
2417
2418uno::Sequence<uno::Any> SwXStyle::getPropertyValues(const uno::Sequence<OUString>& rPropertyNames)
2419{
2420 SolarMutexGuard aGuard;
2421 if(!m_pDoc)
2422 throw uno::RuntimeException();
2423 if(!m_pBasePool && !m_bIsDescriptor)
2424 throw uno::RuntimeException();
2425 sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.propMapType();
2426 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
2427 SwStyleBase_Impl aBase(*m_pDoc, m_sStyleName, &m_pDoc->GetDfltTextFormatColl()->GetAttrSet()); // add pDfltTextFormatColl as parent
2428 uno::Sequence<uno::Any> aValues(rPropertyNames.getLength());
2429 auto aValuesRange = asNonConstRange(aValues);
2430 // workaround for bad designed API
2431 try
2432 {
2433 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp)
2434 aValuesRange[nProp] = GetPropertyValue_Impl(pPropSet, aBase, rPropertyNames[nProp]);
2435 }
2436 catch(beans::UnknownPropertyException&)
2437 {
2438 css::uno::Any anyEx = cppu::getCaughtException();
2439 throw css::lang::WrappedTargetRuntimeException("Unknown property exception caught",
2440 static_cast < cppu::OWeakObject * > ( this ), anyEx );
2441 }
2442 catch(lang::WrappedTargetException&)
2443 {
2444 css::uno::Any anyEx = cppu::getCaughtException();
2445 throw lang::WrappedTargetRuntimeException("WrappedTargetException caught",
2446 static_cast < cppu::OWeakObject * > ( this ), anyEx );
2447 }
2448 return aValues;
2449}
2450
2451void SwXStyle::setPropertyValue(const OUString& rPropertyName, const uno::Any& rValue)
2452{
2453 SolarMutexGuard aGuard;
2454 const uno::Sequence<OUString> aProperties(&rPropertyName, 1);
2455 const uno::Sequence<uno::Any> aValues(&rValue, 1);
2456 SetPropertyValues_Impl(aProperties, aValues);
2457}
2458
2459beans::PropertyState SwXStyle::getPropertyState(const OUString& rPropertyName)
2460{
2461 SolarMutexGuard aGuard;
2462 uno::Sequence<OUString> aNames{rPropertyName};
2463 uno::Sequence<beans::PropertyState> aStates = getPropertyStates(aNames);
2464 return aStates.getConstArray()[0];
2465}
2466
2467// allow to retarget the SfxItemSet working on, default correctly. Only
2468// use pSourceSet below this point (except in header/footer processing)
2469static const SfxItemSet* lcl_GetItemsetForProperty(const SfxItemSet& rSet, SfxStyleFamily eFamily, std::u16string_view rPropertyName)
2470{
2471 if(eFamily != SfxStyleFamily::Page)
2472 return &rSet;
2473 const bool isFooter = o3tl::starts_with(rPropertyName, u"Footer");
2474 if(!isFooter && !o3tl::starts_with(rPropertyName, u"Header") && rPropertyName != UNO_NAME_FIRST_IS_SHARED)
2475 return &rSet;
2476 const SvxSetItem* pSetItem;
2477 if(!lcl_GetHeaderFooterItem(rSet, rPropertyName, isFooter, pSetItem))
2478 return nullptr;
2479 return &pSetItem->GetItemSet();
2480}
2481uno::Sequence<beans::PropertyState> SwXStyle::getPropertyStates(const uno::Sequence<OUString>& rPropertyNames)
2482{
2483 SolarMutexGuard aGuard;
2484 uno::Sequence<beans::PropertyState> aRet(rPropertyNames.getLength());
2485 beans::PropertyState* pStates = aRet.getArray();
2486
2487 if(!m_pBasePool)
2488 throw uno::RuntimeException();
2489 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName, m_rEntry.family());
2490
2491 SAL_WARN_IF(!pBase, "sw.uno", "where is the style?");
2492 if(!pBase)
2493 throw uno::RuntimeException();
2494
2495 const OUString* pNames = rPropertyNames.getConstArray();
2496 rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2497 sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.propMapType();
2498
2499 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
2500 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
2501 const SfxItemSet& rSet = xStyle->GetItemSet();
2502
2503 for(sal_Int32 i = 0; i < rPropertyNames.getLength(); ++i)
2504 {
2505 const OUString sPropName = pNames[i];
2506 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(sPropName);
2507
2508 if(!pEntry)
2509 throw beans::UnknownPropertyException("Unknown property: " + sPropName, static_cast<cppu::OWeakObject*>(this));
2510
2511 if (FN_UNO_NUM_RULES == pEntry->nWID || FN_UNO_FOLLOW_STYLE == pEntry->nWID
2512 || pEntry->nWID == FN_UNO_LINK_STYLE)
2513 {
2514 // handle NumRules first, done
2515 pStates[i] = beans::PropertyState_DIRECT_VALUE;
2516 continue;
2517 }
2518 const SfxItemSet* pSourceSet = lcl_GetItemsetForProperty(rSet, m_rEntry.family(), sPropName);
2519 if(!pSourceSet)
2520 {
2521 // if no SetItem, value is ambiguous and we are done
2522 pStates[i] = beans::PropertyState_AMBIGUOUS_VALUE;
2523 continue;
2524 }
2525 switch(pEntry->nWID)
2526 {
2528 {
2529 if(SfxItemState::SET == pSourceSet->GetItemState(XATTR_FILLBMP_STRETCH, false)
2530 || SfxItemState::SET == pSourceSet->GetItemState(XATTR_FILLBMP_TILE, false))
2531 {
2532 pStates[i] = beans::PropertyState_DIRECT_VALUE;
2533 }
2534 else
2535 {
2536 pStates[i] = beans::PropertyState_AMBIGUOUS_VALUE;
2537 }
2538 }
2539 break;
2540 case RES_BACKGROUND:
2541 {
2542 // for FlyFrames we need to mark the used properties from type RES_BACKGROUND
2543 // as beans::PropertyState_DIRECT_VALUE to let users of this property call
2544 // getPropertyValue where the member properties will be mapped from the
2545 // fill attributes to the according SvxBrushItem entries
2547 {
2548 pStates[i] = beans::PropertyState_DIRECT_VALUE;
2549 }
2550 else
2551 {
2552 pStates[i] = beans::PropertyState_DEFAULT_VALUE;
2553 }
2554 }
2555 break;
2556 default:
2557 {
2558 pStates[i] = pPropSet->getPropertyState(*pEntry, *pSourceSet);
2559
2560 if(SfxStyleFamily::Page == m_rEntry.family() && SID_ATTR_PAGE_SIZE == pEntry->nWID && beans::PropertyState_DIRECT_VALUE == pStates[i])
2561 {
2562 const SvxSizeItem& rSize = rSet.Get(SID_ATTR_PAGE_SIZE);
2563 sal_uInt8 nMemberId = pEntry->nMemberId & 0x7f;
2564
2565 if((LONG_MAX == rSize.GetSize().Width() && (MID_SIZE_WIDTH == nMemberId || MID_SIZE_SIZE == nMemberId)) ||
2566 (LONG_MAX == rSize.GetSize().Height() && MID_SIZE_HEIGHT == nMemberId))
2567 {
2568 pStates[i] = beans::PropertyState_DEFAULT_VALUE;
2569 }
2570 }
2571 }
2572 }
2573 }
2574 return aRet;
2575}
2576
2577void SwXStyle::setPropertyToDefault(const OUString& rPropertyName)
2578{
2579 const uno::Sequence<OUString> aSequence(&rPropertyName, 1);
2580 setPropertiesToDefault(aSequence);
2581}
2582
2583static SwFormat* lcl_GetFormatForStyle(SwDoc const * pDoc, const rtl::Reference<SwDocStyleSheet>& xStyle, const SfxStyleFamily eFamily)
2584{
2585 if(!xStyle.is())
2586 return nullptr;
2587 switch(eFamily)
2588 {
2589 case SfxStyleFamily::Char: return xStyle->GetCharFormat();
2590 case SfxStyleFamily::Para: return xStyle->GetCollection();
2591 case SfxStyleFamily::Frame: return xStyle->GetFrameFormat();
2592 case SfxStyleFamily::Page:
2593 {
2594 SwPageDesc* pDesc(pDoc->FindPageDesc(xStyle->GetPageDesc()->GetName()));
2595 if(pDesc)
2596 return &pDesc->GetMaster();
2597 }
2598 break;
2599 default: ;
2600 }
2601 return nullptr;
2602}
2603
2604void SAL_CALL SwXStyle::setPropertiesToDefault(const uno::Sequence<OUString>& aPropertyNames)
2605{
2606 SolarMutexGuard aGuard;
2607 const rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(GetStyleSheetBase())));
2608 SwFormat* pTargetFormat = lcl_GetFormatForStyle(m_pDoc, xStyle, m_rEntry.family());
2609 if(!pTargetFormat)
2610 {
2611 if(!m_bIsDescriptor)
2612 return;
2613 for(const auto& rName : aPropertyNames)
2614 m_pPropertiesImpl->ClearProperty(rName);
2615 return;
2616 }
2617 const sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.propMapType();
2618 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
2619 const SfxItemPropertyMap &rMap = pPropSet->getPropertyMap();
2620 for(const auto& rName : aPropertyNames)
2621 {
2622 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(rName);
2623 if(!pEntry)
2624 throw beans::UnknownPropertyException("Unknown property: " + rName, static_cast<cppu::OWeakObject*>(this));
2625 if (pEntry->nWID == FN_UNO_FOLLOW_STYLE || pEntry->nWID == FN_UNO_LINK_STYLE
2626 || pEntry->nWID == FN_UNO_NUM_RULES)
2627 throw uno::RuntimeException("Cannot reset: " + rName, static_cast<cppu::OWeakObject*>(this));
2628 if(pEntry->nFlags & beans::PropertyAttribute::READONLY)
2629 throw uno::RuntimeException("setPropertiesToDefault: property is read-only: " + rName, static_cast<cppu::OWeakObject*>(this));
2630 if(pEntry->nWID == RES_PARATR_OUTLINELEVEL)
2631 {
2632 static_cast<SwTextFormatColl*>(pTargetFormat)->DeleteAssignmentToListLevelOfOutlineStyle();
2633 continue;
2634 }
2635 pTargetFormat->ResetFormatAttr(pEntry->nWID);
2636 if(OWN_ATTR_FILLBMP_MODE == pEntry->nWID)
2637 {
2638 //
2639 SwDoc* pDoc = pTargetFormat->GetDoc();
2641 aSet.SetParent(&pTargetFormat->GetAttrSet());
2642
2643 aSet.ClearItem(XATTR_FILLBMP_STRETCH);
2644 aSet.ClearItem(XATTR_FILLBMP_TILE);
2645
2646 pTargetFormat->SetFormatAttr(aSet);
2647 }
2648 }
2649}
2650
2651void SAL_CALL SwXStyle::setAllPropertiesToDefault()
2652{
2653 SolarMutexGuard aGuard;
2654 if(!m_pBasePool)
2655 {
2656 if(!m_bIsDescriptor)
2657 throw uno::RuntimeException();
2658 m_pPropertiesImpl->ClearAllProperties();
2659 return;
2660 }
2661 const rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(GetStyleSheetBase())));
2662 if(!xStyle.is())
2663 throw uno::RuntimeException();
2664 if(SfxStyleFamily::Page == m_rEntry.family())
2665 {
2666 size_t nPgDscPos(0);
2667 SwPageDesc* pDesc = m_pDoc->FindPageDesc(xStyle->GetPageDesc()->GetName(), &nPgDscPos);
2668 SwFormat* pPageFormat(nullptr);
2669 if(pDesc)
2670 {
2671 pPageFormat = &pDesc->GetMaster();
2672 pDesc->SetUseOn(UseOnPage::All);
2673 }
2674 else
2675 pPageFormat = lcl_GetFormatForStyle(m_pDoc, xStyle, m_rEntry.family());
2676 SwPageDesc& rPageDesc = m_pDoc->GetPageDesc(nPgDscPos);
2677 rPageDesc.ResetAllMasterAttr();
2678
2679 pPageFormat->SetPageFormatToDefault();
2681 std::shared_ptr<SwFormatFrameSize> aFrameSz(std::make_shared<SwFormatFrameSize>(SwFrameSize::Fixed));
2682
2683 if(RES_POOLPAGE_STANDARD == rPageDesc.GetPoolFormatId())
2684 {
2685 if(m_pDoc->getIDocumentDeviceAccess().getPrinter(false))
2686 {
2687 const Size aPhysSize( SvxPaperInfo::GetPaperSize(
2688 static_cast<Printer*>(m_pDoc->getIDocumentDeviceAccess().getPrinter(false))));
2689 aFrameSz->SetSize(aPhysSize);
2690 }
2691 else
2692 {
2693 aFrameSz->SetSize(SvxPaperInfo::GetDefaultPaperSize());
2694 }
2695
2696 }
2697 else
2698 {
2699 aFrameSz.reset(pStdPgDsc->GetMaster().GetFrameSize().Clone());
2700 }
2701
2702 if(pStdPgDsc->GetLandscape())
2703 {
2704 SwTwips nTmp = aFrameSz->GetHeight();
2705 aFrameSz->SetHeight(aFrameSz->GetWidth());
2706 aFrameSz->SetWidth(nTmp);
2707 }
2708
2709 pPageFormat->SetFormatAttr(*aFrameSz);
2710 m_pDoc->ChgPageDesc(nPgDscPos, m_pDoc->GetPageDesc(nPgDscPos));
2711 return;
2712 }
2713 if(SfxStyleFamily::Para == m_rEntry.family())
2714 {
2715 if(xStyle->GetCollection())
2716 xStyle->GetCollection()->DeleteAssignmentToListLevelOfOutlineStyle();
2717 }
2718 SwFormat* const pTargetFormat = lcl_GetFormatForStyle(m_pDoc, xStyle, m_rEntry.family());
2719 if(!pTargetFormat)
2720 return;
2721 pTargetFormat->ResetAllFormatAttr();
2722}
2723
2724uno::Sequence<uno::Any> SAL_CALL SwXStyle::getPropertyDefaults(const uno::Sequence<OUString>& aPropertyNames)
2725{
2726 SolarMutexGuard aGuard;
2727 sal_Int32 nCount = aPropertyNames.getLength();
2728 uno::Sequence<uno::Any> aRet(nCount);
2729 if(!nCount)
2730 return aRet;
2731 auto pRet = aRet.getArray();
2732 SfxStyleSheetBase* pBase = GetStyleSheetBase();
2733 if(!pBase)
2734 throw uno::RuntimeException();
2735 rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2736 const sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.propMapType();
2737 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
2738 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
2739
2740 const SfxItemSet &rSet = xStyle->GetItemSet(), *pParentSet = rSet.GetParent();
2741 for(sal_Int32 i = 0; i < nCount; ++i)
2742 {
2743 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(aPropertyNames[i]);
2744
2745 if(!pEntry)
2746 throw beans::UnknownPropertyException("Unknown property: " + aPropertyNames[i], static_cast < cppu::OWeakObject * >(this));
2747 // these cannot be in an item set, especially not the
2748 // parent set, so the default value is void
2749 if (pEntry->nWID >= RES_UNKNOWNATR_END)
2750 continue;
2751
2752 if(pParentSet)
2753 {
2754 aSwMapProvider.GetPropertySet(nPropSetId)->getPropertyValue(aPropertyNames[i], *pParentSet, pRet[i]);
2755 }
2756 else if(pEntry->nWID != rSet.GetPool()->GetSlotId(pEntry->nWID))
2757 {
2758 const SfxPoolItem& rItem = rSet.GetPool()->GetDefaultItem(pEntry->nWID);
2759 rItem.QueryValue(pRet[i], pEntry->nMemberId);
2760 }
2761 }
2762 return aRet;
2763}
2764
2765uno::Any SwXStyle::getPropertyDefault(const OUString& rPropertyName)
2766{
2767 const uno::Sequence<OUString> aSequence(&rPropertyName, 1);
2768 return getPropertyDefaults(aSequence)[0];
2769}
2770
2771void SwXStyle::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
2772{
2773 if((rHint.GetId() == SfxHintId::Dying) || (rHint.GetId() == SfxHintId::StyleSheetErased))
2774 {
2775 m_pBasePool = nullptr;
2777 }
2778 else if(rHint.GetId() == SfxHintId::StyleSheetChanged)
2779 {
2780 SfxStyleSheetBasePool& rBP = static_cast<SfxStyleSheetBasePool&>(rBC);
2781 SfxStyleSheetBase* pOwnBase = rBP.Find(m_sStyleName, m_rEntry.family());
2782 if(!pOwnBase)
2783 {
2785 Invalidate();
2786 }
2787 }
2788}
2789
2790void SwXStyle::Invalidate()
2791{
2792 m_sStyleName.clear();
2793 m_pBasePool = nullptr;
2794 m_pDoc = nullptr;
2795 m_xStyleData.clear();
2796 m_xStyleFamily.clear();
2797}
2798
2799SwXPageStyle::SwXPageStyle(SfxStyleSheetBasePool& rPool, SwDocShell* pDocSh, const OUString& rStyleName)
2800 : SwXStyle(&rPool, SfxStyleFamily::Page, pDocSh->GetDoc(), rStyleName)
2801{ }
2802
2803SwXPageStyle::SwXPageStyle(SwDocShell* pDocSh)
2804 : SwXStyle(pDocSh->GetDoc(), SfxStyleFamily::Page)
2805{ }
2806
2807void SwXStyle::PutItemToSet(const SvxSetItem* pSetItem, const SfxItemPropertySet& rPropSet, const SfxItemPropertyMapEntry& rEntry, const uno::Any& rVal, SwStyleBase_Impl& rBaseImpl)
2808{
2809 // create a new SvxSetItem and get it's ItemSet as new target
2810 std::unique_ptr<SvxSetItem> pNewSetItem(pSetItem->Clone());
2811 SfxItemSet& rSetSet = pNewSetItem->GetItemSet();
2812
2813 // set parent to ItemSet to ensure XFILL_NONE as XFillStyleItem
2814 rSetSet.SetParent(&m_pDoc->GetDfltFrameFormat()->GetAttrSet());
2815
2816 // replace the used SfxItemSet at the SwStyleBase_Impl temporarily and use the
2817 // default method to set the property
2818 {
2819 SwStyleBase_Impl::ItemSetOverrider o(rBaseImpl, &rSetSet);
2820 SetStyleProperty(rEntry, rPropSet, rVal, rBaseImpl);
2821 }
2822
2823 // reset parent at ItemSet from SetItem
2824 rSetSet.SetParent(nullptr);
2825
2826 // set the new SvxSetItem at the real target and delete it
2827 rBaseImpl.GetItemSet().Put(std::move(pNewSetItem));
2828}
2829
2830void SwXPageStyle::SetPropertyValues_Impl(const uno::Sequence<OUString>& rPropertyNames, const uno::Sequence<uno::Any>& rValues)
2831{
2832 if(!GetDoc())
2833 throw uno::RuntimeException();
2834
2835 if(rPropertyNames.getLength() != rValues.getLength())
2836 throw lang::IllegalArgumentException();
2837
2839 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
2840 SwStyleBase_Impl aBaseImpl(*GetDoc(), GetStyleName(), &GetDoc()->GetDfltFrameFormat()->GetAttrSet()); // add pDfltFrameFormat as parent
2841 if(!m_pBasePool)
2842 {
2843 if(!IsDescriptor())
2844 throw uno::RuntimeException();
2845 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp)
2846 if(!m_pPropertiesImpl->SetProperty(rPropertyNames[nProp], rValues[nProp]))
2847 throw lang::IllegalArgumentException();
2848 return;
2849 }
2850 SfxStyleSheetBase* pBase = GetStyleSheetBase();
2851 if(!pBase)
2852 throw uno::RuntimeException();
2853 aBaseImpl.setNewBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2854 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp)
2855 {
2856 const OUString& rPropName = rPropertyNames[nProp];
2857 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(rPropName);
2858
2859 if(!pEntry)
2860 throw beans::UnknownPropertyException("Unknown property: " + rPropName, static_cast<cppu::OWeakObject*>(this));
2861 if(pEntry->nFlags & beans::PropertyAttribute::READONLY)
2862 throw beans::PropertyVetoException("Property is read-only: " + rPropName, static_cast<cppu::OWeakObject*>(this));
2863
2864 const bool bHeader(rPropName.startsWith("Header"));
2865 const bool bFooter(rPropName.startsWith("Footer"));
2866 const bool bFirstIsShared(rPropName == UNO_NAME_FIRST_IS_SHARED);
2867 if(bHeader || bFooter || bFirstIsShared)
2868 {
2869 switch(pEntry->nWID)
2870 {
2871 case SID_ATTR_PAGE_ON:
2872 case RES_BACKGROUND:
2873 case RES_BOX:
2874 case RES_LR_SPACE:
2875 case RES_SHADOW:
2876 case RES_UL_SPACE:
2877 case SID_ATTR_PAGE_DYNAMIC:
2878 case SID_ATTR_PAGE_SHARED:
2879 case SID_ATTR_PAGE_SHARED_FIRST:
2880 case SID_ATTR_PAGE_SIZE:
2882 {
2883 // it is a Header/Footer entry, access the SvxSetItem containing it's information
2884 const SvxSetItem* pSetItem = nullptr;
2885 if (lcl_GetHeaderFooterItem(aBaseImpl.GetItemSet(), rPropName, bFooter, pSetItem))
2886 {
2887 PutItemToSet(pSetItem, *pPropSet, *pEntry, rValues[nProp], aBaseImpl);
2888
2889 if (pEntry->nWID == SID_ATTR_PAGE_SHARED_FIRST)
2890 {
2891 // Need to add this to the other as well
2892 pSetItem = aBaseImpl.GetItemSet().GetItemIfSet(
2893 bFooter ? SID_ATTR_PAGE_HEADERSET : SID_ATTR_PAGE_FOOTERSET,
2894 false);
2895 if (pSetItem)
2896 {
2897 PutItemToSet(pSetItem, *pPropSet, *pEntry, rValues[nProp], aBaseImpl);
2898 }
2899 }
2900 }
2901 else if(pEntry->nWID == SID_ATTR_PAGE_ON && rValues[nProp].get<bool>())
2902 {
2903 // Header/footer gets switched on, create defaults and the needed SfxSetItem
2905 <RES_FRMATR_BEGIN,RES_FRMATR_END - 1, // [82
2906
2907 // FillAttribute support
2909
2910 SID_ATTR_BORDER_INNER,SID_ATTR_BORDER_INNER, // [10023
2911 SID_ATTR_PAGE_SIZE,SID_ATTR_PAGE_SIZE, // [10051
2912 SID_ATTR_PAGE_ON,SID_ATTR_PAGE_SHARED, // [10060
2913 SID_ATTR_PAGE_SHARED_FIRST,SID_ATTR_PAGE_SHARED_FIRST>
2914 aTempSet(*aBaseImpl.GetItemSet().GetPool());
2915
2916 // set correct parent to get the XFILL_NONE FillStyle as needed
2917 aTempSet.SetParent(&GetDoc()->GetDfltFrameFormat()->GetAttrSet());
2918
2919 aTempSet.Put(SfxBoolItem(SID_ATTR_PAGE_ON, true));
2921 aTempSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(constTwips_5mm, constTwips_5mm)));
2922 aTempSet.Put(SvxLRSpaceItem(RES_LR_SPACE));
2923 aTempSet.Put(SvxULSpaceItem(RES_UL_SPACE));
2924 aTempSet.Put(SfxBoolItem(SID_ATTR_PAGE_SHARED, true));
2925 aTempSet.Put(SfxBoolItem(SID_ATTR_PAGE_SHARED_FIRST, true));
2926 aTempSet.Put(SfxBoolItem(SID_ATTR_PAGE_DYNAMIC, true));
2927
2928 SvxSetItem aNewSetItem(bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, aTempSet);
2929 aBaseImpl.GetItemSet().Put(aNewSetItem);
2930 }
2931 }
2932 continue;
2938 case XATTR_FILLBMP_POS:
2942 case XATTR_FILLBMP_TILE:
2944 case XATTR_FILLCOLOR:
2946 case XATTR_FILLBITMAP:
2948 case XATTR_FILLGRADIENT:
2949 case XATTR_FILLHATCH:
2950 case XATTR_FILLSTYLE:
2954 if(bFirstIsShared) // only special handling for headers/footers here
2955 break;
2956 {
2957 const SvxSetItem* pSetItem =
2958 aBaseImpl.GetItemSet().GetItemIfSet(bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, false);
2959
2960 if(pSetItem)
2961 {
2962 // create a new SvxSetItem and get it's ItemSet as new target
2963 std::unique_ptr<SvxSetItem> pNewSetItem(pSetItem->Clone());
2964 SfxItemSet& rSetSet = pNewSetItem->GetItemSet();
2965
2966 // set parent to ItemSet to ensure XFILL_NONE as XFillStyleItem
2967 rSetSet.SetParent(&GetDoc()->GetDfltFrameFormat()->GetAttrSet());
2968
2969 // replace the used SfxItemSet at the SwStyleBase_Impl temporarily and use the
2970 // default method to set the property
2971 {
2972 SwStyleBase_Impl::ItemSetOverrider o(aBaseImpl, &rSetSet);
2973 SetStyleProperty(*pEntry, *pPropSet, rValues[nProp], aBaseImpl);
2974 }
2975
2976 // reset parent at ItemSet from SetItem
2977 rSetSet.SetParent(nullptr);
2978
2979 // set the new SvxSetItem at the real target and delete it
2980 aBaseImpl.GetItemSet().Put(std::move(pNewSetItem));
2981 }
2982 }
2983 continue;
2984 default: ;
2985 }
2986 }
2987 switch(pEntry->nWID)
2988 {
2989 case SID_ATTR_PAGE_DYNAMIC:
2990 case SID_ATTR_PAGE_SHARED:
2991 case SID_ATTR_PAGE_SHARED_FIRST:
2992 case SID_ATTR_PAGE_ON:
2994 // these slots are exclusive to Header/Footer, thus this is an error
2995 throw beans::UnknownPropertyException("Unknown property: " + rPropName, static_cast<cppu::OWeakObject*>(this));
2996 case FN_UNO_HEADER:
2997 case FN_UNO_HEADER_LEFT:
3000 case FN_UNO_FOOTER:
3001 case FN_UNO_FOOTER_LEFT:
3004 throw lang::IllegalArgumentException();
3005 case FN_PARAM_FTN_INFO:
3006 {
3007 const SwPageFootnoteInfoItem& rItem = aBaseImpl.GetItemSet().Get(FN_PARAM_FTN_INFO);
3008 std::unique_ptr<SfxPoolItem> pNewFootnoteItem(rItem.Clone());
3009 if(!pNewFootnoteItem->PutValue(rValues[nProp], pEntry->nMemberId))
3010 throw lang::IllegalArgumentException();
3011 aBaseImpl.GetItemSet().Put(std::move(pNewFootnoteItem));
3012 break;
3013 }
3014 default:
3015 {
3016 SetStyleProperty(*pEntry, *pPropSet, rValues[nProp], aBaseImpl);
3017 break;
3018 }
3019 }
3020 }
3021
3022 if(aBaseImpl.HasItemSet())
3023 {
3024 ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
3025
3026 if (undoGuard.UndoWasEnabled())
3027 {
3028 // Fix i64460: as long as Undo of page styles with header/footer causes trouble...
3029 GetDoc()->GetIDocumentUndoRedo().DelAllUndoObj();
3030 }
3031
3032 aBaseImpl.getNewBase()->SetItemSet(aBaseImpl.GetItemSet());
3033 }
3034}
3035
3036void SwXPageStyle::setPropertyValues(const uno::Sequence<OUString>& rPropertyNames, const uno::Sequence<uno::Any>& rValues)
3037{
3038 SolarMutexGuard aGuard;
3039
3040 // workaround for bad designed API
3041 try
3042 {
3043 SetPropertyValues_Impl(rPropertyNames, rValues);
3044 }
3045 catch (const beans::UnknownPropertyException &rException)
3046 {
3047 // wrap the original (here not allowed) exception in
3048 // a lang::WrappedTargetException that gets thrown instead.
3049 lang::WrappedTargetException aWExc;
3050 aWExc.TargetException <<= rException;
3051 throw aWExc;
3052 }
3053}
3054
3055static uno::Reference<text::XText> lcl_makeHeaderFooter(const sal_uInt16 nRes, const bool bHeader, SwFrameFormat const*const pFrameFormat)
3056{
3057 if (!pFrameFormat)
3058 return nullptr;
3059 const SfxItemSet& rSet = pFrameFormat->GetAttrSet();
3060 const SfxPoolItem* pItem;
3061 if(SfxItemState::SET != rSet.GetItemState(nRes, true, &pItem))
3062 return nullptr;
3063 SwFrameFormat* const pHeadFootFormat = bHeader
3064 ? static_cast<SwFormatHeader*>(const_cast<SfxPoolItem*>(pItem))->GetHeaderFormat()
3065 : static_cast<SwFormatFooter*>(const_cast<SfxPoolItem*>(pItem))->GetFooterFormat();
3066 if(!pHeadFootFormat)
3067 return nullptr;
3068 return SwXHeadFootText::CreateXHeadFootText(*pHeadFootFormat, bHeader);
3069}
3070
3071uno::Sequence<uno::Any> SwXPageStyle::GetPropertyValues_Impl(const uno::Sequence<OUString>& rPropertyNames)
3072{
3073 if(!GetDoc())
3074 throw uno::RuntimeException();
3075
3076 sal_Int32 nLength = rPropertyNames.getLength();
3077 uno::Sequence<uno::Any> aRet (nLength);
3078 auto aRetRange = asNonConstRange(aRet);
3079 if(!m_pBasePool)
3080 {
3081 if(!IsDescriptor())
3082 throw uno::RuntimeException();
3083 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp)
3084 {
3085 const uno::Any* pAny = nullptr;
3086 m_pPropertiesImpl->GetProperty(rPropertyNames[nProp], pAny);
3087 if (!pAny->hasValue())
3088 aRetRange[nProp] = m_xStyleData->getPropertyValue(rPropertyNames[nProp]);
3089 else
3090 aRetRange[nProp] = *pAny;
3091 }
3092 return aRet;
3093 }
3095 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
3096 SwStyleBase_Impl aBase(*GetDoc(), GetStyleName(), &GetDoc()->GetDfltFrameFormat()->GetAttrSet()); // add pDfltFrameFormat as parent
3097 SfxStyleSheetBase* pBase = GetStyleSheetBase();
3098 if(!pBase)
3099 throw uno::RuntimeException();
3100 for(sal_Int32 nProp = 0; nProp < nLength; ++nProp)
3101 {
3102 const OUString& rPropName = rPropertyNames[nProp];
3103 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(rPropName);
3104
3105 if (!pEntry)
3106 throw beans::UnknownPropertyException("Unknown property: " + rPropName, static_cast < cppu::OWeakObject * > ( this ) );
3107 const bool bHeader(rPropName.startsWith("Header"));
3108 const bool bFooter(rPropName.startsWith("Footer"));
3109 const bool bFirstIsShared(rPropName == UNO_NAME_FIRST_IS_SHARED);
3110 if(bHeader || bFooter || bFirstIsShared)
3111 {
3112 switch(pEntry->nWID)
3113 {
3114 case SID_ATTR_PAGE_ON:
3115 case RES_BACKGROUND:
3116 case RES_BOX:
3117 case RES_LR_SPACE:
3118 case RES_SHADOW:
3119 case RES_UL_SPACE:
3120 case SID_ATTR_PAGE_DYNAMIC:
3121 case SID_ATTR_PAGE_SHARED:
3122 case SID_ATTR_PAGE_SHARED_FIRST:
3123 case SID_ATTR_PAGE_SIZE:
3125 {
3126 // slot is a Header/Footer slot
3127 rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pBase) ) );
3128 const SfxItemSet& rSet = xStyle->GetItemSet();
3129 const SvxSetItem* pSetItem;
3130
3131 if (lcl_GetHeaderFooterItem(rSet, rPropName, bFooter, pSetItem))
3132 {
3133 // get from SfxItemSet of the corresponding SfxSetItem
3134 const SfxItemSet& rSetSet = pSetItem->GetItemSet();
3135 {
3136 SwStyleBase_Impl::ItemSetOverrider o(aBase, &const_cast< SfxItemSet& >(rSetSet));
3137 aRetRange[nProp] = GetStyleProperty_Impl(*pEntry, *pPropSet, aBase);
3138 }
3139 }
3140 else if(pEntry->nWID == SID_ATTR_PAGE_ON)
3141 {
3142 // header/footer is not available, thus off. Default is <false>, though
3143 aRetRange[nProp] <<= false;
3144 }
3145 }
3146 continue;
3152 case XATTR_FILLBMP_POS:
3156 case XATTR_FILLBMP_TILE:
3158 case XATTR_FILLCOLOR:
3160 case XATTR_FILLBITMAP:
3162 case XATTR_FILLGRADIENT:
3163 case XATTR_FILLHATCH:
3164 case XATTR_FILLSTYLE:
3168 if(bFirstIsShared) // only special handling for headers/footers here
3169 break;
3170 {
3171 rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pBase) ) );
3172 const SfxItemSet& rSet = xStyle->GetItemSet();
3173 const SvxSetItem* pSetItem =
3174 rSet.GetItemIfSet(bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, false);
3175 if(pSetItem)
3176 {
3177 // set at SfxItemSet of the corresponding SfxSetItem
3178 const SfxItemSet& rSetSet = pSetItem->GetItemSet();
3179 {
3180 SwStyleBase_Impl::ItemSetOverrider o(aBase, &const_cast<SfxItemSet&>(rSetSet));
3181 aRetRange[nProp] = GetStyleProperty_Impl(*pEntry, *pPropSet, aBase);
3182 }
3183 }
3184 }
3185 continue;
3186 default: ;
3187 }
3188 }
3189 switch(pEntry->nWID)
3190 {
3191 // these slots are exclusive to Header/Footer, thus this is an error
3192 case SID_ATTR_PAGE_DYNAMIC:
3193 case SID_ATTR_PAGE_SHARED:
3194 case SID_ATTR_PAGE_SHARED_FIRST:
3195 case SID_ATTR_PAGE_ON:
3197 throw beans::UnknownPropertyException( "Unknown property: " + rPropName, static_cast < cppu::OWeakObject * > ( this ) );
3198 case FN_UNO_HEADER:
3199 case FN_UNO_HEADER_LEFT:
3202 case FN_UNO_FOOTER:
3203 case FN_UNO_FOOTER_LEFT:
3206 {
3207 bool bLeft(false);
3208 bool bFirst(false);
3209 sal_uInt16 nRes = 0;
3210 switch(pEntry->nWID)
3211 {
3212 case FN_UNO_HEADER: nRes = RES_HEADER; break;
3213 case FN_UNO_HEADER_LEFT: nRes = RES_HEADER; bLeft = true; break;
3214 case FN_UNO_HEADER_FIRST: nRes = RES_HEADER; bFirst = true; break;
3215 case FN_UNO_HEADER_RIGHT: nRes = RES_HEADER; break;
3216 case FN_UNO_FOOTER: nRes = RES_FOOTER; break;
3217 case FN_UNO_FOOTER_LEFT: nRes = RES_FOOTER; bLeft = true; break;
3218 case FN_UNO_FOOTER_FIRST: nRes = RES_FOOTER; bFirst = true; break;
3219 case FN_UNO_FOOTER_RIGHT: nRes = RES_FOOTER; break;
3220 default: ;
3221 }
3222
3223 const SwPageDesc* pDesc = aBase.GetOldPageDesc();
3224 assert(pDesc);
3225 const SwFrameFormat* pFrameFormat = nullptr;
3226 bool bShare = (nRes == RES_HEADER && pDesc->IsHeaderShared()) || (nRes == RES_FOOTER && pDesc->IsFooterShared());
3227 bool bShareFirst = pDesc->IsFirstShared();
3228 // TextLeft returns the left content if there is one,
3229 // Text and TextRight return the master content.
3230 // TextRight does the same as Text and is for
3231 // compatibility only.
3232 if(bLeft && !bShare)
3233 pFrameFormat = &pDesc->GetLeft();
3234 else if(bFirst && !bShareFirst)
3235 {
3236 pFrameFormat = &pDesc->GetFirstMaster();
3237 // no need to make GetFirstLeft() accessible
3238 // since it is always shared
3239 }
3240 else
3241 pFrameFormat = &pDesc->GetMaster();
3242 const uno::Reference<text::XText> xRet = lcl_makeHeaderFooter(nRes, nRes == RES_HEADER, pFrameFormat);
3243 if (xRet.is())
3244 aRetRange[nProp] <<= xRet;
3245 }
3246 break;
3247 case FN_PARAM_FTN_INFO:
3248 {
3249 rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
3250 const SfxItemSet& rSet = xStyle->GetItemSet();
3251 const SfxPoolItem& rItem = rSet.Get(FN_PARAM_FTN_INFO);
3252 rItem.QueryValue(aRetRange[nProp], pEntry->nMemberId);
3253 }
3254 break;
3255 default:
3256 aRetRange[nProp] = GetStyleProperty_Impl(*pEntry, *pPropSet, aBase);
3257 }
3258 }
3259 return aRet;
3260}
3261
3262uno::Sequence<uno::Any> SwXPageStyle::getPropertyValues(const uno::Sequence<OUString>& rPropertyNames)
3263{
3264 SolarMutexGuard aGuard;
3265 uno::Sequence<uno::Any> aValues;
3266
3267 // workaround for bad designed API
3268 try
3269 {
3270 aValues = GetPropertyValues_Impl(rPropertyNames);
3271 }
3272 catch(beans::UnknownPropertyException &)
3273 {
3274 css::uno::Any anyEx = cppu::getCaughtException();
3275 throw lang::WrappedTargetRuntimeException("Unknown property exception caught",
3276 static_cast < cppu::OWeakObject * > ( this ), anyEx );
3277 }
3278 catch(lang::WrappedTargetException &)
3279 {
3280 css::uno::Any anyEx = cppu::getCaughtException();
3281 throw lang::WrappedTargetRuntimeException("WrappedTargetException caught",
3282 static_cast < cppu::OWeakObject * > ( this ), anyEx );
3283 }
3284
3285 return aValues;
3286}
3287
3288uno::Any SwXPageStyle::getPropertyValue(const OUString& rPropertyName)
3289{
3290 SolarMutexGuard aGuard;
3291 const uno::Sequence<OUString> aProperties(&rPropertyName, 1);
3292 return GetPropertyValues_Impl(aProperties)[0];
3293}
3294
3295void SwXPageStyle::setPropertyValue(const OUString& rPropertyName, const uno::Any& rValue)
3296{
3297 SolarMutexGuard aGuard;
3298 const uno::Sequence<OUString> aProperties(&rPropertyName, 1);
3299 const uno::Sequence<uno::Any> aValues(&rValue, 1);
3300
3301 // Trick: if the Domain Mapper changes the props of shared header/footer,
3302 // store the old ones in time for later use.
3303 const bool bIsHeader = rPropertyName == UNO_NAME_HEADER_IS_SHARED;
3304 const bool bIsFooter = rPropertyName == UNO_NAME_FOOTER_IS_SHARED;
3305 if ((bIsFooter || bIsHeader) && rValue == uno::Any(true))
3306 {
3307 // Find the matching page descriptor
3308 for (size_t i = 0; i < GetDoc()->GetPageDescCnt(); i++)
3309 {
3310 auto pPageDesc = &GetDoc()->GetPageDesc(i);
3311 // If we have the right page descriptor stash the necessary formats in import time.
3312 if (pPageDesc->GetName() == GetStyleName())
3313 {
3314 auto pLeftHeader = pPageDesc->GetLeft().GetHeader().GetHeaderFormat();
3315 if (bIsHeader && pLeftHeader)
3316 {
3317 pPageDesc->StashFrameFormat(pPageDesc->GetLeft(), true, true, false);
3318 pPageDesc->StashFrameFormat(pPageDesc->GetFirstMaster(), true, false, true);
3319 pPageDesc->StashFrameFormat(pPageDesc->GetFirstLeft(), true, true, true);
3320 }
3321 auto pLeftFooter = pPageDesc->GetLeft().GetFooter().GetFooterFormat();
3322 if (bIsFooter && pLeftFooter)
3323 {
3324 pPageDesc->StashFrameFormat(pPageDesc->GetLeft(), false, true, false);
3325 pPageDesc->StashFrameFormat(pPageDesc->GetFirstMaster(), false, false, true);
3326 pPageDesc->StashFrameFormat(pPageDesc->GetFirstLeft(), false, true, true);
3327 }
3328 }
3329 }
3330 }
3331 // And set the props... as we did it before.
3332 SetPropertyValues_Impl(aProperties, aValues);
3333}
3334
3335SwXFrameStyle::SwXFrameStyle(SwDoc *pDoc)
3336 : SwXFrameStyle_Base(pDoc, SfxStyleFamily::Frame, false)
3337{ }
3338
3339void SwXFrameStyle::SetItem(sal_uInt16 eAtr, const SfxPoolItem& rItem)
3340{
3341 assert(eAtr >= RES_FRMATR_BEGIN && eAtr < RES_FRMATR_END);
3342 SfxStyleSheetBase* pBase = GetStyleSheetBase();
3343 if(!pBase)
3344 return;
3345 rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
3346 SfxItemSet& rStyleSet = xStyle->GetItemSet();
3347 SfxItemSet aSet(*rStyleSet.GetPool(), sal_uInt16(eAtr), sal_uInt16(eAtr));
3348 aSet.Put(rItem);
3349 xStyle->SetItemSet(aSet);
3350}
3351
3352const SfxPoolItem* SwXFrameStyle::GetItem(sal_uInt16 eAtr)
3353{
3354 assert(eAtr >= RES_FRMATR_BEGIN && eAtr < RES_FRMATR_END);
3355 SfxStyleSheetBase* pBase = GetStyleSheetBase();
3356 if(!pBase)
3357 return nullptr;
3358 rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
3359 return &xStyle->GetItemSet().Get(eAtr);
3360}
3361
3362uno::Reference<container::XNameReplace> SwXFrameStyle::getEvents()
3363{
3364 return new SwFrameStyleEventDescriptor(*this);
3365}
3366
3367// Already implemented autostyle families: 3
3368#define AUTOSTYLE_FAMILY_COUNT 3
3370{
3374};
3375
3377{
3378 std::vector<std::shared_ptr<SfxItemSet>> mAutoStyles;
3379 std::vector<std::shared_ptr<SfxItemSet>>::iterator m_aIter;
3382public:
3384 bool hasMoreElements() { return m_aIter != mAutoStyles.end(); }
3385 std::shared_ptr<SfxItemSet> const & nextElement() { return *(m_aIter++); }
3387 SwDoc& getDoc() const { return m_rDoc; }
3388};
3389
3391 SwUnoCollection(rDocShell.GetDoc()), m_pDocShell( &rDocShell )
3392{
3393}
3394
3396{
3397}
3398
3400{
3402}
3403
3405{
3406 SolarMutexGuard aGuard;
3407 uno::Any aRet;
3408 if(nIndex < 0 || nIndex >= AUTOSTYLE_FAMILY_COUNT)
3409 throw lang::IndexOutOfBoundsException();
3410 if(!IsValid())
3411 throw uno::RuntimeException();
3412
3413 uno::Reference< style::XAutoStyleFamily > aRef;
3415 switch( nType )
3416 {
3418 {
3419 if(!m_xAutoCharStyles.is())
3421 aRef = m_xAutoCharStyles;
3422 }
3423 break;
3425 {
3426 if(!m_xAutoRubyStyles.is())
3428 aRef = m_xAutoRubyStyles;
3429 }
3430 break;
3432 {
3433 if(!m_xAutoParaStyles.is())
3435 aRef = m_xAutoParaStyles;
3436 }
3437 break;
3438
3439 default:
3440 ;
3441 }
3442 aRet <<= aRef;
3443
3444 return aRet;
3445}
3446
3448{
3450}
3451
3453{
3454 return true;
3455}
3456
3458{
3459 uno::Any aRet;
3460 if(Name == "CharacterStyles")
3461 aRet = getByIndex(0);
3462 else if(Name == "RubyStyles")
3463 aRet = getByIndex(1);
3464 else if(Name == "ParagraphStyles")
3465 aRet = getByIndex(2);
3466 else
3467 throw container::NoSuchElementException();
3468 return aRet;
3469}
3470
3471uno::Sequence< OUString > SwXAutoStyles::getElementNames()
3472{
3473 uno::Sequence< OUString > aNames(AUTOSTYLE_FAMILY_COUNT);
3474 OUString* pNames = aNames.getArray();
3475 pNames[0] = "CharacterStyles";
3476 pNames[1] = "RubyStyles";
3477 pNames[2] = "ParagraphStyles";
3478 return aNames;
3479}
3480
3482{
3483 if( Name == "CharacterStyles" ||
3484 Name == "RubyStyles" ||
3485 Name == "ParagraphStyles" )
3486 return true;
3487 else
3488 return false;
3489}
3490
3492 m_pDocShell( pDocSh ), m_eFamily(nFamily)
3493{
3494 // Register ourselves as a listener to the document (via the page descriptor)
3496}
3497
3499{
3500}
3501
3503{
3504 if(rHint.GetId() == SfxHintId::Dying)
3505 m_pDocShell = nullptr;
3506}
3507
3508uno::Reference< style::XAutoStyle > SwXAutoStyleFamily::insertStyle(
3509 const uno::Sequence< beans::PropertyValue >& Values )
3510{
3511 if (!m_pDocShell)
3512 {
3513 throw uno::RuntimeException();
3514 }
3515
3516 WhichRangesContainer pRange;
3517 const SfxItemPropertySet* pPropSet = nullptr;
3518 switch( m_eFamily )
3519 {
3521 {
3522 pRange = aCharAutoFormatSetRange;
3524 break;
3525 }
3527 {
3530 break;
3531 }
3533 {
3534 pRange = aTextNodeSetRange; // checked, already added support for [XATTR_FILL_FIRST, XATTR_FILL_LAST]
3536 break;
3537 }
3538 default: ;
3539 }
3540
3541 if( !pPropSet)
3542 throw uno::RuntimeException();
3543
3544 SwAttrSet aSet( m_pDocShell->GetDoc()->GetAttrPool(), pRange );
3545 const bool bTakeCareOfDrawingLayerFillStyle(IStyleAccess::AUTO_STYLE_PARA == m_eFamily);
3546
3547 if(!bTakeCareOfDrawingLayerFillStyle)
3548 {
3549 for( const beans::PropertyValue& rValue : Values )
3550 {
3551 try
3552 {
3553 pPropSet->setPropertyValue( rValue.Name, rValue.Value, aSet );
3554 }
3555 catch (const beans::UnknownPropertyException &)
3556 {
3557 OSL_FAIL( "Unknown property" );
3558 }
3559 catch (const lang::IllegalArgumentException &)
3560 {
3561 OSL_FAIL( "Illegal argument" );
3562 }
3563 }
3564 }
3565 else
3566 {
3567 // set parent to ItemSet to ensure XFILL_NONE as XFillStyleItem
3568 // to make cases in RES_BACKGROUND work correct; target *is* a style
3569 // where this is the case
3571
3572 // here the used DrawingLayer FillStyles are imported when family is
3573 // equal to IStyleAccess::AUTO_STYLE_PARA, thus we will need to serve the
3574 // used slots functionality here to do this correctly
3575 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
3576
3577 for( const beans::PropertyValue& rValue : Values )
3578 {
3579 const OUString& rPropName = rValue.Name;
3580 uno::Any aValue(rValue.Value);
3581 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(rPropName);
3582
3583 if (!pEntry)
3584 {
3585 SAL_WARN("sw.core", "SwXAutoStyleFamily::insertStyle: Unknown property: " << rPropName);
3586 continue;
3587 }
3588
3589 const sal_uInt8 nMemberId(pEntry->nMemberId);
3590 bool bDone(false);
3591
3592 // check for needed metric translation
3593 if(pEntry->nMoreFlags & PropertyMoreFlags::METRIC_ITEM)
3594 {
3595 bool bDoIt(true);
3596
3597 if(XATTR_FILLBMP_SIZEX == pEntry->nWID || XATTR_FILLBMP_SIZEY == pEntry->nWID)
3598 {
3599 // exception: If these ItemTypes are used, do not convert when these are negative
3600 // since this means they are intended as percent values
3601 sal_Int32 nValue = 0;
3602
3603 if(aValue >>= nValue)
3604 {
3605 bDoIt = nValue > 0;
3606 }
3607 }
3608
3609 if(bDoIt)
3610 {
3611 const SfxItemPool& rPool = m_pDocShell->GetDoc()->GetAttrPool();
3612 const MapUnit eMapUnit(rPool.GetMetric(pEntry->nWID));
3613
3614 if(eMapUnit != MapUnit::Map100thMM)
3615 {
3616 SvxUnoConvertFromMM(eMapUnit, aValue);
3617 }
3618 }
3619 }
3620
3621 switch(pEntry->nWID)
3622 {
3623 case XATTR_FILLGRADIENT:
3624 case XATTR_FILLHATCH:
3625 case XATTR_FILLBITMAP:
3627 // not yet needed; activate when LineStyle support may be added
3628 // case XATTR_LINESTART:
3629 // case XATTR_LINEEND:
3630 // case XATTR_LINEDASH:
3631 {
3632 if(MID_NAME == nMemberId)
3633 {
3634 // add set commands for FillName items
3635 OUString aTempName;
3636
3637 if(!(aValue >>= aTempName))
3638 {
3639 throw lang::IllegalArgumentException();
3640 }
3641
3642 SvxShape::SetFillAttribute(pEntry->nWID, aTempName, aSet);
3643 bDone = true;
3644 }
3645 else if (MID_BITMAP == nMemberId)
3646 {
3647 if(XATTR_FILLBITMAP == pEntry->nWID)
3648 {
3649 Graphic aNullGraphic;
3650 XFillBitmapItem aXFillBitmapItem(std::move(aNullGraphic));
3651
3652 aXFillBitmapItem.PutValue(aValue, nMemberId);
3653 aSet.Put(aXFillBitmapItem);
3654 bDone = true;
3655 }
3656 }
3657
3658 break;
3659 }
3660 case RES_BACKGROUND:
3661 {
3662 const std::unique_ptr<SvxBrushItem> aOriginalBrushItem(getSvxBrushItemFromSourceSet(aSet, RES_BACKGROUND, true, m_pDocShell->GetDoc()->IsInXMLImport()));
3663 std::unique_ptr<SvxBrushItem> aChangedBrushItem(aOriginalBrushItem->Clone());
3664
3665 aChangedBrushItem->PutValue(aValue, nMemberId);
3666
3667 if(*aChangedBrushItem != *aOriginalBrushItem)
3668 {
3669 setSvxBrushItemAsFillAttributesToTargetSet(*aChangedBrushItem, aSet);
3670 }
3671
3672 bDone = true;
3673 break;
3674 }
3676 {
3677 drawing::BitmapMode eMode;
3678
3679 if(!(aValue >>= eMode))
3680 {
3681 sal_Int32 nMode = 0;
3682
3683 if(!(aValue >>= nMode))
3684 {
3685 throw lang::IllegalArgumentException();
3686 }
3687
3688 eMode = static_cast<drawing::BitmapMode>(nMode);
3689 }
3690
3691 aSet.Put(XFillBmpStretchItem(drawing::BitmapMode_STRETCH == eMode));
3692 aSet.Put(XFillBmpTileItem(drawing::BitmapMode_REPEAT == eMode));
3693
3694 bDone = true;
3695 break;
3696 }
3697 default: break;
3698 }
3699
3700 if(!bDone)
3701 {
3702 try
3703 {
3704 pPropSet->setPropertyValue( rPropName, aValue, aSet );
3705 }
3706 catch (const beans::UnknownPropertyException &)
3707 {
3708 OSL_FAIL( "Unknown property" );
3709 }
3710 catch (const lang::IllegalArgumentException &)
3711 {
3712 OSL_FAIL( "Illegal argument" );
3713 }
3714 }
3715 }
3716
3717 // clear parent again
3718 aSet.SetParent(nullptr);
3719 }
3720
3721 // need to ensure uniqueness of evtl. added NameOrIndex items
3722 // currently in principle only needed when bTakeCareOfDrawingLayerFillStyle,
3723 // but does not hurt and is easily forgotten later eventually, so keep it
3724 // as common case
3726
3727 // AutomaticStyle creation
3728 std::shared_ptr<SfxItemSet> pSet = m_pDocShell->GetDoc()->GetIStyleAccess().cacheAutomaticStyle( aSet, m_eFamily );
3729 uno::Reference<style::XAutoStyle> xRet = new SwXAutoStyle(m_pDocShell->GetDoc(), pSet, m_eFamily);
3730
3731 return xRet;
3732}
3733
3734uno::Reference< container::XEnumeration > SwXAutoStyleFamily::createEnumeration( )
3735{
3736 if( !m_pDocShell )
3737 throw uno::RuntimeException();
3738 return uno::Reference< container::XEnumeration >
3740}
3741
3743{
3745}
3746
3748{
3749 return false;
3750}
3751
3753: m_rDoc( rInitDoc ), m_eFamily( eFam )
3754{
3755 // special case for ruby auto styles:
3756 if ( IStyleAccess::AUTO_STYLE_RUBY == eFam )
3757 {
3758 std::set< std::pair< sal_uInt16, text::RubyAdjust > > aRubyMap;
3759 SwAttrPool& rAttrPool = m_rDoc.GetAttrPool();
3760
3761 // do this in two phases otherwise we invalidate the iterators when we insert into the pool
3762 std::vector<const SwFormatRuby*> vRubyItems;
3763 for (const SfxPoolItem* pItem : rAttrPool.GetItemSurrogates(RES_TXTATR_CJK_RUBY))
3764 {
3765 auto pRubyItem = dynamic_cast<const SwFormatRuby*>(pItem);
3766 if ( pRubyItem && pRubyItem->GetTextRuby() )
3767 vRubyItems.push_back(pRubyItem);
3768 }
3769 for (const SwFormatRuby* pRubyItem : vRubyItems)
3770 {
3771 std::pair< sal_uInt16, text::RubyAdjust > aPair( pRubyItem->GetPosition(), pRubyItem->GetAdjustment() );
3772 if ( aRubyMap.insert( aPair ).second )
3773 {
3774 auto pItemSet = std::make_shared<SfxItemSetFixed<RES_TXTATR_CJK_RUBY, RES_TXTATR_CJK_RUBY>>( rAttrPool );
3775 pItemSet->Put( *pRubyItem );
3776 mAutoStyles.push_back( pItemSet );
3777 }
3778 }
3779 }
3780 else
3781 {
3783 }
3784
3785 m_aIter = mAutoStyles.begin();
3786}
3787
3789: m_pImpl( new SwAutoStylesEnumImpl( rDoc, eFam ) )
3790{
3791 // Register ourselves as a listener to the document (via the page descriptor)
3793}
3794
3796{
3797}
3798
3800{
3801 if(rHint.GetId() == SfxHintId::Dying)
3802 m_pImpl.reset();
3803}
3804
3806{
3807 if( !m_pImpl )
3808 throw uno::RuntimeException();
3809 return m_pImpl->hasMoreElements();
3810}
3811
3813{
3814 if( !m_pImpl )
3815 throw uno::RuntimeException();
3816 uno::Any aRet;
3817 if( m_pImpl->hasMoreElements() )
3818 {
3819 std::shared_ptr<SfxItemSet> pNextSet = m_pImpl->nextElement();
3820 uno::Reference< style::XAutoStyle > xAutoStyle = new SwXAutoStyle(&m_pImpl->getDoc(),
3821 pNextSet, m_pImpl->getFamily());
3822 aRet <<= xAutoStyle;
3823 }
3824 return aRet;
3825}
3826
3827// SwXAutoStyle with the family IStyleAccess::AUTO_STYLE_PARA (or
3828// PROPERTY_MAP_PARA_AUTO_STYLE) now uses DrawingLayer FillStyles to allow
3829// unified paragraph background fill, thus the UNO API implementation has to
3830// support the needed slots for these. This seems to be used only for reading
3831// (no setPropertyValue implementation here), so maybe specialized for saving
3832// the Writer Doc to ODF
3833
3835 SwDoc* pDoc,
3836 std::shared_ptr<SfxItemSet> pInitSet,
3838: mpSet(std::move(pInitSet)),
3839 meFamily(eFam),
3840 mrDoc(*pDoc)
3841{
3842 // Register ourselves as a listener to the document (via the page descriptor)
3843 //StartListening(mrDoc.getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier());
3844}
3845
3847{
3848}
3849
3851{
3852 if(rHint.GetId() == SfxHintId::Dying)
3853 mpSet.reset();
3854}
3855
3856uno::Reference< beans::XPropertySetInfo > SwXAutoStyle::getPropertySetInfo( )
3857{
3858 uno::Reference< beans::XPropertySetInfo > xRet;
3859 switch( meFamily )
3860 {
3862 {
3864 xRet = xCharRef;
3865 }
3866 break;
3868 {
3870 xRet = xRubyRef;
3871 }
3872 break;
3874 {
3876 xRet = xParaRef;
3877 }
3878 break;
3879
3880 default:
3881 ;
3882 }
3883
3884 return xRet;
3885}
3886
3887void SwXAutoStyle::setPropertyValue( const OUString& /*rPropertyName*/, const uno::Any& /*rValue*/ )
3888{
3889}
3890
3891uno::Any SwXAutoStyle::getPropertyValue( const OUString& rPropertyName )
3892{
3893 SolarMutexGuard aGuard;
3894 const uno::Sequence<OUString> aProperties(&rPropertyName, 1);
3895 return GetPropertyValues_Impl(aProperties).getConstArray()[0];
3896}
3897
3898void SwXAutoStyle::addPropertyChangeListener( const OUString& /*aPropertyName*/,
3899 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
3900{
3901}
3902
3903void SwXAutoStyle::removePropertyChangeListener( const OUString& /*aPropertyName*/,
3904 const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
3905{
3906}
3907
3908void SwXAutoStyle::addVetoableChangeListener( const OUString& /*PropertyName*/,
3909 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
3910{
3911}
3912
3913void SwXAutoStyle::removeVetoableChangeListener( const OUString& /*PropertyName*/,
3914 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
3915{
3916}
3917
3919 const uno::Sequence< OUString >& /*aPropertyNames*/,
3920 const uno::Sequence< uno::Any >& /*aValues*/ )
3921{
3922}
3923
3925 const uno::Sequence< OUString > & rPropertyNames )
3926{
3927 if( !mpSet )
3928 {
3929 throw uno::RuntimeException();
3930 }
3931
3932 // query_item
3934 switch(meFamily)
3935 {
3939 default: ;
3940 }
3941
3942 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
3943 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
3944 const OUString* pNames = rPropertyNames.getConstArray();
3945
3946 const sal_Int32 nLen(rPropertyNames.getLength());
3947 uno::Sequence< uno::Any > aRet( nLen );
3948 uno::Any* pValues = aRet.getArray();
3949 const bool bTakeCareOfDrawingLayerFillStyle(IStyleAccess::AUTO_STYLE_PARA == meFamily);
3950
3951 for( sal_Int32 i = 0; i < nLen; ++i )
3952 {
3953 const OUString sPropName = pNames[i];
3954 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(sPropName);
3955 if(!pEntry)
3956 {
3957 throw beans::UnknownPropertyException("Unknown property: " + sPropName, static_cast < cppu::OWeakObject * > ( this ) );
3958 }
3959
3960 uno::Any aTarget;
3961 bool bDone(false);
3962
3963 if ( RES_TXTATR_AUTOFMT == pEntry->nWID || RES_AUTO_STYLE == pEntry->nWID )
3964 {
3965 OUString sName(StylePool::nameOf( mpSet ));
3966 aTarget <<= sName;
3967 bDone = true;
3968 }
3969 else if(bTakeCareOfDrawingLayerFillStyle)
3970 {
3971 // add support for DrawingLayer FillStyle slots
3972 switch(pEntry->nWID)
3973 {
3974 case RES_BACKGROUND:
3975 {
3976 const std::unique_ptr<SvxBrushItem> aOriginalBrushItem(getSvxBrushItemFromSourceSet(*mpSet, RES_BACKGROUND));
3977
3978 if(!aOriginalBrushItem->QueryValue(aTarget, pEntry->nMemberId))
3979 {
3980 OSL_ENSURE(false, "Error getting attribute from RES_BACKGROUND (!)");
3981 }
3982
3983 bDone = true;
3984 break;
3985 }
3987 {
3988 if (mpSet->Get(XATTR_FILLBMP_TILE).GetValue())
3989 {
3990 aTarget <<= drawing::BitmapMode_REPEAT;
3991 }
3992 else if (mpSet->Get(XATTR_FILLBMP_STRETCH).GetValue())
3993 {
3994 aTarget <<= drawing::BitmapMode_STRETCH;
3995 }
3996 else
3997 {
3998 aTarget <<= drawing::BitmapMode_NO_REPEAT;
3999 }
4000
4001 bDone = true;
4002 break;
4003 }
4004 }
4005 }
4006
4007 if(!bDone)
4008 {
4009 pPropSet->getPropertyValue( *pEntry, *mpSet, aTarget );
4010 }
4011
4012 if(bTakeCareOfDrawingLayerFillStyle)
4013 {
4014 if(pEntry->aType == cppu::UnoType<sal_Int16>::get() && pEntry->aType != aTarget.getValueType())
4015 {
4016 // since the sfx uint16 item now exports a sal_Int32, we may have to fix this here
4017 sal_Int32 nValue = 0;
4018 if (aTarget >>= nValue)
4019 {
4020 aTarget <<= static_cast<sal_Int16>(nValue);
4021 }
4022 }
4023
4024 // check for needed metric translation
4025 if(pEntry->nMoreFlags & PropertyMoreFlags::METRIC_ITEM)
4026 {
4027 bool bDoIt(true);
4028
4029 if(XATTR_FILLBMP_SIZEX == pEntry->nWID || XATTR_FILLBMP_SIZEY == pEntry->nWID)
4030 {
4031 // exception: If these ItemTypes are used, do not convert when these are negative
4032 // since this means they are intended as percent values
4033 sal_Int32 nValue = 0;
4034
4035 if(aTarget >>= nValue)
4036 {
4037 bDoIt = nValue > 0;
4038 }
4039 }
4040
4041 if(bDoIt)
4042 {
4043 const SfxItemPool& rPool = mrDoc.GetAttrPool();
4044 const MapUnit eMapUnit(rPool.GetMetric(pEntry->nWID));
4045
4046 if(eMapUnit != MapUnit::Map100thMM)
4047 {
4048 SvxUnoConvertToMM(eMapUnit, aTarget);
4049 }
4050 }
4051 }
4052 }
4053
4054 // add value
4055 pValues[i] = aTarget;
4056 }
4057
4058 return aRet;
4059}
4060
4061uno::Sequence< uno::Any > SwXAutoStyle::getPropertyValues (
4062 const uno::Sequence< OUString >& rPropertyNames )
4063{
4064 SolarMutexGuard aGuard;
4065 uno::Sequence< uno::Any > aValues;
4066
4067 // workaround for bad designed API
4068 try
4069 {
4070 aValues = GetPropertyValues_Impl( rPropertyNames );
4071 }
4072 catch (beans::UnknownPropertyException &)
4073 {
4074 css::uno::Any exc = cppu::getCaughtException();
4075 throw lang::WrappedTargetRuntimeException("Unknown property exception caught", static_cast < cppu::OWeakObject * > ( this ), exc );
4076 }
4077 catch (lang::WrappedTargetException &)
4078 {
4079 css::uno::Any exc = cppu::getCaughtException();
4080 throw lang::WrappedTargetRuntimeException("WrappedTargetException caught", static_cast < cppu::OWeakObject * > ( this ), exc );
4081 }
4082
4083 return aValues;
4084}
4085
4087 const uno::Sequence< OUString >& /*aPropertyNames*/,
4088 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
4089{
4090}
4091
4093 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
4094{
4095}
4096
4098 const uno::Sequence< OUString >& /*aPropertyNames*/,
4099 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
4100{
4101}
4102
4103beans::PropertyState SwXAutoStyle::getPropertyState( const OUString& rPropertyName )
4104{
4105 SolarMutexGuard aGuard;
4106
4107 uno::Sequence< OUString > aNames { rPropertyName };
4108 uno::Sequence< beans::PropertyState > aStates = getPropertyStates(aNames);
4109 return aStates.getConstArray()[0];
4110}
4111
4112void SwXAutoStyle::setPropertyToDefault( const OUString& /*PropertyName*/ )
4113{
4114}
4115
4116uno::Any SwXAutoStyle::getPropertyDefault( const OUString& rPropertyName )
4117{
4118 const uno::Sequence < OUString > aSequence ( &rPropertyName, 1 );
4119 return getPropertyDefaults ( aSequence ).getConstArray()[0];
4120}
4121
4122uno::Sequence< beans::PropertyState > SwXAutoStyle::getPropertyStates(
4123 const uno::Sequence< OUString >& rPropertyNames )
4124{
4125 if (!mpSet)
4126 {
4127 throw uno::RuntimeException();
4128 }
4129
4130 SolarMutexGuard aGuard;
4131 uno::Sequence< beans::PropertyState > aRet(rPropertyNames.getLength());
4132 beans::PropertyState* pStates = aRet.getArray();
4133 const OUString* pNames = rPropertyNames.getConstArray();
4134
4136 switch(meFamily)
4137 {
4141 default: ;
4142 }
4143
4144 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
4145 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
4146 const bool bTakeCareOfDrawingLayerFillStyle(IStyleAccess::AUTO_STYLE_PARA == meFamily);
4147
4148 for(sal_Int32 i = 0; i < rPropertyNames.getLength(); i++)
4149 {
4150 const OUString sPropName = pNames[i];
4151 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(sPropName);
4152 if(!pEntry)
4153 {
4154 throw beans::UnknownPropertyException("Unknown property: " + sPropName, static_cast < cppu::OWeakObject * > ( this ) );
4155 }
4156
4157 bool bDone(false);
4158
4159 if(bTakeCareOfDrawingLayerFillStyle)
4160 {
4161 // DrawingLayer PropertyStyle support
4162 switch(pEntry->nWID)
4163 {
4165 {
4166 if(SfxItemState::SET == mpSet->GetItemState(XATTR_FILLBMP_STRETCH, false)
4167 || SfxItemState::SET == mpSet->GetItemState(XATTR_FILLBMP_TILE, false))
4168 {
4169 pStates[i] = beans::PropertyState_DIRECT_VALUE;
4170 }
4171 else
4172 {
4173 pStates[i] = beans::PropertyState_AMBIGUOUS_VALUE;
4174 }
4175
4176 bDone = true;
4177 break;
4178 }
4179 case RES_BACKGROUND:
4180 {
4182 pEntry->nMemberId))
4183 {
4184 pStates[i] = beans::PropertyState_DIRECT_VALUE;
4185 }
4186 else
4187 {
4188 pStates[i] = beans::PropertyState_DEFAULT_VALUE;
4189 }
4190 bDone = true;
4191
4192 break;
4193 }
4194 }
4195 }
4196
4197 if(!bDone)
4198 {
4199 pStates[i] = pPropSet->getPropertyState(*pEntry, *mpSet );
4200 }
4201 }
4202
4203 return aRet;
4204}
4205
4207{
4208}
4209
4211 const uno::Sequence< OUString >& /*rPropertyNames*/ )
4212{
4213}
4214
4215uno::Sequence< uno::Any > SwXAutoStyle::getPropertyDefaults(
4216 const uno::Sequence< OUString >& /*aPropertyNames*/ )
4217{
4218 return { };
4219}
4220
4221uno::Sequence< beans::PropertyValue > SwXAutoStyle::getProperties()
4222{
4223 if( !mpSet )
4224 throw uno::RuntimeException();
4225 SolarMutexGuard aGuard;
4226 std::vector< beans::PropertyValue > aPropertyVector;
4227
4228 sal_Int8 nPropSetId = 0;
4229 switch(meFamily)
4230 {
4234 default: ;
4235 }
4236
4237 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
4238 const SfxItemPropertyMap &rMap = pPropSet->getPropertyMap();
4239
4240 SfxItemSet& rSet = *mpSet;
4241 SfxItemIter aIter(rSet);
4242
4243 for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem())
4244 {
4245 const sal_uInt16 nWID = pItem->Which();
4246
4247 // TODO: Optimize - and fix! the old iteration filled each WhichId
4248 // only once but there are more properties than WhichIds
4249 for( const auto pEntry : rMap.getPropertyEntries() )
4250 {
4251 if ( pEntry->nWID == nWID )
4252 {
4253 beans::PropertyValue aPropertyValue;
4254 aPropertyValue.Name = pEntry->aName;
4255 pItem->QueryValue( aPropertyValue.Value, pEntry->nMemberId );
4256 aPropertyVector.push_back( aPropertyValue );
4257 }
4258 }
4259 }
4260
4261 const sal_Int32 nCount = aPropertyVector.size();
4262 uno::Sequence< beans::PropertyValue > aRet( nCount );
4263 beans::PropertyValue* pProps = aRet.getArray();
4264
4265 for ( int i = 0; i < nCount; ++i, pProps++ )
4266 {
4267 *pProps = aPropertyVector[i];
4268 }
4269
4270 return aRet;
4271}
4272
4274 m_pDocShell(pDocShell), m_pTableAutoFormat(pTableAutoFormat), m_bPhysical(true)
4275{
4277}
4278
4279SwXTextTableStyle::SwXTextTableStyle(SwDocShell* pDocShell, const OUString& rTableAutoFormatName) :
4280 m_pDocShell(pDocShell), m_pTableAutoFormat_Impl(new SwTableAutoFormat(rTableAutoFormatName)), m_bPhysical(false)
4281{
4284}
4285
4286uno::Reference<style::XStyle> SwXTextTableStyle::CreateXTextTableStyle(SwDocShell* pDocShell, const OUString& rTableAutoFormatName)
4287{
4288 SolarMutexGuard aGuard;
4289 uno::Reference<style::XStyle> xTextTableStyle;
4290 SwTableAutoFormat* pAutoFormat = GetTableAutoFormat(pDocShell, rTableAutoFormatName);
4291 if (pAutoFormat && pAutoFormat->GetName() == rTableAutoFormatName)
4292 {
4293 xTextTableStyle.set(pAutoFormat->GetXObject(), uno::UNO_QUERY);
4294 if (!xTextTableStyle.is())
4295 {
4296 xTextTableStyle.set(new SwXTextTableStyle(pDocShell, pAutoFormat));
4297 pAutoFormat->SetXObject(xTextTableStyle);
4298 }
4299 }
4300
4301 // If corresponding AutoFormat doesn't exist create a non physical style.
4302 if (!xTextTableStyle.is())
4303 {
4304 xTextTableStyle.set(new SwXTextTableStyle(pDocShell, rTableAutoFormatName));
4305 SAL_INFO("sw.uno", "creating SwXTextTableStyle for non existing SwTableAutoFormat");
4306 }
4307
4308 return xTextTableStyle;
4309}
4310
4312{
4313 const std::vector<sal_Int32> aTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap();
4314 assert(aTableTemplateMap.size() == STYLE_COUNT && "can not map SwTableAutoFormat to a SwXTextTableStyle");
4315 for (sal_Int32 i=0; i<STYLE_COUNT; ++i)
4316 {
4317 SwBoxAutoFormat* pBoxFormat = &m_pTableAutoFormat->GetBoxFormat(aTableTemplateMap[i]);
4318 uno::Reference<style::XStyle> xCellStyle(pBoxFormat->GetXObject(), uno::UNO_QUERY);
4319 if (!xCellStyle.is())
4320 {
4321 xCellStyle.set(new SwXTextCellStyle(m_pDocShell, pBoxFormat, m_pTableAutoFormat->GetName()));
4322 pBoxFormat->SetXObject(xCellStyle);
4323 }
4324 m_aCellStyles[i] = xCellStyle;
4325 }
4326}
4327
4329{
4330 static CellStyleNameMap const aMap
4331 {
4332 { "first-row" , FIRST_ROW_STYLE },
4333 { "last-row" , LAST_ROW_STYLE },
4334 { "first-column" , FIRST_COLUMN_STYLE },
4335 { "last-column" , LAST_COLUMN_STYLE },
4336 { "body" , BODY_STYLE },
4337 { "even-rows" , EVEN_ROWS_STYLE },
4338 { "odd-rows" , ODD_ROWS_STYLE },
4339 { "even-columns" , EVEN_COLUMNS_STYLE },
4340 { "odd-columns" , ODD_COLUMNS_STYLE },
4341 { "background" , BACKGROUND_STYLE },
4342 // loext namespace
4343 { "first-row-start-column" , FIRST_ROW_START_COLUMN_STYLE },
4344 { "first-row-end-column" , FIRST_ROW_END_COLUMN_STYLE },
4345 { "last-row-start-column" , LAST_ROW_START_COLUMN_STYLE },
4346 { "last-row-end-column" , LAST_ROW_END_COLUMN_STYLE },
4347 { "first-row-even-column" , FIRST_ROW_EVEN_COLUMN_STYLE },
4348 { "last-row-even-column" , LAST_ROW_EVEN_COLUMN_STYLE },
4349 };
4350 return aMap;
4351}
4352
4354{
4355 return m_pTableAutoFormat;
4356}
4357
4359{
4360 const size_t nStyles = pDocShell->GetDoc()->GetTableStyles().size();
4361 for(size_t i=0; i < nStyles; ++i)
4362 {
4363 SwTableAutoFormat* pAutoFormat = &pDocShell->GetDoc()->GetTableStyles()[i];
4364 if (pAutoFormat->GetName() == sName)
4365 {
4366 return pAutoFormat;
4367 }
4368 }
4369 // not found
4370 return nullptr;
4371}
4372
4374{
4375 if (!m_bPhysical)
4376 {
4377 // find table format in doc
4379 if (pTableAutoFormat)
4380 {
4381 m_bPhysical = true;
4383 const std::vector<sal_Int32> aTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap();
4384 for (size_t i=0; i<aTableTemplateMap.size(); ++i)
4385 {
4386 SwBoxAutoFormat* pOldBoxFormat = &m_pTableAutoFormat->GetBoxFormat(aTableTemplateMap[i]);
4387 uno::Reference<style::XStyle> xCellStyle(pOldBoxFormat->GetXObject(), uno::UNO_QUERY);
4388 if (!xCellStyle.is())
4389 continue;
4390 SwXTextCellStyle& rStyle = dynamic_cast<SwXTextCellStyle&>(*xCellStyle);
4391 SwBoxAutoFormat& rNewBoxFormat = pTableAutoFormat->GetBoxFormat(aTableTemplateMap[i]);
4392 rStyle.SetBoxFormat(&rNewBoxFormat);
4393 rNewBoxFormat.SetXObject(xCellStyle);
4394 }
4395 m_pTableAutoFormat_Impl = nullptr;
4396 m_pTableAutoFormat = pTableAutoFormat;
4397 m_pTableAutoFormat->SetXObject(uno::Reference<style::XStyle>(this));
4398 }
4399 else
4400 SAL_WARN("sw.uno", "setting style physical, but SwTableAutoFormat in document not found");
4401 }
4402 else
4403 SAL_WARN("sw.uno", "calling SetPhysical on a physical SwXTextTableStyle");
4404}
4405
4406// XStyle
4408{
4409 SolarMutexGuard aGuard;
4410 // only first style is not user defined
4411 if (m_pDocShell->GetDoc()->GetTableStyles()[0].GetName() == m_pTableAutoFormat->GetName())
4412 return false;
4413
4414 return true;
4415}
4416
4418{
4419 SolarMutexGuard aGuard;
4420 if (!m_bPhysical)
4421 return false;
4422
4424
4425 for (SwFrameFormat* const & pFormat : *m_pDocShell->GetDoc()->GetTableFrameFormats())
4426 {
4427 if (!pFormat->GetInfo(aGetHt))
4428 {
4429 SwTable* pTable = SwTable::FindTable(pFormat);
4430 if (pTable->GetTableStyleName() == m_pTableAutoFormat->GetName())
4431 return true;
4432 }
4433 }
4434
4435 return false;
4436}
4437
4439{
4440 return OUString();
4441}
4442
4443void SAL_CALL SwXTextTableStyle::setParentStyle(const OUString& /*aParentStyle*/)
4444{ }
4445
4446//XNamed
4448{
4449 SolarMutexGuard aGuard;
4450 OUString sProgName;
4452 return sProgName;
4453}
4454
4455void SAL_CALL SwXTextTableStyle::setName(const OUString& rName)
4456{
4457 SolarMutexGuard aGuard;
4459}
4460
4461//XPropertySet
4462css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL SwXTextTableStyle::getPropertySetInfo()
4463{
4464 static uno::Reference<beans::XPropertySetInfo> xRef(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TABLE_STYLE)->getPropertySetInfo());
4465 return xRef;
4466}
4467
4468void SAL_CALL SwXTextTableStyle::setPropertyValue(const OUString& /*rPropertyName*/, const css::uno::Any& /*aValue*/)
4469{
4470 SAL_WARN("sw.uno", "not implemented");
4471}
4472
4473css::uno::Any SAL_CALL SwXTextTableStyle::getPropertyValue(const OUString& rPropertyName)
4474{
4475 SolarMutexGuard aGuard;
4476 bool bIsRow = false;
4477
4478 if (rPropertyName == UNO_NAME_TABLE_FIRST_ROW_END_COLUMN)
4480 else if (rPropertyName == UNO_NAME_TABLE_FIRST_ROW_START_COLUMN)
4482 else if (rPropertyName == UNO_NAME_TABLE_LAST_ROW_END_COLUMN)
4484 else if (rPropertyName == UNO_NAME_TABLE_LAST_ROW_START_COLUMN)
4486 else if (rPropertyName == UNO_NAME_DISPLAY_NAME)
4488 else
4489 throw css::beans::UnknownPropertyException(rPropertyName);
4490
4491 return uno::Any(bIsRow ? OUString("row") : OUString("column"));
4492}
4493
4494void SAL_CALL SwXTextTableStyle::addPropertyChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XPropertyChangeListener >& /*xListener*/ )
4495{
4496 SAL_WARN("sw.uno", "not implemented");
4497}
4498
4499void SAL_CALL SwXTextTableStyle::removePropertyChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XPropertyChangeListener >& /*aListener*/ )
4500{
4501 SAL_WARN("sw.uno", "not implemented");
4502}
4503
4504void SAL_CALL SwXTextTableStyle::addVetoableChangeListener( const OUString& /*PropertyName*/, const css::uno::Reference< css::beans::XVetoableChangeListener >& /*aListener*/ )
4505{
4506 SAL_WARN("sw.uno", "not implemented");
4507}
4508
4509void SAL_CALL SwXTextTableStyle::removeVetoableChangeListener( const OUString& /*PropertyName*/, const css::uno::Reference< css::beans::XVetoableChangeListener >& /*aListener*/ )
4510{
4511 SAL_WARN("sw.uno", "not implemented");
4512}
4513
4514//XNameAccess
4515uno::Any SAL_CALL SwXTextTableStyle::getByName(const OUString& rName)
4516{
4517 SolarMutexGuard aGuard;
4518 const CellStyleNameMap& rMap = GetCellStyleNameMap();
4519 CellStyleNameMap::const_iterator iter = rMap.find(rName);
4520 if(iter == rMap.end())
4521 throw css::container::NoSuchElementException();
4522
4523 return css::uno::Any(m_aCellStyles[(*iter).second]);
4524}
4525
4526css::uno::Sequence<OUString> SAL_CALL SwXTextTableStyle::getElementNames()
4527{
4529}
4530
4531sal_Bool SAL_CALL SwXTextTableStyle::hasByName(const OUString& rName)
4532{
4533 const CellStyleNameMap& rMap = GetCellStyleNameMap();
4534 CellStyleNameMap::const_iterator iter = rMap.find(rName);
4535 return iter != rMap.end();
4536}
4537
4538//XNameContainer
4539void SAL_CALL SwXTextTableStyle::insertByName(const OUString& /*Name*/, const uno::Any& /*Element*/)
4540{
4541 SAL_WARN("sw.uno", "not implemented");
4542}
4543
4544void SAL_CALL SwXTextTableStyle::replaceByName(const OUString& rName, const uno::Any& rElement)
4545{
4546 SolarMutexGuard aGuard;
4547 const CellStyleNameMap& rMap = GetCellStyleNameMap();
4548 CellStyleNameMap::const_iterator iter = rMap.find(rName);
4549 if(iter == rMap.end())
4550 throw container::NoSuchElementException();
4551 const sal_Int32 nCellStyle = iter->second;
4552
4553 uno::Reference<style::XStyle> xStyle = rElement.get<uno::Reference<style::XStyle>>();
4554 if (!xStyle.is())
4555 throw lang::IllegalArgumentException();
4556
4557 SwXTextCellStyle* pStyleToReplaceWith = dynamic_cast<SwXTextCellStyle*>(xStyle.get());
4558 if (!pStyleToReplaceWith)
4559 throw lang::IllegalArgumentException();
4560
4561 // replace only with physical ...
4562 if (!pStyleToReplaceWith->IsPhysical())
4563 throw lang::IllegalArgumentException();
4564
4565 const auto& rTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap();
4566 const sal_Int32 nBoxFormat = rTableTemplateMap[nCellStyle];
4567
4568 // move SwBoxAutoFormat to dest. SwTableAutoFormat
4569 m_pTableAutoFormat->SetBoxFormat(*pStyleToReplaceWith->GetBoxFormat(), nBoxFormat);
4570 // remove unassigned SwBoxAutoFormat, which is not anymore in use anyways
4571 m_pDocShell->GetDoc()->GetCellStyles().RemoveBoxFormat(xStyle->getName());
4572 // make SwXTextCellStyle use new, moved SwBoxAutoFormat
4573 pStyleToReplaceWith->SetBoxFormat(&m_pTableAutoFormat->GetBoxFormat(nBoxFormat));
4574 m_pTableAutoFormat->GetBoxFormat(nBoxFormat).SetXObject(xStyle);
4575 // make this SwXTextTableStyle use new SwXTextCellStyle
4576 m_aCellStyles[nCellStyle] = xStyle;
4577}
4578
4579void SAL_CALL SwXTextTableStyle::removeByName(const OUString& /*Name*/)
4580{
4581 SAL_WARN("sw.uno", "not implemented");
4582}
4583
4584//XElementAccess
4586{
4588}
4589
4591{
4592 return true;
4593}
4594
4595//XServiceInfo
4597{
4598 return {"SwXTextTableStyle"};
4599}
4600
4601sal_Bool SAL_CALL SwXTextTableStyle::supportsService(const OUString& rServiceName)
4602{
4603 return cppu::supportsService(this, rServiceName);
4604}
4605
4606css::uno::Sequence<OUString> SAL_CALL SwXTextTableStyle::getSupportedServiceNames()
4607{
4608 return {"com.sun.star.style.Style"};
4609}
4610
4611// SwXTextCellStyle
4612SwXTextCellStyle::SwXTextCellStyle(SwDocShell* pDocShell, SwBoxAutoFormat* pBoxAutoFormat, OUString sParentStyle) :
4613 m_pDocShell(pDocShell),
4614 m_pBoxAutoFormat(pBoxAutoFormat),
4615 m_sParentStyle(std::move(sParentStyle)),
4616 m_bPhysical(true)
4617{ }
4618
4620 m_pDocShell(pDocShell),
4621 m_pBoxAutoFormat_Impl(std::make_shared<SwBoxAutoFormat>()),
4622 m_sName(std::move(sName)),
4623 m_bPhysical(false)
4624{
4626}
4627
4629{
4630 return m_pBoxAutoFormat;
4631}
4632
4634{
4635 if (m_bPhysical)
4636 m_pBoxAutoFormat = pBoxFormat;
4637 else
4638 SAL_INFO("sw.uno", "trying to call SwXTextCellStyle::SetBoxFormat on non physical style");
4639}
4640
4642{
4643 if (!m_bPhysical)
4644 {
4646 if (pBoxAutoFormat)
4647 {
4648 m_bPhysical = true;
4649 m_pBoxAutoFormat_Impl = nullptr;
4650 m_pBoxAutoFormat = pBoxAutoFormat;
4651 m_pBoxAutoFormat->SetXObject(uno::Reference<style::XStyle>(this));
4652 }
4653 else
4654 SAL_WARN("sw.uno", "setting style physical, but SwBoxAutoFormat in document not found");
4655 }
4656 else
4657 SAL_WARN("sw.uno", "calling SetPhysical on a physical SwXTextCellStyle");
4658}
4659
4661{
4662 return m_bPhysical;
4663}
4664
4665SwBoxAutoFormat* SwXTextCellStyle::GetBoxAutoFormat(SwDocShell* pDocShell, std::u16string_view sName, OUString* pParentName)
4666{
4667 if (sName.empty())
4668 return nullptr;
4669
4670 SwBoxAutoFormat* pBoxAutoFormat = pDocShell->GetDoc()->GetCellStyles().GetBoxFormat(sName);
4671 if (!pBoxAutoFormat)
4672 {
4673 sal_Int32 nTemplateIndex;
4674 OUString sParentName;
4675 std::u16string_view sCellSubName;
4676
4677 size_t nSeparatorIndex = sName.rfind('.');
4678 if (nSeparatorIndex == std::u16string_view::npos)
4679 return nullptr;
4680
4681 sParentName = sName.substr(0, nSeparatorIndex);
4682 sCellSubName = sName.substr(nSeparatorIndex+1);
4683 nTemplateIndex = o3tl::toInt32(sCellSubName)-1; // -1 because cell styles names start from 1, but internally are indexed from 0
4684 if (0 > nTemplateIndex)
4685 return nullptr;
4686
4687 const auto& rTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap();
4688 if (rTableTemplateMap.size() <= o3tl::make_unsigned(nTemplateIndex))
4689 return nullptr;
4690
4692 SwTableAutoFormat* pTableAutoFormat = pDocShell->GetDoc()->GetTableStyles().FindAutoFormat(sParentName);
4693 if (!pTableAutoFormat)
4694 return nullptr;
4695
4696 if (pParentName)
4697 *pParentName = sParentName;
4698 sal_uInt32 nBoxIndex = rTableTemplateMap[nTemplateIndex];
4699 pBoxAutoFormat = &pTableAutoFormat->GetBoxFormat(nBoxIndex);
4700 }
4701
4702 return pBoxAutoFormat;
4703}
4704
4705css::uno::Reference<css::style::XStyle> SwXTextCellStyle::CreateXTextCellStyle(SwDocShell* pDocShell, const OUString& sName)
4706{
4707 uno::Reference<style::XStyle> xTextCellStyle;
4708
4709 if (!sName.isEmpty()) // create a cell style for a physical box
4710 {
4711 OUString sParentName;
4712 SwBoxAutoFormat* pBoxFormat = GetBoxAutoFormat(pDocShell, sName, &sParentName);
4713
4714 // something went wrong but we don't want a crash
4715 if (!pBoxFormat)
4716 {
4717 // return a default-dummy style to prevent crash
4718 static SwBoxAutoFormat aDefaultBoxFormat;
4719 pBoxFormat = &aDefaultBoxFormat;
4720 }
4721
4722 xTextCellStyle.set(pBoxFormat->GetXObject(), uno::UNO_QUERY);
4723 if (!xTextCellStyle.is())
4724 {
4725 xTextCellStyle.set(new SwXTextCellStyle(pDocShell, pBoxFormat, sParentName));
4726 pBoxFormat->SetXObject(xTextCellStyle);
4727 }
4728 }
4729 else // create a non physical style
4730 xTextCellStyle.set(new SwXTextCellStyle(pDocShell, sName));
4731
4732 return xTextCellStyle;
4733}
4734
4735// XStyle
4737{
4738 SolarMutexGuard aGuard;
4739 // if this cell belong to first table style then its default style
4741 return false;
4742
4743 return true;
4744}
4745
4747{
4748 SolarMutexGuard aGuard;
4749 uno::Reference<style::XStyleFamiliesSupplier> xFamiliesSupplier(m_pDocShell->GetModel(), uno::UNO_QUERY);
4750 if (!xFamiliesSupplier.is())
4751 return false;
4752
4753 uno::Reference<container::XNameAccess> xFamilies = xFamiliesSupplier->getStyleFamilies();
4754 if (!xFamilies.is())
4755 return false;
4756
4757 uno::Reference<container::XNameAccess> xTableStyles;
4758 xFamilies->getByName("TableStyles") >>= xTableStyles;
4759 if (!xTableStyles.is())
4760 return false;
4761
4762 uno::Reference<style::XStyle> xStyle;
4763 xTableStyles->getByName(m_sParentStyle) >>= xStyle;
4764 if (!xStyle.is())
4765 return false;
4766
4767 return xStyle->isInUse();
4768}
4769
4771{
4772 // Do not return name of the parent (which is a table style) because the parent should be a cell style.
4773 return OUString();
4774}
4775
4776void SAL_CALL SwXTextCellStyle::setParentStyle(const OUString& /*sParentStyle*/)
4777{
4778 // Changing parent to one which is unaware of it will lead to a something unexpected. getName() rely on a parent.
4779 SAL_INFO("sw.uno", "Changing SwXTextCellStyle parent");
4780}
4781
4782//XNamed
4783OUString SAL_CALL SwXTextCellStyle::getName()
4784{
4785 SolarMutexGuard aGuard;
4786 OUString sName;
4787
4788 // if style is physical then we request a name from doc
4789 if (m_bPhysical)
4790 {
4792 if (!pTableFormat)
4793 {
4794 // if auto format is not found as a child of table formats, look in SwDoc cellstyles
4796 }
4797 else
4798 {
4799 OUString sParentStyle;
4801 sName = sParentStyle + pTableFormat->GetTableTemplateCellSubName(*m_pBoxAutoFormat);
4802 }
4803 }
4804 else
4805 sName = m_sName;
4806
4807 return sName;
4808}
4809
4810void SAL_CALL SwXTextCellStyle::setName(const OUString& sName)
4811{
4812 SolarMutexGuard aGuard;
4813 // if style is physical then we can not rename it.
4814 if (!m_bPhysical)
4815 m_sName = sName;
4816 // change name if style is unassigned (name is not generated automatically)
4818}
4819
4820//XPropertySet
4821css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL SwXTextCellStyle::getPropertySetInfo()
4822{
4823 static uno::Reference<beans::XPropertySetInfo> xRef(aSwMapProvider.GetPropertySet(PROPERTY_MAP_CELL_STYLE)->getPropertySetInfo());
4824 return xRef;
4825}
4826
4827void SAL_CALL SwXTextCellStyle::setPropertyValue(const OUString& rPropertyName, const css::uno::Any& aValue)
4828{
4829 SolarMutexGuard aGuard;
4831 if(pEntry)
4832 {
4833 switch(pEntry->nWID)
4834 {
4835 case RES_BACKGROUND:
4836 {
4838 rBrush.PutValue(aValue, 0);
4840 return;
4841 }
4842 case RES_BOX:
4843 {
4845 rBox.PutValue(aValue, pEntry->nMemberId);
4846 m_pBoxAutoFormat->SetBox(rBox);
4847 return;
4848 }
4849 case RES_VERT_ORIENT:
4850 {
4852 rVertOrient.PutValue(aValue, pEntry->nMemberId);
4854 return;
4855 }
4856 case RES_FRAMEDIR:
4857 {
4859 rDirItem.PutValue(aValue, pEntry->nMemberId);
4861 return;
4862 }
4863 case RES_BOXATR_FORMAT:
4864 {
4865 sal_uInt32 nKey;
4866 if (aValue >>= nKey)
4867 {
4868 // FIXME: It's not working for old "automatic" currency formats, which are still in use by autotbl.fmt.
4869 // Scenario:
4870 // 1) Mark all styles present by default in autotbl.fmt as default.
4871 // 2) convert all currencies present in autotbl.fmt before calling this code
4872 const SvNumberformat* pNumFormat = m_pDocShell->GetDoc()->GetNumberFormatter()->GetEntry(nKey);
4873 if (pNumFormat)
4875 }
4876 return;
4877 }
4878 // Paragraph attributes
4879 case RES_PARATR_ADJUST:
4880 {
4881 SvxAdjustItem rAdjustItem = m_pBoxAutoFormat->GetAdjust();
4882 rAdjustItem.PutValue(aValue, pEntry->nMemberId);
4883 m_pBoxAutoFormat->SetAdjust(rAdjustItem);
4884 return;
4885 }
4886 case RES_CHRATR_COLOR:
4887 {
4888 SvxColorItem rColorItem = m_pBoxAutoFormat->GetColor();
4889 rColorItem.PutValue(aValue, pEntry->nMemberId);
4890 m_pBoxAutoFormat->SetColor(rColorItem);
4891 return;
4892 }
4894 {
4895 SvxShadowedItem rShadowedItem = m_pBoxAutoFormat->GetShadowed();
4896 bool bValue = false; aValue >>= bValue;
4897 rShadowedItem.SetValue(bValue);
4898 m_pBoxAutoFormat->SetShadowed(rShadowedItem);
4899 return;
4900 }
4901 case RES_CHRATR_CONTOUR:
4902 {
4903 SvxContourItem rContourItem = m_pBoxAutoFormat->GetContour();
4904 bool bValue = false; aValue >>= bValue;
4905 rContourItem.SetValue(bValue);
4906 m_pBoxAutoFormat->SetContour(rContourItem);
4907 return;
4908 }
4910 {
4912 rCrossedOutItem.PutValue(aValue, pEntry->nMemberId);
4913 m_pBoxAutoFormat->SetCrossedOut(rCrossedOutItem);
4914 return;
4915 }
4917 {
4919 rUnderlineItem.PutValue(aValue, pEntry->nMemberId);
4920 m_pBoxAutoFormat->SetUnderline(rUnderlineItem);
4921 return;
4922 }
4924 {
4925 SvxFontHeightItem rFontHeightItem = m_pBoxAutoFormat->GetHeight();
4926 rFontHeightItem.PutValue(aValue, pEntry->nMemberId);
4927 m_pBoxAutoFormat->SetHeight(rFontHeightItem);
4928 return;
4929 }
4930 case RES_CHRATR_WEIGHT:
4931 {
4932 SvxWeightItem rWeightItem = m_pBoxAutoFormat->GetWeight();
4933 rWeightItem.PutValue(aValue, pEntry->nMemberId);
4934 m_pBoxAutoFormat->SetWeight(rWeightItem);
4935 return;
4936 }
4937 case RES_CHRATR_POSTURE:
4938 {
4939 SvxPostureItem rPostureItem = m_pBoxAutoFormat->GetPosture();
4940 rPostureItem.PutValue(aValue, pEntry->nMemberId);
4941 m_pBoxAutoFormat->SetPosture(rPostureItem);
4942 return;
4943 }
4944 case RES_CHRATR_FONT:
4945 {
4946 SvxFontItem rFontItem = m_pBoxAutoFormat->GetFont();
4947 rFontItem.PutValue(aValue, pEntry->nMemberId);
4948 m_pBoxAutoFormat->SetFont(rFontItem);
4949 return;
4950 }
4952 {
4953 SvxFontHeightItem rFontHeightItem = m_pBoxAutoFormat->GetCJKHeight();
4954 rFontHeightItem.PutValue(aValue, pEntry->nMemberId);
4955 m_pBoxAutoFormat->SetCJKHeight(rFontHeightItem);
4956 return;
4957 }
4959 {
4961 rWeightItem.PutValue(aValue, pEntry->nMemberId);
4962 m_pBoxAutoFormat->SetCJKWeight(rWeightItem);
4963 return;
4964 }
4966 {
4968 rPostureItem.PutValue(aValue, pEntry->nMemberId);
4969 m_pBoxAutoFormat->SetCJKPosture(rPostureItem);
4970 return;
4971 }
4973 {
4975 rFontItem.PutValue(aValue, pEntry->nMemberId);
4976 m_pBoxAutoFormat->SetCJKFont(rFontItem);
4977 return;
4978 }
4980 {
4981 SvxFontHeightItem rFontHeightItem = m_pBoxAutoFormat->GetCTLHeight();
4982 rFontHeightItem.PutValue(aValue, pEntry->nMemberId);
4983 m_pBoxAutoFormat->SetCTLHeight(rFontHeightItem);
4984 return;
4985 }
4987 {
4989 rWeightItem.PutValue(aValue, pEntry->nMemberId);
4990 m_pBoxAutoFormat->SetCTLWeight(rWeightItem);
4991 return;
4992 }
4994 {
4996 rPostureItem.PutValue(aValue, pEntry->nMemberId);
4997 m_pBoxAutoFormat->SetCTLPosture(rPostureItem);
4998 return;
4999 }
5001 {
5003 rFontItem.PutValue(aValue, pEntry->nMemberId);
5004 m_pBoxAutoFormat->SetCTLFont(rFontItem);
5005 return;
5006 }
5007 default:
5008 SAL_WARN("sw.uno", "SwXTextCellStyle unknown nWID");
5009 throw css::uno::RuntimeException();
5010 }
5011 }
5012
5013 throw css::beans::UnknownPropertyException(rPropertyName);
5014}
5015
5016css::uno::Any SAL_CALL SwXTextCellStyle::getPropertyValue(const OUString& rPropertyName)
5017{
5018 SolarMutexGuard aGuard;
5019 uno::Any aRet;
5021 if(pEntry)
5022 {