1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <config_options.h>
24 #include <com/sun/star/style/XStyle.hpp>
25 #include <com/sun/star/lang/XUnoTunnel.hpp>
27 #include <rtl/ref.hxx>
28 #include <comphelper/weak.hxx>
29 #include <cppuhelper/implbase.hxx>
30 #include <svl/svldllapi.h>
31 #include <svl/hint.hxx>
32 #include <svl/lstner.hxx>
33 #include <svl/SfxBroadcaster.hxx>
34 #include <svl/stylesheetuser.hxx>
35 #include <o3tl/typed_flags_set.hxx>
36 #include <tools/mapunit.hxx>
37 #include <tools/solar.h>
41 // This is used as a flags enum in sw/, but only there,
42 // so I don't pull in o3tl::typed_flags here
43 enum class SfxStyleFamily
{
55 enum class SfxStyleSearchBits
{
68 Auto
= 0x0000, ///< automatic: flags from application
69 Hidden
= 0x0200, ///< hidden styles (search mask)
70 ReadOnly
= 0x2000, ///< readonly styles (search mask)
71 Used
= 0x4000, ///< used styles (search mask)
72 UserDefined
= 0x8000, ///< user defined styles (search mask)
73 AllVisible
= 0xe07f, ///< all visible styles
74 All
= 0xe27f, ///< all styles
77 template<> struct typed_flags
<SfxStyleSearchBits
> : is_typed_flags
<SfxStyleSearchBits
, 0xe27f> {};
83 class SfxStyleSheetBasePool
;
86 namespace svl
{ class IndexedStyleSheets
; }
88 Everyone changing instances of SfxStyleSheetBasePool or SfxStyleSheetBase
89 must broadcast this using <SfxStyleSheetBasePool::GetBroadcaster()> broadcasts.
90 The class <SfxStyleSheetHint> is used for this, it contains an Action-Id and a
91 pointer to the <SfxStyleSheetBase>. The actions are:
93 #define SfxHintId::StyleSheetCreated // style is created
94 #define SfxHintId::StyleSheetModified // style is modified
95 #define SfxHintId::StyleSheetChanged // style is replaced
96 #define SfxHintId::StyleSheetErased // style is deleted
98 The following methods already broadcast themself
100 SfxSimpleHint(SfxHintId::Dying) from:
101 SfxStyleSheetBasePool::~SfxStyleSheetBasePool()
103 SfxStyleSheetHint( SfxHintId::StyleSheetCreated, *p ) from:
104 SfxStyleSheetBasePool::Make( const String& rName,
105 SfxStyleFamily eFam, sal_uInt16 mask)
107 SfxStyleSheetHint( SfxHintId::StyleSheetChanged, *pNew ) from:
108 SfxStyleSheetBasePool::Add( SfxStyleSheetBase& rSheet )
110 SfxStyleSheetHint( SfxHintId::StyleSheetErased, *p ) from:
111 SfxStyleSheetBasePool::Erase( SfxStyleSheetBase* p )
112 SfxStyleSheetBasePool::Clear()
115 class SVL_DLLPUBLIC SfxStyleSheetBase
: public comphelper::OWeakTypeObject
118 friend class SfxStyleSheetBasePool
;
121 SfxStyleSheetBasePool
* m_pPool
; // related pool
122 SfxStyleFamily nFamily
;
124 OUString aName
, aParent
, aFollow
;
125 OUString aHelpFile
; // name of the help file
126 SfxItemSet
* pSet
; // ItemSet
127 SfxStyleSearchBits nMask
; // Flags
129 sal_uLong nHelpId
; // help ID
131 bool bMySet
; // sal_True: delete Set in dtor
134 SfxStyleSheetBase( const OUString
&, SfxStyleSheetBasePool
*, SfxStyleFamily eFam
, SfxStyleSearchBits mask
);
135 SfxStyleSheetBase( const SfxStyleSheetBase
& );
136 virtual ~SfxStyleSheetBase() override
;
140 // returns the internal name of this style
141 const OUString
& GetName() const;
143 // sets the internal name of this style.
145 // If the name of a style is changed, then the styles container needs to be
146 // reindexed (see IndexedStyleSheets). If you set bReindexNow to false to
147 // defer that indexing, then you must call the Reindex manually on the
148 // SfxStyleSheetBasePool parent.
149 virtual bool SetName(const OUString
& rNewName
, bool bReindexNow
= true);
151 virtual const OUString
& GetParent() const;
152 virtual bool SetParent( const OUString
& );
153 virtual const OUString
& GetFollow() const;
154 virtual bool SetFollow( const OUString
& );
155 virtual bool HasFollowSupport() const; // Default true
156 virtual bool HasParentSupport() const; // Default true
157 virtual bool HasClearParentSupport() const; // Default false
158 virtual bool IsUsed() const; // Default true
159 virtual OUString
GetDescription( MapUnit eMetric
);
161 virtual OUString
GetUsedBy() { return OUString(); }
163 SfxStyleSheetBasePool
* GetPool() { return m_pPool
; }
164 SfxStyleFamily
GetFamily() const { return nFamily
; }
165 SfxStyleSearchBits
GetMask() const { return nMask
; }
166 void SetMask( SfxStyleSearchBits mask
) { nMask
= mask
; }
167 bool IsUserDefined() const
168 { return bool( nMask
& SfxStyleSearchBits::UserDefined
); }
170 virtual bool IsHidden() const { return bHidden
; }
171 virtual void SetHidden( bool bValue
);
173 virtual sal_uLong
GetHelpId( OUString
& rFile
);
174 virtual void SetHelpId( const OUString
& r
, sal_uLong nId
);
176 virtual SfxItemSet
& GetItemSet();
177 /// Due to writer's usual lack of sanity this is a separate function for
178 /// preview only; it shall not create the style in case it does not exist.
179 /// If the style has parents, it is _not_ required that the returned item
180 /// set has parents (i.e. use it for display purposes only).
181 virtual std::unique_ptr
<SfxItemSet
> GetItemSetForPreview();
183 /// Fix for expensive dynamic_cast
184 virtual bool isScStyleSheet() const { return false; }
187 /* Class to iterate and search on a SfxStyleSheetBasePool */
188 class SVL_DLLPUBLIC SfxStyleSheetIterator
192 * The iterator will only iterate over style sheets which have the family \p eFam
194 SfxStyleSheetIterator(SfxStyleSheetBasePool
*pBase
,
195 SfxStyleFamily eFam
, SfxStyleSearchBits n
=SfxStyleSearchBits::All
);
196 SfxStyleSearchBits
GetSearchMask() const;
197 SfxStyleFamily
GetSearchFamily() const;
198 virtual sal_Int32
Count();
199 virtual SfxStyleSheetBase
*operator[](sal_Int32 nIdx
);
200 virtual SfxStyleSheetBase
* First();
201 virtual SfxStyleSheetBase
* Next();
202 virtual SfxStyleSheetBase
* Find(const OUString
& rStr
);
203 virtual ~SfxStyleSheetIterator();
205 bool SearchUsed() const { return bSearchUsed
; }
209 SfxStyleSheetBasePool
* pBasePool
;
210 SfxStyleFamily nSearchFamily
;
211 SfxStyleSearchBits nMask
;
215 SVL_DLLPRIVATE
bool IsTrivialSearch() const;
217 SfxStyleSheetBase
* pCurrentStyle
;
218 sal_uInt16 nCurrentPosition
;
221 friend class SfxStyleSheetBasePool
;
224 class SfxStyleSheetBasePool_Impl
;
226 class SVL_DLLPUBLIC SfxStyleSheetBasePool
: public SfxBroadcaster
, public comphelper::OWeakTypeObject
228 friend class SfxStyleSheetIterator
;
229 friend class SfxStyleSheetBase
;
231 std::unique_ptr
<SfxStyleSheetBasePool_Impl
> pImpl
;
233 SfxStyleSheetIterator
& GetIterator_Impl(SfxStyleFamily eFamily
, SfxStyleSearchBits eMask
);
235 SfxStyleSheetIterator
* GetCachedIterator();
239 void ChangeParent(const OUString
& rOld
, const OUString
& rNew
, SfxStyleFamily eFamily
, 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
);
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
= SfxStyleSearchBits::All
);
262 virtual SfxStyleSheetBase
& Make(const OUString
&,
264 SfxStyleSearchBits nMask
= SfxStyleSearchBits::All
);
266 virtual void Remove( SfxStyleSheetBase
* );
267 void Insert( SfxStyleSheetBase
* );
271 SfxStyleSheetBasePool
& operator=( const SfxStyleSheetBasePool
& );
272 SfxStyleSheetBasePool
& operator+=( const SfxStyleSheetBasePool
& );
274 SfxStyleSheetBase
* First(SfxStyleFamily eFamily
, SfxStyleSearchBits eMask
= SfxStyleSearchBits::All
);
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
);
283 /** Add a style sheet.
284 * Not an actual public function. Do not call it from non-subclasses.
286 void Add( const SfxStyleSheetBase
& );
289 class SVL_DLLPUBLIC SfxStyleSheet
: public SfxStyleSheetBase
,
290 public SfxListener
, public SfxBroadcaster
, public svl::StyleSheetUser
294 SfxStyleSheet( const OUString
&, const SfxStyleSheetBasePool
&, SfxStyleFamily
, SfxStyleSearchBits
);
295 SfxStyleSheet( const SfxStyleSheet
& );
297 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
299 virtual bool isUsedByModel() const override
;
301 virtual bool SetParent( const OUString
& ) override
;
304 virtual ~SfxStyleSheet() override
;
307 class SVL_DLLPUBLIC SfxStyleSheetPool
: public SfxStyleSheetBasePool
310 using SfxStyleSheetBasePool::Create
;
311 virtual SfxStyleSheetBase
* Create(const OUString
&, SfxStyleFamily
, SfxStyleSearchBits mask
) override
;
314 SfxStyleSheetPool( SfxItemPool
const& );
318 class SVL_DLLPUBLIC SfxStyleSheetPoolHint final
: public SfxHint
321 SfxStyleSheetPoolHint() {}
325 class SVL_DLLPUBLIC SfxStyleSheetHint
: public SfxHint
327 SfxStyleSheetBase
* pStyleSh
;
329 SfxStyleSheetHint( SfxHintId
, SfxStyleSheetBase
& );
330 SfxStyleSheetBase
* GetStyleSheet() const
334 class UNLESS_MERGELIBS(SVL_DLLPUBLIC
) SfxStyleSheetModifiedHint final
: public SfxStyleSheetHint
339 SfxStyleSheetModifiedHint( const OUString
& rOld
,
340 SfxStyleSheetBase
& );
341 const OUString
& GetOldName() const { return aName
; }
344 class SVL_DLLPUBLIC SfxUnoStyleSheet
: public cppu::ImplInheritanceHelper
<SfxStyleSheet
, css::style::XStyle
, css::lang::XUnoTunnel
>
347 SfxUnoStyleSheet( const OUString
& _rName
, const SfxStyleSheetBasePool
& _rPool
, SfxStyleFamily _eFamily
, SfxStyleSearchBits _nMask
);
349 static SfxUnoStyleSheet
* getUnoStyleSheet( const css::uno::Reference
< css::style::XStyle
>& xStyle
);
352 static const css::uno::Sequence
< ::sal_Int8
>& getUnoTunnelId();
353 virtual ::sal_Int64 SAL_CALL
getSomething( const css::uno::Sequence
< ::sal_Int8
>& aIdentifier
) override
;
358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */