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