LibreOffice Module sw (master) 1
softpagebreak.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
28
30{
32 for( const SwTextFrame *pFrame = aIter.First(); pFrame; pFrame = aIter.Next() )
33 {
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() )
43 {
44 const SwContentFrame* pFirst2 = pPage->FindFirstBodyContent();
45 // Special handling for content frame in table frames
46 if( pFrame->IsInTab() )
47 {
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() )
70 {
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 )
78 {
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)
85 {
86 rBreak.insert(pos.second);
87 }
88 break;
89 }
90 pCell = pCell->GetNext();
91 }
92 }
93 }
94 else // No soft page break if there's a "hard" page break attribute
95 if( pFirst2 == pFrame && !pFrame->IsPageBreak( true ) )
96 {
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);
102 }
103 }
104 }
105 }
106}
107
109{
110 // No soft page break for sub tables
111 if( GetUpper() || !GetFrameFormat() )
112 return false;
114 for( SwRowFrame* pLast = aIter.First(); pLast; pLast = aIter.Next() )
115 {
116 if( pLast->GetTabLine() == this )
117 {
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 )
144 {
145 // The last check: no soft page break for "follow" table lines
146 return !pTab->IsFollow() || !pTab->FindMaster()->HasFollowFlowLine();
147 }
148 return false;
149 }
150 }
151 return false;
152}
153
154/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwContentFrame is the layout for content nodes: a common base class for text (paragraph) and non-text...
Definition: cntfrm.hxx:59
Base class of the Writer layout elements.
Definition: frame.hxx:315
bool IsRowFrame() const
Definition: frame.hxx:1228
SwFrame * GetIndPrev() const
Definition: frame.hxx:730
SwTabFrame * FindTabFrame()
Definition: frame.hxx:1105
SwFrame * GetNext()
Definition: frame.hxx:682
bool IsTabFrame() const
Definition: frame.hxx:1224
bool IsInTab() const
Definition: frame.hxx:961
bool IsInFly() const
Definition: frame.hxx:967
SwLayoutFrame * GetUpper()
Definition: frame.hxx:684
SwFrame * GetPrev()
Definition: frame.hxx:683
SwPageFrame * FindPageFrame()
Definition: frame.hxx:686
SwFrame * FindFooterOrHeader()
Definition: findfrm.cxx:633
TElementType * Next()
Definition: calbck.hxx:380
TElementType * First()
Definition: calbck.hxx:372
A layout frame is a frame that contains other frames (m_pLower), e.g. SwPageFrame or SwTabFrame.
Definition: layfrm.hxx:36
bool IsAnLower(const SwFrame *) const
Definition: findfrm.cxx:233
const SwFrame * Lower() const
Definition: layfrm.hxx:101
A page of the document layout.
Definition: pagefrm.hxx:60
SwContentFrame * FindFirstBodyContent()
Definition: pagefrm.hxx:359
SwRowFrame is one table row in the document layout.
Definition: rowfrm.hxx:29
SwTabFrame is one table in the document layout, containing rows (which contain cells).
Definition: tabfrm.hxx:49
SwTabFrame * FindMaster(bool bFirstMaster=false) const
Definition: flowfrm.cxx:798
SwRowFrame * GetFirstNonHeadlineRow() const
Definition: tabfrm.cxx:5985
bool HasFollowFlowLine() const
Definition: tabfrm.hxx:178
SwFrameFormat * GetFrameFormat()
Definition: swtable.hxx:398
bool hasSoftPageBreak() const
SwTableBox * GetUpper()
Definition: swtable.hxx:394
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:168
void fillSoftPageBreakList(SwSoftPageBreakList &rBreak) const
std::pair< const_iterator, bool > insert(Value &&x)
size_t pos