xref: /AOO41X/main/svl/inc/svl/itempool.hxx (revision 39a19a47feaddbaa21988da8c7bf801707fd3d48)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SFXITEMPOOL_HXX
25 #define _SFXITEMPOOL_HXX
26 
27 #include "svl/svldllapi.h"
28 
29 #ifndef INCLUDED_LIMITS_H
30 #include <limits.h>
31 #define INCLUDED_LIMITS_H
32 #endif
33 #include <tools/solar.h>
34 #include <tools/string.hxx>
35 #include <svl/svarray.hxx>
36 #include <svl/poolitem.hxx>
37 #include <vector>
38 
39 class SvStream;
40 class SfxBroadcaster;
41 struct SfxItemPool_Impl;
42 
43 #define SFX_WHICH_MAX 4999
44 
45 DBG_NAMEEX(SfxItemPool)
46 
47 //====================================================================
48 
49 #define SFX_ITEM_POOLABLE           0x0001
50 #define SFX_ITEM_NOT_POOLABLE       0x0002
51 
52 #define SFX_ITEM_USERFLAG0          0x0100
53 #define SFX_ITEM_USERFLAG1          0x0200
54 #define SFX_ITEM_USERFLAG2          0x0400
55 #define SFX_ITEM_USERFLAG3          0x0800
56 #define SFX_ITEM_USERFLAG4          0x1000
57 #define SFX_ITEM_USERFLAG5          0x2000
58 #define SFX_ITEM_USERFLAG6          0x4000
59 #define SFX_ITEM_USERFLAG7          0x8000
60 #define SFX_ITEM_USERFLAG8          0x0010
61 #define SFX_ITEM_USERFLAG9          0x0020
62 #define SFX_ITEM_USERFLAGA          0x0040
63 #define SFX_ITEM_USERFLAGB          0x0080
64 
65 //====================================================================
66 
67 struct SfxItemInfo
68 {
69     sal_uInt16      _nSID;
70     sal_uInt16      _nFlags;
71 };
72 
73 //====================================================================
74 
75 class SfxStyleSheetIterator;
76 struct SfxPoolItemArray_Impl;
77 class SfxItemPool;
78 
79 class SVL_DLLPUBLIC SfxItemPoolUser
80 {
81 public:
82     virtual void ObjectInDestruction(const SfxItemPool& rSfxItemPool) = 0;
83 };
84 
85 typedef ::std::vector< SfxItemPoolUser* > SfxItemPoolUserVector;
86 
87 class SVL_DLLPUBLIC SfxItemPool
88 
89 /*  [Beschreibung]
90 
91     Die von dieser Klasse abgeleiteten Klassen dienen der Bereitstellung von
92     Defaults von SfxPoolItems und halten konkrete (konstante) Instanzen, die
93     dann von mehreren Stellen (i.d.R. eines Dokuments) referenziert werden
94     k�nnen.
95 
96     Dadurch ist jeder Wert nur einmalig gespeichert, was zu wenig Konstruktor
97     und Destruktor-Aufrufen f�hrt, Vergleiche zwischen Items eines Dokuments
98     beschleunigt und ein einfaches Laden und Speichern von Attributen
99     bereitstellt.
100 */
101 
102 {
103     SVL_DLLPRIVATE void readTheItems(SvStream & rStream, sal_uInt32 nCount, sal_uInt16 nVersion,
104                                      SfxPoolItem * pDefItem, SfxPoolItemArray_Impl ** pArr);
105 
106     UniString                       aName;
107     sal_uInt16                          nStart, nEnd;
108     sal_uInt16                          _nFileFormatVersion;
109 #ifdef TF_POOLABLE
110     const SfxItemInfo*              pItemInfos;
111 #else
112     sal_uInt16*                         pSlotIds;
113 #endif
114     SfxItemPool_Impl*               pImp;
115     SfxPoolItem**                   ppStaticDefaults;
116     SfxPoolItem**                   ppPoolDefaults;
117     SfxItemPool*                    pSecondary;
118     SfxItemPool*                    pMaster;
119     sal_uInt16*                         _pPoolRanges;
120     FASTBOOL                        bPersistentRefCounts;
121 
122 private:
123     // ObjectUser section
124     SfxItemPoolUserVector           maSfxItemPoolUsers;
125 
126 public:
127     void AddSfxItemPoolUser(SfxItemPoolUser& rNewUser);
128     void RemoveSfxItemPoolUser(SfxItemPoolUser& rOldUser);
129 
130     //---------------------------------------------------------------------
131 #ifndef _SFXITEMS_HXX
132 
133 friend class SfxPoolWhichMap;
134 
135 private:
136     inline  sal_uInt16                  GetIndex_Impl(sal_uInt16 nWhich) const;
GetSize_Impl() const137     inline  sal_uInt16                  GetSize_Impl() const { return nEnd - nStart + 1; }
138 
139     SVL_DLLPRIVATE SvStream&                        Load1_Impl( SvStream &rStream );
140     SVL_DLLPRIVATE FASTBOOL                     IsItemFlag_Impl( sal_uInt16 nWhich, sal_uInt16 nFlag ) const;
141 
142 public:
143     // fuer dflt. SfxItemSet::CTOR, setze dflt. WhichRanges
144     void                            FillItemIdRanges_Impl( sal_uInt16*& pWhichRanges ) const;
GetFrozenIdRanges() const145     const sal_uInt16*                   GetFrozenIdRanges() const
146                                     { return _pPoolRanges; }
147     FASTBOOL                        IsVer2_Impl() const;
148 
149 #endif
150     //---------------------------------------------------------------------
151 
152 protected:
153     static inline void              SetRefCount( SfxPoolItem& rItem, sal_uLong n );
154     static inline sal_uLong             AddRef( const SfxPoolItem& rItem, sal_uLong n = 1 );
155     static inline sal_uLong             ReleaseRef( const SfxPoolItem& rItem, sal_uLong n = 1);
156 
157 public:
158                                     SfxItemPool( const SfxItemPool &rPool,
159                                                  sal_Bool bCloneStaticDefaults = sal_False );
160                                     SfxItemPool( const UniString &rName,
161                                                  sal_uInt16 nStart, sal_uInt16 nEnd,
162 #ifdef TF_POOLABLE
163                                                  const SfxItemInfo *pItemInfos,
164 #endif
165                                                  SfxPoolItem **pDefaults = 0,
166 #ifndef TF_POOLABLE
167                                                  sal_uInt16 *pSlotIds = 0,
168 #endif
169                                                  FASTBOOL bLoadRefCounts = sal_True );
170 protected:
171     virtual                         ~SfxItemPool();
172 public:
173     static void Free(SfxItemPool* pPool);
174 
175     SfxBroadcaster&                 BC();
176 
177     void                            SetPoolDefaultItem( const SfxPoolItem& );
178     const SfxPoolItem*              GetPoolDefaultItem( sal_uInt16 nWhich ) const;
179     void                            ResetPoolDefaultItem( sal_uInt16 nWhich );
180 
181     void                            SetDefaults( SfxPoolItem **pDefaults );
182     void                            ReleaseDefaults( sal_Bool bDelete = sal_False );
183     static void                     ReleaseDefaults( SfxPoolItem **pDefaults, sal_uInt16 nCount, sal_Bool bDelete = sal_False );
184 
185     virtual SfxMapUnit              GetMetric( sal_uInt16 nWhich ) const;
186     void                            SetDefaultMetric( SfxMapUnit eNewMetric );
187     virtual SfxItemPresentation     GetPresentation( const SfxPoolItem& rItem,
188                                         SfxItemPresentation ePresentation,
189                                         SfxMapUnit          ePresentationMetric,
190                                         XubString&              rText,
191                                         const IntlWrapper * pIntlWrapper
192                                          = 0 ) const;
193     virtual SfxItemPool*            Clone() const;
GetName() const194     UniString const &               GetName() const { return aName; }
195 
196     virtual const SfxPoolItem&      Put( const SfxPoolItem&, sal_uInt16 nWhich = 0 );
197     virtual void                    Remove( const SfxPoolItem& );
198     virtual const SfxPoolItem&      GetDefaultItem( sal_uInt16 nWhich ) const;
199 
200     const SfxPoolItem*              LoadItem( SvStream &rStream,
201                                               FASTBOOL bDirect = sal_False,
202                                               const SfxItemPool *pRefPool = 0 );
203     FASTBOOL                        StoreItem( SvStream &rStream,
204                                                const SfxPoolItem &rItem,
205                                                FASTBOOL bDirect = sal_False ) const;
206 
207     sal_uInt32                      GetSurrogate(const SfxPoolItem *) const;
208     const SfxPoolItem *             GetItem2(sal_uInt16 nWhich, sal_uInt32 nSurrogate) const;
209     sal_uInt32                      GetItemCount2(sal_uInt16 nWhich) const;
210     const SfxPoolItem*              LoadSurrogate(SvStream& rStream,
211                                             sal_uInt16 &rWhich, sal_uInt16 nSlotId,
212                                             const SfxItemPool* pRefPool = 0 );
213     FASTBOOL                        StoreSurrogate(SvStream& rStream,
214                                             const SfxPoolItem *pItem ) const;
215 
216     virtual SvStream &              Load(SvStream &);
217     virtual SvStream &              Store(SvStream &) const;
HasPersistentRefCounts() const218     int                             HasPersistentRefCounts() const {
219                                         return bPersistentRefCounts; }
220     void                            LoadCompleted();
221 
GetFirstWhich() const222     sal_uInt16                          GetFirstWhich() const { return nStart; }
GetLastWhich() const223     sal_uInt16                          GetLastWhich() const { return nEnd; }
IsInRange(sal_uInt16 nWhich) const224     FASTBOOL                        IsInRange( sal_uInt16 nWhich ) const {
225                                         return nWhich >= nStart &&
226                                                nWhich <= nEnd; }
227     FASTBOOL                        IsInVersionsRange( sal_uInt16 nWhich ) const;
228     FASTBOOL                        IsInStoringRange( sal_uInt16 nWhich ) const;
229     void                            SetStoringRange( sal_uInt16 nFrom, sal_uInt16 nTo );
230     void                            SetSecondaryPool( SfxItemPool *pPool );
GetSecondaryPool() const231     SfxItemPool*                    GetSecondaryPool() const {
232                                         return pSecondary; }
GetMasterPool() const233     SfxItemPool*                    GetMasterPool() const {
234                                         return pMaster; }
235     void                            FreezeIdRanges();
236 
237     void                            Cleanup();
238     void                            Delete();
239 
240 #ifdef TF_POOLABLE
241     FASTBOOL                        IsItemFlag( sal_uInt16 nWhich, sal_uInt16 nFlag ) const;
IsItemFlag(const SfxPoolItem & rItem,sal_uInt16 nFlag) const242     FASTBOOL                        IsItemFlag( const SfxPoolItem &rItem, sal_uInt16 nFlag ) const
243                                     { return IsItemFlag( rItem.Which(), nFlag ); }
SetItemInfos(const SfxItemInfo * pInfos)244     void                            SetItemInfos( const SfxItemInfo *pInfos )
245                                     { pItemInfos = pInfos; }
246 #else
HasMap() const247     int                             HasMap() const { return 0 != pSlotIds; }
SetMap(sal_uInt16 * pNewSlotIds)248     void                            SetMap( sal_uInt16 *pNewSlotIds )
249                                     { pSlotIds = pNewSlotIds; }
250 #endif
251     sal_uInt16                          GetWhich( sal_uInt16 nSlot, sal_Bool bDeep = sal_True ) const;
252     sal_uInt16                          GetSlotId( sal_uInt16 nWhich, sal_Bool bDeep = sal_True ) const;
253     sal_uInt16                          GetTrueWhich( sal_uInt16 nSlot, sal_Bool bDeep = sal_True ) const;
254     sal_uInt16                          GetTrueSlotId( sal_uInt16 nWhich, sal_Bool bDeep = sal_True ) const;
255 
256     void                            SetVersionMap( sal_uInt16 nVer,
257                                                    sal_uInt16 nOldStart, sal_uInt16 nOldEnd,
258                                                    sal_uInt16 *pWhichIdTab );
259     sal_uInt16                          GetNewWhich( sal_uInt16 nOldWhich ) const;
260     sal_uInt16                          GetVersion() const;
GetFileFormatVersion() const261     sal_uInt16                          GetFileFormatVersion() const
262                                     { return _nFileFormatVersion; }
263     void                            SetFileFormatVersion( sal_uInt16 nFileFormatVersion );
264     sal_uInt16                          GetLoadingVersion() const;
265     FASTBOOL                        IsCurrentVersionLoading() const;
266 
IsWhich(sal_uInt16 nId)267     static int                      IsWhich(sal_uInt16 nId) {
268                                         return nId && nId <= SFX_WHICH_MAX; }
IsSlot(sal_uInt16 nId)269     static int                      IsSlot(sal_uInt16 nId) {
270                                         return nId && nId > SFX_WHICH_MAX; }
271 
272     static const SfxItemPool*       GetStoringPool();
273     static void                     SetStoringPool( const SfxItemPool * );
274 
275 private:
276     const SfxItemPool&              operator=(const SfxItemPool &);   // n.i.!!
277 };
278 
279 // --------------- Inline Implementierungen ------------------------------
280 
281 // nur der Pool darf den Referenz-Zaehler manipulieren !!!
SetRefCount(SfxPoolItem & rItem,sal_uLong n)282 inline void SfxItemPool::SetRefCount( SfxPoolItem& rItem, sal_uLong n )
283 {
284     rItem.SetRefCount(n);
285 }
286 
287 // nur der Pool darf den Referenz-Zaehler manipulieren !!!
AddRef(const SfxPoolItem & rItem,sal_uLong n)288 inline sal_uLong SfxItemPool::AddRef( const SfxPoolItem& rItem, sal_uLong n )
289 {
290     return rItem.AddRef(n);
291 }
292 
293 // nur der Pool darf den Referenz-Zaehler manipulieren !!!
ReleaseRef(const SfxPoolItem & rItem,sal_uLong n)294 inline sal_uLong SfxItemPool::ReleaseRef( const SfxPoolItem& rItem, sal_uLong n )
295 {
296     return rItem.ReleaseRef(n);
297 }
298 
299 #endif
300