sd/Library_sd.mk | 1 sd/inc/ModelTraverser.hxx | 53 ++++++++++++++++++++++++++++ sd/source/core/ModelTraverser.cxx | 47 +++++++++++++++++++++++++ sd/source/ui/tools/GraphicSizeCheck.cxx | 59 -------------------------------- 4 files changed, 102 insertions(+), 58 deletions(-)
New commits: commit f2ff3ef6bd3a55243847503a65599ff87705c7bd Author: Tomaž Vajngerl <[email protected]> AuthorDate: Fri Apr 25 14:41:35 2025 +0900 Commit: Miklos Vajna <[email protected]> CommitDate: Wed Apr 30 16:38:49 2025 +0200 sd: move ModelTraverser to own file so it can be reused Change-Id: I8d487fd009ca3fa5fb9de8aabe65fd3e5e21b41d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184692 Reviewed-by: Tomaž Vajngerl <[email protected]> Tested-by: Jenkins (cherry picked from commit f6ad4397dc7cee97020d8d2e89345157dbfc7a0f) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184816 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/sd/Library_sd.mk b/sd/Library_sd.mk index df3309c6d78d..a05aba888eb6 100644 --- a/sd/Library_sd.mk +++ b/sd/Library_sd.mk @@ -154,6 +154,7 @@ $(eval $(call gb_Library_add_exception_objects,sd,\ sd/source/core/CustomAnimationEffect \ sd/source/core/CustomAnimationPreset \ sd/source/core/EffectMigration \ + sd/source/core/ModelTraverser \ sd/source/core/PageListWatcher \ sd/source/core/TransitionPreset \ sd/source/core/ThemeColorChanger \ diff --git a/sd/inc/ModelTraverser.hxx b/sd/inc/ModelTraverser.hxx new file mode 100644 index 000000000000..209ace6047e4 --- /dev/null +++ b/sd/inc/ModelTraverser.hxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <vector> +#include <memory> +#include "drawdoc.hxx" + +class SdrObject; + +namespace sd +{ +/** + * Interface for the visitor class, which handles each visited SdrObject + * in the DOM. + */ +class ModelTraverseHandler +{ +public: + virtual ~ModelTraverseHandler() {} + virtual void handleSdrObject(SdrObject* pObject) = 0; +}; + +/** + * Traverses the DOM and calls a handler for each object (SdrObject) it + * encounters. + */ +class ModelTraverser +{ +private: + std::vector<std::shared_ptr<ModelTraverseHandler>> m_pNodeHandler; + SdDrawDocument* m_pDocument; + +public: + ModelTraverser(SdDrawDocument* pDocument) + : m_pDocument(pDocument) + { + } + + void traverse(); + void addNodeHandler(std::shared_ptr<ModelTraverseHandler> pHandler); +}; + +} // end sd namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/core/ModelTraverser.cxx b/sd/source/core/ModelTraverser.cxx new file mode 100644 index 000000000000..6eb15de0a6ee --- /dev/null +++ b/sd/source/core/ModelTraverser.cxx @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <ModelTraverser.hxx> + +#include <svx/svdobj.hxx> +#include <svx/svdpage.hxx> + +using namespace css; + +namespace sd +{ +void ModelTraverser::traverse() +{ + if (!m_pDocument) + return; + + for (sal_uInt16 nPage = 0; nPage < m_pDocument->GetPageCount(); ++nPage) + { + SdrPage* pPage = m_pDocument->GetPage(nPage); + if (pPage) + { + for (const rtl::Reference<SdrObject>& pObject : *pPage) + { + for (auto& pNodeHandler : m_pNodeHandler) + { + pNodeHandler->handleSdrObject(pObject.get()); + } + } + } + } +} + +void ModelTraverser::addNodeHandler(std::shared_ptr<ModelTraverseHandler> pHandler) +{ + m_pNodeHandler.push_back(pHandler); +} + +} // end sd namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/tools/GraphicSizeCheck.cxx b/sd/source/ui/tools/GraphicSizeCheck.cxx index 68bd33a3e194..d145de1ad22d 100644 --- a/sd/source/ui/tools/GraphicSizeCheck.cxx +++ b/sd/source/ui/tools/GraphicSizeCheck.cxx @@ -10,6 +10,7 @@ #include <memory> #include <tools/GraphicSizeCheck.hxx> +#include <ModelTraverser.hxx> #include <svx/strings.hrc> #include <svx/svdobj.hxx> #include <svx/svdpage.hxx> @@ -22,64 +23,6 @@ namespace sd { -namespace -{ -/** - * Interface for the visitor class, which handles each visited SdrObject - * in the DOM. - */ -class ModelTraverseHandler -{ -public: - virtual ~ModelTraverseHandler() {} - - virtual void handleSdrObject(SdrObject* pObject) = 0; -}; - -/** - * Traverses the DOM and calls a handler for each object (SdrObject) it - * encounters. - */ -class ModelTraverser -{ -private: - std::vector<std::shared_ptr<ModelTraverseHandler>> m_pNodeHandler; - SdDrawDocument* m_pDocument; - -public: - ModelTraverser(SdDrawDocument* pDocument) - : m_pDocument(pDocument) - { - } - - void traverse() - { - if (!m_pDocument) - return; - - for (sal_uInt16 nPage = 0; nPage < m_pDocument->GetPageCount(); ++nPage) - { - SdrPage* pPage = m_pDocument->GetPage(nPage); - if (pPage) - { - for (const rtl::Reference<SdrObject>& pObject : *pPage) - { - for (auto& pNodeHandler : m_pNodeHandler) - { - pNodeHandler->handleSdrObject(pObject.get()); - } - } - } - } - } - - void addNodeHandler(std::shared_ptr<ModelTraverseHandler> pHandler) - { - m_pNodeHandler.push_back(pHandler); - } -}; -} - GraphicSizeViolation::GraphicSizeViolation(sal_Int32 nDPI, SdrGrafObj* pGraphicObject) : m_pGraphicObject(pGraphicObject) {
