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