sw/source/core/access/AccessibilityCheck.cxx        |   34 ++++++++++++++--
 sw/source/core/access/AccessibilityIssue.cxx        |   41 +++++++++++++++-----
 sw/source/core/inc/AccessibilityCheck.hxx           |    2 
 sw/source/core/inc/AccessibilityIssue.hxx           |    1 
 sw/source/core/txtnode/OnlineAccessibilityCheck.cxx |    4 -
 5 files changed, 63 insertions(+), 19 deletions(-)

New commits:
commit fa13d9c0e7c113a0a39ba4cbc5093135597513d2
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Thu Mar 6 10:43:23 2025 +0100
Commit:     Adolfo Jayme Barrientos <fit...@ubuntu.com>
CommitDate: Mon Mar 10 01:41:46 2025 +0100

    tdf#161583 sw: a11y check: warn about flys with RES_URL with no "name"
    
    Fly frames can have hyperlinks too.
    
    Change-Id: I80da4b53e44e6f82a4f37f4b2aa859b8475b452a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182577
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit 5445e9de41b1330fa27e07d46eaa4babe956645f)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182624
    Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com>

diff --git a/sw/source/core/access/AccessibilityCheck.cxx 
b/sw/source/core/access/AccessibilityCheck.cxx
index 1526ce43da6d..d66abd060518 100644
--- a/sw/source/core/access/AccessibilityCheck.cxx
+++ b/sw/source/core/access/AccessibilityCheck.cxx
@@ -43,6 +43,7 @@
 #include <o3tl/vector_utils.hxx>
 #include <svx/swframetypes.hxx>
 #include <fmtanchr.hxx>
+#include <fmturl.hxx>
 #include <dcontact.hxx>
 #include <unotext.hxx>
 #include <svx/svdoashp.hxx>
@@ -2259,13 +2260,38 @@ public:
 } // end anonymous namespace
 
 // Check Shapes, TextBox
-void AccessibilityCheck::checkObject(SwNode* pCurrent, SdrObject* pObject)
+void AccessibilityCheck::checkObject(SwNode* pCurrent, SwFrameFormat const& 
rFrameFormat)
 {
+    SdrObject const* const pObject{ rFrameFormat.FindSdrObject() };
     if (!pObject)
         return;
 
+    // check hyperlink
+    if (SwFormatURL const* const pItem{ rFrameFormat.GetItemIfSet(RES_URL, 
false) })
+    {
+        OUString const sHyperlink{ pItem->GetURL() };
+        if (!sHyperlink.isEmpty() && pItem->GetName().isEmpty())
+        {
+            INetURLObject const aHyperlink(sHyperlink);
+            if (aHyperlink.GetProtocol() != INetProtocol::NotValid)
+            {
+                std::shared_ptr<sw::AccessibilityIssue> pNameIssue
+                    = lclAddIssue(m_aIssueCollection, 
SwResId(STR_HYPERLINK_NO_NAME),
+                                  
sfx::AccessibilityIssueID::HYPERLINK_NO_NAME);
+
+                if (pNameIssue)
+                {
+                    pNameIssue->setIssueObject(IssueObject::HYPERLINKFLY);
+                    pNameIssue->setObjectID(rFrameFormat.GetName());
+                    pNameIssue->setNode(pCurrent);
+                    pNameIssue->setDoc(*m_pDoc);
+                }
+            }
+        }
+    }
+
     // Check for fontworks.
-    if (SdrObjCustomShape* pCustomShape = 
dynamic_cast<SdrObjCustomShape*>(pObject))
+    if (SdrObjCustomShape const* pCustomShape = dynamic_cast<SdrObjCustomShape 
const*>(pObject))
     {
         const SdrCustomShapeGeometryItem& rGeometryItem
             = pCustomShape->GetMergedItem(SDRATTR_CUSTOMSHAPE_GEOMETRY);
@@ -2403,9 +2429,7 @@ void AccessibilityCheck::check()
 
             for (SwFrameFormat* const& pFrameFormat : pNode->GetAnchoredFlys())
             {
-                SdrObject* pObject = pFrameFormat->FindSdrObject();
-                if (pObject)
-                    checkObject(pNode, pObject);
+                checkObject(pNode, *pFrameFormat);
             }
         }
     }
diff --git a/sw/source/core/access/AccessibilityIssue.cxx 
b/sw/source/core/access/AccessibilityIssue.cxx
index 5c34449f6e40..eac76bda1291 100644
--- a/sw/source/core/access/AccessibilityIssue.cxx
+++ b/sw/source/core/access/AccessibilityIssue.cxx
@@ -29,6 +29,7 @@
 
 #include <svx/svdview.hxx>
 #include <flyfrm.hxx>
+#include <fmturl.hxx>
 #include <unotextrange.hxx>
 #include <txatbase.hxx>
 #include <txtfrm.hxx>
@@ -82,6 +83,7 @@ void AccessibilityIssue::gotoIssue() const
         case IssueObject::GRAPHIC:
         case IssueObject::OLE:
         case IssueObject::TEXTFRAME:
+        case IssueObject::HYPERLINKFLY:
         {
             bool bSelected = pWrtShell->GotoFly(TempIssueObject.m_sObjectID, 
FLYCNTTYPE_ALL, true);
 
@@ -244,6 +246,7 @@ bool AccessibilityIssue::canQuickFixIssue() const
            || m_eIssueObject == IssueObject::DOCUMENT_TITLE
            || m_eIssueObject == IssueObject::DOCUMENT_BACKGROUND
            || m_eIssueObject == IssueObject::LANGUAGE_NOT_SET
+           || m_eIssueObject == IssueObject::HYPERLINKFLY
            || m_eIssueObject == IssueObject::HYPERLINKTEXT;
 }
 
@@ -327,6 +330,7 @@ void AccessibilityIssue::quickFixIssue() const
         }
         break;
         case IssueObject::HYPERLINKTEXT:
+        case IssueObject::HYPERLINKFLY:
         {
             SvxAbstractDialogFactory* pFact = 
SvxAbstractDialogFactory::Create();
             SwWrtShell* pWrtShell = m_pDoc->GetDocShell()->GetWrtShell();
@@ -335,18 +339,35 @@ void AccessibilityIssue::quickFixIssue() const
                 SwResId(STR_HYPERLINK_NO_NAME_DLG)));
             if (aNameDialog->Execute() == RET_OK)
             {
-                SwContentNode* pContentNode = m_pNode->GetContentNode();
-                SwPosition aStart(*pContentNode, m_nStart);
-                SwPosition aEnd(*pContentNode, m_nEnd);
-                uno::Reference<text::XTextRange> xRun
-                    = SwXTextRange::CreateXTextRange(*m_pDoc, aStart, &aEnd);
-                if (xRun.is())
+                if (m_eIssueObject == IssueObject::HYPERLINKTEXT)
                 {
-                    uno::Reference<beans::XPropertySet> xProperties(xRun, 
uno::UNO_QUERY);
-                    if 
(xProperties->getPropertySetInfo()->hasPropertyByName(u"HyperLinkName"_ustr))
+                    SwContentNode* pContentNode = m_pNode->GetContentNode();
+                    SwPosition aStart(*pContentNode, m_nStart);
+                    SwPosition aEnd(*pContentNode, m_nEnd);
+                    uno::Reference<text::XTextRange> xRun
+                        = SwXTextRange::CreateXTextRange(*m_pDoc, aStart, 
&aEnd);
+                    if (xRun.is())
                     {
-                        xProperties->setPropertyValue(u"HyperLinkName"_ustr,
-                                                      
uno::Any(aNameDialog->GetName()));
+                        uno::Reference<beans::XPropertySet> xProperties(xRun, 
uno::UNO_QUERY);
+                        if 
(xProperties->getPropertySetInfo()->hasPropertyByName(
+                                u"HyperLinkName"_ustr))
+                        {
+                            
xProperties->setPropertyValue(u"HyperLinkName"_ustr,
+                                                          
uno::Any(aNameDialog->GetName()));
+                        }
+                    }
+                }
+                else
+                {
+                    SwFlyFrameFormat* const pFlyFormat{ 
const_cast<SwFlyFrameFormat*>(
+                        m_pDoc->FindFlyByName(m_sObjectID)) };
+                    if (pFlyFormat)
+                    {
+                        SwFormatURL item{ pFlyFormat->GetURL() };
+                        item.SetName(aNameDialog->GetName());
+                        SwAttrSet set{ m_pDoc->GetAttrPool(), 
svl::Items<RES_URL, RES_URL> };
+                        set.Put(item);
+                        m_pDoc->SetFlyFrameAttr(*pFlyFormat, set);
                     }
                 }
                 pWrtShell->SetModified();
diff --git a/sw/source/core/inc/AccessibilityCheck.hxx 
b/sw/source/core/inc/AccessibilityCheck.hxx
index caaff1944842..30fb75246481 100644
--- a/sw/source/core/inc/AccessibilityCheck.hxx
+++ b/sw/source/core/inc/AccessibilityCheck.hxx
@@ -49,7 +49,7 @@ public:
     }
 
     void check() override;
-    void checkObject(SwNode* pNode, SdrObject* pObject);
+    void checkObject(SwNode* pNode, SwFrameFormat const&);
     void checkNode(SwNode* pNode);
     void checkDocumentProperties();
 };
diff --git a/sw/source/core/inc/AccessibilityIssue.hxx 
b/sw/source/core/inc/AccessibilityIssue.hxx
index e4c1b3206c76..7ddb31d832a8 100644
--- a/sw/source/core/inc/AccessibilityIssue.hxx
+++ b/sw/source/core/inc/AccessibilityIssue.hxx
@@ -27,6 +27,7 @@ enum class IssueObject
     TABLE,
     TEXT,
     HYPERLINKTEXT,
+    HYPERLINKFLY,
     DOCUMENT_TITLE,
     DOCUMENT_BACKGROUND,
     LANGUAGE_NOT_SET,
diff --git a/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx 
b/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx
index d861084d7018..235a7b5b4545 100644
--- a/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx
+++ b/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx
@@ -140,9 +140,7 @@ void 
OnlineAccessibilityCheck::runAccessibilityCheck(SwNode* pNode)
 
     for (SwFrameFormat* const& pFrameFormat : pNode->GetAnchoredFlys())
     {
-        SdrObject* pObject = pFrameFormat->FindSdrObject();
-        if (pObject)
-            m_aAccessibilityCheck.checkObject(pNode, pObject);
+        m_aAccessibilityCheck.checkObject(pNode, *pFrameFormat);
     }
 
     auto aCollection = m_aAccessibilityCheck.getIssueCollection();

Reply via email to