cid#1607171 Data race condition
[LibreOffice.git] / sc / source / ui / undo / undosort.cxx
blob4a8844720246bf4f592efc3e975e9c9e7809d692
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <undosort.hxx>
11 #include <globstr.hrc>
12 #include <scresid.hxx>
13 #include <global.hxx>
14 #include <undoutil.hxx>
15 #include <utility>
17 namespace sc {
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);
27 void UndoSort::Undo()
29 BeginUndo();
30 Execute(true);
31 EndUndo();
34 void UndoSort::Redo()
36 BeginRedo();
37 Execute(false);
38 EndRedo();
41 void UndoSort::Execute( bool bUndo )
43 ScDocument& rDoc = pDocShell->GetDocument();
44 sc::ReorderParam aParam = maParam;
45 if (bUndo)
46 aParam.reverse();
47 rDoc.Reorder(aParam);
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);
61 if (maParam.mbByRow)
63 if (aMarkRange.aStart.Row() > 0)
64 aMarkRange.aStart.IncRow(-1);
66 else
68 if (aMarkRange.aStart.Col() > 0)
69 aMarkRange.aStart.IncCol(-1);
71 ScUndoUtil::MarkSimpleBlock(pDocShell, aMarkRange);
73 else
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: */