Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / layout / ssfrm.cxx
blobc36a7de33e5fec66c6d4e379f229e03099b472c1
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 <config_wasm_strip.h>
22 #include <pagefrm.hxx>
23 #include <rootfrm.hxx>
24 #include <dcontact.hxx>
25 #include <flyfrm.hxx>
26 #include <tabfrm.hxx>
27 #include <txtfrm.hxx>
28 #include <cellfrm.hxx>
29 #include <swtable.hxx>
30 #include <fmtfsize.hxx>
31 #include <editeng/boxitem.hxx>
32 #include <editeng/shaditem.hxx>
33 #include <IDocumentRedlineAccess.hxx>
34 #include <IDocumentMarkAccess.hxx>
35 #include <fmtclds.hxx>
36 #include <viewimp.hxx>
37 #include <sortedobjs.hxx>
38 #include <hints.hxx>
39 #include <frmtool.hxx>
40 #include <ndtxt.hxx>
41 #include <osl/diagnose.h>
43 // No inline cause we need the function pointers
44 tools::Long SwFrame::GetTopMargin() const
45 { return getFramePrintArea().Top(); }
46 tools::Long SwFrame::GetBottomMargin() const
47 { return getFrameArea().Height() -getFramePrintArea().Height() -getFramePrintArea().Top(); }
48 tools::Long SwFrame::GetLeftMargin() const
49 { return getFramePrintArea().Left(); }
50 tools::Long SwFrame::GetRightMargin() const
51 { return getFrameArea().Width() - getFramePrintArea().Width() - getFramePrintArea().Left(); }
52 tools::Long SwFrame::GetPrtLeft() const
53 { return getFrameArea().Left() + getFramePrintArea().Left(); }
54 tools::Long SwFrame::GetPrtBottom() const
55 { return getFrameArea().Top() + getFramePrintArea().Height() + getFramePrintArea().Top(); }
56 tools::Long SwFrame::GetPrtRight() const
57 { return getFrameArea().Left() + getFramePrintArea().Width() + getFramePrintArea().Left(); }
58 tools::Long SwFrame::GetPrtTop() const
59 { return getFrameArea().Top() + getFramePrintArea().Top(); }
61 bool SwFrame::SetMinLeft( tools::Long nDeadline )
63 SwTwips nDiff = nDeadline - getFrameArea().Left();
64 if( nDiff > 0 )
66 SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this);
67 aFrm.Left( nDeadline );
69 SwFrameAreaDefinition::FramePrintAreaWriteAccess aPrt(*this);
70 aPrt.Width( aPrt.Width() - nDiff );
72 return true;
74 return false;
77 bool SwFrame::SetMaxBottom( tools::Long nDeadline )
79 SwTwips nDiff = getFrameArea().Top() + getFrameArea().Height() - nDeadline;
80 if( nDiff > 0 )
82 SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this);
83 aFrm.Height( aFrm.Height() - nDiff );
85 SwFrameAreaDefinition::FramePrintAreaWriteAccess aPrt(*this);
86 aPrt.Height( aPrt.Height() - nDiff );
88 return true;
90 return false;
93 bool SwFrame::SetMaxRight( tools::Long nDeadline )
95 SwTwips nDiff = getFrameArea().Left() + getFrameArea().Width() - nDeadline;
96 if( nDiff > 0 )
98 SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this);
99 aFrm.Width( aFrm.Width() - nDiff );
101 SwFrameAreaDefinition::FramePrintAreaWriteAccess aPrt(*this);
102 aPrt.Width( aPrt.Width() - nDiff );
104 return true;
106 return false;
109 void SwFrame::MakeBelowPos( const SwFrame* pUp, const SwFrame* pPrv, bool bNotify )
111 SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this);
113 if( pPrv )
115 aFrm.Pos( pPrv->getFrameArea().Pos() );
116 aFrm.Pos().AdjustY(pPrv->getFrameArea().Height() );
118 else
120 aFrm.Pos( pUp->getFrameArea().Pos() );
121 aFrm.Pos() += pUp->getFramePrintArea().Pos();
124 if( bNotify )
126 aFrm.Pos().AdjustY(1 );
130 void SwFrame::MakeLeftPos( const SwFrame* pUp, const SwFrame* pPrv, bool bNotify )
132 SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this);
134 if( pPrv )
136 aFrm.Pos( pPrv->getFrameArea().Pos() );
137 aFrm.Pos().AdjustX( -(aFrm.Width()) );
139 else
141 aFrm.Pos( pUp->getFrameArea().Pos() );
142 aFrm.Pos() += pUp->getFramePrintArea().Pos();
143 aFrm.Pos().AdjustX(pUp->getFramePrintArea().Width() - aFrm.Width() );
146 if( bNotify )
148 aFrm.Pos().AdjustX( -1 );
152 void SwFrame::MakeRightPos( const SwFrame* pUp, const SwFrame* pPrv, bool bNotify )
154 SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this);
156 if( pPrv )
158 aFrm.Pos( pPrv->getFrameArea().Pos() );
159 aFrm.Pos().AdjustX(pPrv->getFrameArea().Width() );
161 else
163 aFrm.Pos( pUp->getFrameArea().Pos() );
164 aFrm.Pos() += pUp->getFramePrintArea().Pos();
167 if( bNotify )
169 aFrm.Pos().AdjustX(1 );
173 void SwFrame::SetTopBottomMargins( tools::Long nTop, tools::Long nBot )
175 SwFrameAreaDefinition::FramePrintAreaWriteAccess aPrt(*this);
176 aPrt.Top( nTop );
177 aPrt.Height( getFrameArea().Height() - nTop - nBot );
180 void SwFrame::SetLeftRightMargins( tools::Long nLeft, tools::Long nRight)
182 SwFrameAreaDefinition::FramePrintAreaWriteAccess aPrt(*this);
183 aPrt.Left( nLeft );
184 aPrt.Width( getFrameArea().Width() - nLeft - nRight );
187 void SwFrame::SetRightLeftMargins( tools::Long nRight, tools::Long nLeft)
189 SwFrameAreaDefinition::FramePrintAreaWriteAccess aPrt(*this);
190 aPrt.Left( nLeft );
191 aPrt.Width( getFrameArea().Width() - nLeft - nRight );
194 /// checks the layout direction and invalidates the lower frames recursively, if necessary.
195 void SwFrame::CheckDirChange()
197 bool bOldVert = mbVertical;
198 bool bOldR2L = mbRightToLeft;
199 SetInvalidVert( true );
200 mbInvalidR2L = true;
201 bool bChg = bOldR2L != IsRightToLeft();
202 bool bOldVertL2R = IsVertLR();
203 if( !(( IsVertical() != bOldVert ) || bChg || bOldVertL2R != IsVertLR()) )
204 return;
206 InvalidateAll();
207 if( IsLayoutFrame() )
209 // set minimum row height for vertical cells in horizontal table:
210 if ( IsCellFrame() && GetUpper() )
212 if ( IsVertical() != GetUpper()->IsVertical() &&
213 static_cast<SwCellFrame*>(this)->GetTabBox()->getRowSpan() == 1 )
215 enum {
216 MIN_VERT_CELL_HEIGHT = 1135
219 SwTableLine* pLine = const_cast<SwTableLine*>(static_cast<SwCellFrame*>(this)->GetTabBox()->GetUpper());
220 SwFrameFormat* pFrameFormat = pLine->GetFrameFormat();
221 SwFormatFrameSize aNew( pFrameFormat->GetFrameSize() );
222 if ( SwFrameSize::Fixed != aNew.GetHeightSizeType() )
223 aNew.SetHeightSizeType( SwFrameSize::Minimum );
224 if ( aNew.GetHeight() < MIN_VERT_CELL_HEIGHT )
225 aNew.SetHeight( MIN_VERT_CELL_HEIGHT );
226 SwDoc* pDoc = pFrameFormat->GetDoc();
227 pDoc->SetAttr( aNew, *pLine->ClaimFrameFormat() );
231 SwFrame* pFrame = static_cast<SwLayoutFrame*>(this)->Lower();
232 const SwFormatCol* pCol = nullptr;
233 SwLayoutFrame* pBody = nullptr;
234 if( pFrame )
236 if( IsPageFrame() )
238 // If we're a page frame and we change our layout direction,
239 // we have to look for columns and rearrange them.
240 pBody = static_cast<SwPageFrame*>(this)->FindBodyCont();
241 if(pBody && pBody->Lower() && pBody->Lower()->IsColumnFrame())
242 pCol = &static_cast<SwPageFrame*>(this)->GetFormat()->GetCol();
244 else if( pFrame->IsColumnFrame() )
246 pBody = static_cast<SwLayoutFrame*>(this);
247 const SwFrameFormat *pFormat = pBody->GetFormat();
248 if( pFormat )
249 pCol = &pFormat->GetCol();
252 while( pFrame )
254 pFrame->CheckDirChange();
255 pFrame = pFrame->GetNext();
257 if( pCol )
258 pBody->AdjustColumns( pCol, true );
260 else if( IsTextFrame() )
261 static_cast<SwTextFrame*>(this)->Prepare();
263 // #i31698# - notify anchored objects also for page frames.
264 // Remove code above for special handling of page frames
265 if ( !GetDrawObjs() )
266 return;
268 const SwSortedObjs *pObjs = GetDrawObjs();
269 const size_t nCnt = pObjs->size();
270 for ( size_t i = 0; i < nCnt; ++i )
272 SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
273 if( auto pFlyFrame = pAnchoredObj->DynCastFlyFrame() )
274 pFlyFrame->CheckDirChange();
275 else
277 // OD 2004-04-06 #i26791# - direct object
278 // positioning no longer needed. Instead
279 // invalidate
280 pAnchoredObj->InvalidateObjPos();
282 // #i31698# - update layout direction of
283 // anchored object
285 ::setContextWritingMode( pAnchoredObj->DrawObj(), pAnchoredObj->GetAnchorFrameContainingAnchPos() );
286 pAnchoredObj->UpdateLayoutDir();
291 /// returns the position for anchors based on frame direction
292 // OD 2004-03-10 #i11860# - consider lower space and line spacing of
293 // previous frame according to new option 'Use former object positioning'
294 Point SwFrame::GetFrameAnchorPos( bool bIgnoreFlysAnchoredAtThisFrame ) const
296 Point aAnchor = getFrameArea().Pos();
298 if ( ( IsVertical() && !IsVertLR() ) || IsRightToLeft() )
299 aAnchor.AdjustX(getFrameArea().Width() );
301 if ( IsTextFrame() )
303 SwTwips nBaseOfstForFly =
304 static_cast<const SwTextFrame*>(this)->GetBaseOffsetForFly( bIgnoreFlysAnchoredAtThisFrame );
305 if ( IsVertical() )
306 aAnchor.AdjustY(nBaseOfstForFly );
307 else
308 aAnchor.AdjustX(nBaseOfstForFly );
310 // OD 2004-03-10 #i11860# - if option 'Use former object positioning'
311 // is OFF, consider the lower space and the line spacing of the
312 // previous frame and the spacing considered for the page grid
313 const SwTextFrame* pThisTextFrame = static_cast<const SwTextFrame*>(this);
314 const SwTwips nUpperSpaceAmountConsideredForPrevFrameAndPageGrid =
315 pThisTextFrame->GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid();
316 if ( IsVertical() )
318 aAnchor.AdjustX( -nUpperSpaceAmountConsideredForPrevFrameAndPageGrid );
320 else
322 aAnchor.AdjustY(nUpperSpaceAmountConsideredForPrevFrameAndPageGrid );
326 return aAnchor;
329 void SwFrame::DestroyImpl()
331 mbInDtor = true;
333 // accessible objects for fly and cell frames have been already disposed
334 // by the destructors of the derived classes.
335 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
336 if (IsAccessibleFrame() && !(IsFlyFrame() || IsCellFrame())
337 && (GetDep() || IsTextFrame())) // sw_redlinehide: text frame may not have Dep!
339 assert(!IsTextFrame() || GetDep() || static_cast<SwTextFrame*>(this)->GetMergedPara());
340 const bool bInDocDtor = IsTabFrame() && static_cast<SwTabFrame*>(this)->GetFormat()->GetDoc()->IsInDtor();
341 SwRootFrame *pRootFrame = getRootFrame();
342 if( !bInDocDtor && pRootFrame && pRootFrame->IsAnyShellAccessible() )
344 SwViewShell *pVSh = pRootFrame->GetCurrShell();
345 if( pVSh && pVSh->Imp() )
347 OSL_ENSURE( !GetLower(), "Lowers should be dispose already!" );
348 pVSh->Imp()->DisposeAccessibleFrame( this );
352 #endif
354 if (!m_pDrawObjs)
355 return;
357 for (size_t i = m_pDrawObjs->size(); i; )
359 SwAnchoredObject* pAnchoredObj = (*m_pDrawObjs)[--i];
360 if ( auto pFlyFrame = pAnchoredObj->DynCastFlyFrame() )
362 SwFrame::DestroyFrame(pFlyFrame);
364 else
366 SdrObject* pSdrObj = pAnchoredObj->DrawObj();
367 SwDrawContact* pContact =
368 static_cast<SwDrawContact*>(pSdrObj->GetUserCall());
369 OSL_ENSURE( pContact,
370 "<SwFrame::~SwFrame> - missing contact for drawing object" );
371 if ( pContact )
373 pContact->DisconnectObjFromLayout( pSdrObj );
377 m_pDrawObjs.reset();
380 SwFrame::~SwFrame()
382 assert(m_isInDestroy); // check that only DestroySwFrame does "delete"
383 assert(!IsDeleteForbidden()); // check that it's not deleted while deletes are forbidden
384 #if OSL_DEBUG_LEVEL > 0
385 // JP 15.10.2001: for detection of access to deleted frames
386 mpRoot = reinterpret_cast<SwRootFrame*>(0x33333333);
387 #endif
390 void SwFrame::DestroyFrame(SwFrame *const pFrame)
392 if (pFrame)
394 pFrame->m_isInDestroy = true;
395 pFrame->DestroyImpl();
396 assert(pFrame->mbInDtor); // check that nobody forgot to call base class
397 delete pFrame;
401 const SwFrameFormat * SwLayoutFrame::GetFormat() const
403 return static_cast< const SwFrameFormat * >( GetDep() );
406 SwFrameFormat * SwLayoutFrame::GetFormat()
408 return static_cast< SwFrameFormat * >( GetDep() );
411 void SwLayoutFrame::SetFrameFormat(SwFrameFormat* pNew)
413 if(pNew == GetFormat())
414 return;
415 const SwFormatChg aOldFormat(GetFormat());
416 pNew->Add(this);
417 const SwFormatChg aNewFormat(pNew);
418 SwClientNotify(*pNew, sw::LegacyModifyHint(&aOldFormat, &aNewFormat));
421 SwContentFrame::SwContentFrame( SwContentNode * const pContent, SwFrame* pSib ) :
422 SwFrame( pContent, pSib ),
423 SwFlowFrame( static_cast<SwFrame&>(*this) )
425 assert(!getRootFrame()->HasMergedParas() || pContent->IsCreateFrameWhenHidingRedlines());
428 void SwContentFrame::DestroyImpl()
430 const SwContentNode* pCNd(dynamic_cast<SwContentNode*>(GetDep()));
431 if (nullptr == pCNd && IsTextFrame())
433 pCNd = static_cast<SwTextFrame*>(this)->GetTextNodeFirst();
435 // IsInDtor shouldn't be happening with ViewShell owning layout
436 assert(nullptr == pCNd || !pCNd->GetDoc().IsInDtor());
437 if (nullptr != pCNd && !pCNd->GetDoc().IsInDtor())
439 //Unregister from root if I'm still in turbo there.
440 SwRootFrame *pRoot = getRootFrame();
441 if( pRoot && pRoot->GetTurbo() == this )
443 pRoot->DisallowTurbo();
444 pRoot->ResetTurbo();
448 SwFrame::DestroyImpl();
451 SwContentFrame::~SwContentFrame()
455 void SwTextFrame::RegisterToNode(SwTextNode & rNode, bool const isForceNodeAsFirst)
457 if (isForceNodeAsFirst && m_pMergedPara)
458 { // nothing registered here, in particular no delete redlines (insert
459 // redline might end on empty node where delete rl starts, should be ok)
460 assert(m_pMergedPara->pFirstNode->GetIndex() + 1 == rNode.GetIndex());
461 assert(rNode.GetDoc().getIDocumentRedlineAccess().GetRedlinePos(
462 *m_pMergedPara->pFirstNode, RedlineType::Delete) == SwRedlineTable::npos);
463 assert(std::find_if(
464 rNode.GetDoc().getIDocumentMarkAccess()->getFieldmarksBegin(),
465 rNode.GetDoc().getIDocumentMarkAccess()->getFieldmarksEnd(),
466 [this](::sw::mark::IMark const*const pMark) {
467 return pMark->GetMarkStart().GetNode() == *m_pMergedPara->pFirstNode
468 && pMark->GetMarkEnd().GetNode() != *m_pMergedPara->pFirstNode;
469 }) == rNode.GetDoc().getIDocumentMarkAccess()->getFieldmarksEnd());
471 assert(&rNode != GetDep());
472 assert(!m_pMergedPara
473 || (m_pMergedPara->pFirstNode->GetIndex() < rNode.GetIndex())
474 || (rNode.GetIndex() + 1 == m_pMergedPara->pFirstNode->GetIndex()));
475 SwTextNode & rFirstNode(
476 (!isForceNodeAsFirst && m_pMergedPara && m_pMergedPara->pFirstNode->GetIndex() < rNode.GetIndex())
477 ? *m_pMergedPara->pFirstNode
478 : rNode);
479 // sw_redlinehide: use New here, because the only caller also calls lcl_ChangeFootnoteRef
480 m_pMergedPara = sw::CheckParaRedlineMerge(*this, rFirstNode, sw::FrameMode::New);
481 if (!m_pMergedPara)
483 rNode.Add(this);
487 void SwLayoutFrame::DestroyImpl()
489 while (!m_VertPosOrientFramesFor.empty())
491 SwAnchoredObject *pObj = *m_VertPosOrientFramesFor.begin();
492 pObj->ClearVertPosOrientFrame();
495 assert(m_VertPosOrientFramesFor.empty());
497 SwFrame *pFrame = m_pLower;
499 if( GetFormat() && !GetFormat()->GetDoc()->IsInDtor() )
501 while ( pFrame )
503 //First delete the Objs of the Frame because they can't unregister
504 //from the page after remove.
505 //We don't want to create an endless loop only because one couldn't
506 //unregister.
508 while ( pFrame->GetDrawObjs() && pFrame->GetDrawObjs()->size() )
510 const size_t nCnt = pFrame->GetDrawObjs()->size();
511 // #i28701#
512 SwAnchoredObject* pAnchoredObj = (*pFrame->GetDrawObjs())[0];
513 if (SwFlyFrame* pFlyFrame = pAnchoredObj->DynCastFlyFrame())
515 SwFrame::DestroyFrame(pFlyFrame);
516 assert(!pFrame->GetDrawObjs() || nCnt > pFrame->GetDrawObjs()->size());
518 else
520 pAnchoredObj->ClearTmpConsiderWrapInfluence();
521 SdrObject* pSdrObj = pAnchoredObj->DrawObj();
522 SwDrawContact* pContact =
523 static_cast<SwDrawContact*>(pSdrObj->GetUserCall());
524 OSL_ENSURE( pContact,
525 "<SwFrame::~SwFrame> - missing contact for drawing object" );
526 if ( pContact )
528 pContact->DisconnectObjFromLayout( pSdrObj );
531 if ( pFrame->GetDrawObjs() &&
532 nCnt == pFrame->GetDrawObjs()->size() )
534 pFrame->GetDrawObjs()->Remove( *pAnchoredObj );
538 pFrame->RemoveFromLayout();
539 SwFrame::DestroyFrame(pFrame);
540 pFrame = m_pLower;
542 //Delete the Flys, the last one also deletes the array.
543 while ( GetDrawObjs() && GetDrawObjs()->size() )
545 const size_t nCnt = GetDrawObjs()->size();
547 // #i28701#
548 SwAnchoredObject* pAnchoredObj = (*GetDrawObjs())[0];
549 if ( auto pFlyFrame = pAnchoredObj->DynCastFlyFrame() )
551 SwFrame::DestroyFrame(pFlyFrame);
552 assert(!GetDrawObjs() || nCnt > GetDrawObjs()->size());
554 else
556 SdrObject* pSdrObj = pAnchoredObj->DrawObj();
557 SwDrawContact* pContact =
558 static_cast<SwDrawContact*>(pSdrObj->GetUserCall());
559 OSL_ENSURE( pContact,
560 "<SwFrame::~SwFrame> - missing contact for drawing object" );
561 if ( pContact )
563 pContact->DisconnectObjFromLayout( pSdrObj );
566 if ( GetDrawObjs() && nCnt == GetDrawObjs()->size() )
568 GetDrawObjs()->Remove( *pAnchoredObj );
573 else
575 while( pFrame )
577 SwFrame *pNxt = pFrame->GetNext();
578 SwFrame::DestroyFrame(pFrame);
579 pFrame = pNxt;
583 SwFrame::DestroyImpl();
586 SwLayoutFrame::~SwLayoutFrame()
591 |* The paintarea is the area, in which the content of a frame is allowed
592 |* to be displayed. This region could be larger than the printarea (getFramePrintArea())
593 |* of the upper, it includes e.g. often the margin of the page.
595 SwRect SwFrame::GetPaintArea() const
597 // NEW TABLES
598 // Cell frames may not leave their upper:
599 SwRect aRect = IsRowFrame() ? GetUpper()->getFrameArea() : getFrameArea();
600 const bool bVert = IsVertical();
601 SwRectFn fnRect = bVert ? ( IsVertLR() ? (IsVertLRBT() ? fnRectVertL2RB2T : fnRectVertL2R) : fnRectVert ) : fnRectHori;
602 SwRectFnSet aRectFnSet(this);
603 tools::Long nRight = (aRect.*fnRect->fnGetRight)();
604 tools::Long nLeft = (aRect.*fnRect->fnGetLeft)();
605 const SwFrame* pTmp = this;
606 bool bLeft = true;
607 bool bRight = true;
608 tools::Long nRowSpan = 0;
609 while( pTmp )
611 if( pTmp->IsCellFrame() && pTmp->GetUpper() &&
612 pTmp->GetUpper()->IsVertical() != pTmp->IsVertical() )
613 nRowSpan = static_cast<const SwCellFrame*>(pTmp)->GetTabBox()->getRowSpan();
614 tools::Long nTmpRight = (pTmp->getFrameArea().*fnRect->fnGetRight)();
615 tools::Long nTmpLeft = (pTmp->getFrameArea().*fnRect->fnGetLeft)();
616 if( pTmp->IsRowFrame() && nRowSpan > 1 )
618 const SwFrame* pNxt = pTmp;
619 while( --nRowSpan > 0 && pNxt->GetNext() )
620 pNxt = pNxt->GetNext();
621 if( pTmp->IsVertical() )
622 nTmpLeft = (pNxt->getFrameArea().*fnRect->fnGetLeft)();
623 else
625 // pTmp is a row frame, but it's not vertical.
626 if (IsVertLRBT())
628 // This frame cell is OK to expand towards the physical down direction.
629 // Physical down is left.
630 nTmpLeft = (pNxt->getFrameArea().*fnRect->fnGetLeft)();
632 else
634 nTmpRight = (pNxt->getFrameArea().*fnRect->fnGetRight)();
638 OSL_ENSURE( pTmp, "GetPaintArea lost in time and space" );
639 if( pTmp->IsPageFrame() || pTmp->IsFlyFrame() ||
640 pTmp->IsCellFrame() || pTmp->IsRowFrame() || //nobody leaves a table!
641 pTmp->IsRootFrame() )
643 // BTLR is OK to expand towards the physical down direction. Physical down is left.
644 if( bLeft || (aRectFnSet.XDiff(nTmpLeft, nLeft) > 0 && !IsVertLRBT()) )
645 nLeft = nTmpLeft;
646 if( bRight || aRectFnSet.XDiff(nRight, nTmpRight) > 0 )
647 nRight = nTmpRight;
648 if( pTmp->IsPageFrame() || pTmp->IsFlyFrame() || pTmp->IsRootFrame() )
649 break;
650 bLeft = false;
651 bRight = false;
653 else if( pTmp->IsColumnFrame() ) // nobody enters neighbour columns
655 bool bR2L = pTmp->IsRightToLeft();
656 // the first column has _no_ influence to the left range
657 if( bR2L ? pTmp->GetNext() : pTmp->GetPrev() )
659 if( bLeft || aRectFnSet.XDiff(nTmpLeft, nLeft) > 0 )
660 nLeft = nTmpLeft;
661 bLeft = false;
663 // the last column has _no_ influence to the right range
664 if( bR2L ? pTmp->GetPrev() : pTmp->GetNext() )
666 if( bRight || aRectFnSet.XDiff(nRight, nTmpRight) > 0 )
667 nRight = nTmpRight;
668 bRight = false;
671 else if( bVert && pTmp->IsBodyFrame() )
673 // Header and footer frames have always horizontal direction and
674 // limit the body frame.
675 // A previous frame of a body frame must be a header,
676 // the next frame of a body frame may be a footnotecontainer or
677 // a footer. The footnotecontainer has the same direction like
678 // the body frame.
679 if( pTmp->GetPrev() && ( bLeft || aRectFnSet.XDiff(nTmpLeft, nLeft) > 0 ) )
681 nLeft = nTmpLeft;
682 bLeft = false;
684 if( pTmp->GetNext() &&
685 ( pTmp->GetNext()->IsFooterFrame() || pTmp->GetNext()->GetNext() )
686 && ( bRight || aRectFnSet.XDiff(nRight, nTmpRight) > 0 ) )
688 nRight = nTmpRight;
689 bRight = false;
692 pTmp = pTmp->GetUpper();
694 (aRect.*fnRect->fnSetLeft)( nLeft );
695 (aRect.*fnRect->fnSetRight)( nRight );
696 return aRect;
700 |* The unionframe is the framearea (getFrameArea()) of a frame expanded by the
701 |* printarea, if there's a negative margin at the left or right side.
703 SwRect SwFrame::UnionFrame( bool bBorder ) const
705 bool bVert = IsVertical();
706 SwRectFn fnRect = bVert ? ( IsVertLR() ? (IsVertLRBT() ? fnRectVertL2RB2T : fnRectVertL2R) : fnRectVert ) : fnRectHori;
707 tools::Long nLeft = (getFrameArea().*fnRect->fnGetLeft)();
708 tools::Long nWidth = (getFrameArea().*fnRect->fnGetWidth)();
709 tools::Long nPrtLeft = (getFramePrintArea().*fnRect->fnGetLeft)();
710 tools::Long nPrtWidth = (getFramePrintArea().*fnRect->fnGetWidth)();
711 SwRectFnSet aRectFnSet(this);
712 if (aRectFnSet.XInc(nPrtLeft, nPrtWidth) > nWidth)
713 nWidth = nPrtLeft + nPrtWidth;
714 if( nPrtLeft < 0 )
716 nLeft += nPrtLeft;
717 nWidth -= nPrtLeft;
719 SwTwips nRight = aRectFnSet.XInc(nLeft, nWidth);
720 tools::Long nAdd = 0;
721 if( bBorder )
723 SwBorderAttrAccess aAccess( SwFrame::GetCache(), this );
724 const SwBorderAttrs &rAttrs = *aAccess.Get();
725 const SvxBoxItem &rBox = rAttrs.GetBox();
726 if ( rBox.GetLeft() )
727 nLeft -= rBox.CalcLineSpace( SvxBoxItemLine::LEFT );
728 else
729 nLeft -= rBox.GetDistance( SvxBoxItemLine::LEFT ) + 1;
730 if ( rBox.GetRight() )
731 nAdd += rBox.CalcLineSpace( SvxBoxItemLine::RIGHT );
732 else
733 nAdd += rBox.GetDistance( SvxBoxItemLine::RIGHT ) + 1;
734 if( rAttrs.GetShadow().GetLocation() != SvxShadowLocation::NONE )
736 const SvxShadowItem &rShadow = rAttrs.GetShadow();
737 nLeft -= rShadow.CalcShadowSpace( SvxShadowItemSide::LEFT );
738 nAdd += rShadow.CalcShadowSpace( SvxShadowItemSide::RIGHT );
741 if( IsTextFrame() && static_cast<const SwTextFrame*>(this)->HasPara() )
743 tools::Long nTmp = static_cast<const SwTextFrame*>(this)->HangingMargin();
744 if( nTmp > nAdd )
745 nAdd = nTmp;
747 nWidth = aRectFnSet.XDiff(aRectFnSet.XInc(nRight, nAdd), nLeft);
748 SwRect aRet( getFrameArea() );
749 (aRet.*fnRect->fnSetLeft)(nLeft);
750 (aRet.*fnRect->fnSetWidth)( nWidth );
751 return aRet;
754 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */