sw/inc/crsrsh.hxx | 2 +- sw/source/core/crsr/crsrsh.cxx | 4 ++-- sw/source/core/crsr/viscrs.cxx | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
New commits: commit f80fc21dc57224a34b416d866f8930369ad54d7e Author: shlok3640 <[email protected]> AuthorDate: Fri Dec 5 13:43:30 2025 +0000 Commit: Mike Kaganski <[email protected]> CommitDate: Sat Dec 13 08:37:51 2025 +0100 tdf#90341 Clean up excessive const_cast in SwCursorShell The GetPageNum function logically retrieves information without modifying the document, so it should be marked as const. This patch: 1. Marks GetPageNum as const in the header and source. 2. Removes the unnecessary const_cast at the call site in viscrs.cxx. 3. Handle the non-const requirement of CurrShell internally using const_cast to preserve logical constness of the API. Change-Id: Id4ff5245d4160166bbddee7dce0b0999bb3fc5c8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195084 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/sw/inc/crsrsh.hxx b/sw/inc/crsrsh.hxx index c126d8a8e878..87afc4f91264 100644 --- a/sw/inc/crsrsh.hxx +++ b/sw/inc/crsrsh.hxx @@ -587,7 +587,7 @@ public: // true: in which cursor is located. // false: which is visible at the upper margin. SW_DLLPUBLIC void GetPageNum( sal_uInt16 &rnPhyNum, sal_uInt16 &rnVirtNum, - bool bAtCursorPos = true, const bool bCalcFrame = true ); + bool bAtCursorPos = true, const bool bCalcFrame = true ) const; // Returns current page's sequential number (1-based),in which cursor is located, ignoring autoinserted empty pages. // Returns 0 on error SW_DLLPUBLIC sal_uInt16 GetPageNumSeqNonEmpty(); diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx index b84d6376fff1..04e52f41096f 100644 --- a/sw/source/core/crsr/crsrsh.cxx +++ b/sw/source/core/crsr/crsrsh.cxx @@ -1565,9 +1565,9 @@ void SwCursorShell::GetCharRectAt(SwRect& rRect, const SwPosition* pPos) } void SwCursorShell::GetPageNum( sal_uInt16 &rnPhyNum, sal_uInt16 &rnVirtNum, - bool bAtCursorPos, const bool bCalcFrame ) + bool bAtCursorPos, const bool bCalcFrame ) const { - CurrShell aCurr( this ); + CurrShell aCurr(const_cast<SwCursorShell*>(this)); // page number: first visible page or the one at the cursor const SwContentFrame* pCFrame; const SwPageFrame *pPg = nullptr; diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx index 150be2666e82..c301d7a9085c 100644 --- a/sw/source/core/crsr/viscrs.cxx +++ b/sw/source/core/crsr/viscrs.cxx @@ -229,7 +229,7 @@ void SwVisibleCursor::SetPosAndShow(SfxViewShell const * pViewShell) sal_uInt16 nPage, nVirtPage; // bCalcFrame=false is important to avoid calculating the layout when // we're in the middle of doing that already. - const_cast<SwCursorShell*>(m_pCursorShell)->GetPageNum(nPage, nVirtPage, /*bAtCursorPos=*/true, /*bCalcFrame=*/false); + m_pCursorShell->GetPageNum(nPage, nVirtPage, /*bAtCursorPos=*/true, /*bCalcFrame=*/false); if (nPage != m_nPageLastTime) { m_nPageLastTime = nPage;
