1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
28 #include <itabenum.hxx>
29 #include <tblenum.hxx>
44 class SwTableAutoFormat
;
45 class SwTableSortBoxes
;
47 class SwUndoInsTable
: public SwUndo
49 OUString m_sTableName
;
50 SwInsertTableOptions m_aInsTableOptions
;
51 std::unique_ptr
<SwDDEFieldType
> m_pDDEFieldType
;
52 std::unique_ptr
<std::vector
<sal_uInt16
>> m_pColumnWidth
;
53 std::unique_ptr
<SwRedlineData
> m_pRedlineData
;
54 std::unique_ptr
<SwTableAutoFormat
> m_pAutoFormat
;
55 sal_uLong m_nStartNode
;
56 sal_uInt16 m_nRows
, m_nColumns
;
57 sal_uInt16
const m_nAdjust
;
60 SwUndoInsTable( const SwPosition
&, sal_uInt16 nCols
, sal_uInt16 nRows
,
61 sal_uInt16 eAdjust
, const SwInsertTableOptions
& rInsTableOpts
,
62 const SwTableAutoFormat
* pTAFormat
, const std::vector
<sal_uInt16
> *pColArr
,
63 const OUString
& rName
);
65 virtual ~SwUndoInsTable() override
;
67 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
68 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
69 virtual void RepeatImpl( ::sw::RepeatContext
& ) override
;
71 virtual SwRewriter
GetRewriter() const override
;
74 class SwUndoTextToTable
: public SwUndo
, public SwUndRng
76 OUString m_sTableName
;
77 SwInsertTableOptions m_aInsertTableOpts
;
78 std::vector
<sal_uLong
> mvDelBoxes
;
79 std::unique_ptr
<SwTableAutoFormat
> m_pAutoFormat
;
80 SwHistory
* m_pHistory
;
81 sal_Unicode m_cSeparator
;
86 SwUndoTextToTable( const SwPaM
&, const SwInsertTableOptions
&, sal_Unicode
,
88 const SwTableAutoFormat
* pAFormat
);
90 virtual ~SwUndoTextToTable() override
;
92 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
93 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
94 virtual void RepeatImpl( ::sw::RepeatContext
& ) override
;
96 SwHistory
& GetHistory(); // will be created if necessary
97 void AddFillBox( const SwTableBox
& rBox
);
100 class SwUndoTableToText
: public SwUndo
102 OUString m_sTableName
;
103 std::unique_ptr
<SwDDEFieldType
> m_pDDEFieldType
;
104 std::unique_ptr
<SaveTable
> m_pTableSave
;
105 SwTableToTextSaves m_vBoxSaves
;
106 std::unique_ptr
<SwHistory
> m_pHistory
;
107 sal_uLong m_nStartNode
, m_nEndNode
;
108 sal_Unicode m_cSeparator
;
109 sal_uInt16 m_nHeadlineRepeat
;
110 bool m_bCheckNumFormat
: 1;
113 SwUndoTableToText( const SwTable
& rTable
, sal_Unicode cCh
);
115 virtual ~SwUndoTableToText() override
;
117 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
118 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
119 virtual void RepeatImpl( ::sw::RepeatContext
& ) override
;
121 void SetRange( const SwNodeRange
& );
122 void AddBoxPos( SwDoc
& rDoc
, sal_uLong nNdIdx
, sal_uLong nEndIdx
,
123 sal_Int32 nContentIdx
= SAL_MAX_INT32
);
126 class SwUndoAttrTable
: public SwUndo
128 sal_uLong m_nStartNode
;
129 std::unique_ptr
<SaveTable
> m_pSaveTable
;
130 bool m_bClearTableCol
: 1;
133 SwUndoAttrTable( const SwTableNode
& rTableNd
, bool bClearTabCols
= false );
135 virtual ~SwUndoAttrTable() override
;
137 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
138 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
141 class SwUndoTableNumFormat
;
143 class SwUndoTableAutoFormat
: public SwUndo
145 OUString m_TableStyleName
;
146 sal_uLong m_nStartNode
;
147 std::unique_ptr
<SaveTable
> m_pSaveTable
;
148 std::vector
< std::shared_ptr
<SwUndoTableNumFormat
> > m_Undos
;
149 bool m_bSaveContentAttr
;
150 sal_uInt16 m_nRepeatHeading
;
152 void UndoRedo(bool const bUndo
, ::sw::UndoRedoContext
& rContext
);
155 SwUndoTableAutoFormat( const SwTableNode
& rTableNd
, const SwTableAutoFormat
& );
157 virtual ~SwUndoTableAutoFormat() override
;
159 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
160 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
162 void SaveBoxContent( const SwTableBox
& rBox
);
165 using SwUndoSaveSections
= std::vector
<std::unique_ptr
<SwUndoSaveSection
, o3tl::default_delete
<SwUndoSaveSection
>>>;
167 class SwUndoTableNdsChg
: public SwUndo
169 std::unique_ptr
<SaveTable
> m_pSaveTable
;
170 std::set
<sal_uLong
> m_Boxes
;
173 sal_uLong index
; ///< Index of this box.
174 bool hasMoved
; ///< Has this box been moved already.
175 BoxMove(sal_uLong idx
, bool moved
=false) : index(idx
), hasMoved(moved
) {};
176 bool operator<(const BoxMove
& other
) const { return index
< other
.index
; };
178 std::unique_ptr
< std::set
<BoxMove
> > m_pNewSttNds
;
179 std::unique_ptr
<SwUndoSaveSections
> m_pDelSects
;
180 tools::Long m_nMin
, m_nMax
; // for redo of delete column
181 sal_uLong m_nSttNode
;
184 bool m_bSameHeight
; // only used for SplitRow
186 SwUndoTableNdsChg(SwUndoTableNdsChg
const&) = delete;
187 SwUndoTableNdsChg
& operator=(SwUndoTableNdsChg
const&) = delete;
190 SwUndoTableNdsChg( SwUndoId UndoId
,
191 const SwSelBoxes
& rBoxes
,
192 const SwTableNode
& rTableNd
,
193 tools::Long nMn
, tools::Long nMx
,
194 sal_uInt16 nCnt
, bool bFlg
, bool bSameHeight
);
196 virtual ~SwUndoTableNdsChg() override
;
198 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
199 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
201 void SaveNewBoxes( const SwTableNode
& rTableNd
, const SwTableSortBoxes
& rOld
);
202 void SaveNewBoxes( const SwTableNode
& rTableNd
, const SwTableSortBoxes
& rOld
,
203 const SwSelBoxes
& rBoxes
, const std::vector
<sal_uLong
> &rNodeCnts
);
204 void SaveSection( SwStartNode
* pSttNd
);
205 void ReNewBoxes( const SwSelBoxes
& rBoxes
);
211 class SwUndoTableMerge
: public SwUndo
, private SwUndRng
213 sal_uLong m_nTableNode
;
214 std::unique_ptr
<SaveTable
> m_pSaveTable
;
215 std::set
<sal_uLong
> m_Boxes
;
216 std::vector
<sal_uLong
> m_aNewStartNodes
;
217 std::vector
<std::unique_ptr
<SwUndoMove
>> m_vMoves
;
218 std::unique_ptr
<SwHistory
> m_pHistory
;
221 SwUndoTableMerge( const SwPaM
& rTableSel
);
223 virtual ~SwUndoTableMerge() override
;
225 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
226 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
228 void MoveBoxContent( SwDoc
& rDoc
, SwNodeRange
& rRg
, SwNodeIndex
& rPos
);
230 void SetSelBoxes( const SwSelBoxes
& rBoxes
);
232 void AddNewBox( sal_uLong nSttNdIdx
)
233 { m_aNewStartNodes
.push_back( nSttNdIdx
); }
235 void SaveCollection( const SwTableBox
& rBox
);
238 class SwUndoTableNumFormat
: public SwUndo
240 std::unique_ptr
<SfxItemSet
> m_pBoxSet
;
241 std::unique_ptr
<SwHistory
> m_pHistory
;
242 OUString m_aStr
, m_aNewFormula
;
244 sal_uLong m_nFormatIdx
, m_nNewFormatIdx
;
245 double m_fNum
, m_fNewNum
;
247 sal_uLong m_nNodePos
;
249 bool m_bNewFormat
: 1;
250 bool m_bNewFormula
: 1;
251 bool m_bNewValue
: 1;
254 SwUndoTableNumFormat( const SwTableBox
& rBox
, const SfxItemSet
* pNewSet
= nullptr );
256 virtual ~SwUndoTableNumFormat() override
;
258 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
259 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
261 void SetNumFormat( sal_uLong nNewNumFormatIdx
, const double& rNewNumber
)
262 { m_nFormatIdx
= nNewNumFormatIdx
; m_fNum
= rNewNumber
; }
263 void SetBox( const SwTableBox
& rBox
);
266 struct UndoTableCpyTable_Entry
;
268 class SwUndoTableCpyTable
: public SwUndo
270 std::vector
<std::unique_ptr
<UndoTableCpyTable_Entry
>> m_vArr
;
271 std::unique_ptr
<SwUndoTableNdsChg
> m_pInsRowUndo
;
273 //b6341295: When redlining is active, PrepareRedline has to create the
274 //redlining attributes for the new and the old table cell content
275 static std::unique_ptr
<SwUndo
> PrepareRedline( SwDoc
* pDoc
, const SwTableBox
& rBox
,
276 SwPosition
& rPos
, bool& rJoin
, bool bRedo
);
279 SwUndoTableCpyTable(const SwDoc
& rDoc
);
281 virtual ~SwUndoTableCpyTable() override
;
283 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
284 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
286 void AddBoxBefore( const SwTableBox
& rBox
, bool bDelContent
);
287 void AddBoxAfter( const SwTableBox
& rBox
, const SwNodeIndex
& rIdx
,
290 bool IsEmpty() const;
291 bool InsertRow( SwTable
& rTable
, const SwSelBoxes
& rBoxes
, sal_uInt16 nCnt
);
294 class SwUndoCpyTable
: public SwUndo
296 std::unique_ptr
<SwUndoDelete
> m_pDelete
;
297 sal_uLong m_nTableNode
;
300 SwUndoCpyTable(const SwDoc
& rDoc
);
302 virtual ~SwUndoCpyTable() override
;
304 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
305 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
307 void SetTableSttIdx( sal_uLong nIdx
) { m_nTableNode
= nIdx
; }
310 class SwUndoSplitTable
: public SwUndo
312 sal_uLong m_nTableNode
, m_nOffset
;
313 std::unique_ptr
<SwSaveRowSpan
> mpSaveRowSpan
; // stores row span values at the splitting row
314 std::unique_ptr
<SaveTable
> m_pSavedTable
;
315 std::unique_ptr
<SwHistory
> m_pHistory
;
316 SplitTable_HeadlineOption
const m_nMode
;
317 sal_uInt16 m_nFormulaEnd
;
321 SwUndoSplitTable( const SwTableNode
& rTableNd
, std::unique_ptr
<SwSaveRowSpan
> pRowSp
,
322 SplitTable_HeadlineOption nMode
, bool bCalcNewSize
);
324 virtual ~SwUndoSplitTable() override
;
326 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
327 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
328 virtual void RepeatImpl( ::sw::RepeatContext
& ) override
;
330 void SetTableNodeOffset( sal_uLong nIdx
) { m_nOffset
= nIdx
- m_nTableNode
; }
331 SwHistory
* GetHistory() { return m_pHistory
.get(); }
332 void SaveFormula( SwHistory
& rHistory
);
335 class SwUndoMergeTable
: public SwUndo
338 sal_uLong m_nTableNode
;
339 std::unique_ptr
<SaveTable
> m_pSaveTable
, m_pSaveHdl
;
340 std::unique_ptr
<SwHistory
> m_pHistory
;
345 SwUndoMergeTable( const SwTableNode
& rTableNd
, const SwTableNode
& rDelTableNd
,
346 bool bWithPrev
, sal_uInt16 nMode
);
348 virtual ~SwUndoMergeTable() override
;
350 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
351 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
352 virtual void RepeatImpl( ::sw::RepeatContext
& ) override
;
354 void SaveFormula( SwHistory
& rHistory
);
357 class SwUndoTableHeadline
: public SwUndo
359 sal_uLong m_nTableNode
;
360 sal_uInt16 m_nOldHeadline
;
361 sal_uInt16 m_nNewHeadline
;
364 SwUndoTableHeadline( const SwTable
&, sal_uInt16 nOldHdl
, sal_uInt16 nNewHdl
);
366 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
367 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
368 virtual void RepeatImpl( ::sw::RepeatContext
& ) override
;
371 void InsertSort( std::vector
<sal_uInt16
>& rArr
, sal_uInt16 nIdx
);
373 class SwUndoTableStyleMake
: public SwUndo
376 std::unique_ptr
<SwTableAutoFormat
> m_pAutoFormat
;
378 SwUndoTableStyleMake(const OUString
& rName
, const SwDoc
& rDoc
);
380 virtual ~SwUndoTableStyleMake() override
;
382 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
383 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
385 virtual SwRewriter
GetRewriter() const override
;
388 class SwUndoTableStyleDelete
: public SwUndo
390 std::unique_ptr
<SwTableAutoFormat
> m_pAutoFormat
;
391 std::vector
<SwTable
*> m_rAffectedTables
;
393 SwUndoTableStyleDelete(std::unique_ptr
<SwTableAutoFormat
> pAutoFormat
, const std::vector
<SwTable
*>& rAffectedTables
, const SwDoc
& rDoc
);
395 virtual ~SwUndoTableStyleDelete() override
;
397 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
398 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
400 virtual SwRewriter
GetRewriter() const override
;
403 class SwUndoTableStyleUpdate
: public SwUndo
405 std::unique_ptr
<SwTableAutoFormat
> m_pOldFormat
, m_pNewFormat
;
407 SwUndoTableStyleUpdate(const SwTableAutoFormat
& rNewFormat
, const SwTableAutoFormat
& rOldFormat
, const SwDoc
& rDoc
);
409 virtual ~SwUndoTableStyleUpdate() override
;
411 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
412 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
414 virtual SwRewriter
GetRewriter() const override
;
417 #endif // INCLUDED_SW_SOURCE_CORE_INC_UNDOTABLE_HXX
419 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */