Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / include / svl / style.hxx
bloba36c3757e09685eb9ea4ac837f8ae2d8e267b8c6
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;
79 protected:
80 SfxStyleSheetBasePool* pPool; // related pool
81 SfxStyleFamily nFamily;
83 OUString aName, aParent, aFollow;
84 OUString maDisplayName;
85 OUString aHelpFile; // name of the help file
86 SfxItemSet* pSet; // ItemSet
87 sal_uInt16 nMask; // Flags
89 sal_uLong nHelpId; // help ID
91 bool bMySet; // sal_True: delete Set in dtor
92 bool bHidden;
94 SfxStyleSheetBase( const OUString&, SfxStyleSheetBasePool*, SfxStyleFamily eFam, sal_uInt16 mask );
95 SfxStyleSheetBase( const SfxStyleSheetBase& );
96 virtual ~SfxStyleSheetBase();
97 virtual void Load( SvStream&, sal_uInt16 );
98 virtual void Store( SvStream& );
100 public:
102 // returns the internal name of this style
103 virtual const OUString& GetName() const;
105 // sets the internal name of this style.
107 // If the name of a style is changed, then the styles container needs to be
108 // reindexed (see IndexedStyleSheets). If you set bReindexNow to false to
109 // defer that indexing, then you must call the Reindex manually on the
110 // SfxStyleSheetBasePool parent.
111 virtual bool SetName(const OUString& rNewName, bool bReindexNow = true);
113 /** returns the display name of this style, it is used at the user interface.
114 If the display name is empty, this method returns the internal name. */
115 OUString GetDisplayName() const;
117 virtual const OUString& GetParent() const;
118 virtual bool SetParent( const OUString& );
119 virtual const OUString& GetFollow() const;
120 virtual bool SetFollow( const OUString& );
121 virtual bool HasFollowSupport() const; // Default true
122 virtual bool HasParentSupport() const; // Default true
123 virtual bool HasClearParentSupport() const; // Default false
124 virtual bool IsUsed() const; // Default true
125 virtual OUString GetDescription( SfxMapUnit eMetric );
127 SfxStyleSheetBasePool& GetPool() { return *pPool; }
128 SfxStyleFamily GetFamily() const { return nFamily; }
129 sal_uInt16 GetMask() const { return nMask; }
130 void SetMask( sal_uInt16 mask) { nMask = mask; }
131 bool IsUserDefined() const
132 { return ( nMask & SFXSTYLEBIT_USERDEF) != 0; }
134 virtual bool IsHidden() const { return bHidden; }
135 virtual void SetHidden( bool bValue );
137 virtual sal_uLong GetHelpId( OUString& rFile );
138 virtual void SetHelpId( const OUString& r, sal_uLong nId );
140 virtual SfxItemSet& GetItemSet();
141 /// Due to writer's usual lack of sanity this is a separate function for
142 /// preview only; it shall not create the style in case it does not exist.
143 /// If the style has parents, it is _not_ required that the returned item
144 /// set has parents (i.e. use it for display purposes only).
145 virtual std::unique_ptr<SfxItemSet> GetItemSetForPreview();
148 /* Class to iterate and search on a SfxStyleSheetBasePool */
149 class SVL_DLLPUBLIC SfxStyleSheetIterator
151 public:
152 /** Constructor.
153 * The iterator will only iterate over style sheets which have the family \p eFam
155 SfxStyleSheetIterator(SfxStyleSheetBasePool *pBase,
156 SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
157 sal_uInt16 GetSearchMask() const;
158 SfxStyleFamily GetSearchFamily() const;
159 virtual sal_uInt16 Count();
160 virtual SfxStyleSheetBase *operator[](sal_uInt16 nIdx);
161 virtual SfxStyleSheetBase* First();
162 virtual SfxStyleSheetBase* Next();
163 virtual SfxStyleSheetBase* Find(const OUString& rStr);
164 virtual ~SfxStyleSheetIterator();
166 bool SearchUsed() const { return bSearchUsed; }
168 protected:
170 SfxStyleSheetBasePool* pBasePool;
171 SfxStyleFamily nSearchFamily;
172 sal_uInt16 nMask;
175 private:
176 SVL_DLLPRIVATE bool IsTrivialSearch();
178 SfxStyleSheetBase* pAktStyle;
179 sal_uInt16 nAktPosition;
180 bool bSearchUsed;
182 friend class SfxStyleSheetBasePool;
185 typedef std::shared_ptr< SfxStyleSheetIterator > SfxStyleSheetIteratorPtr;
188 class SfxStyleSheetBasePool_Impl;
190 class SVL_DLLPUBLIC SfxStyleSheetBasePool: public SfxBroadcaster, public comphelper::OWeakTypeObject
192 friend class SfxStyleSheetIterator;
193 friend class SfxStyleSheetBase;
195 SfxStyleSheetBasePool_Impl *pImp;
197 protected:
198 SfxStyleSheetIterator& GetIterator_Impl();
200 OUString aAppName;
201 SfxItemPool& rPool;
202 SfxStyleFamily nSearchFamily;
203 sal_uInt16 nMask;
205 void ChangeParent( const OUString&, const OUString&, bool bVirtual = true );
206 virtual SfxStyleSheetBase* Create( const OUString&, SfxStyleFamily, sal_uInt16 );
207 virtual SfxStyleSheetBase* Create( const SfxStyleSheetBase& );
209 virtual ~SfxStyleSheetBasePool();
211 void StoreStyleSheet(const rtl::Reference< SfxStyleSheetBase >&);
213 /** Obtain the indexed style sheets.
215 const svl::IndexedStyleSheets&
216 GetIndexedStyleSheets() const;
217 rtl::Reference<SfxStyleSheetBase>
218 GetStyleSheetByPositionInIndex(unsigned pos);
220 public:
221 SfxStyleSheetBasePool( SfxItemPool& );
222 SfxStyleSheetBasePool( const SfxStyleSheetBasePool& );
224 SfxItemPool& GetPool() { return rPool;}
225 const SfxItemPool& GetPool() const { return rPool;}
227 virtual SfxStyleSheetIteratorPtr CreateIterator(SfxStyleFamily, sal_uInt16 nMask);
228 sal_uInt16 Count();
229 SfxStyleSheetBase* operator[](sal_uInt16 nIdx);
231 virtual SfxStyleSheetBase& Make(const OUString&,
232 SfxStyleFamily eFam,
233 sal_uInt16 nMask = SFXSTYLEBIT_ALL);
235 virtual void Remove( SfxStyleSheetBase* );
236 void Insert( SfxStyleSheetBase* );
238 void Clear();
240 SfxStyleSheetBasePool& operator=( const SfxStyleSheetBasePool& );
241 SfxStyleSheetBasePool& operator+=( const SfxStyleSheetBasePool& );
243 SfxStyleSheetBase* First();
244 SfxStyleSheetBase* Next();
245 virtual SfxStyleSheetBase* Find( const OUString&, SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
247 virtual bool SetParent(SfxStyleFamily eFam,
248 const OUString &rStyle,
249 const OUString &rParent);
251 SfxStyleSheetBase* Find(const OUString& rStr)
252 { return Find(rStr, nSearchFamily, nMask); }
254 void SetSearchMask(SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
255 sal_uInt16 GetSearchMask() const { return nMask;}
256 SfxStyleFamily GetSearchFamily() const { return nSearchFamily; }
258 void Reindex();
259 /** Add a style sheet.
260 * Not an actual public function. Do not call it from non-subclasses.
262 void Add( const SfxStyleSheetBase& );
265 class SVL_DLLPUBLIC SfxStyleSheet: public SfxStyleSheetBase,
266 public SfxListener, public SfxBroadcaster, public svl::StyleSheetUser
268 public:
270 SfxStyleSheet( const OUString&, const SfxStyleSheetBasePool&, SfxStyleFamily, sal_uInt16 );
271 SfxStyleSheet( const SfxStyleSheet& );
273 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
275 virtual bool isUsedByModel() const override;
277 virtual bool SetParent( const OUString& ) override;
279 protected:
280 SfxStyleSheet() // do not use! needed by MSVC at compile time to satisfy ImplInheritanceHelper2
281 : SfxStyleSheetBase(OUString("dummy"), nullptr, SfxStyleFamily::All, 0)
283 assert(false);
285 virtual ~SfxStyleSheet();
289 class SVL_DLLPUBLIC SfxStyleSheetPool: public SfxStyleSheetBasePool
291 protected:
292 using SfxStyleSheetBasePool::Create;
293 virtual SfxStyleSheetBase* Create(const OUString&, SfxStyleFamily, sal_uInt16 mask) override;
295 public:
296 SfxStyleSheetPool( SfxItemPool const& );
300 enum SfxStyleSheetHintId
302 CREATED = 1, // new
303 MODIFIED = 2, // changed
304 CHANGED = 3, // erased and re-created (replaced)
305 ERASED = 4, // erased
306 INDESTRUCTION = 5, // in the process of being destructed
309 class SVL_DLLPUBLIC SfxStyleSheetPoolHint : public SfxHint
311 public:
312 SfxStyleSheetPoolHint(SfxStyleSheetHintId ) {}
316 class SVL_DLLPUBLIC SfxStyleSheetHint: public SfxHint
318 SfxStyleSheetBase* pStyleSh;
319 sal_uInt16 nHint;
321 public:
322 SfxStyleSheetHint( sal_uInt16, SfxStyleSheetBase& );
323 SfxStyleSheetBase* GetStyleSheet() const
324 { return pStyleSh; }
325 sal_uInt16 GetHint() const
326 { return nHint; }
329 class SVL_DLLPUBLIC SfxStyleSheetHintExtended: public SfxStyleSheetHint
331 OUString aName;
333 public:
334 SfxStyleSheetHintExtended( sal_uInt16, const OUString& rOld,
335 SfxStyleSheetBase& );
336 const OUString& GetOldName() const { return aName; }
339 class SVL_DLLPUBLIC SfxUnoStyleSheet : public ::cppu::ImplInheritanceHelper2< SfxStyleSheet, css::style::XStyle, css::lang::XUnoTunnel >
341 public:
342 SfxUnoStyleSheet( const OUString& _rName, const SfxStyleSheetBasePool& _rPool, SfxStyleFamily _eFamily, sal_uInt16 _nMaske );
344 static SfxUnoStyleSheet* getUnoStyleSheet( const css::uno::Reference< css::style::XStyle >& xStyle );
346 // XUnoTunnel
347 virtual ::sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< ::sal_Int8 >& aIdentifier ) throw (css::uno::RuntimeException, std::exception) override;
349 private:
350 static const css::uno::Sequence< ::sal_Int8 >& getIdentifier();
353 #endif
355 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */