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