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