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.
50 class SwUndoSaveSection
;
53 class SwUndoDelLayFmt
;
66 #ifndef ROLBCK_HISTORY_ONLY
70 #include <SwNumberTreeTypes.hxx>
71 // --> OD 2007-10-17 #i81002#
72 #include <IDocumentMarkAccess.hxx>
80 #define OUT_HSTR_HINT( name ) \
81 friend Writer& OutUndo_Hstr_ ## name( Writer&, const SwHistoryHint& );
83 #define OUT_HSTR_HINT( name )
102 HSTRY_CHGCHARFMT
, // #i27615#
108 const HISTORY_HINT m_eWhichId
;
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
;
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
;
138 // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
139 SwHistoryResetFmt( const SfxPoolItem
* pFmtHt
, ULONG nNodeIdx
);
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
;
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
;
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
;
187 SwHistorySetRefMark( SwTxtRefMark
* pTxtHt
, ULONG nNode
);
188 virtual void SetInDoc( SwDoc
* pDoc
, bool bTmpSet
);
190 OUT_HSTR_HINT(SetRefMarkHnt
)
193 class SwHistorySetTOXMark
: public SwHistoryHint
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
;
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
;
218 SwHistoryResetTxt( USHORT nWhich
, xub_StrLen nStt
, xub_StrLen nEnd
,
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
;
234 const xub_StrLen m_nStart
;
235 const bool m_bEndNote
;
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
;
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
;
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
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
)
287 const ::rtl::OUString m_aName
;
288 ::rtl::OUString m_aShortName
;
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
303 SvUShorts m_ResetArray
;
304 const ULONG m_nNodeIndex
;
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
;
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
338 const ULONG m_nOldNodeIndex
;
339 const xub_StrLen m_nOldContentIndex
;
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
;
353 SwHistoryChangeFlyChain( SwFlyFrmFmt
& rFmt
, const SwFmtChain
& rAttr
);
354 virtual void SetInDoc( SwDoc
* pDoc
, bool bTmpSet
);
358 class SwHistoryChangeCharFmt
: public SwHistoryHint
360 const SfxItemSet m_OldSet
;
364 SwHistoryChangeCharFmt( const SfxItemSet
& rSet
, const String
& sFmt
);
365 virtual void SetInDoc( SwDoc
* pDoc
, bool bTmpSet
);
367 OUT_HSTR_HINT(SetAttrSet
)
373 typedef SwHistoryHint
* SwHistoryHintPtr
;
374 SV_DECL_PTRARR_DEL( SwpHstry
, SwHistoryHintPtr
, 0, 2 )
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
386 SwHistory( USHORT nInitSz
= 0, USHORT nGrowSz
= 2 );
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
,
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
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
);
434 #ifndef ROLBCK_HISTORY_ONLY
436 class SwRegHistory
: public SwClient
439 SvUShortsSort m_WhichIdSet
;
440 SwHistory
* const m_pHistory
;
443 void _MakeSetWhichIds();
446 // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
447 SwRegHistory( SwHistory
* pHst
);
449 SwRegHistory( SwTxtNode
* pTxtNode
, const SfxItemSet
& rSet
,
450 xub_StrLen nStart
, xub_StrLen nEnd
, USHORT nFlags
,
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
; }
465 #endif // _ROLBCK_HXX