Resolves: tdf#133385 dangling pTargetEntry after remove or clear

Change-Id: Id04b08ea5af1341d548f7bb1e3c3c7f5b7197548
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94955
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/vcl/source/treelist/treelistbox.cxx b/vcl/source/treelist/treelistbox.cxx
index d8bc727..bb52e28 100644
--- a/vcl/source/treelist/treelistbox.cxx
+++ b/vcl/source/treelist/treelistbox.cxx
@@ -1977,6 +1977,7 @@ void SvTreeListBox::LoseFocus()
void SvTreeListBox::ModelHasCleared()
{
    pImpl->m_pCursor = nullptr; // else we crash in GetFocus when editing in-place
    pTargetEntry = nullptr;
    pEdCtrl.reset();
    pImpl->Clear();
    nFocusWidth = -1;
@@ -2250,8 +2251,12 @@ void SvTreeListBox::ModelIsRemoving( SvTreeListEntry* pEntry )

void SvTreeListBox::ModelHasRemoved( SvTreeListEntry* pEntry  )
{
    if ( pEntry == pHdlEntry)
    if (pEntry == pHdlEntry)
        pHdlEntry = nullptr;

    if (pEntry == pTargetEntry)
        pTargetEntry = nullptr;

    pImpl->EntryRemoved();
}