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 <vector>
28 : #include <comphelper/weak.hxx>
29 : #include <cppuhelper/implbase2.hxx>
30 : #include <svl/svldllapi.h>
31 : #include <rsc/rscsfx.hxx>
32 : #include <svl/hint.hxx>
33 : #include <svl/lstner.hxx>
34 : #include <svl/poolitem.hxx>
35 : #include <svl/SfxBroadcaster.hxx>
36 : #include <svl/stylesheetuser.hxx>
37 :
38 : #include <svl/style.hrc>
39 : #include <boost/shared_ptr.hpp>
40 :
41 : class SfxItemSet;
42 : class SfxItemPool;
43 : class SfxStyleSheetBasePool;
44 : class SvStream;
45 :
46 : namespace svl { class IndexedStyleSheets; }
47 : /*
48 : Everyone changing instances of SfxStyleSheetBasePool or SfxStyleSheetBase
49 : must broadcast this using <SfxStyleSheetBasePool::GetBroadcaster()> broadcasts.
50 : The class <SfxStyleSheetHint> is used for this, it contains an Action-Id and a
51 : pointer to the <SfxStyleSheetBase>. The actions are:
52 :
53 : #define SFX_STYLESHEET_CREATED // style is created
54 : #define SFX_STYLESHEET_MODIFIED // style is modified
55 : #define SFX_STYLESHEET_CHANGED // style is replaced
56 : #define SFX_STYLESHEET_ERASED // style is deleted
57 :
58 : The following methods already broadcast themself
59 :
60 : SfxSimpleHint(SFX_HINT_DYING) from:
61 : SfxStyleSheetBasePool::~SfxStyleSheetBasePool()
62 :
63 : SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *p ) from:
64 : SfxStyleSheetBasePool::Make( const String& rName,
65 : SfxStyleFamily eFam, sal_uInt16 mask)
66 :
67 : SfxStyleSheetHint( SFX_STYLESHEET_CHANGED, *pNew ) from:
68 : SfxStyleSheetBasePool::Add( SfxStyleSheetBase& rSheet )
69 :
70 : SfxStyleSheetHint( SFX_STYLESHEET_ERASED, *p ) from:
71 : SfxStyleSheetBasePool::Erase( SfxStyleSheetBase* p )
72 : SfxStyleSheetBasePool::Clear()
73 : */
74 :
75 : class SVL_DLLPUBLIC SfxStyleSheetBase : public comphelper::OWeakTypeObject
76 : {
77 : private:
78 : friend class SfxStyleSheetBasePool;
79 : SVL_DLLPRIVATE static SfxStyleSheetBasePool& implGetStaticPool();
80 :
81 : protected:
82 : SfxStyleSheetBasePool* pPool; // zugehoeriger Pool
83 : SfxStyleFamily nFamily; // Familie
84 :
85 : OUString aName, aParent, aFollow;
86 : OUString maDisplayName;
87 : OUString aHelpFile; // Name der Hilfedatei
88 : SfxItemSet* pSet; // ItemSet
89 : sal_uInt16 nMask; // Flags
90 :
91 : sal_uLong nHelpId; // Hilfe-ID
92 :
93 : bool bMySet; // sal_True: Set loeschen im dtor
94 : bool bHidden;
95 :
96 : SfxStyleSheetBase( const OUString&, SfxStyleSheetBasePool*, SfxStyleFamily eFam, sal_uInt16 mask );
97 : SfxStyleSheetBase( const SfxStyleSheetBase& );
98 : virtual ~SfxStyleSheetBase();
99 : virtual void Load( SvStream&, sal_uInt16 );
100 : virtual void Store( SvStream& );
101 :
102 : public:
103 : TYPEINFO();
104 :
105 : // returns the internal name of this style
106 : virtual const OUString& GetName() const;
107 :
108 : // sets the internal name of this style.
109 : //
110 : // If the name of a style is changed, then the styles container needs to be
111 : // reindexed (see IndexedStyleSheets). If you set bReindexNow to false to
112 : // defer that indexing, then you must call the Reindex manually on the
113 : // SfxStyleSheetBasePool parent.
114 : virtual bool SetName(const OUString& rNewName, bool bReindexNow = true);
115 :
116 : /** returns the display name of this style, it is used at the user interface.
117 : If the display name is empty, this method returns the internal name. */
118 : virtual OUString GetDisplayName() const;
119 :
120 : // sets the display name of this style
121 : virtual void SetDisplayName( const OUString& );
122 :
123 : virtual const OUString& GetParent() const;
124 : virtual bool SetParent( const OUString& );
125 : virtual const OUString& GetFollow() const;
126 : virtual bool SetFollow( const OUString& );
127 : virtual bool HasFollowSupport() const; // Default true
128 : virtual bool HasParentSupport() const; // Default true
129 : virtual bool HasClearParentSupport() const; // Default false
130 : virtual bool IsUsed() const; // Default true
131 : // Default aus dem Itemset; entweder dem uebergebenen
132 : // oder aus dem per GetItemSet() zurueckgelieferten Set
133 : virtual OUString GetDescription();
134 : virtual OUString GetDescription( SfxMapUnit eMetric );
135 :
136 300403 : SfxStyleSheetBasePool& GetPool() { return *pPool; }
137 747480 : SfxStyleFamily GetFamily() const { return nFamily; }
138 543198 : sal_uInt16 GetMask() const { return nMask; }
139 0 : void SetMask( sal_uInt16 mask) { nMask = mask; }
140 4740 : bool IsUserDefined() const
141 4740 : { return ( nMask & SFXSTYLEBIT_USERDEF) != 0; }
142 :
143 20924 : virtual bool IsHidden() const { return bHidden; }
144 : virtual void SetHidden( bool bValue );
145 :
146 : virtual sal_uLong GetHelpId( OUString& rFile );
147 : virtual void SetHelpId( const OUString& r, sal_uLong nId );
148 :
149 : virtual SfxItemSet& GetItemSet();
150 : virtual sal_uInt16 GetVersion() const;
151 : };
152 :
153 : /* Class to iterate and search on a SfxStyleSheetBasePool */
154 : class SVL_DLLPUBLIC SfxStyleSheetIterator
155 : {
156 : public:
157 : /** Constructor.
158 : * The iterator will only iterate over style sheets which have the family \p eFam
159 : */
160 : SfxStyleSheetIterator(SfxStyleSheetBasePool *pBase,
161 : SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
162 : virtual sal_uInt16 GetSearchMask() const;
163 : virtual 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();
170 :
171 423688 : bool SearchUsed() const { return bSearchUsed; }
172 :
173 : protected:
174 :
175 : SfxStyleSheetBasePool* pBasePool;
176 : SfxStyleFamily nSearchFamily;
177 : sal_uInt16 nMask;
178 :
179 :
180 : private:
181 : sal_uInt16 GetPos() { return nAktPosition; }
182 : SVL_DLLPRIVATE bool IsTrivialSearch();
183 :
184 : SfxStyleSheetBase* pAktStyle;
185 : sal_uInt16 nAktPosition;
186 : bool bSearchUsed;
187 :
188 : friend class SfxStyleSheetBasePool;
189 : };
190 :
191 : typedef ::boost::shared_ptr< SfxStyleSheetIterator > SfxStyleSheetIteratorPtr;
192 :
193 :
194 : class SfxStyleSheetBasePool_Impl;
195 :
196 : class SVL_DLLPUBLIC SfxStyleSheetBasePool: public SfxBroadcaster, public comphelper::OWeakTypeObject
197 : {
198 : friend class SfxStyleSheetIterator;
199 : friend class SfxStyleSheetBase;
200 :
201 : SfxStyleSheetBasePool_Impl *pImp;
202 :
203 : protected:
204 : SfxStyleSheetIterator& GetIterator_Impl();
205 :
206 : OUString aAppName;
207 : SfxItemPool& rPool;
208 : SfxStyleFamily nSearchFamily;
209 : sal_uInt16 nMask;
210 :
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& );
214 :
215 : virtual ~SfxStyleSheetBasePool();
216 :
217 : void StoreStyleSheet(rtl::Reference< SfxStyleSheetBase >);
218 :
219 : /** Obtain the indexed style sheets.
220 : */
221 : const svl::IndexedStyleSheets&
222 : GetIndexedStyleSheets() const;
223 : rtl::Reference<SfxStyleSheetBase>
224 : GetStyleSheetByPositionInIndex(unsigned pos);
225 :
226 : public:
227 : SfxStyleSheetBasePool( SfxItemPool& );
228 : SfxStyleSheetBasePool( const SfxStyleSheetBasePool& );
229 :
230 0 : const OUString& GetAppName() const { return aAppName; }
231 :
232 187824 : SfxItemPool& GetPool() { return rPool;}
233 : const SfxItemPool& GetPool() const { return rPool;}
234 :
235 : virtual SfxStyleSheetIteratorPtr CreateIterator(SfxStyleFamily, sal_uInt16 nMask);
236 : virtual sal_uInt16 Count();
237 : virtual SfxStyleSheetBase* operator[](sal_uInt16 nIdx);
238 :
239 : virtual SfxStyleSheetBase& Make(const OUString&,
240 : SfxStyleFamily eFam,
241 : sal_uInt16 nMask = SFXSTYLEBIT_ALL);
242 :
243 : virtual void Replace(
244 : SfxStyleSheetBase& rSource, SfxStyleSheetBase& rTarget );
245 :
246 : virtual void Remove( SfxStyleSheetBase* );
247 : virtual void Insert( SfxStyleSheetBase* );
248 :
249 : virtual void Clear();
250 :
251 : SfxStyleSheetBasePool& operator=( const SfxStyleSheetBasePool& );
252 : SfxStyleSheetBasePool& operator+=( const SfxStyleSheetBasePool& );
253 :
254 : unsigned GetNumberOfStyles();
255 :
256 : virtual SfxStyleSheetBase* First();
257 : virtual SfxStyleSheetBase* Next();
258 : virtual SfxStyleSheetBase* Find( const OUString&, SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
259 :
260 : virtual bool SetParent(SfxStyleFamily eFam,
261 : const OUString &rStyle,
262 : const OUString &rParent);
263 :
264 1373448 : SfxStyleSheetBase* Find(const OUString& rStr)
265 1373448 : { return Find(rStr, nSearchFamily, nMask); }
266 :
267 : void SetSearchMask(SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
268 698016 : sal_uInt16 GetSearchMask() const { return nMask;}
269 5426 : SfxStyleFamily GetSearchFamily() const { return nSearchFamily; }
270 :
271 : void Reindex();
272 : /** Add a style sheet.
273 : * Not an actual public function. Do not call it from non-subclasses.
274 : */
275 : SfxStyleSheetBase& Add( const SfxStyleSheetBase& );
276 :
277 : private:
278 : /** This member holds the indexed style sheets.
279 : *
280 : * @internal
281 : * This member is private and not protected in order to have more control which style sheets are added
282 : * where. Ideally, all calls which add/remove/change style sheets are done in the base class.
283 : */
284 : boost::shared_ptr<svl::IndexedStyleSheets> mIndexedStyleSheets;
285 : };
286 :
287 :
288 :
289 : class SVL_DLLPUBLIC SfxStyleSheet: public SfxStyleSheetBase,
290 : public SfxListener, public SfxBroadcaster, public svl::StyleSheetUser
291 : {
292 : public:
293 : TYPEINFO_OVERRIDE();
294 :
295 : SfxStyleSheet( const OUString&, const SfxStyleSheetBasePool&, SfxStyleFamily, sal_uInt16 );
296 : SfxStyleSheet( const SfxStyleSheet& );
297 :
298 : virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
299 :
300 : virtual bool isUsedByModel() const SAL_OVERRIDE;
301 :
302 : virtual bool SetParent( const OUString& ) SAL_OVERRIDE;
303 :
304 : protected:
305 : SfxStyleSheet() // do not use! needed by MSVC at compile time to satisfy ImplInheritanceHelper2
306 : : SfxStyleSheetBase(OUString("dummy"), NULL, SFX_STYLE_FAMILY_ALL, 0)
307 : {
308 : assert(false);
309 : }
310 : virtual ~SfxStyleSheet();
311 : };
312 :
313 :
314 :
315 2650 : class SVL_DLLPUBLIC SfxStyleSheetPool: public SfxStyleSheetBasePool
316 : {
317 : protected:
318 : using SfxStyleSheetBasePool::Create;
319 : virtual SfxStyleSheetBase* Create(const OUString&, SfxStyleFamily, sal_uInt16 mask) SAL_OVERRIDE;
320 : virtual SfxStyleSheetBase* Create(const SfxStyleSheet &);
321 :
322 : public:
323 : SfxStyleSheetPool( SfxItemPool const& );
324 : };
325 :
326 :
327 :
328 : #define SFX_STYLESHEET_CREATED 1 // new
329 : #define SFX_STYLESHEET_MODIFIED 2 // changed
330 : #define SFX_STYLESHEET_CHANGED 3 // erased and re-created (replaced)
331 : #define SFX_STYLESHEET_ERASED 4 // erased
332 : #define SFX_STYLESHEET_INDESTRUCTION 5 // in the process of being destructed
333 :
334 : #define SFX_STYLESHEETPOOL_CHANGES 1 // Changes which change the state of the pool, but should not be
335 : // broadcasted by STYLESHEET hits.
336 :
337 :
338 :
339 558 : class SVL_DLLPUBLIC SfxStyleSheetPoolHint : public SfxHint
340 : {
341 : sal_uInt16 nHint;
342 :
343 : public:
344 558 : SfxStyleSheetPoolHint(sal_uInt16 nArgHint) : nHint(nArgHint){}
345 : sal_uInt16 GetHint() const
346 : { return nHint; }
347 : };
348 :
349 :
350 :
351 278158 : class SVL_DLLPUBLIC SfxStyleSheetHint: public SfxHint
352 : {
353 : SfxStyleSheetBase* pStyleSh;
354 : sal_uInt16 nHint;
355 :
356 : public:
357 : SfxStyleSheetHint( sal_uInt16, SfxStyleSheetBase& );
358 126252 : SfxStyleSheetBase* GetStyleSheet() const
359 126252 : { return pStyleSh; }
360 177570 : sal_uInt16 GetHint() const
361 177570 : { return nHint; }
362 : };
363 :
364 1674 : class SVL_DLLPUBLIC SfxStyleSheetHintExtended: public SfxStyleSheetHint
365 : {
366 : OUString aName;
367 :
368 : public:
369 : SfxStyleSheetHintExtended( sal_uInt16, const OUString& rOld,
370 : SfxStyleSheetBase& );
371 29984 : const OUString& GetOldName() const { return aName; }
372 : };
373 :
374 28762 : class SVL_DLLPUBLIC SfxUnoStyleSheet : public ::cppu::ImplInheritanceHelper2< SfxStyleSheet, ::com::sun::star::style::XStyle, ::com::sun::star::lang::XUnoTunnel >
375 : {
376 : public:
377 : SfxUnoStyleSheet( const OUString& _rName, const SfxStyleSheetBasePool& _rPool, SfxStyleFamily _eFamily, sal_uInt16 _nMaske );
378 :
379 : static SfxUnoStyleSheet* getUnoStyleSheet( const ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle >& xStyle );
380 :
381 : // XUnoTunnel
382 : 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;
383 :
384 : private:
385 : SfxUnoStyleSheet(); // not implemented
386 :
387 : static const ::com::sun::star::uno::Sequence< ::sal_Int8 >& getIdentifier();
388 : };
389 :
390 : #endif
391 :
392 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|