Branch data 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 _SFXSTYLE_HXX
21 : : #define _SFXSTYLE_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 <tools/string.hxx>
33 : : #include <svl/hint.hxx>
34 : : #include <svl/lstner.hxx>
35 : : #include <svl/brdcst.hxx>
36 : : #include <svl/poolitem.hxx>
37 : :
38 : : #include <svl/style.hrc>
39 : :
40 : : class SfxItemSet;
41 : : class SfxItemPool;
42 : :
43 : : class SfxStyleSheetBasePool;
44 : : class SvStream;
45 : :
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 SFX_STYLESHEET_CREATED // style is created
53 : : #define SFX_STYLESHEET_MODIFIED // style is modified
54 : : #define SFX_STYLESHEET_CHANGED // style is replaced
55 : : #define SFX_STYLESHEET_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( SFX_STYLESHEET_CREATED, *p ) from:
63 : : SfxStyleSheetBasePool::Make( const String& rName,
64 : : SfxStyleFamily eFam, sal_uInt16 mask, sal_uInt16 nPos)
65 : :
66 : : SfxStyleSheetHint( SFX_STYLESHEET_CHANGED, *pNew ) from:
67 : : SfxStyleSheetBasePool::Add( SfxStyleSheetBase& rSheet )
68 : :
69 : : SfxStyleSheetHint( SFX_STYLESHEET_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; // zugehoeriger Pool
82 : : SfxStyleFamily nFamily; // Familie
83 : :
84 : : UniString aName, aParent, aFollow;
85 : : rtl::OUString maDisplayName;
86 : : String aHelpFile; // Name der Hilfedatei
87 : : SfxItemSet* pSet; // ItemSet
88 : : sal_uInt16 nMask; // Flags
89 : :
90 : : sal_uLong nHelpId; // Hilfe-ID
91 : :
92 : : sal_Bool bMySet; // sal_True: Set loeschen im dtor
93 : :
94 : : SfxStyleSheetBase( const UniString&, 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& );
99 : :
100 : : public:
101 : : TYPEINFO();
102 : :
103 : : // returns the internal name of this style
104 : : virtual const UniString& GetName() const;
105 : :
106 : : // sets the internal name of this style
107 : : virtual sal_Bool SetName( const UniString& );
108 : :
109 : : /** returns the display name of this style, it is used at the user interface.
110 : : If the display name is empty, this method returns the internal name. */
111 : : virtual rtl::OUString GetDisplayName() const;
112 : :
113 : : // sets the display name of this style
114 : : virtual void SetDisplayName( const rtl::OUString& );
115 : :
116 : : virtual const UniString& GetParent() const;
117 : : virtual sal_Bool SetParent( const UniString& );
118 : : virtual const UniString& GetFollow() const;
119 : : virtual sal_Bool SetFollow( const UniString& );
120 : : virtual sal_Bool HasFollowSupport() const; // Default sal_True
121 : : virtual sal_Bool HasParentSupport() const; // Default sal_True
122 : : virtual sal_Bool HasClearParentSupport() const; // Default sal_False
123 : : virtual sal_Bool IsUsed() const; // Default sal_True
124 : : // Default aus dem Itemset; entweder dem uebergebenen
125 : : // oder aus dem per GetItemSet() zurueckgelieferten Set
126 : : virtual UniString GetDescription();
127 : : virtual UniString GetDescription( SfxMapUnit eMetric );
128 : :
129 : 48605 : SfxStyleSheetBasePool& GetPool() { return *pPool; }
130 : 252590 : SfxStyleFamily GetFamily() const { return nFamily; }
131 : 128750 : sal_uInt16 GetMask() const { return nMask; }
132 : 0 : void SetMask( sal_uInt16 mask) { nMask = mask; }
133 : 2001 : sal_Bool IsUserDefined() const
134 : 2001 : { return sal_Bool( ( nMask & SFXSTYLEBIT_USERDEF) != 0 ); }
135 : :
136 : : virtual sal_uLong GetHelpId( String& rFile );
137 : : virtual void SetHelpId( const String& r, sal_uLong nId );
138 : :
139 : : virtual SfxItemSet& GetItemSet();
140 : : virtual sal_uInt16 GetVersion() const;
141 : : };
142 : :
143 : : //=========================================================================
144 : :
145 : : typedef std::vector< rtl::Reference< SfxStyleSheetBase > > SfxStyles;
146 : :
147 : : //=========================================================================
148 : :
149 : : class SVL_DLLPUBLIC SfxStyleSheetIterator
150 : :
151 : : /* [Beschreibung]
152 : :
153 : : Klasse zum Iterieren und Suchen auf einem SfxStyleSheetBasePool.
154 : :
155 : : */
156 : :
157 : : {
158 : : public:
159 : : SfxStyleSheetIterator(SfxStyleSheetBasePool *pBase,
160 : : SfxStyleFamily eFam, sal_uInt16 n=0xFFFF );
161 : : virtual sal_uInt16 GetSearchMask() const;
162 : : virtual SfxStyleFamily GetSearchFamily() const;
163 : : virtual sal_uInt16 Count();
164 : : virtual SfxStyleSheetBase *operator[](sal_uInt16 nIdx);
165 : : virtual SfxStyleSheetBase* First();
166 : : virtual SfxStyleSheetBase* Next();
167 : : virtual SfxStyleSheetBase* Find(const rtl::OUString& rStr);
168 : : virtual ~SfxStyleSheetIterator();
169 : :
170 : : protected:
171 : :
172 : : SfxStyleSheetBasePool* pBasePool;
173 : : SfxStyleFamily nSearchFamily;
174 : : sal_uInt16 nMask;
175 : 21526 : sal_Bool SearchUsed() const { return bSearchUsed; }
176 : :
177 : : private:
178 : 0 : sal_uInt16 GetPos(){return nAktPosition;}
179 : : SVL_DLLPRIVATE sal_Bool IsTrivialSearch();
180 : : SVL_DLLPRIVATE sal_Bool DoesStyleMatch(SfxStyleSheetBase *pStyle);
181 : :
182 : : SfxStyleSheetBase* pAktStyle;
183 : : sal_uInt16 nAktPosition;
184 : : sal_Bool bSearchUsed;
185 : :
186 : : friend class SfxStyleSheetBasePool;
187 : : };
188 : :
189 : : //=========================================================================
190 : :
191 : : class SfxStyleSheetBasePool_Impl;
192 : :
193 : : class SVL_DLLPUBLIC SfxStyleSheetBasePool: public SfxBroadcaster, public comphelper::OWeakTypeObject
194 : : {
195 : : friend class SfxStyleSheetIterator;
196 : : friend class SfxStyleSheetBase;
197 : :
198 : : SfxStyleSheetBasePool_Impl *pImp;
199 : :
200 : : private:
201 : : SVL_DLLPRIVATE SfxStyleSheetIterator& GetIterator_Impl();
202 : : protected:
203 : : String aAppName;
204 : : SfxItemPool& rPool;
205 : : SfxStyles aStyles;
206 : : SfxStyleFamily nSearchFamily;
207 : : sal_uInt16 nMask;
208 : :
209 : : SfxStyleSheetBase& Add( SfxStyleSheetBase& );
210 : : void ChangeParent( const UniString&, const UniString&, sal_Bool bVirtual = sal_True );
211 : : virtual SfxStyleSheetBase* Create( const UniString&, SfxStyleFamily, sal_uInt16 );
212 : : virtual SfxStyleSheetBase* Create( const SfxStyleSheetBase& );
213 : :
214 : : virtual ~SfxStyleSheetBasePool();
215 : :
216 : : public:
217 : : SfxStyleSheetBasePool( SfxItemPool& );
218 : : SfxStyleSheetBasePool( const SfxStyleSheetBasePool& );
219 : :
220 : 0 : const String& GetAppName() const { return aAppName; }
221 : :
222 : : SfxItemPool& GetPool();
223 : : const SfxItemPool& GetPool() const;
224 : :
225 : : virtual SfxStyleSheetIterator* CreateIterator(SfxStyleFamily, sal_uInt16 nMask);
226 : : virtual sal_uInt16 Count();
227 : : virtual SfxStyleSheetBase* operator[](sal_uInt16 nIdx);
228 : :
229 : : virtual SfxStyleSheetBase& Make(const UniString&,
230 : : SfxStyleFamily eFam,
231 : : sal_uInt16 nMask = 0xffff ,
232 : : sal_uInt16 nPos = 0xffff);
233 : :
234 : : virtual void Replace(
235 : : SfxStyleSheetBase& rSource, SfxStyleSheetBase& rTarget );
236 : :
237 : : virtual void Remove( SfxStyleSheetBase* );
238 : : virtual void Insert( SfxStyleSheetBase* );
239 : :
240 : : virtual void Clear();
241 : :
242 : : SfxStyleSheetBasePool& operator=( const SfxStyleSheetBasePool& );
243 : : SfxStyleSheetBasePool& operator+=( const SfxStyleSheetBasePool& );
244 : :
245 : : const SfxStyles& GetStyles();
246 : : virtual SfxStyleSheetBase* First();
247 : : virtual SfxStyleSheetBase* Next();
248 : : virtual SfxStyleSheetBase* Find( const UniString&, SfxStyleFamily eFam, sal_uInt16 n=0xFFFF );
249 : :
250 : : virtual sal_Bool SetParent(SfxStyleFamily eFam,
251 : : const UniString &rStyle,
252 : : const UniString &rParent);
253 : :
254 : 56900 : SfxStyleSheetBase* Find(const UniString& rStr)
255 : 56900 : { return Find(rStr, nSearchFamily, nMask); }
256 : :
257 : : void SetSearchMask(SfxStyleFamily eFam, sal_uInt16 n=0xFFFF );
258 : : sal_uInt16 GetSearchMask() const;
259 : 1067 : SfxStyleFamily GetSearchFamily() const { return nSearchFamily; }
260 : : };
261 : :
262 : : //=========================================================================
263 : :
264 : : class SVL_DLLPUBLIC SfxStyleSheet: public SfxStyleSheetBase,
265 : : public SfxListener, public SfxBroadcaster
266 : : {
267 : : public:
268 : : TYPEINFO();
269 : :
270 : : SfxStyleSheet( const UniString&, const SfxStyleSheetBasePool&, SfxStyleFamily, sal_uInt16 );
271 : : SfxStyleSheet( const SfxStyleSheet& );
272 : :
273 : : virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
274 : : virtual sal_Bool SetParent( const UniString& );
275 : :
276 : : protected:
277 : : SfxStyleSheet() // do not use! needed by MSVC at compile time to satisfy ImplInheritanceHelper2
278 : : : SfxStyleSheetBase(rtl::OUString("dummy"),
279 : : NULL, SFX_STYLE_FAMILY_ALL, 0)
280 : : {
281 : : assert(false);
282 : : }
283 : : virtual ~SfxStyleSheet();
284 : : };
285 : :
286 : : //=========================================================================
287 : :
288 [ - + ]: 870 : class SVL_DLLPUBLIC SfxStyleSheetPool: public SfxStyleSheetBasePool
289 : : {
290 : : protected:
291 : : using SfxStyleSheetBasePool::Create;
292 : : virtual SfxStyleSheetBase* Create(const UniString&, SfxStyleFamily, sal_uInt16 mask);
293 : : virtual SfxStyleSheetBase* Create(const SfxStyleSheet &);
294 : :
295 : : public:
296 : : SfxStyleSheetPool( SfxItemPool const& );
297 : :
298 : : // virtual sal_Bool CopyTo(SfxStyleSheetPool &rDest, const String &rSourceName);
299 : : };
300 : :
301 : : //=========================================================================
302 : :
303 : : #define SFX_STYLESHEET_CREATED 1 // neu
304 : : #define SFX_STYLESHEET_MODIFIED 2 // ver"andert
305 : : #define SFX_STYLESHEET_CHANGED 3 // gel"oscht und neu (ausgetauscht)
306 : : #define SFX_STYLESHEET_ERASED 4 // gel"oscht
307 : : #define SFX_STYLESHEET_INDESTRUCTION 5 // wird gerade entfernt
308 : :
309 : : #define SFX_STYLESHEETPOOL_CHANGES 1 // Aenderungen, die den Zustand
310 : : // des Pools anedern, aber nicht
311 : : // ueber die STYLESHEET Hints
312 : : // verschickt werden sollen.
313 : :
314 : : //========================================================================
315 : :
316 [ - + ]: 496 : class SVL_DLLPUBLIC SfxStyleSheetPoolHint : public SfxHint
317 : : {
318 : : sal_uInt16 nHint;
319 : :
320 : : public:
321 : : TYPEINFO();
322 : :
323 : 496 : SfxStyleSheetPoolHint(sal_uInt16 nArgHint) : nHint(nArgHint){}
324 : : sal_uInt16 GetHint() const
325 : : { return nHint; }
326 : : };
327 : :
328 : : //=========================================================================
329 : :
330 [ - + ]: 61499 : class SVL_DLLPUBLIC SfxStyleSheetHint: public SfxHint
331 : : {
332 : : SfxStyleSheetBase* pStyleSh;
333 : : sal_uInt16 nHint;
334 : :
335 : : public:
336 : : TYPEINFO();
337 : :
338 : : SfxStyleSheetHint( sal_uInt16, SfxStyleSheetBase& );
339 : 15932 : SfxStyleSheetBase* GetStyleSheet() const
340 : 15932 : { return pStyleSh; }
341 : 8945 : sal_uInt16 GetHint() const
342 : 8945 : { return nHint; }
343 : : };
344 : :
345 [ + - ][ - + ]: 198 : class SVL_DLLPUBLIC SfxStyleSheetHintExtended: public SfxStyleSheetHint
346 : : {
347 : : String aName;
348 : :
349 : : public:
350 : : TYPEINFO();
351 : :
352 : : SfxStyleSheetHintExtended(
353 : : sal_uInt16, const String& rOld,
354 : : SfxStyleSheetBase& );
355 : 1694 : const String& GetOldName() { return aName; }
356 : : };
357 : :
358 [ # # ][ - + ]: 11970 : class SVL_DLLPUBLIC SfxUnoStyleSheet : public ::cppu::ImplInheritanceHelper2< SfxStyleSheet, ::com::sun::star::style::XStyle, ::com::sun::star::lang::XUnoTunnel >
359 : : {
360 : : public:
361 : : SfxUnoStyleSheet( const UniString& _rName, const SfxStyleSheetBasePool& _rPool, SfxStyleFamily _eFamily, sal_uInt16 _nMaske );
362 : :
363 : : static SfxUnoStyleSheet* getUnoStyleSheet( const ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle >& xStyle );
364 : :
365 : : // XUnoTunnel
366 : : virtual ::sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aIdentifier ) throw (::com::sun::star::uno::RuntimeException);
367 : :
368 : : private:
369 : : SfxUnoStyleSheet(); // not implemented
370 : :
371 : : static const ::com::sun::star::uno::Sequence< ::sal_Int8 >& getIdentifier();
372 : : };
373 : :
374 : : #endif
375 : :
376 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|