LibreOffice Module sc (master)  1
undosort.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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  */
9 
10 #include <undosort.hxx>
11 #include <globstr.hrc>
12 #include <scresid.hxx>
13 #include <global.hxx>
14 #include <undoutil.hxx>
15 
16 namespace sc {
17 
18 UndoSort::UndoSort( ScDocShell* pDocSh, const ReorderParam& rParam ) :
19  ScSimpleUndo(pDocSh), maParam(rParam) {}
20 
21 OUString UndoSort::GetComment() const
22 {
23  return ScResId(STR_UNDO_SORT);
24 }
25 
27 {
28  BeginUndo();
29  Execute(true);
30  EndUndo();
31 }
32 
34 {
35  BeginRedo();
36  Execute(false);
37  EndRedo();
38 }
39 
40 void UndoSort::Execute( bool bUndo )
41 {
42  ScDocument& rDoc = pDocShell->GetDocument();
43  sc::ReorderParam aParam = maParam;
44  if (bUndo)
45  aParam.reverse();
46  rDoc.Reorder(aParam);
47 
48  ScRange aOverallRange( maParam.maSortRange);
50  {
55  }
56 
58  {
59  ScRange aMarkRange( aOverallRange);
60  if (maParam.mbByRow)
61  {
62  if (aMarkRange.aStart.Row() > 0)
63  aMarkRange.aStart.IncRow(-1);
64  }
65  else
66  {
67  if (aMarkRange.aStart.Col() > 0)
68  aMarkRange.aStart.IncCol(-1);
69  }
71  }
72  else
73  {
74  ScUndoUtil::MarkSimpleBlock(pDocShell, aOverallRange);
75  }
76 
77  rDoc.SetDirty(maParam.maSortRange, true);
78  if (!aParam.mbUpdateRefs)
79  rDoc.BroadcastCells(aParam.maSortRange, SfxHintId::ScDataChanged);
80 
81  pDocShell->PostPaint(aOverallRange, PaintPartFlags::Grid);
83 }
84 
85 }
86 
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScAddress aStart
Definition: address.hxx:499
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:89
virtual void Redo() override
Definition: undosort.cxx:33
SCROW Row() const
Definition: address.hxx:261
UndoSort(ScDocShell *pDocSh, const ReorderParam &rParam)
Definition: undosort.cxx:18
static void MarkSimpleBlock(const ScDocShell *pDocShell, SCCOL nStartX, SCROW nStartY, SCTAB nStartZ, SCCOL nEndX, SCROW nEndY, SCTAB nEndZ)
Mark Block (invisible - has to be repainted)
Definition: undoutil.cxx:31
ScAddress aEnd
Definition: address.hxx:500
void EndUndo()
Definition: undobase.cxx:122
bool anyExtrasWanted() const
Definition: sortparam.hxx:56
ScRange maSortRange
This sort range already takes into account the presence or absence of header row / column i...
Definition: sortparam.hxx:151
void SetRow(SCROW nRowP)
Definition: address.hxx:274
void SetCol(SCCOL nColP)
Definition: address.hxx:278
void BeginRedo()
Definition: undobase.cxx:142
void Reorder(const sc::ReorderParam &rParam)
Definition: documen3.cxx:1447
virtual void Undo() override
Definition: undosort.cxx:26
void IncCol(SCCOL nDelta=1)
Definition: address.hxx:303
ReorderParam maParam
Definition: undosort.hxx:19
ScDocShell * pDocShell
Definition: undobase.hxx:47
void IncRow(SCROW nDelta=1)
Definition: address.hxx:299
void PostPaint(SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, PaintPartFlags nPart, sal_uInt16 nExtFlags=0)
Definition: docsh3.cxx:101
void PostDataChanged()
Definition: docsh3.cxx:93
void BroadcastCells(const ScRange &rRange, SfxHintId nHint, bool bBroadcastSingleBroadcasters=true)
Definition: documen7.cxx:143
SCCOL Col() const
Definition: address.hxx:266
void SetDirty(const ScRange &, bool bIncludeEmptyCells)
Definition: document.cxx:3888
void reverse()
Reorder the position indices such that it can be used to undo the original reordering.
Definition: sortparam.cxx:277
virtual OUString GetComment() const override
Definition: undosort.cxx:21
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
ScDataAreaExtras maDataAreaExtras
Definition: sortparam.hxx:152
void EndRedo()
Definition: undobase.cxx:151
void BeginUndo()
Definition: undobase.cxx:87
void Execute(bool bUndo)
Definition: undosort.cxx:40