/src/libreoffice/sw/inc/docstyle.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | #pragma once |
20 | | |
21 | | #include <rtl/ref.hxx> |
22 | | #include <rtl/ustring.hxx> |
23 | | |
24 | | #include <svl/style.hxx> |
25 | | #include <svl/itemset.hxx> |
26 | | #include "swdllapi.h" |
27 | | |
28 | | #include <unordered_map> |
29 | | #include <memory> |
30 | | #include <optional> |
31 | | #include <vector> |
32 | | |
33 | | class SwDoc; |
34 | | class SwDocStyleSheetPool; |
35 | | class SwPageDesc; |
36 | | class SwCharFormat; |
37 | | class SwTextFormatColl; |
38 | | class SwFrameFormat; |
39 | | class SwNumRule; |
40 | | class SwTableAutoFormat; |
41 | | class SwBoxAutoFormat; |
42 | | enum class SwGetPoolIdFromName : sal_uInt16; |
43 | | |
44 | | // Temporary StyleSheet. |
45 | | class SW_DLLPUBLIC SwDocStyleSheet final : public SfxStyleSheetBase |
46 | | { |
47 | | friend class SwDocStyleSheetPool; |
48 | | friend class SwStyleSheetIterator; |
49 | | |
50 | | SwCharFormat* m_pCharFormat; |
51 | | SwTextFormatColl* m_pColl; |
52 | | SwFrameFormat* m_pFrameFormat; |
53 | | const SwPageDesc* m_pDesc; |
54 | | const SwNumRule* m_pNumRule; |
55 | | SwTableAutoFormat* m_pTableFormat; |
56 | | const SwBoxAutoFormat* m_pBoxFormat; |
57 | | SwDoc& m_rDoc; |
58 | | SfxItemSet m_aCoreSet; |
59 | | |
60 | | bool m_bPhysical; |
61 | | OUString m_aLink; |
62 | | |
63 | | /// Make empty shell a real StyleSheet (Core). |
64 | | SAL_DLLPRIVATE void Create(); |
65 | | |
66 | | /// Fill StyleSheet with data. |
67 | | enum FillStyleType { |
68 | | FillOnlyName, |
69 | | FillAllInfo, |
70 | | FillPhysical, |
71 | | FillPreview, |
72 | | }; |
73 | | |
74 | | SAL_DLLPRIVATE bool FillStyleSheet(FillStyleType eFType, |
75 | | std::optional<SfxItemSet> * o_ppFlatSet = nullptr); |
76 | | |
77 | | virtual ~SwDocStyleSheet() override; |
78 | | |
79 | | public: |
80 | | SwDocStyleSheet( SwDoc& rDoc, |
81 | | SwDocStyleSheetPool& rPool); |
82 | | |
83 | | SwDocStyleSheet( const SwDocStyleSheet& ); |
84 | | |
85 | | void Reset(); |
86 | | |
87 | 2.93M | void SetFamily(SfxStyleFamily eFam) { nFamily = eFam; } |
88 | | |
89 | 2.91M | bool IsPhysical() const { return m_bPhysical; } |
90 | | void SetPhysical(bool bPhys); |
91 | | |
92 | | virtual void SetHidden( bool bHidden ) override; |
93 | | virtual bool IsHidden( ) const override; |
94 | | void SetGrabBagItem(const css::uno::Any& rVal); |
95 | | void GetGrabBagItem(css::uno::Any& rVal) const; |
96 | | |
97 | | /** add optional parameter <bResetIndentAttrsAtParagraphStyle>, default value false, |
98 | | which indicates that the indent attributes at a paragraph style should |
99 | | be reset in case that a list style is applied to the paragraph style and |
100 | | no indent attributes are applied. */ |
101 | | void SetItemSet( const SfxItemSet& rSet, const bool bBroadcast = true, |
102 | | const bool bResetIndentAttrsAtParagraphStyle = false ); |
103 | | |
104 | | virtual SfxItemSet& GetItemSet() override; |
105 | | virtual std::optional<SfxItemSet> GetItemSetForPreview() override; |
106 | | /** new method for paragraph styles to merge indent attributes of applied list |
107 | | style into the given item set, if the list style indent attributes are applicable. */ |
108 | | void MergeIndentAttrsOfListStyle( SfxItemSet& rSet ); |
109 | | virtual const OUString& GetParent() const override; |
110 | | virtual const OUString& GetFollow() const override; |
111 | | const OUString& GetLink() const; |
112 | | |
113 | | virtual sal_uInt32 GetHelpId( OUString& rFile ) override; |
114 | | virtual void SetHelpId( const OUString& r, sal_uInt32 nId ) override; |
115 | | |
116 | | virtual sal_Int32 GetSpotlightId() override; |
117 | | |
118 | | /** Preset the members without physical access. |
119 | | Used by StyleSheetPool. */ |
120 | 2.93M | void PresetName(const OUString& rName) { aName = rName; } |
121 | | void PresetNameAndFamily(SfxStyleFamily eFamily, const OUString& rName); |
122 | 2.29M | void PresetParent(const OUString& rName){ aParent = rName; } |
123 | 4.20M | void PresetFollow(const OUString& rName){ aFollow = rName; } |
124 | | |
125 | | virtual bool SetName(const OUString& rNewName, bool bReindexNow = true) override; |
126 | | virtual bool SetParent( const OUString& rStr) override; |
127 | | virtual bool SetFollow( const OUString& rStr) override; |
128 | | void SetLink(const OUString& rStr); |
129 | | |
130 | | virtual bool HasFollowSupport() const override; |
131 | | virtual bool HasParentSupport() const override; |
132 | | virtual bool HasClearParentSupport() const override; |
133 | | virtual OUString GetDescription(MapUnit eUnit) override; |
134 | | |
135 | | virtual OUString GetUsedBy() override; |
136 | | |
137 | | SwCharFormat* GetCharFormat(); |
138 | | SwTextFormatColl* GetCollection(); |
139 | | SwFrameFormat* GetFrameFormat(); |
140 | | const SwPageDesc* GetPageDesc(); |
141 | | const SwNumRule* GetNumRule(); |
142 | | void SetNumRule(const SwNumRule& rRule); |
143 | | SwTableAutoFormat* GetTableFormat(); |
144 | | |
145 | | virtual bool IsUsed() const override; |
146 | | }; |
147 | | |
148 | | // Iterator for Pool. |
149 | | class SwStyleSheetIterator final : public SfxStyleSheetIterator, public SfxListener |
150 | | { |
151 | | // Local helper class. |
152 | | class SwPoolFormatList |
153 | | { |
154 | | struct Hash |
155 | | { |
156 | | size_t operator()(const std::pair<SfxStyleFamily, UIName>& p) const |
157 | 55.6k | { |
158 | 55.6k | return std::hash<SfxStyleFamily>()(p.first) ^ std::hash<UIName>()(p.second); |
159 | 55.6k | } |
160 | | }; |
161 | | std::vector<std::pair<SfxStyleFamily, UIName>> maImpl; |
162 | | typedef std::unordered_map<std::pair<SfxStyleFamily, UIName>, sal_uInt32, Hash> UniqueHash; |
163 | | UniqueHash maUnique; |
164 | | void rehash(); |
165 | | public: |
166 | 1.10k | SwPoolFormatList() {} |
167 | | void Append( SfxStyleFamily eFam, const UIName& rStr ); |
168 | 1.10k | void clear() { maImpl.clear(); maUnique.clear(); } |
169 | 29.0k | size_t size() { return maImpl.size(); } |
170 | 1.10k | bool empty() { return maImpl.empty(); } |
171 | | sal_uInt32 FindName(SfxStyleFamily eFam, const UIName& rName); |
172 | | void RemoveName(SfxStyleFamily eFam, const UIName& rName); |
173 | 27.9k | const std::pair<SfxStyleFamily,UIName> &operator[](sal_uInt32 nIdx) { return maImpl[ nIdx ]; } |
174 | | }; |
175 | | |
176 | | rtl::Reference< SwDocStyleSheet > mxIterSheet; |
177 | | rtl::Reference< SwDocStyleSheet > mxStyleSheet; |
178 | | SwPoolFormatList m_aLst; |
179 | | sal_uInt32 m_nLastPos; |
180 | | bool m_bFirstCalled; |
181 | | |
182 | | bool IsUsedInComments(const UIName& rName) const; |
183 | | void AppendStyleList(const std::vector<OUString>& rLst, |
184 | | bool bUsed, |
185 | | bool bTestHidden, |
186 | | bool bOnlyHidden, |
187 | | SwGetPoolIdFromName nSection, |
188 | | SfxStyleFamily eFamily); |
189 | | |
190 | | public: |
191 | | SwStyleSheetIterator(SwDocStyleSheetPool& rBase, |
192 | | SfxStyleFamily eFam, SfxStyleSearchBits n); |
193 | | virtual ~SwStyleSheetIterator() override; |
194 | | |
195 | | virtual sal_Int32 Count() override; |
196 | | virtual SfxStyleSheetBase *operator[](sal_Int32 nIdx) override; |
197 | | virtual SfxStyleSheetBase* First() override; |
198 | | virtual SfxStyleSheetBase* Next() override; |
199 | | virtual SfxStyleSheetBase* Find(const OUString& rStr) override; |
200 | | |
201 | | virtual void Notify( SfxBroadcaster&, const SfxHint& ) override; |
202 | | |
203 | | void InvalidateIterator(); |
204 | | }; |
205 | | |
206 | | class SwDocStyleSheetPool final : public SfxStyleSheetBasePool |
207 | | { |
208 | | rtl::Reference< SwDocStyleSheet > mxStyleSheet; |
209 | | rtl::Reference< SfxStyleSheetPool > mxEEStyleSheetPool; |
210 | | SwDoc& m_rDoc; |
211 | | bool m_bOrganizer : 1; ///< Organizer |
212 | | |
213 | | virtual rtl::Reference<SfxStyleSheetBase> Create( const OUString&, SfxStyleFamily, SfxStyleSearchBits nMask, const OUString& rParentStyleSheetName) override; |
214 | | virtual rtl::Reference<SfxStyleSheetBase> Create( const SfxStyleSheetBase& ) override; |
215 | | |
216 | | using SfxStyleSheetBasePool::Find; |
217 | | |
218 | | public: |
219 | | SwDocStyleSheetPool( SwDoc&, bool bOrganizer ); |
220 | | |
221 | | virtual SfxStyleSheetBase& Make(const OUString&, SfxStyleFamily, |
222 | | SfxStyleSearchBits nMask = SfxStyleSearchBits::All, |
223 | | const OUString& rParentStyleSheetName = u""_ustr) override; |
224 | | |
225 | | virtual SfxStyleSheetBase* Find( const OUString&, SfxStyleFamily eFam, |
226 | | SfxStyleSearchBits n=SfxStyleSearchBits::All ) override; |
227 | | |
228 | | virtual void Remove( SfxStyleSheetBase* pStyle) override; |
229 | | |
230 | 1.10k | bool IsOrganizerMode() const { return m_bOrganizer; } |
231 | | |
232 | | virtual std::unique_ptr<SfxStyleSheetIterator> CreateIterator( SfxStyleFamily, SfxStyleSearchBits nMask = SfxStyleSearchBits::All) override; |
233 | | |
234 | 5.16k | SwDoc& GetDoc() const { return m_rDoc; } |
235 | 4.08k | SfxStyleSheetPool* GetEEStyleSheetPool() const { return mxEEStyleSheetPool.get(); } |
236 | | |
237 | | void dispose(); |
238 | | |
239 | | void InvalidateIterator(); |
240 | | |
241 | | private: |
242 | | virtual ~SwDocStyleSheetPool() override; |
243 | | |
244 | | SwDocStyleSheetPool( const SwDocStyleSheetPool& ) = delete; |
245 | | }; |
246 | | |
247 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |