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 $
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 ************************************************************************/
33 #include <tools/solar.h>
35 #define _SVSTDARR_USHORTS
36 #define _SVSTDARR_USHORTSSORT
37 #include <svtools/svstdarr.hxx>
39 #include <svtools/itemset.hxx>
41 //Nur die History anziehen, um das docnew.cxx gegen die CLOOK's zu behaupten.
44 class MetadatableUndo
;
54 class SwUndoSaveSection
;
57 class SwUndoDelLayFmt
;
70 #ifndef ROLBCK_HISTORY_ONLY
74 #include <SwNumberTreeTypes.hxx>
75 // --> OD 2007-10-17 #i81002#
76 #include <IDocumentMarkAccess.hxx>
84 #define OUT_HSTR_HINT( name ) \
85 friend Writer& OutUndo_Hstr_ ## name( Writer&, const SwHistoryHint& );
87 #define OUT_HSTR_HINT( name )
106 HSTRY_CHGCHARFMT
, // #i27615#
112 const HISTORY_HINT m_eWhichId
;
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
;
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
;
142 // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
143 SwHistoryResetFmt( const SfxPoolItem
* pFmtHt
, ULONG nNodeIdx
);
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
;
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
;
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
;
191 SwHistorySetRefMark( SwTxtRefMark
* pTxtHt
, ULONG nNode
);
192 virtual void SetInDoc( SwDoc
* pDoc
, bool bTmpSet
);
194 OUT_HSTR_HINT(SetRefMarkHnt
)
197 class SwHistorySetTOXMark
: public SwHistoryHint
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
;
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
;
222 SwHistoryResetTxt( USHORT nWhich
, xub_StrLen nStt
, xub_StrLen nEnd
,
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
;
238 const xub_StrLen m_nStart
;
239 const bool m_bEndNote
;
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
;
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
;
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
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
)
291 const ::rtl::OUString m_aName
;
292 ::rtl::OUString m_aShortName
;
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
308 SvUShorts m_ResetArray
;
309 const ULONG m_nNodeIndex
;
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
;
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
343 const ULONG m_nOldNodeIndex
;
344 const xub_StrLen m_nOldContentIndex
;
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
;
358 SwHistoryChangeFlyChain( SwFlyFrmFmt
& rFmt
, const SwFmtChain
& rAttr
);
359 virtual void SetInDoc( SwDoc
* pDoc
, bool bTmpSet
);
363 class SwHistoryChangeCharFmt
: public SwHistoryHint
365 const SfxItemSet m_OldSet
;
369 SwHistoryChangeCharFmt( const SfxItemSet
& rSet
, const String
& sFmt
);
370 virtual void SetInDoc( SwDoc
* pDoc
, bool bTmpSet
);
372 OUT_HSTR_HINT(SetAttrSet
)
378 typedef SwHistoryHint
* SwHistoryHintPtr
;
379 SV_DECL_PTRARR_DEL( SwpHstry
, SwHistoryHintPtr
, 0, 2 )
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
391 SwHistory( USHORT nInitSz
= 0, USHORT nGrowSz
= 2 );
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
,
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
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
);
439 #ifndef ROLBCK_HISTORY_ONLY
441 class SwRegHistory
: public SwClient
444 SvUShortsSort m_WhichIdSet
;
445 SwHistory
* const m_pHistory
;
448 void _MakeSetWhichIds();
451 // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
452 SwRegHistory( SwHistory
* pHst
);
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
; }
473 #endif // _ROLBCK_HXX