lok: avoid expensive fetching of a property.
[LibreOffice.git] / sw / inc / fmtcol.hxx
blob07f157f13bf2a76c079d08c4a89c0bd6fba1941c
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_FMTCOL_HXX
20 #define INCLUDED_SW_INC_FMTCOL_HXX
22 #include "swdllapi.h"
23 #include "format.hxx"
24 #include "hintids.hxx"
25 #include "paratr.hxx"
26 #include <rtl/ustring.hxx>
27 #include <tools/solar.h>
29 #include <vector>
30 #include <memory>
32 class SwAttrPool;
33 namespace sw{ class DocumentStylePoolManager; }
35 class SAL_DLLPUBLIC_RTTI SwFormatColl: public SwFormat
37 protected:
38 SwFormatColl( SwAttrPool& rPool, const char* pFormatName,
39 const sal_uInt16* pWhichRanges, SwFormatColl* pDerFrom,
40 sal_uInt16 nFormatWhich )
41 : SwFormat( rPool, pFormatName, pWhichRanges, pDerFrom, nFormatWhich )
42 { SetAuto(false); }
44 SwFormatColl( SwAttrPool& rPool, const OUString &rFormatName,
45 const sal_uInt16* pWhichRanges, SwFormatColl* pDerFrom,
46 sal_uInt16 nFormatWhich )
47 : SwFormat( rPool, rFormatName, pWhichRanges, pDerFrom, nFormatWhich )
48 { SetAuto(false); }
50 private:
51 SwFormatColl(const SwFormatColl & ) = delete;
52 const SwFormatColl &operator=(const SwFormatColl &) = delete;
55 /// Represents the style of a paragraph.
56 class SW_DLLPUBLIC SwTextFormatColl
57 : public SwFormatColl
58 , public sw::FormatDropDefiner
60 friend class SwDoc;
61 friend class ::sw::DocumentStylePoolManager;
63 SwTextFormatColl(const SwTextFormatColl & rRef) = delete;
65 bool mbStayAssignedToListLevelOfOutlineStyle;
67 bool mbAssignedToOutlineStyle;
69 SwTextFormatColl *mpNextTextFormatColl;
71 protected:
72 SwTextFormatColl( SwAttrPool& rPool, const char* pFormatCollName,
73 SwTextFormatColl* pDerFrom = nullptr,
74 sal_uInt16 nFormatWh = RES_TXTFMTCOLL )
75 : SwFormatColl(rPool, pFormatCollName, aTextFormatCollSetRange, pDerFrom, nFormatWh)
76 , mbStayAssignedToListLevelOfOutlineStyle(false)
77 , mbAssignedToOutlineStyle(false)
79 mpNextTextFormatColl = this;
82 SwTextFormatColl( SwAttrPool& rPool, const OUString &rFormatCollName,
83 SwTextFormatColl* pDerFrom,
84 sal_uInt16 nFormatWh = RES_TXTFMTCOLL )
85 : SwFormatColl(rPool, rFormatCollName, aTextFormatCollSetRange, pDerFrom, nFormatWh)
86 , mbStayAssignedToListLevelOfOutlineStyle(false)
87 , mbAssignedToOutlineStyle(false)
89 mpNextTextFormatColl = this;
92 /// To get UL- / LR- / FontHeight-changes.
93 virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
95 public:
96 inline void SetNextTextFormatColl(SwTextFormatColl& rNext);
97 SwTextFormatColl& GetNextTextFormatColl() const { return *mpNextTextFormatColl; }
99 bool IsAtDocNodeSet() const;
101 void SetAttrOutlineLevel( int );
102 int GetAttrOutlineLevel() const;
104 // Return the list level of the Outline Style - the List Style for the
105 // outline numbering -
106 // to which the Paragraph Style is assigned.
107 int GetAssignedOutlineStyleLevel() const;
109 bool IsAssignedToListLevelOfOutlineStyle() const
111 return mbAssignedToOutlineStyle;
114 // If a Paragraph Style is assigned to list level N of the Outline Style,
115 // then its outline level - AttrOutlineLevel - is set to N+1
116 void AssignToListLevelOfOutlineStyle(const int nAssignedListLevel);
117 void DeleteAssignmentToListLevelOfOutlineStyle();
119 /** Override to recognize changes on the <SwNumRuleItem> and register/unregister
120 the paragragh style at the corresponding <SwNumRule> instance. */
121 virtual bool SetFormatAttr( const SfxPoolItem& rAttr ) override;
122 virtual bool SetFormatAttr( const SfxItemSet& rSet ) override;
123 virtual bool ResetFormatAttr( sal_uInt16 nWhich1, sal_uInt16 nWhich2 = 0 ) override;
125 /// Override <ResetAllFormatAttr()> to stay assigned to list level of outline style.
126 virtual sal_uInt16 ResetAllFormatAttr() override;
128 bool StayAssignedToListLevelOfOutlineStyle() const
130 return mbStayAssignedToListLevelOfOutlineStyle;
133 bool AreListLevelIndentsApplicable() const;
135 void dumpAsXml(xmlTextWriterPtr pWriter) const;
136 virtual void FormatDropNotify(const SwFormatDrop& rDrop) override
138 if(HasWriterListeners() && !IsModifyLocked())
139 CallSwClientNotify(sw::LegacyModifyHint(&rDrop, &rDrop));
143 class SwGrfFormatColl final : public SwFormatColl
145 friend class SwDoc;
147 SwGrfFormatColl( SwAttrPool& rPool, const char* pFormatCollName,
148 SwGrfFormatColl* pDerFrom = nullptr )
149 : SwFormatColl( rPool, pFormatCollName, aGrfFormatCollSetRange,
150 pDerFrom, RES_GRFFMTCOLL )
153 SwGrfFormatColl( SwAttrPool& rPool, const OUString &rFormatCollName,
154 SwGrfFormatColl* pDerFrom )
155 : SwFormatColl( rPool, rFormatCollName, aGrfFormatCollSetRange,
156 pDerFrom, RES_GRFFMTCOLL )
160 // FEATURE::CONDCOLL
161 /// Conditional styles.
162 enum class Master_CollCondition
164 NONE,
165 PARA_IN_LIST,
166 PARA_IN_OUTLINE,
167 PARA_IN_FRAME,
168 PARA_IN_TABLEHEAD,
169 PARA_IN_TABLEBODY,
170 PARA_IN_SECTION,
171 PARA_IN_FOOTNOTE,
172 PARA_IN_FOOTER,
173 PARA_IN_HEADER,
174 PARA_IN_ENDNOTE
177 class SW_DLLPUBLIC SwCollCondition final : public SwClient
179 Master_CollCondition m_nCondition;
180 sal_uLong m_nSubCondition;
182 public:
184 SwCollCondition( SwTextFormatColl* pColl, Master_CollCondition nMasterCond,
185 sal_uLong nSubCond );
186 virtual ~SwCollCondition() override;
188 /// @@@ public copy ctor, but no copy assignment?
189 SwCollCondition( const SwCollCondition& rCpy );
190 private:
191 /// @@@ public copy ctor, but no copy assignment?
192 SwCollCondition & operator= (const SwCollCondition &) = delete;
193 public:
195 bool operator==( const SwCollCondition& rCmp ) const;
197 Master_CollCondition GetCondition() const { return m_nCondition; }
198 sal_uLong GetSubCondition() const { return m_nSubCondition; }
200 void SetCondition( Master_CollCondition nCond, sal_uLong nSubCond );
201 SwTextFormatColl* GetTextFormatColl() const { return const_cast<SwTextFormatColl*>(static_cast<const SwTextFormatColl*>(GetRegisteredIn())); }
202 void RegisterToFormat( SwFormat& );
205 using SwFormatCollConditions = std::vector<std::unique_ptr<SwCollCondition>>;
207 class SW_DLLPUBLIC SwConditionTextFormatColl final : public SwTextFormatColl
209 friend class SwDoc;
210 friend class ::sw::DocumentStylePoolManager;
212 SwFormatCollConditions m_CondColls;
214 SwConditionTextFormatColl( SwAttrPool& rPool, const OUString &rFormatCollName,
215 SwTextFormatColl* pDerFrom )
216 : SwTextFormatColl( rPool, rFormatCollName, pDerFrom, RES_CONDTXTFMTCOLL )
219 public:
221 virtual ~SwConditionTextFormatColl() override;
223 const SwCollCondition* HasCondition( const SwCollCondition& rCond ) const;
224 const SwFormatCollConditions& GetCondColls() const { return m_CondColls; }
225 void InsertCondition( const SwCollCondition& rCond );
226 void RemoveCondition( const SwCollCondition& rCond );
228 void SetConditions( const SwFormatCollConditions& );
231 // FEATURE::CONDCOLL
232 /// Inline implementations.
233 inline void SwTextFormatColl::SetNextTextFormatColl( SwTextFormatColl& rNext )
235 mpNextTextFormatColl = &rNext;
237 #endif
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */