Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / layout / softpagebreak.cxx
blob87ba7c24e653315933106257a46b432ff11ab497
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <txtfrm.hxx>
21 #include <pagefrm.hxx>
22 #include <swtable.hxx>
23 #include <frmfmt.hxx>
24 #include <rowfrm.hxx>
25 #include <tabfrm.hxx>
26 #include <calbck.hxx>
27 #include <ndtxt.hxx>
29 void SwTextNode::fillSoftPageBreakList( SwSoftPageBreakList& rBreak ) const
31 SwIterator<SwTextFrame, SwTextNode, sw::IteratorMode::UnwrapMulti> aIter(*this);
32 for( const SwTextFrame *pFrame = aIter.First(); pFrame; pFrame = aIter.Next() )
34 // No soft page break in header or footer
35 if( pFrame->FindFooterOrHeader() || pFrame->IsInFly() )
36 return;
37 // No soft page break if I'm not the first frame in my layout frame
38 if( pFrame->GetIndPrev() )
39 continue;
40 const SwPageFrame* pPage = pFrame->FindPageFrame();
41 // No soft page break at the first page
42 if( pPage && pPage->GetPrev() )
44 const SwContentFrame* pFirst2 = pPage->FindFirstBodyContent();
45 // Special handling for content frame in table frames
46 if( pFrame->IsInTab() )
48 // No soft page break if I'm in a table but the first content frame
49 // at my page is not in a table
50 if( !pFirst2 || !pFirst2->IsInTab() )
51 continue;
52 const SwLayoutFrame *pRow = pFrame->GetUpper();
53 // Looking for the "most upper" row frame,
54 // skipping sub tables and/or table in table
55 while( !pRow->IsRowFrame() || !pRow->GetUpper()->IsTabFrame() ||
56 pRow->GetUpper()->GetUpper()->IsInTab() )
57 pRow = pRow->GetUpper();
58 const SwTabFrame *pTab = pRow->FindTabFrame();
59 // For master tables the soft page break will exported at the table row,
60 // not at the content frame.
61 // If the first content is outside my table frame, no soft page break.
62 if( !pTab->IsFollow() || !pTab->IsAnLower( pFirst2 ) )
63 continue;
64 // Only content of non-heading-rows can get a soft page break
65 const SwFrame* pFirstRow = pTab->GetFirstNonHeadlineRow();
66 // If there's no follow flow line, the soft page break will be
67 // exported at the row, not at the content.
68 if( pRow == pFirstRow &&
69 pTab->FindMaster()->HasFollowFlowLine() )
71 // Now we have the row which causes a new page,
72 // this row is a follow flow line and therefore cannot get
73 // the soft page break itself.
74 // Every first content frame of every cell frame in this row
75 // will get the soft page break
76 const SwFrame* pCell = pRow->Lower();
77 while( pCell )
79 pFirst2 = static_cast<const SwLayoutFrame*>(pCell)->ContainsContent();
80 if( pFirst2 == pFrame )
81 { // Here we are: a first content inside a cell
82 // inside the split row => soft page break
83 auto const pos(pFrame->MapViewToModel(pFrame->GetOffset()));
84 if (pos.first == this)
86 rBreak.insert(pos.second);
88 break;
90 pCell = pCell->GetNext();
94 else // No soft page break if there's a "hard" page break attribute
95 if( pFirst2 == pFrame && !pFrame->IsPageBreak( true ) )
97 auto const pos(pFrame->MapViewToModel(pFrame->GetOffset()));
98 if (pos.first == this)
99 { // in the !Show case, we have to iterate over the merged
100 // SwTextFrame for every node
101 rBreak.insert(pos.second);
108 bool SwTableLine::hasSoftPageBreak() const
110 // No soft page break for sub tables
111 if( GetUpper() || !GetFrameFormat() )
112 return false;
113 SwIterator<SwRowFrame,SwFormat> aIter( *GetFrameFormat() );
114 for( SwRowFrame* pLast = aIter.First(); pLast; pLast = aIter.Next() )
116 if( pLast->GetTabLine() == this )
118 const SwTabFrame* pTab = pLast->FindTabFrame();
119 // No soft page break for
120 // tables with prevs, i.e. if the frame is not the first in its layout frame
121 // tables in footer or header
122 // tables in flies
123 // inner tables of nested tables
124 // master table frames with "hard" page break attribute
125 if( pTab->GetIndPrev() || pTab->FindFooterOrHeader()
126 || pTab->IsInFly() || pTab->GetUpper()->IsInTab() ||
127 ( !pTab->IsFollow() && pTab->IsPageBreak( true ) ) )
128 return false;
129 const SwPageFrame* pPage = pTab->FindPageFrame();
130 // No soft page break at the first page of the document
131 if( pPage && !pPage->GetPrev() )
132 return false;
133 const SwContentFrame* pFirst = pPage ? pPage->FindFirstBodyContent() : nullptr;
134 // No soft page break for
135 // tables which does not contain the first body content of the page
136 if( !pFirst || !pTab->IsAnLower( pFirst->FindTabFrame() ) )
137 return false;
138 // The row which could get a soft page break must be either the first
139 // row of a master table frame or the first "non-headline-row" of a
140 // follow table frame...
141 const SwFrame* pRow = pTab->IsFollow() ?
142 pTab->GetFirstNonHeadlineRow() : pTab->Lower();
143 if( pRow == pLast )
145 // The last check: no soft page break for "follow" table lines
146 return !pTab->IsFollow() || !pTab->FindMaster()->HasFollowFlowLine();
148 return false;
151 return false;
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */