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 #ifndef INCLUDED_SW_INC_FMTCOL_HXX
20 #define INCLUDED_SW_INC_FMTCOL_HXX
21 
22 #include "swdllapi.h"
23 #include "format.hxx"
24 #include "hintids.hxx"
25 #include <rtl/ustring.hxx>
26 #include <tools/solar.h>
27 
28 #include <vector>
29 #include <memory>
30 
31 class SwAttrPool;
32 namespace sw{ class DocumentStylePoolManager; }
33 
34 class SAL_DLLPUBLIC_RTTI SwFormatColl : public SwFormat
35 {
36 protected:
SwFormatColl(SwAttrPool & rPool,const sal_Char * pFormatName,const sal_uInt16 * pWhichRanges,SwFormatColl * pDerFrom,sal_uInt16 nFormatWhich)37     SwFormatColl( SwAttrPool& rPool, const sal_Char* pFormatName,
38                 const sal_uInt16* pWhichRanges, SwFormatColl* pDerFrom,
39                 sal_uInt16 nFormatWhich )
40           : SwFormat( rPool, pFormatName, pWhichRanges, pDerFrom, nFormatWhich )
41     { SetAuto(false); }
42 
SwFormatColl(SwAttrPool & rPool,const OUString & rFormatName,const sal_uInt16 * pWhichRanges,SwFormatColl * pDerFrom,sal_uInt16 nFormatWhich)43     SwFormatColl( SwAttrPool& rPool, const OUString &rFormatName,
44                 const sal_uInt16* pWhichRanges, SwFormatColl* pDerFrom,
45                 sal_uInt16 nFormatWhich )
46           : SwFormat( rPool, rFormatName, pWhichRanges, pDerFrom, nFormatWhich )
47     { SetAuto(false); }
48 
49 private:
50     SwFormatColl(const SwFormatColl & ) = delete;
51     const SwFormatColl &operator=(const SwFormatColl &) = delete;
52 };
53 
54 /// Represents the style of a paragraph.
55 class SW_DLLPUBLIC SwTextFormatColl: public SwFormatColl
56 {
57     friend class SwDoc;
58     friend class ::sw::DocumentStylePoolManager;
59 
60     SwTextFormatColl(const SwTextFormatColl & rRef) = delete;
61 
62     bool mbStayAssignedToListLevelOfOutlineStyle;
63 
64     bool mbAssignedToOutlineStyle;
65 
66     SwTextFormatColl *mpNextTextFormatColl;
67 
68 protected:
69 
SwTextFormatColl(SwAttrPool & rPool,const sal_Char * pFormatCollName,SwTextFormatColl * pDerFrom=nullptr,sal_uInt16 nFormatWh=RES_TXTFMTCOLL)70     SwTextFormatColl( SwAttrPool& rPool, const sal_Char* pFormatCollName,
71                     SwTextFormatColl* pDerFrom = nullptr,
72                     sal_uInt16 nFormatWh = RES_TXTFMTCOLL )
73         : SwFormatColl(rPool, pFormatCollName, aTextFormatCollSetRange, pDerFrom, nFormatWh)
74         , mbStayAssignedToListLevelOfOutlineStyle(false)
75         , mbAssignedToOutlineStyle(false)
76     {
77         mpNextTextFormatColl = this;
78     }
79 
SwTextFormatColl(SwAttrPool & rPool,const OUString & rFormatCollName,SwTextFormatColl * pDerFrom,sal_uInt16 nFormatWh=RES_TXTFMTCOLL)80     SwTextFormatColl( SwAttrPool& rPool, const OUString &rFormatCollName,
81                     SwTextFormatColl* pDerFrom,
82                     sal_uInt16 nFormatWh = RES_TXTFMTCOLL )
83         : SwFormatColl(rPool, rFormatCollName, aTextFormatCollSetRange, pDerFrom, nFormatWh)
84         , mbStayAssignedToListLevelOfOutlineStyle(false)
85         , mbAssignedToOutlineStyle(false)
86     {
87         mpNextTextFormatColl = this;
88     }
89 
90     /// To get UL- / LR- / FontHeight-changes.
91     virtual void Modify( const SfxPoolItem*, const SfxPoolItem* ) override;
92 
93 public:
94 
95 
96     inline void SetNextTextFormatColl(SwTextFormatColl& rNext);
GetNextTextFormatColl() const97     SwTextFormatColl& GetNextTextFormatColl() const { return *mpNextTextFormatColl; }
98 
99     bool IsAtDocNodeSet() const;
100 
101     void SetAttrOutlineLevel( int );
102     int  GetAttrOutlineLevel() const;
103 
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;
108 
IsAssignedToListLevelOfOutlineStyle() const109     bool IsAssignedToListLevelOfOutlineStyle() const
110     {
111         return mbAssignedToOutlineStyle;
112     }
113 
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();
118 
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;
124 
125     /// Override <ResetAllFormatAttr()> to stay assigned to list level of outline style.
126     virtual sal_uInt16 ResetAllFormatAttr() override;
127 
StayAssignedToListLevelOfOutlineStyle() const128     bool StayAssignedToListLevelOfOutlineStyle() const
129     {
130         return mbStayAssignedToListLevelOfOutlineStyle;
131     }
132 
133     bool AreListLevelIndentsApplicable() const;
134 
135     void dumpAsXml(xmlTextWriterPtr pWriter) const;
136 };
137 
138 class SwGrfFormatColl final : public SwFormatColl
139 {
140     friend class SwDoc;
141 
SwGrfFormatColl(SwAttrPool & rPool,const sal_Char * pFormatCollName,SwGrfFormatColl * pDerFrom=nullptr)142     SwGrfFormatColl( SwAttrPool& rPool, const sal_Char* pFormatCollName,
143                     SwGrfFormatColl* pDerFrom = nullptr )
144         : SwFormatColl( rPool, pFormatCollName, aGrfFormatCollSetRange,
145                     pDerFrom, RES_GRFFMTCOLL )
146     {}
147 
SwGrfFormatColl(SwAttrPool & rPool,const OUString & rFormatCollName,SwGrfFormatColl * pDerFrom)148     SwGrfFormatColl( SwAttrPool& rPool, const OUString &rFormatCollName,
149                     SwGrfFormatColl* pDerFrom )
150         : SwFormatColl( rPool, rFormatCollName, aGrfFormatCollSetRange,
151                     pDerFrom, RES_GRFFMTCOLL )
152     {}
153 };
154 
155 // FEATURE::CONDCOLL
156 /// Conditional styles.
157 enum class Master_CollCondition
158 {
159     NONE,
160     PARA_IN_LIST,
161     PARA_IN_OUTLINE,
162     PARA_IN_FRAME,
163     PARA_IN_TABLEHEAD,
164     PARA_IN_TABLEBODY,
165     PARA_IN_SECTION,
166     PARA_IN_FOOTNOTE,
167     PARA_IN_FOOTER,
168     PARA_IN_HEADER,
169     PARA_IN_ENDNOTE
170 };
171 
172 class SW_DLLPUBLIC SwCollCondition final : public SwClient
173 {
174     Master_CollCondition m_nCondition;
175     sal_uLong m_nSubCondition;
176 
177 public:
178 
179     SwCollCondition( SwTextFormatColl* pColl, Master_CollCondition nMasterCond,
180                     sal_uLong nSubCond );
181     virtual ~SwCollCondition() override;
182 
183     /// @@@ public copy ctor, but no copy assignment?
184     SwCollCondition( const SwCollCondition& rCpy );
185 private:
186     /// @@@ public copy ctor, but no copy assignment?
187     SwCollCondition & operator= (const SwCollCondition &) = delete;
188 public:
189 
190     bool operator==( const SwCollCondition& rCmp ) const;
191 
GetCondition() const192     Master_CollCondition GetCondition() const      { return m_nCondition; }
GetSubCondition() const193     sal_uLong GetSubCondition() const   { return m_nSubCondition; }
194 
195     void SetCondition( Master_CollCondition nCond, sal_uLong nSubCond );
GetTextFormatColl() const196     SwTextFormatColl* GetTextFormatColl() const     { return const_cast<SwTextFormatColl*>(static_cast<const SwTextFormatColl*>(GetRegisteredIn())); }
197     void RegisterToFormat( SwFormat& );
198 };
199 
200 using SwFormatCollConditions = std::vector<std::unique_ptr<SwCollCondition>>;
201 
202 class SW_DLLPUBLIC SwConditionTextFormatColl final : public SwTextFormatColl
203 {
204     friend class SwDoc;
205     friend class ::sw::DocumentStylePoolManager;
206 
207     SwFormatCollConditions m_CondColls;
208 
SwConditionTextFormatColl(SwAttrPool & rPool,const OUString & rFormatCollName,SwTextFormatColl * pDerFrom)209     SwConditionTextFormatColl( SwAttrPool& rPool, const OUString &rFormatCollName,
210                             SwTextFormatColl* pDerFrom )
211         : SwTextFormatColl( rPool, rFormatCollName, pDerFrom, RES_CONDTXTFMTCOLL )
212     {}
213 
214 public:
215 
216     virtual ~SwConditionTextFormatColl() override;
217 
218     const SwCollCondition* HasCondition( const SwCollCondition& rCond ) const;
GetCondColls() const219     const SwFormatCollConditions& GetCondColls() const { return m_CondColls; }
220     void InsertCondition( const SwCollCondition& rCond );
221     void RemoveCondition( const SwCollCondition& rCond );
222 
223     void SetConditions( const SwFormatCollConditions& );
224 };
225 
226 // FEATURE::CONDCOLL
227 /// Inline implementations.
SetNextTextFormatColl(SwTextFormatColl & rNext)228 inline void SwTextFormatColl::SetNextTextFormatColl( SwTextFormatColl& rNext )
229 {
230     mpNextTextFormatColl = &rNext;
231 }
232 #endif
233 
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
235