merged tag ooo/OOO330_m14
[LibreOffice.git] / sw / inc / rolbck.hxx
blobe2aa129f65e1bb6e9e98669fb69a96f6dfe84917
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
27 #ifndef _ROLBCK_HXX
28 #define _ROLBCK_HXX
30 #include <tools/solar.h>
31 #ifndef _SVSTDARR_HXX
32 #define _SVSTDARR_USHORTS
33 #define _SVSTDARR_USHORTSSORT
34 #include <svl/svstdarr.hxx>
35 #endif
36 #include <svl/itemset.hxx>
38 //Nur die History anziehen, um das docnew.cxx gegen die CLOOK's zu behaupten.
40 namespace sfx2 {
41 class MetadatableUndo;
44 class SwDoc;
45 class SwFmt;
46 class SwFmtColl;
47 class SwHistoryHint;
48 class SwTxtAttr;
49 class SfxPoolItem;
50 class SwTxtNode;
51 class SwUndoSaveSection;
52 class SwTxtFtn;
53 class SwTxtFlyCnt;
54 class SwUndoDelLayFmt;
55 class SwFlyFrmFmt;
56 class SwFmtFld;
57 class SwTxtFld;
58 class SwFieldType;
59 class SwTxtTOXMark;
60 class SwTxtRefMark;
61 class SwFrmFmt;
62 class SwpHints;
63 class SwFmtChain;
64 class SwNode;
65 class SwCharFmt;
67 #ifndef ROLBCK_HISTORY_ONLY
69 #include <tox.hxx>
71 #include <SwNumberTreeTypes.hxx>
72 // --> OD 2007-10-17 #i81002#
73 #include <IDocumentMarkAccess.hxx>
74 // <--
76 #include <memory>
79 enum HISTORY_HINT {
80 HSTRY_SETFMTHNT,
81 HSTRY_RESETFMTHNT,
82 HSTRY_SETTXTHNT,
83 HSTRY_SETTXTFLDHNT,
84 HSTRY_SETREFMARKHNT,
85 HSTRY_SETTOXMARKHNT,
86 HSTRY_RESETTXTHNT,
87 HSTRY_SETFTNHNT,
88 HSTRY_CHGFMTCOLL,
89 HSTRY_FLYCNT,
90 HSTRY_BOOKMARK,
91 HSTRY_SETATTRSET,
92 HSTRY_RESETATTRSET,
93 HSTRY_CHGFLYANCHOR,
94 HSTRY_CHGFLYCHAIN,
95 HSTRY_CHGCHARFMT, // #i27615#
96 HSTRY_END
99 class SwHistoryHint
101 const HISTORY_HINT m_eWhichId;
103 public:
104 SwHistoryHint( HISTORY_HINT eWhich ) : m_eWhichId( eWhich ) {}
105 virtual ~SwHistoryHint() {}
106 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) = 0;
107 HISTORY_HINT Which() const { return m_eWhichId; }
108 virtual String GetDescription() const;
111 class SwHistorySetFmt : public SwHistoryHint
113 ::std::auto_ptr<SfxPoolItem> m_pAttr;
114 const ULONG m_nNodeIndex;
116 public:
117 SwHistorySetFmt( const SfxPoolItem* pFmtHt, ULONG nNode );
118 virtual ~SwHistorySetFmt();
119 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
120 virtual String GetDescription() const;
124 class SwHistoryResetFmt : public SwHistoryHint
126 const ULONG m_nNodeIndex;
127 const USHORT m_nWhich;
129 public:
130 // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
131 SwHistoryResetFmt( const SfxPoolItem* pFmtHt, ULONG nNodeIdx );
132 // <--
133 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
137 class SwHistorySetTxt : public SwHistoryHint
139 ::std::auto_ptr<SfxPoolItem> m_pAttr;
140 const ULONG m_nNodeIndex;
141 const xub_StrLen m_nStart;
142 const xub_StrLen m_nEnd;
144 public:
145 SwHistorySetTxt( SwTxtAttr* pTxtHt, ULONG nNode );
146 virtual ~SwHistorySetTxt();
147 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
151 class SwHistorySetTxtFld : public SwHistoryHint
153 //!! beware of the order for the declation of the auto_ptrs.
154 //!! If they get destroyed in the wrong order sw may crash (namely mail-merge as well)
155 ::std::auto_ptr<SwFieldType> m_pFldType;
156 const ::std::auto_ptr<SwFmtFld> m_pFld;
158 ULONG m_nNodeIndex;
159 xub_StrLen m_nPos;
160 USHORT m_nFldWhich;
162 public:
163 SwHistorySetTxtFld( SwTxtFld* pTxtFld, ULONG nNode );
164 virtual ~SwHistorySetTxtFld();
165 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
167 virtual String GetDescription() const;
171 class SwHistorySetRefMark : public SwHistoryHint
173 const String m_RefName;
174 const ULONG m_nNodeIndex;
175 const xub_StrLen m_nStart;
176 const xub_StrLen m_nEnd;
178 public:
179 SwHistorySetRefMark( SwTxtRefMark* pTxtHt, ULONG nNode );
180 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
184 class SwHistorySetTOXMark : public SwHistoryHint
186 SwTOXMark m_TOXMark;
187 const String m_TOXName;
188 const TOXTypes m_eTOXTypes;
189 const ULONG m_nNodeIndex;
190 const xub_StrLen m_nStart;
191 const xub_StrLen m_nEnd;
193 public:
194 SwHistorySetTOXMark( SwTxtTOXMark* pTxtHt, ULONG nNode );
195 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
196 int IsEqual( const SwTOXMark& rCmp ) const;
200 class SwHistoryResetTxt : public SwHistoryHint
202 const ULONG m_nNodeIndex;
203 const xub_StrLen m_nStart;
204 const xub_StrLen m_nEnd;
205 const USHORT m_nAttr;
207 public:
208 SwHistoryResetTxt( USHORT nWhich, xub_StrLen nStt, xub_StrLen nEnd,
209 ULONG nNode );
210 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
212 USHORT GetWhich() const { return m_nAttr; }
213 ULONG GetNode() const { return m_nNodeIndex; }
214 xub_StrLen GetCntnt() const { return m_nStart; }
218 class SwHistorySetFootnote : public SwHistoryHint
220 const ::std::auto_ptr<SwUndoSaveSection> m_pUndo;
221 const String m_FootnoteNumber;
222 ULONG m_nNodeIndex;
223 const xub_StrLen m_nStart;
224 const bool m_bEndNote;
226 public:
227 SwHistorySetFootnote( SwTxtFtn* pTxtFtn, ULONG nNode );
228 SwHistorySetFootnote( const SwTxtFtn& );
229 virtual ~SwHistorySetFootnote();
230 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
232 virtual String GetDescription() const;
236 class SwHistoryChangeFmtColl : public SwHistoryHint
238 SwFmtColl * const m_pColl;
239 const ULONG m_nNodeIndex;
240 const BYTE m_nNodeType;
242 public:
243 SwHistoryChangeFmtColl( SwFmtColl* pColl, ULONG nNode, BYTE nNodeWhich );
244 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
248 class SwHistoryTxtFlyCnt : public SwHistoryHint
250 ::std::auto_ptr<SwUndoDelLayFmt> m_pUndo;
252 public:
253 SwHistoryTxtFlyCnt( SwFrmFmt* const pFlyFmt );
254 virtual ~SwHistoryTxtFlyCnt();
255 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
256 SwUndoDelLayFmt* GetUDelLFmt() { return m_pUndo.get(); }
260 class SwHistoryBookmark : public SwHistoryHint
262 public:
263 SwHistoryBookmark(const ::sw::mark::IMark& rBkmk,
264 bool bSavePos, bool bSaveOtherPos);
265 virtual void SetInDoc(SwDoc * pDoc, bool);
267 bool IsEqualBookmark(const ::sw::mark::IMark& rBkmk);
268 const ::rtl::OUString& GetName() const;
271 private:
272 const ::rtl::OUString m_aName;
273 ::rtl::OUString m_aShortName;
274 KeyCode m_aKeycode;
275 const ULONG m_nNode;
276 const 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;
286 class SwHistorySetAttrSet : public SwHistoryHint
288 SfxItemSet m_OldSet;
289 SvUShorts m_ResetArray;
290 const ULONG m_nNodeIndex;
292 public:
293 SwHistorySetAttrSet( const SfxItemSet& rSet, ULONG nNode,
294 const SvUShortsSort& rSetArr );
295 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
300 class SwHistoryResetAttrSet : public SwHistoryHint
302 const ULONG m_nNodeIndex;
303 const xub_StrLen m_nStart;
304 const xub_StrLen m_nEnd;
305 SvUShorts m_Array;
307 public:
308 SwHistoryResetAttrSet( const SfxItemSet& rSet, ULONG nNode,
309 xub_StrLen nStt = STRING_MAXLEN,
310 xub_StrLen nEnd = STRING_MAXLEN );
311 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
313 const SvUShorts& GetArr() const { return m_Array; }
314 ULONG GetNode() const { return m_nNodeIndex; }
315 xub_StrLen GetCntnt() const { return m_nStart; }
319 class SwHistoryChangeFlyAnchor : public SwHistoryHint
321 SwFrmFmt & m_rFmt;
322 const ULONG m_nOldNodeIndex;
323 const xub_StrLen m_nOldContentIndex;
325 public:
326 SwHistoryChangeFlyAnchor( SwFrmFmt& rFmt );
327 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
330 class SwHistoryChangeFlyChain : public SwHistoryHint
332 SwFlyFrmFmt * const m_pPrevFmt;
333 SwFlyFrmFmt * const m_pNextFmt;
334 SwFlyFrmFmt * const m_pFlyFmt;
336 public:
337 SwHistoryChangeFlyChain( SwFlyFrmFmt& rFmt, const SwFmtChain& rAttr );
338 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
341 // #i27615#
342 class SwHistoryChangeCharFmt : public SwHistoryHint
344 const SfxItemSet m_OldSet;
345 const String m_Fmt;
347 public:
348 SwHistoryChangeCharFmt( const SfxItemSet& rSet, const String & sFmt);
349 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
354 #endif
356 typedef SwHistoryHint* SwHistoryHintPtr;
357 SV_DECL_PTRARR_DEL( SwpHstry, SwHistoryHintPtr, 0, 2 )
359 class SwHistory
361 friend class SwDoc; // actually only SwDoc::DelUndoObj may access
362 friend class SwUndoWriter; // for Undo/Redo Writer
363 friend class SwRegHistory; // for inserting History attributes
365 SwpHstry m_SwpHstry;
366 USHORT m_nEndDiff;
368 public:
369 SwHistory( USHORT nInitSz = 0, USHORT nGrowSz = 2 );
370 ~SwHistory();
372 // delete History from nStart to array end
373 void Delete( USHORT nStart = 0 );
374 // call and delete all objects between nStart and array end
375 bool Rollback( SwDoc* pDoc, USHORT nStart = 0 );
376 // call all objects between nStart and TmpEnd; store nStart as TmpEnd
377 bool TmpRollback( SwDoc* pDoc, USHORT nStart, bool ToFirst = true );
379 // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
380 void Add( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue,
381 ULONG nNodeIdx );
382 // <--
383 void Add( SwTxtAttr* pTxtHt, ULONG nNodeIdx, bool bNewAttr = true );
384 void Add( SwFmtColl*, ULONG nNodeIdx, BYTE nWhichNd );
385 void Add( const ::sw::mark::IMark&, bool bSavePos, bool bSaveOtherPos );
386 void Add( SwFrmFmt& rFmt );
387 void Add( SwFlyFrmFmt&, USHORT& rSetPos );
388 void Add( const SwTxtFtn& );
389 void Add( const SfxItemSet & rSet, const SwCharFmt & rCharFmt); // #i27615#
391 USHORT Count() const { return m_SwpHstry.Count(); }
392 USHORT GetTmpEnd() const { return m_SwpHstry.Count() - m_nEndDiff; }
393 USHORT SetTmpEnd( USHORT nTmpEnd ); // return previous value
394 SwHistoryHint * operator[]( USHORT nPos ) { return m_SwpHstry[nPos]; }
395 SwHistoryHint const* operator[]( USHORT nPos ) const
396 { return m_SwpHstry[nPos]; }
398 // for SwUndoDelete::Undo/Redo
399 void Move( USHORT nPos, SwHistory *pIns,
400 USHORT nStart = 0, USHORT nEnd = USHRT_MAX )
402 m_SwpHstry.Insert( &pIns->m_SwpHstry, nPos, nStart, nEnd );
403 pIns->m_SwpHstry.Remove( nStart, (nEnd == USHRT_MAX)
404 ? pIns->Count() - nStart
405 : nEnd );
408 // helper methods for recording attribute in History
409 // used by Undo classes (Delete/Overwrite/Inserts)
410 void CopyAttr( SwpHints* pHts, ULONG nNodeIdx, xub_StrLen nStart,
411 xub_StrLen nEnd, bool bFields );
412 // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
413 void CopyFmtAttr( const SfxItemSet& rSet, ULONG nNodeIdx );
414 // <--
417 #ifndef ROLBCK_HISTORY_ONLY
419 class SwRegHistory : public SwClient
421 private:
422 SvUShortsSort m_WhichIdSet;
423 SwHistory * const m_pHistory;
424 ULONG m_nNodeIndex;
426 void _MakeSetWhichIds();
428 public:
429 // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
430 SwRegHistory( SwHistory* pHst );
431 // <--
432 SwRegHistory( const SwNode& rNd, SwHistory* pHst );
433 SwRegHistory( SwModify* pRegIn, const SwNode& rNd, SwHistory* pHst );
435 virtual void Modify( SfxPoolItem* pOld, SfxPoolItem* pNew );
437 /// @return true iff at least 1 item was inserted
438 bool InsertItems( const SfxItemSet& rSet,
439 xub_StrLen const nStart, xub_StrLen const nEnd,
440 SetAttrMode const nFlags );
442 void AddHint( SwTxtAttr* pHt, const bool bNew = false );
444 void RegisterInModify( SwModify* pRegIn, const SwNode& rNd );
445 void ChangeNodeIndex( ULONG nNew ) { m_nNodeIndex = nNew; }
448 #endif
451 #endif // _ROLBCK_HXX