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 _SFXITEMPOOL_HXX
21 : : #define _SFXITEMPOOL_HXX
22 : :
23 : : #include "svl/svldllapi.h"
24 : :
25 : : #include <limits.h>
26 : : #include <tools/solar.h>
27 : : #include <tools/string.hxx>
28 : : #include <svl/poolitem.hxx>
29 : : #include <vector>
30 : :
31 : : class SvStream;
32 : : class SfxBroadcaster;
33 : : struct SfxItemPool_Impl;
34 : :
35 : : #define SFX_WHICH_MAX 4999
36 : :
37 : : DBG_NAMEEX(SfxItemPool)
38 : :
39 : : //====================================================================
40 : :
41 : : #define SFX_ITEM_POOLABLE 0x0001
42 : : #define SFX_ITEM_NOT_POOLABLE 0x0002
43 : :
44 : : #define SFX_ITEM_USERFLAG0 0x0100
45 : : #define SFX_ITEM_USERFLAG1 0x0200
46 : : #define SFX_ITEM_USERFLAG2 0x0400
47 : : #define SFX_ITEM_USERFLAG3 0x0800
48 : : #define SFX_ITEM_USERFLAG4 0x1000
49 : : #define SFX_ITEM_USERFLAG5 0x2000
50 : : #define SFX_ITEM_USERFLAG6 0x4000
51 : : #define SFX_ITEM_USERFLAG7 0x8000
52 : : #define SFX_ITEM_USERFLAG8 0x0010
53 : : #define SFX_ITEM_USERFLAG9 0x0020
54 : : #define SFX_ITEM_USERFLAGA 0x0040
55 : : #define SFX_ITEM_USERFLAGB 0x0080
56 : :
57 : : //====================================================================
58 : :
59 : : struct SfxItemInfo
60 : : {
61 : : sal_uInt16 _nSID;
62 : : sal_uInt16 _nFlags;
63 : : };
64 : :
65 : : //====================================================================
66 : :
67 : : class SfxStyleSheetIterator;
68 : : struct SfxPoolItemArray_Impl;
69 : : class SfxItemPool;
70 : :
71 : 132867 : class SVL_DLLPUBLIC SfxItemPoolUser
72 : : {
73 : : public:
74 : : virtual void ObjectInDestruction(const SfxItemPool& rSfxItemPool) = 0;
75 : :
76 : : protected:
77 : 130035 : ~SfxItemPoolUser() {}
78 : : };
79 : :
80 : : class SVL_DLLPUBLIC SfxItemPool
81 : :
82 : : /* [Beschreibung]
83 : :
84 : : Die von dieser Klasse abgeleiteten Klassen dienen der Bereitstellung von
85 : : Defaults von SfxPoolItems und halten konkrete (konstante) Instanzen, die
86 : : dann von mehreren Stellen (i.d.R. eines Dokuments) referenziert werden
87 : : k�nnen.
88 : :
89 : : Dadurch ist jeder Wert nur einmalig gespeichert, was zu wenig Konstruktor
90 : : und Destruktor-Aufrufen f�hrt, Vergleiche zwischen Items eines Dokuments
91 : : beschleunigt und ein einfaches Laden und Speichern von Attributen
92 : : bereitstellt.
93 : : */
94 : :
95 : : {
96 : : friend struct SfxItemPool_Impl;
97 : :
98 : : const SfxItemInfo* pItemInfos;
99 : : SfxItemPool_Impl* pImp;
100 : :
101 : : public:
102 : : void AddSfxItemPoolUser(SfxItemPoolUser& rNewUser);
103 : : void RemoveSfxItemPoolUser(SfxItemPoolUser& rOldUser);
104 : :
105 : : //---------------------------------------------------------------------
106 : : #ifndef _SFXITEMS_HXX
107 : :
108 : : private:
109 : : sal_uInt16 GetIndex_Impl(sal_uInt16 nWhich) const;
110 : : sal_uInt16 GetSize_Impl() const;
111 : :
112 : : SVL_DLLPRIVATE SvStream& Load1_Impl( SvStream &rStream );
113 : : SVL_DLLPRIVATE bool IsItemFlag_Impl( sal_uInt16 nWhich, sal_uInt16 nFlag ) const;
114 : :
115 : : public:
116 : : // fuer dflt. SfxItemSet::CTOR, setze dflt. WhichRanges
117 : : void FillItemIdRanges_Impl( sal_uInt16*& pWhichRanges ) const;
118 : : const sal_uInt16* GetFrozenIdRanges() const;
119 : :
120 : : #endif
121 : : //---------------------------------------------------------------------
122 : :
123 : : protected:
124 : : static inline void SetRefCount( SfxPoolItem& rItem, sal_uLong n );
125 : : static inline sal_uLong AddRef( const SfxPoolItem& rItem, sal_uLong n = 1 );
126 : : static inline sal_uLong ReleaseRef( const SfxPoolItem& rItem, sal_uLong n = 1);
127 : : static inline void SetKind( SfxPoolItem& rItem, sal_uInt16 nRef );
128 : :
129 : : public:
130 : : SfxItemPool( const SfxItemPool &rPool,
131 : : sal_Bool bCloneStaticDefaults = sal_False );
132 : : SfxItemPool( const rtl::OUString &rName,
133 : : sal_uInt16 nStart, sal_uInt16 nEnd,
134 : : const SfxItemInfo *pItemInfos,
135 : : SfxPoolItem **pDefaults = 0,
136 : : bool bLoadRefCounts = true );
137 : : protected:
138 : : virtual ~SfxItemPool();
139 : : public:
140 : : static void Free(SfxItemPool* pPool);
141 : :
142 : : SfxBroadcaster& BC();
143 : :
144 : : void SetPoolDefaultItem( const SfxPoolItem& );
145 : : const SfxPoolItem* GetPoolDefaultItem( sal_uInt16 nWhich ) const;
146 : : void ResetPoolDefaultItem( sal_uInt16 nWhich );
147 : :
148 : : void SetDefaults( SfxPoolItem **pDefaults );
149 : : void ReleaseDefaults( sal_Bool bDelete = sal_False );
150 : : static void ReleaseDefaults( SfxPoolItem **pDefaults, sal_uInt16 nCount, sal_Bool bDelete = sal_False );
151 : :
152 : : virtual SfxMapUnit GetMetric( sal_uInt16 nWhich ) const;
153 : : void SetDefaultMetric( SfxMapUnit eNewMetric );
154 : : virtual SfxItemPresentation GetPresentation( const SfxPoolItem& rItem,
155 : : SfxItemPresentation ePresentation,
156 : : SfxMapUnit ePresentationMetric,
157 : : XubString& rText,
158 : : const IntlWrapper * pIntlWrapper
159 : : = 0 ) const;
160 : : virtual SfxItemPool* Clone() const;
161 : : const rtl::OUString& GetName() const;
162 : :
163 : : virtual const SfxPoolItem& Put( const SfxPoolItem&, sal_uInt16 nWhich = 0 );
164 : : virtual void Remove( const SfxPoolItem& );
165 : : virtual const SfxPoolItem& GetDefaultItem( sal_uInt16 nWhich ) const;
166 : :
167 : : const SfxPoolItem* LoadItem( SvStream &rStream,
168 : : bool bDirect = false,
169 : : const SfxItemPool *pRefPool = 0 );
170 : : bool StoreItem( SvStream &rStream,
171 : : const SfxPoolItem &rItem,
172 : : bool bDirect = false ) const;
173 : :
174 : : sal_uInt32 GetSurrogate(const SfxPoolItem *) const;
175 : : const SfxPoolItem * GetItem2(sal_uInt16 nWhich, sal_uInt32 nSurrogate) const;
176 : : sal_uInt32 GetItemCount2(sal_uInt16 nWhich) const;
177 : : const SfxPoolItem* LoadSurrogate(SvStream& rStream,
178 : : sal_uInt16 &rWhich, sal_uInt16 nSlotId,
179 : : const SfxItemPool* pRefPool = 0 );
180 : : bool StoreSurrogate(SvStream& rStream,
181 : : const SfxPoolItem *pItem ) const;
182 : :
183 : : virtual SvStream & Load(SvStream &);
184 : : virtual SvStream & Store(SvStream &) const;
185 : : bool HasPersistentRefCounts() const;
186 : : void LoadCompleted();
187 : :
188 : : sal_uInt16 GetFirstWhich() const;
189 : : sal_uInt16 GetLastWhich() const;
190 : : bool IsInRange( sal_uInt16 nWhich ) const;
191 : : bool IsInVersionsRange( sal_uInt16 nWhich ) const;
192 : : bool IsInStoringRange( sal_uInt16 nWhich ) const;
193 : : void SetStoringRange( sal_uInt16 nFrom, sal_uInt16 nTo );
194 : : void SetSecondaryPool( SfxItemPool *pPool );
195 : : SfxItemPool* GetSecondaryPool() const;
196 : : SfxItemPool* GetMasterPool() const;
197 : : void FreezeIdRanges();
198 : :
199 : : void Delete();
200 : :
201 : : bool IsItemFlag( sal_uInt16 nWhich, sal_uInt16 nFlag ) const;
202 : 4791558 : bool IsItemFlag( const SfxPoolItem &rItem, sal_uInt16 nFlag ) const
203 : 4791558 : { return IsItemFlag( rItem.Which(), nFlag ); }
204 : 3921 : void SetItemInfos( const SfxItemInfo *pInfos )
205 : 3921 : { pItemInfos = pInfos; }
206 : : sal_uInt16 GetWhich( sal_uInt16 nSlot, sal_Bool bDeep = sal_True ) const;
207 : : sal_uInt16 GetSlotId( sal_uInt16 nWhich, sal_Bool bDeep = sal_True ) const;
208 : : sal_uInt16 GetTrueWhich( sal_uInt16 nSlot, sal_Bool bDeep = sal_True ) const;
209 : : sal_uInt16 GetTrueSlotId( sal_uInt16 nWhich, sal_Bool bDeep = sal_True ) const;
210 : :
211 : : void SetVersionMap( sal_uInt16 nVer,
212 : : sal_uInt16 nOldStart, sal_uInt16 nOldEnd,
213 : : const sal_uInt16 *pWhichIdTab );
214 : : sal_uInt16 GetNewWhich( sal_uInt16 nOldWhich ) const;
215 : : sal_uInt16 GetVersion() const;
216 : : void SetFileFormatVersion( sal_uInt16 nFileFormatVersion );
217 : : bool IsCurrentVersionLoading() const;
218 : :
219 : 161587 : static int IsWhich(sal_uInt16 nId) {
220 [ + - ][ + + ]: 161587 : return nId && nId <= SFX_WHICH_MAX; }
221 : 2219068 : static int IsSlot(sal_uInt16 nId) {
222 [ + - ][ + + ]: 2219068 : return nId && nId > SFX_WHICH_MAX; }
223 : :
224 : : static const SfxItemPool* GetStoringPool();
225 : :
226 : : private:
227 : : const SfxItemPool& operator=(const SfxItemPool &); // n.i.!!
228 : :
229 : : static const SfxItemPool* pStoringPool_;
230 : : };
231 : :
232 : : // --------------- Inline Implementierungen ------------------------------
233 : :
234 : : // nur der Pool darf den Referenz-Zaehler manipulieren !!!
235 : 856917 : inline void SfxItemPool::SetRefCount( SfxPoolItem& rItem, sal_uLong n )
236 : : {
237 : 856917 : rItem.SetRefCount(n);
238 : 856917 : }
239 : :
240 : : // nur der Pool darf den Referenz-Zaehler manipulieren !!!
241 : 14623449 : inline sal_uLong SfxItemPool::AddRef( const SfxPoolItem& rItem, sal_uLong n )
242 : : {
243 : 14623449 : return rItem.AddRef(n);
244 : : }
245 : :
246 : : // nur der Pool darf den Referenz-Zaehler manipulieren !!!
247 : 3103306 : inline sal_uLong SfxItemPool::ReleaseRef( const SfxPoolItem& rItem, sal_uLong n )
248 : : {
249 : 3103306 : return rItem.ReleaseRef(n);
250 : : }
251 : :
252 : 0 : inline void SfxItemPool::SetKind( SfxPoolItem& rItem, sal_uInt16 nRef )
253 : : {
254 : 0 : rItem.SetKind( nRef );
255 : 0 : }
256 : :
257 : : #endif
258 : :
259 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|