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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include "undobase.hxx"
23 #include <detdata.hxx>
25 #include <cellvalue.hxx>
26 #include <cellvalues.hxx>
27 #include <editeng/editobj.hxx>
36 class ScUndoCursorAttr
: public ScSimpleUndo
39 ScUndoCursorAttr( ScDocShell
* pNewDocShell
,
40 SCCOL nNewCol
, SCROW nNewRow
, SCTAB nNewTab
,
41 const ScPatternAttr
* pOldPat
, const ScPatternAttr
* pNewPat
,
42 const ScPatternAttr
* pApplyPat
);
43 virtual ~ScUndoCursorAttr() override
;
45 virtual void Undo() override
;
46 virtual void Redo() override
;
47 virtual void Repeat(SfxRepeatTarget
& rTarget
) override
;
48 virtual bool CanRepeat(SfxRepeatTarget
& rTarget
) const override
;
50 virtual OUString
GetComment() const override
;
52 /** once the objects are passed to this class, their life-cycle is
53 managed by this class; the calling function must pass new'ed
54 objects to this method. */
55 void SetEditData( std::unique_ptr
<EditTextObject
> pOld
, std::unique_ptr
<EditTextObject
> pNew
);
61 const CellAttributeHolder aOldPattern
;
62 const CellAttributeHolder aNewPattern
;
63 const CellAttributeHolder aApplyPattern
;
64 std::unique_ptr
<EditTextObject
> pOldEditData
;
65 std::unique_ptr
<EditTextObject
> pNewEditData
;
67 void DoChange( const CellAttributeHolder
& rWhichPattern
, const std::unique_ptr
<EditTextObject
>& pEditData
) const;
70 class ScUndoEnterData
: public ScSimpleUndo
84 typedef std::vector
<Value
> ValuesType
;
87 ScDocShell
* pNewDocShell
, const ScAddress
& rPos
,
88 ValuesType
& rOldValues
, OUString aNewStr
, std::unique_ptr
<EditTextObject
> pObj
);
90 virtual void Undo() override
;
91 virtual void Redo() override
;
92 virtual void Repeat(SfxRepeatTarget
& rTarget
) override
;
93 virtual bool CanRepeat(SfxRepeatTarget
& rTarget
) const override
;
95 virtual OUString
GetComment() const override
;
97 virtual std::optional
<ScRange
> getAffectedRange() const override
{ return ScRange(maPos
); }
100 ValuesType maOldValues
;
102 OUString maNewString
;
103 std::unique_ptr
<EditTextObject
> mpNewEditData
;
104 sal_uLong mnEndChangeAction
;
107 void DoChange() const;
108 void SetChangeTrack();
111 class ScUndoEnterValue
: public ScSimpleUndo
115 ScDocShell
* pNewDocShell
, const ScAddress
& rNewPos
,
116 ScCellValue aUndoCell
, double nVal
);
118 virtual ~ScUndoEnterValue() override
;
120 virtual void Undo() override
;
121 virtual void Redo() override
;
122 virtual void Repeat(SfxRepeatTarget
& rTarget
) override
;
123 virtual bool CanRepeat(SfxRepeatTarget
& rTarget
) const override
;
125 virtual OUString
GetComment() const override
;
127 virtual std::optional
<ScRange
> getAffectedRange() const override
{ return ScRange(aPos
); }
131 ScCellValue maOldCell
;
133 sal_uLong nEndChangeAction
;
135 void SetChangeTrack();
138 class ScUndoSetCell
: public ScSimpleUndo
141 ScUndoSetCell( ScDocShell
* pDocSh
, const ScAddress
& rPos
, ScCellValue aOldVal
, ScCellValue aNewVal
);
143 virtual ~ScUndoSetCell() override
;
145 virtual void Undo() override
;
146 virtual void Redo() override
;
147 virtual void Repeat( SfxRepeatTarget
& rTarget
) override
;
148 virtual bool CanRepeat( SfxRepeatTarget
& rTarget
) const override
;
149 virtual OUString
GetComment() const override
;
151 virtual std::optional
<ScRange
> getAffectedRange() const override
{ return ScRange(maPos
); }
154 void SetChangeTrack();
155 void SetValue( const ScCellValue
& rVal
);
156 void MoveCursorToCell();
160 ScCellValue maOldValue
;
161 ScCellValue maNewValue
;
162 sal_uLong mnEndChangeAction
;
165 class ScUndoPageBreak
: public ScSimpleUndo
168 ScUndoPageBreak( ScDocShell
* pNewDocShell
,
169 SCCOL nNewCol
, SCROW nNewRow
, SCTAB nNewTab
,
170 bool bNewColumn
, bool bNewInsert
);
171 virtual ~ScUndoPageBreak() override
;
173 virtual void Undo() override
;
174 virtual void Redo() override
;
175 virtual void Repeat(SfxRepeatTarget
& rTarget
) override
;
176 virtual bool CanRepeat(SfxRepeatTarget
& rTarget
) const override
;
178 virtual OUString
GetComment() const override
;
184 bool bColumn
; // Column or row break
185 bool bInsert
; // Insert or Delete
187 void DoChange( bool bInsert
) const;
190 class ScUndoPrintZoom
: public ScSimpleUndo
193 ScUndoPrintZoom( ScDocShell
* pNewDocShell
, SCTAB nT
,
194 sal_uInt16 nOS
, sal_uInt16 nOP
, sal_uInt16 nNS
, sal_uInt16 nNP
);
195 virtual ~ScUndoPrintZoom() override
;
197 virtual void Undo() override
;
198 virtual void Redo() override
;
199 virtual void Repeat(SfxRepeatTarget
& rTarget
) override
;
200 virtual bool CanRepeat(SfxRepeatTarget
& rTarget
) const override
;
202 virtual OUString
GetComment() const override
;
206 sal_uInt16 nOldScale
;
207 sal_uInt16 nOldPages
;
208 sal_uInt16 nNewScale
;
209 sal_uInt16 nNewPages
;
211 void DoChange( bool bUndo
);
214 class ScUndoThesaurus
: public ScSimpleUndo
217 ScUndoThesaurus( ScDocShell
* pNewDocShell
,
218 SCCOL nNewCol
, SCROW nNewRow
, SCTAB nNewTab
,
219 ScCellValue aOldText
, ScCellValue aNewText
);
220 virtual ~ScUndoThesaurus() override
;
222 virtual void Undo() override
;
223 virtual void Redo() override
;
224 virtual void Repeat(SfxRepeatTarget
& rTarget
) override
;
225 virtual bool CanRepeat(SfxRepeatTarget
& rTarget
) const override
;
227 virtual OUString
GetComment() const override
;
233 sal_uLong nEndChangeAction
;
235 ScCellValue maOldText
;
236 ScCellValue maNewText
;
238 void DoChange( bool bUndo
, const ScCellValue
& rText
);
239 void SetChangeTrack( const ScCellValue
& rOldCell
);
242 /** Undo action for inserting, removing, and replacing a cell note. */
243 class ScUndoReplaceNote
: public ScSimpleUndo
247 /** Constructs an undo action for inserting or removing a cell note. */
249 ScDocShell
& rDocShell
,
250 const ScAddress
& rPos
,
251 const ScNoteData
& rNoteData
,
253 std::unique_ptr
<SdrUndoAction
> pDrawUndo
);
255 /** Constructs an undo action for replacing a cell note with another. */
257 ScDocShell
& rDocShell
,
258 const ScAddress
& rPos
,
261 std::unique_ptr
<SdrUndoAction
> pDrawUndo
);
263 virtual ~ScUndoReplaceNote() override
;
265 virtual void Undo() override
;
266 virtual void Redo() override
;
267 virtual void Repeat( SfxRepeatTarget
& rTarget
) override
;
268 virtual bool CanRepeat( SfxRepeatTarget
& rTarget
) const override
;
270 virtual OUString
GetComment() const override
;
272 virtual std::optional
<ScRange
> getAffectedRange() const override
{ return ScRange(maPos
); }
275 void DoInsertNote( const ScNoteData
& rNoteData
);
276 void DoRemoveNote( const ScNoteData
& rNoteData
);
280 ScNoteData maOldData
;
281 ScNoteData maNewData
;
282 std::unique_ptr
<SdrUndoAction
> mpDrawUndo
;
285 /** Undo action for showing or hiding a cell note caption. */
286 class ScUndoShowHideNote
: public ScSimpleUndo
289 ScUndoShowHideNote( ScDocShell
& rDocShell
, const ScAddress
& rPos
, bool bShow
);
290 virtual ~ScUndoShowHideNote() override
;
292 virtual void Undo() override
;
293 virtual void Redo() override
;
294 virtual void Repeat( SfxRepeatTarget
& rTarget
) override
;
295 virtual bool CanRepeat( SfxRepeatTarget
& rTarget
) const override
;
297 virtual OUString
GetComment() const override
;
299 virtual std::optional
<ScRange
> getAffectedRange() const override
{ return ScRange(maPos
); }
306 class ScUndoDetective
: public ScSimpleUndo
309 ScUndoDetective( ScDocShell
* pNewDocShell
,
310 std::unique_ptr
<SdrUndoAction
> pDraw
, const ScDetOpData
* pOperation
,
311 std::unique_ptr
<ScDetOpList
> pUndoList
= nullptr );
312 virtual ~ScUndoDetective() override
;
314 virtual void Undo() override
;
315 virtual void Redo() override
;
316 virtual void Repeat(SfxRepeatTarget
& rTarget
) override
;
317 virtual bool CanRepeat(SfxRepeatTarget
& rTarget
) const override
;
319 virtual OUString
GetComment() const override
;
323 std::unique_ptr
<ScDetOpList
> pOldList
;
326 std::unique_ptr
<SdrUndoAction
> pDrawUndo
;
329 class ScUndoRangeNames
: public ScSimpleUndo
332 //use nTab = -1 for global range names
333 ScUndoRangeNames( ScDocShell
* pNewDocShell
,
334 std::unique_ptr
<ScRangeName
> pOld
, std::unique_ptr
<ScRangeName
> pNew
, SCTAB nTab
);
335 virtual ~ScUndoRangeNames() override
;
337 virtual void Undo() override
;
338 virtual void Redo() override
;
339 virtual void Repeat(SfxRepeatTarget
& rTarget
) override
;
340 virtual bool CanRepeat(SfxRepeatTarget
& rTarget
) const override
;
342 virtual OUString
GetComment() const override
;
345 std::unique_ptr
<ScRangeName
> pOldRanges
;
346 std::unique_ptr
<ScRangeName
> pNewRanges
;
349 void DoChange( bool bUndo
);
354 class UndoSetCells
: public ScSimpleUndo
357 CellValues maOldValues
;
358 CellValues maNewValues
;
360 void DoChange( const CellValues
& rValues
);
363 UndoSetCells( ScDocShell
* pDocSh
, const ScAddress
& rTopPos
);
364 virtual ~UndoSetCells() override
;
366 virtual void Undo() override
;
367 virtual void Redo() override
;
369 virtual bool CanRepeat( SfxRepeatTarget
& ) const override
;
370 virtual OUString
GetComment() const override
;
372 CellValues
& GetOldValues() { return maOldValues
;}
373 void SetNewValues( const std::vector
<double>& rVals
);
374 void SetNewValues( const std::vector
<ScFormulaCell
*>& rVals
);
379 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */