LibreOffice Module svl (master) 1
style.hxx
Go to the documentation of this file.
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 <rtl/ref.hxx>
28#include <svl/svldllapi.h>
29#include <svl/hint.hxx>
30#include <svl/lstner.hxx>
34#include <tools/mapunit.hxx>
35#include <tools/solar.h>
36
37#include <memory>
38#include <optional>
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
42enum 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
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,
68 Hidden = 0x0200,
69 ReadOnly = 0x2000,
70 Used = 0x4000,
71 UserDefined = 0x8000,
72 AllVisible = 0xe07f,
73 All = 0xe27f,
74};
75namespace o3tl {
76 template<> struct typed_flags<SfxStyleSearchBits> : is_typed_flags<SfxStyleSearchBits, 0xe27f> {};
77}
78
79
80class SfxItemSet;
81class SfxItemPool;
83class SvStream;
84
85namespace svl { class IndexedStyleSheets; }
86/*
87Everyone changing instances of SfxStyleSheetBasePool or SfxStyleSheetBase
88must broadcast this using <SfxStyleSheetBasePool::GetBroadcaster()> broadcasts.
89The class <SfxStyleSheetHint> is used for this, it contains an Action-Id and a
90pointer to the <SfxStyleSheetBase>. The actions are:
91
92#define SfxHintId::StyleSheetCreated // style is created
93#define SfxHintId::StyleSheetModified // style is modified
94#define SfxHintId::StyleSheetChanged // style is replaced
95#define SfxHintId::StyleSheetErased // style is deleted
96
97The following methods already broadcast themself
98
99SfxSimpleHint(SfxHintId::Dying) from:
100 SfxStyleSheetBasePool::~SfxStyleSheetBasePool()
101
102SfxStyleSheetHint( SfxHintId::StyleSheetCreated, *p ) from:
103 SfxStyleSheetBasePool::Make( const String& rName,
104 SfxStyleFamily eFam, sal_uInt16 mask)
105
106SfxStyleSheetHint( SfxHintId::StyleSheetChanged, *pNew ) from:
107 SfxStyleSheetBasePool::Add( SfxStyleSheetBase& rSheet )
108
109SfxStyleSheetHint( SfxHintId::StyleSheetErased, *p ) from:
110 SfxStyleSheetBasePool::Erase( SfxStyleSheetBase* p )
111 SfxStyleSheetBasePool::Clear()
112*/
113
114class SVL_DLLPUBLIC SfxStyleSheetBase : public cppu::WeakImplHelper<>
115{
116private:
118
119protected:
122
123 OUString aName, aParent, aFollow;
124 OUString aHelpFile; // name of the help file
125 SfxItemSet* pSet; // ItemSet
127
128 sal_uLong nHelpId; // help ID
129
130 bool bMySet; // sal_True: delete Set in dtor
132
135 virtual ~SfxStyleSheetBase() override;
136
137public:
138
139 // returns the internal name of this style
140 const OUString& GetName() const;
141
142 // sets the internal name of this style.
143 //
144 // If the name of a style is changed, then the styles container needs to be
145 // reindexed (see IndexedStyleSheets). If you set bReindexNow to false to
146 // defer that indexing, then you must call the Reindex manually on the
147 // SfxStyleSheetBasePool parent.
148 virtual bool SetName(const OUString& rNewName, bool bReindexNow = true);
149
150 virtual const OUString& GetParent() const;
151 virtual bool SetParent( const OUString& );
152 virtual const OUString& GetFollow() const;
153 virtual bool SetFollow( const OUString& );
154 virtual bool HasFollowSupport() const; // Default true
155 virtual bool HasParentSupport() const; // Default true
156 virtual bool HasClearParentSupport() const; // Default false
157 virtual bool IsUsed() const; // Default true
158 virtual OUString GetDescription( MapUnit eMetric );
159
160 virtual OUString GetUsedBy() { return OUString(); }
161
162 SfxStyleSheetBasePool* GetPool() { return m_pPool; }
163 SfxStyleFamily GetFamily() const { return nFamily; }
164 SfxStyleSearchBits GetMask() const { return nMask; }
165 void SetMask( SfxStyleSearchBits mask) { nMask = mask; }
166 bool IsUserDefined() const
167 { return bool( nMask & SfxStyleSearchBits::UserDefined); }
168
169 virtual bool IsHidden() const { return bHidden; }
170 virtual void SetHidden( bool bValue );
171
172 virtual sal_uLong GetHelpId( OUString& rFile );
173 virtual void SetHelpId( const OUString& r, sal_uLong nId );
174
175 virtual SfxItemSet& GetItemSet();
180 virtual std::optional<SfxItemSet> GetItemSetForPreview();
181
183 virtual bool isScStyleSheet() const { return false; }
184};
185
186/* Class to iterate and search on a SfxStyleSheetBasePool */
188{
189public:
195 SfxStyleSearchBits GetSearchMask() const;
196 SfxStyleFamily GetSearchFamily() const;
197 virtual sal_Int32 Count();
198 virtual SfxStyleSheetBase *operator[](sal_Int32 nIdx);
199 virtual SfxStyleSheetBase* First();
200 virtual SfxStyleSheetBase* Next();
201 virtual SfxStyleSheetBase* Find(const OUString& rStr);
202 virtual ~SfxStyleSheetIterator();
203
204 bool SearchUsed() const { return bSearchUsed; }
205
206protected:
207
211
212
213private:
214 SVL_DLLPRIVATE bool IsTrivialSearch() const;
215
219
221};
222
224
225class SVL_DLLPUBLIC SfxStyleSheetBasePool: public SfxBroadcaster, public cppu::WeakImplHelper<>
226{
228friend class SfxStyleSheetBase;
229
230 std::unique_ptr<SfxStyleSheetBasePool_Impl> pImpl;
231
232 SfxStyleSheetIterator& GetIterator_Impl(SfxStyleFamily eFamily, SfxStyleSearchBits eMask);
233protected:
234 SfxStyleSheetIterator* GetCachedIterator();
235
237
238 void ChangeParent(std::u16string_view rOld, const OUString& rNew, SfxStyleFamily eFamily, bool bVirtual = true);
241
242 virtual ~SfxStyleSheetBasePool() override;
243
244 void StoreStyleSheet(const rtl::Reference< SfxStyleSheetBase >&);
245
249 GetIndexedStyleSheets() const;
250 SfxStyleSheetBase* GetStyleSheetByPositionInIndex(unsigned pos);
251
252public:
255
256 SfxItemPool& GetPool() { return rPool;}
257 const SfxItemPool& GetPool() const { return rPool;}
258
259 virtual std::unique_ptr<SfxStyleSheetIterator> CreateIterator(SfxStyleFamily, SfxStyleSearchBits nMask = SfxStyleSearchBits::All);
260
261 virtual SfxStyleSheetBase& Make(const OUString&,
262 SfxStyleFamily eFam,
264
265 virtual void Remove( SfxStyleSheetBase* );
266 void Insert( SfxStyleSheetBase* );
267
268 void Clear();
269
270 SfxStyleSheetBasePool& operator=( const SfxStyleSheetBasePool& );
272
275 virtual SfxStyleSheetBase* Find( const OUString&, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All );
276
277 void Reindex();
281 void Add( const SfxStyleSheetBase& );
282};
283
285 public SfxListener, public SfxBroadcaster, public svl::StyleSheetUser
286{
287public:
288
291
292 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
293
294 virtual bool isUsedByModel() const override;
295
296 virtual bool SetParent( const OUString& ) override;
297
298protected:
299 virtual ~SfxStyleSheet() override;
300};
301
303{
304protected:
306 virtual rtl::Reference<SfxStyleSheetBase> Create(const OUString&, SfxStyleFamily, SfxStyleSearchBits mask) override;
307
308public:
310};
311
312
314{
315public:
317};
318
319
321{
323public:
326 { return pStyleSh; }
327};
328
329class UNLESS_MERGELIBS(SVL_DLLPUBLIC) SfxStyleSheetModifiedHint final : public SfxStyleSheetHint
330{
331 OUString aName;
332
333public:
334 SfxStyleSheetModifiedHint( OUString aOld,
336 const OUString& GetOldName() const { return aName; }
337};
338
339class SVL_DLLPUBLIC SfxUnoStyleSheet : public cppu::ImplInheritanceHelper<SfxStyleSheet, css::style::XStyle>
340{
341public:
342 SfxUnoStyleSheet( const OUString& _rName, const SfxStyleSheetBasePool& _rPool, SfxStyleFamily _eFamily, SfxStyleSearchBits _nMask );
343
344 static SfxUnoStyleSheet* getUnoStyleSheet( const css::uno::Reference< css::style::XStyle >& xStyle );
345};
346
347#endif
348
349/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base class for providers of defaults of SfxPoolItems.
Definition: itempool.hxx:51
friend class SfxStyleSheetBase
Definition: style.hxx:228
std::unique_ptr< SfxStyleSheetBasePool_Impl > pImpl
Definition: style.hxx:230
SfxItemPool & GetPool()
Definition: style.hxx:256
virtual rtl::Reference< SfxStyleSheetBase > Create(const OUString &, SfxStyleFamily, SfxStyleSearchBits)
Definition: style.cxx:598
SfxItemPool & rPool
Definition: style.hxx:236
const SfxItemPool & GetPool() const
Definition: style.hxx:257
OUString aHelpFile
Definition: style.hxx:124
SfxStyleSearchBits GetMask() const
Definition: style.hxx:164
OUString aFollow
Definition: style.hxx:123
friend class SfxStyleSheetBasePool
Definition: style.hxx:117
SfxStyleSearchBits nMask
Definition: style.hxx:126
SfxStyleFamily GetFamily() const
Definition: style.hxx:163
bool IsUserDefined() const
Definition: style.hxx:166
virtual bool IsHidden() const
Definition: style.hxx:169
SfxItemSet * pSet
Definition: style.hxx:125
virtual bool isScStyleSheet() const
Fix for expensive dynamic_cast.
Definition: style.hxx:183
SfxStyleSheetBasePool * GetPool()
Definition: style.hxx:162
SfxStyleSheetBasePool * m_pPool
Definition: style.hxx:120
sal_uLong nHelpId
Definition: style.hxx:128
virtual OUString GetUsedBy()
Definition: style.hxx:160
void SetMask(SfxStyleSearchBits mask)
Definition: style.hxx:165
SfxStyleFamily nFamily
Definition: style.hxx:121
SfxStyleSheetBase * GetStyleSheet() const
Definition: style.hxx:325
SfxStyleSheetBase * pStyleSh
Definition: style.hxx:322
SfxStyleFamily nSearchFamily
Definition: style.hxx:209
bool SearchUsed() const
Definition: style.hxx:204
const SfxStyleSheetBasePool * pBasePool
Definition: style.hxx:208
sal_Int32 mnCurrentPosition
Definition: style.hxx:217
SfxStyleSheetBase * pCurrentStyle
Definition: style.hxx:216
SfxStyleSearchBits nMask
Definition: style.hxx:210
This class holds SfxStyleSheets and allows for access via an id and a name.
virtual OUString GetName() const override
virtual void Insert(SotClipboardFormatId nFormat, const OUString &rFormatName) override
virtual void GetDescription(OUString &rName) override
virtual void SetHelpId(const OUString &) override
void Notify(SwFlyFrame *pFly, SwPageFrame *pOld, const SwRect &rOld, const SwRect *pOldRect=nullptr)
SfxHintId
hint ids, mostly used to avoid dynamic_cast of SfxHint
Definition: hint.hxx:28
OUString aName
sal_Int64 n
MapUnit
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
void Clear(EHistoryType eHistory)
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
None
sal_uIntPtr sal_uLong
SfxStyleFamily
Definition: style.hxx:42
SfxStyleSearchBits
Definition: style.hxx:54
@ AllVisible
all visible styles
@ UserDefined
user defined styles (search mask)
TOOLS_DLLPUBLIC tools::Rectangle & operator+=(tools::Rectangle &rRect, const SvBorder &rBorder)
#define SVL_DLLPRIVATE
Definition: svldllapi.h:30
#define SVL_DLLPUBLIC
Definition: svldllapi.h:28
Count
Page