1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #include <svl/brdcst.hxx> 28 #include <boost/shared_ptr.hpp> 29 #include <deque> 30 31 #ifndef DELETEZ 32 #define DELETEZ(pPtr) { delete pPtr; pPtr = 0; } 33 #endif 34 35 36 struct SfxPoolVersion_Impl 37 { 38 sal_uInt16 _nVer; 39 sal_uInt16 _nStart, _nEnd; 40 sal_uInt16* _pMap; 41 42 SfxPoolVersion_Impl( sal_uInt16 nVer, sal_uInt16 nStart, sal_uInt16 nEnd, 43 sal_uInt16 *pMap ) 44 : _nVer( nVer ), 45 _nStart( nStart ), 46 _nEnd( nEnd ), 47 _pMap( pMap ) 48 {} 49 SfxPoolVersion_Impl( const SfxPoolVersion_Impl &rOrig ) 50 : _nVer( rOrig._nVer ), 51 _nStart( rOrig._nStart ), 52 _nEnd( rOrig._nEnd ), 53 _pMap( rOrig._pMap ) 54 {} 55 }; 56 57 typedef std::deque<SfxPoolItem*> SfxPoolItemArrayBase_Impl; 58 59 typedef boost::shared_ptr< SfxPoolVersion_Impl > SfxPoolVersion_ImplPtr; 60 typedef std::deque< SfxPoolVersion_ImplPtr > SfxPoolVersionArr_Impl; 61 62 struct SfxPoolItemArray_Impl: public SfxPoolItemArrayBase_Impl 63 { 64 size_t nFirstFree; 65 66 SfxPoolItemArray_Impl () 67 : nFirstFree( 0 ) 68 {} 69 }; 70 71 class SfxStyleSheetIterator; 72 73 struct SfxItemPool_Impl 74 { 75 SfxBroadcaster aBC; 76 SfxPoolItemArray_Impl** ppPoolItems; 77 SfxPoolVersionArr_Impl aVersions; 78 sal_uInt16 nVersion; 79 sal_uInt16 nLoadingVersion; 80 sal_uInt16 nInitRefCount; // 1, beim Laden ggf. 2 81 sal_uInt16 nVerStart, nVerEnd; // WhichRange in Versions 82 sal_uInt16 nStoringStart, nStoringEnd; // zu speichernder Range 83 sal_uInt8 nMajorVer, nMinorVer; // Pool selbst 84 SfxMapUnit eDefMetric; 85 FASTBOOL bInSetItem; 86 FASTBOOL bStreaming; // in Load() bzw. Store() 87 88 SfxItemPool_Impl( sal_uInt16 nStart, sal_uInt16 nEnd ) 89 : ppPoolItems (new SfxPoolItemArray_Impl*[ nEnd - nStart + 1]) 90 , nLoadingVersion(0) 91 , nInitRefCount(0) 92 , nVerStart(0) 93 , nVerEnd(0) 94 , nStoringStart(0) 95 , nStoringEnd(0) 96 , nMajorVer(0) 97 , nMinorVer(0) 98 , bInSetItem(false) 99 , bStreaming(false) 100 { 101 memset( ppPoolItems, 0, sizeof( SfxPoolItemArray_Impl* ) * ( nEnd - nStart + 1) ); 102 } 103 104 ~SfxItemPool_Impl() 105 { 106 delete[] ppPoolItems; 107 } 108 109 void DeleteItems() 110 { 111 delete[] ppPoolItems; 112 ppPoolItems = 0; 113 } 114 }; 115 116 // ----------------------------------------------------------------------- 117 118 // IBM-C-Set mag keine doppelten Defines 119 #ifdef DBG 120 # undef DBG 121 #endif 122 123 #if defined(DBG_UTIL) && defined(MSC) 124 #define SFX_TRACE(s,p) \ 125 { \ 126 ByteString aPtr(RTL_CONSTASCII_STRINGPARAM("0x0000:0x0000")); \ 127 _snprintf(const_cast< sal_Char *>(aPtr.GetBuffer()), aPtr.Len(), \ 128 "%lp", p ); \ 129 aPtr.Insert(s, 0); \ 130 DbgTrace( aPtr.GetBuffer() ); \ 131 } 132 #define DBG(x) x 133 #else 134 #define SFX_TRACE(s,p) 135 #define DBG(x) 136 #endif 137 138 #define CHECK_FILEFORMAT( rStream, nTag ) \ 139 { sal_uInt16 nFileTag; \ 140 rStream >> nFileTag; \ 141 if ( nTag != nFileTag ) \ 142 { \ 143 DBG_ERROR( #nTag ); /*! s.u. */ \ 144 /*! error-code setzen und auswerten! */ \ 145 (rStream).SetError(SVSTREAM_FILEFORMAT_ERROR); \ 146 pImp->bStreaming = sal_False; \ 147 return rStream; \ 148 } \ 149 } 150 151 #define CHECK_FILEFORMAT_RELEASE( rStream, nTag, pPointer ) \ 152 { sal_uInt16 nFileTag; \ 153 rStream >> nFileTag; \ 154 if ( nTag != nFileTag ) \ 155 { \ 156 DBG_ERROR( #nTag ); /*! s.u. */ \ 157 /*! error-code setzen und auswerten! */ \ 158 (rStream).SetError(SVSTREAM_FILEFORMAT_ERROR); \ 159 pImp->bStreaming = sal_False; \ 160 delete pPointer; \ 161 return rStream; \ 162 } \ 163 } 164 165 #define CHECK_FILEFORMAT2( rStream, nTag1, nTag2 ) \ 166 { sal_uInt16 nFileTag; \ 167 rStream >> nFileTag; \ 168 if ( nTag1 != nFileTag && nTag2 != nFileTag ) \ 169 { \ 170 DBG_ERROR( #nTag1 ); /*! s.u. */ \ 171 /*! error-code setzen und auswerten! */ \ 172 (rStream).SetError(SVSTREAM_FILEFORMAT_ERROR); \ 173 pImp->bStreaming = sal_False; \ 174 return rStream; \ 175 } \ 176 } 177 178 #define SFX_ITEMPOOL_VER_MAJOR sal_uInt8(2) 179 #define SFX_ITEMPOOL_VER_MINOR sal_uInt8(0) 180 181 #define SFX_ITEMPOOL_TAG_STARTPOOL_4 sal_uInt16(0x1111) 182 #define SFX_ITEMPOOL_TAG_STARTPOOL_5 sal_uInt16(0xBBBB) 183 #define SFX_ITEMPOOL_TAG_ITEMPOOL sal_uInt16(0xAAAA) 184 #define SFX_ITEMPOOL_TAG_ITEMS sal_uInt16(0x2222) 185 #define SFX_ITEMPOOL_TAG_ITEM sal_uInt16(0x7777) 186 #define SFX_ITEMPOOL_TAG_SIZES sal_uInt16(0x3333) 187 #define SFX_ITEMPOOL_TAG_DEFAULTS sal_uInt16(0x4444) 188 #define SFX_ITEMPOOL_TAG_VERSIONMAP sal_uInt16(0x5555) 189 #define SFX_ITEMPOOL_TAG_HEADER sal_uInt16(0x6666) 190 #define SFX_ITEMPOOL_TAG_ENDPOOL sal_uInt16(0xEEEE) 191 #define SFX_ITEMPOOL_TAG_TRICK4OLD sal_uInt16(0xFFFF) 192 193 #define SFX_ITEMPOOL_REC sal_uInt8(0x01) 194 #define SFX_ITEMPOOL_REC_HEADER sal_uInt8(0x10) 195 #define SFX_ITEMPOOL_REC_VERSIONMAP sal_uInt16(0x0020) 196 #define SFX_ITEMPOOL_REC_WHICHIDS sal_uInt16(0x0030) 197 #define SFX_ITEMPOOL_REC_ITEMS sal_uInt16(0x0040) 198 #define SFX_ITEMPOOL_REC_DEFAULTS sal_uInt16(0x0050) 199 200 #define SFX_ITEMSET_REC sal_uInt8(0x02) 201 202 #define SFX_STYLES_REC sal_uInt8(0x03) 203 #define SFX_STYLES_REC_HEADER sal_uInt16(0x0010) 204 #define SFX_STYLES_REC_STYLES sal_uInt16(0x0020) 205 206 //======================================================================== 207 208 inline sal_uInt16 SfxItemPool::GetIndex_Impl(sal_uInt16 nWhich) const 209 { 210 DBG_CHKTHIS(SfxItemPool, 0); 211 DBG_ASSERT(nWhich >= nStart && nWhich <= nEnd, "Which-Id nicht im Pool-Bereich"); 212 return nWhich - nStart; 213 } 214 215