update dev300-m57
[ooovba.git] / sw / inc / rolbck.hxx
blobbd97b81f1b6ba4624c29a3ad8daa8bbc4218c362
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rolbck.hxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _ROLBCK_HXX
31 #define _ROLBCK_HXX
33 #include <tools/solar.h>
34 #ifndef _SVSTDARR_HXX
35 #define _SVSTDARR_USHORTS
36 #define _SVSTDARR_USHORTSSORT
37 #include <svtools/svstdarr.hxx>
38 #endif
39 #include <svtools/itemset.hxx>
41 //Nur die History anziehen, um das docnew.cxx gegen die CLOOK's zu behaupten.
43 class SwDoc;
44 class SwFmt;
45 class SwFmtColl;
46 class SwHistoryHint;
47 class SwTxtAttr;
48 class SfxPoolItem;
49 class SwTxtNode;
50 class SwUndoSaveSection;
51 class SwTxtFtn;
52 class SwTxtFlyCnt;
53 class SwUndoDelLayFmt;
54 class SwFlyFrmFmt;
55 class SwFmtFld;
56 class SwTxtFld;
57 class SwFieldType;
58 class SwTxtTOXMark;
59 class SwTxtRefMark;
60 class SwFrmFmt;
61 class SwpHints;
62 class SwFmtChain;
63 class SwNode;
64 class SwCharFmt;
66 #ifndef ROLBCK_HISTORY_ONLY
68 #include <tox.hxx>
70 #include <SwNumberTreeTypes.hxx>
71 // --> OD 2007-10-17 #i81002#
72 #include <IDocumentMarkAccess.hxx>
73 // <--
75 #include <memory>
78 #ifndef PRODUCT
79 class Writer;
80 #define OUT_HSTR_HINT( name ) \
81 friend Writer& OutUndo_Hstr_ ## name( Writer&, const SwHistoryHint& );
82 #else
83 #define OUT_HSTR_HINT( name )
84 #endif
86 enum HISTORY_HINT {
87 HSTRY_SETFMTHNT,
88 HSTRY_RESETFMTHNT,
89 HSTRY_SETTXTHNT,
90 HSTRY_SETTXTFLDHNT,
91 HSTRY_SETREFMARKHNT,
92 HSTRY_SETTOXMARKHNT,
93 HSTRY_RESETTXTHNT,
94 HSTRY_SETFTNHNT,
95 HSTRY_CHGFMTCOLL,
96 HSTRY_FLYCNT,
97 HSTRY_BOOKMARK,
98 HSTRY_SETATTRSET,
99 HSTRY_RESETATTRSET,
100 HSTRY_CHGFLYANCHOR,
101 HSTRY_CHGFLYCHAIN,
102 HSTRY_CHGCHARFMT, // #i27615#
103 HSTRY_END
106 class SwHistoryHint
108 const HISTORY_HINT m_eWhichId;
110 public:
111 SwHistoryHint( HISTORY_HINT eWhich ) : m_eWhichId( eWhich ) {}
112 virtual ~SwHistoryHint() {}
113 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) = 0;
114 HISTORY_HINT Which() const { return m_eWhichId; }
115 virtual String GetDescription() const;
118 class SwHistorySetFmt : public SwHistoryHint
120 ::std::auto_ptr<SfxPoolItem> m_pAttr;
121 const ULONG m_nNodeIndex;
123 public:
124 SwHistorySetFmt( const SfxPoolItem* pFmtHt, ULONG nNode );
125 virtual ~SwHistorySetFmt();
126 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
127 virtual String GetDescription() const;
129 OUT_HSTR_HINT(SetFmtHnt)
132 class SwHistoryResetFmt : public SwHistoryHint
134 const ULONG m_nNodeIndex;
135 const USHORT m_nWhich;
137 public:
138 // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
139 SwHistoryResetFmt( const SfxPoolItem* pFmtHt, ULONG nNodeIdx );
140 // <--
141 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
143 OUT_HSTR_HINT(ResetFmtHnt)
146 class SwHistorySetTxt : public SwHistoryHint
148 ::std::auto_ptr<SfxPoolItem> m_pAttr;
149 const ULONG m_nNodeIndex;
150 const xub_StrLen m_nStart;
151 const xub_StrLen m_nEnd;
153 public:
154 SwHistorySetTxt( SwTxtAttr* pTxtHt, ULONG nNode );
155 virtual ~SwHistorySetTxt();
156 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
158 OUT_HSTR_HINT(SetTxtHnt)
161 class SwHistorySetTxtFld : public SwHistoryHint
163 ::std::auto_ptr<SwFieldType> m_pFldType;
164 const ::std::auto_ptr<SwFmtFld> m_pFld;
165 ULONG m_nNodeIndex;
166 xub_StrLen m_nPos;
167 USHORT m_nFldWhich;
169 public:
170 SwHistorySetTxtFld( SwTxtFld* pTxtFld, ULONG nNode );
171 virtual ~SwHistorySetTxtFld();
172 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
174 virtual String GetDescription() const;
176 OUT_HSTR_HINT(SetTxtFldHnt)
179 class SwHistorySetRefMark : public SwHistoryHint
181 const String m_RefName;
182 const ULONG m_nNodeIndex;
183 const xub_StrLen m_nStart;
184 const xub_StrLen m_nEnd;
186 public:
187 SwHistorySetRefMark( SwTxtRefMark* pTxtHt, ULONG nNode );
188 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
190 OUT_HSTR_HINT(SetRefMarkHnt)
193 class SwHistorySetTOXMark : public SwHistoryHint
195 SwTOXMark m_TOXMark;
196 const String m_TOXName;
197 const TOXTypes m_eTOXTypes;
198 const ULONG m_nNodeIndex;
199 const xub_StrLen m_nStart;
200 const xub_StrLen m_nEnd;
202 public:
203 SwHistorySetTOXMark( SwTxtTOXMark* pTxtHt, ULONG nNode );
204 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
205 int IsEqual( const SwTOXMark& rCmp ) const;
207 OUT_HSTR_HINT(SetToxMarkHnt)
210 class SwHistoryResetTxt : public SwHistoryHint
212 const ULONG m_nNodeIndex;
213 const xub_StrLen m_nStart;
214 const xub_StrLen m_nEnd;
215 const USHORT m_nAttr;
217 public:
218 SwHistoryResetTxt( USHORT nWhich, xub_StrLen nStt, xub_StrLen nEnd,
219 ULONG nNode );
220 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
222 USHORT GetWhich() const { return m_nAttr; }
223 ULONG GetNode() const { return m_nNodeIndex; }
224 xub_StrLen GetCntnt() const { return m_nStart; }
226 OUT_HSTR_HINT(ResetTxtHnt)
229 class SwHistorySetFootnote : public SwHistoryHint
231 const ::std::auto_ptr<SwUndoSaveSection> m_pUndo;
232 const String m_FootnoteNumber;
233 ULONG m_nNodeIndex;
234 const xub_StrLen m_nStart;
235 const bool m_bEndNote;
237 public:
238 SwHistorySetFootnote( SwTxtFtn* pTxtFtn, ULONG nNode );
239 SwHistorySetFootnote( const SwTxtFtn& );
240 virtual ~SwHistorySetFootnote();
241 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
243 virtual String GetDescription() const;
245 OUT_HSTR_HINT(SetFtnHnt)
248 class SwHistoryChangeFmtColl : public SwHistoryHint
250 SwFmtColl * const m_pColl;
251 const ULONG m_nNodeIndex;
252 const BYTE m_nNodeType;
254 public:
255 SwHistoryChangeFmtColl( SwFmtColl* pColl, ULONG nNode, BYTE nNodeWhich );
256 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
258 OUT_HSTR_HINT(ChangeFmtColl)
261 class SwHistoryTxtFlyCnt : public SwHistoryHint
263 ::std::auto_ptr<SwUndoDelLayFmt> m_pUndo;
265 public:
266 SwHistoryTxtFlyCnt( SwFrmFmt* const pFlyFmt );
267 virtual ~SwHistoryTxtFlyCnt();
268 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
269 SwUndoDelLayFmt* GetUDelLFmt() { return m_pUndo.get(); }
271 OUT_HSTR_HINT(FlyCnt)
274 class SwHistoryBookmark : public SwHistoryHint
276 public:
277 SwHistoryBookmark(const ::sw::mark::IMark& rBkmk,
278 bool bSavePos, bool bSaveOtherPos);
279 virtual void SetInDoc(SwDoc * pDoc, bool);
281 bool IsEqualBookmark(const ::sw::mark::IMark& rBkmk);
282 const ::rtl::OUString& GetName() const;
284 OUT_HSTR_HINT(Bookmark)
286 private:
287 const ::rtl::OUString m_aName;
288 ::rtl::OUString m_aShortName;
289 KeyCode m_aKeycode;
290 const ULONG m_nNode;
291 const ULONG m_nOtherNode;
292 const xub_StrLen m_nCntnt;
293 const xub_StrLen m_nOtherCntnt;
294 const bool m_bSavePos;
295 const bool m_bSaveOtherPos;
296 const bool m_bHadOtherPos;
297 const IDocumentMarkAccess::MarkType m_eBkmkType;
300 class SwHistorySetAttrSet : public SwHistoryHint
302 SfxItemSet m_OldSet;
303 SvUShorts m_ResetArray;
304 const ULONG m_nNodeIndex;
306 public:
307 SwHistorySetAttrSet( const SfxItemSet& rSet, ULONG nNode,
308 const SvUShortsSort& rSetArr );
309 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
311 OUT_HSTR_HINT(SetAttrSet)
315 class SwHistoryResetAttrSet : public SwHistoryHint
317 const ULONG m_nNodeIndex;
318 const xub_StrLen m_nStart;
319 const xub_StrLen m_nEnd;
320 SvUShorts m_Array;
322 public:
323 SwHistoryResetAttrSet( const SfxItemSet& rSet, ULONG nNode,
324 xub_StrLen nStt = STRING_MAXLEN,
325 xub_StrLen nEnd = STRING_MAXLEN );
326 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
328 const SvUShorts& GetArr() const { return m_Array; }
329 ULONG GetNode() const { return m_nNodeIndex; }
330 xub_StrLen GetCntnt() const { return m_nStart; }
332 OUT_HSTR_HINT(ResetAttrSet)
335 class SwHistoryChangeFlyAnchor : public SwHistoryHint
337 SwFrmFmt & m_rFmt;
338 const ULONG m_nOldNodeIndex;
339 const xub_StrLen m_nOldContentIndex;
341 public:
342 SwHistoryChangeFlyAnchor( SwFrmFmt& rFmt );
343 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
346 class SwHistoryChangeFlyChain : public SwHistoryHint
348 SwFlyFrmFmt * const m_pPrevFmt;
349 SwFlyFrmFmt * const m_pNextFmt;
350 SwFlyFrmFmt * const m_pFlyFmt;
352 public:
353 SwHistoryChangeFlyChain( SwFlyFrmFmt& rFmt, const SwFmtChain& rAttr );
354 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
357 // #i27615#
358 class SwHistoryChangeCharFmt : public SwHistoryHint
360 const SfxItemSet m_OldSet;
361 const String m_Fmt;
363 public:
364 SwHistoryChangeCharFmt( const SfxItemSet& rSet, const String & sFmt);
365 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
367 OUT_HSTR_HINT(SetAttrSet)
371 #endif
373 typedef SwHistoryHint* SwHistoryHintPtr;
374 SV_DECL_PTRARR_DEL( SwpHstry, SwHistoryHintPtr, 0, 2 )
376 class SwHistory
378 friend class SwDoc; // actually only SwDoc::DelUndoObj may access
379 friend class SwUndoWriter; // for Undo/Redo Writer
380 friend class SwRegHistory; // for inserting History attributes
382 SwpHstry m_SwpHstry;
383 USHORT m_nEndDiff;
385 public:
386 SwHistory( USHORT nInitSz = 0, USHORT nGrowSz = 2 );
387 ~SwHistory();
389 // delete History from nStart to array end
390 void Delete( USHORT nStart = 0 );
391 // call and delete all objects between nStart and array end
392 bool Rollback( SwDoc* pDoc, USHORT nStart = 0 );
393 // call all objects between nStart and TmpEnd; store nStart as TmpEnd
394 bool TmpRollback( SwDoc* pDoc, USHORT nStart, bool ToFirst = true );
396 // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
397 void Add( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue,
398 ULONG nNodeIdx );
399 // <--
400 void Add( SwTxtAttr* pTxtHt, ULONG nNodeIdx, bool bNewAttr = true );
401 void Add( SwFmtColl*, ULONG nNodeIdx, BYTE nWhichNd );
402 void Add( const ::sw::mark::IMark&, bool bSavePos, bool bSaveOtherPos );
403 void Add( SwFrmFmt& rFmt );
404 void Add( SwFlyFrmFmt&, USHORT& rSetPos );
405 void Add( const SwTxtFtn& );
406 void Add( const SfxItemSet & rSet, const SwCharFmt & rCharFmt); // #i27615#
408 USHORT Count() const { return m_SwpHstry.Count(); }
409 USHORT GetTmpEnd() const { return m_SwpHstry.Count() - m_nEndDiff; }
410 USHORT SetTmpEnd( USHORT nTmpEnd ); // return previous value
411 SwHistoryHint * operator[]( USHORT nPos ) { return m_SwpHstry[nPos]; }
412 SwHistoryHint const* operator[]( USHORT nPos ) const
413 { return m_SwpHstry[nPos]; }
415 // for SwUndoDelete::Undo/Redo
416 void Move( USHORT nPos, SwHistory *pIns,
417 USHORT nStart = 0, USHORT nEnd = USHRT_MAX )
419 m_SwpHstry.Insert( &pIns->m_SwpHstry, nPos, nStart, nEnd );
420 pIns->m_SwpHstry.Remove( nStart, (nEnd == USHRT_MAX)
421 ? pIns->Count() - nStart
422 : nEnd );
425 // helper methods for recording attribute in History
426 // used by Undo classes (Delete/Overwrite/Inserts)
427 void CopyAttr( SwpHints* pHts, ULONG nNodeIdx, xub_StrLen nStart,
428 xub_StrLen nEnd, bool bFields );
429 // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
430 void CopyFmtAttr( const SfxItemSet& rSet, ULONG nNodeIdx );
431 // <--
434 #ifndef ROLBCK_HISTORY_ONLY
436 class SwRegHistory : public SwClient
438 private:
439 SvUShortsSort m_WhichIdSet;
440 SwHistory * const m_pHistory;
441 ULONG m_nNodeIndex;
443 void _MakeSetWhichIds();
445 public:
446 // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
447 SwRegHistory( SwHistory* pHst );
448 // <--
449 SwRegHistory( SwTxtNode* pTxtNode, const SfxItemSet& rSet,
450 xub_StrLen nStart, xub_StrLen nEnd, USHORT nFlags,
451 SwHistory* pHst );
452 SwRegHistory( const SwNode& rNd, SwHistory* pHst );
453 SwRegHistory( SwModify* pRegIn, const SwNode& rNd, SwHistory* pHst );
455 virtual void Modify( SfxPoolItem* pOld, SfxPoolItem* pNew );
456 void AddHint( SwTxtAttr* pHt, const bool bNew = false );
458 void RegisterInModify( SwModify* pRegIn, const SwNode& rNd );
459 void ChangeNodeIndex( ULONG nNew ) { m_nNodeIndex = nNew; }
462 #endif
465 #endif // _ROLBCK_HXX