build fix
[LibreOffice.git] / include / svl / style.hxx
blob6e0b0b996a9c12833f25aba9a646dc79d5cd7b54
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 <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() override;
97 virtual void Load( SvStream&, sal_uInt16 );
99 public:
101 // returns the internal name of this style
102 const OUString& GetName() const;
104 // sets the internal name of this style.
106 // If the name of a style is changed, then the styles container needs to be
107 // reindexed (see IndexedStyleSheets). If you set bReindexNow to false to
108 // defer that indexing, then you must call the Reindex manually on the
109 // SfxStyleSheetBasePool parent.
110 virtual bool SetName(const OUString& rNewName, bool bReindexNow = true);
112 /** returns the display name of this style, it is used at the user interface.
113 If the display name is empty, this method returns the internal name. */
114 OUString const & GetDisplayName() const;
116 virtual const OUString& GetParent() const;
117 virtual bool SetParent( const OUString& );
118 virtual const OUString& GetFollow() const;
119 virtual bool SetFollow( const OUString& );
120 virtual bool HasFollowSupport() const; // Default true
121 virtual bool HasParentSupport() const; // Default true
122 virtual bool HasClearParentSupport() const; // Default false
123 virtual bool IsUsed() const; // Default true
124 virtual OUString GetDescription( MapUnit eMetric );
126 SfxStyleSheetBasePool& GetPool() { return *pPool; }
127 SfxStyleFamily GetFamily() const { return nFamily; }
128 sal_uInt16 GetMask() const { return nMask; }
129 void SetMask( sal_uInt16 mask) { nMask = mask; }
130 bool IsUserDefined() const
131 { return ( nMask & SFXSTYLEBIT_USERDEF) != 0; }
133 virtual bool IsHidden() const { return bHidden; }
134 virtual void SetHidden( bool bValue );
136 virtual sal_uLong GetHelpId( OUString& rFile );
137 virtual void SetHelpId( const OUString& r, sal_uLong nId );
139 virtual SfxItemSet& GetItemSet();
140 /// Due to writer's usual lack of sanity this is a separate function for
141 /// preview only; it shall not create the style in case it does not exist.
142 /// If the style has parents, it is _not_ required that the returned item
143 /// set has parents (i.e. use it for display purposes only).
144 virtual std::unique_ptr<SfxItemSet> GetItemSetForPreview();
147 /* Class to iterate and search on a SfxStyleSheetBasePool */
148 class SVL_DLLPUBLIC SfxStyleSheetIterator
150 public:
151 /** Constructor.
152 * The iterator will only iterate over style sheets which have the family \p eFam
154 SfxStyleSheetIterator(SfxStyleSheetBasePool *pBase,
155 SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
156 sal_uInt16 GetSearchMask() const;
157 SfxStyleFamily GetSearchFamily() const;
158 virtual sal_uInt16 Count();
159 virtual SfxStyleSheetBase *operator[](sal_uInt16 nIdx);
160 virtual SfxStyleSheetBase* First();
161 virtual SfxStyleSheetBase* Next();
162 virtual SfxStyleSheetBase* Find(const OUString& rStr);
163 virtual ~SfxStyleSheetIterator();
165 bool SearchUsed() const { return bSearchUsed; }
167 protected:
169 SfxStyleSheetBasePool* pBasePool;
170 SfxStyleFamily nSearchFamily;
171 sal_uInt16 nMask;
174 private:
175 SVL_DLLPRIVATE bool IsTrivialSearch();
177 SfxStyleSheetBase* pAktStyle;
178 sal_uInt16 nAktPosition;
179 bool bSearchUsed;
181 friend class SfxStyleSheetBasePool;
184 class SfxStyleSheetBasePool_Impl;
186 class SVL_DLLPUBLIC SfxStyleSheetBasePool: public SfxBroadcaster, public comphelper::OWeakTypeObject
188 friend class SfxStyleSheetIterator;
189 friend class SfxStyleSheetBase;
191 std::unique_ptr<SfxStyleSheetBasePool_Impl> pImpl;
193 protected:
194 SfxStyleSheetIterator& GetIterator_Impl();
196 SfxItemPool& rPool;
197 SfxStyleFamily nSearchFamily;
198 sal_uInt16 nMask;
200 void ChangeParent( const OUString&, const OUString&, bool bVirtual = true );
201 virtual SfxStyleSheetBase* Create( const OUString&, SfxStyleFamily, sal_uInt16 );
202 virtual SfxStyleSheetBase* Create( const SfxStyleSheetBase& );
204 virtual ~SfxStyleSheetBasePool() override;
206 void StoreStyleSheet(const rtl::Reference< SfxStyleSheetBase >&);
208 /** Obtain the indexed style sheets.
210 const svl::IndexedStyleSheets&
211 GetIndexedStyleSheets() const;
212 rtl::Reference<SfxStyleSheetBase>
213 GetStyleSheetByPositionInIndex(unsigned pos);
215 public:
216 SfxStyleSheetBasePool( SfxItemPool& );
217 SfxStyleSheetBasePool( const SfxStyleSheetBasePool& );
219 SfxItemPool& GetPool() { return rPool;}
220 const SfxItemPool& GetPool() const { return rPool;}
222 virtual std::shared_ptr<SfxStyleSheetIterator> CreateIterator(SfxStyleFamily, sal_uInt16 nMask);
223 sal_uInt16 Count();
224 SfxStyleSheetBase* operator[](sal_uInt16 nIdx);
226 virtual SfxStyleSheetBase& Make(const OUString&,
227 SfxStyleFamily eFam,
228 sal_uInt16 nMask = SFXSTYLEBIT_ALL);
230 virtual void Remove( SfxStyleSheetBase* );
231 void Insert( SfxStyleSheetBase* );
233 void Clear();
235 SfxStyleSheetBasePool& operator=( const SfxStyleSheetBasePool& );
236 SfxStyleSheetBasePool& operator+=( const SfxStyleSheetBasePool& );
238 SfxStyleSheetBase* First();
239 SfxStyleSheetBase* Next();
240 virtual SfxStyleSheetBase* Find( const OUString&, SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
242 virtual bool SetParent(SfxStyleFamily eFam,
243 const OUString &rStyle,
244 const OUString &rParent);
246 SfxStyleSheetBase* Find(const OUString& rStr)
247 { return Find(rStr, nSearchFamily, nMask); }
249 void SetSearchMask(SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
250 sal_uInt16 GetSearchMask() const { return nMask;}
251 SfxStyleFamily GetSearchFamily() const { return nSearchFamily; }
253 void Reindex();
254 /** Add a style sheet.
255 * Not an actual public function. Do not call it from non-subclasses.
257 void Add( const SfxStyleSheetBase& );
260 class SVL_DLLPUBLIC SfxStyleSheet: public SfxStyleSheetBase,
261 public SfxListener, public SfxBroadcaster, public svl::StyleSheetUser
263 public:
265 SfxStyleSheet( const OUString&, const SfxStyleSheetBasePool&, SfxStyleFamily, sal_uInt16 );
266 SfxStyleSheet( const SfxStyleSheet& );
268 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
270 virtual bool isUsedByModel() const override;
272 virtual bool SetParent( const OUString& ) override;
274 protected:
275 SfxStyleSheet() // do not use! needed by MSVC at compile time to satisfy ImplInheritanceHelper
276 : SfxStyleSheetBase(OUString("dummy"), nullptr, SfxStyleFamily::All, 0)
278 assert(false);
280 virtual ~SfxStyleSheet() override;
284 class SVL_DLLPUBLIC SfxStyleSheetPool: public SfxStyleSheetBasePool
286 protected:
287 using SfxStyleSheetBasePool::Create;
288 virtual SfxStyleSheetBase* Create(const OUString&, SfxStyleFamily, sal_uInt16 mask) override;
290 public:
291 SfxStyleSheetPool( SfxItemPool const& );
295 enum SfxStyleSheetHintId
297 CREATED = 1, // new
298 MODIFIED = 2, // changed
299 CHANGED = 3, // erased and re-created (replaced)
300 ERASED = 4, // erased
301 INDESTRUCTION = 5, // in the process of being destructed
304 class SVL_DLLPUBLIC SfxStyleSheetPoolHint : public SfxHint
306 public:
307 SfxStyleSheetPoolHint() {}
311 class SVL_DLLPUBLIC SfxStyleSheetHint: public SfxHint
313 SfxStyleSheetBase* pStyleSh;
314 sal_uInt16 nHint;
316 public:
317 SfxStyleSheetHint( sal_uInt16, SfxStyleSheetBase& );
318 SfxStyleSheetBase* GetStyleSheet() const
319 { return pStyleSh; }
320 sal_uInt16 GetHint() const
321 { return nHint; }
324 class SVL_DLLPUBLIC SfxStyleSheetHintExtended: public SfxStyleSheetHint
326 OUString aName;
328 public:
329 SfxStyleSheetHintExtended( sal_uInt16, const OUString& rOld,
330 SfxStyleSheetBase& );
331 const OUString& GetOldName() const { return aName; }
334 class SVL_DLLPUBLIC SfxUnoStyleSheet : public cppu::ImplInheritanceHelper<SfxStyleSheet, css::style::XStyle, css::lang::XUnoTunnel>
336 public:
337 SfxUnoStyleSheet( const OUString& _rName, const SfxStyleSheetBasePool& _rPool, SfxStyleFamily _eFamily, sal_uInt16 _nMaske );
339 static SfxUnoStyleSheet* getUnoStyleSheet( const css::uno::Reference< css::style::XStyle >& xStyle );
341 // XUnoTunnel
342 virtual ::sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< ::sal_Int8 >& aIdentifier ) throw (css::uno::RuntimeException, std::exception) override;
344 private:
345 static const css::uno::Sequence< ::sal_Int8 >& getIdentifier();
348 #endif
350 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */