Resolves: tdf#138512 don't crash on removing already Disposed a11y context

Change-Id: I2a8f3d10a1349de233e11d841f7f244e4e513b2c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151582
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/sw/source/core/access/acccontext.cxx b/sw/source/core/access/acccontext.cxx
index 37cb87f..3445114 100644
--- a/sw/source/core/access/acccontext.cxx
+++ b/sw/source/core/access/acccontext.cxx
@@ -518,9 +518,14 @@ bool SwAccessibleContext::IsEditableState()
    return bRet;
}

bool SwAccessibleContext::IsDisposed() const
{
    return !(GetFrame() && GetMap());
}

void SwAccessibleContext::ThrowIfDisposed()
{
    if (!(GetFrame() && GetMap()))
    if (IsDisposed())
    {
        throw lang::DisposedException("object is nonfunctional",
                static_cast<cppu::OWeakObject*>(this));
diff --git a/sw/source/core/access/acccontext.hxx b/sw/source/core/access/acccontext.hxx
index 32d13ef..d649390 100644
--- a/sw/source/core/access/acccontext.hxx
+++ b/sw/source/core/access/acccontext.hxx
@@ -349,6 +349,8 @@ public:
    virtual bool SetSelectedState(bool bSelected);
    bool  IsSelectedInDoc() const { return m_isSelectedInDoc; }

    bool IsDisposed() const;

    static OUString GetResource(TranslateId pResId,
                                const OUString *pArg1 = nullptr,
                                const OUString *pArg2 = nullptr);
diff --git a/sw/source/core/access/accmap.cxx b/sw/source/core/access/accmap.cxx
index fe0384c..5cc2fd7 100644
--- a/sw/source/core/access/accmap.cxx
+++ b/sw/source/core/access/accmap.cxx
@@ -2673,7 +2673,9 @@ void SwAccessibleMap::InvalidateCursorPosition( const SwFrame *pFrame )

    for (SwAccessibleParagraph* pAccPara : m_setParaRemove)
    {
        if(pAccPara && pAccPara->getSelectedAccessibleChildCount() == 0 && pAccPara->getSelectedText().getLength() == 0)
        if (pAccPara && !pAccPara->IsDisposed() &&
            pAccPara->getSelectedAccessibleChildCount() == 0 &&
            pAccPara->getSelectedText().getLength() == 0)
        {
            if(pAccPara->SetSelectedState(false))
            {