38#include <osl/diagnose.h>
52 mpVertPosOrientFrame( nullptr ),
53 mbAnchorToChar ( false ),
54 mpToCharOrientFrame( nullptr ),
55 mpToCharRect( nullptr ),
57 mnToCharTopOfLine( 0 )
87 "SwToContentAnchoredObjectPosition::GetAnchorTextFrame() - wrong anchor frame type" );
97 const bool _bGrowInTable,
100 bool bVertPosFits =
false;
102 if ( _nRelPosY <= _nAvail )
108 if ( _pUpperOfOrientFrame->
IsInSct() )
112 bVertPosFits = pSctFrame->
GetUpper()->
Grow( _nRelPosY - _nAvail,
true ) > 0;
117 bVertPosFits =
const_cast<SwLayoutFrame*
>(_pUpperOfOrientFrame)->
118 Grow( _nRelPosY - _nAvail,
true ) > 0;
120 _orpLayoutFrameToGrow =
const_cast<SwLayoutFrame*
>(_pUpperOfOrientFrame);
123 else if ( _pUpperOfOrientFrame->
IsInTab() && _bGrowInTable )
128 Grow( _nRelPosY - _nAvail,
true );
129 bVertPosFits = ( nTwipsGrown == ( _nRelPosY - _nAvail ) );
131 _orpLayoutFrameToGrow =
const_cast<SwLayoutFrame*
>(_pUpperOfOrientFrame);
164 const bool bNoSurround = rSurround.
GetSurround() == css::text::WrapTextMode_NONE;
165 const bool bWrapThrough = rSurround.
GetSurround() == css::text::WrapTextMode_THROUGH;
188 bool bMoveable = rAnchorTextFrame.
IsMoveable();
191 const SwTextFrame* pOrientFrame = &rAnchorTextFrame;
195 bool bFollowSplitFly =
false;
228 pOrientFrame = &(
const_cast<SwTextFrame&
>(rAnchorTextFrame).GetFrameAtOfst(
236 if (pFlyFrame->IsFlySplitAllowed())
248 SAL_WARN(
"sw.core",
"SwToContentAnchoredObjectPosition::CalcPosition: fly "
249 "chain length is longer then anchor chain length");
254 if (pAnchor && pAnchor->GetPrecede())
256 pOrientFrame = pAnchor;
258 bFollowSplitFly =
true;
263 aRectFnSet.
Refresh(pOrientFrame);
284 nAlignAreaHeight, nAlignAreaOffset );
292 const SwTwips nHeightBetweenOffsetAndMargin = nAlignAreaOffset + nTopMarginHeight;
295 SwTwips nRelPosY = nAlignAreaOffset;
310 case text::VertOrientation::CHAR_BOTTOM:
315 nRelPosY += nAlignAreaHeight + nUpperSpace;
318 nRelPosY += nObjHeight;
324 case text::VertOrientation::TOP:
331 nRelPosY -= (nObjHeight + nLowerSpace);
335 nRelPosY += nUpperSpace;
340 case text::VertOrientation::LINE_TOP:
345 nRelPosY -= (nObjHeight + nLowerSpace);
349 OSL_FAIL(
"<SwToContentAnchoredObjectPosition::CalcPosition()> - unknown combination of vertical position and vertical alignment." );
353 case text::VertOrientation::CENTER:
356 nRelPosY = (nAlignAreaOffset / 2) - (nObjHeight / 2) + (nHeightBetweenOffsetAndMargin / 2);
358 nRelPosY += (nAlignAreaHeight / 2) - (nObjHeight / 2);
362 case text::VertOrientation::LINE_CENTER:
367 nRelPosY += (nAlignAreaHeight / 2) - (nObjHeight / 2);
371 OSL_FAIL(
"<SwToContentAnchoredObjectPosition::CalcPosition()> - unknown combination of vertical position and vertical alignment." );
375 case text::VertOrientation::BOTTOM:
382 nRelPosY += nAlignAreaHeight + nUpperSpace;
391 nRelPosY += nUpperSpace;
396 nRelPosY = 0 - (nObjHeight + nLowerSpace) + nHeightBetweenOffsetAndMargin;
398 nRelPosY += nAlignAreaHeight - (nObjHeight + nLowerSpace);
404 case text::VertOrientation::LINE_BOTTOM:
409 nRelPosY += nUpperSpace;
413 OSL_FAIL(
"<SwToContentAnchoredObjectPosition::CalcPosition()> - unknown combination of vertical position and vertical alignment." );
430 nRelPosY += aRectFnSet.
YDiff( nTopOfOrient,
444 rVertEnvironLayFrame, nRelPosY,
453 SwTwips nAttrRelPosY = nRelPosY - nAlignAreaOffset;
455 if ( nAttrRelPosY != aVert.
GetPos() )
457 aVert.
SetPos( nAttrRelPosY );
459 const_cast<SwFrameFormat&
>(rFrameFormat).SetFormatAttr( aVert );
467 if ( aRectFnSet.
IsVert() )
469 aRelPos.
setX( nRelPosY );
474 aRelPos.
setY( nRelPosY );
489 if ( &rAnchorTextFrame == pOrientFrame ||
495 pUpperOfOrientFrame = rAnchorTextFrame.
GetUpper();
496 pAnchorFrameForVertPos = &rAnchorTextFrame;
500 pUpperOfOrientFrame = pOrientFrame->
GetUpper();
501 pAnchorFrameForVertPos = pOrientFrame;
508 if ( pUpperOfOrientFrame->
IsInSct() )
511 const bool bIgnoreSection = pUpperOfOrientFrame->
IsSctFrame() ||
514 if ( bIgnoreSection )
515 pUpperOfOrientFrame = pSctFrame->
GetUpper();
526 SwTwips nVertOffsetToFrameAnchorPos( 0 );
538 nVertOffsetToFrameAnchorPos = aRectFnSet.
YDiff(
547 nRelPosY = nVertOffsetToFrameAnchorPos - aVert.
GetPos();
554 nVertOffsetToFrameAnchorPos = 0;
568 GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid();
578 nVertOffsetToFrameAnchorPos += aRectFnSet.
YDiff(
588 static_cast<const SwPageFrame&
>(rPageAlignLayFrame).PrtWithoutHeaderAndFooter();
590 nVertOffsetToFrameAnchorPos += aRectFnSet.
YDiff(
591 aRectFnSet.
GetTop(aPgPrtRect),
594 else if (aVert.
GetRelationOrient() == text::RelOrientation::PAGE_PRINT_AREA_BOTTOM)
600 auto& rPageFrame =
static_cast<const SwPageFrame&
>(rPageAlignLayFrame);
601 aPgPrtRect = rPageFrame.PrtWithoutHeaderAndFooter();
604 nVertOffsetToFrameAnchorPos += aRectFnSet.
YDiff(nPageBottom, nTopOfOrient);
606 nRelPosY = nVertOffsetToFrameAnchorPos + aVert.
GetPos();
611 nRelPosY -= aVert.
GetPos();
618 auto& rPageFrame =
static_cast<const SwPageFrame&
>(rPageAlignLayFrame);
623 - rPageFrame.getFrameArea().Top();
639 if ( aRectFnSet.
IsVert() )
657 rVertEnvironLayFrame, nRelPosY,
660 if ( aRectFnSet.
IsVert() )
661 aRelPos.
setX( nRelPosY );
663 aRelPos.
setY( nRelPosY );
667 aRectFnSet.
Refresh(pAnchorFrameForVertPos);
671 const bool bInFootnote = pAnchorFrameForVertPos->
IsInFootnote();
679 nRelPosY, nAvail, pUpperOfOrientFrame, bBrowse,
680 bGrow, pLayoutFrameToGrow );
682 if ( bDoesVertPosFits )
690 const SwFrame& rVertEnvironLayFrame =
697 rVertEnvironLayFrame,
701 if ( aRectFnSet.
IsVert() )
702 aRelPos.
setX( nTmpRelPosY );
704 aRelPos.
setY( nTmpRelPosY );
709 if ( pLayoutFrameToGrow )
715 pLayoutFrameToGrow->
Grow( nRelPosY - nAvail );
736 const bool bInSct = pUpperOfOrientFrame->
IsInSct();
741 pUpperOfOrientFrame->
GetLeaf( eMakePage,
true, &rAnchorTextFrame );
746 pUpperOfOrientFrame = pTmp;
747 bMoveable = rAnchorTextFrame.
IsMoveable( pUpperOfOrientFrame );
748 aRectFnSet.
Refresh(pUpperOfOrientFrame);
761 pUpperOfOrientFrame = pSct->
GetUpper();
762 nAvail = aRectFnSet.
YDiff(
768#if OSL_DEBUG_LEVEL > 1
769 OSL_FAIL(
"<SwToContentAnchoredObjectPosition::CalcPosition()> - !bInSct" );
785 const SwFrame& rVertEnvironLayFrame =
788 rVertEnvironLayFrame,
792 aRelPos.
setX( nRelPosY );
794 aRelPos.
setY( nRelPosY );
812 ( aRelPos.
X() - nRelDiff ) -
813 aObjBoundRect.
Width() );
818 ( aRelPos.
X() - nRelDiff ) );
824 ( aRelPos.
Y() - nRelDiff ) );
831 if ( pUpperOfOrientFrame->
IsInSct() )
834 const bool bIgnoreSection = pUpperOfOrientFrame->
IsSctFrame() ||
837 if ( bIgnoreSection )
838 pUpperOfOrientFrame = pSctFrame->
GetUpper();
848 if ( bBrowse && rAnchorTextFrame.
IsMoveable() )
850 if ( pUpperOfOrientFrame->
IsInSct() )
858 pLayoutFrameToGrow =
nullptr;
867 else if ( rAnchorTextFrame.
IsInTab() && bGrow )
869 pLayoutFrameToGrow =
const_cast<SwLayoutFrame*
>(pUpperOfOrientFrame);
871 if ( pLayoutFrameToGrow )
877 pLayoutFrameToGrow->
Grow( -nDist );
892 if ( nDist < 0 && pOrientFrame->IsInTab() )
898 if ( pOrientFrame == &rAnchorTextFrame &&
903 ->SetDoesObjsFit(
false );
908 if ( aRectFnSet.
IsVert() )
909 nTmpRelPosY = aRelPos.
X() - nDist;
911 nTmpRelPosY = aRelPos.
Y() + nDist;
915 rVertEnvironLayFrame,
919 if ( aRectFnSet.
IsVert() )
921 aRelPos.
setX( nTmpRelPosY );
927 aObjBoundRect.
Width() );
936 aRelPos.
setY( nTmpRelPosY );
945 pOrientFrame == &rAnchorTextFrame && !pOrientFrame->
GetIndPrev() )
948 ->SetDoesObjsFit(
false );
955 const bool bInFootnote = rAnchorTextFrame.
IsInFootnote();
956 while( bMoveable && nDist < 0 )
958 bool bInSct = pUpperOfOrientFrame->
IsInSct();
976 aRectFnSet.
GetPrtTop(*pUpperOfOrientFrame) )
984 true, &rAnchorTextFrame );
1002 if ( aRectFnSet.
IsVert() )
1003 aRelPos.
setX( nTmpRelPosY );
1005 aRelPos.
setY( nTmpRelPosY );
1006 pUpperOfOrientFrame = pNextLay;
1007 aRectFnSet.
Refresh(pUpperOfOrientFrame);
1008 bMoveable = rAnchorTextFrame.
IsMoveable( pUpperOfOrientFrame );
1016 aObjBoundRect.
Width() );
1037 pUpperOfOrientFrame = pTmp;
1050 pUpperOfOrientFrame = pTmp;
1065 CalcOverlap(pAnchorFrameForVertPos, aRelPos, nTopOfAnch);
1076 if( aRectFnSet.
IsVert() )
1082 aRelPos.
X() - aObjBoundRect.
Width() );
1100 SwTwips nHoriOffsetToFrameAnchorPos( 0 );
1102 aHori, rLR, rUL, bWrapThrough,
1103 ( aRectFnSet.
IsVert() ? aRelPos.
X() : aRelPos.
Y() ),
1104 nHoriOffsetToFrameAnchorPos );
1108 if ( aRectFnSet.
IsVert() )
1110 aRelPos.
setY( nRelPosX );
1115 aRelPos.
setX( nRelPosX );
1122 SwTwips nAttrRelPosX = nRelPosX - nHoriOffsetToFrameAnchorPos;
1124 aHori.
GetPos() != nAttrRelPosX )
1126 aHori.
SetPos( nAttrRelPosX );
1128 const_cast<SwFrameFormat&
>(rFrameFormat).SetFormatAttr( aHori );
1136 if( aRectFnSet.
IsVert() )
1142 aRelPos.
X() - aObjBoundRect.
Width() );
1183 if (pShapeOfTextBox)
1188 rRelPos.
setY(rRelPos.
getY() + nYDiff + 1);
1196 auto pSortedObjs = pAnchorFrameForVertPos->
GetDrawObjs();
1202 for (
const auto& pAnchoredObj : *pSortedObjs)
1216 css::text::WrapTextMode eWrap = pAnchoredObj->GetFrameFormat().GetSurround().GetSurround();
1217 if (eWrap == css::text::WrapTextMode_THROUGH)
1223 if (!
GetAnchoredObj().GetObjRect().Overlaps(pAnchoredObj->GetObjRect()))
1231 rRelPos.
setY(rRelPos.
getY() + nYDiff + 1);
1239 const_cast<SwFrameFormat&
>(rFrameFormat).SetFormatAttr(aInfluence);
1250 const SwFrame* pHoriVirtAnchFrame = &_rProposedFrame;
1261 pHoriVirtAnchFrame = pFrame;
1267 return *pHoriVirtAnchFrame;
constexpr tools::Long Y() const
void setX(tools::Long nX)
void setY(tools::Long nY)
constexpr tools::Long X() const
constexpr tools::Long getY() const
tools::Long GetRight() const
tools::Long GetLeft() const
sal_uInt16 GetUpper() const
sal_uInt16 GetLower() const
void SetObjTop(const SwTwips _nTop)
void CheckCharRectAndTopOfLine(const bool _bCheckForParaPorInf)
check anchor character rectangle and top of line
void SetCurrRelPos(Point _aRelPos)
void SetObjLeft(const SwTwips _nLeft)
const SwRect & GetLastCharRect() const
SwTwips GetLastTopOfLine() const
virtual const SwFlyFrame * DynCastFlyFrame() const
virtual SwRect GetObjRect() const =0
SwContentFrame is the layout for content nodes: a common base class for text (paragraph) and non-text...
Flys that are anchored to content (at-para, at-char) but not in content (as-char).
const SwFlyAtContentFrame * GetPrecede() const
general base class for all free-flowing frames
const SwRect & getFrameArea() const
const SwRect & getFramePrintArea() const
Base class of the Writer layout elements.
SwTwips Grow(SwTwips, bool bTst=false, bool bInfo=false)
SwRect GetPaintArea() const
|* The paintarea is the area, in which the content of a frame is allowed |* to be displayed.
SwFrame * GetIndPrev() const
SwSectionFrame * FindSctFrame()
SwTabFrame * FindTabFrame()
bool IsColumnFrame() const
bool IsInFootnote() const
const SwSortedObjs * GetDrawObjs() const
bool IsMoveable(const SwLayoutFrame *_pLayoutFrame=nullptr) const
determine, if frame is moveable in given environment
bool IsFooterFrame() const
bool IsFootnoteFrame() const
SwLayoutFrame * GetUpper()
SwLayoutFrame * GetLeaf(MakePageType eMakePage, bool bFwd)
SwRootFrame * getRootFrame()
bool IsContentFrame() const
SwPageFrame * FindPageFrame()
SwFrame * FindFooterOrHeader()
tools::Long GetTopMargin() const
A layout frame is a frame that contains other frames (m_pLower), e.g. SwPageFrame or SwTabFrame.
const SwFrame * Lower() const
A page of the document layout.
const SwHeaderFrame * GetHeaderFrame() const
tools::Long GetHeight(const SwRect &rRect) const
tools::Long GetTopMargin(const SwFrame &rFrame) const
tools::Long GetTop(const SwRect &rRect) const
tools::Long YDiff(tools::Long n1, tools::Long n2) const
tools::Long GetPrtTop(const SwFrame &rFrame) const
tools::Long GetBottom(const SwRect &rRect) const
tools::Long BottomDist(const SwRect &rRect, tools::Long nPos) const
void Refresh(const SwFrame *pFrame)
tools::Long GetPrtBottom(const SwFrame &rFrame) const
Of course Writer needs its own rectangles.
void Height(tools::Long nNew)
void Top(const tools::Long nTop)
void Left(const tools::Long nLeft)
void Width(tools::Long nNew)
SwViewShell * GetCurrShell() const
SwTabFrame is one table in the document layout, containing rows (which contain cells).
static SwFrameFormat * getOtherTextBoxFormat(const SwFrameFormat *pFormat, sal_uInt16 nType, const SdrObject *pObject=nullptr)
If we have an associated TextFrame, then return that.
static bool isTextBox(const SwFrameFormat *pFormat, sal_uInt16 nType, const SdrObject *pObject=nullptr)
Is the frame format a text box?
Represents the visualization of a paragraph.
SwTextFrame * GetFollow()
TextFrameIndex MapModelToViewPos(SwPosition const &rPos) const
bool getBrowseMode() const
const SwViewOption * GetViewOptions() const
bool DoesObjFollowsTextFlow() const
SwAnchoredObject & GetAnchoredObj() const
SwTwips CalcRelPosX(const SwFrame &_rHoriOrientFrame, const SwEnvironmentOfAnchoredObject &_rEnvOfObj, const SwFormatHoriOrient &_rHoriOrient, const SvxLRSpaceItem &_rLRSpacing, const SvxULSpaceItem &_rULSpacing, const bool _bObjWrapThrough, const SwTwips _nRelPosY, SwTwips &_roHoriOffsetToFrameAnchorPos) const
calculate relative horizontal position
SwTwips AdjustVertRelPos(const SwTwips nTopOfAnch, const bool bVert, const bool bVertL2R, const SwFrame &rPageAlignLayFrame, const SwTwips nProposedRelPosY, const bool bFollowTextFlow, const bool bCheckBottom=true) const
adjust calculated vertical in order to keep object inside 'page' alignment layout frame.
const SwFrameFormat & GetFrameFormat() const
void GetVertAlignmentValues(const SwFrame &_rVertOrientFrame, const SwFrame &_rPageAlignLayFrame, const sal_Int16 _eRelOrient, SwTwips &_orAlignAreaHeight, SwTwips &_orAlignAreaOffset) const
SwFrame & GetAnchorFrame() const
SwTwips GetTopForObjPos(const SwFrame &_rFrame, const SwRectFn &_fnRect, const bool _bVert) const
helper method to determine top of a frame for the vertical object positioning
const SwLayoutFrame & GetVertEnvironmentLayoutFrame(const SwFrame &_rVertOrientFrame) const
determine environment layout frame for possible vertical object positions respectively for alignments...
const SwFrame * mpToCharOrientFrame
virtual ~SwToContentAnchoredObjectPosition() override
virtual SwTwips ToCharTopOfLine() const override
virtual bool IsAnchoredToChar() const override
virtual const SwFrame * ToCharOrientFrame() const override
Point maOffsetToFrameAnchorPos
const SwFrame & GetHoriVirtualAnchor(const SwLayoutFrame &_pProposedFrame) const
determine frame for horizontal position
const SwLayoutFrame * mpVertPosOrientFrame
SwTextFrame & GetAnchorTextFrame() const
virtual void CalcPosition() override
calculate position of object
SwTwips mnToCharTopOfLine
void CalcOverlap(const SwTextFrame *pAnchorFrameForVertPos, Point &rRelPos, const SwTwips nTopOfAnch)
In case overlap is not allowed, re-position the current object.
SwToContentAnchoredObjectPosition(SdrObject &_rDrawObj)
virtual const SwRect * ToCharRect() const override
const SwRect * mpToCharRect
constexpr TypedWhichId< SwFlyFrameFormat > RES_FLYFRMFMT(162)
#define SAL_WARN(area, stream)
tools::Long const nTopMargin
static bool lcl_DoesVertPosFits(const SwTwips _nRelPosY, const SwTwips _nAvail, const SwLayoutFrame *_pUpperOfOrientFrame, const bool _bBrowse, const bool _bGrowInTable, SwLayoutFrame *&_orpLayoutFrameToGrow)