update credits
[LibreOffice.git] / include / svl / style.hxx
blob79eadf62cc7ad5749248861afbc7d92593304469
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/implbase2.hxx>
29 #include <svl/svldllapi.h>
30 #include <rsc/rscsfx.hxx>
31 #include <svl/hint.hxx>
32 #include <svl/lstner.hxx>
33 #include <svl/poolitem.hxx>
34 #include <svl/SfxBroadcaster.hxx>
35 #include <svl/stylesheetuser.hxx>
37 #include <svl/style.hrc>
38 #include <memory>
40 class SfxItemSet;
41 class SfxItemPool;
42 class SfxStyleSheetBasePool;
43 class SvStream;
45 namespace svl { class IndexedStyleSheets; }
47 Everyone changing instances of SfxStyleSheetBasePool or SfxStyleSheetBase
48 must broadcast this using <SfxStyleSheetBasePool::GetBroadcaster()> broadcasts.
49 The class <SfxStyleSheetHint> is used for this, it contains an Action-Id and a
50 pointer to the <SfxStyleSheetBase>. The actions are:
52 #define SfxStyleSheetHintId::CREATED // style is created
53 #define SfxStyleSheetHintId::MODIFIED // style is modified
54 #define SfxStyleSheetHintId::CHANGED // style is replaced
55 #define SfxStyleSheetHintId::ERASED // style is deleted
57 The following methods already broadcast themself
59 SfxSimpleHint(SFX_HINT_DYING) from:
60 SfxStyleSheetBasePool::~SfxStyleSheetBasePool()
62 SfxStyleSheetHint( SfxStyleSheetHintId::CREATED, *p ) from:
63 SfxStyleSheetBasePool::Make( const String& rName,
64 SfxStyleFamily eFam, sal_uInt16 mask)
66 SfxStyleSheetHint( SfxStyleSheetHintId::CHANGED, *pNew ) from:
67 SfxStyleSheetBasePool::Add( SfxStyleSheetBase& rSheet )
69 SfxStyleSheetHint( SfxStyleSheetHintId::ERASED, *p ) from:
70 SfxStyleSheetBasePool::Erase( SfxStyleSheetBase* p )
71 SfxStyleSheetBasePool::Clear()
74 class SVL_DLLPUBLIC SfxStyleSheetBase : public comphelper::OWeakTypeObject
76 private:
77 friend class SfxStyleSheetBasePool;
78 SVL_DLLPRIVATE static SfxStyleSheetBasePool& implGetStaticPool();
80 protected:
81 SfxStyleSheetBasePool* pPool; // related pool
82 SfxStyleFamily nFamily;
84 OUString aName, aParent, aFollow;
85 OUString maDisplayName;
86 OUString aHelpFile; // name of the help file
87 SfxItemSet* pSet; // ItemSet
88 sal_uInt16 nMask; // Flags
90 sal_uLong nHelpId; // help ID
92 bool bMySet; // sal_True: delete Set in dtor
93 bool bHidden;
95 SfxStyleSheetBase( const OUString&, SfxStyleSheetBasePool*, SfxStyleFamily eFam, sal_uInt16 mask );
96 SfxStyleSheetBase( const SfxStyleSheetBase& );
97 virtual ~SfxStyleSheetBase();
98 virtual void Load( SvStream&, sal_uInt16 );
99 virtual void Store( SvStream& );
101 public:
102 TYPEINFO();
104 // returns the internal name of this style
105 virtual const OUString& GetName() const;
107 // sets the internal name of this style.
109 // If the name of a style is changed, then the styles container needs to be
110 // reindexed (see IndexedStyleSheets). If you set bReindexNow to false to
111 // defer that indexing, then you must call the Reindex manually on the
112 // SfxStyleSheetBasePool parent.
113 virtual bool SetName(const OUString& rNewName, bool bReindexNow = true);
115 /** returns the display name of this style, it is used at the user interface.
116 If the display name is empty, this method returns the internal name. */
117 OUString GetDisplayName() const;
119 virtual const OUString& GetParent() const;
120 virtual bool SetParent( const OUString& );
121 virtual const OUString& GetFollow() const;
122 virtual bool SetFollow( const OUString& );
123 virtual bool HasFollowSupport() const; // Default true
124 virtual bool HasParentSupport() const; // Default true
125 virtual bool HasClearParentSupport() const; // Default false
126 virtual bool IsUsed() const; // Default true
127 // Default from the Itemset; either from the passed one
128 // or from the Set returned by GetItemSet()
129 virtual OUString GetDescription();
130 virtual OUString GetDescription( SfxMapUnit eMetric );
132 SfxStyleSheetBasePool& GetPool() { return *pPool; }
133 SfxStyleFamily GetFamily() const { return nFamily; }
134 sal_uInt16 GetMask() const { return nMask; }
135 void SetMask( sal_uInt16 mask) { nMask = mask; }
136 bool IsUserDefined() const
137 { return ( nMask & SFXSTYLEBIT_USERDEF) != 0; }
139 virtual bool IsHidden() const { return bHidden; }
140 virtual void SetHidden( bool bValue );
142 virtual sal_uLong GetHelpId( OUString& rFile );
143 virtual void SetHelpId( const OUString& r, sal_uLong nId );
145 virtual SfxItemSet& GetItemSet();
146 /// Due to writer's usual lack of sanity this is a separate function for
147 /// preview only; it shall not create the style in case it does not exist.
148 /// If the style has parents, it is _not_ required that the returned item
149 /// set has parents (i.e. use it for display purposes only).
150 virtual std::unique_ptr<SfxItemSet> GetItemSetForPreview();
153 /* Class to iterate and search on a SfxStyleSheetBasePool */
154 class SVL_DLLPUBLIC SfxStyleSheetIterator
156 public:
157 /** Constructor.
158 * The iterator will only iterate over style sheets which have the family \p eFam
160 SfxStyleSheetIterator(SfxStyleSheetBasePool *pBase,
161 SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
162 sal_uInt16 GetSearchMask() const;
163 SfxStyleFamily GetSearchFamily() const;
164 virtual sal_uInt16 Count();
165 virtual SfxStyleSheetBase *operator[](sal_uInt16 nIdx);
166 virtual SfxStyleSheetBase* First();
167 virtual SfxStyleSheetBase* Next();
168 virtual SfxStyleSheetBase* Find(const OUString& rStr);
169 virtual ~SfxStyleSheetIterator();
171 bool SearchUsed() const { return bSearchUsed; }
173 protected:
175 SfxStyleSheetBasePool* pBasePool;
176 SfxStyleFamily nSearchFamily;
177 sal_uInt16 nMask;
180 private:
181 sal_uInt16 GetPos() { return nAktPosition; }
182 SVL_DLLPRIVATE bool IsTrivialSearch();
184 SfxStyleSheetBase* pAktStyle;
185 sal_uInt16 nAktPosition;
186 bool bSearchUsed;
188 friend class SfxStyleSheetBasePool;
191 typedef std::shared_ptr< SfxStyleSheetIterator > SfxStyleSheetIteratorPtr;
194 class SfxStyleSheetBasePool_Impl;
196 class SVL_DLLPUBLIC SfxStyleSheetBasePool: public SfxBroadcaster, public comphelper::OWeakTypeObject
198 friend class SfxStyleSheetIterator;
199 friend class SfxStyleSheetBase;
201 SfxStyleSheetBasePool_Impl *pImp;
203 protected:
204 SfxStyleSheetIterator& GetIterator_Impl();
206 OUString aAppName;
207 SfxItemPool& rPool;
208 SfxStyleFamily nSearchFamily;
209 sal_uInt16 nMask;
211 void ChangeParent( const OUString&, const OUString&, bool bVirtual = true );
212 virtual SfxStyleSheetBase* Create( const OUString&, SfxStyleFamily, sal_uInt16 );
213 virtual SfxStyleSheetBase* Create( const SfxStyleSheetBase& );
215 virtual ~SfxStyleSheetBasePool();
217 void StoreStyleSheet(rtl::Reference< SfxStyleSheetBase >);
219 /** Obtain the indexed style sheets.
221 const svl::IndexedStyleSheets&
222 GetIndexedStyleSheets() const;
223 rtl::Reference<SfxStyleSheetBase>
224 GetStyleSheetByPositionInIndex(unsigned pos);
226 public:
227 SfxStyleSheetBasePool( SfxItemPool& );
228 SfxStyleSheetBasePool( const SfxStyleSheetBasePool& );
230 const OUString& GetAppName() const { return aAppName; }
232 SfxItemPool& GetPool() { return rPool;}
233 const SfxItemPool& GetPool() const { return rPool;}
235 virtual SfxStyleSheetIteratorPtr CreateIterator(SfxStyleFamily, sal_uInt16 nMask);
236 sal_uInt16 Count();
237 SfxStyleSheetBase* operator[](sal_uInt16 nIdx);
239 virtual SfxStyleSheetBase& Make(const OUString&,
240 SfxStyleFamily eFam,
241 sal_uInt16 nMask = SFXSTYLEBIT_ALL);
243 virtual void Replace(
244 SfxStyleSheetBase& rSource, SfxStyleSheetBase& rTarget );
246 virtual void Remove( SfxStyleSheetBase* );
247 void Insert( SfxStyleSheetBase* );
249 void Clear();
251 SfxStyleSheetBasePool& operator=( const SfxStyleSheetBasePool& );
252 SfxStyleSheetBasePool& operator+=( const SfxStyleSheetBasePool& );
254 unsigned GetNumberOfStyles();
256 SfxStyleSheetBase* First();
257 SfxStyleSheetBase* Next();
258 virtual SfxStyleSheetBase* Find( const OUString&, SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
260 virtual bool SetParent(SfxStyleFamily eFam,
261 const OUString &rStyle,
262 const OUString &rParent);
264 SfxStyleSheetBase* Find(const OUString& rStr)
265 { return Find(rStr, nSearchFamily, nMask); }
267 void SetSearchMask(SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
268 sal_uInt16 GetSearchMask() const { return nMask;}
269 SfxStyleFamily GetSearchFamily() const { return nSearchFamily; }
271 void Reindex();
272 /** Add a style sheet.
273 * Not an actual public function. Do not call it from non-subclasses.
275 SfxStyleSheetBase& Add( const SfxStyleSheetBase& );
278 class SVL_DLLPUBLIC SfxStyleSheet: public SfxStyleSheetBase,
279 public SfxListener, public SfxBroadcaster, public svl::StyleSheetUser
281 public:
282 TYPEINFO_OVERRIDE();
284 SfxStyleSheet( const OUString&, const SfxStyleSheetBasePool&, SfxStyleFamily, sal_uInt16 );
285 SfxStyleSheet( const SfxStyleSheet& );
287 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
289 virtual bool isUsedByModel() const SAL_OVERRIDE;
291 virtual bool SetParent( const OUString& ) SAL_OVERRIDE;
293 protected:
294 SfxStyleSheet() // do not use! needed by MSVC at compile time to satisfy ImplInheritanceHelper2
295 : SfxStyleSheetBase(OUString("dummy"), NULL, SFX_STYLE_FAMILY_ALL, 0)
297 assert(false);
299 virtual ~SfxStyleSheet();
303 class SVL_DLLPUBLIC SfxStyleSheetPool: public SfxStyleSheetBasePool
305 protected:
306 using SfxStyleSheetBasePool::Create;
307 virtual SfxStyleSheetBase* Create(const OUString&, SfxStyleFamily, sal_uInt16 mask) SAL_OVERRIDE;
309 public:
310 SfxStyleSheetPool( SfxItemPool const& );
315 enum SfxStyleSheetHintId
317 CREATED = 1, // new
318 MODIFIED = 2, // changed
319 CHANGED = 3, // erased and re-created (replaced)
320 ERASED = 4, // erased
321 INDESTRUCTION = 5, // in the process of being destructed
324 class SVL_DLLPUBLIC SfxStyleSheetPoolHint : public SfxHint
326 SfxStyleSheetHintId nHint;
328 public:
329 SfxStyleSheetPoolHint(SfxStyleSheetHintId nArgHint) : nHint(nArgHint){}
330 SfxStyleSheetHintId GetHint() const
331 { return nHint; }
336 class SVL_DLLPUBLIC SfxStyleSheetHint: public SfxHint
338 SfxStyleSheetBase* pStyleSh;
339 sal_uInt16 nHint;
341 public:
342 SfxStyleSheetHint( sal_uInt16, SfxStyleSheetBase& );
343 SfxStyleSheetBase* GetStyleSheet() const
344 { return pStyleSh; }
345 sal_uInt16 GetHint() const
346 { return nHint; }
349 class SVL_DLLPUBLIC SfxStyleSheetHintExtended: public SfxStyleSheetHint
351 OUString aName;
353 public:
354 SfxStyleSheetHintExtended( sal_uInt16, const OUString& rOld,
355 SfxStyleSheetBase& );
356 const OUString& GetOldName() const { return aName; }
359 class SVL_DLLPUBLIC SfxUnoStyleSheet : public ::cppu::ImplInheritanceHelper2< SfxStyleSheet, ::com::sun::star::style::XStyle, ::com::sun::star::lang::XUnoTunnel >
361 public:
362 SfxUnoStyleSheet( const OUString& _rName, const SfxStyleSheetBasePool& _rPool, SfxStyleFamily _eFamily, sal_uInt16 _nMaske );
364 static SfxUnoStyleSheet* getUnoStyleSheet( const ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle >& xStyle );
366 // XUnoTunnel
367 virtual ::sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aIdentifier ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
369 private:
370 SfxUnoStyleSheet(); // not implemented
372 static const ::com::sun::star::uno::Sequence< ::sal_Int8 >& getIdentifier();
375 #endif
377 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */