Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / svl / style.hxx
blobcb8498a2d118ee5d8dde8eae6344a8ce2e4e217c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SVL_STYLE_HXX
21 #define INCLUDED_SVL_STYLE_HXX
23 #include <config_options.h>
24 #include <com/sun/star/style/XStyle.hpp>
26 #include <rtl/ref.hxx>
27 #include <cppuhelper/implbase.hxx>
28 #include <svl/svldllapi.h>
29 #include <svl/hint.hxx>
30 #include <svl/lstner.hxx>
31 #include <svl/SfxBroadcaster.hxx>
32 #include <svl/stylesheetuser.hxx>
33 #include <o3tl/typed_flags_set.hxx>
34 #include <tools/mapunit.hxx>
35 #include <tools/solar.h>
37 #include <memory>
38 #include <optional>
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
54 enum class SfxStyleSearchBits {
55 // sc/calc styles
56 ScStandard = 0x0001,
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,
67 Auto = 0x0000, ///< automatic: flags from application
68 Hidden = 0x0200, ///< hidden styles (search mask)
69 ReadOnly = 0x2000, ///< readonly styles (search mask)
70 Used = 0x4000, ///< used styles (search mask)
71 UserDefined = 0x8000, ///< user defined styles (search mask)
72 AllVisible = 0xe07f, ///< all visible styles
73 All = 0xe27f, ///< all styles
75 namespace o3tl {
76 template<> struct typed_flags<SfxStyleSearchBits> : is_typed_flags<SfxStyleSearchBits, 0xe27f> {};
80 class SfxItemSet;
81 class SfxItemPool;
82 class SfxStyleSheetBasePool;
83 class SvStream;
85 namespace svl { class IndexedStyleSheets; }
87 Everyone changing instances of SfxStyleSheetBasePool or SfxStyleSheetBase
88 must broadcast this using <SfxStyleSheetBasePool::GetBroadcaster()> broadcasts.
89 The class <SfxStyleSheetHint> is used for this, it contains an Action-Id and a
90 pointer to the <SfxStyleSheetBase>. The actions are:
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
97 The following methods already broadcast themself
99 SfxSimpleHint(SfxHintId::Dying) from:
100 SfxStyleSheetBasePool::~SfxStyleSheetBasePool()
102 SfxStyleSheetHint( SfxHintId::StyleSheetCreated, *p ) from:
103 SfxStyleSheetBasePool::Make( const String& rName,
104 SfxStyleFamily eFam, sal_uInt16 mask)
106 SfxStyleSheetHint( SfxHintId::StyleSheetChanged, *pNew ) from:
107 SfxStyleSheetBasePool::Add( SfxStyleSheetBase& rSheet )
109 SfxStyleSheetHint( SfxHintId::StyleSheetErased, *p ) from:
110 SfxStyleSheetBasePool::Erase( SfxStyleSheetBase* p )
111 SfxStyleSheetBasePool::Clear()
114 class SVL_DLLPUBLIC SfxStyleSheetBase : public cppu::WeakImplHelper<>
116 private:
117 friend class SfxStyleSheetBasePool;
119 protected:
120 SfxStyleSheetBasePool* m_pPool; // related pool
121 SfxStyleFamily nFamily;
123 OUString aName, aParent, aFollow;
124 OUString aHelpFile; // name of the help file
125 SfxItemSet* pSet; // ItemSet
126 SfxStyleSearchBits nMask; // Flags
128 sal_uLong nHelpId; // help ID
130 bool bMySet; // sal_True: delete Set in dtor
131 bool bHidden;
133 SfxStyleSheetBase( const OUString&, SfxStyleSheetBasePool*, SfxStyleFamily eFam, SfxStyleSearchBits mask );
134 SfxStyleSheetBase( const SfxStyleSheetBase& );
135 virtual ~SfxStyleSheetBase() override;
137 public:
139 // returns the internal name of this style
140 const OUString& GetName() const;
142 // sets the internal name of this style.
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);
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 );
160 virtual OUString GetUsedBy() { return OUString(); }
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); }
169 virtual bool IsHidden() const { return bHidden; }
170 virtual void SetHidden( bool bValue );
172 virtual sal_uLong GetHelpId( OUString& rFile );
173 virtual void SetHelpId( const OUString& r, sal_uLong nId );
175 virtual SfxItemSet& GetItemSet();
176 /// Due to writer's usual lack of sanity this is a separate function for
177 /// preview only; it shall not create the style in case it does not exist.
178 /// If the style has parents, it is _not_ required that the returned item
179 /// set has parents (i.e. use it for display purposes only).
180 virtual std::optional<SfxItemSet> GetItemSetForPreview();
182 /// Fix for expensive dynamic_cast
183 virtual bool isScStyleSheet() const { return false; }
186 /* Class to iterate and search on a SfxStyleSheetBasePool */
187 class SVL_DLLPUBLIC SfxStyleSheetIterator
189 public:
190 /** Constructor.
191 * The iterator will only iterate over style sheets which have the family \p eFam
193 SfxStyleSheetIterator(const SfxStyleSheetBasePool *pBase,
194 SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All );
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();
204 bool SearchUsed() const { return bSearchUsed; }
206 protected:
208 const SfxStyleSheetBasePool* pBasePool;
209 SfxStyleFamily nSearchFamily;
210 SfxStyleSearchBits nMask;
213 private:
214 SVL_DLLPRIVATE bool IsTrivialSearch() const;
216 SfxStyleSheetBase* pCurrentStyle;
217 sal_Int32 mnCurrentPosition;
218 bool bSearchUsed;
220 friend class SfxStyleSheetBasePool;
223 class SfxStyleSheetBasePool_Impl;
225 class SVL_DLLPUBLIC SfxStyleSheetBasePool: public SfxBroadcaster, public cppu::WeakImplHelper<>
227 friend class SfxStyleSheetIterator;
228 friend class SfxStyleSheetBase;
230 std::unique_ptr<SfxStyleSheetBasePool_Impl> pImpl;
232 SfxStyleSheetIterator& GetIterator_Impl(SfxStyleFamily eFamily, SfxStyleSearchBits eMask);
233 protected:
234 SfxStyleSheetIterator* GetCachedIterator();
236 SfxItemPool& rPool;
238 void ChangeParent(std::u16string_view rOld, const OUString& rNew, SfxStyleFamily eFamily, bool bVirtual = true);
239 virtual rtl::Reference<SfxStyleSheetBase> Create( const OUString&, SfxStyleFamily, SfxStyleSearchBits );
240 virtual rtl::Reference<SfxStyleSheetBase> Create( const SfxStyleSheetBase& );
242 virtual ~SfxStyleSheetBasePool() override;
244 void StoreStyleSheet(const rtl::Reference< SfxStyleSheetBase >&);
246 /** Obtain the indexed style sheets.
248 const svl::IndexedStyleSheets&
249 GetIndexedStyleSheets() const;
250 SfxStyleSheetBase* GetStyleSheetByPositionInIndex(unsigned pos);
252 public:
253 SfxStyleSheetBasePool( SfxItemPool& );
254 SfxStyleSheetBasePool( const SfxStyleSheetBasePool& );
256 SfxItemPool& GetPool() { return rPool;}
257 const SfxItemPool& GetPool() const { return rPool;}
259 virtual std::unique_ptr<SfxStyleSheetIterator> CreateIterator(SfxStyleFamily, SfxStyleSearchBits nMask = SfxStyleSearchBits::All);
261 virtual SfxStyleSheetBase& Make(const OUString&,
262 SfxStyleFamily eFam,
263 SfxStyleSearchBits nMask = SfxStyleSearchBits::All);
265 virtual void Remove( SfxStyleSheetBase* );
266 void Insert( SfxStyleSheetBase* );
268 void Clear();
270 SfxStyleSheetBasePool& operator=( const SfxStyleSheetBasePool& );
271 SfxStyleSheetBasePool& operator+=( const SfxStyleSheetBasePool& );
273 SfxStyleSheetBase* First(SfxStyleFamily eFamily, SfxStyleSearchBits eMask = SfxStyleSearchBits::All);
274 SfxStyleSheetBase* Next();
275 virtual SfxStyleSheetBase* Find( const OUString&, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All ) const;
277 virtual bool SetParent(SfxStyleFamily eFam,
278 const OUString &rStyle,
279 const OUString &rParent);
281 void Reindex();
282 /** Add a style sheet.
283 * Not an actual public function. Do not call it from non-subclasses.
285 void Add( const SfxStyleSheetBase& );
288 class SVL_DLLPUBLIC SfxStyleSheet: public SfxStyleSheetBase,
289 public SfxListener, public SfxBroadcaster, public svl::StyleSheetUser
291 public:
293 SfxStyleSheet( const OUString&, const SfxStyleSheetBasePool&, SfxStyleFamily, SfxStyleSearchBits );
294 SfxStyleSheet( const SfxStyleSheet& );
296 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
298 virtual bool isUsedByModel() const override;
300 virtual bool SetParent( const OUString& ) override;
302 protected:
303 virtual ~SfxStyleSheet() override;
306 class SVL_DLLPUBLIC SfxStyleSheetPool: public SfxStyleSheetBasePool
308 protected:
309 using SfxStyleSheetBasePool::Create;
310 virtual rtl::Reference<SfxStyleSheetBase> Create(const OUString&, SfxStyleFamily, SfxStyleSearchBits mask) override;
312 public:
313 SfxStyleSheetPool( SfxItemPool const& );
317 class SVL_DLLPUBLIC SfxStyleSheetPoolHint final : public SfxHint
319 public:
320 SfxStyleSheetPoolHint() {}
324 class SVL_DLLPUBLIC SfxStyleSheetHint: public SfxHint
326 SfxStyleSheetBase* pStyleSh;
327 public:
328 SfxStyleSheetHint( SfxHintId, SfxStyleSheetBase& );
329 SfxStyleSheetBase* GetStyleSheet() const
330 { return pStyleSh; }
333 class UNLESS_MERGELIBS(SVL_DLLPUBLIC) SfxStyleSheetModifiedHint final : public SfxStyleSheetHint
335 OUString aName;
337 public:
338 SfxStyleSheetModifiedHint( OUString aOld,
339 SfxStyleSheetBase& );
340 const OUString& GetOldName() const { return aName; }
343 class SVL_DLLPUBLIC SfxUnoStyleSheet : public cppu::ImplInheritanceHelper<SfxStyleSheet, css::style::XStyle>
345 public:
346 SfxUnoStyleSheet( const OUString& _rName, const SfxStyleSheetBasePool& _rPool, SfxStyleFamily _eFamily, SfxStyleSearchBits _nMask );
348 static SfxUnoStyleSheet* getUnoStyleSheet( const css::uno::Reference< css::style::XStyle >& xStyle );
351 #endif
353 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */