1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #include "ndtxt.hxx"
32 #include "txtfrm.hxx"
33 #include "pagefrm.hxx"
34 #include "swtable.hxx"
35 #include "frmfmt.hxx"
36 #include "rowfrm.hxx"
37 #include "tabfrm.hxx"
38 #include "switerator.hxx"
39 
40 void SwTxtNode::fillSoftPageBreakList( SwSoftPageBreakList& rBreak ) const
41 {
42     SwIterator<SwTxtFrm,SwTxtNode> aIter( *this );
43     for( const SwTxtFrm *pFrm = aIter.First(); pFrm; pFrm = aIter.Next() )
44     {
45         // No soft page break in header or footer
46         if( pFrm->FindFooterOrHeader() || pFrm->IsInFly() )
47             return;
48         // No soft page break if I'm not the first frame in my layout frame
49         if( pFrm->GetIndPrev() )
50             continue;
51         const SwPageFrm* pPage = pFrm->FindPageFrm();
52         // No soft page break at the first page
53         if( pPage && pPage->GetPrev() )
54         {
55             const SwCntntFrm* pFirst2 = pPage->FindFirstBodyCntnt();
56             // Special handling for content frame in table frames
57             if( pFrm->IsInTab() )
58             {
59                 // No soft page break if I'm in a table but the first content frame
60                 // at my page is not in a table
61                 if( !pFirst2->IsInTab() )
62                     continue;
63                 const SwLayoutFrm *pRow = pFrm->GetUpper();
64                 // Looking for the "most upper" row frame,
65                 // skipping sub tables and/or table in table
66                 while( !pRow->IsRowFrm() || !pRow->GetUpper()->IsTabFrm() ||
67                     pRow->GetUpper()->GetUpper()->IsInTab() )
68                     pRow = pRow->GetUpper();
69                 const SwTabFrm *pTab = pRow->FindTabFrm();
70                 // For master tables the soft page break will exported at the table row,
71                 // not at the content frame.
72                 // If the first content is outside my table frame, no soft page break.
73                 if( !pTab->IsFollow() || !pTab->IsAnLower( pFirst2 ) )
74                     continue;
75                 // Only content of non-heading-rows can get a soft page break
76                 const SwFrm* pFirstRow = pTab->GetFirstNonHeadlineRow();
77                 // If there's no follow flow line, the soft page break will be
78                 // exported at the row, not at the content.
79                 if( pRow == pFirstRow &&
80                     pTab->FindMaster( false )->HasFollowFlowLine() )
81                 {
82                     // Now we have the row which causes a new page,
83                     // this row is a follow flow line and therefor cannot get
84                     // the soft page break itself.
85                     // Every first content frame of every cell frane in this row
86                     // will get the soft page break
87                     const SwFrm* pCell = pRow->Lower();
88                     while( pCell )
89                     {
90                         pFirst2 = static_cast<const SwLayoutFrm*>(pCell)->ContainsCntnt();
91                         if( pFirst2 == pFrm )
92                         {   // Here we are: a first content inside a cell
93                             // inside the splitted row => soft page break
94                             rBreak.insert( pFrm->GetOfst() );
95                             break;
96                         }
97                         pCell = pCell->GetNext();
98                     }
99                 }
100             }
101             else // No soft page break if there's a "hard" page break attribute
102             if( pFirst2 == pFrm && !pFrm->IsPageBreak( sal_True ) )
103                 rBreak.insert( pFrm->GetOfst() );
104         }
105     }
106 }
107 
108 bool SwTableLine::hasSoftPageBreak() const
109 {
110     // No soft page break for sub tables
111     if( GetUpper() || !GetFrmFmt() )
112         return false;
113 	SwIterator<SwRowFrm,SwFmt> aIter( *GetFrmFmt() );
114 	for( SwRowFrm* pLast = aIter.First(); pLast; pLast = aIter.Next() )
115     {
116 		if( pLast->GetTabLine() == this )
117 		{
118             const SwTabFrm* pTab = pLast->FindTabFrm();
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( sal_True ) ) )
128                 return false;
129             const SwPageFrm* pPage = pTab->FindPageFrm();
130             // No soft page break at the first page of the document
131             if( pPage && !pPage->GetPrev() )
132                 return false;
133             const SwCntntFrm* pFirst = pPage->FindFirstBodyCntnt();
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->FindTabFrm() ) )
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 SwFrm* 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                 if( pTab->IsFollow() && pTab->FindMaster( false )->HasFollowFlowLine() )
147                     return false;
148                 return true;
149             }
150             return false;
151         }
152     }
153     return false;
154 }
155 
156