Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / inc / UndoTable.hxx
blob29850d2f07e205fe6d4162c27c9e85290a733f01
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_SW_SOURCE_CORE_INC_UNDOTABLE_HXX
21 #define INCLUDED_SW_SOURCE_CORE_INC_UNDOTABLE_HXX
23 #include <o3tl/deleter.hxx>
24 #include <tools/long.hxx>
25 #include <tools/solar.h>
26 #include <ndarr.hxx>
27 #include <undobj.hxx>
28 #include <set>
29 #include <itabenum.hxx>
30 #include <tblenum.hxx>
31 #include <memory>
32 #include <vector>
34 class SfxItemSet;
36 struct SwSaveRowSpan;
37 class SaveTable;
38 class SwDDEFieldType;
39 class SwUndoDelete;
40 class SwSelBoxes;
41 class SwTable;
42 class SwTableBox;
43 class SwStartNode;
44 class SwTableNode;
45 class SwTableAutoFormat;
46 class SwTableSortBoxes;
47 class SwContentNode;
48 class SwCursorShell;
50 namespace sw {
52 void NotifyTableCollapsedParagraph(const SwContentNode* pNode, SwCursorShell *const pShell);
56 /// Implements undo/redo for Table -> Insert Table.
57 class SwUndoInsTable final : public SwUndo
59 OUString m_sTableName;
60 SwInsertTableOptions m_aInsTableOptions;
61 std::unique_ptr<SwDDEFieldType> m_pDDEFieldType;
62 std::optional<std::vector<sal_uInt16>> m_oColumnWidth;
63 std::unique_ptr<SwRedlineData> m_pRedlineData;
64 std::unique_ptr<SwTableAutoFormat> m_pAutoFormat;
65 SwNodeOffset m_nStartNode;
66 sal_uInt16 m_nRows, m_nColumns;
67 sal_uInt16 const m_nAdjust;
69 public:
70 SwUndoInsTable( const SwPosition&, sal_uInt16 nCols, sal_uInt16 nRows,
71 sal_uInt16 eAdjust, const SwInsertTableOptions& rInsTableOpts,
72 const SwTableAutoFormat* pTAFormat, const std::vector<sal_uInt16> *pColArr,
73 const OUString & rName);
75 virtual ~SwUndoInsTable() override;
77 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
78 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
79 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
81 virtual SwRewriter GetRewriter() const override;
84 class SwUndoTextToTable final : public SwUndo, public SwUndRng
86 OUString m_sTableName;
87 SwInsertTableOptions m_aInsertTableOpts;
88 std::vector<SwNodeOffset> mvDelBoxes;
89 std::unique_ptr<SwTableAutoFormat> m_pAutoFormat;
90 SwHistory* m_pHistory;
91 sal_Unicode m_cSeparator;
92 sal_uInt16 m_nAdjust;
93 bool m_bSplitEnd : 1;
95 public:
96 SwUndoTextToTable( const SwPaM&, const SwInsertTableOptions&, sal_Unicode,
97 sal_uInt16,
98 const SwTableAutoFormat* pAFormat );
100 virtual ~SwUndoTextToTable() override;
102 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
103 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
104 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
106 SwHistory& GetHistory(); // will be created if necessary
107 void AddFillBox( const SwTableBox& rBox );
110 class SwUndoTableToText final : public SwUndo
112 OUString m_sTableName;
113 std::unique_ptr<SwDDEFieldType> m_pDDEFieldType;
114 std::unique_ptr<SaveTable> m_pTableSave;
115 SwTableToTextSaves m_vBoxSaves;
116 std::unique_ptr<SwHistory> m_pHistory;
117 SwNodeOffset m_nStartNode, m_nEndNode;
118 sal_Unicode m_cSeparator;
119 sal_uInt16 m_nHeadlineRepeat;
120 bool m_bCheckNumFormat : 1;
122 public:
123 SwUndoTableToText( const SwTable& rTable, sal_Unicode cCh );
125 virtual ~SwUndoTableToText() override;
127 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
128 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
129 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
131 void SetRange( const SwNodeRange& );
132 void AddBoxPos( SwDoc& rDoc, SwNodeOffset nNdIdx, SwNodeOffset nEndIdx,
133 sal_Int32 nContentIdx = SAL_MAX_INT32);
136 class SwUndoAttrTable final : public SwUndo
138 SwNodeOffset m_nStartNode;
139 std::unique_ptr<SaveTable> m_pSaveTable;
140 bool m_bClearTableCol : 1;
142 public:
143 SwUndoAttrTable( const SwTableNode& rTableNd, bool bClearTabCols = false );
145 virtual ~SwUndoAttrTable() override;
147 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
148 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
151 class SwUndoTableNumFormat;
153 class SwUndoTableAutoFormat final : public SwUndo
155 OUString m_TableStyleName;
156 SwNodeOffset m_nStartNode;
157 std::unique_ptr<SaveTable> m_pSaveTable;
158 std::vector< std::shared_ptr<SwUndoTableNumFormat> > m_Undos;
159 bool m_bSaveContentAttr;
160 sal_uInt16 m_nRepeatHeading;
162 void UndoRedo(bool const bUndo, ::sw::UndoRedoContext & rContext);
164 public:
165 SwUndoTableAutoFormat( const SwTableNode& rTableNd, const SwTableAutoFormat& );
167 virtual ~SwUndoTableAutoFormat() override;
169 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
170 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
172 void SaveBoxContent( const SwTableBox& rBox );
175 using SwUndoSaveSections = std::vector<std::unique_ptr<SwUndoSaveSection, o3tl::default_delete<SwUndoSaveSection>>>;
177 class SwUndoTableNdsChg final : public SwUndo
179 std::unique_ptr<SaveTable> m_pSaveTable;
180 std::set<SwNodeOffset> m_Boxes;
181 struct BoxMove
183 SwNodeOffset index; ///< Index of this box.
184 bool hasMoved; ///< Has this box been moved already.
185 BoxMove(SwNodeOffset idx, bool moved=false) : index(idx), hasMoved(moved) {};
186 bool operator<(const BoxMove& other) const { return index < other.index; };
188 std::optional< std::set<BoxMove> > m_xNewSttNds;
189 std::unique_ptr<SwUndoSaveSections> m_pDelSects;
190 tools::Long m_nMin, m_nMax; // for redo of delete column
191 SwNodeOffset m_nSttNode;
192 sal_uInt16 m_nCount;
193 bool m_bFlag;
194 bool m_bSameHeight; // only used for SplitRow
196 SwUndoTableNdsChg(SwUndoTableNdsChg const&) = delete;
197 SwUndoTableNdsChg& operator=(SwUndoTableNdsChg const&) = delete;
199 public:
200 SwUndoTableNdsChg( SwUndoId UndoId,
201 const SwSelBoxes& rBoxes,
202 const SwTableNode& rTableNd,
203 tools::Long nMn, tools::Long nMx,
204 sal_uInt16 nCnt, bool bFlg, bool bSameHeight );
206 virtual ~SwUndoTableNdsChg() override;
208 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
209 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
211 void SaveNewBoxes( const SwTableNode& rTableNd, const SwTableSortBoxes& rOld );
212 void SaveNewBoxes( const SwTableNode& rTableNd, const SwTableSortBoxes& rOld,
213 const SwSelBoxes& rBoxes, const std::vector<SwNodeOffset> &rNodeCnts );
214 void SaveSection( SwStartNode* pSttNd );
215 void ReNewBoxes( const SwSelBoxes& rBoxes );
219 class SwUndoMove;
221 class SwUndoTableMerge final : public SwUndo, private SwUndRng
223 SwNodeOffset m_nTableNode;
224 std::unique_ptr<SaveTable> m_pSaveTable;
225 std::set<SwNodeOffset> m_Boxes;
226 std::vector<SwNodeOffset> m_aNewStartNodes;
227 std::vector<std::unique_ptr<SwUndoMove>> m_vMoves;
228 std::unique_ptr<SwHistory> m_pHistory;
230 public:
231 SwUndoTableMerge( const SwPaM& rTableSel );
233 virtual ~SwUndoTableMerge() override;
235 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
236 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
238 void MoveBoxContent( SwDoc& rDoc, SwNodeRange& rRg, SwNode& rPos );
240 void SetSelBoxes( const SwSelBoxes& rBoxes );
242 void AddNewBox( SwNodeOffset nSttNdIdx )
243 { m_aNewStartNodes.push_back( nSttNdIdx ); }
245 void SaveCollection( const SwTableBox& rBox );
248 class SwUndoTableNumFormat final : public SwUndo
250 std::unique_ptr<SfxItemSet> m_pBoxSet;
251 std::unique_ptr<SwHistory> m_pHistory;
252 OUString m_aStr, m_aNewFormula;
254 sal_uLong m_nFormatIdx, m_nNewFormatIdx;
255 double m_fNum, m_fNewNum;
256 SwNodeOffset m_nNode;
257 SwNodeOffset m_nNodePos;
259 bool m_bNewFormat : 1;
260 bool m_bNewFormula : 1;
261 bool m_bNewValue : 1;
263 public:
264 SwUndoTableNumFormat( const SwTableBox& rBox, const SfxItemSet* pNewSet = nullptr );
266 virtual ~SwUndoTableNumFormat() override;
268 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
269 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
271 void SetNumFormat( sal_uLong nNewNumFormatIdx, const double& rNewNumber )
272 { m_nFormatIdx = nNewNumFormatIdx; m_fNum = rNewNumber; }
273 void SetBox( const SwTableBox& rBox );
276 struct UndoTableCpyTable_Entry;
278 class SwUndoTableCpyTable final : public SwUndo
280 std::vector<std::unique_ptr<UndoTableCpyTable_Entry>> m_vArr;
281 std::unique_ptr<SwUndoTableNdsChg> m_pInsRowUndo;
283 //b6341295: When redlining is active, PrepareRedline has to create the
284 //redlining attributes for the new and the old table cell content
285 static std::unique_ptr<SwUndo> PrepareRedline( SwDoc* pDoc, const SwTableBox& rBox,
286 SwPosition& rPos, bool& rJoin, bool bRedo );
288 public:
289 SwUndoTableCpyTable(const SwDoc& rDoc);
291 virtual ~SwUndoTableCpyTable() override;
293 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
294 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
296 void AddBoxBefore( const SwTableBox& rBox, bool bDelContent );
297 void AddBoxAfter( const SwTableBox& rBox, const SwNodeIndex& rIdx,
298 bool bDelContent );
300 bool IsEmpty() const;
301 bool InsertRow( SwTable& rTable, const SwSelBoxes& rBoxes, sal_uInt16 nCnt );
302 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
305 class SwUndoCpyTable final : public SwUndo
307 std::unique_ptr<SwUndoDelete> m_pDelete;
308 SwNodeOffset m_nTableNode;
310 public:
311 SwUndoCpyTable(const SwDoc& rDoc);
313 virtual ~SwUndoCpyTable() override;
315 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
316 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
318 void SetTableSttIdx( SwNodeOffset nIdx ) { m_nTableNode = nIdx; }
321 class SwUndoSplitTable final : public SwUndo
323 SwNodeOffset m_nTableNode, m_nOffset;
324 std::unique_ptr<SwSaveRowSpan> mpSaveRowSpan; // stores row span values at the splitting row
325 std::unique_ptr<SaveTable> m_pSavedTable;
326 std::unique_ptr<SwHistory> m_pHistory;
327 SplitTable_HeadlineOption const m_nMode;
328 sal_uInt16 m_nFormulaEnd;
329 bool m_bCalcNewSize;
331 public:
332 SwUndoSplitTable( const SwTableNode& rTableNd, std::unique_ptr<SwSaveRowSpan> pRowSp,
333 SplitTable_HeadlineOption nMode, bool bCalcNewSize );
335 virtual ~SwUndoSplitTable() override;
337 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
338 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
339 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
341 void SetTableNodeOffset( SwNodeOffset nIdx ) { m_nOffset = nIdx - m_nTableNode; }
342 SwHistory* GetHistory() { return m_pHistory.get(); }
343 void SaveFormula( SwHistory& rHistory );
346 class SwUndoMergeTable final : public SwUndo
348 OUString m_aName;
349 SwNodeOffset m_nTableNode;
350 std::unique_ptr<SaveTable> m_pSaveTable, m_pSaveHdl;
351 std::unique_ptr<SwHistory> m_pHistory;
352 bool m_bWithPrev;
354 public:
355 SwUndoMergeTable( const SwTableNode& rTableNd, const SwTableNode& rDelTableNd,
356 bool bWithPrev );
358 virtual ~SwUndoMergeTable() override;
360 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
361 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
362 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
364 void SaveFormula( SwHistory& rHistory );
367 class SwUndoTableHeadline final : public SwUndo
369 SwNodeOffset m_nTableNode;
370 sal_uInt16 m_nOldHeadline;
371 sal_uInt16 m_nNewHeadline;
373 public:
374 SwUndoTableHeadline( const SwTable&, sal_uInt16 nOldHdl, sal_uInt16 nNewHdl );
376 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
377 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
378 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
381 void InsertSort( std::vector<sal_uInt16>& rArr, sal_uInt16 nIdx );
383 class SwUndoTableStyleMake final : public SwUndo
385 OUString m_sName;
386 std::unique_ptr<SwTableAutoFormat> m_pAutoFormat;
387 public:
388 SwUndoTableStyleMake(OUString aName, const SwDoc& rDoc);
390 virtual ~SwUndoTableStyleMake() override;
392 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
393 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
395 virtual SwRewriter GetRewriter() const override;
398 class SwUndoTableStyleDelete final : public SwUndo
400 std::unique_ptr<SwTableAutoFormat> m_pAutoFormat;
401 std::vector<SwTable*> m_rAffectedTables;
402 public:
403 SwUndoTableStyleDelete(std::unique_ptr<SwTableAutoFormat> pAutoFormat, std::vector<SwTable*>&& rAffectedTables, const SwDoc& rDoc);
405 virtual ~SwUndoTableStyleDelete() override;
407 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
408 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
410 virtual SwRewriter GetRewriter() const override;
413 class SwUndoTableStyleUpdate final : public SwUndo
415 std::unique_ptr<SwTableAutoFormat> m_pOldFormat, m_pNewFormat;
416 public:
417 SwUndoTableStyleUpdate(const SwTableAutoFormat& rNewFormat, const SwTableAutoFormat& rOldFormat, const SwDoc& rDoc);
419 virtual ~SwUndoTableStyleUpdate() override;
421 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
422 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
424 virtual SwRewriter GetRewriter() const override;
427 #endif // INCLUDED_SW_SOURCE_CORE_INC_UNDOTABLE_HXX
429 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */