Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / inc / rolbck.hxx
blob20fa600a63015f504257bf2da7cf2599910d6589
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SW_SOURCE_CORE_INC_ROLBCK_HXX
20 #define INCLUDED_SW_SOURCE_CORE_INC_ROLBCK_HXX
22 #include <o3tl/deleter.hxx>
23 #include <o3tl/sorted_vector.hxx>
24 #include <svl/itemset.hxx>
25 #include <vcl/keycod.hxx>
26 #include <tox.hxx>
28 #include <IDocumentMarkAccess.hxx>
30 #include <memory>
31 #include <vector>
33 namespace sfx2 {
34 class MetadatableUndo;
36 namespace sw {
37 class SpzFrameFormat;
40 class SwDoc;
41 class SwFormatColl;
42 class SwTextAttr;
43 class SfxPoolItem;
44 class SwUndoSaveSection;
45 class SwTextFootnote;
46 class SwUndoDelLayFormat;
47 class SwFlyFrameFormat;
48 class SwFormatField;
49 class SwTextField;
50 class SwFieldType;
51 class SwTextTOXMark;
52 class SwTextRefMark;
53 class SwFrameFormat;
54 class SwpHints;
55 class SwFormatChain;
56 class SwNode;
57 class SwCharFormat;
58 enum class SwFieldIds : sal_uInt16;
59 typedef struct _xmlTextWriter* xmlTextWriterPtr;
61 enum HISTORY_HINT {
62 HSTRY_SETFMTHNT,
63 HSTRY_RESETFMTHNT,
64 HSTRY_SETTXTHNT,
65 HSTRY_SETTXTFLDHNT,
66 HSTRY_SETREFMARKHNT,
67 HSTRY_SETTOXMARKHNT,
68 HSTRY_RESETTXTHNT,
69 HSTRY_SETFTNHNT,
70 HSTRY_CHGFMTCOLL,
71 HSTRY_FLYCNT,
72 HSTRY_BOOKMARK,
73 HSTRY_SETATTRSET,
74 HSTRY_CHGFLYANCHOR,
75 HSTRY_CHGFLYCHAIN,
76 HSTRY_CHGCHARFMT,
77 HSTRY_NOTEXTFIELDMARK,
78 HSTRY_TEXTFIELDMARK,
81 class SwHistoryHint
83 const HISTORY_HINT m_eWhichId;
85 public:
86 SwHistoryHint( HISTORY_HINT eWhich ) : m_eWhichId( eWhich ) {}
87 virtual ~SwHistoryHint() {}
88 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) = 0;
89 HISTORY_HINT Which() const { return m_eWhichId; }
90 virtual OUString GetDescription() const;
91 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
94 class SwHistorySetFormat final : public SwHistoryHint
96 std::unique_ptr<SfxPoolItem> m_pAttr;
97 const SwNodeOffset m_nNodeIndex;
99 public:
100 SwHistorySetFormat( const SfxPoolItem* pFormatHt, SwNodeOffset nNode );
101 virtual ~SwHistorySetFormat() override;
102 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) override;
103 virtual OUString GetDescription() const override;
105 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
108 class SwHistoryResetFormat final : public SwHistoryHint
110 const SwNodeOffset m_nNodeIndex;
111 const sal_uInt16 m_nWhich;
113 public:
114 SwHistoryResetFormat( const SfxPoolItem* pFormatHt, SwNodeOffset nNodeIdx );
115 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) override;
119 class SwHistorySetText final : public SwHistoryHint
121 std::unique_ptr<SfxPoolItem> m_pAttr;
122 const SwNodeOffset m_nNodeIndex;
123 const sal_Int32 m_nStart;
124 const sal_Int32 m_nEnd;
125 bool m_bFormatIgnoreStart : 1;
126 bool m_bFormatIgnoreEnd : 1;
128 public:
129 SwHistorySetText( SwTextAttr* pTextHt, SwNodeOffset nNode );
130 virtual ~SwHistorySetText() override;
131 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) override;
135 class SwHistorySetTextField final : public SwHistoryHint
137 //!! beware of the order for the declaration of the unique_ptrs.
138 //!! If they get destroyed in the wrong order sw may crash (namely mail-merge as well)
139 std::unique_ptr<SwFieldType> m_pFieldType;
140 const std::unique_ptr<SwFormatField> m_pField;
142 SwNodeOffset m_nNodeIndex;
143 sal_Int32 m_nPos;
144 SwFieldIds m_nFieldWhich;
146 public:
147 SwHistorySetTextField( const SwTextField* pTextField, SwNodeOffset nNode );
148 virtual ~SwHistorySetTextField() override;
149 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) override;
151 virtual OUString GetDescription() const override;
155 class SwHistorySetRefMark final : public SwHistoryHint
157 const OUString m_RefName;
158 const SwNodeOffset m_nNodeIndex;
159 const sal_Int32 m_nStart;
160 const sal_Int32 m_nEnd;
162 public:
163 SwHistorySetRefMark( const SwTextRefMark* pTextHt, SwNodeOffset nNode );
164 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) override;
165 const OUString& GetRefName() {return m_RefName;}
168 class SwHistorySetTOXMark final : public SwHistoryHint
170 SwTOXMark m_TOXMark;
171 const OUString m_TOXName;
172 const TOXTypes m_eTOXTypes;
173 const SwNodeOffset m_nNodeIndex;
174 const sal_Int32 m_nStart;
175 const sal_Int32 m_nEnd;
177 public:
178 SwHistorySetTOXMark( const SwTextTOXMark* pTextHt, SwNodeOffset nNode );
179 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) override;
180 bool IsEqual( const SwTOXMark& rCmp ) const;
182 static SwTOXType* GetSwTOXType(SwDoc& rDoc, TOXTypes eTOXTypes, const OUString& rTOXName);
185 class SwHistoryResetText final : public SwHistoryHint
187 const SwNodeOffset m_nNodeIndex;
188 const sal_Int32 m_nStart;
189 const sal_Int32 m_nEnd;
190 const sal_uInt16 m_nAttr;
192 public:
193 SwHistoryResetText( sal_uInt16 nWhich, sal_Int32 nStt, sal_Int32 nEnd,
194 SwNodeOffset nNode );
195 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) override;
197 sal_uInt16 GetWhich() const { return m_nAttr; }
198 SwNodeOffset GetNode() const { return m_nNodeIndex; }
199 sal_Int32 GetContent() const { return m_nStart; }
203 class SwHistorySetFootnote final : public SwHistoryHint
205 const std::unique_ptr<SwUndoSaveSection, o3tl::default_delete<SwUndoSaveSection>> m_pUndo;
206 const OUString m_FootnoteNumber;
207 SwNodeOffset m_nNodeIndex;
208 const sal_Int32 m_nStart;
209 const bool m_bEndNote;
211 public:
212 SwHistorySetFootnote( SwTextFootnote* pTextFootnote, SwNodeOffset nNode );
213 SwHistorySetFootnote( const SwTextFootnote& );
214 virtual ~SwHistorySetFootnote() override;
215 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) override;
217 virtual OUString GetDescription() const override;
221 class SwHistoryChangeFormatColl final : public SwHistoryHint
223 SwFormatColl * const m_pColl;
224 const SwNodeOffset m_nNodeIndex;
225 const SwNodeType m_nNodeType;
227 public:
228 SwHistoryChangeFormatColl( SwFormatColl* pColl, SwNodeOffset nNode, SwNodeType nNodeWhich );
229 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) override;
233 class SwHistoryTextFlyCnt final : public SwHistoryHint
235 std::unique_ptr<SwUndoDelLayFormat> m_pUndo;
237 public:
238 SwHistoryTextFlyCnt( SwFrameFormat* const pFlyFormat );
239 virtual ~SwHistoryTextFlyCnt() override;
240 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) override;
241 SwUndoDelLayFormat* GetUDelLFormat() { return m_pUndo.get(); }
243 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
246 class SwHistoryBookmark final : public SwHistoryHint
248 public:
249 SwHistoryBookmark(const ::sw::mark::IMark& rBkmk,
250 bool bSavePos, bool bSaveOtherPos);
251 virtual void SetInDoc(SwDoc * pDoc, bool) override;
253 bool IsEqualBookmark(const ::sw::mark::IMark& rBkmk);
254 const OUString& GetName() const { return m_aName;}
256 private:
257 const OUString m_aName;
258 OUString m_aShortName;
259 bool m_bHidden;
260 OUString m_aHideCondition;
261 vcl::KeyCode m_aKeycode;
262 const SwNodeOffset m_nNode;
263 const SwNodeOffset m_nOtherNode;
264 const sal_Int32 m_nContent;
265 const sal_Int32 m_nOtherContent;
266 const bool m_bSavePos;
267 const bool m_bSaveOtherPos;
268 const bool m_bHadOtherPos;
269 const IDocumentMarkAccess::MarkType m_eBkmkType;
270 std::shared_ptr< ::sfx2::MetadatableUndo > m_pMetadataUndo;
273 /// History object containing all information used during undo / redo
274 /// of checkbox and drop-down form field insertion.
275 class SwHistoryNoTextFieldmark final : public SwHistoryHint
277 public:
278 SwHistoryNoTextFieldmark(const ::sw::mark::IFieldmark& rFieldMark);
279 virtual void SetInDoc(SwDoc* pDoc, bool) override;
280 void ResetInDoc(SwDoc& rDoc);
282 private:
283 const OUString m_sType;
284 const SwNodeOffset m_nNode;
285 const sal_Int32 m_nContent;
288 /// History object containing all information used during undo / redo
289 /// of text form field insertion.
290 class SwHistoryTextFieldmark final : public SwHistoryHint
292 public:
293 SwHistoryTextFieldmark(const ::sw::mark::IFieldmark& rFieldMark);
294 virtual void SetInDoc(SwDoc* pDoc, bool) override;
295 void ResetInDoc(SwDoc& rDoc);
297 private:
298 const OUString m_sName;
299 const OUString m_sType;
300 const SwNodeOffset m_nStartNode;
301 const sal_Int32 m_nStartContent;
302 const SwNodeOffset m_nEndNode;
303 const sal_Int32 m_nEndContent;
304 /*const*/ SwNodeOffset m_nSepNode;
305 /*const*/ sal_Int32 m_nSepContent;
308 class SwHistorySetAttrSet final : public SwHistoryHint
310 SfxItemSet m_OldSet;
311 std::vector<sal_uInt16> m_ResetArray;
312 const SwNodeOffset m_nNodeIndex;
314 public:
315 SwHistorySetAttrSet( const SfxItemSet& rSet, SwNodeOffset nNode,
316 const o3tl::sorted_vector<sal_uInt16> &rSetArr );
317 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) override;
321 class SwHistoryChangeFlyAnchor final : public SwHistoryHint
323 sw::SpzFrameFormat& m_rFormat; // despite the name, this is not only used for flys, but also for draw formats(!)
324 const SwNodeOffset m_nOldNodeIndex;
325 const sal_Int32 m_nOldContentIndex;
327 public:
328 SwHistoryChangeFlyAnchor(sw::SpzFrameFormat& rFormat);
329 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) override;
332 class SwHistoryChangeFlyChain final : public SwHistoryHint
334 SwFlyFrameFormat * const m_pPrevFormat;
335 SwFlyFrameFormat * const m_pNextFormat;
336 SwFlyFrameFormat * const m_pFlyFormat;
338 public:
339 SwHistoryChangeFlyChain( SwFlyFrameFormat& rFormat, const SwFormatChain& rAttr );
340 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) override;
343 class SwHistoryChangeCharFormat final : public SwHistoryHint
345 const SfxItemSet m_OldSet;
346 const OUString m_Format;
348 public:
349 SwHistoryChangeCharFormat( SfxItemSet aSet, OUString sFormat);
350 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) override;
354 class SwHistory
356 friend class SwDoc; // actually only SwDoc::DelUndoObj may access
357 friend class SwRegHistory; // for inserting History attributes
359 std::vector<std::unique_ptr<SwHistoryHint>> m_SwpHstry;
360 sal_uInt16 m_nEndDiff;
362 public:
363 SwHistory();
364 ~SwHistory();
366 // call and delete all objects between nStart and array end
367 bool Rollback( SwDoc* pDoc, sal_uInt16 nStart = 0 );
368 // call all objects between nStart and TmpEnd; store nStart as TmpEnd
369 bool TmpRollback( SwDoc* pDoc, sal_uInt16 nStart, bool ToFirst = true );
371 void Add( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue,
372 SwNodeOffset nNodeIdx );
373 void Add( SwTextAttr* pTextHt, SwNodeOffset nNodeIdx, bool bNewAttr );
374 void Add( SwFormatColl*, SwNodeOffset nNodeIdx, SwNodeType nWhichNd );
375 void Add( const ::sw::mark::IMark&, bool bSavePos, bool bSaveOtherPos );
376 void AddChangeFlyAnchor(sw::SpzFrameFormat& rFormat);
377 void AddDeleteFly( SwFrameFormat&, sal_uInt16& rSetPos );
378 void Add( const SwTextFootnote& );
379 void Add( const SfxItemSet & rSet, const SwCharFormat & rCharFormat);
381 sal_uInt16 Count() const { return m_SwpHstry.size(); }
382 sal_uInt16 GetTmpEnd() const { return m_SwpHstry.size() - m_nEndDiff; }
383 sal_uInt16 SetTmpEnd( sal_uInt16 nTmpEnd ); // return previous value
384 SwHistoryHint * operator[]( sal_uInt16 nPos ) { return m_SwpHstry[nPos].get(); }
385 SwHistoryHint const* operator[]( sal_uInt16 nPos ) const
386 { return m_SwpHstry[nPos].get(); }
388 // for SwUndoDelete::Undo/Redo
389 void Move( sal_uInt16 nPos, SwHistory *pIns,
390 sal_uInt16 const nStart = 0)
392 auto itSourceBegin = pIns->m_SwpHstry.begin() + nStart;
393 auto itSourceEnd = pIns->m_SwpHstry.end();
394 if (itSourceBegin == itSourceEnd)
395 return;
396 m_SwpHstry.insert(m_SwpHstry.begin() + nPos, std::make_move_iterator(itSourceBegin), std::make_move_iterator(itSourceEnd));
397 pIns->m_SwpHstry.erase( itSourceBegin, itSourceEnd );
400 // helper methods for recording attribute in History
401 // used by Undo classes (Delete/Overwrite/Inserts)
402 void CopyAttr(
403 SwpHints const * pHts,
404 const SwNodeOffset nNodeIdx,
405 const sal_Int32 nStart,
406 const sal_Int32 nEnd,
407 const bool bCopyFields );
409 void CopyFormatAttr( const SfxItemSet& rSet, SwNodeOffset nNodeIdx );
411 void dumpAsXml(xmlTextWriterPtr pWriter) const;
414 class SwRegHistory final: public SwClient
416 private:
417 o3tl::sorted_vector<sal_uInt16> m_WhichIdSet;
418 SwHistory * const m_pHistory;
419 SwNodeOffset m_nNodeIndex;
421 void MakeSetWhichIds();
423 public:
424 SwRegHistory( SwHistory* pHst );
425 SwRegHistory( const SwNode& rNd, SwHistory* pHst );
426 SwRegHistory( sw::BroadcastingModify* pRegIn, const SwNode& rNd, SwHistory* pHst );
427 virtual void SwClientNotify(const SwModify&, const SfxHint& rHint) override;
429 /// @return true if at least 1 item was inserted
430 bool InsertItems( const SfxItemSet& rSet,
431 sal_Int32 const nStart, sal_Int32 const nEnd,
432 SetAttrMode const nFlags,
433 SwTextAttr **ppNewTextAttr );
435 void AddHint( SwTextAttr* pHt, const bool bNew );
437 void RegisterInModify( sw::BroadcastingModify* pRegIn, const SwNode& rNd );
438 void ChangeNodeIndex( SwNodeOffset nNew ) { m_nNodeIndex = nNew; }
441 #endif // INCLUDED_SW_SOURCE_CORE_INC_ROLBCK_HXX
443 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */