svx/source/accessibility/AccessibleTextHelper.cxx | 322 +++++++++++----------- 1 file changed, 164 insertions(+), 158 deletions(-)
New commits: commit 294bbbea5d0d51861aff8c319d4b3932428fc0ff Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Fri Mar 14 14:33:50 2025 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Fri Mar 14 15:10:55 2025 +0100 flatten some code in svx Change-Id: I63a15c6274accf75e66a8981ad4c011a505e1532 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182917 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Jenkins diff --git a/svx/source/accessibility/AccessibleTextHelper.cxx b/svx/source/accessibility/AccessibleTextHelper.cxx index 5870c8df6b87..c37845cff514 100644 --- a/svx/source/accessibility/AccessibleTextHelper.cxx +++ b/svx/source/accessibility/AccessibleTextHelper.cxx @@ -496,188 +496,188 @@ namespace accessibility return; ESelection aSelection; - if( pViewForwarder->GetSelection( aSelection ) ) - { - if( maLastSelection != aSelection && - aSelection.end.nPara < maParaManager.GetNum() ) - { - // #103998# Not that important, changed from assertion to trace - if( mbThisHasFocus ) - { - SAL_INFO("svx", "Parent has focus!"); - } - - sal_Int32 nMaxValidParaIndex( GetTextForwarder().GetParagraphCount() - 1 ); + if( !pViewForwarder->GetSelection( aSelection ) ) + return; - // notify all affected paragraphs (TODO: may be suboptimal, - // since some paragraphs might stay selected) - if (maLastSelection.start.nPara != EE_PARA_MAX) - { - // Did the caret move from one paragraph to another? - // #100530# no caret events if not focused. - if( mbGroupHasFocus && - maLastSelection.end.nPara != aSelection.end.nPara ) - { - if (maLastSelection.end.nPara < maParaManager.GetNum()) - { - maParaManager.FireEvent( ::std::min( maLastSelection.end.nPara, nMaxValidParaIndex ), - ::std::min( maLastSelection.end.nPara, nMaxValidParaIndex )+1, - AccessibleEventId::CARET_CHANGED, - uno::Any(static_cast<sal_Int32>(-1)), - uno::Any(maLastSelection.end.nIndex) ); - } + if( maLastSelection == aSelection || + aSelection.end.nPara >= maParaManager.GetNum() ) + return; - ChangeChildFocus(aSelection.end.nPara); + // #103998# Not that important, changed from assertion to trace + if( mbThisHasFocus ) + { + SAL_INFO("svx", "Parent has focus!"); + } - SAL_INFO( - "svx", - "focus changed, Object: " << this - << ", Paragraph: " << aSelection.end.nPara - << ", Last paragraph: " - << maLastSelection.end.nPara); - } - } + sal_Int32 nMaxValidParaIndex( GetTextForwarder().GetParagraphCount() - 1 ); - // #100530# no caret events if not focused. - if( mbGroupHasFocus ) + // notify all affected paragraphs (TODO: may be suboptimal, + // since some paragraphs might stay selected) + if (maLastSelection.start.nPara != EE_PARA_MAX) + { + // Did the caret move from one paragraph to another? + // #100530# no caret events if not focused. + if( mbGroupHasFocus && + maLastSelection.end.nPara != aSelection.end.nPara ) + { + if (maLastSelection.end.nPara < maParaManager.GetNum()) { - uno::Any aOldCursor; - - // #i13705# The old cursor can only contain valid - // values if it's the same paragraph! - if( maLastSelection.start.nPara != EE_PARA_MAX && - maLastSelection.end.nPara == aSelection.end.nPara ) - { - aOldCursor <<= maLastSelection.end.nIndex; - } - else - { - aOldCursor <<= static_cast<sal_Int32>(-1); - } - - maParaManager.FireEvent( aSelection.end.nPara, - aSelection.end.nPara+1, + maParaManager.FireEvent( ::std::min( maLastSelection.end.nPara, nMaxValidParaIndex ), + ::std::min( maLastSelection.end.nPara, nMaxValidParaIndex )+1, AccessibleEventId::CARET_CHANGED, - uno::Any(aSelection.end.nIndex), - aOldCursor ); + uno::Any(static_cast<sal_Int32>(-1)), + uno::Any(maLastSelection.end.nIndex) ); } + ChangeChildFocus(aSelection.end.nPara); + SAL_INFO( "svx", - "caret changed, Object: " << this << ", New pos: " - << aSelection.end.nIndex << ", Old pos: " - << maLastSelection.end.nIndex << ", New para: " - << aSelection.end.nPara << ", Old para: " + "focus changed, Object: " << this + << ", Paragraph: " << aSelection.end.nPara + << ", Last paragraph: " << maLastSelection.end.nPara); + } + } - // #108947# Sort new range before calling FireEvent - ::std::pair<sal_Int32, sal_Int32> sortedSelection( - makeSortedPair(::std::min( aSelection.start.nPara, nMaxValidParaIndex ), - ::std::min( aSelection.end.nPara, nMaxValidParaIndex ) ) ); - - // #108947# Sort last range before calling FireEvent - ::std::pair<sal_Int32, sal_Int32> sortedLastSelection( - makeSortedPair(::std::min( maLastSelection.start.nPara, nMaxValidParaIndex ), - ::std::min( maLastSelection.end.nPara, nMaxValidParaIndex ) ) ); - - // event TEXT_SELECTION_CHANGED has to be submitted. (#i27299#) - const sal_Int16 nTextSelChgEventId = - AccessibleEventId::TEXT_SELECTION_CHANGED; - // #107037# notify selection change - if (maLastSelection.start.nPara == EE_PARA_MAX) + // #100530# no caret events if not focused. + if( mbGroupHasFocus ) + { + uno::Any aOldCursor; + + // #i13705# The old cursor can only contain valid + // values if it's the same paragraph! + if( maLastSelection.start.nPara != EE_PARA_MAX && + maLastSelection.end.nPara == aSelection.end.nPara ) + { + aOldCursor <<= maLastSelection.end.nIndex; + } + else + { + aOldCursor <<= static_cast<sal_Int32>(-1); + } + + maParaManager.FireEvent( aSelection.end.nPara, + aSelection.end.nPara+1, + AccessibleEventId::CARET_CHANGED, + uno::Any(aSelection.end.nIndex), + aOldCursor ); + } + + SAL_INFO( + "svx", + "caret changed, Object: " << this << ", New pos: " + << aSelection.end.nIndex << ", Old pos: " + << maLastSelection.end.nIndex << ", New para: " + << aSelection.end.nPara << ", Old para: " + << maLastSelection.end.nPara); + + // #108947# Sort new range before calling FireEvent + ::std::pair<sal_Int32, sal_Int32> sortedSelection( + makeSortedPair(::std::min( aSelection.start.nPara, nMaxValidParaIndex ), + ::std::min( aSelection.end.nPara, nMaxValidParaIndex ) ) ); + + // #108947# Sort last range before calling FireEvent + ::std::pair<sal_Int32, sal_Int32> sortedLastSelection( + makeSortedPair(::std::min( maLastSelection.start.nPara, nMaxValidParaIndex ), + ::std::min( maLastSelection.end.nPara, nMaxValidParaIndex ) ) ); + + // event TEXT_SELECTION_CHANGED has to be submitted. (#i27299#) + const sal_Int16 nTextSelChgEventId = + AccessibleEventId::TEXT_SELECTION_CHANGED; + // #107037# notify selection change + if (maLastSelection.start.nPara == EE_PARA_MAX) + { + // last selection is undefined + // use method <ESelection::HasRange()> (#i27299#) + if ( aSelection.HasRange() ) + { + // selection was undefined, now is on + maParaManager.FireEvent( sortedSelection.first, + sortedSelection.second+1, + nTextSelChgEventId ); + } + } + else + { + // last selection is valid + // use method <ESelection::HasRange()> (#i27299#) + if ( maLastSelection.HasRange() && + !aSelection.HasRange() ) + { + // selection was on, now is empty + maParaManager.FireEvent( sortedLastSelection.first, + sortedLastSelection.second+1, + nTextSelChgEventId ); + } + // use method <ESelection::HasRange()> (#i27299#) + else if( !maLastSelection.HasRange() && + aSelection.HasRange() ) + { + // selection was empty, now is on + maParaManager.FireEvent( sortedSelection.first, + sortedSelection.second+1, + nTextSelChgEventId ); + } + // no event TEXT_SELECTION_CHANGED event, if new and + // last selection are empty. (#i27299#) + else if ( maLastSelection.HasRange() && + aSelection.HasRange() ) + { + // use sorted last and new selection + ESelection aTmpLastSel( maLastSelection ); + aTmpLastSel.Adjust(); + ESelection aTmpSel( aSelection ); + aTmpSel.Adjust(); + // first submit event for new and changed selection + sal_Int32 nPara = aTmpSel.start.nPara; + for ( ; nPara <= aTmpSel.end.nPara; ++nPara ) { - // last selection is undefined - // use method <ESelection::HasRange()> (#i27299#) - if ( aSelection.HasRange() ) + if ( nPara < aTmpLastSel.start.nPara || + nPara > aTmpLastSel.end.nPara ) { - // selection was undefined, now is on - maParaManager.FireEvent( sortedSelection.first, - sortedSelection.second+1, + // new selection on paragraph <nPara> + maParaManager.FireEvent( nPara, nTextSelChgEventId ); } - } - else - { - // last selection is valid - // use method <ESelection::HasRange()> (#i27299#) - if ( maLastSelection.HasRange() && - !aSelection.HasRange() ) + else { - // selection was on, now is empty - maParaManager.FireEvent( sortedLastSelection.first, - sortedLastSelection.second+1, - nTextSelChgEventId ); + // check for changed selection on paragraph <nPara> + const sal_Int32 nParaStartPos = + nPara == aTmpSel.start.nPara + ? aTmpSel.start.nIndex : 0; + const sal_Int32 nParaEndPos = + nPara == aTmpSel.end.nPara + ? aTmpSel.end.nIndex : -1; + const sal_Int32 nLastParaStartPos = + nPara == aTmpLastSel.start.nPara + ? aTmpLastSel.start.nIndex : 0; + const sal_Int32 nLastParaEndPos = + nPara == aTmpLastSel.end.nPara + ? aTmpLastSel.end.nIndex : -1; + if ( nParaStartPos != nLastParaStartPos || + nParaEndPos != nLastParaEndPos ) + { + maParaManager.FireEvent( + nPara, nTextSelChgEventId ); + } } - // use method <ESelection::HasRange()> (#i27299#) - else if( !maLastSelection.HasRange() && - aSelection.HasRange() ) + } + // second submit event for 'old' selections + nPara = aTmpLastSel.start.nPara; + for ( ; nPara <= aTmpLastSel.end.nPara; ++nPara ) + { + if ( nPara < aTmpSel.start.nPara || + nPara > aTmpSel.end.nPara ) { - // selection was empty, now is on - maParaManager.FireEvent( sortedSelection.first, - sortedSelection.second+1, + maParaManager.FireEvent( nPara, nTextSelChgEventId ); } - // no event TEXT_SELECTION_CHANGED event, if new and - // last selection are empty. (#i27299#) - else if ( maLastSelection.HasRange() && - aSelection.HasRange() ) - { - // use sorted last and new selection - ESelection aTmpLastSel( maLastSelection ); - aTmpLastSel.Adjust(); - ESelection aTmpSel( aSelection ); - aTmpSel.Adjust(); - // first submit event for new and changed selection - sal_Int32 nPara = aTmpSel.start.nPara; - for ( ; nPara <= aTmpSel.end.nPara; ++nPara ) - { - if ( nPara < aTmpLastSel.start.nPara || - nPara > aTmpLastSel.end.nPara ) - { - // new selection on paragraph <nPara> - maParaManager.FireEvent( nPara, - nTextSelChgEventId ); - } - else - { - // check for changed selection on paragraph <nPara> - const sal_Int32 nParaStartPos = - nPara == aTmpSel.start.nPara - ? aTmpSel.start.nIndex : 0; - const sal_Int32 nParaEndPos = - nPara == aTmpSel.end.nPara - ? aTmpSel.end.nIndex : -1; - const sal_Int32 nLastParaStartPos = - nPara == aTmpLastSel.start.nPara - ? aTmpLastSel.start.nIndex : 0; - const sal_Int32 nLastParaEndPos = - nPara == aTmpLastSel.end.nPara - ? aTmpLastSel.end.nIndex : -1; - if ( nParaStartPos != nLastParaStartPos || - nParaEndPos != nLastParaEndPos ) - { - maParaManager.FireEvent( - nPara, nTextSelChgEventId ); - } - } - } - // second submit event for 'old' selections - nPara = aTmpLastSel.start.nPara; - for ( ; nPara <= aTmpLastSel.end.nPara; ++nPara ) - { - if ( nPara < aTmpSel.start.nPara || - nPara > aTmpSel.end.nPara ) - { - maParaManager.FireEvent( nPara, - nTextSelChgEventId ); - } - } - } } - - maLastSelection = aSelection; } } + + maLastSelection = aSelection; } // no selection? no update actions catch( const uno::RuntimeException& ) {} commit 8597681fe6ebf65cb1555e56f14ff748b864be4a Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Fri Mar 14 14:31:26 2025 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Fri Mar 14 15:10:47 2025 +0100 avoid cost of throwing and ignoring exceptions.. .. in AccessibleTextHelper_Impl::UpdateSelection Which gets expensive when we do it for a whole spreadsheet Change-Id: Iaea424903f4abc65d8b7b2342a50feae1aa38db1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182916 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Jenkins diff --git a/svx/source/accessibility/AccessibleTextHelper.cxx b/svx/source/accessibility/AccessibleTextHelper.cxx index f771f638c77d..5870c8df6b87 100644 --- a/svx/source/accessibility/AccessibleTextHelper.cxx +++ b/svx/source/accessibility/AccessibleTextHelper.cxx @@ -489,8 +489,14 @@ namespace accessibility { try { + if( !maEditSource.IsValid() ) + return; + SvxEditViewForwarder* pViewForwarder = maEditSource.GetEditViewForwarder(); + if( !pViewForwarder || !pViewForwarder->IsValid()) + return; + ESelection aSelection; - if( GetEditViewForwarder().GetSelection( aSelection ) ) + if( pViewForwarder->GetSelection( aSelection ) ) { if( maLastSelection != aSelection && aSelection.end.nPara < maParaManager.GetNum() )