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