From 403ea882af35337431e0f67aa973c5f046deb630 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Mon, 13 Mar 2023 21:42:47 +0100 Subject: [PATCH] tdf#142978 Add a11y check sidebar Change-Id: I6d9d6dca0118567f68db11b7c0cce60643211ab2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149000 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt --- .../data/org/openoffice/Office/UI/Sidebar.xcu | 52 +++++++ svx/uiconfig/ui/accessibilitycheckentry.ui | 2 +- sw/Library_sw.mk | 1 + sw/UIConfig_swriter.mk | 1 + .../uibase/sidebar/A11yCheckIssuesPanel.cxx | 129 ++++++++++++++++++ .../uibase/sidebar/A11yCheckIssuesPanel.hxx | 74 ++++++++++ sw/source/uibase/sidebar/SwPanelFactory.cxx | 7 + .../swriter/ui/a11ycheckissuespanel.ui | 49 +++++++ 8 files changed, 314 insertions(+), 1 deletion(-) create mode 100644 sw/source/uibase/sidebar/A11yCheckIssuesPanel.cxx create mode 100644 sw/source/uibase/sidebar/A11yCheckIssuesPanel.hxx create mode 100644 sw/uiconfig/swriter/ui/a11ycheckissuespanel.ui diff --git a/officecfg/registry/data/org/openoffice/Office/UI/Sidebar.xcu b/officecfg/registry/data/org/openoffice/Office/UI/Sidebar.xcu index 0747b7eee792..83f4aa33091b 100644 --- a/officecfg/registry/data/org/openoffice/Office/UI/Sidebar.xcu +++ b/officecfg/registry/data/org/openoffice/Office/UI/Sidebar.xcu @@ -81,6 +81,26 @@ + + + Accessibility Check + + + A11yCheckDeck + + + private:graphicrepository/cmd/lc_adddirect.png + + + + WriterVariants, any, visible ; + + + + 900 + + + Shapes @@ -577,6 +597,38 @@ + + + Accessibility Issues + + + true + + + A11yCheckIssuesPanel + + + A11yCheckDeck + + + + + + + WriterVariants, any, visible ; + + + + private:resource/toolpanel/SwPanelFactory/A11yCheckIssuesPanel + + + 100 + + + false + + + Area diff --git a/svx/uiconfig/ui/accessibilitycheckentry.ui b/svx/uiconfig/ui/accessibilitycheckentry.ui index 3d60179f16b5..e084bb367473 100644 --- a/svx/uiconfig/ui/accessibilitycheckentry.ui +++ b/svx/uiconfig/ui/accessibilitycheckentry.ui @@ -29,7 +29,7 @@ - Go to Issue + Go to True True True diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk index 05dd36258649..8a79be4f9e41 100644 --- a/sw/Library_sw.mk +++ b/sw/Library_sw.mk @@ -734,6 +734,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\ sw/source/uibase/sidebar/ThemePanel \ sw/source/uibase/sidebar/SwPanelFactory \ sw/source/uibase/sidebar/WriterInspectorTextPanel \ + sw/source/uibase/sidebar/A11yCheckIssuesPanel \ sw/source/uibase/table/chartins \ sw/source/uibase/table/swtablerep \ sw/source/uibase/table/tablemgr \ diff --git a/sw/UIConfig_swriter.mk b/sw/UIConfig_swriter.mk index 867baf40ba88..7011ed16bdc2 100644 --- a/sw/UIConfig_swriter.mk +++ b/sw/UIConfig_swriter.mk @@ -285,6 +285,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/swriter,\ sw/uiconfig/swriter/ui/pagestylespanel \ sw/uiconfig/swriter/ui/pageheaderpanel \ sw/uiconfig/swriter/ui/pagefooterpanel \ + sw/uiconfig/swriter/ui/a11ycheckissuespanel \ sw/uiconfig/swriter/ui/poseditbox \ sw/uiconfig/swriter/ui/sidebarwrap \ sw/uiconfig/swriter/ui/sidebarstylepresets \ diff --git a/sw/source/uibase/sidebar/A11yCheckIssuesPanel.cxx b/sw/source/uibase/sidebar/A11yCheckIssuesPanel.cxx new file mode 100644 index 000000000000..f9d625f8427b --- /dev/null +++ b/sw/source/uibase/sidebar/A11yCheckIssuesPanel.cxx @@ -0,0 +1,129 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "A11yCheckIssuesPanel.hxx" + +#include + +namespace sw::sidebar +{ +AccessibilityCheckEntry::AccessibilityCheckEntry( + weld::Container* pParent, std::shared_ptr const& rAccessibilityIssue) + : m_xBuilder(Application::CreateBuilder(pParent, "svx/ui/accessibilitycheckentry.ui")) + , m_xContainer(m_xBuilder->weld_container("accessibilityCheckEntryBox")) + , m_xLabel(m_xBuilder->weld_label("accessibilityCheckEntryLabel")) + , m_xGotoButton(m_xBuilder->weld_button("accessibilityCheckEntryGotoButton")) + , m_pAccessibilityIssue(rAccessibilityIssue) +{ + m_xLabel->set_label(m_pAccessibilityIssue->m_aIssueText); + // lock in the height as including the button so all rows are the same height + m_xContainer->set_size_request(-1, m_xContainer->get_preferred_size().Height()); + m_xGotoButton->set_visible(m_pAccessibilityIssue->canGotoIssue()); + m_xGotoButton->connect_clicked(LINK(this, AccessibilityCheckEntry, GotoButtonClicked)); +} + +IMPL_LINK_NOARG(AccessibilityCheckEntry, GotoButtonClicked, weld::Button&, void) +{ + m_pAccessibilityIssue->gotoIssue(); +} + +std::unique_ptr A11yCheckIssuesPanel::Create(weld::Widget* pParent, + SfxBindings* pBindings) +{ + if (pParent == nullptr) + throw ::com::sun::star::lang::IllegalArgumentException( + "no parent window given to A11yCheckIssuesPanel::Create", nullptr, 0); + return std::make_unique(pParent, pBindings); +} + +A11yCheckIssuesPanel::A11yCheckIssuesPanel(weld::Widget* pParent, SfxBindings* pBindings) + : PanelLayout(pParent, "A11yCheckIssuesPanel", "modules/swriter/ui/a11ycheckissuespanel.ui") + , m_xAccessibilityCheckBox(m_xBuilder->weld_box("accessibilityCheckBox")) + , m_xScrolledWindow(m_xBuilder->weld_scrolled_window("scrolledwindow")) + , maA11yCheckController(FN_STAT_ACCESSIBILITY_CHECK, *pBindings, *this) + , mnIssueCount(0) +{ + SwDocShell* pDocSh = dynamic_cast(SfxObjectShell::Current()); + if (!pDocSh) + return; + + mpDoc = pDocSh->GetDoc(); + + populateIssues(); +} + +A11yCheckIssuesPanel::~A11yCheckIssuesPanel() { m_xAccessibilityCheckBox.reset(); } + +void A11yCheckIssuesPanel::populateIssues() +{ + if (!mpDoc) + return; + sw::AccessibilityCheck aCheck(mpDoc); + aCheck.check(); + m_aIssueCollection = aCheck.getIssueCollection(); + + // Remove old issue widgets + for (auto const& xEntry : m_aAccessibilityCheckEntries) + m_xAccessibilityCheckBox->move(xEntry->get_widget(), nullptr); + + sal_Int32 i = 0; + for (std::shared_ptr const& pIssue : m_aIssueCollection.getIssues()) + { + auto xEntry + = std::make_unique(m_xAccessibilityCheckBox.get(), pIssue); + m_xAccessibilityCheckBox->reorder_child(xEntry->get_widget(), i++); + m_aAccessibilityCheckEntries.push_back(std::move(xEntry)); + } + + if (!m_aAccessibilityCheckEntries.empty()) + { + auto nRowHeight + = m_aAccessibilityCheckEntries.back()->get_widget()->get_preferred_size().Height(); + // 6 is the spacing set in the .ui + m_xScrolledWindow->vadjustment_set_step_increment(nRowHeight + 6); + } +} + +void A11yCheckIssuesPanel::NotifyItemUpdate(const sal_uInt16 nSid, const SfxItemState /* eState */, + const SfxPoolItem* pState) +{ + if (!m_xAccessibilityCheckBox) //disposed + return; + + switch (nSid) + { + case FN_STAT_ACCESSIBILITY_CHECK: + { + sal_Int32 nIssueCount = static_cast(pState)->GetValue(); + if (nIssueCount != mnIssueCount) + { + mnIssueCount = nIssueCount; + populateIssues(); + } + } + break; + default: + break; + } +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sw/source/uibase/sidebar/A11yCheckIssuesPanel.hxx b/sw/source/uibase/sidebar/A11yCheckIssuesPanel.hxx new file mode 100644 index 000000000000..23bf6468f196 --- /dev/null +++ b/sw/source/uibase/sidebar/A11yCheckIssuesPanel.hxx @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include + +#include +#include +#include +#include +#include +#include + +#include + +namespace sw::sidebar +{ +class AccessibilityCheckEntry final +{ +private: + std::unique_ptr m_xBuilder; + std::unique_ptr m_xContainer; + std::unique_ptr m_xLabel; + std::unique_ptr m_xGotoButton; + + std::shared_ptr const& m_pAccessibilityIssue; + +public: + AccessibilityCheckEntry(weld::Container* pParent, + std::shared_ptr const& pAccessibilityIssue); + + weld::Widget* get_widget() const { return m_xContainer.get(); } + + DECL_LINK(GotoButtonClicked, weld::Button&, void); +}; + +class A11yCheckIssuesPanel : public PanelLayout, + public ::sfx2::sidebar::ControllerItem::ItemUpdateReceiverInterface +{ +public: + static std::unique_ptr Create(weld::Widget* pParent, SfxBindings* pBindings); + + virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, + const SfxPoolItem* pState) override; + + virtual void GetControlState(const sal_uInt16 /*nSId*/, + boost::property_tree::ptree& /*rState*/) override{}; + + A11yCheckIssuesPanel(weld::Widget* pParent, SfxBindings* pBindings); + virtual ~A11yCheckIssuesPanel() override; + +private: + std::vector> m_aAccessibilityCheckEntries; + std::unique_ptr m_xAccessibilityCheckBox; + std::unique_ptr m_xScrolledWindow; + sfx::AccessibilityIssueCollection m_aIssueCollection; + std::function m_getIssueCollection; + void populateIssues(); + + SwDoc* mpDoc; + ::sfx2::sidebar::ControllerItem maA11yCheckController; + sal_Int32 mnIssueCount; +}; + +} //end of namespace sw::sidebar + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sw/source/uibase/sidebar/SwPanelFactory.cxx b/sw/source/uibase/sidebar/SwPanelFactory.cxx index 5dcd0f389216..5ae3a781bc2d 100644 --- a/sw/source/uibase/sidebar/SwPanelFactory.cxx +++ b/sw/source/uibase/sidebar/SwPanelFactory.cxx @@ -19,6 +19,7 @@ #include +#include "A11yCheckIssuesPanel.hxx" #include "ThemePanel.hxx" #include "StylePresetsPanel.hxx" #include "PageStylesPanel.hxx" @@ -196,6 +197,12 @@ Reference SAL_CALL SwPanelFactory::createUIElement ( xElement = sfx2::sidebar::SidebarPanelBase::Create( rsResourceURL, xFrame, std::move(xPanel), ui::LayoutSize(-1,-1,-1)); } + else if (rsResourceURL.endsWith("/A11yCheckIssuesPanel")) + { + std::unique_ptr xPanel = sw::sidebar::A11yCheckIssuesPanel::Create(pParent, pBindings); + xElement = sfx2::sidebar::SidebarPanelBase::Create( + rsResourceURL, xFrame, std::move(xPanel), ui::LayoutSize(-1,-1,-1)); + } return xElement; } diff --git a/sw/uiconfig/swriter/ui/a11ycheckissuespanel.ui b/sw/uiconfig/swriter/ui/a11ycheckissuespanel.ui new file mode 100644 index 000000000000..da87f9bc8be7 --- /dev/null +++ b/sw/uiconfig/swriter/ui/a11ycheckissuespanel.ui @@ -0,0 +1,49 @@ + + + + + + True + False + True + True + vertical + + + True + True + True + True + in + + + True + False + True + True + + + True + False + start + True + True + vertical + 6 + True + + + + + + + + + + True + True + 1 + + + +