update dev300-m58
[ooovba.git] / sw / source / core / layout / softpagebreak.cxx
blob40ac959ee0e6327ba0c723c6adfb76387e498848
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: softpagebreak.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #include "ndtxt.hxx"
35 #include "txtfrm.hxx"
36 #include "pagefrm.hxx"
37 #include "swtable.hxx"
38 #include "frmfmt.hxx"
39 #include "rowfrm.hxx"
40 #include "tabfrm.hxx"
42 void SwTxtNode::fillSoftPageBreakList( SwSoftPageBreakList& rBreak ) const
44 SwClientIter aIter( const_cast<SwTxtNode&>(*this) );
45 for( const SwTxtFrm *pFrm = (const SwTxtFrm*)aIter.First( TYPE(SwTxtFrm) );
46 pFrm; pFrm = (const SwTxtFrm*)aIter.Next() )
48 // No soft page break in header or footer
49 if( pFrm->FindFooterOrHeader() || pFrm->IsInFly() )
50 return;
51 // No soft page break if I'm not the first frame in my layout frame
52 if( pFrm->GetIndPrev() )
53 continue;
54 const SwPageFrm* pPage = pFrm->FindPageFrm();
55 // No soft page break at the first page
56 if( pPage && pPage->GetPrev() )
58 const SwCntntFrm* pFirst2 = pPage->FindFirstBodyCntnt();
59 // Special handling for content frame in table frames
60 if( pFrm->IsInTab() )
62 // No soft page break if I'm in a table but the first content frame
63 // at my page is not in a table
64 if( !pFirst2->IsInTab() )
65 continue;
66 const SwLayoutFrm *pRow = pFrm->GetUpper();
67 // Looking for the "most upper" row frame,
68 // skipping sub tables and/or table in table
69 while( !pRow->IsRowFrm() || !pRow->GetUpper()->IsTabFrm() ||
70 pRow->GetUpper()->GetUpper()->IsInTab() )
71 pRow = pRow->GetUpper();
72 const SwTabFrm *pTab = pRow->FindTabFrm();
73 // For master tables the soft page break will exported at the table row,
74 // not at the content frame.
75 // If the first content is outside my table frame, no soft page break.
76 if( !pTab->IsFollow() || !pTab->IsAnLower( pFirst2 ) )
77 continue;
78 // Only content of non-heading-rows can get a soft page break
79 const SwFrm* pFirstRow = pTab->GetFirstNonHeadlineRow();
80 // If there's no follow flow line, the soft page break will be
81 // exported at the row, not at the content.
82 if( pRow == pFirstRow &&
83 pTab->FindMaster( false )->HasFollowFlowLine() )
85 // Now we have the row which causes a new page,
86 // this row is a follow flow line and therefor cannot get
87 // the soft page break itself.
88 // Every first content frame of every cell frane in this row
89 // will get the soft page break
90 const SwFrm* pCell = pRow->Lower();
91 while( pCell )
93 pFirst2 = static_cast<const SwLayoutFrm*>(pCell)->ContainsCntnt();
94 if( pFirst2 == pFrm )
95 { // Here we are: a first content inside a cell
96 // inside the splitted row => soft page break
97 rBreak.insert( pFrm->GetOfst() );
98 break;
100 pCell = pCell->GetNext();
104 else // No soft page break if there's a "hard" page break attribute
105 if( pFirst2 == pFrm && !pFrm->IsPageBreak( TRUE ) )
106 rBreak.insert( pFrm->GetOfst() );
111 bool SwTableLine::hasSoftPageBreak() const
113 // No soft page break for sub tables
114 if( GetUpper() || !GetFrmFmt() )
115 return false;
116 SwClientIter aIter( *GetFrmFmt() );
117 for( SwClient* pLast = aIter.First( TYPE( SwFrm ) ); pLast;
118 pLast = aIter.Next() )
120 if( ((SwRowFrm*)pLast)->GetTabLine() == this )
122 const SwTabFrm* pTab = static_cast<SwRowFrm*>(pLast)->FindTabFrm();
123 // No soft page break for
124 // tables with prevs, i.e. if the frame is not the first in its layout frame
125 // tables in footer or header
126 // tables in flies
127 // inner tables of nested tables
128 // master table frames with "hard" page break attribute
129 if( pTab->GetIndPrev() || pTab->FindFooterOrHeader()
130 || pTab->IsInFly() || pTab->GetUpper()->IsInTab() ||
131 ( !pTab->IsFollow() && pTab->IsPageBreak( TRUE ) ) )
132 return false;
133 const SwPageFrm* pPage = pTab->FindPageFrm();
134 // No soft page break at the first page of the document
135 if( pPage && !pPage->GetPrev() )
136 return false;
137 const SwCntntFrm* pFirst = pPage->FindFirstBodyCntnt();
138 // No soft page break for
139 // tables which does not contain the first body content of the page
140 if( !pFirst || !pTab->IsAnLower( pFirst->FindTabFrm() ) )
141 return false;
142 // The row which could get a soft page break must be either the first
143 // row of a master table frame or the first "non-headline-row" of a
144 // follow table frame...
145 const SwFrm* pRow = pTab->IsFollow() ?
146 pTab->GetFirstNonHeadlineRow() : pTab->Lower();
147 if( pRow == pLast )
149 // The last check: no soft page break for "follow" table lines
150 if( pTab->IsFollow() && pTab->FindMaster( false )->HasFollowFlowLine() )
151 return false;
152 return true;
154 return false;
157 return false;