tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / inc / undocell.hxx
blob1bceeb3af5fba6b74fe45b54423af85b6e21c9d9
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 #pragma once
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>
29 #include <memory>
31 class ScDocShell;
32 class ScPatternAttr;
33 class ScRangeName;
34 class ScFormulaCell;
36 class ScUndoCursorAttr: public ScSimpleUndo
38 public:
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 );
57 private:
58 SCCOL nCol;
59 SCROW nRow;
60 SCTAB nTab;
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
72 public:
74 struct Value
76 SCTAB mnTab;
77 bool mbHasFormat;
78 sal_uInt32 mnFormat;
79 ScCellValue maCell;
81 Value();
84 typedef std::vector<Value> ValuesType;
86 ScUndoEnterData(
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); }
99 private:
100 ValuesType maOldValues;
102 OUString maNewString;
103 std::unique_ptr<EditTextObject> mpNewEditData;
104 sal_uLong mnEndChangeAction;
105 ScAddress maPos;
107 void DoChange() const;
108 void SetChangeTrack();
111 class ScUndoEnterValue: public ScSimpleUndo
113 public:
114 ScUndoEnterValue(
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); }
129 private:
130 ScAddress aPos;
131 ScCellValue maOldCell;
132 double nValue;
133 sal_uLong nEndChangeAction;
135 void SetChangeTrack();
138 class ScUndoSetCell : public ScSimpleUndo
140 public:
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); }
153 private:
154 void SetChangeTrack();
155 void SetValue( const ScCellValue& rVal );
156 void MoveCursorToCell();
158 private:
159 ScAddress maPos;
160 ScCellValue maOldValue;
161 ScCellValue maNewValue;
162 sal_uLong mnEndChangeAction;
165 class ScUndoPageBreak: public ScSimpleUndo
167 public:
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;
180 private:
181 SCCOL nCol;
182 SCROW nRow;
183 SCTAB nTab;
184 bool bColumn; // Column or row break
185 bool bInsert; // Insert or Delete
187 void DoChange( bool bInsert ) const;
190 class ScUndoPrintZoom: public ScSimpleUndo
192 public:
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;
204 private:
205 SCTAB nTab;
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
216 public:
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;
229 private:
230 SCCOL nCol;
231 SCROW nRow;
232 SCTAB nTab;
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
245 public:
247 /** Constructs an undo action for inserting or removing a cell note. */
248 ScUndoReplaceNote(
249 ScDocShell& rDocShell,
250 const ScAddress& rPos,
251 const ScNoteData& rNoteData,
252 bool bInsert,
253 std::unique_ptr<SdrUndoAction> pDrawUndo );
255 /** Constructs an undo action for replacing a cell note with another. */
256 ScUndoReplaceNote(
257 ScDocShell& rDocShell,
258 const ScAddress& rPos,
259 ScNoteData aOldData,
260 ScNoteData aNewData,
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); }
274 private:
275 void DoInsertNote( const ScNoteData& rNoteData );
276 void DoRemoveNote( const ScNoteData& rNoteData );
278 private:
279 ScAddress maPos;
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
288 public:
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); }
301 private:
302 ScAddress maPos;
303 bool mbShown;
306 class ScUndoDetective: public ScSimpleUndo
308 public:
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;
321 private:
322 bool bIsDelete;
323 std::unique_ptr<ScDetOpList> pOldList;
324 sal_uInt16 nAction;
325 ScAddress aPos;
326 std::unique_ptr<SdrUndoAction> pDrawUndo;
329 class ScUndoRangeNames: public ScSimpleUndo
331 public:
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;
344 private:
345 std::unique_ptr<ScRangeName> pOldRanges;
346 std::unique_ptr<ScRangeName> pNewRanges;
347 SCTAB mnTab;
349 void DoChange( bool bUndo );
352 namespace sc {
354 class UndoSetCells : public ScSimpleUndo
356 ScAddress maTopPos;
357 CellValues maOldValues;
358 CellValues maNewValues;
360 void DoChange( const CellValues& rValues );
362 public:
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 );
377 } // namespace sc
379 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */