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 final
: 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);
76 virtual ~SwDocStyleSheet() override
;
79 SwDocStyleSheet( SwDoc
& rDoc
,
80 SwDocStyleSheetPool
& rPool
);
82 SwDocStyleSheet( const SwDocStyleSheet
& );
86 void SetFamily(SfxStyleFamily eFam
) { nFamily
= eFam
; }
88 bool IsPhysical() const { return bPhysical
; }
89 void SetPhysical(bool bPhys
);
91 virtual void SetHidden( bool bHidden
) override
;
92 virtual bool IsHidden( ) const override
;
93 void SetGrabBagItem(const css::uno::Any
& rVal
);
94 void GetGrabBagItem(css::uno::Any
& rVal
) const;
96 /** add optional parameter <bResetIndentAttrsAtParagraphStyle>, default value false,
97 which indicates that the indent attributes at a paragraph style should
98 be reset in case that a list style is applied to the paragraph style and
99 no indent attributes are applied. */
100 void SetItemSet( const SfxItemSet
& rSet
,
101 const bool bResetIndentAttrsAtParagraphStyle
= false );
103 virtual SfxItemSet
& GetItemSet() override
;
104 virtual std::unique_ptr
<SfxItemSet
> GetItemSetForPreview() override
;
105 /** new method for paragraph styles to merge indent attributes of applied list
106 style into the given item set, if the list style indent attributes are applicable. */
107 void MergeIndentAttrsOfListStyle( SfxItemSet
& rSet
);
108 virtual const OUString
& GetParent() const override
;
109 virtual const OUString
& GetFollow() const override
;
111 virtual sal_uLong
GetHelpId( OUString
& rFile
) override
;
112 virtual void SetHelpId( const OUString
& r
, sal_uLong nId
) override
;
114 /** Preset the members without physical access.
115 Used by StyleSheetPool. */
116 void PresetName(const OUString
& rName
) { aName
= rName
; }
117 void PresetNameAndFamily(const OUString
& rName
);
118 void PresetParent(const OUString
& rName
){ aParent
= rName
; }
119 void PresetFollow(const OUString
& rName
){ aFollow
= rName
; }
121 virtual bool SetName(const OUString
& rNewName
, bool bReindexNow
= true) override
;
122 virtual bool SetParent( const OUString
& rStr
) override
;
123 virtual bool SetFollow( const OUString
& rStr
) override
;
125 virtual bool HasFollowSupport() const override
;
126 virtual bool HasParentSupport() const override
;
127 virtual bool HasClearParentSupport() const override
;
128 virtual OUString
GetDescription(MapUnit eUnit
) override
;
130 virtual OUString
GetUsedBy() 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
> 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
& rBase
,
179 SfxStyleFamily eFam
, SfxStyleSearchBits 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
, SfxStyleSearchBits 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 SfxStyleSearchBits nMask
= SfxStyleSearchBits::All
) override
;
210 virtual SfxStyleSheetBase
* Find( const OUString
&, SfxStyleFamily eFam
,
211 SfxStyleSearchBits n
=SfxStyleSearchBits::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::unique_ptr
<SfxStyleSheetIterator
> CreateIterator( SfxStyleFamily
, SfxStyleSearchBits 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: */