1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <sal/config.h>
22 #include <sal/log.hxx>
23 #include <osl/diagnose.h>
27 #include <hintids.hxx>
28 #include <rtl/ustrbuf.hxx>
29 #include <svl/itemiter.hxx>
30 #include <svl/eitem.hxx>
31 #include <unotools/syslocale.hxx>
32 #include <editeng/boxitem.hxx>
33 #include <editeng/numitem.hxx>
34 #include <editeng/lrspitem.hxx>
35 #include <drawdoc.hxx>
41 #include <charfmt.hxx>
42 #include <tblafmt.hxx>
43 #include <poolfmt.hxx>
44 #include <pagedesc.hxx>
45 #include <docstyle.hxx>
49 #include <IDocumentUndoRedo.hxx>
50 #include <IDocumentStylePoolAccess.hxx>
51 #include <IDocumentSettingAccess.hxx>
52 #include <IDocumentDrawModelAccess.hxx>
53 #include <IDocumentState.hxx>
55 #include <strings.hrc>
57 #include <SwStyleNameMapper.hxx>
58 #include <svl/cjkoptions.hxx>
59 #include <svl/ctloptions.hxx>
60 #include <unotools/intlwrapper.hxx>
61 #include <numrule.hxx>
62 #include <svx/xdef.hxx>
63 #include <SwRewriter.hxx>
65 #include <frameformats.hxx>
66 #include <svx/xfillit0.hxx>
67 #include <svx/xflftrit.hxx>
68 #include <svx/drawitem.hxx>
70 using namespace com::sun::star
;
72 // At the names' publication, this character is removed again and the
73 // family is newly generated.
75 // In addition now there is the Bit bPhysical. In case this Bit is
76 // TRUE, the Pool-Formatnames are not being submitted.
80 class SwImplShellAction
83 std::unique_ptr
<CurrShell
> m_pCurrSh
;
85 explicit SwImplShellAction( SwDoc
& rDoc
);
86 ~SwImplShellAction() COVERITY_NOEXCEPT_FALSE
;
87 SwImplShellAction(const SwImplShellAction
&) = delete;
88 SwImplShellAction
& operator=(const SwImplShellAction
&) = delete;
93 SwImplShellAction::SwImplShellAction( SwDoc
& rDoc
)
95 if( rDoc
.GetDocShell() )
96 m_pSh
= rDoc
.GetDocShell()->GetWrtShell();
102 m_pCurrSh
.reset( new CurrShell( m_pSh
) );
103 m_pSh
->StartAllAction();
107 SwImplShellAction::~SwImplShellAction() COVERITY_NOEXCEPT_FALSE
111 m_pSh
->EndAllAction();
116 // find/create SwCharFormate
117 // possibly fill Style
118 static SwCharFormat
* lcl_FindCharFormat( SwDoc
& rDoc
,
119 const OUString
& rName
,
120 SwDocStyleSheet
* pStyle
= nullptr,
121 bool bCreate
= true )
123 SwCharFormat
* pFormat
= nullptr;
124 if (!rName
.isEmpty())
126 pFormat
= rDoc
.FindCharFormatByName( rName
);
127 if( !pFormat
&& rName
== SwResId(STR_POOLCHR_STANDARD
))
129 // Standard-Character template
130 pFormat
= rDoc
.GetDfltCharFormat();
133 if( !pFormat
&& bCreate
)
135 const sal_uInt16 nId
= SwStyleNameMapper::GetPoolIdFromUIName(rName
, SwGetPoolIdFromName::ChrFmt
);
137 pFormat
= rDoc
.getIDocumentStylePoolAccess().GetCharFormatFromPool(nId
);
144 pStyle
->SetPhysical(true);
145 SwFormat
* p
= pFormat
->DerivedFrom();
146 if( p
&& !p
->IsDefault() )
147 pStyle
->PresetParent( p
->GetName() );
149 pStyle
->PresetParent( OUString() );
152 pStyle
->SetPhysical(false);
157 // find/create ParaFormats
159 static SwTextFormatColl
* lcl_FindParaFormat( SwDoc
& rDoc
,
160 const OUString
& rName
,
161 SwDocStyleSheet
* pStyle
= nullptr,
162 bool bCreate
= true )
164 SwTextFormatColl
* pColl
= nullptr;
166 if (!rName
.isEmpty())
168 pColl
= rDoc
.FindTextFormatCollByName( rName
);
169 if( !pColl
&& bCreate
)
171 const sal_uInt16 nId
= SwStyleNameMapper::GetPoolIdFromUIName(rName
, SwGetPoolIdFromName::TxtColl
);
173 pColl
= rDoc
.getIDocumentStylePoolAccess().GetTextCollFromPool(nId
);
181 pStyle
->SetPhysical(true);
182 if( pColl
->DerivedFrom() && !pColl
->DerivedFrom()->IsDefault() )
183 pStyle
->PresetParent( pColl
->DerivedFrom()->GetName() );
185 pStyle
->PresetParent( OUString() );
187 SwTextFormatColl
& rNext
= pColl
->GetNextTextFormatColl();
188 pStyle
->PresetFollow(rNext
.GetName());
191 pStyle
->SetPhysical(false);
197 static SwFrameFormat
* lcl_FindFrameFormat( SwDoc
& rDoc
,
198 const OUString
& rName
,
199 SwDocStyleSheet
* pStyle
= nullptr,
200 bool bCreate
= true )
202 SwFrameFormat
* pFormat
= nullptr;
203 if( !rName
.isEmpty() )
205 pFormat
= rDoc
.FindFrameFormatByName( rName
);
206 if( !pFormat
&& bCreate
)
208 const sal_uInt16 nId
= SwStyleNameMapper::GetPoolIdFromUIName(rName
, SwGetPoolIdFromName::FrmFmt
);
210 pFormat
= rDoc
.getIDocumentStylePoolAccess().GetFrameFormatFromPool(nId
);
218 pStyle
->SetPhysical(true);
219 if( pFormat
->DerivedFrom() && !pFormat
->DerivedFrom()->IsDefault() )
220 pStyle
->PresetParent( pFormat
->DerivedFrom()->GetName() );
222 pStyle
->PresetParent( OUString() );
225 pStyle
->SetPhysical(false);
231 static const SwPageDesc
* lcl_FindPageDesc( SwDoc
& rDoc
,
232 const OUString
& rName
,
233 SwDocStyleSheet
* pStyle
= nullptr,
234 bool bCreate
= true )
236 const SwPageDesc
* pDesc
= nullptr;
238 if (!rName
.isEmpty())
240 pDesc
= rDoc
.FindPageDesc(rName
);
241 if( !pDesc
&& bCreate
)
243 sal_uInt16 nId
= SwStyleNameMapper::GetPoolIdFromUIName(rName
, SwGetPoolIdFromName::PageDesc
);
245 pDesc
= rDoc
.getIDocumentStylePoolAccess().GetPageDescFromPool(nId
);
253 pStyle
->SetPhysical(true);
254 if(pDesc
->GetFollow())
255 pStyle
->PresetFollow(pDesc
->GetFollow()->GetName());
257 pStyle
->PresetParent( OUString() );
260 pStyle
->SetPhysical(false);
265 static const SwNumRule
* lcl_FindNumRule( SwDoc
& rDoc
,
266 const OUString
& rName
,
267 SwDocStyleSheet
* pStyle
= nullptr,
268 bool bCreate
= true )
270 const SwNumRule
* pRule
= nullptr;
272 if (!rName
.isEmpty())
274 pRule
= rDoc
.FindNumRulePtr( rName
);
275 if( !pRule
&& bCreate
)
277 sal_uInt16 nId
= SwStyleNameMapper::GetPoolIdFromUIName(rName
, SwGetPoolIdFromName::NumRule
);
279 pRule
= rDoc
.getIDocumentStylePoolAccess().GetNumRuleFromPool(nId
);
287 pStyle
->SetPhysical(true);
288 pStyle
->PresetParent( OUString() );
291 pStyle
->SetPhysical(false);
296 static SwTableAutoFormat
* lcl_FindTableStyle(SwDoc
& rDoc
, const OUString
& rName
, SwDocStyleSheet
*pStyle
= nullptr, bool bCreate
= true)
298 SwTableAutoFormat
* pFormat
= nullptr;
300 if (!rName
.isEmpty())
302 pFormat
= rDoc
.GetTableStyles().FindAutoFormat(rName
);
303 if (!pFormat
&& bCreate
)
305 SwTableAutoFormat
aNew(rName
);
306 rDoc
.GetTableStyles().AddAutoFormat(aNew
);
314 pStyle
->SetPhysical(true);
315 pStyle
->PresetParent(OUString());
318 pStyle
->SetPhysical(false);
323 static const SwBoxAutoFormat
* lcl_FindCellStyle(SwDoc
& rDoc
, std::u16string_view rName
, SwDocStyleSheet
*pStyle
)
325 const SwBoxAutoFormat
* pFormat
= rDoc
.GetCellStyles().GetBoxFormat(rName
);
329 const auto& aTableTemplateMap
= SwTableAutoFormat::GetTableTemplateMap();
330 SwTableAutoFormatTable
& rTableStyles
= rDoc
.GetTableStyles();
331 for (size_t i
=0; i
< rTableStyles
.size() && !pFormat
; ++i
)
333 const SwTableAutoFormat
& rTableStyle
= rTableStyles
[i
];
334 for (size_t nBoxFormat
=0; nBoxFormat
< aTableTemplateMap
.size() && !pFormat
; ++nBoxFormat
)
336 const sal_uInt32 nBoxIndex
= aTableTemplateMap
[nBoxFormat
];
337 const SwBoxAutoFormat
& rBoxFormat
= rTableStyle
.GetBoxFormat(nBoxIndex
);
338 OUString sBoxFormatName
;
339 SwStyleNameMapper::FillProgName(rTableStyle
.GetName(), sBoxFormatName
, SwGetPoolIdFromName::TabStyle
);
340 sBoxFormatName
+= rTableStyle
.GetTableTemplateCellSubName(rBoxFormat
);
341 if (rName
== sBoxFormatName
)
342 pFormat
= &rBoxFormat
;
351 pStyle
->SetPhysical(true);
352 pStyle
->PresetParent(OUString());
355 pStyle
->SetPhysical(false);
360 sal_uInt32
SwStyleSheetIterator::SwPoolFormatList::FindName(SfxStyleFamily eFam
,
361 const OUString
& rName
)
365 UniqueHash::const_iterator it
= maUnique
.find(std::pair
<SfxStyleFamily
,OUString
>{eFam
, rName
});
366 if (it
!= maUnique
.end())
368 sal_uInt32 nIdx
= it
->second
;
369 assert (nIdx
< maImpl
.size());
370 assert (maImpl
.size() == maUnique
.size());
374 return SAL_MAX_UINT32
;
377 void SwStyleSheetIterator::SwPoolFormatList::rehash()
380 for (size_t i
= 0; i
< maImpl
.size(); i
++)
381 maUnique
[maImpl
[i
]] = i
;
382 assert (maImpl
.size() == maUnique
.size());
385 void SwStyleSheetIterator::SwPoolFormatList::RemoveName(SfxStyleFamily eFam
,
386 const OUString
& rName
)
388 sal_uInt32 nTmpPos
= FindName( eFam
, rName
);
389 if (nTmpPos
!= SAL_MAX_UINT32
)
390 maImpl
.erase(maImpl
.begin() + nTmpPos
);
392 // assumption: this seldom occurs, the iterator is built, then emptied.
394 assert (maImpl
.size() == maUnique
.size());
397 // Add Strings to the list of templates
398 void SwStyleSheetIterator::SwPoolFormatList::Append( SfxStyleFamily eFam
, const OUString
& rStr
)
400 UniqueHash::const_iterator it
= maUnique
.find(std::pair
<SfxStyleFamily
,OUString
>{eFam
, rStr
});
401 if (it
!= maUnique
.end())
404 maUnique
.emplace(std::pair
<SfxStyleFamily
,OUString
>{eFam
, rStr
}, static_cast<sal_uInt32
>(maImpl
.size()));
405 maImpl
.push_back(std::pair
<SfxStyleFamily
,OUString
>{eFam
, rStr
});
408 // UI-sided implementation of StyleSheets
409 // uses the Core-Engine
410 SwDocStyleSheet::SwDocStyleSheet( SwDoc
& rDocument
,
411 SwDocStyleSheetPool
& rPool
) :
413 SfxStyleSheetBase( OUString(), &rPool
, SfxStyleFamily::Char
, SfxStyleSearchBits::Auto
),
414 m_pCharFormat(nullptr),
416 m_pFrameFormat(nullptr),
419 m_pTableFormat(nullptr),
420 m_pBoxFormat(nullptr),
425 RES_CHRATR_BEGIN
, RES_CHRATR_END
- 1,
426 RES_PARATR_BEGIN
, RES_FRMATR_END
- 1,
427 RES_UNKNOWNATR_BEGIN
, RES_UNKNOWNATR_END
- 1,
428 // FillAttribute support:
429 XATTR_FILL_FIRST
, XATTR_FILL_LAST
,
430 SID_ATTR_BORDER_INNER
, SID_ATTR_BORDER_INNER
,
431 SID_ATTR_PAGE
, SID_ATTR_PAGE_EXT1
,
432 SID_ATTR_PAGE_HEADERSET
, SID_ATTR_PAGE_FOOTERSET
,
433 SID_ATTR_PARA_MODEL
, SID_ATTR_PARA_MODEL
,
434 // Items to hand over XPropertyList things like XColorList,
435 // XHatchList, XGradientList, and XBitmapList to the Area TabPage:
436 SID_COLOR_TABLE
, SID_PATTERN_LIST
,
437 SID_SWREGISTER_COLLECTION
, SID_SWREGISTER_COLLECTION
,
438 SID_ATTR_PARA_PAGENUM
, SID_ATTR_PARA_PAGENUM
,
439 SID_SWREGISTER_MODE
, SID_SWREGISTER_MODE
,
440 SID_ATTR_BRUSH_CHAR
, SID_ATTR_BRUSH_CHAR
,
441 SID_ATTR_NUMBERING_RULE
, SID_ATTR_NUMBERING_RULE
,
442 SID_ATTR_CHAR_GRABBAG
, SID_ATTR_CHAR_GRABBAG
,
443 SID_ATTR_AUTO_STYLE_UPDATE
, SID_ATTR_AUTO_STYLE_UPDATE
,
444 FN_PARAM_FTN_INFO
, FN_PARAM_FTN_INFO
,
445 FN_KEEP_ASPECT_RATIO
, FN_KEEP_ASPECT_RATIO
,
446 FN_COND_COLL
, FN_COND_COLL
>),
452 SwDocStyleSheet::SwDocStyleSheet( const SwDocStyleSheet
& ) = default;
454 SwDocStyleSheet::~SwDocStyleSheet() = default;
456 void SwDocStyleSheet::Reset()
464 void SwDocStyleSheet::SetGrabBagItem(const uno::Any
& rVal
)
468 FillStyleSheet(FillPhysical
);
470 SwFormat
* pFormat
= nullptr;
473 case SfxStyleFamily::Char
:
474 pFormat
= m_rDoc
.FindCharFormatByName(aName
);
477 pFormat
->SetGrabBagItem(rVal
);
481 case SfxStyleFamily::Para
:
482 pFormat
= m_rDoc
.FindTextFormatCollByName(aName
);
485 pFormat
->SetGrabBagItem(rVal
);
489 case SfxStyleFamily::Pseudo
:
491 SwNumRule
* pRule
= m_rDoc
.FindNumRulePtr(aName
);
494 pRule
->SetGrabBagItem(rVal
);
505 dynamic_cast<SwDocStyleSheetPool
&>(*m_pPool
).InvalidateIterator();
506 m_pPool
->Broadcast(SfxStyleSheetHint(SfxHintId::StyleSheetModified
, *this));
507 if (SwEditShell
* pSh
= m_rDoc
.GetEditShell())
512 void SwDocStyleSheet::GetGrabBagItem(uno::Any
& rVal
) const
514 SwFormat
* pFormat
= nullptr;
517 case SfxStyleFamily::Char
:
518 pFormat
= m_rDoc
.FindCharFormatByName(aName
);
520 pFormat
->GetGrabBagItem(rVal
);
522 case SfxStyleFamily::Para
:
523 pFormat
= m_rDoc
.FindTextFormatCollByName(aName
);
525 pFormat
->GetGrabBagItem(rVal
);
527 case SfxStyleFamily::Pseudo
:
529 SwNumRule
* pRule
= m_rDoc
.FindNumRulePtr(aName
);
531 pRule
->GetGrabBagItem(rVal
);
539 void SwDocStyleSheet::SetHidden( bool bValue
)
543 FillStyleSheet( FillPhysical
);
545 SwFormat
* pFormat
= nullptr;
548 case SfxStyleFamily::Char
:
549 pFormat
= m_rDoc
.FindCharFormatByName( aName
);
552 pFormat
->SetHidden( bValue
);
557 case SfxStyleFamily::Para
:
558 pFormat
= m_rDoc
.FindTextFormatCollByName( aName
);
561 pFormat
->SetHidden( bValue
);
566 case SfxStyleFamily::Frame
:
567 pFormat
= m_rDoc
.FindFrameFormatByName( aName
);
570 pFormat
->SetHidden( bValue
);
575 case SfxStyleFamily::Page
:
577 SwPageDesc
* pPgDesc
= m_rDoc
.FindPageDesc(aName
);
580 pPgDesc
->SetHidden( bValue
);
586 case SfxStyleFamily::Pseudo
:
588 SwNumRule
* pRule
= m_rDoc
.FindNumRulePtr( aName
);
591 pRule
->SetHidden( bValue
);
597 case SfxStyleFamily::Table
:
599 SwTableAutoFormat
* pTableAutoFormat
= m_rDoc
.GetTableStyles().FindAutoFormat( aName
);
600 if ( pTableAutoFormat
)
602 pTableAutoFormat
->SetHidden( bValue
);
614 // calling pPool->First() here would be quite slow...
615 dynamic_cast<SwDocStyleSheetPool
&>(*m_pPool
).InvalidateIterator(); // internal list has to be updated
616 m_pPool
->Broadcast( SfxStyleSheetHint( SfxHintId::StyleSheetModified
, *this ) );
617 if (SwEditShell
* pSh
= m_rDoc
.GetEditShell())
622 bool SwDocStyleSheet::IsHidden( ) const
626 SwFormat
* pFormat
= nullptr;
629 case SfxStyleFamily::Char
:
630 pFormat
= m_rDoc
.FindCharFormatByName( aName
);
631 bRet
= pFormat
&& pFormat
->IsHidden( );
634 case SfxStyleFamily::Para
:
635 pFormat
= m_rDoc
.FindTextFormatCollByName( aName
);
636 bRet
= pFormat
&& pFormat
->IsHidden( );
639 case SfxStyleFamily::Frame
:
640 pFormat
= m_rDoc
.FindFrameFormatByName( aName
);
641 bRet
= pFormat
&& pFormat
->IsHidden( );
644 case SfxStyleFamily::Page
:
646 SwPageDesc
* pPgDesc
= m_rDoc
.FindPageDesc(aName
);
647 bRet
= pPgDesc
&& pPgDesc
->IsHidden( );
650 case SfxStyleFamily::Pseudo
:
652 SwNumRule
* pRule
= m_rDoc
.FindNumRulePtr( aName
);
653 bRet
= pRule
&& pRule
->IsHidden( );
656 case SfxStyleFamily::Table
:
658 SwTableAutoFormat
* pTableAutoFormat
= m_rDoc
.GetTableStyles().FindAutoFormat( aName
);
659 bRet
= pTableAutoFormat
&& pTableAutoFormat
->IsHidden( );
669 const OUString
& SwDocStyleSheet::GetParent() const
673 // check if it's already in document
674 SwFormat
* pFormat
= nullptr;
675 SwGetPoolIdFromName eGetType
;
678 case SfxStyleFamily::Char
:
679 pFormat
= m_rDoc
.FindCharFormatByName( aName
);
680 eGetType
= SwGetPoolIdFromName::ChrFmt
;
683 case SfxStyleFamily::Para
:
684 pFormat
= m_rDoc
.FindTextFormatCollByName( aName
);
685 eGetType
= SwGetPoolIdFromName::TxtColl
;
688 case SfxStyleFamily::Frame
:
689 pFormat
= m_rDoc
.FindFrameFormatByName( aName
);
690 eGetType
= SwGetPoolIdFromName::FrmFmt
;
693 case SfxStyleFamily::Page
:
694 case SfxStyleFamily::Pseudo
:
697 static const OUString sEmpty
;
698 return sEmpty
; // there's no parent
703 if( !pFormat
) // not yet there, so default Parent
705 sal_uInt16 i
= SwStyleNameMapper::GetPoolIdFromUIName( aName
, eGetType
);
706 i
= ::GetPoolParent( i
);
707 if( i
&& USHRT_MAX
!= i
)
708 SwStyleNameMapper::FillUIName( i
, sTmp
);
712 SwFormat
* p
= pFormat
->DerivedFrom();
713 if( p
&& !p
->IsDefault() )
716 SwDocStyleSheet
* pThis
= const_cast<SwDocStyleSheet
*>(this);
717 pThis
->aParent
= sTmp
;
723 const OUString
& SwDocStyleSheet::GetFollow() const
727 SwDocStyleSheet
* pThis
= const_cast<SwDocStyleSheet
*>(this);
728 pThis
->FillStyleSheet( FillAllInfo
);
733 void SwDocStyleSheet::SetLink(const OUString
& rStr
)
735 SwImplShellAction
aTmpSh(m_rDoc
);
738 case SfxStyleFamily::Para
:
742 SwCharFormat
* pLink
= lcl_FindCharFormat(m_rDoc
, rStr
);
745 m_pColl
->SetLinkedCharFormat(pLink
);
750 case SfxStyleFamily::Char
:
754 SwTextFormatColl
* pLink
= lcl_FindParaFormat(m_rDoc
, rStr
);
757 m_pCharFormat
->SetLinkedParaFormat(pLink
);
767 const OUString
& SwDocStyleSheet::GetLink() const
771 SwDocStyleSheet
* pThis
= const_cast<SwDocStyleSheet
*>(this);
772 pThis
->FillStyleSheet(FillAllInfo
);
778 // What Linkage is possible
779 bool SwDocStyleSheet::HasFollowSupport() const
783 case SfxStyleFamily::Para
:
784 case SfxStyleFamily::Page
: return true;
785 case SfxStyleFamily::Frame
:
786 case SfxStyleFamily::Char
:
787 case SfxStyleFamily::Pseudo
: return false;
789 OSL_ENSURE(false, "unknown style family");
795 bool SwDocStyleSheet::HasParentSupport() const
800 case SfxStyleFamily::Char
:
801 case SfxStyleFamily::Para
:
802 case SfxStyleFamily::Frame
: bRet
= true;
804 default:; //prevent warning
809 bool SwDocStyleSheet::HasClearParentSupport() const
814 case SfxStyleFamily::Para
:
815 case SfxStyleFamily::Char
:
816 case SfxStyleFamily::Frame
: bRet
= true;
818 default:; //prevent warning
823 // determine textual description
824 OUString
SwDocStyleSheet::GetDescription(MapUnit eUnit
)
826 IntlWrapper
aIntlWrapper(SvtSysLocale().GetUILanguageTag());
828 static const OUStringLiteral
sPlus(u
" + ");
829 if ( SfxStyleFamily::Page
== nFamily
)
834 SfxItemIter
aIter( *pSet
);
835 OUStringBuffer aDesc
;
837 for (const SfxPoolItem
* pItem
= aIter
.GetCurItem(); pItem
; pItem
= aIter
.NextItem())
839 if(!IsInvalidItem(pItem
))
841 switch ( pItem
->Which() )
844 case SID_ATTR_PAGE_SIZE
:
845 case SID_ATTR_PAGE_MAXSIZE
:
846 case SID_ATTR_PAGE_PAPERBIN
:
847 case SID_ATTR_BORDER_INNER
:
851 OUString aItemPresentation
;
852 if ( !IsInvalidItem( pItem
) &&
853 m_pPool
->GetPool().GetPresentation(
854 *pItem
, eUnit
, aItemPresentation
, aIntlWrapper
) )
856 if ( !aDesc
.isEmpty() && !aItemPresentation
.isEmpty() )
858 aDesc
.append(aItemPresentation
);
864 return aDesc
.makeStringAndClear();
867 if ( SfxStyleFamily::Frame
== nFamily
|| SfxStyleFamily::Para
== nFamily
|| SfxStyleFamily::Char
== nFamily
)
872 SfxItemIter
aIter( *pSet
);
873 OUStringBuffer aDesc
;
877 bool bHasWesternFontPrefix
= false;
878 bool bHasCJKFontPrefix
= false;
879 bool bHasCTLFontPrefix
= false;
880 SvtCTLOptions aCTLOptions
;
882 // Get currently used FillStyle and remember, also need the XFillFloatTransparenceItem
883 // to decide if gradient transparence is used
884 const drawing::FillStyle
eFillStyle(pSet
->Get(XATTR_FILLSTYLE
).GetValue());
885 const bool bUseFloatTransparence(pSet
->Get(XATTR_FILLFLOATTRANSPARENCE
).IsEnabled());
887 for (const SfxPoolItem
* pItem
= aIter
.GetCurItem(); pItem
; pItem
= aIter
.NextItem())
889 if(!IsInvalidItem(pItem
))
891 switch ( pItem
->Which() )
893 case SID_ATTR_AUTO_STYLE_UPDATE
:
898 OUString aItemPresentation
;
899 if ( !IsInvalidItem( pItem
) &&
900 m_pPool
->GetPool().GetPresentation(
901 *pItem
, eUnit
, aItemPresentation
, aIntlWrapper
) )
903 bool bIsDefault
= false;
904 switch ( pItem
->Which() )
906 case XATTR_FILLCOLOR
:
908 // only use active FillStyle information
909 bIsDefault
= (drawing::FillStyle_SOLID
== eFillStyle
);
912 case XATTR_FILLGRADIENT
:
914 // only use active FillStyle information
915 bIsDefault
= (drawing::FillStyle_GRADIENT
== eFillStyle
);
918 case XATTR_FILLHATCH
:
920 // only use active FillStyle information
921 bIsDefault
= (drawing::FillStyle_HATCH
== eFillStyle
);
924 case XATTR_FILLBITMAP
:
926 // only use active FillStyle information
927 bIsDefault
= (drawing::FillStyle_BITMAP
== eFillStyle
);
930 case XATTR_FILLTRANSPARENCE
:
932 // only active when not FloatTransparence
933 bIsDefault
= !bUseFloatTransparence
;
936 case XATTR_FILLFLOATTRANSPARENCE
:
938 // only active when FloatTransparence
939 bIsDefault
= bUseFloatTransparence
;
943 case SID_ATTR_PARA_PAGENUM
:
944 sPageNum
= aItemPresentation
;
946 case SID_ATTR_PARA_MODEL
:
947 sModel
= aItemPresentation
;
950 sBreak
= aItemPresentation
;
952 case RES_CHRATR_CJK_FONT
:
953 case RES_CHRATR_CJK_FONTSIZE
:
954 case RES_CHRATR_CJK_LANGUAGE
:
955 case RES_CHRATR_CJK_POSTURE
:
956 case RES_CHRATR_CJK_WEIGHT
:
957 if(SvtCJKOptions::IsCJKFontEnabled())
959 if(!bHasCJKFontPrefix
)
961 aItemPresentation
= SwResId(STR_CJK_FONT
) + aItemPresentation
;
962 bHasCJKFontPrefix
= true;
965 case RES_CHRATR_CTL_FONT
:
966 case RES_CHRATR_CTL_FONTSIZE
:
967 case RES_CHRATR_CTL_LANGUAGE
:
968 case RES_CHRATR_CTL_POSTURE
:
969 case RES_CHRATR_CTL_WEIGHT
:
970 if(SvtCTLOptions::IsCTLFontEnabled())
972 if(!bHasCTLFontPrefix
)
974 aItemPresentation
= SwResId(STR_CTL_FONT
) + aItemPresentation
;
975 bHasCTLFontPrefix
= true;
978 case RES_CHRATR_FONT
:
979 case RES_CHRATR_FONTSIZE
:
980 case RES_CHRATR_LANGUAGE
:
981 case RES_CHRATR_POSTURE
:
982 case RES_CHRATR_WEIGHT
:
983 if(!bHasWesternFontPrefix
)
985 aItemPresentation
= SwResId(STR_WESTERN_FONT
) + aItemPresentation
;
986 bHasWesternFontPrefix
= true;
994 if ( !aDesc
.isEmpty() && !aItemPresentation
.isEmpty() )
996 aDesc
.append(aItemPresentation
);
1003 // Special treatment for Break, Page template and Site offset
1004 if (!sModel
.isEmpty())
1006 if (!aDesc
.isEmpty())
1007 aDesc
.append(sPlus
);
1008 aDesc
.append(SwResId(STR_PAGEBREAK
) + sPlus
+ sModel
);
1009 if (sPageNum
!= "0")
1011 aDesc
.append(sPlus
+ SwResId(STR_PAGEOFFSET
) + sPageNum
);
1014 else if (!sBreak
.isEmpty()) // Break can be valid only when NO Model
1016 if (!aDesc
.isEmpty())
1017 aDesc
.append(sPlus
);
1018 aDesc
.append(sBreak
);
1020 return aDesc
.makeStringAndClear();
1023 if( SfxStyleFamily::Pseudo
== nFamily
)
1028 return SfxStyleSheetBase::GetDescription(eUnit
);
1032 bool SwDocStyleSheet::SetName(const OUString
& rStr
, bool bReindexNow
)
1034 if( rStr
.isEmpty() )
1039 if( !SfxStyleSheetBase::SetName(rStr
, bReindexNow
))
1042 else if(!m_bPhysical
)
1043 FillStyleSheet( FillPhysical
);
1048 case SfxStyleFamily::Char
:
1050 OSL_ENSURE(m_pCharFormat
, "SwCharFormat missing!");
1051 if( m_pCharFormat
&& m_pCharFormat
->GetName() != rStr
)
1053 if (!m_pCharFormat
->GetName().isEmpty())
1054 m_rDoc
.RenameFormat(*m_pCharFormat
, rStr
);
1056 m_pCharFormat
->SetFormatName(rStr
);
1062 case SfxStyleFamily::Para
:
1064 OSL_ENSURE(m_pColl
, "Collection missing!");
1065 if( m_pColl
&& m_pColl
->GetName() != rStr
)
1067 if (!m_pColl
->GetName().isEmpty())
1068 m_rDoc
.RenameFormat(*m_pColl
, rStr
);
1070 m_pColl
->SetFormatName(rStr
);
1076 case SfxStyleFamily::Frame
:
1078 OSL_ENSURE(m_pFrameFormat
, "FrameFormat missing!");
1079 if( m_pFrameFormat
&& m_pFrameFormat
->GetName() != rStr
)
1081 if (!m_pFrameFormat
->GetName().isEmpty())
1082 m_rDoc
.RenameFormat(*m_pFrameFormat
, rStr
);
1084 m_pFrameFormat
->SetFormatName( rStr
);
1090 case SfxStyleFamily::Page
:
1091 OSL_ENSURE(m_pDesc
, "PageDesc missing!");
1092 if( m_pDesc
&& m_pDesc
->GetName() != rStr
)
1094 // Set PageDesc - copy with earlier one - probably not
1095 // necessary for setting the name. So here we allow a
1097 SwPageDesc
aPageDesc(*const_cast<SwPageDesc
*>(m_pDesc
));
1098 const OUString
aOldName(aPageDesc
.GetName());
1100 aPageDesc
.SetName( rStr
);
1101 bool const bDoesUndo
= m_rDoc
.GetIDocumentUndoRedo().DoesUndo();
1103 m_rDoc
.GetIDocumentUndoRedo().DoUndo(!aOldName
.isEmpty());
1104 m_rDoc
.ChgPageDesc(aOldName
, aPageDesc
);
1105 m_rDoc
.GetIDocumentUndoRedo().DoUndo(bDoesUndo
);
1107 m_rDoc
.getIDocumentState().SetModified();
1111 case SfxStyleFamily::Pseudo
:
1112 OSL_ENSURE(m_pNumRule
, "NumRule missing!");
1116 OUString aOldName
= m_pNumRule
->GetName();
1118 if (!aOldName
.isEmpty())
1120 if ( aOldName
!= rStr
&&
1121 m_rDoc
.RenameNumRule(aOldName
, rStr
))
1123 m_pNumRule
= m_rDoc
.FindNumRulePtr(rStr
);
1124 m_rDoc
.getIDocumentState().SetModified();
1132 const_cast<SwNumRule
*>(m_pNumRule
)->SetName( rStr
, m_rDoc
.getIDocumentListsAccess() );
1133 m_rDoc
.getIDocumentState().SetModified();
1142 OSL_ENSURE(false, "unknown style family");
1147 m_pPool
->First(nFamily
); // internal list has to be updated
1148 m_pPool
->Broadcast( SfxStyleSheetHint( SfxHintId::StyleSheetModified
, *this ) );
1149 if (SwEditShell
* pSh
= m_rDoc
.GetEditShell())
1155 // hierarchy of deduction
1156 bool SwDocStyleSheet::SetParent( const OUString
& rStr
)
1158 SwFormat
* pFormat
= nullptr, *pParent
= nullptr;
1161 case SfxStyleFamily::Char
:
1162 OSL_ENSURE( m_pCharFormat
, "SwCharFormat missing!" );
1163 if( nullptr != ( pFormat
= m_pCharFormat
) && !rStr
.isEmpty() )
1164 pParent
= lcl_FindCharFormat(m_rDoc
, rStr
);
1167 case SfxStyleFamily::Para
:
1168 OSL_ENSURE( m_pColl
, "Collection missing!");
1169 if( nullptr != ( pFormat
= m_pColl
) && !rStr
.isEmpty() )
1170 pParent
= lcl_FindParaFormat( m_rDoc
, rStr
);
1173 case SfxStyleFamily::Frame
:
1174 OSL_ENSURE(m_pFrameFormat
, "FrameFormat missing!");
1175 if( nullptr != ( pFormat
= m_pFrameFormat
) && !rStr
.isEmpty() )
1176 pParent
= lcl_FindFrameFormat( m_rDoc
, rStr
);
1179 case SfxStyleFamily::Page
:
1180 case SfxStyleFamily::Pseudo
:
1183 OSL_ENSURE(false, "unknown style family");
1187 if( pFormat
&& pFormat
->DerivedFrom() &&
1188 pFormat
->DerivedFrom()->GetName() != rStr
)
1191 SwImplShellAction
aTmp( m_rDoc
);
1192 bRet
= pFormat
->SetDerivedFrom( pParent
);
1198 m_pPool
->Broadcast( SfxStyleSheetHint( SfxHintId::StyleSheetModified
,
1207 bool SwDocStyleSheet::SetFollow( const OUString
& rStr
)
1209 if( !rStr
.isEmpty() && !SfxStyleSheetBase::SetFollow( rStr
))
1212 SwImplShellAction
aTmpSh( m_rDoc
);
1215 case SfxStyleFamily::Para
:
1217 OSL_ENSURE(m_pColl
, "Collection missing!");
1220 SwTextFormatColl
* pFollow
= m_pColl
;
1221 if( !rStr
.isEmpty() && nullptr == (pFollow
= lcl_FindParaFormat(m_rDoc
, rStr
) ))
1224 m_pColl
->SetNextTextFormatColl(*pFollow
);
1228 case SfxStyleFamily::Page
:
1230 OSL_ENSURE(m_pDesc
, "PageDesc missing!");
1233 const SwPageDesc
* pFollowDesc
= !rStr
.isEmpty()
1234 ? lcl_FindPageDesc(m_rDoc
, rStr
)
1237 if (pFollowDesc
!= m_pDesc
->GetFollow() && m_rDoc
.FindPageDesc(m_pDesc
->GetName(), &nId
))
1239 SwPageDesc
aDesc( *m_pDesc
);
1240 aDesc
.SetFollow( pFollowDesc
);
1241 m_rDoc
.ChgPageDesc( nId
, aDesc
);
1242 m_pDesc
= &m_rDoc
.GetPageDesc( nId
);
1247 case SfxStyleFamily::Char
:
1248 case SfxStyleFamily::Frame
:
1249 case SfxStyleFamily::Pseudo
:
1252 OSL_ENSURE(false, "unknown style family");
1259 void lcl_SwFormatToFlatItemSet(SwFormat
const *const pFormat
, std::optional
<SfxItemSet
>& pRet
)
1261 // note: we don't add the odd items that GetItemSet() would add
1262 // because they don't seem relevant for preview
1263 std::vector
<SfxItemSet
const*> sets
;
1264 sets
.push_back(&pFormat
->GetAttrSet());
1265 while (SfxItemSet
const*const pParent
= sets
.back()->GetParent())
1267 sets
.push_back(pParent
);
1269 // start by copying top-level parent set
1270 pRet
.emplace(*sets
.back());
1272 for (auto iter
= sets
.rbegin(); iter
!= sets
.rend(); ++iter
)
1273 { // in reverse so child overrides parent
1278 std::optional
<SfxItemSet
> SwDocStyleSheet::GetItemSetForPreview()
1280 if (SfxStyleFamily::Page
== nFamily
|| SfxStyleFamily::Pseudo
== nFamily
|| SfxStyleFamily::Table
== nFamily
)
1282 SAL_WARN("sw.ui", "GetItemSetForPreview not implemented for page or number or table style");
1283 return std::optional
<SfxItemSet
>();
1287 // because not only this style, but also any number of its parents
1288 // (or follow style) may not actually exist in the document at this
1289 // time, return one "flattened" item set that contains all items from
1291 std::optional
<SfxItemSet
> pRet
;
1293 bool bModifiedEnabled
= m_rDoc
.getIDocumentState().IsEnableSetModified();
1294 m_rDoc
.getIDocumentState().SetEnableSetModified(false);
1296 FillStyleSheet(FillPreview
, &pRet
);
1298 m_rDoc
.getIDocumentState().SetEnableSetModified(bModifiedEnabled
);
1305 std::optional
<SfxItemSet
> pRet
;
1308 case SfxStyleFamily::Char
:
1309 lcl_SwFormatToFlatItemSet(m_pCharFormat
, pRet
);
1311 case SfxStyleFamily::Para
:
1312 lcl_SwFormatToFlatItemSet(m_pColl
, pRet
);
1314 case SfxStyleFamily::Frame
:
1315 lcl_SwFormatToFlatItemSet(m_pFrameFormat
, pRet
);
1324 // extract ItemSet to Name and Family, Mask
1326 SfxItemSet
& SwDocStyleSheet::GetItemSet()
1329 FillStyleSheet( FillPhysical
);
1333 case SfxStyleFamily::Char
:
1334 case SfxStyleFamily::Para
:
1335 case SfxStyleFamily::Frame
:
1337 SvxBoxInfoItem
aBoxInfo( SID_ATTR_BORDER_INNER
);
1338 aBoxInfo
.SetTable( false );
1339 aBoxInfo
.SetDist( true ); // always show gap field
1340 aBoxInfo
.SetMinDist( true );// set minimum size in tables and paragraphs
1341 aBoxInfo
.SetDefDist( MIN_BORDER_DIST
);// always set Default-Gap
1342 // Single lines can only have DontCare-Status in tables
1343 aBoxInfo
.SetValid( SvxBoxInfoItemValidFlags::DISABLE
);
1345 if( nFamily
== SfxStyleFamily::Char
)
1347 SAL_WARN_IF(!m_pCharFormat
, "sw.ui", "Where's SwCharFormat");
1348 m_aCoreSet
.Put(m_pCharFormat
->GetAttrSet());
1349 m_aCoreSet
.Put( aBoxInfo
);
1351 if(m_pCharFormat
->DerivedFrom())
1352 m_aCoreSet
.SetParent(&m_pCharFormat
->DerivedFrom()->GetAttrSet());
1354 else if ( nFamily
== SfxStyleFamily::Para
)
1356 OSL_ENSURE(m_pColl
, "Where's Collection");
1357 m_aCoreSet
.Put(m_pColl
->GetAttrSet());
1358 m_aCoreSet
.Put( aBoxInfo
);
1359 m_aCoreSet
.Put(SfxBoolItem(SID_ATTR_AUTO_STYLE_UPDATE
, m_pColl
->IsAutoUpdateOnDirectFormat()));
1361 if(m_pColl
->DerivedFrom())
1362 m_aCoreSet
.SetParent(&m_pColl
->DerivedFrom()->GetAttrSet());
1366 OSL_ENSURE(m_pFrameFormat
, "Where's FrameFormat");
1367 m_aCoreSet
.Put(m_pFrameFormat
->GetAttrSet());
1368 m_aCoreSet
.Put( aBoxInfo
);
1369 m_aCoreSet
.Put(SfxBoolItem(SID_ATTR_AUTO_STYLE_UPDATE
, m_pFrameFormat
->IsAutoUpdateOnDirectFormat()));
1371 if(m_pFrameFormat
->DerivedFrom())
1372 m_aCoreSet
.SetParent(&m_pFrameFormat
->DerivedFrom()->GetAttrSet());
1374 // create needed items for XPropertyList entries from the DrawModel so that
1375 // the Area TabPage can access them
1376 const SwDrawModel
* pDrawModel
= m_rDoc
.getIDocumentDrawModelAccess().GetDrawModel();
1378 m_aCoreSet
.Put(SvxColorListItem(pDrawModel
->GetColorList(), SID_COLOR_TABLE
));
1379 m_aCoreSet
.Put(SvxGradientListItem(pDrawModel
->GetGradientList(), SID_GRADIENT_LIST
));
1380 m_aCoreSet
.Put(SvxHatchListItem(pDrawModel
->GetHatchList(), SID_HATCH_LIST
));
1381 m_aCoreSet
.Put(SvxBitmapListItem(pDrawModel
->GetBitmapList(), SID_BITMAP_LIST
));
1382 m_aCoreSet
.Put(SvxPatternListItem(pDrawModel
->GetPatternList(), SID_PATTERN_LIST
));
1387 case SfxStyleFamily::Page
:
1389 // set correct parent to get the drawing::FillStyle_NONE FillStyle as needed
1390 if(!m_aCoreSet
.GetParent())
1392 m_aCoreSet
.SetParent(&m_rDoc
.GetDfltFrameFormat()->GetAttrSet());
1395 OSL_ENSURE(m_pDesc
, "No PageDescriptor");
1396 ::PageDescToItemSet(*const_cast<SwPageDesc
*>(m_pDesc
), m_aCoreSet
);
1400 case SfxStyleFamily::Pseudo
:
1402 OSL_ENSURE(m_pNumRule
, "No NumRule");
1403 SvxNumRule aRule
= m_pNumRule
->MakeSvxNumRule();
1404 m_aCoreSet
.Put(SvxNumBulletItem(std::move(aRule
)));
1409 OSL_ENSURE(false, "unknown style family");
1411 // Member of Baseclass
1417 void SwDocStyleSheet::MergeIndentAttrsOfListStyle( SfxItemSet
& rSet
)
1419 if ( nFamily
!= SfxStyleFamily::Para
)
1424 OSL_ENSURE( m_pColl
, "<SwDocStyleSheet::MergeIndentAttrsOfListStyle(..)> - missing paragraph style");
1425 ::sw::ListLevelIndents
const indents(m_pColl
->AreListLevelIndentsApplicable());
1426 if (indents
== ::sw::ListLevelIndents::No
)
1429 OSL_ENSURE( m_pColl
->GetItemState( RES_PARATR_NUMRULE
) == SfxItemState::SET
,
1430 "<SwDocStyleSheet::MergeIndentAttrsOfListStyle(..)> - list level indents are applicable at paragraph style, but no list style found. Serious defect." );
1431 const OUString sNumRule
= m_pColl
->GetNumRule().GetValue();
1432 if (sNumRule
.isEmpty())
1435 const SwNumRule
* pRule
= m_rDoc
.FindNumRulePtr( sNumRule
);
1438 const SwNumFormat
& rFormat
= pRule
->Get( 0 );
1439 if ( rFormat
.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT
)
1441 if (indents
& ::sw::ListLevelIndents::FirstLine
)
1443 SvxFirstLineIndentItem
const firstLine(static_cast<short>(rFormat
.GetFirstLineIndent()), RES_MARGIN_FIRSTLINE
);
1444 rSet
.Put(firstLine
);
1446 if (indents
& ::sw::ListLevelIndents::LeftMargin
)
1448 SvxTextLeftMarginItem
const leftMargin(rFormat
.GetIndentAt(), RES_MARGIN_TEXTLEFT
);
1449 rSet
.Put(leftMargin
);
1455 // handling of parameter <bResetIndentAttrsAtParagraphStyle>
1456 void SwDocStyleSheet::SetItemSet( const SfxItemSet
& rSet
,
1457 const bool bResetIndentAttrsAtParagraphStyle
)
1459 // if applicable determine format first
1461 FillStyleSheet( FillPhysical
);
1463 SwImplShellAction
aTmpSh( m_rDoc
);
1465 OSL_ENSURE( &rSet
!= &m_aCoreSet
, "SetItemSet with own Set is not allowed" );
1467 if (m_rDoc
.GetIDocumentUndoRedo().DoesUndo())
1469 SwRewriter aRewriter
;
1470 aRewriter
.AddRule( UndoArg1
, GetName() );
1471 m_rDoc
.GetIDocumentUndoRedo().StartUndo( SwUndoId::INSFMTATTR
, &aRewriter
);
1474 SwFormat
* pFormat
= nullptr;
1475 std::unique_ptr
<SwPageDesc
> pNewDsc
;
1476 size_t nPgDscPos
= 0;
1480 case SfxStyleFamily::Char
:
1482 OSL_ENSURE(m_pCharFormat
, "Where's CharFormat");
1483 pFormat
= m_pCharFormat
;
1487 case SfxStyleFamily::Para
:
1489 OSL_ENSURE(m_pColl
, "Where's Collection");
1490 if(const SfxBoolItem
* pAutoUpdate
= rSet
.GetItemIfSet(SID_ATTR_AUTO_STYLE_UPDATE
,false))
1492 m_pColl
->SetAutoUpdateOnDirectFormat(pAutoUpdate
->GetValue());
1495 const SwCondCollItem
* pCondItem
= rSet
.GetItemIfSet( FN_COND_COLL
, false );
1497 if( RES_CONDTXTFMTCOLL
== m_pColl
->Which() && pCondItem
)
1499 const CommandStruct
* pCmds
= SwCondCollItem::GetCmds();
1500 for(sal_uInt16 i
= 0; i
< COND_COMMAND_COUNT
; i
++)
1502 SwCollCondition
aCond( nullptr, pCmds
[ i
].nCnd
, pCmds
[ i
].nSubCond
);
1503 static_cast<SwConditionTextFormatColl
*>(m_pColl
)->RemoveCondition( aCond
);
1504 const OUString sStyle
= pCondItem
->GetStyle( i
);
1505 if (sStyle
.isEmpty())
1507 SwFormat
*const pFindFormat
= lcl_FindParaFormat( m_rDoc
, sStyle
);
1510 aCond
.RegisterToFormat( *pFindFormat
);
1511 static_cast<SwConditionTextFormatColl
*>(m_pColl
)->InsertCondition( aCond
);
1515 m_pColl
->GetNotifier().Broadcast(sw::CondCollCondChg(*m_pColl
));
1517 else if( pCondItem
&& !m_pColl
->HasWriterListeners() )
1519 // no conditional template, then first create and adopt
1520 // all important values
1521 SwConditionTextFormatColl
* pCColl
= m_rDoc
.MakeCondTextFormatColl(
1522 m_pColl
->GetName(), static_cast<SwTextFormatColl
*>(m_pColl
->DerivedFrom()) );
1523 if( m_pColl
!= &m_pColl
->GetNextTextFormatColl() )
1524 pCColl
->SetNextTextFormatColl( m_pColl
->GetNextTextFormatColl() );
1526 if( m_pColl
->IsAssignedToListLevelOfOutlineStyle())
1527 pCColl
->AssignToListLevelOfOutlineStyle(m_pColl
->GetAssignedOutlineStyleLevel());
1529 pCColl
->DeleteAssignmentToListLevelOfOutlineStyle();
1531 const CommandStruct
* pCmds
= SwCondCollItem::GetCmds();
1532 for( sal_uInt16 i
= 0; i
< COND_COMMAND_COUNT
; ++i
)
1534 const OUString sStyle
= pCondItem
->GetStyle( i
);
1535 if (sStyle
.isEmpty())
1537 SwTextFormatColl
*const pFindFormat
= lcl_FindParaFormat( m_rDoc
, sStyle
);
1540 pCColl
->InsertCondition( SwCollCondition( pFindFormat
,
1541 pCmds
[ i
].nCnd
, pCmds
[ i
].nSubCond
) );
1545 m_rDoc
.DelTextFormatColl( m_pColl
);
1548 if ( bResetIndentAttrsAtParagraphStyle
&&
1549 rSet
.GetItemState( RES_PARATR_NUMRULE
, false ) == SfxItemState::SET
&&
1550 rSet
.GetItemState(RES_MARGIN_FIRSTLINE
, false) != SfxItemState::SET
&&
1551 m_pColl
->GetItemState(RES_MARGIN_FIRSTLINE
, false) == SfxItemState::SET
)
1553 m_rDoc
.ResetAttrAtFormat(RES_MARGIN_FIRSTLINE
, *m_pColl
);
1555 if ( bResetIndentAttrsAtParagraphStyle
&&
1556 rSet
.GetItemState( RES_PARATR_NUMRULE
, false ) == SfxItemState::SET
&&
1557 rSet
.GetItemState(RES_MARGIN_TEXTLEFT
, false) != SfxItemState::SET
&&
1558 m_pColl
->GetItemState(RES_MARGIN_TEXTLEFT
, false) == SfxItemState::SET
)
1560 m_rDoc
.ResetAttrAtFormat(RES_MARGIN_TEXTLEFT
, *m_pColl
);
1563 // #i56252: If a standard numbering style is assigned to a standard paragraph style
1564 // we have to create a physical instance of the numbering style. If we do not and
1565 // neither the paragraph style nor the numbering style is used in the document
1566 // the numbering style will not be saved with the document and the assignment got lost.
1567 if( const SfxPoolItem
* pNumRuleItem
= rSet
.GetItemIfSet( RES_PARATR_NUMRULE
, false ) )
1568 { // Setting a numbering rule?
1569 const OUString sNumRule
= static_cast<const SwNumRuleItem
*>(pNumRuleItem
)->GetValue();
1570 if (!sNumRule
.isEmpty())
1572 SwNumRule
* pRule
= m_rDoc
.FindNumRulePtr( sNumRule
);
1574 { // Numbering rule not in use yet.
1575 sal_uInt16 nPoolId
= SwStyleNameMapper::GetPoolIdFromUIName( sNumRule
, SwGetPoolIdFromName::NumRule
);
1576 if( USHRT_MAX
!= nPoolId
) // It's a standard numbering rule
1578 m_rDoc
.getIDocumentStylePoolAccess().GetNumRuleFromPool( nPoolId
); // Create numbering rule (physical)
1586 sal_uInt16 nId
= m_pColl
->GetPoolFormatId() &
1587 ~ ( COLL_GET_RANGE_BITS
| POOLGRP_NOCOLLID
);
1588 switch( GetMask() & ( static_cast<SfxStyleSearchBits
>(0x0fff) & ~SfxStyleSearchBits::SwCondColl
) )
1590 case SfxStyleSearchBits::SwText
:
1591 nId
|= COLL_TEXT_BITS
;
1593 case SfxStyleSearchBits::SwChapter
:
1594 nId
|= COLL_DOC_BITS
;
1596 case SfxStyleSearchBits::SwList
:
1597 nId
|= COLL_LISTS_BITS
;
1599 case SfxStyleSearchBits::SwIndex
:
1600 nId
|= COLL_REGISTER_BITS
;
1602 case SfxStyleSearchBits::SwExtra
:
1603 nId
|= COLL_EXTRA_BITS
;
1605 case SfxStyleSearchBits::SwHtml
:
1606 nId
|= COLL_HTML_BITS
;
1610 m_pColl
->SetPoolFormatId( nId
);
1613 case SfxStyleFamily::Frame
:
1615 OSL_ENSURE(m_pFrameFormat
, "Where's FrameFormat");
1617 if(const SfxPoolItem
* pAutoUpdate
= rSet
.GetItemIfSet(SID_ATTR_AUTO_STYLE_UPDATE
,false))
1619 m_pFrameFormat
->SetAutoUpdateOnDirectFormat(static_cast<const SfxBoolItem
*>(pAutoUpdate
)->GetValue());
1621 pFormat
= m_pFrameFormat
;
1625 case SfxStyleFamily::Page
:
1627 OSL_ENSURE(m_pDesc
, "Where's PageDescriptor");
1629 if (m_rDoc
.FindPageDesc(m_pDesc
->GetName(), &nPgDscPos
))
1631 pNewDsc
.reset( new SwPageDesc( *m_pDesc
) );
1632 // #i48949# - no undo actions for the
1633 // copy of the page style
1634 ::sw::UndoGuard
const ug(m_rDoc
.GetIDocumentUndoRedo());
1635 m_rDoc
.CopyPageDesc(*m_pDesc
, *pNewDsc
); // #i7983#
1637 pFormat
= &pNewDsc
->GetMaster();
1642 case SfxStyleFamily::Pseudo
:
1644 OSL_ENSURE(m_pNumRule
, "Where's NumRule");
1649 const SfxPoolItem
* pItem
;
1650 switch( rSet
.GetItemState( SID_ATTR_NUMBERING_RULE
, false, &pItem
))
1652 case SfxItemState::SET
:
1654 SvxNumRule
& rSetRule
= const_cast<SvxNumRule
&>(static_cast<const SvxNumBulletItem
*>(pItem
)->GetNumRule());
1655 rSetRule
.UnLinkGraphics();
1656 SwNumRule
aSetRule(*m_pNumRule
);
1657 aSetRule
.SetSvxRule(rSetRule
, &m_rDoc
);
1658 m_rDoc
.ChgNumRuleFormats( aSetRule
);
1661 case SfxItemState::DONTCARE
:
1662 // set NumRule to default values
1663 // what are the default values?
1665 SwNumRule
aRule( m_pNumRule
->GetName(),
1667 numfunc::GetDefaultPositionAndSpaceMode() );
1668 m_rDoc
.ChgNumRuleFormats( aRule
);
1677 OSL_ENSURE(false, "unknown style family");
1680 if( pFormat
&& rSet
.Count())
1682 SfxItemIter
aIter( rSet
);
1683 const SfxPoolItem
* pItem
= aIter
.GetCurItem();
1686 if( IsInvalidItem( pItem
) ) // Clear
1688 // use method <SwDoc::ResetAttrAtFormat(..)> in order to
1689 // create an Undo object for the attribute reset.
1690 m_rDoc
.ResetAttrAtFormat( rSet
.GetWhichByPos(aIter
.GetCurPos()),
1694 pItem
= aIter
.NextItem();
1696 SfxItemSet
aSet(rSet
);
1697 aSet
.ClearInvalidItems();
1699 if(SfxStyleFamily::Frame
== nFamily
)
1701 // Need to check for unique item for DrawingLayer items of type NameOrIndex
1702 // and evtl. correct that item to ensure unique names for that type. This call may
1703 // modify/correct entries inside of the given SfxItemSet
1704 m_rDoc
.CheckForUniqueItemForLineFillNameOrIndex(aSet
);
1707 m_aCoreSet
.ClearItem();
1711 ::ItemSetToPageDesc( aSet
, *pNewDsc
);
1712 m_rDoc
.ChgPageDesc( nPgDscPos
, *pNewDsc
);
1713 m_pDesc
= &m_rDoc
.GetPageDesc( nPgDscPos
);
1714 m_rDoc
.PreDelPageDesc(pNewDsc
.get()); // #i7983#
1718 m_rDoc
.ChgFormat(*pFormat
, aSet
); // put all that is set
1722 m_aCoreSet
.ClearItem();
1723 if( pNewDsc
) // we still need to delete it
1725 m_rDoc
.PreDelPageDesc(pNewDsc
.get()); // #i7983#
1730 if (m_rDoc
.GetIDocumentUndoRedo().DoesUndo())
1732 m_rDoc
.GetIDocumentUndoRedo().EndUndo(SwUndoId::END
, nullptr);
1736 static void lcl_SaveStyles( SfxStyleFamily nFamily
, std::vector
<void*>& rArr
, SwDoc
& rDoc
)
1740 case SfxStyleFamily::Char
:
1742 const SwCharFormats
& rTable
= *rDoc
.GetCharFormats();
1743 for(auto const& rChar
: rTable
)
1745 rArr
.push_back(rChar
);
1749 case SfxStyleFamily::Para
:
1751 const SwTextFormatColls
& rTable
= *rDoc
.GetTextFormatColls();
1752 for(auto const& rPara
: rTable
)
1754 rArr
.push_back(rPara
);
1758 case SfxStyleFamily::Frame
:
1760 for(auto const& rFrame
: *rDoc
.GetFrameFormats())
1762 rArr
.push_back(rFrame
);
1767 case SfxStyleFamily::Page
:
1769 for( size_t n
= 0, nCnt
= rDoc
.GetPageDescCnt(); n
< nCnt
; ++n
)
1771 rArr
.push_back( &rDoc
.GetPageDesc( n
) );
1776 case SfxStyleFamily::Pseudo
:
1778 const SwNumRuleTable
& rTable
= rDoc
.GetNumRuleTable();
1779 for(auto const& rPseudo
: rTable
)
1781 rArr
.push_back(rPseudo
);
1789 static bool lcl_Contains(const std::vector
<void*>& rArr
, const void* p
)
1791 return std::find( rArr
.begin(), rArr
.end(), p
) != rArr
.end();
1794 static void lcl_DeleteInfoStyles( SfxStyleFamily nFamily
, std::vector
<void*> const & rArr
, SwDoc
& rDoc
)
1799 case SfxStyleFamily::Char
:
1801 std::deque
<sal_uInt16
> aDelArr
;
1802 const SwCharFormats
& rTable
= *rDoc
.GetCharFormats();
1803 for( n
= 0, nCnt
= rTable
.size(); n
< nCnt
; ++n
)
1805 if( !lcl_Contains( rArr
, rTable
[ n
] ))
1806 aDelArr
.push_front( n
);
1808 for(auto const& rDelArr
: aDelArr
)
1809 rDoc
.DelCharFormat( rDelArr
);
1813 case SfxStyleFamily::Para
:
1815 std::deque
<sal_uInt16
> aDelArr
;
1816 const SwTextFormatColls
& rTable
= *rDoc
.GetTextFormatColls();
1817 for( n
= 0, nCnt
= rTable
.size(); n
< nCnt
; ++n
)
1819 if( !lcl_Contains( rArr
, rTable
[ n
] ))
1820 aDelArr
.push_front( n
);
1822 for(auto const& rDelArr
: aDelArr
)
1823 rDoc
.DelTextFormatColl( rDelArr
);
1827 case SfxStyleFamily::Frame
:
1829 std::deque
<SwFrameFormat
*> aDelArr
;
1830 for(auto const& rFrame
: *rDoc
.GetFrameFormats())
1832 if( !lcl_Contains( rArr
, rFrame
))
1833 aDelArr
.push_front( rFrame
);
1835 for( auto const& rDelArr
: aDelArr
)
1836 rDoc
.DelFrameFormat( rDelArr
);
1840 case SfxStyleFamily::Page
:
1842 std::deque
<size_t> aDelArr
;
1843 for( n
= 0, nCnt
= rDoc
.GetPageDescCnt(); n
< nCnt
; ++n
)
1845 if( !lcl_Contains( rArr
, &rDoc
.GetPageDesc( n
) ))
1846 aDelArr
.push_front( n
);
1848 for( auto const& rDelArr
: aDelArr
)
1849 rDoc
.DelPageDesc( rDelArr
);
1853 case SfxStyleFamily::Pseudo
:
1855 std::deque
<SwNumRule
*> aDelArr
;
1856 const SwNumRuleTable
& rTable
= rDoc
.GetNumRuleTable();
1857 for( auto const& rPseudo
: rTable
)
1859 if( !lcl_Contains( rArr
, rPseudo
))
1860 aDelArr
.push_front( rPseudo
);
1862 for( auto const& rDelArr
: aDelArr
)
1863 rDoc
.DelNumRule( rDelArr
->GetName() );
1870 // determine the format
1871 bool SwDocStyleSheet::FillStyleSheet(
1872 FillStyleType
const eFType
, std::optional
<SfxItemSet
> *const o_ppFlatSet
)
1875 sal_uInt16 nPoolId
= USHRT_MAX
;
1876 SwFormat
* pFormat
= nullptr;
1878 bool bCreate
= FillPhysical
== eFType
;
1879 bool bDeleteInfo
= false;
1880 bool bFillOnlyInfo
= FillAllInfo
== eFType
|| FillPreview
== eFType
;
1881 std::vector
<void*> aDelArr
;
1882 bool const isModified(m_rDoc
.getIDocumentState().IsModified());
1886 case SfxStyleFamily::Char
:
1887 m_pCharFormat
= lcl_FindCharFormat(m_rDoc
, aName
, this, bCreate
);
1888 m_bPhysical
= nullptr != m_pCharFormat
;
1889 if( bFillOnlyInfo
&& !m_bPhysical
)
1891 // create style (plus all needed parents) and clean it up
1892 // later - without affecting the undo/redo stack
1893 ::sw::UndoGuard
const ug(m_rDoc
.GetIDocumentUndoRedo());
1895 ::lcl_SaveStyles( nFamily
, aDelArr
, m_rDoc
);
1896 m_pCharFormat
= lcl_FindCharFormat(m_rDoc
, aName
, this );
1899 pFormat
= m_pCharFormat
;
1901 if( !bCreate
&& !pFormat
)
1903 if( aName
== SwResId(STR_POOLCHR_STANDARD
))
1906 nPoolId
= SwStyleNameMapper::GetPoolIdFromUIName( aName
, SwGetPoolIdFromName::ChrFmt
);
1911 const SwTextFormatColl
* pParaFormat
= m_pCharFormat
->GetLinkedParaFormat();
1914 m_aLink
= pParaFormat
->GetName();
1918 bRet
= nullptr != m_pCharFormat
|| USHRT_MAX
!= nPoolId
;
1921 m_pCharFormat
= nullptr;
1924 case SfxStyleFamily::Para
:
1926 m_pColl
= lcl_FindParaFormat(m_rDoc
, aName
, this, bCreate
);
1927 m_bPhysical
= nullptr != m_pColl
;
1928 if( bFillOnlyInfo
&& !m_bPhysical
)
1930 ::sw::UndoGuard
const ug(m_rDoc
.GetIDocumentUndoRedo());
1932 ::lcl_SaveStyles( nFamily
, aDelArr
, m_rDoc
);
1933 m_pColl
= lcl_FindParaFormat(m_rDoc
, aName
, this );
1940 PresetFollow( m_pColl
->GetNextTextFormatColl().GetName() );
1941 const SwCharFormat
* pCharFormat
= m_pColl
->GetLinkedCharFormat();
1944 m_aLink
= pCharFormat
->GetName();
1948 nPoolId
= SwStyleNameMapper::GetPoolIdFromUIName( aName
, SwGetPoolIdFromName::TxtColl
);
1950 bRet
= nullptr != m_pColl
|| USHRT_MAX
!= nPoolId
;
1957 case SfxStyleFamily::Frame
:
1958 m_pFrameFormat
= lcl_FindFrameFormat(m_rDoc
, aName
, this, bCreate
);
1959 m_bPhysical
= nullptr != m_pFrameFormat
;
1960 if (bFillOnlyInfo
&& !m_bPhysical
)
1962 ::sw::UndoGuard
const ug(m_rDoc
.GetIDocumentUndoRedo());
1964 ::lcl_SaveStyles( nFamily
, aDelArr
, m_rDoc
);
1965 m_pFrameFormat
= lcl_FindFrameFormat(m_rDoc
, aName
, this );
1967 pFormat
= m_pFrameFormat
;
1968 if( !bCreate
&& !pFormat
)
1969 nPoolId
= SwStyleNameMapper::GetPoolIdFromUIName( aName
, SwGetPoolIdFromName::FrmFmt
);
1971 bRet
= nullptr != m_pFrameFormat
|| USHRT_MAX
!= nPoolId
;
1974 m_pFrameFormat
= nullptr;
1977 case SfxStyleFamily::Page
:
1978 m_pDesc
= lcl_FindPageDesc(m_rDoc
, aName
, this, bCreate
);
1979 m_bPhysical
= nullptr != m_pDesc
;
1980 if( bFillOnlyInfo
&& !m_pDesc
)
1982 ::sw::UndoGuard
const ug(m_rDoc
.GetIDocumentUndoRedo());
1984 ::lcl_SaveStyles( nFamily
, aDelArr
, m_rDoc
);
1985 m_pDesc
= lcl_FindPageDesc( m_rDoc
, aName
, this );
1990 nPoolId
= m_pDesc
->GetPoolFormatId();
1991 nHelpId
= m_pDesc
->GetPoolHelpId();
1992 if (const OUString
* pattern
= m_pDesc
->GetPoolHlpFileId() != UCHAR_MAX
1993 ? m_rDoc
.GetDocPattern(m_pDesc
->GetPoolHlpFileId())
1995 aHelpFile
= *pattern
;
2000 nPoolId
= SwStyleNameMapper::GetPoolIdFromUIName( aName
, SwGetPoolIdFromName::PageDesc
);
2001 SetMask( (USER_FMT
& nPoolId
) ? SfxStyleSearchBits::UserDefined
: SfxStyleSearchBits::Auto
);
2003 bRet
= nullptr != m_pDesc
|| USHRT_MAX
!= nPoolId
;
2008 case SfxStyleFamily::Pseudo
:
2009 m_pNumRule
= lcl_FindNumRule(m_rDoc
, aName
, this, bCreate
);
2010 m_bPhysical
= nullptr != m_pNumRule
;
2011 if( bFillOnlyInfo
&& !m_pNumRule
)
2013 ::sw::UndoGuard
const ug(m_rDoc
.GetIDocumentUndoRedo());
2015 ::lcl_SaveStyles( nFamily
, aDelArr
, m_rDoc
);
2016 m_pNumRule
= lcl_FindNumRule( m_rDoc
, aName
, this );
2021 nPoolId
= m_pNumRule
->GetPoolFormatId();
2022 nHelpId
= m_pNumRule
->GetPoolHelpId();
2023 if (const OUString
* pattern
= m_pNumRule
->GetPoolHlpFileId() != UCHAR_MAX
2024 ? m_rDoc
.GetDocPattern(m_pNumRule
->GetPoolHlpFileId())
2026 aHelpFile
= *pattern
;
2031 nPoolId
= SwStyleNameMapper::GetPoolIdFromUIName( aName
, SwGetPoolIdFromName::NumRule
);
2032 SetMask( (USER_FMT
& nPoolId
) ? SfxStyleSearchBits::UserDefined
: SfxStyleSearchBits::Auto
);
2034 bRet
= nullptr != m_pNumRule
|| USHRT_MAX
!= nPoolId
;
2037 m_pNumRule
= nullptr;
2040 case SfxStyleFamily::Table
:
2041 m_pTableFormat
= lcl_FindTableStyle(m_rDoc
, aName
, this, bCreate
);
2042 SetMask((m_pTableFormat
&& m_pTableFormat
->IsUserDefined()) ? SfxStyleSearchBits::UserDefined
: SfxStyleSearchBits::Auto
);
2043 bRet
= m_bPhysical
= (nullptr != m_pTableFormat
);
2046 case SfxStyleFamily::Cell
:
2047 m_pBoxFormat
= lcl_FindCellStyle(m_rDoc
, aName
, this);
2048 bRet
= m_bPhysical
= (nullptr != m_pBoxFormat
);
2050 default:; //prevent warning
2053 if( SfxStyleFamily::Char
== nFamily
||
2054 SfxStyleFamily::Para
== nFamily
||
2055 SfxStyleFamily::Frame
== nFamily
)
2058 nPoolId
= pFormat
->GetPoolFormatId();
2060 SfxStyleSearchBits _nMask
= SfxStyleSearchBits::Auto
;
2061 if( pFormat
== m_rDoc
.GetDfltCharFormat() )
2062 _nMask
|= SfxStyleSearchBits::ReadOnly
;
2063 else if( USER_FMT
& nPoolId
)
2064 _nMask
|= SfxStyleSearchBits::UserDefined
;
2066 switch ( COLL_GET_RANGE_BITS
& nPoolId
)
2068 case COLL_TEXT_BITS
: _nMask
|= SfxStyleSearchBits::SwText
; break;
2069 case COLL_DOC_BITS
: _nMask
|= SfxStyleSearchBits::SwChapter
; break;
2070 case COLL_LISTS_BITS
: _nMask
|= SfxStyleSearchBits::SwList
; break;
2071 case COLL_REGISTER_BITS
: _nMask
|= SfxStyleSearchBits::SwIndex
; break;
2072 case COLL_EXTRA_BITS
: _nMask
|= SfxStyleSearchBits::SwExtra
; break;
2073 case COLL_HTML_BITS
: _nMask
|= SfxStyleSearchBits::SwHtml
; break;
2078 OSL_ENSURE( m_bPhysical
, "Format not found" );
2080 nHelpId
= pFormat
->GetPoolHelpId();
2081 if (const OUString
* pattern
= pFormat
->GetPoolHlpFileId() != UCHAR_MAX
2082 ? m_rDoc
.GetDocPattern(pFormat
->GetPoolHlpFileId())
2084 aHelpFile
= *pattern
;
2088 if( RES_CONDTXTFMTCOLL
== pFormat
->Which() )
2089 _nMask
|= SfxStyleSearchBits::SwCondColl
;
2091 if (FillPreview
== eFType
)
2093 assert(o_ppFlatSet
);
2094 lcl_SwFormatToFlatItemSet(pFormat
, *o_ppFlatSet
);
2100 if( bDeleteInfo
&& bFillOnlyInfo
)
2102 ::sw::UndoGuard
const ug(m_rDoc
.GetIDocumentUndoRedo());
2103 ::lcl_DeleteInfoStyles( nFamily
, aDelArr
, m_rDoc
);
2106 m_rDoc
.getIDocumentState().ResetModified();
2112 // Create new format in Core
2113 void SwDocStyleSheet::Create()
2117 case SfxStyleFamily::Char
:
2118 m_pCharFormat
= lcl_FindCharFormat( m_rDoc
, aName
);
2119 if( !m_pCharFormat
)
2120 m_pCharFormat
= m_rDoc
.MakeCharFormat(aName
,
2121 m_rDoc
.GetDfltCharFormat());
2122 m_pCharFormat
->SetAuto(false);
2125 case SfxStyleFamily::Para
:
2126 m_pColl
= lcl_FindParaFormat( m_rDoc
, aName
);
2129 SwTextFormatColl
*pPar
= (*m_rDoc
.GetTextFormatColls())[0];
2130 if( nMask
& SfxStyleSearchBits::SwCondColl
)
2131 m_pColl
= m_rDoc
.MakeCondTextFormatColl( aName
, pPar
);
2133 m_pColl
= m_rDoc
.MakeTextFormatColl( aName
, pPar
);
2137 case SfxStyleFamily::Frame
:
2138 m_pFrameFormat
= lcl_FindFrameFormat( m_rDoc
, aName
);
2139 if( !m_pFrameFormat
)
2140 m_pFrameFormat
= m_rDoc
.MakeFrameFormat(aName
, m_rDoc
.GetDfltFrameFormat(), false, false);
2144 case SfxStyleFamily::Page
:
2145 m_pDesc
= lcl_FindPageDesc( m_rDoc
, aName
);
2148 m_pDesc
= m_rDoc
.MakePageDesc(aName
);
2152 case SfxStyleFamily::Pseudo
:
2153 m_pNumRule
= lcl_FindNumRule( m_rDoc
, aName
);
2156 const OUString
sTmpNm( aName
.isEmpty() ? m_rDoc
.GetUniqueNumRuleName() : aName
);
2157 SwNumRule
* pRule
= m_rDoc
.GetNumRuleTable()[
2158 m_rDoc
.MakeNumRule( sTmpNm
, nullptr, false,
2160 numfunc::GetDefaultPositionAndSpaceMode() ) ];
2161 pRule
->SetAutoRule( false );
2162 if( aName
.isEmpty() )
2165 pRule
->SetName( aName
, m_rDoc
.getIDocumentListsAccess() );
2171 case SfxStyleFamily::Table
:
2172 if (aName
.isEmpty())
2174 m_pTableFormat
= lcl_FindTableStyle(m_rDoc
, aName
);
2175 if (!m_pTableFormat
)
2177 m_rDoc
.MakeTableStyle(aName
);
2178 m_pTableFormat
= m_rDoc
.GetTableStyles().FindAutoFormat(aName
);
2179 SAL_WARN_IF(!m_pTableFormat
, "sw.ui", "Recently added auto format not found");
2182 default:; //prevent warning
2185 m_aCoreSet
.ClearItem();
2188 SwCharFormat
* SwDocStyleSheet::GetCharFormat()
2191 FillStyleSheet( FillPhysical
);
2192 return m_pCharFormat
;
2195 SwTextFormatColl
* SwDocStyleSheet::GetCollection()
2198 FillStyleSheet( FillPhysical
);
2202 const SwPageDesc
* SwDocStyleSheet::GetPageDesc()
2205 FillStyleSheet( FillPhysical
);
2209 const SwNumRule
* SwDocStyleSheet::GetNumRule()
2212 FillStyleSheet( FillPhysical
);
2217 void SwDocStyleSheet::SetNumRule(const SwNumRule
& rRule
)
2219 OSL_ENSURE(m_pNumRule
, "Where is the NumRule");
2220 m_rDoc
.ChgNumRuleFormats( rRule
);
2223 SwTableAutoFormat
* SwDocStyleSheet::GetTableFormat()
2226 FillStyleSheet( FillPhysical
);
2227 assert(m_pTableFormat
&& "SwDocStyleSheet table style, SwTableAutoFormat not found");
2228 return m_pTableFormat
;
2231 // re-generate Name AND Family from String
2232 // First() and Next() (see below) insert an identification letter at Pos.1
2234 void SwDocStyleSheet::PresetNameAndFamily(SfxStyleFamily eFamily
, const OUString
& rName
)
2236 this->nFamily
= eFamily
;
2237 this->aName
= rName
;
2240 // Is the format physically present yet
2241 void SwDocStyleSheet::SetPhysical(bool bPhys
)
2243 m_bPhysical
= bPhys
;
2247 m_pCharFormat
= nullptr;
2249 m_pFrameFormat
= nullptr;
2254 SwFrameFormat
* SwDocStyleSheet::GetFrameFormat()
2257 FillStyleSheet( FillPhysical
);
2258 return m_pFrameFormat
;
2261 bool SwDocStyleSheet::IsUsed() const
2265 SwDocStyleSheet
* pThis
= const_cast<SwDocStyleSheet
*>(this);
2266 pThis
->FillStyleSheet( FillOnlyName
);
2272 const sw::BroadcastingModify
* pMod
;
2275 case SfxStyleFamily::Char
: pMod
= m_pCharFormat
; break;
2276 case SfxStyleFamily::Para
: pMod
= m_pColl
; break;
2277 case SfxStyleFamily::Frame
: pMod
= m_pFrameFormat
; break;
2278 case SfxStyleFamily::Page
: pMod
= m_pDesc
; break;
2280 case SfxStyleFamily::Pseudo
:
2281 return m_pNumRule
&& m_rDoc
.IsUsed(*m_pNumRule
);
2283 case SfxStyleFamily::Table
:
2284 return m_pTableFormat
&& m_rDoc
.IsUsed( *m_pTableFormat
);
2287 OSL_ENSURE(false, "unknown style family");
2290 return m_rDoc
.IsUsed( *pMod
);
2293 OUString
SwDocStyleSheet::GetUsedBy()
2295 return m_pNumRule
? m_pNumRule
->MakeParagraphStyleListString() : OUString();
2298 sal_uLong
SwDocStyleSheet::GetHelpId( OUString
& rFile
)
2301 sal_uInt16 nPoolId
= 0;
2302 unsigned char nFileId
= UCHAR_MAX
;
2304 rFile
= "swrhlppi.hlp";
2306 const SwFormat
* pTmpFormat
= nullptr;
2309 case SfxStyleFamily::Char
:
2310 if( !m_pCharFormat
&&
2311 nullptr == (m_pCharFormat
= lcl_FindCharFormat( m_rDoc
, aName
, nullptr, false )) )
2313 nId
= SwStyleNameMapper::GetPoolIdFromUIName( aName
, SwGetPoolIdFromName::ChrFmt
);
2314 return USHRT_MAX
== nId
? 0 : nId
;
2316 pTmpFormat
= m_pCharFormat
;
2319 case SfxStyleFamily::Para
:
2321 nullptr == ( m_pColl
= lcl_FindParaFormat( m_rDoc
, aName
, nullptr, false )) )
2323 nId
= SwStyleNameMapper::GetPoolIdFromUIName( aName
, SwGetPoolIdFromName::TxtColl
);
2324 return USHRT_MAX
== nId
? 0 : nId
;
2326 pTmpFormat
= m_pColl
;
2329 case SfxStyleFamily::Frame
:
2330 if( !m_pFrameFormat
&&
2331 nullptr == ( m_pFrameFormat
= lcl_FindFrameFormat( m_rDoc
, aName
, nullptr, false ) ) )
2333 nId
= SwStyleNameMapper::GetPoolIdFromUIName( aName
, SwGetPoolIdFromName::FrmFmt
);
2334 return USHRT_MAX
== nId
? 0 : nId
;
2336 pTmpFormat
= m_pFrameFormat
;
2339 case SfxStyleFamily::Page
:
2341 nullptr == ( m_pDesc
= lcl_FindPageDesc( m_rDoc
, aName
, nullptr, false ) ) )
2343 nId
= SwStyleNameMapper::GetPoolIdFromUIName( aName
, SwGetPoolIdFromName::PageDesc
);
2344 return USHRT_MAX
== nId
? 0 : nId
;
2347 nId
= m_pDesc
->GetPoolHelpId();
2348 nFileId
= m_pDesc
->GetPoolHlpFileId();
2349 nPoolId
= m_pDesc
->GetPoolFormatId();
2352 case SfxStyleFamily::Pseudo
:
2354 nullptr == ( m_pNumRule
= lcl_FindNumRule( m_rDoc
, aName
, nullptr, false ) ) )
2356 nId
= SwStyleNameMapper::GetPoolIdFromUIName( aName
, SwGetPoolIdFromName::NumRule
);
2357 return USHRT_MAX
== nId
? 0 : nId
;
2360 nId
= m_pNumRule
->GetPoolHelpId();
2361 nFileId
= m_pNumRule
->GetPoolHlpFileId();
2362 nPoolId
= m_pNumRule
->GetPoolFormatId();
2366 OSL_ENSURE(false, "unknown style family");
2372 nId
= pTmpFormat
->GetPoolHelpId();
2373 nFileId
= pTmpFormat
->GetPoolHlpFileId();
2374 nPoolId
= pTmpFormat
->GetPoolFormatId();
2377 if( UCHAR_MAX
!= nFileId
)
2379 const OUString
*pTemplate
= m_rDoc
.GetDocPattern( nFileId
);
2385 else if( !IsPoolUserFormat( nPoolId
) )
2390 // because SFX acts like that, with HelpId:
2391 if( USHRT_MAX
== nId
)
2392 nId
= 0; // don't show Help accordingly
2397 void SwDocStyleSheet::SetHelpId( const OUString
& r
, sal_uLong nId
)
2399 sal_uInt8 nFileId
= static_cast< sal_uInt8
>(m_rDoc
.SetDocPattern( r
));
2400 sal_uInt16 nHId
= static_cast< sal_uInt16
>(nId
); //!! SFX changed over to ULONG arbitrarily!
2402 SwFormat
* pTmpFormat
= nullptr;
2405 case SfxStyleFamily::Char
: pTmpFormat
= m_pCharFormat
; break;
2406 case SfxStyleFamily::Para
: pTmpFormat
= m_pColl
; break;
2407 case SfxStyleFamily::Frame
: pTmpFormat
= m_pFrameFormat
; break;
2408 case SfxStyleFamily::Page
:
2409 const_cast<SwPageDesc
*>(m_pDesc
)->SetPoolHelpId( nHId
);
2410 const_cast<SwPageDesc
*>(m_pDesc
)->SetPoolHlpFileId( nFileId
);
2413 case SfxStyleFamily::Pseudo
:
2414 const_cast<SwNumRule
*>(m_pNumRule
)->SetPoolHelpId( nHId
);
2415 const_cast<SwNumRule
*>(m_pNumRule
)->SetPoolHlpFileId( nFileId
);
2419 OSL_ENSURE(false, "unknown style family");
2424 pTmpFormat
->SetPoolHelpId( nHId
);
2425 pTmpFormat
->SetPoolHlpFileId( nFileId
);
2429 // methods for DocStyleSheetPool
2430 SwDocStyleSheetPool::SwDocStyleSheetPool( SwDoc
& rDocument
, bool bOrg
)
2431 : SfxStyleSheetBasePool(rDocument
.GetAttrPool())
2432 , mxStyleSheet(new SwDocStyleSheet(rDocument
, *this))
2435 m_bOrganizer
= bOrg
;
2438 SwDocStyleSheetPool::~SwDocStyleSheetPool()
2442 SfxStyleSheetBase
& SwDocStyleSheetPool::Make( const OUString
& rName
,
2443 SfxStyleFamily eFam
,
2444 SfxStyleSearchBits _nMask
)
2446 mxStyleSheet
->PresetName(rName
);
2447 mxStyleSheet
->PresetParent(OUString());
2448 mxStyleSheet
->PresetFollow(OUString());
2449 mxStyleSheet
->SetMask(_nMask
) ;
2450 mxStyleSheet
->SetFamily(eFam
);
2451 mxStyleSheet
->SetPhysical(true);
2452 mxStyleSheet
->Create();
2454 return *mxStyleSheet
;
2457 rtl::Reference
<SfxStyleSheetBase
> SwDocStyleSheetPool::Create( const SfxStyleSheetBase
& /*rOrg*/)
2459 OSL_ENSURE(false , "Create in SW-Stylesheet-Pool not possible" );
2463 rtl::Reference
<SfxStyleSheetBase
> SwDocStyleSheetPool::Create( const OUString
&,
2464 SfxStyleFamily
, SfxStyleSearchBits
)
2466 OSL_ENSURE( false, "Create in SW-Stylesheet-Pool not possible" );
2470 std::unique_ptr
<SfxStyleSheetIterator
> SwDocStyleSheetPool::CreateIterator( SfxStyleFamily eFam
, SfxStyleSearchBits _nMask
)
2472 return std::make_unique
<SwStyleSheetIterator
>(*this, eFam
, _nMask
);
2475 void SwDocStyleSheetPool::dispose()
2477 mxStyleSheet
.clear();
2480 void SwDocStyleSheetPool::Remove( SfxStyleSheetBase
* pStyle
)
2485 bool bBroadcast
= true;
2486 SwImplShellAction
aTmpSh( m_rDoc
);
2487 const OUString sName
= pStyle
->GetName();
2488 switch( pStyle
->GetFamily() )
2490 case SfxStyleFamily::Char
:
2492 SwCharFormat
* pFormat
= lcl_FindCharFormat(m_rDoc
, sName
, nullptr, false );
2494 m_rDoc
.DelCharFormat(pFormat
);
2497 case SfxStyleFamily::Para
:
2499 SwTextFormatColl
* pColl
= lcl_FindParaFormat(m_rDoc
, sName
, nullptr, false );
2501 m_rDoc
.DelTextFormatColl(pColl
);
2504 case SfxStyleFamily::Frame
:
2506 SwFrameFormat
* pFormat
= lcl_FindFrameFormat(m_rDoc
, sName
, nullptr, false );
2508 m_rDoc
.DelFrameFormat(pFormat
);
2511 case SfxStyleFamily::Page
:
2513 m_rDoc
.DelPageDesc(sName
);
2517 case SfxStyleFamily::Pseudo
:
2519 if( !m_rDoc
.DelNumRule( sName
) )
2520 // Only send Broadcast, when something was deleted
2525 case SfxStyleFamily::Table
:
2527 m_rDoc
.DelTableStyle(sName
);
2532 OSL_ENSURE(false, "unknown style family");
2537 Broadcast( SfxStyleSheetHint( SfxHintId::StyleSheetErased
, *pStyle
) );
2540 bool SwDocStyleSheetPool::SetParent( SfxStyleFamily eFam
,
2541 const OUString
&rStyle
, const OUString
&rParent
)
2543 SwFormat
* pFormat
= nullptr, *pParent
= nullptr;
2546 case SfxStyleFamily::Char
:
2547 if( nullptr != ( pFormat
= lcl_FindCharFormat( m_rDoc
, rStyle
) ) && !rParent
.isEmpty() )
2548 pParent
= lcl_FindCharFormat(m_rDoc
, rParent
);
2551 case SfxStyleFamily::Para
:
2552 if( nullptr != ( pFormat
= lcl_FindParaFormat( m_rDoc
, rStyle
) ) && !rParent
.isEmpty() )
2553 pParent
= lcl_FindParaFormat( m_rDoc
, rParent
);
2556 case SfxStyleFamily::Frame
:
2557 if( nullptr != ( pFormat
= lcl_FindFrameFormat( m_rDoc
, rStyle
) ) && !rParent
.isEmpty() )
2558 pParent
= lcl_FindFrameFormat( m_rDoc
, rParent
);
2561 case SfxStyleFamily::Page
:
2562 case SfxStyleFamily::Pseudo
:
2566 OSL_ENSURE(false, "unknown style family");
2570 if( pFormat
&& pFormat
->DerivedFrom() &&
2571 pFormat
->DerivedFrom()->GetName() != rParent
)
2574 SwImplShellAction
aTmpSh( m_rDoc
);
2575 bRet
= pFormat
->SetDerivedFrom( pParent
);
2580 // only for Broadcasting
2581 mxStyleSheet
->PresetName( rStyle
);
2582 mxStyleSheet
->PresetParent( rParent
);
2583 if( SfxStyleFamily::Para
== eFam
)
2584 mxStyleSheet
->PresetFollow( static_cast<SwTextFormatColl
*>(pFormat
)->
2585 GetNextTextFormatColl().GetName() );
2587 mxStyleSheet
->PresetFollow( OUString() );
2589 Broadcast( SfxStyleSheetHint( SfxHintId::StyleSheetModified
, *mxStyleSheet
) );
2596 SfxStyleSheetBase
* SwDocStyleSheetPool::Find(const OUString
& rName
,
2597 SfxStyleFamily eFam
, SfxStyleSearchBits n
) const
2599 SfxStyleSearchBits nSMask
= n
;
2600 if( SfxStyleFamily::Para
== eFam
&& m_rDoc
.getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE
) )
2602 // then only HTML-Templates are of interest
2603 if( SfxStyleSearchBits::All
== nSMask
)
2604 nSMask
= SfxStyleSearchBits::SwHtml
| SfxStyleSearchBits::UserDefined
| SfxStyleSearchBits::Used
;
2606 nSMask
&= SfxStyleSearchBits::Used
| SfxStyleSearchBits::UserDefined
|
2607 SfxStyleSearchBits::SwCondColl
| SfxStyleSearchBits::SwHtml
;
2608 if( nSMask
== SfxStyleSearchBits::Auto
)
2609 nSMask
= SfxStyleSearchBits::SwHtml
;
2612 const bool bSearchUsed
= ( n
!= SfxStyleSearchBits::All
&& n
& SfxStyleSearchBits::Used
);
2613 const sw::BroadcastingModify
* pMod
= nullptr;
2615 mxStyleSheet
->SetPhysical( false );
2616 mxStyleSheet
->PresetName( rName
);
2617 mxStyleSheet
->SetFamily( eFam
);
2618 bool bFnd
= mxStyleSheet
->FillStyleSheet( SwDocStyleSheet::FillOnlyName
);
2620 if( mxStyleSheet
->IsPhysical() )
2624 case SfxStyleFamily::Char
:
2625 pMod
= mxStyleSheet
->GetCharFormat();
2628 case SfxStyleFamily::Para
:
2629 pMod
= mxStyleSheet
->GetCollection();
2632 case SfxStyleFamily::Frame
:
2633 pMod
= mxStyleSheet
->GetFrameFormat();
2636 case SfxStyleFamily::Page
:
2637 pMod
= mxStyleSheet
->GetPageDesc();
2640 case SfxStyleFamily::Pseudo
:
2642 const SwNumRule
* pRule
= mxStyleSheet
->GetNumRule();
2645 (( nSMask
& ~SfxStyleSearchBits::Used
) == SfxStyleSearchBits::UserDefined
2646 ? !(pRule
->GetPoolFormatId() & USER_FMT
)
2647 // searched for used and found none
2653 case SfxStyleFamily::Table
:
2654 case SfxStyleFamily::Cell
:
2657 OSL_ENSURE(false, "unknown style family");
2661 // then evaluate the mask:
2662 if( pMod
&& !bSearchUsed
)
2664 const sal_uInt16 nId
= SfxStyleFamily::Page
== eFam
2665 ? static_cast<const SwPageDesc
*>(pMod
)->GetPoolFormatId()
2666 : static_cast<const SwFormat
*>(pMod
)->GetPoolFormatId();
2668 if( ( nSMask
& ~SfxStyleSearchBits::Used
) == SfxStyleSearchBits::UserDefined
2669 && !(nId
& USER_FMT
) )
2670 // searched for used and found none
2673 return bFnd
? mxStyleSheet
.get() : nullptr;
2676 SwStyleSheetIterator::SwStyleSheetIterator(SwDocStyleSheetPool
& rBase
,
2677 SfxStyleFamily eFam
, SfxStyleSearchBits n
)
2678 : SfxStyleSheetIterator(&rBase
, eFam
, n
)
2679 , mxIterSheet(new SwDocStyleSheet(rBase
.GetDoc(), rBase
))
2680 , mxStyleSheet(new SwDocStyleSheet(rBase
.GetDoc(), rBase
))
2682 m_bFirstCalled
= false;
2684 StartListening(rBase
);
2687 SwStyleSheetIterator::~SwStyleSheetIterator()
2689 EndListening( *mxIterSheet
->GetPool() );
2692 sal_Int32
SwStyleSheetIterator::Count()
2694 // let the list fill correctly!!
2695 if( !m_bFirstCalled
)
2697 return m_aLst
.size();
2700 SfxStyleSheetBase
* SwStyleSheetIterator::operator[]( sal_Int32 nIdx
)
2703 if( !m_bFirstCalled
)
2705 auto const & rEntry
= m_aLst
[ nIdx
];
2706 mxStyleSheet
->PresetNameAndFamily( rEntry
.first
, rEntry
.second
);
2707 mxStyleSheet
->SetPhysical( false );
2708 mxStyleSheet
->FillStyleSheet( SwDocStyleSheet::FillOnlyName
);
2710 return mxStyleSheet
.get();
2713 SfxStyleSheetBase
* SwStyleSheetIterator::First()
2716 m_bFirstCalled
= true;
2721 mxIterSheet
->Reset();
2723 const SwDoc
& rDoc
= static_cast<const SwDocStyleSheetPool
*>(pBasePool
)->GetDoc();
2724 const SfxStyleSearchBits nSrchMask
= nMask
;
2725 const bool bIsSearchUsed
= SearchUsed();
2727 bool bSearchHidden( nMask
& SfxStyleSearchBits::Hidden
);
2728 bool bOnlyHidden
= nMask
== SfxStyleSearchBits::Hidden
;
2730 const bool bOrganizer
= static_cast<const SwDocStyleSheetPool
*>(pBasePool
)->IsOrganizerMode();
2731 bool bAll
= ( nSrchMask
& SfxStyleSearchBits::AllVisible
) == SfxStyleSearchBits::AllVisible
;
2733 if( nSearchFamily
== SfxStyleFamily::Char
2734 || nSearchFamily
== SfxStyleFamily::All
)
2736 const size_t nArrLen
= rDoc
.GetCharFormats()->size();
2737 for( size_t i
= 0; i
< nArrLen
; i
++ )
2739 SwCharFormat
* pFormat
= (*rDoc
.GetCharFormats())[ i
];
2741 const bool bUsed
= bIsSearchUsed
&& (bOrganizer
|| rDoc
.IsUsed(*pFormat
));
2742 if( ( !bSearchHidden
&& pFormat
->IsHidden() && !bUsed
) || ( pFormat
->IsDefault() && pFormat
!= rDoc
.GetDfltCharFormat() ) )
2745 if ( nSrchMask
== SfxStyleSearchBits::Hidden
&& !pFormat
->IsHidden( ) )
2750 // Standard is no User template
2751 const sal_uInt16 nId
= rDoc
.GetDfltCharFormat() == pFormat
?
2752 sal_uInt16( RES_POOLCHR_INET_NORMAL
):
2753 pFormat
->GetPoolFormatId();
2754 if( (nSrchMask
& ~SfxStyleSearchBits::Used
) == SfxStyleSearchBits::UserDefined
2756 // searched for used and found none
2762 if( rDoc
.getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE
) && !(nId
& USER_FMT
) &&
2763 ( RES_POOLCHR_HTML_BEGIN
> nId
|| nId
>= RES_POOLCHR_HTML_END
) &&
2764 RES_POOLCHR_INET_NORMAL
!= nId
&&
2765 RES_POOLCHR_INET_VISIT
!= nId
&&
2766 RES_POOLCHR_FOOTNOTE
!= nId
&&
2767 RES_POOLCHR_ENDNOTE
!= nId
)
2771 m_aLst
.Append( SfxStyleFamily::Char
, pFormat
== rDoc
.GetDfltCharFormat()
2772 ? SwResId(STR_POOLCHR_STANDARD
)
2773 : pFormat
->GetName() );
2779 if( ! rDoc
.getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE
) )
2780 AppendStyleList(SwStyleNameMapper::GetChrFormatUINameArray(),
2781 bIsSearchUsed
, bSearchHidden
, bOnlyHidden
,
2782 SwGetPoolIdFromName::ChrFmt
, SfxStyleFamily::Char
);
2785 m_aLst
.Append( SfxStyleFamily::Char
, SwStyleNameMapper::GetChrFormatUINameArray()[
2786 RES_POOLCHR_INET_NORMAL
- RES_POOLCHR_BEGIN
] );
2787 m_aLst
.Append( SfxStyleFamily::Char
, SwStyleNameMapper::GetChrFormatUINameArray()[
2788 RES_POOLCHR_INET_VISIT
- RES_POOLCHR_BEGIN
] );
2789 m_aLst
.Append( SfxStyleFamily::Char
, SwStyleNameMapper::GetChrFormatUINameArray()[
2790 RES_POOLCHR_ENDNOTE
- RES_POOLCHR_BEGIN
] );
2791 m_aLst
.Append( SfxStyleFamily::Char
, SwStyleNameMapper::GetChrFormatUINameArray()[
2792 RES_POOLCHR_FOOTNOTE
- RES_POOLCHR_BEGIN
] );
2794 AppendStyleList(SwStyleNameMapper::GetHTMLChrFormatUINameArray(),
2795 bIsSearchUsed
, bSearchHidden
, bOnlyHidden
,
2796 SwGetPoolIdFromName::ChrFmt
, SfxStyleFamily::Char
);
2800 if( nSearchFamily
== SfxStyleFamily::Para
||
2801 nSearchFamily
== SfxStyleFamily::All
)
2803 SfxStyleSearchBits nSMask
= nSrchMask
;
2804 if( rDoc
.getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE
) )
2806 // then only HTML-Template are of interest
2807 if( SfxStyleSearchBits::AllVisible
== ( nSMask
& SfxStyleSearchBits::AllVisible
) )
2808 nSMask
= SfxStyleSearchBits::SwHtml
| SfxStyleSearchBits::UserDefined
|
2809 SfxStyleSearchBits::Used
;
2811 nSMask
&= SfxStyleSearchBits::Used
| SfxStyleSearchBits::UserDefined
|
2812 SfxStyleSearchBits::SwCondColl
| SfxStyleSearchBits::SwHtml
;
2813 if( nSMask
== SfxStyleSearchBits::Auto
)
2814 nSMask
= SfxStyleSearchBits::SwHtml
;
2817 const size_t nArrLen
= rDoc
.GetTextFormatColls()->size();
2818 for( size_t i
= 0; i
< nArrLen
; i
++ )
2820 SwTextFormatColl
* pColl
= (*rDoc
.GetTextFormatColls())[ i
];
2822 const bool bUsed
= bOrganizer
|| rDoc
.IsUsed(*pColl
);
2823 if ( ( !bSearchHidden
&& pColl
->IsHidden( ) && !bUsed
) || pColl
->IsDefault() )
2826 if ( nSMask
== SfxStyleSearchBits::Hidden
&& !pColl
->IsHidden( ) )
2829 if( !(bIsSearchUsed
&& bUsed
))
2831 const sal_uInt16 nId
= pColl
->GetPoolFormatId();
2832 auto tmpMask
= nSMask
& ~SfxStyleSearchBits::Used
;
2833 if (tmpMask
== SfxStyleSearchBits::UserDefined
)
2835 if(!IsPoolUserFormat(nId
)) continue;
2837 else if (tmpMask
== SfxStyleSearchBits::SwText
)
2839 if((nId
& COLL_GET_RANGE_BITS
) != COLL_TEXT_BITS
) continue;
2841 else if (tmpMask
== SfxStyleSearchBits::SwChapter
)
2843 if((nId
& COLL_GET_RANGE_BITS
) != COLL_DOC_BITS
) continue;
2845 else if (tmpMask
== SfxStyleSearchBits::SwList
)
2847 if((nId
& COLL_GET_RANGE_BITS
) != COLL_LISTS_BITS
) continue;
2849 else if (tmpMask
== SfxStyleSearchBits::SwIndex
)
2851 if((nId
& COLL_GET_RANGE_BITS
) != COLL_REGISTER_BITS
) continue;
2853 else if (tmpMask
== SfxStyleSearchBits::SwExtra
)
2855 if((nId
& COLL_GET_RANGE_BITS
) != COLL_EXTRA_BITS
) continue;
2857 else if (tmpMask
== (SfxStyleSearchBits::SwHtml
| SfxStyleSearchBits::UserDefined
)
2858 || tmpMask
== SfxStyleSearchBits::SwHtml
)
2860 if((tmpMask
& SfxStyleSearchBits::UserDefined
) && IsPoolUserFormat(nId
))
2862 else if( (nId
& COLL_GET_RANGE_BITS
) != COLL_HTML_BITS
)
2864 // but some we also want to see in this section
2865 bool bContinue
= true;
2868 case RES_POOLCOLL_SEND_ADDRESS
: // --> ADDRESS
2869 case RES_POOLCOLL_TABLE_HDLN
: // --> TH
2870 case RES_POOLCOLL_TABLE
: // --> TD
2871 case RES_POOLCOLL_TEXT
: // --> P
2872 case RES_POOLCOLL_HEADLINE_BASE
:// --> H
2873 case RES_POOLCOLL_HEADLINE1
: // --> H1
2874 case RES_POOLCOLL_HEADLINE2
: // --> H2
2875 case RES_POOLCOLL_HEADLINE3
: // --> H3
2876 case RES_POOLCOLL_HEADLINE4
: // --> H4
2877 case RES_POOLCOLL_HEADLINE5
: // --> H5
2878 case RES_POOLCOLL_HEADLINE6
: // --> H6
2879 case RES_POOLCOLL_STANDARD
: // --> P
2880 case RES_POOLCOLL_FOOTNOTE
:
2881 case RES_POOLCOLL_ENDNOTE
:
2889 else if (tmpMask
== SfxStyleSearchBits::SwCondColl
)
2891 if( RES_CONDTXTFMTCOLL
!= pColl
->Which() ) continue;
2895 // searched for used and found none
2900 m_aLst
.Append( SfxStyleFamily::Para
, pColl
->GetName() );
2903 bAll
= ( nSMask
& SfxStyleSearchBits::AllVisible
) == SfxStyleSearchBits::AllVisible
;
2904 if ( bAll
|| (nSMask
& ~SfxStyleSearchBits::Used
) == SfxStyleSearchBits::SwText
)
2905 AppendStyleList(SwStyleNameMapper::GetTextUINameArray(),
2906 bIsSearchUsed
, bSearchHidden
, bOnlyHidden
, SwGetPoolIdFromName::TxtColl
, SfxStyleFamily::Para
);
2907 if ( bAll
|| (nSMask
& ~SfxStyleSearchBits::Used
) == SfxStyleSearchBits::SwChapter
)
2908 AppendStyleList(SwStyleNameMapper::GetDocUINameArray(),
2909 bIsSearchUsed
, bSearchHidden
, bOnlyHidden
, SwGetPoolIdFromName::TxtColl
, SfxStyleFamily::Para
) ;
2910 if ( bAll
|| (nSMask
& ~SfxStyleSearchBits::Used
) == SfxStyleSearchBits::SwList
)
2911 AppendStyleList(SwStyleNameMapper::GetListsUINameArray(),
2912 bIsSearchUsed
, bSearchHidden
, bOnlyHidden
, SwGetPoolIdFromName::TxtColl
, SfxStyleFamily::Para
) ;
2913 if ( bAll
|| (nSMask
& ~SfxStyleSearchBits::Used
) == SfxStyleSearchBits::SwIndex
)
2914 AppendStyleList(SwStyleNameMapper::GetRegisterUINameArray(),
2915 bIsSearchUsed
, bSearchHidden
, bOnlyHidden
, SwGetPoolIdFromName::TxtColl
, SfxStyleFamily::Para
) ;
2916 if ( bAll
|| (nSMask
& ~SfxStyleSearchBits::Used
) == SfxStyleSearchBits::SwExtra
)
2917 AppendStyleList(SwStyleNameMapper::GetExtraUINameArray(),
2918 bIsSearchUsed
, bSearchHidden
, bOnlyHidden
, SwGetPoolIdFromName::TxtColl
, SfxStyleFamily::Para
) ;
2919 if ( bAll
|| (nSMask
& ~SfxStyleSearchBits::Used
) == SfxStyleSearchBits::SwCondColl
)
2921 if( !bIsSearchUsed
||
2922 rDoc
.getIDocumentStylePoolAccess().IsPoolTextCollUsed( RES_POOLCOLL_TEXT
))
2923 m_aLst
.Append( SfxStyleFamily::Para
, SwStyleNameMapper::GetTextUINameArray()[
2924 RES_POOLCOLL_TEXT
- RES_POOLCOLL_TEXT_BEGIN
] );
2927 (nSMask
& ~SfxStyleSearchBits::Used
) == SfxStyleSearchBits::SwHtml
||
2928 (nSMask
& ~SfxStyleSearchBits::Used
) ==
2929 (SfxStyleSearchBits::SwHtml
| SfxStyleSearchBits::UserDefined
) )
2931 AppendStyleList(SwStyleNameMapper::GetHTMLUINameArray(),
2932 bIsSearchUsed
, bSearchHidden
, bOnlyHidden
, SwGetPoolIdFromName::TxtColl
, SfxStyleFamily::Para
) ;
2935 // then also the ones, that we are mapping:
2936 static sal_uInt16 aPoolIds
[] = {
2937 RES_POOLCOLL_SEND_ADDRESS
, // --> ADDRESS
2938 RES_POOLCOLL_TABLE_HDLN
, // --> TH
2939 RES_POOLCOLL_TABLE
, // --> TD
2940 RES_POOLCOLL_STANDARD
, // --> P
2941 RES_POOLCOLL_TEXT
, // --> P
2942 RES_POOLCOLL_HEADLINE_BASE
, // --> H
2943 RES_POOLCOLL_HEADLINE1
, // --> H1
2944 RES_POOLCOLL_HEADLINE2
, // --> H2
2945 RES_POOLCOLL_HEADLINE3
, // --> H3
2946 RES_POOLCOLL_HEADLINE4
, // --> H4
2947 RES_POOLCOLL_HEADLINE5
, // --> H5
2948 RES_POOLCOLL_HEADLINE6
, // --> H6
2949 RES_POOLCOLL_FOOTNOTE
,
2950 RES_POOLCOLL_ENDNOTE
,
2954 sal_uInt16
* pPoolIds
= aPoolIds
;
2958 if( !bIsSearchUsed
|| rDoc
.getIDocumentStylePoolAccess().IsPoolTextCollUsed( *pPoolIds
) )
2960 s
= SwStyleNameMapper::GetUIName( *pPoolIds
, s
);
2961 m_aLst
.Append( SfxStyleFamily::Para
, s
);
2969 if( nSearchFamily
== SfxStyleFamily::Frame
||
2970 nSearchFamily
== SfxStyleFamily::All
)
2972 const size_t nArrLen
= rDoc
.GetFrameFormats()->size();
2973 for( size_t i
= 0; i
< nArrLen
; i
++ )
2975 const SwFrameFormat
* pFormat
= (*rDoc
.GetFrameFormats())[ i
];
2977 bool bUsed
= bIsSearchUsed
&& ( bOrganizer
|| rDoc
.IsUsed(*pFormat
));
2978 if( ( !bSearchHidden
&& pFormat
->IsHidden( ) && !bUsed
) || pFormat
->IsDefault() || pFormat
->IsAuto() )
2981 if ( nSrchMask
== SfxStyleSearchBits::Hidden
&& !pFormat
->IsHidden( ) )
2984 const sal_uInt16 nId
= pFormat
->GetPoolFormatId();
2987 if( (nSrchMask
& ~SfxStyleSearchBits::Used
) == SfxStyleSearchBits::UserDefined
2989 // searched for used and found none
2996 m_aLst
.Append( SfxStyleFamily::Frame
, pFormat
->GetName() );
3001 AppendStyleList(SwStyleNameMapper::GetFrameFormatUINameArray(),
3002 bIsSearchUsed
, bSearchHidden
, bOnlyHidden
, SwGetPoolIdFromName::FrmFmt
, SfxStyleFamily::Frame
);
3005 if( nSearchFamily
== SfxStyleFamily::Page
||
3006 nSearchFamily
== SfxStyleFamily::All
)
3008 const size_t nCount
= rDoc
.GetPageDescCnt();
3009 for(size_t i
= 0; i
< nCount
; ++i
)
3011 const SwPageDesc
& rDesc
= rDoc
.GetPageDesc(i
);
3012 const sal_uInt16 nId
= rDesc
.GetPoolFormatId();
3013 bool bUsed
= bIsSearchUsed
&& ( bOrganizer
|| rDoc
.IsUsed(rDesc
));
3016 if ( ( !bSearchHidden
&& rDesc
.IsHidden() ) ||
3017 ( (nSrchMask
& ~SfxStyleSearchBits::Used
) == SfxStyleSearchBits::UserDefined
3019 // searched for used and found none
3024 if ( nSrchMask
== SfxStyleSearchBits::Hidden
&& !rDesc
.IsHidden( ) )
3027 m_aLst
.Append( SfxStyleFamily::Page
, rDesc
.GetName() );
3030 AppendStyleList(SwStyleNameMapper::GetPageDescUINameArray(),
3031 bIsSearchUsed
, bSearchHidden
, bOnlyHidden
, SwGetPoolIdFromName::PageDesc
, SfxStyleFamily::Page
);
3034 if( nSearchFamily
== SfxStyleFamily::Pseudo
||
3035 nSearchFamily
== SfxStyleFamily::All
)
3037 const SwNumRuleTable
& rNumTable
= rDoc
.GetNumRuleTable();
3038 for(auto const& rNum
: rNumTable
)
3040 const SwNumRule
& rRule
= *rNum
;
3041 if( !rRule
.IsAutoRule() )
3043 if ( nSrchMask
== SfxStyleSearchBits::Hidden
&& !rRule
.IsHidden( ) )
3046 bool bUsed
= bIsSearchUsed
&& (bOrganizer
|| rDoc
.IsUsed(rRule
));
3049 if( ( !bSearchHidden
&& rRule
.IsHidden() ) ||
3050 ( (nSrchMask
& ~SfxStyleSearchBits::Used
) == SfxStyleSearchBits::UserDefined
3051 ? !(rRule
.GetPoolFormatId() & USER_FMT
)
3052 // searched for used and found none
3057 m_aLst
.Append( SfxStyleFamily::Pseudo
, rRule
.GetName() );
3061 AppendStyleList(SwStyleNameMapper::GetNumRuleUINameArray(),
3062 bIsSearchUsed
, bSearchHidden
, bOnlyHidden
, SwGetPoolIdFromName::NumRule
, SfxStyleFamily::Pseudo
);
3065 if( nSearchFamily
== SfxStyleFamily::Table
||
3066 nSearchFamily
== SfxStyleFamily::All
)
3068 const SwTableAutoFormatTable
& rTableStyles
= rDoc
.GetTableStyles();
3069 for(size_t i
= 0; i
< rTableStyles
.size(); ++i
)
3071 const SwTableAutoFormat
& rTableStyle
= rTableStyles
[i
];
3073 bool bUsed
= bIsSearchUsed
&& (bOrganizer
|| rDoc
.IsUsed(rTableStyle
));
3076 if(nSrchMask
== SfxStyleSearchBits::Hidden
&& !rTableStyle
.IsHidden())
3079 if( (!bSearchHidden
&& rTableStyle
.IsHidden() ) ||
3080 ( (nSrchMask
& ~SfxStyleSearchBits::Used
) == SfxStyleSearchBits::UserDefined
3081 ? !rTableStyle
.IsUserDefined()
3082 // searched for used and found none
3087 m_aLst
.Append( SfxStyleFamily::Table
, rTableStyle
.GetName() );
3091 if( nSearchFamily
== SfxStyleFamily::Cell
||
3092 nSearchFamily
== SfxStyleFamily::All
)
3094 const auto& aTableTemplateMap
= SwTableAutoFormat::GetTableTemplateMap();
3095 if (rDoc
.HasTableStyles())
3097 const SwTableAutoFormatTable
& rTableStyles
= rDoc
.GetTableStyles();
3098 for(size_t i
= 0; i
< rTableStyles
.size(); ++i
)
3100 const SwTableAutoFormat
& rTableStyle
= rTableStyles
[i
];
3101 for(size_t nBoxFormat
= 0; nBoxFormat
< aTableTemplateMap
.size(); ++nBoxFormat
)
3103 const sal_uInt32 nBoxIndex
= aTableTemplateMap
[nBoxFormat
];
3104 const SwBoxAutoFormat
& rBoxFormat
= rTableStyle
.GetBoxFormat(nBoxIndex
);
3105 OUString sBoxFormatName
;
3106 SwStyleNameMapper::FillProgName(rTableStyle
.GetName(), sBoxFormatName
, SwGetPoolIdFromName::TabStyle
);
3107 sBoxFormatName
+= rTableStyle
.GetTableTemplateCellSubName(rBoxFormat
);
3108 m_aLst
.Append( SfxStyleFamily::Cell
, sBoxFormatName
);
3112 const SwCellStyleTable
& rCellStyles
= rDoc
.GetCellStyles();
3113 for(size_t i
= 0; i
< rCellStyles
.size(); ++i
)
3114 m_aLst
.Append( SfxStyleFamily::Cell
, rCellStyles
[i
].GetName() );
3119 m_nLastPos
= SAL_MAX_UINT32
;
3125 SfxStyleSheetBase
* SwStyleSheetIterator::Next()
3127 assert(m_bFirstCalled
);
3129 if(m_nLastPos
< m_aLst
.size())
3131 auto const & rEntry
= m_aLst
[m_nLastPos
];
3132 mxIterSheet
->PresetNameAndFamily(rEntry
.first
, rEntry
.second
);
3133 mxIterSheet
->SetPhysical( false );
3134 mxIterSheet
->SetMask( nMask
);
3135 if(mxIterSheet
->pSet
)
3137 mxIterSheet
->pSet
->ClearItem();
3138 mxIterSheet
->pSet
= nullptr;
3140 return mxIterSheet
.get();
3145 SfxStyleSheetBase
* SwStyleSheetIterator::Find(const OUString
& rName
)
3148 if( !m_bFirstCalled
)
3151 m_nLastPos
= m_aLst
.FindName( nSearchFamily
, rName
);
3152 if( SAL_MAX_UINT32
!= m_nLastPos
)
3155 auto const & rEntry
= m_aLst
[m_nLastPos
];
3156 mxStyleSheet
->PresetNameAndFamily(rEntry
.first
, rEntry
.second
);
3157 // new name is set, so determine its Data
3158 mxStyleSheet
->FillStyleSheet( SwDocStyleSheet::FillOnlyName
);
3159 if( !mxStyleSheet
->IsPhysical() )
3160 mxStyleSheet
->SetPhysical( false );
3162 return mxStyleSheet
.get();
3167 void SwStyleSheetIterator::AppendStyleList(const std::vector
<OUString
>& rList
,
3168 bool bTestUsed
, bool bTestHidden
, bool bOnlyHidden
,
3169 SwGetPoolIdFromName nSection
, SfxStyleFamily eFamily
)
3171 const SwDoc
& rDoc
= static_cast<const SwDocStyleSheetPool
*>(pBasePool
)->GetDoc();
3173 for (const auto & i
: rList
)
3175 bool bHidden
= false;
3176 sal_uInt16 nId
= SwStyleNameMapper::GetPoolIdFromUIName(i
, nSection
);
3179 case SwGetPoolIdFromName::TxtColl
:
3181 bUsed
= rDoc
.getIDocumentStylePoolAccess().IsPoolTextCollUsed( nId
);
3182 SwFormat
* pFormat
= rDoc
.FindTextFormatCollByName( i
);
3183 bHidden
= pFormat
&& pFormat
->IsHidden( );
3186 case SwGetPoolIdFromName::ChrFmt
:
3188 bUsed
= rDoc
.getIDocumentStylePoolAccess().IsPoolFormatUsed( nId
);
3189 SwFormat
* pFormat
= rDoc
.FindCharFormatByName( i
);
3190 bHidden
= pFormat
&& pFormat
->IsHidden( );
3193 case SwGetPoolIdFromName::FrmFmt
:
3195 bUsed
= rDoc
.getIDocumentStylePoolAccess().IsPoolFormatUsed( nId
);
3196 SwFormat
* pFormat
= rDoc
.FindFrameFormatByName( i
);
3197 bHidden
= pFormat
&& pFormat
->IsHidden( );
3200 case SwGetPoolIdFromName::PageDesc
:
3202 bUsed
= rDoc
.getIDocumentStylePoolAccess().IsPoolPageDescUsed( nId
);
3203 SwPageDesc
* pPgDesc
= rDoc
.FindPageDesc(i
);
3204 bHidden
= pPgDesc
&& pPgDesc
->IsHidden( );
3207 case SwGetPoolIdFromName::NumRule
:
3209 SwNumRule
* pRule
= rDoc
.FindNumRulePtr( i
);
3210 bUsed
= pRule
&& rDoc
.IsUsed(*pRule
);
3211 bHidden
= pRule
&& pRule
->IsHidden( );
3215 OSL_ENSURE( false, "unknown PoolFormat-Id" );
3218 bool bMatchHidden
= ( bTestHidden
&& ( bHidden
|| !bOnlyHidden
) ) || ( !bTestHidden
&& ( !bHidden
|| bUsed
) );
3219 if ( ( !bTestUsed
&& bMatchHidden
) || ( bTestUsed
&& bUsed
) )
3220 m_aLst
.Append( eFamily
, i
);
3224 void SwDocStyleSheetPool::InvalidateIterator()
3226 if (SfxStyleSheetIterator
* pIter
= GetCachedIterator())
3227 dynamic_cast<SwStyleSheetIterator
&>(*pIter
).InvalidateIterator();
3230 void SwStyleSheetIterator::InvalidateIterator()
3232 // potentially we could send an SfxHint to Notify but currently it's
3233 // iterating over the vector anyway so would still be slow - why does
3234 // this iterator not use a map?
3235 m_bFirstCalled
= false;
3240 void SwStyleSheetIterator::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
3242 // search and remove from View-List!!
3243 const SfxStyleSheetHint
* pStyleSheetHint
= dynamic_cast<const SfxStyleSheetHint
*>(&rHint
);
3244 if( pStyleSheetHint
&&
3245 SfxHintId::StyleSheetErased
== pStyleSheetHint
->GetId() )
3247 SfxStyleSheetBase
* pStyle
= pStyleSheetHint
->GetStyleSheet();
3250 m_aLst
.RemoveName(pStyle
->GetFamily(), pStyle
->GetName());
3254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */