Add a comment to clarify what kind of inputs the class handles
[LibreOffice.git] / sw / source / core / inc / flowfrm.hxx
blobc8ca0b55cd0692dfb9681bebd38c6b700c07f66f
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 #ifndef INCLUDED_SW_SOURCE_CORE_INC_FLOWFRM_HXX
21 #define INCLUDED_SW_SOURCE_CORE_INC_FLOWFRM_HXX
23 #include "frame.hxx"
24 #include "layfrm.hxx"
25 #include <swtypes.hxx>
27 class SvxFormatKeepItem;
28 class SvxFormatBreakItem;
29 class SwPageFrame;
30 class SwRect;
31 class SwBorderAttrs;
32 class SwDoc;
33 class SwNode;
34 class SwNodeIndex;
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 - too high additional costs, that we IMHO are not able to
52 afford nowadays.
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
57 its own this-pointer.
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 * );
66 // #i44049#
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;
77 SwFrame& m_rThis;
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
92 upper space
94 #i11860#
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
103 the previous frame
105 #i11860#
107 SwTwips GetUpperSpaceAmountConsideredForPrevFrame() const;
109 /** method to determine the upper space amount, which is considered for
110 the page grid
112 #i11860#
114 SwTwips GetUpperSpaceAmountConsideredForPageGrid_(
115 const SwTwips _nUpperSpaceWithoutGrid ) const;
117 protected:
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
133 0: no overlapping
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;
148 public:
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 SwFrame * FindPrevIgnoreHidden() const;
188 SwFrame * FindNextIgnoreHidden() const;
190 bool HasLockedFollow() const;
192 bool HasParaSpaceAtPages( bool bSct ) const;
194 /** method to determine the upper space hold by the frame
196 #i11860#
198 @param _bConsiderGrid
199 optional input parameter - consider the page grid while calculating?
201 SwTwips CalcUpperSpace( const SwBorderAttrs *pAttrs = nullptr,
202 const SwFrame* pPr = nullptr,
203 const bool _bConsiderGrid = true ) const;
205 /** method to determine the upper space amount, which is considered for
206 the previous frame and the page grid, if option 'Use former object
207 positioning' is OFF
209 #i11860#
211 SwTwips GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid() const;
213 /** calculation of lower space */
214 SwTwips CalcLowerSpace( const SwBorderAttrs* _pAttrs = nullptr ) const;
216 /** calculation of the additional space to be considered, if flow frame
217 is the last inside a table cell
219 #i26250
221 @param _pAttrs
222 optional input parameter - border attributes of the flow frame.
223 Used for optimization, if caller has already determined the border
224 attributes.
226 @return SwTwips
228 SwTwips CalcAddLowerSpaceAsLastInTableCell(
229 const SwBorderAttrs* _pAttrs = nullptr ) const;
231 void CheckKeep();
233 void SetFlyLock( bool bNew ){ m_bFlyLock = bNew; }
234 bool IsFlyLock() const { return m_bFlyLock; }
236 bool ForbiddenForFootnoteCntFwd() const;
238 // Casting of a Frame into a FlowFrame (if it is one, otherwise 0)
239 // These methods need to be customized in subclasses!
240 static SwFlowFrame *CastFlowFrame( SwFrame *pFrame );
241 static const SwFlowFrame *CastFlowFrame( const SwFrame *pFrame );
244 inline bool SwFlowFrame::IsFwdMoveAllowed() const
246 return m_rThis.GetIndPrev() != nullptr;
249 //use this to protect a SwLayoutFrame for a given scope from getting merged with
250 //its neighbour and thus deleted
251 class FlowFrameJoinLockGuard
253 private:
254 SwFlowFrame *m_pFlow;
255 bool m_bOldJoinLocked;
256 public:
257 //JoinLock pParent for the lifetime of the Cut/Paste call, etc. to avoid
258 //SwSectionFrame::MergeNext removing the pParent we're trying to reparent
259 //into
260 FlowFrameJoinLockGuard(SwLayoutFrame* pFrame)
262 m_pFlow = SwFlowFrame::CastFlowFrame(pFrame);
263 if (m_pFlow)
265 m_bOldJoinLocked = m_pFlow->IsJoinLocked();
266 m_pFlow->LockJoin();
268 else
270 m_bOldJoinLocked = false;
274 ~FlowFrameJoinLockGuard()
276 if (m_pFlow && !m_bOldJoinLocked)
277 m_pFlow->UnlockJoin();
281 #endif
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */