sc/Library_sc.mk | 1 sc/source/ui/docshell/SheetViewOperationsTester.cxx | 2 sc/source/ui/docshell/docfunc.cxx | 71 ---------- sc/source/ui/inc/SheetViewOperationsTester.hxx | 1 sc/source/ui/inc/docfunc.hxx | 2 sc/source/ui/inc/operation/ApplyAttributesOperation.hxx | 42 ++++++ sc/source/ui/operation/ApplyAttributesOperation.cxx | 105 ++++++++++++++++ 7 files changed, 157 insertions(+), 67 deletions(-)
New commits: commit 7d94ce6da1470d032a47b10fa0fc044c2ac8f7c5 Author: Tomaž Vajngerl <[email protected]> AuthorDate: Wed Feb 11 22:21:39 2026 +0900 Commit: Miklos Vajna <[email protected]> CommitDate: Mon Feb 16 15:23:16 2026 +0100 sc: Introduce ApplyAttributesOperation and use impl. from ScDocFunc No functional change, just moving and adapting the code to new location. Change-Id: I4c9c6bf952e861a9be0bbea1d5f5a29853a3a120 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199183 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk index 137c72f06ed8..cdd5fafec742 100644 --- a/sc/Library_sc.mk +++ b/sc/Library_sc.mk @@ -529,6 +529,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\ sc/source/ui/navipi/navcitem \ sc/source/ui/navipi/navipi \ sc/source/ui/navipi/scenwnd \ + sc/source/ui/operation/ApplyAttributesOperation \ sc/source/ui/operation/DeleteCellOperation \ sc/source/ui/operation/DeleteContentOperation \ sc/source/ui/operation/Operation \ diff --git a/sc/source/ui/docshell/SheetViewOperationsTester.cxx b/sc/source/ui/docshell/SheetViewOperationsTester.cxx index 2ef2c6b986a5..5740018ef0b8 100644 --- a/sc/source/ui/docshell/SheetViewOperationsTester.cxx +++ b/sc/source/ui/docshell/SheetViewOperationsTester.cxx @@ -27,6 +27,8 @@ constexpr std::string_view getOperationName(OperationType eOperation) { case OperationType::Unknown: return "Unknown"; + case OperationType::ApplyAttributes: + return "ApplyAttributes"; case OperationType::DeleteContent: return "DeleteContent"; case OperationType::DeleteCell: diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index f9211d3f75ff..f417f18d0a11 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -117,6 +117,7 @@ #include <operation/SetStringOperation.hxx> #include <operation/SetFormulaOperation.hxx> #include <operation/SetEditTextOperation.hxx> +#include <operation/ApplyAttributesOperation.hxx> #include <basic/basmgr.hxx> #include <set> #include <vector> @@ -1133,74 +1134,10 @@ void ScDocFunc::ImportNote( const ScAddress& rPos, aModificator.SetDocumentModified(); } -bool ScDocFunc::ApplyAttributes( const ScMarkData& rMark, const ScPatternAttr& rPattern, - bool bApi ) +bool ScDocFunc::ApplyAttributes(const ScMarkData& rMark, const ScPatternAttr& rPattern, bool bApi ) { - ScDocument& rDoc = rDocShell.GetDocument(); - bool bRecord = true; - if ( !rDoc.IsUndoEnabled() ) - bRecord = false; - - bool bImportingXML = rDoc.IsImportingXML(); - bool bImportingXLSX = rDoc.IsImportingXLSX(); - // Cell formats can still be set if the range isn't editable only because of matrix formulas. - // #i62483# When loading XML, the check can be skipped altogether. - bool bOnlyNotBecauseOfMatrix; - if ( !bImportingXML && !rDoc.IsSelectionEditable( rMark, &bOnlyNotBecauseOfMatrix ) - && !bOnlyNotBecauseOfMatrix ) - { - if (!bApi) - rDocShell.ErrorMessage(STR_PROTECTIONERR); - return false; - } - - ScDocShellModificator aModificator( rDocShell ); - - //! Border - - ScRange aMultiRange; - bool bMulti = rMark.IsMultiMarked(); - if ( bMulti ) - aMultiRange = rMark.GetMultiMarkArea(); - else - aMultiRange = rMark.GetMarkArea(); - - if ( bRecord ) - { - ScDocumentUniquePtr pUndoDoc( new ScDocument( SCDOCMODE_UNDO )); - pUndoDoc->InitUndo( rDoc, aMultiRange.aStart.Tab(), aMultiRange.aEnd.Tab() ); - rDoc.CopyToDocument(aMultiRange, InsertDeleteFlags::ATTRIB, bMulti, *pUndoDoc, &rMark); - - rDocShell.GetUndoManager()->AddUndoAction( - std::make_unique<ScUndoSelectionAttr>( - &rDocShell, rMark, - aMultiRange.aStart.Col(), aMultiRange.aStart.Row(), aMultiRange.aStart.Tab(), - aMultiRange.aEnd.Col(), aMultiRange.aEnd.Row(), aMultiRange.aEnd.Tab(), - std::move(pUndoDoc), bMulti, &rPattern ) ); - } - - // While loading XML it is not necessary to ask HasAttrib. It needs too much time. - sal_uInt16 nExtFlags = 0; - if ( !bImportingXML && !bImportingXLSX ) - rDocShell.UpdatePaintExt( nExtFlags, aMultiRange ); // content before the change - - bool bChanged = false; - rDoc.ApplySelectionPattern( rPattern, rMark, nullptr, &bChanged ); - - if(bChanged) - { - if ( !bImportingXML && !bImportingXLSX ) - rDocShell.UpdatePaintExt( nExtFlags, aMultiRange ); // content after the change - - if (!AdjustRowHeight( aMultiRange, true, bApi )) - rDocShell.PostPaint( aMultiRange, PaintPartFlags::Grid, nExtFlags ); - else if (nExtFlags & SC_PF_LINES) - PaintAbove( rDocShell, aMultiRange ); // because of lines above the range - - aModificator.SetDocumentModified(); - } - - return true; + sc::ApplyAttributesOperation aOperation(*this, rDocShell, rMark, rPattern, bApi); + return aOperation.run(); } bool ScDocFunc::ApplyStyle( const ScMarkData& rMark, const OUString& rStyleName, diff --git a/sc/source/ui/inc/SheetViewOperationsTester.hxx b/sc/source/ui/inc/SheetViewOperationsTester.hxx index da97348a7850..f1c882f9bae3 100644 --- a/sc/source/ui/inc/SheetViewOperationsTester.hxx +++ b/sc/source/ui/inc/SheetViewOperationsTester.hxx @@ -19,6 +19,7 @@ namespace sc enum class OperationType { Unknown, + ApplyAttributes, DeleteContent, DeleteCell, TransliterateText, diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx index 25f53bf6e029..523567c32ffe 100644 --- a/sc/source/ui/inc/docfunc.hxx +++ b/sc/source/ui/inc/docfunc.hxx @@ -66,6 +66,7 @@ namespace sc class SetStringOperation; class SetEditTextOperation; class SetFormulaOperation; + class ApplyAttributesOperation; } namespace tools { @@ -81,6 +82,7 @@ class ScDocFunc friend class sc::SetStringOperation; friend class sc::SetEditTextOperation; friend class sc::SetFormulaOperation; + friend class sc::ApplyAttributesOperation; ScDocShell& rDocShell; static bool CheckSheetViewProtection(sc::OperationType eOperation); diff --git a/sc/source/ui/inc/operation/ApplyAttributesOperation.hxx b/sc/source/ui/inc/operation/ApplyAttributesOperation.hxx new file mode 100644 index 000000000000..7fbc88c84dff --- /dev/null +++ b/sc/source/ui/inc/operation/ApplyAttributesOperation.hxx @@ -0,0 +1,42 @@ +/* -*- 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 "Operation.hxx" +#include <sal/types.h> +#include <rtl/ustring.hxx> +#include <rangelst.hxx> + +class ScDocShell; +class ScMarkData; +class ScPatternAttr; +class ScDocFunc; + +namespace sc +{ +/** Operation which applies input attributes to marked cells or range. */ +class ApplyAttributesOperation : public Operation +{ +private: + ScDocFunc& mrDocFunc; + ScDocShell& mrDocShell; + ScMarkData const& mrMark; + ScPatternAttr const& mrPattern; + + bool runImplementation() override; + +public: + ApplyAttributesOperation(ScDocFunc& rDocFunc, ScDocShell& rDocShell, const ScMarkData& rMark, + const ScPatternAttr& rPattern, bool bApi); +}; + +} // end sc namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/operation/ApplyAttributesOperation.cxx b/sc/source/ui/operation/ApplyAttributesOperation.cxx new file mode 100644 index 000000000000..6c7a85ca33b3 --- /dev/null +++ b/sc/source/ui/operation/ApplyAttributesOperation.cxx @@ -0,0 +1,105 @@ +/* -*- 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 <operation/ApplyAttributesOperation.hxx> + +#include <docfuncutil.hxx> +#include <docfunc.hxx> +#include <address.hxx> +#include <editable.hxx> +#include <undoblk.hxx> +#include <validat.hxx> +#include <globstr.hrc> + +#include <memory> + +namespace sc +{ +ApplyAttributesOperation::ApplyAttributesOperation(ScDocFunc& rDocFunc, ScDocShell& rDocShell, + const ScMarkData& rMark, + const ScPatternAttr& rPattern, bool bApi) + : Operation(OperationType::ApplyAttributes, true, bApi) + , mrDocFunc(rDocFunc) + , mrDocShell(rDocShell) + , mrMark(rMark) + , mrPattern(rPattern) +{ +} + +bool ApplyAttributesOperation::runImplementation() +{ + ScDocument& rDoc = mrDocShell.GetDocument(); + bool bRecord = true; + if (!rDoc.IsUndoEnabled()) + bRecord = false; + + ScMarkData aMark = mrMark; + + bool bImportingXML = rDoc.IsImportingXML(); + bool bImportingXLSX = rDoc.IsImportingXLSX(); + // Cell formats can still be set if the range isn't editable only because of matrix formulas. + // #i62483# When loading XML, the check can be skipped altogether. + bool bOnlyNotBecauseOfMatrix; + if (!bImportingXML && !rDoc.IsSelectionEditable(aMark, &bOnlyNotBecauseOfMatrix) + && !bOnlyNotBecauseOfMatrix) + { + if (!mbApi) + mrDocShell.ErrorMessage(STR_PROTECTIONERR); + return false; + } + + ScDocShellModificator aModificator(mrDocShell); + + //! Border + + ScRange aMultiRange; + bool bMulti = aMark.IsMultiMarked(); + if (bMulti) + aMultiRange = aMark.GetMultiMarkArea(); + else + aMultiRange = aMark.GetMarkArea(); + + if (bRecord) + { + ScDocumentUniquePtr pUndoDoc(new ScDocument(SCDOCMODE_UNDO)); + pUndoDoc->InitUndo(rDoc, aMultiRange.aStart.Tab(), aMultiRange.aEnd.Tab()); + rDoc.CopyToDocument(aMultiRange, InsertDeleteFlags::ATTRIB, bMulti, *pUndoDoc, &aMark); + + mrDocShell.GetUndoManager()->AddUndoAction(std::make_unique<ScUndoSelectionAttr>( + &mrDocShell, aMark, aMultiRange.aStart.Col(), aMultiRange.aStart.Row(), + aMultiRange.aStart.Tab(), aMultiRange.aEnd.Col(), aMultiRange.aEnd.Row(), + aMultiRange.aEnd.Tab(), std::move(pUndoDoc), bMulti, &mrPattern)); + } + + // While loading XML it is not necessary to ask HasAttrib. It needs too much time. + sal_uInt16 nExtFlags = 0; + if (!bImportingXML && !bImportingXLSX) + mrDocShell.UpdatePaintExt(nExtFlags, aMultiRange); // content before the change + + bool bChanged = false; + rDoc.ApplySelectionPattern(mrPattern, aMark, nullptr, &bChanged); + + if (bChanged) + { + if (!bImportingXML && !bImportingXLSX) + mrDocShell.UpdatePaintExt(nExtFlags, aMultiRange); // content after the change + + if (!mrDocFunc.AdjustRowHeight(aMultiRange, true, mbApi)) + mrDocShell.PostPaint(aMultiRange, PaintPartFlags::Grid, nExtFlags); + else if (nExtFlags & SC_PF_LINES) + ScDocFunc::PaintAbove(mrDocShell, aMultiRange); // because of lines above the range + + aModificator.SetDocumentModified(); + } + + return true; +} +} // end sc namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
