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 : #ifndef SW_UNDOBJ_HXX
20 : #define SW_UNDOBJ_HXX
21 :
22 : #include <vector>
23 :
24 : #include <boost/shared_ptr.hpp>
25 :
26 : #include <svl/undo.hxx>
27 :
28 : #include <SwRewriter.hxx>
29 : #include <swundo.hxx>
30 :
31 : class SwHistory;
32 : class SwIndex;
33 : class SwPaM;
34 : struct SwPosition;
35 : class SwDoc;
36 : class SwTxtFmtColl;
37 : class SwFrmFmt;
38 : class SwNodeIndex;
39 : class SwNodeRange;
40 : class SwRedlineData;
41 : class SwRedlineSaveDatas;
42 :
43 : namespace sw {
44 : class UndoRedoContext;
45 : class RepeatContext;
46 : }
47 :
48 : class SwUndo
49 : : public SfxUndoAction
50 : {
51 : SwUndoId const m_nId;
52 : sal_uInt16 nOrigRedlineMode;
53 :
54 : protected:
55 : bool bCacheComment;
56 : mutable String * pComment;
57 :
58 : void RemoveIdxFromSection( SwDoc&, sal_uLong nSttIdx, sal_uLong* pEndIdx = 0 );
59 : void RemoveIdxFromRange( SwPaM& rPam, sal_Bool bMoveNext );
60 : void RemoveIdxRel( sal_uLong, const SwPosition& );
61 :
62 : static sal_Bool CanRedlineGroup( SwRedlineSaveDatas& rCurr,
63 : const SwRedlineSaveDatas& rCheck,
64 : sal_Bool bCurrIsEnd );
65 :
66 : /**
67 : Returns the rewriter for this object.
68 :
69 : @return the rewriter for this object
70 : */
71 : virtual SwRewriter GetRewriter() const;
72 :
73 : // return type is sal_uInt16 because this overrides SfxUndoAction::GetId()
74 21 : virtual sal_uInt16 GetId() const { return static_cast<sal_uInt16>(m_nId); }
75 :
76 : // the 4 methods that derived classes have to override
77 : // base implementation does nothing
78 : virtual void RepeatImpl( ::sw::RepeatContext & );
79 : virtual bool CanRepeatImpl( ::sw::RepeatContext & ) const;
80 : public: // should not be public, but ran into trouble in untbl.cxx
81 : virtual void UndoImpl( ::sw::UndoRedoContext & ) = 0;
82 : virtual void RedoImpl( ::sw::UndoRedoContext & ) = 0;
83 :
84 : private:
85 : // SfxUndoAction
86 : virtual void Undo();
87 : virtual void Redo();
88 : virtual void UndoWithContext(SfxUndoContext &);
89 : virtual void RedoWithContext(SfxUndoContext &);
90 : virtual void Repeat(SfxRepeatTarget &);
91 : virtual sal_Bool CanRepeat(SfxRepeatTarget &) const;
92 :
93 : public:
94 : SwUndo(SwUndoId const nId);
95 : virtual ~SwUndo();
96 :
97 : /**
98 : Returns textual comment for this undo object.
99 :
100 : The textual comment is created from the resource string
101 : corresponding to this object's ID. The rewriter of this object
102 : is applied to the resource string to get the final comment.
103 :
104 : @return textual comment for this undo object
105 : */
106 : virtual rtl::OUString GetComment() const;
107 :
108 : // UndoObject remembers which mode was turned on.
109 : // In Undo/Redo/Repeat this remembered mode is switched on.
110 21 : sal_uInt16 GetRedlineMode() const { return nOrigRedlineMode; }
111 21 : void SetRedlineMode( sal_uInt16 eMode ) { nOrigRedlineMode = eMode; }
112 :
113 : bool IsDelBox() const;
114 :
115 : // Save and set Redline data.
116 : static sal_Bool FillSaveData( const SwPaM& rRange, SwRedlineSaveDatas& rSData,
117 : sal_Bool bDelRange = sal_True, sal_Bool bCopyNext = sal_True );
118 : static sal_Bool FillSaveDataForFmt( const SwPaM& , SwRedlineSaveDatas& );
119 : static void SetSaveData( SwDoc& rDoc, const SwRedlineSaveDatas& rSData );
120 : static sal_Bool HasHiddenRedlines( const SwRedlineSaveDatas& rSData );
121 : };
122 :
123 : typedef sal_uInt16 DelCntntType;
124 : namespace nsDelCntntType
125 : {
126 : const DelCntntType DELCNT_FTN = 0x01;
127 : const DelCntntType DELCNT_FLY = 0x02;
128 : const DelCntntType DELCNT_TOC = 0x04;
129 : const DelCntntType DELCNT_BKM = 0x08;
130 : const DelCntntType DELCNT_ALL = 0x0F;
131 : const DelCntntType DELCNT_CHKNOCNTNT = 0x80;
132 : }
133 :
134 : /// will DelCntntIndex destroy a frame anchored at character at rAnchorPos?
135 : bool IsDestroyFrameAnchoredAtChar(SwPosition const & rAnchorPos,
136 : SwPosition const & rStart, SwPosition const & rEnd,
137 : DelCntntType const nDelCntntType = nsDelCntntType::DELCNT_ALL);
138 :
139 :
140 : // This class has to be inherited into an Undo-object if it saves content
141 : // for Redo/Undo...
142 : class SwUndoSaveCntnt
143 : {
144 : protected:
145 :
146 : SwHistory* pHistory;
147 :
148 : // Needed for deletion of content. For Redo content is moved into the
149 : // UndoNodesArray. These methods insert a separator for the attributes
150 : // at the end of a TextNode. 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 : void MoveToUndoNds( SwPaM& rPam,
154 : SwNodeIndex* pNodeIdx = 0, SwIndex* pCntIdx = 0,
155 : sal_uLong* pEndNdIdx = 0, xub_StrLen * pEndCntIdx = 0 );
156 : void MoveFromUndoNds( SwDoc& rDoc, sal_uLong nNodeIdx, xub_StrLen nCntntIdx,
157 : SwPosition& rInsPos,
158 : sal_uLong* pEndNdIdx = 0, xub_StrLen * pEndCntIdx = 0 );
159 :
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 : sal_Bool MovePtBackward( SwPaM& rPam );
165 : void MovePtForward( SwPaM& rPam, sal_Bool bMvBkwrd );
166 :
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 DelCntntIndex( const SwPosition& pMark, const SwPosition& pPoint,
170 : DelCntntType nDelCntntType = nsDelCntntType::DELCNT_ALL );
171 :
172 : public:
173 : SwUndoSaveCntnt();
174 : ~SwUndoSaveCntnt();
175 : };
176 :
177 : // Save a complete section in nodes-array.
178 : class SwUndoSaveSection : private SwUndoSaveCntnt
179 : {
180 : SwNodeIndex *pMvStt;
181 : SwRedlineSaveDatas* pRedlSaveData;
182 : sal_uLong nMvLen; // Index into UndoNodes-Array.
183 : sal_uLong nStartPos;
184 :
185 : protected:
186 0 : SwNodeIndex* GetMvSttIdx() const { return pMvStt; }
187 0 : sal_uLong GetMvNodeCnt() const { return nMvLen; }
188 :
189 : public:
190 : SwUndoSaveSection();
191 : ~SwUndoSaveSection();
192 :
193 : void SaveSection( SwDoc* pDoc, const SwNodeIndex& rSttIdx );
194 : void SaveSection( SwDoc* pDoc, const SwNodeRange& rRange );
195 : void RestoreSection( SwDoc* pDoc, SwNodeIndex* pIdx, sal_uInt16 nSectType );
196 : void RestoreSection( SwDoc* pDoc, const SwNodeIndex& rInsPos );
197 :
198 : const SwHistory* GetHistory() const { return pHistory; }
199 0 : SwHistory* GetHistory() { return pHistory; }
200 : };
201 :
202 :
203 : // This class saves the PaM as sal_uInt16's and is able to restore it
204 : // into a PaM.
205 : class SwUndRng
206 : {
207 : public:
208 : sal_uLong nSttNode, nEndNode;
209 : xub_StrLen nSttCntnt, nEndCntnt;
210 :
211 : SwUndRng();
212 : SwUndRng( const SwPaM& );
213 :
214 : void SetValues( const SwPaM& rPam );
215 : void SetPaM( SwPaM&, sal_Bool bCorrToCntnt = sal_False ) const;
216 : SwPaM & AddUndoRedoPaM(
217 : ::sw::UndoRedoContext &, bool const bCorrToCntnt = false) const;
218 : };
219 :
220 :
221 : class SwUndoInsLayFmt;
222 :
223 : // base class for insertion of Document, Glossaries and Copy
224 : class SwUndoInserts : public SwUndo, public SwUndRng, private SwUndoSaveCntnt
225 : {
226 : SwTxtFmtColl *pTxtFmtColl, *pLastNdColl;
227 : std::vector<SwFrmFmt*>* pFrmFmts;
228 : ::std::vector< ::boost::shared_ptr<SwUndoInsLayFmt> > m_FlyUndos;
229 : SwRedlineData* pRedlData;
230 : sal_Bool bSttWasTxtNd;
231 : protected:
232 : sal_uLong nNdDiff;
233 : SwPosition *pPos; // Content for Redo.
234 : sal_uInt16 nSetPos; // Start in the history list.
235 :
236 : SwUndoInserts( SwUndoId nUndoId, const SwPaM& );
237 : public:
238 : virtual ~SwUndoInserts();
239 :
240 : virtual void UndoImpl( ::sw::UndoRedoContext & );
241 : virtual void RedoImpl( ::sw::UndoRedoContext & );
242 : virtual void RepeatImpl( ::sw::RepeatContext & );
243 :
244 : // Set destination range after reading.
245 : void SetInsertRange( const SwPaM&, sal_Bool bScanFlys = sal_True,
246 : sal_Bool bSttWasTxtNd = sal_True );
247 : };
248 :
249 0 : class SwUndoInsDoc : public SwUndoInserts
250 : {
251 : public:
252 : SwUndoInsDoc( const SwPaM& );
253 : };
254 :
255 0 : class SwUndoCpyDoc : public SwUndoInserts
256 : {
257 : public:
258 : SwUndoCpyDoc( const SwPaM& );
259 : };
260 :
261 : //--------------------------------------------------------------------
262 :
263 : class SwUndoFlyBase : public SwUndo, private SwUndoSaveSection
264 : {
265 : protected:
266 : SwFrmFmt* pFrmFmt; // The saved FlyFormat.
267 : sal_uLong nNdPgPos;
268 : xub_StrLen nCntPos; // Page at/in paragraph.
269 : sal_uInt16 nRndId;
270 : sal_Bool bDelFmt; // Delete saved format.
271 :
272 : void InsFly(::sw::UndoRedoContext & rContext, bool bShowSel = true);
273 : void DelFly( SwDoc* );
274 :
275 : SwUndoFlyBase( SwFrmFmt* pFormat, SwUndoId nUndoId );
276 :
277 0 : SwNodeIndex* GetMvSttIdx() const { return SwUndoSaveSection::GetMvSttIdx(); }
278 0 : sal_uLong GetMvNodeCnt() const { return SwUndoSaveSection::GetMvNodeCnt(); }
279 :
280 : public:
281 : virtual ~SwUndoFlyBase();
282 :
283 : };
284 :
285 : class SwUndoInsLayFmt : public SwUndoFlyBase
286 : {
287 : sal_uLong mnCrsrSaveIndexPara; // Cursor position
288 : xub_StrLen mnCrsrSaveIndexPos; // for undo
289 : public:
290 : SwUndoInsLayFmt( SwFrmFmt* pFormat, sal_uLong nNodeIdx, xub_StrLen nCntIdx );
291 :
292 : virtual ~SwUndoInsLayFmt();
293 :
294 : virtual void UndoImpl( ::sw::UndoRedoContext & );
295 : virtual void RedoImpl( ::sw::UndoRedoContext & );
296 : virtual void RepeatImpl( ::sw::RepeatContext & );
297 :
298 : virtual rtl::OUString GetComment() const;
299 :
300 : };
301 :
302 0 : class SwUndoDelLayFmt : public SwUndoFlyBase
303 : {
304 : sal_Bool bShowSelFrm;
305 : public:
306 : SwUndoDelLayFmt( SwFrmFmt* pFormat );
307 :
308 : virtual void UndoImpl( ::sw::UndoRedoContext & );
309 : virtual void RedoImpl( ::sw::UndoRedoContext & );
310 :
311 : void RedoForRollback();
312 :
313 0 : void ChgShowSel( sal_Bool bNew ) { bShowSelFrm = bNew; }
314 :
315 : virtual SwRewriter GetRewriter() const;
316 :
317 : };
318 :
319 : #endif
320 :
321 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|