xref: /aoo42x/main/sw/source/core/inc/UndoTable.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SW_UNDO_TABLE_HXX
29 #define SW_UNDO_TABLE_HXX
30 
31 #include <undobj.hxx>
32 
33 #ifndef _SVSTDARR_HXX
34 #define _SVSTDARR_USHORTS
35 #define _SVSTDARR_ULONGS
36 #define _SVSTDARR_BOOLS
37 #define _SVSTDARR_BYTES
38 #define _SVSTDARR_USHORTSSORT
39 #include <svl/svstdarr.hxx>
40 #endif
41 
42 #include <swtypes.hxx>
43 #include <itabenum.hxx>
44 
45 
46 class SfxItemSet;
47 
48 struct SwSaveRowSpan;
49 class _SaveTable;
50 class SwDDEFieldType;
51 class SwUndoSaveSections;
52 class SwUndoMoves;
53 class SwUndoDelete;
54 class SwSelBoxes;
55 class SwTblToTxtSaves;
56 class SwTable;
57 class SwTableBox;
58 class SwStartNode;
59 class SwTableNode;
60 class SwTableAutoFmt;
61 class SwTableSortBoxes;
62 
63 
64 class SwUndoInsTbl : public SwUndo
65 {
66     String sTblNm;
67     SwInsertTableOptions aInsTblOpts;
68     SwDDEFieldType* pDDEFldType;
69     SvUShorts* pColWidth;
70     SwRedlineData*  pRedlData;
71     SwTableAutoFmt* pAutoFmt;
72     sal_uLong nSttNode;
73     sal_uInt16 nRows, nCols;
74     sal_uInt16 nAdjust;
75 
76 public:
77     SwUndoInsTbl( const SwPosition&, sal_uInt16 nCols, sal_uInt16 nRows,
78                     sal_uInt16 eAdjust, const SwInsertTableOptions& rInsTblOpts,
79                     const SwTableAutoFmt* pTAFmt, const SvUShorts* pColArr,
80                   const String & rName);
81 
82     virtual ~SwUndoInsTbl();
83 
84     virtual void UndoImpl( ::sw::UndoRedoContext & );
85     virtual void RedoImpl( ::sw::UndoRedoContext & );
86     virtual void RepeatImpl( ::sw::RepeatContext & );
87 
88     virtual SwRewriter GetRewriter() const;
89 
90 };
91 
92 class SwUndoTxtToTbl : public SwUndo, public SwUndRng
93 {
94     String sTblNm;
95     SwInsertTableOptions aInsTblOpts;
96     SvULongs* pDelBoxes;
97     SwTableAutoFmt* pAutoFmt;
98     SwHistory* pHistory;
99     sal_Unicode cTrenner;
100     sal_uInt16 nAdjust;
101     sal_Bool bSplitEnd : 1;
102 
103 public:
104     SwUndoTxtToTbl( const SwPaM&, const SwInsertTableOptions&, sal_Unicode,
105                     sal_uInt16,
106                     const SwTableAutoFmt* pAFmt );
107 
108     virtual ~SwUndoTxtToTbl();
109 
110 
111     virtual void UndoImpl( ::sw::UndoRedoContext & );
112     virtual void RedoImpl( ::sw::UndoRedoContext & );
113     virtual void RepeatImpl( ::sw::RepeatContext & );
114 
115     SwHistory& GetHistory(); // will be created if necessary
116     void AddFillBox( const SwTableBox& rBox );
117 };
118 
119 class SwUndoTblToTxt : public SwUndo
120 {
121     String sTblNm;
122     SwDDEFieldType* pDDEFldType;
123     _SaveTable* pTblSave;
124     SwTblToTxtSaves* pBoxSaves;
125     SwHistory* pHistory;
126     sal_uLong nSttNd, nEndNd;
127     sal_uInt16 nAdjust;
128     sal_Unicode cTrenner;
129     sal_uInt16 nHdlnRpt;
130     sal_Bool bCheckNumFmt : 1;
131 
132 public:
133     SwUndoTblToTxt( const SwTable& rTbl, sal_Unicode cCh );
134 
135     virtual ~SwUndoTblToTxt();
136 
137     virtual void UndoImpl( ::sw::UndoRedoContext & );
138     virtual void RedoImpl( ::sw::UndoRedoContext & );
139     virtual void RepeatImpl( ::sw::RepeatContext & );
140 
141     void SetRange( const SwNodeRange& );
142     void AddBoxPos( SwDoc& rDoc, sal_uLong nNdIdx, sal_uLong nEndIdx,
143                     xub_StrLen nCntntIdx = STRING_MAXLEN);
144 };
145 
146 class SwUndoAttrTbl : public SwUndo
147 {
148     sal_uLong nSttNode;
149     _SaveTable* pSaveTbl;
150     sal_Bool bClearTabCol : 1;
151 public:
152     SwUndoAttrTbl( const SwTableNode& rTblNd, sal_Bool bClearTabCols = sal_False );
153 
154     virtual ~SwUndoAttrTbl();
155 
156     virtual void UndoImpl( ::sw::UndoRedoContext & );
157     virtual void RedoImpl( ::sw::UndoRedoContext & );
158 };
159 
160 class SwUndoTblNumFmt;
161 
162 class SwUndoTblAutoFmt : public SwUndo
163 {
164     sal_uLong nSttNode;
165     _SaveTable* pSaveTbl;
166     ::std::vector< ::boost::shared_ptr<SwUndoTblNumFmt> > m_Undos;
167     sal_Bool bSaveCntntAttr;
168 
169     void UndoRedo(bool const bUndo, ::sw::UndoRedoContext & rContext);
170 
171 public:
172     SwUndoTblAutoFmt( const SwTableNode& rTblNd, const SwTableAutoFmt& );
173 
174     virtual ~SwUndoTblAutoFmt();
175 
176     virtual void UndoImpl( ::sw::UndoRedoContext & );
177     virtual void RedoImpl( ::sw::UndoRedoContext & );
178 
179     void SaveBoxCntnt( const SwTableBox& rBox );
180 };
181 
182 class SwUndoTblNdsChg : public SwUndo
183 {
184     _SaveTable* pSaveTbl;
185     SvULongs aBoxes;
186 
187     union {
188         SvULongs* pNewSttNds;
189         SwUndoSaveSections* pDelSects;
190     } Ptrs;
191     SvBools aMvBoxes;       // for SplitRow (split Nodes of Box)
192     long nMin, nMax;        // for redo of delete column
193     sal_uLong nSttNode, nCurrBox;
194     sal_uInt16 nCount, nRelDiff, nAbsDiff, nSetColType;
195     sal_Bool bFlag;
196     sal_Bool bSameHeight;                   // only used for SplitRow
197 public:
198     SwUndoTblNdsChg( SwUndoId UndoId,
199                     const SwSelBoxes& rBoxes,
200                     const SwTableNode& rTblNd,
201                     long nMn, long nMx,
202                     sal_uInt16 nCnt, sal_Bool bFlg, sal_Bool bSameHeight );
203 
204     // for SetColWidth
205     SwUndoTblNdsChg( SwUndoId UndoId, const SwSelBoxes& rBoxes,
206                     const SwTableNode& rTblNd );
207 
208     virtual ~SwUndoTblNdsChg();
209 
210     virtual void UndoImpl( ::sw::UndoRedoContext & );
211     virtual void RedoImpl( ::sw::UndoRedoContext & );
212 
213     void SaveNewBoxes( const SwTableNode& rTblNd, const SwTableSortBoxes& rOld );
214     void SaveNewBoxes( const SwTableNode& rTblNd, const SwTableSortBoxes& rOld,
215                        const SwSelBoxes& rBoxes, const SvULongs& rNodeCnts );
216     void SaveSection( SwStartNode* pSttNd );
217     void ReNewBoxes( const SwSelBoxes& rBoxes );
218 
219 
220     void SetColWidthParam( sal_uLong nBoxIdx, sal_uInt16 nMode, sal_uInt16 nType,
221                             SwTwips nAbsDif, SwTwips nRelDif )
222     {
223         nCurrBox = nBoxIdx;
224         nCount = nMode;
225         nSetColType = nType;
226         nAbsDiff = (sal_uInt16)nAbsDif;
227         nRelDiff = (sal_uInt16)nRelDif;
228     }
229 
230 };
231 
232 class SwUndoTblMerge : public SwUndo, private SwUndRng
233 {
234     sal_uLong nTblNode;
235     _SaveTable* pSaveTbl;
236     SvULongs aBoxes, aNewSttNds;
237     SwUndoMoves* pMoves;
238     SwHistory* pHistory;
239 
240 public:
241     SwUndoTblMerge( const SwPaM& rTblSel );
242 
243     virtual ~SwUndoTblMerge();
244 
245     virtual void UndoImpl( ::sw::UndoRedoContext & );
246     virtual void RedoImpl( ::sw::UndoRedoContext & );
247 
248     void MoveBoxCntnt( SwDoc* pDoc, SwNodeRange& rRg, SwNodeIndex& rPos );
249 
250     void SetSelBoxes( const SwSelBoxes& rBoxes );
251 
252     void AddNewBox( sal_uLong nSttNdIdx )
253         { aNewSttNds.Insert( nSttNdIdx, aNewSttNds.Count() ); }
254 
255     void SaveCollection( const SwTableBox& rBox );
256 
257 };
258 
259 
260 class SwUndoTblNumFmt : public SwUndo
261 {
262     SfxItemSet *pBoxSet;
263     SwHistory* pHistory;
264     String aStr, aNewFml;
265 
266     sal_uLong nFmtIdx, nNewFmtIdx;
267     double fNum, fNewNum;
268     sal_uLong nNode;
269     sal_uLong nNdPos;
270 
271     sal_Bool bNewFmt : 1;
272     sal_Bool bNewFml : 1;
273     sal_Bool bNewValue : 1;
274 
275 public:
276     SwUndoTblNumFmt( const SwTableBox& rBox, const SfxItemSet* pNewSet = 0 );
277 
278     virtual ~SwUndoTblNumFmt();
279 
280     virtual void UndoImpl( ::sw::UndoRedoContext & );
281     virtual void RedoImpl( ::sw::UndoRedoContext & );
282 
283     void SetNumFmt( sal_uLong nNewNumFmtIdx, const double& rNewNumber )
284             { nFmtIdx = nNewNumFmtIdx; fNum = rNewNumber; }
285     void SetBox( const SwTableBox& rBox );
286 };
287 
288 class _UndoTblCpyTbl_Entries;
289 
290 class SwUndoTblCpyTbl : public SwUndo
291 {
292     _UndoTblCpyTbl_Entries* pArr;
293     SwUndoTblNdsChg* pInsRowUndo;
294 
295     //b6341295: When redlining is active, PrepareRedline has to create the
296     //redlining attributes for the new and the old table cell content
297     SwUndo* PrepareRedline( SwDoc* pDoc, const SwTableBox& rBox,
298                 const SwPosition& rPos, bool& rJoin, bool bRedo );
299 public:
300     SwUndoTblCpyTbl();
301 
302     virtual ~SwUndoTblCpyTbl();
303 
304     virtual void UndoImpl( ::sw::UndoRedoContext & );
305     virtual void RedoImpl( ::sw::UndoRedoContext & );
306 
307     void AddBoxBefore( const SwTableBox& rBox, sal_Bool bDelCntnt );
308     void AddBoxAfter( const SwTableBox& rBox, const SwNodeIndex& rIdx,
309                 sal_Bool bDelCntnt );
310 
311     sal_Bool IsEmpty() const;
312     sal_Bool InsertRow( SwTable& rTbl, const SwSelBoxes& rBoxes, sal_uInt16 nCnt );
313 };
314 
315 class SwUndoCpyTbl : public SwUndo
316 {
317     SwUndoDelete* pDel;
318     sal_uLong nTblNode;
319 public:
320     SwUndoCpyTbl();
321 
322     virtual ~SwUndoCpyTbl();
323 
324     virtual void UndoImpl( ::sw::UndoRedoContext & );
325     virtual void RedoImpl( ::sw::UndoRedoContext & );
326 
327     void SetTableSttIdx( sal_uLong nIdx )           { nTblNode = nIdx; }
328 };
329 
330 class SwUndoSplitTbl : public SwUndo
331 {
332     sal_uLong nTblNode, nOffset;
333     SwSaveRowSpan* mpSaveRowSpan; // stores row span values at the splitting row
334     _SaveTable* pSavTbl;
335     SwHistory* pHistory;
336     sal_uInt16 nMode, nFmlEnd;
337     sal_Bool bCalcNewSize;
338 public:
339     SwUndoSplitTbl( const SwTableNode& rTblNd, SwSaveRowSpan* pRowSp,
340             sal_uInt16 nMode, sal_Bool bCalcNewSize );
341 
342     virtual ~SwUndoSplitTbl();
343 
344     virtual void UndoImpl( ::sw::UndoRedoContext & );
345     virtual void RedoImpl( ::sw::UndoRedoContext & );
346     virtual void RepeatImpl( ::sw::RepeatContext & );
347 
348     void SetTblNodeOffset( sal_uLong nIdx )     { nOffset = nIdx - nTblNode; }
349     SwHistory* GetHistory()                 { return pHistory; }
350     void SaveFormula( SwHistory& rHistory );
351 };
352 
353 class SwUndoMergeTbl : public SwUndo
354 {
355     String aName;
356     sal_uLong nTblNode;
357     _SaveTable* pSavTbl, *pSavHdl;
358     SwHistory* pHistory;
359     sal_uInt16 nMode;
360     sal_Bool bWithPrev;
361 public:
362     SwUndoMergeTbl( const SwTableNode& rTblNd, const SwTableNode& rDelTblNd,
363                     sal_Bool bWithPrev, sal_uInt16 nMode );
364 
365     virtual ~SwUndoMergeTbl();
366 
367     virtual void UndoImpl( ::sw::UndoRedoContext & );
368     virtual void RedoImpl( ::sw::UndoRedoContext & );
369     virtual void RepeatImpl( ::sw::RepeatContext & );
370 
371     void SaveFormula( SwHistory& rHistory );
372 };
373 
374 
375 //--------------------------------------------------------------------
376 
377 class SwUndoTblHeadline : public SwUndo
378 {
379     sal_uLong nTblNd;
380     sal_uInt16 nOldHeadline;
381     sal_uInt16 nNewHeadline;
382 public:
383     SwUndoTblHeadline( const SwTable&, sal_uInt16 nOldHdl,  sal_uInt16 nNewHdl );
384 
385     virtual void UndoImpl( ::sw::UndoRedoContext & );
386     virtual void RedoImpl( ::sw::UndoRedoContext & );
387     virtual void RepeatImpl( ::sw::RepeatContext & );
388 };
389 
390 #endif // SW_UNDO_TABLE_HXX
391 
392