Related tdf#156116 - A11Y - fix goto textframes after renaming object

Only give one warninig message (Anchor Frames/Text boxes “As Character“.)
per floating textframes.
Fix goto after renaming textframe.

Follow-up of:
bac847ded67941c6db21a2f041a0b9dad9d2b0bd
069569e4a095f2fe42e94c2dad15356e2038727a

Change-Id: Icc2a9cc90fcb948821a5420b8a1dab61a3a977ae
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156303
Tested-by: Jenkins
Reviewed-by: Balazs Varga <balazs.varga.extern@allotropia.de>
diff --git a/sw/source/core/access/AccessibilityCheck.cxx b/sw/source/core/access/AccessibilityCheck.cxx
index 8c6f116..cf214d0 100644
--- a/sw/source/core/access/AccessibilityCheck.cxx
+++ b/sw/source/core/access/AccessibilityCheck.cxx
@@ -1176,10 +1176,6 @@ public:
/// Check for floating text frames, as it causes problems with reading order.
class FloatingTextCheck : public NodeCheck
{
private:
    // list of already added textframes.
    std::map<SwNodeIndex, SwNodeIndex> m_vIdx;

public:
    FloatingTextCheck(sfx::AccessibilityIssueCollection& rIssueCollection)
        : NodeCheck(rIssueCollection)
@@ -1196,15 +1192,29 @@ public:
        // If a node is in fly and if it is not anchored as char, throw warning.
        const SwNode* startFly = pCurrent->FindFlyStartNode();
        if (startFly
            && startFly->GetFlyFormat()->GetAnchor().GetAnchorId() != RndStdIds::FLY_AS_CHAR
            && m_vIdx.insert(std::make_pair(SwNodeIndex(*startFly), SwNodeIndex(*pCurrent))).second
                   == true)
            && startFly->GetFlyFormat()->GetAnchor().GetAnchorId() != RndStdIds::FLY_AS_CHAR)
        {
            auto pIssue = lclAddIssue(m_rIssueCollection, SwResId(STR_FLOATING_TEXT));
            pIssue->setIssueObject(IssueObject::TEXTFRAME);
            pIssue->setObjectID(startFly->GetFlyFormat()->GetName());
            pIssue->setDoc(pCurrent->GetDoc());
            pIssue->setNode(pCurrent);
            SwNodeIndex aCurrentIdx(*pCurrent);
            SwNodeIndex aIdx(*startFly);
            SwNode* pFirstTextNode = &aIdx.GetNode();
            SwNodeOffset nEnd = startFly->EndOfSectionIndex();
            while (aIdx < nEnd)
            {
                if (pFirstTextNode->IsContentNode() && pFirstTextNode->IsTextNode())
                {
                    if (aIdx == aCurrentIdx)
                    {
                        auto pIssue = lclAddIssue(m_rIssueCollection, SwResId(STR_FLOATING_TEXT));
                        pIssue->setIssueObject(IssueObject::TEXTFRAME);
                        pIssue->setObjectID(startFly->GetFlyFormat()->GetName());
                        pIssue->setDoc(pCurrent->GetDoc());
                        pIssue->setNode(pCurrent);
                    }
                    break;
                }
                ++aIdx;
                pFirstTextNode = &aIdx.GetNode();
            }
        }
    }
};
diff --git a/sw/source/core/access/AccessibilityIssue.cxx b/sw/source/core/access/AccessibilityIssue.cxx
index edef086..080ce2e 100644
--- a/sw/source/core/access/AccessibilityIssue.cxx
+++ b/sw/source/core/access/AccessibilityIssue.cxx
@@ -65,24 +65,24 @@ void AccessibilityIssue::gotoIssue() const
    /* Copying the issueobject because the EnterSelFrameMode ends up calling some sidebar functions
    that recreate the list of a11y issues and the AccessibilityIssue objects are stored by value in a vector
    and the vector is being mutated there and so the instance is overwritten with something else. */
    AccessibilityIssue TempObject(*this);
    AccessibilityIssue TempIssueObject(*this);

    switch (TempObject.m_eIssueObject)
    switch (TempIssueObject.m_eIssueObject)
    {
        case IssueObject::GRAPHIC:
        case IssueObject::OLE:
        case IssueObject::TEXTFRAME:
        {
            SwWrtShell* pWrtShell = TempObject.m_pDoc->GetDocShell()->GetWrtShell();
            bool bSelected = pWrtShell->GotoFly(TempObject.m_sObjectID, FLYCNTTYPE_ALL, true);
            SwWrtShell* pWrtShell = TempIssueObject.m_pDoc->GetDocShell()->GetWrtShell();
            bool bSelected = pWrtShell->GotoFly(TempIssueObject.m_sObjectID, FLYCNTTYPE_ALL, true);
            if (bSelected && pWrtShell->IsFrameSelected())
            {
                pWrtShell->HideCursor();
                pWrtShell->EnterSelFrameMode();
            }

            if (!bSelected && TempObject.m_eIssueObject == IssueObject::TEXTFRAME)
                pWrtShell->GotoDrawingObject(TempObject.m_sObjectID);
            if (!bSelected && TempIssueObject.m_eIssueObject == IssueObject::TEXTFRAME)
                pWrtShell->GotoDrawingObject(TempIssueObject.m_sObjectID);

            if (comphelper::LibreOfficeKit::isActive())
                pWrtShell->ShowCursor();
@@ -90,21 +90,21 @@ void AccessibilityIssue::gotoIssue() const
        break;
        case IssueObject::SHAPE:
        {
            SwWrtShell* pWrtShell = TempObject.m_pDoc->GetDocShell()->GetWrtShell();
            pWrtShell->GotoDrawingObject(TempObject.m_sObjectID);
            SwWrtShell* pWrtShell = TempIssueObject.m_pDoc->GetDocShell()->GetWrtShell();
            pWrtShell->GotoDrawingObject(TempIssueObject.m_sObjectID);
            if (comphelper::LibreOfficeKit::isActive())
                pWrtShell->ShowCursor();
        }
        break;
        case IssueObject::FORM:
        {
            SwWrtShell* pWrtShell = TempObject.m_pDoc->GetDocShell()->GetWrtShell();
            SwWrtShell* pWrtShell = TempIssueObject.m_pDoc->GetDocShell()->GetWrtShell();
            bool bIsDesignMode = pWrtShell->GetView().GetFormShell()->IsDesignMode();
            if (bIsDesignMode || (!bIsDesignMode && pWrtShell->WarnSwitchToDesignModeDialog()))
            {
                if (!bIsDesignMode)
                    pWrtShell->GetView().GetFormShell()->SetDesignMode(true);
                pWrtShell->GotoDrawingObject(TempObject.m_sObjectID);
                pWrtShell->GotoDrawingObject(TempIssueObject.m_sObjectID);
                if (comphelper::LibreOfficeKit::isActive())
                    pWrtShell->ShowCursor();
            }
@@ -112,18 +112,18 @@ void AccessibilityIssue::gotoIssue() const
        break;
        case IssueObject::TABLE:
        {
            SwWrtShell* pWrtShell = TempObject.m_pDoc->GetDocShell()->GetWrtShell();
            pWrtShell->GotoTable(TempObject.m_sObjectID);
            SwWrtShell* pWrtShell = TempIssueObject.m_pDoc->GetDocShell()->GetWrtShell();
            pWrtShell->GotoTable(TempIssueObject.m_sObjectID);
            if (comphelper::LibreOfficeKit::isActive())
                pWrtShell->ShowCursor();
        }
        break;
        case IssueObject::TEXT:
        {
            SwWrtShell* pWrtShell = TempObject.m_pDoc->GetDocShell()->GetWrtShell();
            SwContentNode* pContentNode = TempObject.m_pNode->GetContentNode();
            SwPosition aPoint(*pContentNode, TempObject.m_nStart);
            SwPosition aMark(*pContentNode, TempObject.m_nEnd);
            SwWrtShell* pWrtShell = TempIssueObject.m_pDoc->GetDocShell()->GetWrtShell();
            SwContentNode* pContentNode = TempIssueObject.m_pNode->GetContentNode();
            SwPosition aPoint(*pContentNode, TempIssueObject.m_nStart);
            SwPosition aMark(*pContentNode, TempIssueObject.m_nEnd);
            pWrtShell->EnterStdMode();
            pWrtShell->StartAllAction();
            SwPaM* pPaM = pWrtShell->GetCursor();
@@ -137,9 +137,9 @@ void AccessibilityIssue::gotoIssue() const
        break;
        case IssueObject::FOOTENDNOTE:
        {
            SwWrtShell* pWrtShell = TempObject.m_pDoc->GetDocShell()->GetWrtShell();
            if (TempObject.m_pTextFootnote)
                pWrtShell->GotoFootnoteAnchor(*TempObject.m_pTextFootnote);
            SwWrtShell* pWrtShell = TempIssueObject.m_pDoc->GetDocShell()->GetWrtShell();
            if (TempIssueObject.m_pTextFootnote)
                pWrtShell->GotoFootnoteAnchor(*TempIssueObject.m_pTextFootnote);
            if (comphelper::LibreOfficeKit::isActive())
                pWrtShell->ShowCursor();
        }
@@ -147,7 +147,7 @@ void AccessibilityIssue::gotoIssue() const
        default:
            break;
    }
    TempObject.m_pDoc->GetDocShell()->GetView()->GetEditWin().GrabFocus();
    TempIssueObject.m_pDoc->GetDocShell()->GetView()->GetEditWin().GrabFocus();
}

bool AccessibilityIssue::canQuickFixIssue() const
diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx
index 3f8ed0d..08d47bd 100644
--- a/sw/source/core/layout/atrfrm.cxx
+++ b/sw/source/core/layout/atrfrm.cxx
@@ -2627,14 +2627,13 @@ void SwFrameFormat::SetFormatName( const OUString& rNewName, bool bBroadcast )
            {
                if (pSFly->Lower() && !pSFly->Lower()->IsNoTextFrame())
                {
                    // TODO: update AccessibilityCheckStatus for textframes
                    if (SwTextNode* pSwTxtNode = static_cast<SwTextFrame*>(pSFly->ContainsContent())->GetTextNodeFirst())
                        pSwTxtNode->resetAndQueueAccessibilityCheck(true);
                }
                else
                {
                    if (SwNode* pSwNode = static_cast<SwNoTextFrame*>(pSFly->Lower())->GetNode())
                    {
                        pSwNode->resetAndQueueAccessibilityCheck(true);
                    }
                }
            }
        }