a11y: Simplify OCommonAccessibleComponent::getAccessibleIndexInParent
[LibreOffice.git] / sw / inc / docstyle.hxx
blobe45c599d2a0ba0b001c14421ed6a3631a9444fcd
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 #pragma once
21 #include <rtl/ref.hxx>
22 #include <rtl/ustring.hxx>
24 #include <svl/style.hxx>
25 #include <svl/itemset.hxx>
26 #include "swdllapi.h"
28 #include <unordered_map>
29 #include <memory>
30 #include <optional>
31 #include <vector>
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;
44 // Temporary StyleSheet.
45 class SW_DLLPUBLIC SwDocStyleSheet final : public SfxStyleSheetBase
47 friend class SwDocStyleSheetPool;
48 friend class SwStyleSheetIterator;
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;
60 bool m_bPhysical;
61 OUString m_aLink;
63 /// Make empty shell a real StyleSheet (Core).
64 SAL_DLLPRIVATE void Create();
66 /// Fill StyleSheet with data.
67 enum FillStyleType {
68 FillOnlyName,
69 FillAllInfo,
70 FillPhysical,
71 FillPreview,
74 SAL_DLLPRIVATE bool FillStyleSheet(FillStyleType eFType,
75 std::optional<SfxItemSet> * o_ppFlatSet = nullptr);
77 virtual ~SwDocStyleSheet() override;
79 public:
80 SwDocStyleSheet( SwDoc& rDoc,
81 SwDocStyleSheetPool& rPool);
83 SwDocStyleSheet( const SwDocStyleSheet& );
85 void Reset();
87 void SetFamily(SfxStyleFamily eFam) { nFamily = eFam; }
89 bool IsPhysical() const { return m_bPhysical; }
90 void SetPhysical(bool bPhys);
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;
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 );
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;
113 virtual sal_uInt32 GetHelpId( OUString& rFile ) override;
114 virtual void SetHelpId( const OUString& r, sal_uInt32 nId ) override;
116 /** Preset the members without physical access.
117 Used by StyleSheetPool. */
118 void PresetName(const OUString& rName) { aName = rName; }
119 void PresetNameAndFamily(SfxStyleFamily eFamily, 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;
126 void SetLink(const OUString& rStr);
128 virtual bool HasFollowSupport() const override;
129 virtual bool HasParentSupport() const override;
130 virtual bool HasClearParentSupport() const override;
131 virtual OUString GetDescription(MapUnit eUnit) override;
133 virtual OUString GetUsedBy() override;
135 SwCharFormat* GetCharFormat();
136 SwTextFormatColl* GetCollection();
137 SwFrameFormat* GetFrameFormat();
138 const SwPageDesc* GetPageDesc();
139 const SwNumRule* GetNumRule();
140 void SetNumRule(const SwNumRule& rRule);
141 SwTableAutoFormat* GetTableFormat();
143 virtual bool IsUsed() const override;
146 namespace std {
147 template<>
148 struct hash<std::pair<SfxStyleFamily,OUString>>
150 std::size_t operator()(std::pair<SfxStyleFamily,OUString> const & pair) const
151 { return static_cast<std::size_t>(pair.first) ^ std::size_t(pair.second.hashCode()); }
156 // Iterator for Pool.
157 class SwStyleSheetIterator final : public SfxStyleSheetIterator, public SfxListener
159 // Local helper class.
160 class SwPoolFormatList
162 std::vector<std::pair<SfxStyleFamily, OUString>> maImpl;
163 typedef std::unordered_map<std::pair<SfxStyleFamily, OUString>, sal_uInt32> UniqueHash;
164 UniqueHash maUnique;
165 void rehash();
166 public:
167 SwPoolFormatList() {}
168 void Append( SfxStyleFamily eFam, const OUString& rStr );
169 void clear() { maImpl.clear(); maUnique.clear(); }
170 size_t size() { return maImpl.size(); }
171 bool empty() { return maImpl.empty(); }
172 sal_uInt32 FindName(SfxStyleFamily eFam, const OUString& rName);
173 void RemoveName(SfxStyleFamily eFam, const OUString& rName);
174 const std::pair<SfxStyleFamily,OUString> &operator[](sal_uInt32 nIdx) { return maImpl[ nIdx ]; }
177 rtl::Reference< SwDocStyleSheet > mxIterSheet;
178 rtl::Reference< SwDocStyleSheet > mxStyleSheet;
179 SwPoolFormatList m_aLst;
180 sal_uInt32 m_nLastPos;
181 bool m_bFirstCalled;
183 bool IsUsedInComments(const OUString& rName) const;
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 rtl::Reference< SfxStyleSheetPool > mxEEStyleSheetPool;
211 SwDoc& m_rDoc;
212 bool m_bOrganizer : 1; ///< Organizer
214 virtual rtl::Reference<SfxStyleSheetBase> Create( const OUString&, SfxStyleFamily, SfxStyleSearchBits nMask, const OUString& rParentStyleSheetName) override;
215 virtual rtl::Reference<SfxStyleSheetBase> Create( const SfxStyleSheetBase& ) override;
217 using SfxStyleSheetBasePool::Find;
219 public:
220 SwDocStyleSheetPool( SwDoc&, bool bOrganizer );
222 virtual SfxStyleSheetBase& Make(const OUString&, SfxStyleFamily,
223 SfxStyleSearchBits nMask = SfxStyleSearchBits::All,
224 const OUString& rParentStyleSheetName = u""_ustr) override;
226 virtual SfxStyleSheetBase* Find( const OUString&, SfxStyleFamily eFam,
227 SfxStyleSearchBits n=SfxStyleSearchBits::All ) override;
229 virtual void Remove( SfxStyleSheetBase* pStyle) override;
231 bool IsOrganizerMode() const { return m_bOrganizer; }
233 virtual std::unique_ptr<SfxStyleSheetIterator> CreateIterator( SfxStyleFamily, SfxStyleSearchBits nMask = SfxStyleSearchBits::All) override;
235 SwDoc& GetDoc() const { return m_rDoc; }
236 SfxStyleSheetPool* GetEEStyleSheetPool() const { return mxEEStyleSheetPool.get(); }
238 void dispose();
240 void InvalidateIterator();
242 private:
243 virtual ~SwDocStyleSheetPool() override;
245 SwDocStyleSheetPool( const SwDocStyleSheetPool& ) = delete;
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */