sw/inc/AccessibilityCheckStrings.hrc         |    1 
 sw/source/core/access/AccessibilityCheck.cxx |   45 +++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)

New commits:
commit 3f6ad9d3cdd6fe97989d85b7ec31fe9b8ae340cd
Author:     Balazs Varga <balazs.varga.ext...@allotropia.de>
AuthorDate: Fri Jul 21 12:31:20 2023 +0200
Commit:     Balazs Varga <balazs.varga.ext...@allotropia.de>
CommitDate: Fri Jul 21 17:57:36 2023 +0200

    tdf#155000 - A11Y - Add warning message if content control in header/footer
    
    Add warning message if content controls are in the header or footer.
    
    Change-Id: Ie2a0a8aa1bfaf629f8e17828f2f99e590ea4e3af
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154715
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    Reviewed-by: Balazs Varga <balazs.varga.ext...@allotropia.de>

diff --git a/sw/inc/AccessibilityCheckStrings.hrc 
b/sw/inc/AccessibilityCheckStrings.hrc
index 0186c062273b..1412f66372ec 100644
--- a/sw/inc/AccessibilityCheckStrings.hrc
+++ b/sw/inc/AccessibilityCheckStrings.hrc
@@ -37,6 +37,7 @@
 #define STR_HEADING_START               NC_("STR_HEADING_START", "Outline 
levels should start with level 1, instead of level %LEVEL_CURRENT%.")
 #define STR_FONTWORKS                   NC_("STR_FONTWORKS", "Avoid Fontwork 
objects in your documents. Make sure you use it for samples or other 
meaningless text.")
 #define STR_TABLE_FORMATTING            NC_("STR_TABLE_FORMATTING", "Avoid 
using empty table cells for formatting.")
+#define STR_CONTENT_CONTROL_IN_HEADER_OR_FOOTER 
NC_("STR_CONTENT_CONTROL_IN_HEADER", "Avoid content controls in header or 
footer.")
 
 #define STR_DOCUMENT_DEFAULT_LANGUAGE   NC_("STR_DOCUMENT_DEFAULT_LANGUAGE", 
"Document default language is not set.")
 #define STR_STYLE_NO_LANGUAGE           NC_("STR_STYLE_NO_LANGUAGE", "Style 
“%STYLE_NAME%” has no language set.")
diff --git a/sw/source/core/access/AccessibilityCheck.cxx 
b/sw/source/core/access/AccessibilityCheck.cxx
index 4cde7b8a7777..9a990b0fa981 100644
--- a/sw/source/core/access/AccessibilityCheck.cxx
+++ b/sw/source/core/access/AccessibilityCheck.cxx
@@ -1224,6 +1224,50 @@ private:
     int m_prevLevel = 0;
 };
 
+/// Checking content controls in header or footer
+class ContentControlCheck : public NodeCheck
+{
+private:
+    // Boolean indicating if content controls in header or footer warning is 
already triggered.
+    bool m_bPrevPassed;
+
+public:
+    ContentControlCheck(sfx::AccessibilityIssueCollection& rIssueCollection)
+        : NodeCheck(rIssueCollection)
+        , m_bPrevPassed(true)
+    {
+    }
+
+    void check(SwNode* pCurrent) override
+    {
+        if (!m_bPrevPassed)
+            return;
+
+        const SwTextNode* pTextNode = pCurrent->GetTextNode();
+        if (pTextNode)
+        {
+            if (pCurrent->FindHeaderStartNode() || 
pCurrent->FindFooterStartNode())
+            {
+                const SwpHints* pHts = pTextNode->GetpSwpHints();
+                if (pHts)
+                {
+                    for (size_t i = 0; i < pHts->Count(); ++i)
+                    {
+                        const SwTextAttr* pHt = pHts->Get(i);
+                        if (pHt->Which() == RES_TXTATR_CONTENTCONTROL)
+                        {
+                            m_bPrevPassed = false;
+                            lclAddIssue(m_rIssueCollection,
+                                        
SwResId(STR_CONTENT_CONTROL_IN_HEADER_OR_FOOTER));
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+    }
+};
+
 class DocumentCheck : public BaseCheck
 {
 public:
@@ -1458,6 +1502,7 @@ void AccessibilityCheck::init()
         m_aNodeChecks.emplace_back(new SpaceSpacingCheck(m_aIssueCollection));
         m_aNodeChecks.emplace_back(new FakeFootnoteCheck(m_aIssueCollection));
         m_aNodeChecks.emplace_back(new FakeCaptionCheck(m_aIssueCollection));
+        m_aNodeChecks.emplace_back(new 
ContentControlCheck(m_aIssueCollection));
     }
 }
 

Reply via email to