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_ITEMPOOL_HXX
21 : #define INCLUDED_SVL_ITEMPOOL_HXX
22 :
23 : #include <rtl/string.hxx>
24 : #include <svl/poolitem.hxx>
25 : #include <svl/svldllapi.h>
26 : #include <tools/solar.h>
27 : #include <o3tl/typed_flags_set.hxx>
28 :
29 : class SvStream;
30 : class SfxBroadcaster;
31 : struct SfxItemPool_Impl;
32 :
33 : #define SFX_WHICH_MAX 4999
34 :
35 : enum class SfxItemPoolFlags
36 : {
37 : NONE = 0x00,
38 : POOLABLE = 0x01,
39 : NOT_POOLABLE = 0x02,
40 : };
41 : namespace o3tl
42 : {
43 : template<> struct typed_flags<SfxItemPoolFlags> : is_typed_flags<SfxItemPoolFlags, 0x03> {};
44 : }
45 :
46 : struct SfxItemInfo
47 : {
48 : sal_uInt16 _nSID;
49 : SfxItemPoolFlags _nFlags;
50 : };
51 :
52 : class SfxStyleSheetIterator;
53 : struct SfxPoolItemArray_Impl;
54 : class SfxItemPool;
55 :
56 393760 : class SVL_DLLPUBLIC SfxItemPoolUser
57 : {
58 : public:
59 : virtual void ObjectInDestruction(const SfxItemPool& rSfxItemPool) = 0;
60 :
61 : protected:
62 387154 : ~SfxItemPoolUser() {}
63 : };
64 :
65 : /** Base class for providers of defaults of SfxPoolItems.
66 : *
67 : * The derived classes hold the concrete (const) instances which are referenced in several places
68 : * (usually within a single document).
69 : * This helps to lower the amount of calls to lifecycle methods, speeds up comparisons within a document
70 : * and facilitates loading and saving of attributes.
71 : */
72 : class SVL_DLLPUBLIC SfxItemPool
73 : {
74 : friend struct SfxItemPool_Impl;
75 :
76 : const SfxItemInfo* pItemInfos;
77 : SfxItemPool_Impl* pImp;
78 :
79 : public:
80 : void AddSfxItemPoolUser(SfxItemPoolUser& rNewUser);
81 : void RemoveSfxItemPoolUser(SfxItemPoolUser& rOldUser);
82 :
83 : private:
84 : sal_uInt16 GetIndex_Impl(sal_uInt16 nWhich) const;
85 : sal_uInt16 GetSize_Impl() const;
86 :
87 : SVL_DLLPRIVATE bool IsItemFlag_Impl( sal_uInt16 nWhich, SfxItemPoolFlags nFlag ) const;
88 :
89 : public:
90 : // for default SfxItemSet::CTOR, set default WhichRanges
91 : void FillItemIdRanges_Impl( sal_uInt16*& pWhichRanges ) const;
92 : const sal_uInt16* GetFrozenIdRanges() const;
93 :
94 : protected:
95 : static inline void SetRefCount( SfxPoolItem& rItem, sal_uLong n );
96 : static inline void AddRef( const SfxPoolItem& rItem, sal_uLong n = 1 );
97 : static inline sal_uLong ReleaseRef( const SfxPoolItem& rItem, sal_uLong n = 1);
98 : static inline void SetKind( SfxPoolItem& rItem, SfxItemKind nRef );
99 :
100 : public:
101 : SfxItemPool( const SfxItemPool &rPool,
102 : bool bCloneStaticDefaults = false );
103 : SfxItemPool( const OUString &rName,
104 : sal_uInt16 nStart, sal_uInt16 nEnd,
105 : const SfxItemInfo *pItemInfos,
106 : SfxPoolItem **pDefaults = 0,
107 : bool bLoadRefCounts = true );
108 :
109 : protected:
110 : virtual ~SfxItemPool();
111 :
112 : public:
113 : static void Free(SfxItemPool* pPool);
114 :
115 : SfxBroadcaster& BC();
116 :
117 : void SetPoolDefaultItem( const SfxPoolItem& );
118 : const SfxPoolItem* GetPoolDefaultItem( sal_uInt16 nWhich ) const;
119 : void ResetPoolDefaultItem( sal_uInt16 nWhich );
120 :
121 : void SetDefaults( SfxPoolItem **pDefaults );
122 : void ReleaseDefaults( bool bDelete = false );
123 : static void ReleaseDefaults( SfxPoolItem **pDefaults, sal_uInt16 nCount, bool bDelete = false );
124 :
125 : virtual SfxMapUnit GetMetric( sal_uInt16 nWhich ) const;
126 : void SetDefaultMetric( SfxMapUnit eNewMetric );
127 :
128 : /** Request string representation of pool items.
129 :
130 : This virtual function produces a string representation
131 : from the respective SfxItemPool subclass' known SfxPoolItems.
132 :
133 : Subclasses, please override this method, and handle
134 : SfxPoolItems that don't return useful/complete information on
135 : SfxPoolItem::GetPresentation()
136 :
137 : This baseclass yields the unmodified string representation of
138 : rItem.
139 :
140 : @param[in] rItem
141 : SfxPoolItem to query the string representation of
142 :
143 : @param[in] ePresent
144 : requested kind of representation - see SfxItemPresentation
145 :
146 : @param[in] eMetric
147 : requested unit of measure of the representation
148 :
149 : @param[out] rText
150 : string representation of 'rItem'
151 :
152 : @return true if it has a valid string representation
153 : */
154 : virtual bool GetPresentation( const SfxPoolItem& rItem,
155 : SfxMapUnit ePresentationMetric,
156 : OUString& rText,
157 : const IntlWrapper * pIntlWrapper = 0 ) const;
158 : virtual SfxItemPool* Clone() const;
159 : const OUString& GetName() const;
160 :
161 : virtual const SfxPoolItem& Put( const SfxPoolItem&, sal_uInt16 nWhich = 0 );
162 : virtual void Remove( const SfxPoolItem& );
163 : const SfxPoolItem& GetDefaultItem( sal_uInt16 nWhich ) const;
164 :
165 : const SfxPoolItem* LoadItem( SvStream &rStream,
166 : bool bDirect = false,
167 : const SfxItemPool *pRefPool = 0 );
168 : bool StoreItem( SvStream &rStream,
169 : const SfxPoolItem &rItem,
170 : bool bDirect = false ) const;
171 :
172 : sal_uInt32 GetSurrogate(const SfxPoolItem *) const;
173 : const SfxPoolItem * GetItem2(sal_uInt16 nWhich, sal_uInt32 nSurrogate) const;
174 : const SfxPoolItem * GetItem2Default(sal_uInt16 nWhich) const;
175 : sal_uInt32 GetItemCount2(sal_uInt16 nWhich) const;
176 : const SfxPoolItem* LoadSurrogate(SvStream& rStream,
177 : sal_uInt16 &rWhich, sal_uInt16 nSlotId,
178 : const SfxItemPool* pRefPool = 0 );
179 : bool StoreSurrogate(SvStream& rStream,
180 : const SfxPoolItem *pItem ) const;
181 :
182 : SvStream & Load(SvStream &);
183 : virtual SvStream & Store(SvStream &) const;
184 : bool HasPersistentRefCounts() const;
185 : void LoadCompleted();
186 :
187 : sal_uInt16 GetFirstWhich() const;
188 : sal_uInt16 GetLastWhich() const;
189 : bool IsInRange( sal_uInt16 nWhich ) const;
190 : bool IsInVersionsRange( sal_uInt16 nWhich ) const;
191 : bool IsInStoringRange( sal_uInt16 nWhich ) const;
192 : void SetStoringRange( sal_uInt16 nFrom, sal_uInt16 nTo );
193 : void SetSecondaryPool( SfxItemPool *pPool );
194 : SfxItemPool* GetSecondaryPool() const;
195 : SfxItemPool* GetMasterPool() const;
196 : void FreezeIdRanges();
197 :
198 : void Delete();
199 :
200 : bool IsItemFlag( sal_uInt16 nWhich, SfxItemPoolFlags nFlag ) const;
201 16577365 : bool IsItemFlag( const SfxPoolItem &rItem, SfxItemPoolFlags nFlag ) const
202 16577365 : { return IsItemFlag( rItem.Which(), nFlag ); }
203 : void SetItemInfos( const SfxItemInfo *pInfos );
204 : sal_uInt16 GetWhich( sal_uInt16 nSlot, bool bDeep = true ) const;
205 : sal_uInt16 GetSlotId( sal_uInt16 nWhich, bool bDeep = true ) const;
206 : sal_uInt16 GetTrueWhich( sal_uInt16 nSlot, bool bDeep = true ) const;
207 : sal_uInt16 GetTrueSlotId( sal_uInt16 nWhich, bool bDeep = true ) const;
208 :
209 : void SetVersionMap( sal_uInt16 nVer,
210 : sal_uInt16 nOldStart, sal_uInt16 nOldEnd,
211 : const sal_uInt16 *pWhichIdTab );
212 : sal_uInt16 GetNewWhich( sal_uInt16 nOldWhich ) const;
213 : sal_uInt16 GetVersion() const;
214 : void SetFileFormatVersion( sal_uInt16 nFileFormatVersion );
215 : bool IsCurrentVersionLoading() const;
216 :
217 196569 : static bool IsWhich(sal_uInt16 nId) {
218 196569 : return nId && nId <= SFX_WHICH_MAX; }
219 4795568 : static bool IsSlot(sal_uInt16 nId) {
220 4795568 : return nId && nId > SFX_WHICH_MAX; }
221 :
222 : static const SfxItemPool* GetStoringPool();
223 :
224 : private:
225 : const SfxItemPool& operator=(const SfxItemPool &) SAL_DELETED_FUNCTION;
226 :
227 : static const SfxItemPool* pStoringPool_;
228 : };
229 :
230 : // only the pool may manipulate the reference counts
231 1255450 : inline void SfxItemPool::SetRefCount( SfxPoolItem& rItem, sal_uLong n )
232 : {
233 1255450 : rItem.SetRefCount(n);
234 1255450 : }
235 :
236 : // only the pool may manipulate the reference counts
237 29361860 : inline void SfxItemPool::AddRef( const SfxPoolItem& rItem, sal_uLong n )
238 : {
239 29361860 : rItem.AddRef(n);
240 29361860 : }
241 :
242 : // only the pool may manipulate the reference counts
243 8474618 : inline sal_uLong SfxItemPool::ReleaseRef( const SfxPoolItem& rItem, sal_uLong n )
244 : {
245 8474618 : return rItem.ReleaseRef(n);
246 : }
247 :
248 0 : inline void SfxItemPool::SetKind( SfxPoolItem& rItem, SfxItemKind nRef )
249 : {
250 0 : rItem.SetKind( nRef );
251 0 : }
252 :
253 : #endif
254 :
255 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|