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