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