xref: /core/sw/source/core/unocore/unosett.cxx (revision 3e86a879508e55673b4f6d24ce84eb98b332da63)
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 <editeng/editids.hrc>
21 #include <swtypes.hxx>
22 #include <unomid.h>
23 #include <hintids.hxx>
24 #include <strings.hrc>
25 #include <poolfmt.hxx>
26 #include <fmtcol.hxx>
27 #include <unomap.hxx>
28 #include <unosett.hxx>
29 #include <unoprnms.hxx>
30 #include <ftninfo.hxx>
31 #include <doc.hxx>
32 #include <pagedesc.hxx>
33 #include <IDocumentStylePoolAccess.hxx>
34 #include <charfmt.hxx>
35 #include <lineinfo.hxx>
36 #include <docsh.hxx>
37 #include <docary.hxx>
38 #include <docstyle.hxx>
39 #include <editeng/brushitem.hxx>
40 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
41 #include <com/sun/star/text/FootnoteNumbering.hpp>
42 #include <com/sun/star/text/HoriOrientation.hpp>
43 #include <com/sun/star/style/LineNumberPosition.hpp>
44 #include <com/sun/star/awt/FontDescriptor.hpp>
45 #include <com/sun/star/awt/XBitmap.hpp>
46 #include <com/sun/star/graphic/XGraphic.hpp>
47 #include <com/sun/star/beans/PropertyAttribute.hpp>
48 #include <o3tl/any.hxx>
49 #include <o3tl/enumarray.hxx>
50 #include <tools/UnitConversion.hxx>
51 #include <vcl/font.hxx>
52 #include <editeng/flstitem.hxx>
53 #include <vcl/metric.hxx>
54 #include <vcl/graph.hxx>
55 #include <vcl/GraphicLoader.hxx>
56 #include <sfx2/docfile.hxx>
57 #include <svtools/ctrltool.hxx>
58 #include <vcl/svapp.hxx>
59 #include <editeng/unofdesc.hxx>
60 #include <fmtornt.hxx>
61 #include <SwStyleNameMapper.hxx>
62 #include <com/sun/star/text/PositionAndSpaceMode.hpp>
63 #include <com/sun/star/text/LabelFollow.hpp>
64 #include <numrule.hxx>
65 #include <comphelper/servicehelper.hxx>
66 #include <comphelper/sequence.hxx>
67 #include <cppuhelper/supportsservice.hxx>
68 #include <comphelper/propertyvalue.hxx>
69 #include <svl/itemprop.hxx>
70 #include <svl/listener.hxx>
71 #include <paratr.hxx>
72 #include <sal/log.hxx>
73 #include <names.hxx>
74 
75 using namespace ::com::sun::star;
76 using namespace ::com::sun::star::uno;
77 using namespace ::com::sun::star::lang;
78 using namespace ::com::sun::star::beans;
79 using namespace ::com::sun::star::text;
80 using namespace ::com::sun::star::style;
81 
82 
83 namespace
84 {
GetPageDescNotifier(SwDoc * pDoc)85     SvtBroadcaster& GetPageDescNotifier(SwDoc* pDoc)
86     {
87         return pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier();
88     }
89 }
90 
91 #define WID_PREFIX                      0
92 #define WID_SUFFIX                      1
93 #define WID_NUMBERING_TYPE              2
94 #define WID_START_AT                    3
95 #define WID_FOOTNOTE_COUNTING           4
96 #define WID_PARAGRAPH_STYLE             5
97 #define WID_PAGE_STYLE                  6
98 #define WID_CHARACTER_STYLE             7
99 #define WID_POSITION_END_OF_DOC         8
100 #define WID_END_NOTICE                  9
101 #define WID_BEGIN_NOTICE                10
102 #define WID_ANCHOR_CHARACTER_STYLE      11
103 #define WID_NUM_ON                      12
104 #define WID_SEPARATOR_INTERVAL          13
105 #define WID_NUMBER_POSITION             14
106 #define WID_DISTANCE                    15
107 #define WID_INTERVAL                    16
108 #define WID_SEPARATOR_TEXT              17
109 #define WID_COUNT_EMPTY_LINES           18
110 #define WID_COUNT_LINES_IN_FRAMES       19
111 #define WID_RESTART_AT_EACH_PAGE        20
112 
113 
GetFootnoteSet()114 static const SfxItemPropertySet* GetFootnoteSet()
115 {
116     static const SfxItemPropertyMapEntry aFootnoteMap_Impl[] =
117     {
118         { UNO_NAME_ANCHOR_CHAR_STYLE_NAME,WID_ANCHOR_CHARACTER_STYLE, ::cppu::UnoType<OUString>::get(), PROPERTY_NONE,     0},
119         { UNO_NAME_BEGIN_NOTICE,          WID_BEGIN_NOTICE,       ::cppu::UnoType<OUString>::get(), PROPERTY_NONE,     0},
120         { UNO_NAME_CHAR_STYLE_NAME,       WID_CHARACTER_STYLE,    ::cppu::UnoType<OUString>::get(), PROPERTY_NONE,     0},
121         { UNO_NAME_END_NOTICE,            WID_END_NOTICE ,        ::cppu::UnoType<OUString>::get(), PROPERTY_NONE,     0},
122         { UNO_NAME_FOOTNOTE_COUNTING,     WID_FOOTNOTE_COUNTING,  ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE,     0},
123         { UNO_NAME_NUMBERING_TYPE,        WID_NUMBERING_TYPE,     ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE,         0},
124         { UNO_NAME_PAGE_STYLE_NAME,       WID_PAGE_STYLE,         ::cppu::UnoType<OUString>::get(), PROPERTY_NONE,     0},
125         { UNO_NAME_PARA_STYLE_NAME,       WID_PARAGRAPH_STYLE,    ::cppu::UnoType<OUString>::get(), PROPERTY_NONE,     0},
126         { UNO_NAME_POSITION_END_OF_DOC,   WID_POSITION_END_OF_DOC,cppu::UnoType<bool>::get(), PROPERTY_NONE,         0},
127         { UNO_NAME_PREFIX,                WID_PREFIX,             ::cppu::UnoType<OUString>::get(), PROPERTY_NONE,     0},
128         { UNO_NAME_START_AT,              WID_START_AT ,          ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE,         0},
129         { UNO_NAME_SUFFIX,                WID_SUFFIX,             ::cppu::UnoType<OUString>::get(), PROPERTY_NONE,     0},
130     };
131     static const SfxItemPropertySet aFootnoteSet_Impl(aFootnoteMap_Impl);
132     return &aFootnoteSet_Impl;
133 }
134 
GetEndnoteSet()135 static const SfxItemPropertySet* GetEndnoteSet()
136 {
137     static const SfxItemPropertyMapEntry aEndnoteMap_Impl[] =
138     {
139         { UNO_NAME_ANCHOR_CHAR_STYLE_NAME,WID_ANCHOR_CHARACTER_STYLE, ::cppu::UnoType<OUString>::get(), PROPERTY_NONE,     0},
140         { UNO_NAME_CHAR_STYLE_NAME,       WID_CHARACTER_STYLE,    ::cppu::UnoType<OUString>::get(), PROPERTY_NONE,     0},
141         { UNO_NAME_NUMBERING_TYPE,        WID_NUMBERING_TYPE,     ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE,         0},
142         { UNO_NAME_PAGE_STYLE_NAME,       WID_PAGE_STYLE,         ::cppu::UnoType<OUString>::get(), PROPERTY_NONE,     0},
143         { UNO_NAME_PARA_STYLE_NAME,       WID_PARAGRAPH_STYLE,    ::cppu::UnoType<OUString>::get(), PROPERTY_NONE,     0},
144         { UNO_NAME_PREFIX,                WID_PREFIX,     ::cppu::UnoType<OUString>::get(), PROPERTY_NONE,     0},
145         { UNO_NAME_START_AT,              WID_START_AT ,          ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE,         0},
146         { UNO_NAME_SUFFIX,                WID_SUFFIX,     ::cppu::UnoType<OUString>::get(), PROPERTY_NONE,     0},
147     };
148     static const SfxItemPropertySet aEndnoteSet_Impl(aEndnoteMap_Impl);
149     return &aEndnoteSet_Impl;
150 }
151 
GetNumberingRulesSet()152 static const SfxItemPropertySet* GetNumberingRulesSet()
153 {
154     static const SfxItemPropertyMapEntry aNumberingRulesMap_Impl[] =
155     {
156         { UNO_NAME_IS_ABSOLUTE_MARGINS,       WID_IS_ABS_MARGINS, cppu::UnoType<bool>::get(),            PROPERTY_NONE,     0},
157         { UNO_NAME_IS_AUTOMATIC,              WID_IS_AUTOMATIC,   cppu::UnoType<bool>::get(),            PROPERTY_NONE,     0},
158         { UNO_NAME_IS_CONTINUOUS_NUMBERING,   WID_CONTINUOUS,     cppu::UnoType<bool>::get(),            PROPERTY_NONE,     0},
159         { UNO_NAME_NAME,                      WID_RULE_NAME   ,   ::cppu::UnoType<OUString>::get(), PropertyAttribute::READONLY,     0},
160         { UNO_NAME_NUMBERING_IS_OUTLINE,      WID_IS_OUTLINE, cppu::UnoType<bool>::get(),            PROPERTY_NONE,     0},
161         { UNO_NAME_DEFAULT_LIST_ID,           WID_DEFAULT_LIST_ID, ::cppu::UnoType<OUString>::get(), PropertyAttribute::READONLY, 0},
162     };
163     static const SfxItemPropertySet  aNumberingRulesSet_Impl( aNumberingRulesMap_Impl );
164     return &aNumberingRulesSet_Impl;
165 }
166 
GetLineNumberingSet()167 static const SfxItemPropertySet* GetLineNumberingSet()
168 {
169     static const SfxItemPropertyMapEntry aLineNumberingMap_Impl[] =
170     {
171         { UNO_NAME_CHAR_STYLE_NAME,         WID_CHARACTER_STYLE,    ::cppu::UnoType<OUString>::get(), PROPERTY_NONE,     0},
172         { UNO_NAME_COUNT_EMPTY_LINES,       WID_COUNT_EMPTY_LINES , cppu::UnoType<bool>::get(),PROPERTY_NONE,     0},
173         { UNO_NAME_COUNT_LINES_IN_FRAMES,   WID_COUNT_LINES_IN_FRAMES, cppu::UnoType<bool>::get(),PROPERTY_NONE,     0},
174         { UNO_NAME_DISTANCE,                WID_DISTANCE       ,    ::cppu::UnoType<sal_Int32>::get(),PROPERTY_NONE,     0},
175         { UNO_NAME_IS_ON,                   WID_NUM_ON,             cppu::UnoType<bool>::get()  ,          PROPERTY_NONE,     0},
176         { UNO_NAME_INTERVAL,                WID_INTERVAL  ,       ::cppu::UnoType<sal_Int16>::get(),PROPERTY_NONE,     0},
177         { UNO_NAME_SEPARATOR_TEXT,          WID_SEPARATOR_TEXT,   ::cppu::UnoType<OUString>::get(), PROPERTY_NONE,     0},
178         { UNO_NAME_NUMBER_POSITION,         WID_NUMBER_POSITION,    ::cppu::UnoType<sal_Int16>::get(),PROPERTY_NONE,     0},
179         { UNO_NAME_NUMBERING_TYPE,          WID_NUMBERING_TYPE ,    ::cppu::UnoType<sal_Int16>::get(),PROPERTY_NONE,     0},
180         { UNO_NAME_RESTART_AT_EACH_PAGE,    WID_RESTART_AT_EACH_PAGE, cppu::UnoType<bool>::get()  ,          PROPERTY_NONE,     0},
181         { UNO_NAME_SEPARATOR_INTERVAL,      WID_SEPARATOR_INTERVAL, ::cppu::UnoType<sal_Int16>::get(),PROPERTY_NONE,     0},
182     };
183     static const SfxItemPropertySet aLineNumberingSet_Impl(aLineNumberingMap_Impl);
184     return &aLineNumberingSet_Impl;
185 }
186 
lcl_getCharFormat(SwDoc * pDoc,const uno::Any & aValue)187 static SwCharFormat* lcl_getCharFormat(SwDoc* pDoc, const uno::Any& aValue)
188 {
189     SwCharFormat* pRet = nullptr;
190     OUString uTmp;
191     aValue >>= uTmp;
192     UIName sCharFormat;
193     SwStyleNameMapper::FillUIName(ProgName(uTmp), sCharFormat, SwGetPoolIdFromName::ChrFmt);
194     if (sCharFormat != SwResId(STR_POOLCHR_STANDARD))
195     {
196         pRet = pDoc->FindCharFormatByName( sCharFormat );
197     }
198     if(!pRet)
199     {
200         const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(sCharFormat, SwGetPoolIdFromName::ChrFmt);
201         if(USHRT_MAX != nId)
202             pRet = pDoc->getIDocumentStylePoolAccess().GetCharFormatFromPool( nId );
203     }
204     return pRet;
205 }
206 
lcl_GetParaStyle(SwDoc * pDoc,const uno::Any & aValue)207 static SwTextFormatColl* lcl_GetParaStyle(SwDoc* pDoc, const uno::Any& aValue)
208 {
209     OUString uTmp;
210     aValue >>= uTmp;
211     UIName sParaStyle;
212     SwStyleNameMapper::FillUIName(ProgName(uTmp), sParaStyle, SwGetPoolIdFromName::TxtColl );
213     SwTextFormatColl* pRet = pDoc->FindTextFormatCollByName( sParaStyle );
214     if( !pRet  )
215     {
216         const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( sParaStyle, SwGetPoolIdFromName::TxtColl );
217         if( USHRT_MAX != nId  )
218             pRet = pDoc->getIDocumentStylePoolAccess().GetTextCollFromPool( nId );
219     }
220     return pRet;
221 }
222 
lcl_GetPageDesc(SwDoc * pDoc,const uno::Any & aValue)223 static SwPageDesc* lcl_GetPageDesc(SwDoc* pDoc, const uno::Any& aValue)
224 {
225     OUString uTmp;
226     aValue >>= uTmp;
227     UIName sPageDesc;
228     SwStyleNameMapper::FillUIName(ProgName(uTmp), sPageDesc, SwGetPoolIdFromName::PageDesc );
229     SwPageDesc* pRet = pDoc->FindPageDesc( sPageDesc );
230     if(!pRet)
231     {
232         const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(sPageDesc, SwGetPoolIdFromName::PageDesc);
233         if(USHRT_MAX != nId)
234             pRet = pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool( nId );
235     }
236     return pRet;
237 }
238 
239 // Numbering
240 const o3tl::enumarray<SvxAdjust, sal_Int16> aSvxToUnoAdjust
241 {
242     text::HoriOrientation::LEFT,   //3
243     text::HoriOrientation::RIGHT,  //1
244     sal_Int16(-1),
245     text::HoriOrientation::CENTER, //2
246     sal_Int16(-1),
247     sal_Int16(-1)
248 };
249 
getImplementationName()250 OUString SwXFootnoteProperties::getImplementationName()
251 {
252     return u"SwXFootnoteProperties"_ustr;
253 }
254 
supportsService(const OUString & rServiceName)255 sal_Bool SwXFootnoteProperties::supportsService(const OUString& rServiceName)
256 {
257     return cppu::supportsService(this, rServiceName);
258 }
259 
getSupportedServiceNames()260 Sequence< OUString > SwXFootnoteProperties::getSupportedServiceNames()
261 {
262     Sequence<OUString> aRet { u"com.sun.star.text.FootnoteSettings"_ustr };
263     return aRet;
264 }
265 
SwXFootnoteProperties(SwDoc * pDc)266 SwXFootnoteProperties::SwXFootnoteProperties(SwDoc* pDc) :
267     m_pDoc(pDc),
268     m_pPropertySet(GetFootnoteSet())
269 {
270 }
271 
~SwXFootnoteProperties()272 SwXFootnoteProperties::~SwXFootnoteProperties()
273 {
274 
275 }
276 
getPropertySetInfo()277 uno::Reference< beans::XPropertySetInfo >  SwXFootnoteProperties::getPropertySetInfo()
278 {
279     static uno::Reference< beans::XPropertySetInfo >  aRef = m_pPropertySet->getPropertySetInfo();
280     return aRef;
281 }
282 
setPropertyValue(const OUString & rPropertyName,const uno::Any & aValue)283 void SwXFootnoteProperties::setPropertyValue(const OUString& rPropertyName, const uno::Any& aValue)
284 {
285     SolarMutexGuard aGuard;
286     if(!m_pDoc)
287         throw uno::RuntimeException(u"Footnote's document is not set."_ustr);
288 
289     const SfxItemPropertyMapEntry*  pEntry = m_pPropertySet->getPropertyMap().getByName( rPropertyName );
290     if(!pEntry)
291         throw beans::UnknownPropertyException("Unknown property: " + rPropertyName, getXWeak() );
292 
293     if ( pEntry->nFlags & PropertyAttribute::READONLY)
294         throw PropertyVetoException("Property is read-only: " + rPropertyName, getXWeak() );
295     SwFootnoteInfo aFootnoteInfo(m_pDoc->GetFootnoteInfo());
296     switch(pEntry->nWID)
297     {
298         case WID_PREFIX:
299         {
300             OUString uTmp;
301             aValue >>= uTmp;
302             aFootnoteInfo.SetPrefix(uTmp);
303         }
304         break;
305         case WID_SUFFIX:
306         {
307             OUString uTmp;
308             aValue >>= uTmp;
309             aFootnoteInfo.SetSuffix(uTmp);
310         }
311         break;
312         case WID_NUMBERING_TYPE:
313         {
314             sal_Int16 nTmp = 0;
315             aValue >>= nTmp;
316             if(!(nTmp >= 0 &&
317                 (nTmp <= SVX_NUM_ARABIC ||
318                     nTmp > SVX_NUM_BITMAP)))
319                 throw lang::IllegalArgumentException();
320 
321             aFootnoteInfo.m_aFormat.SetNumberingType(static_cast<SvxNumType>(nTmp));
322 
323         }
324         break;
325         case WID_START_AT:
326         {
327             sal_Int16 nTmp = 0;
328             aValue >>= nTmp;
329             aFootnoteInfo.m_nFootnoteOffset = nTmp;
330         }
331         break;
332         case WID_FOOTNOTE_COUNTING:
333         {
334             sal_Int16 nTmp = 0;
335             aValue >>= nTmp;
336             switch(nTmp)
337             {
338                 case  FootnoteNumbering::PER_PAGE:
339                     aFootnoteInfo.m_eNum = FTNNUM_PAGE;
340                 break;
341                 case  FootnoteNumbering::PER_CHAPTER:
342                     aFootnoteInfo.m_eNum = FTNNUM_CHAPTER;
343                 break;
344                 case  FootnoteNumbering::PER_DOCUMENT:
345                     aFootnoteInfo.m_eNum = FTNNUM_DOC;
346                 break;
347             }
348         }
349         break;
350         case WID_PARAGRAPH_STYLE:
351         {
352             SwTextFormatColl* pColl = lcl_GetParaStyle(m_pDoc, aValue);
353             if(pColl)
354                 aFootnoteInfo.SetFootnoteTextColl(*pColl);
355         }
356         break;
357         case WID_PAGE_STYLE:
358         {
359             SwPageDesc* pDesc = lcl_GetPageDesc(m_pDoc, aValue);
360             if(pDesc)
361                 aFootnoteInfo.ChgPageDesc( pDesc );
362         }
363         break;
364         case WID_ANCHOR_CHARACTER_STYLE:
365         case WID_CHARACTER_STYLE:
366         {
367             SwCharFormat* pFormat = lcl_getCharFormat(m_pDoc, aValue);
368             if(pFormat)
369             {
370                 if(pEntry->nWID == WID_ANCHOR_CHARACTER_STYLE)
371                     aFootnoteInfo.SetAnchorCharFormat(pFormat);
372                 else
373                     aFootnoteInfo.SetCharFormat(pFormat);
374             }
375         }
376         break;
377         case WID_POSITION_END_OF_DOC:
378         {
379             bool bVal = *o3tl::doAccess<bool>(aValue);
380             aFootnoteInfo.m_ePos = bVal ? FTNPOS_CHAPTER : FTNPOS_PAGE;
381         }
382         break;
383         case WID_END_NOTICE:
384         {
385             OUString uTmp;
386             aValue >>= uTmp;
387             aFootnoteInfo.m_aQuoVadis = uTmp;
388         }
389         break;
390         case WID_BEGIN_NOTICE:
391         {
392             OUString uTmp;
393             aValue >>= uTmp;
394             aFootnoteInfo.m_aErgoSum = uTmp;
395         }
396         break;
397     }
398     m_pDoc->SetFootnoteInfo(aFootnoteInfo);
399 
400 
401 }
402 
getPropertyValue(const OUString & rPropertyName)403 uno::Any SwXFootnoteProperties::getPropertyValue(const OUString& rPropertyName)
404 {
405     SolarMutexGuard aGuard;
406     uno::Any aRet;
407     if(!m_pDoc)
408         throw uno::RuntimeException(u"Footnote's document is not set."_ustr);
409 
410     const SfxItemPropertyMapEntry*  pEntry = m_pPropertySet->getPropertyMap().getByName( rPropertyName );
411     if(!pEntry)
412         throw UnknownPropertyException("Unknown property: " + rPropertyName, getXWeak() );
413 
414     const SwFootnoteInfo& rFootnoteInfo = m_pDoc->GetFootnoteInfo();
415     switch(pEntry->nWID)
416     {
417         case WID_PREFIX:
418         {
419             aRet <<= rFootnoteInfo.GetPrefix();
420         }
421         break;
422         case WID_SUFFIX:
423         {
424             aRet <<= rFootnoteInfo.GetSuffix();
425         }
426         break;
427         case  WID_NUMBERING_TYPE :
428         {
429             aRet <<= static_cast<sal_Int16>(rFootnoteInfo.m_aFormat.GetNumberingType());
430         }
431         break;
432         case  WID_START_AT:
433             aRet <<= static_cast<sal_Int16>(rFootnoteInfo.m_nFootnoteOffset);
434         break;
435         case  WID_FOOTNOTE_COUNTING  :
436         {
437             sal_Int16 nRet = 0;
438             switch(rFootnoteInfo.m_eNum)
439             {
440                 case  FTNNUM_PAGE:
441                     nRet = FootnoteNumbering::PER_PAGE;
442                 break;
443                 case  FTNNUM_CHAPTER:
444                     nRet = FootnoteNumbering::PER_CHAPTER;
445                 break;
446                 case  FTNNUM_DOC:
447                     nRet = FootnoteNumbering::PER_DOCUMENT;
448                 break;
449             }
450             aRet <<= nRet;
451         }
452         break;
453         case  WID_PARAGRAPH_STYLE    :
454         {
455             SwTextFormatColl* pColl = rFootnoteInfo.GetFootnoteTextColl();
456             UIName aString;
457             if(pColl)
458                 aString = pColl->GetName();
459             ProgName aRetName;
460             SwStyleNameMapper::FillProgName(aString, aRetName, SwGetPoolIdFromName::TxtColl);
461             aRet <<= aRetName.toString();
462         }
463         break;
464         case  WID_PAGE_STYLE :
465         {
466             ProgName aString;
467             if( rFootnoteInfo.KnowsPageDesc() )
468             {
469                 SwStyleNameMapper::FillProgName(
470                         rFootnoteInfo.GetPageDesc( *m_pDoc )->GetName(),
471                         aString,
472                         SwGetPoolIdFromName::PageDesc);
473             }
474             aRet <<= aString.toString();
475         }
476         break;
477         case WID_ANCHOR_CHARACTER_STYLE:
478         case WID_CHARACTER_STYLE:
479         {
480             ProgName aString;
481             const SwCharFormat* pCharFormat = rFootnoteInfo.GetCurrentCharFormat(pEntry->nWID == WID_ANCHOR_CHARACTER_STYLE);
482             if( pCharFormat )
483             {
484                 SwStyleNameMapper::FillProgName(
485                         pCharFormat->GetName(),
486                         aString,
487                         SwGetPoolIdFromName::ChrFmt);
488             }
489             aRet <<= aString.toString();
490         }
491         break;
492         case  WID_POSITION_END_OF_DOC:
493             aRet <<= FTNPOS_CHAPTER == rFootnoteInfo.m_ePos;
494         break;
495         case  WID_END_NOTICE         :
496             aRet <<= rFootnoteInfo.m_aQuoVadis;
497         break;
498         case  WID_BEGIN_NOTICE       :
499             aRet <<= rFootnoteInfo.m_aErgoSum;
500         break;
501     }
502 
503 
504     return aRet;
505 }
506 
addPropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)507 void SwXFootnoteProperties::addPropertyChangeListener(
508     const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/)
509 {
510     OSL_FAIL("not implemented");
511 }
512 
removePropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)513 void SwXFootnoteProperties::removePropertyChangeListener(
514     const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/)
515 {
516     OSL_FAIL("not implemented");
517 }
518 
addVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)519 void SwXFootnoteProperties::addVetoableChangeListener(
520     const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/)
521 {
522     OSL_FAIL("not implemented");
523 }
524 
removeVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)525 void SwXFootnoteProperties::removeVetoableChangeListener(
526     const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/)
527 {
528     OSL_FAIL("not implemented");
529 }
530 
getImplementationName()531 OUString SwXEndnoteProperties::getImplementationName()
532 {
533     return u"SwXEndnoteProperties"_ustr;
534 }
535 
supportsService(const OUString & rServiceName)536 sal_Bool SwXEndnoteProperties::supportsService(const OUString& rServiceName)
537 {
538     return cppu::supportsService(this, rServiceName);
539 }
540 
getSupportedServiceNames()541 Sequence< OUString > SwXEndnoteProperties::getSupportedServiceNames()
542 {
543     Sequence<OUString> aRet { u"com.sun.star.text.FootnoteSettings"_ustr };
544     return aRet;
545 }
546 
SwXEndnoteProperties(SwDoc * pDc)547 SwXEndnoteProperties::SwXEndnoteProperties(SwDoc* pDc) :
548     m_pDoc(pDc),
549     m_pPropertySet(GetEndnoteSet())
550 {
551 }
552 
~SwXEndnoteProperties()553 SwXEndnoteProperties::~SwXEndnoteProperties()
554 {
555 }
556 
getPropertySetInfo()557 uno::Reference< beans::XPropertySetInfo >  SwXEndnoteProperties::getPropertySetInfo()
558 {
559     static uno::Reference< beans::XPropertySetInfo >  aRef = m_pPropertySet->getPropertySetInfo();
560     return aRef;
561 }
562 
setPropertyValue(const OUString & rPropertyName,const uno::Any & aValue)563 void SwXEndnoteProperties::setPropertyValue(const OUString& rPropertyName, const uno::Any& aValue)
564 {
565     SolarMutexGuard aGuard;
566     if(!m_pDoc)
567         return;
568 
569     const SfxItemPropertyMapEntry*  pEntry = m_pPropertySet->getPropertyMap().getByName( rPropertyName );
570     if(!pEntry)
571         throw UnknownPropertyException("Unknown property: " + rPropertyName, getXWeak() );
572 
573     if ( pEntry->nFlags & PropertyAttribute::READONLY)
574         throw PropertyVetoException("Property is read-only: " + rPropertyName, getXWeak() );
575     SwEndNoteInfo aEndInfo(m_pDoc->GetEndNoteInfo());
576     switch(pEntry->nWID)
577     {
578         case WID_PREFIX:
579         {
580             OUString uTmp;
581             aValue >>= uTmp;
582             aEndInfo.SetPrefix(uTmp);
583         }
584         break;
585         case WID_SUFFIX:
586         {
587             OUString uTmp;
588             aValue >>= uTmp;
589             aEndInfo.SetSuffix(uTmp);
590         }
591         break;
592         case  WID_NUMBERING_TYPE :
593         {
594             sal_Int16 nTmp = 0;
595             aValue >>= nTmp;
596             aEndInfo.m_aFormat.SetNumberingType(static_cast<SvxNumType>(nTmp));
597         }
598         break;
599         case  WID_START_AT:
600         {
601             sal_Int16 nTmp = 0;
602             aValue >>= nTmp;
603             aEndInfo.m_nFootnoteOffset = nTmp;
604         }
605         break;
606         case  WID_PARAGRAPH_STYLE    :
607         {
608             SwTextFormatColl* pColl = lcl_GetParaStyle(m_pDoc, aValue);
609             if(pColl)
610                 aEndInfo.SetFootnoteTextColl(*pColl);
611         }
612         break;
613         case  WID_PAGE_STYLE :
614         {
615             SwPageDesc* pDesc = lcl_GetPageDesc(m_pDoc, aValue);
616             if(pDesc)
617                 aEndInfo.ChgPageDesc( pDesc );
618         }
619         break;
620         case WID_ANCHOR_CHARACTER_STYLE:
621         case  WID_CHARACTER_STYLE    :
622         {
623             SwCharFormat* pFormat = lcl_getCharFormat(m_pDoc, aValue);
624             if(pFormat)
625             {
626                 if(pEntry->nWID == WID_ANCHOR_CHARACTER_STYLE)
627                     aEndInfo.SetAnchorCharFormat(pFormat);
628                 else
629                     aEndInfo.SetCharFormat(pFormat);
630             }
631         }
632         break;
633     }
634     m_pDoc->SetEndNoteInfo(aEndInfo);
635 }
636 
getPropertyValue(const OUString & rPropertyName)637 uno::Any SwXEndnoteProperties::getPropertyValue(const OUString& rPropertyName)
638 {
639     SolarMutexGuard aGuard;
640     uno::Any aRet;
641     if(m_pDoc)
642     {
643         const SfxItemPropertyMapEntry*  pEntry = m_pPropertySet->getPropertyMap().getByName( rPropertyName );
644         if(!pEntry)
645             throw UnknownPropertyException("Unknown property: " + rPropertyName, getXWeak() );
646 
647         const SwEndNoteInfo& rEndInfo = m_pDoc->GetEndNoteInfo();
648         switch(pEntry->nWID)
649         {
650             case WID_PREFIX:
651                 aRet <<= rEndInfo.GetPrefix();
652             break;
653             case WID_SUFFIX:
654                 aRet <<= rEndInfo.GetSuffix();
655             break;
656             case  WID_NUMBERING_TYPE :
657                 aRet <<= static_cast<sal_Int16>(rEndInfo.m_aFormat.GetNumberingType());
658             break;
659             case  WID_START_AT:
660                 aRet <<= static_cast<sal_Int16>(rEndInfo.m_nFootnoteOffset);
661             break;
662             case  WID_PARAGRAPH_STYLE    :
663             {
664                 SwTextFormatColl* pColl = rEndInfo.GetFootnoteTextColl();
665                 UIName aName;
666                 if(pColl)
667                     aName = pColl->GetName();
668                 ProgName aString;
669                 SwStyleNameMapper::FillProgName(
670                         aName,
671                         aString,
672                         SwGetPoolIdFromName::TxtColl);
673                 aRet <<= aString.toString();
674 
675             }
676             break;
677             case  WID_PAGE_STYLE :
678             {
679                 ProgName aString;
680                 if( rEndInfo.KnowsPageDesc() )
681                 {
682                     SwStyleNameMapper::FillProgName(
683                         rEndInfo.GetPageDesc( *m_pDoc )->GetName(),
684                         aString,
685                         SwGetPoolIdFromName::PageDesc);
686                 }
687                 aRet <<= aString.toString();
688             }
689             break;
690             case WID_ANCHOR_CHARACTER_STYLE:
691             case WID_CHARACTER_STYLE:
692             {
693                 ProgName aString;
694                 const SwCharFormat* pCharFormat = rEndInfo.GetCurrentCharFormat( pEntry->nWID == WID_ANCHOR_CHARACTER_STYLE );
695                 if( pCharFormat )
696                 {
697                     SwStyleNameMapper::FillProgName(
698                             pCharFormat->GetName(),
699                             aString,
700                             SwGetPoolIdFromName::ChrFmt);
701                 }
702                 aRet <<= aString.toString();
703             }
704             break;
705         }
706 
707     }
708     return aRet;
709 }
710 
addPropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)711 void SwXEndnoteProperties::addPropertyChangeListener(
712     const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/)
713 {
714     OSL_FAIL("not implemented");
715 }
716 
removePropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)717 void SwXEndnoteProperties::removePropertyChangeListener(const OUString& /*PropertyName*/,
718         const uno:: Reference< beans::XPropertyChangeListener > & /*xListener*/)
719 {
720     OSL_FAIL("not implemented");
721 }
722 
addVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)723 void SwXEndnoteProperties::addVetoableChangeListener(const OUString& /*PropertyName*/,
724     const uno:: Reference< beans::XVetoableChangeListener > & /*xListener*/)
725 {
726     OSL_FAIL("not implemented");
727 }
728 
removeVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)729 void SwXEndnoteProperties::removeVetoableChangeListener(const OUString& /*PropertyName*/, const uno:: Reference< beans::XVetoableChangeListener > & /*xListener*/)
730 {
731     OSL_FAIL("not implemented");
732 }
733 
getImplementationName()734 OUString SwXLineNumberingProperties::getImplementationName()
735 {
736     return u"SwXLineNumberingProperties"_ustr;
737 }
738 
supportsService(const OUString & rServiceName)739 sal_Bool SwXLineNumberingProperties::supportsService(const OUString& rServiceName)
740 {
741     return cppu::supportsService(this, rServiceName);
742 }
743 
getSupportedServiceNames()744 Sequence< OUString > SwXLineNumberingProperties::getSupportedServiceNames()
745 {
746     Sequence<OUString> aRet { u"com.sun.star.text.LineNumberingProperties"_ustr };
747     return aRet;
748 }
749 
SwXLineNumberingProperties(SwDoc * pDc)750 SwXLineNumberingProperties::SwXLineNumberingProperties(SwDoc* pDc) :
751     m_pDoc(pDc),
752     m_pPropertySet(GetLineNumberingSet())
753 {
754 }
755 
~SwXLineNumberingProperties()756 SwXLineNumberingProperties::~SwXLineNumberingProperties()
757 {
758 }
759 
getPropertySetInfo()760 uno::Reference< beans::XPropertySetInfo >  SwXLineNumberingProperties::getPropertySetInfo()
761 {
762     static uno::Reference< beans::XPropertySetInfo >  aRef = m_pPropertySet->getPropertySetInfo();
763     return aRef;
764 }
765 
setPropertyValue(const OUString & rPropertyName,const Any & aValue)766 void SwXLineNumberingProperties::setPropertyValue(
767     const OUString& rPropertyName, const Any& aValue)
768 {
769     SolarMutexGuard aGuard;
770     if(!m_pDoc)
771         throw uno::RuntimeException(u"Numbering's document is not set."_ustr);
772 
773     const SfxItemPropertyMapEntry*  pEntry = m_pPropertySet->getPropertyMap().getByName( rPropertyName );
774     if(!pEntry)
775         throw UnknownPropertyException("Unknown property: " + rPropertyName, getXWeak() );
776 
777     if ( pEntry->nFlags & PropertyAttribute::READONLY)
778         throw PropertyVetoException("Property is read-only: " + rPropertyName, getXWeak() );
779     SwLineNumberInfo  aFontMetric(m_pDoc->GetLineNumberInfo());
780     switch(pEntry->nWID)
781     {
782         case WID_NUM_ON:
783         {
784             bool bVal = *o3tl::doAccess<bool>(aValue);
785             aFontMetric.SetPaintLineNumbers(bVal);
786         }
787         break;
788         case WID_CHARACTER_STYLE :
789         {
790             SwCharFormat* pFormat = lcl_getCharFormat(m_pDoc, aValue);
791             if(pFormat)
792                 aFontMetric.SetCharFormat(pFormat);
793         }
794         break;
795         case WID_NUMBERING_TYPE  :
796         {
797             SvxNumberType aNumType(aFontMetric.GetNumType());
798             sal_Int16 nTmp = 0;
799             aValue >>= nTmp;
800             aNumType.SetNumberingType(static_cast<SvxNumType>(nTmp));
801             aFontMetric.SetNumType(aNumType);
802         }
803         break;
804         case WID_NUMBER_POSITION :
805         {
806             sal_Int16 nTmp = 0;
807             aValue >>= nTmp;
808             switch(nTmp)
809             {
810                 case  style::LineNumberPosition::LEFT:
811                      aFontMetric.SetPos(LINENUMBER_POS_LEFT);
812                 break;
813                 case style::LineNumberPosition::RIGHT :
814                      aFontMetric.SetPos(LINENUMBER_POS_RIGHT);
815                 break;
816                 case  style::LineNumberPosition::INSIDE:
817                     aFontMetric.SetPos(LINENUMBER_POS_INSIDE);
818                 break;
819                 case  style::LineNumberPosition::OUTSIDE:
820                     aFontMetric.SetPos(LINENUMBER_POS_OUTSIDE);
821                 break;
822             }
823         }
824         break;
825         case WID_DISTANCE        :
826         {
827             sal_Int32 nVal = 0;
828             aValue >>= nVal;
829             sal_Int32 nTmp = o3tl::toTwips(nVal, o3tl::Length::mm100);
830             if (nTmp > SAL_MAX_UINT16)
831                 nTmp = SAL_MAX_UINT16;
832             aFontMetric.SetPosFromLeft(nTmp);
833         }
834         break;
835         case WID_INTERVAL   :
836         {
837             sal_Int16 nTmp = 0;
838             aValue >>= nTmp;
839             if( nTmp > 0)
840                 aFontMetric.SetCountBy(nTmp);
841         }
842         break;
843         case WID_SEPARATOR_TEXT  :
844         {
845             OUString uTmp;
846             aValue >>= uTmp;
847             aFontMetric.SetDivider(uTmp);
848         }
849         break;
850         case WID_SEPARATOR_INTERVAL:
851         {
852             sal_Int16 nTmp = 0;
853             aValue >>= nTmp;
854             if( nTmp >= 0)
855                 aFontMetric.SetDividerCountBy(nTmp);
856         }
857         break;
858         case WID_COUNT_EMPTY_LINES :
859         {
860             bool bVal = *o3tl::doAccess<bool>(aValue);
861             aFontMetric.SetCountBlankLines(bVal);
862         }
863         break;
864         case WID_COUNT_LINES_IN_FRAMES :
865         {
866             bool bVal = *o3tl::doAccess<bool>(aValue);
867             aFontMetric.SetCountInFlys(bVal);
868         }
869         break;
870         case WID_RESTART_AT_EACH_PAGE :
871         {
872             bool bVal = *o3tl::doAccess<bool>(aValue);
873             aFontMetric.SetRestartEachPage(bVal);
874         }
875         break;
876     }
877     m_pDoc->SetLineNumberInfo(aFontMetric);
878 }
879 
getPropertyValue(const OUString & rPropertyName)880 Any SwXLineNumberingProperties::getPropertyValue(const OUString& rPropertyName)
881 {
882     SolarMutexGuard aGuard;
883     Any aRet;
884     if(!m_pDoc)
885         throw uno::RuntimeException(u"Numbering's document is not set."_ustr);
886 
887     const SfxItemPropertyMapEntry*  pEntry = m_pPropertySet->getPropertyMap().getByName( rPropertyName );
888     if(!pEntry)
889         throw UnknownPropertyException("Unknown property: " + rPropertyName, getXWeak() );
890 
891     const SwLineNumberInfo& rInfo = m_pDoc->GetLineNumberInfo();
892     switch(pEntry->nWID)
893     {
894         case WID_NUM_ON:
895             aRet <<= rInfo.IsPaintLineNumbers();
896         break;
897         case WID_CHARACTER_STYLE :
898         {
899             ProgName aString;
900             // return empty string if no char format is set
901             // otherwise it would be created here
902             if(rInfo.HasCharFormat())
903             {
904                 SwStyleNameMapper::FillProgName(
905                             rInfo.GetCharFormat(m_pDoc->getIDocumentStylePoolAccess())->GetName(),
906                             aString,
907                             SwGetPoolIdFromName::ChrFmt);
908             }
909             aRet <<= aString.toString();
910         }
911         break;
912         case WID_NUMBERING_TYPE  :
913             aRet <<= static_cast<sal_Int16>(rInfo.GetNumType().GetNumberingType());
914         break;
915         case WID_NUMBER_POSITION :
916         {
917             sal_Int16 nRet = 0;
918             switch(rInfo.GetPos())
919             {
920                 case  LINENUMBER_POS_LEFT:
921                     nRet = style::LineNumberPosition::LEFT;
922                 break;
923                 case LINENUMBER_POS_RIGHT :
924                     nRet = style::LineNumberPosition::RIGHT      ;
925                 break;
926                 case  LINENUMBER_POS_INSIDE:
927                     nRet = style::LineNumberPosition::INSIDE     ;
928                 break;
929                 case LINENUMBER_POS_OUTSIDE :
930                     nRet = style::LineNumberPosition::OUTSIDE    ;
931                 break;
932             }
933             aRet <<= nRet;
934         }
935         break;
936         case WID_DISTANCE        :
937         {
938             sal_uInt16 nPos = rInfo.GetPosFromLeft();
939             if(USHRT_MAX == nPos)
940                 nPos = 0;
941             aRet <<= static_cast < sal_Int32 >(convertTwipToMm100(nPos));
942         }
943         break;
944         case WID_INTERVAL   :
945             aRet <<= static_cast<sal_Int16>(rInfo.GetCountBy());
946         break;
947         case WID_SEPARATOR_TEXT  :
948             aRet <<= rInfo.GetDivider();
949         break;
950         case WID_SEPARATOR_INTERVAL:
951             aRet <<= static_cast<sal_Int16>(rInfo.GetDividerCountBy());
952         break;
953         case WID_COUNT_EMPTY_LINES :
954             aRet <<= rInfo.IsCountBlankLines();
955         break;
956         case WID_COUNT_LINES_IN_FRAMES :
957             aRet <<= rInfo.IsCountInFlys();
958         break;
959         case WID_RESTART_AT_EACH_PAGE :
960             aRet <<= rInfo.IsRestartEachPage();
961         break;
962     }
963     return aRet;
964 }
965 
addPropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)966 void SwXLineNumberingProperties::addPropertyChangeListener(const OUString& /*rPropertyName*/, const uno:: Reference< beans::XPropertyChangeListener > & /*xListener*/)
967 {
968 OSL_FAIL("not implemented");
969 }
970 
removePropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)971 void SwXLineNumberingProperties::removePropertyChangeListener(const OUString& /*rPropertyName*/, const uno:: Reference< beans::XPropertyChangeListener > & /*xListener*/)
972 {
973 OSL_FAIL("not implemented");
974 }
975 
addVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)976 void SwXLineNumberingProperties::addVetoableChangeListener(const OUString& /*rPropertyName*/, const uno:: Reference< beans::XVetoableChangeListener > & /*xListener*/)
977 {
978 OSL_FAIL("not implemented");
979 }
980 
removeVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)981 void SwXLineNumberingProperties::removeVetoableChangeListener(const OUString& /*rPropertyName*/, const uno:: Reference< beans::XVetoableChangeListener > & /*xListener*/)
982 {
983 OSL_FAIL("not implemented");
984 }
985 
986 constexpr OUString aInvalidStyle = u"__XXX___invalid"_ustr;
987 
988 class SwXNumberingRules::Impl
989     : public SvtListener
990 {
991     SwXNumberingRules& m_rParent;
992     virtual void Notify(const SfxHint&) override;
993     public:
Impl(SwXNumberingRules & rParent)994         explicit Impl(SwXNumberingRules& rParent) : m_rParent(rParent) {}
995 };
996 
isInvalidStyle(const UIName & rName)997 bool SwXNumberingRules::isInvalidStyle(const UIName& rName)
998 {
999     return rName == aInvalidStyle;
1000 }
1001 
getImplementationName()1002 OUString SwXNumberingRules::getImplementationName()
1003 {
1004     return u"SwXNumberingRules"_ustr;
1005 }
1006 
supportsService(const OUString & rServiceName)1007 sal_Bool SwXNumberingRules::supportsService(const OUString& rServiceName)
1008 {
1009     return cppu::supportsService(this, rServiceName);
1010 }
1011 
getSupportedServiceNames()1012 Sequence< OUString > SwXNumberingRules::getSupportedServiceNames()
1013 {
1014     Sequence<OUString> aRet { u"com.sun.star.text.NumberingRules"_ustr };
1015     return aRet;
1016 }
1017 
SwXNumberingRules(const SwNumRule & rRule,SwDoc * doc)1018 SwXNumberingRules::SwXNumberingRules(const SwNumRule& rRule, SwDoc* doc) :
1019     m_pImpl(new SwXNumberingRules::Impl(*this)),
1020     m_pDoc(doc),
1021     m_pDocShell(nullptr),
1022     m_pNumRule(new SwNumRule(rRule)),
1023     m_pPropertySet(GetNumberingRulesSet()),
1024     m_bOwnNumRuleCreated(true)
1025 {
1026     // first organize the document - it is dependent on the set character formats
1027     // if no format is set, it should work as well
1028     for( sal_uInt16 i = 0; i < MAXLEVEL; ++i)
1029     {
1030         SwNumFormat rFormat(m_pNumRule->Get(i));
1031         SwCharFormat* pCharFormat = rFormat.GetCharFormat();
1032         if(pCharFormat)
1033         {
1034             m_pDoc = &pCharFormat->GetDoc();
1035             break;
1036         }
1037     }
1038     if(m_pDoc)
1039         m_pImpl->StartListening(GetPageDescNotifier(m_pDoc));
1040     for(sal_uInt16 i = 0; i < MAXLEVEL; ++i)
1041     {
1042         m_sNewCharStyleNames[i] = UIName(aInvalidStyle);
1043         m_sNewBulletFontNames[i] = UIName(aInvalidStyle);
1044     }
1045 }
1046 
SwXNumberingRules(SwDocShell & rDocSh)1047 SwXNumberingRules::SwXNumberingRules(SwDocShell& rDocSh) :
1048     m_pImpl(new SwXNumberingRules::Impl(*this)),
1049     m_pDoc(nullptr),
1050     m_pDocShell(&rDocSh),
1051     m_pNumRule(nullptr),
1052     m_pPropertySet(GetNumberingRulesSet()),
1053     m_bOwnNumRuleCreated(false)
1054 {
1055     if (!m_pDocShell->GetDoc())
1056         throw uno::RuntimeException(u"Uninitialized shell passed to SwXNumberingRules constructor"_ustr);
1057     m_pImpl->StartListening(GetPageDescNotifier(m_pDocShell->GetDoc()));
1058 }
1059 
SwXNumberingRules(SwDoc & rDoc)1060 SwXNumberingRules::SwXNumberingRules(SwDoc& rDoc) :
1061     m_pImpl(new SwXNumberingRules::Impl(*this)),
1062     m_pDoc(&rDoc),
1063     m_pDocShell(nullptr),
1064     m_pNumRule(nullptr),
1065     m_pPropertySet(GetNumberingRulesSet()),
1066     m_bOwnNumRuleCreated(false)
1067 {
1068     m_pImpl->StartListening(GetPageDescNotifier(&rDoc));
1069     m_sCreatedNumRuleName = rDoc.GetUniqueNumRuleName();
1070     rDoc.MakeNumRule( m_sCreatedNumRuleName, nullptr,
1071                       // #i89178#
1072                       numfunc::GetDefaultPositionAndSpaceMode() );
1073 }
1074 
~SwXNumberingRules()1075 SwXNumberingRules::~SwXNumberingRules()
1076 {
1077     SolarMutexGuard aGuard;
1078     if(m_pDoc && !m_sCreatedNumRuleName.isEmpty())
1079         m_pDoc->DelNumRule( m_sCreatedNumRuleName );
1080     if( m_bOwnNumRuleCreated )
1081         delete m_pNumRule;
1082 }
1083 
replaceByIndex(sal_Int32 nIndex,const uno::Any & rElement)1084 void SwXNumberingRules::replaceByIndex(sal_Int32 nIndex, const uno::Any& rElement)
1085 {
1086     SolarMutexGuard aGuard;
1087     if(nIndex < 0 || MAXLEVEL <= nIndex)
1088         throw lang::IndexOutOfBoundsException();
1089 
1090     auto rProperties = o3tl::tryAccess<uno::Sequence<beans::PropertyValue>>(
1091         rElement);
1092     if(!rProperties)
1093         throw lang::IllegalArgumentException();
1094     SwNumRule* pRule = nullptr;
1095     if(m_pNumRule)
1096         SwXNumberingRules::SetNumberingRuleByIndex( *m_pNumRule,
1097                             *rProperties, nIndex);
1098     else if(m_pDocShell)
1099     {
1100         // #i87650# - correction of cws warnings:
1101         SwNumRule aNumRule( *(m_pDocShell->GetDoc()->GetOutlineNumRule()) );
1102         SwXNumberingRules::SetNumberingRuleByIndex( aNumRule,
1103                             *rProperties, nIndex);
1104         // set character format if needed
1105         // this code appears to be dead - except when a style is assigned for BITMAP numbering?
1106         const SwCharFormats* pFormats = m_pDocShell->GetDoc()->GetCharFormats();
1107         const size_t nChCount = pFormats->size();
1108         for(sal_uInt16 i = 0; i < MAXLEVEL;i++)
1109         {
1110             SwNumFormat aFormat(aNumRule.Get( i ));
1111             if (!m_sNewCharStyleNames[i].isEmpty() &&
1112                 (!aFormat.GetCharFormat() || aFormat.GetCharFormat()->GetName()!= m_sNewCharStyleNames[i]))
1113             {
1114                 SwCharFormat* pCharFormat = nullptr;
1115                 for(size_t j = 0; j< nChCount; ++j)
1116                 {
1117                     SwCharFormat* pTmp = (*pFormats)[j];
1118                     if(pTmp->GetName() == m_sNewCharStyleNames[i])
1119                     {
1120                         pCharFormat = pTmp;
1121                         break;
1122                     }
1123                 }
1124                 if(!pCharFormat)
1125                 {
1126                     SfxStyleSheetBase* pBase;
1127                     pBase = m_pDocShell->GetStyleSheetPool()->Find(m_sNewCharStyleNames[i].toString(),
1128                                                                     SfxStyleFamily::Char);
1129                     if(!pBase)
1130                         pBase = &m_pDocShell->GetStyleSheetPool()->Make(m_sNewCharStyleNames[i].toString(), SfxStyleFamily::Char);
1131                     pCharFormat = static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat();
1132 
1133                 }
1134                 aFormat.SetCharFormat( pCharFormat );
1135                 aNumRule.Set( i, aFormat );
1136             }
1137         }
1138         m_pDocShell->GetDoc()->SetOutlineNumRule( aNumRule );
1139     }
1140     else if(m_pDoc && !m_sCreatedNumRuleName.isEmpty() &&
1141         nullptr != (pRule = m_pDoc->FindNumRulePtr( m_sCreatedNumRuleName )))
1142     {
1143         SwXNumberingRules::SetNumberingRuleByIndex( *pRule,
1144                             *rProperties, nIndex);
1145 
1146         pRule->Validate(*m_pDoc);
1147     }
1148     else
1149         throw uno::RuntimeException();
1150 }
1151 
getCount()1152 sal_Int32 SwXNumberingRules::getCount()
1153 {
1154     return MAXLEVEL;
1155 }
1156 
getPropertyByIndex(sal_Int32 nIndex,const OUString & rPropName)1157 uno::Any SwXNumberingRules::getPropertyByIndex(sal_Int32 nIndex, const OUString& rPropName)
1158 {
1159     SolarMutexGuard aGuard;
1160     if(nIndex < 0 || MAXLEVEL <= nIndex)
1161         throw lang::IndexOutOfBoundsException();
1162 
1163     const SwNumRule* pRule = m_pNumRule;
1164     if(!pRule && m_pDoc && !m_sCreatedNumRuleName.isEmpty())
1165         pRule = m_pDoc->FindNumRulePtr( m_sCreatedNumRuleName );
1166     if (!pRule && m_pDocShell)
1167         pRule = m_pDocShell->GetDoc()->GetOutlineNumRule();
1168     if (!pRule)
1169         throw uno::RuntimeException();
1170     return GetNumberingRuleByIndex(*pRule, nIndex, rPropName);
1171 }
1172 
getByIndex(sal_Int32 nIndex)1173 uno::Any SwXNumberingRules::getByIndex(sal_Int32 nIndex)
1174 {
1175     SolarMutexGuard aGuard;
1176     if(nIndex < 0 || MAXLEVEL <= nIndex)
1177         throw lang::IndexOutOfBoundsException();
1178 
1179     uno::Any aVal;
1180     const SwNumRule* pRule = m_pNumRule;
1181     if(!pRule && m_pDoc && !m_sCreatedNumRuleName.isEmpty())
1182         pRule = m_pDoc->FindNumRulePtr( m_sCreatedNumRuleName );
1183     if(pRule)
1184     {
1185         uno::Sequence<beans::PropertyValue> aRet = GetNumberingRuleByIndex(
1186                                         *pRule, nIndex);
1187         aVal <<= aRet;
1188 
1189     }
1190     else if(m_pDocShell)
1191     {
1192         uno::Sequence<beans::PropertyValue> aRet = GetNumberingRuleByIndex(
1193                 *m_pDocShell->GetDoc()->GetOutlineNumRule(), nIndex);
1194         aVal <<= aRet;
1195     }
1196     else
1197         throw uno::RuntimeException(u"Could not get numbering rule."_ustr);
1198     return aVal;
1199 }
1200 
getElementType()1201 uno::Type SwXNumberingRules::getElementType()
1202 {
1203     return cppu::UnoType<uno::Sequence<beans::PropertyValue>>::get();
1204 }
1205 
hasElements()1206 sal_Bool SwXNumberingRules::hasElements()
1207 {
1208     return true;
1209 }
1210 
1211 const TranslateId STR_POOLCOLL_HEADLINE_ARY[]
1212 {
1213     STR_POOLCOLL_HEADLINE1,
1214     STR_POOLCOLL_HEADLINE2,
1215     STR_POOLCOLL_HEADLINE3,
1216     STR_POOLCOLL_HEADLINE4,
1217     STR_POOLCOLL_HEADLINE5,
1218     STR_POOLCOLL_HEADLINE6,
1219     STR_POOLCOLL_HEADLINE7,
1220     STR_POOLCOLL_HEADLINE8,
1221     STR_POOLCOLL_HEADLINE9,
1222     STR_POOLCOLL_HEADLINE10
1223 };
1224 
GetNumberingRuleByIndex(const SwNumRule & rNumRule,sal_Int32 nIndex) const1225 uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetNumberingRuleByIndex(
1226                 const SwNumRule& rNumRule, sal_Int32 nIndex) const
1227 {
1228     SolarMutexGuard aGuard;
1229     OSL_ENSURE( 0 <= nIndex && nIndex < MAXLEVEL, "index out of range" );
1230 
1231     const SwNumFormat& rFormat = rNumRule.Get( o3tl::narrowing<sal_uInt16>(nIndex) );
1232 
1233     SwCharFormat* pCharFormat = rFormat.GetCharFormat();
1234     UIName CharStyleName;
1235     if (pCharFormat)
1236         CharStyleName = pCharFormat->GetName();
1237 
1238     // Whether or not a style is present: the array entry overwrites this string
1239     if (!m_sNewCharStyleNames[nIndex].isEmpty() &&
1240         !SwXNumberingRules::isInvalidStyle(m_sNewCharStyleNames[nIndex]))
1241     {
1242         CharStyleName = m_sNewCharStyleNames[nIndex];
1243     }
1244 
1245     ProgName aUString;
1246     if (m_pDocShell) // -> Chapter Numbering
1247     {
1248         // template name
1249         UIName sValue(SwResId(STR_POOLCOLL_HEADLINE_ARY[nIndex]));
1250         const SwTextFormatColls* pColls = m_pDocShell->GetDoc()->GetTextFormatColls();
1251         const size_t nCount = pColls->size();
1252         for(size_t i = 0; i < nCount; ++i)
1253         {
1254             SwTextFormatColl &rTextColl = *pColls->operator[](i);
1255             if(rTextColl.IsDefault())
1256                 continue;
1257 
1258             const sal_Int16 nOutLevel = rTextColl.IsAssignedToListLevelOfOutlineStyle()
1259                                         ? static_cast<sal_Int16>(rTextColl.GetAssignedOutlineStyleLevel())
1260                                         : MAXLEVEL;
1261             if ( nOutLevel == nIndex )
1262             {
1263                 sValue = rTextColl.GetName();
1264                 break; // the style for the level in question has been found
1265             }
1266             else if( sValue==rTextColl.GetName() )
1267             {
1268                 // if the default for the level is existing, but its
1269                 // level is different, then it cannot be the default.
1270                 sValue = UIName();
1271             }
1272         }
1273         SwStyleNameMapper::FillProgName(sValue, aUString, SwGetPoolIdFromName::TxtColl);
1274     }
1275 
1276     OUString referer;
1277     if (m_pDoc != nullptr) {
1278         auto const sh = m_pDoc->GetPersist();
1279         if (sh != nullptr && sh->HasName()) {
1280             referer = sh->GetMedium()->GetName();
1281         }
1282     }
1283     return GetPropertiesForNumFormat(
1284         rFormat, CharStyleName, m_pDocShell ? & aUString : nullptr, referer);
1285 
1286 }
1287 
GetNumberingRuleByIndex(const SwNumRule & rNumRule,sal_Int32 nIndex,const OUString & rPropName) const1288 uno::Any SwXNumberingRules::GetNumberingRuleByIndex(
1289                 const SwNumRule& rNumRule, sal_Int32 nIndex, const OUString& rPropName) const
1290 {
1291     SolarMutexGuard aGuard;
1292     OSL_ENSURE( 0 <= nIndex && nIndex < MAXLEVEL, "index out of range" );
1293 
1294     const SwNumFormat& rFormat = rNumRule.Get( o3tl::narrowing<sal_uInt16>(nIndex) );
1295 
1296     SwCharFormat* pCharFormat = rFormat.GetCharFormat();
1297     UIName CharStyleName;
1298     if (pCharFormat)
1299         CharStyleName = pCharFormat->GetName();
1300 
1301     // Whether or not a style is present: the array entry overwrites this string
1302     if (!m_sNewCharStyleNames[nIndex].isEmpty() &&
1303         !SwXNumberingRules::isInvalidStyle(m_sNewCharStyleNames[nIndex]))
1304     {
1305         CharStyleName = m_sNewCharStyleNames[nIndex];
1306     }
1307 
1308     ProgName aUString;
1309     if (m_pDocShell) // -> Chapter Numbering
1310     {
1311         // template name
1312         UIName sValue(SwResId(STR_POOLCOLL_HEADLINE_ARY[nIndex]));
1313         const SwTextFormatColls* pColls = m_pDocShell->GetDoc()->GetTextFormatColls();
1314         const size_t nCount = pColls->size();
1315         for(size_t i = 0; i < nCount; ++i)
1316         {
1317             SwTextFormatColl &rTextColl = *pColls->operator[](i);
1318             if(rTextColl.IsDefault())
1319                 continue;
1320 
1321             const sal_Int16 nOutLevel = rTextColl.IsAssignedToListLevelOfOutlineStyle()
1322                                         ? static_cast<sal_Int16>(rTextColl.GetAssignedOutlineStyleLevel())
1323                                         : MAXLEVEL;
1324             if ( nOutLevel == nIndex )
1325             {
1326                 sValue = rTextColl.GetName();
1327                 break; // the style for the level in question has been found
1328             }
1329             else if( sValue==rTextColl.GetName() )
1330             {
1331                 // if the default for the level is existing, but its
1332                 // level is different, then it cannot be the default.
1333                 sValue = UIName();
1334             }
1335         }
1336         SwStyleNameMapper::FillProgName(sValue, aUString, SwGetPoolIdFromName::TxtColl);
1337     }
1338 
1339     OUString referer;
1340     if (m_pDoc != nullptr) {
1341         auto const sh = m_pDoc->GetPersist();
1342         if (sh != nullptr && sh->HasName()) {
1343             referer = sh->GetMedium()->GetName();
1344         }
1345     }
1346     return GetPropertyForNumFormat(
1347         rFormat, CharStyleName, m_pDocShell ? & aUString : nullptr, referer, rPropName);
1348 
1349 }
1350 
GetPropertiesForNumFormat(const SwNumFormat & rFormat,UIName const & rCharFormatName,ProgName const * const pHeadingStyleName,OUString const & referer)1351 uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFormat(
1352         const SwNumFormat& rFormat, UIName const& rCharFormatName,
1353         ProgName const*const pHeadingStyleName, OUString const & referer)
1354 {
1355     bool bChapterNum = pHeadingStyleName != nullptr;
1356 
1357     std::vector<PropertyValue> aPropertyValues;
1358     aPropertyValues.reserve(32);
1359     //fill all properties into the array
1360 
1361     //adjust
1362     SvxAdjust eAdj = rFormat.GetNumAdjust();
1363     sal_Int16 nINT16 = aSvxToUnoAdjust[eAdj];
1364     aPropertyValues.push_back(comphelper::makePropertyValue(u"Adjust"_ustr, nINT16));
1365 
1366     //parentnumbering
1367     nINT16 = rFormat.GetIncludeUpperLevels();
1368     aPropertyValues.push_back(comphelper::makePropertyValue(u"ParentNumbering"_ustr, nINT16));
1369 
1370     //prefix
1371     OUString aUString = rFormat.GetPrefix();
1372     aPropertyValues.push_back(comphelper::makePropertyValue(u"Prefix"_ustr, aUString));
1373 
1374     //suffix
1375     aUString = rFormat.GetSuffix();
1376     aPropertyValues.push_back(comphelper::makePropertyValue(u"Suffix"_ustr, aUString));
1377 
1378     //listformat
1379     if (rFormat.HasListFormat())
1380     {
1381         aPropertyValues.push_back(comphelper::makePropertyValue(u"ListFormat"_ustr, rFormat.GetListFormat()));
1382     }
1383 
1384     if (rFormat.GetIsLegal())
1385         aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_LEVEL_IS_LEGAL, true));
1386 
1387     //char style name
1388     ProgName aCharStyleProgName;
1389     SwStyleNameMapper::FillProgName( rCharFormatName, aCharStyleProgName, SwGetPoolIdFromName::ChrFmt);
1390     aPropertyValues.push_back(comphelper::makePropertyValue(u"CharStyleName"_ustr, aCharStyleProgName.toString()));
1391 
1392     //startvalue
1393     nINT16 = rFormat.GetStart();
1394     aPropertyValues.push_back(comphelper::makePropertyValue(u"StartWith"_ustr, nINT16));
1395 
1396     if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
1397     {
1398         //leftmargin
1399         sal_Int32 nINT32 = convertTwipToMm100(rFormat.GetAbsLSpace());
1400         aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_LEFT_MARGIN, nINT32));
1401 
1402         //chartextoffset
1403         nINT32 = convertTwipToMm100(rFormat.GetCharTextDistance());
1404         aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_SYMBOL_TEXT_DISTANCE, nINT32));
1405 
1406         //firstlineoffset
1407         nINT32 = convertTwipToMm100(rFormat.GetFirstLineOffset());
1408         aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_FIRST_LINE_OFFSET, nINT32));
1409     }
1410 
1411     // PositionAndSpaceMode
1412     nINT16 = PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION;
1413     if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
1414     {
1415         nINT16 = PositionAndSpaceMode::LABEL_ALIGNMENT;
1416     }
1417     aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_POSITION_AND_SPACE_MODE, nINT16));
1418 
1419     if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
1420     {
1421         // LabelFollowedBy
1422         nINT16 = LabelFollow::LISTTAB;
1423         if ( rFormat.GetLabelFollowedBy() == SvxNumberFormat::SPACE )
1424         {
1425             nINT16 = LabelFollow::SPACE;
1426         }
1427         else if ( rFormat.GetLabelFollowedBy() == SvxNumberFormat::NOTHING )
1428         {
1429             nINT16 = LabelFollow::NOTHING;
1430         }
1431         else if ( rFormat.GetLabelFollowedBy() == SvxNumberFormat::NEWLINE )
1432         {
1433             nINT16 = LabelFollow::NEWLINE;
1434         }
1435         aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_LABEL_FOLLOWED_BY, nINT16));
1436 
1437         // ListtabStopPosition
1438         sal_Int32 nINT32 = convertTwipToMm100(rFormat.GetListtabPos());
1439         aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_LISTTAB_STOP_POSITION, nINT32));
1440 
1441         // FirstLineIndent
1442         nINT32 = convertTwipToMm100(rFormat.GetFirstLineIndent());
1443         aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_FIRST_LINE_INDENT, nINT32));
1444 
1445         // IndentAt
1446         nINT32 = convertTwipToMm100(rFormat.GetIndentAt());
1447         aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_INDENT_AT, nINT32));
1448     }
1449 
1450     //numberingtype
1451     nINT16 = rFormat.GetNumberingType();
1452     aPropertyValues.push_back(comphelper::makePropertyValue(u"NumberingType"_ustr, nINT16));
1453 
1454     if(!bChapterNum)
1455     {
1456         if(SVX_NUM_CHAR_SPECIAL == rFormat.GetNumberingType())
1457         {
1458             sal_UCS4 cBullet = rFormat.GetBulletChar();
1459 
1460             //BulletId
1461             nINT16 = cBullet;
1462             aPropertyValues.push_back(comphelper::makePropertyValue(u"BulletId"_ustr, nINT16));
1463 
1464             const std::optional<vcl::Font>& pFont = rFormat.GetBulletFont();
1465 
1466             //BulletChar
1467             aUString = OUString(&cBullet, 1);
1468             aPropertyValues.push_back(comphelper::makePropertyValue(u"BulletChar"_ustr, aUString));
1469 
1470             //BulletFontName
1471             aUString = pFont ? pFont->GetFamilyName() : OUString();
1472             aPropertyValues.push_back(comphelper::makePropertyValue(u"BulletFontName"_ustr, aUString));
1473 
1474             //BulletFont
1475             if(pFont)
1476             {
1477                 awt::FontDescriptor aDesc;
1478                 SvxUnoFontDescriptor::ConvertFromFont( *pFont, aDesc );
1479                 aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_BULLET_FONT, aDesc));
1480             }
1481         }
1482         if (SVX_NUM_BITMAP == rFormat.GetNumberingType())
1483         {
1484             const SvxBrushItem* pBrush = rFormat.GetBrush();
1485             const Graphic* pGraphic = pBrush ? pBrush->GetGraphic(referer) : nullptr;
1486             if (pGraphic)
1487             {
1488                 //GraphicBitmap
1489                 uno::Reference<awt::XBitmap> xBitmap(pGraphic->GetXGraphic(), uno::UNO_QUERY);
1490                 aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_GRAPHIC_BITMAP, xBitmap));
1491             }
1492 
1493             Size aSize = rFormat.GetGraphicSize();
1494             // #i101131#
1495             // adjust conversion due to type mismatch between <Size> and <awt::Size>
1496             awt::Size aAwtSize(convertTwipToMm100(aSize.Width()), convertTwipToMm100(aSize.Height()));
1497             aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_GRAPHIC_SIZE, aAwtSize));
1498 
1499             const SwFormatVertOrient* pOrient = rFormat.GetGraphicOrientation();
1500             if(pOrient)
1501             {
1502                 uno::Any any;
1503                 pOrient->QueryValue(any);
1504                 aPropertyValues.emplace_back(
1505                     UNO_NAME_VERT_ORIENT, -1, any, PropertyState_DIRECT_VALUE);
1506             }
1507         }
1508     }
1509     else
1510     {
1511         aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_HEADING_STYLE_NAME, pHeadingStyleName->toString()));
1512     }
1513 
1514     return ::comphelper::containerToSequence(aPropertyValues);
1515 }
1516 
GetPropertyForNumFormat(const SwNumFormat & rFormat,UIName const & rCharFormatName,ProgName const * const pHeadingStyleName,OUString const & referer,OUString const & rPropName)1517 uno::Any SwXNumberingRules::GetPropertyForNumFormat(
1518         const SwNumFormat& rFormat, UIName const& rCharFormatName,
1519         ProgName const*const pHeadingStyleName, OUString const & referer, OUString const & rPropName)
1520 {
1521     bool bChapterNum = pHeadingStyleName != nullptr;
1522 
1523 
1524     //adjust
1525     if (rPropName == u"Adjust"_ustr)
1526     {
1527         SvxAdjust eAdj = rFormat.GetNumAdjust();
1528         return uno::Any(sal_Int16(aSvxToUnoAdjust[eAdj]));
1529     }
1530     if (rPropName == u"ParentNumbering"_ustr)
1531         return uno::Any(sal_Int16(rFormat.GetIncludeUpperLevels()));
1532     if (rPropName == u"Prefix"_ustr)
1533         return uno::Any(rFormat.GetPrefix());
1534     if (rPropName == u"Suffix"_ustr)
1535         return uno::Any(rFormat.GetSuffix());
1536     if (rPropName == u"ListFormat"_ustr)
1537     {
1538         if (rFormat.HasListFormat())
1539             return uno::Any(rFormat.GetListFormat());
1540         else
1541             return uno::Any();
1542     }
1543     if (rPropName == UNO_NAME_LEVEL_IS_LEGAL)
1544         return uno::Any(rFormat.GetIsLegal());
1545     if (rPropName == u"CharStyleName"_ustr)
1546     {
1547         ProgName aUString;
1548         SwStyleNameMapper::FillProgName( rCharFormatName, aUString, SwGetPoolIdFromName::ChrFmt);
1549         return uno::Any(aUString.toString());
1550     }
1551     if (rPropName == u"StartWith"_ustr)
1552         return uno::Any(sal_Int16(rFormat.GetStart()));
1553     if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
1554     {
1555         //leftmargin
1556         if (rPropName == UNO_NAME_LEFT_MARGIN)
1557             return uno::Any(sal_Int32(convertTwipToMm100(rFormat.GetAbsLSpace())));
1558 
1559         //chartextoffset
1560         if (rPropName == UNO_NAME_SYMBOL_TEXT_DISTANCE)
1561             return uno::Any(sal_Int32(convertTwipToMm100(rFormat.GetCharTextDistance())));
1562 
1563         //firstlineoffset
1564         if (rPropName == UNO_NAME_FIRST_LINE_OFFSET)
1565             return uno::Any(sal_Int32(convertTwipToMm100(rFormat.GetFirstLineOffset())));
1566     }
1567 
1568     // PositionAndSpaceMode
1569     if (rPropName == UNO_NAME_POSITION_AND_SPACE_MODE)
1570     {
1571         sal_Int16 nINT16 = PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION;
1572         if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
1573         {
1574             nINT16 = PositionAndSpaceMode::LABEL_ALIGNMENT;
1575         }
1576         return uno::Any(nINT16);
1577     }
1578 
1579     if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
1580     {
1581         // LabelFollowedBy
1582         if (rPropName == UNO_NAME_LABEL_FOLLOWED_BY)
1583         {
1584             sal_Int16 nINT16 = LabelFollow::LISTTAB;
1585             if ( rFormat.GetLabelFollowedBy() == SvxNumberFormat::SPACE )
1586             {
1587                 nINT16 = LabelFollow::SPACE;
1588             }
1589             else if ( rFormat.GetLabelFollowedBy() == SvxNumberFormat::NOTHING )
1590             {
1591                 nINT16 = LabelFollow::NOTHING;
1592             }
1593             else if ( rFormat.GetLabelFollowedBy() == SvxNumberFormat::NEWLINE )
1594             {
1595                 nINT16 = LabelFollow::NEWLINE;
1596             }
1597             return uno::Any(nINT16);
1598         }
1599 
1600         // ListtabStopPosition
1601         if (rPropName == UNO_NAME_LISTTAB_STOP_POSITION)
1602             return uno::Any(sal_Int32(convertTwipToMm100(rFormat.GetListtabPos())));
1603 
1604         // FirstLineIndent
1605         if (rPropName == UNO_NAME_FIRST_LINE_INDENT)
1606             return uno::Any(sal_Int32(convertTwipToMm100(rFormat.GetFirstLineIndent())));
1607 
1608         // IndentAt
1609         if (rPropName == UNO_NAME_INDENT_AT)
1610             return uno::Any(sal_Int32(convertTwipToMm100(rFormat.GetIndentAt())));
1611     }
1612 
1613     //numberingtype
1614     if (rPropName == u"NumberingType"_ustr)
1615         return uno::Any(sal_Int16(rFormat.GetNumberingType()));
1616 
1617     if(!bChapterNum)
1618     {
1619         if(SVX_NUM_CHAR_SPECIAL == rFormat.GetNumberingType())
1620         {
1621             //BulletId
1622             if (rPropName == u"BulletId"_ustr)
1623                 return uno::Any(sal_Int16(rFormat.GetBulletChar()));
1624 
1625             //BulletChar
1626             if (rPropName == u"BulletChar"_ustr)
1627             {
1628                 sal_UCS4 cBullet = rFormat.GetBulletChar();
1629                 return uno::Any(OUString(&cBullet, 1));
1630             }
1631 
1632             //BulletFontName
1633             if (rPropName == u"BulletFontName"_ustr)
1634             {
1635                 const std::optional<vcl::Font>& pFont = rFormat.GetBulletFont();
1636                 return uno::Any(pFont ? pFont->GetFamilyName() : OUString());
1637             }
1638 
1639             //BulletFont
1640             if (rPropName == UNO_NAME_BULLET_FONT)
1641             {
1642                 if (const std::optional<vcl::Font>& pFont = rFormat.GetBulletFont())
1643                 {
1644                     awt::FontDescriptor aDesc;
1645                     SvxUnoFontDescriptor::ConvertFromFont( *pFont, aDesc );
1646                     return uno::Any(aDesc);
1647                 }
1648             }
1649         }
1650         if (SVX_NUM_BITMAP == rFormat.GetNumberingType())
1651         {
1652             //GraphicBitmap
1653             if (rPropName == UNO_NAME_GRAPHIC_BITMAP)
1654             {
1655                 const SvxBrushItem* pBrush = rFormat.GetBrush();
1656                 const Graphic* pGraphic = pBrush ? pBrush->GetGraphic(referer) : nullptr;
1657                 if (pGraphic)
1658                 {
1659                     return uno::Any(uno::Reference<awt::XBitmap>(pGraphic->GetXGraphic(), uno::UNO_QUERY));
1660                 }
1661             }
1662 
1663             if (rPropName == UNO_NAME_GRAPHIC_SIZE)
1664             {
1665                 Size aSize = rFormat.GetGraphicSize();
1666                 // #i101131#
1667                 // adjust conversion due to type mismatch between <Size> and <awt::Size>
1668                 return uno::Any(awt::Size(convertTwipToMm100(aSize.Width()), convertTwipToMm100(aSize.Height())));
1669             }
1670 
1671             if (rPropName == UNO_NAME_VERT_ORIENT)
1672             {
1673                 const SwFormatVertOrient* pOrient = rFormat.GetGraphicOrientation();
1674                 if(pOrient)
1675                 {
1676                     uno::Any any;
1677                     pOrient->QueryValue(any);
1678                     return any;
1679                 }
1680             }
1681         }
1682     }
1683     else
1684     {
1685         if (rPropName == UNO_NAME_HEADING_STYLE_NAME)
1686             return uno::Any(pHeadingStyleName->toString());
1687     }
1688 
1689     throw UnknownPropertyException(rPropName);
1690 }
1691 
SetNumberingRuleByIndex(SwNumRule & rNumRule,const uno::Sequence<beans::PropertyValue> & rProperties,sal_Int32 nIndex)1692 void SwXNumberingRules::SetNumberingRuleByIndex(
1693             SwNumRule& rNumRule,
1694             const uno::Sequence<beans::PropertyValue>& rProperties, sal_Int32 nIndex)
1695 {
1696     SolarMutexGuard aGuard;
1697     OSL_ENSURE( 0 <= nIndex && nIndex < MAXLEVEL, "index out of range" );
1698 
1699     SwNumFormat aFormat(rNumRule.Get( o3tl::narrowing<sal_uInt16>(nIndex) ));
1700 
1701     UIName sHeadingStyleName;
1702     OUString sParagraphStyleName;
1703 
1704     SetPropertiesToNumFormat(aFormat, m_sNewCharStyleNames[nIndex],
1705         &m_sNewBulletFontNames[nIndex],
1706         &sHeadingStyleName, &sParagraphStyleName,
1707         m_pDoc, m_pDocShell, rProperties);
1708 
1709 
1710     if (m_pDoc && !sParagraphStyleName.isEmpty())
1711     {
1712         const SwTextFormatColls* pColls = m_pDoc->GetTextFormatColls();
1713         const size_t nCount = pColls->size();
1714         for (size_t k = 0; k < nCount; ++k)
1715         {
1716             SwTextFormatColl &rTextColl = *((*pColls)[k]);
1717             if (rTextColl.GetName() == sParagraphStyleName)
1718                 rTextColl.SetFormatAttr( SwNumRuleItem( rNumRule.GetName()));
1719         }
1720     }
1721 
1722     if (!sHeadingStyleName.isEmpty())
1723     {
1724         assert(m_pDocShell);
1725         const SwTextFormatColls* pColls = m_pDocShell->GetDoc()->GetTextFormatColls();
1726         const size_t nCount = pColls->size();
1727         for (size_t k = 0; k < nCount; ++k)
1728         {
1729             SwTextFormatColl &rTextColl = *((*pColls)[k]);
1730             if (rTextColl.IsDefault())
1731                 continue;
1732             if (rTextColl.IsAssignedToListLevelOfOutlineStyle() &&
1733                 rTextColl.GetAssignedOutlineStyleLevel() == nIndex &&
1734                 rTextColl.GetName() != sHeadingStyleName)
1735             {
1736                 rTextColl.DeleteAssignmentToListLevelOfOutlineStyle();
1737             }
1738             else if (rTextColl.GetName() == sHeadingStyleName)
1739             {
1740                 rTextColl.AssignToListLevelOfOutlineStyle( nIndex );
1741             }
1742         }
1743     }
1744 
1745     rNumRule.Set(o3tl::narrowing<sal_uInt16>(nIndex), aFormat);
1746 }
1747 
SetPropertiesToNumFormat(SwNumFormat & aFormat,UIName & rCharStyleName,UIName * const pBulletFontName,UIName * const pHeadingStyleName,OUString * const pParagraphStyleName,SwDoc * const pDoc,SwDocShell * const pDocShell,const uno::Sequence<beans::PropertyValue> & rProperties)1748 void SwXNumberingRules::SetPropertiesToNumFormat(
1749         SwNumFormat & aFormat,
1750         UIName & rCharStyleName, UIName *const pBulletFontName,
1751         UIName *const pHeadingStyleName,
1752         OUString *const pParagraphStyleName,
1753         SwDoc *const pDoc,
1754         SwDocShell *const pDocShell,
1755         const uno::Sequence<beans::PropertyValue>& rProperties)
1756 {
1757     assert(pDoc == nullptr || pDocShell == nullptr); // can't be both ordinary and chapter numbering
1758 
1759     bool bWrongArg = false;
1760     std::unique_ptr<SvxBrushItem> pSetBrush;
1761     std::unique_ptr<Size> pSetSize;
1762     std::unique_ptr<SwFormatVertOrient> pSetVOrient;
1763     bool bCharStyleNameSet = false;
1764 
1765     for (const beans::PropertyValue& rProp : rProperties)
1766     {
1767         if (rProp.Name == UNO_NAME_ADJUST)
1768         {
1769             sal_Int16 nValue = text::HoriOrientation::NONE;
1770             rProp.Value >>= nValue;
1771             switch (nValue) {
1772             case text::HoriOrientation::RIGHT:
1773                 aFormat.SetNumAdjust(SvxAdjust::Right);
1774                 break;
1775             case text::HoriOrientation::CENTER:
1776                 aFormat.SetNumAdjust(SvxAdjust::Center);
1777                 break;
1778             case text::HoriOrientation::LEFT:
1779                 aFormat.SetNumAdjust(SvxAdjust::Left);
1780                 break;
1781             default:
1782                 bWrongArg = true;
1783                 break;
1784             }
1785         }
1786         else if (rProp.Name == UNO_NAME_PARENT_NUMBERING)
1787         {
1788             sal_Int16 nSet = 0;
1789             rProp.Value >>= nSet;
1790             if(nSet >= 0 && MAXLEVEL >= nSet)
1791                 aFormat.SetIncludeUpperLevels( static_cast< sal_uInt8 >(nSet) );
1792         }
1793         else if (rProp.Name == UNO_NAME_PREFIX)
1794         {
1795             OUString uTmp;
1796             rProp.Value >>= uTmp;
1797             aFormat.SetPrefix(uTmp);
1798         }
1799         else if (rProp.Name == UNO_NAME_SUFFIX)
1800         {
1801             OUString uTmp;
1802             rProp.Value >>= uTmp;
1803             aFormat.SetSuffix(uTmp);
1804         }
1805         else if (rProp.Name == UNO_NAME_CHAR_STYLE_NAME)
1806         {
1807             bCharStyleNameSet = true;
1808             OUString uTmp;
1809             rProp.Value >>= uTmp;
1810             UIName sCharFormatName;
1811             SwStyleNameMapper::FillUIName( ProgName(uTmp), sCharFormatName, SwGetPoolIdFromName::ChrFmt );
1812             SwDoc *const pLocalDoc = pDocShell ? pDocShell->GetDoc() : pDoc;
1813             if (sCharFormatName.isEmpty())
1814             {
1815                 rCharStyleName = UIName();
1816                 aFormat.SetCharFormat(nullptr);
1817                 aFormat.SetCharFormatName(u""_ustr);
1818             }
1819             else if (pLocalDoc)
1820             {
1821                 SwCharFormat* pCharFormat = nullptr;
1822                 if (!sCharFormatName.isEmpty())
1823                 {
1824                     pCharFormat = pLocalDoc->FindCharFormatByName(sCharFormatName);
1825                     if(!pCharFormat)
1826                     {
1827 
1828                         SfxStyleSheetBase* pBase;
1829                         SfxStyleSheetBasePool* pPool = pLocalDoc->GetDocShell()->GetStyleSheetPool();
1830                         pBase = pPool->Find(sCharFormatName.toString(), SfxStyleFamily::Char);
1831                         if(!pBase)
1832                             pBase = &pPool->Make(sCharFormatName.toString(), SfxStyleFamily::Char);
1833                         pCharFormat = static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat();
1834                     }
1835                 }
1836                 aFormat.SetCharFormat( pCharFormat );
1837                 // #i51842#
1838                 // If the character format has been found its name should not be in the
1839                 // char style names array
1840                 rCharStyleName = UIName();
1841             }
1842             else
1843                 rCharStyleName = std::move(sCharFormatName);
1844         }
1845         else if (rProp.Name == UNO_NAME_START_WITH)
1846         {
1847             sal_Int16 nVal = 0;
1848             rProp.Value >>= nVal;
1849             aFormat.SetStart(nVal);
1850         }
1851         else if (rProp.Name == UNO_NAME_LEFT_MARGIN)
1852         {
1853             sal_Int32 nValue = 0;
1854             rProp.Value >>= nValue;
1855             // #i23727# nValue can be negative
1856             aFormat.SetAbsLSpace(o3tl::toTwips(nValue, o3tl::Length::mm100));
1857         }
1858         else if (rProp.Name == UNO_NAME_SYMBOL_TEXT_DISTANCE)
1859         {
1860             sal_Int32 nValue = 0;
1861             rProp.Value >>= nValue;
1862             if (nValue >= 0)
1863                 aFormat.SetCharTextDistance(o3tl::toTwips(nValue, o3tl::Length::mm100));
1864             else
1865                 bWrongArg = true;
1866         }
1867         else if (rProp.Name == UNO_NAME_FIRST_LINE_OFFSET)
1868         {
1869             sal_Int32 nValue = 0;
1870             rProp.Value >>= nValue;
1871             // #i23727# nValue can be positive
1872             nValue = o3tl::toTwips(nValue, o3tl::Length::mm100);
1873             aFormat.SetFirstLineOffset(nValue);
1874         }
1875         else if (rProp.Name == UNO_NAME_POSITION_AND_SPACE_MODE)
1876         {
1877             sal_Int16 nValue = 0;
1878             rProp.Value >>= nValue;
1879             if ( nValue == 0 )
1880             {
1881                 aFormat.SetPositionAndSpaceMode( SvxNumberFormat::LABEL_WIDTH_AND_POSITION );
1882             }
1883             else if ( nValue == 1 )
1884             {
1885                 aFormat.SetPositionAndSpaceMode( SvxNumberFormat::LABEL_ALIGNMENT );
1886             }
1887             else
1888             {
1889                 bWrongArg = true;
1890             }
1891         }
1892         else if (rProp.Name == UNO_NAME_LABEL_FOLLOWED_BY)
1893         {
1894             sal_Int16 nValue = 0;
1895             rProp.Value >>= nValue;
1896             if ( nValue == LabelFollow::LISTTAB )
1897             {
1898                 aFormat.SetLabelFollowedBy( SvxNumberFormat::LISTTAB );
1899             }
1900             else if ( nValue == LabelFollow::SPACE )
1901             {
1902                 aFormat.SetLabelFollowedBy( SvxNumberFormat::SPACE );
1903             }
1904             else if ( nValue == LabelFollow::NOTHING )
1905             {
1906                 aFormat.SetLabelFollowedBy( SvxNumberFormat::NOTHING );
1907             }
1908             else if ( nValue == LabelFollow::NEWLINE )
1909             {
1910                 aFormat.SetLabelFollowedBy( SvxNumberFormat::NEWLINE );
1911             }
1912             else
1913             {
1914                 bWrongArg = true;
1915             }
1916         }
1917         else if (rProp.Name == UNO_NAME_LISTTAB_STOP_POSITION)
1918         {
1919             sal_Int32 nValue = 0;
1920             rProp.Value >>= nValue;
1921             nValue = o3tl::toTwips(nValue, o3tl::Length::mm100);
1922             if ( nValue >= 0 )
1923             {
1924                 aFormat.SetListtabPos( nValue );
1925             }
1926             else
1927             {
1928                 bWrongArg = true;
1929             }
1930         }
1931         else if (rProp.Name == UNO_NAME_FIRST_LINE_INDENT)
1932         {
1933             sal_Int32 nValue = 0;
1934             rProp.Value >>= nValue;
1935             nValue = o3tl::toTwips(nValue, o3tl::Length::mm100);
1936             aFormat.SetFirstLineIndent( nValue );
1937         }
1938         else if (rProp.Name == UNO_NAME_INDENT_AT)
1939         {
1940             sal_Int32 nValue = 0;
1941             rProp.Value >>= nValue;
1942             nValue = o3tl::toTwips(nValue, o3tl::Length::mm100);
1943             aFormat.SetIndentAt( nValue );
1944         }
1945         else if (rProp.Name == UNO_NAME_NUMBERING_TYPE)
1946         {
1947             sal_Int16 nSet = 0;
1948             rProp.Value >>= nSet;
1949             if(nSet >= 0)
1950                 aFormat.SetNumberingType(static_cast<SvxNumType>(nSet));
1951             else
1952                 bWrongArg = true;
1953         }
1954         else if (rProp.Name == UNO_NAME_PARAGRAPH_STYLE_NAME)
1955         {
1956             if (pParagraphStyleName)
1957             {
1958                 OUString uTmp;
1959                 rProp.Value >>= uTmp;
1960                 UIName sStyleName;
1961                 SwStyleNameMapper::FillUIName(ProgName(uTmp), sStyleName, SwGetPoolIdFromName::TxtColl );
1962                 *pParagraphStyleName = sStyleName.toString();
1963             }
1964         }
1965         else if (rProp.Name == UNO_NAME_BULLET_ID)
1966         {
1967             sal_Int16 nSet = 0;
1968             if( rProp.Value >>= nSet )
1969                 aFormat.SetBulletChar(nSet);
1970             else
1971                 bWrongArg = true;
1972         }
1973         else if (rProp.Name == UNO_NAME_BULLET_FONT)
1974         {
1975             awt::FontDescriptor desc;
1976             if (rProp.Value >>= desc)
1977             {
1978                 // #i93725#
1979                 // do not accept "empty" font
1980                 if (!desc.Name.isEmpty())
1981                 {
1982                     vcl::Font aFont;
1983                     SvxUnoFontDescriptor::ConvertToFont(desc, aFont);
1984                     aFormat.SetBulletFont(&aFont);
1985                 }
1986             }
1987             else
1988                 bWrongArg = true;
1989         }
1990         else if (rProp.Name == UNO_NAME_BULLET_FONT_NAME)
1991         {
1992             OUString sBulletFontName;
1993             rProp.Value >>= sBulletFontName;
1994             SwDocShell *const pLclDocShell = pDocShell ? pDocShell : pDoc ? pDoc->GetDocShell() : nullptr;
1995             if (!sBulletFontName.isEmpty() && pLclDocShell)
1996             {
1997                 const SvxFontListItem* pFontListItem =
1998                         static_cast<const SvxFontListItem* >(pLclDocShell
1999                                             ->GetItem( SID_ATTR_CHAR_FONTLIST ));
2000                 const FontList*  pList = pFontListItem->GetFontList();
2001                 vcl::Font aFont(pList->Get(sBulletFontName, WEIGHT_NORMAL, ITALIC_NONE));
2002                 aFormat.SetBulletFont(&aFont);
2003             }
2004             else if (pBulletFontName)
2005                 *pBulletFontName = UIName(sBulletFontName);
2006         }
2007         else if (rProp.Name == UNO_NAME_BULLET_CHAR)
2008         {
2009             OUString aChar;
2010             rProp.Value >>= aChar;
2011             if (aChar.isEmpty())
2012             {
2013                 // If w:lvlText's value is null - set bullet char to zero
2014                 aFormat.SetBulletChar(u'\0');
2015             }
2016             else
2017             {
2018                 sal_Int32 nIndexUtf16 = 0;
2019                 sal_UCS4 cBullet = aChar.iterateCodePoints(&nIndexUtf16);
2020                 if (aChar.getLength() == nIndexUtf16)
2021                     aFormat.SetBulletChar(cBullet);
2022                 else
2023                     bWrongArg = true;
2024             }
2025         }
2026         else if (rProp.Name == UNO_NAME_GRAPHIC)
2027         {
2028             uno::Reference<graphic::XGraphic> xGraphic;
2029             if (rProp.Value >>= xGraphic)
2030             {
2031                 if (!pSetBrush)
2032                 {
2033                     const SvxBrushItem* pOrigBrush = aFormat.GetBrush();
2034                     if(pOrigBrush)
2035                         pSetBrush.reset(new SvxBrushItem(*pOrigBrush));
2036                     else
2037                         pSetBrush.reset(new SvxBrushItem(OUString(), OUString(), GPOS_AREA, RES_BACKGROUND));
2038                 }
2039                 Graphic aGraphic(xGraphic);
2040                 pSetBrush->SetGraphic(aGraphic);
2041             }
2042             else
2043                 bWrongArg = true;
2044         }
2045         else if (rProp.Name == UNO_NAME_GRAPHIC_BITMAP)
2046         {
2047             uno::Reference<awt::XBitmap> xBitmap;
2048             if (rProp.Value >>= xBitmap)
2049             {
2050                 if(!pSetBrush)
2051                 {
2052                     const SvxBrushItem* pOrigBrush = aFormat.GetBrush();
2053                     if(pOrigBrush)
2054                         pSetBrush.reset(new SvxBrushItem(*pOrigBrush));
2055                     else
2056                         pSetBrush.reset(new SvxBrushItem(OUString(), OUString(), GPOS_AREA, RES_BACKGROUND));
2057                 }
2058 
2059                 uno::Reference<graphic::XGraphic> xGraphic(xBitmap, uno::UNO_QUERY);
2060                 Graphic aGraphic(xGraphic);
2061                 pSetBrush->SetGraphic(aGraphic);
2062             }
2063             else
2064                 bWrongArg = true;
2065         }
2066         else if (rProp.Name == UNO_NAME_GRAPHIC_SIZE)
2067         {
2068             if(!pSetSize)
2069                 pSetSize.reset(new Size);
2070             awt::Size size;
2071             if (rProp.Value >>= size)
2072             {
2073                 pSetSize->setWidth(o3tl::toTwips(size.Width, o3tl::Length::mm100));
2074                 pSetSize->setHeight(o3tl::toTwips(size.Height, o3tl::Length::mm100));
2075             }
2076             else
2077                 bWrongArg = true;
2078         }
2079         else if (rProp.Name == UNO_NAME_VERT_ORIENT)
2080         {
2081             if(!pSetVOrient)
2082             {
2083                 if(aFormat.GetGraphicOrientation())
2084                     pSetVOrient.reset(aFormat.GetGraphicOrientation()->Clone());
2085                 else
2086                     pSetVOrient.reset(new SwFormatVertOrient);
2087             }
2088             pSetVOrient->PutValue(rProp.Value, MID_VERTORIENT_ORIENT);
2089         }
2090         else if (rProp.Name == UNO_NAME_HEADING_STYLE_NAME
2091                 && pDocShell) // only on chapter numbering
2092         {
2093             if (pHeadingStyleName)
2094             {
2095                 OUString uTmp;
2096                 rProp.Value >>= uTmp;
2097                 UIName sStyleName;
2098                 SwStyleNameMapper::FillUIName(ProgName(uTmp), sStyleName, SwGetPoolIdFromName::TxtColl );
2099                 *pHeadingStyleName = std::move(sStyleName);
2100             }
2101         }
2102         else if (rProp.Name == UNO_NAME_BULLET_REL_SIZE)
2103         {
2104             // BulletRelSize - unsupported - only available in Impress
2105         }
2106         else if (rProp.Name == UNO_NAME_BULLET_COLOR)
2107         {
2108             // BulletColor - ignored too
2109         }
2110         else if (rProp.Name == UNO_NAME_GRAPHIC_URL)
2111         {
2112             OUString aURL;
2113             if (rProp.Value >>= aURL)
2114             {
2115                 if(!pSetBrush)
2116                 {
2117                     const SvxBrushItem* pOrigBrush = aFormat.GetBrush();
2118                     if(pOrigBrush)
2119                         pSetBrush.reset(new SvxBrushItem(*pOrigBrush));
2120                     else
2121                         pSetBrush.reset(new SvxBrushItem(OUString(), OUString(), GPOS_AREA, RES_BACKGROUND));
2122                 }
2123 
2124                 Graphic aGraphic = vcl::graphic::loadFromURL(aURL);
2125                 if (!aGraphic.IsNone())
2126                     pSetBrush->SetGraphic(aGraphic);
2127             }
2128             else
2129                 bWrongArg = true;
2130         }
2131         else if (rProp.Name == UNO_NAME_LIST_FORMAT)
2132         {
2133             OUString uTmp;
2134             rProp.Value >>= uTmp;
2135             aFormat.SetListFormat(uTmp);
2136         }
2137         else if (rProp.Name == UNO_NAME_LEVEL_IS_LEGAL)
2138         {
2139             if (bool bVal; rProp.Value >>= bVal)
2140                 aFormat.SetIsLegal(bVal);
2141         }
2142         else
2143         {
2144             // Invalid property name
2145             throw beans::UnknownPropertyException("Unknown property " + rProp.Name);
2146         }
2147     }
2148     if(!bWrongArg && (pSetBrush || pSetSize || pSetVOrient))
2149     {
2150         if(!pSetBrush && aFormat.GetBrush())
2151             pSetBrush.reset(new SvxBrushItem(*aFormat.GetBrush()));
2152 
2153         if(pSetBrush)
2154         {
2155             if(!pSetVOrient && aFormat.GetGraphicOrientation())
2156                 pSetVOrient.reset( new SwFormatVertOrient(*aFormat.GetGraphicOrientation()) );
2157 
2158             if(!pSetSize)
2159             {
2160                 pSetSize.reset(new Size(aFormat.GetGraphicSize()));
2161                 if(!pSetSize->Width() || !pSetSize->Height())
2162                 {
2163                     const Graphic* pGraphic = pSetBrush->GetGraphic();
2164                     if(pGraphic)
2165                         *pSetSize = ::GetGraphicSizeTwip(*pGraphic, nullptr);
2166                 }
2167             }
2168             sal_Int16 eOrient = pSetVOrient ?
2169                 pSetVOrient->GetVertOrient() : text::VertOrientation::NONE;
2170             aFormat.SetGraphicBrush( pSetBrush.get(), pSetSize.get(), text::VertOrientation::NONE == eOrient ? nullptr : &eOrient );
2171         }
2172     }
2173     if ((!bCharStyleNameSet || rCharStyleName.isEmpty())
2174         && aFormat.GetNumberingType() == NumberingType::BITMAP
2175         && !aFormat.GetCharFormat()
2176         && !SwXNumberingRules::isInvalidStyle(rCharStyleName))
2177     {
2178         ProgName tmp;
2179         SwStyleNameMapper::FillProgName(RES_POOLCHR_BULLET_LEVEL, tmp);
2180         rCharStyleName = UIName(tmp.toString());
2181     }
2182 
2183     if(bWrongArg)
2184         throw lang::IllegalArgumentException();
2185 }
2186 
getPropertySetInfo()2187 uno::Reference< XPropertySetInfo > SwXNumberingRules::getPropertySetInfo()
2188 {
2189     static uno::Reference< beans::XPropertySetInfo >  aRef = m_pPropertySet->getPropertySetInfo();
2190     return aRef;
2191 }
2192 
setPropertyValue(const OUString & rPropertyName,const Any & rValue)2193 void SwXNumberingRules::setPropertyValue( const OUString& rPropertyName, const Any& rValue )
2194 {
2195     SolarMutexGuard aGuard;
2196     std::unique_ptr<SwNumRule> pDocRule;
2197     SwNumRule* pCreatedRule = nullptr;
2198     if(!m_pNumRule)
2199     {
2200         if(m_pDocShell)
2201         {
2202             pDocRule.reset(new SwNumRule(*m_pDocShell->GetDoc()->GetOutlineNumRule()));
2203         }
2204         else if(m_pDoc && !m_sCreatedNumRuleName.isEmpty())
2205         {
2206             pCreatedRule = m_pDoc->FindNumRulePtr(m_sCreatedNumRuleName);
2207         }
2208 
2209     }
2210     if(!m_pNumRule && !pDocRule && !pCreatedRule)
2211         throw RuntimeException("Could not set numbering rule property \'" + rPropertyName + "\'.");
2212 
2213     if(rPropertyName == UNO_NAME_IS_AUTOMATIC)
2214     {
2215         bool bVal = *o3tl::doAccess<bool>(rValue);
2216         if(!pCreatedRule)
2217             pDocRule ? pDocRule->SetAutoRule(bVal) : m_pNumRule->SetAutoRule(bVal);
2218     }
2219     else if(rPropertyName == UNO_NAME_IS_CONTINUOUS_NUMBERING)
2220     {
2221         bool bVal = *o3tl::doAccess<bool>(rValue);
2222         pDocRule ? pDocRule->SetContinusNum(bVal) :
2223             pCreatedRule ? pCreatedRule->SetContinusNum(bVal) : m_pNumRule->SetContinusNum(bVal);
2224     }
2225     else if(rPropertyName == UNO_NAME_NAME)
2226     {
2227         throw IllegalArgumentException();
2228     }
2229     else if(rPropertyName == UNO_NAME_IS_ABSOLUTE_MARGINS)
2230     {
2231         bool bVal = *o3tl::doAccess<bool>(rValue);
2232         pDocRule ? pDocRule->SetAbsSpaces(bVal) :
2233             pCreatedRule ? pCreatedRule->SetAbsSpaces(bVal) : m_pNumRule->SetAbsSpaces(bVal);
2234     }
2235     else if(rPropertyName == UNO_NAME_NUMBERING_IS_OUTLINE)
2236     {
2237         bool bVal = *o3tl::doAccess<bool>(rValue);
2238         SwNumRuleType eNumRuleType = bVal ? OUTLINE_RULE : NUM_RULE;
2239         pDocRule ? pDocRule->SetRuleType(eNumRuleType) :
2240             pCreatedRule ? pCreatedRule->SetRuleType(eNumRuleType) : m_pNumRule->SetRuleType(eNumRuleType);
2241     }
2242     else if(rPropertyName == UNO_NAME_DEFAULT_LIST_ID)
2243     {
2244         throw IllegalArgumentException();
2245     }
2246     else
2247         throw UnknownPropertyException(rPropertyName);
2248 
2249     if(pDocRule)
2250     {
2251         assert(m_pDocShell);
2252         m_pDocShell->GetDoc()->SetOutlineNumRule(*pDocRule);
2253         pDocRule.reset();
2254     }
2255     else if(pCreatedRule)
2256     {
2257         pCreatedRule->Validate(*m_pDoc);
2258     }
2259 }
2260 
getPropertyValue(const OUString & rPropertyName)2261 Any SwXNumberingRules::getPropertyValue( const OUString& rPropertyName )
2262 {
2263     Any aRet;
2264     const SwNumRule* pRule = m_pNumRule;
2265     if(!pRule && m_pDocShell)
2266         pRule = m_pDocShell->GetDoc()->GetOutlineNumRule();
2267     else if(m_pDoc && !m_sCreatedNumRuleName.isEmpty())
2268         pRule = m_pDoc->FindNumRulePtr( m_sCreatedNumRuleName );
2269     if(!pRule)
2270         throw RuntimeException("Could not get numbering rule property \'" + rPropertyName + "\'.");
2271 
2272     if(rPropertyName == UNO_NAME_IS_AUTOMATIC)
2273     {
2274         aRet <<= pRule->IsAutoRule();
2275     }
2276     else if(rPropertyName == UNO_NAME_IS_CONTINUOUS_NUMBERING)
2277     {
2278         aRet <<= pRule->IsContinusNum();
2279     }
2280     else if(rPropertyName == UNO_NAME_NAME)
2281         aRet <<= pRule->GetName().toString();
2282     else if(rPropertyName == UNO_NAME_IS_ABSOLUTE_MARGINS)
2283     {
2284         aRet <<= pRule->IsAbsSpaces();
2285     }
2286     else if(rPropertyName == UNO_NAME_NUMBERING_IS_OUTLINE)
2287     {
2288         aRet <<= pRule->IsOutlineRule();
2289     }
2290     else if(rPropertyName == UNO_NAME_DEFAULT_LIST_ID)
2291     {
2292         OSL_ENSURE( !pRule->GetDefaultListId().isEmpty(),
2293                 "<SwXNumberingRules::getPropertyValue(..)> - no default list id found. Serious defect." );
2294         aRet <<= pRule->GetDefaultListId();
2295     }
2296     else
2297         throw UnknownPropertyException(rPropertyName);
2298     return aRet;
2299 }
2300 
addPropertyChangeListener(const OUString &,const uno::Reference<XPropertyChangeListener> &)2301 void SwXNumberingRules::addPropertyChangeListener(
2302     const OUString& /*rPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ )
2303 {
2304 }
2305 
removePropertyChangeListener(const OUString &,const uno::Reference<XPropertyChangeListener> &)2306 void SwXNumberingRules::removePropertyChangeListener(
2307     const OUString& /*rPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ )
2308 {
2309 }
2310 
addVetoableChangeListener(const OUString &,const uno::Reference<XVetoableChangeListener> &)2311 void SwXNumberingRules::addVetoableChangeListener(
2312     const OUString& /*rPropertyName*/, const uno::Reference< XVetoableChangeListener >& /*xListener*/ )
2313 {
2314 }
2315 
removeVetoableChangeListener(const OUString &,const uno::Reference<XVetoableChangeListener> &)2316 void SwXNumberingRules::removeVetoableChangeListener(
2317     const OUString& /*rPropertyName*/, const uno::Reference< XVetoableChangeListener >& /*xListener*/ )
2318 {
2319 }
2320 
getName()2321 OUString SwXNumberingRules::getName()
2322 {
2323     if(m_pNumRule)
2324     {
2325         ProgName aString;
2326         SwStyleNameMapper::FillProgName(m_pNumRule->GetName(), aString, SwGetPoolIdFromName::NumRule );
2327         return aString.toString();
2328     }
2329     // consider chapter numbering <SwXNumberingRules>
2330     if ( m_pDocShell )
2331     {
2332         ProgName aString;
2333         SwStyleNameMapper::FillProgName( m_pDocShell->GetDoc()->GetOutlineNumRule()->GetName(),
2334                                          aString, SwGetPoolIdFromName::NumRule );
2335         return aString.toString();
2336     }
2337     return m_sCreatedNumRuleName.toString();
2338 }
2339 
setName(const OUString &)2340 void SwXNumberingRules::setName(const OUString& /*rName*/)
2341 {
2342     throw RuntimeException(u"readonly"_ustr);
2343 }
2344 
Notify(const SfxHint & rHint)2345 void SwXNumberingRules::Impl::Notify(const SfxHint& rHint)
2346 {
2347     if(rHint.GetId() == SfxHintId::Dying)
2348     {
2349         if(m_rParent.m_bOwnNumRuleCreated)
2350             delete m_rParent.m_pNumRule;
2351         m_rParent.m_pNumRule = nullptr;
2352         m_rParent.m_pDoc = nullptr;
2353     }
2354 }
2355 
getImplementationName()2356 OUString SwXChapterNumbering::getImplementationName()
2357 {
2358     return u"SwXChapterNumbering"_ustr;
2359 }
2360 
supportsService(const OUString & rServiceName)2361 sal_Bool SwXChapterNumbering::supportsService(const OUString& rServiceName)
2362 {
2363     return cppu::supportsService(this, rServiceName);
2364 }
2365 
getSupportedServiceNames()2366 Sequence< OUString > SwXChapterNumbering::getSupportedServiceNames()
2367 {
2368     return { u"com.sun.star.text.ChapterNumbering"_ustr, u"com.sun.star.text.NumberingRules"_ustr };
2369 }
2370 
SwXChapterNumbering(SwDocShell & rDocSh)2371 SwXChapterNumbering::SwXChapterNumbering(SwDocShell& rDocSh) :
2372     SwXNumberingRules(rDocSh)
2373 {
2374 }
2375 
~SwXChapterNumbering()2376 SwXChapterNumbering::~SwXChapterNumbering()
2377 {
2378 }
2379 
2380 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
2381