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 .
19 #ifndef INCLUDED_SW_INC_UNDOBJ_HXX
20 #define INCLUDED_SW_INC_UNDOBJ_HXX
24 #include <boost/scoped_ptr.hpp>
25 #include <boost/shared_ptr.hpp>
27 #include <svl/undo.hxx>
29 #include <SwRewriter.hxx>
37 class SwTextFormatColl
;
42 class SwRedlineSaveDatas
;
45 class UndoRedoContext
;
50 : public SfxUndoAction
53 sal_uInt16 nOrigRedlineMode
;
57 mutable OUString
* pComment
;
59 static void RemoveIdxFromSection( SwDoc
&, sal_uLong nSttIdx
, sal_uLong
* pEndIdx
= 0 );
60 static void RemoveIdxFromRange( SwPaM
& rPam
, bool bMoveNext
);
61 static void RemoveIdxRel( sal_uLong
, const SwPosition
& );
63 static bool CanRedlineGroup( SwRedlineSaveDatas
& rCurr
,
64 const SwRedlineSaveDatas
& rCheck
,
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 SAL_OVERRIDE
{ 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 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;
87 virtual void Undo() SAL_OVERRIDE
;
88 virtual void Redo() SAL_OVERRIDE
;
89 virtual void UndoWithContext(SfxUndoContext
&) SAL_OVERRIDE
;
90 virtual void RedoWithContext(SfxUndoContext
&) SAL_OVERRIDE
;
91 virtual void Repeat(SfxRepeatTarget
&) SAL_OVERRIDE
;
92 virtual bool CanRepeat(SfxRepeatTarget
&) const SAL_OVERRIDE
;
95 SwUndo(SwUndoId
const nId
);
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 SAL_OVERRIDE
;
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 bool FillSaveData( const SwPaM
& rRange
, SwRedlineSaveDatas
& rSData
,
118 bool bDelRange
= true, bool bCopyNext
= true );
119 static bool FillSaveDataForFormat( const SwPaM
& , SwRedlineSaveDatas
& );
120 static void SetSaveData( SwDoc
& rDoc
, SwRedlineSaveDatas
& rSData
);
121 static bool HasHiddenRedlines( const SwRedlineSaveDatas
& rSData
);
124 typedef sal_uInt16 DelContentType
;
125 namespace nsDelContentType
127 const DelContentType DELCNT_FTN
= 0x01;
128 const DelContentType DELCNT_FLY
= 0x02;
129 const DelContentType DELCNT_TOC
= 0x04;
130 const DelContentType DELCNT_BKM
= 0x08;
131 const DelContentType DELCNT_ALL
= 0x0F;
132 const DelContentType DELCNT_CHKNOCNTNT
= 0x80;
135 /// will DelContentIndex destroy a frame anchored at character at rAnchorPos?
136 bool IsDestroyFrameAnchoredAtChar(SwPosition
const & rAnchorPos
,
137 SwPosition
const & rStart
, SwPosition
const & rEnd
, const SwDoc
* doc
,
138 DelContentType
const nDelContentType
= nsDelContentType::DELCNT_ALL
);
140 // This class has to be inherited into an Undo-object if it saves content
142 class SwUndoSaveContent
148 // Needed for deletion of content. For Redo content is moved into the
149 // UndoNodesArray. These methods always create a new node to insert
150 // content. So the attributes do not get expanded.
151 // MoveTo: moves from the NodesArray into the UndoNodesArray.
152 // MoveFrom: moves from the UndoNodesArray into the NodesArray.
153 static void MoveToUndoNds( SwPaM
& rPam
,
154 SwNodeIndex
* pNodeIdx
= 0,
155 sal_uLong
* pEndNdIdx
= 0, sal_Int32
* pEndCntIdx
= 0 );
156 static void MoveFromUndoNds( SwDoc
& rDoc
, sal_uLong nNodeIdx
,
158 sal_uLong
* pEndNdIdx
= 0, sal_Int32
* pEndCntIdx
= 0 );
160 // These two methods move the SPoint back/forth from PaM. With it
161 // a range can be spanned for Undo/Redo. (In this case the SPoint
162 // is before the manipulated range!!)
163 // The flag indicates if there is content before the SPoint.
164 static bool MovePtBackward( SwPaM
& rPam
);
165 static void MovePtForward( SwPaM
& rPam
, bool bMvBkwrd
);
167 // Before moving stuff into UndoNodes-Array care has to be taken that
168 // the content-bearing attributes are removed from the nodes-array.
169 void DelContentIndex( const SwPosition
& pMark
, const SwPosition
& pPoint
,
170 DelContentType nDelContentType
= nsDelContentType::DELCNT_ALL
);
174 ~SwUndoSaveContent();
177 // Save a complete section in nodes-array.
178 class SwUndoSaveSection
: private SwUndoSaveContent
181 SwRedlineSaveDatas
* pRedlSaveData
;
182 sal_uLong nMvLen
; // Index into UndoNodes-Array.
186 SwNodeIndex
* GetMvSttIdx() const { return pMvStt
; }
187 sal_uLong
GetMvNodeCnt() const { return nMvLen
; }
191 ~SwUndoSaveSection();
193 void SaveSection( const SwNodeIndex
& rSttIdx
);
194 void SaveSection( const SwNodeRange
& rRange
);
195 void RestoreSection( SwDoc
* pDoc
, SwNodeIndex
* pIdx
, sal_uInt16 nSectType
);
196 void RestoreSection( SwDoc
* pDoc
, const SwNodeIndex
& rInsPos
);
198 const SwHistory
* GetHistory() const { return pHistory
; }
199 SwHistory
* GetHistory() { return pHistory
; }
202 // This class saves the PaM as sal_uInt16's and is able to restore it
207 sal_uLong nSttNode
, nEndNode
;
208 sal_Int32 nSttContent
, nEndContent
;
211 SwUndRng( const SwPaM
& );
213 void SetValues( const SwPaM
& rPam
);
214 void SetPaM( SwPaM
&, bool bCorrToContent
= false ) const;
215 SwPaM
& AddUndoRedoPaM(
216 ::sw::UndoRedoContext
&, bool const bCorrToContent
= false) const;
219 class SwUndoInsLayFormat
;
221 // base class for insertion of Document, Glossaries and Copy
222 class SwUndoInserts
: public SwUndo
, public SwUndRng
, private SwUndoSaveContent
224 SwTextFormatColl
*pTextFormatColl
, *pLastNdColl
;
225 std::vector
<SwFrameFormat
*>* pFrameFormats
;
226 ::std::vector
< ::boost::shared_ptr
<SwUndoInsLayFormat
> > m_FlyUndos
;
227 SwRedlineData
* pRedlData
;
231 /// start of Content in UndoNodes for Redo
232 ::boost::scoped_ptr
<SwNodeIndex
> m_pUndoNodeIndex
;
233 sal_uInt16 nSetPos
; // Start in the history list.
235 SwUndoInserts( SwUndoId nUndoId
, const SwPaM
& );
237 virtual ~SwUndoInserts();
239 virtual void UndoImpl( ::sw::UndoRedoContext
& ) SAL_OVERRIDE
;
240 virtual void RedoImpl( ::sw::UndoRedoContext
& ) SAL_OVERRIDE
;
241 virtual void RepeatImpl( ::sw::RepeatContext
& ) SAL_OVERRIDE
;
243 // Set destination range after reading.
244 void SetInsertRange( const SwPaM
&, bool bScanFlys
= true,
245 bool bSttWasTextNd
= true );
248 class SwUndoInsDoc
: public SwUndoInserts
251 SwUndoInsDoc( const SwPaM
& );
254 class SwUndoCpyDoc
: public SwUndoInserts
257 SwUndoCpyDoc( const SwPaM
& );
260 class SwUndoFlyBase
: public SwUndo
, private SwUndoSaveSection
263 SwFrameFormat
* pFrameFormat
; // The saved FlyFormat.
265 sal_Int32 nCntPos
; // Page at/in paragraph.
267 bool bDelFormat
; // Delete saved format.
269 void InsFly(::sw::UndoRedoContext
& rContext
, bool bShowSel
= true);
270 void DelFly( SwDoc
* );
272 SwUndoFlyBase( SwFrameFormat
* pFormat
, SwUndoId nUndoId
);
274 SwNodeIndex
* GetMvSttIdx() const { return SwUndoSaveSection::GetMvSttIdx(); }
275 sal_uLong
GetMvNodeCnt() const { return SwUndoSaveSection::GetMvNodeCnt(); }
278 virtual ~SwUndoFlyBase();
282 class SwUndoInsLayFormat
: public SwUndoFlyBase
284 sal_uLong mnCrsrSaveIndexPara
; // Cursor position
285 sal_Int32 mnCrsrSaveIndexPos
; // for undo
287 SwUndoInsLayFormat( SwFrameFormat
* pFormat
, sal_uLong nNodeIdx
, sal_Int32 nCntIdx
);
289 virtual ~SwUndoInsLayFormat();
291 virtual void UndoImpl( ::sw::UndoRedoContext
& ) SAL_OVERRIDE
;
292 virtual void RedoImpl( ::sw::UndoRedoContext
& ) SAL_OVERRIDE
;
293 virtual void RepeatImpl( ::sw::RepeatContext
& ) SAL_OVERRIDE
;
295 virtual OUString
GetComment() const SAL_OVERRIDE
;
299 class SwUndoDelLayFormat
: public SwUndoFlyBase
303 SwUndoDelLayFormat( SwFrameFormat
* pFormat
);
305 virtual void UndoImpl( ::sw::UndoRedoContext
& ) SAL_OVERRIDE
;
306 virtual void RedoImpl( ::sw::UndoRedoContext
& ) SAL_OVERRIDE
;
308 void RedoForRollback();
310 void ChgShowSel( bool bNew
) { bShowSelFrm
= bNew
; }
312 virtual SwRewriter
GetRewriter() const SAL_OVERRIDE
;
318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */