xref: /aoo42x/main/sw/source/core/inc/rolbck.hxx (revision 1d2dbeb0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _ROLBCK_HXX
24 #define _ROLBCK_HXX
25 
26 #include <tools/solar.h>
27 #ifndef _SVSTDARR_HXX
28 #define _SVSTDARR_USHORTS
29 #define _SVSTDARR_USHORTSSORT
30 #include <svl/svstdarr.hxx>
31 #endif
32 #include <svl/itemset.hxx>
33 
34 //Nur die History anziehen, um das docnew.cxx gegen die CLOOK's zu behaupten.
35 
36 namespace sfx2 {
37     class MetadatableUndo;
38 }
39 
40 class SwDoc;
41 class SwFmt;
42 class SwFmtColl;
43 class SwHistoryHint;
44 class SwTxtAttr;
45 class SfxPoolItem;
46 class SwTxtNode;
47 class SwUndoSaveSection;
48 class SwTxtFtn;
49 class SwTxtFlyCnt;
50 class SwUndoDelLayFmt;
51 class SwFlyFrmFmt;
52 class SwFmtFld;
53 class SwTxtFld;
54 class SwFieldType;
55 class SwTxtTOXMark;
56 class SwTxtRefMark;
57 class SwFrmFmt;
58 class SwpHints;
59 class SwFmtChain;
60 class SwNode;
61 class SwCharFmt;
62 
63 #ifndef ROLBCK_HISTORY_ONLY
64 
65 #include <tox.hxx>
66 
67 #include <SwNumberTreeTypes.hxx>
68 // --> OD 2007-10-17 #i81002#
69 #include <IDocumentMarkAccess.hxx>
70 // <--
71 
72 #include <memory>
73 
74 
75 enum HISTORY_HINT {
76     HSTRY_SETFMTHNT,
77     HSTRY_RESETFMTHNT,
78     HSTRY_SETTXTHNT,
79     HSTRY_SETTXTFLDHNT,
80     HSTRY_SETREFMARKHNT,
81     HSTRY_SETTOXMARKHNT,
82     HSTRY_RESETTXTHNT,
83     HSTRY_SETFTNHNT,
84     HSTRY_CHGFMTCOLL,
85     HSTRY_FLYCNT,
86     HSTRY_BOOKMARK,
87     HSTRY_SETATTRSET,
88     HSTRY_RESETATTRSET,
89     HSTRY_CHGFLYANCHOR,
90     HSTRY_CHGFLYCHAIN,
91     HSTRY_CHGCHARFMT, // #i27615#
92     HSTRY_END
93 };
94 
95 class SwHistoryHint
96 {
97     const HISTORY_HINT m_eWhichId;
98 
99 public:
100     SwHistoryHint( HISTORY_HINT eWhich ) : m_eWhichId( eWhich ) {}
101     virtual ~SwHistoryHint() {}
102     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) = 0;
103     HISTORY_HINT Which() const                     { return m_eWhichId; }
104     virtual String GetDescription() const;
105 };
106 
107 class SwHistorySetFmt : public SwHistoryHint
108 {
109     ::std::auto_ptr<SfxPoolItem> m_pAttr;
110     const sal_uLong m_nNodeIndex;
111 
112 public:
113     SwHistorySetFmt( const SfxPoolItem* pFmtHt, sal_uLong nNode );
114     virtual ~SwHistorySetFmt();
115     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
116     virtual String GetDescription() const;
117 
118 };
119 
120 class SwHistoryResetFmt : public SwHistoryHint
121 {
122     const sal_uLong m_nNodeIndex;
123     const sal_uInt16 m_nWhich;
124 
125 public:
126     // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
127     SwHistoryResetFmt( const SfxPoolItem* pFmtHt, sal_uLong nNodeIdx );
128     // <--
129     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
130 
131 };
132 
133 class SwHistorySetTxt : public SwHistoryHint
134 {
135     ::std::auto_ptr<SfxPoolItem> m_pAttr;
136     const sal_uLong m_nNodeIndex;
137     const xub_StrLen m_nStart;
138     const xub_StrLen m_nEnd;
139 
140 public:
141     SwHistorySetTxt( SwTxtAttr* pTxtHt, sal_uLong nNode );
142     virtual ~SwHistorySetTxt();
143     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
144 
145 };
146 
147 class SwHistorySetTxtFld : public SwHistoryHint
148 {
149     //!! beware of the order for the declation of the auto_ptrs.
150     //!! If they get destroyed in the wrong order sw may crash (namely mail-merge as well)
151     ::std::auto_ptr<SwFieldType> m_pFldType;
152     const ::std::auto_ptr<SwFmtFld> m_pFld;
153 
154     sal_uLong m_nNodeIndex;
155     xub_StrLen m_nPos;
156     sal_uInt16 m_nFldWhich;
157 
158 public:
159     SwHistorySetTxtFld( SwTxtFld* pTxtFld, sal_uLong nNode );
160     virtual ~SwHistorySetTxtFld();
161     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
162 
163     virtual String GetDescription() const;
164 
165 };
166 
167 class SwHistorySetRefMark : public SwHistoryHint
168 {
169     const String m_RefName;
170     const sal_uLong m_nNodeIndex;
171     const xub_StrLen m_nStart;
172     const xub_StrLen m_nEnd;
173 
174 public:
175     SwHistorySetRefMark( SwTxtRefMark* pTxtHt, sal_uLong nNode );
176     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
177 
178 };
179 
180 class SwHistorySetTOXMark : public SwHistoryHint
181 {
182     SwTOXMark m_TOXMark;
183     const String m_TOXName;
184     const TOXTypes m_eTOXTypes;
185     const sal_uLong m_nNodeIndex;
186     const xub_StrLen m_nStart;
187     const xub_StrLen m_nEnd;
188 
189 public:
190     SwHistorySetTOXMark( SwTxtTOXMark* pTxtHt, sal_uLong nNode );
191     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
192     int IsEqual( const SwTOXMark& rCmp ) const;
193 
194 };
195 
196 class SwHistoryResetTxt : public SwHistoryHint
197 {
198     const sal_uLong m_nNodeIndex;
199     const xub_StrLen m_nStart;
200     const xub_StrLen m_nEnd;
201     const sal_uInt16 m_nAttr;
202 
203 public:
204     SwHistoryResetTxt( sal_uInt16 nWhich, xub_StrLen nStt, xub_StrLen nEnd,
205                        sal_uLong nNode );
206     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
207 
208     sal_uInt16 GetWhich() const         { return m_nAttr; }
209     sal_uLong GetNode() const           { return m_nNodeIndex; }
210     xub_StrLen GetCntnt() const     { return m_nStart; }
211 
212 };
213 
214 class SwHistorySetFootnote : public SwHistoryHint
215 {
216     const ::std::auto_ptr<SwUndoSaveSection> m_pUndo;
217     const String m_FootnoteNumber;
218     sal_uLong m_nNodeIndex;
219     const xub_StrLen m_nStart;
220     const bool m_bEndNote;
221 
222 public:
223     SwHistorySetFootnote( SwTxtFtn* pTxtFtn, sal_uLong nNode );
224     SwHistorySetFootnote( const SwTxtFtn& );
225     virtual ~SwHistorySetFootnote();
226     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
227 
228     virtual String GetDescription() const;
229 
230 };
231 
232 class SwHistoryChangeFmtColl : public SwHistoryHint
233 {
234     SwFmtColl * const m_pColl;
235     const sal_uLong m_nNodeIndex;
236     const sal_uInt8 m_nNodeType;
237 
238 public:
239     SwHistoryChangeFmtColl( SwFmtColl* pColl, sal_uLong nNode, sal_uInt8 nNodeWhich );
240     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
241 
242 };
243 
244 class SwHistoryTxtFlyCnt : public SwHistoryHint
245 {
246     ::std::auto_ptr<SwUndoDelLayFmt> m_pUndo;
247 
248 public:
249     SwHistoryTxtFlyCnt( SwFrmFmt* const pFlyFmt );
250     virtual ~SwHistoryTxtFlyCnt();
251     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
252     SwUndoDelLayFmt* GetUDelLFmt() { return m_pUndo.get(); }
253 
254 };
255 
256 class SwHistoryBookmark : public SwHistoryHint
257 {
258     public:
259         SwHistoryBookmark(const ::sw::mark::IMark& rBkmk,
260                         bool bSavePos, bool bSaveOtherPos);
261         virtual void SetInDoc(SwDoc * pDoc, bool);
262 
263         bool IsEqualBookmark(const ::sw::mark::IMark& rBkmk);
264         const ::rtl::OUString& GetName() const;
265 
266 
267     private:
268         const ::rtl::OUString m_aName;
269         ::rtl::OUString m_aShortName;
270         KeyCode m_aKeycode;
271         const sal_uLong m_nNode;
272         const sal_uLong m_nOtherNode;
273         const xub_StrLen m_nCntnt;
274         const xub_StrLen m_nOtherCntnt;
275         const bool m_bSavePos;
276         const bool m_bSaveOtherPos;
277         const bool m_bHadOtherPos;
278         const IDocumentMarkAccess::MarkType m_eBkmkType;
279         ::boost::shared_ptr< ::sfx2::MetadatableUndo > m_pMetadataUndo;
280 };
281 
282 class SwHistorySetAttrSet : public SwHistoryHint
283 {
284     SfxItemSet m_OldSet;
285     SvUShorts m_ResetArray;
286     const sal_uLong m_nNodeIndex;
287 
288 public:
289     SwHistorySetAttrSet( const SfxItemSet& rSet, sal_uLong nNode,
290                          const SvUShortsSort& rSetArr );
291     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
292 
293 };
294 
295 
296 class SwHistoryResetAttrSet : public SwHistoryHint
297 {
298     const sal_uLong m_nNodeIndex;
299     const xub_StrLen m_nStart;
300     const xub_StrLen m_nEnd;
301     SvUShorts m_Array;
302 
303 public:
304     SwHistoryResetAttrSet( const SfxItemSet& rSet, sal_uLong nNode,
305                         xub_StrLen nStt = STRING_MAXLEN,
306                         xub_StrLen nEnd = STRING_MAXLEN );
307     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
308 
309     const SvUShorts& GetArr() const     { return m_Array; }
310     sal_uLong GetNode() const               { return m_nNodeIndex; }
311     xub_StrLen GetCntnt() const         { return m_nStart; }
312 
313 };
314 
315 class SwHistoryChangeFlyAnchor : public SwHistoryHint
316 {
317     SwFrmFmt & m_rFmt;
318     const sal_uLong m_nOldNodeIndex;
319     const xub_StrLen m_nOldContentIndex;
320 
321 public:
322     SwHistoryChangeFlyAnchor( SwFrmFmt& rFmt );
323     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
324 };
325 
326 class SwHistoryChangeFlyChain : public SwHistoryHint
327 {
328     SwFlyFrmFmt * const m_pPrevFmt;
329     SwFlyFrmFmt * const m_pNextFmt;
330     SwFlyFrmFmt * const m_pFlyFmt;
331 
332 public:
333     SwHistoryChangeFlyChain( SwFlyFrmFmt& rFmt, const SwFmtChain& rAttr );
334     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
335 };
336 
337 // #i27615#
338 class SwHistoryChangeCharFmt : public SwHistoryHint
339 {
340     const SfxItemSet m_OldSet;
341     const String m_Fmt;
342 
343 public:
344     SwHistoryChangeCharFmt( const SfxItemSet& rSet, const String & sFmt);
345     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet );
346 
347 };
348 
349 
350 #endif
351 
352 typedef SwHistoryHint* SwHistoryHintPtr;
353 SV_DECL_PTRARR_DEL( SwpHstry, SwHistoryHintPtr, 0, 2 )
354 
355 class SwHistory
356 {
357     friend class SwDoc;         // actually only SwDoc::DelUndoObj may access
358     friend class SwUndoWriter;  // for Undo/Redo Writer
359     friend class SwRegHistory;  // for inserting History attributes
360 
361     SwpHstry m_SwpHstry;
362     sal_uInt16 m_nEndDiff;
363 
364 public:
365     SwHistory( sal_uInt16 nInitSz = 0, sal_uInt16 nGrowSz = 2 );
366     ~SwHistory();
367 
368     // delete History from nStart to array end
369     void Delete( sal_uInt16 nStart = 0 );
370     // call and delete all objects between nStart and array end
371     bool Rollback( SwDoc* pDoc, sal_uInt16 nStart = 0 );
372     // call all objects between nStart and TmpEnd; store nStart as TmpEnd
373     bool TmpRollback( SwDoc* pDoc, sal_uInt16 nStart, bool ToFirst = true );
374 
375     // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
376     void Add( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue,
377               sal_uLong nNodeIdx );
378     // <--
379     void Add( SwTxtAttr* pTxtHt, sal_uLong nNodeIdx, bool bNewAttr = true );
380     void Add( SwFmtColl*, sal_uLong nNodeIdx, sal_uInt8 nWhichNd );
381     void Add( const ::sw::mark::IMark&, bool bSavePos, bool bSaveOtherPos );
382     void Add( SwFrmFmt& rFmt );
383     void Add( SwFlyFrmFmt&, sal_uInt16& rSetPos );
384     void Add( const SwTxtFtn& );
385     void Add( const SfxItemSet & rSet, const SwCharFmt & rCharFmt); // #i27615#
386 
387     sal_uInt16 Count() const { return m_SwpHstry.Count(); }
388     sal_uInt16 GetTmpEnd() const { return m_SwpHstry.Count() - m_nEndDiff; }
389     sal_uInt16 SetTmpEnd( sal_uInt16 nTmpEnd );        // return previous value
390     SwHistoryHint      * operator[]( sal_uInt16 nPos ) { return m_SwpHstry[nPos]; }
391     SwHistoryHint const* operator[]( sal_uInt16 nPos ) const
392         { return m_SwpHstry[nPos]; }
393 
394     // for SwUndoDelete::Undo/Redo
395     void Move( sal_uInt16 nPos, SwHistory *pIns,
396                sal_uInt16 nStart = 0, sal_uInt16 nEnd = USHRT_MAX )
397     {
398         m_SwpHstry.Insert( &pIns->m_SwpHstry, nPos, nStart, nEnd );
399         pIns->m_SwpHstry.Remove( nStart, (nEnd == USHRT_MAX)
400                                             ? pIns->Count() - nStart
401                                             : nEnd );
402     }
403 
404     // helper methods for recording attribute in History
405     // used by Undo classes (Delete/Overwrite/Inserts)
406     void CopyAttr( SwpHints* pHts, sal_uLong nNodeIdx, xub_StrLen nStart,
407                     xub_StrLen nEnd, bool bFields );
408     // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
409     void CopyFmtAttr( const SfxItemSet& rSet, sal_uLong nNodeIdx );
410     // <--
411 };
412 
413 #ifndef ROLBCK_HISTORY_ONLY
414 
415 class SwRegHistory : public SwClient
416 {
417 private:
418     SvUShortsSort m_WhichIdSet;
419     SwHistory * const m_pHistory;
420     sal_uLong m_nNodeIndex;
421 
422     void _MakeSetWhichIds();
423 
424 protected:
425     virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew );
426 
427 public:
428     // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
429     SwRegHistory( SwHistory* pHst );
430     // <--
431     SwRegHistory( const SwNode& rNd, SwHistory* pHst );
432     SwRegHistory( SwModify* pRegIn, const SwNode& rNd, SwHistory* pHst );
433 
434     /// @return true iff at least 1 item was inserted
435     bool InsertItems( const SfxItemSet& rSet,
436         xub_StrLen const nStart, xub_StrLen const nEnd,
437         SetAttrMode const nFlags );
438 
439     void AddHint( SwTxtAttr* pHt, const bool bNew = false );
440 
441     void RegisterInModify( SwModify* pRegIn, const SwNode& rNd );
442     void ChangeNodeIndex( sal_uLong nNew ) { m_nNodeIndex = nNew; }
443 };
444 
445 #endif
446 
447 
448 #endif // _ROLBCK_HXX
449 
450