tdf#145030 resync with empty selection if we unselected everything

if we had something selected, but ended up unselecting everything then
while the maSelectionLock is unlocked resync with the empty selection

(git show -w)

Change-Id: Idf3ad1ce93e4dcf94dc79332cbb431dc5d896988
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123420
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/sd/source/ui/animations/CustomAnimationPane.cxx b/sd/source/ui/animations/CustomAnimationPane.cxx
index 77850c5..a125838 100644
--- a/sd/source/ui/animations/CustomAnimationPane.cxx
+++ b/sd/source/ui/animations/CustomAnimationPane.cxx
@@ -2443,22 +2443,37 @@ void CustomAnimationPane::onSelect()
    if( maSelectionLock.isLocked() )
        return;

    ScopeLockGuard aGuard( maSelectionLock );
    DrawViewShell* pViewShell = dynamic_cast< DrawViewShell* >(
        FrameworkHelper::Instance(mrBase)->GetViewShell(FrameworkHelper::msCenterPaneURL).get());
    DrawView* pView = pViewShell ? pViewShell->GetDrawView() : nullptr;
    bool bHadSelection = maViewSelection.hasValue();
    bool bHasSelection = bHadSelection;

    if( pView )
    {
        pView->UnmarkAllObj();
        for( const CustomAnimationEffectPtr& pEffect : maListSelection )
        ScopeLockGuard aGuard( maSelectionLock );

        DrawViewShell* pViewShell = dynamic_cast< DrawViewShell* >(
            FrameworkHelper::Instance(mrBase)->GetViewShell(FrameworkHelper::msCenterPaneURL).get());
        DrawView* pView = pViewShell ? pViewShell->GetDrawView() : nullptr;

        if (pView)
        {
            Reference< XShape > xShape( pEffect->getTargetShape() );
            SdrObject* pObj = SdrObject::getSdrObjectFromXShape(xShape);
            if( pObj )
                pView->MarkObj(pObj, pView->GetSdrPageView());
            pView->UnmarkAllObj();
            bHasSelection = false;
            for( const CustomAnimationEffectPtr& pEffect : maListSelection )
            {
                Reference< XShape > xShape( pEffect->getTargetShape() );
                SdrObject* pObj = SdrObject::getSdrObjectFromXShape(xShape);
                if (pObj)
                {
                    pView->MarkObj(pObj, pView->GetSdrPageView());
                    bHasSelection = true;
                }
            }
        }
    }

    // tdf#145030 if we had something selected, but ended up unselecting everything
    // then now while the maSelectionLock is unlocked resync with the empty selection
    if (bHadSelection != bHasSelection)
        onSelectionChanged();
}

// ICustomAnimationListController