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  const auto aNamedValues = rValue.get<expectedarg_t>();
1860  for(const auto& rNamedValue : aNamedValues)
1861  {
1862  if(!rNamedValue.Value.has<OUString>())
1863  throw lang::IllegalArgumentException();
1864 
1865  const OUString sValue(rNamedValue.Value.get<OUString>());
1866  // get UI style name from programmatic style name
1867  OUString aStyleName;
1868  SwStyleNameMapper::FillUIName(sValue, aStyleName, lcl_GetSwEnumFromSfxEnum(m_rEntry.m_eFamily));
1869 
1870  // check for correct context and style name
1871  const auto nIdx(GetCommandContextIndex(rNamedValue.Name));
1872  if (nIdx == -1)
1873  throw lang::IllegalArgumentException();
1874  m_pBasePool->SetSearchMask(SfxStyleFamily::Para);
1875  bool bStyleFound = false;
1876  for(auto pBase = m_pBasePool->First(); pBase; pBase = m_pBasePool->Next())
1877  {
1878  bStyleFound = pBase->GetName() == aStyleName;
1879  if (bStyleFound)
1880  break;
1881  }
1882  if (!bStyleFound)
1883  throw lang::IllegalArgumentException();
1884  aCondItem.SetStyle(&aStyleName, nIdx);
1885  }
1886  o_rStyleBase.GetItemSet().Put(aCondItem);
1887 }
1888 template<>
1889 void SwXStyle::SetPropertyValue<FN_UNO_CATEGORY>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1890 {
1891  if(!o_rStyleBase.getNewBase()->IsUserDefined() || !rValue.has<paragraphstyle_t>())
1892  throw lang::IllegalArgumentException();
1893  static std::unique_ptr<std::map<paragraphstyle_t, SfxStyleSearchBits>> pUnoToCore;
1894  if(!pUnoToCore)
1895  {
1896  pUnoToCore.reset(new std::map<paragraphstyle_t, SfxStyleSearchBits>);
1897  auto pEntries = lcl_GetParagraphStyleCategoryEntries();
1898  std::transform(pEntries->begin(), pEntries->end(), std::inserter(*pUnoToCore, pUnoToCore->end()),
1899  [] (const ParagraphStyleCategoryEntry& rEntry) { return std::pair<paragraphstyle_t, SfxStyleSearchBits>(rEntry.m_eCategory, rEntry.m_nSwStyleBits); });
1900  }
1901  const auto pUnoToCoreIt(pUnoToCore->find(rValue.get<paragraphstyle_t>()));
1902  if(pUnoToCoreIt == pUnoToCore->end())
1903  throw lang::IllegalArgumentException();
1904  o_rStyleBase.getNewBase()->SetMask( pUnoToCoreIt->second|SfxStyleSearchBits::UserDefined );
1905 }
1906 template<>
1907 void SwXStyle::SetPropertyValue<SID_SWREGISTER_COLLECTION>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1908 {
1909  OUString sName;
1910  rValue >>= sName;
1911  SwRegisterItem aReg(!sName.isEmpty());
1912  aReg.SetWhich(SID_SWREGISTER_MODE);
1913  o_rStyleBase.GetItemSet().Put(aReg);
1914  OUString aString;
1916  o_rStyleBase.GetItemSet().Put(SfxStringItem(SID_SWREGISTER_COLLECTION, aString ) );
1917 }
1918 template<>
1919 void SwXStyle::SetPropertyValue<sal_uInt16(RES_TXTATR_CJK_RUBY)>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1920 {
1921  if(MID_RUBY_CHARSTYLE != rEntry.nMemberId)
1922  return;
1923  if(!rValue.has<OUString>())
1924  throw lang::IllegalArgumentException();
1925  const auto sValue(rValue.get<OUString>());
1926  SfxItemSet& rStyleSet(o_rStyleBase.GetItemSet());
1927  std::unique_ptr<SwFormatRuby> pRuby;
1928  const SfxPoolItem* pItem;
1929  if(SfxItemState::SET == rStyleSet.GetItemState(RES_TXTATR_CJK_RUBY, true, &pItem))
1930  pRuby.reset(new SwFormatRuby(*static_cast<const SwFormatRuby*>(pItem)));
1931  else
1932  pRuby.reset(new SwFormatRuby(OUString()));
1933  OUString sStyle;
1935  pRuby->SetCharFormatName(sValue);
1936  pRuby->SetCharFormatId(0);
1937  if(!sValue.isEmpty())
1938  {
1940  pRuby->SetCharFormatId(nId);
1941  }
1942  rStyleSet.Put(*pRuby);
1943  SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, rValue, o_rStyleBase);
1944 }
1945 template<>
1946 void SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_DROP)>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1947 {
1948  if(MID_DROPCAP_CHAR_STYLE_NAME != rEntry.nMemberId)
1949  {
1950  SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, rValue, o_rStyleBase);
1951  return;
1952  }
1953  if(!rValue.has<OUString>())
1954  throw lang::IllegalArgumentException();
1955  SfxItemSet& rStyleSet(o_rStyleBase.GetItemSet());
1956  std::unique_ptr<SwFormatDrop> pDrop;
1957  const SfxPoolItem* pItem;
1958  if(SfxItemState::SET == rStyleSet.GetItemState(RES_PARATR_DROP, true, &pItem))
1959  pDrop.reset(new SwFormatDrop(*static_cast<const SwFormatDrop*>(pItem)));
1960  else
1961  pDrop.reset(new SwFormatDrop);
1962  const auto sValue(rValue.get<OUString>());
1963  OUString sStyle;
1965  auto pStyle(static_cast<SwDocStyleSheet*>(m_pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle, SfxStyleFamily::Char)));
1966  //default character style must not be set as default format
1967  if(!pStyle || pStyle->GetCharFormat() == m_pDoc->GetDfltCharFormat() )
1968  {
1969  throw lang::IllegalArgumentException();
1970  }
1971  pDrop->SetCharFormat(pStyle->GetCharFormat());
1972  rStyleSet.Put(*pDrop);
1973 }
1974 template<>
1975 void SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_NUMRULE)>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase)
1976 {
1977  uno::Any aValue(rValue);
1978  lcl_TranslateMetric(rEntry, m_pDoc, aValue);
1979  SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, aValue, o_rStyleBase);
1980  // --> OD 2006-10-18 #i70223#
1981  if(SfxStyleFamily::Para == m_rEntry.m_eFamily &&
1982  o_rStyleBase.getNewBase().is() && o_rStyleBase.getNewBase()->GetCollection() &&
1983  //rBase.getNewBase()->GetCollection()->GetOutlineLevel() < MAXLEVEL /* assigned to list level of outline style */) //#outline level,removed by zhaojianwei
1984  o_rStyleBase.getNewBase()->GetCollection()->IsAssignedToListLevelOfOutlineStyle())
1985  {
1986  OUString sNewNumberingRuleName;
1987  aValue >>= sNewNumberingRuleName;
1988  if(sNewNumberingRuleName.isEmpty() || sNewNumberingRuleName != m_pDoc->GetOutlineNumRule()->GetName())
1989  o_rStyleBase.getNewBase()->GetCollection()->DeleteAssignmentToListLevelOfOutlineStyle();
1990  }
1991 }
1992 
1993 void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase)
1994 {
1995  using propertytype_t = decltype(rEntry.nWID);
1996  using coresetter_t = std::function<void(SwXStyle&, const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any&, SwStyleBase_Impl&)>;
1997  static std::unique_ptr<std::map<propertytype_t, coresetter_t>> pUnoToCore;
1998  if(!pUnoToCore)
1999  {
2000  pUnoToCore.reset(new std::map<propertytype_t, coresetter_t> {
2001  // these explicit std::mem_fn() calls shouldn't be needed, but apparently MSVC is currently too stupid for C++11 again
2002  { FN_UNO_HIDDEN, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_HIDDEN>) },
2003  { FN_UNO_STYLE_INTEROP_GRAB_BAG, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_STYLE_INTEROP_GRAB_BAG>) },
2004  { XATTR_FILLGRADIENT, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(XATTR_FILLGRADIENT)>) },
2005  { XATTR_FILLHATCH, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(XATTR_FILLGRADIENT)>) },
2006  { XATTR_FILLBITMAP, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(XATTR_FILLGRADIENT)>) },
2008  { RES_BACKGROUND, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_BACKGROUND)>) },
2009  { OWN_ATTR_FILLBMP_MODE, std::mem_fn(&SwXStyle::SetPropertyValue<OWN_ATTR_FILLBMP_MODE>) },
2010  { RES_PAPER_BIN, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_PAPER_BIN)>) },
2011  { FN_UNO_NUM_RULES, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_NUM_RULES>) },
2013  { FN_UNO_FOLLOW_STYLE, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_FOLLOW_STYLE>) },
2014  { RES_PAGEDESC, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_PAGEDESC)>) },
2016  { FN_UNO_IS_AUTO_UPDATE, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_IS_AUTO_UPDATE>) },
2017  { FN_UNO_PARA_STYLE_CONDITIONS, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_PARA_STYLE_CONDITIONS>) },
2018  { FN_UNO_CATEGORY, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_CATEGORY>) },
2019  { SID_SWREGISTER_COLLECTION, std::mem_fn(&SwXStyle::SetPropertyValue<SID_SWREGISTER_COLLECTION>) },
2020  { RES_TXTATR_CJK_RUBY, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_TXTATR_CJK_RUBY)>) },
2021  { RES_PARATR_DROP, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_DROP)>) },
2022  { RES_PARATR_NUMRULE, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_NUMRULE)>) }
2023  });
2024  }
2025  const auto pUnoToCoreIt(pUnoToCore->find(rEntry.nWID));
2026  if(pUnoToCoreIt != pUnoToCore->end())
2027  pUnoToCoreIt->second(*this, rEntry, rPropSet, rValue, rBase);
2028  else
2029  {
2030  // adapted switch logic to a more readable state; removed goto's and made
2031  // execution of standard setting of property in ItemSet dependent of this variable
2032  uno::Any aValue(rValue);
2033  lcl_TranslateMetric(rEntry, m_pDoc, aValue);
2034  SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, aValue, rBase);
2035  }
2036 }
2037 
2038 void SwXStyle::SetPropertyValues_Impl(const uno::Sequence<OUString>& rPropertyNames, const uno::Sequence<uno::Any>& rValues)
2039 {
2040  if(!m_pDoc)
2041  throw uno::RuntimeException();
2043  const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
2044  const SfxItemPropertyMap &rMap = pPropSet->getPropertyMap();
2045  if(rPropertyNames.getLength() != rValues.getLength())
2046  throw lang::IllegalArgumentException();
2047 
2048  SwStyleBase_Impl aBaseImpl(*m_pDoc, m_sStyleName, &GetDoc()->GetDfltTextFormatColl()->GetAttrSet()); // add pDfltTextFormatColl as parent
2049  if(m_pBasePool)
2050  {
2051  const SfxStyleSearchBits nSaveMask = m_pBasePool->GetSearchMask();
2052  m_pBasePool->SetSearchMask(m_rEntry.m_eFamily);
2054  m_pBasePool->SetSearchMask(m_rEntry.m_eFamily, nSaveMask);
2055  SAL_WARN_IF(!pBase, "sw.uno", "where is the style?");
2056  if(!pBase)
2057  throw uno::RuntimeException();
2058  aBaseImpl.setNewBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2059  }
2060  if(!aBaseImpl.getNewBase().is() && !m_bIsDescriptor)
2061  throw uno::RuntimeException();
2062 
2063  const OUString* pNames = rPropertyNames.getConstArray();
2064  const uno::Any* pValues = rValues.getConstArray();
2065  for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp)
2066  {
2067  const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(pNames[nProp]);
2068  if(!pEntry || (!m_bIsConditional && pNames[nProp] == UNO_NAME_PARA_STYLE_CONDITIONS))
2069  throw beans::UnknownPropertyException("Unknown property: " + pNames[nProp], static_cast<cppu::OWeakObject*>(this));
2070  if(pEntry->nFlags & beans::PropertyAttribute::READONLY)
2071  throw beans::PropertyVetoException ("Property is read-only: " + pNames[nProp], static_cast<cppu::OWeakObject*>(this));
2072  if(aBaseImpl.getNewBase().is())
2073  SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl);
2074  else if(!m_pPropertiesImpl->SetProperty(pNames[nProp], pValues[nProp]))
2075  throw lang::IllegalArgumentException();
2076  }
2077 
2078  if(aBaseImpl.HasItemSet())
2079  aBaseImpl.getNewBase()->SetItemSet(aBaseImpl.GetItemSet());
2080 }
2081 
2082 void SwXStyle::setPropertyValues(const uno::Sequence<OUString>& rPropertyNames, const uno::Sequence<uno::Any>& rValues)
2083 {
2084  SolarMutexGuard aGuard;
2085  // workaround for bad designed API
2086  try
2087  {
2088  SetPropertyValues_Impl( rPropertyNames, rValues );
2089  }
2090  catch (const beans::UnknownPropertyException &rException)
2091  {
2092  // wrap the original (here not allowed) exception in
2093  // a lang::WrappedTargetException that gets thrown instead.
2094  lang::WrappedTargetException aWExc;
2095  aWExc.TargetException <<= rException;
2096  throw aWExc;
2097  }
2098 }
2099 
2101 {
2102  if(!m_pBasePool)
2103  return nullptr;
2104  const SfxStyleSearchBits nSaveMask = m_pBasePool->GetSearchMask();
2105  m_pBasePool->SetSearchMask(m_rEntry.m_eFamily);
2107  m_pBasePool->SetSearchMask(m_rEntry.m_eFamily, nSaveMask );
2108  return pBase;
2109 }
2111 {
2113  if(!pBase)
2114  throw uno::RuntimeException();
2115  if(!rBase.getNewBase().is())
2116  rBase.setNewBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2117 }
2118 
2119 template<>
2120 uno::Any SwXStyle::GetStyleProperty<HINT_BEGIN>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase);
2121 template<>
2122 uno::Any SwXStyle::GetStyleProperty<FN_UNO_IS_PHYSICAL>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl&)
2123 {
2124  SfxStyleSheetBase* pBase(GetStyleSheetBase());
2125  if(!pBase)
2126  return uno::makeAny(false);
2127  bool bPhys = static_cast<SwDocStyleSheet*>(pBase)->IsPhysical();
2128  // The standard character format is not existing physically
2129  if( bPhys && SfxStyleFamily::Char == GetFamily() &&
2130  static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat() &&
2131  static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat()->IsDefault() )
2132  bPhys = false;
2133  return uno::makeAny<bool>(bPhys);
2134 }
2135 template<>
2136 uno::Any SwXStyle::GetStyleProperty<FN_UNO_HIDDEN>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl&)
2137 {
2138  SfxStyleSheetBase* pBase(GetStyleSheetBase());
2139  if(!pBase)
2140  return uno::makeAny(false);
2141  rtl::Reference<SwDocStyleSheet> xBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2142  return uno::makeAny(xBase->IsHidden());
2143 }
2144 template<>
2145 uno::Any SwXStyle::GetStyleProperty<FN_UNO_STYLE_INTEROP_GRAB_BAG>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl&)
2146 {
2147  SfxStyleSheetBase* pBase(GetStyleSheetBase());
2148  if(!pBase)
2149  return uno::Any();
2150  uno::Any aRet;
2151  rtl::Reference<SwDocStyleSheet> xBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2152  xBase->GetGrabBagItem(aRet);
2153  return aRet;
2154 }
2155 template<>
2156 uno::Any SwXStyle::GetStyleProperty<sal_uInt16(RES_PAPER_BIN)>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase)
2157 {
2158  PrepareStyleBase(rBase);
2159  SfxItemSet& rSet = rBase.GetItemSet();
2160  uno::Any aValue;
2161  rPropSet.getPropertyValue(rEntry, rSet, aValue);
2162  sal_Int8 nBin(aValue.get<sal_Int8>());
2163  if(nBin == -1)
2164  return uno::makeAny<OUString>("[From printer settings]");
2165  SfxPrinter* pPrinter = GetDoc()->getIDocumentDeviceAccess().getPrinter(false);
2166  if(!pPrinter)
2167  return uno::Any();
2168  return uno::makeAny(pPrinter->GetPaperBinName(nBin));
2169 }
2170 template<>
2171 uno::Any SwXStyle::GetStyleProperty<FN_UNO_NUM_RULES>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2172 {
2173  PrepareStyleBase(rBase);
2174  const SwNumRule* pRule = rBase.getNewBase()->GetNumRule();
2175  assert(pRule && "Where is the NumRule?");
2176  uno::Reference<container::XIndexReplace> xRules(new SwXNumberingRules(*pRule, GetDoc()));
2177  return uno::makeAny<uno::Reference<container::XIndexReplace>>(xRules);
2178 }
2179 template<>
2180 uno::Any SwXStyle::GetStyleProperty<sal_uInt16(RES_PARATR_OUTLINELEVEL)>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2181 {
2182  PrepareStyleBase(rBase);
2183  SAL_WARN_IF(SfxStyleFamily::Para != GetFamily(), "sw.uno", "only paras");
2184  return uno::makeAny<sal_Int16>(rBase.getNewBase()->GetCollection()->GetAttrOutlineLevel());
2185 }
2186 template<>
2187 uno::Any SwXStyle::GetStyleProperty<FN_UNO_FOLLOW_STYLE>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2188 {
2189  PrepareStyleBase(rBase);
2190  OUString aString;
2191  SwStyleNameMapper::FillProgName(rBase.getNewBase()->GetFollow(), aString, lcl_GetSwEnumFromSfxEnum(GetFamily()));
2192  return uno::makeAny(aString);
2193 }
2194 template<>
2195 uno::Any SwXStyle::GetStyleProperty<sal_uInt16(RES_PAGEDESC)>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase)
2196 {
2197  PrepareStyleBase(rBase);
2198  if(MID_PAGEDESC_PAGEDESCNAME != rEntry.nMemberId)
2199  return GetStyleProperty<HINT_BEGIN>(rEntry, rPropSet, rBase);
2200  // special handling for RES_PAGEDESC
2201  const SfxPoolItem* pItem;
2202  if(SfxItemState::SET != rBase.GetItemSet().GetItemState(RES_PAGEDESC, true, &pItem))
2203  return uno::Any();
2204  const SwPageDesc* pDesc = static_cast<const SwFormatPageDesc*>(pItem)->GetPageDesc();
2205  if(!pDesc)
2206  return uno::Any();
2207  OUString aString;
2209  return uno::makeAny(aString);
2210 }
2211 template<>
2212 uno::Any SwXStyle::GetStyleProperty<FN_UNO_IS_AUTO_UPDATE>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2213 {
2214  PrepareStyleBase(rBase);
2215  switch(GetFamily())
2216  {
2217  case SfxStyleFamily::Para : return uno::makeAny<bool>(rBase.getNewBase()->GetCollection()->IsAutoUpdateFormat());
2218  case SfxStyleFamily::Frame: return uno::makeAny<bool>(rBase.getNewBase()->GetFrameFormat()->IsAutoUpdateFormat());
2219  default: return uno::Any();
2220  }
2221 }
2222 template<>
2223 uno::Any SwXStyle::GetStyleProperty<FN_UNO_DISPLAY_NAME>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2224 {
2225  PrepareStyleBase(rBase);
2226  return uno::makeAny(rBase.getNewBase()->GetName());
2227 }
2228 template<>
2229 uno::Any SwXStyle::GetStyleProperty<FN_UNO_PARA_STYLE_CONDITIONS>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2230 {
2231  PrepareStyleBase(rBase);
2232  static_assert(COND_COMMAND_COUNT == 28, "invalid size of command count?");
2233  uno::Sequence<beans::NamedValue> aSeq(COND_COMMAND_COUNT);
2234  sal_uInt16 nIndex = 0;
2235  for(auto& rNV : aSeq)
2236  {
2237  rNV.Name = GetCommandContextByIndex(nIndex++);
2238  rNV.Value <<= OUString();
2239  }
2240  SwFormat* pFormat = static_cast<SwDocStyleSheet*>(GetStyleSheetBase())->GetCollection();
2241  if(pFormat && RES_CONDTXTFMTCOLL == pFormat->Which())
2242  {
2243  const CommandStruct* pCmds = SwCondCollItem::GetCmds();
2244  beans::NamedValue* pSeq = aSeq.getArray();
2245  for(sal_uInt16 n = 0; n < COND_COMMAND_COUNT; ++n)
2246  {
2247  const SwCollCondition* pCond = static_cast<SwConditionTextFormatColl*>(pFormat)->HasCondition(SwCollCondition(nullptr, pCmds[n].nCnd, pCmds[n].nSubCond));
2248  if(!pCond || !pCond->GetTextFormatColl())
2249  continue;
2250  // get programmatic style name from UI style name
2251  OUString aStyleName = pCond->GetTextFormatColl()->GetName();
2252  SwStyleNameMapper::FillProgName(aStyleName, aStyleName, lcl_GetSwEnumFromSfxEnum(GetFamily()));
2253  pSeq[n].Value <<= aStyleName;
2254  }
2255  }
2256  return uno::makeAny(aSeq);
2257 }
2258 template<>
2259 uno::Any SwXStyle::GetStyleProperty<FN_UNO_CATEGORY>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2260 {
2261  PrepareStyleBase(rBase);
2262  static std::unique_ptr<std::map<collectionbits_t, paragraphstyle_t>> pUnoToCore;
2263  if(!pUnoToCore)
2264  {
2265  pUnoToCore.reset(new std::map<collectionbits_t, paragraphstyle_t>);
2266  auto pEntries = lcl_GetParagraphStyleCategoryEntries();
2267  std::transform(pEntries->begin(), pEntries->end(), std::inserter(*pUnoToCore, pUnoToCore->end()),
2268  [] (const ParagraphStyleCategoryEntry& rEntry) { return std::pair<collectionbits_t, paragraphstyle_t>(rEntry.m_nCollectionBits, rEntry.m_eCategory); });
2269  }
2270  const sal_uInt16 nPoolId = rBase.getNewBase()->GetCollection()->GetPoolFormatId();
2271  const auto pUnoToCoreIt(pUnoToCore->find(COLL_GET_RANGE_BITS & nPoolId));
2272  if(pUnoToCoreIt == pUnoToCore->end())
2273  return uno::makeAny<sal_Int16>(-1);
2274  return uno::makeAny(pUnoToCoreIt->second);
2275 }
2276 template<>
2277 uno::Any SwXStyle::GetStyleProperty<SID_SWREGISTER_COLLECTION>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2278 {
2279  PrepareStyleBase(rBase);
2280  const SwPageDesc *pPageDesc = rBase.getNewBase()->GetPageDesc();
2281  if(!pPageDesc)
2282  return uno::makeAny(OUString());
2283  const SwTextFormatColl* pCol = pPageDesc->GetRegisterFormatColl();
2284  if(!pCol)
2285  return uno::makeAny(OUString());
2286  OUString aName;
2288  return uno::makeAny(aName);
2289 }
2290 template<>
2291 uno::Any SwXStyle::GetStyleProperty<sal_uInt16(RES_BACKGROUND)>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2292 {
2293  PrepareStyleBase(rBase);
2294  const SfxItemSet& rSet = rBase.GetItemSet();
2295  const std::shared_ptr<SvxBrushItem> aOriginalBrushItem(getSvxBrushItemFromSourceSet(rSet, RES_BACKGROUND));
2296  uno::Any aResult;
2297  if(!aOriginalBrushItem->QueryValue(aResult, rEntry.nMemberId))
2298  SAL_WARN("sw.uno", "error getting attribute from RES_BACKGROUND.");
2299  return aResult;
2300 }
2301 template<>
2302 uno::Any SwXStyle::GetStyleProperty<OWN_ATTR_FILLBMP_MODE>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase)
2303 {
2304  PrepareStyleBase(rBase);
2305  const SfxItemSet& rSet = rBase.GetItemSet();
2306  if (rSet.Get(XATTR_FILLBMP_TILE).GetValue())
2307  return uno::makeAny(drawing::BitmapMode_REPEAT);
2308  if (rSet.Get(XATTR_FILLBMP_STRETCH).GetValue())
2309  return uno::makeAny(drawing::BitmapMode_STRETCH);
2310  return uno::makeAny(drawing::BitmapMode_NO_REPEAT);
2311 }
2312 template<>
2313 uno::Any SwXStyle::GetStyleProperty<HINT_BEGIN>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase)
2314 {
2315  PrepareStyleBase(rBase);
2316  SfxItemSet& rSet = rBase.GetItemSet();
2317  uno::Any aResult;
2318  rPropSet.getPropertyValue(rEntry, rSet, aResult);
2319  //
2320  // since the sfx uint16 item now exports a sal_Int32, we may have to fix this here
2321  if(rEntry.aType == cppu::UnoType<sal_Int16>::get() && aResult.getValueType() == cppu::UnoType<sal_Int32>::get())
2322  aResult <<= static_cast<sal_Int16>(aResult.get<sal_Int32>());
2323  // check for needed metric translation
2324  if(rEntry.nMoreFlags & PropertyMoreFlags::METRIC_ITEM && GetDoc())
2325  {
2326  const SfxItemPool& rPool = GetDoc()->GetAttrPool();
2327  const MapUnit eMapUnit(rPool.GetMetric(rEntry.nWID));
2328  bool bAllowedConvert(true);
2329  // exception: If these ItemTypes are used, do not convert when these are negative
2330  // since this means they are intended as percent values
2331  if(XATTR_FILLBMP_SIZEX == rEntry.nWID || XATTR_FILLBMP_SIZEY == rEntry.nWID)
2332  bAllowedConvert = !aResult.has<sal_Int32>() || aResult.get<sal_Int32>() > 0;
2333  if(eMapUnit != MapUnit::Map100thMM && bAllowedConvert)
2334  SvxUnoConvertToMM(eMapUnit, aResult);
2335  }
2336  return aResult;
2337 }
2338 
2340 {
2341  using propertytype_t = decltype(rEntry.nWID);
2342  using coresetter_t = std::function<uno::Any(SwXStyle&, const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl&)>;
2343  static std::unique_ptr<std::map<propertytype_t, coresetter_t>> pUnoToCore;
2344  if(!pUnoToCore)
2345  {
2346  pUnoToCore.reset(new std::map<propertytype_t, coresetter_t> {
2347  // these explicit std::mem_fn() calls shouldn't be needed, but apparently MSVC is currently too stupid for C++11 again
2348  { FN_UNO_IS_PHYSICAL, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_IS_PHYSICAL>) },
2349  { FN_UNO_HIDDEN, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_HIDDEN>) },
2350  { FN_UNO_STYLE_INTEROP_GRAB_BAG, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_STYLE_INTEROP_GRAB_BAG>) },
2351  { RES_PAPER_BIN, std::mem_fn(&SwXStyle::GetStyleProperty<sal_uInt16(RES_PAPER_BIN)>) },
2352  { FN_UNO_NUM_RULES, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_NUM_RULES>) },
2354  { FN_UNO_FOLLOW_STYLE, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_FOLLOW_STYLE>) },
2355  { RES_PAGEDESC, std::mem_fn(&SwXStyle::GetStyleProperty<sal_uInt16(RES_PAGEDESC)>) },
2356  { FN_UNO_IS_AUTO_UPDATE, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_IS_AUTO_UPDATE>) },
2357  { FN_UNO_DISPLAY_NAME, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_DISPLAY_NAME>) },
2358  { FN_UNO_PARA_STYLE_CONDITIONS, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_PARA_STYLE_CONDITIONS>) },
2359  { FN_UNO_CATEGORY, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_CATEGORY>) },
2360  { SID_SWREGISTER_COLLECTION, std::mem_fn(&SwXStyle::GetStyleProperty<SID_SWREGISTER_COLLECTION>) },
2361  { RES_BACKGROUND, std::mem_fn(&SwXStyle::GetStyleProperty<sal_uInt16(RES_BACKGROUND)>) },
2362  { OWN_ATTR_FILLBMP_MODE, std::mem_fn(&SwXStyle::GetStyleProperty<OWN_ATTR_FILLBMP_MODE>) }
2363  });
2364  }
2365  const auto pUnoToCoreIt(pUnoToCore->find(rEntry.nWID));
2366  if(pUnoToCoreIt != pUnoToCore->end())
2367  return pUnoToCoreIt->second(*this, rEntry, rPropSet, rBase);
2368  return GetStyleProperty<HINT_BEGIN>(rEntry, rPropSet, rBase);
2369 }
2370 
2371 uno::Any SwXStyle::GetPropertyValue_Impl(const SfxItemPropertySet* pPropSet, SwStyleBase_Impl& rBase, const OUString& rPropertyName)
2372 {
2373  const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
2374  const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(rPropertyName);
2375  if(!pEntry || (!m_bIsConditional && rPropertyName == UNO_NAME_PARA_STYLE_CONDITIONS))
2376  throw beans::UnknownPropertyException("Unknown property: " + rPropertyName, static_cast<cppu::OWeakObject*>(this));
2377  if(m_pBasePool)
2378  return GetStyleProperty_Impl(*pEntry, *pPropSet, rBase);
2379  const uno::Any* pAny = nullptr;
2380  m_pPropertiesImpl->GetProperty(rPropertyName, pAny);
2381  if(pAny->hasValue())
2382  return *pAny;
2383  uno::Any aValue;
2384  switch(m_rEntry.m_eFamily)
2385  {
2386  case SfxStyleFamily::Pseudo:
2387  throw uno::RuntimeException("No default value for: " + rPropertyName);
2388  break;
2389  case SfxStyleFamily::Para:
2390  case SfxStyleFamily::Page:
2391  SwStyleProperties_Impl::GetProperty(rPropertyName, m_xStyleData, aValue);
2392  break;
2393  case SfxStyleFamily::Char:
2394  case SfxStyleFamily::Frame:
2395  {
2396  if(pEntry->nWID < POOLATTR_BEGIN || pEntry->nWID >= RES_UNKNOWNATR_END)
2397  throw uno::RuntimeException("No default value for: " + rPropertyName);
2398  SwFormat* pFormat;
2399  if(m_rEntry.m_eFamily == SfxStyleFamily::Char)
2400  pFormat = m_pDoc->GetDfltCharFormat();
2401  else
2402  pFormat = m_pDoc->GetDfltFrameFormat();
2403  const SwAttrPool* pPool = pFormat->GetAttrSet().GetPool();
2404  const SfxPoolItem& rItem = pPool->GetDefaultItem(pEntry->nWID);
2405  rItem.QueryValue(aValue, pEntry->nMemberId);
2406  }
2407  break;
2408  default:
2409  ;
2410  }
2411  return aValue;
2412 }
2413 
2414 uno::Any SwXStyle::getPropertyValue(const OUString& rPropertyName)
2415 {
2416  SolarMutexGuard aGuard;
2417  if(!m_pDoc)
2418  throw uno::RuntimeException();
2419  if(!m_pBasePool && !m_bIsDescriptor)
2420  throw uno::RuntimeException();
2422  const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
2423  SwStyleBase_Impl aBase(*m_pDoc, m_sStyleName, &m_pDoc->GetDfltTextFormatColl()->GetAttrSet()); // add pDfltTextFormatColl as parent
2424  return GetPropertyValue_Impl(pPropSet, aBase, rPropertyName);
2425 }
2426 
2427 uno::Sequence<uno::Any> SwXStyle::getPropertyValues(const uno::Sequence<OUString>& rPropertyNames)
2428 {
2429  SolarMutexGuard aGuard;
2430  if(!m_pDoc)
2431  throw uno::RuntimeException();
2432  if(!m_pBasePool && !m_bIsDescriptor)
2433  throw uno::RuntimeException();
2435  const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
2436  SwStyleBase_Impl aBase(*m_pDoc, m_sStyleName, &m_pDoc->GetDfltTextFormatColl()->GetAttrSet()); // add pDfltTextFormatColl as parent
2437  uno::Sequence<uno::Any> aValues(rPropertyNames.getLength());
2438  // workaround for bad designed API
2439  try
2440  {
2441  for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp)
2442  aValues[nProp] = GetPropertyValue_Impl(pPropSet, aBase, rPropertyNames[nProp]);
2443  }
2444  catch(beans::UnknownPropertyException&)
2445  {
2446  css::uno::Any anyEx = cppu::getCaughtException();
2447  throw css::lang::WrappedTargetRuntimeException("Unknown property exception caught",
2448  static_cast < cppu::OWeakObject * > ( this ), anyEx );
2449  }
2450  catch(lang::WrappedTargetException&)
2451  {
2452  css::uno::Any anyEx = cppu::getCaughtException();
2453  throw lang::WrappedTargetRuntimeException("WrappedTargetException caught",
2454  static_cast < cppu::OWeakObject * > ( this ), anyEx );
2455  }
2456  return aValues;
2457 }
2458 
2459 void SwXStyle::setPropertyValue(const OUString& rPropertyName, const uno::Any& rValue)
2460 {
2461  SolarMutexGuard aGuard;
2462  const uno::Sequence<OUString> aProperties(&rPropertyName, 1);
2463  const uno::Sequence<uno::Any> aValues(&rValue, 1);
2464  SetPropertyValues_Impl(aProperties, aValues);
2465 }
2466 
2467 beans::PropertyState SwXStyle::getPropertyState(const OUString& rPropertyName)
2468 {
2469  SolarMutexGuard aGuard;
2470  uno::Sequence<OUString> aNames{rPropertyName};
2471  uno::Sequence<beans::PropertyState> aStates = getPropertyStates(aNames);
2472  return aStates.getConstArray()[0];
2473 }
2474 
2475 // allow to retarget the SfxItemSet working on, default correctly. Only
2476 // use pSourceSet below this point (except in header/footer processing)
2477 static const SfxItemSet* lcl_GetItemsetForProperty(const SfxItemSet& rSet, SfxStyleFamily eFamily, const OUString& rPropertyName)
2478 {
2479  if(eFamily != SfxStyleFamily::Page)
2480  return &rSet;
2481  const bool isFooter = rPropertyName.startsWith("Footer");
2482  if(!isFooter && !rPropertyName.startsWith("Header") && rPropertyName != UNO_NAME_FIRST_IS_SHARED)
2483  return &rSet;
2484  const SvxSetItem* pSetItem;
2485  if(!lcl_GetHeaderFooterItem(rSet, rPropertyName, isFooter, pSetItem))
2486  return nullptr;
2487  return &pSetItem->GetItemSet();
2488 }
2489 uno::Sequence<beans::PropertyState> SwXStyle::getPropertyStates(const uno::Sequence<OUString>& rPropertyNames)
2490 {
2491  SolarMutexGuard aGuard;
2492  uno::Sequence<beans::PropertyState> aRet(rPropertyNames.getLength());
2493  beans::PropertyState* pStates = aRet.getArray();
2494 
2495  if(!m_pBasePool)
2496  throw uno::RuntimeException();
2497  m_pBasePool->SetSearchMask(m_rEntry.m_eFamily);
2499 
2500  SAL_WARN_IF(!pBase, "sw.uno", "where is the style?");
2501  if(!pBase)
2502  throw uno::RuntimeException();
2503 
2504  const OUString* pNames = rPropertyNames.getConstArray();
2505  rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2507 
2508  const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
2509  const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
2510  const SfxItemSet& rSet = xStyle->GetItemSet();
2511 
2512  for(sal_Int32 i = 0; i < rPropertyNames.getLength(); ++i)
2513  {
2514  const OUString sPropName = pNames[i];
2515  const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(sPropName);
2516 
2517  if(!pEntry)
2518  throw beans::UnknownPropertyException("Unknown property: " + sPropName, static_cast<cppu::OWeakObject*>(this));
2519 
2520  if(FN_UNO_NUM_RULES == pEntry->nWID || FN_UNO_FOLLOW_STYLE == pEntry->nWID)
2521  {
2522  // handle NumRules first, done
2523  pStates[i] = beans::PropertyState_DIRECT_VALUE;
2524  continue;
2525  }
2526  const SfxItemSet* pSourceSet = lcl_GetItemsetForProperty(rSet, m_rEntry.m_eFamily, sPropName);
2527  if(!pSourceSet)
2528  {
2529  // if no SetItem, value is ambiguous and we are done
2530  pStates[i] = beans::PropertyState_AMBIGUOUS_VALUE;
2531  continue;
2532  }
2533  switch(pEntry->nWID)
2534  {
2535  case OWN_ATTR_FILLBMP_MODE:
2536  {
2537  if(SfxItemState::SET == pSourceSet->GetItemState(XATTR_FILLBMP_STRETCH, false)
2538  || SfxItemState::SET == pSourceSet->GetItemState(XATTR_FILLBMP_TILE, false))
2539  {
2540  pStates[i] = beans::PropertyState_DIRECT_VALUE;
2541  }
2542  else
2543  {
2544  pStates[i] = beans::PropertyState_AMBIGUOUS_VALUE;
2545  }
2546  }
2547  break;
2548  case RES_BACKGROUND:
2549  {
2550  // for FlyFrames we need to mark the used properties from type RES_BACKGROUND
2551  // as beans::PropertyState_DIRECT_VALUE to let users of this property call
2552  // getPropertyValue where the member properties will be mapped from the
2553  // fill attributes to the according SvxBrushItem entries
2555  {
2556  pStates[i] = beans::PropertyState_DIRECT_VALUE;
2557  }
2558  else
2559  {
2560  pStates[i] = beans::PropertyState_DEFAULT_VALUE;
2561  }
2562  }
2563  break;
2564  default:
2565  {
2566  pStates[i] = pPropSet->getPropertyState(*pEntry, *pSourceSet);
2567 
2568  if(SfxStyleFamily::Page == m_rEntry.m_eFamily && SID_ATTR_PAGE_SIZE == pEntry->nWID && beans::PropertyState_DIRECT_VALUE == pStates[i])
2569  {
2570  const SvxSizeItem& rSize = rSet.Get(SID_ATTR_PAGE_SIZE);
2571  sal_uInt8 nMemberId = pEntry->nMemberId & 0x7f;
2572 
2573  if((LONG_MAX == rSize.GetSize().Width() && (MID_SIZE_WIDTH == nMemberId || MID_SIZE_SIZE == nMemberId)) ||
2574  (LONG_MAX == rSize.GetSize().Height() && MID_SIZE_HEIGHT == nMemberId))
2575  {
2576  pStates[i] = beans::PropertyState_DEFAULT_VALUE;
2577  }
2578  }
2579  }
2580  }
2581  }
2582  return aRet;
2583 }
2584 
2585 void SwXStyle::setPropertyToDefault(const OUString& rPropertyName)
2586 {
2587  const uno::Sequence<OUString> aSequence(&rPropertyName, 1);
2588  setPropertiesToDefault(aSequence);
2589 }
2590 
2591 static SwFormat* lcl_GetFormatForStyle(SwDoc const * pDoc, const rtl::Reference<SwDocStyleSheet>& xStyle, const SfxStyleFamily eFamily)
2592 {
2593  if(!xStyle.is())
2594  return nullptr;
2595  switch(eFamily)
2596  {
2597  case SfxStyleFamily::Char: return xStyle->GetCharFormat();
2598  case SfxStyleFamily::Para: return xStyle->GetCollection();
2599  case SfxStyleFamily::Frame: return xStyle->GetFrameFormat();
2600  case SfxStyleFamily::Page:
2601  {
2602  SwPageDesc* pDesc(pDoc->FindPageDesc(xStyle->GetPageDesc()->GetName()));
2603  if(pDesc)
2604  return &pDesc->GetMaster();
2605  }
2606  break;
2607  default: ;
2608  }
2609  return nullptr;
2610 }
2611 
2612 void SAL_CALL SwXStyle::setPropertiesToDefault(const uno::Sequence<OUString>& aPropertyNames)
2613 {
2614  SolarMutexGuard aGuard;
2615  const rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(GetStyleSheetBase())));
2616  SwFormat* pTargetFormat = lcl_GetFormatForStyle(m_pDoc, xStyle, m_rEntry.m_eFamily);
2617  if(!pTargetFormat)
2618  {
2619  if(!m_bIsDescriptor)
2620  return;
2621  for(const auto& rName : aPropertyNames)
2622  m_pPropertiesImpl->ClearProperty(rName);
2623  return;
2624  }
2625  const sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.m_nPropMapType;
2626  const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
2627  const SfxItemPropertyMap &rMap = pPropSet->getPropertyMap();
2628  for(const auto& rName : aPropertyNames)
2629  {
2630  const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(rName);
2631  if(!pEntry)
2632  throw beans::UnknownPropertyException("Unknown property: " + rName, static_cast<cppu::OWeakObject*>(this));
2633  if(pEntry->nWID == FN_UNO_FOLLOW_STYLE || pEntry->nWID == FN_UNO_NUM_RULES)
2634  throw uno::RuntimeException("Cannot reset: " + rName, static_cast<cppu::OWeakObject*>(this));
2635  if(pEntry->nFlags & beans::PropertyAttribute::READONLY)
2636  throw uno::RuntimeException("setPropertiesToDefault: property is read-only: " + rName, static_cast<cppu::OWeakObject*>(this));
2637  if(pEntry->nWID == RES_PARATR_OUTLINELEVEL)
2638  {
2639  static_cast<SwTextFormatColl*>(pTargetFormat)->DeleteAssignmentToListLevelOfOutlineStyle();
2640  continue;
2641  }
2642  pTargetFormat->ResetFormatAttr(pEntry->nWID);
2643  if(OWN_ATTR_FILLBMP_MODE == pEntry->nWID)
2644  {
2645  //
2646  SwDoc* pDoc = pTargetFormat->GetDoc();
2648  aSet.SetParent(&pTargetFormat->GetAttrSet());
2649 
2650  aSet.ClearItem(XATTR_FILLBMP_STRETCH);
2651  aSet.ClearItem(XATTR_FILLBMP_TILE);
2652 
2653  pTargetFormat->SetFormatAttr(aSet);
2654  }
2655  }
2656 }
2657 
2659 {
2660  SolarMutexGuard aGuard;
2661  if(!m_pBasePool)
2662  {
2663  if(!m_bIsDescriptor)
2664  throw uno::RuntimeException();
2665  m_pPropertiesImpl->ClearAllProperties();
2666  return;
2667  }
2668  const rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(GetStyleSheetBase())));
2669  if(!xStyle.is())
2670  throw uno::RuntimeException();
2671  if(SfxStyleFamily::Page == m_rEntry.m_eFamily)
2672  {
2673  size_t nPgDscPos(0);
2674  SwPageDesc* pDesc = m_pDoc->FindPageDesc(xStyle->GetPageDesc()->GetName(), &nPgDscPos);
2675  SwFormat* pPageFormat(nullptr);
2676  if(pDesc)
2677  {
2678  pPageFormat = &pDesc->GetMaster();
2679  pDesc->SetUseOn(UseOnPage::All);
2680  }
2681  else
2682  pPageFormat = lcl_GetFormatForStyle(m_pDoc, xStyle, m_rEntry.m_eFamily);
2683  SwPageDesc& rPageDesc = m_pDoc->GetPageDesc(nPgDscPos);
2684  rPageDesc.ResetAllMasterAttr();
2685 
2687  sal_Int32 nSize = GetMetricVal(CM_1) * 2;
2688  aLR.SetLeft(nSize);
2689  aLR.SetLeft(nSize);
2691  aUL.SetUpper(static_cast<sal_uInt16>(nSize));
2692  aUL.SetLower(static_cast<sal_uInt16>(nSize));
2693  pPageFormat->SetFormatAttr(aLR);
2694  pPageFormat->SetFormatAttr(aUL);
2696  std::shared_ptr<SwFormatFrameSize> aFrameSz(std::make_shared<SwFormatFrameSize>(ATT_FIX_SIZE));
2697 
2698  if(RES_POOLPAGE_STANDARD == rPageDesc.GetPoolFormatId())
2699  {
2701  {
2702  const Size aPhysSize( SvxPaperInfo::GetPaperSize(
2703  static_cast<Printer*>(m_pDoc->getIDocumentDeviceAccess().getPrinter(false))));
2704  aFrameSz->SetSize(aPhysSize);
2705  }
2706  else
2707  {
2708  aFrameSz->SetSize(SvxPaperInfo::GetDefaultPaperSize());
2709  }
2710 
2711  }
2712  else
2713  {
2714  aFrameSz.reset(static_cast<SwFormatFrameSize*>(pStdPgDsc->GetMaster().GetFrameSize().Clone()));
2715  }
2716 
2717  if(pStdPgDsc->GetLandscape())
2718  {
2719  SwTwips nTmp = aFrameSz->GetHeight();
2720  aFrameSz->SetHeight(aFrameSz->GetWidth());
2721  aFrameSz->SetWidth(nTmp);
2722  }
2723 
2724  pPageFormat->SetFormatAttr(*aFrameSz);
2725  m_pDoc->ChgPageDesc(nPgDscPos, m_pDoc->GetPageDesc(nPgDscPos));
2726  return;
2727  }
2728  if(SfxStyleFamily::Para == m_rEntry.m_eFamily)
2729  {
2730  if(xStyle->GetCollection())
2731  xStyle->GetCollection()->DeleteAssignmentToListLevelOfOutlineStyle();
2732  }
2733  SwFormat* const pTargetFormat = lcl_GetFormatForStyle(m_pDoc, xStyle, m_rEntry.m_eFamily);
2734  if(!pTargetFormat)
2735  return;
2736  pTargetFormat->ResetAllFormatAttr();
2737 }
2738 
2739 uno::Sequence<uno::Any> SAL_CALL SwXStyle::getPropertyDefaults(const uno::Sequence<OUString>& aPropertyNames)
2740 {
2741  SolarMutexGuard aGuard;
2742  sal_Int32 nCount = aPropertyNames.getLength();
2743  uno::Sequence<uno::Any> aRet(nCount);
2744  if(!nCount)
2745  return aRet;
2747  if(!pBase)
2748  throw uno::RuntimeException();
2749  rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2750  const sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.m_nPropMapType;
2751  const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
2752  const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
2753 
2754  const SfxItemSet &rSet = xStyle->GetItemSet(), *pParentSet = rSet.GetParent();
2755  for(sal_Int32 i = 0; i < nCount; ++i)
2756  {
2757  const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(aPropertyNames[i]);
2758 
2759  if(!pEntry)
2760  throw beans::UnknownPropertyException("Unknown property: " + aPropertyNames[i], static_cast < cppu::OWeakObject * >(this));
2761  // these cannot be in an item set, especially not the
2762  // parent set, so the default value is void
2763  if (pEntry->nWID >= RES_UNKNOWNATR_END)
2764  continue;
2765 
2766  if(pParentSet)
2767  {
2768  aSwMapProvider.GetPropertySet(nPropSetId)->getPropertyValue(aPropertyNames[i], *pParentSet, aRet[i]);
2769  }
2770  else if(pEntry->nWID != rSet.GetPool()->GetSlotId(pEntry->nWID))
2771  {
2772  const SfxPoolItem& rItem = rSet.GetPool()->GetDefaultItem(pEntry->nWID);
2773  rItem.QueryValue(aRet[i], pEntry->nMemberId);
2774  }
2775  }
2776  return aRet;
2777 }
2778 
2779 uno::Any SwXStyle::getPropertyDefault(const OUString& rPropertyName)
2780 {
2781  const uno::Sequence<OUString> aSequence(&rPropertyName, 1);
2782  return getPropertyDefaults(aSequence)[0];
2783 }
2784 
2785 void SwXStyle::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
2786 {
2787  if((rHint.GetId() == SfxHintId::Dying) || (rHint.GetId() == SfxHintId::StyleSheetErased))
2788  {
2789  m_pBasePool = nullptr;
2791  }
2792  else if(rHint.GetId() == SfxHintId::StyleSheetChanged)
2793  {
2794  static_cast<SfxStyleSheetBasePool&>(rBC).SetSearchMask(m_rEntry.m_eFamily);
2795  SfxStyleSheetBase* pOwnBase = static_cast<SfxStyleSheetBasePool&>(rBC).Find(m_sStyleName);
2796  if(!pOwnBase)
2797  {
2799  Invalidate();
2800  }
2801  }
2802 }
2803 
2805 {
2806  m_sStyleName.clear();
2807  m_pBasePool = nullptr;
2808  m_pDoc = nullptr;
2809  m_xStyleData.clear();
2810  m_xStyleFamily.clear();
2811 }
2812 
2813 SwXPageStyle::SwXPageStyle(SfxStyleSheetBasePool& rPool, SwDocShell* pDocSh, const OUString& rStyleName)
2814  : SwXStyle(&rPool, SfxStyleFamily::Page, pDocSh->GetDoc(), rStyleName)
2815 { }
2816 
2818  : SwXStyle(pDocSh->GetDoc(), SfxStyleFamily::Page)
2819 { }
2820 
2821 void SwXStyle::PutItemToSet(const SvxSetItem* pSetItem, const SfxItemPropertySet& rPropSet, const SfxItemPropertySimpleEntry& rEntry, const uno::Any& rVal, SwStyleBase_Impl& rBaseImpl)
2822 {
2823  // create a new SvxSetItem and get it's ItemSet as new target
2824  const std::unique_ptr<SvxSetItem> pNewSetItem(static_cast<SvxSetItem*>(pSetItem->Clone()));
2825  SfxItemSet& rSetSet = pNewSetItem->GetItemSet();
2826 
2827  // set parent to ItemSet to ensure XFILL_NONE as XFillStyleItem
2829 
2830  // replace the used SfxItemSet at the SwStyleBase_Impl temporarily and use the
2831  // default method to set the property
2832  {
2833  SwStyleBase_Impl::ItemSetOverrider o(rBaseImpl, &rSetSet);
2834  SetStyleProperty(rEntry, rPropSet, rVal, rBaseImpl);
2835  }
2836 
2837  // reset parent at ItemSet from SetItem
2838  rSetSet.SetParent(nullptr);
2839 
2840  // set the new SvxSetItem at the real target and delete it
2841  rBaseImpl.GetItemSet().Put(*pNewSetItem);
2842 }
2843 
2844 void SwXPageStyle::SetPropertyValues_Impl(const uno::Sequence<OUString>& rPropertyNames, const uno::Sequence<uno::Any>& rValues)
2845 {
2846  if(!GetDoc())
2847  throw uno::RuntimeException();
2848 
2849  if(rPropertyNames.getLength() != rValues.getLength())
2850  throw lang::IllegalArgumentException();
2851 
2853  const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
2854  SwStyleBase_Impl aBaseImpl(*GetDoc(), GetStyleName(), &GetDoc()->GetDfltFrameFormat()->GetAttrSet()); // add pDfltFrameFormat as parent
2855  if(!m_pBasePool)
2856  {
2857  if(!IsDescriptor())
2858  throw uno::RuntimeException();
2859  for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp)
2860  if(!m_pPropertiesImpl->SetProperty(rPropertyNames[nProp], rValues[nProp]))
2861  throw lang::IllegalArgumentException();
2862  return;
2863  }
2865  if(!pBase)
2866  throw uno::RuntimeException();
2867  aBaseImpl.setNewBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
2868  for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp)
2869  {
2870  const OUString& rPropName = rPropertyNames[nProp];
2871  const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(rPropName);
2872 
2873  if(!pEntry)
2874  throw beans::UnknownPropertyException("Unknown property: " + rPropName, static_cast<cppu::OWeakObject*>(this));
2875  if(pEntry->nFlags & beans::PropertyAttribute::READONLY)
2876  throw beans::PropertyVetoException("Property is read-only: " + rPropName, static_cast<cppu::OWeakObject*>(this));
2877 
2878  const bool bHeader(rPropName.startsWith("Header"));
2879  const bool bFooter(rPropName.startsWith("Footer"));
2880  const bool bFirstIsShared(rPropName == UNO_NAME_FIRST_IS_SHARED);
2881  if(bHeader || bFooter || bFirstIsShared)
2882  {
2883  switch(pEntry->nWID)
2884  {
2885  case SID_ATTR_PAGE_ON:
2886  case RES_BACKGROUND:
2887  case RES_BOX:
2888  case RES_LR_SPACE:
2889  case RES_SHADOW:
2890  case RES_UL_SPACE:
2891  case SID_ATTR_PAGE_DYNAMIC:
2892  case SID_ATTR_PAGE_SHARED:
2893  case SID_ATTR_PAGE_SHARED_FIRST:
2894  case SID_ATTR_PAGE_SIZE:
2896  {
2897  // it is a Header/Footer entry, access the SvxSetItem containing it's information
2898  const SvxSetItem* pSetItem = nullptr;
2899  if (lcl_GetHeaderFooterItem(aBaseImpl.GetItemSet(), rPropName, bFooter, pSetItem))
2900  {
2901  PutItemToSet(pSetItem, *pPropSet, *pEntry, rValues[nProp], aBaseImpl);
2902 
2903  if (pEntry->nWID == SID_ATTR_PAGE_SHARED_FIRST)
2904  {
2905  // Need to add this to the other as well
2906  if (SfxItemState::SET == aBaseImpl.GetItemSet().GetItemState(
2907  bFooter ? SID_ATTR_PAGE_HEADERSET : SID_ATTR_PAGE_FOOTERSET,
2908  false, reinterpret_cast<const SfxPoolItem**>(&pSetItem)))
2909  {
2910  PutItemToSet(pSetItem, *pPropSet, *pEntry, rValues[nProp], aBaseImpl);
2911  }
2912  }
2913  }
2914  else if(pEntry->nWID == SID_ATTR_PAGE_ON && rValues[nProp].get<bool>())
2915  {
2916  // Header/footer gets switched on, create defaults and the needed SfxSetItem
2917  SfxItemSet aTempSet(*aBaseImpl.GetItemSet().GetPool(),
2919 
2920  // FillAttribute support
2922 
2923  SID_ATTR_BORDER_INNER,SID_ATTR_BORDER_INNER, // [10023
2924  SID_ATTR_PAGE_SIZE,SID_ATTR_PAGE_SIZE, // [10051
2925  SID_ATTR_PAGE_ON,SID_ATTR_PAGE_SHARED, // [10060
2926  SID_ATTR_PAGE_SHARED_FIRST,SID_ATTR_PAGE_SHARED_FIRST>{});
2927 
2928  // set correct parent to get the XFILL_NONE FillStyle as needed
2929  aTempSet.SetParent(&GetDoc()->GetDfltFrameFormat()->GetAttrSet());
2930 
2931  aTempSet.Put(SfxBoolItem(SID_ATTR_PAGE_ON, true));
2932  aTempSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(MM50, MM50)));
2933  aTempSet.Put(SvxLRSpaceItem(RES_LR_SPACE));
2934  aTempSet.Put(SvxULSpaceItem(RES_UL_SPACE));
2935  aTempSet.Put(SfxBoolItem(SID_ATTR_PAGE_SHARED, true));
2936  aTempSet.Put(SfxBoolItem(SID_ATTR_PAGE_SHARED_FIRST, true));
2937  aTempSet.Put(SfxBoolItem(SID_ATTR_PAGE_DYNAMIC, true));
2938 
2939  SvxSetItem aNewSetItem(bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, aTempSet);
2940  aBaseImpl.GetItemSet().Put(aNewSetItem);
2941  }
2942  }
2943  continue;
2944  case XATTR_FILLBMP_SIZELOG:
2949  case XATTR_FILLBMP_POS:
2950  case XATTR_FILLBMP_SIZEX:
2951  case XATTR_FILLBMP_SIZEY:
2952  case XATTR_FILLBMP_STRETCH:
2953  case XATTR_FILLBMP_TILE:
2954  case OWN_ATTR_FILLBMP_MODE:
2955  case XATTR_FILLCOLOR:
2956  case XATTR_FILLBACKGROUND:
2957  case XATTR_FILLBITMAP:
2959  case XATTR_FILLGRADIENT:
2960  case XATTR_FILLHATCH:
2961  case XATTR_FILLSTYLE:
2965  if(bFirstIsShared) // only special handling for headers/footers here
2966  break;
2967  {
2968  const SvxSetItem* pSetItem = nullptr;
2969 
2970  if(SfxItemState::SET == aBaseImpl.GetItemSet().GetItemState(bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, false, reinterpret_cast<const SfxPoolItem**>(&pSetItem)))
2971  {
2972  // create a new SvxSetItem and get it's ItemSet as new target
2973  std::unique_ptr<SvxSetItem> pNewSetItem(static_cast<SvxSetItem*>(pSetItem->Clone()));
2974  SfxItemSet& rSetSet = pNewSetItem->GetItemSet();
2975 
2976  // set parent to ItemSet to ensure XFILL_NONE as XFillStyleItem
2977  rSetSet.SetParent(&GetDoc()->GetDfltFrameFormat()->GetAttrSet());
2978 
2979  // replace the used SfxItemSet at the SwStyleBase_Impl temporarily and use the
2980  // default method to set the property
2981  {
2982  SwStyleBase_Impl::ItemSetOverrider o(aBaseImpl, &rSetSet);
2983  SetStyleProperty(*pEntry, *pPropSet, rValues[nProp], aBaseImpl);
2984  }
2985 
2986  // reset paret at ItemSet from SetItem
2987  rSetSet.SetParent(nullptr);
2988 
2989  // set the new SvxSetItem at the real target and delete it
2990  aBaseImpl.GetItemSet().Put(*pNewSetItem);
2991  }
2992  }
2993  continue;
2994  default: ;
2995  }
2996  }
2997  switch(pEntry->nWID)
2998  {
2999  case SID_ATTR_PAGE_DYNAMIC:
3000  case SID_ATTR_PAGE_SHARED:
3001  case SID_ATTR_PAGE_SHARED_FIRST:
3002  case SID_ATTR_PAGE_ON:
3004  // these slots are exclusive to Header/Footer, thus this is an error
3005  throw beans::UnknownPropertyException("Unknown property: " + rPropName, static_cast<cppu::OWeakObject*>(this));
3006  case FN_UNO_HEADER:
3007  case FN_UNO_HEADER_LEFT:
3008  case FN_UNO_HEADER_RIGHT:
3009  case FN_UNO_HEADER_FIRST:
3010  case FN_UNO_FOOTER:
3011  case FN_UNO_FOOTER_LEFT:
3012  case FN_UNO_FOOTER_RIGHT:
3013  case FN_UNO_FOOTER_FIRST:
3014  throw lang::IllegalArgumentException();
3015  case FN_PARAM_FTN_INFO:
3016  {
3017  const SfxPoolItem& rItem = aBaseImpl.GetItemSet().Get(FN_PARAM_FTN_INFO);
3018  std::unique_ptr<SfxPoolItem> pNewFootnoteItem(rItem.Clone());
3019  if(!pNewFootnoteItem->PutValue(rValues[nProp], pEntry->nMemberId))
3020  throw lang::IllegalArgumentException();
3021  aBaseImpl.GetItemSet().Put(std::move(pNewFootnoteItem));
3022  break;
3023  }
3024  default:
3025  {
3026  SetStyleProperty(*pEntry, *pPropSet, rValues[nProp], aBaseImpl);
3027  break;
3028  }
3029  }
3030  }
3031 
3032  if(aBaseImpl.HasItemSet())
3033  {
3034  ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
3035 
3036  if (undoGuard.UndoWasEnabled())
3037  {
3038  // Fix i64460: as long as Undo of page styles with header/footer causes trouble...
3040  }
3041 
3042  aBaseImpl.getNewBase()->SetItemSet(aBaseImpl.GetItemSet());
3043  }
3044 }
3045 
3046 void SwXPageStyle::setPropertyValues(const uno::Sequence<OUString>& rPropertyNames, const uno::Sequence<uno::Any>& rValues)
3047 {
3048  SolarMutexGuard aGuard;
3049 
3050  // workaround for bad designed API
3051  try
3052  {
3053  SetPropertyValues_Impl(rPropertyNames, rValues);
3054  }
3055  catch (const beans::UnknownPropertyException &rException)
3056  {
3057  // wrap the original (here not allowed) exception in
3058  // a lang::WrappedTargetException that gets thrown instead.
3059  lang::WrappedTargetException aWExc;
3060  aWExc.TargetException <<= rException;
3061  throw aWExc;
3062  }
3063 }
3064 
3065 static uno::Reference<text::XText> lcl_makeHeaderFooter(const sal_uInt16 nRes, const bool bHeader, SwFrameFormat const*const pFrameFormat)
3066 {
3067  if (!pFrameFormat)
3068  return nullptr;
3069  const SfxItemSet& rSet = pFrameFormat->GetAttrSet();
3070  const SfxPoolItem* pItem;
3071  if(SfxItemState::SET != rSet.GetItemState(nRes, true, &pItem))
3072  return nullptr;
3073  SwFrameFormat* const pHeadFootFormat = bHeader
3074  ? static_cast<SwFormatHeader*>(const_cast<SfxPoolItem*>(pItem))->GetHeaderFormat()
3075  : static_cast<SwFormatFooter*>(const_cast<SfxPoolItem*>(pItem))->GetFooterFormat();
3076  if(!pHeadFootFormat)
3077  return nullptr;
3078  return SwXHeadFootText::CreateXHeadFootText(*pHeadFootFormat, bHeader);
3079 }
3080 
3081 uno::Sequence<uno::Any> SwXPageStyle::GetPropertyValues_Impl(const uno::Sequence<OUString>& rPropertyNames)
3082 {
3083  if(!GetDoc())
3084  throw uno::RuntimeException();
3085 
3086  sal_Int32 nLength = rPropertyNames.getLength();
3087  uno::Sequence<uno::Any> aRet (nLength);
3088  if(!m_pBasePool)
3089  {
3090  if(!IsDescriptor())
3091  throw uno::RuntimeException();
3092  for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp)
3093  {
3094  const uno::Any* pAny = nullptr;
3095  m_pPropertiesImpl->GetProperty(rPropertyNames[nProp], pAny);
3096  if (!pAny->hasValue())
3097  SwStyleProperties_Impl::GetProperty(rPropertyNames[nProp], m_xStyleData, aRet[nProp]);
3098  else
3099  aRet[nProp] = *pAny;
3100  }
3101  return aRet;
3102  }
3104  const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
3105  SwStyleBase_Impl aBase(*GetDoc(), GetStyleName(), &GetDoc()->GetDfltFrameFormat()->GetAttrSet()); // add pDfltFrameFormat as parent
3107  if(!pBase)
3108  throw uno::RuntimeException();
3109  for(sal_Int32 nProp = 0; nProp < nLength; ++nProp)
3110  {
3111  const OUString& rPropName = rPropertyNames[nProp];
3112  const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(rPropName);
3113 
3114  if (!pEntry)
3115  throw beans::UnknownPropertyException("Unknown property: " + rPropName, static_cast < cppu::OWeakObject * > ( this ) );
3116  const bool bHeader(rPropName.startsWith("Header"));
3117  const bool bFooter(rPropName.startsWith("Footer"));
3118  const bool bFirstIsShared(rPropName == UNO_NAME_FIRST_IS_SHARED);
3119  if(bHeader || bFooter || bFirstIsShared)
3120  {
3121  switch(pEntry->nWID)
3122  {
3123  case SID_ATTR_PAGE_ON:
3124  case RES_BACKGROUND:
3125  case RES_BOX:
3126  case RES_LR_SPACE:
3127  case RES_SHADOW:
3128  case RES_UL_SPACE:
3129  case SID_ATTR_PAGE_DYNAMIC:
3130  case SID_ATTR_PAGE_SHARED:
3131  case SID_ATTR_PAGE_SHARED_FIRST:
3132  case SID_ATTR_PAGE_SIZE:
3134  {
3135  // slot is a Header/Footer slot
3136  rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pBase) ) );
3137  const SfxItemSet& rSet = xStyle->GetItemSet();
3138  const SvxSetItem* pSetItem;
3139 
3140  if (lcl_GetHeaderFooterItem(rSet, rPropName, bFooter, pSetItem))
3141  {
3142  // get from SfxItemSet of the corresponding SfxSetItem
3143  const SfxItemSet& rSetSet = pSetItem->GetItemSet();
3144  {
3145  SwStyleBase_Impl::ItemSetOverrider o(aBase, &const_cast< SfxItemSet& >(rSetSet));
3146  aRet[nProp] = GetStyleProperty_Impl(*pEntry, *pPropSet, aBase);
3147  }
3148  }
3149  else if(pEntry->nWID == SID_ATTR_PAGE_ON)
3150  {
3151  // header/footer is not available, thus off. Default is <false>, though
3152  aRet[nProp] <<= false;
3153  }
3154  }
3155  continue;
3156  case XATTR_FILLBMP_SIZELOG:
3161  case XATTR_FILLBMP_POS:
3162  case XATTR_FILLBMP_SIZEX:
3163  case XATTR_FILLBMP_SIZEY:
3164  case XATTR_FILLBMP_STRETCH:
3165  case XATTR_FILLBMP_TILE:
3166  case OWN_ATTR_FILLBMP_MODE:
3167  case XATTR_FILLCOLOR:
3168  case XATTR_FILLBACKGROUND:
3169  case XATTR_FILLBITMAP:
3171  case XATTR_FILLGRADIENT:
3172  case XATTR_FILLHATCH:
3173  case XATTR_FILLSTYLE:
3177  if(bFirstIsShared) // only special handling for headers/footers here
3178  break;
3179  {
3180  rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pBase) ) );
3181  const SfxItemSet& rSet = xStyle->GetItemSet();
3182  const SvxSetItem* pSetItem;
3183  if(SfxItemState::SET == rSet.GetItemState(bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, false, reinterpret_cast<const SfxPoolItem**>(&pSetItem)))
3184  {
3185  // set at SfxItemSet of the corresponding SfxSetItem
3186  const SfxItemSet& rSetSet = pSetItem->GetItemSet();
3187  {
3188  SwStyleBase_Impl::ItemSetOverrider o(aBase, &const_cast<SfxItemSet&>(rSetSet));
3189  aRet[nProp] = GetStyleProperty_Impl(*pEntry, *pPropSet, aBase);
3190  }
3191  }
3192  }
3193  continue;
3194  default: ;
3195  }
3196  }
3197  switch(pEntry->nWID)
3198  {
3199  // these slots are exclusive to Header/Footer, thus this is an error
3200  case SID_ATTR_PAGE_DYNAMIC:
3201  case SID_ATTR_PAGE_SHARED:
3202  case SID_ATTR_PAGE_SHARED_FIRST:
3203  case SID_ATTR_PAGE_ON:
3205  throw beans::UnknownPropertyException( "Unknown property: " + rPropName, static_cast < cppu::OWeakObject * > ( this ) );
3206  case FN_UNO_HEADER:
3207  case FN_UNO_HEADER_LEFT:
3208  case FN_UNO_HEADER_FIRST:
3209  case FN_UNO_HEADER_RIGHT:
3210  case FN_UNO_FOOTER:
3211  case FN_UNO_FOOTER_LEFT:
3212  case FN_UNO_FOOTER_FIRST:
3213  case FN_UNO_FOOTER_RIGHT:
3214  {
3215  bool bLeft(false);
3216  bool bFirst(false);
3217  sal_uInt16 nRes = 0;
3218  switch(pEntry->nWID)
3219  {
3220  case FN_UNO_HEADER: nRes = RES_HEADER; break;
3221  case FN_UNO_HEADER_LEFT: nRes = RES_HEADER; bLeft = true; break;
3222  case FN_UNO_HEADER_FIRST: nRes = RES_HEADER; bFirst = true; break;
3223  case FN_UNO_HEADER_RIGHT: nRes = RES_HEADER; break;
3224  case FN_UNO_FOOTER: nRes = RES_FOOTER; break;
3225  case FN_UNO_FOOTER_LEFT: nRes = RES_FOOTER; bLeft = true; break;
3226  case FN_UNO_FOOTER_FIRST: nRes = RES_FOOTER; bFirst = true; break;
3227  case FN_UNO_FOOTER_RIGHT: nRes = RES_FOOTER; break;
3228  default: ;
3229  }
3230 
3231  const SwPageDesc* pDesc = aBase.GetOldPageDesc();
3232  assert(pDesc);
3233  const SwFrameFormat* pFrameFormat = nullptr;
3234  bool bShare = (nRes == RES_HEADER && pDesc->IsHeaderShared()) || (nRes == RES_FOOTER && pDesc->IsFooterShared());
3235  bool bShareFirst = pDesc->IsFirstShared();
3236  // TextLeft returns the left content if there is one,
3237  // Text and TextRight return the master content.
3238  // TextRight does the same as Text and is for
3239  // compatibility only.
3240  if(bLeft && !bShare)
3241  pFrameFormat = &pDesc->GetLeft();
3242  else if(bFirst && !bShareFirst)
3243  {
3244  pFrameFormat = &pDesc->GetFirstMaster();
3245  // no need to make GetFirstLeft() accessible
3246  // since it is always shared
3247  }
3248  else
3249  pFrameFormat = &pDesc->GetMaster();
3250  const uno::Reference<text::XText> xRet = lcl_makeHeaderFooter(nRes, nRes == RES_HEADER, pFrameFormat);
3251  if (xRet.is())
3252  aRet[nProp] <<= xRet;
3253  }
3254  break;
3255  case FN_PARAM_FTN_INFO:
3256  {
3257  rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
3258  const SfxItemSet& rSet = xStyle->GetItemSet();
3259  const SfxPoolItem& rItem = rSet.Get(FN_PARAM_FTN_INFO);
3260  rItem.QueryValue(aRet[nProp], pEntry->nMemberId);
3261  }
3262  break;
3263  default:
3264  aRet[nProp] = GetStyleProperty_Impl(*pEntry, *pPropSet, aBase);
3265  }
3266  }
3267  return aRet;
3268 }
3269 
3270 uno::Sequence<uno::Any> SwXPageStyle::getPropertyValues(const uno::Sequence<OUString>& rPropertyNames)
3271 {
3272  SolarMutexGuard aGuard;
3273  uno::Sequence<uno::Any> aValues;
3274 
3275  // workaround for bad designed API
3276  try
3277  {
3278  aValues = GetPropertyValues_Impl(rPropertyNames);
3279  }
3280  catch(beans::UnknownPropertyException &)
3281  {
3282  css::uno::Any anyEx = cppu::getCaughtException();
3283  throw lang::WrappedTargetRuntimeException("Unknown property exception caught",
3284  static_cast < cppu::OWeakObject * > ( this ), anyEx );
3285  }
3286  catch(lang::WrappedTargetException &)
3287  {
3288  css::uno::Any anyEx = cppu::getCaughtException();
3289  throw lang::WrappedTargetRuntimeException("WrappedTargetException caught",
3290  static_cast < cppu::OWeakObject * > ( this ), anyEx );
3291  }
3292 
3293  return aValues;
3294 }
3295 
3296 uno::Any SwXPageStyle::getPropertyValue(const OUString& rPropertyName)
3297 {
3298  SolarMutexGuard aGuard;
3299  const uno::Sequence<OUString> aProperties(&rPropertyName, 1);
3300  return GetPropertyValues_Impl(aProperties)[0];
3301 }
3302 
3303 void SwXPageStyle::setPropertyValue(const OUString& rPropertyName, const uno::Any& rValue)
3304 {
3305  SolarMutexGuard aGuard;
3306  const uno::Sequence<OUString> aProperties(&rPropertyName, 1);
3307  const uno::Sequence<uno::Any> aValues(&rValue, 1);
3308  SetPropertyValues_Impl(aProperties, aValues);
3309 }
3310 
3312  : SwXStyle(pDoc, SfxStyleFamily::Frame, false)
3313 { }
3314 
3315 void SwXFrameStyle::SetItem(sal_uInt16 eAtr, const SfxPoolItem& rItem)
3316 {
3317  assert(eAtr >= RES_FRMATR_BEGIN && eAtr < RES_FRMATR_END);
3319  if(!pBase)
3320  return;
3321  rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
3322  SfxItemSet& rStyleSet = xStyle->GetItemSet();
3323  SfxItemSet aSet(*rStyleSet.GetPool(), {{sal_uInt16(eAtr), sal_uInt16(eAtr)}});
3324  aSet.Put(rItem);
3325  xStyle->SetItemSet(aSet);
3326 }
3327 
3328 const SfxPoolItem* SwXFrameStyle::GetItem(sal_uInt16 eAtr)
3329 {
3330  assert(eAtr >= RES_FRMATR_BEGIN && eAtr < RES_FRMATR_END);
3332  if(!pBase)
3333  return nullptr;
3334  rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase)));
3335  return &xStyle->GetItemSet().Get(eAtr);
3336 }
3337 
3338 uno::Sequence<uno::Type> SwXFrameStyle::getTypes()
3339 {
3340  return cppu::OTypeCollection(
3342  SwXStyle::getTypes()
3343  ).getTypes();
3344 }
3345 
3347 {
3349  return uno::makeAny(uno::Reference<XEventsSupplier>(this));
3350  return SwXStyle::queryInterface(rType);
3351 }
3352 
3353 uno::Reference<container::XNameReplace> SwXFrameStyle::getEvents()
3354 {
3355  return new SwFrameStyleEventDescriptor(*this);
3356 }
3357 
3358 // Already implemented autostyle families: 3
3359 #define AUTOSTYLE_FAMILY_COUNT 3
3361 {
3365 };
3366 
3368 {
3369  std::vector<std::shared_ptr<SfxItemSet>> mAutoStyles;
3370  std::vector<std::shared_ptr<SfxItemSet>>::iterator aIter;
3373 public:
3375  bool hasMoreElements() { return aIter != mAutoStyles.end(); }
3376  std::shared_ptr<SfxItemSet> const & nextElement() { return *(aIter++); }
3378  SwDoc* getDoc() const { return pDoc; }
3379 };
3380 
3382  SwUnoCollection(rDocShell.GetDoc()), m_pDocShell( &rDocShell )
3383 {
3384 }
3385 
3387 {
3388 }
3389 
3391 {
3392  return AUTOSTYLE_FAMILY_COUNT;
3393 }
3394 
3396 {
3397  SolarMutexGuard aGuard;
3398  uno::Any aRet;
3399  if(nIndex < 0 || nIndex >= AUTOSTYLE_FAMILY_COUNT)
3400  throw lang::IndexOutOfBoundsException();
3401  if(!IsValid())
3402  throw uno::RuntimeException();
3403 
3404  uno::Reference< style::XAutoStyleFamily > aRef;
3406  switch( nType )
3407  {
3409  {
3410  if(!m_xAutoCharStyles.is())
3412  aRef = m_xAutoCharStyles;
3413  }
3414  break;
3416  {
3417  if(!m_xAutoRubyStyles.is())
3419  aRef = m_xAutoRubyStyles;
3420  }
3421  break;
3423  {
3424  if(!m_xAutoParaStyles.is())
3426  aRef = m_xAutoParaStyles;
3427  }
3428  break;
3429 
3430  default:
3431  ;
3432  }
3433  aRet <<= aRef;
3434 
3435  return aRet;
3436 }
3437 
3439 {
3441 }
3442 
3444 {
3445  return true;
3446 }
3447 
3448 uno::Any SwXAutoStyles::getByName(const OUString& Name)
3449 {
3450  uno::Any aRet;
3451  if(Name == "CharacterStyles")
3452  aRet = getByIndex(0);
3453  else if(Name == "RubyStyles")
3454  aRet = getByIndex(1);
3455  else if(Name == "ParagraphStyles")
3456  aRet = getByIndex(2);
3457  else
3458  throw container::NoSuchElementException();
3459  return aRet;
3460 }
3461 
3462 uno::Sequence< OUString > SwXAutoStyles::getElementNames()
3463 {
3464  uno::Sequence< OUString > aNames(AUTOSTYLE_FAMILY_COUNT);
3465  OUString* pNames = aNames.getArray();
3466  pNames[0] = "CharacterStyles";
3467  pNames[1] = "RubyStyles";
3468  pNames[2] = "ParagraphStyles";
3469  return aNames;
3470 }
3471 
3472 sal_Bool SwXAutoStyles::hasByName(const OUString& Name)
3473 {
3474  if( Name == "CharacterStyles" ||
3475  Name == "RubyStyles" ||
3476  Name == "ParagraphStyles" )
3477  return true;
3478  else
3479  return false;
3480 }
3481 
3483  m_pDocShell( pDocSh ), m_eFamily(nFamily)
3484 {
3485  // Register ourselves as a listener to the document (via the page descriptor)
3487 }
3488 
3490 {
3491 }
3492 
3494 {
3495  if(rHint.GetId() == SfxHintId::Dying)
3496  m_pDocShell = nullptr;
3497 }
3498 
3499 uno::Reference< style::XAutoStyle > SwXAutoStyleFamily::insertStyle(
3500  const uno::Sequence< beans::PropertyValue >& Values )
3501 {
3502  if (!m_pDocShell)
3503  {
3504  throw uno::RuntimeException();
3505  }
3506 
3507  const sal_uInt16* pRange = nullptr;
3508  const SfxItemPropertySet* pPropSet = nullptr;
3509  switch( m_eFamily )
3510  {
3512  {
3513  pRange = aCharAutoFormatSetRange;
3515  break;
3516  }
3518  {
3519  pRange = nullptr;//aTextNodeSetRange;
3521  break;
3522  }
3524  {
3525  pRange = aTextNodeSetRange; // checked, already added support for [XATTR_FILL_FIRST, XATTR_FILL_LAST]
3527  break;
3528  }
3529  default: ;
3530  }
3531 
3532  if( !pPropSet)
3533  throw uno::RuntimeException();
3534 
3535  SwAttrSet aSet( m_pDocShell->GetDoc()->GetAttrPool(), pRange );
3536  const bool bTakeCareOfDrawingLayerFillStyle(IStyleAccess::AUTO_STYLE_PARA == m_eFamily);
3537 
3538  if(!bTakeCareOfDrawingLayerFillStyle)
3539  {
3540  for( const beans::PropertyValue& rValue : Values )
3541  {
3542  try
3543  {
3544  pPropSet->setPropertyValue( rValue.Name, rValue.Value, aSet );
3545  }
3546  catch (const beans::UnknownPropertyException &)
3547  {
3548  OSL_FAIL( "Unknown property" );
3549  }
3550  catch (const lang::IllegalArgumentException &)
3551  {
3552  OSL_FAIL( "Illegal argument" );
3553  }
3554  }
3555  }
3556  else
3557  {
3558  // set parent to ItemSet to ensure XFILL_NONE as XFillStyleItem
3559  // to make cases in RES_BACKGROUND work correct; target *is* a style
3560  // where this is the case
3561  aSet.SetParent(&m_pDocShell->GetDoc()->GetDfltTextFormatColl()->GetAttrSet());
3562 
3563  // here the used DrawingLayer FillStyles are imported when family is
3564  // equal to IStyleAccess::AUTO_STYLE_PARA, thus we will need to serve the
3565  // used slots functionality here to do this correctly
3566  const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
3567 
3568  for( const beans::PropertyValue& rValue : Values )
3569  {
3570  const OUString& rPropName = rValue.Name;
3571  uno::Any aValue(rValue.Value);
3572  const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(rPropName);
3573 
3574  if (!pEntry)
3575  {
3576  SAL_WARN("sw.core", "SwXAutoStyleFamily::insertStyle: Unknown property: " << rPropName);
3577  continue;
3578  }
3579 
3580  const sal_uInt8 nMemberId(pEntry->nMemberId);
3581  bool bDone(false);
3582 
3583  // check for needed metric translation
3584  if(pEntry->nMoreFlags & PropertyMoreFlags::METRIC_ITEM)
3585  {
3586  bool bDoIt(true);
3587 
3588  if(XATTR_FILLBMP_SIZEX == pEntry->nWID || XATTR_FILLBMP_SIZEY == pEntry->nWID)
3589  {
3590  // exception: If these ItemTypes are used, do not convert when these are negative
3591  // since this means they are intended as percent values
3592  sal_Int32 nValue = 0;
3593 
3594  if(aValue >>= nValue)
3595  {
3596  bDoIt = nValue > 0;
3597  }
3598  }
3599 
3600  if(bDoIt)
3601  {
3602  const SfxItemPool& rPool = m_pDocShell->GetDoc()->GetAttrPool();
3603  const MapUnit eMapUnit(rPool.GetMetric(pEntry->nWID));
3604 
3605  if(eMapUnit != MapUnit::Map100thMM)
3606  {
3607  SvxUnoConvertFromMM(eMapUnit, aValue);
3608  }
3609  }
3610  }
3611 
3612  switch(pEntry->nWID)
3613  {
3614  case XATTR_FILLGRADIENT:
3615  case XATTR_FILLHATCH:
3616  case XATTR_FILLBITMAP:
3618  // not yet needed; activate when LineStyle support may be added
3619  // case XATTR_LINESTART:
3620  // case XATTR_LINEEND:
3621  // case XATTR_LINEDASH:
3622  {
3623  if(MID_NAME == nMemberId)
3624  {
3625  // add set commands for FillName items
3626  OUString aTempName;
3627 
3628  if(!(aValue >>= aTempName))
3629  {
3630  throw lang::IllegalArgumentException();
3631  }
3632 
3633  SvxShape::SetFillAttribute(pEntry->nWID, aTempName, aSet);
3634  bDone = true;
3635  }
3636  else if (MID_BITMAP == nMemberId)
3637  {
3638  if(XATTR_FILLBITMAP == pEntry->nWID)
3639  {
3640  const Graphic aNullGraphic;
3641  XFillBitmapItem aXFillBitmapItem(aNullGraphic);
3642 
3643  aXFillBitmapItem.PutValue(aValue, nMemberId);
3644  aSet.Put(aXFillBitmapItem);
3645  bDone = true;
3646  }
3647  }
3648 
3649  break;
3650  }
3651  case RES_BACKGROUND:
3652  {
3653  const std::shared_ptr<SvxBrushItem> aOriginalBrushItem(getSvxBrushItemFromSourceSet(aSet, RES_BACKGROUND, true, m_pDocShell->GetDoc()->IsInXMLImport()));
3654  std::shared_ptr<SvxBrushItem> aChangedBrushItem(static_cast<SvxBrushItem*>(aOriginalBrushItem->Clone()));
3655 
3656  aChangedBrushItem->PutValue(aValue, nMemberId);
3657 
3658  if(*aChangedBrushItem != *aOriginalBrushItem)
3659  {
3660  setSvxBrushItemAsFillAttributesToTargetSet(*aChangedBrushItem, aSet);
3661  }
3662 
3663  bDone = true;
3664  break;
3665  }
3666  case OWN_ATTR_FILLBMP_MODE:
3667  {
3668  drawing::BitmapMode eMode;
3669 
3670  if(!(aValue >>= eMode))
3671  {
3672  sal_Int32 nMode = 0;
3673 
3674  if(!(aValue >>= nMode))
3675  {
3676  throw lang::IllegalArgumentException();
3677  }
3678 
3679  eMode = static_cast<drawing::BitmapMode>(nMode);
3680  }
3681 
3682  aSet.Put(XFillBmpStretchItem(drawing::BitmapMode_STRETCH == eMode));
3683  aSet.Put(XFillBmpTileItem(drawing::BitmapMode_REPEAT == eMode));
3684 
3685  bDone = true;
3686  break;
3687  }
3688  default: break;
3689  }
3690 
3691  if(!bDone)
3692  {
3693  try
3694  {
3695  pPropSet->setPropertyValue( rPropName, aValue, aSet );
3696  }
3697  catch (const beans::UnknownPropertyException &)
3698  {
3699  OSL_FAIL( "Unknown property" );
3700  }
3701  catch (const lang::IllegalArgumentException &)
3702  {
3703  OSL_FAIL( "Illegal argument" );
3704  }
3705  }
3706  }
3707 
3708  // clear parent again
3709  aSet.SetParent(nullptr);
3710  }
3711 
3712  // need to ensure uniqueness of evtl. added NameOrIndex items
3713  // currently in principle only needed when bTakeCareOfDrawingLayerFillStyle,
3714  // but does not hurt and is easily forgotten later eventually, so keep it
3715  // as common case
3717 
3718  // AutomaticStyle creation
3719  std::shared_ptr<SfxItemSet> pSet = m_pDocShell->GetDoc()->GetIStyleAccess().cacheAutomaticStyle( aSet, m_eFamily );
3720  uno::Reference<style::XAutoStyle> xRet = new SwXAutoStyle(m_pDocShell->GetDoc(), pSet, m_eFamily);
3721 
3722  return xRet;
3723 }
3724 
3725 uno::Reference< container::XEnumeration > SwXAutoStyleFamily::createEnumeration( )
3726 {
3727  if( !m_pDocShell )
3728  throw uno::RuntimeException();
3729  return uno::Reference< container::XEnumeration >
3731 }
3732 
3734 {
3736 }
3737 
3739 {
3740  return false;
3741 }
3742 
3744 : pDoc( pInitDoc ), eFamily( eFam )
3745 {
3746  // special case for ruby auto styles:
3747  if ( IStyleAccess::AUTO_STYLE_RUBY == eFam )
3748  {
3749  std::set< std::pair< sal_uInt16, text::RubyAdjust > > aRubyMap;
3750  SwAttrPool& rAttrPool = pDoc->GetAttrPool();
3751 
3752  // do this in two phases otherwise we invalidate the iterators when we insert into the pool
3753  std::vector<const SwFormatRuby*> vRubyItems;
3754  for (const SfxPoolItem* pItem : rAttrPool.GetItemSurrogates(RES_TXTATR_CJK_RUBY))
3755  {
3756  auto pRubyItem = dynamic_cast<const SwFormatRuby*>(pItem);
3757  if ( pRubyItem && pRubyItem->GetTextRuby() )
3758  vRubyItems.push_back(pRubyItem);
3759  }
3760  for (const SwFormatRuby* pRubyItem : vRubyItems)
3761  {
3762  std::pair< sal_uInt16, text::RubyAdjust > aPair( pRubyItem->GetPosition(), pRubyItem->GetAdjustment() );
3763  if ( aRubyMap.insert( aPair ).second )
3764  {
3765  std::shared_ptr<SfxItemSet> pItemSet( new SfxItemSet( rAttrPool, svl::Items<RES_TXTATR_CJK_RUBY, RES_TXTATR_CJK_RUBY>{} ) );
3766  pItemSet->Put( *pRubyItem );
3767  mAutoStyles.push_back( pItemSet );
3768  }
3769  }
3770  }
3771  else
3772  {
3774  }
3775 
3776  aIter = mAutoStyles.begin();
3777 }
3778 
3780 : m_pImpl( new SwAutoStylesEnumImpl( pDoc, eFam ) )
3781 {
3782  // Register ourselves as a listener to the document (via the page descriptor)
3784 }
3785 
3787 {
3788 }
3789 
3791 {
3792  if(rHint.GetId() == SfxHintId::Dying)
3793  m_pImpl.reset();
3794 }
3795 
3797 {
3798  if( !m_pImpl )
3799  throw uno::RuntimeException();
3800  return m_pImpl->hasMoreElements();
3801 }
3802 
3804 {
3805  if( !m_pImpl )
3806  throw uno::RuntimeException();
3807  uno::Any aRet;
3808  if( m_pImpl->hasMoreElements() )
3809  {
3810  std::shared_ptr<SfxItemSet> pNextSet = m_pImpl->nextElement();
3811  uno::Reference< style::XAutoStyle > xAutoStyle = new SwXAutoStyle(m_pImpl->getDoc(),
3812  pNextSet, m_pImpl->getFamily());
3813  aRet <<= xAutoStyle;
3814  }
3815  return aRet;
3816 }
3817 
3818 // SwXAutoStyle with the family IStyleAccess::AUTO_STYLE_PARA (or
3819 // PROPERTY_MAP_PARA_AUTO_STYLE) now uses DrawingLayer FillStyles to allow
3820 // unified paragraph background fill, thus the UNO API implementation has to
3821 // support the needed slots for these. This seems to be used only for reading
3822 // (no setPropertyValue implementation here), so maybe specialized for saving
3823 // the Writer Doc to ODF
3824 
3826  SwDoc* pDoc,
3827  std::shared_ptr<SfxItemSet> const & pInitSet,
3829 : mpSet(pInitSet),
3830  meFamily(eFam),
3831  mrDoc(*pDoc)
3832 {
3833  // Register ourselves as a listener to the document (via the page descriptor)
3834  //StartListening(mrDoc.getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier());
3835 }
3836 
3838 {
3839 }
3840 
3841 void SwXAutoStyle::Notify(const SfxHint& rHint)
3842 {
3843  if(rHint.GetId() == SfxHintId::Dying)
3844  mpSet.reset();
3845 }
3846 
3847 uno::Reference< beans::XPropertySetInfo > SwXAutoStyle::getPropertySetInfo( )
3848 {
3849  uno::Reference< beans::XPropertySetInfo > xRet;
3850  switch( meFamily )
3851  {
3853  {
3854  static uno::Reference< beans::XPropertySetInfo > xCharRef;
3855  if(!xCharRef.is())
3856  {
3858  }
3859  xRet = xCharRef;
3860  }
3861  break;
3863  {
3864  static uno::Reference< beans::XPropertySetInfo > xRubyRef;
3865  if(!xRubyRef.is())
3866  {
3867  const sal_uInt16 nMapId = PROPERTY_MAP_RUBY_AUTO_STYLE;
3868  xRubyRef = aSwMapProvider.GetPropertySet(nMapId)->getPropertySetInfo();
3869  }
3870  xRet = xRubyRef;
3871  }
3872  break;
3874  {
3875  static uno::Reference< beans::XPropertySetInfo > xParaRef;
3876  if(!xParaRef.is())
3877  {
3878  const sal_uInt16 nMapId = PROPERTY_MAP_PARA_AUTO_STYLE;
3879  xParaRef = aSwMapProvider.GetPropertySet(nMapId)->getPropertySetInfo();
3880  }
3881  xRet = xParaRef;
3882  }
3883  break;
3884 
3885  default:
3886  ;
3887  }
3888 
3889  return xRet;
3890 }
3891 
3892 void SwXAutoStyle::setPropertyValue( const OUString& /*rPropertyName*/, const uno::Any& /*rValue*/ )
3893 {
3894 }
3895 
3896 uno::Any SwXAutoStyle::getPropertyValue( const OUString& rPropertyName )
3897 {
3898  SolarMutexGuard aGuard;
3899  const uno::Sequence<OUString> aProperties(&rPropertyName, 1);
3900  return GetPropertyValues_Impl(aProperties).getConstArray()[0];
3901 }
3902 
3903 void SwXAutoStyle::addPropertyChangeListener( const OUString& /*aPropertyName*/,
3904  const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
3905 {
3906 }
3907 
3908 void SwXAutoStyle::removePropertyChangeListener( const OUString& /*aPropertyName*/,
3909  const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
3910 {
3911 }
3912 
3913 void SwXAutoStyle::addVetoableChangeListener( const OUString& /*PropertyName*/,
3914  const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
3915 {
3916 }
3917 
3918 void SwXAutoStyle::removeVetoableChangeListener( const OUString& /*PropertyName*/,
3919  const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
3920 {
3921 }
3922 
3924  const uno::Sequence< OUString >& /*aPropertyNames*/,
3925  const uno::Sequence< uno::Any >& /*aValues*/ )
3926 {
3927 }
3928 
3929 uno::Sequence< uno::Any > SwXAutoStyle::GetPropertyValues_Impl(
3930  const uno::Sequence< OUString > & rPropertyNames )
3931 {
3932  if( !mpSet.get() )
3933  {
3934  throw uno::RuntimeException();
3935  }
3936 
3937  // query_item
3939  switch(meFamily)
3940  {
3944  default: ;
3945  }
3946 
3947  const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
3948  const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
3949  const OUString* pNames = rPropertyNames.getConstArray();
3950 
3951  const sal_Int32 nLen(rPropertyNames.getLength());
3952  uno::Sequence< uno::Any > aRet( nLen );
3953  uno::Any* pValues = aRet.getArray();
3954  const bool bTakeCareOfDrawingLayerFillStyle(IStyleAccess::AUTO_STYLE_PARA == meFamily);
3955 
3956  for( sal_Int32 i = 0; i < nLen; ++i )
3957  {
3958  const OUString sPropName = pNames[i];
3959  const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(sPropName);
3960  if(!pEntry)
3961  {
3962  throw beans::UnknownPropertyException("Unknown property: " + sPropName, static_cast < cppu::OWeakObject * > ( this ) );
3963  }
3964 
3965  uno::Any aTarget;
3966  bool bDone(false);
3967 
3968  if ( RES_TXTATR_AUTOFMT == pEntry->nWID || RES_AUTO_STYLE == pEntry->nWID )
3969  {
3970  OUString sName(StylePool::nameOf( mpSet ));
3971  aTarget <<= sName;
3972  bDone = true;
3973  }
3974  else if(bTakeCareOfDrawingLayerFillStyle)
3975  {
3976  // add support for DrawingLayer FillStyle slots
3977  switch(pEntry->nWID)
3978  {
3979  case RES_BACKGROUND:
3980  {
3981  const std::shared_ptr<SvxBrushItem> aOriginalBrushItem(getSvxBrushItemFromSourceSet(*mpSet, RES_BACKGROUND));
3982 
3983  if(!aOriginalBrushItem->QueryValue(aTarget, pEntry->nMemberId))
3984  {
3985  OSL_ENSURE(false, "Error getting attribute from RES_BACKGROUND (!)");
3986  }
3987 
3988  bDone = true;
3989  break;
3990  }
3991  case OWN_ATTR_FILLBMP_MODE:
3992  {
3993  if (mpSet->Get(XATTR_FILLBMP_TILE).GetValue())
3994  {
3995  aTarget <<= drawing::BitmapMode_REPEAT;
3996  }
3997  else if (mpSet->Get(XATTR_FILLBMP_STRETCH).GetValue())
3998  {
3999  aTarget <<= drawing::BitmapMode_STRETCH;
4000  }
4001  else
4002  {
4003  aTarget <<= drawing::BitmapMode_NO_REPEAT;
4004  }
4005 
4006  bDone = true;
4007  break;
4008  }
4009  }
4010  }
4011 
4012  if(!bDone)
4013  {
4014  pPropSet->getPropertyValue( *pEntry, *mpSet, aTarget );
4015  }
4016 
4017  if(bTakeCareOfDrawingLayerFillStyle)
4018  {
4019  if(pEntry->aType == cppu::UnoType<sal_Int16>::get() && pEntry->aType != aTarget.getValueType())
4020  {
4021  // since the sfx uint16 item now exports a sal_Int32, we may have to fix this here
4022  sal_Int32 nValue = 0;
4023  if (aTarget >>= nValue)
4024  {
4025  aTarget <<= static_cast<sal_Int16>(nValue);
4026  }
4027  }
4028 
4029  // check for needed metric translation
4030  if(pEntry->nMoreFlags & PropertyMoreFlags::METRIC_ITEM)
4031  {
4032  bool bDoIt(true);
4033 
4034  if(XATTR_FILLBMP_SIZEX == pEntry->nWID || XATTR_FILLBMP_SIZEY == pEntry->nWID)
4035  {
4036  // exception: If these ItemTypes are used, do not convert when these are negative
4037  // since this means they are intended as percent values
4038  sal_Int32 nValue = 0;
4039 
4040  if(aTarget >>= nValue)
4041  {
4042  bDoIt = nValue > 0;
4043  }
4044  }
4045 
4046  if(bDoIt)
4047  {
4048  const SfxItemPool& rPool = mrDoc.GetAttrPool();
4049  const MapUnit eMapUnit(rPool.GetMetric(pEntry->nWID));
4050 
4051  if(eMapUnit != MapUnit::Map100thMM)
4052  {
4053  SvxUnoConvertToMM(eMapUnit, aTarget);
4054  }
4055  }
4056  }
4057  }
4058 
4059  // add value
4060  pValues[i] = aTarget;
4061  }
4062 
4063  return aRet;
4064 }
4065 
4066 uno::Sequence< uno::Any > SwXAutoStyle::getPropertyValues (
4067  const uno::Sequence< OUString >& rPropertyNames )
4068 {
4069  SolarMutexGuard aGuard;
4070  uno::Sequence< uno::Any > aValues;
4071 
4072  // workaround for bad designed API
4073  try
4074  {
4075  aValues = GetPropertyValues_Impl( rPropertyNames );
4076  }
4077  catch (beans::UnknownPropertyException &)
4078  {
4079  css::uno::Any exc = cppu::getCaughtException();
4080  throw lang::WrappedTargetRuntimeException("Unknown property exception caught", static_cast < cppu::OWeakObject * > ( this ), exc );
4081  }
4082  catch (lang::WrappedTargetException &)
4083  {
4084  css::uno::Any exc = cppu::getCaughtException();
4085  throw lang::WrappedTargetRuntimeException("WrappedTargetException caught", static_cast < cppu::OWeakObject * > ( this ), exc );
4086  }
4087 
4088  return aValues;
4089 }
4090 
4092  const uno::Sequence< OUString >& /*aPropertyNames*/,
4093  const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
4094 {
4095 }
4096 
4098  const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
4099 {
4100 }
4101 
4103  const uno::Sequence< OUString >& /*aPropertyNames*/,
4104  const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
4105 {
4106 }
4107 
4108 beans::PropertyState SwXAutoStyle::getPropertyState( const OUString& rPropertyName )
4109 {
4110  SolarMutexGuard aGuard;
4111 
4112  uno::Sequence< OUString > aNames { rPropertyName };
4113  uno::Sequence< beans::PropertyState > aStates = getPropertyStates(aNames);
4114  return aStates.getConstArray()[0];
4115 }
4116 
4117 void SwXAutoStyle::setPropertyToDefault( const OUString& /*PropertyName*/ )
4118 {
4119 }
4120 
4121 uno::Any SwXAutoStyle::getPropertyDefault( const OUString& rPropertyName )
4122 {
4123  const uno::Sequence < OUString > aSequence ( &rPropertyName, 1 );
4124  return getPropertyDefaults ( aSequence ).getConstArray()[0];
4125 }
4126 
4127 uno::Sequence< beans::PropertyState > SwXAutoStyle::getPropertyStates(
4128  const uno::Sequence< OUString >& rPropertyNames )
4129 {
4130  if (!mpSet.get())
4131  {
4132  throw uno::RuntimeException();
4133  }
4134 
4135  SolarMutexGuard aGuard;
4136  uno::Sequence< beans::PropertyState > aRet(rPropertyNames.getLength());
4137  beans::PropertyState* pStates = aRet.getArray();
4138  const OUString* pNames = rPropertyNames.getConstArray();
4139 
4141  switch(meFamily)
4142  {
4146  default: ;
4147  }
4148 
4149  const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
4150  const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap();
4151  const bool bTakeCareOfDrawingLayerFillStyle(IStyleAccess::AUTO_STYLE_PARA == meFamily);
4152 
4153  for(sal_Int32 i = 0; i < rPropertyNames.getLength(); i++)
4154  {
4155  const OUString sPropName = pNames[i];
4156  const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(sPropName);
4157  if(!pEntry)
4158  {
4159  throw beans::UnknownPropertyException("Unknown property: " + sPropName, static_cast < cppu::OWeakObject * > ( this ) );
4160  }
4161 
4162  bool bDone(false);
4163 
4164  if(bTakeCareOfDrawingLayerFillStyle)
4165  {
4166  // DrawingLayer PropertyStyle support
4167  switch(pEntry->nWID)
4168  {
4169  case OWN_ATTR_FILLBMP_MODE:
4170  {
4171  if(SfxItemState::SET == mpSet->GetItemState(XATTR_FILLBMP_STRETCH, false)
4172  || SfxItemState::SET == mpSet->GetItemState(XATTR_FILLBMP_TILE, false))
4173  {
4174  pStates[i] = beans::PropertyState_DIRECT_VALUE;
4175  }
4176  else
4177  {
4178  pStates[i] = beans::PropertyState_AMBIGUOUS_VALUE;
4179  }
4180 
4181  bDone = true;
4182  break;
4183  }
4184  case RES_BACKGROUND:
4185  {
4187  pEntry->nMemberId))
4188  {
4189  pStates[i] = beans::PropertyState_DIRECT_VALUE;
4190  }
4191  else
4192  {
4193  pStates[i] = beans::PropertyState_DEFAULT_VALUE;
4194  }
4195  bDone = true;
4196 
4197  break;
4198  }
4199  }
4200  }
4201 
4202  if(!bDone)
4203  {
4204  pStates[i] = pPropSet->getPropertyState(*pEntry, *mpSet );
4205  }
4206  }
4207 
4208  return aRet;
4209 }
4210 
4212 {
4213 }
4214 
4216  const uno::Sequence< OUString >& /*rPropertyNames*/ )
4217 {
4218 }
4219 
4220 uno::Sequence< uno::Any > SwXAutoStyle::getPropertyDefaults(
4221  const uno::Sequence< OUString >& /*aPropertyNames*/ )
4222 {
4223  uno::Sequence< uno::Any > aRet(0);
4224  return aRet;
4225 }
4226 
4227 uno::Sequence< beans::PropertyValue > SwXAutoStyle::getProperties()
4228 {
4229  if( !mpSet.get() )
4230  throw uno::RuntimeException();
4231  SolarMutexGuard aGuard;
4232  std::vector< beans::PropertyValue > aPropertyVector;
4233 
4234  sal_Int8 nPropSetId = 0;
4235  switch(meFamily)
4236  {
4240  default: ;
4241  }
4242 
4243  const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId);
4244  const SfxItemPropertyMap &rMap = pPropSet->getPropertyMap();
4245  PropertyEntryVector_t aPropVector = rMap.getPropertyEntries();
4246 
4247  SfxItemSet& rSet = *mpSet;
4248  SfxItemIter aIter(rSet);
4249  const SfxPoolItem* pItem = aIter.FirstItem();
4250 
4251  while ( pItem )
4252  {
4253  const sal_uInt16 nWID = pItem->Which();
4254 
4255  // TODO: Optimize - and fix! the old iteration filled each WhichId
4256  // only once but there are more properties than WhichIds
4257  for( const auto& rProp : aPropVector )
4258  {
4259  if ( rProp.nWID == nWID )
4260  {
4261  beans::PropertyValue aPropertyValue;
4262  aPropertyValue.Name = rProp.sName;
4263  pItem->QueryValue( aPropertyValue.Value, rProp.nMemberId );
4264  aPropertyVector.push_back( aPropertyValue );
4265  }
4266  }
4267  pItem = aIter.NextItem();
4268  }
4269 
4270  const sal_Int32 nCount = aPropertyVector.size();
4271  uno::Sequence< beans::PropertyValue > aRet( nCount );
4272  beans::PropertyValue* pProps = aRet.getArray();
4273 
4274  for ( int i = 0; i < nCount; ++i, pProps++ )
4275  {
4276  *pProps = aPropertyVector[i];
4277  }
4278 
4279  return aRet;
4280 }
4281 
4283  m_pDocShell(pDocShell), m_pTableAutoFormat(pTableAutoFormat), m_bPhysical(true)
4284 {
4286 }
4287 
4288 SwXTextTableStyle::SwXTextTableStyle(SwDocShell* pDocShell, const OUString& rTableAutoFormatName) :
4289  m_pDocShell(pDocShell), m_pTableAutoFormat_Impl(new SwTableAutoFormat(rTableAutoFormatName)), m_bPhysical(false)
4290 {
4293 }
4294 
4295 uno::Reference<style::XStyle> SwXTextTableStyle::CreateXTextTableStyle(SwDocShell* pDocShell, const OUString& rTableAutoFormatName)
4296 {
4297  SolarMutexGuard aGuard;
4298  uno::Reference<style::XStyle> xTextTableStyle;
4299  SwTableAutoFormat* pAutoFormat = GetTableAutoFormat(pDocShell, rTableAutoFormatName);
4300  if (pAutoFormat && pAutoFormat->GetName() == rTableAutoFormatName)
4301  {
4302  xTextTableStyle.set(pAutoFormat->GetXObject(), uno::UNO_QUERY);
4303  if (!xTextTableStyle.is())
4304  {
4305  xTextTableStyle.set(new SwXTextTableStyle(pDocShell, pAutoFormat));
4306  pAutoFormat->SetXObject(xTextTableStyle);
4307  }
4308  }
4309 
4310  // If corresponding AutoFormat doesn't exist create a non physical style.
4311  if (!xTextTableStyle.is())
4312  {
4313  xTextTableStyle.set(new SwXTextTableStyle(pDocShell, rTableAutoFormatName));
4314  SAL_INFO("sw.uno", "creating SwXTextTableStyle for non existing SwTableAutoFormat");
4315  }
4316 
4317  return xTextTableStyle;
4318 }
4319 
4321 {
4322  const std::vector<sal_Int32> aTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap();
4323  assert(aTableTemplateMap.size() == STYLE_COUNT && "can not map SwTableAutoFormat to a SwXTextTableStyle");
4324  for (sal_Int32 i=0; i<STYLE_COUNT; ++i)
4325  {
4326  SwBoxAutoFormat* pBoxFormat = &m_pTableAutoFormat->GetBoxFormat(aTableTemplateMap[i]);
4327  uno::Reference<style::XStyle> xCellStyle(pBoxFormat->GetXObject(), uno::UNO_QUERY);
4328  if (!xCellStyle.is())
4329  {
4330  xCellStyle.set(new SwXTextCellStyle(m_pDocShell, pBoxFormat, m_pTableAutoFormat->GetName()));
4331  pBoxFormat->SetXObject(xCellStyle);
4332  }
4333  m_aCellStyles[i] = xCellStyle;
4334  }
4335 }
4336 
4338 {
4339  static CellStyleNameMap const aMap
4340  {
4341  { "first-row" , FIRST_ROW_STYLE },
4342  { "last-row" , LAST_ROW_STYLE },
4343  { "first-column" , FIRST_COLUMN_STYLE },
4344  { "last-column" , LAST_COLUMN_STYLE },
4345  { "body" , BODY_STYLE },
4346  { "even-rows" , EVEN_ROWS_STYLE },
4347  { "odd-rows" , ODD_ROWS_STYLE },
4348  { "even-columns" , EVEN_COLUMNS_STYLE },
4349  { "odd-columns" , ODD_COLUMNS_STYLE },
4350  { "background" , BACKGROUND_STYLE },
4351  // loext namespace
4352  { "first-row-start-column" , FIRST_ROW_START_COLUMN_STYLE },
4353  { "first-row-end-column" , FIRST_ROW_END_COLUMN_STYLE },
4354  { "last-row-start-column" , LAST_ROW_START_COLUMN_STYLE },
4355  { "last-row-end-column" , LAST_ROW_END_COLUMN_STYLE },
4356  { "first-row-even-column" , FIRST_ROW_EVEN_COLUMN_STYLE },
4357  { "last-row-even-column" , LAST_ROW_EVEN_COLUMN_STYLE },
4358  };
4359  return aMap;
4360 }
4361 
4363 {
4364  return m_pTableAutoFormat;
4365 }
4366 
4368 {
4369  const size_t nStyles = pDocShell->GetDoc()->GetTableStyles().size();
4370  for(size_t i=0; i < nStyles; ++i)
4371  {
4372  SwTableAutoFormat* pAutoFormat = &pDocShell->GetDoc()->GetTableStyles()[i];
4373  if (pAutoFormat->GetName() == sName)
4374  {
4375  return pAutoFormat;
4376  }
4377  }
4378  // not found
4379  return nullptr;
4380 }
4381 
4383 {
4384  if (!m_bPhysical)
4385  {
4386  // find table format in doc
4388  if (pTableAutoFormat)
4389  {
4390  m_bPhysical = true;
4392  const std::vector<sal_Int32> aTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap();
4393  for (size_t i=0; i<aTableTemplateMap.size(); ++i)
4394  {
4395  SwBoxAutoFormat* pOldBoxFormat = &m_pTableAutoFormat->GetBoxFormat(aTableTemplateMap[i]);
4396  uno::Reference<style::XStyle> xCellStyle(pOldBoxFormat->GetXObject(), uno::UNO_QUERY);
4397  if (!xCellStyle.is())
4398  continue;
4399  SwXTextCellStyle& rStyle = dynamic_cast<SwXTextCellStyle&>(*xCellStyle);
4400  SwBoxAutoFormat& rNewBoxFormat = pTableAutoFormat->GetBoxFormat(aTableTemplateMap[i]);
4401  rStyle.SetBoxFormat(&rNewBoxFormat);
4402  rNewBoxFormat.SetXObject(xCellStyle);
4403  }
4404  m_pTableAutoFormat_Impl = nullptr;
4405  m_pTableAutoFormat = pTableAutoFormat;
4406  m_pTableAutoFormat->SetXObject(uno::Reference<style::XStyle>(this));
4407  }
4408  else
4409  SAL_WARN("sw.uno", "setting style physical, but SwTableAutoFormat in document not found");
4410  }
4411  else
4412  SAL_WARN("sw.uno", "calling SetPhysical on a physical SwXTextTableStyle");
4413 }
4414 
4415 // XStyle
4417 {
4418  SolarMutexGuard aGuard;
4419  // only first style is not user defined
4420  if (m_pDocShell->GetDoc()->GetTableStyles()[0].GetName() == m_pTableAutoFormat->GetName())
4421  return false;
4422 
4423  return true;
4424 }
4425 
4427 {
4428  SolarMutexGuard aGuard;
4429  if (!m_bPhysical)
4430  return false;
4431 
4433 
4434  for (SwFrameFormat* const & pFormat : *m_pDocShell->GetDoc()->GetTableFrameFormats())
4435  {
4436  if (!pFormat->GetInfo(aGetHt))
4437  {
4438  uno::Reference<text::XTextTable> xTable = SwXTextTables::GetObject(*pFormat);
4439  if (xTable.is())
4440  {
4441  uno::Reference<beans::XPropertySet> xTablePropertySet(xTable, uno::UNO_QUERY);
4442  OUString sTableTemplateName;
4443  if (xTablePropertySet.is() && (xTablePropertySet->getPropertyValue("TableTemplateName") >>= sTableTemplateName)
4444  && sTableTemplateName == m_pTableAutoFormat->GetName())
4445  {
4446  return true;
4447  }
4448  }
4449  }
4450  }
4451 
4452  return false;
4453 }
4454 
4456 {
4457  return OUString();
4458 }
4459 
4460 void SAL_CALL SwXTextTableStyle::setParentStyle(const OUString& /*aParentStyle*/)
4461 { }
4462 
4463 //XNamed
4464 OUString SAL_CALL SwXTextTableStyle::getName()
4465 {
4466  SolarMutexGuard aGuard;
4467  OUString sProgName;
4469  return sProgName;
4470 }
4471 
4472 void SAL_CALL SwXTextTableStyle::setName(const OUString& rName)
4473 {
4474  SolarMutexGuard aGuard;
4475  m_pTableAutoFormat->SetName(rName);
4476 }
4477 
4478 //XPropertySet
4479 css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL SwXTextTableStyle::getPropertySetInfo()
4480 {
4481  static uno::Reference<beans::XPropertySetInfo> xRef(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TABLE_STYLE)->getPropertySetInfo());
4482  return xRef;
4483 }
4484 
4485 void SAL_CALL SwXTextTableStyle::setPropertyValue(const OUString& /*rPropertyName*/, const css::uno::Any& /*aValue*/)
4486 {
4487  SAL_WARN("sw.uno", "not implemented");
4488 }
4489 
4490 css::uno::Any SAL_CALL SwXTextTableStyle::getPropertyValue(const OUString& rPropertyName)
4491 {
4492  SolarMutexGuard aGuard;
4493  bool bIsRow = false;
4494 
4495  if (rPropertyName == UNO_NAME_TABLE_FIRST_ROW_END_COLUMN)
4497  else if (rPropertyName == UNO_NAME_TABLE_FIRST_ROW_START_COLUMN)
4499  else if (rPropertyName == UNO_NAME_TABLE_LAST_ROW_END_COLUMN)
4501  else if (rPropertyName == UNO_NAME_TABLE_LAST_ROW_START_COLUMN)
4503  else if (rPropertyName == UNO_NAME_DISPLAY_NAME)
4504  return uno::makeAny(m_pTableAutoFormat->GetName());
4505  else
4506  throw css::beans::UnknownPropertyException();
4507 
4508  return uno::makeAny(bIsRow ? OUString("row") : OUString("column"));
4509 }
4510 
4511 void SAL_CALL SwXTextTableStyle::addPropertyChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XPropertyChangeListener >& /*xListener*/ )
4512 {
4513  SAL_WARN("sw.uno", "not implemented");
4514 }
4515 
4516 void SAL_CALL SwXTextTableStyle::removePropertyChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XPropertyChangeListener >& /*aListener*/ )
4517 {
4518  SAL_WARN("sw.uno", "not implemented");
4519 }
4520 
4521 void SAL_CALL SwXTextTableStyle::addVetoableChangeListener( const OUString& /*PropertyName*/, const css::uno::Reference< css::beans::XVetoableChangeListener >& /*aListener*/ )
4522 {
4523  SAL_WARN("sw.uno", "not implemented");
4524 }
4525 
4526 void SAL_CALL SwXTextTableStyle::removeVetoableChangeListener( const OUString& /*PropertyName*/, const css::uno::Reference< css::beans::XVetoableChangeListener >& /*aListener*/ )
4527 {
4528  SAL_WARN("sw.uno", "not implemented");
4529 }
4530 
4531 //XNameAccess
4532 uno::Any SAL_CALL SwXTextTableStyle::getByName(const OUString& rName)
4533 {
4534  SolarMutexGuard aGuard;
4535  const CellStyleNameMap& rMap = GetCellStyleNameMap();
4536  CellStyleNameMap::const_iterator iter = rMap.find(rName);
4537  if(iter == rMap.end())
4538  throw css::container::NoSuchElementException();
4539 
4540  return css::uno::Any(m_aCellStyles[(*iter).second]);
4541 }
4542 
4543 css::uno::Sequence<OUString> SAL_CALL SwXTextTableStyle::getElementNames()
4544 {
4545  SolarMutexGuard aGuard;
4547 }
4548 
4549 sal_Bool SAL_CALL SwXTextTableStyle::hasByName(const OUString& rName)
4550 {
4551  SolarMutexGuard aGuard;
4552  const CellStyleNameMap& rMap = GetCellStyleNameMap();
4553  CellStyleNameMap::const_iterator iter = rMap.find(rName);
4554  return iter != rMap.end();
4555 }
4556 
4557 //XNameContainer
4558 void SAL_CALL SwXTextTableStyle::insertByName(const OUString& /*Name*/, const uno::Any& /*Element*/)
4559 {
4560  SAL_WARN("sw.uno", "not implemented");
4561 }
4562 
4563 void SAL_CALL SwXTextTableStyle::replaceByName(const OUString& rName, const uno::Any& rElement)
4564 {
4565  SolarMutexGuard aGuard;
4566  const CellStyleNameMap& rMap = GetCellStyleNameMap();
4567  CellStyleNameMap::const_iterator iter = rMap.find(rName);
4568  if(iter == rMap.end())
4569  throw container::NoSuchElementException();
4570  const sal_Int32 nCellStyle = iter->second;
4571 
4572  uno::Reference<style::XStyle> xStyle = rElement.get<uno::Reference<style::XStyle>>();
4573  if (!xStyle.is())
4574  throw lang::IllegalArgumentException();
4575 
4576  SwXTextCellStyle* pStyleToReplaceWith = dynamic_cast<SwXTextCellStyle*>(xStyle.get());
4577  if (!pStyleToReplaceWith)
4578  throw lang::IllegalArgumentException();
4579 
4580  // replace only with physical ...
4581  if (!pStyleToReplaceWith->IsPhysical())
4582  throw lang::IllegalArgumentException();
4583 
4584  const auto& rTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap();
4585  const sal_Int32 nBoxFormat = rTableTemplateMap[nCellStyle];
4586 
4587  // move SwBoxAutoFormat to dest. SwTableAutoFormat
4588  m_pTableAutoFormat->SetBoxFormat(*pStyleToReplaceWith->GetBoxFormat(), nBoxFormat);
4589  // make SwXTextCellStyle use new, moved SwBoxAutoFormat
4590  pStyleToReplaceWith->SetBoxFormat(&m_pTableAutoFormat->GetBoxFormat(nBoxFormat));
4591  m_pTableAutoFormat->GetBoxFormat(nBoxFormat).SetXObject(xStyle);
4592  // remove unassigned SwBoxAutoFormat, which is not anymore in use anyways
4593  m_pDocShell->GetDoc()->GetCellStyles().RemoveBoxFormat(xStyle->getName());
4594  // make this SwXTextTableStyle use new SwXTextCellStyle
4595  m_aCellStyles[nCellStyle] = xStyle;
4596 }
4597 
4598 void SAL_CALL SwXTextTableStyle::removeByName(const OUString& /*Name*/)
4599 {
4600  SAL_WARN("sw.uno", "not implemented");
4601 }
4602 
4603 //XElementAccess
4605 {
4607 }
4608 
4610 {
4611  return true;
4612 }
4613 
4614 //XServiceInfo
4616 {
4617  return {"SwXTextTableStyle"};
4618 }
4619 
4620 sal_Bool SAL_CALL SwXTextTableStyle::supportsService(const OUString& rServiceName)
4621 {
4622  return cppu::supportsService(this, rServiceName);
4623 }