Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / unocore / unostyle.cxx
blobaaa7b62f8aa3f58b01885ab01c2b0c4958fecd4d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <o3tl/safeint.hxx>
23 #include <o3tl/string_view.hxx>
24 #include <comphelper/propertysequence.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>
38 #include <editeng/contouritem.hxx>
39 #include <editeng/crossedoutitem.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>
54 #include <autostyle_helper.hxx>
55 #include <pagedesc.hxx>
56 #include <doc.hxx>
57 #include <IDocumentUndoRedo.hxx>
58 #include <IDocumentDeviceAccess.hxx>
59 #include <IDocumentStylePoolAccess.hxx>
60 #include <docary.hxx>
61 #include <charfmt.hxx>
62 #include <cmdid.h>
63 #include <unomid.h>
64 #include <unomap.hxx>
65 #include <unostyle.hxx>
66 #include <unosett.hxx>
67 #include <docsh.hxx>
68 #include <paratr.hxx>
69 #include <unoprnms.hxx>
70 #include <shellio.hxx>
71 #include <docstyle.hxx>
72 #include <unotextbodyhf.hxx>
73 #include <fmthdft.hxx>
74 #include <fmtpdsc.hxx>
75 #include <strings.hrc>
76 #include <poolfmt.hxx>
77 #include <unoevent.hxx>
78 #include <fmtruby.hxx>
79 #include <SwStyleNameMapper.hxx>
80 #include <sfx2/printer.hxx>
81 #include <com/sun/star/frame/XModel.hpp>
82 #include <com/sun/star/io/IOException.hpp>
83 #include <com/sun/star/style/ParagraphStyleCategory.hpp>
84 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
85 #include <com/sun/star/beans/PropertyAttribute.hpp>
86 #include <com/sun/star/beans/NamedValue.hpp>
87 #include <com/sun/star/drawing/BitmapMode.hpp>
88 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
89 #include <com/sun/star/lang/IllegalArgumentException.hpp>
90 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
91 #include <com/sun/star/document/XEventsSupplier.hpp>
92 #include <com/sun/star/io/XInputStream.hpp>
93 #include <istyleaccess.hxx>
94 #include <fmtfsize.hxx>
95 #include <numrule.hxx>
96 #include <tblafmt.hxx>
97 #include <frameformats.hxx>
99 #include <comphelper/servicehelper.hxx>
100 #include <cppuhelper/exc_hlp.hxx>
101 #include <cppuhelper/supportsservice.hxx>
102 #include <cppuhelper/typeprovider.hxx>
103 #include <comphelper/sequence.hxx>
104 #include <sal/log.hxx>
106 #include <svl/stylepool.hxx>
107 #include <svx/unobrushitemhelper.hxx>
108 #include <editeng/unoipset.hxx>
109 #include <editeng/memberids.h>
110 #include <svx/unomid.hxx>
111 #include <svx/unoshape.hxx>
112 #include <svx/xflbstit.hxx>
113 #include <svx/xflbmtit.hxx>
114 #include <swunohelper.hxx>
115 #include <svx/xbtmpit.hxx>
117 #include <ccoll.hxx>
118 #include <hints.hxx>
119 #include <uiitems.hxx>
121 #include <cassert>
122 #include <memory>
123 #include <set>
124 #include <string_view>
125 #include <limits>
127 using namespace css;
128 using namespace css::io;
129 using namespace css::lang;
130 using namespace css::uno;
132 namespace {
134 // these should really be constexprs, but MSVC still is apparently too stupid for them
135 #define nPoolChrNormalRange (RES_POOLCHR_NORMAL_END - RES_POOLCHR_NORMAL_BEGIN)
136 #define nPoolChrHtmlRange (RES_POOLCHR_HTML_END - RES_POOLCHR_HTML_BEGIN)
137 #define nPoolCollTextRange ( RES_POOLCOLL_TEXT_END - RES_POOLCOLL_TEXT_BEGIN)
138 #define nPoolCollListsRange ( RES_POOLCOLL_LISTS_END - RES_POOLCOLL_LISTS_BEGIN)
139 #define nPoolCollExtraRange ( RES_POOLCOLL_EXTRA_END - RES_POOLCOLL_EXTRA_BEGIN)
140 #define nPoolCollRegisterRange ( RES_POOLCOLL_REGISTER_END - RES_POOLCOLL_REGISTER_BEGIN)
141 #define nPoolCollDocRange ( RES_POOLCOLL_DOC_END - RES_POOLCOLL_DOC_BEGIN)
142 #define nPoolCollHtmlRange ( RES_POOLCOLL_HTML_END - RES_POOLCOLL_HTML_BEGIN)
143 #define nPoolFrameRange ( RES_POOLFRM_END - RES_POOLFRM_BEGIN)
144 #define nPoolPageRange ( RES_POOLPAGE_END - RES_POOLPAGE_BEGIN)
145 #define nPoolNumRange ( RES_POOLNUMRULE_END - RES_POOLNUMRULE_BEGIN)
146 #define nPoolCollListsStackedStart ( nPoolCollTextRange)
147 #define nPoolCollExtraStackedStart ( nPoolCollListsStackedStart + nPoolCollListsRange)
148 #define nPoolCollRegisterStackedStart ( nPoolCollExtraStackedStart + nPoolCollExtraRange)
149 #define nPoolCollDocStackedStart ( nPoolCollRegisterStackedStart + nPoolCollRegisterRange)
150 #define nPoolCollHtmlStackedStart ( nPoolCollDocStackedStart + nPoolCollDocRange)
151 using paragraphstyle_t = std::remove_const<decltype(style::ParagraphStyleCategory::TEXT)>::type;
152 using collectionbits_t = sal_uInt16;
153 struct ParagraphStyleCategoryEntry
155 paragraphstyle_t m_eCategory;
156 SfxStyleSearchBits m_nSwStyleBits;
157 collectionbits_t m_nCollectionBits;
158 constexpr ParagraphStyleCategoryEntry(paragraphstyle_t eCategory, SfxStyleSearchBits nSwStyleBits, collectionbits_t nCollectionBits)
159 : m_eCategory(eCategory)
160 , m_nSwStyleBits(nSwStyleBits)
161 , m_nCollectionBits(nCollectionBits)
165 constexpr ParagraphStyleCategoryEntry sParagraphStyleCategoryEntries[]
167 { style::ParagraphStyleCategory::TEXT, SfxStyleSearchBits::SwText, COLL_TEXT_BITS },
168 { style::ParagraphStyleCategory::CHAPTER, SfxStyleSearchBits::SwChapter, COLL_DOC_BITS },
169 { style::ParagraphStyleCategory::LIST, SfxStyleSearchBits::SwList, COLL_LISTS_BITS },
170 { style::ParagraphStyleCategory::INDEX, SfxStyleSearchBits::SwIndex, COLL_REGISTER_BITS },
171 { style::ParagraphStyleCategory::EXTRA, SfxStyleSearchBits::SwExtra, COLL_EXTRA_BITS },
172 { style::ParagraphStyleCategory::HTML, SfxStyleSearchBits::SwHtml, COLL_HTML_BITS }
175 class StyleFamilyEntry
177 public:
178 template <SfxStyleFamily f> static StyleFamilyEntry Create(sal_uInt16 nPropMapType, SwGetPoolIdFromName aPoolId, OUString sName, TranslateId pResId)
180 return StyleFamilyEntry(f, nPropMapType, aPoolId, sName, pResId, GetCountOrName<f>, CreateStyle<f>, TranslateIndex<f>);
183 SfxStyleFamily family() const { return m_eFamily; }
184 sal_uInt16 propMapType() const { return m_nPropMapType; }
185 const uno::Reference<beans::XPropertySetInfo>& xPSInfo() const { return m_xPSInfo; }
186 SwGetPoolIdFromName poolId() const { return m_aPoolId; }
187 const OUString& name() const { return m_sName; }
188 const TranslateId& resId() const { return m_pResId; }
190 sal_Int32 getCountOrName(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex) const { return m_fGetCountOrName(rDoc, pString, nIndex); }
191 css::uno::Reference<css::style::XStyle> createStyle(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName) const { return m_fCreateStyle(pBasePool, pDocShell, sStyleName); }
192 sal_uInt16 translateIndex(const sal_uInt16 nIndex) const { return m_fTranslateIndex(nIndex); }
194 private:
195 using GetCountOrName_t = sal_Int32 (*)(const SwDoc&, OUString*, sal_Int32);
196 using CreateStyle_t = uno::Reference<css::style::XStyle>(*)(SfxStyleSheetBasePool*, SwDocShell*, const OUString&);
197 using TranslateIndex_t = sal_uInt16(*)(const sal_uInt16);
198 SfxStyleFamily m_eFamily;
199 sal_uInt16 m_nPropMapType;
200 uno::Reference<beans::XPropertySetInfo> m_xPSInfo;
201 SwGetPoolIdFromName m_aPoolId;
202 OUString m_sName;
203 TranslateId m_pResId;
204 GetCountOrName_t m_fGetCountOrName;
205 CreateStyle_t m_fCreateStyle;
206 TranslateIndex_t m_fTranslateIndex;
207 StyleFamilyEntry(SfxStyleFamily eFamily, sal_uInt16 nPropMapType, SwGetPoolIdFromName aPoolId, OUString sName, TranslateId pResId, GetCountOrName_t fGetCountOrName, CreateStyle_t fCreateStyle, TranslateIndex_t fTranslateIndex)
208 : m_eFamily(eFamily)
209 , m_nPropMapType(nPropMapType)
210 , m_xPSInfo(aSwMapProvider.GetPropertySet(nPropMapType)->getPropertySetInfo())
211 , m_aPoolId(aPoolId)
212 , m_sName(std::move(sName))
213 , m_pResId(pResId)
214 , m_fGetCountOrName(fGetCountOrName)
215 , m_fCreateStyle(fCreateStyle)
216 , m_fTranslateIndex(fTranslateIndex)
218 template<SfxStyleFamily> static inline sal_Int32 GetCountOrName(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex);
219 template<SfxStyleFamily> static inline css::uno::Reference<css::style::XStyle> CreateStyle(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName);
220 template<SfxStyleFamily> static inline sal_uInt16 TranslateIndex(const sal_uInt16 nIndex) { return nIndex; }
223 template<>
224 sal_Int32 StyleFamilyEntry::GetCountOrName<SfxStyleFamily::Char>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex)
226 const sal_uInt16 nBaseCount = nPoolChrHtmlRange + nPoolChrNormalRange;
227 nIndex -= nBaseCount;
228 sal_Int32 nCount = 0;
229 for(auto pFormat : *rDoc.GetCharFormats())
231 if(pFormat->IsDefault() && pFormat != rDoc.GetDfltCharFormat())
232 continue;
233 if(!IsPoolUserFormat(pFormat->GetPoolFormatId()))
234 continue;
235 if(nIndex == nCount)
237 // the default character format needs to be set to "Default!"
238 if(rDoc.GetDfltCharFormat() == pFormat)
239 *pString = SwResId(STR_POOLCHR_STANDARD);
240 else
241 *pString = pFormat->GetName();
242 break;
244 ++nCount;
246 return nCount + nBaseCount;
249 template<>
250 sal_Int32 StyleFamilyEntry::GetCountOrName<SfxStyleFamily::Para>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex)
252 const sal_uInt16 nBaseCount = nPoolCollHtmlStackedStart + nPoolCollHtmlRange;
253 nIndex -= nBaseCount;
254 sal_Int32 nCount = 0;
255 for(auto pColl : *rDoc.GetTextFormatColls())
257 if(pColl->IsDefault())
258 continue;
259 if(!IsPoolUserFormat(pColl->GetPoolFormatId()))
260 continue;
261 if(nIndex == nCount)
263 *pString = pColl->GetName();
264 break;
266 ++nCount;
268 return nCount + nBaseCount;
271 template<>
272 sal_Int32 StyleFamilyEntry::GetCountOrName<SfxStyleFamily::Frame>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex)
274 nIndex -= nPoolFrameRange;
275 sal_Int32 nCount = 0;
276 for(const auto pFormat : *rDoc.GetFrameFormats())
278 if(pFormat->IsDefault() || pFormat->IsAuto())
279 continue;
280 if(!IsPoolUserFormat(pFormat->GetPoolFormatId()))
281 continue;
282 if(nIndex == nCount)
284 *pString = pFormat->GetName();
285 break;
287 ++nCount;
289 return nCount + nPoolFrameRange;
292 template<>
293 sal_Int32 StyleFamilyEntry::GetCountOrName<SfxStyleFamily::Page>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex)
295 nIndex -= nPoolPageRange;
296 sal_Int32 nCount = 0;
297 const size_t nArrLen = rDoc.GetPageDescCnt();
298 for(size_t i = 0; i < nArrLen; ++i)
300 const SwPageDesc& rDesc = rDoc.GetPageDesc(i);
301 if(!IsPoolUserFormat(rDesc.GetPoolFormatId()))
302 continue;
303 if(nIndex == nCount)
305 *pString = rDesc.GetName();
306 break;
308 ++nCount;
310 nCount += nPoolPageRange;
311 return nCount;
314 template<>
315 sal_Int32 StyleFamilyEntry::GetCountOrName<SfxStyleFamily::Pseudo>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex)
317 nIndex -= nPoolNumRange;
318 sal_Int32 nCount = 0;
319 for(const auto pRule : rDoc.GetNumRuleTable())
321 if(pRule->IsAutoRule())
322 continue;
323 if(!IsPoolUserFormat(pRule->GetPoolFormatId()))
324 continue;
325 if(nIndex == nCount)
327 *pString = pRule->GetName();
328 break;
330 ++nCount;
332 return nCount + nPoolNumRange;
335 template<>
336 sal_Int32 StyleFamilyEntry::GetCountOrName<SfxStyleFamily::Table>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex)
338 if (!rDoc.HasTableStyles())
339 return 0;
341 const auto pAutoFormats = &rDoc.GetTableStyles();
342 const sal_Int32 nCount = pAutoFormats->size();
343 if (0 <= nIndex && nIndex < nCount)
344 *pString = pAutoFormats->operator[](nIndex).GetName();
346 return nCount;
349 template<>
350 sal_Int32 StyleFamilyEntry::GetCountOrName<SfxStyleFamily::Cell>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex)
352 const auto& rAutoFormats = rDoc.GetTableStyles();
353 const auto& rTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap();
354 const sal_Int32 nUsedCellStylesCount = rAutoFormats.size() * rTableTemplateMap.size();
355 const sal_Int32 nCount = nUsedCellStylesCount + rDoc.GetCellStyles().size();
356 if (0 <= nIndex && nIndex < nCount)
358 if (nUsedCellStylesCount > nIndex)
360 const sal_Int32 nAutoFormat = nIndex / rTableTemplateMap.size();
361 const sal_Int32 nBoxFormat = rTableTemplateMap[nIndex % rTableTemplateMap.size()];
362 const SwTableAutoFormat& rTableFormat = rAutoFormats[nAutoFormat];
363 SwStyleNameMapper::FillProgName(rTableFormat.GetName(), *pString, SwGetPoolIdFromName::TabStyle);
364 *pString += rTableFormat.GetTableTemplateCellSubName(rTableFormat.GetBoxFormat(nBoxFormat));
366 else
367 *pString = rDoc.GetCellStyles()[nIndex-nUsedCellStylesCount].GetName();
369 return nCount;
372 template<>
373 sal_uInt16 StyleFamilyEntry::TranslateIndex<SfxStyleFamily::Char>(const sal_uInt16 nIndex)
375 static_assert(nPoolChrNormalRange > 0 && nPoolChrHtmlRange > 0, "invalid pool range");
376 if (nIndex < nPoolChrNormalRange)
377 return nIndex + RES_POOLCHR_NORMAL_BEGIN;
378 else if (nIndex < (nPoolChrHtmlRange + nPoolChrNormalRange))
379 return nIndex + RES_POOLCHR_HTML_BEGIN - nPoolChrNormalRange;
380 throw lang::IndexOutOfBoundsException();
383 template<>
384 sal_uInt16 StyleFamilyEntry::TranslateIndex<SfxStyleFamily::Para>(const sal_uInt16 nIndex)
386 static_assert(nPoolCollTextRange > 0 && nPoolCollListsRange > 0 && nPoolCollExtraRange > 0 && nPoolCollRegisterRange > 0 && nPoolCollDocRange > 0 && nPoolCollHtmlRange > 0, "weird pool range");
387 if (nIndex < nPoolCollListsStackedStart)
388 return nIndex + RES_POOLCOLL_TEXT_BEGIN;
389 else if (nIndex < nPoolCollExtraStackedStart)
390 return nIndex + RES_POOLCOLL_LISTS_BEGIN - nPoolCollListsStackedStart;
391 else if (nIndex < nPoolCollRegisterStackedStart)
392 return nIndex + RES_POOLCOLL_EXTRA_BEGIN - nPoolCollExtraStackedStart;
393 else if (nIndex < nPoolCollDocStackedStart)
394 return nIndex + RES_POOLCOLL_REGISTER_BEGIN - nPoolCollRegisterStackedStart;
395 else if (nIndex < nPoolCollHtmlStackedStart)
396 return nIndex + RES_POOLCOLL_DOC_BEGIN - nPoolCollDocStackedStart;
397 else if (nIndex < nPoolCollHtmlStackedStart + nPoolCollTextRange)
398 return nIndex + RES_POOLCOLL_HTML_BEGIN - nPoolCollHtmlStackedStart;
399 throw lang::IndexOutOfBoundsException();
402 template<>
403 sal_uInt16 StyleFamilyEntry::TranslateIndex<SfxStyleFamily::Page>(const sal_uInt16 nIndex)
405 if (nIndex < nPoolPageRange)
406 return nIndex + RES_POOLPAGE_BEGIN;
407 throw lang::IndexOutOfBoundsException();
410 template<>
411 sal_uInt16 StyleFamilyEntry::TranslateIndex<SfxStyleFamily::Frame>(const sal_uInt16 nIndex)
413 if (nIndex < nPoolFrameRange)
414 return nIndex + RES_POOLFRM_BEGIN;
415 throw lang::IndexOutOfBoundsException();
418 template<>
419 sal_uInt16 StyleFamilyEntry::TranslateIndex<SfxStyleFamily::Pseudo>(const sal_uInt16 nIndex)
421 if (nIndex < nPoolNumRange)
422 return nIndex + RES_POOLNUMRULE_BEGIN;
423 throw lang::IndexOutOfBoundsException();
426 const std::vector<StyleFamilyEntry>& lcl_GetStyleFamilyEntries()
428 static const std::vector<StyleFamilyEntry> our_pStyleFamilyEntries{
429 StyleFamilyEntry::Create<SfxStyleFamily::Char> (PROPERTY_MAP_CHAR_STYLE, SwGetPoolIdFromName::ChrFmt, "CharacterStyles", STR_STYLE_FAMILY_CHARACTER),
430 StyleFamilyEntry::Create<SfxStyleFamily::Para> (PROPERTY_MAP_PARA_STYLE, SwGetPoolIdFromName::TxtColl, "ParagraphStyles", STR_STYLE_FAMILY_PARAGRAPH),
431 StyleFamilyEntry::Create<SfxStyleFamily::Page> (PROPERTY_MAP_PAGE_STYLE, SwGetPoolIdFromName::PageDesc, "PageStyles", STR_STYLE_FAMILY_PAGE),
432 StyleFamilyEntry::Create<SfxStyleFamily::Frame> (PROPERTY_MAP_FRAME_STYLE, SwGetPoolIdFromName::FrmFmt, "FrameStyles", STR_STYLE_FAMILY_FRAME),
433 StyleFamilyEntry::Create<SfxStyleFamily::Pseudo>(PROPERTY_MAP_NUM_STYLE, SwGetPoolIdFromName::NumRule, "NumberingStyles", STR_STYLE_FAMILY_NUMBERING),
434 StyleFamilyEntry::Create<SfxStyleFamily::Table> (PROPERTY_MAP_TABLE_STYLE, SwGetPoolIdFromName::TabStyle, "TableStyles", STR_STYLE_FAMILY_TABLE),
435 StyleFamilyEntry::Create<SfxStyleFamily::Cell> (PROPERTY_MAP_CELL_STYLE, SwGetPoolIdFromName::CellStyle, "CellStyles", STR_STYLE_FAMILY_CELL),
437 return our_pStyleFamilyEntries;
440 class SwStyleBase_Impl
442 private:
443 SwDoc& m_rDoc;
444 const SwPageDesc* m_pOldPageDesc;
445 rtl::Reference<SwDocStyleSheet> m_xNewBase;
446 SfxItemSet* m_pItemSet;
447 std::unique_ptr<SfxItemSet> m_pMyItemSet;
448 OUString m_rStyleName;
449 const SwAttrSet* m_pParentStyle;
450 public:
451 SwStyleBase_Impl(SwDoc& rSwDoc, OUString aName, const SwAttrSet* pParentStyle)
452 : m_rDoc(rSwDoc)
453 , m_pOldPageDesc(nullptr)
454 , m_pItemSet(nullptr)
455 , m_rStyleName(std::move(aName))
456 , m_pParentStyle(pParentStyle)
459 rtl::Reference<SwDocStyleSheet>& getNewBase()
461 return m_xNewBase;
464 void setNewBase(SwDocStyleSheet* pNew)
466 m_xNewBase = pNew;
469 bool HasItemSet() const
471 return m_xNewBase.is();
474 SfxItemSet& GetItemSet()
476 assert(m_xNewBase.is());
477 if(!m_pItemSet)
479 m_pMyItemSet.reset(new SfxItemSet(m_xNewBase->GetItemSet()));
480 m_pItemSet = m_pMyItemSet.get();
482 // set parent style to have the correct XFillStyle setting as XFILL_NONE
483 if(!m_pItemSet->GetParent() && m_pParentStyle)
484 m_pItemSet->SetParent(m_pParentStyle);
486 return *m_pItemSet;
489 const SwPageDesc* GetOldPageDesc();
491 // still a hack, but a bit more explicit and with a proper scope
492 struct ItemSetOverrider
494 SwStyleBase_Impl& m_rStyleBase;
495 SfxItemSet* m_pOldSet;
496 ItemSetOverrider(SwStyleBase_Impl& rStyleBase, SfxItemSet* pTemp)
497 : m_rStyleBase(rStyleBase)
498 , m_pOldSet(m_rStyleBase.m_pItemSet)
499 { m_rStyleBase.m_pItemSet = pTemp; }
500 ~ItemSetOverrider()
501 { m_rStyleBase.m_pItemSet = m_pOldSet; };
505 class SwStyleProperties_Impl;
506 class SwXStyle : public cppu::WeakImplHelper
508 css::style::XStyle,
509 css::beans::XPropertySet,
510 css::beans::XMultiPropertySet,
511 css::lang::XServiceInfo,
512 css::lang::XUnoTunnel,
513 css::beans::XPropertyState,
514 css::beans::XMultiPropertyStates
516 , public SfxListener
517 , public SvtListener
519 SwDoc* m_pDoc;
520 OUString m_sStyleName;
521 const StyleFamilyEntry& m_rEntry;
522 bool m_bIsDescriptor;
523 bool m_bIsConditional;
524 OUString m_sParentStyleName;
526 protected:
527 SfxStyleSheetBasePool* m_pBasePool;
528 std::unique_ptr<SwStyleProperties_Impl> m_pPropertiesImpl;
529 css::uno::Reference<css::container::XNameAccess> m_xStyleFamily;
530 css::uno::Reference<css::beans::XPropertySet> m_xStyleData;
532 template<sal_uInt16>
533 void SetPropertyValue(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const uno::Any&, SwStyleBase_Impl&);
534 void SetPropertyValues_Impl( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& aValues );
535 SfxStyleSheetBase* GetStyleSheetBase();
536 void PrepareStyleBase(SwStyleBase_Impl& rBase);
537 template<sal_uInt16>
538 uno::Any GetStyleProperty(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase);
539 uno::Any GetStyleProperty_Impl(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase);
540 uno::Any GetPropertyValue_Impl(const SfxItemPropertySet* pPropSet, SwStyleBase_Impl& rBase, const OUString& rPropertyName);
542 public:
543 SwXStyle(SwDoc* pDoc, SfxStyleFamily eFam, bool bConditional = false);
544 SwXStyle(SfxStyleSheetBasePool* pPool, SfxStyleFamily eFamily, SwDoc* pDoc, const OUString& rStyleName);
545 virtual ~SwXStyle() override;
548 static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId();
550 //XUnoTunnel
551 virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
553 //XNamed
554 virtual OUString SAL_CALL getName() override;
555 virtual void SAL_CALL setName(const OUString& Name_) override;
557 //XStyle
558 virtual sal_Bool SAL_CALL isUserDefined() override;
559 virtual sal_Bool SAL_CALL isInUse() override;
560 virtual OUString SAL_CALL getParentStyle() override;
561 virtual void SAL_CALL setParentStyle(const OUString& aParentStyle) override;
563 //XPropertySet
564 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
565 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
566 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
567 virtual void SAL_CALL addPropertyChangeListener( const OUString&, const css::uno::Reference< css::beans::XPropertyChangeListener >& ) override
568 { OSL_FAIL("not implemented"); };
569 virtual void SAL_CALL removePropertyChangeListener( const OUString&, const css::uno::Reference< css::beans::XPropertyChangeListener >& ) override
570 { OSL_FAIL("not implemented"); };
571 virtual void SAL_CALL addVetoableChangeListener( const OUString&, const css::uno::Reference< css::beans::XVetoableChangeListener >& ) override
572 { OSL_FAIL("not implemented"); };
573 virtual void SAL_CALL removeVetoableChangeListener( const OUString&, const css::uno::Reference< css::beans::XVetoableChangeListener >& ) override
574 { OSL_FAIL("not implemented"); };
576 //XMultiPropertySet
577 virtual void SAL_CALL setPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& aValues ) override;
578 virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames ) override;
579 virtual void SAL_CALL addPropertiesChangeListener( const css::uno::Sequence< OUString >&, const css::uno::Reference< css::beans::XPropertiesChangeListener >& ) override
581 virtual void SAL_CALL removePropertiesChangeListener( const css::uno::Reference< css::beans::XPropertiesChangeListener >& ) override
583 virtual void SAL_CALL firePropertiesChangeEvent( const css::uno::Sequence< OUString >&, const css::uno::Reference< css::beans::XPropertiesChangeListener >& ) override
586 //XPropertyState
587 virtual css::beans::PropertyState SAL_CALL getPropertyState( const OUString& PropertyName ) override;
588 virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL getPropertyStates( const css::uno::Sequence< OUString >& aPropertyName ) override;
589 virtual void SAL_CALL setPropertyToDefault( const OUString& PropertyName ) override;
590 virtual css::uno::Any SAL_CALL getPropertyDefault( const OUString& aPropertyName ) override;
592 //XMultiPropertyStates
593 virtual void SAL_CALL setAllPropertiesToDefault( ) override;
594 virtual void SAL_CALL setPropertiesToDefault( const css::uno::Sequence< OUString >& aPropertyNames ) override;
595 virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPropertyDefaults( const css::uno::Sequence< OUString >& aPropertyNames ) override;
597 //XServiceInfo
598 virtual OUString SAL_CALL getImplementationName() override
599 { return {"SwXStyle"}; };
600 virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override
601 { return cppu::supportsService(this, rServiceName); };
602 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
604 //SfxListener
605 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
606 //SvtListener
607 virtual void Notify(const SfxHint&) override;
608 const OUString& GetStyleName() const { return m_sStyleName;}
609 SfxStyleFamily GetFamily() const {return m_rEntry.family();}
611 bool IsDescriptor() const {return m_bIsDescriptor;}
612 bool IsConditional() const { return m_bIsConditional;}
613 const OUString& GetParentStyleName() const { return m_sParentStyleName;}
614 void SetDoc(SwDoc* pDc, SfxStyleSheetBasePool* pPool)
616 m_bIsDescriptor = false; m_pDoc = pDc;
617 m_pBasePool = pPool;
618 SfxListener::StartListening(*m_pBasePool);
620 SwDoc* GetDoc() const { return m_pDoc; }
621 void Invalidate();
622 void ApplyDescriptorProperties();
623 void SetStyleName(const OUString& rSet){ m_sStyleName = rSet;}
624 /// @throws beans::PropertyVetoException
625 /// @throws lang::IllegalArgumentException
626 /// @throws lang::WrappedTargetException
627 /// @throws uno::RuntimeException
628 void SetStyleProperty(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase);
629 void PutItemToSet(const SvxSetItem* pSetItem, const SfxItemPropertySet& rPropSet, const SfxItemPropertyMapEntry& rEntry, const uno::Any& rVal, SwStyleBase_Impl& rBaseImpl);
632 typedef cppu::ImplInheritanceHelper< SwXStyle, css::document::XEventsSupplier> SwXFrameStyle_Base;
633 class SwXFrameStyle
634 : public SwXFrameStyle_Base
635 , public sw::ICoreFrameStyle
637 public:
638 SwXFrameStyle(SfxStyleSheetBasePool& rPool,
639 SwDoc* pDoc,
640 const OUString& rStyleName) :
641 SwXFrameStyle_Base(&rPool, SfxStyleFamily::Frame, pDoc, rStyleName){}
642 explicit SwXFrameStyle(SwDoc *pDoc);
644 virtual css::uno::Reference< css::container::XNameReplace > SAL_CALL getEvents( ) override;
646 //ICoreStyle
647 virtual void SetItem(sal_uInt16 eAtr, const SfxPoolItem& rItem) override;
648 virtual const SfxPoolItem* GetItem(sal_uInt16 eAtr) override;
649 virtual css::document::XEventsSupplier& GetEventsSupplier() override
650 { return *this; };
653 class SwXPageStyle
654 : public SwXStyle
656 protected:
657 void SetPropertyValues_Impl( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& aValues );
658 css::uno::Sequence< css::uno::Any > GetPropertyValues_Impl( const css::uno::Sequence< OUString >& aPropertyNames );
660 public:
661 SwXPageStyle(SfxStyleSheetBasePool& rPool, SwDocShell* pDocSh, const OUString& rStyleName);
662 explicit SwXPageStyle(SwDocShell* pDocSh);
664 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
665 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
667 virtual void SAL_CALL setPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& aValues ) override;
668 virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames ) override;
671 class SwStyleProperties_Impl
673 const SfxItemPropertyMap& mrMap;
674 std::map<OUString, uno::Any> m_vPropertyValues;
675 public:
676 explicit SwStyleProperties_Impl(const SfxItemPropertyMap& rMap)
677 : mrMap(rMap)
680 bool AllowsKey(std::u16string_view rName)
682 return mrMap.hasPropertyByName(rName);
684 bool SetProperty(const OUString& rName, const uno::Any& rValue)
686 if(!AllowsKey(rName))
687 return false;
688 m_vPropertyValues[rName] = rValue;
689 return true;
691 void GetProperty(const OUString& rName, const uno::Any*& pAny)
693 if(!AllowsKey(rName))
695 pAny = nullptr;
696 return;
698 pAny = &m_vPropertyValues[rName];
699 return;
701 bool ClearProperty( const OUString& rName )
703 if(!AllowsKey(rName))
704 return false;
705 m_vPropertyValues[rName] = uno::Any();
706 return true;
708 void ClearAllProperties( )
709 { m_vPropertyValues.clear(); }
710 void Apply(SwXStyle& rStyle)
712 for(const auto& rPropertyPair : m_vPropertyValues)
714 if(rPropertyPair.second.hasValue())
715 rStyle.setPropertyValue(rPropertyPair.first, rPropertyPair.second);
720 template<SfxStyleFamily eFamily>
721 css::uno::Reference<css::style::XStyle> StyleFamilyEntry::CreateStyle(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName)
723 return pBasePool ? new SwXStyle(pBasePool, eFamily, pDocShell->GetDoc(), sStyleName) : new SwXStyle(pDocShell->GetDoc(), eFamily, false);
726 template<>
727 css::uno::Reference<css::style::XStyle> StyleFamilyEntry::CreateStyle<SfxStyleFamily::Frame>(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName)
729 return pBasePool ? new SwXFrameStyle(*pBasePool, pDocShell->GetDoc(), sStyleName) : new SwXFrameStyle(pDocShell->GetDoc());
732 template<>
733 css::uno::Reference<css::style::XStyle> StyleFamilyEntry::CreateStyle<SfxStyleFamily::Page>(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName)
735 return pBasePool ? new SwXPageStyle(*pBasePool, pDocShell, sStyleName) : new SwXPageStyle(pDocShell);
738 template<>
739 css::uno::Reference<css::style::XStyle> StyleFamilyEntry::CreateStyle<SfxStyleFamily::Table>(SfxStyleSheetBasePool* /*pBasePool*/, SwDocShell* pDocShell, const OUString& sStyleName)
741 return SwXTextTableStyle::CreateXTextTableStyle(pDocShell, sStyleName);
744 template<>
745 css::uno::Reference<css::style::XStyle> StyleFamilyEntry::CreateStyle<SfxStyleFamily::Cell>(SfxStyleSheetBasePool* /*pBasePool*/, SwDocShell* pDocShell, const OUString& sStyleName)
747 return SwXTextCellStyle::CreateXTextCellStyle(pDocShell, sStyleName);
750 class XStyleFamily : public cppu::WeakImplHelper
752 container::XNameContainer,
753 lang::XServiceInfo,
754 container::XIndexAccess,
755 beans::XPropertySet
757 , public SfxListener
759 const StyleFamilyEntry& m_rEntry;
760 SfxStyleSheetBasePool* m_pBasePool;
761 SwDocShell* m_pDocShell;
763 SwXStyle* FindStyle(std::u16string_view rStyleName) const;
764 sal_Int32 GetCountOrName(OUString* pString, sal_Int32 nIndex = SAL_MAX_INT32)
765 { return m_rEntry.getCountOrName(*m_pDocShell->GetDoc(), pString, nIndex); };
766 static const StyleFamilyEntry& InitEntry(SfxStyleFamily eFamily)
768 auto& entries = lcl_GetStyleFamilyEntries();
769 const auto pEntry = std::find_if(entries.begin(), entries.end(),
770 [eFamily] (const StyleFamilyEntry& e) { return e.family() == eFamily; });
771 assert(pEntry != entries.end());
772 return *pEntry;
774 public:
775 XStyleFamily(SwDocShell* pDocShell, const SfxStyleFamily eFamily)
776 : m_rEntry(InitEntry(eFamily))
777 , m_pBasePool(pDocShell->GetStyleSheetPool())
778 , m_pDocShell(pDocShell)
780 if (m_pBasePool) //tdf#124142 html docs can have no styles
781 StartListening(*m_pBasePool);
784 //XIndexAccess
785 virtual sal_Int32 SAL_CALL getCount() override
787 SolarMutexGuard aGuard;
788 return GetCountOrName(nullptr);
790 virtual uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override;
792 //XElementAccess
793 virtual uno::Type SAL_CALL getElementType( ) override
794 { return cppu::UnoType<style::XStyle>::get(); };
795 virtual sal_Bool SAL_CALL hasElements( ) override
797 if(!m_pBasePool)
798 throw uno::RuntimeException();
799 return true;
802 //XNameAccess
803 virtual uno::Any SAL_CALL getByName(const OUString& Name) override;
804 virtual uno::Sequence< OUString > SAL_CALL getElementNames() override;
805 virtual sal_Bool SAL_CALL hasByName(const OUString& Name) override;
807 //XNameContainer
808 virtual void SAL_CALL insertByName(const OUString& Name, const uno::Any& Element) override;
809 virtual void SAL_CALL replaceByName(const OUString& Name, const uno::Any& Element) override;
810 virtual void SAL_CALL removeByName(const OUString& Name) override;
812 //XPropertySet
813 virtual uno::Reference< beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override
814 { return {}; };
815 virtual void SAL_CALL setPropertyValue( const OUString&, const uno::Any&) override
816 { SAL_WARN("sw.uno", "###unexpected!"); };
817 virtual uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
818 virtual void SAL_CALL addPropertyChangeListener( const OUString&, const uno::Reference<beans::XPropertyChangeListener>&) override
819 { SAL_WARN("sw.uno", "###unexpected!"); };
820 virtual void SAL_CALL removePropertyChangeListener( const OUString&, const uno::Reference<beans::XPropertyChangeListener>&) override
821 { SAL_WARN("sw.uno", "###unexpected!"); };
822 virtual void SAL_CALL addVetoableChangeListener(const OUString&, const uno::Reference<beans::XVetoableChangeListener>&) override
823 { SAL_WARN("sw.uno", "###unexpected!"); };
824 virtual void SAL_CALL removeVetoableChangeListener(const OUString&, const uno::Reference<beans::XVetoableChangeListener>&) override
825 { SAL_WARN("sw.uno", "###unexpected!"); };
827 //SfxListener
828 virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override
830 if(rHint.GetId() == SfxHintId::Dying)
832 m_pBasePool = nullptr;
833 m_pDocShell = nullptr;
834 EndListening(rBC);
838 //XServiceInfo
839 virtual OUString SAL_CALL getImplementationName() override
840 { return {"XStyleFamily"}; };
841 virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override
842 { return cppu::supportsService(this, rServiceName); };
843 virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
844 { return { "com.sun.star.style.StyleFamily" }; }
848 OUString SwXStyleFamilies::getImplementationName()
849 { return {"SwXStyleFamilies"}; }
851 sal_Bool SwXStyleFamilies::supportsService(const OUString& rServiceName)
853 return cppu::supportsService(this, rServiceName);
856 uno::Sequence< OUString > SwXStyleFamilies::getSupportedServiceNames()
857 { return { "com.sun.star.style.StyleFamilies" }; }
859 SwXStyleFamilies::SwXStyleFamilies(SwDocShell& rDocShell) :
860 SwUnoCollection(rDocShell.GetDoc()),
861 m_pDocShell(&rDocShell)
864 SwXStyleFamilies::~SwXStyleFamilies()
867 uno::Any SAL_CALL SwXStyleFamilies::getByName(const OUString& Name)
869 SolarMutexGuard aGuard;
870 if(!IsValid())
871 throw uno::RuntimeException();
872 auto& entries(lcl_GetStyleFamilyEntries());
873 const auto pEntry = std::find_if(entries.begin(), entries.end(),
874 [&Name] (const StyleFamilyEntry& e) { return e.name() == Name; });
875 if(pEntry == entries.end())
876 throw container::NoSuchElementException();
877 return getByIndex(pEntry - entries.begin());
880 uno::Sequence< OUString > SwXStyleFamilies::getElementNames()
882 auto& entries(lcl_GetStyleFamilyEntries());
883 uno::Sequence<OUString> aNames(entries.size());
884 std::transform(entries.begin(), entries.end(),
885 aNames.getArray(), [] (const StyleFamilyEntry& e) { return e.name(); });
886 return aNames;
889 sal_Bool SwXStyleFamilies::hasByName(const OUString& Name)
891 auto& entries(lcl_GetStyleFamilyEntries());
892 return std::any_of(entries.begin(), entries.end(),
893 [&Name] (const StyleFamilyEntry& e) { return e.name() == Name; });
896 sal_Int32 SwXStyleFamilies::getCount()
898 return lcl_GetStyleFamilyEntries().size();
901 uno::Any SwXStyleFamilies::getByIndex(sal_Int32 nIndex)
903 auto& entries(lcl_GetStyleFamilyEntries());
904 SolarMutexGuard aGuard;
905 if(nIndex < 0 || o3tl::make_unsigned(nIndex) >= entries.size())
906 throw lang::IndexOutOfBoundsException();
907 if(!IsValid())
908 throw uno::RuntimeException();
909 auto eFamily = entries[nIndex].family();
910 assert(eFamily != SfxStyleFamily::All);
911 auto& rxFamily = m_vFamilies[eFamily];
912 if(!rxFamily.is())
913 rxFamily = new XStyleFamily(m_pDocShell, eFamily);
914 return uno::Any(rxFamily);
917 uno::Type SwXStyleFamilies::getElementType()
919 return cppu::UnoType<container::XNameContainer>::get();
922 sal_Bool SwXStyleFamilies::hasElements()
923 { return true; }
925 void SwXStyleFamilies::loadStylesFromURL(const OUString& rURL,
926 const uno::Sequence< beans::PropertyValue >& aOptions)
928 SolarMutexGuard aGuard;
929 if(!IsValid() || rURL.isEmpty())
930 throw uno::RuntimeException();
931 SwgReaderOption aOpt;
932 aOpt.SetFrameFormats(true);
933 aOpt.SetTextFormats(true);
934 aOpt.SetPageDescs(true);
935 aOpt.SetNumRules(true);
936 aOpt.SetMerge(false);
937 for(const auto& rProperty: aOptions)
939 bool bValue = false;
940 if(rProperty.Value.getValueType() == cppu::UnoType<bool>::get())
941 bValue = rProperty.Value.get<bool>();
943 if(rProperty.Name == UNO_NAME_OVERWRITE_STYLES)
944 aOpt.SetMerge(!bValue);
945 else if(rProperty.Name == UNO_NAME_LOAD_NUMBERING_STYLES)
946 aOpt.SetNumRules(bValue);
947 else if(rProperty.Name == UNO_NAME_LOAD_PAGE_STYLES)
948 aOpt.SetPageDescs(bValue);
949 else if(rProperty.Name == UNO_NAME_LOAD_FRAME_STYLES)
950 aOpt.SetFrameFormats(bValue);
951 else if(rProperty.Name == UNO_NAME_LOAD_TEXT_STYLES)
952 aOpt.SetTextFormats(bValue);
953 else if(rProperty.Name == "InputStream")
955 Reference<XInputStream> xInputStream;
956 if (!(rProperty.Value >>= xInputStream))
957 throw IllegalArgumentException("Parameter 'InputStream' could not be converted to "
958 "type 'com::sun::star::io::XInputStream'",
959 nullptr, 0);
961 aOpt.SetInputStream(xInputStream);
965 const ErrCode nErr = m_pDocShell->LoadStylesFromFile( rURL, aOpt, true );
966 if(nErr)
967 throw io::IOException();
970 uno::Sequence< beans::PropertyValue > SwXStyleFamilies::getStyleLoaderOptions()
972 const uno::Any aVal(true);
973 return comphelper::InitPropertySequence({
974 { UNO_NAME_LOAD_TEXT_STYLES, aVal },
975 { UNO_NAME_LOAD_FRAME_STYLES, aVal },
976 { UNO_NAME_LOAD_PAGE_STYLES, aVal },
977 { UNO_NAME_LOAD_NUMBERING_STYLES, aVal },
978 { UNO_NAME_OVERWRITE_STYLES, aVal }
982 static bool lcl_GetHeaderFooterItem(
983 SfxItemSet const& rSet, std::u16string_view rPropName, bool const bFooter,
984 SvxSetItem const*& o_rpItem)
986 o_rpItem = rSet.GetItemIfSet(
987 bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET,
988 false);
989 if (!o_rpItem &&
990 rPropName == UNO_NAME_FIRST_IS_SHARED)
991 { // fdo#79269 header may not exist, check footer then
992 o_rpItem = rSet.GetItemIfSet(
993 (!bFooter) ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET,
994 false);
996 return o_rpItem;
999 uno::Reference<css::style::XStyle> SwXStyleFamilies::CreateStyle(SfxStyleFamily eFamily, SwDoc& rDoc)
1001 auto& entries(lcl_GetStyleFamilyEntries());
1002 const auto pEntry = std::find_if(entries.begin(), entries.end(),
1003 [eFamily] (const StyleFamilyEntry& e) { return e.family() == eFamily; });
1004 return pEntry == entries.end() ? nullptr : pEntry->createStyle(nullptr, rDoc.GetDocShell(), "");
1007 // FIXME: Ugly special casing that should die.
1008 uno::Reference<css::style::XStyle> SwXStyleFamilies::CreateStyleCondParagraph(SwDoc& rDoc)
1009 { return new SwXStyle(&rDoc, SfxStyleFamily::Para, true); };
1011 uno::Any XStyleFamily::getByIndex(sal_Int32 nIndex)
1013 SolarMutexGuard aGuard;
1014 if(nIndex < 0)
1015 throw lang::IndexOutOfBoundsException();
1016 if(!m_pBasePool)
1017 throw uno::RuntimeException();
1018 OUString sStyleName;
1021 SwStyleNameMapper::FillUIName(m_rEntry.translateIndex(nIndex), sStyleName);
1022 } catch(...) {}
1023 if (sStyleName.isEmpty())
1024 GetCountOrName(&sStyleName, nIndex);
1025 if(sStyleName.isEmpty())
1026 throw lang::IndexOutOfBoundsException();
1027 return getByName(sStyleName);
1030 uno::Any XStyleFamily::getByName(const OUString& rName)
1032 SolarMutexGuard aGuard;
1033 OUString sStyleName;
1034 SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.poolId());
1035 if(!m_pBasePool)
1036 throw uno::RuntimeException();
1037 SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName, m_rEntry.family());
1038 if(!pBase)
1039 throw container::NoSuchElementException(rName);
1040 uno::Reference<style::XStyle> xStyle = FindStyle(sStyleName);
1041 if(!xStyle.is())
1042 xStyle = m_rEntry.createStyle(m_pBasePool, m_pDocShell, m_rEntry.family() == SfxStyleFamily::Frame ? pBase->GetName() : sStyleName);
1043 return uno::Any(xStyle);
1046 uno::Sequence<OUString> XStyleFamily::getElementNames()
1048 SolarMutexGuard aGuard;
1049 if(!m_pBasePool)
1050 throw uno::RuntimeException();
1051 std::vector<OUString> vRet;
1052 std::unique_ptr<SfxStyleSheetIterator> pIt = m_pBasePool->CreateIterator(m_rEntry.family());
1053 for (SfxStyleSheetBase* pStyle = pIt->First(); pStyle; pStyle = pIt->Next())
1055 OUString sName;
1056 SwStyleNameMapper::FillProgName(pStyle->GetName(), sName, m_rEntry.poolId());
1057 vRet.push_back(sName);
1059 return comphelper::containerToSequence(vRet);
1062 sal_Bool XStyleFamily::hasByName(const OUString& rName)
1064 SolarMutexGuard aGuard;
1065 if(!m_pBasePool)
1066 throw uno::RuntimeException();
1067 OUString sStyleName;
1068 SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.poolId());
1069 SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName, m_rEntry.family());
1070 return nullptr != pBase;
1073 void XStyleFamily::insertByName(const OUString& rName, const uno::Any& rElement)
1075 SolarMutexGuard aGuard;
1076 if(!m_pBasePool)
1077 throw uno::RuntimeException();
1078 OUString sStyleName;
1079 SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.poolId());
1080 SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName, m_rEntry.family());
1081 if (pBase)
1082 throw container::ElementExistException();
1083 if(rElement.getValueType().getTypeClass() != uno::TypeClass_INTERFACE)
1084 throw lang::IllegalArgumentException();
1085 if (SwGetPoolIdFromName::CellStyle == m_rEntry.poolId())
1087 // handle cell style
1088 uno::Reference<style::XStyle> xStyle = rElement.get<uno::Reference<style::XStyle>>();
1089 SwXTextCellStyle* pNewStyle = dynamic_cast<SwXTextCellStyle*>(xStyle.get());
1090 if (!pNewStyle)
1091 throw lang::IllegalArgumentException();
1093 pNewStyle->setName(sStyleName); // insertByName sets the element name
1094 m_pDocShell->GetDoc()->GetCellStyles().AddBoxFormat(*pNewStyle->GetBoxFormat(), sStyleName);
1095 pNewStyle->SetPhysical();
1097 else if (SwGetPoolIdFromName::TabStyle == m_rEntry.poolId())
1099 // handle table style
1100 uno::Reference<style::XStyle> xStyle = rElement.get<uno::Reference<style::XStyle>>();
1101 SwXTextTableStyle* pNewStyle = dynamic_cast<SwXTextTableStyle*>(xStyle.get());
1102 if (!pNewStyle)
1103 throw lang::IllegalArgumentException();
1105 pNewStyle->setName(sStyleName); // insertByName sets the element name
1106 m_pDocShell->GetDoc()->GetTableStyles().AddAutoFormat(*pNewStyle->GetTableFormat());
1107 pNewStyle->SetPhysical();
1109 else
1111 uno::Reference<lang::XUnoTunnel> xStyleTunnel = rElement.get<uno::Reference<lang::XUnoTunnel>>();
1112 SwXStyle* pNewStyle = comphelper::getFromUnoTunnel<SwXStyle>(xStyleTunnel);
1113 if (!pNewStyle || !pNewStyle->IsDescriptor() || pNewStyle->GetFamily() != m_rEntry.family())
1114 throw lang::IllegalArgumentException();
1116 SfxStyleSearchBits nMask = SfxStyleSearchBits::All;
1117 if(m_rEntry.family() == SfxStyleFamily::Para && !pNewStyle->IsConditional())
1118 nMask &= ~SfxStyleSearchBits::SwCondColl;
1119 m_pBasePool->Make(sStyleName, m_rEntry.family(), nMask);
1120 pNewStyle->SetDoc(m_pDocShell->GetDoc(), m_pBasePool);
1121 pNewStyle->SetStyleName(sStyleName);
1122 const OUString sParentStyleName(pNewStyle->GetParentStyleName());
1123 if (!sParentStyleName.isEmpty())
1125 SfxStyleSheetBase* pParentBase = m_pBasePool->Find(sParentStyleName, m_rEntry.family());
1126 if(pParentBase && pParentBase->GetFamily() == m_rEntry.family() &&
1127 pParentBase->GetPool() == m_pBasePool)
1128 m_pBasePool->SetParent(m_rEntry.family(), sStyleName, sParentStyleName);
1130 // after all, we still need to apply the properties of the descriptor
1131 pNewStyle->ApplyDescriptorProperties();
1135 void XStyleFamily::replaceByName(const OUString& rName, const uno::Any& rElement)
1137 SolarMutexGuard aGuard;
1138 if(!m_pBasePool)
1139 throw uno::RuntimeException();
1140 OUString sStyleName;
1141 SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.poolId());
1142 SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName, m_rEntry.family());
1143 // replacements only for userdefined styles
1144 if(!pBase)
1145 throw container::NoSuchElementException();
1146 if (SwGetPoolIdFromName::CellStyle == m_rEntry.poolId())
1148 // handle cell styles, don't call on assigned cell styles (TableStyle child)
1149 OUString sParent;
1150 SwBoxAutoFormat* pBoxAutoFormat = SwXTextCellStyle::GetBoxAutoFormat(m_pDocShell, sStyleName, &sParent);
1151 if (pBoxAutoFormat && sParent.isEmpty())// if parent exists then this style is assigned to a table style. Don't replace.
1153 uno::Reference<style::XStyle> xStyle = rElement.get<uno::Reference<style::XStyle>>();
1154 SwXTextCellStyle* pStyleToReplaceWith = dynamic_cast<SwXTextCellStyle*>(xStyle.get());
1155 if (!pStyleToReplaceWith)
1156 throw lang::IllegalArgumentException();
1158 pStyleToReplaceWith->setName(sStyleName);
1159 *pBoxAutoFormat = *pStyleToReplaceWith->GetBoxFormat();
1160 pStyleToReplaceWith->SetPhysical();
1163 else if (SwGetPoolIdFromName::TabStyle == m_rEntry.poolId())
1165 // handle table styles
1166 SwTableAutoFormat* pTableAutoFormat = SwXTextTableStyle::GetTableAutoFormat(m_pDocShell, sStyleName);
1167 if (pTableAutoFormat)
1169 uno::Reference<style::XStyle> xStyle = rElement.get<uno::Reference<style::XStyle>>();
1170 SwXTextTableStyle* pStyleToReplaceWith = dynamic_cast<SwXTextTableStyle*>(xStyle.get());
1171 if (!pStyleToReplaceWith)
1172 throw lang::IllegalArgumentException();
1174 pStyleToReplaceWith->setName(sStyleName);
1175 *pTableAutoFormat = *pStyleToReplaceWith->GetTableFormat();
1176 pStyleToReplaceWith->SetPhysical();
1179 else
1181 if(!pBase->IsUserDefined())
1182 throw lang::IllegalArgumentException();
1183 //if there's an object available to this style then it must be invalidated
1184 uno::Reference<style::XStyle> xStyle = FindStyle(pBase->GetName());
1185 if(xStyle.is())
1187 SwXStyle* pStyle = comphelper::getFromUnoTunnel<SwXStyle>(xStyle);
1188 if(pStyle)
1189 pStyle->Invalidate();
1191 m_pBasePool->Remove(pBase);
1192 insertByName(rName, rElement);
1196 void XStyleFamily::removeByName(const OUString& rName)
1198 SolarMutexGuard aGuard;
1199 if(!m_pBasePool)
1200 throw uno::RuntimeException();
1201 OUString sName;
1202 SwStyleNameMapper::FillUIName(rName, sName, m_rEntry.poolId());
1203 SfxStyleSheetBase* pBase = m_pBasePool->Find(sName, m_rEntry.family());
1204 if(!pBase)
1205 throw container::NoSuchElementException();
1206 if (SwGetPoolIdFromName::CellStyle == m_rEntry.poolId())
1208 // handle cell style
1209 m_pDocShell->GetDoc()->GetCellStyles().RemoveBoxFormat(rName);
1211 else if (SwGetPoolIdFromName::TabStyle == m_rEntry.poolId())
1213 // handle table style
1214 m_pDocShell->GetDoc()->GetTableStyles().EraseAutoFormat(rName);
1216 else
1217 m_pBasePool->Remove(pBase);
1220 uno::Any SAL_CALL XStyleFamily::getPropertyValue( const OUString& sPropertyName )
1222 if(sPropertyName != "DisplayName")
1223 throw beans::UnknownPropertyException( "unknown property: " + sPropertyName, static_cast<OWeakObject *>(this) );
1224 SolarMutexGuard aGuard;
1225 return uno::Any(SwResId(m_rEntry.resId()));
1229 SwXStyle* XStyleFamily::FindStyle(std::u16string_view rStyleName) const
1231 const size_t nLCount = m_pBasePool->GetSizeOfVector();
1232 for(size_t i = 0; i < nLCount; ++i)
1234 SfxListener* pListener = m_pBasePool->GetListener(i);
1235 SwXStyle* pTempStyle = dynamic_cast<SwXStyle*>(pListener);
1236 if(pTempStyle && pTempStyle->GetFamily() == m_rEntry.family() && pTempStyle->GetStyleName() == rStyleName)
1237 return pTempStyle;
1239 return nullptr;
1242 static SwGetPoolIdFromName lcl_GetSwEnumFromSfxEnum(SfxStyleFamily eFamily)
1244 auto& entries(lcl_GetStyleFamilyEntries());
1245 const auto pEntry = std::find_if(entries.begin(), entries.end(),
1246 [eFamily] (const StyleFamilyEntry& e) { return e.family() == eFamily; });
1247 if(pEntry != entries.end())
1248 return pEntry->poolId();
1249 SAL_WARN("sw.uno", "someone asking for all styles in unostyle.cxx!" );
1250 return SwGetPoolIdFromName::ChrFmt;
1253 const uno::Sequence<sal_Int8>& SwXStyle::getUnoTunnelId()
1255 static const comphelper::UnoIdInit theSwXStyleUnoTunnelId;
1256 return theSwXStyleUnoTunnelId.getSeq();
1259 sal_Int64 SAL_CALL SwXStyle::getSomething(const uno::Sequence<sal_Int8>& rId)
1261 return comphelper::getSomethingImpl(rId, this);
1265 uno::Sequence< OUString > SwXStyle::getSupportedServiceNames()
1267 tools::Long nCount = 1;
1268 if(SfxStyleFamily::Para == m_rEntry.family())
1270 nCount = 5;
1271 if(m_bIsConditional)
1272 nCount++;
1274 else if(SfxStyleFamily::Char == m_rEntry.family())
1275 nCount = 5;
1276 else if(SfxStyleFamily::Page == m_rEntry.family())
1277 nCount = 3;
1278 uno::Sequence< OUString > aRet(nCount);
1279 OUString* pArray = aRet.getArray();
1280 pArray[0] = "com.sun.star.style.Style";
1281 switch(m_rEntry.family())
1283 case SfxStyleFamily::Char:
1284 pArray[1] = "com.sun.star.style.CharacterStyle";
1285 pArray[2] = "com.sun.star.style.CharacterProperties";
1286 pArray[3] = "com.sun.star.style.CharacterPropertiesAsian";
1287 pArray[4] = "com.sun.star.style.CharacterPropertiesComplex";
1288 break;
1289 case SfxStyleFamily::Page:
1290 pArray[1] = "com.sun.star.style.PageStyle";
1291 pArray[2] = "com.sun.star.style.PageProperties";
1292 break;
1293 case SfxStyleFamily::Para:
1294 pArray[1] = "com.sun.star.style.ParagraphStyle";
1295 pArray[2] = "com.sun.star.style.ParagraphProperties";
1296 pArray[3] = "com.sun.star.style.ParagraphPropertiesAsian";
1297 pArray[4] = "com.sun.star.style.ParagraphPropertiesComplex";
1298 if(m_bIsConditional)
1299 pArray[5] = "com.sun.star.style.ConditionalParagraphStyle";
1300 break;
1302 default:
1305 return aRet;
1308 static uno::Reference<beans::XPropertySet> lcl_InitStandardStyle(const SfxStyleFamily eFamily, uno::Reference<container::XNameAccess> const & rxStyleFamily)
1310 using return_t = decltype(lcl_InitStandardStyle(eFamily, rxStyleFamily));
1311 if(eFamily != SfxStyleFamily::Para && eFamily != SfxStyleFamily::Page)
1312 return {};
1313 auto aResult(rxStyleFamily->getByName("Standard"));
1314 if(!aResult.has<return_t>())
1315 return {};
1316 return aResult.get<return_t>();
1319 static uno::Reference<container::XNameAccess> lcl_InitStyleFamily(SwDoc* pDoc, const StyleFamilyEntry& rEntry)
1321 using return_t = decltype(lcl_InitStyleFamily(pDoc, rEntry));
1322 if(rEntry.family() != SfxStyleFamily::Char
1323 && rEntry.family() != SfxStyleFamily::Para
1324 && rEntry.family() != SfxStyleFamily::Page)
1325 return {};
1326 auto xModel(pDoc->GetDocShell()->GetBaseModel());
1327 uno::Reference<style::XStyleFamiliesSupplier> xFamilySupplier(xModel, uno::UNO_QUERY);
1328 auto xFamilies = xFamilySupplier->getStyleFamilies();
1329 auto aResult(xFamilies->getByName(rEntry.name()));
1330 if(!aResult.has<return_t>())
1331 return {};
1332 return aResult.get<return_t>();
1335 static bool lcl_InitConditional(SfxStyleSheetBasePool* pBasePool, const SfxStyleFamily eFamily, const OUString& rStyleName)
1337 if(!pBasePool || eFamily != SfxStyleFamily::Para)
1338 return false;
1339 SfxStyleSheetBase* pBase = pBasePool->Find(rStyleName, eFamily);
1340 SAL_WARN_IF(!pBase, "sw.uno", "where is the style?" );
1341 if(!pBase)
1342 return false;
1343 const sal_uInt16 nId(SwStyleNameMapper::GetPoolIdFromUIName(rStyleName, SwGetPoolIdFromName::TxtColl));
1344 if(nId != USHRT_MAX)
1345 return ::IsConditionalByPoolId(nId);
1346 return RES_CONDTXTFMTCOLL == static_cast<SwDocStyleSheet*>(pBase)->GetCollection()->Which();
1349 static const StyleFamilyEntry& lcl_GetStyleEntry(const SfxStyleFamily eFamily)
1351 auto& entries = lcl_GetStyleFamilyEntries();
1352 const auto pEntry = std::find_if(entries.begin(), entries.end(),
1353 [eFamily] (const StyleFamilyEntry& e) { return e.family() == eFamily; });
1354 assert(pEntry != entries.end());
1355 return *pEntry;
1358 SwXStyle::SwXStyle(SwDoc* pDoc, SfxStyleFamily eFamily, bool bConditional)
1359 : m_pDoc(pDoc)
1360 , m_rEntry(lcl_GetStyleEntry(eFamily))
1361 , m_bIsDescriptor(true)
1362 , m_bIsConditional(bConditional)
1363 , m_pBasePool(nullptr)
1364 , m_xStyleFamily(lcl_InitStyleFamily(pDoc, m_rEntry))
1365 , m_xStyleData(lcl_InitStandardStyle(eFamily, m_xStyleFamily))
1367 assert(!m_bIsConditional || m_rEntry.family() == SfxStyleFamily::Para); // only paragraph styles are conditional
1368 // Register ourselves as a listener to the document (via the page descriptor)
1369 SvtListener::StartListening(pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier());
1370 m_pPropertiesImpl = std::make_unique<SwStyleProperties_Impl>(
1371 aSwMapProvider.GetPropertySet(m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.propMapType())->getPropertyMap());
1374 SwXStyle::SwXStyle(SfxStyleSheetBasePool* pPool, SfxStyleFamily eFamily, SwDoc* pDoc, const OUString& rStyleName)
1375 : m_pDoc(pDoc)
1376 , m_sStyleName(rStyleName)
1377 , m_rEntry(lcl_GetStyleEntry(eFamily))
1378 , m_bIsDescriptor(false)
1379 , m_bIsConditional(lcl_InitConditional(pPool, eFamily, rStyleName))
1380 , m_pBasePool(pPool)
1383 SwXStyle::~SwXStyle()
1385 SolarMutexGuard aGuard;
1386 if(m_pBasePool)
1387 SfxListener::EndListening(*m_pBasePool);
1388 m_pPropertiesImpl.reset();
1389 SvtListener::EndListeningAll();
1392 void SwXStyle::Notify(const SfxHint& rHint)
1394 if(rHint.GetId() == SfxHintId::Dying)
1396 m_pDoc = nullptr;
1397 m_xStyleData.clear();
1398 m_xStyleFamily.clear();
1402 OUString SwXStyle::getName()
1404 SolarMutexGuard aGuard;
1405 if(!m_pBasePool)
1406 return m_sStyleName;
1407 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName, m_rEntry.family());
1408 SAL_WARN_IF(!pBase, "sw.uno", "where is the style?");
1409 if(!pBase)
1410 throw uno::RuntimeException();
1411 OUString aString;
1412 SwStyleNameMapper::FillProgName(pBase->GetName(), aString, lcl_GetSwEnumFromSfxEnum ( m_rEntry.family()));
1413 return aString;
1416 void SwXStyle::setName(const OUString& rName)
1418 SolarMutexGuard aGuard;
1419 if(!m_pBasePool)
1421 m_sStyleName = rName;
1422 return;
1424 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName, m_rEntry.family());
1425 SAL_WARN_IF(!pBase, "sw.uno", "where is the style?");
1426 if(!pBase || !pBase->IsUserDefined())
1427 throw uno::RuntimeException();
1428 rtl::Reference<SwDocStyleSheet> xTmp(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
1429 if(!xTmp->SetName(rName))
1430 throw uno::RuntimeException();
1431 m_sStyleName = rName;
1434 sal_Bool SwXStyle::isUserDefined()
1436 SolarMutexGuard aGuard;
1437 if(!m_pBasePool)
1438 throw uno::RuntimeException();
1439 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName, m_rEntry.family());
1440 //if it is not found it must be non user defined
1441 return pBase && pBase->IsUserDefined();
1444 sal_Bool SwXStyle::isInUse()
1446 SolarMutexGuard aGuard;
1447 if(!m_pBasePool)
1448 throw uno::RuntimeException();
1449 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName, m_rEntry.family(), SfxStyleSearchBits::Used);
1450 return pBase && pBase->IsUsed();
1453 OUString SwXStyle::getParentStyle()
1455 SolarMutexGuard aGuard;
1456 if(!m_pBasePool)
1458 if(!m_bIsDescriptor)
1459 throw uno::RuntimeException();
1460 return m_sParentStyleName;
1462 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName, m_rEntry.family());
1463 OUString aString;
1464 if(pBase)
1465 aString = pBase->GetParent();
1466 SwStyleNameMapper::FillProgName(aString, aString, lcl_GetSwEnumFromSfxEnum(m_rEntry.family()));
1467 return aString;
1470 void SwXStyle::setParentStyle(const OUString& rParentStyle)
1472 SolarMutexGuard aGuard;
1473 OUString sParentStyle;
1474 SwStyleNameMapper::FillUIName(rParentStyle, sParentStyle, lcl_GetSwEnumFromSfxEnum ( m_rEntry.family()) );
1475 if(!m_pBasePool)
1477 if(!m_bIsDescriptor)
1478 throw uno::RuntimeException();
1479 m_sParentStyleName = sParentStyle;
1482 const auto aAny = m_xStyleFamily->getByName(sParentStyle);
1483 m_xStyleData = aAny.get<decltype(m_xStyleData)>();
1485 catch(...)
1487 return;
1489 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName, m_rEntry.family());
1490 if(!pBase)
1491 throw uno::RuntimeException();
1492 rtl::Reference<SwDocStyleSheet> xBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
1493 //make it a 'real' style - necessary for pooled styles
1494 xBase->GetItemSet();
1495 if(xBase->GetParent() != sParentStyle)
1497 if(!xBase->SetParent(sParentStyle))
1498 throw uno::RuntimeException();
1502 uno::Reference<beans::XPropertySetInfo> SwXStyle::getPropertySetInfo()
1504 if(m_bIsConditional)
1506 assert(m_rEntry.family() == SfxStyleFamily::Para);
1507 static auto xCondParaRef = aSwMapProvider.GetPropertySet(PROPERTY_MAP_CONDITIONAL_PARA_STYLE)->getPropertySetInfo();
1508 return xCondParaRef;
1510 return m_rEntry.xPSInfo();
1513 void SwXStyle::ApplyDescriptorProperties()
1515 m_bIsDescriptor = false;
1516 m_xStyleData.clear();
1517 m_xStyleFamily.clear();
1518 m_pPropertiesImpl->Apply(*this);
1521 namespace {
1522 const TranslateId STR_POOLPAGE_ARY[] =
1524 // Page styles
1525 STR_POOLPAGE_STANDARD,
1526 STR_POOLPAGE_FIRST,
1527 STR_POOLPAGE_LEFT,
1528 STR_POOLPAGE_RIGHT,
1529 STR_POOLPAGE_ENVELOPE,
1530 STR_POOLPAGE_REGISTER,
1531 STR_POOLPAGE_HTML,
1532 STR_POOLPAGE_FOOTNOTE,
1533 STR_POOLPAGE_ENDNOTE,
1534 STR_POOLPAGE_LANDSCAPE
1538 const SwPageDesc* SwStyleBase_Impl::GetOldPageDesc()
1540 if(!m_pOldPageDesc)
1542 SwPageDesc *pd = m_rDoc.FindPageDesc(m_rStyleName);
1543 if(pd)
1544 m_pOldPageDesc = pd;
1546 if(!m_pOldPageDesc)
1548 for (size_t i = 0; i < SAL_N_ELEMENTS(STR_POOLPAGE_ARY); ++i)
1550 if (SwResId(STR_POOLPAGE_ARY[i]) == m_rStyleName)
1552 m_pOldPageDesc = m_rDoc.getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_BEGIN + i);
1553 break;
1558 return m_pOldPageDesc;
1563 static sal_uInt8 lcl_TranslateMetric(const SfxItemPropertyMapEntry& rEntry, SwDoc* pDoc, uno::Any& o_aValue)
1565 // check for needed metric translation
1566 if(!(rEntry.nMoreFlags & PropertyMoreFlags::METRIC_ITEM))
1567 return rEntry.nMemberId;
1568 // exception: If these ItemTypes are used, do not convert when these are negative
1569 // since this means they are intended as percent values
1570 if((XATTR_FILLBMP_SIZEX == rEntry.nWID || XATTR_FILLBMP_SIZEY == rEntry.nWID)
1571 && o_aValue.has<sal_Int32>()
1572 && o_aValue.get<sal_Int32>() < 0)
1573 return rEntry.nMemberId;
1574 if(!pDoc)
1575 return rEntry.nMemberId;
1577 const SfxItemPool& rPool = pDoc->GetAttrPool();
1578 const MapUnit eMapUnit(rPool.GetMetric(rEntry.nWID));
1579 if(eMapUnit != MapUnit::Map100thMM)
1580 SvxUnoConvertFromMM(eMapUnit, o_aValue);
1581 return rEntry.nMemberId;
1583 template<>
1584 void SwXStyle::SetPropertyValue<HINT_BEGIN>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1586 // default ItemSet handling
1587 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet();
1588 SfxItemSet aSet(*rStyleSet.GetPool(), rEntry.nWID, rEntry.nWID);
1589 aSet.SetParent(&rStyleSet);
1590 rPropSet.setPropertyValue(rEntry, rValue, aSet);
1591 rStyleSet.Put(aSet);
1593 template<>
1594 void SwXStyle::SetPropertyValue<FN_UNO_HIDDEN>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1596 bool bHidden = false;
1597 if(rValue >>= bHidden)
1599 //make it a 'real' style - necessary for pooled styles
1600 o_rStyleBase.getNewBase()->GetItemSet();
1601 o_rStyleBase.getNewBase()->SetHidden(bHidden);
1603 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, rValue, o_rStyleBase);
1605 template<>
1606 void SwXStyle::SetPropertyValue<FN_UNO_STYLE_INTEROP_GRAB_BAG>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1608 o_rStyleBase.getNewBase()->GetItemSet();
1609 o_rStyleBase.getNewBase()->SetGrabBagItem(rValue);
1610 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, rValue, o_rStyleBase);
1612 template<>
1613 void SwXStyle::SetPropertyValue<sal_uInt16(XATTR_FILLGRADIENT)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1615 uno::Any aValue(rValue);
1616 const auto nMemberId(lcl_TranslateMetric(rEntry, m_pDoc, aValue));
1617 if(MID_NAME == nMemberId)
1619 // add set commands for FillName items
1620 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet();
1621 if(!aValue.has<OUString>())
1622 throw lang::IllegalArgumentException();
1623 SvxShape::SetFillAttribute(rEntry.nWID, aValue.get<OUString>(), rStyleSet);
1625 else if(MID_BITMAP == nMemberId)
1627 if(sal_uInt16(XATTR_FILLBITMAP) == rEntry.nWID)
1629 Graphic aNullGraphic;
1630 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet();
1631 XFillBitmapItem aXFillBitmapItem(std::move(aNullGraphic));
1632 aXFillBitmapItem.PutValue(aValue, nMemberId);
1633 rStyleSet.Put(aXFillBitmapItem);
1636 else
1637 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, aValue, o_rStyleBase);
1639 template<>
1640 void SwXStyle::SetPropertyValue<sal_uInt16(RES_BACKGROUND)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1642 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet();
1643 const std::unique_ptr<SvxBrushItem> aOriginalBrushItem(getSvxBrushItemFromSourceSet(rStyleSet, RES_BACKGROUND, true, m_pDoc->IsInXMLImport()));
1644 std::unique_ptr<SvxBrushItem> aChangedBrushItem(aOriginalBrushItem->Clone());
1646 uno::Any aValue(rValue);
1647 const auto nMemberId(lcl_TranslateMetric(rEntry, m_pDoc, aValue));
1648 aChangedBrushItem->PutValue(aValue, nMemberId);
1650 // 0xff is already the default - but if BackTransparent is set
1651 // to true, it must be applied in the item set on ODF import
1652 // to potentially override parent style, which is unknown yet
1653 if(*aChangedBrushItem == *aOriginalBrushItem && (MID_GRAPHIC_TRANSPARENT != nMemberId || !aValue.has<bool>() || !aValue.get<bool>()))
1654 return;
1656 setSvxBrushItemAsFillAttributesToTargetSet(*aChangedBrushItem, rStyleSet);
1658 template<>
1659 void SwXStyle::SetPropertyValue<OWN_ATTR_FILLBMP_MODE>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1661 drawing::BitmapMode eMode;
1662 if(!(rValue >>= eMode))
1664 if(!rValue.has<sal_Int32>())
1665 throw lang::IllegalArgumentException();
1666 eMode = static_cast<drawing::BitmapMode>(rValue.get<sal_Int32>());
1668 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet();
1669 rStyleSet.Put(XFillBmpStretchItem(drawing::BitmapMode_STRETCH == eMode));
1670 rStyleSet.Put(XFillBmpTileItem(drawing::BitmapMode_REPEAT == eMode));
1672 template<>
1673 void SwXStyle::SetPropertyValue<sal_uInt16(RES_PAPER_BIN)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1675 if(!rValue.has<OUString>())
1676 throw lang::IllegalArgumentException();
1677 SfxPrinter* pPrinter = m_pDoc->getIDocumentDeviceAccess().getPrinter(true);
1678 OUString sValue(rValue.get<OUString>());
1679 using printeridx_t = decltype(pPrinter->GetPaperBinCount());
1680 printeridx_t nBin = std::numeric_limits<printeridx_t>::max();
1681 if(sValue == "[From printer settings]")
1682 nBin = std::numeric_limits<printeridx_t>::max()-1;
1683 else if(pPrinter)
1685 for(sal_uInt16 i=0, nEnd = pPrinter->GetPaperBinCount(); i < nEnd; ++i)
1687 if (sValue == pPrinter->GetPaperBinName(i))
1689 nBin = i;
1690 break;
1694 if(nBin == std::numeric_limits<printeridx_t>::max())
1695 throw lang::IllegalArgumentException();
1696 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet();
1697 SfxItemSet aSet(*rStyleSet.GetPool(), rEntry.nWID, rEntry.nWID);
1698 aSet.SetParent(&rStyleSet);
1699 rPropSet.setPropertyValue(rEntry, uno::Any(static_cast<sal_Int8>(nBin == std::numeric_limits<printeridx_t>::max()-1 ? -1 : nBin)), aSet);
1700 rStyleSet.Put(aSet);
1702 template<>
1703 void SwXStyle::SetPropertyValue<FN_UNO_NUM_RULES>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1705 auto xNumberTunnel(rValue.get<uno::Reference<container::XIndexReplace>>());
1706 if(!xNumberTunnel)
1707 throw lang::IllegalArgumentException();
1708 SwXNumberingRules* pSwXRules = dynamic_cast<SwXNumberingRules*>(xNumberTunnel.get());
1709 if(!pSwXRules)
1710 return;
1711 SwNumRule aSetRule(*pSwXRules->GetNumRule());
1712 for(sal_uInt16 i = 0; i < MAXLEVEL; ++i)
1714 const SwNumFormat* pFormat = aSetRule.GetNumFormat(i);
1715 if(!pFormat)
1716 continue;
1717 SwNumFormat aFormat(*pFormat);
1718 const auto& rCharName(pSwXRules->GetNewCharStyleNames()[i]);
1719 if(!rCharName.isEmpty()
1720 && !SwXNumberingRules::isInvalidStyle(rCharName)
1721 && (!pFormat->GetCharFormat() || pFormat->GetCharFormat()->GetName() != rCharName))
1723 auto pCharFormatIt(std::find_if(m_pDoc->GetCharFormats()->begin(), m_pDoc->GetCharFormats()->end(),
1724 [&rCharName] (SwCharFormat* pF) { return pF->GetName() == rCharName; }));
1725 if(pCharFormatIt != m_pDoc->GetCharFormats()->end())
1726 aFormat.SetCharFormat(*pCharFormatIt);
1727 else if(m_pBasePool)
1729 auto pBase(m_pBasePool->Find(rCharName, SfxStyleFamily::Char));
1730 if(!pBase)
1731 pBase = &m_pBasePool->Make(rCharName, SfxStyleFamily::Char);
1732 aFormat.SetCharFormat(static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat());
1734 else
1735 aFormat.SetCharFormat(nullptr);
1737 // same for fonts:
1738 const auto& rBulletName(pSwXRules->GetBulletFontNames()[i]);
1739 if(!rBulletName.isEmpty()
1740 && !SwXNumberingRules::isInvalidStyle(rBulletName)
1741 && (!pFormat->GetBulletFont() || pFormat->GetBulletFont()->GetFamilyName() != rBulletName))
1743 const auto pFontListItem(static_cast<const SvxFontListItem*>(m_pDoc->GetDocShell()->GetItem(SID_ATTR_CHAR_FONTLIST)));
1744 const auto pList(pFontListItem->GetFontList());
1745 FontMetric aFontInfo(pList->Get(rBulletName, WEIGHT_NORMAL, ITALIC_NONE));
1746 vcl::Font aFont(aFontInfo);
1747 aFormat.SetBulletFont(&aFont);
1749 aSetRule.Set(i, &aFormat);
1751 o_rStyleBase.getNewBase()->SetNumRule(aSetRule);
1753 template<>
1754 void SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_OUTLINELEVEL)>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1756 if(!rValue.has<sal_Int16>())
1757 return;
1758 const auto nLevel(rValue.get<sal_Int16>());
1759 if(0 <= nLevel && nLevel <= MAXLEVEL)
1760 o_rStyleBase.getNewBase()->GetCollection()->SetAttrOutlineLevel(nLevel);
1762 template<>
1763 void SwXStyle::SetPropertyValue<FN_UNO_FOLLOW_STYLE>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1765 if(!rValue.has<OUString>())
1766 return;
1767 const auto sValue(rValue.get<OUString>());
1768 OUString aString;
1769 SwStyleNameMapper::FillUIName(sValue, aString, m_rEntry.poolId());
1770 o_rStyleBase.getNewBase()->SetFollow(aString);
1773 template <>
1774 void SwXStyle::SetPropertyValue<FN_UNO_LINK_STYLE>(const SfxItemPropertyMapEntry&,
1775 const SfxItemPropertySet&,
1776 const uno::Any& rValue,
1777 SwStyleBase_Impl& o_rStyleBase)
1779 if (!rValue.has<OUString>())
1780 return;
1781 const auto sValue(rValue.get<OUString>());
1782 OUString aString;
1783 SwStyleNameMapper::FillUIName(sValue, aString, m_rEntry.poolId());
1784 o_rStyleBase.getNewBase()->SetLink(aString);
1787 template<>
1788 void SwXStyle::SetPropertyValue<sal_uInt16(RES_PAGEDESC)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1790 if(MID_PAGEDESC_PAGEDESCNAME != rEntry.nMemberId)
1792 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, rValue, o_rStyleBase);
1793 return;
1795 if(!rValue.has<OUString>())
1796 throw lang::IllegalArgumentException();
1797 // special handling for RES_PAGEDESC
1798 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet();
1799 std::unique_ptr<SwFormatPageDesc> pNewDesc;
1800 if(const SwFormatPageDesc* pItem = rStyleSet.GetItemIfSet(RES_PAGEDESC))
1801 pNewDesc.reset(new SwFormatPageDesc(*pItem));
1802 else
1803 pNewDesc.reset(new SwFormatPageDesc);
1804 const auto sValue(rValue.get<OUString>());
1805 OUString sDescName;
1806 SwStyleNameMapper::FillUIName(sValue, sDescName, SwGetPoolIdFromName::PageDesc);
1807 if(pNewDesc->GetPageDesc() && pNewDesc->GetPageDesc()->GetName() == sDescName)
1808 return;
1809 if(sDescName.isEmpty())
1811 rStyleSet.ClearItem(RES_BREAK);
1812 rStyleSet.Put(SwFormatPageDesc());
1814 else
1816 SwPageDesc* pPageDesc(SwPageDesc::GetByName(*m_pDoc, sDescName));
1817 if(!pPageDesc)
1818 throw lang::IllegalArgumentException();
1819 pNewDesc->RegisterToPageDesc(*pPageDesc);
1820 rStyleSet.Put(std::move(pNewDesc));
1823 template<>
1824 void SwXStyle::SetPropertyValue<sal_uInt16(RES_TEXT_VERT_ADJUST)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1826 if(m_rEntry.family() != SfxStyleFamily::Page)
1828 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, rValue, o_rStyleBase);
1829 return;
1831 if(!m_pDoc || !rValue.has<drawing::TextVerticalAdjust>() || !o_rStyleBase.GetOldPageDesc())
1832 return;
1833 SwPageDesc* pPageDesc = m_pDoc->FindPageDesc(o_rStyleBase.GetOldPageDesc()->GetName());
1834 if(pPageDesc)
1835 pPageDesc->SetVerticalAdjustment(rValue.get<drawing::TextVerticalAdjust>());
1837 template<>
1838 void SwXStyle::SetPropertyValue<FN_UNO_IS_AUTO_UPDATE>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1840 if(!rValue.has<bool>())
1841 throw lang::IllegalArgumentException();
1842 const bool bAuto(rValue.get<bool>());
1843 if(SfxStyleFamily::Para == m_rEntry.family())
1844 o_rStyleBase.getNewBase()->GetCollection()->SetAutoUpdateOnDirectFormat(bAuto);
1845 else if(SfxStyleFamily::Frame == m_rEntry.family())
1846 o_rStyleBase.getNewBase()->GetFrameFormat()->SetAutoUpdateOnDirectFormat(bAuto);
1848 template<>
1849 void SwXStyle::SetPropertyValue<FN_UNO_PARA_STYLE_CONDITIONS>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1851 static_assert(COND_COMMAND_COUNT == 28, "invalid size of command count?");
1852 using expectedarg_t = uno::Sequence<beans::NamedValue>;
1853 if(!rValue.has<expectedarg_t>() || !m_pBasePool)
1854 throw lang::IllegalArgumentException();
1855 SwCondCollItem aCondItem;
1856 const auto aNamedValues = rValue.get<expectedarg_t>();
1857 for(const auto& rNamedValue : aNamedValues)
1859 if(!rNamedValue.Value.has<OUString>())
1860 throw lang::IllegalArgumentException();
1862 const OUString sValue(rNamedValue.Value.get<OUString>());
1863 // get UI style name from programmatic style name
1864 OUString aStyleName;
1865 SwStyleNameMapper::FillUIName(sValue, aStyleName, lcl_GetSwEnumFromSfxEnum(m_rEntry.family()));
1867 // check for correct context and style name
1868 const auto nIdx(GetCommandContextIndex(rNamedValue.Name));
1869 if (nIdx == -1)
1870 throw lang::IllegalArgumentException();
1871 bool bStyleFound = false;
1872 for(auto pBase = m_pBasePool->First(SfxStyleFamily::Para); pBase; pBase = m_pBasePool->Next())
1874 bStyleFound = pBase->GetName() == aStyleName;
1875 if (bStyleFound)
1876 break;
1878 if (!bStyleFound)
1879 throw lang::IllegalArgumentException();
1880 aCondItem.SetStyle(&aStyleName, nIdx);
1882 o_rStyleBase.GetItemSet().Put(aCondItem);
1884 template<>
1885 void SwXStyle::SetPropertyValue<FN_UNO_CATEGORY>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1887 if(!o_rStyleBase.getNewBase()->IsUserDefined() || !rValue.has<paragraphstyle_t>())
1888 throw lang::IllegalArgumentException();
1889 static const std::map<paragraphstyle_t, SfxStyleSearchBits> aUnoToCore = []{
1890 std::map<paragraphstyle_t, SfxStyleSearchBits> map;
1891 std::transform(std::begin(sParagraphStyleCategoryEntries), std::end(sParagraphStyleCategoryEntries), std::inserter(map, map.end()),
1892 [] (const ParagraphStyleCategoryEntry& rEntry) { return std::make_pair(rEntry.m_eCategory, rEntry.m_nSwStyleBits); });
1893 return map;
1894 }();
1895 const auto pUnoToCoreIt(aUnoToCore.find(rValue.get<paragraphstyle_t>()));
1896 if (pUnoToCoreIt == aUnoToCore.end())
1897 throw lang::IllegalArgumentException();
1898 o_rStyleBase.getNewBase()->SetMask( pUnoToCoreIt->second|SfxStyleSearchBits::UserDefined );
1900 template<>
1901 void SwXStyle::SetPropertyValue<SID_SWREGISTER_COLLECTION>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1903 OUString sName;
1904 rValue >>= sName;
1905 SwRegisterItem aReg(!sName.isEmpty());
1906 aReg.SetWhich(SID_SWREGISTER_MODE);
1907 o_rStyleBase.GetItemSet().Put(aReg);
1908 OUString aString;
1909 SwStyleNameMapper::FillUIName(sName, aString, SwGetPoolIdFromName::TxtColl);
1910 o_rStyleBase.GetItemSet().Put(SfxStringItem(SID_SWREGISTER_COLLECTION, aString ) );
1912 template<>
1913 void SwXStyle::SetPropertyValue<sal_uInt16(RES_TXTATR_CJK_RUBY)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1915 if(MID_RUBY_CHARSTYLE != rEntry.nMemberId)
1916 return;
1917 if(!rValue.has<OUString>())
1918 throw lang::IllegalArgumentException();
1919 const auto sValue(rValue.get<OUString>());
1920 SfxItemSet& rStyleSet(o_rStyleBase.GetItemSet());
1921 std::unique_ptr<SwFormatRuby> pRuby;
1922 if(const SwFormatRuby* pRubyItem = rStyleSet.GetItemIfSet(RES_TXTATR_CJK_RUBY))
1923 pRuby.reset(new SwFormatRuby(*pRubyItem));
1924 else
1925 pRuby.reset(new SwFormatRuby(OUString()));
1926 OUString sStyle;
1927 SwStyleNameMapper::FillUIName(sValue, sStyle, SwGetPoolIdFromName::ChrFmt);
1928 pRuby->SetCharFormatName(sValue);
1929 pRuby->SetCharFormatId(0);
1930 if(!sValue.isEmpty())
1932 const sal_uInt16 nId(SwStyleNameMapper::GetPoolIdFromUIName(sValue, SwGetPoolIdFromName::ChrFmt));
1933 pRuby->SetCharFormatId(nId);
1935 rStyleSet.Put(std::move(pRuby));
1936 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, rValue, o_rStyleBase);
1938 template<>
1939 void SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_DROP)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1941 if(MID_DROPCAP_CHAR_STYLE_NAME != rEntry.nMemberId)
1943 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, rValue, o_rStyleBase);
1944 return;
1946 if(!rValue.has<OUString>())
1947 throw lang::IllegalArgumentException();
1948 SfxItemSet& rStyleSet(o_rStyleBase.GetItemSet());
1949 std::unique_ptr<SwFormatDrop> pDrop;
1950 if(const SwFormatDrop* pDropItem = rStyleSet.GetItemIfSet(RES_PARATR_DROP))
1951 pDrop.reset(new SwFormatDrop(*pDropItem));
1952 else
1953 pDrop.reset(new SwFormatDrop);
1954 const auto sValue(rValue.get<OUString>());
1955 OUString sStyle;
1956 SwStyleNameMapper::FillUIName(sValue, sStyle, SwGetPoolIdFromName::ChrFmt);
1957 auto pStyle(static_cast<SwDocStyleSheet*>(m_pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle, SfxStyleFamily::Char)));
1958 //default character style must not be set as default format
1959 if(!pStyle || pStyle->GetCharFormat() == m_pDoc->GetDfltCharFormat() )
1961 throw lang::IllegalArgumentException();
1963 pDrop->SetCharFormat(pStyle->GetCharFormat());
1964 rStyleSet.Put(std::move(pDrop));
1966 template<>
1967 void SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_NUMRULE)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1969 uno::Any aValue(rValue);
1970 lcl_TranslateMetric(rEntry, m_pDoc, aValue);
1971 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, aValue, o_rStyleBase);
1972 // --> OD 2006-10-18 #i70223#
1973 if(SfxStyleFamily::Para == m_rEntry.family() &&
1974 o_rStyleBase.getNewBase().is() && o_rStyleBase.getNewBase()->GetCollection() &&
1975 //rBase.getNewBase()->GetCollection()->GetOutlineLevel() < MAXLEVEL /* assigned to list level of outline style */) //#outline level,removed by zhaojianwei
1976 o_rStyleBase.getNewBase()->GetCollection()->IsAssignedToListLevelOfOutlineStyle()) ////<-end,add by zhaojianwei
1978 OUString sNewNumberingRuleName;
1979 aValue >>= sNewNumberingRuleName;
1980 if(sNewNumberingRuleName.isEmpty() || sNewNumberingRuleName != m_pDoc->GetOutlineNumRule()->GetName())
1981 o_rStyleBase.getNewBase()->GetCollection()->DeleteAssignmentToListLevelOfOutlineStyle();
1985 void SwXStyle::SetStyleProperty(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase)
1987 using propertytype_t = decltype(rEntry.nWID);
1988 using coresetter_t = std::function<void(SwXStyle&, const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const uno::Any&, SwStyleBase_Impl&)>;
1989 static const std::map<propertytype_t, coresetter_t> aUnoToCore{
1990 // these explicit std::mem_fn() calls shouldn't be needed, but apparently MSVC is currently too stupid for C++11 again
1991 { FN_UNO_HIDDEN, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_HIDDEN>) },
1992 { FN_UNO_STYLE_INTEROP_GRAB_BAG, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_STYLE_INTEROP_GRAB_BAG>) },
1993 { XATTR_FILLGRADIENT, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(XATTR_FILLGRADIENT)>) },
1994 { XATTR_FILLHATCH, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(XATTR_FILLGRADIENT)>) },
1995 { XATTR_FILLBITMAP, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(XATTR_FILLGRADIENT)>) },
1996 { XATTR_FILLFLOATTRANSPARENCE, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(XATTR_FILLGRADIENT)>) },
1997 { RES_BACKGROUND, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_BACKGROUND)>) },
1998 { OWN_ATTR_FILLBMP_MODE, std::mem_fn(&SwXStyle::SetPropertyValue<OWN_ATTR_FILLBMP_MODE>) },
1999 { RES_PAPER_BIN, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_PAPER_BIN)>) },
2000 { FN_UNO_NUM_RULES, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_NUM_RULES>) },
2001 { RES_PARATR_OUTLINELEVEL, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_OUTLINELEVEL)>) },
2002 { FN_UNO_FOLLOW_STYLE, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_FOLLOW_STYLE>) },
2003 { FN_UNO_LINK_STYLE, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_LINK_STYLE>) },
2004 { RES_PAGEDESC, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_PAGEDESC)>) },
2005 { RES_TEXT_VERT_ADJUST, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_TEXT_VERT_ADJUST)>) },
2006 { FN_UNO_IS_AUTO_UPDATE, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_IS_AUTO_UPDATE>) },
2007 { FN_UNO_PARA_STYLE_CONDITIONS, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_PARA_STYLE_CONDITIONS>) },
2008 { FN_UNO_CATEGORY, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_CATEGORY>) },
2009 { SID_SWREGISTER_COLLECTION, std::mem_fn(&SwXStyle::SetPropertyValue<SID_SWREGISTER_COLLECTION>) },
2010 { RES_TXTATR_CJK_RUBY, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_TXTATR_CJK_RUBY)>) },
2011 { RES_PARATR_DROP, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_DROP)>) },
2012 { RES_PARATR_NUMRULE, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_NUMRULE)>) }
2014 const auto pUnoToCoreIt(aUnoToCore.find(rEntry.nWID));
2015 if(pUnoToCoreIt != aUnoToCore.end())
2016 pUnoToCoreIt->second(*this, rEntry, rPropSet, rValue, rBase);
2017 else
2019 // adapted switch logic to a more readable state; removed goto's and made
2020 // execution of standard setting of property in ItemSet dependent of this variable
2021 uno::Any aValue(rValue);
2022 lcl_TranslateMetric(rEntry, m_pDoc, aValue);
2023 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, aValue, rBase);
2027 void SwXStyle::SetPropertyValues_Impl(const uno::Sequence<OUString>& rPropertyNames, const uno::Sequence<uno::Any>& rValues)
2029 if(!m_pDoc)
2030 throw uno::RuntimeException();
2031 sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.propMapType();
2032 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
2033 const SfxItemPropertyMap &rMap = pPropSet->getPropertyMap();
2034 if(rPropertyNames.getLength() != rValues.getLength())
2035 throw lang::IllegalArgumentException();
2037 SwStyleBase_Impl aBaseImpl(*m_pDoc, m_sStyleName, &GetDoc()->GetDfltTextFormatColl()->GetAttrSet()); // add pDfltTextFormatColl as parent
2038 if(m_pBasePool)
2040 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName, m_rEntry.family());
2041 SAL_WARN_IF(!pBase, "sw.uno", "where is the style?");
2042 if(!pBase)
2043 throw uno::RuntimeException();
2044 aBaseImpl.setNewBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2046 if(!aBaseImpl.getNewBase().is() && !m_bIsDescriptor)
2047 throw uno::RuntimeException();
2049 const OUString* pNames = rPropertyNames.getConstArray();
2050 const uno::Any* pValues = rValues.getConstArray();
2051 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp)
2053 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(pNames[nProp]);
2054 if(!pEntry || (!m_bIsConditional && pNames[nProp] == UNO_NAME_PARA_STYLE_CONDITIONS))
2055 throw beans::UnknownPropertyException("Unknown property: " + pNames[nProp], static_cast<cppu::OWeakObject*>(this));
2056 if(pEntry->nFlags & beans::PropertyAttribute::READONLY)
2057 throw beans::PropertyVetoException ("Property is read-only: " + pNames[nProp], static_cast<cppu::OWeakObject*>(this));
2058 if(aBaseImpl.getNewBase().is())
2059 SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl);
2060 else if(!m_pPropertiesImpl->SetProperty(pNames[nProp], pValues[nProp]))
2061 throw lang::IllegalArgumentException();
2064 if(aBaseImpl.HasItemSet())
2065 aBaseImpl.getNewBase()->SetItemSet(aBaseImpl.GetItemSet());
2068 void SwXStyle::setPropertyValues(const uno::Sequence<OUString>& rPropertyNames, const uno::Sequence<uno::Any>& rValues)
2070 SolarMutexGuard aGuard;
2071 // workaround for bad designed API
2074 SetPropertyValues_Impl( rPropertyNames, rValues );
2076 catch (const beans::UnknownPropertyException &rException)
2078 // wrap the original (here not allowed) exception in
2079 // a lang::WrappedTargetException that gets thrown instead.
2080 lang::WrappedTargetException aWExc;
2081 aWExc.TargetException <<= rException;
2082 throw aWExc;
2086 SfxStyleSheetBase* SwXStyle::GetStyleSheetBase()
2088 if(!m_pBasePool)
2089 return nullptr;
2090 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName, m_rEntry.family());
2091 return pBase;
2093 void SwXStyle::PrepareStyleBase(SwStyleBase_Impl& rBase)
2095 SfxStyleSheetBase* pBase(GetStyleSheetBase());
2096 if(!pBase)
2097 throw uno::RuntimeException();
2098 if(!rBase.getNewBase().is())
2099 rBase.setNewBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2102 template<>
2103 uno::Any SwXStyle::GetStyleProperty<HINT_BEGIN>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase);
2104 template<>
2105 uno::Any SwXStyle::GetStyleProperty<FN_UNO_IS_PHYSICAL>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl&)
2107 SfxStyleSheetBase* pBase(GetStyleSheetBase());
2108 if(!pBase)
2109 return uno::Any(false);
2110 bool bPhys = static_cast<SwDocStyleSheet*>(pBase)->IsPhysical();
2111 // The standard character format is not existing physically
2112 if( bPhys && SfxStyleFamily::Char == GetFamily() &&
2113 static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat() &&
2114 static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat()->IsDefault() )
2115 bPhys = false;
2116 return uno::Any(bool(bPhys));
2118 template<>
2119 uno::Any SwXStyle::GetStyleProperty<FN_UNO_HIDDEN>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl&)
2121 SfxStyleSheetBase* pBase(GetStyleSheetBase());
2122 if(!pBase)
2123 return uno::Any(false);
2124 rtl::Reference<SwDocStyleSheet> xBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2125 return uno::Any(xBase->IsHidden());
2127 template<>
2128 uno::Any SwXStyle::GetStyleProperty<FN_UNO_STYLE_INTEROP_GRAB_BAG>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl&)
2130 SfxStyleSheetBase* pBase(GetStyleSheetBase());
2131 if(!pBase)
2132 return uno::Any();
2133 uno::Any aRet;
2134 rtl::Reference<SwDocStyleSheet> xBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2135 xBase->GetGrabBagItem(aRet);
2136 return aRet;
2138 template<>
2139 uno::Any SwXStyle::GetStyleProperty<sal_uInt16(RES_PAPER_BIN)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase)
2141 PrepareStyleBase(rBase);
2142 SfxItemSet& rSet = rBase.GetItemSet();
2143 uno::Any aValue;
2144 rPropSet.getPropertyValue(rEntry, rSet, aValue);
2145 sal_Int8 nBin(aValue.get<sal_Int8>());
2146 if(nBin == -1)
2147 return uno::Any(OUString("[From printer settings]"));
2148 SfxPrinter* pPrinter = GetDoc()->getIDocumentDeviceAccess().getPrinter(false);
2149 if(!pPrinter)
2150 return uno::Any();
2151 return uno::Any(pPrinter->GetPaperBinName(nBin));
2153 template<>
2154 uno::Any SwXStyle::GetStyleProperty<FN_UNO_NUM_RULES>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2156 PrepareStyleBase(rBase);
2157 const SwNumRule* pRule = rBase.getNewBase()->GetNumRule();
2158 assert(pRule && "Where is the NumRule?");
2159 uno::Reference<container::XIndexReplace> xRules(new SwXNumberingRules(*pRule, GetDoc()));
2160 return uno::Any(xRules);
2162 template<>
2163 uno::Any SwXStyle::GetStyleProperty<sal_uInt16(RES_PARATR_OUTLINELEVEL)>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2165 PrepareStyleBase(rBase);
2166 SAL_WARN_IF(SfxStyleFamily::Para != GetFamily(), "sw.uno", "only paras");
2167 return uno::Any(sal_Int16(rBase.getNewBase()->GetCollection()->GetAttrOutlineLevel()));
2169 template<>
2170 uno::Any SwXStyle::GetStyleProperty<FN_UNO_FOLLOW_STYLE>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2172 PrepareStyleBase(rBase);
2173 OUString aString;
2174 SwStyleNameMapper::FillProgName(rBase.getNewBase()->GetFollow(), aString, lcl_GetSwEnumFromSfxEnum(GetFamily()));
2175 return uno::Any(aString);
2178 template <>
2179 uno::Any SwXStyle::GetStyleProperty<FN_UNO_LINK_STYLE>(const SfxItemPropertyMapEntry&,
2180 const SfxItemPropertySet&,
2181 SwStyleBase_Impl& rBase)
2183 PrepareStyleBase(rBase);
2184 OUString aString;
2185 SwStyleNameMapper::FillProgName(rBase.getNewBase()->GetLink(), aString,
2186 lcl_GetSwEnumFromSfxEnum(GetFamily()));
2187 return uno::Any(aString);
2190 template<>
2191 uno::Any SwXStyle::GetStyleProperty<sal_uInt16(RES_PAGEDESC)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase)
2193 PrepareStyleBase(rBase);
2194 if(MID_PAGEDESC_PAGEDESCNAME != rEntry.nMemberId)
2195 return GetStyleProperty<HINT_BEGIN>(rEntry, rPropSet, rBase);
2196 // special handling for RES_PAGEDESC
2197 const SwFormatPageDesc* pItem =
2198 rBase.GetItemSet().GetItemIfSet(RES_PAGEDESC);
2199 if(!pItem)
2200 return uno::Any();
2201 const SwPageDesc* pDesc = pItem->GetPageDesc();
2202 if(!pDesc)
2203 return uno::Any();
2204 OUString aString;
2205 SwStyleNameMapper::FillProgName(pDesc->GetName(), aString, SwGetPoolIdFromName::PageDesc);
2206 return uno::Any(aString);
2208 template<>
2209 uno::Any SwXStyle::GetStyleProperty<FN_UNO_IS_AUTO_UPDATE>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2211 PrepareStyleBase(rBase);
2212 switch(GetFamily())
2214 case SfxStyleFamily::Para : return uno::Any(rBase.getNewBase()->GetCollection()->IsAutoUpdateOnDirectFormat());
2215 case SfxStyleFamily::Frame: return uno::Any(rBase.getNewBase()->GetFrameFormat()->IsAutoUpdateOnDirectFormat());
2216 default: return uno::Any();
2219 template<>
2220 uno::Any SwXStyle::GetStyleProperty<FN_UNO_DISPLAY_NAME>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2222 PrepareStyleBase(rBase);
2223 return uno::Any(rBase.getNewBase()->GetName());
2225 template<>
2226 uno::Any SwXStyle::GetStyleProperty<FN_UNO_PARA_STYLE_CONDITIONS>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2228 PrepareStyleBase(rBase);
2229 static_assert(COND_COMMAND_COUNT == 28, "invalid size of command count?");
2230 uno::Sequence<beans::NamedValue> aSeq(COND_COMMAND_COUNT);
2231 sal_uInt16 nIndex = 0;
2232 for(auto& rNV : asNonConstRange(aSeq))
2234 rNV.Name = GetCommandContextByIndex(nIndex++);
2235 rNV.Value <<= OUString();
2237 SwFormat* pFormat = static_cast<SwDocStyleSheet*>(GetStyleSheetBase())->GetCollection();
2238 if(pFormat && RES_CONDTXTFMTCOLL == pFormat->Which())
2240 const CommandStruct* pCmds = SwCondCollItem::GetCmds();
2241 beans::NamedValue* pSeq = aSeq.getArray();
2242 for(sal_uInt16 n = 0; n < COND_COMMAND_COUNT; ++n)
2244 const SwCollCondition* pCond = static_cast<SwConditionTextFormatColl*>(pFormat)->HasCondition(SwCollCondition(nullptr, pCmds[n].nCnd, pCmds[n].nSubCond));
2245 if(!pCond || !pCond->GetTextFormatColl())
2246 continue;
2247 // get programmatic style name from UI style name
2248 OUString aStyleName = pCond->GetTextFormatColl()->GetName();
2249 SwStyleNameMapper::FillProgName(aStyleName, aStyleName, lcl_GetSwEnumFromSfxEnum(GetFamily()));
2250 pSeq[n].Value <<= aStyleName;
2253 return uno::Any(aSeq);
2255 template<>
2256 uno::Any SwXStyle::GetStyleProperty<FN_UNO_CATEGORY>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2258 PrepareStyleBase(rBase);
2259 static const std::map<collectionbits_t, paragraphstyle_t> aUnoToCore = []{
2260 std::map<collectionbits_t, paragraphstyle_t> map;
2261 std::transform(std::begin(sParagraphStyleCategoryEntries), std::end(sParagraphStyleCategoryEntries), std::inserter(map, map.end()),
2262 [] (const ParagraphStyleCategoryEntry& rEntry) { return std::make_pair(rEntry.m_nCollectionBits, rEntry.m_eCategory); });
2263 return map;
2264 }();
2265 const sal_uInt16 nPoolId = rBase.getNewBase()->GetCollection()->GetPoolFormatId();
2266 const auto pUnoToCoreIt(aUnoToCore.find(COLL_GET_RANGE_BITS & nPoolId));
2267 if(pUnoToCoreIt == aUnoToCore.end())
2268 return uno::Any(sal_Int16(-1));
2269 return uno::Any(pUnoToCoreIt->second);
2271 template<>
2272 uno::Any SwXStyle::GetStyleProperty<SID_SWREGISTER_COLLECTION>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2274 PrepareStyleBase(rBase);
2275 const SwPageDesc *pPageDesc = rBase.getNewBase()->GetPageDesc();
2276 if(!pPageDesc)
2277 return uno::Any(OUString());
2278 const SwTextFormatColl* pCol = pPageDesc->GetRegisterFormatColl();
2279 if(!pCol)
2280 return uno::Any(OUString());
2281 OUString aName;
2282 SwStyleNameMapper::FillProgName(pCol->GetName(), aName, SwGetPoolIdFromName::TxtColl);
2283 return uno::Any(aName);
2285 template<>
2286 uno::Any SwXStyle::GetStyleProperty<sal_uInt16(RES_BACKGROUND)>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2288 PrepareStyleBase(rBase);
2289 const SfxItemSet& rSet = rBase.GetItemSet();
2290 const std::unique_ptr<SvxBrushItem> aOriginalBrushItem(getSvxBrushItemFromSourceSet(rSet, RES_BACKGROUND));
2291 uno::Any aResult;
2292 if(!aOriginalBrushItem->QueryValue(aResult, rEntry.nMemberId))
2293 SAL_WARN("sw.uno", "error getting attribute from RES_BACKGROUND.");
2294 return aResult;
2296 template<>
2297 uno::Any SwXStyle::GetStyleProperty<OWN_ATTR_FILLBMP_MODE>(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2299 PrepareStyleBase(rBase);
2300 const SfxItemSet& rSet = rBase.GetItemSet();
2301 if (rSet.Get(XATTR_FILLBMP_TILE).GetValue())
2302 return uno::Any(drawing::BitmapMode_REPEAT);
2303 if (rSet.Get(XATTR_FILLBMP_STRETCH).GetValue())
2304 return uno::Any(drawing::BitmapMode_STRETCH);
2305 return uno::Any(drawing::BitmapMode_NO_REPEAT);
2307 template<>
2308 uno::Any SwXStyle::GetStyleProperty<HINT_BEGIN>(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase)
2310 PrepareStyleBase(rBase);
2311 SfxItemSet& rSet = rBase.GetItemSet();
2312 uno::Any aResult;
2313 rPropSet.getPropertyValue(rEntry, rSet, aResult);
2315 // since the sfx uint16 item now exports a sal_Int32, we may have to fix this here
2316 if(rEntry.aType == cppu::UnoType<sal_Int16>::get() && aResult.getValueType() == cppu::UnoType<sal_Int32>::get())
2317 aResult <<= static_cast<sal_Int16>(aResult.get<sal_Int32>());
2318 // check for needed metric translation
2319 if(rEntry.nMoreFlags & PropertyMoreFlags::METRIC_ITEM && GetDoc())
2321 const SfxItemPool& rPool = GetDoc()->GetAttrPool();
2322 const MapUnit eMapUnit(rPool.GetMetric(rEntry.nWID));
2323 bool bAllowedConvert(true);
2324 // exception: If these ItemTypes are used, do not convert when these are negative
2325 // since this means they are intended as percent values
2326 if(XATTR_FILLBMP_SIZEX == rEntry.nWID || XATTR_FILLBMP_SIZEY == rEntry.nWID)
2327 bAllowedConvert = !aResult.has<sal_Int32>() || aResult.get<sal_Int32>() > 0;
2328 if(eMapUnit != MapUnit::Map100thMM && bAllowedConvert)
2329 SvxUnoConvertToMM(eMapUnit, aResult);
2331 return aResult;
2334 uno::Any SwXStyle::GetStyleProperty_Impl(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase)
2336 using propertytype_t = decltype(rEntry.nWID);
2337 using coresetter_t = std::function<uno::Any(SwXStyle&, const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, SwStyleBase_Impl&)>;
2338 static const std::map<propertytype_t, coresetter_t> aUnoToCore{
2339 // these explicit std::mem_fn() calls shouldn't be needed, but apparently MSVC is currently too stupid for C++11 again
2340 { FN_UNO_IS_PHYSICAL, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_IS_PHYSICAL>) },
2341 { FN_UNO_HIDDEN, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_HIDDEN>) },
2342 { FN_UNO_STYLE_INTEROP_GRAB_BAG, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_STYLE_INTEROP_GRAB_BAG>) },
2343 { RES_PAPER_BIN, std::mem_fn(&SwXStyle::GetStyleProperty<sal_uInt16(RES_PAPER_BIN)>) },
2344 { FN_UNO_NUM_RULES, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_NUM_RULES>) },
2345 { RES_PARATR_OUTLINELEVEL, std::mem_fn(&SwXStyle::GetStyleProperty<sal_uInt16(RES_PARATR_OUTLINELEVEL)>) },
2346 { FN_UNO_FOLLOW_STYLE, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_FOLLOW_STYLE>) },
2347 { FN_UNO_LINK_STYLE, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_LINK_STYLE>) },
2348 { RES_PAGEDESC, std::mem_fn(&SwXStyle::GetStyleProperty<sal_uInt16(RES_PAGEDESC)>) },
2349 { FN_UNO_IS_AUTO_UPDATE, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_IS_AUTO_UPDATE>) },
2350 { FN_UNO_DISPLAY_NAME, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_DISPLAY_NAME>) },
2351 { FN_UNO_PARA_STYLE_CONDITIONS, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_PARA_STYLE_CONDITIONS>) },
2352 { FN_UNO_CATEGORY, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_CATEGORY>) },
2353 { SID_SWREGISTER_COLLECTION, std::mem_fn(&SwXStyle::GetStyleProperty<SID_SWREGISTER_COLLECTION>) },
2354 { RES_BACKGROUND, std::mem_fn(&SwXStyle::GetStyleProperty<sal_uInt16(RES_BACKGROUND)>) },
2355 { OWN_ATTR_FILLBMP_MODE, std::mem_fn(&SwXStyle::GetStyleProperty<OWN_ATTR_FILLBMP_MODE>) }
2357 const auto pUnoToCoreIt(aUnoToCore.find(rEntry.nWID));
2358 if(pUnoToCoreIt != aUnoToCore.end())
2359 return pUnoToCoreIt->second(*this, rEntry, rPropSet, rBase);
2360 return GetStyleProperty<HINT_BEGIN>(rEntry, rPropSet, rBase);
2363 uno::Any SwXStyle::GetPropertyValue_Impl(const SfxItemPropertySet* pPropSet, SwStyleBase_Impl& rBase, const OUString& rPropertyName)
2365 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
2366 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(rPropertyName);
2367 if(!pEntry || (!m_bIsConditional && rPropertyName == UNO_NAME_PARA_STYLE_CONDITIONS))
2368 throw beans::UnknownPropertyException("Unknown property: " + rPropertyName, static_cast<cppu::OWeakObject*>(this));
2369 if(m_pBasePool)
2370 return GetStyleProperty_Impl(*pEntry, *pPropSet, rBase);
2371 const uno::Any* pAny = nullptr;
2372 m_pPropertiesImpl->GetProperty(rPropertyName, pAny);
2373 if(pAny->hasValue())
2374 return *pAny;
2375 uno::Any aValue;
2376 switch(m_rEntry.family())
2378 case SfxStyleFamily::Pseudo:
2379 throw uno::RuntimeException("No default value for: " + rPropertyName);
2380 break;
2381 case SfxStyleFamily::Para:
2382 case SfxStyleFamily::Page:
2383 aValue = m_xStyleData->getPropertyValue(rPropertyName);
2384 break;
2385 case SfxStyleFamily::Char:
2386 case SfxStyleFamily::Frame:
2388 if(pEntry->nWID < POOLATTR_BEGIN || pEntry->nWID >= RES_UNKNOWNATR_END)
2389 throw uno::RuntimeException("No default value for: " + rPropertyName);
2390 SwFormat* pFormat;
2391 if(m_rEntry.family() == SfxStyleFamily::Char)
2392 pFormat = m_pDoc->GetDfltCharFormat();
2393 else
2394 pFormat = m_pDoc->GetDfltFrameFormat();
2395 const SwAttrPool* pPool = pFormat->GetAttrSet().GetPool();
2396 const SfxPoolItem& rItem = pPool->GetDefaultItem(pEntry->nWID);
2397 rItem.QueryValue(aValue, pEntry->nMemberId);
2399 break;
2400 default:
2403 return aValue;
2406 uno::Any SwXStyle::getPropertyValue(const OUString& rPropertyName)
2408 SolarMutexGuard aGuard;
2409 if(!m_pDoc)
2410 throw uno::RuntimeException();
2411 if(!m_pBasePool && !m_bIsDescriptor)
2412 throw uno::RuntimeException();
2413 sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.propMapType();
2414 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
2415 SwStyleBase_Impl aBase(*m_pDoc, m_sStyleName, &m_pDoc->GetDfltTextFormatColl()->GetAttrSet()); // add pDfltTextFormatColl as parent
2416 return GetPropertyValue_Impl(pPropSet, aBase, rPropertyName);
2419 uno::Sequence<uno::Any> SwXStyle::getPropertyValues(const uno::Sequence<OUString>& rPropertyNames)
2421 SolarMutexGuard aGuard;
2422 if(!m_pDoc)
2423 throw uno::RuntimeException();
2424 if(!m_pBasePool && !m_bIsDescriptor)
2425 throw uno::RuntimeException();
2426 sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.propMapType();
2427 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
2428 SwStyleBase_Impl aBase(*m_pDoc, m_sStyleName, &m_pDoc->GetDfltTextFormatColl()->GetAttrSet()); // add pDfltTextFormatColl as parent
2429 uno::Sequence<uno::Any> aValues(rPropertyNames.getLength());
2430 auto aValuesRange = asNonConstRange(aValues);
2431 // workaround for bad designed API
2434 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp)
2435 aValuesRange[nProp] = GetPropertyValue_Impl(pPropSet, aBase, rPropertyNames[nProp]);
2437 catch(beans::UnknownPropertyException&)
2439 css::uno::Any anyEx = cppu::getCaughtException();
2440 throw css::lang::WrappedTargetRuntimeException("Unknown property exception caught",
2441 static_cast < cppu::OWeakObject * > ( this ), anyEx );
2443 catch(lang::WrappedTargetException&)
2445 css::uno::Any anyEx = cppu::getCaughtException();
2446 throw lang::WrappedTargetRuntimeException("WrappedTargetException caught",
2447 static_cast < cppu::OWeakObject * > ( this ), anyEx );
2449 return aValues;
2452 void SwXStyle::setPropertyValue(const OUString& rPropertyName, const uno::Any& rValue)
2454 SolarMutexGuard aGuard;
2455 const uno::Sequence<OUString> aProperties(&rPropertyName, 1);
2456 const uno::Sequence<uno::Any> aValues(&rValue, 1);
2457 SetPropertyValues_Impl(aProperties, aValues);
2460 beans::PropertyState SwXStyle::getPropertyState(const OUString& rPropertyName)
2462 SolarMutexGuard aGuard;
2463 uno::Sequence<OUString> aNames{rPropertyName};
2464 uno::Sequence<beans::PropertyState> aStates = getPropertyStates(aNames);
2465 return aStates.getConstArray()[0];
2468 // allow to retarget the SfxItemSet working on, default correctly. Only
2469 // use pSourceSet below this point (except in header/footer processing)
2470 static const SfxItemSet* lcl_GetItemsetForProperty(const SfxItemSet& rSet, SfxStyleFamily eFamily, std::u16string_view rPropertyName)
2472 if(eFamily != SfxStyleFamily::Page)
2473 return &rSet;
2474 const bool isFooter = o3tl::starts_with(rPropertyName, u"Footer");
2475 if(!isFooter && !o3tl::starts_with(rPropertyName, u"Header") && rPropertyName != UNO_NAME_FIRST_IS_SHARED)
2476 return &rSet;
2477 const SvxSetItem* pSetItem;
2478 if(!lcl_GetHeaderFooterItem(rSet, rPropertyName, isFooter, pSetItem))
2479 return nullptr;
2480 return &pSetItem->GetItemSet();
2482 uno::Sequence<beans::PropertyState> SwXStyle::getPropertyStates(const uno::Sequence<OUString>& rPropertyNames)
2484 SolarMutexGuard aGuard;
2485 uno::Sequence<beans::PropertyState> aRet(rPropertyNames.getLength());
2486 beans::PropertyState* pStates = aRet.getArray();
2488 if(!m_pBasePool)
2489 throw uno::RuntimeException();
2490 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName, m_rEntry.family());
2492 SAL_WARN_IF(!pBase, "sw.uno", "where is the style?");
2493 if(!pBase)
2494 throw uno::RuntimeException();
2496 const OUString* pNames = rPropertyNames.getConstArray();
2497 rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2498 sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.propMapType();
2500 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
2501 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
2502 const SfxItemSet& rSet = xStyle->GetItemSet();
2504 for(sal_Int32 i = 0; i < rPropertyNames.getLength(); ++i)
2506 const OUString sPropName = pNames[i];
2507 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(sPropName);
2509 if(!pEntry)
2510 throw beans::UnknownPropertyException("Unknown property: " + sPropName, static_cast<cppu::OWeakObject*>(this));
2512 if (FN_UNO_NUM_RULES == pEntry->nWID || FN_UNO_FOLLOW_STYLE == pEntry->nWID
2513 || pEntry->nWID == FN_UNO_LINK_STYLE)
2515 // handle NumRules first, done
2516 pStates[i] = beans::PropertyState_DIRECT_VALUE;
2517 continue;
2519 const SfxItemSet* pSourceSet = lcl_GetItemsetForProperty(rSet, m_rEntry.family(), sPropName);
2520 if(!pSourceSet)
2522 // if no SetItem, value is ambiguous and we are done
2523 pStates[i] = beans::PropertyState_AMBIGUOUS_VALUE;
2524 continue;
2526 switch(pEntry->nWID)
2528 case OWN_ATTR_FILLBMP_MODE:
2530 if(SfxItemState::SET == pSourceSet->GetItemState(XATTR_FILLBMP_STRETCH, false)
2531 || SfxItemState::SET == pSourceSet->GetItemState(XATTR_FILLBMP_TILE, false))
2533 pStates[i] = beans::PropertyState_DIRECT_VALUE;
2535 else
2537 pStates[i] = beans::PropertyState_AMBIGUOUS_VALUE;
2540 break;
2541 case XATTR_FILLSTYLE:
2543 if (m_rEntry.family() == SfxStyleFamily::Frame
2544 && xStyle->GetFrameFormat()->DerivedFrom() == GetDoc()->GetDfltFrameFormat())
2545 { // tdf#156155 mpDfltFrameFormat is the parent, but because
2546 // it IsDefault() it is not enumerated/exported as a style
2547 // to ODF, so export its one important value here.
2548 pStates[i] = beans::PropertyState_DIRECT_VALUE;
2550 else
2552 pStates[i] = pPropSet->getPropertyState(*pEntry, *pSourceSet);
2555 break;
2556 case RES_BACKGROUND:
2558 // for FlyFrames we need to mark the used properties from type RES_BACKGROUND
2559 // as beans::PropertyState_DIRECT_VALUE to let users of this property call
2560 // getPropertyValue where the member properties will be mapped from the
2561 // fill attributes to the according SvxBrushItem entries
2562 if (SWUnoHelper::needToMapFillItemsToSvxBrushItemTypes(*pSourceSet, pEntry->nMemberId))
2564 pStates[i] = beans::PropertyState_DIRECT_VALUE;
2566 else
2568 pStates[i] = beans::PropertyState_DEFAULT_VALUE;
2571 break;
2572 default:
2574 pStates[i] = pPropSet->getPropertyState(*pEntry, *pSourceSet);
2576 if(SfxStyleFamily::Page == m_rEntry.family() && SID_ATTR_PAGE_SIZE == pEntry->nWID && beans::PropertyState_DIRECT_VALUE == pStates[i])
2578 const SvxSizeItem& rSize = rSet.Get(SID_ATTR_PAGE_SIZE);
2579 sal_uInt8 nMemberId = pEntry->nMemberId & 0x7f;
2581 if((LONG_MAX == rSize.GetSize().Width() && (MID_SIZE_WIDTH == nMemberId || MID_SIZE_SIZE == nMemberId)) ||
2582 (LONG_MAX == rSize.GetSize().Height() && MID_SIZE_HEIGHT == nMemberId))
2584 pStates[i] = beans::PropertyState_DEFAULT_VALUE;
2590 return aRet;
2593 void SwXStyle::setPropertyToDefault(const OUString& rPropertyName)
2595 const uno::Sequence<OUString> aSequence(&rPropertyName, 1);
2596 setPropertiesToDefault(aSequence);
2599 static SwFormat* lcl_GetFormatForStyle(SwDoc const * pDoc, const rtl::Reference<SwDocStyleSheet>& xStyle, const SfxStyleFamily eFamily)
2601 if(!xStyle.is())
2602 return nullptr;
2603 switch(eFamily)
2605 case SfxStyleFamily::Char: return xStyle->GetCharFormat();
2606 case SfxStyleFamily::Para: return xStyle->GetCollection();
2607 case SfxStyleFamily::Frame: return xStyle->GetFrameFormat();
2608 case SfxStyleFamily::Page:
2610 SwPageDesc* pDesc(pDoc->FindPageDesc(xStyle->GetPageDesc()->GetName()));
2611 if(pDesc)
2612 return &pDesc->GetMaster();
2614 break;
2615 default: ;
2617 return nullptr;
2620 void SAL_CALL SwXStyle::setPropertiesToDefault(const uno::Sequence<OUString>& aPropertyNames)
2622 SolarMutexGuard aGuard;
2623 const rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(GetStyleSheetBase())));
2624 SwFormat* pTargetFormat = lcl_GetFormatForStyle(m_pDoc, xStyle, m_rEntry.family());
2625 if(!pTargetFormat)
2627 if(!m_bIsDescriptor)
2628 return;
2629 for(const auto& rName : aPropertyNames)
2630 m_pPropertiesImpl->ClearProperty(rName);
2631 return;
2633 const sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.propMapType();
2634 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
2635 const SfxItemPropertyMap &rMap = pPropSet->getPropertyMap();
2636 for(const auto& rName : aPropertyNames)
2638 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(rName);
2639 if(!pEntry)
2640 throw beans::UnknownPropertyException("Unknown property: " + rName, static_cast<cppu::OWeakObject*>(this));
2641 if (pEntry->nWID == FN_UNO_FOLLOW_STYLE || pEntry->nWID == FN_UNO_LINK_STYLE
2642 || pEntry->nWID == FN_UNO_NUM_RULES)
2643 throw uno::RuntimeException("Cannot reset: " + rName, static_cast<cppu::OWeakObject*>(this));
2644 if(pEntry->nFlags & beans::PropertyAttribute::READONLY)
2645 throw uno::RuntimeException("setPropertiesToDefault: property is read-only: " + rName, static_cast<cppu::OWeakObject*>(this));
2646 if(pEntry->nWID == RES_PARATR_OUTLINELEVEL)
2648 static_cast<SwTextFormatColl*>(pTargetFormat)->DeleteAssignmentToListLevelOfOutlineStyle();
2649 continue;
2651 pTargetFormat->ResetFormatAttr(pEntry->nWID);
2652 if(OWN_ATTR_FILLBMP_MODE == pEntry->nWID)
2655 SwDoc* pDoc = pTargetFormat->GetDoc();
2656 SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST> aSet(pDoc->GetAttrPool());
2657 aSet.SetParent(&pTargetFormat->GetAttrSet());
2659 aSet.ClearItem(XATTR_FILLBMP_STRETCH);
2660 aSet.ClearItem(XATTR_FILLBMP_TILE);
2662 pTargetFormat->SetFormatAttr(aSet);
2667 void SAL_CALL SwXStyle::setAllPropertiesToDefault()
2669 SolarMutexGuard aGuard;
2670 if(!m_pBasePool)
2672 if(!m_bIsDescriptor)
2673 throw uno::RuntimeException();
2674 m_pPropertiesImpl->ClearAllProperties();
2675 return;
2677 const rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(GetStyleSheetBase())));
2678 if(!xStyle.is())
2679 throw uno::RuntimeException();
2680 if(SfxStyleFamily::Page == m_rEntry.family())
2682 size_t nPgDscPos(0);
2683 SwPageDesc* pDesc = m_pDoc->FindPageDesc(xStyle->GetPageDesc()->GetName(), &nPgDscPos);
2684 SwFormat* pPageFormat(nullptr);
2685 if(pDesc)
2687 pPageFormat = &pDesc->GetMaster();
2688 pDesc->SetUseOn(UseOnPage::All);
2690 else
2691 pPageFormat = lcl_GetFormatForStyle(m_pDoc, xStyle, m_rEntry.family());
2692 SwPageDesc& rPageDesc = m_pDoc->GetPageDesc(nPgDscPos);
2693 rPageDesc.ResetAllMasterAttr();
2695 pPageFormat->SetPageFormatToDefault();
2696 SwPageDesc* pStdPgDsc = m_pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD);
2697 std::shared_ptr<SwFormatFrameSize> aFrameSz(std::make_shared<SwFormatFrameSize>(SwFrameSize::Fixed));
2699 if(RES_POOLPAGE_STANDARD == rPageDesc.GetPoolFormatId())
2701 if(m_pDoc->getIDocumentDeviceAccess().getPrinter(false))
2703 const Size aPhysSize( SvxPaperInfo::GetPaperSize(
2704 static_cast<Printer*>(m_pDoc->getIDocumentDeviceAccess().getPrinter(false))));
2705 aFrameSz->SetSize(aPhysSize);
2707 else
2709 aFrameSz->SetSize(SvxPaperInfo::GetDefaultPaperSize());
2713 else
2715 aFrameSz.reset(pStdPgDsc->GetMaster().GetFrameSize().Clone());
2718 if(pStdPgDsc->GetLandscape())
2720 SwTwips nTmp = aFrameSz->GetHeight();
2721 aFrameSz->SetHeight(aFrameSz->GetWidth());
2722 aFrameSz->SetWidth(nTmp);
2725 pPageFormat->SetFormatAttr(*aFrameSz);
2726 m_pDoc->ChgPageDesc(nPgDscPos, m_pDoc->GetPageDesc(nPgDscPos));
2727 return;
2729 if(SfxStyleFamily::Para == m_rEntry.family())
2731 if(xStyle->GetCollection())
2732 xStyle->GetCollection()->DeleteAssignmentToListLevelOfOutlineStyle();
2734 SwFormat* const pTargetFormat = lcl_GetFormatForStyle(m_pDoc, xStyle, m_rEntry.family());
2735 if(!pTargetFormat)
2736 return;
2737 pTargetFormat->ResetAllFormatAttr();
2740 uno::Sequence<uno::Any> SAL_CALL SwXStyle::getPropertyDefaults(const uno::Sequence<OUString>& aPropertyNames)
2742 SolarMutexGuard aGuard;
2743 sal_Int32 nCount = aPropertyNames.getLength();
2744 uno::Sequence<uno::Any> aRet(nCount);
2745 if(!nCount)
2746 return aRet;
2747 auto pRet = aRet.getArray();
2748 SfxStyleSheetBase* pBase = GetStyleSheetBase();
2749 if(!pBase)
2750 throw uno::RuntimeException();
2751 rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2752 const sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.propMapType();
2753 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
2754 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
2756 const SfxItemSet &rSet = xStyle->GetItemSet(), *pParentSet = rSet.GetParent();
2757 for(sal_Int32 i = 0; i < nCount; ++i)
2759 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(aPropertyNames[i]);
2761 if(!pEntry)
2762 throw beans::UnknownPropertyException("Unknown property: " + aPropertyNames[i], static_cast < cppu::OWeakObject * >(this));
2763 // these cannot be in an item set, especially not the
2764 // parent set, so the default value is void
2765 if (pEntry->nWID >= RES_UNKNOWNATR_END)
2766 continue;
2768 if(pParentSet)
2770 aSwMapProvider.GetPropertySet(nPropSetId)->getPropertyValue(aPropertyNames[i], *pParentSet, pRet[i]);
2772 else if(pEntry->nWID != rSet.GetPool()->GetSlotId(pEntry->nWID))
2774 const SfxPoolItem& rItem = rSet.GetPool()->GetDefaultItem(pEntry->nWID);
2775 rItem.QueryValue(pRet[i], pEntry->nMemberId);
2778 return aRet;
2781 uno::Any SwXStyle::getPropertyDefault(const OUString& rPropertyName)
2783 const uno::Sequence<OUString> aSequence(&rPropertyName, 1);
2784 return getPropertyDefaults(aSequence)[0];
2787 void SwXStyle::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
2789 if((rHint.GetId() == SfxHintId::Dying) || (rHint.GetId() == SfxHintId::StyleSheetErased))
2791 m_pBasePool = nullptr;
2792 SfxListener::EndListening(rBC);
2794 else if(rHint.GetId() == SfxHintId::StyleSheetChanged)
2796 SfxStyleSheetBasePool& rBP = static_cast<SfxStyleSheetBasePool&>(rBC);
2797 SfxStyleSheetBase* pOwnBase = rBP.Find(m_sStyleName, m_rEntry.family());
2798 if(!pOwnBase)
2800 SfxListener::EndListening(rBC);
2801 Invalidate();
2806 void SwXStyle::Invalidate()
2808 m_sStyleName.clear();
2809 m_pBasePool = nullptr;
2810 m_pDoc = nullptr;
2811 m_xStyleData.clear();
2812 m_xStyleFamily.clear();
2815 SwXPageStyle::SwXPageStyle(SfxStyleSheetBasePool& rPool, SwDocShell* pDocSh, const OUString& rStyleName)
2816 : SwXStyle(&rPool, SfxStyleFamily::Page, pDocSh->GetDoc(), rStyleName)
2819 SwXPageStyle::SwXPageStyle(SwDocShell* pDocSh)
2820 : SwXStyle(pDocSh->GetDoc(), SfxStyleFamily::Page)
2823 void SwXStyle::PutItemToSet(const SvxSetItem* pSetItem, const SfxItemPropertySet& rPropSet, const SfxItemPropertyMapEntry& rEntry, const uno::Any& rVal, SwStyleBase_Impl& rBaseImpl)
2825 // create a new SvxSetItem and get it's ItemSet as new target
2826 std::unique_ptr<SvxSetItem> pNewSetItem(pSetItem->Clone());
2827 SfxItemSet& rSetSet = pNewSetItem->GetItemSet();
2829 // set parent to ItemSet to ensure XFILL_NONE as XFillStyleItem
2830 rSetSet.SetParent(&m_pDoc->GetDfltFrameFormat()->GetAttrSet());
2832 // replace the used SfxItemSet at the SwStyleBase_Impl temporarily and use the
2833 // default method to set the property
2835 SwStyleBase_Impl::ItemSetOverrider o(rBaseImpl, &rSetSet);
2836 SetStyleProperty(rEntry, rPropSet, rVal, rBaseImpl);
2839 // reset parent at ItemSet from SetItem
2840 rSetSet.SetParent(nullptr);
2842 // set the new SvxSetItem at the real target and delete it
2843 rBaseImpl.GetItemSet().Put(std::move(pNewSetItem));
2846 void SwXPageStyle::SetPropertyValues_Impl(const uno::Sequence<OUString>& rPropertyNames, const uno::Sequence<uno::Any>& rValues)
2848 if(!GetDoc())
2849 throw uno::RuntimeException();
2851 if(rPropertyNames.getLength() != rValues.getLength())
2852 throw lang::IllegalArgumentException();
2854 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(PROPERTY_MAP_PAGE_STYLE);
2855 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
2856 SwStyleBase_Impl aBaseImpl(*GetDoc(), GetStyleName(), &GetDoc()->GetDfltFrameFormat()->GetAttrSet()); // add pDfltFrameFormat as parent
2857 if(!m_pBasePool)
2859 if(!IsDescriptor())
2860 throw uno::RuntimeException();
2861 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp)
2862 if(!m_pPropertiesImpl->SetProperty(rPropertyNames[nProp], rValues[nProp]))
2863 throw lang::IllegalArgumentException();
2864 return;
2866 SfxStyleSheetBase* pBase = GetStyleSheetBase();
2867 if(!pBase)
2868 throw uno::RuntimeException();
2869 aBaseImpl.setNewBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2870 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp)
2872 const OUString& rPropName = rPropertyNames[nProp];
2873 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(rPropName);
2875 if(!pEntry)
2876 throw beans::UnknownPropertyException("Unknown property: " + rPropName, static_cast<cppu::OWeakObject*>(this));
2877 if(pEntry->nFlags & beans::PropertyAttribute::READONLY)
2878 throw beans::PropertyVetoException("Property is read-only: " + rPropName, static_cast<cppu::OWeakObject*>(this));
2880 const bool bHeader(rPropName.startsWith("Header"));
2881 const bool bFooter(rPropName.startsWith("Footer"));
2882 const bool bFirstIsShared(rPropName == UNO_NAME_FIRST_IS_SHARED);
2883 if(bHeader || bFooter || bFirstIsShared)
2885 switch(pEntry->nWID)
2887 case SID_ATTR_PAGE_ON:
2888 case RES_BACKGROUND:
2889 case RES_BOX:
2890 case RES_LR_SPACE:
2891 case RES_SHADOW:
2892 case RES_UL_SPACE:
2893 case SID_ATTR_PAGE_DYNAMIC:
2894 case SID_ATTR_PAGE_SHARED:
2895 case SID_ATTR_PAGE_SHARED_FIRST:
2896 case SID_ATTR_PAGE_SIZE:
2897 case RES_HEADER_FOOTER_EAT_SPACING:
2899 // it is a Header/Footer entry, access the SvxSetItem containing it's information
2900 const SvxSetItem* pSetItem = nullptr;
2901 if (lcl_GetHeaderFooterItem(aBaseImpl.GetItemSet(), rPropName, bFooter, pSetItem))
2903 PutItemToSet(pSetItem, *pPropSet, *pEntry, rValues[nProp], aBaseImpl);
2905 if (pEntry->nWID == SID_ATTR_PAGE_SHARED_FIRST)
2907 // Need to add this to the other as well
2908 pSetItem = aBaseImpl.GetItemSet().GetItemIfSet(
2909 bFooter ? SID_ATTR_PAGE_HEADERSET : SID_ATTR_PAGE_FOOTERSET,
2910 false);
2911 if (pSetItem)
2913 PutItemToSet(pSetItem, *pPropSet, *pEntry, rValues[nProp], aBaseImpl);
2917 else if(pEntry->nWID == SID_ATTR_PAGE_ON && rValues[nProp].get<bool>())
2919 // Header/footer gets switched on, create defaults and the needed SfxSetItem
2920 SfxItemSetFixed
2921 <RES_FRMATR_BEGIN,RES_FRMATR_END - 1, // [82
2923 // FillAttribute support
2924 XATTR_FILL_FIRST, XATTR_FILL_LAST, // [1014
2926 SID_ATTR_BORDER_INNER,SID_ATTR_BORDER_INNER, // [10023
2927 SID_ATTR_PAGE_SIZE,SID_ATTR_PAGE_SIZE, // [10051
2928 SID_ATTR_PAGE_ON,SID_ATTR_PAGE_SHARED, // [10060
2929 SID_ATTR_PAGE_SHARED_FIRST,SID_ATTR_PAGE_SHARED_FIRST>
2930 aTempSet(*aBaseImpl.GetItemSet().GetPool());
2932 // set correct parent to get the XFILL_NONE FillStyle as needed
2933 aTempSet.SetParent(&GetDoc()->GetDfltFrameFormat()->GetAttrSet());
2935 aTempSet.Put(SfxBoolItem(SID_ATTR_PAGE_ON, true));
2936 constexpr tools::Long constTwips_5mm = o3tl::toTwips(5, o3tl::Length::mm);
2937 aTempSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(constTwips_5mm, constTwips_5mm)));
2938 aTempSet.Put(SvxLRSpaceItem(RES_LR_SPACE));
2939 aTempSet.Put(SvxULSpaceItem(RES_UL_SPACE));
2940 aTempSet.Put(SfxBoolItem(SID_ATTR_PAGE_SHARED, true));
2941 aTempSet.Put(SfxBoolItem(SID_ATTR_PAGE_SHARED_FIRST, true));
2942 aTempSet.Put(SfxBoolItem(SID_ATTR_PAGE_DYNAMIC, true));
2944 SvxSetItem aNewSetItem(bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, aTempSet);
2945 aBaseImpl.GetItemSet().Put(aNewSetItem);
2948 continue;
2949 case XATTR_FILLBMP_SIZELOG:
2950 case XATTR_FILLBMP_TILEOFFSETX:
2951 case XATTR_FILLBMP_TILEOFFSETY:
2952 case XATTR_FILLBMP_POSOFFSETX:
2953 case XATTR_FILLBMP_POSOFFSETY:
2954 case XATTR_FILLBMP_POS:
2955 case XATTR_FILLBMP_SIZEX:
2956 case XATTR_FILLBMP_SIZEY:
2957 case XATTR_FILLBMP_STRETCH:
2958 case XATTR_FILLBMP_TILE:
2959 case OWN_ATTR_FILLBMP_MODE:
2960 case XATTR_FILLCOLOR:
2961 case XATTR_FILLBACKGROUND:
2962 case XATTR_FILLBITMAP:
2963 case XATTR_GRADIENTSTEPCOUNT:
2964 case XATTR_FILLGRADIENT:
2965 case XATTR_FILLHATCH:
2966 case XATTR_FILLSTYLE:
2967 case XATTR_FILLTRANSPARENCE:
2968 case XATTR_FILLFLOATTRANSPARENCE:
2969 case XATTR_SECONDARYFILLCOLOR:
2970 if(bFirstIsShared) // only special handling for headers/footers here
2971 break;
2973 const SvxSetItem* pSetItem =
2974 aBaseImpl.GetItemSet().GetItemIfSet(bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, false);
2976 if(pSetItem)
2978 // create a new SvxSetItem and get it's ItemSet as new target
2979 std::unique_ptr<SvxSetItem> pNewSetItem(pSetItem->Clone());
2980 SfxItemSet& rSetSet = pNewSetItem->GetItemSet();
2982 // set parent to ItemSet to ensure XFILL_NONE as XFillStyleItem
2983 rSetSet.SetParent(&GetDoc()->GetDfltFrameFormat()->GetAttrSet());
2985 // replace the used SfxItemSet at the SwStyleBase_Impl temporarily and use the
2986 // default method to set the property
2988 SwStyleBase_Impl::ItemSetOverrider o(aBaseImpl, &rSetSet);
2989 SetStyleProperty(*pEntry, *pPropSet, rValues[nProp], aBaseImpl);
2992 // reset parent at ItemSet from SetItem
2993 rSetSet.SetParent(nullptr);
2995 // set the new SvxSetItem at the real target and delete it
2996 aBaseImpl.GetItemSet().Put(std::move(pNewSetItem));
2999 continue;
3000 default: ;
3003 switch(pEntry->nWID)
3005 case SID_ATTR_PAGE_DYNAMIC:
3006 case SID_ATTR_PAGE_SHARED:
3007 case SID_ATTR_PAGE_SHARED_FIRST:
3008 case SID_ATTR_PAGE_ON:
3009 case RES_HEADER_FOOTER_EAT_SPACING:
3010 // these slots are exclusive to Header/Footer, thus this is an error
3011 throw beans::UnknownPropertyException("Unknown property: " + rPropName, static_cast<cppu::OWeakObject*>(this));
3012 case FN_UNO_HEADER:
3013 case FN_UNO_HEADER_LEFT:
3014 case FN_UNO_HEADER_RIGHT:
3015 case FN_UNO_HEADER_FIRST:
3016 case FN_UNO_FOOTER:
3017 case FN_UNO_FOOTER_LEFT:
3018 case FN_UNO_FOOTER_RIGHT:
3019 case FN_UNO_FOOTER_FIRST:
3020 throw lang::IllegalArgumentException();
3021 case FN_PARAM_FTN_INFO:
3023 const SwPageFootnoteInfoItem& rItem = aBaseImpl.GetItemSet().Get(FN_PARAM_FTN_INFO);
3024 std::unique_ptr<SfxPoolItem> pNewFootnoteItem(rItem.Clone());
3025 if(!pNewFootnoteItem->PutValue(rValues[nProp], pEntry->nMemberId))
3026 throw lang::IllegalArgumentException();
3027 aBaseImpl.GetItemSet().Put(std::move(pNewFootnoteItem));
3028 break;
3030 default:
3032 SetStyleProperty(*pEntry, *pPropSet, rValues[nProp], aBaseImpl);
3033 break;
3038 if(aBaseImpl.HasItemSet())
3040 ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
3042 if (undoGuard.UndoWasEnabled())
3044 // Fix i64460: as long as Undo of page styles with header/footer causes trouble...
3045 GetDoc()->GetIDocumentUndoRedo().DelAllUndoObj();
3048 aBaseImpl.getNewBase()->SetItemSet(aBaseImpl.GetItemSet());
3052 void SwXPageStyle::setPropertyValues(const uno::Sequence<OUString>& rPropertyNames, const uno::Sequence<uno::Any>& rValues)
3054 SolarMutexGuard aGuard;
3056 // workaround for bad designed API
3059 SetPropertyValues_Impl(rPropertyNames, rValues);
3061 catch (const beans::UnknownPropertyException &rException)
3063 // wrap the original (here not allowed) exception in
3064 // a lang::WrappedTargetException that gets thrown instead.
3065 lang::WrappedTargetException aWExc;
3066 aWExc.TargetException <<= rException;
3067 throw aWExc;
3071 static uno::Reference<text::XText> lcl_makeHeaderFooter(const sal_uInt16 nRes, const bool bHeader, SwFrameFormat const*const pFrameFormat)
3073 if (!pFrameFormat)
3074 return nullptr;
3075 const SfxItemSet& rSet = pFrameFormat->GetAttrSet();
3076 const SfxPoolItem* pItem;
3077 if(SfxItemState::SET != rSet.GetItemState(nRes, true, &pItem))
3078 return nullptr;
3079 SwFrameFormat* const pHeadFootFormat = bHeader
3080 ? static_cast<SwFormatHeader*>(const_cast<SfxPoolItem*>(pItem))->GetHeaderFormat()
3081 : static_cast<SwFormatFooter*>(const_cast<SfxPoolItem*>(pItem))->GetFooterFormat();
3082 if(!pHeadFootFormat)
3083 return nullptr;
3084 return SwXHeadFootText::CreateXHeadFootText(*pHeadFootFormat, bHeader);
3087 uno::Sequence<uno::Any> SwXPageStyle::GetPropertyValues_Impl(const uno::Sequence<OUString>& rPropertyNames)
3089 if(!GetDoc())
3090 throw uno::RuntimeException();
3092 sal_Int32 nLength = rPropertyNames.getLength();
3093 uno::Sequence<uno::Any> aRet (nLength);
3094 auto aRetRange = asNonConstRange(aRet);
3095 if(!m_pBasePool)
3097 if(!IsDescriptor())
3098 throw uno::RuntimeException();
3099 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp)
3101 const uno::Any* pAny = nullptr;
3102 m_pPropertiesImpl->GetProperty(rPropertyNames[nProp], pAny);
3103 if (!pAny->hasValue())
3104 aRetRange[nProp] = m_xStyleData->getPropertyValue(rPropertyNames[nProp]);
3105 else
3106 aRetRange[nProp] = *pAny;
3108 return aRet;
3110 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(PROPERTY_MAP_PAGE_STYLE);
3111 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
3112 SwStyleBase_Impl aBase(*GetDoc(), GetStyleName(), &GetDoc()->GetDfltFrameFormat()->GetAttrSet()); // add pDfltFrameFormat as parent
3113 SfxStyleSheetBase* pBase = GetStyleSheetBase();
3114 if(!pBase)
3115 throw uno::RuntimeException();
3116 for(sal_Int32 nProp = 0; nProp < nLength; ++nProp)
3118 const OUString& rPropName = rPropertyNames[nProp];
3119 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(rPropName);
3121 if (!pEntry)
3122 throw beans::UnknownPropertyException("Unknown property: " + rPropName, static_cast < cppu::OWeakObject * > ( this ) );
3123 const bool bHeader(rPropName.startsWith("Header"));
3124 const bool bFooter(rPropName.startsWith("Footer"));
3125 const bool bFirstIsShared(rPropName == UNO_NAME_FIRST_IS_SHARED);
3126 if(bHeader || bFooter || bFirstIsShared)
3128 switch(pEntry->nWID)
3130 case SID_ATTR_PAGE_ON:
3131 case RES_BACKGROUND:
3132 case RES_BOX:
3133 case RES_LR_SPACE:
3134 case RES_SHADOW:
3135 case RES_UL_SPACE:
3136 case SID_ATTR_PAGE_DYNAMIC:
3137 case SID_ATTR_PAGE_SHARED:
3138 case SID_ATTR_PAGE_SHARED_FIRST:
3139 case SID_ATTR_PAGE_SIZE:
3140 case RES_HEADER_FOOTER_EAT_SPACING:
3142 // slot is a Header/Footer slot
3143 rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pBase) ) );
3144 const SfxItemSet& rSet = xStyle->GetItemSet();
3145 const SvxSetItem* pSetItem;
3147 if (lcl_GetHeaderFooterItem(rSet, rPropName, bFooter, pSetItem))
3149 // get from SfxItemSet of the corresponding SfxSetItem
3150 const SfxItemSet& rSetSet = pSetItem->GetItemSet();
3152 SwStyleBase_Impl::ItemSetOverrider o(aBase, &const_cast< SfxItemSet& >(rSetSet));
3153 aRetRange[nProp] = GetStyleProperty_Impl(*pEntry, *pPropSet, aBase);
3156 else if(pEntry->nWID == SID_ATTR_PAGE_ON)
3158 // header/footer is not available, thus off. Default is <false>, though
3159 aRetRange[nProp] <<= false;
3162 continue;
3163 case XATTR_FILLBMP_SIZELOG:
3164 case XATTR_FILLBMP_TILEOFFSETX:
3165 case XATTR_FILLBMP_TILEOFFSETY:
3166 case XATTR_FILLBMP_POSOFFSETX:
3167 case XATTR_FILLBMP_POSOFFSETY:
3168 case XATTR_FILLBMP_POS:
3169 case XATTR_FILLBMP_SIZEX:
3170 case XATTR_FILLBMP_SIZEY:
3171 case XATTR_FILLBMP_STRETCH:
3172 case XATTR_FILLBMP_TILE:
3173 case OWN_ATTR_FILLBMP_MODE:
3174 case XATTR_FILLCOLOR:
3175 case XATTR_FILLBACKGROUND:
3176 case XATTR_FILLBITMAP:
3177 case XATTR_GRADIENTSTEPCOUNT:
3178 case XATTR_FILLGRADIENT:
3179 case XATTR_FILLHATCH:
3180 case XATTR_FILLSTYLE:
3181 case XATTR_FILLTRANSPARENCE:
3182 case XATTR_FILLFLOATTRANSPARENCE:
3183 case XATTR_SECONDARYFILLCOLOR:
3184 if(bFirstIsShared) // only special handling for headers/footers here
3185 break;
3187 rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pBase) ) );
3188 const SfxItemSet& rSet = xStyle->GetItemSet();
3189 const SvxSetItem* pSetItem =
3190 rSet.GetItemIfSet(bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, false);
3191 if(pSetItem)
3193 // set at SfxItemSet of the corresponding SfxSetItem
3194 const SfxItemSet& rSetSet = pSetItem->GetItemSet();
3196 SwStyleBase_Impl::ItemSetOverrider o(aBase, &const_cast<SfxItemSet&>(rSetSet));
3197 aRetRange[nProp] = GetStyleProperty_Impl(*pEntry, *pPropSet, aBase);
3201 continue;
3202 default: ;
3205 switch(pEntry->nWID)
3207 // these slots are exclusive to Header/Footer, thus this is an error
3208 case SID_ATTR_PAGE_DYNAMIC:
3209 case SID_ATTR_PAGE_SHARED:
3210 case SID_ATTR_PAGE_SHARED_FIRST:
3211 case SID_ATTR_PAGE_ON:
3212 case RES_HEADER_FOOTER_EAT_SPACING:
3213 throw beans::UnknownPropertyException( "Unknown property: " + rPropName, static_cast < cppu::OWeakObject * > ( this ) );
3214 case FN_UNO_HEADER:
3215 case FN_UNO_HEADER_LEFT:
3216 case FN_UNO_HEADER_FIRST:
3217 case FN_UNO_HEADER_RIGHT:
3218 case FN_UNO_FOOTER:
3219 case FN_UNO_FOOTER_LEFT:
3220 case FN_UNO_FOOTER_FIRST:
3221 case FN_UNO_FOOTER_RIGHT:
3223 bool bLeft(false);
3224 bool bFirst(false);
3225 sal_uInt16 nRes = 0;
3226 switch(pEntry->nWID)
3228 case FN_UNO_HEADER: nRes = RES_HEADER; break;
3229 case FN_UNO_HEADER_LEFT: nRes = RES_HEADER; bLeft = true; break;
3230 case FN_UNO_HEADER_FIRST: nRes = RES_HEADER; bFirst = true; break;
3231 case FN_UNO_HEADER_RIGHT: nRes = RES_HEADER; break;
3232 case FN_UNO_FOOTER: nRes = RES_FOOTER; break;
3233 case FN_UNO_FOOTER_LEFT: nRes = RES_FOOTER; bLeft = true; break;
3234 case FN_UNO_FOOTER_FIRST: nRes = RES_FOOTER; bFirst = true; break;
3235 case FN_UNO_FOOTER_RIGHT: nRes = RES_FOOTER; break;
3236 default: ;
3239 const SwPageDesc* pDesc = aBase.GetOldPageDesc();
3240 assert(pDesc);
3241 const SwFrameFormat* pFrameFormat = nullptr;
3242 bool bShare = (nRes == RES_HEADER && pDesc->IsHeaderShared()) || (nRes == RES_FOOTER && pDesc->IsFooterShared());
3243 bool bShareFirst = pDesc->IsFirstShared();
3244 // TextLeft returns the left content if there is one,
3245 // Text and TextRight return the master content.
3246 // TextRight does the same as Text and is for
3247 // compatibility only.
3248 if(bLeft && !bShare)
3249 pFrameFormat = &pDesc->GetLeft();
3250 else if(bFirst && !bShareFirst)
3252 pFrameFormat = &pDesc->GetFirstMaster();
3253 // no need to make GetFirstLeft() accessible
3254 // since it is always shared
3256 else
3257 pFrameFormat = &pDesc->GetMaster();
3258 const uno::Reference<text::XText> xRet = lcl_makeHeaderFooter(nRes, nRes == RES_HEADER, pFrameFormat);
3259 if (xRet.is())
3260 aRetRange[nProp] <<= xRet;
3262 break;
3263 case FN_PARAM_FTN_INFO:
3265 rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
3266 const SfxItemSet& rSet = xStyle->GetItemSet();
3267 const SfxPoolItem& rItem = rSet.Get(FN_PARAM_FTN_INFO);
3268 rItem.QueryValue(aRetRange[nProp], pEntry->nMemberId);
3270 break;
3271 default:
3272 aRetRange[nProp] = GetStyleProperty_Impl(*pEntry, *pPropSet, aBase);
3275 return aRet;
3278 uno::Sequence<uno::Any> SwXPageStyle::getPropertyValues(const uno::Sequence<OUString>& rPropertyNames)
3280 SolarMutexGuard aGuard;
3281 uno::Sequence<uno::Any> aValues;
3283 // workaround for bad designed API
3286 aValues = GetPropertyValues_Impl(rPropertyNames);
3288 catch(beans::UnknownPropertyException &)
3290 css::uno::Any anyEx = cppu::getCaughtException();
3291 throw lang::WrappedTargetRuntimeException("Unknown property exception caught",
3292 static_cast < cppu::OWeakObject * > ( this ), anyEx );
3294 catch(lang::WrappedTargetException &)
3296 css::uno::Any anyEx = cppu::getCaughtException();
3297 throw lang::WrappedTargetRuntimeException("WrappedTargetException caught",
3298 static_cast < cppu::OWeakObject * > ( this ), anyEx );
3301 return aValues;
3304 uno::Any SwXPageStyle::getPropertyValue(const OUString& rPropertyName)
3306 SolarMutexGuard aGuard;
3307 const uno::Sequence<OUString> aProperties(&rPropertyName, 1);
3308 return GetPropertyValues_Impl(aProperties)[0];
3311 void SwXPageStyle::setPropertyValue(const OUString& rPropertyName, const uno::Any& rValue)
3313 SolarMutexGuard aGuard;
3314 const uno::Sequence<OUString> aProperties(&rPropertyName, 1);
3315 const uno::Sequence<uno::Any> aValues(&rValue, 1);
3317 // Trick: if the Domain Mapper changes the props of shared header/footer,
3318 // store the old ones in time for later use.
3319 const bool bIsHeader = rPropertyName == UNO_NAME_HEADER_IS_SHARED;
3320 const bool bIsFooter = rPropertyName == UNO_NAME_FOOTER_IS_SHARED;
3321 if ((bIsFooter || bIsHeader) && rValue == uno::Any(true))
3323 // Find the matching page descriptor
3324 for (size_t i = 0; i < GetDoc()->GetPageDescCnt(); i++)
3326 auto pPageDesc = &GetDoc()->GetPageDesc(i);
3327 // If we have the right page descriptor stash the necessary formats in import time.
3328 if (pPageDesc->GetName() == GetStyleName())
3330 auto pLeftHeader = pPageDesc->GetLeft().GetHeader().GetHeaderFormat();
3331 if (bIsHeader && pLeftHeader)
3333 pPageDesc->StashFrameFormat(pPageDesc->GetLeft(), true, true, false);
3334 pPageDesc->StashFrameFormat(pPageDesc->GetFirstMaster(), true, false, true);
3335 pPageDesc->StashFrameFormat(pPageDesc->GetFirstLeft(), true, true, true);
3337 auto pLeftFooter = pPageDesc->GetLeft().GetFooter().GetFooterFormat();
3338 if (bIsFooter && pLeftFooter)
3340 pPageDesc->StashFrameFormat(pPageDesc->GetLeft(), false, true, false);
3341 pPageDesc->StashFrameFormat(pPageDesc->GetFirstMaster(), false, false, true);
3342 pPageDesc->StashFrameFormat(pPageDesc->GetFirstLeft(), false, true, true);
3347 // And set the props... as we did it before.
3348 SetPropertyValues_Impl(aProperties, aValues);
3351 SwXFrameStyle::SwXFrameStyle(SwDoc *pDoc)
3352 : SwXFrameStyle_Base(pDoc, SfxStyleFamily::Frame, false)
3355 void SwXFrameStyle::SetItem(sal_uInt16 eAtr, const SfxPoolItem& rItem)
3357 assert(eAtr >= RES_FRMATR_BEGIN && eAtr < RES_FRMATR_END);
3358 SfxStyleSheetBase* pBase = GetStyleSheetBase();
3359 if(!pBase)
3360 return;
3361 rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
3362 SfxItemSet& rStyleSet = xStyle->GetItemSet();
3363 SfxItemSet aSet(*rStyleSet.GetPool(), sal_uInt16(eAtr), sal_uInt16(eAtr));
3364 aSet.Put(rItem);
3365 xStyle->SetItemSet(aSet);
3368 const SfxPoolItem* SwXFrameStyle::GetItem(sal_uInt16 eAtr)
3370 assert(eAtr >= RES_FRMATR_BEGIN && eAtr < RES_FRMATR_END);
3371 SfxStyleSheetBase* pBase = GetStyleSheetBase();
3372 if(!pBase)
3373 return nullptr;
3374 rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
3375 return &xStyle->GetItemSet().Get(eAtr);
3378 uno::Reference<container::XNameReplace> SwXFrameStyle::getEvents()
3380 return new SwFrameStyleEventDescriptor(*this);
3383 // Already implemented autostyle families: 3
3384 #define AUTOSTYLE_FAMILY_COUNT 3
3385 const IStyleAccess::SwAutoStyleFamily aAutoStyleByIndex[] =
3387 IStyleAccess::AUTO_STYLE_CHAR,
3388 IStyleAccess::AUTO_STYLE_RUBY,
3389 IStyleAccess::AUTO_STYLE_PARA
3392 class SwAutoStylesEnumImpl
3394 std::vector<std::shared_ptr<SfxItemSet>> mAutoStyles;
3395 std::vector<std::shared_ptr<SfxItemSet>>::iterator m_aIter;
3396 SwDoc& m_rDoc;
3397 IStyleAccess::SwAutoStyleFamily m_eFamily;
3398 public:
3399 SwAutoStylesEnumImpl( SwDoc& rInitDoc, IStyleAccess::SwAutoStyleFamily eFam );
3400 bool hasMoreElements() { return m_aIter != mAutoStyles.end(); }
3401 std::shared_ptr<SfxItemSet> const & nextElement() { return *(m_aIter++); }
3402 IStyleAccess::SwAutoStyleFamily getFamily() const { return m_eFamily; }
3403 SwDoc& getDoc() const { return m_rDoc; }
3406 SwXAutoStyles::SwXAutoStyles(SwDocShell& rDocShell) :
3407 SwUnoCollection(rDocShell.GetDoc()), m_pDocShell( &rDocShell )
3411 SwXAutoStyles::~SwXAutoStyles()
3415 sal_Int32 SwXAutoStyles::getCount()
3417 return AUTOSTYLE_FAMILY_COUNT;
3420 uno::Any SwXAutoStyles::getByIndex(sal_Int32 nIndex)
3422 SolarMutexGuard aGuard;
3423 uno::Any aRet;
3424 if(nIndex < 0 || nIndex >= AUTOSTYLE_FAMILY_COUNT)
3425 throw lang::IndexOutOfBoundsException();
3426 if(!IsValid())
3427 throw uno::RuntimeException();
3429 uno::Reference< style::XAutoStyleFamily > aRef;
3430 IStyleAccess::SwAutoStyleFamily nType = aAutoStyleByIndex[nIndex];
3431 switch( nType )
3433 case IStyleAccess::AUTO_STYLE_CHAR:
3435 if(!m_xAutoCharStyles.is())
3436 m_xAutoCharStyles = new SwXAutoStyleFamily(m_pDocShell, nType);
3437 aRef = m_xAutoCharStyles;
3439 break;
3440 case IStyleAccess::AUTO_STYLE_RUBY:
3442 if(!m_xAutoRubyStyles.is())
3443 m_xAutoRubyStyles = new SwXAutoStyleFamily(m_pDocShell, nType );
3444 aRef = m_xAutoRubyStyles;
3446 break;
3447 case IStyleAccess::AUTO_STYLE_PARA:
3449 if(!m_xAutoParaStyles.is())
3450 m_xAutoParaStyles = new SwXAutoStyleFamily(m_pDocShell, nType );
3451 aRef = m_xAutoParaStyles;
3453 break;
3455 default:
3458 aRet <<= aRef;
3460 return aRet;
3463 uno::Type SwXAutoStyles::getElementType( )
3465 return cppu::UnoType<style::XAutoStyleFamily>::get();
3468 sal_Bool SwXAutoStyles::hasElements( )
3470 return true;
3473 uno::Any SwXAutoStyles::getByName(const OUString& Name)
3475 uno::Any aRet;
3476 if(Name == "CharacterStyles")
3477 aRet = getByIndex(0);
3478 else if(Name == "RubyStyles")
3479 aRet = getByIndex(1);
3480 else if(Name == "ParagraphStyles")
3481 aRet = getByIndex(2);
3482 else
3483 throw container::NoSuchElementException();
3484 return aRet;
3487 uno::Sequence< OUString > SwXAutoStyles::getElementNames()
3489 uno::Sequence< OUString > aNames(AUTOSTYLE_FAMILY_COUNT);
3490 OUString* pNames = aNames.getArray();
3491 pNames[0] = "CharacterStyles";
3492 pNames[1] = "RubyStyles";
3493 pNames[2] = "ParagraphStyles";
3494 return aNames;
3497 sal_Bool SwXAutoStyles::hasByName(const OUString& Name)
3499 if( Name == "CharacterStyles" ||
3500 Name == "RubyStyles" ||
3501 Name == "ParagraphStyles" )
3502 return true;
3503 else
3504 return false;
3507 SwXAutoStyleFamily::SwXAutoStyleFamily(SwDocShell* pDocSh, IStyleAccess::SwAutoStyleFamily nFamily) :
3508 m_pDocShell( pDocSh ), m_eFamily(nFamily)
3510 // Register ourselves as a listener to the document (via the page descriptor)
3511 StartListening(pDocSh->GetDoc()->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier());
3514 SwXAutoStyleFamily::~SwXAutoStyleFamily()
3518 void SwXAutoStyleFamily::Notify(const SfxHint& rHint)
3520 if(rHint.GetId() == SfxHintId::Dying)
3521 m_pDocShell = nullptr;
3524 std::shared_ptr<SfxItemSet>
3525 PropValuesToAutoStyleItemSet(SwDoc& rDoc, IStyleAccess::SwAutoStyleFamily eFamily,
3526 const uno::Sequence<beans::PropertyValue>& Values, SwAttrSet& aSet)
3528 const SfxItemPropertySet* pPropSet = nullptr;
3529 switch( eFamily )
3531 case IStyleAccess::AUTO_STYLE_CHAR:
3533 pPropSet = aSwMapProvider.GetPropertySet(PROPERTY_MAP_CHAR_AUTO_STYLE);
3534 break;
3536 case IStyleAccess::AUTO_STYLE_RUBY:
3538 pPropSet = aSwMapProvider.GetPropertySet(PROPERTY_MAP_RUBY_AUTO_STYLE);
3539 break;
3541 case IStyleAccess::AUTO_STYLE_PARA:
3543 pPropSet = aSwMapProvider.GetPropertySet(PROPERTY_MAP_PARA_AUTO_STYLE);
3544 break;
3546 default: ;
3549 if( !pPropSet)
3550 throw uno::RuntimeException();
3552 const bool bTakeCareOfDrawingLayerFillStyle(IStyleAccess::AUTO_STYLE_PARA == eFamily);
3554 if(!bTakeCareOfDrawingLayerFillStyle)
3556 for( const beans::PropertyValue& rValue : Values )
3560 pPropSet->setPropertyValue( rValue.Name, rValue.Value, aSet );
3562 catch (const beans::UnknownPropertyException &)
3564 OSL_FAIL( "Unknown property" );
3566 catch (const lang::IllegalArgumentException &)
3568 OSL_FAIL( "Illegal argument" );
3572 else
3574 // set parent to ItemSet to ensure XFILL_NONE as XFillStyleItem
3575 // to make cases in RES_BACKGROUND work correct; target *is* a style
3576 // where this is the case
3577 aSet.SetParent(&rDoc.GetDfltTextFormatColl()->GetAttrSet());
3579 // here the used DrawingLayer FillStyles are imported when family is
3580 // equal to IStyleAccess::AUTO_STYLE_PARA, thus we will need to serve the
3581 // used slots functionality here to do this correctly
3582 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
3584 for( const beans::PropertyValue& rValue : Values )
3586 const OUString& rPropName = rValue.Name;
3587 uno::Any aValue(rValue.Value);
3588 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(rPropName);
3590 if (!pEntry)
3592 SAL_WARN("sw.core", "SwXAutoStyleFamily::insertStyle: Unknown property: " << rPropName);
3593 continue;
3596 const sal_uInt8 nMemberId(pEntry->nMemberId);
3597 bool bDone(false);
3599 // check for needed metric translation
3600 if(pEntry->nMoreFlags & PropertyMoreFlags::METRIC_ITEM)
3602 bool bDoIt(true);
3604 if(XATTR_FILLBMP_SIZEX == pEntry->nWID || XATTR_FILLBMP_SIZEY == pEntry->nWID)
3606 // exception: If these ItemTypes are used, do not convert when these are negative
3607 // since this means they are intended as percent values
3608 sal_Int32 nValue = 0;
3610 if(aValue >>= nValue)
3612 bDoIt = nValue > 0;
3616 if(bDoIt)
3618 const SfxItemPool& rPool = rDoc.GetAttrPool();
3619 const MapUnit eMapUnit(rPool.GetMetric(pEntry->nWID));
3621 if(eMapUnit != MapUnit::Map100thMM)
3623 SvxUnoConvertFromMM(eMapUnit, aValue);
3628 switch(pEntry->nWID)
3630 case XATTR_FILLGRADIENT:
3631 case XATTR_FILLHATCH:
3632 case XATTR_FILLBITMAP:
3633 case XATTR_FILLFLOATTRANSPARENCE:
3634 // not yet needed; activate when LineStyle support may be added
3635 // case XATTR_LINESTART:
3636 // case XATTR_LINEEND:
3637 // case XATTR_LINEDASH:
3639 if(MID_NAME == nMemberId)
3641 // add set commands for FillName items
3642 OUString aTempName;
3644 if(!(aValue >>= aTempName))
3646 throw lang::IllegalArgumentException();
3649 SvxShape::SetFillAttribute(pEntry->nWID, aTempName, aSet);
3650 bDone = true;
3652 else if (MID_BITMAP == nMemberId)
3654 if(XATTR_FILLBITMAP == pEntry->nWID)
3656 Graphic aNullGraphic;
3657 XFillBitmapItem aXFillBitmapItem(std::move(aNullGraphic));
3659 aXFillBitmapItem.PutValue(aValue, nMemberId);
3660 aSet.Put(aXFillBitmapItem);
3661 bDone = true;
3665 break;
3667 case RES_BACKGROUND:
3669 const std::unique_ptr<SvxBrushItem> aOriginalBrushItem(getSvxBrushItemFromSourceSet(aSet, RES_BACKGROUND, true, rDoc.IsInXMLImport()));
3670 std::unique_ptr<SvxBrushItem> aChangedBrushItem(aOriginalBrushItem->Clone());
3672 aChangedBrushItem->PutValue(aValue, nMemberId);
3674 if(*aChangedBrushItem != *aOriginalBrushItem)
3676 setSvxBrushItemAsFillAttributesToTargetSet(*aChangedBrushItem, aSet);
3679 bDone = true;
3680 break;
3682 case OWN_ATTR_FILLBMP_MODE:
3684 drawing::BitmapMode eMode;
3686 if(!(aValue >>= eMode))
3688 sal_Int32 nMode = 0;
3690 if(!(aValue >>= nMode))
3692 throw lang::IllegalArgumentException();
3695 eMode = static_cast<drawing::BitmapMode>(nMode);
3698 aSet.Put(XFillBmpStretchItem(drawing::BitmapMode_STRETCH == eMode));
3699 aSet.Put(XFillBmpTileItem(drawing::BitmapMode_REPEAT == eMode));
3701 bDone = true;
3702 break;
3704 default: break;
3707 if(!bDone)
3711 pPropSet->setPropertyValue( rPropName, aValue, aSet );
3713 catch (const beans::UnknownPropertyException &)
3715 OSL_FAIL( "Unknown property" );
3717 catch (const lang::IllegalArgumentException &)
3719 OSL_FAIL( "Illegal argument" );
3724 // clear parent again
3725 aSet.SetParent(nullptr);
3728 // need to ensure uniqueness of evtl. added NameOrIndex items
3729 // currently in principle only needed when bTakeCareOfDrawingLayerFillStyle,
3730 // but does not hurt and is easily forgotten later eventually, so keep it
3731 // as common case
3732 rDoc.CheckForUniqueItemForLineFillNameOrIndex(aSet);
3734 return rDoc.GetIStyleAccess().cacheAutomaticStyle(aSet, eFamily);
3737 uno::Reference< style::XAutoStyle > SwXAutoStyleFamily::insertStyle(
3738 const uno::Sequence< beans::PropertyValue >& Values )
3740 if (!m_pDocShell)
3742 throw uno::RuntimeException();
3745 WhichRangesContainer pRange;
3746 switch (m_eFamily)
3748 case IStyleAccess::AUTO_STYLE_CHAR:
3750 pRange = aCharAutoFormatSetRange;
3751 break;
3753 case IStyleAccess::AUTO_STYLE_RUBY:
3755 pRange = WhichRangesContainer(RES_TXTATR_CJK_RUBY, RES_TXTATR_CJK_RUBY);
3756 break;
3758 case IStyleAccess::AUTO_STYLE_PARA:
3760 pRange = aTextNodeSetRange; // checked, already added support for [XATTR_FILL_FIRST, XATTR_FILL_LAST]
3761 break;
3763 default:
3764 throw uno::RuntimeException();
3767 SwAttrSet aEmptySet(m_pDocShell->GetDoc()->GetAttrPool(), pRange);
3768 auto pSet = PropValuesToAutoStyleItemSet(*m_pDocShell->GetDoc(), m_eFamily, Values, aEmptySet);
3770 uno::Reference<style::XAutoStyle> xRet = new SwXAutoStyle(m_pDocShell->GetDoc(), pSet, m_eFamily);
3772 return xRet;
3775 uno::Reference< container::XEnumeration > SwXAutoStyleFamily::createEnumeration( )
3777 if( !m_pDocShell )
3778 throw uno::RuntimeException();
3779 return uno::Reference< container::XEnumeration >
3780 (new SwXAutoStylesEnumerator( *m_pDocShell->GetDoc(), m_eFamily ));
3783 uno::Type SwXAutoStyleFamily::getElementType( )
3785 return cppu::UnoType<style::XAutoStyle>::get();
3788 sal_Bool SwXAutoStyleFamily::hasElements( )
3790 return false;
3793 SwAutoStylesEnumImpl::SwAutoStylesEnumImpl( SwDoc& rInitDoc, IStyleAccess::SwAutoStyleFamily eFam )
3794 : m_rDoc( rInitDoc ), m_eFamily( eFam )
3796 // special case for ruby auto styles:
3797 if ( IStyleAccess::AUTO_STYLE_RUBY == eFam )
3799 std::set< std::pair< sal_uInt16, text::RubyAdjust > > aRubyMap;
3800 SwAttrPool& rAttrPool = m_rDoc.GetAttrPool();
3802 // do this in two phases otherwise we invalidate the iterators when we insert into the pool
3803 std::vector<const SwFormatRuby*> vRubyItems;
3804 for (const SfxPoolItem* pItem : rAttrPool.GetItemSurrogates(RES_TXTATR_CJK_RUBY))
3806 auto pRubyItem = dynamic_cast<const SwFormatRuby*>(pItem);
3807 if ( pRubyItem && pRubyItem->GetTextRuby() )
3808 vRubyItems.push_back(pRubyItem);
3810 for (const SwFormatRuby* pRubyItem : vRubyItems)
3812 std::pair< sal_uInt16, text::RubyAdjust > aPair( pRubyItem->GetPosition(), pRubyItem->GetAdjustment() );
3813 if ( aRubyMap.insert( aPair ).second )
3815 auto pItemSet = std::make_shared<SfxItemSetFixed<RES_TXTATR_CJK_RUBY, RES_TXTATR_CJK_RUBY>>( rAttrPool );
3816 pItemSet->Put( *pRubyItem );
3817 mAutoStyles.push_back( pItemSet );
3821 else
3823 m_rDoc.GetIStyleAccess().getAllStyles( mAutoStyles, m_eFamily );
3826 m_aIter = mAutoStyles.begin();
3829 SwXAutoStylesEnumerator::SwXAutoStylesEnumerator( SwDoc& rDoc, IStyleAccess::SwAutoStyleFamily eFam )
3830 : m_pImpl( new SwAutoStylesEnumImpl( rDoc, eFam ) )
3832 // Register ourselves as a listener to the document (via the page descriptor)
3833 StartListening(rDoc.getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier());
3836 SwXAutoStylesEnumerator::~SwXAutoStylesEnumerator()
3840 void SwXAutoStylesEnumerator::Notify( const SfxHint& rHint)
3842 if(rHint.GetId() == SfxHintId::Dying)
3843 m_pImpl.reset();
3846 sal_Bool SwXAutoStylesEnumerator::hasMoreElements( )
3848 if( !m_pImpl )
3849 throw uno::RuntimeException();
3850 return m_pImpl->hasMoreElements();
3853 uno::Any SwXAutoStylesEnumerator::nextElement( )
3855 if( !m_pImpl )
3856 throw uno::RuntimeException();
3857 uno::Any aRet;
3858 if( m_pImpl->hasMoreElements() )
3860 std::shared_ptr<SfxItemSet> pNextSet = m_pImpl->nextElement();
3861 uno::Reference< style::XAutoStyle > xAutoStyle = new SwXAutoStyle(&m_pImpl->getDoc(),
3862 pNextSet, m_pImpl->getFamily());
3863 aRet <<= xAutoStyle;
3865 return aRet;
3868 // SwXAutoStyle with the family IStyleAccess::AUTO_STYLE_PARA (or
3869 // PROPERTY_MAP_PARA_AUTO_STYLE) now uses DrawingLayer FillStyles to allow
3870 // unified paragraph background fill, thus the UNO API implementation has to
3871 // support the needed slots for these. This seems to be used only for reading
3872 // (no setPropertyValue implementation here), so maybe specialized for saving
3873 // the Writer Doc to ODF
3875 SwXAutoStyle::SwXAutoStyle(
3876 SwDoc* pDoc,
3877 std::shared_ptr<SfxItemSet> pInitSet,
3878 IStyleAccess::SwAutoStyleFamily eFam)
3879 : mpSet(std::move(pInitSet)),
3880 meFamily(eFam),
3881 mrDoc(*pDoc)
3883 // Register ourselves as a listener to the document (via the page descriptor)
3884 //StartListening(mrDoc.getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier());
3887 SwXAutoStyle::~SwXAutoStyle()
3891 void SwXAutoStyle::Notify(const SfxHint& rHint)
3893 if(rHint.GetId() == SfxHintId::Dying)
3894 mpSet.reset();
3897 uno::Reference< beans::XPropertySetInfo > SwXAutoStyle::getPropertySetInfo( )
3899 uno::Reference< beans::XPropertySetInfo > xRet;
3900 switch( meFamily )
3902 case IStyleAccess::AUTO_STYLE_CHAR:
3904 static const auto xCharRef = aSwMapProvider.GetPropertySet(PROPERTY_MAP_CHAR_AUTO_STYLE)->getPropertySetInfo();
3905 xRet = xCharRef;
3907 break;
3908 case IStyleAccess::AUTO_STYLE_RUBY:
3910 static const auto xRubyRef = aSwMapProvider.GetPropertySet(PROPERTY_MAP_RUBY_AUTO_STYLE)->getPropertySetInfo();
3911 xRet = xRubyRef;
3913 break;
3914 case IStyleAccess::AUTO_STYLE_PARA:
3916 static const auto xParaRef = aSwMapProvider.GetPropertySet(PROPERTY_MAP_PARA_AUTO_STYLE)->getPropertySetInfo();
3917 xRet = xParaRef;
3919 break;
3921 default:
3925 return xRet;
3928 void SwXAutoStyle::setPropertyValue( const OUString& /*rPropertyName*/, const uno::Any& /*rValue*/ )
3932 uno::Any SwXAutoStyle::getPropertyValue( const OUString& rPropertyName )
3934 SolarMutexGuard aGuard;
3935 const uno::Sequence<OUString> aProperties(&rPropertyName, 1);
3936 return GetPropertyValues_Impl(aProperties).getConstArray()[0];
3939 void SwXAutoStyle::addPropertyChangeListener( const OUString& /*aPropertyName*/,
3940 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
3944 void SwXAutoStyle::removePropertyChangeListener( const OUString& /*aPropertyName*/,
3945 const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
3949 void SwXAutoStyle::addVetoableChangeListener( const OUString& /*PropertyName*/,
3950 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
3954 void SwXAutoStyle::removeVetoableChangeListener( const OUString& /*PropertyName*/,
3955 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
3959 void SwXAutoStyle::setPropertyValues(
3960 const uno::Sequence< OUString >& /*aPropertyNames*/,
3961 const uno::Sequence< uno::Any >& /*aValues*/ )
3965 uno::Sequence< uno::Any > SwXAutoStyle::GetPropertyValues_Impl(
3966 const uno::Sequence< OUString > & rPropertyNames )
3968 if( !mpSet )
3970 throw uno::RuntimeException();
3973 // query_item
3974 sal_Int8 nPropSetId = PROPERTY_MAP_CHAR_AUTO_STYLE;
3975 switch(meFamily)
3977 case IStyleAccess::AUTO_STYLE_CHAR : nPropSetId = PROPERTY_MAP_CHAR_AUTO_STYLE; break;
3978 case IStyleAccess::AUTO_STYLE_RUBY : nPropSetId = PROPERTY_MAP_RUBY_AUTO_STYLE; break;
3979 case IStyleAccess::AUTO_STYLE_PARA : nPropSetId = PROPERTY_MAP_PARA_AUTO_STYLE; break;
3980 default: ;
3983 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
3984 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
3985 const OUString* pNames = rPropertyNames.getConstArray();
3987 const sal_Int32 nLen(rPropertyNames.getLength());
3988 uno::Sequence< uno::Any > aRet( nLen );
3989 uno::Any* pValues = aRet.getArray();
3990 const bool bTakeCareOfDrawingLayerFillStyle(IStyleAccess::AUTO_STYLE_PARA == meFamily);
3992 for( sal_Int32 i = 0; i < nLen; ++i )
3994 const OUString sPropName = pNames[i];
3995 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(sPropName);
3996 if(!pEntry)
3998 throw beans::UnknownPropertyException("Unknown property: " + sPropName, static_cast < cppu::OWeakObject * > ( this ) );
4001 uno::Any aTarget;
4002 bool bDone(false);
4004 if ( RES_TXTATR_AUTOFMT == pEntry->nWID || RES_AUTO_STYLE == pEntry->nWID )
4006 OUString sName(StylePool::nameOf( mpSet ));
4007 aTarget <<= sName;
4008 bDone = true;
4010 else if(bTakeCareOfDrawingLayerFillStyle)
4012 // add support for DrawingLayer FillStyle slots
4013 switch(pEntry->nWID)
4015 case RES_BACKGROUND:
4017 const std::unique_ptr<SvxBrushItem> aOriginalBrushItem(getSvxBrushItemFromSourceSet(*mpSet, RES_BACKGROUND));
4019 if(!aOriginalBrushItem->QueryValue(aTarget, pEntry->nMemberId))
4021 OSL_ENSURE(false, "Error getting attribute from RES_BACKGROUND (!)");
4024 bDone = true;
4025 break;
4027 case OWN_ATTR_FILLBMP_MODE:
4029 if (mpSet->Get(XATTR_FILLBMP_TILE).GetValue())
4031 aTarget <<= drawing::BitmapMode_REPEAT;
4033 else if (mpSet->Get(XATTR_FILLBMP_STRETCH).GetValue())
4035 aTarget <<= drawing::BitmapMode_STRETCH;
4037 else
4039 aTarget <<= drawing::BitmapMode_NO_REPEAT;
4042 bDone = true;
4043 break;
4048 if(!bDone)
4050 pPropSet->getPropertyValue( *pEntry, *mpSet, aTarget );
4053 if(bTakeCareOfDrawingLayerFillStyle)
4055 if(pEntry->aType == cppu::UnoType<sal_Int16>::get() && pEntry->aType != aTarget.getValueType())
4057 // since the sfx uint16 item now exports a sal_Int32, we may have to fix this here
4058 sal_Int32 nValue = 0;
4059 if (aTarget >>= nValue)
4061 aTarget <<= static_cast<sal_Int16>(nValue);
4065 // check for needed metric translation
4066 if(pEntry->nMoreFlags & PropertyMoreFlags::METRIC_ITEM)
4068 bool bDoIt(true);
4070 if(XATTR_FILLBMP_SIZEX == pEntry->nWID || XATTR_FILLBMP_SIZEY == pEntry->nWID)
4072 // exception: If these ItemTypes are used, do not convert when these are negative
4073 // since this means they are intended as percent values
4074 sal_Int32 nValue = 0;
4076 if(aTarget >>= nValue)
4078 bDoIt = nValue > 0;
4082 if(bDoIt)
4084 const SfxItemPool& rPool = mrDoc.GetAttrPool();
4085 const MapUnit eMapUnit(rPool.GetMetric(pEntry->nWID));
4087 if(eMapUnit != MapUnit::Map100thMM)
4089 SvxUnoConvertToMM(eMapUnit, aTarget);
4095 // add value
4096 pValues[i] = aTarget;
4099 return aRet;
4102 uno::Sequence< uno::Any > SwXAutoStyle::getPropertyValues (
4103 const uno::Sequence< OUString >& rPropertyNames )
4105 SolarMutexGuard aGuard;
4106 uno::Sequence< uno::Any > aValues;
4108 // workaround for bad designed API
4111 aValues = GetPropertyValues_Impl( rPropertyNames );
4113 catch (beans::UnknownPropertyException &)
4115 css::uno::Any exc = cppu::getCaughtException();
4116 throw lang::WrappedTargetRuntimeException("Unknown property exception caught", static_cast < cppu::OWeakObject * > ( this ), exc );
4118 catch (lang::WrappedTargetException &)
4120 css::uno::Any exc = cppu::getCaughtException();
4121 throw lang::WrappedTargetRuntimeException("WrappedTargetException caught", static_cast < cppu::OWeakObject * > ( this ), exc );
4124 return aValues;
4127 void SwXAutoStyle::addPropertiesChangeListener(
4128 const uno::Sequence< OUString >& /*aPropertyNames*/,
4129 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
4133 void SwXAutoStyle::removePropertiesChangeListener(
4134 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
4138 void SwXAutoStyle::firePropertiesChangeEvent(
4139 const uno::Sequence< OUString >& /*aPropertyNames*/,
4140 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
4144 beans::PropertyState SwXAutoStyle::getPropertyState( const OUString& rPropertyName )
4146 SolarMutexGuard aGuard;
4148 uno::Sequence< OUString > aNames { rPropertyName };
4149 uno::Sequence< beans::PropertyState > aStates = getPropertyStates(aNames);
4150 return aStates.getConstArray()[0];
4153 void SwXAutoStyle::setPropertyToDefault( const OUString& /*PropertyName*/ )
4157 uno::Any SwXAutoStyle::getPropertyDefault( const OUString& rPropertyName )
4159 const uno::Sequence < OUString > aSequence ( &rPropertyName, 1 );
4160 return getPropertyDefaults ( aSequence ).getConstArray()[0];
4163 uno::Sequence< beans::PropertyState > SwXAutoStyle::getPropertyStates(
4164 const uno::Sequence< OUString >& rPropertyNames )
4166 if (!mpSet)
4168 throw uno::RuntimeException();
4171 SolarMutexGuard aGuard;
4172 uno::Sequence< beans::PropertyState > aRet(rPropertyNames.getLength());
4173 beans::PropertyState* pStates = aRet.getArray();
4174 const OUString* pNames = rPropertyNames.getConstArray();
4176 sal_Int8 nPropSetId = PROPERTY_MAP_CHAR_AUTO_STYLE;
4177 switch(meFamily)
4179 case IStyleAccess::AUTO_STYLE_CHAR : nPropSetId = PROPERTY_MAP_CHAR_AUTO_STYLE; break;
4180 case IStyleAccess::AUTO_STYLE_RUBY : nPropSetId = PROPERTY_MAP_RUBY_AUTO_STYLE; break;
4181 case IStyleAccess::AUTO_STYLE_PARA : nPropSetId = PROPERTY_MAP_PARA_AUTO_STYLE; break;
4182 default: ;
4185 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
4186 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
4187 const bool bTakeCareOfDrawingLayerFillStyle(IStyleAccess::AUTO_STYLE_PARA == meFamily);
4189 for(sal_Int32 i = 0; i < rPropertyNames.getLength(); i++)
4191 const OUString sPropName = pNames[i];
4192 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(sPropName);
4193 if(!pEntry)
4195 throw beans::UnknownPropertyException("Unknown property: " + sPropName, static_cast < cppu::OWeakObject * > ( this ) );
4198 bool bDone(false);
4200 if(bTakeCareOfDrawingLayerFillStyle)
4202 // DrawingLayer PropertyStyle support
4203 switch(pEntry->nWID)
4205 case OWN_ATTR_FILLBMP_MODE:
4207 if(SfxItemState::SET == mpSet->GetItemState(XATTR_FILLBMP_STRETCH, false)
4208 || SfxItemState::SET == mpSet->GetItemState(XATTR_FILLBMP_TILE, false))
4210 pStates[i] = beans::PropertyState_DIRECT_VALUE;
4212 else
4214 pStates[i] = beans::PropertyState_AMBIGUOUS_VALUE;
4217 bDone = true;
4218 break;
4220 case RES_BACKGROUND:
4222 if (SWUnoHelper::needToMapFillItemsToSvxBrushItemTypes(*mpSet,
4223 pEntry->nMemberId))
4225 pStates[i] = beans::PropertyState_DIRECT_VALUE;
4227 else
4229 pStates[i] = beans::PropertyState_DEFAULT_VALUE;
4231 bDone = true;
4233 break;
4238 if(!bDone)
4240 pStates[i] = pPropSet->getPropertyState(*pEntry, *mpSet );
4244 return aRet;
4247 void SwXAutoStyle::setAllPropertiesToDefault( )
4251 void SwXAutoStyle::setPropertiesToDefault(
4252 const uno::Sequence< OUString >& /*rPropertyNames*/ )
4256 uno::Sequence< uno::Any > SwXAutoStyle::getPropertyDefaults(
4257 const uno::Sequence< OUString >& /*aPropertyNames*/ )
4259 return { };
4262 uno::Sequence< beans::PropertyValue > SwXAutoStyle::getProperties()
4264 if( !mpSet )
4265 throw uno::RuntimeException();
4266 SolarMutexGuard aGuard;
4267 std::vector< beans::PropertyValue > aPropertyVector;
4269 sal_Int8 nPropSetId = 0;
4270 switch(meFamily)
4272 case IStyleAccess::AUTO_STYLE_CHAR : nPropSetId = PROPERTY_MAP_CHAR_AUTO_STYLE; break;
4273 case IStyleAccess::AUTO_STYLE_RUBY : nPropSetId = PROPERTY_MAP_RUBY_AUTO_STYLE; break;
4274 case IStyleAccess::AUTO_STYLE_PARA : nPropSetId = PROPERTY_MAP_PARA_AUTO_STYLE; break;
4275 default: ;
4278 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
4279 const SfxItemPropertyMap &rMap = pPropSet->getPropertyMap();
4281 SfxItemSet& rSet = *mpSet;
4282 SfxItemIter aIter(rSet);
4284 for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem())
4286 const sal_uInt16 nWID = pItem->Which();
4288 // TODO: Optimize - and fix! the old iteration filled each WhichId
4289 // only once but there are more properties than WhichIds
4290 for( const auto pEntry : rMap.getPropertyEntries() )
4292 if ( pEntry->nWID == nWID )
4294 beans::PropertyValue aPropertyValue;
4295 aPropertyValue.Name = pEntry->aName;
4296 pItem->QueryValue( aPropertyValue.Value, pEntry->nMemberId );
4297 aPropertyVector.push_back( aPropertyValue );
4302 const sal_Int32 nCount = aPropertyVector.size();
4303 uno::Sequence< beans::PropertyValue > aRet( nCount );
4304 beans::PropertyValue* pProps = aRet.getArray();
4306 for ( int i = 0; i < nCount; ++i, pProps++ )
4308 *pProps = aPropertyVector[i];
4311 return aRet;
4314 SwXTextTableStyle::SwXTextTableStyle(SwDocShell* pDocShell, SwTableAutoFormat* pTableAutoFormat) :
4315 m_pDocShell(pDocShell), m_pTableAutoFormat(pTableAutoFormat), m_bPhysical(true)
4317 UpdateCellStylesMapping();
4320 SwXTextTableStyle::SwXTextTableStyle(SwDocShell* pDocShell, const OUString& rTableAutoFormatName) :
4321 m_pDocShell(pDocShell), m_pTableAutoFormat_Impl(new SwTableAutoFormat(rTableAutoFormatName)), m_bPhysical(false)
4323 m_pTableAutoFormat = m_pTableAutoFormat_Impl.get();
4324 UpdateCellStylesMapping();
4327 uno::Reference<style::XStyle> SwXTextTableStyle::CreateXTextTableStyle(SwDocShell* pDocShell, const OUString& rTableAutoFormatName)
4329 SolarMutexGuard aGuard;
4330 rtl::Reference<SwXTextTableStyle> xTextTableStyle;
4331 SwTableAutoFormat* pAutoFormat = GetTableAutoFormat(pDocShell, rTableAutoFormatName);
4332 if (pAutoFormat && pAutoFormat->GetName() == rTableAutoFormatName)
4334 xTextTableStyle = pAutoFormat->GetXObject();
4335 if (!xTextTableStyle.is())
4337 xTextTableStyle.set(new SwXTextTableStyle(pDocShell, pAutoFormat));
4338 pAutoFormat->SetXObject(xTextTableStyle);
4342 // If corresponding AutoFormat doesn't exist create a non physical style.
4343 if (!xTextTableStyle.is())
4345 xTextTableStyle.set(new SwXTextTableStyle(pDocShell, rTableAutoFormatName));
4346 SAL_INFO("sw.uno", "creating SwXTextTableStyle for non existing SwTableAutoFormat");
4349 return xTextTableStyle;
4352 void SwXTextTableStyle::UpdateCellStylesMapping()
4354 const std::vector<sal_Int32> aTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap();
4355 assert(aTableTemplateMap.size() == STYLE_COUNT && "can not map SwTableAutoFormat to a SwXTextTableStyle");
4356 for (sal_Int32 i=0; i<STYLE_COUNT; ++i)
4358 SwBoxAutoFormat* pBoxFormat = &m_pTableAutoFormat->GetBoxFormat(aTableTemplateMap[i]);
4359 rtl::Reference<SwXTextCellStyle> xCellStyle(pBoxFormat->GetXObject());
4360 if (!xCellStyle.is())
4362 xCellStyle.set(new SwXTextCellStyle(m_pDocShell, pBoxFormat, m_pTableAutoFormat->GetName()));
4363 pBoxFormat->SetXObject(xCellStyle);
4365 m_aCellStyles[i] = xCellStyle;
4369 const CellStyleNameMap& SwXTextTableStyle::GetCellStyleNameMap()
4371 static CellStyleNameMap const aMap
4373 { "first-row" , FIRST_ROW_STYLE },
4374 { "last-row" , LAST_ROW_STYLE },
4375 { "first-column" , FIRST_COLUMN_STYLE },
4376 { "last-column" , LAST_COLUMN_STYLE },
4377 { "body" , BODY_STYLE },
4378 { "even-rows" , EVEN_ROWS_STYLE },
4379 { "odd-rows" , ODD_ROWS_STYLE },
4380 { "even-columns" , EVEN_COLUMNS_STYLE },
4381 { "odd-columns" , ODD_COLUMNS_STYLE },
4382 { "background" , BACKGROUND_STYLE },
4383 // loext namespace
4384 { "first-row-start-column" , FIRST_ROW_START_COLUMN_STYLE },
4385 { "first-row-end-column" , FIRST_ROW_END_COLUMN_STYLE },
4386 { "last-row-start-column" , LAST_ROW_START_COLUMN_STYLE },
4387 { "last-row-end-column" , LAST_ROW_END_COLUMN_STYLE },
4388 { "first-row-even-column" , FIRST_ROW_EVEN_COLUMN_STYLE },
4389 { "last-row-even-column" , LAST_ROW_EVEN_COLUMN_STYLE },
4391 return aMap;
4394 SwTableAutoFormat* SwXTextTableStyle::GetTableFormat()
4396 return m_pTableAutoFormat;
4399 SwTableAutoFormat* SwXTextTableStyle::GetTableAutoFormat(SwDocShell* pDocShell, std::u16string_view sName)
4401 const size_t nStyles = pDocShell->GetDoc()->GetTableStyles().size();
4402 for(size_t i=0; i < nStyles; ++i)
4404 SwTableAutoFormat* pAutoFormat = &pDocShell->GetDoc()->GetTableStyles()[i];
4405 if (pAutoFormat->GetName() == sName)
4407 return pAutoFormat;
4410 // not found
4411 return nullptr;
4414 void SwXTextTableStyle::SetPhysical()
4416 if (!m_bPhysical)
4418 // find table format in doc
4419 SwTableAutoFormat* pTableAutoFormat = GetTableAutoFormat(m_pDocShell, m_pTableAutoFormat->GetName());
4420 if (pTableAutoFormat)
4422 m_bPhysical = true;
4423 /// take care of children, make SwXTextCellStyles use new core SwBoxAutoFormats
4424 const std::vector<sal_Int32> aTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap();
4425 for (size_t i=0; i<aTableTemplateMap.size(); ++i)
4427 SwBoxAutoFormat* pOldBoxFormat = &m_pTableAutoFormat->GetBoxFormat(aTableTemplateMap[i]);
4428 rtl::Reference<SwXTextCellStyle> xCellStyle(pOldBoxFormat->GetXObject());
4429 if (!xCellStyle.is())
4430 continue;
4431 SwBoxAutoFormat& rNewBoxFormat = pTableAutoFormat->GetBoxFormat(aTableTemplateMap[i]);
4432 xCellStyle->SetBoxFormat(&rNewBoxFormat);
4433 rNewBoxFormat.SetXObject(xCellStyle);
4435 m_pTableAutoFormat_Impl = nullptr;
4436 m_pTableAutoFormat = pTableAutoFormat;
4437 m_pTableAutoFormat->SetXObject(this);
4439 else
4440 SAL_WARN("sw.uno", "setting style physical, but SwTableAutoFormat in document not found");
4442 else
4443 SAL_WARN("sw.uno", "calling SetPhysical on a physical SwXTextTableStyle");
4446 // XStyle
4447 sal_Bool SAL_CALL SwXTextTableStyle::isUserDefined()
4449 SolarMutexGuard aGuard;
4450 // only first style is not user defined
4451 if (m_pDocShell->GetDoc()->GetTableStyles()[0].GetName() == m_pTableAutoFormat->GetName())
4452 return false;
4454 return true;
4457 sal_Bool SAL_CALL SwXTextTableStyle::isInUse()
4459 SolarMutexGuard aGuard;
4460 if (!m_bPhysical)
4461 return false;
4463 SwAutoFormatGetDocNode aGetHt( &m_pDocShell->GetDoc()->GetNodes() );
4465 for (const SwTableFormat* pFormat : *m_pDocShell->GetDoc()->GetTableFrameFormats())
4467 if (!pFormat->GetInfo(aGetHt))
4469 SwTable* pTable = SwTable::FindTable(pFormat);
4470 if (pTable->GetTableStyleName() == m_pTableAutoFormat->GetName())
4471 return true;
4475 return false;
4478 OUString SAL_CALL SwXTextTableStyle::getParentStyle()
4480 return OUString();
4483 void SAL_CALL SwXTextTableStyle::setParentStyle(const OUString& /*aParentStyle*/)
4486 //XNamed
4487 OUString SAL_CALL SwXTextTableStyle::getName()
4489 SolarMutexGuard aGuard;
4490 OUString sProgName;
4491 SwStyleNameMapper::FillProgName(m_pTableAutoFormat->GetName(), sProgName, SwGetPoolIdFromName::TabStyle);
4492 return sProgName;
4495 void SAL_CALL SwXTextTableStyle::setName(const OUString& rName)
4497 SolarMutexGuard aGuard;
4498 m_pTableAutoFormat->SetName(rName);
4501 //XPropertySet
4502 css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL SwXTextTableStyle::getPropertySetInfo()
4504 static uno::Reference<beans::XPropertySetInfo> xRef(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TABLE_STYLE)->getPropertySetInfo());
4505 return xRef;
4508 void SAL_CALL SwXTextTableStyle::setPropertyValue(const OUString& /*rPropertyName*/, const css::uno::Any& /*aValue*/)
4510 SAL_WARN("sw.uno", "not implemented");
4513 css::uno::Any SAL_CALL SwXTextTableStyle::getPropertyValue(const OUString& rPropertyName)
4515 SolarMutexGuard aGuard;
4516 bool bIsRow = false;
4518 if (rPropertyName == UNO_NAME_TABLE_FIRST_ROW_END_COLUMN)
4519 bIsRow = m_pTableAutoFormat->FirstRowEndColumnIsRow();
4520 else if (rPropertyName == UNO_NAME_TABLE_FIRST_ROW_START_COLUMN)
4521 bIsRow = m_pTableAutoFormat->FirstRowStartColumnIsRow();
4522 else if (rPropertyName == UNO_NAME_TABLE_LAST_ROW_END_COLUMN)
4523 bIsRow = m_pTableAutoFormat->LastRowEndColumnIsRow();
4524 else if (rPropertyName == UNO_NAME_TABLE_LAST_ROW_START_COLUMN)
4525 bIsRow = m_pTableAutoFormat->LastRowStartColumnIsRow();
4526 else if (rPropertyName == UNO_NAME_DISPLAY_NAME)
4527 return uno::Any(m_pTableAutoFormat->GetName());
4528 else
4529 throw css::beans::UnknownPropertyException(rPropertyName);
4531 return uno::Any(bIsRow ? OUString("row") : OUString("column"));
4534 void SAL_CALL SwXTextTableStyle::addPropertyChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XPropertyChangeListener >& /*xListener*/ )
4536 SAL_WARN("sw.uno", "not implemented");
4539 void SAL_CALL SwXTextTableStyle::removePropertyChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XPropertyChangeListener >& /*aListener*/ )
4541 SAL_WARN("sw.uno", "not implemented");
4544 void SAL_CALL SwXTextTableStyle::addVetoableChangeListener( const OUString& /*PropertyName*/, const css::uno::Reference< css::beans::XVetoableChangeListener >& /*aListener*/ )
4546 SAL_WARN("sw.uno", "not implemented");
4549 void SAL_CALL SwXTextTableStyle::removeVetoableChangeListener( const OUString& /*PropertyName*/, const css::uno::Reference< css::beans::XVetoableChangeListener >& /*aListener*/ )
4551 SAL_WARN("sw.uno", "not implemented");
4554 //XNameAccess
4555 uno::Any SAL_CALL SwXTextTableStyle::getByName(const OUString& rName)
4557 SolarMutexGuard aGuard;
4558 const CellStyleNameMap& rMap = GetCellStyleNameMap();
4559 CellStyleNameMap::const_iterator iter = rMap.find(rName);
4560 if(iter == rMap.end())
4561 throw css::container::NoSuchElementException();
4563 auto nIdx = (*iter).second;
4564 return css::uno::Any(uno::Reference<XInterface>(static_cast<cppu::OWeakObject*>(m_aCellStyles[nIdx].get())));
4567 css::uno::Sequence<OUString> SAL_CALL SwXTextTableStyle::getElementNames()
4569 return comphelper::mapKeysToSequence(GetCellStyleNameMap());
4572 sal_Bool SAL_CALL SwXTextTableStyle::hasByName(const OUString& rName)
4574 const CellStyleNameMap& rMap = GetCellStyleNameMap();
4575 CellStyleNameMap::const_iterator iter = rMap.find(rName);
4576 return iter != rMap.end();
4579 //XNameContainer
4580 void SAL_CALL SwXTextTableStyle::insertByName(const OUString& /*Name*/, const uno::Any& /*Element*/)
4582 SAL_WARN("sw.uno", "not implemented");
4585 void SAL_CALL SwXTextTableStyle::replaceByName(const OUString& rName, const uno::Any& rElement)
4587 SolarMutexGuard aGuard;
4588 const CellStyleNameMap& rMap = GetCellStyleNameMap();
4589 CellStyleNameMap::const_iterator iter = rMap.find(rName);
4590 if(iter == rMap.end())
4591 throw container::NoSuchElementException();
4592 const sal_Int32 nCellStyle = iter->second;
4594 rtl::Reference<SwXTextCellStyle> xStyleToReplaceWith = dynamic_cast<SwXTextCellStyle*>(rElement.get<uno::Reference<style::XStyle>>().get());
4595 if (!xStyleToReplaceWith.is())
4596 throw lang::IllegalArgumentException();
4598 // replace only with physical ...
4599 if (!xStyleToReplaceWith->IsPhysical())
4600 throw lang::IllegalArgumentException();
4602 const auto& rTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap();
4603 const sal_Int32 nBoxFormat = rTableTemplateMap[nCellStyle];
4605 // move SwBoxAutoFormat to dest. SwTableAutoFormat
4606 m_pTableAutoFormat->SetBoxFormat(*xStyleToReplaceWith->GetBoxFormat(), nBoxFormat);
4607 // remove unassigned SwBoxAutoFormat, which is not anymore in use anyways
4608 m_pDocShell->GetDoc()->GetCellStyles().RemoveBoxFormat(xStyleToReplaceWith->getName());
4609 // make SwXTextCellStyle use new, moved SwBoxAutoFormat
4610 xStyleToReplaceWith->SetBoxFormat(&m_pTableAutoFormat->GetBoxFormat(nBoxFormat));
4611 m_pTableAutoFormat->GetBoxFormat(nBoxFormat).SetXObject(xStyleToReplaceWith);
4612 // make this SwXTextTableStyle use new SwXTextCellStyle
4613 m_aCellStyles[nCellStyle] = xStyleToReplaceWith;
4616 void SAL_CALL SwXTextTableStyle::removeByName(const OUString& /*Name*/)
4618 SAL_WARN("sw.uno", "not implemented");
4621 //XElementAccess
4622 uno::Type SAL_CALL SAL_CALL SwXTextTableStyle::getElementType()
4624 return cppu::UnoType<style::XStyle>::get();
4627 sal_Bool SAL_CALL SAL_CALL SwXTextTableStyle::hasElements()
4629 return true;
4632 //XServiceInfo
4633 OUString SAL_CALL SwXTextTableStyle::getImplementationName()
4635 return {"SwXTextTableStyle"};
4638 sal_Bool SAL_CALL SwXTextTableStyle::supportsService(const OUString& rServiceName)
4640 return cppu::supportsService(this, rServiceName);
4643 css::uno::Sequence<OUString> SAL_CALL SwXTextTableStyle::getSupportedServiceNames()
4645 return {"com.sun.star.style.Style"};
4648 // SwXTextCellStyle
4649 SwXTextCellStyle::SwXTextCellStyle(SwDocShell* pDocShell, SwBoxAutoFormat* pBoxAutoFormat, OUString sParentStyle) :
4650 m_pDocShell(pDocShell),
4651 m_pBoxAutoFormat(pBoxAutoFormat),
4652 m_sParentStyle(std::move(sParentStyle)),
4653 m_bPhysical(true)
4656 SwXTextCellStyle::SwXTextCellStyle(SwDocShell* pDocShell, OUString sName) :
4657 m_pDocShell(pDocShell),
4658 m_pBoxAutoFormat_Impl(std::make_shared<SwBoxAutoFormat>()),
4659 m_sName(std::move(sName)),
4660 m_bPhysical(false)
4662 m_pBoxAutoFormat = m_pBoxAutoFormat_Impl.get();
4665 SwBoxAutoFormat* SwXTextCellStyle::GetBoxFormat()
4667 return m_pBoxAutoFormat;
4670 void SwXTextCellStyle::SetBoxFormat(SwBoxAutoFormat* pBoxFormat)
4672 if (m_bPhysical)
4673 m_pBoxAutoFormat = pBoxFormat;
4674 else
4675 SAL_INFO("sw.uno", "trying to call SwXTextCellStyle::SetBoxFormat on non physical style");
4678 void SwXTextCellStyle::SetPhysical()
4680 if (!m_bPhysical)
4682 SwBoxAutoFormat* pBoxAutoFormat = GetBoxAutoFormat(m_pDocShell, m_sName, &m_sParentStyle);
4683 if (pBoxAutoFormat)
4685 m_bPhysical = true;
4686 m_pBoxAutoFormat_Impl = nullptr;
4687 m_pBoxAutoFormat = pBoxAutoFormat;
4688 m_pBoxAutoFormat->SetXObject(this);
4690 else
4691 SAL_WARN("sw.uno", "setting style physical, but SwBoxAutoFormat in document not found");
4693 else
4694 SAL_WARN("sw.uno", "calling SetPhysical on a physical SwXTextCellStyle");
4697 bool SwXTextCellStyle::IsPhysical() const
4699 return m_bPhysical;
4702 SwBoxAutoFormat* SwXTextCellStyle::GetBoxAutoFormat(SwDocShell* pDocShell, std::u16string_view sName, OUString* pParentName)
4704 if (sName.empty())
4705 return nullptr;
4707 SwBoxAutoFormat* pBoxAutoFormat = pDocShell->GetDoc()->GetCellStyles().GetBoxFormat(sName);
4708 if (!pBoxAutoFormat)
4710 sal_Int32 nTemplateIndex;
4711 OUString sParentName;
4712 std::u16string_view sCellSubName;
4714 size_t nSeparatorIndex = sName.rfind('.');
4715 if (nSeparatorIndex == std::u16string_view::npos)
4716 return nullptr;
4718 sParentName = sName.substr(0, nSeparatorIndex);
4719 sCellSubName = sName.substr(nSeparatorIndex+1);
4720 nTemplateIndex = o3tl::toInt32(sCellSubName)-1; // -1 because cell styles names start from 1, but internally are indexed from 0
4721 if (0 > nTemplateIndex)
4722 return nullptr;
4724 const auto& rTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap();
4725 if (rTableTemplateMap.size() <= o3tl::make_unsigned(nTemplateIndex))
4726 return nullptr;
4728 SwStyleNameMapper::FillUIName(sParentName, sParentName, SwGetPoolIdFromName::TabStyle);
4729 SwTableAutoFormat* pTableAutoFormat = pDocShell->GetDoc()->GetTableStyles().FindAutoFormat(sParentName);
4730 if (!pTableAutoFormat)
4731 return nullptr;
4733 if (pParentName)
4734 *pParentName = sParentName;
4735 sal_uInt32 nBoxIndex = rTableTemplateMap[nTemplateIndex];
4736 pBoxAutoFormat = &pTableAutoFormat->GetBoxFormat(nBoxIndex);
4739 return pBoxAutoFormat;
4742 css::uno::Reference<css::style::XStyle> SwXTextCellStyle::CreateXTextCellStyle(SwDocShell* pDocShell, const OUString& sName)
4744 rtl::Reference<SwXTextCellStyle> xTextCellStyle;
4746 if (!sName.isEmpty()) // create a cell style for a physical box
4748 OUString sParentName;
4749 SwBoxAutoFormat* pBoxFormat = GetBoxAutoFormat(pDocShell, sName, &sParentName);
4751 // something went wrong but we don't want a crash
4752 if (!pBoxFormat)
4754 // return a default-dummy style to prevent crash
4755 static SwBoxAutoFormat aDefaultBoxFormat;
4756 pBoxFormat = &aDefaultBoxFormat;
4759 xTextCellStyle = pBoxFormat->GetXObject();
4760 if (!xTextCellStyle.is())
4762 xTextCellStyle.set(new SwXTextCellStyle(pDocShell, pBoxFormat, sParentName));
4763 pBoxFormat->SetXObject(xTextCellStyle);
4766 else // create a non physical style
4767 xTextCellStyle.set(new SwXTextCellStyle(pDocShell, sName));
4769 return xTextCellStyle;
4772 // XStyle
4773 sal_Bool SAL_CALL SwXTextCellStyle::isUserDefined()
4775 SolarMutexGuard aGuard;
4776 // if this cell belong to first table style then its default style
4777 if (&m_pDocShell->GetDoc()->GetTableStyles()[0] == m_pDocShell->GetDoc()->GetTableStyles().FindAutoFormat(m_sParentStyle))
4778 return false;
4780 return true;
4783 sal_Bool SAL_CALL SwXTextCellStyle::isInUse()
4785 SolarMutexGuard aGuard;
4786 uno::Reference<style::XStyleFamiliesSupplier> xFamiliesSupplier(m_pDocShell->GetModel(), uno::UNO_QUERY);
4787 if (!xFamiliesSupplier.is())
4788 return false;
4790 uno::Reference<container::XNameAccess> xFamilies = xFamiliesSupplier->getStyleFamilies();
4791 if (!xFamilies.is())
4792 return false;
4794 uno::Reference<container::XNameAccess> xTableStyles;
4795 xFamilies->getByName("TableStyles") >>= xTableStyles;
4796 if (!xTableStyles.is())
4797 return false;
4799 uno::Reference<style::XStyle> xStyle;
4800 xTableStyles->getByName(m_sParentStyle) >>= xStyle;
4801 if (!xStyle.is())
4802 return false;
4804 return xStyle->isInUse();
4807 OUString SAL_CALL SwXTextCellStyle::getParentStyle()
4809 // Do not return name of the parent (which is a table style) because the parent should be a cell style.
4810 return OUString();
4813 void SAL_CALL SwXTextCellStyle::setParentStyle(const OUString& /*sParentStyle*/)
4815 // Changing parent to one which is unaware of it will lead to a something unexpected. getName() rely on a parent.
4816 SAL_INFO("sw.uno", "Changing SwXTextCellStyle parent");
4819 //XNamed
4820 OUString SAL_CALL SwXTextCellStyle::getName()
4822 SolarMutexGuard aGuard;
4823 OUString sName;
4825 // if style is physical then we request a name from doc
4826 if (m_bPhysical)
4828 SwTableAutoFormat* pTableFormat = m_pDocShell->GetDoc()->GetTableStyles().FindAutoFormat(m_sParentStyle);
4829 if (!pTableFormat)
4831 // if auto format is not found as a child of table formats, look in SwDoc cellstyles
4832 sName = m_pDocShell->GetDoc()->GetCellStyles().GetBoxFormatName(*m_pBoxAutoFormat);
4834 else
4836 OUString sParentStyle;
4837 SwStyleNameMapper::FillProgName(m_sParentStyle, sParentStyle, SwGetPoolIdFromName::TabStyle);
4838 sName = sParentStyle + pTableFormat->GetTableTemplateCellSubName(*m_pBoxAutoFormat);
4841 else
4842 sName = m_sName;
4844 return sName;
4847 void SAL_CALL SwXTextCellStyle::setName(const OUString& sName)
4849 SolarMutexGuard aGuard;
4850 // if style is physical then we can not rename it.
4851 if (!m_bPhysical)
4852 m_sName = sName;
4853 // change name if style is unassigned (name is not generated automatically)
4854 m_pDocShell->GetDoc()->GetCellStyles().ChangeBoxFormatName(getName(), sName);
4857 //XPropertySet
4858 css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL SwXTextCellStyle::getPropertySetInfo()
4860 static uno::Reference<beans::XPropertySetInfo> xRef(aSwMapProvider.GetPropertySet(PROPERTY_MAP_CELL_STYLE)->getPropertySetInfo());
4861 return xRef;
4864 void SAL_CALL SwXTextCellStyle::setPropertyValue(const OUString& rPropertyName, const css::uno::Any& aValue)
4866 SolarMutexGuard aGuard;
4867 const SfxItemPropertyMapEntry *const pEntry = aSwMapProvider.GetPropertySet(PROPERTY_MAP_CELL_STYLE)->getPropertyMap().getByName(rPropertyName);
4868 if(pEntry)
4870 switch(pEntry->nWID)
4872 case RES_BACKGROUND:
4874 SvxBrushItem rBrush = m_pBoxAutoFormat->GetBackground();
4875 rBrush.PutValue(aValue, 0);
4876 m_pBoxAutoFormat->SetBackground(rBrush);
4877 return;
4879 case RES_BOX:
4881 SvxBoxItem rBox = m_pBoxAutoFormat->GetBox();
4882 rBox.PutValue(aValue, pEntry->nMemberId);
4883 m_pBoxAutoFormat->SetBox(rBox);
4884 return;
4886 case RES_VERT_ORIENT:
4888 SwFormatVertOrient rVertOrient = m_pBoxAutoFormat->GetVerticalAlignment();
4889 rVertOrient.PutValue(aValue, pEntry->nMemberId);
4890 m_pBoxAutoFormat->SetVerticalAlignment(rVertOrient);
4891 return;
4893 case RES_FRAMEDIR:
4895 SvxFrameDirectionItem rDirItem = m_pBoxAutoFormat->GetTextOrientation();
4896 rDirItem.PutValue(aValue, pEntry->nMemberId);
4897 m_pBoxAutoFormat->SetTextOrientation(rDirItem);
4898 return;
4900 case RES_BOXATR_FORMAT:
4902 sal_uInt32 nKey;
4903 if (aValue >>= nKey)
4905 // FIXME: It's not working for old "automatic" currency formats, which are still in use by autotbl.fmt.
4906 // Scenario:
4907 // 1) Mark all styles present by default in autotbl.fmt as default.
4908 // 2) convert all currencies present in autotbl.fmt before calling this code
4909 const SvNumberformat* pNumFormat = m_pDocShell->GetDoc()->GetNumberFormatter()->GetEntry(nKey);
4910 if (pNumFormat)
4911 m_pBoxAutoFormat->SetValueFormat(pNumFormat->GetFormatstring(), pNumFormat->GetLanguage(), GetAppLanguage());
4913 return;
4915 // Paragraph attributes
4916 case RES_PARATR_ADJUST:
4918 SvxAdjustItem rAdjustItem = m_pBoxAutoFormat->GetAdjust();
4919 rAdjustItem.PutValue(aValue, pEntry->nMemberId);
4920 m_pBoxAutoFormat->SetAdjust(rAdjustItem);
4921 return;
4923 case RES_CHRATR_COLOR:
4925 SvxColorItem rColorItem = m_pBoxAutoFormat->GetColor();
4926 rColorItem.PutValue(aValue, pEntry->nMemberId);
4927 m_pBoxAutoFormat->SetColor(rColorItem);
4928 return;
4930 case RES_CHRATR_SHADOWED:
4932 SvxShadowedItem rShadowedItem = m_pBoxAutoFormat->GetShadowed();
4933 bool bValue = false; aValue >>= bValue;
4934 rShadowedItem.SetValue(bValue);
4935 m_pBoxAutoFormat->SetShadowed(rShadowedItem);
4936 return;
4938 case RES_CHRATR_CONTOUR:
4940 SvxContourItem rContourItem = m_pBoxAutoFormat->GetContour();
4941 bool bValue = false; aValue >>= bValue;
4942 rContourItem.SetValue(bValue);
4943 m_pBoxAutoFormat->SetContour(rContourItem);
4944 return;
4946 case RES_CHRATR_CROSSEDOUT:
4948 SvxCrossedOutItem rCrossedOutItem = m_pBoxAutoFormat->GetCrossedOut();
4949 rCrossedOutItem.PutValue(aValue, pEntry->nMemberId);
4950 m_pBoxAutoFormat->SetCrossedOut(rCrossedOutItem);
4951 return;
4953 case RES_CHRATR_UNDERLINE:
4955 SvxUnderlineItem rUnderlineItem = m_pBoxAutoFormat->GetUnderline();
4956 rUnderlineItem.PutValue(aValue, pEntry->nMemberId);
4957 m_pBoxAutoFormat->SetUnderline(rUnderlineItem);
4958 return;
4960 case RES_CHRATR_FONTSIZE:
4962 SvxFontHeightItem rFontHeightItem = m_pBoxAutoFormat->GetHeight();
4963 rFontHeightItem.PutValue(aValue, pEntry->nMemberId);
4964 m_pBoxAutoFormat->SetHeight(rFontHeightItem);
4965 return;
4967 case RES_CHRATR_WEIGHT:
4969 SvxWeightItem rWeightItem = m_pBoxAutoFormat->GetWeight();
4970 rWeightItem.PutValue(aValue, pEntry->nMemberId);
4971 m_pBoxAutoFormat->SetWeight(rWeightItem);
4972 return;
4974 case RES_CHRATR_POSTURE:
4976 SvxPostureItem rPostureItem = m_pBoxAutoFormat->GetPosture();
4977 rPostureItem.PutValue(aValue, pEntry->nMemberId);
4978 m_pBoxAutoFormat->SetPosture(rPostureItem);
4979 return;
4981 case RES_CHRATR_FONT:
4983 SvxFontItem rFontItem = m_pBoxAutoFormat->GetFont();
4984 rFontItem.PutValue(aValue, pEntry->nMemberId);
4985 m_pBoxAutoFormat->SetFont(rFontItem);
4986 return;
4988 case RES_CHRATR_CJK_FONTSIZE:
4990 SvxFontHeightItem rFontHeightItem = m_pBoxAutoFormat->GetCJKHeight();
4991 rFontHeightItem.PutValue(aValue, pEntry->nMemberId);
4992 m_pBoxAutoFormat->SetCJKHeight(rFontHeightItem);
4993 return;
4995 case RES_CHRATR_CJK_WEIGHT:
4997 SvxWeightItem rWeightItem = m_pBoxAutoFormat->GetCJKWeight();
4998 rWeightItem.PutValue(aValue, pEntry->nMemberId);
4999 m_pBoxAutoFormat->SetCJKWeight(rWeightItem);
5000 return;
5002 case RES_CHRATR_CJK_POSTURE:
5004 SvxPostureItem rPostureItem = m_pBoxAutoFormat->GetCJKPosture();
5005 rPostureItem.PutValue(aValue, pEntry->nMemberId);
5006 m_pBoxAutoFormat->SetCJKPosture(rPostureItem);
5007 return;
5009 case RES_CHRATR_CJK_FONT:
5011 SvxFontItem rFontItem = m_pBoxAutoFormat->GetCJKFont();
5012 rFontItem.PutValue(aValue, pEntry->nMemberId);
5013 m_pBoxAutoFormat->SetCJKFont(rFontItem);
5014 return;
5016 case RES_CHRATR_CTL_FONTSIZE:
5018 SvxFontHeightItem rFontHeightItem = m_pBoxAutoFormat->GetCTLHeight();
5019 rFontHeightItem.PutValue(aValue, pEntry->nMemberId);
5020 m_pBoxAutoFormat->SetCTLHeight(rFontHeightItem);
5021 return;
5023 case RES_CHRATR_CTL_WEIGHT:
5025 SvxWeightItem rWeightItem = m_pBoxAutoFormat->GetCTLWeight();
5026 rWeightItem.PutValue(aValue, pEntry->nMemberId);
5027 m_pBoxAutoFormat->SetCTLWeight(rWeightItem);
5028 return;
5030 case RES_CHRATR_CTL_POSTURE:
5032 SvxPostureItem rPostureItem = m_pBoxAutoFormat->GetCTLPosture();
5033 rPostureItem.PutValue(aValue, pEntry->nMemberId);
5034 m_pBoxAutoFormat->SetCTLPosture(rPostureItem);
5035 return;
5037 case RES_CHRATR_CTL_FONT:
5039 SvxFontItem rFontItem = m_pBoxAutoFormat->GetCTLFont();
5040 rFontItem.PutValue(aValue, pEntry->nMemberId);
5041 m_pBoxAutoFormat->SetCTLFont(rFontItem);
5042 return;
5044 default:
5045 SAL_WARN("sw.uno", "SwXTextCellStyle unknown nWID");
5046 throw css::uno::RuntimeException();
5050 throw css::beans::UnknownPropertyException(rPropertyName);
5053 css::uno::Any SAL_CALL SwXTextCellStyle::getPropertyValue(const OUString& rPropertyName)
5055 SolarMutexGuard aGuard;
5056 uno::Any aRet;
5057 const SfxItemPropertyMapEntry *const pEntry = aSwMapProvider.GetPropertySet(PROPERTY_MAP_CELL_STYLE)->getPropertyMap().getByName(rPropertyName);
5058 if(pEntry)
5060 switch(pEntry->nWID)
5062 case RES_BACKGROUND:
5064 const SvxBrushItem& rBrush = m_pBoxAutoFormat->GetBackground();
5065 rBrush.QueryValue(aRet);
5066 return aRet;
5068 case RES_BOX:
5070 const SvxBoxItem& rBox = m_pBoxAutoFormat->GetBox();
5071 rBox.QueryValue(aRet, pEntry->nMemberId);
5072 return aRet;
5074 case RES_VERT_ORIENT:
5076 const SwFormatVertOrient& rVertOrient = m_pBoxAutoFormat->GetVerticalAlignment();
5077 rVertOrient.QueryValue(aRet, pEntry->nMemberId);
5078 return aRet;
5080 case RES_FRAMEDIR:
5082 const SvxFrameDirectionItem& rDirItem = m_pBoxAutoFormat->GetTextOrientation();
5083 rDirItem.QueryValue(aRet, pEntry->nMemberId);
5084 return aRet;
5086 case RES_BOXATR_FORMAT:
5088 OUString sFormat;
5089 LanguageType eLng, eSys;
5090 m_pBoxAutoFormat->GetValueFormat(sFormat, eLng, eSys);
5091 if(!sFormat.isEmpty())
5093 SvNumFormatType nType; bool bNew; sal_Int32 nCheckPos;
5094 sal_uInt32 nKey = m_pDocShell->GetDoc()->GetNumberFormatter()->GetIndexPuttingAndConverting(sFormat, eLng, eSys, nType, bNew, nCheckPos);
5095 aRet <<= nKey;
5097 return aRet;
5099 // Paragraph attributes
5100 case RES_PARATR_ADJUST:
5102 const SvxAdjustItem& rAdjustItem = m_pBoxAutoFormat->GetAdjust();
5103 rAdjustItem.QueryValue(aRet, pEntry->nMemberId);
5104 return aRet;
5106 case RES_CHRATR_COLOR:
5108 const SvxColorItem& rColorItem = m_pBoxAutoFormat->GetColor();
5109 rColorItem.QueryValue(aRet, pEntry->nMemberId);
5110 return aRet;
5112 case RES_CHRATR_SHADOWED:
5114 const SvxShadowedItem& rShadowedItem = m_pBoxAutoFormat->GetShadowed();
5115 aRet <<= rShadowedItem.GetValue();
5116 return aRet;
5118 case RES_CHRATR_CONTOUR:
5120 const SvxContourItem& rContourItem = m_pBoxAutoFormat->GetContour();
5121 aRet <<= rContourItem.GetValue();
5122 return aRet;
5124 case RES_CHRATR_CROSSEDOUT:
5126 const SvxCrossedOutItem& rCrossedOutItem = m_pBoxAutoFormat->GetCrossedOut();
5127 rCrossedOutItem.QueryValue(aRet, pEntry->nMemberId);
5128 return aRet;
5130 case RES_CHRATR_UNDERLINE:
5132 const SvxUnderlineItem& rUnderlineItem = m_pBoxAutoFormat->GetUnderline();
5133 rUnderlineItem.QueryValue(aRet, pEntry->nMemberId);
5134 return aRet;
5136 case RES_CHRATR_FONTSIZE:
5138 const SvxFontHeightItem& rFontHeightItem = m_pBoxAutoFormat->GetHeight();
5139 rFontHeightItem.QueryValue(aRet, pEntry->nMemberId);
5140 return aRet;
5142 case RES_CHRATR_WEIGHT:
5144 const SvxWeightItem& rWeightItem = m_pBoxAutoFormat->GetWeight();
5145 rWeightItem.QueryValue(aRet, pEntry->nMemberId);
5146 return aRet;
5148 case RES_CHRATR_POSTURE:
5150 const SvxPostureItem& rPostureItem = m_pBoxAutoFormat->GetPosture();
5151 rPostureItem.QueryValue(aRet, pEntry->nMemberId);
5152 return aRet;
5154 case RES_CHRATR_FONT:
5156 const SvxFontItem rFontItem = m_pBoxAutoFormat->GetFont();
5157 rFontItem.QueryValue(aRet, pEntry->nMemberId);
5158 return aRet;
5160 case RES_CHRATR_CJK_FONTSIZE:
5162 const SvxFontHeightItem rFontHeightItem = m_pBoxAutoFormat->GetCJKHeight();
5163 rFontHeightItem.QueryValue(aRet, pEntry->nMemberId);
5164 return aRet;
5166 case RES_CHRATR_CJK_WEIGHT:
5168 const SvxWeightItem& rWeightItem = m_pBoxAutoFormat->GetCJKWeight();
5169 rWeightItem.QueryValue(aRet, pEntry->nMemberId);
5170 return aRet;
5172 case RES_CHRATR_CJK_POSTURE:
5174 const SvxPostureItem& rPostureItem = m_pBoxAutoFormat->GetCJKPosture();
5175 rPostureItem.QueryValue(aRet, pEntry->nMemberId);
5176 return aRet;
5178 case RES_CHRATR_CJK_FONT:
5180 const SvxFontItem rFontItem = m_pBoxAutoFormat->GetCJKFont();
5181 rFontItem.QueryValue(aRet, pEntry->nMemberId);
5182 return aRet;
5184 case RES_CHRATR_CTL_FONTSIZE:
5186 const SvxFontHeightItem rFontHeightItem = m_pBoxAutoFormat->GetCTLHeight();
5187 rFontHeightItem.QueryValue(aRet, pEntry->nMemberId);
5188 return aRet;
5190 case RES_CHRATR_CTL_WEIGHT:
5192 const SvxWeightItem& rWeightItem = m_pBoxAutoFormat->GetCTLWeight();
5193 rWeightItem.QueryValue(aRet, pEntry->nMemberId);
5194 return aRet;
5196 case RES_CHRATR_CTL_POSTURE:
5198 const SvxPostureItem& rPostureItem = m_pBoxAutoFormat->GetCTLPosture();
5199 rPostureItem.QueryValue(aRet, pEntry->nMemberId);
5200 return aRet;
5202 case RES_CHRATR_CTL_FONT:
5204 const SvxFontItem rFontItem = m_pBoxAutoFormat->GetCTLFont();
5205 rFontItem.QueryValue(aRet, pEntry->nMemberId);
5206 return aRet;
5208 default:
5209 SAL_WARN("sw.uno", "SwXTextCellStyle unknown nWID");
5210 throw css::uno::RuntimeException();
5214 throw css::beans::UnknownPropertyException(rPropertyName);
5217 void SAL_CALL SwXTextCellStyle::addPropertyChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XPropertyChangeListener >& /*xListener*/ )
5219 SAL_WARN("sw.uno", "not implemented");
5222 void SAL_CALL SwXTextCellStyle::removePropertyChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XPropertyChangeListener >& /*aListener*/ )
5224 SAL_WARN("sw.uno", "not implemented");
5227 void SAL_CALL SwXTextCellStyle::addVetoableChangeListener( const OUString& /*PropertyName*/, const css::uno::Reference< css::beans::XVetoableChangeListener >& /*aListener*/ )
5229 SAL_WARN("sw.uno", "not implemented");
5232 void SAL_CALL SwXTextCellStyle::removeVetoableChangeListener( const OUString& /*PropertyName*/, const css::uno::Reference< css::beans::XVetoableChangeListener >& /*aListener*/ )
5234 SAL_WARN("sw.uno", "not implemented");
5237 //XPropertyState
5238 css::beans::PropertyState SAL_CALL SwXTextCellStyle::getPropertyState(const OUString& rPropertyName)
5240 SolarMutexGuard aGuard;
5241 uno::Sequence<OUString> aNames { rPropertyName };
5242 uno::Sequence<beans::PropertyState> aStates = getPropertyStates(aNames);
5243 return aStates.getConstArray()[0];
5246 css::uno::Sequence<css::beans::PropertyState> SAL_CALL SwXTextCellStyle::getPropertyStates(const css::uno::Sequence<OUString>& aPropertyNames)
5248 SolarMutexGuard aGuard;
5249 uno::Sequence<beans::PropertyState> aRet(aPropertyNames.getLength());
5250 beans::PropertyState* pStates = aRet.getArray();
5251 const SwBoxAutoFormat& rDefaultBoxFormat = SwTableAutoFormat::GetDefaultBoxFormat();
5252 const SfxItemPropertyMap& rMap = aSwMapProvider.GetPropertySet(PROPERTY_MAP_CELL_STYLE)->getPropertyMap();
5253 const OUString* pNames = aPropertyNames.getConstArray();
5254 for(sal_Int32 i=0; i < aPropertyNames.getLength(); ++i)
5256 const OUString sPropName = pNames[i];
5257 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(sPropName);
5258 if(pEntry)
5260 uno::Any aAny1, aAny2;
5261 switch(pEntry->nWID)
5263 case RES_BACKGROUND:
5264 m_pBoxAutoFormat->GetBackground().QueryValue(aAny1, pEntry->nMemberId);
5265 rDefaultBoxFormat.GetBackground().QueryValue(aAny2, pEntry->nMemberId);
5266 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5267 break;
5268 case RES_BOX:
5269 m_pBoxAutoFormat->GetBox().QueryValue(aAny1, pEntry->nMemberId);
5270 rDefaultBoxFormat.GetBox().QueryValue(aAny2, pEntry->nMemberId);
5271 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5272 break;
5273 case RES_VERT_ORIENT:
5274 m_pBoxAutoFormat->GetVerticalAlignment().QueryValue(aAny1, pEntry->nMemberId);
5275 rDefaultBoxFormat.GetVerticalAlignment().QueryValue(aAny2, pEntry->nMemberId);
5276 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5277 break;
5278 case RES_FRAMEDIR:
5279 m_pBoxAutoFormat->GetTextOrientation().QueryValue(aAny1, pEntry->nMemberId);
5280 rDefaultBoxFormat.GetTextOrientation().QueryValue(aAny2, pEntry->nMemberId);
5281 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5282 break;
5283 case RES_BOXATR_FORMAT:
5285 OUString sFormat;
5286 LanguageType eLng, eSys;
5287 m_pBoxAutoFormat->GetValueFormat(sFormat, eLng, eSys);
5288 pStates[i] = sFormat.isEmpty() ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5289 break;
5291 case RES_PARATR_ADJUST:
5292 m_pBoxAutoFormat->GetAdjust().QueryValue(aAny1, pEntry->nMemberId);
5293 rDefaultBoxFormat.GetAdjust().QueryValue(aAny2, pEntry->nMemberId);
5294 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5295 break;
5296 case RES_CHRATR_COLOR:
5297 m_pBoxAutoFormat->GetColor().QueryValue(aAny1, pEntry->nMemberId);
5298 rDefaultBoxFormat.GetColor().QueryValue(aAny2, pEntry->nMemberId);
5299 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5300 break;
5301 case RES_CHRATR_SHADOWED:
5302 m_pBoxAutoFormat->GetShadowed().QueryValue(aAny1, pEntry->nMemberId);
5303 rDefaultBoxFormat.GetShadowed().QueryValue(aAny2, pEntry->nMemberId);
5304 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5305 break;
5306 case RES_CHRATR_CONTOUR:
5307 m_pBoxAutoFormat->GetContour().QueryValue(aAny1, pEntry->nMemberId);
5308 rDefaultBoxFormat.GetContour().QueryValue(aAny2, pEntry->nMemberId);
5309 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5310 break;
5311 case RES_CHRATR_CROSSEDOUT:
5312 m_pBoxAutoFormat->GetCrossedOut().QueryValue(aAny1, pEntry->nMemberId);
5313 rDefaultBoxFormat.GetCrossedOut().QueryValue(aAny2, pEntry->nMemberId);
5314 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5315 break;
5316 case RES_CHRATR_UNDERLINE:
5317 m_pBoxAutoFormat->GetUnderline().QueryValue(aAny1, pEntry->nMemberId);
5318 rDefaultBoxFormat.GetUnderline().QueryValue(aAny2, pEntry->nMemberId);
5319 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5320 break;
5321 case RES_CHRATR_FONTSIZE:
5322 m_pBoxAutoFormat->GetHeight().QueryValue(aAny1, pEntry->nMemberId);
5323 rDefaultBoxFormat.GetHeight().QueryValue(aAny2, pEntry->nMemberId);
5324 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5325 break;
5326 case RES_CHRATR_WEIGHT:
5327 m_pBoxAutoFormat->GetWeight().QueryValue(aAny1, pEntry->nMemberId);
5328 rDefaultBoxFormat.GetWeight().QueryValue(aAny2, pEntry->nMemberId);
5329 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5330 break;
5331 case RES_CHRATR_POSTURE:
5332 m_pBoxAutoFormat->GetPosture().QueryValue(aAny1, pEntry->nMemberId);
5333 rDefaultBoxFormat.GetPosture().QueryValue(aAny2, pEntry->nMemberId);
5334 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5335 break;
5336 case RES_CHRATR_FONT:
5337 m_pBoxAutoFormat->GetFont().QueryValue(aAny1, pEntry->nMemberId);
5338 rDefaultBoxFormat.GetFont().QueryValue(aAny2, pEntry->nMemberId);
5339 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5340 break;
5341 case RES_CHRATR_CJK_FONTSIZE:
5342 m_pBoxAutoFormat->GetCJKHeight().QueryValue(aAny1, pEntry->nMemberId);
5343 rDefaultBoxFormat.GetCJKHeight().QueryValue(aAny2, pEntry->nMemberId);
5344 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5345 break;
5346 case RES_CHRATR_CJK_WEIGHT:
5347 m_pBoxAutoFormat->GetCJKWeight().QueryValue(aAny1, pEntry->nMemberId);
5348 rDefaultBoxFormat.GetCJKWeight().QueryValue(aAny2, pEntry->nMemberId);
5349 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5350 break;
5351 case RES_CHRATR_CJK_POSTURE:
5352 m_pBoxAutoFormat->GetCJKPosture().QueryValue(aAny1, pEntry->nMemberId);
5353 rDefaultBoxFormat.GetCJKPosture().QueryValue(aAny2, pEntry->nMemberId);
5354 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5355 break;
5356 case RES_CHRATR_CJK_FONT:
5357 m_pBoxAutoFormat->GetCJKFont().QueryValue(aAny1, pEntry->nMemberId);
5358 rDefaultBoxFormat.GetCJKFont().QueryValue(aAny2, pEntry->nMemberId);
5359 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5360 break;
5361 case RES_CHRATR_CTL_FONTSIZE:
5362 m_pBoxAutoFormat->GetCTLHeight().QueryValue(aAny1, pEntry->nMemberId);
5363 rDefaultBoxFormat.GetCTLHeight().QueryValue(aAny2, pEntry->nMemberId);
5364 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5365 break;
5366 case RES_CHRATR_CTL_WEIGHT:
5367 m_pBoxAutoFormat->GetCTLWeight().QueryValue(aAny1, pEntry->nMemberId);
5368 rDefaultBoxFormat.GetCTLWeight().QueryValue(aAny2, pEntry->nMemberId);
5369 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5370 break;
5371 case RES_CHRATR_CTL_POSTURE:
5372 m_pBoxAutoFormat->GetCTLPosture().QueryValue(aAny1, pEntry->nMemberId);
5373 rDefaultBoxFormat.GetCTLPosture().QueryValue(aAny2, pEntry->nMemberId);
5374 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5375 break;
5376 case RES_CHRATR_CTL_FONT:
5377 m_pBoxAutoFormat->GetCTLFont().QueryValue(aAny1, pEntry->nMemberId);
5378 rDefaultBoxFormat.GetCTLFont().QueryValue(aAny2, pEntry->nMemberId);
5379 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE;
5380 break;
5381 default:
5382 // fallthrough to DIRECT_VALUE, to export properties for which getPropertyStates is not implemented
5383 pStates[i] = beans::PropertyState_DIRECT_VALUE;
5384 SAL_WARN("sw.uno", "SwXTextCellStyle getPropertyStates unknown nWID");
5387 else
5389 SAL_WARN("sw.uno", "SwXTextCellStyle unknown property:" + sPropName);
5390 throw css::beans::UnknownPropertyException(sPropName);
5393 return aRet;
5396 void SAL_CALL SwXTextCellStyle::setPropertyToDefault(const OUString& rPropertyName)
5398 SolarMutexGuard aGuard;
5399 const SwBoxAutoFormat& rDefaultBoxFormat = SwTableAutoFormat::GetDefaultBoxFormat();
5400 const SfxItemPropertyMap& rMap = aSwMapProvider.GetPropertySet(PROPERTY_MAP_CELL_STYLE)->getPropertyMap();
5401 const SfxItemPropertyMapEntry* pEntry = rMap.getByName(rPropertyName);
5402 if(!pEntry)
5403 return;
5405 uno::Any aAny;
5406 switch(pEntry->nWID)
5408 case RES_BACKGROUND:
5410 SvxBrushItem rBrush = m_pBoxAutoFormat->GetBackground();
5411 rDefaultBoxFormat.GetBackground().QueryValue(aAny, pEntry->nMemberId);
5412 rBrush.PutValue(aAny, pEntry->nMemberId);
5413 m_pBoxAutoFormat->SetBackground(rBrush);
5414 break;
5416 case RES_BOX:
5418 SvxBoxItem rBox = m_pBoxAutoFormat->GetBox();
5419 rDefaultBoxFormat.GetBox().QueryValue(aAny, pEntry->nMemberId);
5420 rBox.PutValue(aAny, pEntry->nMemberId);
5421 m_pBoxAutoFormat->SetBox(rBox);
5422 break;
5424 case RES_VERT_ORIENT:
5426 SwFormatVertOrient rVertOrient = m_pBoxAutoFormat->GetVerticalAlignment();
5427 rDefaultBoxFormat.GetVerticalAlignment().QueryValue(aAny, pEntry->nMemberId);
5428 rVertOrient.PutValue(aAny, pEntry->nMemberId);
5429 m_pBoxAutoFormat->SetVerticalAlignment(rVertOrient);
5430 break;
5432 case RES_FRAMEDIR:
5434 SvxFrameDirectionItem rFrameDirectionItem = m_pBoxAutoFormat->GetTextOrientation();
5435 rDefaultBoxFormat.GetTextOrientation().QueryValue(aAny, pEntry->nMemberId);
5436 rFrameDirectionItem.PutValue(aAny, pEntry->nMemberId);
5437 m_pBoxAutoFormat->SetTextOrientation(rFrameDirectionItem);
5438 break;
5440 case RES_BOXATR_FORMAT:
5442 OUString sFormat;
5443 LanguageType eLng, eSys;
5444 rDefaultBoxFormat.GetValueFormat(sFormat, eLng, eSys);
5445 m_pBoxAutoFormat->SetValueFormat(sFormat, eLng, eSys);
5446 break;
5448 case RES_PARATR_ADJUST:
5450 SvxAdjustItem rAdjustItem = m_pBoxAutoFormat->GetAdjust();
5451 rDefaultBoxFormat.GetAdjust().QueryValue(aAny, pEntry->nMemberId);
5452 rAdjustItem.PutValue(aAny, pEntry->nMemberId);
5453 m_pBoxAutoFormat->SetAdjust(rAdjustItem);
5454 break;
5456 case RES_CHRATR_COLOR:
5458 SvxColorItem rColorItem = m_pBoxAutoFormat->GetColor();
5459 rDefaultBoxFormat.GetColor().QueryValue(aAny, pEntry->nMemberId);
5460 rColorItem.PutValue(aAny, pEntry->nMemberId);
5461 m_pBoxAutoFormat->SetColor(rColorItem);
5462 break;
5464 case RES_CHRATR_SHADOWED:
5466 SvxShadowedItem rShadowedItem = m_pBoxAutoFormat->GetShadowed();
5467 rDefaultBoxFormat.GetShadowed().QueryValue(aAny, pEntry->nMemberId);
5468 rShadowedItem.PutValue(aAny, pEntry->nMemberId);
5469 m_pBoxAutoFormat->SetShadowed(rShadowedItem);
5470 break;
5472 case RES_CHRATR_CONTOUR:
5474 SvxContourItem rContourItem = m_pBoxAutoFormat->GetContour();
5475 rDefaultBoxFormat.GetContour().QueryValue(aAny, pEntry->nMemberId);
5476 rContourItem.PutValue(aAny, pEntry->nMemberId);
5477 m_pBoxAutoFormat->SetContour(rContourItem);
5478 break;
5480 case RES_CHRATR_CROSSEDOUT:
5482 SvxCrossedOutItem rCrossedOutItem = m_pBoxAutoFormat->GetCrossedOut();
5483 rDefaultBoxFormat.GetCrossedOut().QueryValue(aAny, pEntry->nMemberId);
5484 rCrossedOutItem.PutValue(aAny, pEntry->nMemberId);
5485 m_pBoxAutoFormat->SetCrossedOut(rCrossedOutItem);
5486 break;
5488 case RES_CHRATR_UNDERLINE:
5490 SvxUnderlineItem rUnderlineItem = m_pBoxAutoFormat->GetUnderline();
5491 rDefaultBoxFormat.GetUnderline().QueryValue(aAny, pEntry->nMemberId);
5492 rUnderlineItem.PutValue(aAny, pEntry->nMemberId);
5493 m_pBoxAutoFormat->SetUnderline(rUnderlineItem);
5494 break;
5496 case RES_CHRATR_FONTSIZE:
5498 SvxFontHeightItem rFontHeightItem = m_pBoxAutoFormat->GetHeight();
5499 rDefaultBoxFormat.GetHeight().QueryValue(aAny, pEntry->nMemberId);
5500 rFontHeightItem.PutValue(aAny, pEntry->nMemberId);
5501 m_pBoxAutoFormat->SetHeight(rFontHeightItem);
5502 break;
5504 case RES_CHRATR_WEIGHT:
5506 SvxWeightItem rWeightItem = m_pBoxAutoFormat->GetWeight();
5507 rDefaultBoxFormat.GetWeight().QueryValue(aAny, pEntry->nMemberId);
5508 rWeightItem.PutValue(aAny, pEntry->nMemberId);
5509 m_pBoxAutoFormat->SetWeight(rWeightItem);
5510 break;
5512 case RES_CHRATR_POSTURE:
5514 SvxPostureItem rPostureItem = m_pBoxAutoFormat->GetPosture();
5515 rDefaultBoxFormat.GetPosture().QueryValue(aAny, pEntry->nMemberId);
5516 rPostureItem.PutValue(aAny, pEntry->nMemberId);
5517 m_pBoxAutoFormat->SetPosture(rPostureItem);
5518 break;
5520 case RES_CHRATR_FONT:
5522 SvxFontItem rFontItem = m_pBoxAutoFormat->GetFont();
5523 rDefaultBoxFormat.GetFont().QueryValue(aAny, pEntry->nMemberId);
5524 rFontItem.PutValue(aAny, pEntry->nMemberId);
5525 m_pBoxAutoFormat->SetFont(rFontItem);
5526 break;
5528 case RES_CHRATR_CJK_FONTSIZE:
5530 SvxFontHeightItem rFontHeightItem = m_pBoxAutoFormat->GetCJKHeight();
5531 rDefaultBoxFormat.GetCJKHeight().QueryValue(aAny, pEntry->nMemberId);
5532 rFontHeightItem.PutValue(aAny, pEntry->nMemberId);
5533 m_pBoxAutoFormat->SetCJKHeight(rFontHeightItem);
5534 break;
5536 case RES_CHRATR_CJK_WEIGHT:
5538 SvxWeightItem rWeightItem = m_pBoxAutoFormat->GetCJKWeight();
5539 rDefaultBoxFormat.GetCJKWeight().QueryValue(aAny, pEntry->nMemberId);
5540 rWeightItem.PutValue(aAny, pEntry->nMemberId);
5541 m_pBoxAutoFormat->SetCJKWeight(rWeightItem);
5542 break;
5544 case RES_CHRATR_CJK_POSTURE:
5546 SvxPostureItem rPostureItem = m_pBoxAutoFormat->GetCJKPosture();
5547 rDefaultBoxFormat.GetCJKPosture().QueryValue(aAny, pEntry->nMemberId);
5548 rPostureItem.PutValue(aAny, pEntry->nMemberId);
5549 m_pBoxAutoFormat->SetCJKPosture(rPostureItem);
5550 break;
5552 case RES_CHRATR_CJK_FONT:
5554 SvxFontItem rFontItem = m_pBoxAutoFormat->GetCJKFont();
5555 rDefaultBoxFormat.GetCJKFont().QueryValue(aAny, pEntry->nMemberId);
5556 rFontItem.PutValue(aAny, pEntry->nMemberId);
5557 m_pBoxAutoFormat->SetCJKFont(rFontItem);
5558 break;
5560 case RES_CHRATR_CTL_FONTSIZE:
5562 SvxFontHeightItem rFontHeightItem = m_pBoxAutoFormat->GetCTLHeight();
5563 rDefaultBoxFormat.GetCTLHeight().QueryValue(aAny, pEntry->nMemberId);
5564 rFontHeightItem.PutValue(aAny, pEntry->nMemberId);
5565 m_pBoxAutoFormat->SetCTLHeight(rFontHeightItem);
5566 break;
5568 case RES_CHRATR_CTL_WEIGHT:
5570 SvxWeightItem rWeightItem = m_pBoxAutoFormat->GetCTLWeight();
5571 rDefaultBoxFormat.GetCTLWeight().QueryValue(aAny, pEntry->nMemberId);
5572 rWeightItem.PutValue(aAny, pEntry->nMemberId);
5573 m_pBoxAutoFormat->SetCTLWeight(rWeightItem);
5574 break;
5576 case RES_CHRATR_CTL_POSTURE:
5578 SvxPostureItem rPostureItem = m_pBoxAutoFormat->GetCTLPosture();
5579 rDefaultBoxFormat.GetCTLPosture().QueryValue(aAny, pEntry->nMemberId);
5580 rPostureItem.PutValue(aAny, pEntry->nMemberId);
5581 m_pBoxAutoFormat->SetCTLPosture(rPostureItem);
5582 break;
5584 case RES_CHRATR_CTL_FONT:
5586 SvxFontItem rFontItem = m_pBoxAutoFormat->GetCTLFont();
5587 rDefaultBoxFormat.GetCTLFont().QueryValue(aAny, pEntry->nMemberId);
5588 rFontItem.PutValue(aAny, pEntry->nMemberId);
5589 m_pBoxAutoFormat->SetCTLFont(rFontItem);
5590 break;
5592 default:
5593 SAL_WARN("sw.uno", "SwXTextCellStyle setPropertyToDefault unknown nWID");
5597 css::uno::Any SAL_CALL SwXTextCellStyle::getPropertyDefault(const OUString& /*aPropertyName*/)
5599 SAL_WARN("sw.uno", "not implemented");
5600 uno::Any aRet;
5601 return aRet;
5604 //XServiceInfo
5605 OUString SAL_CALL SwXTextCellStyle::getImplementationName()
5607 return {"SwXTextCellStyle"};
5610 sal_Bool SAL_CALL SwXTextCellStyle::supportsService(const OUString& rServiceName)
5612 return cppu::supportsService(this, rServiceName);
5615 css::uno::Sequence<OUString> SAL_CALL SwXTextCellStyle::getSupportedServiceNames()
5617 return {"com.sun.star.style.Style"};
5620 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */