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