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