Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / ui / inc / undocell.hxx
blob98157823cb384fc42ec15527952a8c176c389c57
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/.
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 .
20 #ifndef INCLUDED_SC_SOURCE_UI_INC_UNDOCELL_HXX
21 #define INCLUDED_SC_SOURCE_UI_INC_UNDOCELL_HXX
23 #include "undobase.hxx"
24 #include "postit.hxx"
25 #include "cellvalue.hxx"
26 #include <cellvalues.hxx>
28 #include <memory>
30 class ScDocShell;
31 class ScPatternAttr;
32 class EditTextObject;
33 class SdrUndoAction;
34 class ScDetOpList;
35 class ScDetOpData;
36 class ScRangeName;
37 class ScDocument;
39 namespace sc {
41 class CellValues;
45 class ScUndoCursorAttr: public ScSimpleUndo
47 public:
48 ScUndoCursorAttr( ScDocShell* pNewDocShell,
49 SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab,
50 const ScPatternAttr* pOldPat, const ScPatternAttr* pNewPat,
51 const ScPatternAttr* pApplyPat );
52 virtual ~ScUndoCursorAttr();
54 virtual void Undo() override;
55 virtual void Redo() override;
56 virtual void Repeat(SfxRepeatTarget& rTarget) override;
57 virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override;
59 virtual OUString GetComment() const override;
61 /** once the objects are passed to this class, their life-cycle is
62 managed by this class; the calling function must pass new'ed
63 objects to this method. */
64 void SetEditData( EditTextObject* pOld, EditTextObject* pNew );
66 private:
67 SCCOL nCol;
68 SCROW nRow;
69 SCTAB nTab;
70 ScPatternAttr* pOldPattern;
71 ScPatternAttr* pNewPattern;
72 ScPatternAttr* pApplyPattern;
73 std::shared_ptr<EditTextObject> pOldEditData;
74 std::shared_ptr<EditTextObject> pNewEditData;
75 bool bIsAutomatic;
77 void DoChange( const ScPatternAttr* pWhichPattern, const std::shared_ptr<EditTextObject>& pEditData ) const;
80 class ScUndoEnterData: public ScSimpleUndo
82 public:
84 struct Value
86 SCTAB mnTab;
87 bool mbHasFormat;
88 sal_uInt32 mnFormat;
89 ScCellValue maCell;
91 Value();
94 typedef std::vector<Value> ValuesType;
96 ScUndoEnterData(
97 ScDocShell* pNewDocShell, const ScAddress& rPos,
98 ValuesType& rOldValues, const OUString& rNewStr, EditTextObject* pObj = nullptr );
100 virtual ~ScUndoEnterData();
102 virtual void Undo() override;
103 virtual void Redo() override;
104 virtual void Repeat(SfxRepeatTarget& rTarget) override;
105 virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override;
107 virtual OUString GetComment() const override;
109 private:
110 ValuesType maOldValues;
112 OUString maNewString;
113 std::unique_ptr<EditTextObject> mpNewEditData;
114 sal_uLong mnEndChangeAction;
115 ScAddress maPos;
117 void DoChange() const;
118 void SetChangeTrack();
121 class ScUndoEnterValue: public ScSimpleUndo
123 public:
124 ScUndoEnterValue(
125 ScDocShell* pNewDocShell, const ScAddress& rNewPos,
126 const ScCellValue& rUndoCell, double nVal );
128 virtual ~ScUndoEnterValue();
130 virtual void Undo() override;
131 virtual void Redo() override;
132 virtual void Repeat(SfxRepeatTarget& rTarget) override;
133 virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override;
135 virtual OUString GetComment() const override;
137 private:
138 ScAddress aPos;
139 ScCellValue maOldCell;
140 double nValue;
141 sal_uLong nEndChangeAction;
143 void SetChangeTrack();
146 class ScUndoSetCell : public ScSimpleUndo
148 public:
149 ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const ScCellValue& rOldVal, const ScCellValue& rNewVal );
151 virtual ~ScUndoSetCell();
153 virtual void Undo() override;
154 virtual void Redo() override;
155 virtual void Repeat( SfxRepeatTarget& rTarget ) override;
156 virtual bool CanRepeat( SfxRepeatTarget& rTarget ) const override;
157 virtual OUString GetComment() const override;
159 private:
160 void SetChangeTrack();
161 void SetValue( const ScCellValue& rVal );
163 private:
164 ScAddress maPos;
165 ScCellValue maOldValue;
166 ScCellValue maNewValue;
167 sal_uLong mnEndChangeAction;
170 class ScUndoPageBreak: public ScSimpleUndo
172 public:
173 ScUndoPageBreak( ScDocShell* pNewDocShell,
174 SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab,
175 bool bNewColumn, bool bNewInsert );
176 virtual ~ScUndoPageBreak();
178 virtual void Undo() override;
179 virtual void Redo() override;
180 virtual void Repeat(SfxRepeatTarget& rTarget) override;
181 virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override;
183 virtual OUString GetComment() const override;
185 private:
186 SCCOL nCol;
187 SCROW nRow;
188 SCTAB nTab;
189 bool bColumn; // Column or row break
190 bool bInsert; // Insert or Delete
192 void DoChange( bool bInsert ) const;
195 class ScUndoPrintZoom: public ScSimpleUndo
197 public:
198 ScUndoPrintZoom( ScDocShell* pNewDocShell, SCTAB nT,
199 sal_uInt16 nOS, sal_uInt16 nOP, sal_uInt16 nNS, sal_uInt16 nNP );
200 virtual ~ScUndoPrintZoom();
202 virtual void Undo() override;
203 virtual void Redo() override;
204 virtual void Repeat(SfxRepeatTarget& rTarget) override;
205 virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override;
207 virtual OUString GetComment() const override;
209 private:
210 SCTAB nTab;
211 sal_uInt16 nOldScale;
212 sal_uInt16 nOldPages;
213 sal_uInt16 nNewScale;
214 sal_uInt16 nNewPages;
216 void DoChange( bool bUndo );
219 class ScUndoThesaurus: public ScSimpleUndo
221 public:
222 ScUndoThesaurus( ScDocShell* pNewDocShell,
223 SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab,
224 const ScCellValue& rOldText, const ScCellValue& rNewText );
225 virtual ~ScUndoThesaurus();
227 virtual void Undo() override;
228 virtual void Redo() override;
229 virtual void Repeat(SfxRepeatTarget& rTarget) override;
230 virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override;
232 virtual OUString GetComment() const override;
234 private:
235 SCCOL nCol;
236 SCROW nRow;
237 SCTAB nTab;
238 sal_uLong nEndChangeAction;
240 ScCellValue maOldText;
241 ScCellValue maNewText;
243 void DoChange( bool bUndo, const ScCellValue& rText );
244 void SetChangeTrack( const ScCellValue& rOldCell );
247 /** Undo action for inserting, removing, and replacing a cell note. */
248 class ScUndoReplaceNote : public ScSimpleUndo
250 public:
252 /** Constructs an undo action for inserting or removing a cell note. */
253 ScUndoReplaceNote(
254 ScDocShell& rDocShell,
255 const ScAddress& rPos,
256 const ScNoteData& rNoteData,
257 bool bInsert,
258 SdrUndoAction* pDrawUndo );
260 /** Constructs an undo action for replacing a cell note with another. */
261 ScUndoReplaceNote(
262 ScDocShell& rDocShell,
263 const ScAddress& rPos,
264 const ScNoteData& rOldData,
265 const ScNoteData& rNewData,
266 SdrUndoAction* pDrawUndo );
268 virtual ~ScUndoReplaceNote();
270 virtual void Undo() override;
271 virtual void Redo() override;
272 virtual void Repeat( SfxRepeatTarget& rTarget ) override;
273 virtual bool CanRepeat( SfxRepeatTarget& rTarget ) const override;
275 virtual OUString GetComment() const override;
277 private:
278 void DoInsertNote( const ScNoteData& rNoteData );
279 void DoRemoveNote( const ScNoteData& rNoteData );
281 private:
282 ScAddress maPos;
283 ScNoteData maOldData;
284 ScNoteData maNewData;
285 SdrUndoAction* mpDrawUndo;
288 /** Undo action for showing or hiding a cell note caption. */
289 class ScUndoShowHideNote : public ScSimpleUndo
291 public:
292 ScUndoShowHideNote( ScDocShell& rDocShell, const ScAddress& rPos, bool bShow );
293 virtual ~ScUndoShowHideNote();
295 virtual void Undo() override;
296 virtual void Redo() override;
297 virtual void Repeat( SfxRepeatTarget& rTarget ) override;
298 virtual bool CanRepeat( SfxRepeatTarget& rTarget ) const override;
300 virtual OUString GetComment() const override;
302 private:
303 ScAddress maPos;
304 bool mbShown;
307 class ScUndoDetective: public ScSimpleUndo
309 public:
310 ScUndoDetective( ScDocShell* pNewDocShell,
311 SdrUndoAction* pDraw, const ScDetOpData* pOperation,
312 ScDetOpList* pUndoList = nullptr );
313 virtual ~ScUndoDetective();
315 virtual void Undo() override;
316 virtual void Redo() override;
317 virtual void Repeat(SfxRepeatTarget& rTarget) override;
318 virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override;
320 virtual OUString GetComment() const override;
322 private:
323 bool bIsDelete;
324 ScDetOpList* pOldList;
325 sal_uInt16 nAction;
326 ScAddress aPos;
327 SdrUndoAction* pDrawUndo;
330 class ScUndoRangeNames: public ScSimpleUndo
332 public:
333 //use nTab = -1 for global range names
334 ScUndoRangeNames( ScDocShell* pNewDocShell,
335 ScRangeName* pOld, ScRangeName* pNew , SCTAB nTab = -1);
336 virtual ~ScUndoRangeNames();
338 virtual void Undo() override;
339 virtual void Redo() override;
340 virtual void Repeat(SfxRepeatTarget& rTarget) override;
341 virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override;
343 virtual OUString GetComment() const override;
345 private:
346 ScRangeName* pOldRanges;
347 ScRangeName* pNewRanges;
348 SCTAB mnTab;
350 void DoChange( bool bUndo );
353 namespace sc {
355 class UndoSetCells : public ScSimpleUndo
357 ScAddress maTopPos;
358 CellValues maOldValues;
359 CellValues maNewValues;
361 void DoChange( const CellValues& rValues );
363 public:
364 UndoSetCells( ScDocShell* pDocSh, const ScAddress& rTopPos );
365 virtual ~UndoSetCells();
367 virtual void Undo() override;
368 virtual void Redo() override;
370 virtual bool CanRepeat( SfxRepeatTarget& ) const override;
371 virtual OUString GetComment() const override;
373 CellValues& GetOldValues() { return maOldValues;}
374 void SetNewValues( const std::vector<double>& rVals );
377 } // namespace sc
379 #endif
381 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */