1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <undosort.hxx>
11 #include <globstr.hrc>
12 #include <scresid.hxx>
14 #include <undoutil.hxx>
19 UndoSort::UndoSort( ScDocShell
* pDocSh
, ReorderParam aParam
) :
20 ScSimpleUndo(pDocSh
), maParam(std::move(aParam
)) {}
22 OUString
UndoSort::GetComment() const
24 return ScResId(STR_UNDO_SORT
);
41 void UndoSort::Execute( bool bUndo
)
43 ScDocument
& rDoc
= pDocShell
->GetDocument();
44 sc::ReorderParam aParam
= maParam
;
49 ScRange
aOverallRange( maParam
.maSortRange
);
50 if (maParam
.maDataAreaExtras
.anyExtrasWanted())
52 aOverallRange
.aStart
.SetCol( maParam
.maDataAreaExtras
.mnStartCol
);
53 aOverallRange
.aStart
.SetRow( maParam
.maDataAreaExtras
.mnStartRow
);
54 aOverallRange
.aEnd
.SetCol( maParam
.maDataAreaExtras
.mnEndCol
);
55 aOverallRange
.aEnd
.SetRow( maParam
.maDataAreaExtras
.mnEndRow
);
58 if (maParam
.mbHasHeaders
)
60 ScRange
aMarkRange( aOverallRange
);
63 if (aMarkRange
.aStart
.Row() > 0)
64 aMarkRange
.aStart
.IncRow(-1);
68 if (aMarkRange
.aStart
.Col() > 0)
69 aMarkRange
.aStart
.IncCol(-1);
71 ScUndoUtil::MarkSimpleBlock(pDocShell
, aMarkRange
);
75 ScUndoUtil::MarkSimpleBlock(pDocShell
, aOverallRange
);
78 rDoc
.SetDirty(maParam
.maSortRange
, true);
79 if (!aParam
.mbUpdateRefs
)
80 rDoc
.BroadcastCells(aParam
.maSortRange
, SfxHintId::ScDataChanged
);
82 pDocShell
->PostPaint(aOverallRange
, PaintPartFlags::Grid
);
83 pDocShell
->PostDataChanged();
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */