editeng/source/editeng/editeng.cxx | 13 +++++++------ editeng/source/editeng/editview.cxx | 2 +- editeng/source/editeng/impedit.cxx | 34 +++++++++++++++++----------------- editeng/source/editeng/impedit.hxx | 24 ++++++++++-------------- editeng/source/editeng/impedit2.cxx | 29 ++++++++++++++--------------- editeng/source/editeng/impedit3.cxx | 2 +- 6 files changed, 50 insertions(+), 54 deletions(-)
New commits: commit f104a9d8c806ccb352c680af6a29422d796114df Author: Tomaž Vajngerl <[email protected]> AuthorDate: Fri Feb 2 15:34:25 2024 +0900 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Fri Feb 2 11:29:32 2024 +0100 editeng: GetCursorFlags flags to CursorFlags struct of bools Convert bitflags to struct of bools, which is much easier to read and you don't need to mess with bitwise operations. Change-Id: I475eb2743b105f8a5bfcab1159dff2b298594740 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162925 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/editeng/source/editeng/editeng.cxx b/editeng/source/editeng/editeng.cxx index 95f605b1ccbf..2493325ac578 100644 --- a/editeng/source/editeng/editeng.cxx +++ b/editeng/source/editeng/editeng.cxx @@ -996,7 +996,7 @@ bool EditEngine::PostKeyEvent( const KeyEvent& rKeyEvent, EditView* pEditView, v bool bAllowIdle = true; bool bReadOnly = pEditView->IsReadOnly(); - GetCursorFlags nNewCursorFlags = GetCursorFlags::NONE; + CursorFlags aNewCursorFlags; bool bSetCursorFlags = true; EditSelection aCurSel( pEditView->getImpl().GetEditSelection() ); @@ -1122,9 +1122,9 @@ bool EditEngine::PostKeyEvent( const KeyEvent& rKeyEvent, EditView* pEditView, v bMoved = true; if ( nCode == KEY_HOME ) - nNewCursorFlags |= GetCursorFlags::StartOfLine; + aNewCursorFlags.bStartOfLine = true; else if ( nCode == KEY_END ) - nNewCursorFlags |= GetCursorFlags::EndOfLine; + aNewCursorFlags.bEndOfLine = true; } #if OSL_DEBUG_LEVEL > 1 @@ -1402,7 +1402,7 @@ bool EditEngine::PostKeyEvent( const KeyEvent& rKeyEvent, EditView* pEditView, v } if (bSetCursorFlags) - pEditView->getImpl().mnExtraCursorFlags = nNewCursorFlags; + pEditView->getImpl().maExtraCursorFlags = aNewCursorFlags; if ( bModified ) { @@ -2410,8 +2410,9 @@ tools::Rectangle EditEngine::GetCharacterBounds( const EPosition& rPos ) const // Check against index, not paragraph if ( pNode && ( rPos.nIndex < pNode->Len() ) ) { - aBounds = getImpl().PaMtoEditCursor(EditPaM(pNode, rPos.nIndex), GetCursorFlags::TextOnly); - tools::Rectangle aR2 = getImpl().PaMtoEditCursor(EditPaM(pNode, rPos.nIndex + 1), GetCursorFlags::TextOnly|GetCursorFlags::EndOfLine); + aBounds = getImpl().PaMtoEditCursor(EditPaM(pNode, rPos.nIndex), CursorFlags{.bTextOnly = true}); + CursorFlags aFlags { .bTextOnly = true, .bEndOfLine = true}; + tools::Rectangle aR2 = getImpl().PaMtoEditCursor(EditPaM(pNode, rPos.nIndex + 1), aFlags); if ( aR2.Right() > aBounds.Right() ) aBounds.SetRight( aR2.Right() ); } diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx index c8b702c0de71..e08c3c81d77d 100644 --- a/editeng/source/editeng/editview.cxx +++ b/editeng/source/editeng/editview.cxx @@ -1006,7 +1006,7 @@ bool EditView::ExecuteSpellPopup(const Point& rPosPixel, const Link<SpellCallbac return false; // PaMtoEditCursor returns Logical units - tools::Rectangle aTempRect = getImpEditEngine().PaMtoEditCursor( aPaM, GetCursorFlags::TextOnly ); + tools::Rectangle aTempRect = getImpEditEngine().PaMtoEditCursor(aPaM, CursorFlags{ .bTextOnly = true }); // GetWindowPos works in Logical units aTempRect = getImpl().GetWindowPos(aTempRect); // Convert to pixels diff --git a/editeng/source/editeng/impedit.cxx b/editeng/source/editeng/impedit.cxx index 4d5ba270bcb9..22412fd2fc37 100644 --- a/editeng/source/editeng/impedit.cxx +++ b/editeng/source/editeng/impedit.cxx @@ -187,7 +187,6 @@ ImpEditView::ImpEditView(EditView* pView, EditEngine* pEditEngine, vcl::Window* , mnInvalidateMore(1) , mnControl(EVControlBits::AUTOSCROLL | EVControlBits::ENABLEPASTE) , mnTravelXPos(TRAVEL_X_DONTKNOW) - , mnExtraCursorFlags(GetCursorFlags::NONE) , mnCursorBidiLevel(CURSOR_BIDILEVEL_DONTKNOW) , mnScrollDiffX(0) , mbReadOnly(false) @@ -577,8 +576,7 @@ void ImpEditView::DrawSelectionXOR( EditSelection aTmpSel, vcl::Region* pRegion, if (nEndIndex < nStartIndex) nEndIndex = nStartIndex; - tools::Rectangle aTmpRect(getImpEditEngine().GetEditCursor( - rInfo.rPortion, *rInfo.pLine, nStartIndex, GetCursorFlags::NONE)); + tools::Rectangle aTmpRect(getImpEditEngine().GetEditCursor(rInfo.rPortion, *rInfo.pLine, nStartIndex, CursorFlags())); const Size aLineOffset = getImpEditEngine().getTopLeftDocOffset(rInfo.aArea); aTmpRect.Move(0, aLineOffset.Height()); @@ -1105,15 +1103,15 @@ boost::property_tree::ptree getHyperlinkPropTree(const OUString& sText, const OU } // End of anon namespace -tools::Rectangle ImpEditView::ImplGetEditCursor(EditPaM& aPaM, GetCursorFlags nShowCursorFlags, sal_Int32& nTextPortionStart, ParaPortion const& rParaPortion) const +tools::Rectangle ImpEditView::ImplGetEditCursor(EditPaM& aPaM, CursorFlags aShowCursorFlags, sal_Int32& nTextPortionStart, ParaPortion const& rParaPortion) const { - tools::Rectangle aEditCursor = getImpEditEngine().PaMtoEditCursor( aPaM, nShowCursorFlags ); + tools::Rectangle aEditCursor = getImpEditEngine().PaMtoEditCursor(aPaM, aShowCursorFlags); if (!IsInsertMode() && !maEditSelection.HasRange()) { if ( aPaM.GetNode()->Len() && ( aPaM.GetIndex() < aPaM.GetNode()->Len() ) ) { // If we are behind a portion, and the next portion has other direction, we must change position... - aEditCursor.SetLeft(getImpEditEngine().PaMtoEditCursor( aPaM, GetCursorFlags::TextOnly|GetCursorFlags::PreferPortionStart ).Left() ); + aEditCursor.SetLeft(getImpEditEngine().PaMtoEditCursor(aPaM, CursorFlags{.bTextOnly = true, .bPreferPortionStart = true}).Left()); aEditCursor.SetRight( aEditCursor.Left() ); sal_Int32 nTextPortion = rParaPortion.GetTextPortions().FindPortion( aPaM.GetIndex(), nTextPortionStart, true ); @@ -1125,9 +1123,9 @@ tools::Rectangle ImpEditView::ImplGetEditCursor(EditPaM& aPaM, GetCursorFlags nS else { EditPaM aNext = getEditEngine().CursorRight( aPaM ); - tools::Rectangle aTmpRect = getImpEditEngine().PaMtoEditCursor( aNext, GetCursorFlags::TextOnly ); + tools::Rectangle aTmpRect = getImpEditEngine().PaMtoEditCursor(aNext, CursorFlags{ .bTextOnly = true }); if ( aTmpRect.Top() != aEditCursor.Top() ) - aTmpRect = getImpEditEngine().PaMtoEditCursor( aNext, GetCursorFlags::TextOnly|GetCursorFlags::EndOfLine ); + aTmpRect = getImpEditEngine().PaMtoEditCursor(aNext, CursorFlags{ .bTextOnly = true, .bEndOfLine = true }); aEditCursor.SetRight( aTmpRect.Left() ); } } @@ -1153,7 +1151,8 @@ tools::Rectangle ImpEditView::GetEditCursor() const ParaPortion const& rParaPortion = getEditEngine().GetParaPortions().getRef(nPara); - GetCursorFlags nShowCursorFlags = mnExtraCursorFlags | GetCursorFlags::TextOnly; + CursorFlags aShowCursorFlags = maExtraCursorFlags; + aShowCursorFlags.bTextOnly = true; // Use CursorBidiLevel 0/1 in meaning of // 0: prefer portion end, normal mode @@ -1161,10 +1160,10 @@ tools::Rectangle ImpEditView::GetEditCursor() const if ( ( GetCursorBidiLevel() != CURSOR_BIDILEVEL_DONTKNOW ) && GetCursorBidiLevel() ) { - nShowCursorFlags |= GetCursorFlags::PreferPortionStart; + aShowCursorFlags.bPreferPortionStart = true; } - return ImplGetEditCursor(aPaM, nShowCursorFlags, nTextPortionStart, rParaPortion); + return ImplGetEditCursor(aPaM, aShowCursorFlags, nTextPortionStart, rParaPortion); } void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) @@ -1200,7 +1199,8 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) ParaPortion const& rParaPortion = getEditEngine().GetParaPortions().getRef(nPara); - GetCursorFlags nShowCursorFlags = mnExtraCursorFlags | GetCursorFlags::TextOnly; + CursorFlags aShowCursorFlags = maExtraCursorFlags; + aShowCursorFlags.bTextOnly = true; // Use CursorBidiLevel 0/1 in meaning of // 0: prefer portion end, normal mode @@ -1208,10 +1208,10 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) if ( ( GetCursorBidiLevel() != CURSOR_BIDILEVEL_DONTKNOW ) && GetCursorBidiLevel() ) { - nShowCursorFlags |= GetCursorFlags::PreferPortionStart; + aShowCursorFlags.bPreferPortionStart = true; } - tools::Rectangle aEditCursor = ImplGetEditCursor(aPaM, nShowCursorFlags, nTextPortionStart, rParaPortion); + tools::Rectangle aEditCursor = ImplGetEditCursor(aPaM, aShowCursorFlags, nTextPortionStart, rParaPortion); if ( bGotoCursor ) // && (!getImpEditEngine().GetStatus().AutoPageSize() ) ) { @@ -1458,7 +1458,7 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) CursorDirection nCursorDir = CursorDirection::NONE; if ( IsInsertMode() && !maEditSelection.HasRange() && (getImpEditEngine().HasDifferentRTLLevels(aPaM.GetNode()) ) ) { - sal_uInt16 nTextPortion = rParaPortion.GetTextPortions().FindPortion( aPaM.GetIndex(), nTextPortionStart, bool(nShowCursorFlags & GetCursorFlags::PreferPortionStart) ); + sal_uInt16 nTextPortion = rParaPortion.GetTextPortions().FindPortion( aPaM.GetIndex(), nTextPortionStart, aShowCursorFlags.bPreferPortionStart); const TextPortion& rTextPortion = rParaPortion.GetTextPortions()[nTextPortion]; if (rTextPortion.IsRightToLeft()) nCursorDir = CursorDirection::RTL; @@ -1708,7 +1708,7 @@ bool ImpEditView::MouseButtonUp( const MouseEvent& rMouseEvent ) { mnTravelXPos = TRAVEL_X_DONTKNOW; mnCursorBidiLevel = CURSOR_BIDILEVEL_DONTKNOW; - mnExtraCursorFlags = GetCursorFlags::NONE; + maExtraCursorFlags = CursorFlags(); mbClickedInSelection = false; if ( rMouseEvent.IsMiddle() && !mbReadOnly && @@ -1735,7 +1735,7 @@ bool ImpEditView::MouseButtonDown( const MouseEvent& rMouseEvent ) { getEditEngine().CheckIdleFormatter(); // If fast typing and mouse button downs mnTravelXPos = TRAVEL_X_DONTKNOW; - mnExtraCursorFlags = GetCursorFlags::NONE; + maExtraCursorFlags = CursorFlags(); mnCursorBidiLevel = CURSOR_BIDILEVEL_DONTKNOW; bool bPrevUpdateLayout = getImpEditEngine().SetUpdateLayout(true); mbClickedInSelection = IsSelectionAtPoint( rMouseEvent.GetPosPixel() ); diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx index 275f1d02a1f0..199a9cd29f12 100644 --- a/editeng/source/editeng/impedit.hxx +++ b/editeng/source/editeng/impedit.hxx @@ -90,17 +90,13 @@ namespace editeng { #define ATTRSPECIAL_WHOLEWORD 1 #define ATTRSPECIAL_EDGE 2 -enum class GetCursorFlags { - NONE = 0x0000, - TextOnly = 0x0001, - StartOfLine = 0x0002, - EndOfLine = 0x0004, - PreferPortionStart = 0x0008, +struct CursorFlags +{ + bool bTextOnly : 1 = false; + bool bStartOfLine : 1 = false; + bool bEndOfLine : 1 = false; + bool bPreferPortionStart : 1 = false; }; -namespace o3tl { - template<> struct typed_flags<GetCursorFlags> : is_typed_flags<GetCursorFlags, 0x0f> {}; -} - struct DragAndDropInfo { @@ -281,7 +277,7 @@ private: tools::Long mnInvalidateMore; EVControlBits mnControl; sal_uInt32 mnTravelXPos; - GetCursorFlags mnExtraCursorFlags; + CursorFlags maExtraCursorFlags; sal_uInt16 mnCursorBidiLevel; sal_uInt16 mnScrollDiffX; bool mbReadOnly; @@ -343,7 +339,7 @@ protected: void HideDDCursor(); void ImplDrawHighlightRect(OutputDevice& rTarget, const Point& rDocPosTopLeft, const Point& rDocPosBottomRight, tools::PolyPolygon* pPolyPoly, bool bLOKCalcRTL); - tools::Rectangle ImplGetEditCursor(EditPaM& aPaM, GetCursorFlags nShowCursorFlags, sal_Int32& nTextPortionStart, ParaPortion const& rParaPortion) const; + tools::Rectangle ImplGetEditCursor(EditPaM& aPaM, CursorFlags aShowCursorFlags, sal_Int32& nTextPortionStart, ParaPortion const& rParaPortion) const; public: ImpEditView(EditView* pView, EditEngine* pEditEngine, vcl::Window* pWindow); @@ -1068,8 +1064,8 @@ public: return static_cast<const T&>(GetParaAttrib(nPara, sal_uInt16(nWhich))); } - tools::Rectangle PaMtoEditCursor(EditPaM aPaM, GetCursorFlags nFlags = GetCursorFlags::NONE); - tools::Rectangle GetEditCursor(ParaPortion const& rPortion, EditLine const& rLine, sal_Int32 nIndex, GetCursorFlags nFlags); + tools::Rectangle PaMtoEditCursor(EditPaM aPaM, CursorFlags aFlags = CursorFlags()); + tools::Rectangle GetEditCursor(ParaPortion const& rPortion, EditLine const& rLine, sal_Int32 nIndex, CursorFlags aFlags); bool IsModified() const { return maEditDoc.IsModified(); } void SetModifyFlag(bool b) { maEditDoc.SetModified( b ); } diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx index 39d530a18ccc..d37679c9a612 100644 --- a/editeng/source/editeng/impedit2.cxx +++ b/editeng/source/editeng/impedit2.cxx @@ -492,7 +492,7 @@ bool ImpEditEngine::Command( const CommandEvent& rCEvt, EditView* pView ) const EditLine& rLine = pParaPortion->GetLines()[nLine]; if ( nInputEnd > rLine.GetEnd() ) nInputEnd = rLine.GetEnd(); - tools::Rectangle aR2 = PaMtoEditCursor( EditPaM( aPaM.GetNode(), nInputEnd ), GetCursorFlags::EndOfLine ); + tools::Rectangle aR2 = PaMtoEditCursor( EditPaM( aPaM.GetNode(), nInputEnd ), CursorFlags{ .bEndOfLine = true }); tools::Rectangle aRect = pView->getImpl().GetWindowPos( aR1 ); auto nExtTextInputWidth = aR2.Left() - aR1.Right(); if (EditViewCallbacks* pEditViewCallbacks = pView->getEditViewCallbacks()) @@ -578,7 +578,7 @@ bool ImpEditEngine::Command( const CommandEvent& rCEvt, EditView* pView ) { if (rInfo.pLine->IsIn(n)) { - tools::Rectangle aR = GetEditCursor(*pParaPortion, *rInfo.pLine, n, GetCursorFlags::NONE); + tools::Rectangle aR = GetEditCursor(*pParaPortion, *rInfo.pLine, n, CursorFlags()); aR.Move(getTopLeftDocOffset(rInfo.aArea)); aRects[n - nMinPos] = pView->getImpl().GetWindowPos(aR); } @@ -989,7 +989,7 @@ EditPaM ImpEditEngine::CursorVisualStartEnd( EditView const * mpEditView, const const EditLine& rLine = pParaPortion->GetLines()[nLine]; bool bEmptyLine = rLine.GetStart() == rLine.GetEnd(); - mpEditView->getImpl().mnExtraCursorFlags = GetCursorFlags::NONE; + mpEditView->getImpl().maExtraCursorFlags = CursorFlags(); if ( !bEmptyLine ) { @@ -1044,7 +1044,7 @@ EditPaM ImpEditEngine::CursorVisualLeftRight( EditView const * pEditView, const const EditLine& rLine = pParaPortion->GetLines()[nLine]; bool bEmptyLine = rLine.GetStart() == rLine.GetEnd(); - pEditView->getImpl().mnExtraCursorFlags = GetCursorFlags::NONE; + pEditView->getImpl().maExtraCursorFlags = CursorFlags(); bool bParaRTL = IsRightToLeft( nPara ); @@ -3129,19 +3129,19 @@ EditPaM ImpEditEngine::InsertLineBreak(const EditSelection& aCurSel) // Helper functions tools::Rectangle ImpEditEngine::GetEditCursor(ParaPortion const& rPortion, EditLine const& rLine, - sal_Int32 nIndex, GetCursorFlags nFlags) + sal_Int32 nIndex, CursorFlags aFlags) { // nIndex might be not in the line // Search within the line... tools::Long nX; - if ((nIndex == rLine.GetStart()) && (nFlags & GetCursorFlags::StartOfLine)) + if (nIndex == rLine.GetStart() && aFlags.bStartOfLine) { Range aXRange = GetLineXPosStartEnd(rPortion, rLine); nX = !IsRightToLeft(GetEditDoc().GetPos(rPortion.GetNode())) ? aXRange.Min() : aXRange.Max(); } - else if ((nIndex == rLine.GetEnd()) && (nFlags & GetCursorFlags::EndOfLine)) + else if (nIndex == rLine.GetEnd() && aFlags.bEndOfLine) { Range aXRange = GetLineXPosStartEnd(rPortion, rLine); nX = !IsRightToLeft(GetEditDoc().GetPos(rPortion.GetNode())) ? aXRange.Max() @@ -3149,7 +3149,7 @@ tools::Rectangle ImpEditEngine::GetEditCursor(ParaPortion const& rPortion, EditL } else { - nX = GetXPos(rPortion, rLine, nIndex, bool(nFlags & GetCursorFlags::PreferPortionStart)); + nX = GetXPos(rPortion, rLine, nIndex, aFlags.bPreferPortionStart); } tools::Rectangle aEditCursor; @@ -3157,15 +3157,14 @@ tools::Rectangle ImpEditEngine::GetEditCursor(ParaPortion const& rPortion, EditL aEditCursor.SetRight(nX); aEditCursor.SetBottom(rLine.GetHeight() - 1); - if (nFlags & GetCursorFlags::TextOnly) + if (aFlags.bTextOnly) aEditCursor.SetTop(aEditCursor.Bottom() - rLine.GetTxtHeight() + 1); else - aEditCursor.SetTop(aEditCursor.Bottom() - - std::min(rLine.GetTxtHeight(), rLine.GetHeight()) + 1); + aEditCursor.SetTop(aEditCursor.Bottom() - std::min(rLine.GetTxtHeight(), rLine.GetHeight()) + 1); return aEditCursor; } -tools::Rectangle ImpEditEngine::PaMtoEditCursor( EditPaM aPaM, GetCursorFlags nFlags ) +tools::Rectangle ImpEditEngine::PaMtoEditCursor( EditPaM aPaM, CursorFlags aFlags) { assert( IsUpdateLayout() && "Must not be reached when Update=FALSE: PaMtoEditCursor" ); @@ -3175,8 +3174,8 @@ tools::Rectangle ImpEditEngine::PaMtoEditCursor( EditPaM aPaM, GetCursorFlags nF const EditLine* pLastLine = nullptr; tools::Rectangle aLineArea; - auto FindPortionLineAndArea - = [&, bEOL(bool(nFlags & GetCursorFlags::EndOfLine))](const LineAreaInfo& rInfo) { + auto FindPortionLineAndArea = [&, bEOL(aFlags.bEndOfLine)](const LineAreaInfo& rInfo) + { if (!rInfo.pLine) // start of ParaPortion { ContentNode* pNode = rInfo.rPortion.GetNode(); @@ -3198,7 +3197,7 @@ tools::Rectangle ImpEditEngine::PaMtoEditCursor( EditPaM aPaM, GetCursorFlags nF if (pLastLine && pPortion) { - aEditCursor = GetEditCursor(*pPortion, *pLastLine, nIndex, nFlags); + aEditCursor = GetEditCursor(*pPortion, *pLastLine, nIndex, aFlags); aEditCursor.Move(getTopLeftDocOffset(aLineArea)); } else diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx index bc0bf2823037..e48e90f44406 100644 --- a/editeng/source/editeng/impedit3.cxx +++ b/editeng/source/editeng/impedit3.cxx @@ -876,7 +876,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY ) { GetTextRanger()->SetVertical( IsEffectivelyVertical() ); - tools::Long nTextY = nStartPosY + GetEditCursor(rParaPortion, *pLine, pLine->GetStart(), GetCursorFlags::NONE).Top(); + tools::Long nTextY = nStartPosY + GetEditCursor(rParaPortion, *pLine, pLine->GetStart(), CursorFlags()).Top(); if ( !bSameLineAgain ) { SeekCursor( pNode, nTmpPos+1, aTmpFont );
