/src/libreoffice/sc/source/ui/inc/undocell.hxx
Line | Count | Source |
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 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include "undobase.hxx" |
23 | | #include <detdata.hxx> |
24 | | #include <postit.hxx> |
25 | | #include <cellvalue.hxx> |
26 | | #include <cellvalues.hxx> |
27 | | #include <editeng/editobj.hxx> |
28 | | |
29 | | #include <memory> |
30 | | |
31 | | class ScDocShell; |
32 | | class ScRangeName; |
33 | | class ScFormulaCell; |
34 | | |
35 | | class ScUndoCursorAttr: public ScSimpleUndo |
36 | | { |
37 | | public: |
38 | | ScUndoCursorAttr( ScDocShell& rNewDocShell, |
39 | | SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab, |
40 | | const ScPatternAttr* pOldPat, const ScPatternAttr* pNewPat, |
41 | | const ScPatternAttr* pApplyPat ); |
42 | | virtual ~ScUndoCursorAttr() override; |
43 | | |
44 | | virtual void Undo() override; |
45 | | virtual void Redo() override; |
46 | | virtual void Repeat(SfxRepeatTarget& rTarget) override; |
47 | | virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override; |
48 | | |
49 | | virtual OUString GetComment() const override; |
50 | | |
51 | | /** once the objects are passed to this class, their life-cycle is |
52 | | managed by this class; the calling function must pass new'ed |
53 | | objects to this method. */ |
54 | | void SetEditData( std::unique_ptr<EditTextObject> pOld, std::unique_ptr<EditTextObject> pNew ); |
55 | | |
56 | | private: |
57 | | SCCOL nCol; |
58 | | SCROW nRow; |
59 | | SCTAB nTab; |
60 | | const CellAttributeHolder aOldPattern; |
61 | | const CellAttributeHolder aNewPattern; |
62 | | const CellAttributeHolder aApplyPattern; |
63 | | std::unique_ptr<EditTextObject> pOldEditData; |
64 | | std::unique_ptr<EditTextObject> pNewEditData; |
65 | | |
66 | | void DoChange( const CellAttributeHolder& rWhichPattern, const std::unique_ptr<EditTextObject>& pEditData ) const; |
67 | | }; |
68 | | |
69 | | class ScUndoEnterData: public ScSimpleUndo |
70 | | { |
71 | | public: |
72 | | |
73 | | struct Value |
74 | | { |
75 | | SCTAB mnTab; |
76 | | bool mbHasFormat; |
77 | | sal_uInt32 mnFormat; |
78 | | ScCellValue maCell; |
79 | | |
80 | | Value(); |
81 | | }; |
82 | | |
83 | | typedef std::vector<Value> ValuesType; |
84 | | |
85 | | ScUndoEnterData( |
86 | | ScDocShell& rNewDocShell, const ScAddress& rPos, |
87 | | ValuesType& rOldValues, OUString aNewStr, std::unique_ptr<EditTextObject> pObj ); |
88 | | |
89 | | virtual void Undo() override; |
90 | | virtual void Redo() override; |
91 | | virtual void Repeat(SfxRepeatTarget& rTarget) override; |
92 | | virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override; |
93 | | |
94 | | virtual OUString GetComment() const override; |
95 | | |
96 | 0 | virtual std::optional<ScRange> getAffectedRange() const override { return ScRange(maPos); } |
97 | | |
98 | | private: |
99 | | ValuesType maOldValues; |
100 | | |
101 | | OUString maNewString; |
102 | | std::unique_ptr<EditTextObject> mpNewEditData; |
103 | | sal_uLong mnEndChangeAction; |
104 | | ScAddress maPos; |
105 | | |
106 | | void DoChange() const; |
107 | | void SetChangeTrack(); |
108 | | }; |
109 | | |
110 | | class ScUndoEnterValue: public ScSimpleUndo |
111 | | { |
112 | | public: |
113 | | ScUndoEnterValue( |
114 | | ScDocShell& rNewDocShell, const ScAddress& rNewPos, |
115 | | ScCellValue aUndoCell, double nVal ); |
116 | | |
117 | | virtual ~ScUndoEnterValue() override; |
118 | | |
119 | | virtual void Undo() override; |
120 | | virtual void Redo() override; |
121 | | virtual void Repeat(SfxRepeatTarget& rTarget) override; |
122 | | virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override; |
123 | | |
124 | | virtual OUString GetComment() const override; |
125 | | |
126 | 0 | virtual std::optional<ScRange> getAffectedRange() const override { return ScRange(aPos); } |
127 | | |
128 | | private: |
129 | | ScAddress aPos; |
130 | | ScCellValue maOldCell; |
131 | | double nValue; |
132 | | sal_uLong nEndChangeAction; |
133 | | |
134 | | void SetChangeTrack(); |
135 | | }; |
136 | | |
137 | | class ScUndoSetCell : public ScSimpleUndo |
138 | | { |
139 | | public: |
140 | | ScUndoSetCell( ScDocShell& rDocSh, const ScAddress& rPos, ScCellValue aOldVal, ScCellValue aNewVal ); |
141 | | |
142 | | virtual ~ScUndoSetCell() override; |
143 | | |
144 | | virtual void Undo() override; |
145 | | virtual void Redo() override; |
146 | | virtual void Repeat( SfxRepeatTarget& rTarget ) override; |
147 | | virtual bool CanRepeat( SfxRepeatTarget& rTarget ) const override; |
148 | | virtual OUString GetComment() const override; |
149 | | |
150 | 0 | virtual std::optional<ScRange> getAffectedRange() const override { return ScRange(maPos); } |
151 | | |
152 | | private: |
153 | | void SetChangeTrack(); |
154 | | void SetValue( const ScCellValue& rVal ); |
155 | | void MoveCursorToCell(); |
156 | | |
157 | | private: |
158 | | ScAddress maPos; |
159 | | ScCellValue maOldValue; |
160 | | ScCellValue maNewValue; |
161 | | sal_uLong mnEndChangeAction; |
162 | | }; |
163 | | |
164 | | class ScUndoPageBreak: public ScSimpleUndo |
165 | | { |
166 | | public: |
167 | | ScUndoPageBreak( ScDocShell& rNewDocShell, |
168 | | SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab, |
169 | | bool bNewColumn, bool bNewInsert ); |
170 | | virtual ~ScUndoPageBreak() override; |
171 | | |
172 | | virtual void Undo() override; |
173 | | virtual void Redo() override; |
174 | | virtual void Repeat(SfxRepeatTarget& rTarget) override; |
175 | | virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override; |
176 | | |
177 | | virtual OUString GetComment() const override; |
178 | | |
179 | | private: |
180 | | SCCOL nCol; |
181 | | SCROW nRow; |
182 | | SCTAB nTab; |
183 | | bool bColumn; // Column or row break |
184 | | bool bInsert; // Insert or Delete |
185 | | |
186 | | void DoChange( bool bInsert ) const; |
187 | | }; |
188 | | |
189 | | class ScUndoPrintZoom: public ScSimpleUndo |
190 | | { |
191 | | public: |
192 | | ScUndoPrintZoom( ScDocShell& rNewDocShell, SCTAB nT, |
193 | | sal_uInt16 nOS, sal_uInt16 nOP, sal_uInt16 nNS, sal_uInt16 nNP ); |
194 | | virtual ~ScUndoPrintZoom() override; |
195 | | |
196 | | virtual void Undo() override; |
197 | | virtual void Redo() override; |
198 | | virtual void Repeat(SfxRepeatTarget& rTarget) override; |
199 | | virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override; |
200 | | |
201 | | virtual OUString GetComment() const override; |
202 | | |
203 | | private: |
204 | | SCTAB nTab; |
205 | | sal_uInt16 nOldScale; |
206 | | sal_uInt16 nOldPages; |
207 | | sal_uInt16 nNewScale; |
208 | | sal_uInt16 nNewPages; |
209 | | |
210 | | void DoChange( bool bUndo ); |
211 | | }; |
212 | | |
213 | | class ScUndoThesaurus: public ScSimpleUndo |
214 | | { |
215 | | public: |
216 | | ScUndoThesaurus( ScDocShell& rNewDocShell, |
217 | | SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab, |
218 | | ScCellValue aOldText, ScCellValue aNewText ); |
219 | | virtual ~ScUndoThesaurus() override; |
220 | | |
221 | | virtual void Undo() override; |
222 | | virtual void Redo() override; |
223 | | virtual void Repeat(SfxRepeatTarget& rTarget) override; |
224 | | virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override; |
225 | | |
226 | | virtual OUString GetComment() const override; |
227 | | |
228 | | private: |
229 | | SCCOL nCol; |
230 | | SCROW nRow; |
231 | | SCTAB nTab; |
232 | | sal_uLong nEndChangeAction; |
233 | | |
234 | | ScCellValue maOldText; |
235 | | ScCellValue maNewText; |
236 | | |
237 | | void DoChange( bool bUndo, const ScCellValue& rText ); |
238 | | void SetChangeTrack( const ScCellValue& rOldCell ); |
239 | | }; |
240 | | |
241 | | /** Undo action for inserting, removing, and replacing a cell note. */ |
242 | | class ScUndoReplaceNote : public ScSimpleUndo |
243 | | { |
244 | | public: |
245 | | |
246 | | /** Constructs an undo action for inserting or removing a cell note. */ |
247 | | ScUndoReplaceNote( |
248 | | ScDocShell& rDocShell, |
249 | | const ScAddress& rPos, |
250 | | const ScNoteData& rNoteData, |
251 | | bool bInsert, |
252 | | std::unique_ptr<SdrUndoAction> pDrawUndo ); |
253 | | |
254 | | /** Constructs an undo action for replacing a cell note with another. */ |
255 | | ScUndoReplaceNote( |
256 | | ScDocShell& rDocShell, |
257 | | const ScAddress& rPos, |
258 | | ScNoteData aOldData, |
259 | | ScNoteData aNewData, |
260 | | std::unique_ptr<SdrUndoAction> pDrawUndo ); |
261 | | |
262 | | virtual ~ScUndoReplaceNote() override; |
263 | | |
264 | | virtual void Undo() override; |
265 | | virtual void Redo() override; |
266 | | virtual void Repeat( SfxRepeatTarget& rTarget ) override; |
267 | | virtual bool CanRepeat( SfxRepeatTarget& rTarget ) const override; |
268 | | |
269 | | virtual OUString GetComment() const override; |
270 | | |
271 | 0 | virtual std::optional<ScRange> getAffectedRange() const override { return ScRange(maPos); } |
272 | | |
273 | | private: |
274 | | void DoInsertNote( const ScNoteData& rNoteData ); |
275 | | void DoRemoveNote( const ScNoteData& rNoteData ); |
276 | | |
277 | | private: |
278 | | ScAddress maPos; |
279 | | ScNoteData maOldData; |
280 | | ScNoteData maNewData; |
281 | | std::unique_ptr<SdrUndoAction> mpDrawUndo; |
282 | | }; |
283 | | |
284 | | /** Undo action for showing or hiding a cell note caption. */ |
285 | | class ScUndoShowHideNote : public ScSimpleUndo |
286 | | { |
287 | | public: |
288 | | ScUndoShowHideNote( ScDocShell& rDocShell, const ScAddress& rPos, bool bShow ); |
289 | | virtual ~ScUndoShowHideNote() override; |
290 | | |
291 | | virtual void Undo() override; |
292 | | virtual void Redo() override; |
293 | | virtual void Repeat( SfxRepeatTarget& rTarget ) override; |
294 | | virtual bool CanRepeat( SfxRepeatTarget& rTarget ) const override; |
295 | | |
296 | | virtual OUString GetComment() const override; |
297 | | |
298 | 0 | virtual std::optional<ScRange> getAffectedRange() const override { return ScRange(maPos); } |
299 | | |
300 | | private: |
301 | | ScAddress maPos; |
302 | | bool mbShown; |
303 | | }; |
304 | | |
305 | | class ScUndoDetective: public ScSimpleUndo |
306 | | { |
307 | | public: |
308 | | ScUndoDetective( ScDocShell& rNewDocShell, |
309 | | std::unique_ptr<SdrUndoAction> pDraw, const ScDetOpData* pOperation, |
310 | | std::unique_ptr<ScDetOpList> pUndoList = nullptr ); |
311 | | virtual ~ScUndoDetective() override; |
312 | | |
313 | | virtual void Undo() override; |
314 | | virtual void Redo() override; |
315 | | virtual void Repeat(SfxRepeatTarget& rTarget) override; |
316 | | virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override; |
317 | | |
318 | | virtual OUString GetComment() const override; |
319 | | |
320 | | private: |
321 | | bool bIsDelete; |
322 | | std::unique_ptr<ScDetOpList> pOldList; |
323 | | sal_uInt16 nAction; |
324 | | ScAddress aPos; |
325 | | std::unique_ptr<SdrUndoAction> pDrawUndo; |
326 | | }; |
327 | | |
328 | | class ScUndoRangeNames: public ScSimpleUndo |
329 | | { |
330 | | public: |
331 | | //use nTab = -1 for global range names |
332 | | ScUndoRangeNames( ScDocShell& rNewDocShell, |
333 | | std::unique_ptr<ScRangeName> pOld, std::unique_ptr<ScRangeName> pNew , SCTAB nTab); |
334 | | virtual ~ScUndoRangeNames() override; |
335 | | |
336 | | virtual void Undo() override; |
337 | | virtual void Redo() override; |
338 | | virtual void Repeat(SfxRepeatTarget& rTarget) override; |
339 | | virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override; |
340 | | |
341 | | virtual OUString GetComment() const override; |
342 | | |
343 | | private: |
344 | | std::unique_ptr<ScRangeName> pOldRanges; |
345 | | std::unique_ptr<ScRangeName> pNewRanges; |
346 | | SCTAB mnTab; |
347 | | |
348 | | void DoChange( bool bUndo ); |
349 | | }; |
350 | | |
351 | | namespace sc { |
352 | | |
353 | | class UndoSetCells : public ScSimpleUndo |
354 | | { |
355 | | ScAddress maTopPos; |
356 | | CellValues maOldValues; |
357 | | CellValues maNewValues; |
358 | | |
359 | | void DoChange( const CellValues& rValues ); |
360 | | |
361 | | public: |
362 | | UndoSetCells( ScDocShell& rDocSh, const ScAddress& rTopPos ); |
363 | | virtual ~UndoSetCells() override; |
364 | | |
365 | | virtual void Undo() override; |
366 | | virtual void Redo() override; |
367 | | |
368 | | virtual bool CanRepeat( SfxRepeatTarget& ) const override; |
369 | | virtual OUString GetComment() const override; |
370 | | |
371 | 0 | CellValues& GetOldValues() { return maOldValues;} |
372 | | void SetNewValues( const std::vector<double>& rVals ); |
373 | | void SetNewValues( const std::vector<ScFormulaCell*>& rVals ); |
374 | | }; |
375 | | |
376 | | } // namespace sc |
377 | | |
378 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |