1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*efeef26fSAndrew Rist  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19*efeef26fSAndrew Rist  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "ndtxt.hxx"
28cdf0e10cSrcweir #include "txtfrm.hxx"
29cdf0e10cSrcweir #include "pagefrm.hxx"
30cdf0e10cSrcweir #include "swtable.hxx"
31cdf0e10cSrcweir #include "frmfmt.hxx"
32cdf0e10cSrcweir #include "rowfrm.hxx"
33cdf0e10cSrcweir #include "tabfrm.hxx"
34cdf0e10cSrcweir #include "switerator.hxx"
35cdf0e10cSrcweir 
fillSoftPageBreakList(SwSoftPageBreakList & rBreak) const36cdf0e10cSrcweir void SwTxtNode::fillSoftPageBreakList( SwSoftPageBreakList& rBreak ) const
37cdf0e10cSrcweir {
38cdf0e10cSrcweir     SwIterator<SwTxtFrm,SwTxtNode> aIter( *this );
39cdf0e10cSrcweir     for( const SwTxtFrm *pFrm = aIter.First(); pFrm; pFrm = aIter.Next() )
40cdf0e10cSrcweir     {
41cdf0e10cSrcweir         // No soft page break in header or footer
42cdf0e10cSrcweir         if( pFrm->FindFooterOrHeader() || pFrm->IsInFly() )
43cdf0e10cSrcweir             return;
44cdf0e10cSrcweir         // No soft page break if I'm not the first frame in my layout frame
45cdf0e10cSrcweir         if( pFrm->GetIndPrev() )
46cdf0e10cSrcweir             continue;
47cdf0e10cSrcweir         const SwPageFrm* pPage = pFrm->FindPageFrm();
48cdf0e10cSrcweir         // No soft page break at the first page
49cdf0e10cSrcweir         if( pPage && pPage->GetPrev() )
50cdf0e10cSrcweir         {
51cdf0e10cSrcweir             const SwCntntFrm* pFirst2 = pPage->FindFirstBodyCntnt();
52cdf0e10cSrcweir             // Special handling for content frame in table frames
53cdf0e10cSrcweir             if( pFrm->IsInTab() )
54cdf0e10cSrcweir             {
55cdf0e10cSrcweir                 // No soft page break if I'm in a table but the first content frame
56cdf0e10cSrcweir                 // at my page is not in a table
57cdf0e10cSrcweir                 if( !pFirst2->IsInTab() )
58cdf0e10cSrcweir                     continue;
59cdf0e10cSrcweir                 const SwLayoutFrm *pRow = pFrm->GetUpper();
60cdf0e10cSrcweir                 // Looking for the "most upper" row frame,
61cdf0e10cSrcweir                 // skipping sub tables and/or table in table
62cdf0e10cSrcweir                 while( !pRow->IsRowFrm() || !pRow->GetUpper()->IsTabFrm() ||
63cdf0e10cSrcweir                     pRow->GetUpper()->GetUpper()->IsInTab() )
64cdf0e10cSrcweir                     pRow = pRow->GetUpper();
65cdf0e10cSrcweir                 const SwTabFrm *pTab = pRow->FindTabFrm();
66cdf0e10cSrcweir                 // For master tables the soft page break will exported at the table row,
67cdf0e10cSrcweir                 // not at the content frame.
68cdf0e10cSrcweir                 // If the first content is outside my table frame, no soft page break.
69cdf0e10cSrcweir                 if( !pTab->IsFollow() || !pTab->IsAnLower( pFirst2 ) )
70cdf0e10cSrcweir                     continue;
71cdf0e10cSrcweir                 // Only content of non-heading-rows can get a soft page break
72cdf0e10cSrcweir                 const SwFrm* pFirstRow = pTab->GetFirstNonHeadlineRow();
73cdf0e10cSrcweir                 // If there's no follow flow line, the soft page break will be
74cdf0e10cSrcweir                 // exported at the row, not at the content.
75cdf0e10cSrcweir                 if( pRow == pFirstRow &&
76cdf0e10cSrcweir                     pTab->FindMaster( false )->HasFollowFlowLine() )
77cdf0e10cSrcweir                 {
78cdf0e10cSrcweir                     // Now we have the row which causes a new page,
79cdf0e10cSrcweir                     // this row is a follow flow line and therefor cannot get
80cdf0e10cSrcweir                     // the soft page break itself.
81cdf0e10cSrcweir                     // Every first content frame of every cell frane in this row
82cdf0e10cSrcweir                     // will get the soft page break
83cdf0e10cSrcweir                     const SwFrm* pCell = pRow->Lower();
84cdf0e10cSrcweir                     while( pCell )
85cdf0e10cSrcweir                     {
86cdf0e10cSrcweir                         pFirst2 = static_cast<const SwLayoutFrm*>(pCell)->ContainsCntnt();
87cdf0e10cSrcweir                         if( pFirst2 == pFrm )
88cdf0e10cSrcweir                         {   // Here we are: a first content inside a cell
89cdf0e10cSrcweir                             // inside the splitted row => soft page break
90cdf0e10cSrcweir                             rBreak.insert( pFrm->GetOfst() );
91cdf0e10cSrcweir                             break;
92cdf0e10cSrcweir                         }
93cdf0e10cSrcweir                         pCell = pCell->GetNext();
94cdf0e10cSrcweir                     }
95cdf0e10cSrcweir                 }
96cdf0e10cSrcweir             }
97cdf0e10cSrcweir             else // No soft page break if there's a "hard" page break attribute
98cdf0e10cSrcweir             if( pFirst2 == pFrm && !pFrm->IsPageBreak( sal_True ) )
99cdf0e10cSrcweir                 rBreak.insert( pFrm->GetOfst() );
100cdf0e10cSrcweir         }
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
hasSoftPageBreak() const104cdf0e10cSrcweir bool SwTableLine::hasSoftPageBreak() const
105cdf0e10cSrcweir {
106cdf0e10cSrcweir     // No soft page break for sub tables
107cdf0e10cSrcweir     if( GetUpper() || !GetFrmFmt() )
108cdf0e10cSrcweir         return false;
109cdf0e10cSrcweir 	SwIterator<SwRowFrm,SwFmt> aIter( *GetFrmFmt() );
110cdf0e10cSrcweir 	for( SwRowFrm* pLast = aIter.First(); pLast; pLast = aIter.Next() )
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir 		if( pLast->GetTabLine() == this )
113cdf0e10cSrcweir 		{
114cdf0e10cSrcweir             const SwTabFrm* pTab = pLast->FindTabFrm();
115cdf0e10cSrcweir             // No soft page break for
116cdf0e10cSrcweir             //   tables with prevs, i.e. if the frame is not the first in its layout frame
117cdf0e10cSrcweir             //   tables in footer or header
118cdf0e10cSrcweir             //   tables in flies
119cdf0e10cSrcweir             //   inner tables of nested tables
120cdf0e10cSrcweir             //   master table frames with "hard" page break attribute
121cdf0e10cSrcweir             if( pTab->GetIndPrev() || pTab->FindFooterOrHeader()
122cdf0e10cSrcweir                 || pTab->IsInFly() || pTab->GetUpper()->IsInTab() ||
123cdf0e10cSrcweir                 ( !pTab->IsFollow() && pTab->IsPageBreak( sal_True ) ) )
124cdf0e10cSrcweir                 return false;
125cdf0e10cSrcweir             const SwPageFrm* pPage = pTab->FindPageFrm();
126cdf0e10cSrcweir             // No soft page break at the first page of the document
127cdf0e10cSrcweir             if( pPage && !pPage->GetPrev() )
128cdf0e10cSrcweir                 return false;
129cdf0e10cSrcweir             const SwCntntFrm* pFirst = pPage->FindFirstBodyCntnt();
130cdf0e10cSrcweir             // No soft page break for
131cdf0e10cSrcweir             //   tables which does not contain the first body content of the page
132cdf0e10cSrcweir             if( !pFirst || !pTab->IsAnLower( pFirst->FindTabFrm() ) )
133cdf0e10cSrcweir                 return false;
134cdf0e10cSrcweir             // The row which could get a soft page break must be either the first
135cdf0e10cSrcweir             // row of a master table frame or the first "non-headline-row" of a
136cdf0e10cSrcweir             // follow table frame...
137cdf0e10cSrcweir             const SwFrm* pRow = pTab->IsFollow() ?
138cdf0e10cSrcweir                 pTab->GetFirstNonHeadlineRow() : pTab->Lower();
139cdf0e10cSrcweir             if( pRow == pLast )
140cdf0e10cSrcweir             {
141cdf0e10cSrcweir                 // The last check: no soft page break for "follow" table lines
142cdf0e10cSrcweir                 if( pTab->IsFollow() && pTab->FindMaster( false )->HasFollowFlowLine() )
143cdf0e10cSrcweir                     return false;
144cdf0e10cSrcweir                 return true;
145cdf0e10cSrcweir             }
146cdf0e10cSrcweir             return false;
147cdf0e10cSrcweir         }
148cdf0e10cSrcweir     }
149cdf0e10cSrcweir     return false;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152