diff --git a/src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp b/src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp index d041ddc1ca..fd712ba1af 100644 --- a/src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp +++ b/src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp @@ -37,11 +37,11 @@ #include "DlgSettingsImp.h" #include "SpreadsheetView.h" +#include "SheetTableViewAccessibleInterface.h" #include "ViewProviderSpreadsheet.h" #include "Workbench.h" - -// use a different name to CreateCommand() + // use a different name to CreateCommand() void CreateSpreadsheetCommands(void); void loadSpreadsheetResource() @@ -52,52 +52,51 @@ void loadSpreadsheetResource() } namespace SpreadsheetGui { -class Module : public Py::ExtensionModule -{ -public: - Module() : Py::ExtensionModule("SpreadsheetGui") + class Module : public Py::ExtensionModule { + public: + Module() : Py::ExtensionModule("SpreadsheetGui") + { add_varargs_method("open",&Module::open - ); - initialize("This module is the SpreadsheetGui module."); // register with Python - } + ); + initialize("This module is the SpreadsheetGui module."); // register with Python + } - ~Module() override {} + ~Module() override {} -private: - Py::Object open(const Py::Tuple& args) - { - char* Name; + private: + Py::Object open(const Py::Tuple& args) + { + char* Name; const char* DocName=nullptr; if (!PyArg_ParseTuple(args.ptr(), "et|s","utf-8",&Name,&DocName)) - throw Py::Exception(); - std::string EncodedName = std::string(Name); - PyMem_Free(Name); + throw Py::Exception(); + std::string EncodedName = std::string(Name); + PyMem_Free(Name); - try { - Base::FileInfo file(EncodedName); + try { + Base::FileInfo file(EncodedName); App::Document *pcDoc = App::GetApplication().newDocument(DocName ? DocName : QT_TR_NOOP("Unnamed")); Spreadsheet::Sheet *pcSheet = static_cast(pcDoc->addObject("Spreadsheet::Sheet", file.fileNamePure().c_str())); - pcSheet->importFromFile(EncodedName, '\t', '"', '\\'); - pcSheet->execute(); - } - catch (const Base::Exception& e) { - throw Py::RuntimeError(e.what()); - } + pcSheet->importFromFile(EncodedName, '\t', '"', '\\'); + pcSheet->execute(); + } + catch (const Base::Exception& e) { + throw Py::RuntimeError(e.what()); + } - return Py::None(); + return Py::None(); + } + }; + + PyObject* initModule() + { + return Base::Interpreter().addModule(new Module); } -}; - -PyObject* initModule() -{ - return Base::Interpreter().addModule(new Module); -} } // namespace SpreadsheetGui - /* Python entry */ PyMOD_INIT_FUNC(SpreadsheetGui) { @@ -109,6 +108,8 @@ PyMOD_INIT_FUNC(SpreadsheetGui) // instantiating the commands CreateSpreadsheetCommands(); + QAccessible::installFactory(SpreadsheetGui::SheetTableViewAccessibleInterface::ifactory); + SpreadsheetGui::ViewProviderSheet::init(); SpreadsheetGui::ViewProviderSheetPython::init(); SpreadsheetGui::Workbench::init(); diff --git a/src/Mod/Spreadsheet/Gui/CMakeLists.txt b/src/Mod/Spreadsheet/Gui/CMakeLists.txt index ab8d012020..b7b2d0b03d 100644 --- a/src/Mod/Spreadsheet/Gui/CMakeLists.txt +++ b/src/Mod/Spreadsheet/Gui/CMakeLists.txt @@ -66,6 +66,8 @@ SET(SpreadsheetGui_SRCS SpreadsheetDelegate.cpp SheetTableView.cpp SheetTableView.h + SheetTableViewAccessibleInterface.h + SheetTableViewAccessibleInterface.cpp SheetModel.h SheetModel.cpp PreCompiled.cpp diff --git a/src/Mod/Spreadsheet/Gui/SheetTableViewAccessibleInterface.cpp b/src/Mod/Spreadsheet/Gui/SheetTableViewAccessibleInterface.cpp new file mode 100644 index 0000000000..891149dc6f --- /dev/null +++ b/src/Mod/Spreadsheet/Gui/SheetTableViewAccessibleInterface.cpp @@ -0,0 +1,85 @@ +/*************************************************************************** + * Copyright (c) 2023 Adrian Popescu * + * * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +# include +# include +# include +# include +# include +# include +#endif + +#include "SheetTableViewAccessibleInterface.h" + +namespace SpreadsheetGui { + + SheetTableViewAccessibleInterface::SheetTableViewAccessibleInterface( + SpreadsheetGui::SheetTableView* w) + : QAccessibleWidget(w) + { + } + + QString SheetTableViewAccessibleInterface::text(QAccessible::Text t) const + { + if (t == QAccessible::Help) + return QString::fromLatin1("Implement me"); + return QAccessibleWidget::text(t); + } + + QAccessibleInterface* SheetTableViewAccessibleInterface::childAt(int x, int y) const + { + return (QAccessibleInterface*)this; + } + + int SheetTableViewAccessibleInterface::indexOfChild(const QAccessibleInterface*) const + { + return 0; + } + + int SheetTableViewAccessibleInterface::childCount() const + { + return 0; + } + + QAccessibleInterface* SheetTableViewAccessibleInterface::focusChild() const + { + return (QAccessibleInterface*)this; + } + + QAccessibleInterface* SheetTableViewAccessibleInterface::child(int index) const + { + return (QAccessibleInterface*)this; + } + + QAccessibleInterface* SheetTableViewAccessibleInterface::ifactory(const QString& key, QObject* o) + { + if (key == QString::fromUtf8("SpreadsheetGui::SheetTableView")) + return new SheetTableViewAccessibleInterface( + static_cast(o)); + return 0; + } +} \ No newline at end of file diff --git a/src/Mod/Spreadsheet/Gui/SheetTableViewAccessibleInterface.h b/src/Mod/Spreadsheet/Gui/SheetTableViewAccessibleInterface.h new file mode 100644 index 0000000000..86a4119f8b --- /dev/null +++ b/src/Mod/Spreadsheet/Gui/SheetTableViewAccessibleInterface.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright (c) 2023 Adrian Popescu * + * * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef SHEETTABLEVIEW_INTERFACE_H +#define SHEETTABLEVIEW_INTERFACE_H + +#include +#include + +namespace SpreadsheetGui { + + // Currently SheetTableViewAccessibleInterface below deactivates the + // built-in QAccessibleTable interface, and all the accessibility + // features. + // + // For a proper implementation, start by extending that + // and ensure you're not queue-ing empty cells, or counting empty cells + // + // Otherwise it will hang - https://github.com/FreeCAD/FreeCAD/issues/8265 + + class SheetTableViewAccessibleInterface : public QAccessibleWidget + { + public: + SheetTableViewAccessibleInterface(SpreadsheetGui::SheetTableView* w); + + QString text(QAccessible::Text t) const override; + + QAccessibleInterface* childAt(int x, int y) const override; + int indexOfChild(const QAccessibleInterface*) const override; + int childCount() const override; + QAccessibleInterface* focusChild() const override; + QAccessibleInterface* child(int index) const override; + + static QAccessibleInterface* ifactory(const QString& key, QObject* o); + }; +} + +#endif // SHEETTABLEVIEW_INTERFACE_H