Line data Source code
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 : #ifndef SW_UNDO_TABLE_HXX
21 : #define SW_UNDO_TABLE_HXX
22 :
23 : #include <undobj.hxx>
24 : #include <memory>
25 : #include <vector>
26 : #include <set>
27 : #include <swtypes.hxx>
28 : #include <itabenum.hxx>
29 : #include "boost/noncopyable.hpp"
30 : #include "boost/scoped_ptr.hpp"
31 :
32 : class SfxItemSet;
33 :
34 : struct SwSaveRowSpan;
35 : class _SaveTable;
36 : class SwDDEFieldType;
37 : class SwUndoSaveSections;
38 : class SwUndoMoves;
39 : class SwUndoDelete;
40 : class SwSelBoxes;
41 : class SwTblToTxtSaves;
42 : class SwTable;
43 : class SwTableBox;
44 : class SwStartNode;
45 : class SwTableNode;
46 : class SwTableAutoFmt;
47 : class SwTableSortBoxes;
48 :
49 : class SwUndoInsTbl : public SwUndo
50 : {
51 : String sTblNm;
52 : SwInsertTableOptions aInsTblOpts;
53 : SwDDEFieldType* pDDEFldType;
54 : std::vector<sal_uInt16> *pColWidth;
55 : SwRedlineData* pRedlData;
56 : SwTableAutoFmt* pAutoFmt;
57 : sal_uLong nSttNode;
58 : sal_uInt16 nRows, nCols;
59 : sal_uInt16 nAdjust;
60 :
61 : public:
62 : SwUndoInsTbl( const SwPosition&, sal_uInt16 nCols, sal_uInt16 nRows,
63 : sal_uInt16 eAdjust, const SwInsertTableOptions& rInsTblOpts,
64 : const SwTableAutoFmt* pTAFmt, const std::vector<sal_uInt16> *pColArr,
65 : const String & rName);
66 :
67 : virtual ~SwUndoInsTbl();
68 :
69 : virtual void UndoImpl( ::sw::UndoRedoContext & );
70 : virtual void RedoImpl( ::sw::UndoRedoContext & );
71 : virtual void RepeatImpl( ::sw::RepeatContext & );
72 :
73 : virtual SwRewriter GetRewriter() const;
74 : };
75 :
76 : class SwUndoTxtToTbl : public SwUndo, public SwUndRng
77 : {
78 : String sTblNm;
79 : SwInsertTableOptions aInsTblOpts;
80 : std::vector<sal_uLong>* pDelBoxes;
81 : SwTableAutoFmt* pAutoFmt;
82 : SwHistory* pHistory;
83 : sal_Unicode cTrenner;
84 : sal_uInt16 nAdjust;
85 : sal_Bool bSplitEnd : 1;
86 :
87 : public:
88 : SwUndoTxtToTbl( const SwPaM&, const SwInsertTableOptions&, sal_Unicode,
89 : sal_uInt16,
90 : const SwTableAutoFmt* pAFmt );
91 :
92 : virtual ~SwUndoTxtToTbl();
93 :
94 : virtual void UndoImpl( ::sw::UndoRedoContext & );
95 : virtual void RedoImpl( ::sw::UndoRedoContext & );
96 : virtual void RepeatImpl( ::sw::RepeatContext & );
97 :
98 : SwHistory& GetHistory(); // will be created if necessary
99 : void AddFillBox( const SwTableBox& rBox );
100 : };
101 :
102 : class SwUndoTblToTxt : public SwUndo
103 : {
104 : String sTblNm;
105 : SwDDEFieldType* pDDEFldType;
106 : _SaveTable* pTblSave;
107 : SwTblToTxtSaves* pBoxSaves;
108 : SwHistory* pHistory;
109 : sal_uLong nSttNd, nEndNd;
110 : sal_uInt16 nAdjust;
111 : sal_Unicode cTrenner;
112 : sal_uInt16 nHdlnRpt;
113 : sal_Bool bCheckNumFmt : 1;
114 :
115 : public:
116 : SwUndoTblToTxt( const SwTable& rTbl, sal_Unicode cCh );
117 :
118 : virtual ~SwUndoTblToTxt();
119 :
120 : virtual void UndoImpl( ::sw::UndoRedoContext & );
121 : virtual void RedoImpl( ::sw::UndoRedoContext & );
122 : virtual void RepeatImpl( ::sw::RepeatContext & );
123 :
124 : void SetRange( const SwNodeRange& );
125 : void AddBoxPos( SwDoc& rDoc, sal_uLong nNdIdx, sal_uLong nEndIdx,
126 : xub_StrLen nCntntIdx = STRING_MAXLEN);
127 : };
128 :
129 : class SwUndoAttrTbl : public SwUndo
130 : {
131 : sal_uLong nSttNode;
132 : _SaveTable* pSaveTbl;
133 : sal_Bool bClearTabCol : 1;
134 :
135 : public:
136 : SwUndoAttrTbl( const SwTableNode& rTblNd, sal_Bool bClearTabCols = sal_False );
137 :
138 : virtual ~SwUndoAttrTbl();
139 :
140 : virtual void UndoImpl( ::sw::UndoRedoContext & );
141 : virtual void RedoImpl( ::sw::UndoRedoContext & );
142 : };
143 :
144 : class SwUndoTblNumFmt;
145 :
146 : class SwUndoTblAutoFmt : public SwUndo
147 : {
148 : sal_uLong nSttNode;
149 : _SaveTable* pSaveTbl;
150 : ::std::vector< ::boost::shared_ptr<SwUndoTblNumFmt> > m_Undos;
151 : sal_Bool bSaveCntntAttr;
152 : sal_uInt16 m_nRepeatHeading;
153 :
154 : void UndoRedo(bool const bUndo, ::sw::UndoRedoContext & rContext);
155 :
156 : public:
157 : SwUndoTblAutoFmt( const SwTableNode& rTblNd, const SwTableAutoFmt& );
158 :
159 : virtual ~SwUndoTblAutoFmt();
160 :
161 : virtual void UndoImpl( ::sw::UndoRedoContext & );
162 : virtual void RedoImpl( ::sw::UndoRedoContext & );
163 :
164 : void SaveBoxCntnt( const SwTableBox& rBox );
165 : };
166 :
167 : class SwUndoTblNdsChg : public SwUndo, private boost::noncopyable
168 : {
169 : _SaveTable* pSaveTbl;
170 : std::set<sal_uLong> m_Boxes;
171 : struct _BoxMove
172 : {
173 : sal_uLong index; ///< Index of this box.
174 : bool hasMoved; ///< Has this box been moved already.
175 0 : _BoxMove(sal_uLong idx, bool moved=false) : index(idx), hasMoved(moved) {};
176 0 : bool operator<(const _BoxMove other) const { return index < other.index; };
177 : };
178 : boost::scoped_ptr< std::set<_BoxMove> > pNewSttNds;
179 : boost::scoped_ptr< SwUndoSaveSections > pDelSects;
180 : long nMin, nMax; // for redo of delete column
181 : sal_uLong nSttNode, nCurrBox;
182 : sal_uInt16 nCount, nRelDiff, nAbsDiff, nSetColType;
183 : sal_Bool bFlag;
184 : sal_Bool bSameHeight; // only used for SplitRow
185 :
186 : public:
187 : SwUndoTblNdsChg( SwUndoId UndoId,
188 : const SwSelBoxes& rBoxes,
189 : const SwTableNode& rTblNd,
190 : long nMn, long nMx,
191 : sal_uInt16 nCnt, sal_Bool bFlg, sal_Bool bSameHeight );
192 :
193 : // for SetColWidth
194 : SwUndoTblNdsChg( SwUndoId UndoId, const SwSelBoxes& rBoxes,
195 : const SwTableNode& rTblNd );
196 :
197 : virtual ~SwUndoTblNdsChg();
198 :
199 : virtual void UndoImpl( ::sw::UndoRedoContext & );
200 : virtual void RedoImpl( ::sw::UndoRedoContext & );
201 :
202 : void SaveNewBoxes( const SwTableNode& rTblNd, const SwTableSortBoxes& rOld );
203 : void SaveNewBoxes( const SwTableNode& rTblNd, const SwTableSortBoxes& rOld,
204 : const SwSelBoxes& rBoxes, const std::vector<sal_uLong> &rNodeCnts );
205 : void SaveSection( SwStartNode* pSttNd );
206 : void ReNewBoxes( const SwSelBoxes& rBoxes );
207 :
208 0 : void SetColWidthParam( sal_uLong nBoxIdx, sal_uInt16 nMode, sal_uInt16 nType,
209 : SwTwips nAbsDif, SwTwips nRelDif )
210 : {
211 0 : nCurrBox = nBoxIdx;
212 0 : nCount = nMode;
213 0 : nSetColType = nType;
214 0 : nAbsDiff = (sal_uInt16)nAbsDif;
215 0 : nRelDiff = (sal_uInt16)nRelDif;
216 0 : }
217 : };
218 :
219 : class SwUndoTblMerge : public SwUndo, private SwUndRng
220 : {
221 : sal_uLong nTblNode;
222 : _SaveTable* pSaveTbl;
223 : std::set<sal_uLong> m_Boxes;
224 : std::vector<sal_uLong> aNewSttNds;
225 : SwUndoMoves* pMoves;
226 : SwHistory* pHistory;
227 :
228 : public:
229 : SwUndoTblMerge( const SwPaM& rTblSel );
230 :
231 : virtual ~SwUndoTblMerge();
232 :
233 : virtual void UndoImpl( ::sw::UndoRedoContext & );
234 : virtual void RedoImpl( ::sw::UndoRedoContext & );
235 :
236 : void MoveBoxCntnt( SwDoc* pDoc, SwNodeRange& rRg, SwNodeIndex& rPos );
237 :
238 : void SetSelBoxes( const SwSelBoxes& rBoxes );
239 :
240 0 : void AddNewBox( sal_uLong nSttNdIdx )
241 0 : { aNewSttNds.push_back( nSttNdIdx ); }
242 :
243 : void SaveCollection( const SwTableBox& rBox );
244 : };
245 :
246 : class SwUndoTblNumFmt : public SwUndo
247 : {
248 : SfxItemSet *pBoxSet;
249 : SwHistory* pHistory;
250 : String aStr, aNewFml;
251 :
252 : sal_uLong nFmtIdx, nNewFmtIdx;
253 : double fNum, fNewNum;
254 : sal_uLong nNode;
255 : sal_uLong nNdPos;
256 :
257 : sal_Bool bNewFmt : 1;
258 : sal_Bool bNewFml : 1;
259 : sal_Bool bNewValue : 1;
260 :
261 : public:
262 : SwUndoTblNumFmt( const SwTableBox& rBox, const SfxItemSet* pNewSet = 0 );
263 :
264 : virtual ~SwUndoTblNumFmt();
265 :
266 : virtual void UndoImpl( ::sw::UndoRedoContext & );
267 : virtual void RedoImpl( ::sw::UndoRedoContext & );
268 :
269 0 : void SetNumFmt( sal_uLong nNewNumFmtIdx, const double& rNewNumber )
270 0 : { nFmtIdx = nNewNumFmtIdx; fNum = rNewNumber; }
271 : void SetBox( const SwTableBox& rBox );
272 : };
273 :
274 : class _UndoTblCpyTbl_Entries;
275 :
276 : class SwUndoTblCpyTbl : public SwUndo
277 : {
278 : _UndoTblCpyTbl_Entries* pArr;
279 : SwUndoTblNdsChg* pInsRowUndo;
280 :
281 : //b6341295: When redlining is active, PrepareRedline has to create the
282 : //redlining attributes for the new and the old table cell content
283 : SwUndo* PrepareRedline( SwDoc* pDoc, const SwTableBox& rBox,
284 : const SwPosition& rPos, bool& rJoin, bool bRedo );
285 :
286 : public:
287 : SwUndoTblCpyTbl();
288 :
289 : virtual ~SwUndoTblCpyTbl();
290 :
291 : virtual void UndoImpl( ::sw::UndoRedoContext & );
292 : virtual void RedoImpl( ::sw::UndoRedoContext & );
293 :
294 : void AddBoxBefore( const SwTableBox& rBox, bool bDelCntnt );
295 : void AddBoxAfter( const SwTableBox& rBox, const SwNodeIndex& rIdx,
296 : bool bDelCntnt );
297 :
298 : sal_Bool IsEmpty() const;
299 : bool InsertRow( SwTable& rTbl, const SwSelBoxes& rBoxes, sal_uInt16 nCnt );
300 : };
301 :
302 : class SwUndoCpyTbl : public SwUndo
303 : {
304 : SwUndoDelete* pDel;
305 : sal_uLong nTblNode;
306 :
307 : public:
308 : SwUndoCpyTbl();
309 :
310 : virtual ~SwUndoCpyTbl();
311 :
312 : virtual void UndoImpl( ::sw::UndoRedoContext & );
313 : virtual void RedoImpl( ::sw::UndoRedoContext & );
314 :
315 0 : void SetTableSttIdx( sal_uLong nIdx ) { nTblNode = nIdx; }
316 : };
317 :
318 : class SwUndoSplitTbl : public SwUndo
319 : {
320 : sal_uLong nTblNode, nOffset;
321 : SwSaveRowSpan* mpSaveRowSpan; // stores row span values at the splitting row
322 : _SaveTable* pSavTbl;
323 : SwHistory* pHistory;
324 : sal_uInt16 nMode, nFmlEnd;
325 : sal_Bool bCalcNewSize;
326 :
327 : public:
328 : SwUndoSplitTbl( const SwTableNode& rTblNd, SwSaveRowSpan* pRowSp,
329 : sal_uInt16 nMode, sal_Bool bCalcNewSize );
330 :
331 : virtual ~SwUndoSplitTbl();
332 :
333 : virtual void UndoImpl( ::sw::UndoRedoContext & );
334 : virtual void RedoImpl( ::sw::UndoRedoContext & );
335 : virtual void RepeatImpl( ::sw::RepeatContext & );
336 :
337 0 : void SetTblNodeOffset( sal_uLong nIdx ) { nOffset = nIdx - nTblNode; }
338 0 : SwHistory* GetHistory() { return pHistory; }
339 : void SaveFormula( SwHistory& rHistory );
340 : };
341 :
342 : class SwUndoMergeTbl : public SwUndo
343 : {
344 : String aName;
345 : sal_uLong nTblNode;
346 : _SaveTable* pSavTbl, *pSavHdl;
347 : SwHistory* pHistory;
348 : sal_uInt16 nMode;
349 : sal_Bool bWithPrev;
350 :
351 : public:
352 : SwUndoMergeTbl( const SwTableNode& rTblNd, const SwTableNode& rDelTblNd,
353 : sal_Bool bWithPrev, sal_uInt16 nMode );
354 :
355 : virtual ~SwUndoMergeTbl();
356 :
357 : virtual void UndoImpl( ::sw::UndoRedoContext & );
358 : virtual void RedoImpl( ::sw::UndoRedoContext & );
359 : virtual void RepeatImpl( ::sw::RepeatContext & );
360 :
361 : void SaveFormula( SwHistory& rHistory );
362 : };
363 :
364 0 : class SwUndoTblHeadline : public SwUndo
365 : {
366 : sal_uLong nTblNd;
367 : sal_uInt16 nOldHeadline;
368 : sal_uInt16 nNewHeadline;
369 :
370 : public:
371 : SwUndoTblHeadline( const SwTable&, sal_uInt16 nOldHdl, sal_uInt16 nNewHdl );
372 :
373 : virtual void UndoImpl( ::sw::UndoRedoContext & );
374 : virtual void RedoImpl( ::sw::UndoRedoContext & );
375 : virtual void RepeatImpl( ::sw::RepeatContext & );
376 : };
377 :
378 : #endif // SW_UNDO_TABLE_HXX
379 :
380 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|