tdf#156116 - A11Y - fix object name does not update in accessibility sidebar

when we modify the name on the Navigator sidebar.
Update the related accessibility issue after we modify the name on the sidebar.

Change-Id: I8f4b8780ff1ffe7cfb86ff837c9579d6b785b832
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155904
Tested-by: Jenkins
Reviewed-by: Balazs Varga <balazs.varga.extern@allotropia.de>
(cherry picked from commit 069569e4a095f2fe42e94c2dad15356e2038727a)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155925
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
diff --git a/sw/inc/OnlineAccessibilityCheck.hxx b/sw/inc/OnlineAccessibilityCheck.hxx
index 1055c7e..1e32055 100644
--- a/sw/inc/OnlineAccessibilityCheck.hxx
+++ b/sw/inc/OnlineAccessibilityCheck.hxx
@@ -57,7 +57,7 @@ private:

    void runAccessibilityCheck(SwNode* pNode);
    void updateStatusbar();
    void updateNodeStatus(SwNode* pContentNode);
    void updateNodeStatus(SwNode* pContentNode, bool bIssueObjectNameChanged = false);
    void initialCheck();
    void lookForPreviousNodeAndUpdate(SwPosition const& rNewPos);
    void clearAccessibilityIssuesFromAllNodes();
@@ -66,7 +66,7 @@ private:
public:
    OnlineAccessibilityCheck(SwDoc& rDocument);
    void update(SwPosition const& rNewPos);
    void resetAndQueue(SwNode* pNode);
    void resetAndQueue(SwNode* pNode, bool bIssueObjectNameChanged = false);
    void resetAndQueueDocumentLevel();
    void updateCheckerActivity();
    sal_Int32 getNumberOfAccessibilityIssues() { return m_nAccessibilityIssues; }
diff --git a/sw/inc/node.hxx b/sw/inc/node.hxx
index a6a7dc6..240bdb0 100644
--- a/sw/inc/node.hxx
+++ b/sw/inc/node.hxx
@@ -336,7 +336,7 @@ public:
        return m_aAccessibilityCheckStatus;
    }

    void resetAndQueueAccessibilityCheck();
    void resetAndQueueAccessibilityCheck(bool bIssueObjectNameChanged = false);

private:
    SwNode( const SwNode & rNodes ) = delete;
diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx
index 64a9e86..4304b87 100644
--- a/sw/source/core/docnode/node.cxx
+++ b/sw/source/core/docnode/node.cxx
@@ -2179,9 +2179,9 @@ void SwNode::RemoveAnchoredFly(SwFrameFormat *const pFlyFormat)
    m_aAnchoredFlys.erase(it);
}

void SwNode::resetAndQueueAccessibilityCheck()
void SwNode::resetAndQueueAccessibilityCheck(bool bIssueObjectNameChanged)
{
    GetDoc().getOnlineAccessibilityCheck()->resetAndQueue(this);
    GetDoc().getOnlineAccessibilityCheck()->resetAndQueue(this, bIssueObjectNameChanged);
}


diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx
index f988cfa..07f767e 100644
--- a/sw/source/core/layout/atrfrm.cxx
+++ b/sw/source/core/layout/atrfrm.cxx
@@ -2614,6 +2614,16 @@ void SwFrameFormat::SetFormatName( const OUString& rNewName, bool bBroadcast )
        if (bBroadcast) {
            GetNotifier().Broadcast(aHint);
        }

        // update accessibility sidebar object name if we modify the object name on the navigator bar
        if (!aHint.m_sOld.isEmpty() && aHint.m_sOld != aHint.m_sNew)
        {
            if (SwFlyFrame* pSFly = SwIterator<SwFlyFrame, SwFormat>(*this).First())
            {
                if (SwNode* pSwNode = static_cast<SwNoTextFrame*>(pSFly->Lower())->GetNode())
                    pSwNode->resetAndQueueAccessibilityCheck(true);
            }
        }
    }
    else
        SwFormat::SetFormatName( rNewName, bBroadcast );
diff --git a/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx b/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx
index c7da361..9836810 100644
--- a/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx
+++ b/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx
@@ -79,13 +79,16 @@ OnlineAccessibilityCheck::OnlineAccessibilityCheck(SwDoc& rDocument)
{
}

void OnlineAccessibilityCheck::updateNodeStatus(SwNode* pNode)
void OnlineAccessibilityCheck::updateNodeStatus(SwNode* pNode, bool bIssueObjectNameChanged)
{
    if (!pNode->IsContentNode() && !pNode->IsTableNode())
        return;

    m_nAccessibilityIssues = 0;

    if (bIssueObjectNameChanged)
        return;

    auto it = m_aNodes.find(pNode);
    if (it == m_aNodes.end())
    {
@@ -292,7 +295,7 @@ void OnlineAccessibilityCheck::clearAccessibilityIssuesFromAllNodes()
    updateStatusbar();
}

void OnlineAccessibilityCheck::resetAndQueue(SwNode* pNode)
void OnlineAccessibilityCheck::resetAndQueue(SwNode* pNode, bool bIssueObjectNameChanged)
{
    if (utl::ConfigManager::IsFuzzing())
        return;
@@ -305,7 +308,7 @@ void OnlineAccessibilityCheck::resetAndQueue(SwNode* pNode)
    pNode->getAccessibilityCheckStatus().reset();
    m_aNodes.erase(pNode);
    runAccessibilityCheck(pNode);
    updateNodeStatus(pNode);
    updateNodeStatus(pNode, bIssueObjectNameChanged);
    updateStatusbar();
}

diff --git a/sw/source/uibase/shells/drwbassh.cxx b/sw/source/uibase/shells/drwbassh.cxx
index cbb8a9c..a5a63a6 100644
--- a/sw/source/uibase/shells/drwbassh.cxx
+++ b/sw/source/uibase/shells/drwbassh.cxx
@@ -595,9 +595,17 @@ void SwDrawBaseShell::Execute(SfxRequest const &rReq)

                if(RET_OK == pDlg->Execute())
                {
                    const OUString aOrigName = aName;
                    pDlg->GetName(aName);
                    pSelected->SetName(aName);
                    pSh->SetModified();

                    // update accessibility sidebar object name if we modify the object name on the navigator bar
                    if (!aName.isEmpty() && aOrigName != aName)
                    {
                        if (SwNode* pSwNode = FindFrameFormat(pSelected)->GetAnchor().GetAnchorNode())
                            pSwNode->resetAndQueueAccessibilityCheck(true);
                    }
                }
            }