1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_SW_SOURCE_CORE_INC_FLOWFRM_HXX
21 #define INCLUDED_SW_SOURCE_CORE_INC_FLOWFRM_HXX
25 #include <swtypes.hxx>
27 class SvxFormatKeepItem
;
28 class SvxFormatBreakItem
;
36 /** Base class that provides the general functionalities for frames that are
37 allowed at page breaks (flow) and shall continue on the next page (can be
38 split), e.g. paragraphs (ContentFrame) or tables (TabFrame).
40 Some parts of these functionalities are implemented in FlowFrame while the
41 specific ones are done in the corresponding Frame classes. The FlowFrame has to
42 be seen as a base class. As such it is no Frame by itself and thus no direct
43 instances of FlowFrame can exist.
45 Actually it is not even a real Frame. The obvious implementation would be a
46 FlowFrame that is virtually inherited from SwFrame and that works with its own
47 member data. Further classes would need to inherit from FlowFrame and (via
48 multiple base classes since the class tree splits exactly at the branch
49 from SwFrame to SwContentFrame and SwLayoutFrame) also virtually from SwFrame as
50 well. Unfortunately, this leads - besides problems with compilers and
51 debugging programs - to high additional costs, that we IMHO are not able to
54 Hence, we use another technique: A FlowFrame keeps a reference to a SwFrame
55 - which it is actually itself - and they are friends. As a result, the
56 FlowFrame can work with the reference to the SwFrame instead of working with
59 class SAL_DLLPUBLIC_RTTI
SAL_LOPLUGIN_ANNOTATE("crosscast") SwFlowFrame
61 // PrepareMake is allowed to lock/unlock (robustness)
62 friend inline void PrepareLock ( SwFlowFrame
* );
63 friend inline void PrepareUnlock( SwFlowFrame
* );
64 friend inline void TableSplitRecalcLock( SwFlowFrame
* );
65 friend inline void TableSplitRecalcUnlock( SwFlowFrame
* );
67 friend class SwObjectFormatterTextFrame
;
68 friend class FlowFrameJoinLockGuard
;
70 // TableSel is allowed to reset the follow-bit
71 friend inline void UnsetFollow( SwFlowFrame
*pFlow
);
73 friend void MakeFrames( SwDoc
*, SwNode
&, SwNode
& );
75 friend class SwNode2LayImpl
;
79 // helper methods for MoveSubTree()
80 static SwLayoutFrame
*CutTree( SwFrame
* );
81 static bool PasteTree( SwFrame
*, SwLayoutFrame
*, SwFrame
*, SwFrame
* );
83 /** indicates that a backward move was done over multiple pages
85 Needed for the interaction of _GetPrevxxx and MoveBwd so that multiple
86 pages can be skipped at the same time. In addition, it is evaluated by
87 the MoveBwd() method in TabFrame.
89 static bool s_bMoveBwdJump
;
91 /** helper method to determine previous frame for calculation of the
96 @param _pProposedPrevFrame
97 optional input parameter - pointer to frame, which should be used
98 instead of the direct previous frame.
100 const SwFrame
* GetPrevFrameForUpperSpaceCalc_( const SwFrame
* _pProposedPrevFrame
= nullptr ) const;
102 /** method to determine the upper space amount, which is considered for
107 SwTwips
GetUpperSpaceAmountConsideredForPrevFrame() const;
109 /** method to determine the upper space amount, which is considered for
114 SwTwips
GetUpperSpaceAmountConsideredForPageGrid_(
115 const SwTwips _nUpperSpaceWithoutGrid
) const;
118 SwFlowFrame
*m_pFollow
;
119 SwFlowFrame
*m_pPrecede
;
121 bool m_bLockJoin
:1; // if true than joins (and thus deletes) are prohibited!
122 bool m_bUndersized
:1; // I am smaller than needed
123 bool m_bFlyLock
:1; // stop positioning of at-character flyframes
125 // checks if forward flow makes sense to prevent infinite moves
126 inline bool IsFwdMoveAllowed() const;
127 // #i44049# - method <CalcContent(..)> has to check this property.
128 friend void CalcContent( SwLayoutFrame
*pLay
, bool bNoColl
);
129 bool IsKeepFwdMoveAllowed( bool bIgnoreMyOwnKeepValue
= false ); // like above, forward flow for Keep.
131 /** method to determine overlapping of an object that requests floating
134 1: objects that are anchored at the FlowFrame overlap
135 2: objects that are anchored somewhere else overlap
136 3: both types of objects overlap
138 sal_uInt8
BwdMoveNecessary( const SwPageFrame
*pPage
, const SwRect
&rRect
);
140 void LockJoin() { m_bLockJoin
= true; }
141 void UnlockJoin() { m_bLockJoin
= false; }
143 bool CheckMoveFwd( bool& rbMakePage
, bool bKeep
, bool bIgnoreMyOwnKeepValue
);
144 bool MoveFwd( bool bMakePage
, bool bPageBreak
, bool bMoveAlways
= false );
145 bool MoveBwd( bool &rbReformat
);
146 virtual bool ShouldBwdMoved( SwLayoutFrame
*pNewUpper
, bool &rReformat
)=0;
149 SwFlowFrame( SwFrame
&rFrame
);
150 virtual ~SwFlowFrame();
152 const SwFrame
& GetFrame() const { return m_rThis
; }
153 SwFrame
& GetFrame() { return m_rThis
; }
155 static bool IsMoveBwdJump() { return s_bMoveBwdJump
; }
156 static void SetMoveBwdJump( bool bNew
){ s_bMoveBwdJump
= bNew
; }
158 void SetUndersized( const bool bNew
) { m_bUndersized
= bNew
; }
159 bool IsUndersized() const { return m_bUndersized
; }
161 bool IsPrevObjMove() const;
163 /** hook tree onto new parent with minimal operations and notifications */
164 void MoveSubTree( SwLayoutFrame
* pParent
, SwFrame
* pSibling
= nullptr );
166 bool HasFollow() const { return m_pFollow
!= nullptr; }
167 bool IsFollow() const { return nullptr != m_pPrecede
; }
168 bool IsAnFollow( const SwFlowFrame
*pFlow
) const;
169 const SwFlowFrame
*GetFollow() const { return m_pFollow
; }
170 SwFlowFrame
*GetFollow() { return m_pFollow
; }
171 void SetFollow(SwFlowFrame
*const pFollow
);
173 const SwFlowFrame
*GetPrecede() const { return m_pPrecede
; }
174 SwFlowFrame
*GetPrecede() { return m_pPrecede
; }
176 bool IsJoinLocked() const { return m_bLockJoin
; }
177 bool IsAnyJoinLocked() const { return m_bLockJoin
|| HasLockedFollow(); }
179 bool IsPageBreak( bool bAct
) const;
180 bool IsColBreak( bool bAct
) const;
182 /** method to determine if a Keep needs to be considered (Breaks!) */
183 bool IsKeep(SvxFormatKeepItem
const& rKeep
,
184 SvxFormatBreakItem
const& rBreak
,
185 bool bBreakCheck
= false ) const;
187 bool HasLockedFollow() const;
189 bool HasParaSpaceAtPages( bool bSct
) const;
191 /** method to determine the upper space hold by the frame
195 @param _bConsiderGrid
196 optional input parameter - consider the page grid while calculating?
198 SwTwips
CalcUpperSpace( const SwBorderAttrs
*pAttrs
= nullptr,
199 const SwFrame
* pPr
= nullptr,
200 const bool _bConsiderGrid
= true ) const;
202 /** method to determine the upper space amount, which is considered for
203 the previous frame and the page grid, if option 'Use former object
208 SwTwips
GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid() const;
210 /** calculation of lower space */
211 SwTwips
CalcLowerSpace( const SwBorderAttrs
* _pAttrs
= nullptr ) const;
213 /** calculation of the additional space to be considered, if flow frame
214 is the last inside a table cell
219 optional input parameter - border attributes of the flow frame.
220 Used for optimization, if caller has already determined the border
225 SwTwips
CalcAddLowerSpaceAsLastInTableCell(
226 const SwBorderAttrs
* _pAttrs
= nullptr ) const;
230 void SetFlyLock( bool bNew
){ m_bFlyLock
= bNew
; }
231 bool IsFlyLock() const { return m_bFlyLock
; }
233 bool ForbiddenForFootnoteCntFwd() const;
235 // Casting of a Frame into a FlowFrame (if it is one, otherwise 0)
236 // These methods need to be customized in subclasses!
237 static SwFlowFrame
*CastFlowFrame( SwFrame
*pFrame
);
238 static const SwFlowFrame
*CastFlowFrame( const SwFrame
*pFrame
);
241 inline bool SwFlowFrame::IsFwdMoveAllowed() const
243 return m_rThis
.GetIndPrev() != nullptr;
246 //use this to protect a SwLayoutFrame for a given scope from getting merged with
247 //its neighbour and thus deleted
248 class FlowFrameJoinLockGuard
251 SwFlowFrame
*m_pFlow
;
252 bool m_bOldJoinLocked
;
254 //JoinLock pParent for the lifetime of the Cut/Paste call, etc. to avoid
255 //SwSectionFrame::MergeNext removing the pParent we're trying to reparent
257 FlowFrameJoinLockGuard(SwLayoutFrame
* pFrame
)
259 m_pFlow
= SwFlowFrame::CastFlowFrame(pFrame
);
262 m_bOldJoinLocked
= m_pFlow
->IsJoinLocked();
267 m_bOldJoinLocked
= false;
271 ~FlowFrameJoinLockGuard()
273 if (m_pFlow
&& !m_bOldJoinLocked
)
274 m_pFlow
->UnlockJoin();
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */