xref: /trunk/main/sw/source/core/layout/laycache.cxx (revision 083d9fe7b3d2dda5c3695550b2c36f86003acbfa)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_sw.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <hintids.hxx>
26cdf0e10cSrcweir #include <editeng/brkitem.hxx>
27cdf0e10cSrcweir #include <tools/stream.hxx>
28cdf0e10cSrcweir #include <doc.hxx>
29cdf0e10cSrcweir #include <docstat.hxx>
30cdf0e10cSrcweir #include <docary.hxx>
31cdf0e10cSrcweir #include <fmtpdsc.hxx>
32cdf0e10cSrcweir #include <laycache.hxx>
33cdf0e10cSrcweir #include <layhelp.hxx>
34cdf0e10cSrcweir #include <pagefrm.hxx>
35cdf0e10cSrcweir #include <rootfrm.hxx>
36cdf0e10cSrcweir #include <txtfrm.hxx>
37cdf0e10cSrcweir #include <ndtxt.hxx>
38cdf0e10cSrcweir #include <swtable.hxx>
39cdf0e10cSrcweir #include <tabfrm.hxx>
40cdf0e10cSrcweir #include <rowfrm.hxx>
41cdf0e10cSrcweir #include <colfrm.hxx>
42cdf0e10cSrcweir #include <bodyfrm.hxx>
43cdf0e10cSrcweir #include <ndindex.hxx>
44cdf0e10cSrcweir #include <sectfrm.hxx>
45cdf0e10cSrcweir #include <frmfmt.hxx>
46cdf0e10cSrcweir #include <fmtcntnt.hxx>
47cdf0e10cSrcweir #include <pagedesc.hxx>
48cdf0e10cSrcweir #include <frmtool.hxx>
49cdf0e10cSrcweir #include <dflyobj.hxx>
50cdf0e10cSrcweir #include <dcontact.hxx>
51cdf0e10cSrcweir #include "viewopt.hxx"
52cdf0e10cSrcweir #include "viewsh.hxx"
53cdf0e10cSrcweir #include <flyfrm.hxx>
54cdf0e10cSrcweir // OD 2004-05-24 #i28701#
55cdf0e10cSrcweir #include <sortedobjs.hxx>
56cdf0e10cSrcweir // --> OD 2006-03-22 #b6375613#
57cdf0e10cSrcweir #include <pam.hxx>
58cdf0e10cSrcweir #include <docsh.hxx>
59cdf0e10cSrcweir #include <com/sun/star/document/XDocumentInfoSupplier.hpp>
60cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
61cdf0e10cSrcweir 
62cdf0e10cSrcweir #include <set>
63cdf0e10cSrcweir 
64cdf0e10cSrcweir using namespace ::com::sun::star;
65cdf0e10cSrcweir // <--
66cdf0e10cSrcweir 
SV_IMPL_PTRARR(SwPageFlyCache,SwFlyCachePtr)67cdf0e10cSrcweir SV_IMPL_PTRARR( SwPageFlyCache, SwFlyCachePtr )
68cdf0e10cSrcweir 
69cdf0e10cSrcweir /*-----------------28.5.2001 10:06------------------
70cdf0e10cSrcweir  *  Reading and writing of the layout cache.
71cdf0e10cSrcweir  *  The layout cache is not necessary, but it improves
72cdf0e10cSrcweir  *  the performance and reduces the text flow during
73cdf0e10cSrcweir  *  the formatting.
74cdf0e10cSrcweir  *  The layout cache contains the index of the paragraphs/tables
75cdf0e10cSrcweir  *  at the top of every page, so it's possible to create
76cdf0e10cSrcweir  *  the right count of pages and to distribute the document content
77cdf0e10cSrcweir  *  to this pages before the formatting starts.
78cdf0e10cSrcweir  *--------------------------------------------------*/
79cdf0e10cSrcweir 
80cdf0e10cSrcweir void SwLayoutCache::Read( SvStream &rStream )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir     if( !pImpl )
83cdf0e10cSrcweir     {
84cdf0e10cSrcweir         pImpl = new SwLayCacheImpl;
85cdf0e10cSrcweir         if( !pImpl->Read( rStream ) )
86cdf0e10cSrcweir         {
87cdf0e10cSrcweir             delete pImpl;
88cdf0e10cSrcweir             pImpl = 0;
89cdf0e10cSrcweir         }
90cdf0e10cSrcweir     }
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir //-----------------------------------------------------------------------------
94cdf0e10cSrcweir 
Insert(sal_uInt16 nType,sal_uLong nIndex,xub_StrLen nOffset)95cdf0e10cSrcweir void SwLayCacheImpl::Insert( sal_uInt16 nType, sal_uLong nIndex, xub_StrLen nOffset )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir     aType.Insert( nType, aType.Count() );
98cdf0e10cSrcweir     SvULongs::Insert( nIndex, SvULongs::Count() );
99cdf0e10cSrcweir     aOffset.push_back( nOffset );
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
Read(SvStream & rStream)102cdf0e10cSrcweir sal_Bool SwLayCacheImpl::Read( SvStream& rStream )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     SwLayCacheIoImpl aIo( rStream, sal_False );
105cdf0e10cSrcweir     if( aIo.GetMajorVersion() > SW_LAYCACHE_IO_VERSION_MAJOR )
106cdf0e10cSrcweir         return sal_False;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     // Due to an evil bug in the layout cache (#102759#), we cannot trust the
109cdf0e10cSrcweir     // sizes of fly frames which have been written using the "old" layout cache.
110cdf0e10cSrcweir     // This flag should indicate that we do not want to trust the width and
111cdf0e10cSrcweir     // height of fly frames
112cdf0e10cSrcweir     bUseFlyCache = aIo.GetMinorVersion() >= 1;
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     sal_uInt8 cFlags;
115cdf0e10cSrcweir     sal_uInt32 nIndex, nOffset;
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     aIo.OpenRec( SW_LAYCACHE_IO_REC_PAGES );
118cdf0e10cSrcweir     aIo.OpenFlagRec();
119cdf0e10cSrcweir     aIo.CloseFlagRec();
120cdf0e10cSrcweir     while( aIo.BytesLeft() && !aIo.HasError() )
121cdf0e10cSrcweir     {
122cdf0e10cSrcweir         switch( aIo.Peek() )
123cdf0e10cSrcweir         {
124cdf0e10cSrcweir         case SW_LAYCACHE_IO_REC_PARA:
125cdf0e10cSrcweir             aIo.OpenRec( SW_LAYCACHE_IO_REC_PARA );
126cdf0e10cSrcweir             cFlags = aIo.OpenFlagRec();
127cdf0e10cSrcweir             aIo.GetStream() >> nIndex;
128cdf0e10cSrcweir             if( (cFlags & 0x01) != 0 )
129cdf0e10cSrcweir                 aIo.GetStream() >> nOffset;
130cdf0e10cSrcweir             else
131cdf0e10cSrcweir                 nOffset = STRING_LEN;
132cdf0e10cSrcweir             aIo.CloseFlagRec();
133cdf0e10cSrcweir             Insert( SW_LAYCACHE_IO_REC_PARA, nIndex, (xub_StrLen)nOffset );
134cdf0e10cSrcweir             aIo.CloseRec( SW_LAYCACHE_IO_REC_PARA );
135cdf0e10cSrcweir             break;
136cdf0e10cSrcweir         case SW_LAYCACHE_IO_REC_TABLE:
137cdf0e10cSrcweir             aIo.OpenRec( SW_LAYCACHE_IO_REC_TABLE );
138cdf0e10cSrcweir             aIo.OpenFlagRec();
139cdf0e10cSrcweir             aIo.GetStream() >> nIndex
140cdf0e10cSrcweir                             >> nOffset;
141cdf0e10cSrcweir             Insert( SW_LAYCACHE_IO_REC_TABLE, nIndex, (xub_StrLen)nOffset );
142cdf0e10cSrcweir             aIo.CloseFlagRec();
143cdf0e10cSrcweir             aIo.CloseRec( SW_LAYCACHE_IO_REC_TABLE );
144cdf0e10cSrcweir             break;
145cdf0e10cSrcweir         case SW_LAYCACHE_IO_REC_FLY:
146cdf0e10cSrcweir         {
147cdf0e10cSrcweir             aIo.OpenRec( SW_LAYCACHE_IO_REC_FLY );
148cdf0e10cSrcweir             aIo.OpenFlagRec();
149cdf0e10cSrcweir             aIo.CloseFlagRec();
150cdf0e10cSrcweir             long nX, nY, nW, nH;
151cdf0e10cSrcweir             sal_uInt16 nPgNum;
152cdf0e10cSrcweir             aIo.GetStream() >> nPgNum >> nIndex
153cdf0e10cSrcweir                     >> nX >> nY >> nW >> nH;
154cdf0e10cSrcweir             SwFlyCache* pFly = new SwFlyCache( nPgNum, nIndex, nX, nY, nW, nH );
155cdf0e10cSrcweir             aFlyCache.Insert( pFly, aFlyCache.Count() );
156cdf0e10cSrcweir             aIo.CloseRec( SW_LAYCACHE_IO_REC_FLY );
157cdf0e10cSrcweir             break;
158cdf0e10cSrcweir         }
159cdf0e10cSrcweir         default:
160cdf0e10cSrcweir             aIo.SkipRec();
161cdf0e10cSrcweir             break;
162cdf0e10cSrcweir         }
163cdf0e10cSrcweir     }
164cdf0e10cSrcweir     aIo.CloseRec( SW_LAYCACHE_IO_REC_PAGES );
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     return !aIo.HasError();
167cdf0e10cSrcweir }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir /*-----------------28.5.2001 10:19------------------
170cdf0e10cSrcweir  * SwLayoutCache::Write(..)
171cdf0e10cSrcweir  * writes the index (more precise: the difference between
172cdf0e10cSrcweir  * the index and the first index of the document content)
173cdf0e10cSrcweir  * of the first paragraph/table at the top of every page.
174cdf0e10cSrcweir  * If at the top of a page is the rest of a paragraph/table
175cdf0e10cSrcweir  * from the bottom of the previous page, the character/row
176cdf0e10cSrcweir  * number is stored, too.
177cdf0e10cSrcweir  * The position, size and page number of the text frames
178cdf0e10cSrcweir  * are stored, too
179cdf0e10cSrcweir  * --------------------------------------------------*/
180cdf0e10cSrcweir 
Write(SvStream & rStream,const SwDoc & rDoc)181cdf0e10cSrcweir void SwLayoutCache::Write( SvStream &rStream, const SwDoc& rDoc )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir     if( rDoc.GetCurrentLayout() ) // the layout itself ..   //swmod 080218
184cdf0e10cSrcweir     {
185cdf0e10cSrcweir         SwLayCacheIoImpl aIo( rStream, sal_True );
186cdf0e10cSrcweir         // We want to save the relative index, so we need the index
187cdf0e10cSrcweir         // of the first content
188cdf0e10cSrcweir         sal_uLong nStartOfContent = rDoc.GetNodes().GetEndOfContent().
189cdf0e10cSrcweir                                 StartOfSectionNode()->GetIndex();
190cdf0e10cSrcweir         // The first page..
191cdf0e10cSrcweir         SwPageFrm* pPage = (SwPageFrm*)rDoc.GetCurrentLayout()->Lower();    //swmod 080218
192cdf0e10cSrcweir 
193cdf0e10cSrcweir         aIo.OpenRec( SW_LAYCACHE_IO_REC_PAGES );
194cdf0e10cSrcweir         aIo.OpenFlagRec( 0, 0 );
195cdf0e10cSrcweir         aIo.CloseFlagRec();
196cdf0e10cSrcweir         while( pPage )
197cdf0e10cSrcweir         {
198cdf0e10cSrcweir             if( pPage->GetPrev() )
199cdf0e10cSrcweir             {
200cdf0e10cSrcweir                 SwLayoutFrm* pLay = pPage->FindBodyCont();
201cdf0e10cSrcweir                 SwFrm* pTmp = pLay ? pLay->ContainsAny() : NULL;
202cdf0e10cSrcweir                 // We are only interested in paragraph or table frames,
203cdf0e10cSrcweir                 // a section frames contains paragraphs/tables.
204cdf0e10cSrcweir                 if( pTmp && pTmp->IsSctFrm() )
205cdf0e10cSrcweir                     pTmp = ((SwSectionFrm*)pTmp)->ContainsAny();
206cdf0e10cSrcweir 
207cdf0e10cSrcweir                 if( pTmp ) // any content
208cdf0e10cSrcweir                 {
209cdf0e10cSrcweir                     if( pTmp->IsTxtFrm() )
210cdf0e10cSrcweir                     {
211cdf0e10cSrcweir                         sal_uLong nNdIdx = ((SwTxtFrm*)pTmp)->GetNode()->GetIndex();
212cdf0e10cSrcweir                         if( nNdIdx > nStartOfContent )
213cdf0e10cSrcweir                         {
214cdf0e10cSrcweir                             /*  Open Paragraph Record */
215cdf0e10cSrcweir                             aIo.OpenRec( SW_LAYCACHE_IO_REC_PARA );
216cdf0e10cSrcweir                             sal_Bool bFollow = ((SwTxtFrm*)pTmp)->IsFollow();
217cdf0e10cSrcweir                             aIo.OpenFlagRec( bFollow ? 0x01 : 0x00,
218cdf0e10cSrcweir                                             bFollow ? 8 : 4 );
219cdf0e10cSrcweir                             nNdIdx -= nStartOfContent;
220cdf0e10cSrcweir                             aIo.GetStream() << static_cast<sal_uInt32>(nNdIdx);
221cdf0e10cSrcweir                             if( bFollow )
222cdf0e10cSrcweir                                 aIo.GetStream() << static_cast<sal_uInt32>(((SwTxtFrm*)pTmp)->GetOfst());
223cdf0e10cSrcweir                             aIo.CloseFlagRec();
224cdf0e10cSrcweir                             /*  Close Paragraph Record */
225cdf0e10cSrcweir                             aIo.CloseRec( SW_LAYCACHE_IO_REC_PARA );
226cdf0e10cSrcweir                         }
227cdf0e10cSrcweir                     }
228cdf0e10cSrcweir                     else if( pTmp->IsTabFrm() )
229cdf0e10cSrcweir                     {
230cdf0e10cSrcweir                         SwTabFrm* pTab = (SwTabFrm*)pTmp;
231cdf0e10cSrcweir                         sal_uLong nOfst = STRING_LEN;
232cdf0e10cSrcweir                         if( pTab->IsFollow() )
233cdf0e10cSrcweir                         {
234cdf0e10cSrcweir                             // If the table is a follow, we have to look for the
235cdf0e10cSrcweir                             // master and to count all rows to get the row number
236cdf0e10cSrcweir                             nOfst = 0;
237cdf0e10cSrcweir                             if( pTab->IsFollow() )
238cdf0e10cSrcweir                                 pTab = pTab->FindMaster( true );
239cdf0e10cSrcweir                             while( pTab != pTmp )
240cdf0e10cSrcweir                             {
241cdf0e10cSrcweir                                 SwFrm* pSub = pTab->Lower();
242cdf0e10cSrcweir                                 while( pSub )
243cdf0e10cSrcweir                                 {
244cdf0e10cSrcweir                                     ++nOfst;
245cdf0e10cSrcweir                                     pSub = pSub->GetNext();
246cdf0e10cSrcweir                                 }
247cdf0e10cSrcweir                                 pTab = pTab->GetFollow();
248cdf0e10cSrcweir                                 ASSERT( pTab, "Table follow without master" );
249cdf0e10cSrcweir                             }
250cdf0e10cSrcweir                         }
251cdf0e10cSrcweir                         do
252cdf0e10cSrcweir                         {
253cdf0e10cSrcweir                             sal_uLong nNdIdx =
254cdf0e10cSrcweir                                     pTab->GetTable()->GetTableNode()->GetIndex();
255cdf0e10cSrcweir                             if( nNdIdx > nStartOfContent )
256cdf0e10cSrcweir                             {
257cdf0e10cSrcweir                                 /* Open Table Record */
258cdf0e10cSrcweir                                 aIo.OpenRec( SW_LAYCACHE_IO_REC_TABLE );
259cdf0e10cSrcweir                                 aIo.OpenFlagRec( 0, 8 );
260cdf0e10cSrcweir                                 nNdIdx -= nStartOfContent;
261cdf0e10cSrcweir                                 aIo.GetStream() << static_cast<sal_uInt32>(nNdIdx)
262cdf0e10cSrcweir                                                 << static_cast<sal_uInt32>(nOfst);
263cdf0e10cSrcweir                                 aIo.CloseFlagRec();
264cdf0e10cSrcweir                                 /* Close Table Record  */
265cdf0e10cSrcweir                                 aIo.CloseRec( SW_LAYCACHE_IO_REC_TABLE );
266cdf0e10cSrcweir                             }
267cdf0e10cSrcweir                             // If the table has a follow on the next page,
268cdf0e10cSrcweir                             // we know already the row number and store this
269cdf0e10cSrcweir                             // immediately.
270cdf0e10cSrcweir                             if( pTab->GetFollow() )
271cdf0e10cSrcweir                             {
272cdf0e10cSrcweir                                 if( nOfst == STRING_LEN )
273cdf0e10cSrcweir                                     nOfst = 0;
274cdf0e10cSrcweir                                 do
275cdf0e10cSrcweir                                 {
276cdf0e10cSrcweir                                     SwFrm* pSub = pTab->Lower();
277cdf0e10cSrcweir                                     while( pSub )
278cdf0e10cSrcweir                                     {
279cdf0e10cSrcweir                                         ++nOfst;
280cdf0e10cSrcweir                                         pSub = pSub->GetNext();
281cdf0e10cSrcweir                                     }
282cdf0e10cSrcweir                                     pTab = pTab->GetFollow();
283cdf0e10cSrcweir                                     SwPageFrm *pTabPage = pTab->FindPageFrm();
284cdf0e10cSrcweir                                     if( pTabPage != pPage )
285cdf0e10cSrcweir                                     {
286cdf0e10cSrcweir                                         ASSERT( pPage->GetPhyPageNum() <
287cdf0e10cSrcweir                                                 pTabPage->GetPhyPageNum(),
288cdf0e10cSrcweir                                                 "Looping Tableframes" );
289cdf0e10cSrcweir                                         pPage = pTabPage;
290cdf0e10cSrcweir                                         break;
291cdf0e10cSrcweir                                     }
292cdf0e10cSrcweir                                 } while ( pTab->GetFollow() );
293cdf0e10cSrcweir                             }
294cdf0e10cSrcweir                             else
295cdf0e10cSrcweir                                 break;
296cdf0e10cSrcweir                         } while( pTab );
297cdf0e10cSrcweir                     }
298cdf0e10cSrcweir                 }
299cdf0e10cSrcweir             }
300cdf0e10cSrcweir             if( pPage->GetSortedObjs() )
301cdf0e10cSrcweir             {
302cdf0e10cSrcweir                 SwSortedObjs &rObjs = *pPage->GetSortedObjs();
303cdf0e10cSrcweir                 for ( sal_uInt16 i = 0; i < rObjs.Count(); ++i )
304cdf0e10cSrcweir                 {
305cdf0e10cSrcweir                     SwAnchoredObject* pAnchoredObj = rObjs[i];
306cdf0e10cSrcweir                     if ( pAnchoredObj->ISA(SwFlyFrm) )
307cdf0e10cSrcweir                     {
308cdf0e10cSrcweir                         SwFlyFrm *pFly = static_cast<SwFlyFrm*>(pAnchoredObj);
309cdf0e10cSrcweir                         if( pFly->Frm().Left() != WEIT_WECH &&
310cdf0e10cSrcweir                             !pFly->GetAnchorFrm()->FindFooterOrHeader() )
311cdf0e10cSrcweir                         {
312cdf0e10cSrcweir                             const SwContact *pC =
313cdf0e10cSrcweir                                     ::GetUserCall(pAnchoredObj->GetDrawObj());
314cdf0e10cSrcweir                             if( pC )
315cdf0e10cSrcweir                             {
316cdf0e10cSrcweir                                 sal_uInt32 nOrdNum = pAnchoredObj->GetDrawObj()->GetOrdNum();
317cdf0e10cSrcweir                                 sal_uInt16 nPageNum = pPage->GetPhyPageNum();
318cdf0e10cSrcweir                                 /* Open Fly Record */
319cdf0e10cSrcweir                                 aIo.OpenRec( SW_LAYCACHE_IO_REC_FLY );
320cdf0e10cSrcweir                                 aIo.OpenFlagRec( 0, 0 );
321cdf0e10cSrcweir                                 aIo.CloseFlagRec();
322cdf0e10cSrcweir                                 SwRect &rRct = pFly->Frm();
323cdf0e10cSrcweir                                 sal_Int32 nX = rRct.Left() - pPage->Frm().Left();
324cdf0e10cSrcweir                                 sal_Int32 nY = rRct.Top() - pPage->Frm().Top();
325cdf0e10cSrcweir                                 aIo.GetStream() << nPageNum << nOrdNum
326cdf0e10cSrcweir                                                 << nX << nY << rRct.Width()
327cdf0e10cSrcweir                                                 << rRct.Height();
328cdf0e10cSrcweir                                 /* Close Fly Record  */
329cdf0e10cSrcweir                                 aIo.CloseRec( SW_LAYCACHE_IO_REC_FLY );
330cdf0e10cSrcweir                             }
331cdf0e10cSrcweir                         }
332cdf0e10cSrcweir                     }
333cdf0e10cSrcweir                 }
334cdf0e10cSrcweir             }
335cdf0e10cSrcweir             pPage = (SwPageFrm*)pPage->GetNext();
336cdf0e10cSrcweir         }
337cdf0e10cSrcweir         aIo.CloseRec( SW_LAYCACHE_IO_REC_PAGES );
338cdf0e10cSrcweir     }
339cdf0e10cSrcweir }
340cdf0e10cSrcweir 
341cdf0e10cSrcweir #ifdef DBG_UTIL
CompareLayout(const SwDoc & rDoc) const342cdf0e10cSrcweir sal_Bool SwLayoutCache::CompareLayout( const SwDoc& rDoc ) const
343cdf0e10cSrcweir {
344cdf0e10cSrcweir     if( !pImpl )
345cdf0e10cSrcweir         return sal_True;
346cdf0e10cSrcweir     const SwRootFrm *pRootFrm = rDoc.GetCurrentLayout();
347cdf0e10cSrcweir     sal_Bool bRet = sal_True;
348cdf0e10cSrcweir     if( pRootFrm )
349cdf0e10cSrcweir     {
350cdf0e10cSrcweir         sal_uInt16 nIndex = 0;
351cdf0e10cSrcweir         sal_uLong nStartOfContent = rDoc.GetNodes().GetEndOfContent().
352cdf0e10cSrcweir                                 StartOfSectionNode()->GetIndex();
353cdf0e10cSrcweir         SwPageFrm* pPage = (SwPageFrm*)pRootFrm->Lower();
354cdf0e10cSrcweir         if( pPage )
355cdf0e10cSrcweir             pPage = (SwPageFrm*)pPage->GetNext();
356cdf0e10cSrcweir         while( pPage )
357cdf0e10cSrcweir         {
358cdf0e10cSrcweir             if( nIndex >= pImpl->Count() )
359cdf0e10cSrcweir             {
360cdf0e10cSrcweir                 if( bRet )
361cdf0e10cSrcweir                     bRet = sal_False;
362cdf0e10cSrcweir                 break;
363cdf0e10cSrcweir             }
364cdf0e10cSrcweir             SwLayoutFrm* pLay = pPage->FindBodyCont();
365cdf0e10cSrcweir             SwFrm* pTmp = pLay ? pLay->ContainsAny() : NULL;
366cdf0e10cSrcweir             if( pTmp && pTmp->IsSctFrm() )
367cdf0e10cSrcweir                 pTmp = ((SwSectionFrm*)pTmp)->ContainsAny();
368cdf0e10cSrcweir             if( pTmp )
369cdf0e10cSrcweir             {
370cdf0e10cSrcweir                 if( pTmp->IsTxtFrm() )
371cdf0e10cSrcweir                 {
372cdf0e10cSrcweir                     sal_uLong nNdIdx = ((SwTxtFrm*)pTmp)->GetNode()->GetIndex();
373cdf0e10cSrcweir                     if( nNdIdx > nStartOfContent )
374cdf0e10cSrcweir                     {
375cdf0e10cSrcweir                         sal_Bool bFollow = ((SwTxtFrm*)pTmp)->IsFollow();
376cdf0e10cSrcweir                         nNdIdx -= nStartOfContent;
377cdf0e10cSrcweir                         if( pImpl->GetBreakIndex( nIndex ) != nNdIdx ||
378cdf0e10cSrcweir                             SW_LAYCACHE_IO_REC_PARA !=
379cdf0e10cSrcweir                             pImpl->GetBreakType( nIndex ) ||
380cdf0e10cSrcweir                             ( bFollow ? ((SwTxtFrm*)pTmp)->GetOfst()
381cdf0e10cSrcweir                               : STRING_LEN ) != pImpl->GetBreakOfst( nIndex ) )
382cdf0e10cSrcweir                         {
383cdf0e10cSrcweir                             if( bRet )
384cdf0e10cSrcweir                                 bRet = sal_False;
385cdf0e10cSrcweir                         }
386cdf0e10cSrcweir                         ++nIndex;
387cdf0e10cSrcweir                     }
388cdf0e10cSrcweir                 }
389cdf0e10cSrcweir                 else if( pTmp->IsTabFrm() )
390cdf0e10cSrcweir                 {
391cdf0e10cSrcweir                     SwTabFrm* pTab = (SwTabFrm*)pTmp;
392cdf0e10cSrcweir                     sal_uLong nOfst = STRING_LEN;
393cdf0e10cSrcweir                     if( pTab->IsFollow() )
394cdf0e10cSrcweir                     {
395cdf0e10cSrcweir                         nOfst = 0;
396cdf0e10cSrcweir                         if( pTab->IsFollow() )
397cdf0e10cSrcweir                             pTab = pTab->FindMaster( true );
398cdf0e10cSrcweir                         while( pTab != pTmp )
399cdf0e10cSrcweir                         {
400cdf0e10cSrcweir                             SwFrm* pSub = pTab->Lower();
401cdf0e10cSrcweir                             while( pSub )
402cdf0e10cSrcweir                             {
403cdf0e10cSrcweir                                 ++nOfst;
404cdf0e10cSrcweir                                 pSub = pSub->GetNext();
405cdf0e10cSrcweir                             }
406cdf0e10cSrcweir                             pTab = pTab->GetFollow();
407cdf0e10cSrcweir                         }
408cdf0e10cSrcweir                     }
409cdf0e10cSrcweir                     do
410cdf0e10cSrcweir                     {
411cdf0e10cSrcweir                         sal_uLong nNdIdx =
412cdf0e10cSrcweir                                 pTab->GetTable()->GetTableNode()->GetIndex();
413cdf0e10cSrcweir                         if( nNdIdx > nStartOfContent )
414cdf0e10cSrcweir                         {
415cdf0e10cSrcweir                             nNdIdx -= nStartOfContent;
416cdf0e10cSrcweir                             if( pImpl->GetBreakIndex( nIndex ) != nNdIdx ||
417cdf0e10cSrcweir                                 SW_LAYCACHE_IO_REC_TABLE !=
418cdf0e10cSrcweir                                 pImpl->GetBreakType( nIndex ) ||
419cdf0e10cSrcweir                                nOfst != pImpl->GetBreakOfst( nIndex ) )
420cdf0e10cSrcweir                             {
421cdf0e10cSrcweir                                 if( bRet )
422cdf0e10cSrcweir                                     bRet = sal_False;
423cdf0e10cSrcweir                             }
424cdf0e10cSrcweir                             ++nIndex;
425cdf0e10cSrcweir                         }
426cdf0e10cSrcweir                         if( pTab->GetFollow() )
427cdf0e10cSrcweir                         {
428cdf0e10cSrcweir                             if( nOfst == STRING_LEN )
429cdf0e10cSrcweir                                 nOfst = 0;
430cdf0e10cSrcweir                             do
431cdf0e10cSrcweir                             {
432cdf0e10cSrcweir                                 SwFrm* pSub = pTab->Lower();
433cdf0e10cSrcweir                                 while( pSub )
434cdf0e10cSrcweir                                 {
435cdf0e10cSrcweir                                     ++nOfst;
436cdf0e10cSrcweir                                     pSub = pSub->GetNext();
437cdf0e10cSrcweir                                 }
438cdf0e10cSrcweir                                 pTab = pTab->GetFollow();
439cdf0e10cSrcweir                                 SwPageFrm *pTabPage = pTab->FindPageFrm();
440cdf0e10cSrcweir                                 if( pTabPage != pPage )
441cdf0e10cSrcweir                                 {
442cdf0e10cSrcweir                                     pPage = pTabPage;
443cdf0e10cSrcweir                                     break;
444cdf0e10cSrcweir                                 }
445cdf0e10cSrcweir                             } while ( pTab->GetFollow() );
446cdf0e10cSrcweir                         }
447cdf0e10cSrcweir                         else
448cdf0e10cSrcweir                             break;
449cdf0e10cSrcweir                     } while( pTab );
450cdf0e10cSrcweir                 }
451cdf0e10cSrcweir             }
452cdf0e10cSrcweir             pPage = (SwPageFrm*)pPage->GetNext();
453cdf0e10cSrcweir         }
454cdf0e10cSrcweir     }
455cdf0e10cSrcweir     return bRet;
456cdf0e10cSrcweir }
457cdf0e10cSrcweir #endif
458cdf0e10cSrcweir 
ClearImpl()459cdf0e10cSrcweir void SwLayoutCache::ClearImpl()
460cdf0e10cSrcweir {
461cdf0e10cSrcweir     if( !IsLocked() )
462cdf0e10cSrcweir     {
463cdf0e10cSrcweir         delete pImpl;
464cdf0e10cSrcweir         pImpl = 0;
465cdf0e10cSrcweir     }
466cdf0e10cSrcweir }
467cdf0e10cSrcweir 
468cdf0e10cSrcweir 
~SwLayoutCache()469cdf0e10cSrcweir SwLayoutCache::~SwLayoutCache()
470cdf0e10cSrcweir {
471cdf0e10cSrcweir     ASSERT( !nLockCount, "Deleting a locked SwLayoutCache!?" );
472cdf0e10cSrcweir     delete pImpl;
473cdf0e10cSrcweir }
474cdf0e10cSrcweir 
475cdf0e10cSrcweir /*-----------------28.5.2001 10:47------------------
476cdf0e10cSrcweir  * SwActualSection,
477cdf0e10cSrcweir  *  a help class to create not nested section frames
478cdf0e10cSrcweir  *  for nested sections.
479cdf0e10cSrcweir  * --------------------------------------------------*/
480cdf0e10cSrcweir 
SwActualSection(SwActualSection * pUp,SwSectionFrm * pSect,SwSectionNode * pNd)481cdf0e10cSrcweir SwActualSection::SwActualSection( SwActualSection *pUp,
482cdf0e10cSrcweir                                   SwSectionFrm    *pSect,
483cdf0e10cSrcweir                                   SwSectionNode   *pNd ) :
484cdf0e10cSrcweir     pUpper( pUp ),
485cdf0e10cSrcweir     pSectFrm( pSect ),
486cdf0e10cSrcweir     pSectNode( pNd )
487cdf0e10cSrcweir {
488cdf0e10cSrcweir     if ( !pSectNode )
489cdf0e10cSrcweir     {
490cdf0e10cSrcweir         const SwNodeIndex *pIndex = pSect->GetFmt()->GetCntnt().GetCntntIdx();
491cdf0e10cSrcweir         pSectNode = pIndex->GetNode().FindSectionNode();
492cdf0e10cSrcweir     }
493cdf0e10cSrcweir }
494cdf0e10cSrcweir 
495cdf0e10cSrcweir /*-----------------28.5.2001 11:09------------------
496cdf0e10cSrcweir  * SwLayHelper
497cdf0e10cSrcweir  *  is the helper class, which utilizes the layout cache information
498*083d9fe7Smseidel  *  to distribute the document content to the right pages.
499cdf0e10cSrcweir  * It's used by the _InsertCnt(..)-function.
500531ea755SJohn Bampton  * If there's no layout cache, the distribution to the pages is more
501cdf0e10cSrcweir  * a guess, but a guess with statistical background.
502cdf0e10cSrcweir  * --------------------------------------------------*/
503cdf0e10cSrcweir 
SwLayHelper(SwDoc * pD,SwFrm * & rpF,SwFrm * & rpP,SwPageFrm * & rpPg,SwLayoutFrm * & rpL,SwActualSection * & rpA,sal_Bool & rB,sal_uLong nNodeIndex,sal_Bool bCache)504cdf0e10cSrcweir SwLayHelper::SwLayHelper( SwDoc *pD, SwFrm* &rpF, SwFrm* &rpP, SwPageFrm* &rpPg,
505cdf0e10cSrcweir             SwLayoutFrm* &rpL, SwActualSection* &rpA, sal_Bool &rB,
506cdf0e10cSrcweir             sal_uLong nNodeIndex, sal_Bool bCache )
507cdf0e10cSrcweir     : rpFrm( rpF ), rpPrv( rpP ), rpPage( rpPg ), rpLay( rpL ),
508cdf0e10cSrcweir       rpActualSection( rpA ), rbBreakAfter(rB), pDoc(pD), nMaxParaPerPage( 25 ),
509cdf0e10cSrcweir       nParagraphCnt( bCache ? 0 : USHRT_MAX ), bFirst( bCache )
510cdf0e10cSrcweir {
511cdf0e10cSrcweir     pImpl = pDoc->GetLayoutCache() ? pDoc->GetLayoutCache()->LockImpl() : NULL;
512cdf0e10cSrcweir     if( pImpl )
513cdf0e10cSrcweir     {
514cdf0e10cSrcweir         nMaxParaPerPage = 1000;
515cdf0e10cSrcweir         nStartOfContent = pDoc->GetNodes().GetEndOfContent().StartOfSectionNode()
516cdf0e10cSrcweir                           ->GetIndex();
517cdf0e10cSrcweir         nNodeIndex -= nStartOfContent;
518cdf0e10cSrcweir         nIndex = 0;
519cdf0e10cSrcweir         nFlyIdx = 0;
520cdf0e10cSrcweir         while( nIndex < pImpl->Count() && (*pImpl)[ nIndex ] < nNodeIndex )
521cdf0e10cSrcweir             ++nIndex;
522cdf0e10cSrcweir         if( nIndex >= pImpl->Count() )
523cdf0e10cSrcweir         {
524cdf0e10cSrcweir             pDoc->GetLayoutCache()->UnlockImpl();
525cdf0e10cSrcweir             pImpl = NULL;
526cdf0e10cSrcweir         }
527cdf0e10cSrcweir     }
528cdf0e10cSrcweir     else
529cdf0e10cSrcweir     {
530cdf0e10cSrcweir         nIndex = USHRT_MAX;
531cdf0e10cSrcweir         nStartOfContent = ULONG_MAX;
532cdf0e10cSrcweir     }
533cdf0e10cSrcweir }
534cdf0e10cSrcweir 
~SwLayHelper()535cdf0e10cSrcweir SwLayHelper::~SwLayHelper()
536cdf0e10cSrcweir {
537cdf0e10cSrcweir     if( pImpl )
538cdf0e10cSrcweir     {
539cdf0e10cSrcweir         ASSERT( pDoc && pDoc->GetLayoutCache(), "Missing layoutcache" );
540cdf0e10cSrcweir         pDoc->GetLayoutCache()->UnlockImpl();
541cdf0e10cSrcweir     }
542cdf0e10cSrcweir }
543cdf0e10cSrcweir 
544cdf0e10cSrcweir /*-----------------23.5.2001 16:40------------------
545cdf0e10cSrcweir  * SwLayHelper::CalcPageCount() does not really calculate the page count,
546cdf0e10cSrcweir  * it returns the page count value from the layout cache, if available,
547cdf0e10cSrcweir  * otherwise it estimates the page count.
548cdf0e10cSrcweir  * --------------------------------------------------*/
549cdf0e10cSrcweir 
CalcPageCount()550cdf0e10cSrcweir sal_uLong SwLayHelper::CalcPageCount()
551cdf0e10cSrcweir {
552cdf0e10cSrcweir     sal_uLong nPgCount;
553cdf0e10cSrcweir     SwLayCacheImpl *pCache = pDoc->GetLayoutCache() ?
554cdf0e10cSrcweir                              pDoc->GetLayoutCache()->LockImpl() : NULL;
555cdf0e10cSrcweir     if( pCache )
556cdf0e10cSrcweir     {
557cdf0e10cSrcweir         nPgCount = pCache->Count() + 1;
558cdf0e10cSrcweir         pDoc->GetLayoutCache()->UnlockImpl();
559cdf0e10cSrcweir     }
560cdf0e10cSrcweir     else
561cdf0e10cSrcweir     {
562cdf0e10cSrcweir         nPgCount = pDoc->GetDocStat().nPage;
563cdf0e10cSrcweir         if ( nPgCount <= 10 ) // no page insertion for less than 10 pages
564cdf0e10cSrcweir             nPgCount = 0;
565cdf0e10cSrcweir         sal_uLong nNdCount = pDoc->GetDocStat().nPara;
566cdf0e10cSrcweir         if ( nNdCount <= 1 )
567cdf0e10cSrcweir         {
568cdf0e10cSrcweir             //Estimates the number of paragraphs.
569cdf0e10cSrcweir             sal_uLong nTmp = pDoc->GetNodes().GetEndOfContent().GetIndex() -
570cdf0e10cSrcweir                         pDoc->GetNodes().GetEndOfExtras().GetIndex();
571cdf0e10cSrcweir             //Tables have a little overhead..
572cdf0e10cSrcweir             nTmp -= pDoc->GetTblFrmFmts()->Count() * 25;
573cdf0e10cSrcweir             //Fly frames, too ..
574cdf0e10cSrcweir             nTmp -= (pDoc->GetNodes().GetEndOfAutotext().GetIndex() -
575cdf0e10cSrcweir                        pDoc->GetNodes().GetEndOfInserts().GetIndex()) / 3 * 5;
576cdf0e10cSrcweir             if ( nTmp > 0 )
577cdf0e10cSrcweir                 nNdCount = nTmp;
578cdf0e10cSrcweir         }
579cdf0e10cSrcweir         if ( nNdCount > 100 ) // no estimation below this value
580cdf0e10cSrcweir         {
581cdf0e10cSrcweir             if ( nPgCount > 0 )
582cdf0e10cSrcweir                 nMaxParaPerPage = nNdCount / nPgCount;
583cdf0e10cSrcweir             else
584cdf0e10cSrcweir             {
585cdf0e10cSrcweir                 nMaxParaPerPage = Max( sal_uLong(20),
586cdf0e10cSrcweir                                        sal_uLong(20 + nNdCount / 1000 * 3) );
587cdf0e10cSrcweir #ifdef PM2
588cdf0e10cSrcweir                 const sal_uLong nMax = 49;
589cdf0e10cSrcweir #else
590cdf0e10cSrcweir                 const sal_uLong nMax = 53;
591cdf0e10cSrcweir #endif
592cdf0e10cSrcweir                 nMaxParaPerPage = Min( nMaxParaPerPage, nMax );
593cdf0e10cSrcweir                 nPgCount = nNdCount / nMaxParaPerPage;
594cdf0e10cSrcweir             }
595cdf0e10cSrcweir             if ( nNdCount < 1000 )
596cdf0e10cSrcweir                 nPgCount = 0;// no progress bar for small documents
597cdf0e10cSrcweir             ViewShell *pSh = 0;
598cdf0e10cSrcweir             if( rpLay && rpLay->getRootFrm() )
599cdf0e10cSrcweir                 pSh = rpLay->getRootFrm()->GetCurrShell();
600cdf0e10cSrcweir             if( pSh && pSh->GetViewOptions()->getBrowseMode() )
601cdf0e10cSrcweir                 nMaxParaPerPage *= 6;
602cdf0e10cSrcweir         }
603cdf0e10cSrcweir     }
604cdf0e10cSrcweir     return nPgCount;
605cdf0e10cSrcweir }
606cdf0e10cSrcweir 
607cdf0e10cSrcweir /*-----------------23.5.2001 16:44------------------
608cdf0e10cSrcweir  * SwLayHelper::CheckInsertPage()
609cdf0e10cSrcweir  * inserts a page and return sal_True, if
610cdf0e10cSrcweir  * - the break after flag is set
611cdf0e10cSrcweir  * - the actual content wants a break before
612cdf0e10cSrcweir  * - the maximum count of paragraph/rows is reached
613cdf0e10cSrcweir  *
614cdf0e10cSrcweir  * The break after flag is set, if the actual content
615cdf0e10cSrcweir  * wants a break after.
616cdf0e10cSrcweir  * --------------------------------------------------*/
617cdf0e10cSrcweir 
CheckInsertPage()618cdf0e10cSrcweir sal_Bool SwLayHelper::CheckInsertPage()
619cdf0e10cSrcweir {
620cdf0e10cSrcweir     sal_Bool bEnd = 0 == rpPage->GetNext();
621cdf0e10cSrcweir     const SwAttrSet* pAttr = rpFrm->GetAttrSet();
622cdf0e10cSrcweir     const SvxFmtBreakItem& rBrk = pAttr->GetBreak();
623cdf0e10cSrcweir     const SwFmtPageDesc& rDesc = pAttr->GetPageDesc();
624cdf0e10cSrcweir     // --> FME 2004-10-26 #118195# Do not evaluate page description if frame
625cdf0e10cSrcweir     // is a follow frame!
626cdf0e10cSrcweir     const SwPageDesc* pDesc = rpFrm->IsFlowFrm() &&
627cdf0e10cSrcweir                               SwFlowFrm::CastFlowFrm( rpFrm )->IsFollow() ?
628cdf0e10cSrcweir                               0 :
629cdf0e10cSrcweir                               rDesc.GetPageDesc();
630cdf0e10cSrcweir     // <--
631cdf0e10cSrcweir 
632cdf0e10cSrcweir     sal_Bool bBrk = nParagraphCnt > nMaxParaPerPage || rbBreakAfter;
633cdf0e10cSrcweir     rbBreakAfter = rBrk.GetBreak() == SVX_BREAK_PAGE_AFTER ||
634cdf0e10cSrcweir                    rBrk.GetBreak() == SVX_BREAK_PAGE_BOTH;
635cdf0e10cSrcweir     if ( !bBrk )
636cdf0e10cSrcweir         bBrk = rBrk.GetBreak() == SVX_BREAK_PAGE_BEFORE ||
637cdf0e10cSrcweir                rBrk.GetBreak() == SVX_BREAK_PAGE_BOTH;
638cdf0e10cSrcweir 
639cdf0e10cSrcweir     if ( bBrk || pDesc )
640cdf0e10cSrcweir     {
641cdf0e10cSrcweir         sal_uInt16 nPgNum = 0;
642cdf0e10cSrcweir         if ( !pDesc )
643cdf0e10cSrcweir             pDesc = rpPage->GetPageDesc()->GetFollow();
644cdf0e10cSrcweir         else
645cdf0e10cSrcweir         {
646cdf0e10cSrcweir             if ( 0 != (nPgNum = rDesc.GetNumOffset()) )
647cdf0e10cSrcweir                 ((SwRootFrm*)rpPage->GetUpper())->SetVirtPageNum(sal_True);
648cdf0e10cSrcweir         }
649cdf0e10cSrcweir         sal_Bool bNextPageOdd = !rpPage->OnRightPage();
650cdf0e10cSrcweir         sal_Bool bInsertEmpty = sal_False;
651cdf0e10cSrcweir         if( nPgNum && bNextPageOdd != ( ( nPgNum % 2 ) != 0 ) )
652cdf0e10cSrcweir         {
653cdf0e10cSrcweir             bNextPageOdd = !bNextPageOdd;
654cdf0e10cSrcweir             bInsertEmpty = sal_True;
655cdf0e10cSrcweir         }
656cdf0e10cSrcweir         ::InsertNewPage( (SwPageDesc&)*pDesc, rpPage->GetUpper(),
657cdf0e10cSrcweir                          bNextPageOdd, bInsertEmpty, sal_False, rpPage->GetNext() );
658cdf0e10cSrcweir         if ( bEnd )
659cdf0e10cSrcweir         {
660cdf0e10cSrcweir             ASSERT( rpPage->GetNext(), "Keine neue Seite?" );
661cdf0e10cSrcweir             do
662cdf0e10cSrcweir             {   rpPage = (SwPageFrm*)rpPage->GetNext();
663cdf0e10cSrcweir             } while ( rpPage->GetNext() );
664cdf0e10cSrcweir         }
665cdf0e10cSrcweir         else
666cdf0e10cSrcweir         {
667cdf0e10cSrcweir             ASSERT( rpPage->GetNext(), "Keine neue Seite?" );
668cdf0e10cSrcweir             rpPage = (SwPageFrm*)rpPage->GetNext();
669cdf0e10cSrcweir             if ( rpPage->IsEmptyPage() )
670cdf0e10cSrcweir             {
671cdf0e10cSrcweir                 ASSERT( rpPage->GetNext(), "Keine neue Seite?" );
672cdf0e10cSrcweir                 rpPage = (SwPageFrm*)rpPage->GetNext();
673cdf0e10cSrcweir             }
674cdf0e10cSrcweir         }
675cdf0e10cSrcweir         rpLay = rpPage->FindBodyCont();
676cdf0e10cSrcweir         while( rpLay->Lower() )
677cdf0e10cSrcweir             rpLay = (SwLayoutFrm*)rpLay->Lower();
678cdf0e10cSrcweir         return sal_True;
679cdf0e10cSrcweir     }
680cdf0e10cSrcweir     return sal_False;
681cdf0e10cSrcweir }
682cdf0e10cSrcweir 
683cdf0e10cSrcweir // --> OD 2006-03-22 #b6375613#
lcl_HasTextFrmAnchoredObjs(SwTxtFrm * p_pTxtFrm)684cdf0e10cSrcweir bool lcl_HasTextFrmAnchoredObjs( SwTxtFrm* p_pTxtFrm )
685cdf0e10cSrcweir {
686cdf0e10cSrcweir     bool bHasTextFrmAnchoredObjs( false );
687cdf0e10cSrcweir 
688cdf0e10cSrcweir     const SwSpzFrmFmts* pSpzFrmFmts = p_pTxtFrm->GetTxtNode()->GetDoc()->GetSpzFrmFmts();
689cdf0e10cSrcweir     for ( sal_uInt16 i = 0; i < pSpzFrmFmts->Count(); ++i )
690cdf0e10cSrcweir     {
691cdf0e10cSrcweir         SwFrmFmt *pFmt = (SwFrmFmt*)(*pSpzFrmFmts)[i];
692cdf0e10cSrcweir         const SwFmtAnchor &rAnch = pFmt->GetAnchor();
693cdf0e10cSrcweir         if ( rAnch.GetCntntAnchor() &&
694cdf0e10cSrcweir              ((rAnch.GetAnchorId() == FLY_AT_PARA) ||
695cdf0e10cSrcweir               (rAnch.GetAnchorId() == FLY_AT_CHAR)) &&
696cdf0e10cSrcweir              rAnch.GetCntntAnchor()->nNode.GetIndex() ==
697cdf0e10cSrcweir                                         p_pTxtFrm->GetTxtNode()->GetIndex() )
698cdf0e10cSrcweir         {
699cdf0e10cSrcweir             bHasTextFrmAnchoredObjs = true;
700cdf0e10cSrcweir             break;
701cdf0e10cSrcweir         }
702cdf0e10cSrcweir     }
703cdf0e10cSrcweir 
704cdf0e10cSrcweir     return bHasTextFrmAnchoredObjs;
705cdf0e10cSrcweir }
706cdf0e10cSrcweir 
lcl_ApplyWorkaroundForB6375613(SwFrm * p_pFirstFrmOnNewPage)707cdf0e10cSrcweir void lcl_ApplyWorkaroundForB6375613( SwFrm* p_pFirstFrmOnNewPage )
708cdf0e10cSrcweir {
709cdf0e10cSrcweir     SwTxtFrm* pFirstTextFrmOnNewPage = dynamic_cast<SwTxtFrm*>(p_pFirstFrmOnNewPage);
710cdf0e10cSrcweir     //
711cdf0e10cSrcweir     if ( pFirstTextFrmOnNewPage &&
712cdf0e10cSrcweir          !pFirstTextFrmOnNewPage->IsFollow() &&
713cdf0e10cSrcweir          pFirstTextFrmOnNewPage->GetTxt().Len() == 0 &&
714cdf0e10cSrcweir          lcl_HasTextFrmAnchoredObjs( pFirstTextFrmOnNewPage ) )
715cdf0e10cSrcweir     {
716cdf0e10cSrcweir         // apply page break before at this text frame to assure, that it doesn't flow backward.
717cdf0e10cSrcweir         const SvxBreak eBreak =
718cdf0e10cSrcweir                     pFirstTextFrmOnNewPage->GetAttrSet()->GetBreak().GetBreak();
719cdf0e10cSrcweir         if ( eBreak == SVX_BREAK_NONE )
720cdf0e10cSrcweir         {
721cdf0e10cSrcweir             pFirstTextFrmOnNewPage->GetTxtNode()->LockModify();
722cdf0e10cSrcweir             SwDoc* pDoc( pFirstTextFrmOnNewPage->GetTxtNode()->GetDoc() );
723cdf0e10cSrcweir             IDocumentContentOperations* pIDCO = pFirstTextFrmOnNewPage->GetTxtNode()->getIDocumentContentOperations();
724cdf0e10cSrcweir             const SwPaM aTmpPaM( *(pFirstTextFrmOnNewPage->GetTxtNode()) );
72569a74367SOliver-Rainer Wittmann             pIDCO->InsertPoolItem(
72669a74367SOliver-Rainer Wittmann                 aTmpPaM, SvxFmtBreakItem( SVX_BREAK_PAGE_BEFORE, RES_BREAK ), 0 );
727cdf0e10cSrcweir             pFirstTextFrmOnNewPage->GetTxtNode()->UnlockModify();
728cdf0e10cSrcweir 
729cdf0e10cSrcweir             uno::Reference< document::XDocumentInfoSupplier > xDoc(
730cdf0e10cSrcweir                                         pDoc->GetDocShell()->GetBaseModel(),
731cdf0e10cSrcweir                                         uno::UNO_QUERY);
732cdf0e10cSrcweir             uno::Reference< beans::XPropertySet > xDocInfo(
733cdf0e10cSrcweir                                         xDoc->getDocumentInfo(),
734cdf0e10cSrcweir                                         uno::UNO_QUERY );
735cdf0e10cSrcweir             try
736cdf0e10cSrcweir             {
737cdf0e10cSrcweir                 xDocInfo->setPropertyValue( rtl::OUString::createFromAscii("WorkaroundForB6375613Applied"), uno::makeAny( true ) );
738cdf0e10cSrcweir             }
739cdf0e10cSrcweir             catch( uno::Exception& )
740cdf0e10cSrcweir             {
741cdf0e10cSrcweir             }
742cdf0e10cSrcweir         }
743cdf0e10cSrcweir     }
744cdf0e10cSrcweir }
745cdf0e10cSrcweir // <--
746cdf0e10cSrcweir 
747cdf0e10cSrcweir /*-----------------28.5.2001 11:31------------------
748cdf0e10cSrcweir  * SwLayHelper::CheckInsert
749cdf0e10cSrcweir  *  is the entry point for the _InsertCnt-function.
750cdf0e10cSrcweir  *  The document content index is checked either it is
751cdf0e10cSrcweir  *  in the layout cache either it's time to insert a page
752cdf0e10cSrcweir  *  cause the maximal estimation of content per page is reached.
753cdf0e10cSrcweir  *  A really big table or long paragraph may contains more than
754cdf0e10cSrcweir  *  one page, in this case the needed count of pages will inserted.
755cdf0e10cSrcweir  * --------------------------------------------------*/
756cdf0e10cSrcweir 
CheckInsert(sal_uLong nNodeIndex)757cdf0e10cSrcweir sal_Bool SwLayHelper::CheckInsert( sal_uLong nNodeIndex )
758cdf0e10cSrcweir {
759cdf0e10cSrcweir     sal_Bool bRet = sal_False;
760cdf0e10cSrcweir     sal_Bool bLongTab = sal_False;
761cdf0e10cSrcweir     sal_uLong nMaxRowPerPage( 0 );
762cdf0e10cSrcweir     nNodeIndex -= nStartOfContent;
763cdf0e10cSrcweir     sal_uInt16 nRows( 0 );
764cdf0e10cSrcweir     if( rpFrm->IsTabFrm() )
765cdf0e10cSrcweir     {
766cdf0e10cSrcweir         //Inside a table counts every row as a paragraph
767cdf0e10cSrcweir         SwFrm *pLow = ((SwTabFrm*)rpFrm)->Lower();
768cdf0e10cSrcweir         nRows = 0;
769cdf0e10cSrcweir         do
770cdf0e10cSrcweir         {
771cdf0e10cSrcweir             ++nRows;
772cdf0e10cSrcweir             pLow = pLow->GetNext();
773cdf0e10cSrcweir         } while ( pLow );
774cdf0e10cSrcweir         nParagraphCnt += nRows;
775cdf0e10cSrcweir         if( !pImpl && nParagraphCnt > nMaxParaPerPage + 10 )
776cdf0e10cSrcweir         {
777cdf0e10cSrcweir             // OD 09.04.2003 #108698# - improve heuristics:
778cdf0e10cSrcweir             // Assume that a table, which has more than three times the quantity
779cdf0e10cSrcweir             // of maximal paragraphs per page rows, consists of rows, which have
780cdf0e10cSrcweir             // the height of a normal paragraph. Thus, allow as much rows per page
781cdf0e10cSrcweir             // as much paragraphs are allowed.
782cdf0e10cSrcweir             if ( nRows > ( 3*nMaxParaPerPage ) )
783cdf0e10cSrcweir             {
784cdf0e10cSrcweir                 nMaxRowPerPage = nMaxParaPerPage;
785cdf0e10cSrcweir             }
786cdf0e10cSrcweir             else
787cdf0e10cSrcweir             {
788cdf0e10cSrcweir                 SwFrm *pTmp = ((SwTabFrm*)rpFrm)->Lower();
789cdf0e10cSrcweir                 if( pTmp->GetNext() )
790cdf0e10cSrcweir                     pTmp = pTmp->GetNext();
791cdf0e10cSrcweir                 pTmp = ((SwRowFrm*)pTmp)->Lower();
792cdf0e10cSrcweir                 sal_uInt16 nCnt = 0;
793cdf0e10cSrcweir                 do
794cdf0e10cSrcweir                 {
795cdf0e10cSrcweir                     ++nCnt;
796cdf0e10cSrcweir                     pTmp = pTmp->GetNext();
797cdf0e10cSrcweir                 } while( pTmp );
798cdf0e10cSrcweir                 nMaxRowPerPage = Max( sal_uLong(2), nMaxParaPerPage / nCnt );
799cdf0e10cSrcweir             }
800cdf0e10cSrcweir             bLongTab = sal_True;
801cdf0e10cSrcweir         }
802cdf0e10cSrcweir     }
803cdf0e10cSrcweir     else
804cdf0e10cSrcweir         ++nParagraphCnt;
805cdf0e10cSrcweir     if( bFirst && pImpl && nIndex < pImpl->Count() &&
806cdf0e10cSrcweir         pImpl->GetBreakIndex( nIndex ) == nNodeIndex &&
807cdf0e10cSrcweir         ( pImpl->GetBreakOfst( nIndex ) < STRING_LEN ||
808cdf0e10cSrcweir           ( ++nIndex < pImpl->Count() &&
809cdf0e10cSrcweir           pImpl->GetBreakIndex( nIndex ) == nNodeIndex ) ) )
810cdf0e10cSrcweir         bFirst = sal_False;
811cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
812cdf0e10cSrcweir     sal_uLong nBreakIndex = ( pImpl && nIndex < pImpl->Count() ) ?
813cdf0e10cSrcweir                         pImpl->GetBreakIndex(nIndex) : 0xffff;
814cdf0e10cSrcweir     (void)nBreakIndex;
815cdf0e10cSrcweir #endif
816cdf0e10cSrcweir     // OD 09.04.2003 #108698# - always split a big tables.
817cdf0e10cSrcweir     if ( !bFirst ||
818cdf0e10cSrcweir          ( rpFrm->IsTabFrm() && bLongTab )
819cdf0e10cSrcweir        )
820cdf0e10cSrcweir     {
821cdf0e10cSrcweir         sal_uLong nRowCount = 0;
822cdf0e10cSrcweir         do
823cdf0e10cSrcweir         {
824cdf0e10cSrcweir             if( pImpl || bLongTab )
825cdf0e10cSrcweir             {
826cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
827cdf0e10cSrcweir                 sal_uLong nBrkIndex = ( pImpl && nIndex < pImpl->Count() ) ?
828cdf0e10cSrcweir                         pImpl->GetBreakIndex(nIndex) : 0xffff;
829cdf0e10cSrcweir                 (void)nBrkIndex;
830cdf0e10cSrcweir #endif
831cdf0e10cSrcweir                 xub_StrLen nOfst = STRING_LEN;
832cdf0e10cSrcweir                 sal_uInt16 nType = SW_LAYCACHE_IO_REC_PAGES;
833cdf0e10cSrcweir                 if( bLongTab )
834cdf0e10cSrcweir                 {
835cdf0e10cSrcweir                     rbBreakAfter = sal_True;
836cdf0e10cSrcweir                     nOfst = static_cast<xub_StrLen>(nRowCount + nMaxRowPerPage);
837cdf0e10cSrcweir                 }
838cdf0e10cSrcweir                 else
839cdf0e10cSrcweir                 {
840cdf0e10cSrcweir                     while( nIndex < pImpl->Count() &&
841cdf0e10cSrcweir                            pImpl->GetBreakIndex(nIndex) < nNodeIndex)
842cdf0e10cSrcweir                         ++nIndex;
843cdf0e10cSrcweir                     if( nIndex < pImpl->Count() &&
844cdf0e10cSrcweir                         pImpl->GetBreakIndex(nIndex) == nNodeIndex )
845cdf0e10cSrcweir                     {
846cdf0e10cSrcweir                         nType = pImpl->GetBreakType( nIndex );
847cdf0e10cSrcweir                         nOfst = pImpl->GetBreakOfst( nIndex++ );
848cdf0e10cSrcweir                         rbBreakAfter = sal_True;
849cdf0e10cSrcweir                     }
850cdf0e10cSrcweir                 }
851cdf0e10cSrcweir 
852cdf0e10cSrcweir                 if( nOfst < STRING_LEN )
853cdf0e10cSrcweir                 {
854cdf0e10cSrcweir                     sal_Bool bSplit = sal_False;
855cdf0e10cSrcweir                     sal_uInt16 nRepeat( 0 );
856cdf0e10cSrcweir                     if( !bLongTab && rpFrm->IsTxtFrm() &&
857cdf0e10cSrcweir                         SW_LAYCACHE_IO_REC_PARA == nType &&
858cdf0e10cSrcweir                         nOfst<((SwTxtFrm*)rpFrm)->GetTxtNode()->GetTxt().Len() )
859cdf0e10cSrcweir                         bSplit = sal_True;
860cdf0e10cSrcweir                     else if( rpFrm->IsTabFrm() && nRowCount < nOfst &&
861cdf0e10cSrcweir                              ( bLongTab || SW_LAYCACHE_IO_REC_TABLE == nType ) )
862cdf0e10cSrcweir                     {
863cdf0e10cSrcweir                         nRepeat = ((SwTabFrm*)rpFrm)->
864cdf0e10cSrcweir                                   GetTable()->GetRowsToRepeat();
865cdf0e10cSrcweir                         bSplit = nOfst < nRows && nRowCount + nRepeat < nOfst;
866cdf0e10cSrcweir                         bLongTab = bLongTab && bSplit;
867cdf0e10cSrcweir                     }
868cdf0e10cSrcweir                     if( bSplit )
869cdf0e10cSrcweir                     {
870cdf0e10cSrcweir                         rpFrm->InsertBehind( rpLay, rpPrv );
871cdf0e10cSrcweir                         rpFrm->Frm().Pos() = rpLay->Frm().Pos();
872cdf0e10cSrcweir                         rpFrm->Frm().Pos().Y() += 1;
873cdf0e10cSrcweir                         rpPrv = rpFrm;
874cdf0e10cSrcweir                         if( rpFrm->IsTabFrm() )
875cdf0e10cSrcweir                         {
876cdf0e10cSrcweir                             SwTabFrm* pTab = (SwTabFrm*)rpFrm;
877cdf0e10cSrcweir                             // --> OD 2004-09-23 #i33629#, #i29955#
878cdf0e10cSrcweir                             ::RegistFlys( pTab->FindPageFrm(), pTab );
879cdf0e10cSrcweir                             // <--
880cdf0e10cSrcweir                             SwFrm *pRow = pTab->Lower();
881cdf0e10cSrcweir                             SwTabFrm *pFoll = new SwTabFrm( *pTab );
882cdf0e10cSrcweir 
883cdf0e10cSrcweir                             SwFrm *pPrv;
884cdf0e10cSrcweir                             if( nRepeat > 0 )
885cdf0e10cSrcweir                             {
886cdf0e10cSrcweir                                 bDontCreateObjects = sal_True; //frmtool
887cdf0e10cSrcweir 
888cdf0e10cSrcweir                                 // Insert new headlines:
889cdf0e10cSrcweir                                 sal_uInt16 nRowIdx = 0;
890cdf0e10cSrcweir                                 SwRowFrm* pHeadline = 0;
891cdf0e10cSrcweir                                 while( nRowIdx < nRepeat )
892cdf0e10cSrcweir                                 {
893cdf0e10cSrcweir                                     ASSERT( pTab->GetTable()->GetTabLines()[ nRowIdx ], "Table ohne Zeilen?" );
894cdf0e10cSrcweir                                     pHeadline =
895cdf0e10cSrcweir                                         new SwRowFrm( *pTab->GetTable()->GetTabLines()[ nRowIdx ], pTab );
896cdf0e10cSrcweir                                     pHeadline->SetRepeatedHeadline( true );
897cdf0e10cSrcweir                                     pHeadline->InsertBefore( pFoll, 0 );
898cdf0e10cSrcweir                                     pHeadline->RegistFlys();
899cdf0e10cSrcweir 
900cdf0e10cSrcweir                                     ++nRowIdx;
901cdf0e10cSrcweir                                 }
902cdf0e10cSrcweir 
903cdf0e10cSrcweir                                 bDontCreateObjects = sal_False;
904cdf0e10cSrcweir                                 pPrv = pHeadline;
905cdf0e10cSrcweir                                 nRows = nRows + nRepeat;
906cdf0e10cSrcweir                             }
907cdf0e10cSrcweir                             else
908cdf0e10cSrcweir                                 pPrv = 0;
909cdf0e10cSrcweir                             while( pRow && nRowCount < nOfst )
910cdf0e10cSrcweir                             {
911cdf0e10cSrcweir                                 pRow = pRow->GetNext();
912cdf0e10cSrcweir                                 ++nRowCount;
913cdf0e10cSrcweir                             }
914cdf0e10cSrcweir                             while ( pRow )
915cdf0e10cSrcweir                             {
916cdf0e10cSrcweir                                 SwFrm* pNxt = pRow->GetNext();
917cdf0e10cSrcweir                                 pRow->Remove();
918cdf0e10cSrcweir                                 pRow->InsertBehind( pFoll, pPrv );
919cdf0e10cSrcweir                                 pPrv = pRow;
920cdf0e10cSrcweir                                 pRow = pNxt;
921cdf0e10cSrcweir                             }
922cdf0e10cSrcweir                             rpFrm = pFoll;
923cdf0e10cSrcweir                         }
924cdf0e10cSrcweir                         else
925cdf0e10cSrcweir                         {
926cdf0e10cSrcweir                             SwTxtFrm *pNew = new SwTxtFrm( ((SwTxtFrm*)rpFrm)->
927cdf0e10cSrcweir                                                             GetTxtNode(), rpFrm );
928cdf0e10cSrcweir                             pNew->_SetIsFollow( sal_True );
929cdf0e10cSrcweir                             pNew->ManipOfst( nOfst );
930cdf0e10cSrcweir                             pNew->SetFollow( ((SwTxtFrm*)rpFrm)->GetFollow() );
931cdf0e10cSrcweir                             ((SwTxtFrm*)rpFrm)->SetFollow( pNew );
932cdf0e10cSrcweir                             rpFrm = pNew;
933cdf0e10cSrcweir                         }
934cdf0e10cSrcweir                     }
935cdf0e10cSrcweir                 }
936cdf0e10cSrcweir             }
937cdf0e10cSrcweir 
938cdf0e10cSrcweir             SwPageFrm* pLastPage = rpPage;
939cdf0e10cSrcweir             if( CheckInsertPage() )
940cdf0e10cSrcweir             {
941cdf0e10cSrcweir                 // --> OD 2006-03-21 #b6375613#
942cdf0e10cSrcweir                 if ( pDoc->ApplyWorkaroundForB6375613() )
943cdf0e10cSrcweir                 {
944cdf0e10cSrcweir                     lcl_ApplyWorkaroundForB6375613( rpFrm );
945cdf0e10cSrcweir                 }
946cdf0e10cSrcweir                 // <--
947cdf0e10cSrcweir                 _CheckFlyCache( pLastPage );
948cdf0e10cSrcweir                 if( rpPrv && rpPrv->IsTxtFrm() && !rpPrv->GetValidSizeFlag() )
949cdf0e10cSrcweir                     rpPrv->Frm().Height( rpPrv->GetUpper()->Prt().Height() );
950cdf0e10cSrcweir 
951cdf0e10cSrcweir                 bRet = sal_True;
952cdf0e10cSrcweir                 rpPrv = 0;
953cdf0e10cSrcweir                 nParagraphCnt = 0;
954cdf0e10cSrcweir 
955cdf0e10cSrcweir                 if ( rpActualSection )
956cdf0e10cSrcweir                 {
957cdf0e10cSrcweir                     //Hatte der SectionFrm ueberhaupt Inhalt? Wenn
958cdf0e10cSrcweir                     //nicht kann er gleich umgehaengt werden.
959cdf0e10cSrcweir                     SwSectionFrm *pSct;
960cdf0e10cSrcweir                     bool bInit = false;
961cdf0e10cSrcweir                     if ( !rpActualSection->GetSectionFrm()->ContainsCntnt())
962cdf0e10cSrcweir                     {
963cdf0e10cSrcweir                         pSct = rpActualSection->GetSectionFrm();
964cdf0e10cSrcweir                         pSct->Remove();
965cdf0e10cSrcweir                     }
966cdf0e10cSrcweir                     else
967cdf0e10cSrcweir                     {
968cdf0e10cSrcweir                         pSct = new SwSectionFrm(
969cdf0e10cSrcweir                             *rpActualSection->GetSectionFrm(), sal_False );
970cdf0e10cSrcweir                         rpActualSection->GetSectionFrm()->SimpleFormat();
971cdf0e10cSrcweir                         bInit = true;
972cdf0e10cSrcweir                     }
973cdf0e10cSrcweir                     rpActualSection->SetSectionFrm( pSct );
974cdf0e10cSrcweir                     pSct->InsertBehind( rpLay, 0 );
975cdf0e10cSrcweir                     if( bInit )
976cdf0e10cSrcweir                         pSct->Init();
977cdf0e10cSrcweir                     pSct->Frm().Pos() = rpLay->Frm().Pos();
978cdf0e10cSrcweir                     pSct->Frm().Pos().Y() += 1; //wg. Benachrichtigungen.
979cdf0e10cSrcweir 
980cdf0e10cSrcweir                     rpLay = pSct;
981cdf0e10cSrcweir                     if ( rpLay->Lower() && rpLay->Lower()->IsLayoutFrm() )
982cdf0e10cSrcweir                         rpLay = rpLay->GetNextLayoutLeaf();
983cdf0e10cSrcweir                 }
984cdf0e10cSrcweir             }
985cdf0e10cSrcweir         } while( bLongTab || ( pImpl && nIndex < pImpl->Count() &&
986cdf0e10cSrcweir                  (*pImpl)[ nIndex ] == nNodeIndex ) );
987cdf0e10cSrcweir     }
988cdf0e10cSrcweir     bFirst = sal_False;
989cdf0e10cSrcweir     return bRet;
990cdf0e10cSrcweir }
991cdf0e10cSrcweir 
992cdf0e10cSrcweir struct SdrObjectCompare
993cdf0e10cSrcweir {
operator ()SdrObjectCompare994cdf0e10cSrcweir   bool operator()( const SdrObject* pF1, const SdrObject* pF2 ) const
995cdf0e10cSrcweir   {
996cdf0e10cSrcweir     return pF1->GetOrdNum() < pF2->GetOrdNum();
997cdf0e10cSrcweir   }
998cdf0e10cSrcweir };
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir struct FlyCacheCompare
1001cdf0e10cSrcweir {
operator ()FlyCacheCompare1002cdf0e10cSrcweir   bool operator()( const SwFlyCache* pC1, const SwFlyCache* pC2 ) const
1003cdf0e10cSrcweir   {
1004cdf0e10cSrcweir     return pC1->nOrdNum < pC2->nOrdNum;
1005cdf0e10cSrcweir   }
1006cdf0e10cSrcweir };
1007cdf0e10cSrcweir 
1008cdf0e10cSrcweir  /*-----------------28.6.2001 14:40------------------
1009cdf0e10cSrcweir   * SwLayHelper::_CheckFlyCache(..)
1010cdf0e10cSrcweir   * If a new page is inserted, the last page is analysed.
1011cdf0e10cSrcweir   * If there are text frames with default position, the fly cache
1012cdf0e10cSrcweir   * is checked, if these frames are stored in the cache.
1013cdf0e10cSrcweir   * --------------------------------------------------*/
1014cdf0e10cSrcweir 
_CheckFlyCache(SwPageFrm * pPage)1015cdf0e10cSrcweir void SwLayHelper::_CheckFlyCache( SwPageFrm* pPage )
1016cdf0e10cSrcweir {
1017cdf0e10cSrcweir     if( !pImpl || !pPage )
1018cdf0e10cSrcweir         return;
1019cdf0e10cSrcweir     sal_uInt16 nFlyCount = pImpl->GetFlyCount();
102087ecdd25Smseidel     // Any text frames at the page, fly cache available?
1021cdf0e10cSrcweir     if( pPage->GetSortedObjs() && nFlyIdx < nFlyCount )
1022cdf0e10cSrcweir     {
1023cdf0e10cSrcweir         SwSortedObjs &rObjs = *pPage->GetSortedObjs();
1024cdf0e10cSrcweir         sal_uInt16 nPgNum = pPage->GetPhyPageNum();
1025cdf0e10cSrcweir 
1026cdf0e10cSrcweir /*
1027cdf0e10cSrcweir 
1028cdf0e10cSrcweir         //
1029cdf0e10cSrcweir         // NOTE: This code assumes that all objects have already been
1030cdf0e10cSrcweir         // inserted into the drawing layout, so that the cached objects
1031cdf0e10cSrcweir         // can be identified by their ordnum. Unfortunately this function
1032cdf0e10cSrcweir         // is called with page n if page n+1 has been inserted. Thus
1033cdf0e10cSrcweir         // not all the objects have been inserted and the ordnums cannot
1034cdf0e10cSrcweir         // be used to identify the objects.
1035cdf0e10cSrcweir         //
1036cdf0e10cSrcweir 
1037cdf0e10cSrcweir         for ( sal_uInt16 i = 0; i < rObjs.Count(); ++i )  // check objects
1038cdf0e10cSrcweir         {
1039cdf0e10cSrcweir             SdrObject *pO = rObjs[i];
1040cdf0e10cSrcweir             if ( pO->ISA(SwVirtFlyDrawObj) )  // a text frame?
1041cdf0e10cSrcweir             {
1042cdf0e10cSrcweir                 SwFlyFrm *pFly = ((SwVirtFlyDrawObj*)pO)->GetFlyFrm();
1043cdf0e10cSrcweir                 if( pFly->Frm().Left() == WEIT_WECH && pFly->GetAnchor() &&
1044cdf0e10cSrcweir                     !pFly->GetAnchor()->FindFooterOrHeader() )
1045cdf0e10cSrcweir                 {   // Only frame with default position and not in header/footer
1046cdf0e10cSrcweir                     const SwContact *pC = (SwContact*)GetUserCall(pO);
1047cdf0e10cSrcweir                     if( pC )
1048cdf0e10cSrcweir                     {
1049cdf0e10cSrcweir                         sal_uLong nOrdNum = pO->GetOrdNum(); // the Id
1050cdf0e10cSrcweir                         SwFlyCache* pFlyC;
1051cdf0e10cSrcweir                         while( nFlyIdx < nFlyCount && ( pFlyC = pImpl->
1052cdf0e10cSrcweir                                GetFlyCache(nFlyIdx) )->nPageNum < nPgNum)
1053cdf0e10cSrcweir                             ++nFlyIdx;
1054cdf0e10cSrcweir                         if( nFlyIdx < nFlyCount &&
1055cdf0e10cSrcweir                             pFlyC->nPageNum == nPgNum )
1056cdf0e10cSrcweir                         {
1057cdf0e10cSrcweir                             sal_uInt16 nIdx = nFlyIdx;
1058cdf0e10cSrcweir                             while( nIdx < nFlyCount && ( pFlyC = pImpl->
1059cdf0e10cSrcweir                                    GetFlyCache( nIdx ) )->nPageNum == nPgNum &&
1060cdf0e10cSrcweir                                    pFlyC->nOrdNum != nOrdNum )
1061cdf0e10cSrcweir                                 ++nIdx;
1062cdf0e10cSrcweir                             if( nIdx < nFlyCount && pFlyC->nPageNum == nPgNum &&
1063cdf0e10cSrcweir                                 pFlyC->nOrdNum == nOrdNum )
1064cdf0e10cSrcweir                             {   // we get the stored information
1065cdf0e10cSrcweir                                 pFly->Frm().Pos().X() = pFlyC->Left() +
1066cdf0e10cSrcweir                                                         pPage->Frm().Left();
1067cdf0e10cSrcweir                                 pFly->Frm().Pos().Y() = pFlyC->Top() +
1068cdf0e10cSrcweir                                                         pPage->Frm().Top();
1069cdf0e10cSrcweir                                 pFly->Frm().Width( pFlyC->Width() );
1070cdf0e10cSrcweir                                 pFly->Frm().Height( pFlyC->Height() );
1071cdf0e10cSrcweir                             }
1072cdf0e10cSrcweir                         }
1073cdf0e10cSrcweir                     }
1074cdf0e10cSrcweir                 }
1075cdf0e10cSrcweir             }
1076cdf0e10cSrcweir         }
1077cdf0e10cSrcweir  */
1078cdf0e10cSrcweir 
1079cdf0e10cSrcweir         //
1080cdf0e10cSrcweir         // NOTE: Here we do not use the absolute ordnums but
1081cdf0e10cSrcweir         // relative ordnums for the objects on this page.
1082cdf0e10cSrcweir 
1083cdf0e10cSrcweir         // skip fly frames from pages before the current page
1084cdf0e10cSrcweir         SwFlyCache* pFlyC;
1085cdf0e10cSrcweir         while( nFlyIdx < nFlyCount && ( pFlyC = pImpl->
1086cdf0e10cSrcweir                GetFlyCache(nFlyIdx) )->nPageNum < nPgNum)
1087cdf0e10cSrcweir             ++nFlyIdx;
1088cdf0e10cSrcweir 
1089cdf0e10cSrcweir         // sort cached objects on this page by ordnum
1090cdf0e10cSrcweir         std::set< const SwFlyCache*, FlyCacheCompare > aFlyCacheSet;
1091cdf0e10cSrcweir         sal_uInt16 nIdx = nFlyIdx;
1092cdf0e10cSrcweir 
1093cdf0e10cSrcweir         while( nIdx < nFlyCount && ( pFlyC = pImpl->
1094cdf0e10cSrcweir                GetFlyCache( nIdx ) )->nPageNum == nPgNum )
1095cdf0e10cSrcweir         {
1096cdf0e10cSrcweir             aFlyCacheSet.insert( pFlyC );
1097cdf0e10cSrcweir             ++nIdx;
1098cdf0e10cSrcweir         }
1099cdf0e10cSrcweir 
1100cdf0e10cSrcweir         // sort objects on this page by ordnum
1101cdf0e10cSrcweir         std::set< const SdrObject*, SdrObjectCompare > aFlySet;
1102cdf0e10cSrcweir         for ( sal_uInt16 i = 0; i < rObjs.Count(); ++i )
1103cdf0e10cSrcweir         {
1104cdf0e10cSrcweir             SwAnchoredObject* pAnchoredObj = rObjs[i];
1105cdf0e10cSrcweir             if ( pAnchoredObj->ISA(SwFlyFrm) )  // a text frame?
1106cdf0e10cSrcweir             {
1107cdf0e10cSrcweir                 SwFlyFrm *pFly = static_cast<SwFlyFrm*>(pAnchoredObj);
1108cdf0e10cSrcweir                 if( pFly->GetAnchorFrm() &&
1109cdf0e10cSrcweir                     !pFly->GetAnchorFrm()->FindFooterOrHeader() )
1110cdf0e10cSrcweir                 {
1111cdf0e10cSrcweir                     const SwContact *pC = ::GetUserCall( pAnchoredObj->GetDrawObj() );
1112cdf0e10cSrcweir                     if( pC )
1113cdf0e10cSrcweir                     {
1114cdf0e10cSrcweir                         aFlySet.insert( pAnchoredObj->GetDrawObj() );
1115cdf0e10cSrcweir                     }
1116cdf0e10cSrcweir                 }
1117cdf0e10cSrcweir             }
1118cdf0e10cSrcweir         }
1119cdf0e10cSrcweir 
1120cdf0e10cSrcweir         if ( aFlyCacheSet.size() == aFlySet.size() )
1121cdf0e10cSrcweir         {
1122cdf0e10cSrcweir             std::set< const SwFlyCache*, FlyCacheCompare >::iterator aFlyCacheSetIt =
1123cdf0e10cSrcweir                     aFlyCacheSet.begin();
1124cdf0e10cSrcweir             std::set< const SdrObject*, SdrObjectCompare >::iterator aFlySetIt =
1125cdf0e10cSrcweir                     aFlySet.begin();
1126cdf0e10cSrcweir 
1127cdf0e10cSrcweir             while ( aFlyCacheSetIt != aFlyCacheSet.end() )
1128cdf0e10cSrcweir             {
1129cdf0e10cSrcweir                 const SwFlyCache* pFlyCache = *aFlyCacheSetIt;
1130cdf0e10cSrcweir                 SwFlyFrm* pFly = ((SwVirtFlyDrawObj*)*aFlySetIt)->GetFlyFrm();
1131cdf0e10cSrcweir 
1132cdf0e10cSrcweir                 if ( pFly->Frm().Left() == WEIT_WECH )
1133cdf0e10cSrcweir                 {
1134cdf0e10cSrcweir                     // we get the stored information
1135cdf0e10cSrcweir                     pFly->Frm().Pos().X() = pFlyCache->Left() +
1136cdf0e10cSrcweir                                             pPage->Frm().Left();
1137cdf0e10cSrcweir                     pFly->Frm().Pos().Y() = pFlyCache->Top() +
1138cdf0e10cSrcweir                                             pPage->Frm().Top();
1139cdf0e10cSrcweir                     if ( pImpl->IsUseFlyCache() )
1140cdf0e10cSrcweir                     {
1141cdf0e10cSrcweir                         pFly->Frm().Width( pFlyCache->Width() );
1142cdf0e10cSrcweir                         pFly->Frm().Height( pFlyCache->Height() );
1143cdf0e10cSrcweir                     }
1144cdf0e10cSrcweir                 }
1145cdf0e10cSrcweir 
1146cdf0e10cSrcweir                 ++aFlyCacheSetIt;
1147cdf0e10cSrcweir                 ++aFlySetIt;
1148cdf0e10cSrcweir             }
1149cdf0e10cSrcweir         }
1150cdf0e10cSrcweir     }
1151cdf0e10cSrcweir }
1152cdf0e10cSrcweir 
1153cdf0e10cSrcweir /*-----------------28.6.2001 14:48------------------
1154cdf0e10cSrcweir  * SwLayHelper::CheckPageFlyCache(..)
1155cdf0e10cSrcweir  * looks for the given text frame in the fly cache and sets
1156cdf0e10cSrcweir  * the position and size, if possible.
1157cdf0e10cSrcweir  * The fly cache is sorted by pages and we start searching with the given page.
1158cdf0e10cSrcweir  * If we found the page number in the fly cache, we set
1159cdf0e10cSrcweir  * the rpPage parameter to the right page, if possible.
1160cdf0e10cSrcweir  * --------------------------------------------------*/
1161cdf0e10cSrcweir 
CheckPageFlyCache(SwPageFrm * & rpPage,SwFlyFrm * pFly)1162cdf0e10cSrcweir sal_Bool SwLayHelper::CheckPageFlyCache( SwPageFrm* &rpPage, SwFlyFrm* pFly )
1163cdf0e10cSrcweir {
1164cdf0e10cSrcweir     if( !pFly->GetAnchorFrm() || !pFly->GetVirtDrawObj() ||
1165cdf0e10cSrcweir         pFly->GetAnchorFrm()->FindFooterOrHeader() )
1166cdf0e10cSrcweir         return sal_False;
1167cdf0e10cSrcweir     sal_Bool bRet = sal_False;
1168cdf0e10cSrcweir     SwDoc* pDoc = rpPage->GetFmt()->GetDoc();
1169cdf0e10cSrcweir     SwLayCacheImpl *pCache = pDoc->GetLayoutCache() ?
1170cdf0e10cSrcweir                              pDoc->GetLayoutCache()->LockImpl() : NULL;
1171cdf0e10cSrcweir     if( pCache )
1172cdf0e10cSrcweir     {
1173cdf0e10cSrcweir         sal_uInt16 nPgNum = rpPage->GetPhyPageNum();
1174cdf0e10cSrcweir         sal_uInt16 nIdx = 0;
1175cdf0e10cSrcweir         sal_uInt16 nCnt = pCache->GetFlyCount();
1176cdf0e10cSrcweir         sal_uLong nOrdNum = pFly->GetVirtDrawObj()->GetOrdNum();
1177cdf0e10cSrcweir         SwFlyCache* pFlyC = 0;
1178cdf0e10cSrcweir 
1179cdf0e10cSrcweir         // skip fly frames from pages before the current page
1180cdf0e10cSrcweir         while( nIdx < nCnt &&
1181cdf0e10cSrcweir                nPgNum > (pFlyC = pCache->GetFlyCache( nIdx ))->nPageNum )
1182cdf0e10cSrcweir             ++nIdx;
1183cdf0e10cSrcweir 
1184cdf0e10cSrcweir         while( nIdx < nCnt &&
1185cdf0e10cSrcweir                nOrdNum != (pFlyC = pCache->GetFlyCache( nIdx ))->nOrdNum )
1186cdf0e10cSrcweir             ++nIdx;
1187cdf0e10cSrcweir         if( nIdx < nCnt )
1188cdf0e10cSrcweir         {
1189cdf0e10cSrcweir             SwPageFrm *pPage = rpPage;
1190cdf0e10cSrcweir             while( pPage && pPage->GetPhyPageNum() < pFlyC->nPageNum )
1191cdf0e10cSrcweir                 pPage = (SwPageFrm*)pPage->GetNext();
1192cdf0e10cSrcweir             // --> OD 2005-02-22 #i43266# - if the found page is an empty page,
1193cdf0e10cSrcweir             // take the previous one (take next one, if previous one doesn't exists)
1194cdf0e10cSrcweir             if ( pPage && pPage->IsEmptyPage() )
1195cdf0e10cSrcweir             {
1196cdf0e10cSrcweir                 pPage = static_cast<SwPageFrm*>( pPage->GetPrev()
1197cdf0e10cSrcweir                                                  ? pPage->GetPrev()
1198cdf0e10cSrcweir                                                  : pPage->GetNext() );
1199cdf0e10cSrcweir             }
1200cdf0e10cSrcweir             // <--
1201cdf0e10cSrcweir             if( pPage )
1202cdf0e10cSrcweir             {
1203cdf0e10cSrcweir                 rpPage = pPage;
1204cdf0e10cSrcweir                 pFly->Frm().Pos().X() = pFlyC->Left() + pPage->Frm().Left();
1205cdf0e10cSrcweir                 pFly->Frm().Pos().Y() = pFlyC->Top() + pPage->Frm().Top();
1206cdf0e10cSrcweir                 if ( pCache->IsUseFlyCache() )
1207cdf0e10cSrcweir                 {
1208cdf0e10cSrcweir                     pFly->Frm().Width( pFlyC->Width() );
1209cdf0e10cSrcweir                     pFly->Frm().Height( pFlyC->Height() );
1210cdf0e10cSrcweir                 }
1211cdf0e10cSrcweir                 bRet = sal_True;
1212cdf0e10cSrcweir             }
1213cdf0e10cSrcweir         }
1214cdf0e10cSrcweir         pDoc->GetLayoutCache()->UnlockImpl();
1215cdf0e10cSrcweir     }
1216cdf0e10cSrcweir     return bRet;
1217cdf0e10cSrcweir }
1218cdf0e10cSrcweir 
1219cdf0e10cSrcweir // -----------------------------------------------------------------------------
1220cdf0e10cSrcweir 
SwLayCacheIoImpl(SvStream & rStrm,sal_Bool bWrtMd)1221cdf0e10cSrcweir SwLayCacheIoImpl::SwLayCacheIoImpl( SvStream& rStrm, sal_Bool bWrtMd ) :
1222cdf0e10cSrcweir     pStream( &rStrm ),
1223cdf0e10cSrcweir     nMajorVersion(SW_LAYCACHE_IO_VERSION_MAJOR),
1224cdf0e10cSrcweir     nMinorVersion(SW_LAYCACHE_IO_VERSION_MINOR),
1225cdf0e10cSrcweir     bWriteMode( bWrtMd ),
1226cdf0e10cSrcweir     bError( sal_False  )
1227cdf0e10cSrcweir {
1228cdf0e10cSrcweir     if( bWriteMode )
1229cdf0e10cSrcweir         *pStream << nMajorVersion
1230cdf0e10cSrcweir                  << nMinorVersion;
1231cdf0e10cSrcweir 
1232cdf0e10cSrcweir     else
1233cdf0e10cSrcweir         *pStream >> nMajorVersion
1234cdf0e10cSrcweir                  >> nMinorVersion;
1235cdf0e10cSrcweir }
1236cdf0e10cSrcweir 
OpenRec(sal_uInt8 cType)1237cdf0e10cSrcweir sal_Bool SwLayCacheIoImpl::OpenRec( sal_uInt8 cType )
1238cdf0e10cSrcweir {
1239cdf0e10cSrcweir     sal_Bool bRes = sal_True;
1240cdf0e10cSrcweir     size_t nLvl = aRecTypes.size();
1241cdf0e10cSrcweir     ASSERT( nLvl == aRecSizes.Count(), "OpenRec: Level" );
1242cdf0e10cSrcweir     sal_uInt32 nPos = pStream->Tell();
1243cdf0e10cSrcweir     if( bWriteMode )
1244cdf0e10cSrcweir     {
1245cdf0e10cSrcweir         aRecTypes.push_back( cType );
1246cdf0e10cSrcweir         aRecSizes.Insert( nPos, nLvl );
1247cdf0e10cSrcweir         *pStream << (sal_uInt32) 0;
1248cdf0e10cSrcweir     }
1249cdf0e10cSrcweir     else
1250cdf0e10cSrcweir     {
1251cdf0e10cSrcweir         sal_uInt32 nVal;
1252cdf0e10cSrcweir         *pStream >> nVal;
1253cdf0e10cSrcweir         sal_uInt8 cRecTyp = (sal_uInt8)nVal;
1254cdf0e10cSrcweir         aRecTypes.push_back( cRecTyp );
1255cdf0e10cSrcweir         sal_uInt32 nSize = nVal >> 8;
1256cdf0e10cSrcweir         aRecSizes.Insert( nPos + nSize, nLvl );
1257cdf0e10cSrcweir         if( !nVal || cRecTyp != cType ||
1258cdf0e10cSrcweir             pStream->GetErrorCode() != SVSTREAM_OK || pStream->IsEof() )
1259cdf0e10cSrcweir         {
1260cdf0e10cSrcweir             ASSERT( nVal, "OpenRec: Record-Header is 0" );
1261cdf0e10cSrcweir             ASSERT( cRecTyp == cType,
1262cdf0e10cSrcweir                     "OpenRec: Wrong Record Type" );
1263cdf0e10cSrcweir             aRecTypes.back() = 0;
1264cdf0e10cSrcweir             aRecSizes[nLvl] = pStream->Tell();
1265cdf0e10cSrcweir             bRes = sal_False;
1266cdf0e10cSrcweir             bError = sal_True;
1267cdf0e10cSrcweir         }
1268cdf0e10cSrcweir     }
1269cdf0e10cSrcweir     return bRes;
1270cdf0e10cSrcweir }
1271cdf0e10cSrcweir 
1272cdf0e10cSrcweir // Close record
1273cdf0e10cSrcweir 
CloseRec(sal_uInt8)1274cdf0e10cSrcweir sal_Bool SwLayCacheIoImpl::CloseRec( sal_uInt8 )
1275cdf0e10cSrcweir {
1276cdf0e10cSrcweir     sal_Bool bRes = sal_True;
1277cdf0e10cSrcweir     size_t nLvl = aRecTypes.size();
1278cdf0e10cSrcweir     ASSERT( nLvl == aRecSizes.Count(), "CloseRec: wrong Level" );
1279cdf0e10cSrcweir     ASSERT( nLvl, "CloseRec: no levels" );
1280cdf0e10cSrcweir     if( nLvl )
1281cdf0e10cSrcweir     {
1282cdf0e10cSrcweir         nLvl--;
1283cdf0e10cSrcweir         sal_uInt32 nPos = pStream->Tell();
1284cdf0e10cSrcweir         if( bWriteMode )
1285cdf0e10cSrcweir         {
1286cdf0e10cSrcweir             sal_uInt32 nBgn = aRecSizes[nLvl];
1287cdf0e10cSrcweir             pStream->Seek( nBgn );
1288cdf0e10cSrcweir             sal_uInt32 nSize = nPos - nBgn;
1289cdf0e10cSrcweir             sal_uInt32 nVal = ( nSize << 8 ) | aRecTypes.back();
1290cdf0e10cSrcweir             *pStream << nVal;
1291cdf0e10cSrcweir             pStream->Seek( nPos );
1292cdf0e10cSrcweir             if( pStream->GetError() != SVSTREAM_OK )
1293cdf0e10cSrcweir                 bRes = sal_False;
1294cdf0e10cSrcweir         }
1295cdf0e10cSrcweir         else
1296cdf0e10cSrcweir         {
1297cdf0e10cSrcweir             sal_uInt32 n = aRecSizes[nLvl];
1298cdf0e10cSrcweir             ASSERT( n >= nPos, "CloseRec: to much data read" );
1299cdf0e10cSrcweir             if( n != nPos )
1300cdf0e10cSrcweir             {
1301cdf0e10cSrcweir                 pStream->Seek( n );
1302cdf0e10cSrcweir                 if( n < nPos )
1303cdf0e10cSrcweir                     bRes = sal_False;
1304cdf0e10cSrcweir             }
1305cdf0e10cSrcweir             if( pStream->GetErrorCode() != SVSTREAM_OK )
1306cdf0e10cSrcweir                 bRes = sal_False;
1307cdf0e10cSrcweir         }
1308cdf0e10cSrcweir 
1309cdf0e10cSrcweir         aRecTypes.pop_back();
1310cdf0e10cSrcweir         aRecSizes.Remove( nLvl, 1 );
1311cdf0e10cSrcweir     }
1312cdf0e10cSrcweir 
1313cdf0e10cSrcweir     if( !bRes )
1314cdf0e10cSrcweir         bError = sal_True;
1315cdf0e10cSrcweir 
1316cdf0e10cSrcweir     return bRes;
1317cdf0e10cSrcweir }
1318cdf0e10cSrcweir 
BytesLeft()1319cdf0e10cSrcweir sal_uInt32 SwLayCacheIoImpl::BytesLeft()
1320cdf0e10cSrcweir {
1321cdf0e10cSrcweir     sal_uInt16 nLvl = aRecSizes.Count();
1322cdf0e10cSrcweir     sal_uInt32 n = 0;
1323cdf0e10cSrcweir     if( !bError && nLvl )
1324cdf0e10cSrcweir     {
1325cdf0e10cSrcweir         sal_uInt32 nEndPos = aRecSizes[ nLvl-1 ];
1326cdf0e10cSrcweir         sal_uInt32 nPos = pStream->Tell();
1327cdf0e10cSrcweir         if( nEndPos > nPos )
1328cdf0e10cSrcweir             n = nEndPos - nPos;
1329cdf0e10cSrcweir     }
1330cdf0e10cSrcweir 
1331cdf0e10cSrcweir     return n;
1332cdf0e10cSrcweir }
1333cdf0e10cSrcweir 
Peek()1334cdf0e10cSrcweir sal_uInt8 SwLayCacheIoImpl::Peek()
1335cdf0e10cSrcweir {
1336cdf0e10cSrcweir     sal_uInt8 c = 0;
1337cdf0e10cSrcweir     if( !bError )
1338cdf0e10cSrcweir     {
1339cdf0e10cSrcweir         sal_uInt32 nPos = pStream->Tell();
1340cdf0e10cSrcweir         *pStream >> c;
1341cdf0e10cSrcweir         pStream->Seek( nPos );
1342cdf0e10cSrcweir         if( pStream->GetErrorCode() != SVSTREAM_OK )
1343cdf0e10cSrcweir         {
1344cdf0e10cSrcweir             c = 0;
1345cdf0e10cSrcweir             bError = sal_True;
1346cdf0e10cSrcweir         }
1347cdf0e10cSrcweir     }
1348cdf0e10cSrcweir     return c;
1349cdf0e10cSrcweir }
1350cdf0e10cSrcweir 
SkipRec()1351cdf0e10cSrcweir void SwLayCacheIoImpl::SkipRec()
1352cdf0e10cSrcweir {
1353cdf0e10cSrcweir     sal_uInt8 c = Peek();
1354cdf0e10cSrcweir     OpenRec( c );
1355cdf0e10cSrcweir     pStream->Seek( aRecSizes[aRecSizes.Count()-1] );
1356cdf0e10cSrcweir     CloseRec( c );
1357cdf0e10cSrcweir }
1358cdf0e10cSrcweir 
OpenFlagRec()1359cdf0e10cSrcweir sal_uInt8 SwLayCacheIoImpl::OpenFlagRec()
1360cdf0e10cSrcweir {
1361cdf0e10cSrcweir     ASSERT( !bWriteMode, "OpenFlagRec illegal in write  mode" );
1362cdf0e10cSrcweir     sal_uInt8 cFlags;
1363cdf0e10cSrcweir     *pStream >> cFlags;
1364cdf0e10cSrcweir     nFlagRecEnd = pStream->Tell() + ( cFlags & 0x0F );
1365cdf0e10cSrcweir     return (cFlags >> 4);
1366cdf0e10cSrcweir }
1367cdf0e10cSrcweir 
OpenFlagRec(sal_uInt8 nFlags,sal_uInt8 nLen)1368cdf0e10cSrcweir void SwLayCacheIoImpl::OpenFlagRec( sal_uInt8 nFlags, sal_uInt8 nLen )
1369cdf0e10cSrcweir {
1370cdf0e10cSrcweir     ASSERT( bWriteMode, "OpenFlagRec illegal in read  mode" );
1371cdf0e10cSrcweir     ASSERT( (nFlags & 0xF0) == 0, "illegal flags set" );
1372cdf0e10cSrcweir     ASSERT( nLen < 16, "wrong flag record length" );
1373cdf0e10cSrcweir     sal_uInt8 cFlags = (nFlags << 4) + nLen;
1374cdf0e10cSrcweir     *pStream << cFlags;
1375cdf0e10cSrcweir     nFlagRecEnd = pStream->Tell() + nLen;
1376cdf0e10cSrcweir }
1377cdf0e10cSrcweir 
CloseFlagRec()1378cdf0e10cSrcweir void SwLayCacheIoImpl::CloseFlagRec()
1379cdf0e10cSrcweir {
1380cdf0e10cSrcweir     if( bWriteMode )
1381cdf0e10cSrcweir     {
1382cdf0e10cSrcweir         ASSERT( pStream->Tell() == nFlagRecEnd, "Wrong amount of data written" );
1383cdf0e10cSrcweir     }
1384cdf0e10cSrcweir     else
1385cdf0e10cSrcweir     {
1386cdf0e10cSrcweir         ASSERT( pStream->Tell() <= nFlagRecEnd, "To many data read" );
1387cdf0e10cSrcweir         if( pStream->Tell() != nFlagRecEnd )
1388cdf0e10cSrcweir             pStream->Seek( nFlagRecEnd );
1389cdf0e10cSrcweir     }
1390cdf0e10cSrcweir }
1391*083d9fe7Smseidel 
1392*083d9fe7Smseidel /* vim: set noet sw=4 ts=4: */
1393