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 { 91 memset( ppPoolItems, 0, sizeof( SfxPoolItemArray_Impl* ) * ( nEnd - nStart + 1) ); 92 } 93 94 ~SfxItemPool_Impl() 95 { 96 delete[] ppPoolItems; 97 } 98 99 void DeleteItems() 100 { 101 delete[] ppPoolItems; 102 ppPoolItems = 0; 103 } 104 }; 105 106 // ----------------------------------------------------------------------- 107 108 // IBM-C-Set mag keine doppelten Defines 109 #ifdef DBG 110 # undef DBG 111 #endif 112 113 #if defined(DBG_UTIL) && defined(MSC) 114 #define SFX_TRACE(s,p) \ 115 { \ 116 ByteString aPtr(RTL_CONSTASCII_STRINGPARAM("0x0000:0x0000")); \ 117 _snprintf(const_cast< sal_Char *>(aPtr.GetBuffer()), aPtr.Len(), \ 118 "%lp", p ); \ 119 aPtr.Insert(s, 0); \ 120 DbgTrace( aPtr.GetBuffer() ); \ 121 } 122 #define DBG(x) x 123 #else 124 #define SFX_TRACE(s,p) 125 #define DBG(x) 126 #endif 127 128 #define CHECK_FILEFORMAT( rStream, nTag ) \ 129 { sal_uInt16 nFileTag; \ 130 rStream >> nFileTag; \ 131 if ( nTag != nFileTag ) \ 132 { \ 133 DBG_ERROR( #nTag ); /*! s.u. */ \ 134 /*! error-code setzen und auswerten! */ \ 135 (rStream).SetError(SVSTREAM_FILEFORMAT_ERROR); \ 136 pImp->bStreaming = sal_False; \ 137 return rStream; \ 138 } \ 139 } 140 141 #define CHECK_FILEFORMAT_RELEASE( rStream, nTag, pPointer ) \ 142 { sal_uInt16 nFileTag; \ 143 rStream >> nFileTag; \ 144 if ( nTag != nFileTag ) \ 145 { \ 146 DBG_ERROR( #nTag ); /*! s.u. */ \ 147 /*! error-code setzen und auswerten! */ \ 148 (rStream).SetError(SVSTREAM_FILEFORMAT_ERROR); \ 149 pImp->bStreaming = sal_False; \ 150 delete pPointer; \ 151 return rStream; \ 152 } \ 153 } 154 155 #define CHECK_FILEFORMAT2( rStream, nTag1, nTag2 ) \ 156 { sal_uInt16 nFileTag; \ 157 rStream >> nFileTag; \ 158 if ( nTag1 != nFileTag && nTag2 != nFileTag ) \ 159 { \ 160 DBG_ERROR( #nTag1 ); /*! s.u. */ \ 161 /*! error-code setzen und auswerten! */ \ 162 (rStream).SetError(SVSTREAM_FILEFORMAT_ERROR); \ 163 pImp->bStreaming = sal_False; \ 164 return rStream; \ 165 } \ 166 } 167 168 #define SFX_ITEMPOOL_VER_MAJOR sal_uInt8(2) 169 #define SFX_ITEMPOOL_VER_MINOR sal_uInt8(0) 170 171 #define SFX_ITEMPOOL_TAG_STARTPOOL_4 sal_uInt16(0x1111) 172 #define SFX_ITEMPOOL_TAG_STARTPOOL_5 sal_uInt16(0xBBBB) 173 #define SFX_ITEMPOOL_TAG_ITEMPOOL sal_uInt16(0xAAAA) 174 #define SFX_ITEMPOOL_TAG_ITEMS sal_uInt16(0x2222) 175 #define SFX_ITEMPOOL_TAG_ITEM sal_uInt16(0x7777) 176 #define SFX_ITEMPOOL_TAG_SIZES sal_uInt16(0x3333) 177 #define SFX_ITEMPOOL_TAG_DEFAULTS sal_uInt16(0x4444) 178 #define SFX_ITEMPOOL_TAG_VERSIONMAP sal_uInt16(0x5555) 179 #define SFX_ITEMPOOL_TAG_HEADER sal_uInt16(0x6666) 180 #define SFX_ITEMPOOL_TAG_ENDPOOL sal_uInt16(0xEEEE) 181 #define SFX_ITEMPOOL_TAG_TRICK4OLD sal_uInt16(0xFFFF) 182 183 #define SFX_ITEMPOOL_REC sal_uInt8(0x01) 184 #define SFX_ITEMPOOL_REC_HEADER sal_uInt8(0x10) 185 #define SFX_ITEMPOOL_REC_VERSIONMAP sal_uInt16(0x0020) 186 #define SFX_ITEMPOOL_REC_WHICHIDS sal_uInt16(0x0030) 187 #define SFX_ITEMPOOL_REC_ITEMS sal_uInt16(0x0040) 188 #define SFX_ITEMPOOL_REC_DEFAULTS sal_uInt16(0x0050) 189 190 #define SFX_ITEMSET_REC sal_uInt8(0x02) 191 192 #define SFX_STYLES_REC sal_uInt8(0x03) 193 #define SFX_STYLES_REC_HEADER sal_uInt16(0x0010) 194 #define SFX_STYLES_REC_STYLES sal_uInt16(0x0020) 195 196 //======================================================================== 197 198 inline sal_uInt16 SfxItemPool::GetIndex_Impl(sal_uInt16 nWhich) const 199 { 200 DBG_CHKTHIS(SfxItemPool, 0); 201 DBG_ASSERT(nWhich >= nStart && nWhich <= nEnd, "Which-Id nicht im Pool-Bereich"); 202 return nWhich - nStart; 203 } 204 205