Bump version to 6.4-15
[LibreOffice.git] / include / svl / style.hxx
blob24656eb2318aaaeb3cc0d55e6976c91334fa52d2
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 <com/sun/star/style/XStyle.hpp>
24 #include <com/sun/star/lang/XUnoTunnel.hpp>
26 #include <rtl/ref.hxx>
27 #include <comphelper/weak.hxx>
28 #include <cppuhelper/implbase.hxx>
29 #include <svl/svldllapi.h>
30 #include <svl/hint.hxx>
31 #include <svl/lstner.hxx>
32 #include <svl/SfxBroadcaster.hxx>
33 #include <svl/stylesheetuser.hxx>
34 #include <o3tl/typed_flags_set.hxx>
35 #include <tools/mapunit.hxx>
36 #include <tools/solar.h>
38 #include <memory>
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 = 0xFDFF, ///< all styles
73 All = 0xFFFF, ///< all styles
75 namespace o3tl {
76 template<> struct typed_flags<SfxStyleSearchBits> : is_typed_flags<SfxStyleSearchBits, 0xffff> {};
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 comphelper::OWeakTypeObject
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::unique_ptr<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(SfxStyleSheetBasePool *pBase,
194 SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All );
195 SfxStyleSearchBits GetSearchMask() const;
196 SfxStyleFamily GetSearchFamily() const;
197 virtual sal_uInt16 Count();
198 virtual SfxStyleSheetBase *operator[](sal_uInt16 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 SfxStyleSheetBasePool* pBasePool;
209 SfxStyleFamily nSearchFamily;
210 SfxStyleSearchBits nMask;
213 private:
214 SVL_DLLPRIVATE bool IsTrivialSearch() const;
216 SfxStyleSheetBase* pCurrentStyle;
217 sal_uInt16 nCurrentPosition;
218 bool bSearchUsed;
220 friend class SfxStyleSheetBasePool;
223 class SfxStyleSheetBasePool_Impl;
225 class SVL_DLLPUBLIC SfxStyleSheetBasePool: public SfxBroadcaster, public comphelper::OWeakTypeObject
227 friend class SfxStyleSheetIterator;
228 friend class SfxStyleSheetBase;
230 std::unique_ptr<SfxStyleSheetBasePool_Impl> pImpl;
232 protected:
233 SfxStyleSheetIterator& GetIterator_Impl();
235 SfxItemPool& rPool;
236 SfxStyleFamily nSearchFamily;
237 SfxStyleSearchBits nMask;
239 void ChangeParent( const OUString&, const OUString&, bool bVirtual = true );
240 virtual SfxStyleSheetBase* Create( const OUString&, SfxStyleFamily, SfxStyleSearchBits );
241 virtual SfxStyleSheetBase* Create( const SfxStyleSheetBase& );
243 virtual ~SfxStyleSheetBasePool() override;
245 void StoreStyleSheet(const rtl::Reference< SfxStyleSheetBase >&);
247 /** Obtain the indexed style sheets.
249 const svl::IndexedStyleSheets&
250 GetIndexedStyleSheets() const;
251 SfxStyleSheetBase* GetStyleSheetByPositionInIndex(unsigned pos);
253 public:
254 SfxStyleSheetBasePool( SfxItemPool& );
255 SfxStyleSheetBasePool( const SfxStyleSheetBasePool& );
257 SfxItemPool& GetPool() { return rPool;}
258 const SfxItemPool& GetPool() const { return rPool;}
260 virtual std::unique_ptr<SfxStyleSheetIterator> CreateIterator(SfxStyleFamily, SfxStyleSearchBits nMask);
261 sal_uInt16 Count();
262 SfxStyleSheetBase* operator[](sal_uInt16 nIdx);
264 virtual SfxStyleSheetBase& Make(const OUString&,
265 SfxStyleFamily eFam,
266 SfxStyleSearchBits nMask = SfxStyleSearchBits::All);
268 virtual void Remove( SfxStyleSheetBase* );
269 void Insert( SfxStyleSheetBase* );
271 void Clear();
273 SfxStyleSheetBasePool& operator=( const SfxStyleSheetBasePool& );
274 SfxStyleSheetBasePool& operator+=( const SfxStyleSheetBasePool& );
276 SfxStyleSheetBase* First();
277 SfxStyleSheetBase* Next();
278 virtual SfxStyleSheetBase* Find( const OUString&, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All );
280 virtual bool SetParent(SfxStyleFamily eFam,
281 const OUString &rStyle,
282 const OUString &rParent);
284 SfxStyleSheetBase* Find(const OUString& rStr)
285 { return Find(rStr, nSearchFamily, nMask); }
287 void SetSearchMask(SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All );
288 SfxStyleSearchBits GetSearchMask() const { return nMask;}
289 SfxStyleFamily GetSearchFamily() const { return nSearchFamily; }
291 void Reindex();
292 /** Add a style sheet.
293 * Not an actual public function. Do not call it from non-subclasses.
295 void Add( const SfxStyleSheetBase& );
298 class SVL_DLLPUBLIC SfxStyleSheet: public SfxStyleSheetBase,
299 public SfxListener, public SfxBroadcaster, public svl::StyleSheetUser
301 public:
303 SfxStyleSheet( const OUString&, const SfxStyleSheetBasePool&, SfxStyleFamily, SfxStyleSearchBits );
304 SfxStyleSheet( const SfxStyleSheet& );
306 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
308 virtual bool isUsedByModel() const override;
310 virtual bool SetParent( const OUString& ) override;
312 protected:
313 virtual ~SfxStyleSheet() override;
316 class SVL_DLLPUBLIC SfxStyleSheetPool: public SfxStyleSheetBasePool
318 protected:
319 using SfxStyleSheetBasePool::Create;
320 virtual SfxStyleSheetBase* Create(const OUString&, SfxStyleFamily, SfxStyleSearchBits mask) override;
322 public:
323 SfxStyleSheetPool( SfxItemPool const& );
327 class SVL_DLLPUBLIC SfxStyleSheetPoolHint final : public SfxHint
329 public:
330 SfxStyleSheetPoolHint() {}
334 class SVL_DLLPUBLIC SfxStyleSheetHint: public SfxHint
336 SfxStyleSheetBase* pStyleSh;
337 public:
338 SfxStyleSheetHint( SfxHintId, SfxStyleSheetBase& );
339 SfxStyleSheetBase* GetStyleSheet() const
340 { return pStyleSh; }
343 class SVL_DLLPUBLIC SfxStyleSheetModifiedHint final : public SfxStyleSheetHint
345 OUString aName;
347 public:
348 SfxStyleSheetModifiedHint( const OUString& rOld,
349 SfxStyleSheetBase& );
350 const OUString& GetOldName() const { return aName; }
353 class SVL_DLLPUBLIC SfxUnoStyleSheet : public cppu::ImplInheritanceHelper<SfxStyleSheet, css::style::XStyle, css::lang::XUnoTunnel>
355 public:
356 SfxUnoStyleSheet( const OUString& _rName, const SfxStyleSheetBasePool& _rPool, SfxStyleFamily _eFamily, SfxStyleSearchBits _nMask );
358 static SfxUnoStyleSheet* getUnoStyleSheet( const css::uno::Reference< css::style::XStyle >& xStyle );
360 // XUnoTunnel
361 static const css::uno::Sequence< ::sal_Int8 >& getUnoTunnelId();
362 virtual ::sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< ::sal_Int8 >& aIdentifier ) override;
365 #endif
367 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */