bump product version to 4.1.6.2
[LibreOffice.git] / include / svl / style.hxx
blob97082312b095030639116d109a016f1f9a4b5bea
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 _SFXSTYLE_HXX
21 #define _SFXSTYLE_HXX
23 #include <com/sun/star/style/XStyle.hpp>
24 #include <com/sun/star/lang/XUnoTunnel.hpp>
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 #include <svl/stylesheetuser.hxx>
39 #include <svl/style.hrc>
40 #include <boost/shared_ptr.hpp>
42 class SfxItemSet;
43 class SfxItemPool;
44 class SfxStyleSheetBasePool;
45 class SvStream;
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:
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
58 The following methods already broadcast themself
60 SfxSimpleHint(SFX_HINT_DYING) from:
61 SfxStyleSheetBasePool::~SfxStyleSheetBasePool()
63 SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *p ) from:
64 SfxStyleSheetBasePool::Make( const String& rName,
65 SfxStyleFamily eFam, sal_uInt16 mask, sal_uInt16 nPos)
67 SfxStyleSheetHint( SFX_STYLESHEET_CHANGED, *pNew ) from:
68 SfxStyleSheetBasePool::Add( SfxStyleSheetBase& rSheet )
70 SfxStyleSheetHint( SFX_STYLESHEET_ERASED, *p ) from:
71 SfxStyleSheetBasePool::Erase( SfxStyleSheetBase* p )
72 SfxStyleSheetBasePool::Clear()
75 class SVL_DLLPUBLIC SfxStyleSheetBase : public comphelper::OWeakTypeObject
77 private:
78 friend class SfxStyleSheetBasePool;
79 SVL_DLLPRIVATE static SfxStyleSheetBasePool& implGetStaticPool();
81 protected:
82 SfxStyleSheetBasePool* pPool; // zugehoeriger Pool
83 SfxStyleFamily nFamily; // Familie
85 UniString aName, aParent, aFollow;
86 OUString maDisplayName;
87 OUString aHelpFile; // Name der Hilfedatei
88 SfxItemSet* pSet; // ItemSet
89 sal_uInt16 nMask; // Flags
91 sal_uLong nHelpId; // Hilfe-ID
93 bool bMySet; // sal_True: Set loeschen im dtor
94 bool bHidden;
96 SfxStyleSheetBase( const UniString&, 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& );
102 public:
103 TYPEINFO();
105 // returns the internal name of this style
106 virtual const UniString& GetName() const;
108 // sets the internal name of this style
109 virtual bool SetName( const UniString& );
111 /** returns the display name of this style, it is used at the user interface.
112 If the display name is empty, this method returns the internal name. */
113 virtual OUString GetDisplayName() const;
115 // sets the display name of this style
116 virtual void SetDisplayName( const OUString& );
118 virtual const UniString& GetParent() const;
119 virtual bool SetParent( const UniString& );
120 virtual const UniString& GetFollow() const;
121 virtual bool SetFollow( const UniString& );
122 virtual bool HasFollowSupport() const; // Default true
123 virtual bool HasParentSupport() const; // Default true
124 virtual bool HasClearParentSupport() const; // Default false
125 virtual bool IsUsed() const; // Default true
126 // Default aus dem Itemset; entweder dem uebergebenen
127 // oder aus dem per GetItemSet() zurueckgelieferten Set
128 virtual UniString GetDescription();
129 virtual UniString GetDescription( SfxMapUnit eMetric );
131 SfxStyleSheetBasePool& GetPool() { return *pPool; }
132 SfxStyleFamily GetFamily() const { return nFamily; }
133 sal_uInt16 GetMask() const { return nMask; }
134 void SetMask( sal_uInt16 mask) { nMask = mask; }
135 bool IsUserDefined() const
136 { return ( nMask & SFXSTYLEBIT_USERDEF) != 0; }
138 virtual sal_Bool IsHidden() const { return bHidden; }
139 virtual void SetHidden( sal_Bool bValue );
141 virtual sal_uLong GetHelpId( OUString& rFile );
142 virtual void SetHelpId( const OUString& r, sal_uLong nId );
144 virtual SfxItemSet& GetItemSet();
145 virtual sal_uInt16 GetVersion() const;
148 //=========================================================================
150 typedef std::vector< rtl::Reference< SfxStyleSheetBase > > SfxStyles;
152 //=========================================================================
154 class SVL_DLLPUBLIC SfxStyleSheetIterator
156 /* [Beschreibung]
158 Klasse zum Iterieren und Suchen auf einem SfxStyleSheetBasePool.
163 public:
164 SfxStyleSheetIterator(SfxStyleSheetBasePool *pBase,
165 SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
166 virtual sal_uInt16 GetSearchMask() const;
167 virtual SfxStyleFamily GetSearchFamily() const;
168 virtual sal_uInt16 Count();
169 virtual SfxStyleSheetBase *operator[](sal_uInt16 nIdx);
170 virtual SfxStyleSheetBase* First();
171 virtual SfxStyleSheetBase* Next();
172 virtual SfxStyleSheetBase* Find(const OUString& rStr);
173 virtual ~SfxStyleSheetIterator();
175 protected:
177 SfxStyleSheetBasePool* pBasePool;
178 SfxStyleFamily nSearchFamily;
179 sal_uInt16 nMask;
181 bool SearchUsed() const { return bSearchUsed; }
183 private:
184 sal_uInt16 GetPos() { return nAktPosition; }
185 SVL_DLLPRIVATE bool IsTrivialSearch();
186 SVL_DLLPRIVATE bool DoesStyleMatch(SfxStyleSheetBase *pStyle);
188 SfxStyleSheetBase* pAktStyle;
189 sal_uInt16 nAktPosition;
190 bool bSearchUsed;
192 friend class SfxStyleSheetBasePool;
195 typedef ::boost::shared_ptr< SfxStyleSheetIterator > SfxStyleSheetIteratorPtr;
196 //=========================================================================
198 class SfxStyleSheetBasePool_Impl;
200 class SVL_DLLPUBLIC SfxStyleSheetBasePool: public SfxBroadcaster, public comphelper::OWeakTypeObject
202 friend class SfxStyleSheetIterator;
203 friend class SfxStyleSheetBase;
205 SfxStyleSheetBasePool_Impl *pImp;
207 protected:
208 SfxStyleSheetIterator& GetIterator_Impl();
210 String aAppName;
211 SfxItemPool& rPool;
212 SfxStyles aStyles;
213 SfxStyleFamily nSearchFamily;
214 sal_uInt16 nMask;
216 SfxStyleSheetBase& Add( SfxStyleSheetBase& );
217 void ChangeParent( const UniString&, const UniString&, bool bVirtual = true );
218 virtual SfxStyleSheetBase* Create( const UniString&, SfxStyleFamily, sal_uInt16 );
219 virtual SfxStyleSheetBase* Create( const SfxStyleSheetBase& );
221 virtual ~SfxStyleSheetBasePool();
223 public:
224 SfxStyleSheetBasePool( SfxItemPool& );
225 SfxStyleSheetBasePool( const SfxStyleSheetBasePool& );
227 const String& GetAppName() const { return aAppName; }
229 SfxItemPool& GetPool();
230 const SfxItemPool& GetPool() const;
232 virtual SfxStyleSheetIteratorPtr CreateIterator(SfxStyleFamily, sal_uInt16 nMask);
233 virtual sal_uInt16 Count();
234 virtual SfxStyleSheetBase* operator[](sal_uInt16 nIdx);
236 virtual SfxStyleSheetBase& Make(const UniString&,
237 SfxStyleFamily eFam,
238 sal_uInt16 nMask = SFXSTYLEBIT_ALL ,
239 sal_uInt16 nPos = 0xffff);
241 virtual void Replace(
242 SfxStyleSheetBase& rSource, SfxStyleSheetBase& rTarget );
244 virtual void Remove( SfxStyleSheetBase* );
245 virtual void Insert( SfxStyleSheetBase* );
247 virtual void Clear();
249 SfxStyleSheetBasePool& operator=( const SfxStyleSheetBasePool& );
250 SfxStyleSheetBasePool& operator+=( const SfxStyleSheetBasePool& );
252 const SfxStyles& GetStyles();
253 virtual SfxStyleSheetBase* First();
254 virtual SfxStyleSheetBase* Next();
255 virtual SfxStyleSheetBase* Find( const UniString&, SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
257 virtual bool SetParent(SfxStyleFamily eFam,
258 const UniString &rStyle,
259 const UniString &rParent);
261 SfxStyleSheetBase* Find(const UniString& rStr)
262 { return Find(rStr, nSearchFamily, nMask); }
264 void SetSearchMask(SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
265 sal_uInt16 GetSearchMask() const;
266 SfxStyleFamily GetSearchFamily() const { return nSearchFamily; }
269 //=========================================================================
271 class SVL_DLLPUBLIC SfxStyleSheet: public SfxStyleSheetBase,
272 public SfxListener, public SfxBroadcaster, public svl::StyleSheetUser
274 public:
275 TYPEINFO();
277 SfxStyleSheet( const UniString&, const SfxStyleSheetBasePool&, SfxStyleFamily, sal_uInt16 );
278 SfxStyleSheet( const SfxStyleSheet& );
280 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
282 virtual bool isUsedByModel() const;
284 virtual bool SetParent( const UniString& );
286 protected:
287 SfxStyleSheet() // do not use! needed by MSVC at compile time to satisfy ImplInheritanceHelper2
288 : SfxStyleSheetBase(OUString("dummy"),
289 NULL, SFX_STYLE_FAMILY_ALL, 0)
291 assert(false);
293 virtual ~SfxStyleSheet();
296 //=========================================================================
298 class SVL_DLLPUBLIC SfxStyleSheetPool: public SfxStyleSheetBasePool
300 protected:
301 using SfxStyleSheetBasePool::Create;
302 virtual SfxStyleSheetBase* Create(const UniString&, SfxStyleFamily, sal_uInt16 mask);
303 virtual SfxStyleSheetBase* Create(const SfxStyleSheet &);
305 public:
306 SfxStyleSheetPool( SfxItemPool const& );
308 // virtual sal_Bool CopyTo(SfxStyleSheetPool &rDest, const String &rSourceName);
311 //=========================================================================
313 #define SFX_STYLESHEET_CREATED 1 // neu
314 #define SFX_STYLESHEET_MODIFIED 2 // ver"andert
315 #define SFX_STYLESHEET_CHANGED 3 // gel"oscht und neu (ausgetauscht)
316 #define SFX_STYLESHEET_ERASED 4 // gel"oscht
317 #define SFX_STYLESHEET_INDESTRUCTION 5 // wird gerade entfernt
319 #define SFX_STYLESHEETPOOL_CHANGES 1 // Aenderungen, die den Zustand
320 // des Pools anedern, aber nicht
321 // ueber die STYLESHEET Hints
322 // verschickt werden sollen.
324 //========================================================================
326 class SVL_DLLPUBLIC SfxStyleSheetPoolHint : public SfxHint
328 sal_uInt16 nHint;
330 public:
331 TYPEINFO();
333 SfxStyleSheetPoolHint(sal_uInt16 nArgHint) : nHint(nArgHint){}
334 sal_uInt16 GetHint() const
335 { return nHint; }
338 //=========================================================================
340 class SVL_DLLPUBLIC SfxStyleSheetHint: public SfxHint
342 SfxStyleSheetBase* pStyleSh;
343 sal_uInt16 nHint;
345 public:
346 TYPEINFO();
348 SfxStyleSheetHint( sal_uInt16, SfxStyleSheetBase& );
349 SfxStyleSheetBase* GetStyleSheet() const
350 { return pStyleSh; }
351 sal_uInt16 GetHint() const
352 { return nHint; }
355 class SVL_DLLPUBLIC SfxStyleSheetHintExtended: public SfxStyleSheetHint
357 String aName;
359 public:
360 TYPEINFO();
362 SfxStyleSheetHintExtended(
363 sal_uInt16, const String& rOld,
364 SfxStyleSheetBase& );
365 const String& GetOldName() { return aName; }
368 class SVL_DLLPUBLIC SfxUnoStyleSheet : public ::cppu::ImplInheritanceHelper2< SfxStyleSheet, ::com::sun::star::style::XStyle, ::com::sun::star::lang::XUnoTunnel >
370 public:
371 SfxUnoStyleSheet( const UniString& _rName, const SfxStyleSheetBasePool& _rPool, SfxStyleFamily _eFamily, sal_uInt16 _nMaske );
373 static SfxUnoStyleSheet* getUnoStyleSheet( const ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle >& xStyle );
375 // XUnoTunnel
376 virtual ::sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aIdentifier ) throw (::com::sun::star::uno::RuntimeException);
378 private:
379 SfxUnoStyleSheet(); // not implemented
381 static const ::com::sun::star::uno::Sequence< ::sal_Int8 >& getIdentifier();
384 #endif
386 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */