Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/inc/docstyle.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
#pragma once
20
21
#include <rtl/ref.hxx>
22
#include <rtl/ustring.hxx>
23
24
#include <svl/style.hxx>
25
#include <svl/itemset.hxx>
26
#include "swdllapi.h"
27
#include "names.hxx"
28
29
#include <unordered_map>
30
#include <memory>
31
#include <optional>
32
#include <vector>
33
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;
44
45
// Temporary StyleSheet.
46
class SW_DLLPUBLIC SwDocStyleSheet final : public SfxStyleSheetBase
47
{
48
    friend class SwDocStyleSheetPool;
49
    friend class SwStyleSheetIterator;
50
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;
60
61
    bool                m_bPhysical;
62
    OUString m_aLink;
63
64
    /// Make empty shell a real StyleSheet (Core).
65
    SAL_DLLPRIVATE void              Create();
66
67
    /// Fill StyleSheet with data.
68
    enum FillStyleType {
69
        FillOnlyName,
70
        FillAllInfo,
71
        FillPhysical,
72
        FillPreview,
73
    };
74
75
    SAL_DLLPRIVATE bool FillStyleSheet(FillStyleType eFType,
76
            std::optional<SfxItemSet> * o_ppFlatSet = nullptr);
77
78
    virtual ~SwDocStyleSheet() override;
79
80
public:
81
    SwDocStyleSheet( SwDoc&                 rDoc,
82
                     SwDocStyleSheetPool&   rPool);
83
84
    SwDocStyleSheet( const SwDocStyleSheet& );
85
86
    void                    Reset();
87
88
2.88M
    void                    SetFamily(SfxStyleFamily eFam)  { nFamily = eFam;   }
89
90
2.86M
    bool                    IsPhysical() const              { return m_bPhysical; }
91
    void                    SetPhysical(bool bPhys);
92
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;
97
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, const bool bBroadcast = true,
103
                                        const bool bResetIndentAttrsAtParagraphStyle = false );
104
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;
113
114
    virtual sal_uInt32 GetHelpId( OUString& rFile ) override;
115
    virtual void SetHelpId( const OUString& r, sal_uInt32 nId ) override;
116
117
    virtual sal_Int32 GetSpotlightId() override;
118
119
    /** Preset the members without physical access.
120
     Used by StyleSheetPool. */
121
2.88M
    void                    PresetName(const OUString& rName)  { aName   = rName; }
122
    void                    PresetNameAndFamily(SfxStyleFamily eFamily, const OUString& rName);
123
2.21M
    void                    PresetParent(const OUString& rName){ aParent = rName; }
124
4.06M
    void                    PresetFollow(const OUString& rName){ aFollow = rName; }
125
126
    virtual bool            SetName(const OUString& rNewName, bool bReindexNow = true) override;
127
    virtual bool            SetParent( const OUString& rStr) override;
128
    virtual bool            SetFollow( const OUString& rStr) override;
129
    void SetLink(const OUString& rStr);
130
131
    virtual bool            HasFollowSupport() const override;
132
    virtual bool            HasParentSupport() const override;
133
    virtual bool            HasClearParentSupport() const override;
134
    virtual OUString        GetDescription(MapUnit eUnit) override;
135
    virtual std::vector<std::pair<sal_uInt16, OUString>> GetItemPresentation(
136
        MapUnit eMetric, const SfxItemSet* pWorkingSet = nullptr) override;
137
    void ResetItems(const std::set<sal_uInt16>& rWhichIds);
138
139
    virtual OUString GetUsedBy() override;
140
141
    SwCharFormat*              GetCharFormat();
142
    SwTextFormatColl*           GetCollection();
143
    SwFrameFormat*               GetFrameFormat();
144
    const SwPageDesc*       GetPageDesc();
145
    const SwNumRule*        GetNumRule();
146
    void                    SetNumRule(const SwNumRule& rRule);
147
    SwTableAutoFormat*      GetTableFormat();
148
149
    virtual bool            IsUsed() const override;
150
};
151
152
// Iterator for Pool.
153
class SwStyleSheetIterator final : public SfxStyleSheetIterator, public SfxListener
154
{
155
    // Local helper class.
156
    class SwPoolFormatList
157
    {
158
        struct Hash
159
        {
160
            size_t operator()(const std::pair<SfxStyleFamily, UIName>& p) const
161
51.5k
            {
162
51.5k
                return std::hash<SfxStyleFamily>()(p.first) ^ std::hash<UIName>()(p.second);
163
51.5k
            }
164
        };
165
        std::vector<std::pair<SfxStyleFamily, UIName>> maImpl;
166
        typedef std::unordered_map<std::pair<SfxStyleFamily, UIName>, sal_uInt32, Hash> UniqueHash;
167
        UniqueHash maUnique;
168
        void rehash();
169
    public:
170
1.00k
        SwPoolFormatList() {}
171
        void Append( SfxStyleFamily eFam, const UIName& rStr );
172
1.00k
        void clear() { maImpl.clear(); maUnique.clear(); }
173
26.9k
        size_t size() { return maImpl.size(); }
174
1.00k
        bool empty() { return maImpl.empty(); }
175
        sal_uInt32 FindName(SfxStyleFamily eFam, const UIName& rName);
176
        void RemoveName(SfxStyleFamily eFam, const UIName& rName);
177
25.9k
        const std::pair<SfxStyleFamily,UIName> &operator[](sal_uInt32 nIdx) { return maImpl[ nIdx ]; }
178
    };
179
180
    rtl::Reference< SwDocStyleSheet > mxIterSheet;
181
    rtl::Reference< SwDocStyleSheet > mxStyleSheet;
182
    SwPoolFormatList       m_aLst;
183
    sal_uInt32          m_nLastPos;
184
    bool                m_bFirstCalled;
185
186
    bool IsUsedInComments(const UIName& rName) const;
187
    void                AppendStyleList(const std::vector<OUString>& rLst,
188
                                        bool        bUsed,
189
                                        bool        bTestHidden,
190
                                        bool        bOnlyHidden,
191
                                        SwGetPoolIdFromName nSection,
192
                                        SfxStyleFamily eFamily);
193
194
public:
195
    SwStyleSheetIterator(SwDocStyleSheetPool& rBase,
196
                         SfxStyleFamily eFam, SfxStyleSearchBits n);
197
    virtual ~SwStyleSheetIterator() override;
198
199
    virtual sal_Int32 Count() override;
200
    virtual SfxStyleSheetBase *operator[](sal_Int32 nIdx) override;
201
    virtual SfxStyleSheetBase* First() override;
202
    virtual SfxStyleSheetBase* Next() override;
203
    virtual SfxStyleSheetBase* Find(const OUString& rStr) override;
204
205
    virtual void Notify( SfxBroadcaster&, const SfxHint& ) override;
206
207
    void InvalidateIterator();
208
};
209
210
class SwDocStyleSheetPool final : public SfxStyleSheetBasePool
211
{
212
    rtl::Reference< SwDocStyleSheet > mxStyleSheet;
213
    rtl::Reference< SfxStyleSheetPool > mxEEStyleSheetPool;
214
    SwDoc&              m_rDoc;
215
    bool                m_bOrganizer : 1;     ///< Organizer
216
217
    virtual rtl::Reference<SfxStyleSheetBase> Create( const OUString&, SfxStyleFamily, SfxStyleSearchBits nMask, const OUString& rParentStyleSheetName) override;
218
    virtual rtl::Reference<SfxStyleSheetBase> Create( const SfxStyleSheetBase& ) override;
219
220
    using SfxStyleSheetBasePool::Find;
221
222
public:
223
    SwDocStyleSheetPool( SwDoc&, bool bOrganizer );
224
225
    virtual SfxStyleSheetBase& Make(const OUString&, SfxStyleFamily,
226
            SfxStyleSearchBits nMask = SfxStyleSearchBits::All,
227
            const OUString& rParentStyleSheetName = u""_ustr) override;
228
229
    virtual SfxStyleSheetBase* Find( const OUString&, SfxStyleFamily eFam,
230
                                    SfxStyleSearchBits n=SfxStyleSearchBits::All ) override;
231
232
    virtual void Remove( SfxStyleSheetBase* pStyle) override;
233
234
1.00k
    bool    IsOrganizerMode() const         { return m_bOrganizer; }
235
236
    virtual std::unique_ptr<SfxStyleSheetIterator> CreateIterator( SfxStyleFamily, SfxStyleSearchBits nMask = SfxStyleSearchBits::All) override;
237
238
4.73k
    SwDoc& GetDoc() const { return m_rDoc; }
239
4.33k
    SfxStyleSheetPool* GetEEStyleSheetPool() const { return mxEEStyleSheetPool.get(); }
240
241
    void dispose();
242
243
    void InvalidateIterator();
244
245
private:
246
    virtual ~SwDocStyleSheetPool() override;
247
248
    SwDocStyleSheetPool( const SwDocStyleSheetPool& ) = delete;
249
};
250
251
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */