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 #ifndef _LAYHELP_HXX 28 #define _LAYHELP_HXX 29 #ifndef _SVSTDARR_HXX 30 #define _SVSTDARR_USHORTS 31 #define _SVSTDARR_ULONGS 32 #define _SVSTDARR_BYTES 33 #define _SVSTDARR_XUB_STRLEN 34 #include <svl/svstdarr.hxx> 35 #endif 36 #include <swrect.hxx> 37 38 class SwDoc; 39 class SwFrm; 40 class SwLayoutFrm; 41 class SwPageFrm; 42 class SwFlyFrm; 43 class SwSectionFrm; 44 class SwSectionNode; 45 class SvStream; 46 47 /************************************************************************* 48 * class SwLayCacheImpl 49 * contains the page break information and the text frame positions 50 * of the document (after loading) 51 * and is used inside the constructor of the layout rootframe to 52 * insert content and text frames at the right pages. 53 * For every page of the main text (body content, no footnotes, text frames etc.) 54 * we have the nodeindex of the first content at the page, 55 * the type of content ( table or paragraph ) 56 * and if it's not the first part of the table/paragraph, 57 * the row/character-offset inside the table/paragraph. 58 * The text frame positions are stored in the SwPageFlyCache array. 59 *************************************************************************/ 60 61 class SwFlyCache; 62 typedef SwFlyCache* SwFlyCachePtr; 63 SV_DECL_PTRARR_DEL( SwPageFlyCache, SwFlyCachePtr, 0, 4 ) 64 65 class SwLayCacheImpl : public SvULongs 66 { 67 SvXub_StrLens aOffset; 68 SvUShorts aType; 69 SwPageFlyCache aFlyCache; 70 sal_Bool bUseFlyCache; 71 void Insert( sal_uInt16 nType, sal_uLong nIndex, xub_StrLen nOffset ); 72 73 public: 74 SwLayCacheImpl() : SvULongs( 20, 10 ), aType( 20, 10 ) {} 75 sal_Bool Read( SvStream& rStream ); 76 77 sal_uLong GetBreakIndex( sal_uInt16 nIdx ) const { return GetObject( nIdx ); } 78 xub_StrLen GetBreakOfst( size_t nIdx ) const { return aOffset[ nIdx ]; } 79 sal_uInt16 GetBreakType( sal_uInt16 nIdx ) const { return aType[ nIdx ]; } 80 81 sal_uInt16 GetFlyCount() const { return aFlyCache.Count(); } 82 SwFlyCache *GetFlyCache( sal_uInt16 nIdx ) const { return aFlyCache[ nIdx ]; } 83 84 sal_Bool IsUseFlyCache() const { return bUseFlyCache; } 85 }; 86 87 /************************************************************************* 88 * class SwActualSection 89 * helps to create the sectionframes during the _InsertCnt-function 90 * by controlling nested sections. 91 *************************************************************************/ 92 93 class SwActualSection 94 { 95 SwActualSection *pUpper; 96 SwSectionFrm *pSectFrm; 97 SwSectionNode *pSectNode; 98 public: 99 SwActualSection( SwActualSection *pUpper, 100 SwSectionFrm *pSect, 101 SwSectionNode *pNd ); 102 103 SwSectionFrm *GetSectionFrm() { return pSectFrm; } 104 void SetSectionFrm( SwSectionFrm *p ) { pSectFrm = p; } 105 SwSectionNode *GetSectionNode() { return pSectNode;} 106 SwActualSection *GetUpper() { return pUpper; } 107 }; 108 109 /************************************************************************* 110 * class SwLayHelper 111 * helps during the _InsertCnt-function to create new pages. 112 * If there's a layoutcache available, this information is used. 113 *************************************************************************/ 114 115 class SwLayHelper 116 { 117 SwFrm* &rpFrm; 118 SwFrm* &rpPrv; 119 SwPageFrm* &rpPage; 120 SwLayoutFrm* &rpLay; 121 SwActualSection* &rpActualSection; 122 sal_Bool &rbBreakAfter; 123 SwDoc* pDoc; 124 SwLayCacheImpl* pImpl; 125 sal_uLong nMaxParaPerPage; 126 sal_uLong nParagraphCnt; 127 sal_uLong nStartOfContent; 128 sal_uInt16 nIndex; // the index in the page break array 129 sal_uInt16 nFlyIdx; // the index in the fly cache array 130 sal_Bool bFirst : 1; 131 void _CheckFlyCache( SwPageFrm* pPage ); 132 public: 133 SwLayHelper( SwDoc *pD, SwFrm* &rpF, SwFrm* &rpP, SwPageFrm* &rpPg, 134 SwLayoutFrm* &rpL, SwActualSection* &rpA, sal_Bool &rBrk, 135 sal_uLong nNodeIndex, sal_Bool bCache ); 136 ~SwLayHelper(); 137 sal_uLong CalcPageCount(); 138 sal_Bool CheckInsert( sal_uLong nNodeIndex ); 139 140 sal_Bool BreakPage( xub_StrLen& rOffs, sal_uLong nNodeIndex ); 141 sal_Bool CheckInsertPage(); 142 143 // Look for fresh text frames at this (new) page and set them to the right 144 // position, if they are in the fly cache. 145 void CheckFlyCache( SwPageFrm* pPage ) 146 { if( pImpl && nFlyIdx < pImpl->GetFlyCount() ) _CheckFlyCache( pPage ); } 147 148 // Look for this text frame and set it to the right position, 149 // if it's in the fly cache. 150 static sal_Bool CheckPageFlyCache( SwPageFrm* &rpPage, SwFlyFrm* pFly ); 151 }; 152 153 /************************************************************************* 154 * class SwLayCacheIoImpl 155 * contains the data structures that are required to read and write a 156 * layout cache. 157 *************************************************************************/ 158 159 #define SW_LAYCACHE_IO_REC_PAGES 'p' 160 #define SW_LAYCACHE_IO_REC_PARA 'P' 161 #define SW_LAYCACHE_IO_REC_TABLE 'T' 162 #define SW_LAYCACHE_IO_REC_FLY 'F' 163 164 #define SW_LAYCACHE_IO_VERSION_MAJOR 1 165 #define SW_LAYCACHE_IO_VERSION_MINOR 1 166 167 class SwLayCacheIoImpl 168 { 169 SvBytes aRecTypes; 170 SvULongs aRecSizes; 171 172 SvStream *pStream; 173 174 sal_uLong nFlagRecEnd; 175 176 sal_uInt16 nMajorVersion; 177 sal_uInt16 nMinorVersion; 178 179 sal_Bool bWriteMode : 1; 180 sal_Bool bError : 1; 181 182 public: 183 SwLayCacheIoImpl( SvStream& rStrm, sal_Bool bWrtMd ); 184 185 // Get input or output stream 186 SvStream& GetStream() const { return *pStream; } 187 188 // Open a record of type "nType" 189 sal_Bool OpenRec( sal_uInt8 nType ); 190 191 // Close a record of type "nType". This skips any unread data that 192 // remains in the record. 193 sal_Bool CloseRec( sal_uInt8 nType ); 194 195 // Return the number of bytes contained in the current record that 196 // haven't been read by now. 197 sal_uInt32 BytesLeft(); 198 199 // Return the current record's type 200 sal_uInt8 Peek(); 201 202 // Skip the current record 203 void SkipRec(); 204 205 // Open a flag record for reading. The uppermost four bits are flags, 206 // while the lowermost are the flag record's size. Flag records cannot 207 // be nested. 208 sal_uInt8 OpenFlagRec(); 209 210 // Open flag record for writing; 211 void OpenFlagRec( sal_uInt8 nFlags, sal_uInt8 nLen ); 212 213 // Close a flag record. Any bytes left are skipped. 214 void CloseFlagRec(); 215 216 sal_Bool HasError() const { return bError; } 217 218 sal_uInt16 GetMajorVersion() const { return nMajorVersion; } 219 sal_uInt16 GetMinorVersion() const { return nMinorVersion; } 220 }; 221 222 // Stored information about text frames: 223 class SwFlyCache : public SwRect // position and size 224 { 225 public: 226 sal_uLong nOrdNum; // Id to recognize text frames 227 sal_uInt16 nPageNum; // page number 228 SwFlyCache( sal_uInt16 nP, sal_uLong nO, long nXL, long nYL, long nWL, long nHL ) : 229 SwRect( nXL, nYL, nWL, nHL ), nOrdNum( nO ), nPageNum( nP ){} 230 }; 231 232 #endif 233