sw/inc/swrect.hxx | 192 ++++++--------------------------------- sw/source/core/bastyp/swrect.cxx | 95 ++++++++----------- sw/source/core/layout/ssfrm.cxx | 24 +--- 3 files changed, 84 insertions(+), 227 deletions(-)
New commits: commit 93039f3f4af12f9fbe6390ae26cfc488120682ef Author: Mike Kaganski <[email protected]> AuthorDate: Tue Dec 16 20:18:22 2025 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Tue Dec 16 20:19:09 2025 +0100 Simplify SwRect methods Use '= default' where makes sense. Move one-line inline methods to where they are declared. Use own getters instead of accessing fields. Change-Id: Id208abfca0490e21cc05ac601017544d043a43fc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195729 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/sw/inc/swrect.hxx b/sw/inc/swrect.hxx index 851df2ab57f7..b22c8dda7c0b 100644 --- a/sw/inc/swrect.hxx +++ b/sw/inc/swrect.hxx @@ -37,8 +37,8 @@ class SAL_WARN_UNUSED SwRect Size m_Size; public: - inline SwRect(); - inline SwRect( const SwRect &rRect ) = default; + SwRect() = default; + SwRect(const SwRect& rRect) = default; inline SwRect( const Point& rLT, const Size& rSize ); inline SwRect( const Point& rLT, const Point& rRB ); inline SwRect( tools::Long X, tools::Long Y, tools::Long Width, tools::Long Height ); @@ -48,31 +48,31 @@ public: //Set-Methods inline void Chg( const Point& rNP, const Size &rNS ); - inline void Pos( const Point& rNew ); - inline void Pos( const tools::Long nNewX, const tools::Long nNewY ); - inline void SSize( const Size& rNew ); - inline void SSize( const tools::Long nHeight, const tools::Long nWidth ); - inline void Width( tools::Long nNew ); - inline void Height( tools::Long nNew ); + void Pos(const Point& rNew) { m_Point = rNew; } + void Pos(tools::Long nNewX, tools::Long nNewY) { Pos({ nNewX, nNewY }); } + void SSize(const Size& rNew) { m_Size = rNew; } + void SSize(tools::Long nHeight, tools::Long nWidth) { SSize({ nWidth, nHeight }); } + void Width(tools::Long nNew) { m_Size.setWidth(nNew); } + void Height(tools::Long nNew) { m_Size.setHeight(nNew); } inline void Left( const tools::Long nLeft ); - inline void Right( const tools::Long nRight ); + void Right(tools::Long nRight) { Width(nRight - Left() + 1); } inline void Top( const tools::Long nTop ); - inline void Bottom( const tools::Long nBottom ); + void Bottom(tools::Long nBottom) { Height(nBottom - Top() + 1); } //Get-Methods - inline const Point &Pos() const; - inline const Size &SSize() const; - inline tools::Long Width() const; - inline tools::Long Height() const; - inline tools::Long Left() const; - inline tools::Long Right() const; - inline tools::Long Top() const; - inline tools::Long Bottom() const; + const Point& Pos() const { return m_Point; } + const Size& SSize() const { return m_Size; } + tools::Long Width() const { return m_Size.Width(); } + tools::Long Height() const { return m_Size.Height(); } + tools::Long Left() const { return m_Point.X(); } + tools::Long Right() const { return Width() ? Left() + Width() - 1 : Left(); } + tools::Long Top() const { return m_Point.Y(); } + tools::Long Bottom() const { return Height() ? Top() + Height() - 1 : Top(); } // In order to be able to access the members of Pos and SSize from the layout side. - inline Point &Pos(); + Point& Pos() { return m_Point; } - Point Center() const; + Point Center() const { return Point(Left() + Width() / 2, Top() + Height() / 2); } void Justify(); @@ -89,14 +89,13 @@ public: bool Contains( const SwRect& rRect ) const; bool Overlaps( const SwRect& rRect ) const; bool IsNear(const Point& rPoint, tools::Long nTolerance ) const; - inline bool HasArea() const; - inline bool IsEmpty() const; - inline void Clear(); + bool HasArea() const { return Height() && Width(); } + bool IsEmpty() const { return !HasArea(); } + void Clear() { Chg({}, {}); } SwRect &operator = ( const SwRect &rRect ) = default; - inline bool operator == ( const SwRect& rRect ) const; - inline bool operator != ( const SwRect& rRect ) const; + bool operator==(const SwRect& rRect) const = default; inline SwRect &operator+=( const Point &rPt ); inline SwRect &operator-=( const Point &rPt ); @@ -138,10 +137,10 @@ public: void SetUpperRightCorner( const Point& rNew ); void SetLowerLeftCorner( const Point& rNew ); Size Size_() const; - Point TopLeft() const; - Point TopRight() const; - Point BottomLeft() const; - Point BottomRight() const; + Point TopLeft() const { return Point(Left(), Top()); } + Point TopRight() const { return Point(Right(), Top()); } + Point BottomLeft() const { return Point(Left(), Bottom()); } + Point BottomRight() const { return Point(Right(), Bottom()); } Size SwappedSize() const; tools::Long GetLeftDistance( tools::Long ) const; tools::Long GetBottomDistance( tools::Long ) const; @@ -168,114 +167,16 @@ inline void SwRect::Chg( const Point& rNP, const Size &rNS ) m_Point = rNP; m_Size = rNS; } -inline void SwRect::Pos( const Point& rNew ) -{ - m_Point = rNew; -} -inline void SwRect::Pos( const tools::Long nNewX, const tools::Long nNewY ) -{ - m_Point.setX(nNewX); - m_Point.setY(nNewY); -} -inline void SwRect::SSize( const Size& rNew ) -{ - m_Size = rNew; -} -inline void SwRect::SSize( const tools::Long nNewHeight, const tools::Long nNewWidth ) -{ - m_Size.setWidth(nNewWidth); - m_Size.setHeight(nNewHeight); -} -inline void SwRect::Width( tools::Long nNew ) -{ - m_Size.setWidth(nNew); -} -inline void SwRect::Height( tools::Long nNew ) -{ - m_Size.setHeight(nNew); -} inline void SwRect::Left( const tools::Long nLeft ) { - m_Size.AdjustWidth( m_Point.X() - nLeft ); + m_Size.AdjustWidth( Left() - nLeft ); m_Point.setX(nLeft); } -inline void SwRect::Right( const tools::Long nRight ) -{ - m_Size.setWidth(nRight - m_Point.X() + 1); -} inline void SwRect::Top( const tools::Long nTop ) { - m_Size.AdjustHeight( m_Point.Y() - nTop ); + m_Size.AdjustHeight( Top() - nTop ); m_Point.setY(nTop); } -inline void SwRect::Bottom( const tools::Long nBottom ) -{ - m_Size.setHeight(nBottom - m_Point.Y() + 1); -} - -// Get-Methods -inline const Point &SwRect::Pos() const -{ - return m_Point; -} -inline Point &SwRect::Pos() -{ - return m_Point; -} -inline const Size &SwRect::SSize() const -{ - return m_Size; -} -inline tools::Long SwRect::Width() const -{ - return m_Size.Width(); -} -inline tools::Long SwRect::Height() const -{ - return m_Size.Height(); -} -inline tools::Long SwRect::Left() const -{ - return m_Point.X(); -} -inline tools::Long SwRect::Right() const -{ - return m_Size.Width() ? m_Point.X() + m_Size.Width() - 1 : m_Point.X(); -} -inline tools::Long SwRect::Top() const -{ - return m_Point.Y(); -} -inline tools::Long SwRect::Bottom() const -{ - return m_Size.Height() ? m_Point.Y() + m_Size.Height() - 1 : m_Point.Y(); -} - -inline Point SwRect::TopLeft() const -{ - return Point( Left(), Top()); -} -inline Point SwRect::TopRight() const -{ - return Point( Right(), Top()); -} -inline Point SwRect::BottomLeft() const -{ - return Point( Left(), Bottom()); -} -inline Point SwRect::BottomRight() const -{ - return Point( Right(), Bottom()); -} - -inline bool SwRect::operator == ( const SwRect& rRect ) const -{ - return (m_Point == rRect.m_Point && m_Size == rRect.m_Size); -} -inline bool SwRect::operator != ( const SwRect& rRect ) const -{ - return (m_Point != rRect.m_Point || m_Size != rRect.m_Size); -} inline SwRect &SwRect::operator+=( const Point &rPt ) { @@ -292,33 +193,12 @@ inline SwRect &SwRect::operator-=( const Point &rPt ) inline tools::Rectangle SwRect::SVRect() const { SAL_INFO_IF( IsEmpty(), "sw.core", "SVRect() without Width or Height" ); - return tools::Rectangle( m_Point.X(), m_Point.Y(), - m_Point.X() + m_Size.Width() - 1, //Right() - m_Point.Y() + m_Size.Height() - 1 ); //Bottom() -} - -inline bool SwRect::HasArea() const -{ - return !IsEmpty(); -} -inline bool SwRect::IsEmpty() const -{ - return !(m_Size.Height() && m_Size.Width()); -} -inline void SwRect::Clear() -{ - m_Point.setX(0); - m_Point.setY(0); - m_Size.setWidth(0); - m_Size.setHeight(0); + return tools::Rectangle( Left(), Top(), + Left() + Width() - 1, //Right() + Top() + Height() - 1 ); //Bottom() } // constructors -inline SwRect::SwRect() : - m_Point( 0, 0 ), - m_Size( 0, 0 ) -{ -} inline SwRect::SwRect( const Point& rLT, const Size& rSize ) : m_Point( rLT ), m_Size( rSize ) @@ -335,12 +215,6 @@ inline SwRect::SwRect( tools::Long X, tools::Long Y, tools::Long W, tools::Long { } -inline Point SwRect::Center() const -{ - return Point( Left() + Width() / 2, - Top() + Height() / 2 ); -} - inline bool SwRect::Contains( const SwRect& rRect ) const { const tools::Long nRight = Right(); diff --git a/sw/source/core/bastyp/swrect.cxx b/sw/source/core/bastyp/swrect.cxx index 7617087848aa..83b95e5121a2 100644 --- a/sw/source/core/bastyp/swrect.cxx +++ b/sw/source/core/bastyp/swrect.cxx @@ -26,10 +26,10 @@ #endif SwRect::SwRect( const tools::Rectangle &rRect ) : - m_Point( rRect.Left(), rRect.Top() ) + m_Point( rRect.Left(), rRect.Top() ), + m_Size( rRect.IsWidthEmpty() ? 0 : rRect.Right() - rRect.Left() + 1, + rRect.IsHeightEmpty() ? 0 : rRect.Bottom() - rRect.Top() + 1 ) { - m_Size.setWidth( rRect.IsWidthEmpty() ? 0 : rRect.Right() - rRect.Left() + 1); - m_Size.setHeight(rRect.IsHeightEmpty() ? 0 : rRect.Bottom() - rRect.Top() + 1); } SwRect& SwRect::Union( const SwRect& rRect ) @@ -45,11 +45,9 @@ SwRect& SwRect::Union( const SwRect& rRect ) Top( rRect.Top() ); if ( Left() > rRect.Left() ) Left( rRect.Left() ); - tools::Long n = rRect.Right(); - if ( Right() < n ) + if ( tools::Long n = rRect.Right(); Right() < n ) Right( n ); - n = rRect.Bottom(); - if ( Bottom() < n ) + if ( tools::Long n = rRect.Bottom(); Bottom() < n ) Bottom( n ); return *this; } @@ -81,27 +79,25 @@ SwRect& SwRect::Intersection( const SwRect& rRect ) SwRect& SwRect::Intersection_( const SwRect& rOther ) { // get smaller right and lower, and greater left and upper edge - auto left = std::max( m_Point.X(), rOther.m_Point.X() ); - auto top = std::max( m_Point.Y(), rOther.m_Point.Y() ); - tools::Long right = std::min( m_Point.X() + m_Size.Width(), rOther.m_Point.X() + rOther.m_Size.Width() ); - auto bottom = std::min( m_Point.Y() + m_Size.Height(), rOther.m_Point.Y() + rOther.m_Size.Height() ); + auto left = std::max( Left(), rOther.Left() ); + auto top = std::max( Top(), rOther.Top() ); + auto right = std::min( Left() + Width(), rOther.Left() + rOther.Width() ); + auto bottom = std::min( Top() + Height(), rOther.Top() + rOther.Height() ); - *this = SwRect( left, top, right - left, bottom - top ); + Chg({ left, top }, { right - left, bottom - top }); return *this; } void SwRect::Justify() { - if ( m_Size.Height() < 0 ) + if ( Height() < 0 ) { - m_Point.setY(m_Point.Y() + m_Size.Height() + 1); - m_Size.setHeight(-m_Size.Height()); + SetTopAndHeight(Top() + Height() + 1, -Height()); } - if ( m_Size.Width() < 0 ) + if ( Width() < 0 ) { - m_Point.setX(m_Point.X() + m_Size.Width() + 1); - m_Size.setWidth(-m_Size.Width()); + SetLeftAndWidth(Left() + Width() + 1, -Width()); } } @@ -109,71 +105,64 @@ void SwRect::Justify() void SwRect::Width_( const tools::Long nNew ) { Width(nNew); } void SwRect::Height_( const tools::Long nNew ) { Height(nNew); } void SwRect::Left_( const tools::Long nLeft ) { Left(nLeft); } -void SwRect::Right_( const tools::Long nRight ){ m_Size.setWidth(nRight - m_Point.X()); } +void SwRect::Right_( const tools::Long nRight ) { Width(nRight - Left()); } void SwRect::Top_( const tools::Long nTop ) { Top(nTop); } -void SwRect::Bottom_( const tools::Long nBottom ){ m_Size.setHeight(nBottom - m_Point.Y()); } +void SwRect::Bottom_( const tools::Long nBottom ) { Height(nBottom - Top()); } tools::Long SwRect::Width_() const{ return Width(); } tools::Long SwRect::Height_() const{ return Height(); } tools::Long SwRect::Left_() const{ return Left(); } -tools::Long SwRect::Right_() const{ return m_Point.X() + m_Size.Width(); } +tools::Long SwRect::Right_() const{ return Left() + Width(); } tools::Long SwRect::Top_() const{ return Top(); } -tools::Long SwRect::Bottom_() const{ return m_Point.Y() + m_Size.Height(); } +tools::Long SwRect::Bottom_() const{ return Top() + Height(); } void SwRect::AddWidth( const tools::Long nAdd ) { m_Size.AdjustWidth(nAdd ); } void SwRect::AddHeight( const tools::Long nAdd ) { m_Size.AdjustHeight(nAdd ); } -void SwRect::AddLeft( const tools::Long nAdd ){ m_Size.AdjustWidth(-nAdd ); m_Point.setX(m_Point.X() + nAdd); } -void SwRect::SubLeft( const tools::Long nSub ){ m_Size.AdjustWidth(nSub ); m_Point.setX(m_Point.X() - nSub); } -void SwRect::AddRight( const tools::Long nAdd ){ m_Size.AdjustWidth(nAdd ); } -void SwRect::AddTop( const tools::Long nAdd ){ m_Size.AdjustHeight(-nAdd ); m_Point.setY(m_Point.Y() + nAdd); } -void SwRect::SubTop( const tools::Long nSub ){ m_Size.AdjustHeight(nSub ); m_Point.setY(m_Point.Y() - nSub); } -void SwRect::AddBottom( const tools::Long nAdd ){ m_Size.AdjustHeight(nAdd ); } +void SwRect::AddLeft( const tools::Long nAdd ) { SubLeft(-nAdd); } +void SwRect::SubLeft( const tools::Long nSub ) { AddWidth(nSub); SetPosX(Left() - nSub); } +void SwRect::AddRight( const tools::Long nAdd ) { AddWidth(nAdd); } +void SwRect::AddTop( const tools::Long nAdd ) { SubTop(-nAdd); } +void SwRect::SubTop( const tools::Long nSub ) { AddHeight(nSub); SetPosY(Top() - nSub); } +void SwRect::AddBottom( const tools::Long nAdd ) { AddHeight(nAdd); } void SwRect::SetPosX( const tools::Long nNew ){ m_Point.setX(nNew); } void SwRect::SetPosY( const tools::Long nNew ){ m_Point.setY(nNew); } Size SwRect::Size_() const { return SSize(); } -Size SwRect::SwappedSize() const { return Size( m_Size.Height(), m_Size.Width() ); } +Size SwRect::SwappedSize() const { return Size(Height(), Width()); } -tools::Long SwRect::GetLeftDistance( tools::Long nLimit ) const { return m_Point.X() - nLimit; } -tools::Long SwRect::GetBottomDistance( tools::Long nLim ) const { return nLim - m_Point.Y() - m_Size.Height();} -tools::Long SwRect::GetTopDistance( tools::Long nLimit ) const { return m_Point.Y() - nLimit; } -tools::Long SwRect::GetRightDistance( tools::Long nLim ) const { return nLim - m_Point.X() - m_Size.Width(); } +tools::Long SwRect::GetLeftDistance(tools::Long nLimit) const { return Left() - nLimit; } +tools::Long SwRect::GetTopDistance(tools::Long nLimit) const { return Top() - nLimit; } +tools::Long SwRect::GetRightDistance(tools::Long nLim) const { return nLim - Left() - Width(); } +tools::Long SwRect::GetBottomDistance(tools::Long nLim) const { return nLim - Top() - Height(); } bool SwRect::OverStepLeft( tools::Long nLimit ) const - { return nLimit > m_Point.X() && m_Point.X() + m_Size.Width() > nLimit; } -bool SwRect::OverStepBottom( tools::Long nLimit ) const - { return nLimit > m_Point.Y() && m_Point.Y() + m_Size.Height() > nLimit; } + { return nLimit > Left() && Left() + Width() > nLimit; } +bool SwRect::OverStepRight( tools::Long nLimit ) const { return OverStepLeft(nLimit); } bool SwRect::OverStepTop( tools::Long nLimit ) const - { return nLimit > m_Point.Y() && m_Point.Y() + m_Size.Height() > nLimit; } -bool SwRect::OverStepRight( tools::Long nLimit ) const - { return nLimit > m_Point.X() && m_Point.X() + m_Size.Width() > nLimit; } + { return nLimit > Top() && Top() + Height() > nLimit; } +bool SwRect::OverStepBottom( tools::Long nLimit ) const { return OverStepTop(nLimit); } void SwRect::SetLeftAndWidth( tools::Long nLeft, tools::Long nNew ) { - m_Point.setX(nLeft); - m_Size.setWidth(nNew); + SetPosX(nLeft); + Width(nNew); } void SwRect::SetTopAndHeight( tools::Long nTop, tools::Long nNew ) { - m_Point.setY(nTop); - m_Size.setHeight(nNew); + SetPosY(nTop); + Height(nNew); } void SwRect::SetRightAndWidth( tools::Long nRight, tools::Long nNew ) { - m_Point.setX(nRight - nNew); - m_Size.setWidth(nNew); + SetLeftAndWidth(nRight - nNew, nNew); } void SwRect::SetBottomAndHeight( tools::Long nBottom, tools::Long nNew ) { - m_Point.setY(nBottom - nNew); - m_Size.setHeight(nNew); + SetTopAndHeight(nBottom - nNew, nNew); } -void SwRect::SetUpperLeftCorner( const Point& rNew ) - { m_Point = rNew; } -void SwRect::SetUpperRightCorner( const Point& rNew ) - { m_Point = Point(rNew.X() - m_Size.Width(), rNew.Y()); } -void SwRect::SetLowerLeftCorner( const Point& rNew ) - { m_Point = Point(rNew.X(), rNew.Y() - m_Size.Height()); } +void SwRect::SetUpperLeftCorner(const Point& rNew) { Pos(rNew); } +void SwRect::SetUpperRightCorner(const Point& rNew) { Pos(rNew.X() - Width(), rNew.Y()); } +void SwRect::SetLowerLeftCorner(const Point& rNew) { Pos(rNew.X(), rNew.Y() - Height()); } void SwRect::dumpAsXmlAttributes(xmlTextWriterPtr writer) const { commit eecd337bb43640b6785333c00c6d583011f7f718 Author: Mike Kaganski <[email protected]> AuthorDate: Tue Dec 16 20:16:54 2025 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Tue Dec 16 20:19:03 2025 +0100 Simplify SwFrame methods getting lengths Order them (left-right; top-bottom). Use the methods in other methods to simplify and clarify. Change-Id: Id5f17fb7ae83590636f504dfb35ebcc4689164aa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195728 Reviewed-by: Mike Kaganski <[email protected]> Tested-by: Jenkins diff --git a/sw/source/core/layout/ssfrm.cxx b/sw/source/core/layout/ssfrm.cxx index 9ded10fa3de2..98b875736d35 100644 --- a/sw/source/core/layout/ssfrm.cxx +++ b/sw/source/core/layout/ssfrm.cxx @@ -41,22 +41,16 @@ #include <osl/diagnose.h> // No inline cause we need the function pointers -tools::Long SwFrame::GetTopMargin() const - { return getFramePrintArea().Top(); } -tools::Long SwFrame::GetBottomMargin() const - { return getFrameArea().Height() -getFramePrintArea().Height() -getFramePrintArea().Top(); } -tools::Long SwFrame::GetLeftMargin() const - { return getFramePrintArea().Left(); } +tools::Long SwFrame::GetLeftMargin() const { return getFramePrintArea().Left(); } tools::Long SwFrame::GetRightMargin() const - { return getFrameArea().Width() - getFramePrintArea().Width() - getFramePrintArea().Left(); } -tools::Long SwFrame::GetPrtLeft() const - { return getFrameArea().Left() + getFramePrintArea().Left(); } -tools::Long SwFrame::GetPrtBottom() const - { return getFrameArea().Top() + getFramePrintArea().Height() + getFramePrintArea().Top(); } -tools::Long SwFrame::GetPrtRight() const - { return getFrameArea().Left() + getFramePrintArea().Width() + getFramePrintArea().Left(); } -tools::Long SwFrame::GetPrtTop() const - { return getFrameArea().Top() + getFramePrintArea().Top(); } + { return getFrameArea().Width() - getFramePrintArea().Width() - GetLeftMargin(); } +tools::Long SwFrame::GetPrtLeft() const { return getFrameArea().Left() + GetLeftMargin(); } +tools::Long SwFrame::GetPrtRight() const { return GetPrtLeft() + getFramePrintArea().Width(); } +tools::Long SwFrame::GetTopMargin() const { return getFramePrintArea().Top(); } +tools::Long SwFrame::GetBottomMargin() const + { return getFrameArea().Height() - getFramePrintArea().Height() - GetTopMargin(); } +tools::Long SwFrame::GetPrtTop() const { return getFrameArea().Top() + GetTopMargin(); } +tools::Long SwFrame::GetPrtBottom() const { return GetPrtTop() + getFramePrintArea().Height(); } bool SwFrame::SetMinLeft( tools::Long nDeadline ) {
