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 ************************************************************************/
30 #include <tools/solar.h>
32 #define _SVSTDARR_USHORTS
33 #define _SVSTDARR_USHORTSSORT
34 #include <svl/svstdarr.hxx>
36 #include <svl/itemset.hxx>
38 //Nur die History anziehen, um das docnew.cxx gegen die CLOOK's zu behaupten.
41 class MetadatableUndo
;
51 class SwUndoSaveSection
;
54 class SwUndoDelLayFmt
;
67 #ifndef ROLBCK_HISTORY_ONLY
71 #include <SwNumberTreeTypes.hxx>
72 // --> OD 2007-10-17 #i81002#
73 #include <IDocumentMarkAccess.hxx>
95 HSTRY_CHGCHARFMT
, // #i27615#
101 const HISTORY_HINT m_eWhichId
;
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
;
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
;
130 // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
131 SwHistoryResetFmt( const SfxPoolItem
* pFmtHt
, ULONG nNodeIdx
);
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
;
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
;
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
;
179 SwHistorySetRefMark( SwTxtRefMark
* pTxtHt
, ULONG nNode
);
180 virtual void SetInDoc( SwDoc
* pDoc
, bool bTmpSet
);
184 class SwHistorySetTOXMark
: public SwHistoryHint
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
;
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
;
208 SwHistoryResetTxt( USHORT nWhich
, xub_StrLen nStt
, xub_StrLen nEnd
,
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
;
223 const xub_StrLen m_nStart
;
224 const bool m_bEndNote
;
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
;
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
;
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
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;
272 const ::rtl::OUString m_aName
;
273 ::rtl::OUString m_aShortName
;
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
289 SvUShorts m_ResetArray
;
290 const ULONG m_nNodeIndex
;
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
;
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
322 const ULONG m_nOldNodeIndex
;
323 const xub_StrLen m_nOldContentIndex
;
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
;
337 SwHistoryChangeFlyChain( SwFlyFrmFmt
& rFmt
, const SwFmtChain
& rAttr
);
338 virtual void SetInDoc( SwDoc
* pDoc
, bool bTmpSet
);
342 class SwHistoryChangeCharFmt
: public SwHistoryHint
344 const SfxItemSet m_OldSet
;
348 SwHistoryChangeCharFmt( const SfxItemSet
& rSet
, const String
& sFmt
);
349 virtual void SetInDoc( SwDoc
* pDoc
, bool bTmpSet
);
356 typedef SwHistoryHint
* SwHistoryHintPtr
;
357 SV_DECL_PTRARR_DEL( SwpHstry
, SwHistoryHintPtr
, 0, 2 )
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
369 SwHistory( USHORT nInitSz
= 0, USHORT nGrowSz
= 2 );
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
,
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
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
);
417 #ifndef ROLBCK_HISTORY_ONLY
419 class SwRegHistory
: public SwClient
422 SvUShortsSort m_WhichIdSet
;
423 SwHistory
* const m_pHistory
;
426 void _MakeSetWhichIds();
429 // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
430 SwRegHistory( SwHistory
* pHst
);
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
; }
451 #endif // _ROLBCK_HXX