editeng/source/editeng/impedit.cxx | 90 +++++++++++++++++++++++-------------- editeng/source/editeng/impedit.hxx | 6 ++ svx/source/dialog/weldeditview.cxx | 33 +++++++------ 3 files changed, 80 insertions(+), 49 deletions(-)
New commits: commit 34cf82953ccd260a05a1c3838178ba50314e2eef Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Tue Mar 25 16:58:59 2025 +0100 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Fri Apr 4 16:16:13 2025 +0200 editeng: extract ImpEditView::ImplGetCursorRectAndMaybeScroll() ... to separate it from the VCL-Cursor/LOK logic. Change-Id: I60f533630e6c55e832d1471c1512d6651107d5a7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183310 Reviewed-by: Michael Stahl <michael.st...@allotropia.de> Tested-by: Jenkins diff --git a/editeng/source/editeng/impedit.cxx b/editeng/source/editeng/impedit.cxx index 337183d04ac3..80a27b7952e5 100644 --- a/editeng/source/editeng/impedit.cxx +++ b/editeng/source/editeng/impedit.cxx @@ -1111,7 +1111,9 @@ boost::property_tree::ptree getHyperlinkPropTree(const OUString& sText, const OU } // End of anon namespace -tools::Rectangle ImpEditView::ImplGetEditCursor(EditPaM& aPaM, CursorFlags aShowCursorFlags, sal_Int32& nTextPortionStart, ParaPortion const& rParaPortion) const +tools::Rectangle ImpEditView::ImplGetEditCursor(EditPaM const& aPaM, + CursorFlags const aShowCursorFlags, sal_Int32& nTextPortionStart, + ParaPortion const& rParaPortion) const { tools::Rectangle aEditCursor = getImpEditEngine().PaMtoEditCursor(aPaM, aShowCursorFlags); if (!IsInsertMode() && !maEditSelection.HasRange()) @@ -1174,37 +1176,11 @@ tools::Rectangle ImpEditView::GetEditCursor() const return ImplGetEditCursor(aPaM, aShowCursorFlags, nTextPortionStart, rParaPortion); } -void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) +::std::optional<::std::tuple<tools::Rectangle, tools::Rectangle, CursorFlags, sal_Int32>> +ImpEditView::ImplGetCursorRectAndMaybeScroll(EditPaM const& rPos, + ParaPortion const& rParaPortion, bool const bGotoCursor) { - // No ShowCursor in an empty View ... - if (maOutputArea.IsEmpty()) - return; - if ( (maOutputArea.Left() >= maOutputArea.Right() ) && ( maOutputArea.Top() >= maOutputArea.Bottom() ) ) - return; - - getEditEngine().CheckIdleFormatter(); - - // For some reasons I end up here during the formatting, if the Outliner - // is initialized in Paint, because no SetPool(); - if (getImpEditEngine().IsFormatting()) - return; - if (!getImpEditEngine().IsUpdateLayout()) - return; - if (getImpEditEngine().IsInUndo()) - return; - - if (mpOutputWindow && mpOutputWindow->GetCursor() != GetCursor()) - mpOutputWindow->SetCursor(GetCursor()); - - EditPaM aPaM(maEditSelection.Max()); - sal_Int32 nTextPortionStart = 0; - sal_Int32 nPara = getEditEngine().GetEditDoc().GetPos( aPaM.GetNode() ); - if (nPara == EE_PARA_MAX) // #i94322 - return; - - ParaPortion const& rParaPortion = getEditEngine().GetParaPortions().getRef(nPara); - CursorFlags aShowCursorFlags = maExtraCursorFlags; aShowCursorFlags.bTextOnly = true; @@ -1217,7 +1193,7 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) aShowCursorFlags.bPreferPortionStart = true; } - tools::Rectangle aEditCursor = ImplGetEditCursor(aPaM, aShowCursorFlags, nTextPortionStart, rParaPortion); + tools::Rectangle aEditCursor = ImplGetEditCursor(rPos, aShowCursorFlags, nTextPortionStart, rParaPortion); if ( bGotoCursor ) // && (!getImpEditEngine().GetStatus().AutoPageSize() ) ) { @@ -1267,7 +1243,7 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) else nDocDiffX -= aEditCursor.Left(); } - if ( aPaM.GetIndex() == 0 ) // Olli needed for the Outliner + if (rPos.GetIndex() == 0) // needed for the Outliner { // But make sure that the cursor is not leaving visible area // because of this! @@ -1311,7 +1287,6 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) ( aEditCursor.Right() - nOnePixel <= GetVisDocRight() ) ) { tools::Rectangle aCursorRect = GetWindowPos( aEditCursor ); - GetCursor()->SetPos( aCursorRect.TopLeft() ); Size aCursorSz( aCursorRect.GetSize() ); // Rectangle is inclusive aCursorSz.AdjustWidth( -1 ); @@ -1331,6 +1306,54 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) Size aOldSz( aCursorSz ); aCursorSz.setWidth( aOldSz.Height() ); aCursorSz.setHeight( aOldSz.Width() ); + } + aCursorRect.SetSize(aCursorSz); + return {{aCursorRect, aEditCursor, aShowCursorFlags, nTextPortionStart}}; + } + + return {}; +} + +void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) +{ + // No ShowCursor in an empty View ... + if (maOutputArea.IsEmpty()) + return; + if ( (maOutputArea.Left() >= maOutputArea.Right() ) && ( maOutputArea.Top() >= maOutputArea.Bottom() ) ) + return; + + getEditEngine().CheckIdleFormatter(); + + // For some reasons I end up here during the formatting, if the Outliner + // is initialized in Paint, because no SetPool(); + if (getImpEditEngine().IsFormatting()) + return; + if (!getImpEditEngine().IsUpdateLayout()) + return; + if (getImpEditEngine().IsInUndo()) + return; + + if (mpOutputWindow && mpOutputWindow->GetCursor() != GetCursor()) + mpOutputWindow->SetCursor(GetCursor()); + + EditPaM aPaM(maEditSelection.Max()); + + sal_Int32 nPara = getEditEngine().GetEditDoc().GetPos( aPaM.GetNode() ); + if (nPara == EE_PARA_MAX) // #i94322 + return; + + ParaPortion const& rParaPortion = getEditEngine().GetParaPortions().getRef(nPara); + + auto const oCursor{ImplGetCursorRectAndMaybeScroll(aPaM, rParaPortion, bGotoCursor)}; + if (oCursor) + { + auto const [aCursorRect, aEditCursor, aShowCursorFlags, nTmp]{*oCursor}; + auto nTextPortionStart{nTmp}; // this one can't be const + GetCursor()->SetPos( aCursorRect.TopLeft() ); + Size aCursorSz( aCursorRect.GetSize() ); + // #111036# Let VCL do orientation for cursor, otherwise problem when cursor has direction flag + if ( IsVertical() ) + { GetCursor()->SetPos( aCursorRect.TopRight() ); GetCursor()->SetOrientation( Degree10(IsTopToBottom() ? 2700 : 900) ); } @@ -1344,6 +1367,7 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) { Point aPos = GetCursor()->GetPos(); boost::property_tree::ptree aMessageParams; + const OutputDevice& rOutDev = GetOutputDevice(); if (mpLOKSpecialPositioning) { // Sending the absolute (pure) logical coordinates of the cursor to the client is not diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx index fc7d376af6dd..6201f894f984 100644 --- a/editeng/source/editeng/impedit.hxx +++ b/editeng/source/editeng/impedit.hxx @@ -340,7 +340,7 @@ protected: void HideDDCursor(); void ImplDrawHighlightRect(OutputDevice& rTarget, const Point& rDocPosTopLeft, const Point& rDocPosBottomRight, tools::PolyPolygon* pPolyPoly, bool bLOKCalcRTL); - tools::Rectangle ImplGetEditCursor(EditPaM& aPaM, CursorFlags aShowCursorFlags, sal_Int32& nTextPortionStart, ParaPortion const& rParaPortion) const; + tools::Rectangle ImplGetEditCursor(EditPaM const& rPaM, CursorFlags aShowCursorFlags, sal_Int32& nTextPortionStart, ParaPortion const& rParaPortion) const; public: ImpEditView(EditView* pView, EditEngine* pEditEngine, vcl::Window* pWindow); @@ -460,6 +460,10 @@ public: tools::Rectangle GetEditCursor() const; + ::std::optional<::std::tuple<tools::Rectangle, tools::Rectangle, CursorFlags, sal_Int32>> + ImplGetCursorRectAndMaybeScroll(EditPaM const& rPos, + ParaPortion const& rParaPortion, bool bGotoCursor); + void ShowCursor( bool bGotoCursor, bool bForceVisCursor ); Pair Scroll( tools::Long ndX, tools::Long ndY, ScrollRangeCheck nRangeCheck = ScrollRangeCheck::NoNegative ); commit 8b4a7ea0ac0f26aeaa896cad39235bf2f8195841 Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Fri Feb 14 15:36:03 2025 +0100 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Fri Apr 4 16:16:05 2025 +0200 svx: flatten WeldEditView::DoPaint() Change-Id: I411bcc24400a18fc64c901dba3a0cde0187786e0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181678 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/svx/source/dialog/weldeditview.cxx b/svx/source/dialog/weldeditview.cxx index 1e4af457d560..1303fb5be2bf 100644 --- a/svx/source/dialog/weldeditview.cxx +++ b/svx/source/dialog/weldeditview.cxx @@ -225,28 +225,31 @@ void WeldEditView::PaintSelection(vcl::RenderContext& rRenderContext, tools::Rec void WeldEditView::DoPaint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) { + EditView* const pEditView{ GetEditView() }; + + if (pEditView == nullptr) + { + return; + } + rRenderContext.Push(vcl::PushFlags::ALL); rRenderContext.SetClipRegion(); - std::vector<tools::Rectangle> aLogicRects; + pEditView->Paint(comphelper::LibreOfficeKit::isActive() ? rRenderContext.PixelToLogic(rRect) + : rRect, + &rRenderContext); - if (EditView* pEditView = GetEditView()) + if (HasFocus()) { - pEditView->Paint(comphelper::LibreOfficeKit::isActive() ? rRenderContext.PixelToLogic(rRect) - : rRect, - &rRenderContext); - - if (HasFocus()) - { - pEditView->ShowCursor(false); - vcl::Cursor* pCursor = pEditView->GetCursor(); - pCursor->DrawToDevice(rRenderContext); - } - - // get logic selection - pEditView->GetSelectionRectangles(aLogicRects); + pEditView->ShowCursor(false); + vcl::Cursor* pCursor = pEditView->GetCursor(); + pCursor->DrawToDevice(rRenderContext); } + // get logic selection + std::vector<tools::Rectangle> aLogicRects; + pEditView->GetSelectionRectangles(aLogicRects); + const Color aHighlight(SvtOptionsDrawinglayer::getHilightColor()); PaintSelection(rRenderContext, rRect, aLogicRects, aHighlight);