Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SVL_STYLE_HXX
21 : #define INCLUDED_SVL_STYLE_HXX
22 :
23 : #include <com/sun/star/style/XStyle.hpp>
24 : #include <com/sun/star/lang/XUnoTunnel.hpp>
25 :
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>
36 :
37 : #include <svl/style.hrc>
38 : #include <memory>
39 :
40 : class SfxItemSet;
41 : class SfxItemPool;
42 : class SfxStyleSheetBasePool;
43 : class SvStream;
44 :
45 : namespace svl { class IndexedStyleSheets; }
46 : /*
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:
51 :
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
56 :
57 : The following methods already broadcast themself
58 :
59 : SfxSimpleHint(SFX_HINT_DYING) from:
60 : SfxStyleSheetBasePool::~SfxStyleSheetBasePool()
61 :
62 : SfxStyleSheetHint( SfxStyleSheetHintId::CREATED, *p ) from:
63 : SfxStyleSheetBasePool::Make( const String& rName,
64 : SfxStyleFamily eFam, sal_uInt16 mask)
65 :
66 : SfxStyleSheetHint( SfxStyleSheetHintId::CHANGED, *pNew ) from:
67 : SfxStyleSheetBasePool::Add( SfxStyleSheetBase& rSheet )
68 :
69 : SfxStyleSheetHint( SfxStyleSheetHintId::ERASED, *p ) from:
70 : SfxStyleSheetBasePool::Erase( SfxStyleSheetBase* p )
71 : SfxStyleSheetBasePool::Clear()
72 : */
73 :
74 : class SVL_DLLPUBLIC SfxStyleSheetBase : public comphelper::OWeakTypeObject
75 : {
76 : private:
77 : friend class SfxStyleSheetBasePool;
78 : SVL_DLLPRIVATE static SfxStyleSheetBasePool& implGetStaticPool();
79 :
80 : protected:
81 : SfxStyleSheetBasePool* pPool; // related pool
82 : SfxStyleFamily nFamily;
83 :
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
89 :
90 : sal_uLong nHelpId; // help ID
91 :
92 : bool bMySet; // sal_True: delete Set in dtor
93 : bool bHidden;
94 :
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& );
100 :
101 : public:
102 : TYPEINFO();
103 :
104 : // returns the internal name of this style
105 : virtual const OUString& GetName() const;
106 :
107 : // sets the internal name of this style.
108 : //
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);
114 :
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;
118 :
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 );
131 :
132 244478 : SfxStyleSheetBasePool& GetPool() { return *pPool; }
133 610308 : SfxStyleFamily GetFamily() const { return nFamily; }
134 368281 : sal_uInt16 GetMask() const { return nMask; }
135 0 : void SetMask( sal_uInt16 mask) { nMask = mask; }
136 4517 : bool IsUserDefined() const
137 4517 : { return ( nMask & SFXSTYLEBIT_USERDEF) != 0; }
138 :
139 15771 : virtual bool IsHidden() const { return bHidden; }
140 : virtual void SetHidden( bool bValue );
141 :
142 : virtual sal_uLong GetHelpId( OUString& rFile );
143 : virtual void SetHelpId( const OUString& r, sal_uLong nId );
144 :
145 : virtual SfxItemSet& GetItemSet();
146 : };
147 :
148 : /* Class to iterate and search on a SfxStyleSheetBasePool */
149 : class SVL_DLLPUBLIC SfxStyleSheetIterator
150 : {
151 : public:
152 : /** Constructor.
153 : * The iterator will only iterate over style sheets which have the family \p eFam
154 : */
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();
165 :
166 338475 : bool SearchUsed() const { return bSearchUsed; }
167 :
168 : protected:
169 :
170 : SfxStyleSheetBasePool* pBasePool;
171 : SfxStyleFamily nSearchFamily;
172 : sal_uInt16 nMask;
173 :
174 :
175 : private:
176 : sal_uInt16 GetPos() { return nAktPosition; }
177 : SVL_DLLPRIVATE bool IsTrivialSearch();
178 :
179 : SfxStyleSheetBase* pAktStyle;
180 : sal_uInt16 nAktPosition;
181 : bool bSearchUsed;
182 :
183 : friend class SfxStyleSheetBasePool;
184 : };
185 :
186 : typedef std::shared_ptr< SfxStyleSheetIterator > SfxStyleSheetIteratorPtr;
187 :
188 :
189 : class SfxStyleSheetBasePool_Impl;
190 :
191 : class SVL_DLLPUBLIC SfxStyleSheetBasePool: public SfxBroadcaster, public comphelper::OWeakTypeObject
192 : {
193 : friend class SfxStyleSheetIterator;
194 : friend class SfxStyleSheetBase;
195 :
196 : SfxStyleSheetBasePool_Impl *pImp;
197 :
198 : protected:
199 : SfxStyleSheetIterator& GetIterator_Impl();
200 :
201 : OUString aAppName;
202 : SfxItemPool& rPool;
203 : SfxStyleFamily nSearchFamily;
204 : sal_uInt16 nMask;
205 :
206 : void ChangeParent( const OUString&, const OUString&, bool bVirtual = true );
207 : virtual SfxStyleSheetBase* Create( const OUString&, SfxStyleFamily, sal_uInt16 );
208 : virtual SfxStyleSheetBase* Create( const SfxStyleSheetBase& );
209 :
210 : virtual ~SfxStyleSheetBasePool();
211 :
212 : void StoreStyleSheet(rtl::Reference< SfxStyleSheetBase >);
213 :
214 : /** Obtain the indexed style sheets.
215 : */
216 : const svl::IndexedStyleSheets&
217 : GetIndexedStyleSheets() const;
218 : rtl::Reference<SfxStyleSheetBase>
219 : GetStyleSheetByPositionInIndex(unsigned pos);
220 :
221 : public:
222 : SfxStyleSheetBasePool( SfxItemPool& );
223 : SfxStyleSheetBasePool( const SfxStyleSheetBasePool& );
224 :
225 0 : const OUString& GetAppName() const { return aAppName; }
226 :
227 166479 : SfxItemPool& GetPool() { return rPool;}
228 : const SfxItemPool& GetPool() const { return rPool;}
229 :
230 : virtual SfxStyleSheetIteratorPtr CreateIterator(SfxStyleFamily, sal_uInt16 nMask);
231 : sal_uInt16 Count();
232 : SfxStyleSheetBase* operator[](sal_uInt16 nIdx);
233 :
234 : virtual SfxStyleSheetBase& Make(const OUString&,
235 : SfxStyleFamily eFam,
236 : sal_uInt16 nMask = SFXSTYLEBIT_ALL);
237 :
238 : virtual void Replace(
239 : SfxStyleSheetBase& rSource, SfxStyleSheetBase& rTarget );
240 :
241 : virtual void Remove( SfxStyleSheetBase* );
242 : void Insert( SfxStyleSheetBase* );
243 :
244 : void Clear();
245 :
246 : SfxStyleSheetBasePool& operator=( const SfxStyleSheetBasePool& );
247 : SfxStyleSheetBasePool& operator+=( const SfxStyleSheetBasePool& );
248 :
249 : unsigned GetNumberOfStyles();
250 :
251 : SfxStyleSheetBase* First();
252 : SfxStyleSheetBase* Next();
253 : virtual SfxStyleSheetBase* Find( const OUString&, SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
254 :
255 : virtual bool SetParent(SfxStyleFamily eFam,
256 : const OUString &rStyle,
257 : const OUString &rParent);
258 :
259 821654 : SfxStyleSheetBase* Find(const OUString& rStr)
260 821654 : { return Find(rStr, nSearchFamily, nMask); }
261 :
262 : void SetSearchMask(SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
263 397484 : sal_uInt16 GetSearchMask() const { return nMask;}
264 6453 : SfxStyleFamily GetSearchFamily() const { return nSearchFamily; }
265 :
266 : void Reindex();
267 : /** Add a style sheet.
268 : * Not an actual public function. Do not call it from non-subclasses.
269 : */
270 : SfxStyleSheetBase& Add( const SfxStyleSheetBase& );
271 : };
272 :
273 : class SVL_DLLPUBLIC SfxStyleSheet: public SfxStyleSheetBase,
274 : public SfxListener, public SfxBroadcaster, public svl::StyleSheetUser
275 : {
276 : public:
277 : TYPEINFO_OVERRIDE();
278 :
279 : SfxStyleSheet( const OUString&, const SfxStyleSheetBasePool&, SfxStyleFamily, sal_uInt16 );
280 : SfxStyleSheet( const SfxStyleSheet& );
281 :
282 : virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
283 :
284 : virtual bool isUsedByModel() const SAL_OVERRIDE;
285 :
286 : virtual bool SetParent( const OUString& ) SAL_OVERRIDE;
287 :
288 : protected:
289 : SfxStyleSheet() // do not use! needed by MSVC at compile time to satisfy ImplInheritanceHelper2
290 : : SfxStyleSheetBase(OUString("dummy"), NULL, SFX_STYLE_FAMILY_ALL, 0)
291 : {
292 : assert(false);
293 : }
294 : virtual ~SfxStyleSheet();
295 :
296 : };
297 :
298 1607 : class SVL_DLLPUBLIC SfxStyleSheetPool: public SfxStyleSheetBasePool
299 : {
300 : protected:
301 : using SfxStyleSheetBasePool::Create;
302 : virtual SfxStyleSheetBase* Create(const OUString&, SfxStyleFamily, sal_uInt16 mask) SAL_OVERRIDE;
303 :
304 : public:
305 : SfxStyleSheetPool( SfxItemPool const& );
306 : };
307 :
308 :
309 :
310 : enum SfxStyleSheetHintId
311 : {
312 : CREATED = 1, // new
313 : MODIFIED = 2, // changed
314 : CHANGED = 3, // erased and re-created (replaced)
315 : ERASED = 4, // erased
316 : INDESTRUCTION = 5, // in the process of being destructed
317 : };
318 :
319 314 : class SVL_DLLPUBLIC SfxStyleSheetPoolHint : public SfxHint
320 : {
321 : SfxStyleSheetHintId nHint;
322 :
323 : public:
324 314 : SfxStyleSheetPoolHint(SfxStyleSheetHintId nArgHint) : nHint(nArgHint){}
325 : SfxStyleSheetHintId GetHint() const
326 : { return nHint; }
327 : };
328 :
329 :
330 :
331 174400 : class SVL_DLLPUBLIC SfxStyleSheetHint: public SfxHint
332 : {
333 : SfxStyleSheetBase* pStyleSh;
334 : sal_uInt16 nHint;
335 :
336 : public:
337 : SfxStyleSheetHint( sal_uInt16, SfxStyleSheetBase& );
338 104832 : SfxStyleSheetBase* GetStyleSheet() const
339 104832 : { return pStyleSh; }
340 110905 : sal_uInt16 GetHint() const
341 110905 : { return nHint; }
342 : };
343 :
344 2069 : class SVL_DLLPUBLIC SfxStyleSheetHintExtended: public SfxStyleSheetHint
345 : {
346 : OUString aName;
347 :
348 : public:
349 : SfxStyleSheetHintExtended( sal_uInt16, const OUString& rOld,
350 : SfxStyleSheetBase& );
351 27186 : const OUString& GetOldName() const { return aName; }
352 : };
353 :
354 19657 : class SVL_DLLPUBLIC SfxUnoStyleSheet : public ::cppu::ImplInheritanceHelper2< SfxStyleSheet, ::com::sun::star::style::XStyle, ::com::sun::star::lang::XUnoTunnel >
355 : {
356 : public:
357 : SfxUnoStyleSheet( const OUString& _rName, const SfxStyleSheetBasePool& _rPool, SfxStyleFamily _eFamily, sal_uInt16 _nMaske );
358 :
359 : static SfxUnoStyleSheet* getUnoStyleSheet( const ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle >& xStyle );
360 :
361 : // XUnoTunnel
362 : 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;
363 :
364 : private:
365 : SfxUnoStyleSheet(); // not implemented
366 :
367 : static const ::com::sun::star::uno::Sequence< ::sal_Int8 >& getIdentifier();
368 : };
369 :
370 : #endif
371 :
372 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|