Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/svl/style.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
20
#ifndef INCLUDED_SVL_STYLE_HXX
21
#define INCLUDED_SVL_STYLE_HXX
22
23
#include <config_options.h>
24
#include <com/sun/star/style/XStyle.hpp>
25
26
#include <cppuhelper/implbase.hxx>
27
#include <svl/svldllapi.h>
28
#include <svl/hint.hxx>
29
#include <svl/lstner.hxx>
30
#include <svl/SfxBroadcaster.hxx>
31
#include <svl/stylesheetuser.hxx>
32
#include <o3tl/typed_flags_set.hxx>
33
34
#include <memory>
35
#include <optional>
36
37
#include <vector>
38
#include <utility>
39
40
// This is used as a flags enum in sw/, but only there,
41
// so I don't pull in o3tl::typed_flags here
42
enum class SfxStyleFamily {
43
    None    = 0x00,
44
    Char    = 0x01,
45
    Para    = 0x02,
46
    Frame   = 0x04,
47
    Page    = 0x08,
48
    Pseudo  = 0x10,
49
    Table   = 0x20,
50
    Cell    = 0x40,
51
    All     = 0x7fff
52
};
53
54
enum class SfxStyleSearchBits {
55
    // sc/calc styles
56
    ScStandard  = 0x0001,
57
58
    // sw/writer styles
59
    SwText      = 0x0001,
60
    SwChapter   = 0x0002,
61
    SwList      = 0x0004,
62
    SwIndex     = 0x0008,
63
    SwExtra     = 0x0010,
64
    SwHtml      = 0x0020,
65
    SwCondColl  = 0x0040,
66
67
    Auto        = 0x0000, ///< automatic: flags from application
68
    Favourite   = 0x0100, ///< styles selected to be always visible (search mask)
69
    Hidden      = 0x0200, ///< hidden styles (search mask)
70
    ReadOnly    = 0x2000, ///< readonly styles (search mask)
71
    Used        = 0x4000, ///< used styles (search mask)
72
    UserDefined = 0x8000, ///< user defined styles (search mask)
73
    AllVisible  = 0xe07f, ///< all visible styles
74
    All         = 0xe27f, ///< all styles
75
};
76
namespace o3tl {
77
    template<> struct typed_flags<SfxStyleSearchBits> : is_typed_flags<SfxStyleSearchBits, 0xe37f> {};
78
}
79
80
81
class SfxItemSet;
82
class SfxItemPool;
83
class SfxStyleSheetBasePool;
84
85
namespace svl { class IndexedStyleSheets; }
86
typedef struct _xmlTextWriter* xmlTextWriterPtr;
87
namespace rtl { template <class reference_type> class Reference; }
88
enum class MapUnit : sal_uInt8;
89
90
/*
91
Everyone changing instances of SfxStyleSheetBasePool or SfxStyleSheetBase
92
must broadcast this using <SfxStyleSheetBasePool::GetBroadcaster()> broadcasts.
93
The class <SfxStyleSheetHint> is used for this, it contains an Action-Id and a
94
pointer to the <SfxStyleSheetBase>. The actions are:
95
96
#define SfxHintId::StyleSheetCreated      // style is created
97
#define SfxHintId::StyleSheetModified     // style is modified
98
#define SfxHintId::StyleSheetChanged      // style is replaced
99
#define SfxHintId::StyleSheetErased       // style is deleted
100
101
The following methods already broadcast themself
102
103
SfxSimpleHint(SfxHintId::Dying) from:
104
   SfxStyleSheetBasePool::~SfxStyleSheetBasePool()
105
106
SfxStyleSheetHint( SfxHintId::StyleSheetCreated, *p ) from:
107
   SfxStyleSheetBasePool::Make( const String& rName,
108
   SfxStyleFamily eFam, SfxStyleSearchBits mask)
109
110
SfxStyleSheetHint( SfxHintId::StyleSheetChanged, *pNew ) from:
111
   SfxStyleSheetBasePool::Add( SfxStyleSheetBase& rSheet )
112
113
SfxStyleSheetHint( SfxHintId::StyleSheetErased, *p ) from:
114
   SfxStyleSheetBasePool::Erase( SfxStyleSheetBase* p )
115
   SfxStyleSheetBasePool::Clear()
116
*/
117
118
// avoid LNK2005 duplicate WeakImplHelper definitions with MSVC
119
class SAL_DLLPUBLIC_TEMPLATE SfxStyleSheetBase_Base : public cppu::WeakImplHelper<>
120
{
121
};
122
123
class SVL_DLLPUBLIC SfxStyleSheetBase : public SfxStyleSheetBase_Base
124
{
125
private:
126
    friend class SfxStyleSheetBasePool;
127
128
protected:
129
    SfxStyleSheetBasePool*  m_pPool;          // related pool
130
    SfxStyleFamily          nFamily;
131
132
    OUString                aName, aParent, aFollow;
133
    OUString                aHelpFile;      // name of the help file
134
    SfxItemSet*             pSet;           // ItemSet
135
    SfxStyleSearchBits      nMask;          // Flags
136
137
    sal_uInt32              nHelpId;        // help ID
138
139
    bool                    bMySet;         // sal_True: delete Set in dtor
140
    bool                    bHidden;
141
142
    SfxStyleSheetBase( const OUString&, SfxStyleSheetBasePool*, SfxStyleFamily eFam,
143
                       SfxStyleSearchBits mask, const OUString& rParentStyleSheetName );
144
    SfxStyleSheetBase( const SfxStyleSheetBase& );
145
    virtual ~SfxStyleSheetBase() override;
146
147
public:
148
149
    // returns the internal name of this style
150
    const OUString& GetName() const;
151
152
    // sets the internal name of this style.
153
    //
154
    // If the name of a style is changed, then the styles container needs to be
155
    // reindexed (see IndexedStyleSheets). If you set bReindexNow to false to
156
    // defer that indexing, then you must call the Reindex manually on the
157
    // SfxStyleSheetBasePool parent.
158
    virtual bool SetName(const OUString& rNewName, bool bReindexNow = true);
159
160
    virtual const OUString& GetParent() const;
161
    virtual bool SetParent( const OUString& );
162
    virtual const OUString& GetFollow() const;
163
    virtual bool SetFollow( const OUString& );
164
    virtual bool HasFollowSupport() const;      // Default true
165
    virtual bool HasParentSupport() const;      // Default true
166
    virtual bool HasClearParentSupport() const; // Default false
167
    virtual bool IsUsed() const;                // Default true
168
    virtual OUString GetDescription( MapUnit eMetric );
169
170
    /// Returns individual property presentations for building UI chips
171
    /// Each pair contains: WhichId and presentation string
172
    virtual std::vector<std::pair<sal_uInt16, OUString>> GetItemPresentation(
173
        MapUnit eMetric, const SfxItemSet* pWorkingSet = nullptr);
174
175
0
    virtual OUString GetUsedBy() { return OUString(); }
176
177
13.6M
    SfxStyleSheetBasePool* GetPool() { return m_pPool; }
178
29.8M
    SfxStyleFamily GetFamily() const     { return nFamily; }
179
11.0M
    SfxStyleSearchBits   GetMask() const     { return nMask; }
180
3.09M
    void     SetMask( SfxStyleSearchBits mask) { nMask = mask; }
181
    bool     IsUserDefined() const
182
20.2k
           { return bool( nMask & SfxStyleSearchBits::UserDefined); }
183
184
108k
    virtual bool IsHidden() const { return bHidden; }
185
    virtual void SetHidden( bool bValue );
186
187
    virtual sal_uInt32 GetHelpId( OUString& rFile );
188
    virtual void   SetHelpId( const OUString& r, sal_uInt32 nId );
189
190
    // Spotlight Id, @return -1 for style not in use
191
    virtual sal_Int32 GetSpotlightId();
192
193
    virtual SfxItemSet& GetItemSet();
194
    /// Due to writer's usual lack of sanity this is a separate function for
195
    /// preview only; it shall not create the style in case it does not exist.
196
    /// If the style has parents, it is _not_ required that the returned item
197
    /// set has parents (i.e. use it for display purposes only).
198
    virtual std::optional<SfxItemSet> GetItemSetForPreview();
199
200
    /// Fix for expensive dynamic_cast
201
0
    virtual bool isScStyleSheet() const { return false; }
202
203
    void dumpAsXml(xmlTextWriterPtr pWriter) const;
204
};
205
206
/* Class to iterate and search on a SfxStyleSheetBasePool */
207
class SVL_DLLPUBLIC SfxStyleSheetIterator
208
{
209
public:
210
    /** Constructor.
211
     * The iterator will only iterate over style sheets which have the family \p eFam
212
     */
213
    SfxStyleSheetIterator(const SfxStyleSheetBasePool *pBase,
214
                          SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All );
215
    SfxStyleSearchBits GetSearchMask() const;
216
40.0M
    SfxStyleFamily GetSearchFamily() const { return nSearchFamily; }
217
218
    virtual sal_Int32 Count();
219
    virtual SfxStyleSheetBase *operator[](sal_Int32 nIdx);
220
    virtual SfxStyleSheetBase* First();
221
    virtual SfxStyleSheetBase* Next();
222
    virtual SfxStyleSheetBase* Find(const OUString& rStr);
223
    virtual ~SfxStyleSheetIterator();
224
225
11.7M
    bool                    SearchUsed() const { return bSearchUsed; }
226
227
protected:
228
229
    const SfxStyleSheetBasePool*  pBasePool;
230
    SfxStyleFamily          nSearchFamily;
231
    SfxStyleSearchBits      nMask;
232
233
234
private:
235
    SVL_DLLPRIVATE bool         IsTrivialSearch() const;
236
237
    SfxStyleSheetBase*      pCurrentStyle;
238
    sal_Int32               mnCurrentPosition;
239
    bool                    bSearchUsed;
240
241
friend class SfxStyleSheetBasePool;
242
};
243
244
class SfxStyleSheetBasePool_Impl;
245
246
// avoid LNK2005 duplicate WeakImplHelper definitions with MSVC
247
class SAL_DLLPUBLIC_TEMPLATE SfxStyleSheetBasePool_Base : public cppu::WeakImplHelper<>
248
{
249
};
250
251
typedef struct _xmlTextWriter* xmlTextWriterPtr;
252
253
class SVL_DLLPUBLIC SfxStyleSheetBasePool : public SfxBroadcaster, public SfxStyleSheetBasePool_Base
254
{
255
friend class SfxStyleSheetIterator;
256
friend class SfxStyleSheetBase;
257
258
    std::unique_ptr<SfxStyleSheetBasePool_Impl> pImpl;
259
260
    SfxStyleSheetIterator&      GetIterator_Impl(SfxStyleFamily eFamily, SfxStyleSearchBits eMask);
261
protected:
262
    SfxStyleSheetIterator*      GetCachedIterator();
263
264
    SfxItemPool&                rPool;
265
266
    void                        ChangeParent(std::u16string_view rOld, const OUString& rNew, SfxStyleFamily eFamily, bool bVirtual = true);
267
    virtual rtl::Reference<SfxStyleSheetBase> Create( const OUString&, SfxStyleFamily, SfxStyleSearchBits, const OUString& rParentStyleSheetName );
268
    virtual rtl::Reference<SfxStyleSheetBase>  Create( const SfxStyleSheetBase& );
269
270
    virtual                     ~SfxStyleSheetBasePool() override;
271
272
    void                        StoreStyleSheet(const rtl::Reference< SfxStyleSheetBase >&);
273
274
    /** Obtain the indexed style sheets.
275
     */
276
    const svl::IndexedStyleSheets&
277
                                GetIndexedStyleSheets() const;
278
    SfxStyleSheetBase*          GetStyleSheetByPositionInIndex(unsigned pos);
279
280
public:
281
                                SfxStyleSheetBasePool( SfxItemPool& );
282
                                SfxStyleSheetBasePool( const SfxStyleSheetBasePool& );
283
284
11.1M
    SfxItemPool&                GetPool() { return rPool;}
285
0
    const SfxItemPool&          GetPool() const { return rPool;}
286
287
    virtual std::unique_ptr<SfxStyleSheetIterator> CreateIterator(SfxStyleFamily, SfxStyleSearchBits nMask = SfxStyleSearchBits::All);
288
289
    virtual SfxStyleSheetBase&  Make(const OUString&,
290
                                     SfxStyleFamily eFam,
291
                                     SfxStyleSearchBits nMask = SfxStyleSearchBits::All,
292
                                     const OUString& rParentStyleSheetName = u""_ustr);
293
294
    virtual void                Remove( SfxStyleSheetBase* );
295
    void                Insert( SfxStyleSheetBase* );
296
297
    void                Clear();
298
299
    SfxStyleSheetBasePool&      operator=( const SfxStyleSheetBasePool& );
300
    SfxStyleSheetBasePool&      operator+=( const SfxStyleSheetBasePool& );
301
302
    SfxStyleSheetBase*  First(SfxStyleFamily eFamily, SfxStyleSearchBits eMask = SfxStyleSearchBits::All);
303
    SfxStyleSheetBase*  Next();
304
    virtual SfxStyleSheetBase*  Find( const OUString&, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All );
305
306
    void                        Reindex();
307
    void                        ReindexOnNameChange(const SfxStyleSheetBase& style, const OUString& rOldName, const OUString& rNewName);
308
    /** Add a style sheet.
309
     * Not an actual public function. Do not call it from non-subclasses.
310
     */
311
    void                        Add( const SfxStyleSheetBase& );
312
313
    void dumpAsXml(xmlTextWriterPtr pWriter) const;
314
};
315
316
class SVL_DLLPUBLIC SfxStyleSheet: public SfxStyleSheetBase,
317
                     public SfxListener, public SfxBroadcaster, public svl::StyleSheetUser
318
{
319
public:
320
321
                        SfxStyleSheet( const OUString&, const SfxStyleSheetBasePool&, SfxStyleFamily,
322
                                        SfxStyleSearchBits, const OUString& rParentStyleSheetName = u""_ustr );
323
                        SfxStyleSheet( const SfxStyleSheet& );
324
325
    virtual void        Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
326
327
    virtual bool        isUsedByModel() const override final;
328
329
    virtual bool        SetParent( const OUString& ) override;
330
331
    virtual bool        IsSfxStyleSheet() const override final;
332
333
protected:
334
    virtual             ~SfxStyleSheet() override;
335
};
336
337
class SVL_DLLPUBLIC SfxStyleSheetPool: public SfxStyleSheetBasePool
338
{
339
protected:
340
    using SfxStyleSheetBasePool::Create;
341
    virtual rtl::Reference<SfxStyleSheetBase> Create(const OUString&, SfxStyleFamily,
342
                SfxStyleSearchBits mask, const OUString& rParentStyleSheetName) override;
343
344
public:
345
    SfxStyleSheetPool( SfxItemPool const& );
346
};
347
348
349
class SVL_DLLPUBLIC SfxStyleSheetPoolHint final : public SfxHint
350
{
351
public:
352
0
    SfxStyleSheetPoolHint() : SfxHint(SfxHintId::SfxStyleSheetPool) {}
353
};
354
355
356
class SVL_DLLPUBLIC SfxStyleSheetHint: public SfxHint
357
{
358
    SfxStyleSheetBase*  pStyleSh;
359
public:
360
                        SfxStyleSheetHint( SfxHintId, SfxStyleSheetBase& );
361
    SfxStyleSheetBase*  GetStyleSheet() const
362
35.9M
                        { return pStyleSh; }
363
};
364
365
class UNLESS_MERGELIBS(SVL_DLLPUBLIC) SfxStyleSheetModifiedHint final : public SfxStyleSheetHint
366
{
367
    OUString            aName;
368
369
public:
370
                        SfxStyleSheetModifiedHint( OUString aOld,
371
                                                   SfxStyleSheetBase& );
372
8.96M
    const OUString&     GetOldName() const { return aName; }
373
};
374
375
class SVL_DLLPUBLIC SfxUnoStyleSheet : public cppu::ImplInheritanceHelper<SfxStyleSheet, css::style::XStyle>
376
{
377
public:
378
    SfxUnoStyleSheet( const OUString& _rName, const SfxStyleSheetBasePool& _rPool, SfxStyleFamily _eFamily,
379
                      SfxStyleSearchBits _nMask,
380
                      const OUString& rParentStyleSheetName = u""_ustr );
381
382
    static SfxUnoStyleSheet* getUnoStyleSheet( const css::uno::Reference< css::style::XStyle >& xStyle );
383
};
384
385
#endif
386
387
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */