Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #ifndef _ROLBCK_HXX
29 : : #define _ROLBCK_HXX
30 : :
31 : : #include <tools/solar.h>
32 : : #include <svl/itemset.hxx>
33 : :
34 : : #include <vector>
35 : : #include <set>
36 : :
37 : : //Nur die History anziehen, um das docnew.cxx gegen die CLOOK's zu behaupten.
38 : :
39 : : namespace sfx2 {
40 : : class MetadatableUndo;
41 : : }
42 : :
43 : : class SwDoc;
44 : : class SwFmtColl;
45 : : class SwHistoryHint;
46 : : class SwTxtAttr;
47 : : class SfxPoolItem;
48 : : class SwUndoSaveSection;
49 : : class SwTxtFtn;
50 : : class SwUndoDelLayFmt;
51 : : class SwFlyFrmFmt;
52 : : class SwFmtFld;
53 : : class SwTxtFld;
54 : : class SwFieldType;
55 : : class SwTxtTOXMark;
56 : : class SwTxtRefMark;
57 : : class SwFrmFmt;
58 : : class SwpHints;
59 : : class SwFmtChain;
60 : : class SwNode;
61 : : class SwCharFmt;
62 : :
63 : : #ifndef ROLBCK_HISTORY_ONLY
64 : :
65 : : #include <tox.hxx>
66 : :
67 : : #include <SwNumberTreeTypes.hxx>
68 : : #include <IDocumentMarkAccess.hxx>
69 : :
70 : : #include <memory>
71 : :
72 : : enum HISTORY_HINT {
73 : : HSTRY_SETFMTHNT,
74 : : HSTRY_RESETFMTHNT,
75 : : HSTRY_SETTXTHNT,
76 : : HSTRY_SETTXTFLDHNT,
77 : : HSTRY_SETREFMARKHNT,
78 : : HSTRY_SETTOXMARKHNT,
79 : : HSTRY_RESETTXTHNT,
80 : : HSTRY_SETFTNHNT,
81 : : HSTRY_CHGFMTCOLL,
82 : : HSTRY_FLYCNT,
83 : : HSTRY_BOOKMARK,
84 : : HSTRY_SETATTRSET,
85 : : HSTRY_RESETATTRSET,
86 : : HSTRY_CHGFLYANCHOR,
87 : : HSTRY_CHGFLYCHAIN,
88 : : HSTRY_CHGCHARFMT,
89 : : HSTRY_END
90 : : };
91 : :
92 : : class SwHistoryHint
93 : : {
94 : : const HISTORY_HINT m_eWhichId;
95 : :
96 : : public:
97 : 9616 : SwHistoryHint( HISTORY_HINT eWhich ) : m_eWhichId( eWhich ) {}
98 [ - + ]: 9602 : virtual ~SwHistoryHint() {}
99 : : virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) = 0;
100 : 0 : HISTORY_HINT Which() const { return m_eWhichId; }
101 : : virtual String GetDescription() const;
102 : : };
103 : :
104 : : class SwHistorySetFmt : public SwHistoryHint
105 : : {
106 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
107 : : ::std::auto_ptr<SfxPoolItem> m_pAttr;
108 : : SAL_WNODEPRECATED_DECLARATIONS_POP
109 : : const sal_uLong m_nNodeIndex;
110 : :
111 : : public:
112 : : SwHistorySetFmt( const SfxPoolItem* pFmtHt, sal_uLong nNode );
113 : : virtual ~SwHistorySetFmt();
114 : : virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
115 : : virtual String GetDescription() const;
116 : :
117 : : };
118 : :
119 [ - + ]: 3544 : class SwHistoryResetFmt : public SwHistoryHint
120 : : {
121 : : const sal_uLong m_nNodeIndex;
122 : : const sal_uInt16 m_nWhich;
123 : :
124 : : public:
125 : : SwHistoryResetFmt( const SfxPoolItem* pFmtHt, sal_uLong nNodeIdx );
126 : : virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
127 : :
128 : : };
129 : :
130 : : class SwHistorySetTxt : public SwHistoryHint
131 : : {
132 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
133 : : ::std::auto_ptr<SfxPoolItem> m_pAttr;
134 : : SAL_WNODEPRECATED_DECLARATIONS_POP
135 : : const sal_uLong m_nNodeIndex;
136 : : const xub_StrLen m_nStart;
137 : : const xub_StrLen m_nEnd;
138 : :
139 : : public:
140 : : SwHistorySetTxt( SwTxtAttr* pTxtHt, sal_uLong nNode );
141 : : virtual ~SwHistorySetTxt();
142 : : virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
143 : :
144 : : };
145 : :
146 : : class SwHistorySetTxtFld : public SwHistoryHint
147 : : {
148 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
149 : : //!! beware of the order for the declation of the auto_ptrs.
150 : : //!! If they get destroyed in the wrong order sw may crash (namely mail-merge as well)
151 : : ::std::auto_ptr<SwFieldType> m_pFldType;
152 : : const ::std::auto_ptr<SwFmtFld> m_pFld;
153 : : SAL_WNODEPRECATED_DECLARATIONS_POP
154 : :
155 : : sal_uLong m_nNodeIndex;
156 : : xub_StrLen m_nPos;
157 : : sal_uInt16 m_nFldWhich;
158 : :
159 : : public:
160 : : SwHistorySetTxtFld( SwTxtFld* pTxtFld, sal_uLong nNode );
161 : : virtual ~SwHistorySetTxtFld();
162 : : virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
163 : :
164 : : virtual String GetDescription() const;
165 : :
166 : : };
167 : :
168 [ + - ][ - + ]: 48 : class SwHistorySetRefMark : public SwHistoryHint
169 : : {
170 : : const String m_RefName;
171 : : const sal_uLong m_nNodeIndex;
172 : : const xub_StrLen m_nStart;
173 : : const xub_StrLen m_nEnd;
174 : :
175 : : public:
176 : : SwHistorySetRefMark( SwTxtRefMark* pTxtHt, sal_uLong nNode );
177 : : virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
178 : :
179 : : };
180 : :
181 [ + - ][ + - ]: 52 : class SwHistorySetTOXMark : public SwHistoryHint
[ - + ]
182 : : {
183 : : SwTOXMark m_TOXMark;
184 : : const String m_TOXName;
185 : : const TOXTypes m_eTOXTypes;
186 : : const sal_uLong m_nNodeIndex;
187 : : const xub_StrLen m_nStart;
188 : : const xub_StrLen m_nEnd;
189 : :
190 : : public:
191 : : SwHistorySetTOXMark( SwTxtTOXMark* pTxtHt, sal_uLong nNode );
192 : : virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
193 : : int IsEqual( const SwTOXMark& rCmp ) const;
194 : :
195 : : };
196 : :
197 [ - + ]: 1320 : class SwHistoryResetTxt : public SwHistoryHint
198 : : {
199 : : const sal_uLong m_nNodeIndex;
200 : : const xub_StrLen m_nStart;
201 : : const xub_StrLen m_nEnd;
202 : : const sal_uInt16 m_nAttr;
203 : :
204 : : public:
205 : : SwHistoryResetTxt( sal_uInt16 nWhich, xub_StrLen nStt, xub_StrLen nEnd,
206 : : sal_uLong nNode );
207 : : virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
208 : :
209 : 0 : sal_uInt16 GetWhich() const { return m_nAttr; }
210 : 0 : sal_uLong GetNode() const { return m_nNodeIndex; }
211 : 0 : xub_StrLen GetCntnt() const { return m_nStart; }
212 : :
213 : : };
214 : :
215 : : class SwHistorySetFootnote : public SwHistoryHint
216 : : {
217 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
218 : : const ::std::auto_ptr<SwUndoSaveSection> m_pUndo;
219 : : SAL_WNODEPRECATED_DECLARATIONS_POP
220 : : const String m_FootnoteNumber;
221 : : sal_uLong m_nNodeIndex;
222 : : const xub_StrLen m_nStart;
223 : : const bool m_bEndNote;
224 : :
225 : : public:
226 : : SwHistorySetFootnote( SwTxtFtn* pTxtFtn, sal_uLong nNode );
227 : : SwHistorySetFootnote( const SwTxtFtn& );
228 : : virtual ~SwHistorySetFootnote();
229 : : virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
230 : :
231 : : virtual String GetDescription() const;
232 : :
233 : : };
234 : :
235 [ - + ]: 116 : class SwHistoryChangeFmtColl : public SwHistoryHint
236 : : {
237 : : SwFmtColl * const m_pColl;
238 : : const sal_uLong m_nNodeIndex;
239 : : const sal_uInt8 m_nNodeType;
240 : :
241 : : public:
242 : : SwHistoryChangeFmtColl( SwFmtColl* pColl, sal_uLong nNode, sal_uInt8 nNodeWhich );
243 : : virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
244 : :
245 : : };
246 : :
247 : : class SwHistoryTxtFlyCnt : public SwHistoryHint
248 : : {
249 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
250 : : ::std::auto_ptr<SwUndoDelLayFmt> m_pUndo;
251 : : SAL_WNODEPRECATED_DECLARATIONS_POP
252 : :
253 : : public:
254 : : SwHistoryTxtFlyCnt( SwFrmFmt* const pFlyFmt );
255 : : virtual ~SwHistoryTxtFlyCnt();
256 : : virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
257 : 0 : SwUndoDelLayFmt* GetUDelLFmt() { return m_pUndo.get(); }
258 : :
259 : : };
260 : :
261 [ + - ][ - + ]: 5292 : class SwHistoryBookmark : public SwHistoryHint
262 : : {
263 : : public:
264 : : SwHistoryBookmark(const ::sw::mark::IMark& rBkmk,
265 : : bool bSavePos, bool bSaveOtherPos);
266 : : virtual void SetInDoc(SwDoc * pDoc, bool);
267 : :
268 : : bool IsEqualBookmark(const ::sw::mark::IMark& rBkmk);
269 : : const ::rtl::OUString& GetName() const;
270 : :
271 : : private:
272 : : const ::rtl::OUString m_aName;
273 : : ::rtl::OUString m_aShortName;
274 : : KeyCode m_aKeycode;
275 : : const sal_uLong m_nNode;
276 : : const sal_uLong m_nOtherNode;
277 : : const xub_StrLen m_nCntnt;
278 : : const xub_StrLen m_nOtherCntnt;
279 : : const bool m_bSavePos;
280 : : const bool m_bSaveOtherPos;
281 : : const bool m_bHadOtherPos;
282 : : const IDocumentMarkAccess::MarkType m_eBkmkType;
283 : : ::boost::shared_ptr< ::sfx2::MetadatableUndo > m_pMetadataUndo;
284 : : };
285 : :
286 [ # # ][ # # ]: 0 : class SwHistorySetAttrSet : public SwHistoryHint
287 : : {
288 : : SfxItemSet m_OldSet;
289 : : std::vector<sal_uInt16> m_ResetArray;
290 : : const sal_uLong m_nNodeIndex;
291 : :
292 : : public:
293 : : SwHistorySetAttrSet( const SfxItemSet& rSet, sal_uLong nNode,
294 : : const std::set<sal_uInt16> &rSetArr );
295 : : virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
296 : :
297 : : };
298 : :
299 [ - + ]: 1576 : class SwHistoryResetAttrSet : public SwHistoryHint
300 : : {
301 : : const sal_uLong m_nNodeIndex;
302 : : const xub_StrLen m_nStart;
303 : : const xub_StrLen m_nEnd;
304 : : std::vector<sal_uInt16> m_Array;
305 : :
306 : : public:
307 : : SwHistoryResetAttrSet( const SfxItemSet& rSet, sal_uLong nNode,
308 : : xub_StrLen nStt = STRING_MAXLEN,
309 : : xub_StrLen nEnd = STRING_MAXLEN );
310 : : virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
311 : :
312 : 0 : const std::vector<sal_uInt16>& GetArr() const { return m_Array; }
313 : 0 : sal_uLong GetNode() const { return m_nNodeIndex; }
314 : 0 : xub_StrLen GetCntnt() const { return m_nStart; }
315 : :
316 : : };
317 : :
318 [ # # ]: 0 : class SwHistoryChangeFlyAnchor : public SwHistoryHint
319 : : {
320 : : SwFrmFmt & m_rFmt;
321 : : const sal_uLong m_nOldNodeIndex;
322 : : const xub_StrLen m_nOldContentIndex;
323 : :
324 : : public:
325 : : SwHistoryChangeFlyAnchor( SwFrmFmt& rFmt );
326 : : virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
327 : : };
328 : :
329 [ # # ]: 0 : class SwHistoryChangeFlyChain : public SwHistoryHint
330 : : {
331 : : SwFlyFrmFmt * const m_pPrevFmt;
332 : : SwFlyFrmFmt * const m_pNextFmt;
333 : : SwFlyFrmFmt * const m_pFlyFmt;
334 : :
335 : : public:
336 : : SwHistoryChangeFlyChain( SwFlyFrmFmt& rFmt, const SwFmtChain& rAttr );
337 : : virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
338 : : };
339 : :
340 [ # # ][ # # ]: 0 : class SwHistoryChangeCharFmt : public SwHistoryHint
[ # # ]
341 : : {
342 : : const SfxItemSet m_OldSet;
343 : : const String m_Fmt;
344 : :
345 : : public:
346 : : SwHistoryChangeCharFmt( const SfxItemSet& rSet, const String & sFmt);
347 : : virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
348 : :
349 : : };
350 : :
351 : : #endif
352 : :
353 : 4774 : class SwpHstry : public std::vector<SwHistoryHint*> {
354 : : public:
355 : : // the destructor will free all objects still in the vector
356 : : ~SwpHstry();
357 : : };
358 : :
359 : : class SwHistory
360 : : {
361 : : friend class SwDoc; // actually only SwDoc::DelUndoObj may access
362 : : friend class SwRegHistory; // for inserting History attributes
363 : :
364 : : SwpHstry m_SwpHstry;
365 : : sal_uInt16 m_nEndDiff;
366 : :
367 : : public:
368 : : SwHistory( sal_uInt16 nInitSz = 0 );
369 : : ~SwHistory();
370 : :
371 : : // delete History from nStart to array end
372 : : void Delete( sal_uInt16 nStart = 0 );
373 : : // call and delete all objects between nStart and array end
374 : : bool Rollback( SwDoc* pDoc, sal_uInt16 nStart = 0 );
375 : : // call all objects between nStart and TmpEnd; store nStart as TmpEnd
376 : : bool TmpRollback( SwDoc* pDoc, sal_uInt16 nStart, bool ToFirst = true );
377 : :
378 : : void Add( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue,
379 : : sal_uLong nNodeIdx );
380 : : void Add( SwTxtAttr* pTxtHt, sal_uLong nNodeIdx, bool bNewAttr = true );
381 : : void Add( SwFmtColl*, sal_uLong nNodeIdx, sal_uInt8 nWhichNd );
382 : : void Add( const ::sw::mark::IMark&, bool bSavePos, bool bSaveOtherPos );
383 : : void Add( SwFrmFmt& rFmt );
384 : : void Add( SwFlyFrmFmt&, sal_uInt16& rSetPos );
385 : : void Add( const SwTxtFtn& );
386 : : void Add( const SfxItemSet & rSet, const SwCharFmt & rCharFmt);
387 : :
388 : 9169 : sal_uInt16 Count() const { return m_SwpHstry.size(); }
389 : 0 : sal_uInt16 GetTmpEnd() const { return m_SwpHstry.size() - m_nEndDiff; }
390 : : sal_uInt16 SetTmpEnd( sal_uInt16 nTmpEnd ); // return previous value
391 : 792 : SwHistoryHint * operator[]( sal_uInt16 nPos ) { return m_SwpHstry[nPos]; }
392 : : SwHistoryHint const* operator[]( sal_uInt16 nPos ) const
393 : : { return m_SwpHstry[nPos]; }
394 : :
395 : : // for SwUndoDelete::Undo/Redo
396 : 0 : void Move( sal_uInt16 nPos, SwHistory *pIns,
397 : : sal_uInt16 const nStart = 0)
398 : : {
399 [ # # ]: 0 : SwpHstry::iterator itSourceBegin = pIns->m_SwpHstry.begin() + nStart;
400 : 0 : SwpHstry::iterator itSourceEnd = pIns->m_SwpHstry.end();
401 [ # # ][ # # ]: 0 : if (itSourceBegin == itSourceEnd) return;
402 [ # # ][ # # ]: 0 : m_SwpHstry.insert(m_SwpHstry.begin() + nPos, itSourceBegin, itSourceEnd);
403 [ # # ]: 0 : pIns->m_SwpHstry.erase( itSourceBegin, itSourceEnd );
404 : : }
405 : :
406 : : // helper methods for recording attribute in History
407 : : // used by Undo classes (Delete/Overwrite/Inserts)
408 : : void CopyAttr( SwpHints* pHts, sal_uLong nNodeIdx, xub_StrLen nStart,
409 : : xub_StrLen nEnd, bool bFields );
410 : : void CopyFmtAttr( const SfxItemSet& rSet, sal_uLong nNodeIdx );
411 : : };
412 : :
413 : : #ifndef ROLBCK_HISTORY_ONLY
414 : :
415 [ - + ]: 22570 : class SwRegHistory : public SwClient
416 : : {
417 : : private:
418 : : std::set<sal_uInt16> m_WhichIdSet;
419 : : SwHistory * const m_pHistory;
420 : : sal_uLong m_nNodeIndex;
421 : :
422 : : void _MakeSetWhichIds();
423 : :
424 : : protected:
425 : : virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew );
426 : :
427 : : public:
428 : : SwRegHistory( SwHistory* pHst );
429 : : SwRegHistory( const SwNode& rNd, SwHistory* pHst );
430 : : SwRegHistory( SwModify* pRegIn, const SwNode& rNd, SwHistory* pHst );
431 : :
432 : : /// @return true if at least 1 item was inserted
433 : : bool InsertItems( const SfxItemSet& rSet,
434 : : xub_StrLen const nStart, xub_StrLen const nEnd,
435 : : SetAttrMode const nFlags );
436 : :
437 : : void AddHint( SwTxtAttr* pHt, const bool bNew = false );
438 : :
439 : : void RegisterInModify( SwModify* pRegIn, const SwNode& rNd );
440 : 34 : void ChangeNodeIndex( sal_uLong nNew ) { m_nNodeIndex = nNew; }
441 : : };
442 : :
443 : : #endif
444 : :
445 : : #endif // _ROLBCK_HXX
446 : :
447 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|