update dev300-m58
[ooovba.git] / sw / source / core / layout / layhelp.hxx
blobd488cfdbf4e39dfdb7a9031b1461d3378561bd49
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: layhelp.hxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _LAYHELP_HXX
31 #define _LAYHELP_HXX
32 #ifndef _SVSTDARR_HXX
33 #define _SVSTDARR_USHORTS
34 #define _SVSTDARR_ULONGS
35 #define _SVSTDARR_BYTES
36 #define _SVSTDARR_XUB_STRLEN
37 #include <svtools/svstdarr.hxx>
38 #endif
39 #include <swrect.hxx>
41 class SwDoc;
42 class SwFrm;
43 class SwLayoutFrm;
44 class SwPageFrm;
45 class SwFlyFrm;
46 class SwSectionFrm;
47 class SwSectionNode;
48 class SvStream;
50 /*************************************************************************
51 * class SwLayCacheImpl
52 * contains the page break information and the text frame positions
53 * of the document (after loading)
54 * and is used inside the constructor of the layout rootframe to
55 * insert content and text frames at the right pages.
56 * For every page of the main text (body content, no footnotes, text frames etc.)
57 * we have the nodeindex of the first content at the page,
58 * the type of content ( table or paragraph )
59 * and if it's not the first part of the table/paragraph,
60 * the row/character-offset inside the table/paragraph.
61 * The text frame positions are stored in the SwPageFlyCache array.
62 *************************************************************************/
64 class SwFlyCache;
65 typedef SwFlyCache* SwFlyCachePtr;
66 SV_DECL_PTRARR_DEL( SwPageFlyCache, SwFlyCachePtr, 0, 4 )
68 class SwLayCacheImpl : public SvULongs
70 SvXub_StrLens aOffset;
71 SvUShorts aType;
72 SwPageFlyCache aFlyCache;
73 sal_Bool bUseFlyCache;
74 void Insert( USHORT nType, ULONG nIndex, xub_StrLen nOffset );
76 public:
77 SwLayCacheImpl() : SvULongs( 20, 10 ), aOffset( 20, 10 ), aType( 20, 10 ) {}
78 BOOL Read( SvStream& rStream );
80 ULONG GetBreakIndex( USHORT nIdx ) const { return GetObject( nIdx ); }
81 xub_StrLen GetBreakOfst( USHORT nIdx ) const { return aOffset[ nIdx ]; }
82 USHORT GetBreakType( USHORT nIdx ) const { return aType[ nIdx ]; }
84 USHORT GetFlyCount() const { return aFlyCache.Count(); }
85 SwFlyCache *GetFlyCache( USHORT nIdx ) const { return aFlyCache[ nIdx ]; }
87 sal_Bool IsUseFlyCache() const { return bUseFlyCache; }
90 /*************************************************************************
91 * class SwActualSection
92 * helps to create the sectionframes during the _InsertCnt-function
93 * by controlling nested sections.
94 *************************************************************************/
96 class SwActualSection
98 SwActualSection *pUpper;
99 SwSectionFrm *pSectFrm;
100 SwSectionNode *pSectNode;
101 public:
102 SwActualSection( SwActualSection *pUpper,
103 SwSectionFrm *pSect,
104 SwSectionNode *pNd );
106 SwSectionFrm *GetSectionFrm() { return pSectFrm; }
107 void SetSectionFrm( SwSectionFrm *p ) { pSectFrm = p; }
108 SwSectionNode *GetSectionNode() { return pSectNode;}
109 SwActualSection *GetUpper() { return pUpper; }
112 /*************************************************************************
113 * class SwLayHelper
114 * helps during the _InsertCnt-function to create new pages.
115 * If there's a layoutcache available, this information is used.
116 *************************************************************************/
118 class SwLayHelper
120 SwFrm* &rpFrm;
121 SwFrm* &rpPrv;
122 SwPageFrm* &rpPage;
123 SwLayoutFrm* &rpLay;
124 SwActualSection* &rpActualSection;
125 BOOL &rbBreakAfter;
126 SwDoc* pDoc;
127 SwLayCacheImpl* pImpl;
128 ULONG nMaxParaPerPage;
129 ULONG nParagraphCnt;
130 ULONG nStartOfContent;
131 USHORT nIndex; // the index in the page break array
132 USHORT nFlyIdx; // the index in the fly cache array
133 BOOL bFirst : 1;
134 void _CheckFlyCache( SwPageFrm* pPage );
135 public:
136 SwLayHelper( SwDoc *pD, SwFrm* &rpF, SwFrm* &rpP, SwPageFrm* &rpPg,
137 SwLayoutFrm* &rpL, SwActualSection* &rpA, BOOL &rBrk,
138 ULONG nNodeIndex, BOOL bCache );
139 ~SwLayHelper();
140 ULONG CalcPageCount();
141 BOOL CheckInsert( ULONG nNodeIndex );
143 BOOL BreakPage( xub_StrLen& rOffs, ULONG nNodeIndex );
144 BOOL CheckInsertPage();
146 // Look for fresh text frames at this (new) page and set them to the right
147 // position, if they are in the fly cache.
148 void CheckFlyCache( SwPageFrm* pPage )
149 { if( pImpl && nFlyIdx < pImpl->GetFlyCount() ) _CheckFlyCache( pPage ); }
151 // Look for this text frame and set it to the right position,
152 // if it's in the fly cache.
153 static BOOL CheckPageFlyCache( SwPageFrm* &rpPage, SwFlyFrm* pFly );
156 /*************************************************************************
157 * class SwLayCacheIoImpl
158 * contains the data structures that are required to read and write a
159 * layout cache.
160 *************************************************************************/
162 #define SW_LAYCACHE_IO_REC_PAGES 'p'
163 #define SW_LAYCACHE_IO_REC_PARA 'P'
164 #define SW_LAYCACHE_IO_REC_TABLE 'T'
165 #define SW_LAYCACHE_IO_REC_FLY 'F'
167 #define SW_LAYCACHE_IO_VERSION_MAJOR 1
168 #define SW_LAYCACHE_IO_VERSION_MINOR 1
170 class SwLayCacheIoImpl
172 SvBytes aRecTypes;
173 SvULongs aRecSizes;
175 SvStream *pStream;
177 ULONG nFlagRecEnd;
179 USHORT nMajorVersion;
180 USHORT nMinorVersion;
182 BOOL bWriteMode : 1;
183 BOOL bError : 1;
185 public:
186 SwLayCacheIoImpl( SvStream& rStrm, BOOL bWrtMd );
188 // Get input or output stream
189 SvStream& GetStream() const { return *pStream; }
191 // Open a record of type "nType"
192 BOOL OpenRec( BYTE nType );
194 // Close a record of type "nType". This skips any unread data that
195 // remains in the record.
196 BOOL CloseRec( BYTE nType );
198 // Return the number of bytes contained in the current record that
199 // haven't been read by now.
200 UINT32 BytesLeft();
202 // Return the current record's type
203 BYTE Peek();
205 // Skip the current record
206 void SkipRec();
208 // Open a flag record for reading. The uppermost four bits are flags,
209 // while the lowermost are the flag record's size. Flag records cannot
210 // be nested.
211 BYTE OpenFlagRec();
213 // Open flag record for writing;
214 void OpenFlagRec( BYTE nFlags, BYTE nLen );
216 // Close a flag record. Any bytes left are skipped.
217 void CloseFlagRec();
219 BOOL HasError() const { return bError; }
221 USHORT GetMajorVersion() const { return nMajorVersion; }
222 USHORT GetMinorVersion() const { return nMinorVersion; }
225 // Stored information about text frames:
226 class SwFlyCache : public SwRect // position and size
228 public:
229 ULONG nOrdNum; // Id to recognize text frames
230 USHORT nPageNum; // page number
231 SwFlyCache( USHORT nP, ULONG nO, long nXL, long nYL, long nWL, long nHL ) :
232 SwRect( nXL, nYL, nWL, nHL ), nOrdNum( nO ), nPageNum( nP ){}
235 #endif