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