Add a comment to clarify what kind of inputs the class handles
[LibreOffice.git] / sw / source / core / inc / UndoTable.hxx
blob40d4d0547b6a4fdddc0430c979735b015bb5cdc5
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 <o3tl/deleter.hxx>
23 #include <tools/long.hxx>
24 #include <tools/solar.h>
25 #include <ndarr.hxx>
26 #include <undobj.hxx>
27 #include <set>
28 #include <itabenum.hxx>
29 #include <tblenum.hxx>
30 #include <memory>
31 #include <vector>
33 class SfxItemSet;
35 struct SwSaveRowSpan;
36 class SaveTable;
37 class SwDDEFieldType;
38 class SwUndoDelete;
39 class SwSelBoxes;
40 class SwTable;
41 class SwTableBox;
42 class SwStartNode;
43 class SwTableNode;
44 class SwTableAutoFormat;
45 class SwTableSortBoxes;
46 class SwContentNode;
47 class SwCursorShell;
49 namespace sw {
51 void NotifyTableCollapsedParagraph(const SwContentNode* pNode, SwCursorShell *const pShell);
55 /// Implements undo/redo for Table -> Insert Table.
56 class SwUndoInsTable final : public SwUndo
58 OUString m_sTableName;
59 SwInsertTableOptions m_aInsTableOptions;
60 std::unique_ptr<SwDDEFieldType> m_pDDEFieldType;
61 std::optional<std::vector<sal_uInt16>> m_oColumnWidth;
62 std::unique_ptr<SwRedlineData> m_pRedlineData;
63 std::unique_ptr<SwTableAutoFormat> m_pAutoFormat;
64 SwNodeOffset m_nStartNode;
65 sal_uInt16 m_nRows, m_nColumns;
66 sal_uInt16 const m_nAdjust;
68 public:
69 SwUndoInsTable( const SwPosition&, sal_uInt16 nCols, sal_uInt16 nRows,
70 sal_uInt16 eAdjust, const SwInsertTableOptions& rInsTableOpts,
71 const SwTableAutoFormat* pTAFormat, const std::vector<sal_uInt16> *pColArr,
72 const OUString & rName);
74 virtual ~SwUndoInsTable() override;
76 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
77 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
78 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
80 virtual SwRewriter GetRewriter() const override;
83 class SwUndoTextToTable final : public SwUndo, public SwUndRng
85 OUString m_sTableName;
86 SwInsertTableOptions m_aInsertTableOpts;
87 std::vector<SwNodeOffset> mvDelBoxes;
88 std::unique_ptr<SwTableAutoFormat> m_pAutoFormat;
89 SwHistory* m_pHistory;
90 sal_Unicode m_cSeparator;
91 sal_uInt16 m_nAdjust;
92 bool m_bSplitEnd : 1;
94 public:
95 SwUndoTextToTable( const SwPaM&, const SwInsertTableOptions&, sal_Unicode,
96 sal_uInt16,
97 const SwTableAutoFormat* pAFormat );
99 virtual ~SwUndoTextToTable() override;
101 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
102 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
103 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
105 SwHistory& GetHistory(); // will be created if necessary
106 void AddFillBox( const SwTableBox& rBox );
109 class SwUndoTableToText final : public SwUndo
111 OUString m_sTableName;
112 std::unique_ptr<SwDDEFieldType> m_pDDEFieldType;
113 std::unique_ptr<SaveTable> m_pTableSave;
114 SwTableToTextSaves m_vBoxSaves;
115 std::unique_ptr<SwHistory> m_pHistory;
116 SwNodeOffset m_nStartNode, m_nEndNode;
117 sal_Unicode m_cSeparator;
118 sal_uInt16 m_nHeadlineRepeat;
119 bool m_bCheckNumFormat : 1;
121 public:
122 SwUndoTableToText( const SwTable& rTable, sal_Unicode cCh );
124 virtual ~SwUndoTableToText() override;
126 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
127 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
128 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
130 void SetRange( const SwNodeRange& );
131 void AddBoxPos( SwDoc& rDoc, SwNodeOffset nNdIdx, SwNodeOffset nEndIdx,
132 sal_Int32 nContentIdx = SAL_MAX_INT32);
135 class SwUndoAttrTable final : public SwUndo
137 SwNodeOffset m_nStartNode;
138 std::unique_ptr<SaveTable> m_pSaveTable;
139 bool m_bClearTableCol : 1;
141 public:
142 SwUndoAttrTable( const SwTableNode& rTableNd, bool bClearTabCols = false );
144 virtual ~SwUndoAttrTable() override;
146 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
147 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
150 class SwUndoTableNumFormat;
152 class SwUndoTableAutoFormat final : public SwUndo
154 OUString m_TableStyleName;
155 SwNodeOffset m_nStartNode;
156 std::unique_ptr<SaveTable> m_pSaveTable;
157 std::vector< std::shared_ptr<SwUndoTableNumFormat> > m_Undos;
158 bool m_bSaveContentAttr;
159 sal_uInt16 m_nRepeatHeading;
161 void UndoRedo(bool const bUndo, ::sw::UndoRedoContext & rContext);
163 public:
164 SwUndoTableAutoFormat( const SwTableNode& rTableNd, const SwTableAutoFormat& );
166 virtual ~SwUndoTableAutoFormat() override;
168 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
169 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
171 void SaveBoxContent( const SwTableBox& rBox );
174 using SwUndoSaveSections = std::vector<std::unique_ptr<SwUndoSaveSection, o3tl::default_delete<SwUndoSaveSection>>>;
176 class SwUndoTableNdsChg final : public SwUndo
178 std::unique_ptr<SaveTable> m_pSaveTable;
179 std::set<SwNodeOffset> m_Boxes;
180 struct BoxMove
182 SwNodeOffset index; ///< Index of this box.
183 bool hasMoved; ///< Has this box been moved already.
184 BoxMove(SwNodeOffset idx, bool moved=false) : index(idx), hasMoved(moved) {};
185 bool operator<(const BoxMove& other) const { return index < other.index; };
187 std::optional< std::set<BoxMove> > m_xNewSttNds;
188 std::unique_ptr<SwUndoSaveSections> m_pDelSects;
189 tools::Long m_nMin, m_nMax; // for redo of delete column
190 SwNodeOffset m_nSttNode;
191 sal_uInt16 m_nCount;
192 bool m_bFlag;
193 bool m_bSameHeight; // only used for SplitRow
195 SwUndoTableNdsChg(SwUndoTableNdsChg const&) = delete;
196 SwUndoTableNdsChg& operator=(SwUndoTableNdsChg const&) = delete;
198 public:
199 SwUndoTableNdsChg( SwUndoId UndoId,
200 const SwSelBoxes& rBoxes,
201 const SwTableNode& rTableNd,
202 tools::Long nMn, tools::Long nMx,
203 sal_uInt16 nCnt, bool bFlg, bool bSameHeight );
205 virtual ~SwUndoTableNdsChg() override;
207 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
208 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
210 void SaveNewBoxes( const SwTableNode& rTableNd, const SwTableSortBoxes& rOld );
211 void SaveNewBoxes( const SwTableNode& rTableNd, const SwTableSortBoxes& rOld,
212 const SwSelBoxes& rBoxes, const std::vector<SwNodeOffset> &rNodeCnts );
213 void SaveSection( SwStartNode* pSttNd );
214 void ReNewBoxes( const SwSelBoxes& rBoxes );
218 class SwUndoMove;
220 class SwUndoTableMerge final : public SwUndo, private SwUndRng
222 SwNodeOffset m_nTableNode;
223 std::unique_ptr<SaveTable> m_pSaveTable;
224 std::set<SwNodeOffset> m_Boxes;
225 std::vector<SwNodeOffset> m_aNewStartNodes;
226 std::vector<std::unique_ptr<SwUndoMove>> m_vMoves;
227 std::unique_ptr<SwHistory> m_pHistory;
229 public:
230 SwUndoTableMerge( const SwPaM& rTableSel );
232 virtual ~SwUndoTableMerge() override;
234 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
235 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
237 void MoveBoxContent( SwDoc& rDoc, SwNodeRange& rRg, SwNode& rPos );
239 void SetSelBoxes( const SwSelBoxes& rBoxes );
241 void AddNewBox( SwNodeOffset nSttNdIdx )
242 { m_aNewStartNodes.push_back( nSttNdIdx ); }
244 void SaveCollection( const SwTableBox& rBox );
247 class SwUndoTableNumFormat final : public SwUndo
249 std::unique_ptr<SfxItemSet> m_pBoxSet;
250 std::unique_ptr<SwHistory> m_pHistory;
251 OUString m_aStr, m_aNewFormula;
253 sal_uLong m_nFormatIdx, m_nNewFormatIdx;
254 double m_fNum, m_fNewNum;
255 SwNodeOffset m_nNode;
256 SwNodeOffset m_nNodePos;
258 bool m_bNewFormat : 1;
259 bool m_bNewFormula : 1;
260 bool m_bNewValue : 1;
262 public:
263 SwUndoTableNumFormat( const SwTableBox& rBox, const SfxItemSet* pNewSet = nullptr );
265 virtual ~SwUndoTableNumFormat() override;
267 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
268 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
270 void SetNumFormat( sal_uLong nNewNumFormatIdx, const double& rNewNumber )
271 { m_nFormatIdx = nNewNumFormatIdx; m_fNum = rNewNumber; }
272 void SetBox( const SwTableBox& rBox );
275 struct UndoTableCpyTable_Entry;
277 class SwUndoTableCpyTable final : public SwUndo
279 std::vector<std::unique_ptr<UndoTableCpyTable_Entry>> m_vArr;
280 std::unique_ptr<SwUndoTableNdsChg> m_pInsRowUndo;
282 //b6341295: When redlining is active, PrepareRedline has to create the
283 //redlining attributes for the new and the old table cell content
284 static std::unique_ptr<SwUndo> PrepareRedline( SwDoc* pDoc, const SwTableBox& rBox,
285 SwPosition& rPos, bool& rJoin, bool bRedo );
287 public:
288 SwUndoTableCpyTable(const SwDoc& rDoc);
290 virtual ~SwUndoTableCpyTable() override;
292 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
293 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
295 void AddBoxBefore( const SwTableBox& rBox, bool bDelContent );
296 void AddBoxAfter( const SwTableBox& rBox, const SwNodeIndex& rIdx,
297 bool bDelContent );
299 bool IsEmpty() const;
300 bool InsertRow( SwTable& rTable, const SwSelBoxes& rBoxes, sal_uInt16 nCnt );
301 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
304 class SwUndoCpyTable final : public SwUndo
306 std::unique_ptr<SwUndoDelete> m_pDelete;
307 SwNodeOffset m_nTableNode;
309 public:
310 SwUndoCpyTable(const SwDoc& rDoc);
312 virtual ~SwUndoCpyTable() override;
314 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
315 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
317 void SetTableSttIdx( SwNodeOffset nIdx ) { m_nTableNode = nIdx; }
320 class SwUndoSplitTable final : public SwUndo
322 SwNodeOffset m_nTableNode, m_nOffset;
323 std::unique_ptr<SwSaveRowSpan> mpSaveRowSpan; // stores row span values at the splitting row
324 std::unique_ptr<SaveTable> m_pSavedTable;
325 std::unique_ptr<SwHistory> m_pHistory;
326 SplitTable_HeadlineOption const m_nMode;
327 sal_uInt16 m_nFormulaEnd;
328 bool m_bCalcNewSize;
330 public:
331 SwUndoSplitTable( const SwTableNode& rTableNd, std::unique_ptr<SwSaveRowSpan> pRowSp,
332 SplitTable_HeadlineOption nMode, bool bCalcNewSize );
334 virtual ~SwUndoSplitTable() override;
336 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
337 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
338 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
340 void SetTableNodeOffset( SwNodeOffset nIdx ) { m_nOffset = nIdx - m_nTableNode; }
341 SwHistory* GetHistory() { return m_pHistory.get(); }
342 void SaveFormula( SwHistory& rHistory );
345 class SwUndoMergeTable final : public SwUndo
347 OUString m_aName;
348 SwNodeOffset m_nTableNode;
349 std::unique_ptr<SaveTable> m_pSaveTable, m_pSaveHdl;
350 std::unique_ptr<SwHistory> m_pHistory;
351 bool m_bWithPrev;
353 public:
354 SwUndoMergeTable( const SwTableNode& rTableNd, const SwTableNode& rDelTableNd,
355 bool bWithPrev );
357 virtual ~SwUndoMergeTable() override;
359 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
360 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
361 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
363 void SaveFormula( SwHistory& rHistory );
366 class SwUndoTableHeadline final : public SwUndo
368 SwNodeOffset m_nTableNode;
369 sal_uInt16 m_nOldHeadline;
370 sal_uInt16 m_nNewHeadline;
372 public:
373 SwUndoTableHeadline( const SwTable&, sal_uInt16 nOldHdl, sal_uInt16 nNewHdl );
375 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
376 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
377 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
380 void InsertSort( std::vector<sal_uInt16>& rArr, sal_uInt16 nIdx );
382 class SwUndoTableStyleMake final : public SwUndo
384 OUString m_sName;
385 std::unique_ptr<SwTableAutoFormat> m_pAutoFormat;
386 public:
387 SwUndoTableStyleMake(OUString aName, const SwDoc& rDoc);
389 virtual ~SwUndoTableStyleMake() override;
391 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
392 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
394 virtual SwRewriter GetRewriter() const override;
397 class SwUndoTableStyleDelete final : public SwUndo
399 std::unique_ptr<SwTableAutoFormat> m_pAutoFormat;
400 std::vector<SwTable*> m_rAffectedTables;
401 public:
402 SwUndoTableStyleDelete(std::unique_ptr<SwTableAutoFormat> pAutoFormat, std::vector<SwTable*>&& rAffectedTables, const SwDoc& rDoc);
404 virtual ~SwUndoTableStyleDelete() override;
406 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
407 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
409 virtual SwRewriter GetRewriter() const override;
412 class SwUndoTableStyleUpdate final : public SwUndo
414 std::unique_ptr<SwTableAutoFormat> m_pOldFormat, m_pNewFormat;
415 public:
416 SwUndoTableStyleUpdate(const SwTableAutoFormat& rNewFormat, const SwTableAutoFormat& rOldFormat, const SwDoc& rDoc);
418 virtual ~SwUndoTableStyleUpdate() override;
420 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
421 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
423 virtual SwRewriter GetRewriter() const override;
426 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */