bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / svl / style.hxx
blob2f35e91be4e7f8ef7a298e7332eaed115476d24d
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/poolitem.hxx>
33 #include <svl/SfxBroadcaster.hxx>
34 #include <svl/stylesheetuser.hxx>
35 #include <o3tl/typed_flags_set.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 SfxStyleSheetBasePool* GetPool() { return m_pPool; }
161 SfxStyleFamily GetFamily() const { return nFamily; }
162 SfxStyleSearchBits GetMask() const { return nMask; }
163 void SetMask( SfxStyleSearchBits mask) { nMask = mask; }
164 bool IsUserDefined() const
165 { return bool( nMask & SfxStyleSearchBits::UserDefined); }
167 virtual bool IsHidden() const { return bHidden; }
168 virtual void SetHidden( bool bValue );
170 virtual sal_uLong GetHelpId( OUString& rFile );
171 virtual void SetHelpId( const OUString& r, sal_uLong nId );
173 virtual SfxItemSet& GetItemSet();
174 /// Due to writer's usual lack of sanity this is a separate function for
175 /// preview only; it shall not create the style in case it does not exist.
176 /// If the style has parents, it is _not_ required that the returned item
177 /// set has parents (i.e. use it for display purposes only).
178 virtual std::unique_ptr<SfxItemSet> GetItemSetForPreview();
180 /// Fix for expensive dynamic_cast
181 virtual bool isScStyleSheet() const { return false; }
184 /* Class to iterate and search on a SfxStyleSheetBasePool */
185 class SVL_DLLPUBLIC SfxStyleSheetIterator
187 public:
188 /** Constructor.
189 * The iterator will only iterate over style sheets which have the family \p eFam
191 SfxStyleSheetIterator(SfxStyleSheetBasePool *pBase,
192 SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All );
193 SfxStyleSearchBits GetSearchMask() const;
194 SfxStyleFamily GetSearchFamily() const;
195 virtual sal_uInt16 Count();
196 virtual SfxStyleSheetBase *operator[](sal_uInt16 nIdx);
197 virtual SfxStyleSheetBase* First();
198 virtual SfxStyleSheetBase* Next();
199 virtual SfxStyleSheetBase* Find(const OUString& rStr);
200 virtual ~SfxStyleSheetIterator();
202 bool SearchUsed() const { return bSearchUsed; }
204 protected:
206 SfxStyleSheetBasePool* pBasePool;
207 SfxStyleFamily nSearchFamily;
208 SfxStyleSearchBits nMask;
211 private:
212 SVL_DLLPRIVATE bool IsTrivialSearch() const;
214 SfxStyleSheetBase* pCurrentStyle;
215 sal_uInt16 nCurrentPosition;
216 bool bSearchUsed;
218 friend class SfxStyleSheetBasePool;
221 class SfxStyleSheetBasePool_Impl;
223 class SVL_DLLPUBLIC SfxStyleSheetBasePool: public SfxBroadcaster, public comphelper::OWeakTypeObject
225 friend class SfxStyleSheetIterator;
226 friend class SfxStyleSheetBase;
228 std::unique_ptr<SfxStyleSheetBasePool_Impl> pImpl;
230 protected:
231 SfxStyleSheetIterator& GetIterator_Impl();
233 SfxItemPool& rPool;
234 SfxStyleFamily nSearchFamily;
235 SfxStyleSearchBits nMask;
237 void ChangeParent( const OUString&, const OUString&, bool bVirtual = true );
238 virtual SfxStyleSheetBase* Create( const OUString&, SfxStyleFamily, SfxStyleSearchBits );
239 virtual SfxStyleSheetBase* Create( const SfxStyleSheetBase& );
241 virtual ~SfxStyleSheetBasePool() override;
243 void StoreStyleSheet(const rtl::Reference< SfxStyleSheetBase >&);
245 /** Obtain the indexed style sheets.
247 const svl::IndexedStyleSheets&
248 GetIndexedStyleSheets() const;
249 SfxStyleSheetBase* GetStyleSheetByPositionInIndex(unsigned pos);
251 public:
252 SfxStyleSheetBasePool( SfxItemPool& );
253 SfxStyleSheetBasePool( const SfxStyleSheetBasePool& );
255 SfxItemPool& GetPool() { return rPool;}
256 const SfxItemPool& GetPool() const { return rPool;}
258 virtual std::unique_ptr<SfxStyleSheetIterator> CreateIterator(SfxStyleFamily, SfxStyleSearchBits nMask);
259 sal_uInt16 Count();
260 SfxStyleSheetBase* operator[](sal_uInt16 nIdx);
262 virtual SfxStyleSheetBase& Make(const OUString&,
263 SfxStyleFamily eFam,
264 SfxStyleSearchBits nMask = SfxStyleSearchBits::All);
266 virtual void Remove( SfxStyleSheetBase* );
267 void Insert( SfxStyleSheetBase* );
269 void Clear();
271 SfxStyleSheetBasePool& operator=( const SfxStyleSheetBasePool& );
272 SfxStyleSheetBasePool& operator+=( const SfxStyleSheetBasePool& );
274 SfxStyleSheetBase* First();
275 SfxStyleSheetBase* Next();
276 virtual SfxStyleSheetBase* Find( const OUString&, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All );
278 virtual bool SetParent(SfxStyleFamily eFam,
279 const OUString &rStyle,
280 const OUString &rParent);
282 SfxStyleSheetBase* Find(const OUString& rStr)
283 { return Find(rStr, nSearchFamily, nMask); }
285 void SetSearchMask(SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All );
286 SfxStyleSearchBits GetSearchMask() const { return nMask;}
287 SfxStyleFamily GetSearchFamily() const { return nSearchFamily; }
289 void Reindex();
290 /** Add a style sheet.
291 * Not an actual public function. Do not call it from non-subclasses.
293 void Add( const SfxStyleSheetBase& );
296 class SVL_DLLPUBLIC SfxStyleSheet: public SfxStyleSheetBase,
297 public SfxListener, public SfxBroadcaster, public svl::StyleSheetUser
299 public:
301 SfxStyleSheet( const OUString&, const SfxStyleSheetBasePool&, SfxStyleFamily, SfxStyleSearchBits );
302 SfxStyleSheet( const SfxStyleSheet& );
304 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
306 virtual bool isUsedByModel() const override;
308 virtual bool SetParent( const OUString& ) override;
310 protected:
311 virtual ~SfxStyleSheet() override;
314 class SVL_DLLPUBLIC SfxStyleSheetPool: public SfxStyleSheetBasePool
316 protected:
317 using SfxStyleSheetBasePool::Create;
318 virtual SfxStyleSheetBase* Create(const OUString&, SfxStyleFamily, SfxStyleSearchBits mask) override;
320 public:
321 SfxStyleSheetPool( SfxItemPool const& );
325 class SVL_DLLPUBLIC SfxStyleSheetPoolHint : public SfxHint
327 public:
328 SfxStyleSheetPoolHint() {}
332 class SVL_DLLPUBLIC SfxStyleSheetHint: public SfxHint
334 SfxStyleSheetBase* pStyleSh;
335 public:
336 SfxStyleSheetHint( SfxHintId, SfxStyleSheetBase& );
337 SfxStyleSheetBase* GetStyleSheet() const
338 { return pStyleSh; }
341 class SVL_DLLPUBLIC SfxStyleSheetModifiedHint: public SfxStyleSheetHint
343 OUString aName;
345 public:
346 SfxStyleSheetModifiedHint( const OUString& rOld,
347 SfxStyleSheetBase& );
348 const OUString& GetOldName() const { return aName; }
351 class SVL_DLLPUBLIC SfxUnoStyleSheet : public cppu::ImplInheritanceHelper<SfxStyleSheet, css::style::XStyle, css::lang::XUnoTunnel>
353 public:
354 SfxUnoStyleSheet( const OUString& _rName, const SfxStyleSheetBasePool& _rPool, SfxStyleFamily _eFamily, SfxStyleSearchBits _nMask );
356 static SfxUnoStyleSheet* getUnoStyleSheet( const css::uno::Reference< css::style::XStyle >& xStyle );
358 // XUnoTunnel
359 virtual ::sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< ::sal_Int8 >& aIdentifier ) override;
361 private:
362 static const css::uno::Sequence< ::sal_Int8 >& getIdentifier();
365 #endif
367 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */