merge the formfield patch from ooo-build
[ooovba.git] / sw / inc / rolbck.hxx
blobf910a44ca859e980e14be68f2e93f85de6c80b56
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 namespace sfx2 {
44 class MetadatableUndo;
47 class SwDoc;
48 class SwFmt;
49 class SwFmtColl;
50 class SwHistoryHint;
51 class SwTxtAttr;
52 class SfxPoolItem;
53 class SwTxtNode;
54 class SwUndoSaveSection;
55 class SwTxtFtn;
56 class SwTxtFlyCnt;
57 class SwUndoDelLayFmt;
58 class SwFlyFrmFmt;
59 class SwFmtFld;
60 class SwTxtFld;
61 class SwFieldType;
62 class SwTxtTOXMark;
63 class SwTxtRefMark;
64 class SwFrmFmt;
65 class SwpHints;
66 class SwFmtChain;
67 class SwNode;
68 class SwCharFmt;
70 #ifndef ROLBCK_HISTORY_ONLY
72 #include <tox.hxx>
74 #include <SwNumberTreeTypes.hxx>
75 // --> OD 2007-10-17 #i81002#
76 #include <IDocumentMarkAccess.hxx>
77 // <--
79 #include <memory>
82 #ifndef PRODUCT
83 class Writer;
84 #define OUT_HSTR_HINT( name ) \
85 friend Writer& OutUndo_Hstr_ ## name( Writer&, const SwHistoryHint& );
86 #else
87 #define OUT_HSTR_HINT( name )
88 #endif
90 enum HISTORY_HINT {
91 HSTRY_SETFMTHNT,
92 HSTRY_RESETFMTHNT,
93 HSTRY_SETTXTHNT,
94 HSTRY_SETTXTFLDHNT,
95 HSTRY_SETREFMARKHNT,
96 HSTRY_SETTOXMARKHNT,
97 HSTRY_RESETTXTHNT,
98 HSTRY_SETFTNHNT,
99 HSTRY_CHGFMTCOLL,
100 HSTRY_FLYCNT,
101 HSTRY_BOOKMARK,
102 HSTRY_SETATTRSET,
103 HSTRY_RESETATTRSET,
104 HSTRY_CHGFLYANCHOR,
105 HSTRY_CHGFLYCHAIN,
106 HSTRY_CHGCHARFMT, // #i27615#
107 HSTRY_END
110 class SwHistoryHint
112 const HISTORY_HINT m_eWhichId;
114 public:
115 SwHistoryHint( HISTORY_HINT eWhich ) : m_eWhichId( eWhich ) {}
116 virtual ~SwHistoryHint() {}
117 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) = 0;
118 HISTORY_HINT Which() const { return m_eWhichId; }
119 virtual String GetDescription() const;
122 class SwHistorySetFmt : public SwHistoryHint
124 ::std::auto_ptr<SfxPoolItem> m_pAttr;
125 const ULONG m_nNodeIndex;
127 public:
128 SwHistorySetFmt( const SfxPoolItem* pFmtHt, ULONG nNode );
129 virtual ~SwHistorySetFmt();
130 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
131 virtual String GetDescription() const;
133 OUT_HSTR_HINT(SetFmtHnt)
136 class SwHistoryResetFmt : public SwHistoryHint
138 const ULONG m_nNodeIndex;
139 const USHORT m_nWhich;
141 public:
142 // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
143 SwHistoryResetFmt( const SfxPoolItem* pFmtHt, ULONG nNodeIdx );
144 // <--
145 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
147 OUT_HSTR_HINT(ResetFmtHnt)
150 class SwHistorySetTxt : public SwHistoryHint
152 ::std::auto_ptr<SfxPoolItem> m_pAttr;
153 const ULONG m_nNodeIndex;
154 const xub_StrLen m_nStart;
155 const xub_StrLen m_nEnd;
157 public:
158 SwHistorySetTxt( SwTxtAttr* pTxtHt, ULONG nNode );
159 virtual ~SwHistorySetTxt();
160 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
162 OUT_HSTR_HINT(SetTxtHnt)
165 class SwHistorySetTxtFld : public SwHistoryHint
167 ::std::auto_ptr<SwFieldType> m_pFldType;
168 const ::std::auto_ptr<SwFmtFld> m_pFld;
169 ULONG m_nNodeIndex;
170 xub_StrLen m_nPos;
171 USHORT m_nFldWhich;
173 public:
174 SwHistorySetTxtFld( SwTxtFld* pTxtFld, ULONG nNode );
175 virtual ~SwHistorySetTxtFld();
176 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
178 virtual String GetDescription() const;
180 OUT_HSTR_HINT(SetTxtFldHnt)
183 class SwHistorySetRefMark : public SwHistoryHint
185 const String m_RefName;
186 const ULONG m_nNodeIndex;
187 const xub_StrLen m_nStart;
188 const xub_StrLen m_nEnd;
190 public:
191 SwHistorySetRefMark( SwTxtRefMark* pTxtHt, ULONG nNode );
192 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
194 OUT_HSTR_HINT(SetRefMarkHnt)
197 class SwHistorySetTOXMark : public SwHistoryHint
199 SwTOXMark m_TOXMark;
200 const String m_TOXName;
201 const TOXTypes m_eTOXTypes;
202 const ULONG m_nNodeIndex;
203 const xub_StrLen m_nStart;
204 const xub_StrLen m_nEnd;
206 public:
207 SwHistorySetTOXMark( SwTxtTOXMark* pTxtHt, ULONG nNode );
208 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
209 int IsEqual( const SwTOXMark& rCmp ) const;
211 OUT_HSTR_HINT(SetToxMarkHnt)
214 class SwHistoryResetTxt : public SwHistoryHint
216 const ULONG m_nNodeIndex;
217 const xub_StrLen m_nStart;
218 const xub_StrLen m_nEnd;
219 const USHORT m_nAttr;
221 public:
222 SwHistoryResetTxt( USHORT nWhich, xub_StrLen nStt, xub_StrLen nEnd,
223 ULONG nNode );
224 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
226 USHORT GetWhich() const { return m_nAttr; }
227 ULONG GetNode() const { return m_nNodeIndex; }
228 xub_StrLen GetCntnt() const { return m_nStart; }
230 OUT_HSTR_HINT(ResetTxtHnt)
233 class SwHistorySetFootnote : public SwHistoryHint
235 const ::std::auto_ptr<SwUndoSaveSection> m_pUndo;
236 const String m_FootnoteNumber;
237 ULONG m_nNodeIndex;
238 const xub_StrLen m_nStart;
239 const bool m_bEndNote;
241 public:
242 SwHistorySetFootnote( SwTxtFtn* pTxtFtn, ULONG nNode );
243 SwHistorySetFootnote( const SwTxtFtn& );
244 virtual ~SwHistorySetFootnote();
245 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
247 virtual String GetDescription() const;
249 OUT_HSTR_HINT(SetFtnHnt)
252 class SwHistoryChangeFmtColl : public SwHistoryHint
254 SwFmtColl * const m_pColl;
255 const ULONG m_nNodeIndex;
256 const BYTE m_nNodeType;
258 public:
259 SwHistoryChangeFmtColl( SwFmtColl* pColl, ULONG nNode, BYTE nNodeWhich );
260 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
262 OUT_HSTR_HINT(ChangeFmtColl)
265 class SwHistoryTxtFlyCnt : public SwHistoryHint
267 ::std::auto_ptr<SwUndoDelLayFmt> m_pUndo;
269 public:
270 SwHistoryTxtFlyCnt( SwFrmFmt* const pFlyFmt );
271 virtual ~SwHistoryTxtFlyCnt();
272 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
273 SwUndoDelLayFmt* GetUDelLFmt() { return m_pUndo.get(); }
275 OUT_HSTR_HINT(FlyCnt)
278 class SwHistoryBookmark : public SwHistoryHint
280 public:
281 SwHistoryBookmark(const ::sw::mark::IMark& rBkmk,
282 bool bSavePos, bool bSaveOtherPos);
283 virtual void SetInDoc(SwDoc * pDoc, bool);
285 bool IsEqualBookmark(const ::sw::mark::IMark& rBkmk);
286 const ::rtl::OUString& GetName() const;
288 OUT_HSTR_HINT(Bookmark)
290 private:
291 const ::rtl::OUString m_aName;
292 ::rtl::OUString m_aShortName;
293 KeyCode m_aKeycode;
294 const ULONG m_nNode;
295 const ULONG m_nOtherNode;
296 const xub_StrLen m_nCntnt;
297 const xub_StrLen m_nOtherCntnt;
298 const bool m_bSavePos;
299 const bool m_bSaveOtherPos;
300 const bool m_bHadOtherPos;
301 const IDocumentMarkAccess::MarkType m_eBkmkType;
302 ::boost::shared_ptr< ::sfx2::MetadatableUndo > m_pMetadataUndo;
305 class SwHistorySetAttrSet : public SwHistoryHint
307 SfxItemSet m_OldSet;
308 SvUShorts m_ResetArray;
309 const ULONG m_nNodeIndex;
311 public:
312 SwHistorySetAttrSet( const SfxItemSet& rSet, ULONG nNode,
313 const SvUShortsSort& rSetArr );
314 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
316 OUT_HSTR_HINT(SetAttrSet)
320 class SwHistoryResetAttrSet : public SwHistoryHint
322 const ULONG m_nNodeIndex;
323 const xub_StrLen m_nStart;
324 const xub_StrLen m_nEnd;
325 SvUShorts m_Array;
327 public:
328 SwHistoryResetAttrSet( const SfxItemSet& rSet, ULONG nNode,
329 xub_StrLen nStt = STRING_MAXLEN,
330 xub_StrLen nEnd = STRING_MAXLEN );
331 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
333 const SvUShorts& GetArr() const { return m_Array; }
334 ULONG GetNode() const { return m_nNodeIndex; }
335 xub_StrLen GetCntnt() const { return m_nStart; }
337 OUT_HSTR_HINT(ResetAttrSet)
340 class SwHistoryChangeFlyAnchor : public SwHistoryHint
342 SwFrmFmt & m_rFmt;
343 const ULONG m_nOldNodeIndex;
344 const xub_StrLen m_nOldContentIndex;
346 public:
347 SwHistoryChangeFlyAnchor( SwFrmFmt& rFmt );
348 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
351 class SwHistoryChangeFlyChain : public SwHistoryHint
353 SwFlyFrmFmt * const m_pPrevFmt;
354 SwFlyFrmFmt * const m_pNextFmt;
355 SwFlyFrmFmt * const m_pFlyFmt;
357 public:
358 SwHistoryChangeFlyChain( SwFlyFrmFmt& rFmt, const SwFmtChain& rAttr );
359 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
362 // #i27615#
363 class SwHistoryChangeCharFmt : public SwHistoryHint
365 const SfxItemSet m_OldSet;
366 const String m_Fmt;
368 public:
369 SwHistoryChangeCharFmt( const SfxItemSet& rSet, const String & sFmt);
370 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
372 OUT_HSTR_HINT(SetAttrSet)
376 #endif
378 typedef SwHistoryHint* SwHistoryHintPtr;
379 SV_DECL_PTRARR_DEL( SwpHstry, SwHistoryHintPtr, 0, 2 )
381 class SwHistory
383 friend class SwDoc; // actually only SwDoc::DelUndoObj may access
384 friend class SwUndoWriter; // for Undo/Redo Writer
385 friend class SwRegHistory; // for inserting History attributes
387 SwpHstry m_SwpHstry;
388 USHORT m_nEndDiff;
390 public:
391 SwHistory( USHORT nInitSz = 0, USHORT nGrowSz = 2 );
392 ~SwHistory();
394 // delete History from nStart to array end
395 void Delete( USHORT nStart = 0 );
396 // call and delete all objects between nStart and array end
397 bool Rollback( SwDoc* pDoc, USHORT nStart = 0 );
398 // call all objects between nStart and TmpEnd; store nStart as TmpEnd
399 bool TmpRollback( SwDoc* pDoc, USHORT nStart, bool ToFirst = true );
401 // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
402 void Add( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue,
403 ULONG nNodeIdx );
404 // <--
405 void Add( SwTxtAttr* pTxtHt, ULONG nNodeIdx, bool bNewAttr = true );
406 void Add( SwFmtColl*, ULONG nNodeIdx, BYTE nWhichNd );
407 void Add( const ::sw::mark::IMark&, bool bSavePos, bool bSaveOtherPos );
408 void Add( SwFrmFmt& rFmt );
409 void Add( SwFlyFrmFmt&, USHORT& rSetPos );
410 void Add( const SwTxtFtn& );
411 void Add( const SfxItemSet & rSet, const SwCharFmt & rCharFmt); // #i27615#
413 USHORT Count() const { return m_SwpHstry.Count(); }
414 USHORT GetTmpEnd() const { return m_SwpHstry.Count() - m_nEndDiff; }
415 USHORT SetTmpEnd( USHORT nTmpEnd ); // return previous value
416 SwHistoryHint * operator[]( USHORT nPos ) { return m_SwpHstry[nPos]; }
417 SwHistoryHint const* operator[]( USHORT nPos ) const
418 { return m_SwpHstry[nPos]; }
420 // for SwUndoDelete::Undo/Redo
421 void Move( USHORT nPos, SwHistory *pIns,
422 USHORT nStart = 0, USHORT nEnd = USHRT_MAX )
424 m_SwpHstry.Insert( &pIns->m_SwpHstry, nPos, nStart, nEnd );
425 pIns->m_SwpHstry.Remove( nStart, (nEnd == USHRT_MAX)
426 ? pIns->Count() - nStart
427 : nEnd );
430 // helper methods for recording attribute in History
431 // used by Undo classes (Delete/Overwrite/Inserts)
432 void CopyAttr( SwpHints* pHts, ULONG nNodeIdx, xub_StrLen nStart,
433 xub_StrLen nEnd, bool bFields );
434 // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
435 void CopyFmtAttr( const SfxItemSet& rSet, ULONG nNodeIdx );
436 // <--
439 #ifndef ROLBCK_HISTORY_ONLY
441 class SwRegHistory : public SwClient
443 private:
444 SvUShortsSort m_WhichIdSet;
445 SwHistory * const m_pHistory;
446 ULONG m_nNodeIndex;
448 void _MakeSetWhichIds();
450 public:
451 // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
452 SwRegHistory( SwHistory* pHst );
453 // <--
454 SwRegHistory( const SwNode& rNd, SwHistory* pHst );
455 SwRegHistory( SwModify* pRegIn, const SwNode& rNd, SwHistory* pHst );
457 virtual void Modify( SfxPoolItem* pOld, SfxPoolItem* pNew );
459 /// @return true iff at least 1 item was inserted
460 bool InsertItems( const SfxItemSet& rSet,
461 xub_StrLen const nStart, xub_StrLen const nEnd,
462 SetAttrMode const nFlags );
464 void AddHint( SwTxtAttr* pHt, const bool bNew = false );
466 void RegisterInModify( SwModify* pRegIn, const SwNode& rNd );
467 void ChangeNodeIndex( ULONG nNew ) { m_nNodeIndex = nNew; }
470 #endif
473 #endif // _ROLBCK_HXX