40#include <osl/diagnose.h>
48 : mrDrawObj( _rDrawObj ),
49 mpAnchoredObj( nullptr ),
54 mbFollowTextFlow( false ),
55 mbDoNotCaptureAnchoredObj( false )
57#if OSL_DEBUG_LEVEL > 0
59 const bool bObjOfExceptedType =
64 OSL_ENSURE( bObjOfExceptedType,
65 "SwAnchoredObjectPosition(..) - object of unexpected type!" );
87 "SwAnchoredObjectPosition::GetInfoAboutObj() - missing SwContact-object.");
95 "SwAnchoredObjectPosition::GetInfoAboutObj() - missing anchored object.");
103 "SwAnchoredObjectPosition::GetInfoAboutObj() - missing anchor frame." );
111 "<SwAnchoredObjectPosition::GetInfoAboutObj() - missing frame format.");
163 const bool _bVert )
const
172 nTopOfFrameForObjPos -=
173 rTextFrame.GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid();
177 nTopOfFrameForObjPos +=
178 rTextFrame.GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid();
181 bool bWrapThrough = rSurround.
GetSurround() == css::text::WrapTextMode_THROUGH;
193 return nTopOfFrameForObjPos;
197 const SwFrame& _rVertOrientFrame,
198 const SwFrame& _rPageAlignLayFrame,
199 const sal_Int16 _eRelOrient,
201 SwTwips& _orAlignAreaOffset )
const
210 const SwTwips nVertOrientUpperSpaceForPrevFrameAndPageGrid =
212 ?
static_cast<const SwTextFrame&
>(_rVertOrientFrame).
213 GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid()
215 switch ( _eRelOrient )
217 case text::RelOrientation::FRAME:
221 nVertOrientUpperSpaceForPrevFrameAndPageGrid;
225 case text::RelOrientation::PRINT_AREA:
230 nVertOrientUpperSpaceForPrevFrameAndPageGrid;
248 pPrtFrame = pPrtFrame->
GetNext();
253 case text::RelOrientation::PAGE_FRAME:
254 case text::RelOrientation::PAGE_PRINT_AREA_TOP:
257 nOffset = aRectFnSet.
YDiff(
262 case text::RelOrientation::PAGE_PRINT_AREA:
265 nOffset = aRectFnSet.
GetTopMargin(_rPageAlignLayFrame) +
286 pPrtFrame = pPrtFrame->
GetNext();
291 case text::RelOrientation::PAGE_PRINT_AREA_BOTTOM:
294 nOffset = aRectFnSet.
YDiff(
310 pPrtFrame = pPrtFrame->
GetNext();
317 case text::RelOrientation::TEXT_LINE:
326 OSL_FAIL(
"<SwAnchoredObjectPosition::GetVertAlignmentValues(..)> - invalid relative alignment" );
330 case text::RelOrientation::CHAR:
340 OSL_FAIL(
"<SwAnchoredObjectPosition::GetVertAlignmentValues(..)> - invalid relative alignment" );
347 OSL_FAIL(
"<SwAnchoredObjectPosition::GetVertAlignmentValues(..)> - invalid relative alignment" );
351 _orAlignAreaHeight = nHeight;
352 _orAlignAreaOffset = nOffset;
357 const SwFrame& _rVertOrientFrame,
358 const SwFrame& _rPageAlignLayFrame,
359 const sal_Int16 _eVertOrient,
360 const sal_Int16 _eRelOrient,
364 SwTwips& _roVertOffsetToFrameAnchorPos )
const
372 _eRelOrient, nAlignAreaHeight, nAlignAreaOffset );
374 nRelPosY = nAlignAreaOffset;
378 switch ( _eVertOrient )
383 nRelPosY += _nVertPos;
386 case text::VertOrientation::TOP:
388 nRelPosY += aRectFnSet.
IsVert()
395 case text::VertOrientation::CENTER:
397 nRelPosY += (nAlignAreaHeight / 2) - (nObjHeight / 2);
400 case text::VertOrientation::BOTTOM:
402 nRelPosY += nAlignAreaHeight -
403 ( nObjHeight + ( aRectFnSet.
IsVert()
412 OSL_FAIL(
"<SwAnchoredObjectPosition::GetVertRelPos(..) - invalid vertical positioning" );
417 _roVertOffsetToFrameAnchorPos = nAlignAreaOffset;
434 const SwFrame& rPageAlignLayFrame,
435 const SwTwips nProposedRelPosY,
436 const bool bFollowTextFlow,
437 const bool bCheckBottom )
const
439 SwTwips nAdjustedRelPosY = nProposedRelPosY;
445 return nAdjustedRelPosY;
462 ( !bFollowTextFlow ||
479 nTopOfAnch - nAdjustedRelPosY - aObjSize.
Width() <
480 aPgAlignArea.
Left() )
482 nAdjustedRelPosY = aPgAlignArea.
Left() +
487 if ( nTopOfAnch - nAdjustedRelPosY > aPgAlignArea.
Right() )
489 nAdjustedRelPosY = nTopOfAnch - aPgAlignArea.
Right();
498 if ( bDisablePositioning && !
IsAnchoredToChar() && nTopOfAnch + nAdjustedRelPosY > aPgAlignArea.
Right() )
500 return nProposedRelPosY;
504 nTopOfAnch + nAdjustedRelPosY + aObjSize.
Width() >
505 aPgAlignArea.
Right() )
507 nAdjustedRelPosY = aPgAlignArea.
Right() -
511 if ( nTopOfAnch + nAdjustedRelPosY < aPgAlignArea.
Left() )
513 nAdjustedRelPosY = aPgAlignArea.
Left() - nTopOfAnch;
528 if ( bDisablePositioning && bIsFooterOrHeader && nTopOfAnch + nAdjustedRelPosY > aPgAlignArea.
Bottom() )
530 return nProposedRelPosY;
535 nTopOfAnch + nAdjustedRelPosY + aObjSize.
Height() >
536 aPgAlignArea.
Top() + aPgAlignArea.
Height() )
538 nAdjustedRelPosY = aPgAlignArea.
Top() + aPgAlignArea.
Height() -
542 if ( nTopOfAnch + nAdjustedRelPosY < aPgAlignArea.
Top() )
544 nAdjustedRelPosY = aPgAlignArea.
Top() - nTopOfAnch;
547 return nAdjustedRelPosY;
556 const SwFrame& _rPageAlignLayFrame,
557 const SwTwips _nProposedRelPosX )
const
559 SwTwips nAdjustedRelPosX = _nProposedRelPosX;
562 return nAdjustedRelPosX;
602 return nAdjustedRelPosX;
607 const SwFrame& _rPageAlignLayFrame,
608 const sal_Int16 _eRelOrient,
609 const bool _bObjWrapThrough,
612 bool& _obAlignedRelToPage )
const
617 switch ( _eRelOrient )
619 case text::RelOrientation::PRINT_AREA:
626 nOffset +=
static_cast<const SwTextFrame&
>(_rHoriOrientFrame).GetBaseOffsetForFly( !_bObjWrapThrough );
645 pPrtFrame = pPrtFrame->
GetNext();
650 case text::RelOrientation::PAGE_LEFT:
654 nOffset = aRectFnSet.
XDiff(
657 _obAlignedRelToPage =
true;
660 case text::RelOrientation::PAGE_RIGHT:
664 nOffset = aRectFnSet.
XDiff(
667 _obAlignedRelToPage =
true;
670 case text::RelOrientation::FRAME_LEFT:
677 case text::RelOrientation::FRAME_RIGHT:
685 case text::RelOrientation::CHAR:
692 nOffset = aRectFnSet.
XDiff(
699 case text::RelOrientation::PAGE_PRINT_AREA:
702 nOffset = aRectFnSet.
XDiff(
722 pPrtFrame = pPrtFrame->
GetNext();
725 _obAlignedRelToPage =
true;
728 case text::RelOrientation::PAGE_FRAME:
731 nOffset = aRectFnSet.
XDiff(
734 _obAlignedRelToPage =
true;
741 bool bWrapThrough = _bObjWrapThrough;
746 bool bIgnoreFlysAnchoredAtFrame = !bWrapThrough;
748 static_cast<const SwTextFrame&
>(_rHoriOrientFrame).GetBaseOffsetForFly( bIgnoreFlysAnchoredAtFrame ) :
754 _orAlignAreaWidth = nWidth;
755 _orAlignAreaOffset = nOffset;
760 const bool _bToggleLeftRight,
761 sal_Int16& _ioeHoriOrient,
762 sal_Int16& _iopeRelOrient
765 if( !_bToggleLeftRight )
769 switch ( _ioeHoriOrient )
771 case text::HoriOrientation::RIGHT :
773 _ioeHoriOrient = text::HoriOrientation::LEFT;
776 case text::HoriOrientation::LEFT :
778 _ioeHoriOrient = text::HoriOrientation::RIGHT;
786 switch ( _iopeRelOrient )
788 case text::RelOrientation::PAGE_RIGHT :
790 _iopeRelOrient = text::RelOrientation::PAGE_LEFT;
793 case text::RelOrientation::PAGE_LEFT :
795 _iopeRelOrient = text::RelOrientation::PAGE_RIGHT;
798 case text::RelOrientation::FRAME_RIGHT :
800 _iopeRelOrient = text::RelOrientation::FRAME_LEFT;
803 case text::RelOrientation::FRAME_LEFT :
805 _iopeRelOrient = text::RelOrientation::FRAME_RIGHT;
815 const SwFrame& _rHoriOrientFrame,
820 const bool _bObjWrapThrough,
822 SwTwips& _roHoriOffsetToFrameAnchorPos
826 const SwFrame& rPageAlignLayFrame =
829 const bool bEvenPage = !rPageAlignLayFrame.
OnRightPage();
830 const bool bToggle = _rHoriOrient.
IsPosToggle() && bEvenPage;
843 bool bAlignedRelToPage =
false;
845 eRelOrient, _bObjWrapThrough,
846 nWidth, nOffset, bAlignedRelToPage );
859 nRelPosX -= _rHoriOrient.
GetPos();
861 nRelPosX += _rHoriOrient.
GetPos();
863 else if ( bToggle || ( !_rHoriOrient.
IsPosToggle() && bR2L ) )
867 nRelPosX += nWidth - nObjWidth - _rHoriOrient.
GetPos();
871 nRelPosX += _rHoriOrient.
GetPos();
874 else if ( text::HoriOrientation::CENTER == eHoriOrient )
875 nRelPosX += (nWidth / 2) - (nObjWidth / 2);
876 else if ( text::HoriOrientation::RIGHT == eHoriOrient )
885 if ( &rAnchorFrame != &_rHoriOrientFrame )
889 nRelPosX += aRectFnSet.
XDiff( nLeftOrient, nLeftAnchor );
894 const SwFrame& rEnvironmentLayFrame =
899 if (!rEnvironmentLayFrame.
IsInTab() || !bFollowTextFlow || bWrapThrough)
910 ( eHoriOrient == text::HoriOrientation::LEFT || eHoriOrient == text::HoriOrientation::RIGHT ) &&
911 eRelOrient != text::RelOrientation::CHAR )
915 eHoriOrient, eRelOrient,
916 _rLRSpacing, _rULSpacing,
921 _roHoriOffsetToFrameAnchorPos = nOffset;
932 const SwFrame& _rHoriOrientFrame,
933 const SwTwips _nProposedRelPosX,
935 const sal_Int16 _eHoriOrient,
936 const sal_Int16 _eRelOrient,
939 const bool _bEvenPage
946 OSL_FAIL(
"<SwAnchoredObjectPosition::AdjustHoriRelPosForDrawAside(..) - usage for wrong anchor type" );
947 return _nProposedRelPosX;
957 SwTwips nAdjustedRelPosX = _nProposedRelPosX;
963 aTmpPos.
AdjustX( -(_nRelPosY + aObjBoundRect.
Width()) );
964 aTmpPos.
AdjustY(nAdjustedRelPosX );
968 aTmpPos.
AdjustX(nAdjustedRelPosX );
971 SwRect aTmpObjRect( aTmpPos, aObjBoundRect.
SSize() );
981 if (
DrawAsideFly( pFly, aTmpObjRect, pObjContext, nObjIndex,
982 _bEvenPage, _eHoriOrient, _eRelOrient ) )
989 if ( nOtherTop <= aTmpObjRect.
Bottom() + _rULSpacing.
GetLower() &&
990 nOtherBot >= aTmpObjRect.
Top() - _rULSpacing.
GetUpper() )
992 if ( _eHoriOrient == text::HoriOrientation::LEFT )
996 if ( nTmp > nAdjustedRelPosX &&
1001 nAdjustedRelPosX = nTmp;
1004 else if ( _eHoriOrient == text::HoriOrientation::RIGHT )
1009 if ( nTmp < nAdjustedRelPosX &&
1013 nAdjustedRelPosX = nTmp;
1025 if( nOtherLeft <= aTmpObjRect.
Right() + _rLRSpacing.
GetRight() &&
1026 nOtherRight >= aTmpObjRect.
Left() - _rLRSpacing.
GetLeft() )
1028 if ( _eHoriOrient == text::HoriOrientation::LEFT )
1032 if ( nTmp > nAdjustedRelPosX &&
1037 nAdjustedRelPosX = nTmp;
1040 else if ( _eHoriOrient == text::HoriOrientation::RIGHT )
1043 aObjBoundRect.
Width() -
1045 if ( nTmp < nAdjustedRelPosX &&
1049 nAdjustedRelPosX = nTmp;
1061 return nAdjustedRelPosX;
1072 const bool _bEvenPage,
1073 const sal_Int16 _eHoriOrient,
1074 const sal_Int16 _eRelOrient
1077 bool bRetVal =
false;
1089 || nOtherIndex < _nObjIndex)
1093 if( text::RelOrientation::CHAR != eOtherRelOrient )
1099 if ( eOtherHoriOrient == _eHoriOrient &&
1100 Minor_( _eRelOrient, eOtherRelOrient, text::HoriOrientation::LEFT == _eHoriOrient ) )
1121 sal_Int16 _eRelOrient2,
1128 static sal_uInt16
const aLeft[ 10 ] =
1129 { 5, 6, 0, 1, 8, 4, 7, 2, 3, 9 };
1132 static sal_uInt16
const aRight[ 10 ] =
1133 { 5, 6, 0, 8, 1, 7, 4, 2, 3, 9 };
1137 bRetVal = aLeft[ _eRelOrient1 ] >= aLeft[ _eRelOrient2 ];
1139 bRetVal = aRight[ _eRelOrient1 ] >= aRight[ _eRelOrient2 ];
@ CONSIDER_WRAP_ON_OBJECT_POSITION
@ DISABLE_OFF_PAGE_POSITIONING
@ DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE
virtual bool get(DocumentSettingId id) const =0
Return the specified document setting.
tools::Long AdjustY(tools::Long nVertMove)
tools::Long AdjustX(tools::Long nHorzMove)
sal_uInt32 GetOrdNumDirect() const
sal_uInt32 GetOrdNum() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
tools::Long GetRight() const
tools::Long GetLeft() const
sal_uInt16 GetUpper() const
sal_uInt16 GetLower() const
const SwFrame * GetAnchorFrame() const
virtual SwFrameFormat & GetFrameFormat()=0
static bool IsDraggingOffPageAllowed(const SwFrameFormat *)
method to determine if dragging objects off page is allowed
new class for re-direct methods calls at a 'virtual' drawing object to its referenced object.
Flys that are anchored to content (at-para, at-char) but not in content (as-char).
general base class for all free-flowing frames
const SwVirtFlyDrawObj * GetVirtDrawObj() const
virtual const SwFlyFrameFormat * GetFormat() const override
bool IsFlyAtContentFrame() const
const SwRect & getFrameArea() const
const SwRect & getFramePrintArea() const
Base class of the Writer layout elements.
bool IsHeaderFrame() const
bool IsRightToLeft() const
bool IsFooterFrame() const
SwLayoutFrame * GetUpper()
SwPageFrame * FindPageFrame()
SwNodeOffset GetIndex() const
const SdrObject * Bottom()
A page of the document layout.
tools::Long GetHeight(const SwRect &rRect) const
tools::Long GetRightMargin(const SwFrame &rFrame) const
tools::Long GetTopMargin(const SwFrame &rFrame) const
tools::Long GetWidth(const SwRect &rRect) const
tools::Long GetTop(const SwRect &rRect) const
tools::Long XDiff(tools::Long n1, tools::Long n2) const
tools::Long GetPrtRight(const SwFrame &rFrame) const
Point GetPos(const SwRect &rRect) const
tools::Long GetBottomMargin(const SwFrame &rFrame) const
tools::Long YDiff(tools::Long n1, tools::Long n2) const
tools::Long GetLeftMargin(const SwFrame &rFrame) const
tools::Long GetLeft(const SwRect &rRect) const
tools::Long GetPrtLeft(const SwFrame &rFrame) const
tools::Long BottomDist(const SwRect &rRect, tools::Long nPos) const
tools::Long GetRight(const SwRect &rRect) const
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 Right(const tools::Long nRight)
void Bottom(const tools::Long nBottom)
void Pos(const Point &rNew)
void SSize(const Size &rNew)
void Left(const tools::Long nLeft)
void Width(tools::Long nNew)
static void getShapeWrapThrough(const SwFrameFormat *pTextBox, bool &rWrapThrough)
If pTextBox is a textbox, then set rWrapThrough to the surround of its shape.
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.
SwTwips GetBaseVertOffsetForFly(bool bIgnoreFlysAnchoredAtThisFrame) const
SwTextNode * GetTextNodeFirst()
const SwFrameFormat * mpFrameFormat
bool DoesObjFollowsTextFlow() const
SwTwips AdjustHoriRelPos(const SwFrame &_rPageAlignLayFrame, const SwTwips _nProposedRelPosX) const
adjust calculated horizontal in order to keep object inside 'page' alignment layout frame for object ...
SwAnchoredObject & GetAnchoredObj() const
SwTwips ImplAdjustHoriRelPos(const SwFrame &_rPageAlignLayFrame, const SwTwips _nProposedRelPosX) const
adjust calculated horizontal in order to keep object inside 'page' alignment layout frame.
virtual SwTwips ToCharTopOfLine() const
void GetInfoAboutObj()
determine information about object
SwAnchoredObject * mpAnchoredObj
virtual bool IsAnchoredToChar() 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
bool mbDoNotCaptureAnchoredObj
virtual ~SwAnchoredObjectPosition()
virtual const SwFrame * ToCharOrientFrame() const
static void ToggleHoriOrientAndAlign(const bool _bToggleLeftRight, sal_Int16 &_ioeHoriOrient, sal_Int16 &_iopeRelOrient)
toggle given horizontal orientation and relative alignment
SwTwips AdjustHoriRelPosForDrawAside(const SwFrame &_rHoriOrientFrame, const SwTwips _nProposedRelPosX, const SwTwips _nRelPosY, const sal_Int16 _eHoriOrient, const sal_Int16 _eRelOrient, const SvxLRSpaceItem &_rLRSpacing, const SvxULSpaceItem &_rULSpacing, const bool _bEvenPage) const
adjust calculated horizontal position in order to draw object aside other objects with same positioni...
void GetHoriAlignmentValues(const SwFrame &_rHoriOrientFrame, const SwFrame &_rPageAlignLayFrame, const sal_Int16 _eRelOrient, const bool _bObjWrapThrough, SwTwips &_orAlignAreaWidth, SwTwips &_orAlignAreaOffset, bool &_obAlignedRelToPage) const
determine alignment values for horizontal position of object
const SwFrameFormat & GetFrameFormat() const
static bool Minor_(sal_Int16 _eRelOrient1, sal_Int16 _eRelOrient2, bool _bLeft)
determine, if object has to draw aside another object
void GetVertAlignmentValues(const SwFrame &_rVertOrientFrame, const SwFrame &_rPageAlignLayFrame, const sal_Int16 _eRelOrient, SwTwips &_orAlignAreaHeight, SwTwips &_orAlignAreaOffset) const
SdrObject & GetObject() const
virtual const SwRect * ToCharRect() const
SwFrame & GetAnchorFrame() const
bool DrawAsideFly(const SwFlyFrame *_pFly, const SwRect &_rObjRect, const SwFrame *_pObjContext, const SwNodeOffset _nObjIndex, const bool _bEvenPage, const sal_Int16 _eHoriOrient, const sal_Int16 _eRelOrient) const
determine, if object has to draw aside given fly frame
SwTwips GetVertRelPos(const SwFrame &_rVertOrientFrame, const SwFrame &_rPageAlignLayFrame, const sal_Int16 _eVertOrient, const sal_Int16 _eRelOrient, const SwTwips _nVertPos, const SvxLRSpaceItem &_rLRSpacing, const SvxULSpaceItem &_rULSpacing, SwTwips &_roVertOffsetToFrameAnchorPos) const
SwTwips ImplAdjustVertRelPos(const SwTwips nTopOfAnch, const bool bVert, const bool bVertL2R, const SwFrame &rPageAlignLayFrame, const SwTwips nProposedRelPosY, const bool bFollowTextFlow, const bool bCheckBottom) const
adjust calculated vertical in order to keep object inside 'page' alignment layout frame.
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
SwAnchoredObjectPosition(SdrObject &_rDrawObj)
const SwLayoutFrame & GetHoriEnvironmentLayoutFrame(const SwFrame &_rHoriOrientFrame) const
determine environment layout frame for possible horizontal object positions respectively for alignmen...
constexpr TypedWhichId< SwFlyFrameFormat > RES_FLYFRMFMT(162)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
bool FrameContainsNode(SwContentFrame const &rFrame, SwNodeOffset nNodeIndex)