bump product version to 4.1.6.2
[LibreOffice.git] / sw / inc / undobj.hxx
blob3357401c152453cf9d6d8a10098e47650f14eadd
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 .
19 #ifndef SW_UNDOBJ_HXX
20 #define SW_UNDOBJ_HXX
22 #include <vector>
24 #include <boost/scoped_ptr.hpp>
25 #include <boost/shared_ptr.hpp>
27 #include <svl/undo.hxx>
29 #include <SwRewriter.hxx>
30 #include <swundo.hxx>
32 class SwHistory;
33 class SwIndex;
34 class SwPaM;
35 struct SwPosition;
36 class SwDoc;
37 class SwTxtFmtColl;
38 class SwFrmFmt;
39 class SwNodeIndex;
40 class SwNodeRange;
41 class SwRedlineData;
42 class SwRedlineSaveDatas;
44 namespace sw {
45 class UndoRedoContext;
46 class RepeatContext;
49 class SwUndo
50 : public SfxUndoAction
52 SwUndoId const m_nId;
53 sal_uInt16 nOrigRedlineMode;
55 protected:
56 bool bCacheComment;
57 mutable String * pComment;
59 void RemoveIdxFromSection( SwDoc&, sal_uLong nSttIdx, sal_uLong* pEndIdx = 0 );
60 void RemoveIdxFromRange( SwPaM& rPam, sal_Bool bMoveNext );
61 void RemoveIdxRel( sal_uLong, const SwPosition& );
63 static sal_Bool CanRedlineGroup( SwRedlineSaveDatas& rCurr,
64 const SwRedlineSaveDatas& rCheck,
65 sal_Bool bCurrIsEnd );
67 /**
68 Returns the rewriter for this object.
70 @return the rewriter for this object
72 virtual SwRewriter GetRewriter() const;
74 // return type is sal_uInt16 because this overrides SfxUndoAction::GetId()
75 virtual sal_uInt16 GetId() const { return static_cast<sal_uInt16>(m_nId); }
77 // the 4 methods that derived classes have to override
78 // base implementation does nothing
79 virtual void RepeatImpl( ::sw::RepeatContext & );
80 virtual bool CanRepeatImpl( ::sw::RepeatContext & ) const;
81 public: // should not be public, but ran into trouble in untbl.cxx
82 virtual void UndoImpl( ::sw::UndoRedoContext & ) = 0;
83 virtual void RedoImpl( ::sw::UndoRedoContext & ) = 0;
85 private:
86 // SfxUndoAction
87 virtual void Undo();
88 virtual void Redo();
89 virtual void UndoWithContext(SfxUndoContext &);
90 virtual void RedoWithContext(SfxUndoContext &);
91 virtual void Repeat(SfxRepeatTarget &);
92 virtual sal_Bool CanRepeat(SfxRepeatTarget &) const;
94 public:
95 SwUndo(SwUndoId const nId);
96 virtual ~SwUndo();
98 /**
99 Returns textual comment for this undo object.
101 The textual comment is created from the resource string
102 corresponding to this object's ID. The rewriter of this object
103 is applied to the resource string to get the final comment.
105 @return textual comment for this undo object
107 virtual OUString GetComment() const;
109 // UndoObject remembers which mode was turned on.
110 // In Undo/Redo/Repeat this remembered mode is switched on.
111 sal_uInt16 GetRedlineMode() const { return nOrigRedlineMode; }
112 void SetRedlineMode( sal_uInt16 eMode ) { nOrigRedlineMode = eMode; }
114 bool IsDelBox() const;
116 // Save and set Redline data.
117 static sal_Bool FillSaveData( const SwPaM& rRange, SwRedlineSaveDatas& rSData,
118 sal_Bool bDelRange = sal_True, sal_Bool bCopyNext = sal_True );
119 static sal_Bool FillSaveDataForFmt( const SwPaM& , SwRedlineSaveDatas& );
120 static void SetSaveData( SwDoc& rDoc, const SwRedlineSaveDatas& rSData );
121 static sal_Bool HasHiddenRedlines( const SwRedlineSaveDatas& rSData );
124 typedef sal_uInt16 DelCntntType;
125 namespace nsDelCntntType
127 const DelCntntType DELCNT_FTN = 0x01;
128 const DelCntntType DELCNT_FLY = 0x02;
129 const DelCntntType DELCNT_TOC = 0x04;
130 const DelCntntType DELCNT_BKM = 0x08;
131 const DelCntntType DELCNT_ALL = 0x0F;
132 const DelCntntType DELCNT_CHKNOCNTNT = 0x80;
135 /// will DelCntntIndex destroy a frame anchored at character at rAnchorPos?
136 bool IsDestroyFrameAnchoredAtChar(SwPosition const & rAnchorPos,
137 SwPosition const & rStart, SwPosition const & rEnd,
138 DelCntntType const nDelCntntType = nsDelCntntType::DELCNT_ALL);
141 // This class has to be inherited into an Undo-object if it saves content
142 // for Redo/Undo...
143 class SwUndoSaveCntnt
145 protected:
147 SwHistory* pHistory;
149 // Needed for deletion of content. For Redo content is moved into the
150 // UndoNodesArray. These methods always create a new node to insert
151 // content. So the attributes do not get expanded.
152 // MoveTo: moves from the NodesArray into the UndoNodesArray.
153 // MoveFrom: moves from the UndoNodesArray into the NodesArray.
154 void MoveToUndoNds( SwPaM& rPam,
155 SwNodeIndex* pNodeIdx = 0,
156 sal_uLong* pEndNdIdx = 0, xub_StrLen * pEndCntIdx = 0 );
157 void MoveFromUndoNds( SwDoc& rDoc, sal_uLong nNodeIdx,
158 SwPosition& rInsPos,
159 sal_uLong* pEndNdIdx = 0, xub_StrLen * pEndCntIdx = 0 );
161 // These two methods move the SPoint back/forth from PaM. With it
162 // a range can be spanned for Undo/Redo. (In this case the SPoint
163 // is before the manipulated range!!)
164 // The flag indicates if there is content before the SPoint.
165 sal_Bool MovePtBackward( SwPaM& rPam );
166 void MovePtForward( SwPaM& rPam, sal_Bool bMvBkwrd );
168 // Before moving stuff into UndoNodes-Array care has to be taken that
169 // the content-bearing attributes are removed from the nodes-array.
170 void DelCntntIndex( const SwPosition& pMark, const SwPosition& pPoint,
171 DelCntntType nDelCntntType = nsDelCntntType::DELCNT_ALL );
173 public:
174 SwUndoSaveCntnt();
175 ~SwUndoSaveCntnt();
178 // Save a complete section in nodes-array.
179 class SwUndoSaveSection : private SwUndoSaveCntnt
181 SwNodeIndex *pMvStt;
182 SwRedlineSaveDatas* pRedlSaveData;
183 sal_uLong nMvLen; // Index into UndoNodes-Array.
184 sal_uLong nStartPos;
186 protected:
187 SwNodeIndex* GetMvSttIdx() const { return pMvStt; }
188 sal_uLong GetMvNodeCnt() const { return nMvLen; }
190 public:
191 SwUndoSaveSection();
192 ~SwUndoSaveSection();
194 void SaveSection( SwDoc* pDoc, const SwNodeIndex& rSttIdx );
195 void SaveSection( SwDoc* pDoc, const SwNodeRange& rRange );
196 void RestoreSection( SwDoc* pDoc, SwNodeIndex* pIdx, sal_uInt16 nSectType );
197 void RestoreSection( SwDoc* pDoc, const SwNodeIndex& rInsPos );
199 const SwHistory* GetHistory() const { return pHistory; }
200 SwHistory* GetHistory() { return pHistory; }
204 // This class saves the PaM as sal_uInt16's and is able to restore it
205 // into a PaM.
206 class SwUndRng
208 public:
209 sal_uLong nSttNode, nEndNode;
210 xub_StrLen nSttCntnt, nEndCntnt;
212 SwUndRng();
213 SwUndRng( const SwPaM& );
215 void SetValues( const SwPaM& rPam );
216 void SetPaM( SwPaM&, sal_Bool bCorrToCntnt = sal_False ) const;
217 SwPaM & AddUndoRedoPaM(
218 ::sw::UndoRedoContext &, bool const bCorrToCntnt = false) const;
222 class SwUndoInsLayFmt;
224 // base class for insertion of Document, Glossaries and Copy
225 class SwUndoInserts : public SwUndo, public SwUndRng, private SwUndoSaveCntnt
227 SwTxtFmtColl *pTxtFmtColl, *pLastNdColl;
228 std::vector<SwFrmFmt*>* pFrmFmts;
229 ::std::vector< ::boost::shared_ptr<SwUndoInsLayFmt> > m_FlyUndos;
230 SwRedlineData* pRedlData;
231 sal_Bool bSttWasTxtNd;
232 protected:
233 sal_uLong nNdDiff;
234 /// start of Content in UndoNodes for Redo
235 ::boost::scoped_ptr<SwNodeIndex> m_pUndoNodeIndex;
236 sal_uInt16 nSetPos; // Start in the history list.
238 SwUndoInserts( SwUndoId nUndoId, const SwPaM& );
239 public:
240 virtual ~SwUndoInserts();
242 virtual void UndoImpl( ::sw::UndoRedoContext & );
243 virtual void RedoImpl( ::sw::UndoRedoContext & );
244 virtual void RepeatImpl( ::sw::RepeatContext & );
246 // Set destination range after reading.
247 void SetInsertRange( const SwPaM&, sal_Bool bScanFlys = sal_True,
248 sal_Bool bSttWasTxtNd = sal_True );
251 class SwUndoInsDoc : public SwUndoInserts
253 public:
254 SwUndoInsDoc( const SwPaM& );
257 class SwUndoCpyDoc : public SwUndoInserts
259 public:
260 SwUndoCpyDoc( const SwPaM& );
263 //--------------------------------------------------------------------
265 class SwUndoFlyBase : public SwUndo, private SwUndoSaveSection
267 protected:
268 SwFrmFmt* pFrmFmt; // The saved FlyFormat.
269 sal_uLong nNdPgPos;
270 xub_StrLen nCntPos; // Page at/in paragraph.
271 sal_uInt16 nRndId;
272 sal_Bool bDelFmt; // Delete saved format.
274 void InsFly(::sw::UndoRedoContext & rContext, bool bShowSel = true);
275 void DelFly( SwDoc* );
277 SwUndoFlyBase( SwFrmFmt* pFormat, SwUndoId nUndoId );
279 SwNodeIndex* GetMvSttIdx() const { return SwUndoSaveSection::GetMvSttIdx(); }
280 sal_uLong GetMvNodeCnt() const { return SwUndoSaveSection::GetMvNodeCnt(); }
282 public:
283 virtual ~SwUndoFlyBase();
287 class SwUndoInsLayFmt : public SwUndoFlyBase
289 sal_uLong mnCrsrSaveIndexPara; // Cursor position
290 xub_StrLen mnCrsrSaveIndexPos; // for undo
291 public:
292 SwUndoInsLayFmt( SwFrmFmt* pFormat, sal_uLong nNodeIdx, xub_StrLen nCntIdx );
294 virtual ~SwUndoInsLayFmt();
296 virtual void UndoImpl( ::sw::UndoRedoContext & );
297 virtual void RedoImpl( ::sw::UndoRedoContext & );
298 virtual void RepeatImpl( ::sw::RepeatContext & );
300 virtual OUString GetComment() const;
304 class SwUndoDelLayFmt : public SwUndoFlyBase
306 sal_Bool bShowSelFrm;
307 public:
308 SwUndoDelLayFmt( SwFrmFmt* pFormat );
310 virtual void UndoImpl( ::sw::UndoRedoContext & );
311 virtual void RedoImpl( ::sw::UndoRedoContext & );
313 void RedoForRollback();
315 void ChgShowSel( sal_Bool bNew ) { bShowSelFrm = bNew; }
317 virtual SwRewriter GetRewriter() const;
321 #endif
323 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */