Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / inc / docstyle.hxx
blobd727245c059e94ef30c9ef8ca7773973c085b402
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
27 #include "swdllapi.h"
29 #include <unordered_map>
30 #include <memory>
31 #include <optional>
32 #include <vector>
34 class SwDoc;
35 class SwDocStyleSheetPool;
36 class SwPageDesc;
37 class SwCharFormat;
38 class SwTextFormatColl;
39 class SwFrameFormat;
40 class SwNumRule;
41 class SwTableAutoFormat;
42 class SwBoxAutoFormat;
43 enum class SwGetPoolIdFromName : sal_uInt16;
45 // Temporary StyleSheet.
46 class SW_DLLPUBLIC SwDocStyleSheet final : public SfxStyleSheetBase
48 friend class SwDocStyleSheetPool;
49 friend class SwStyleSheetIterator;
51 SwCharFormat* m_pCharFormat;
52 SwTextFormatColl* m_pColl;
53 SwFrameFormat* m_pFrameFormat;
54 const SwPageDesc* m_pDesc;
55 const SwNumRule* m_pNumRule;
56 SwTableAutoFormat* m_pTableFormat;
57 const SwBoxAutoFormat* m_pBoxFormat;
58 SwDoc& m_rDoc;
59 SfxItemSet m_aCoreSet;
61 bool m_bPhysical;
62 OUString m_aLink;
64 /// Make empty shell a real StyleSheet (Core).
65 SAL_DLLPRIVATE void Create();
67 /// Fill StyleSheet with data.
68 enum FillStyleType {
69 FillOnlyName,
70 FillAllInfo,
71 FillPhysical,
72 FillPreview,
75 SAL_DLLPRIVATE bool FillStyleSheet(FillStyleType eFType,
76 std::optional<SfxItemSet> * o_ppFlatSet = nullptr);
78 virtual ~SwDocStyleSheet() override;
80 public:
81 SwDocStyleSheet( SwDoc& rDoc,
82 SwDocStyleSheetPool& rPool);
84 SwDocStyleSheet( const SwDocStyleSheet& );
86 void Reset();
88 void SetFamily(SfxStyleFamily eFam) { nFamily = eFam; }
90 bool IsPhysical() const { return m_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::optional<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;
112 const OUString& GetLink() const;
114 virtual sal_uLong GetHelpId( OUString& rFile ) override;
115 virtual void SetHelpId( const OUString& r, sal_uLong nId ) override;
117 /** Preset the members without physical access.
118 Used by StyleSheetPool. */
119 void PresetName(const OUString& rName) { aName = rName; }
120 void PresetNameAndFamily(SfxStyleFamily eFamily, const OUString& rName);
121 void PresetParent(const OUString& rName){ aParent = rName; }
122 void PresetFollow(const OUString& rName){ aFollow = rName; }
124 virtual bool SetName(const OUString& rNewName, bool bReindexNow = true) override;
125 virtual bool SetParent( const OUString& rStr) override;
126 virtual bool SetFollow( const OUString& rStr) override;
127 void SetLink(const OUString& rStr);
129 virtual bool HasFollowSupport() const override;
130 virtual bool HasParentSupport() const override;
131 virtual bool HasClearParentSupport() const override;
132 virtual OUString GetDescription(MapUnit eUnit) override;
134 virtual OUString GetUsedBy() override;
136 SwCharFormat* GetCharFormat();
137 SwTextFormatColl* GetCollection();
138 SwFrameFormat* GetFrameFormat();
139 const SwPageDesc* GetPageDesc();
140 const SwNumRule* GetNumRule();
141 void SetNumRule(const SwNumRule& rRule);
142 SwTableAutoFormat* GetTableFormat();
144 virtual bool IsUsed() const override;
147 namespace std {
148 template<>
149 struct hash<std::pair<SfxStyleFamily,OUString>>
151 std::size_t operator()(std::pair<SfxStyleFamily,OUString> const & pair) const
152 { return static_cast<std::size_t>(pair.first) ^ std::size_t(pair.second.hashCode()); }
157 // Iterator for Pool.
158 class SwStyleSheetIterator final : public SfxStyleSheetIterator, public SfxListener
160 // Local helper class.
161 class SwPoolFormatList
163 std::vector<std::pair<SfxStyleFamily, OUString>> maImpl;
164 typedef std::unordered_map<std::pair<SfxStyleFamily, OUString>, sal_uInt32> UniqueHash;
165 UniqueHash maUnique;
166 void rehash();
167 public:
168 SwPoolFormatList() {}
169 void Append( SfxStyleFamily eFam, const OUString& rStr );
170 void clear() { maImpl.clear(); maUnique.clear(); }
171 size_t size() { return maImpl.size(); }
172 bool empty() { return maImpl.empty(); }
173 sal_uInt32 FindName(SfxStyleFamily eFam, const OUString& rName);
174 void RemoveName(SfxStyleFamily eFam, const OUString& rName);
175 const std::pair<SfxStyleFamily,OUString> &operator[](sal_uInt32 nIdx) { return maImpl[ nIdx ]; }
178 rtl::Reference< SwDocStyleSheet > mxIterSheet;
179 rtl::Reference< SwDocStyleSheet > mxStyleSheet;
180 SwPoolFormatList m_aLst;
181 sal_uInt32 m_nLastPos;
182 bool m_bFirstCalled;
184 void AppendStyleList(const std::vector<OUString>& rLst,
185 bool bUsed,
186 bool bTestHidden,
187 bool bOnlyHidden,
188 SwGetPoolIdFromName nSection,
189 SfxStyleFamily eFamily);
191 public:
192 SwStyleSheetIterator(SwDocStyleSheetPool& rBase,
193 SfxStyleFamily eFam, SfxStyleSearchBits n);
194 virtual ~SwStyleSheetIterator() override;
196 virtual sal_Int32 Count() override;
197 virtual SfxStyleSheetBase *operator[](sal_Int32 nIdx) override;
198 virtual SfxStyleSheetBase* First() override;
199 virtual SfxStyleSheetBase* Next() override;
200 virtual SfxStyleSheetBase* Find(const OUString& rStr) override;
202 virtual void Notify( SfxBroadcaster&, const SfxHint& ) override;
204 void InvalidateIterator();
207 class SwDocStyleSheetPool final : public SfxStyleSheetBasePool
209 rtl::Reference< SwDocStyleSheet > mxStyleSheet;
210 SwDoc& m_rDoc;
211 bool m_bOrganizer : 1; ///< Organizer
213 virtual rtl::Reference<SfxStyleSheetBase> Create( const OUString&, SfxStyleFamily, SfxStyleSearchBits nMask) override;
214 virtual rtl::Reference<SfxStyleSheetBase> Create( const SfxStyleSheetBase& ) override;
216 using SfxStyleSheetBasePool::Find;
218 public:
219 SwDocStyleSheetPool( SwDoc&, bool bOrganizer );
221 virtual SfxStyleSheetBase& Make(const OUString&, SfxStyleFamily,
222 SfxStyleSearchBits nMask = SfxStyleSearchBits::All) override;
224 virtual SfxStyleSheetBase* Find( const OUString&, SfxStyleFamily eFam,
225 SfxStyleSearchBits n=SfxStyleSearchBits::All ) const override;
227 virtual bool SetParent( SfxStyleFamily eFam, const OUString &rStyle,
228 const OUString &rParent ) override;
230 virtual void Remove( SfxStyleSheetBase* pStyle) override;
232 bool IsOrganizerMode() const { return m_bOrganizer; }
234 virtual std::unique_ptr<SfxStyleSheetIterator> CreateIterator( SfxStyleFamily, SfxStyleSearchBits nMask = SfxStyleSearchBits::All) override;
236 SwDoc& GetDoc() const { return m_rDoc; }
238 void dispose();
240 void InvalidateIterator();
242 private:
243 virtual ~SwDocStyleSheetPool() override;
245 SwDocStyleSheetPool( const SwDocStyleSheetPool& ) = delete;
248 #endif
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */