Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/inc/fmtcol.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
#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 "paratr.hxx"
26
#include "deletelistener.hxx"
27
#include <rtl/ustring.hxx>
28
#include <tools/solar.h>
29
30
#include <vector>
31
#include <memory>
32
33
class SwAttrPool;
34
class SwViewShell;
35
class SwFontObj;
36
namespace sw{ class DocumentStylePoolManager; }
37
38
/// SwFormatColl is just an SwFormat subclass that defaults to m_bAutoFormat=false, expressing that
39
/// this set of formatting is a style, not direct formatting.
40
class SAL_DLLPUBLIC_RTTI SwFormatColl: public SwFormat
41
{
42
protected:
43
    SwFormatColl( SwAttrPool& rPool, const UIName &rFormatName,
44
                const WhichRangesContainer& pWhichRanges, SwFormatColl* pDerFrom,
45
                sal_uInt16 nFormatWhich )
46
800k
          : SwFormat( rPool, rFormatName, pWhichRanges, pDerFrom, nFormatWhich )
47
800k
    { 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
56
    : public SwFormatColl
57
    , public sw::FormatDropDefiner
58
{
59
    friend class SwDoc;
60
    friend class ::sw::DocumentStylePoolManager;
61
62
    SwTextFormatColl(const SwTextFormatColl & rRef) = delete;
63
64
    bool mbStayAssignedToListLevelOfOutlineStyle;
65
66
    bool mbAssignedToOutlineStyle;
67
68
    SwTextFormatColl *mpNextTextFormatColl;
69
70
    SwCharFormat* mpLinkedCharFormat = nullptr;
71
72
    /** cached/temporary font layout information */
73
    mutable std::unique_ptr<SwFontObj> mxFontObj;
74
75
protected:
76
    SwTextFormatColl( SwAttrPool& rPool, const UIName &rFormatCollName,
77
                    SwTextFormatColl* pDerFrom = nullptr,
78
                    sal_uInt16 nFormatWh = RES_TXTFMTCOLL );
79
80
    /// To get UL- / LR- / FontHeight-changes.
81
    virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
82
83
public:
84
    virtual ~SwTextFormatColl();
85
    inline void SetNextTextFormatColl(SwTextFormatColl& rNext);
86
6.67M
    SwTextFormatColl& GetNextTextFormatColl() const { return *mpNextTextFormatColl; }
87
88
    void SetLinkedCharFormat(SwCharFormat* pLink);
89
90
    const SwCharFormat* GetLinkedCharFormat() const;
91
92
    bool IsAtDocNodeSet() const;
93
94
    void SetAttrOutlineLevel( int );
95
    int  GetAttrOutlineLevel() const;
96
97
    // Return the list level of the Outline Style - the List Style for the
98
    // outline numbering -
99
    // to which the Paragraph Style is assigned.
100
    int  GetAssignedOutlineStyleLevel() const;
101
102
    bool IsAssignedToListLevelOfOutlineStyle() const
103
39.7M
    {
104
39.7M
        return mbAssignedToOutlineStyle;
105
39.7M
    }
106
107
    // If a Paragraph Style is assigned to list level N of the Outline Style,
108
    // then its outline level - AttrOutlineLevel - is set to N+1
109
    void AssignToListLevelOfOutlineStyle(const int nAssignedListLevel);
110
    void DeleteAssignmentToListLevelOfOutlineStyle();
111
112
    /** Override to recognize changes on the <SwNumRuleItem> and register/unregister
113
     the paragragh style at the corresponding <SwNumRule> instance. */
114
    virtual bool SetFormatAttr( const SfxPoolItem& rAttr ) override;
115
    virtual bool SetFormatAttr( const SfxItemSet& rSet ) override;
116
    virtual bool ResetFormatAttr( sal_uInt16 nWhich1, sal_uInt16 nWhich2 = 0 ) override;
117
118
    /// Override <ResetAllFormatAttr()> to stay assigned to list level of outline style.
119
    virtual sal_uInt16 ResetAllFormatAttr() override;
120
121
    bool StayAssignedToListLevelOfOutlineStyle() const
122
515k
    {
123
515k
        return mbStayAssignedToListLevelOfOutlineStyle;
124
515k
    }
125
126
    ::sw::ListLevelIndents AreListLevelIndentsApplicable() const;
127
    bool AreListLevelIndentsApplicableImpl(sal_uInt16 nWhich) const;
128
129
    void dumpAsXml(xmlTextWriterPtr pWriter) const override;
130
    virtual void FormatDropNotify(const SwFormatDrop& rDrop) override
131
11
    {
132
11
        if(HasWriterListeners() && !IsModifyLocked())
133
7
            CallSwClientNotify(sw::LegacyModifyHint(&rDrop, &rDrop));
134
11
    };
135
    virtual void InvalidateInSwFntCache(sal_uInt16 nWhich) override;
136
    virtual void InvalidateInSwFntCache() override;
137
    const SwFontObj & GetFontObj(SwViewShell *pSh) const;
138
};
139
140
class SwGrfFormatColl final : public SwFormatColl
141
{
142
    friend class SwDoc;
143
144
    SwGrfFormatColl( SwAttrPool& rPool, const UIName &rFormatCollName,
145
                    SwGrfFormatColl* pDerFrom = nullptr )
146
77.3k
        : SwFormatColl( rPool, rFormatCollName, aGrfFormatCollSetRange,
147
77.3k
                    pDerFrom, RES_GRFFMTCOLL )
148
77.3k
    {}
149
};
150
151
// FEATURE::CONDCOLL
152
/// Conditional styles.
153
enum class Master_CollCondition
154
{
155
    NONE,
156
    PARA_IN_LIST,
157
    PARA_IN_OUTLINE,
158
    PARA_IN_FRAME,
159
    PARA_IN_TABLEHEAD,
160
    PARA_IN_TABLEBODY,
161
    PARA_IN_SECTION,
162
    PARA_IN_FOOTNOTE,
163
    PARA_IN_FOOTER,
164
    PARA_IN_HEADER,
165
    PARA_IN_ENDNOTE
166
};
167
168
class SW_DLLPUBLIC SwCollCondition final
169
{
170
    Master_CollCondition m_nCondition;
171
    sal_uInt32 m_nSubCondition;
172
    sw::WeakBroadcastingPtr<SwTextFormatColl> m_pCollection;
173
174
public:
175
176
    SwCollCondition( SwTextFormatColl* pColl, Master_CollCondition nMasterCond,
177
                    sal_uInt32 nSubCond );
178
    ~SwCollCondition();
179
180
    /// @@@ public copy ctor, but no copy assignment?
181
    SwCollCondition( const SwCollCondition& rCpy );
182
private:
183
    /// @@@ public copy ctor, but no copy assignment?
184
    SwCollCondition & operator= (const SwCollCondition &) = delete;
185
public:
186
187
    bool operator==( const SwCollCondition& rCmp ) const;
188
189
0
    Master_CollCondition GetCondition() const      { return m_nCondition; }
190
0
    sal_uInt32 GetSubCondition() const   { return m_nSubCondition; }
191
192
    void SetCondition( Master_CollCondition nCond, sal_uInt32 nSubCond );
193
0
    SwTextFormatColl* GetTextFormatColl() const { return const_cast<SwTextFormatColl*>(m_pCollection.operator->()); }
194
    void RegisterToFormat( SwTextFormatColl& );
195
};
196
197
using SwFormatCollConditions = std::vector<std::unique_ptr<SwCollCondition>>;
198
199
class SW_DLLPUBLIC SwConditionTextFormatColl final : public SwTextFormatColl
200
{
201
    friend class SwDoc;
202
    friend class ::sw::DocumentStylePoolManager;
203
204
    SwFormatCollConditions m_CondColls;
205
206
    SwConditionTextFormatColl( SwAttrPool& rPool, const UIName &rFormatCollName,
207
                            SwTextFormatColl* pDerFrom )
208
77.3k
        : SwTextFormatColl( rPool, rFormatCollName, pDerFrom, RES_CONDTXTFMTCOLL )
209
77.3k
    {}
210
211
public:
212
213
    virtual ~SwConditionTextFormatColl() override;
214
215
    const SwCollCondition* HasCondition( const SwCollCondition& rCond ) const;
216
3.23k
    const SwFormatCollConditions& GetCondColls() const { return m_CondColls; }
217
    void InsertCondition( const SwCollCondition& rCond );
218
    void RemoveCondition( const SwCollCondition& rCond );
219
220
    void SetConditions( const SwFormatCollConditions& );
221
};
222
223
// FEATURE::CONDCOLL
224
/// Inline implementations.
225
inline void SwTextFormatColl::SetNextTextFormatColl( SwTextFormatColl& rNext )
226
164k
{
227
164k
    mpNextTextFormatColl = &rNext;
228
164k
}
229
#endif
230
231
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */