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 .
19 #ifndef INCLUDED_SW_INC_DOCSTYLE_HXX
20 #define INCLUDED_SW_INC_DOCSTYLE_HXX
22 #include <rtl/ref.hxx>
23 #include <rtl/ustring.hxx>
25 #include <svl/style.hxx>
26 #include <svl/itemset.hxx>
29 #include <unordered_map>
34 class SwDocStyleSheetPool
;
37 class SwTextFormatColl
;
40 class SwTableAutoFormat
;
41 class SwBoxAutoFormat
;
42 enum class SwGetPoolIdFromName
: sal_uInt16
;
44 // Temporary StyleSheet.
45 class SW_DLLPUBLIC SwDocStyleSheet
: public SfxStyleSheetBase
47 friend class SwDocStyleSheetPool
;
48 friend class SwStyleSheetIterator
;
50 SwCharFormat
* pCharFormat
;
51 SwTextFormatColl
* pColl
;
52 SwFrameFormat
* pFrameFormat
;
53 const SwPageDesc
* pDesc
;
54 const SwNumRule
* pNumRule
;
55 SwTableAutoFormat
* pTableFormat
;
56 const SwBoxAutoFormat
* pBoxFormat
;
62 /// Make empty shell a real StyleSheet (Core).
63 SAL_DLLPRIVATE
void Create();
65 /// Fill StyleSheet with data.
73 SAL_DLLPRIVATE
bool FillStyleSheet(FillStyleType eFType
,
74 std::unique_ptr
<SfxItemSet
> * o_ppFlatSet
= nullptr);
77 virtual ~SwDocStyleSheet() override
;
80 SwDocStyleSheet( SwDoc
& rDoc
,
81 SwDocStyleSheetPool
* pPool
);
83 SwDocStyleSheet( const SwDocStyleSheet
& );
87 void SetMask(sal_uInt16 nMsk
) { nMask
= nMsk
; }
88 void SetFamily(SfxStyleFamily eFam
) { nFamily
= eFam
; }
90 bool IsPhysical() const { return bPhysical
; }
91 void SetPhysical(bool bPhys
);
93 virtual void SetHidden( bool bHidden
) override
;
94 virtual bool IsHidden( ) const override
;
95 void SetGrabBagItem(const css::uno::Any
& rVal
);
96 void GetGrabBagItem(css::uno::Any
& rVal
) const;
98 /** add optional parameter <bResetIndentAttrsAtParagraphStyle>, default value false,
99 which indicates that the indent attributes at a paragraph style should
100 be reset in case that a list style is applied to the paragraph style and
101 no indent attributes are applied. */
102 void SetItemSet( const SfxItemSet
& rSet
,
103 const bool bResetIndentAttrsAtParagraphStyle
= false );
105 virtual SfxItemSet
& GetItemSet() override
;
106 virtual std::unique_ptr
<SfxItemSet
> GetItemSetForPreview() override
;
107 /** new method for paragraph styles to merge indent attributes of applied list
108 style into the given item set, if the list style indent attributes are applicable. */
109 void MergeIndentAttrsOfListStyle( SfxItemSet
& rSet
);
110 virtual const OUString
& GetParent() const override
;
111 virtual const OUString
& GetFollow() const override
;
113 virtual sal_uLong
GetHelpId( OUString
& rFile
) override
;
114 virtual void SetHelpId( const OUString
& r
, sal_uLong nId
) override
;
116 /** Preset the members without physical access.
117 Used by StyleSheetPool. */
118 void PresetName(const OUString
& rName
) { aName
= rName
; }
119 void PresetNameAndFamily(const OUString
& rName
);
120 void PresetParent(const OUString
& rName
){ aParent
= rName
; }
121 void PresetFollow(const OUString
& rName
){ aFollow
= rName
; }
123 virtual bool SetName(const OUString
& rNewName
, bool bReindexNow
= true) override
;
124 virtual bool SetParent( const OUString
& rStr
) override
;
125 virtual bool SetFollow( const OUString
& rStr
) override
;
127 virtual bool HasFollowSupport() const override
;
128 virtual bool HasParentSupport() const override
;
129 virtual bool HasClearParentSupport() const override
;
130 virtual OUString
GetDescription(MapUnit eUnit
) override
;
132 SwCharFormat
* GetCharFormat();
133 SwTextFormatColl
* GetCollection();
134 SwFrameFormat
* GetFrameFormat();
135 const SwPageDesc
* GetPageDesc();
136 const SwNumRule
* GetNumRule();
137 void SetNumRule(const SwNumRule
& rRule
);
138 SwTableAutoFormat
* GetTableFormat();
140 virtual bool IsUsed() const override
;
143 // Iterator for Pool.
144 class SwStyleSheetIterator
: public SfxStyleSheetIterator
, public SfxListener
146 // Local helper class.
147 class SwPoolFormatList
149 std::vector
<OUString
> maImpl
;
150 typedef std::unordered_map
<OUString
, sal_uInt32
, OUStringHash
> UniqueHash
;
154 SwPoolFormatList() {}
155 void Append( char cChar
, const OUString
& rStr
);
156 void clear() { maImpl
.clear(); maUnique
.clear(); }
157 size_t size() { return maImpl
.size(); }
158 bool empty() { return maImpl
.empty(); }
159 sal_uInt32
FindName(SfxStyleFamily eFam
, const OUString
&rName
);
160 void RemoveName(SfxStyleFamily eFam
, const OUString
&rName
);
161 const OUString
&operator[](sal_uInt32 nIdx
) { return maImpl
[ nIdx
]; }
164 rtl::Reference
< SwDocStyleSheet
> mxIterSheet
;
165 rtl::Reference
< SwDocStyleSheet
> mxStyleSheet
;
166 SwPoolFormatList aLst
;
170 void AppendStyleList(const std::vector
<OUString
>& rLst
,
174 SwGetPoolIdFromName nSection
,
178 SwStyleSheetIterator( SwDocStyleSheetPool
* pBase
,
179 SfxStyleFamily eFam
, sal_uInt16 n
);
180 virtual ~SwStyleSheetIterator() override
;
182 virtual sal_uInt16
Count() override
;
183 virtual SfxStyleSheetBase
*operator[](sal_uInt16 nIdx
) override
;
184 virtual SfxStyleSheetBase
* First() override
;
185 virtual SfxStyleSheetBase
* Next() override
;
186 virtual SfxStyleSheetBase
* Find(const OUString
& rStr
) override
;
188 virtual void Notify( SfxBroadcaster
&, const SfxHint
& ) override
;
190 void InvalidateIterator();
193 class SwDocStyleSheetPool
: public SfxStyleSheetBasePool
195 rtl::Reference
< SwDocStyleSheet
> mxStyleSheet
;
197 bool bOrganizer
: 1; ///< Organizer
199 virtual SfxStyleSheetBase
* Create( const OUString
&, SfxStyleFamily
, sal_uInt16 nMask
) override
;
200 virtual SfxStyleSheetBase
* Create( const SfxStyleSheetBase
& ) override
;
202 using SfxStyleSheetBasePool::Find
;
205 SwDocStyleSheetPool( SwDoc
&, bool bOrganizer
);
207 virtual SfxStyleSheetBase
& Make(const OUString
&, SfxStyleFamily
,
208 sal_uInt16 nMask
= SFXSTYLEBIT_ALL
) override
;
210 virtual SfxStyleSheetBase
* Find( const OUString
&, SfxStyleFamily eFam
,
211 sal_uInt16 n
=SFXSTYLEBIT_ALL
) override
;
213 virtual bool SetParent( SfxStyleFamily eFam
, const OUString
&rStyle
,
214 const OUString
&rParent
) override
;
216 virtual void Remove( SfxStyleSheetBase
* pStyle
) override
;
218 bool IsOrganizerMode() const { return bOrganizer
; }
220 virtual std::shared_ptr
<SfxStyleSheetIterator
> CreateIterator( SfxStyleFamily
, sal_uInt16 nMask
) override
;
222 SwDoc
& GetDoc() const { return rDoc
; }
226 void InvalidateIterator();
229 virtual ~SwDocStyleSheetPool() override
;
232 SwDocStyleSheetPool( const SwDocStyleSheetPool
& ) = delete;
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */