Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / inc / UndoAttribute.hxx
blob7fbbb5b522cd5cfaef9c788e539bcdff6f0cab70
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 .
20 #ifndef INCLUDED_SW_SOURCE_CORE_INC_UNDOATTRIBUTE_HXX
21 #define INCLUDED_SW_SOURCE_CORE_INC_UNDOATTRIBUTE_HXX
23 #include <undobj.hxx>
24 #include <memory>
25 #include <rtl/ustring.hxx>
26 #include <svl/itemset.hxx>
27 #include <swtypes.hxx>
28 #include <calbck.hxx>
29 #include <o3tl/sorted_vector.hxx>
31 class SvxTabStopItem;
32 class SwFormat;
33 class SwFootnoteInfo;
34 class SwEndNoteInfo;
35 class SwDoc;
37 class SwUndoAttr final : public SwUndo, private SwUndRng
39 SfxItemSet m_AttrSet; // attributes for Redo
40 const std::unique_ptr<SwHistory> m_pHistory; // History for Undo
41 std::unique_ptr<SwRedlineData> m_pRedlineData; // Redlining
42 std::unique_ptr<SwRedlineSaveDatas> m_pRedlineSaveData;
43 SwNodeOffset m_nNodeIndex; // Offset: for Redlining
44 const SetAttrMode m_nInsertFlags; // insert flags
45 OUString m_aChrFormatName;
47 void RemoveIdx( SwDoc& rDoc );
48 void redoAttribute(SwPaM& rPam, sw::UndoRedoContext& rContext);
49 public:
50 SwUndoAttr( const SwPaM&, SfxItemSet, const SetAttrMode nFlags );
51 SwUndoAttr( const SwPaM&, const SfxPoolItem&, const SetAttrMode nFlags );
53 virtual ~SwUndoAttr() override;
55 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
56 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
57 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
59 void SaveRedlineData( const SwPaM& rPam, bool bInsContent );
61 SwHistory& GetHistory() { return *m_pHistory; }
64 class SwUndoResetAttr final : public SwUndo, private SwUndRng
66 const std::unique_ptr<SwHistory> m_pHistory;
67 o3tl::sorted_vector<sal_uInt16> m_Ids;
68 const sal_uInt16 m_nFormatId; // Format-Id for Redo
70 public:
71 SwUndoResetAttr( const SwPaM&, sal_uInt16 nFormatId );
72 SwUndoResetAttr( const SwPosition&, sal_uInt16 nFormatId );
74 virtual ~SwUndoResetAttr() override;
76 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
77 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
78 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
80 void SetAttrs( o3tl::sorted_vector<sal_uInt16> && rAttrs );
82 SwHistory& GetHistory() { return *m_pHistory; }
85 class SwUndoFormatAttr final : public SwUndo
87 friend class SwUndoDefaultAttr;
88 OUString m_sFormatName;
89 std::optional<SfxItemSet> m_oOldSet; // old attributes
90 sal_Int32 m_nAnchorContentOffset;
91 SwNodeOffset m_nNodeIndex;
92 const sal_uInt16 m_nFormatWhich;
93 const bool m_bSaveDrawPt;
95 void SaveFlyAnchor( const SwFormat * pFormat, bool bSaveDrawPt = false );
96 // #i35443# - Add return value, type <bool>.
97 // Return value indicates, if anchor attribute is restored.
98 // Notes: - If anchor attribute is restored, all other existing attributes
99 // are also restored.
100 // - Anchor attribute isn't restored successfully, if it contains
101 // an invalid anchor position and all other existing attributes
102 // aren't restored.
103 // This situation occurs for undo of styles.
104 bool RestoreFlyAnchor(::sw::UndoRedoContext & rContext);
105 // --> OD 2008-02-27 #refactorlists# - removed <rAffectedItemSet>
106 void Init( const SwFormat & rFormat );
108 public:
109 // register at the Format and save old attributes
110 // --> OD 2008-02-27 #refactorlists# - removed <rNewSet>
111 SwUndoFormatAttr( SfxItemSet&& rOldSet,
112 SwFormat& rFormat,
113 bool bSaveDrawPt );
114 SwUndoFormatAttr( const SfxPoolItem& rItem,
115 SwFormat& rFormat,
116 bool bSaveDrawPt );
118 virtual ~SwUndoFormatAttr() override;
120 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
121 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
122 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
124 virtual SwRewriter GetRewriter() const override;
126 void PutAttr( const SfxPoolItem& rItem, const SwDoc& rDoc );
127 SwFormat* GetFormat( const SwDoc& rDoc ); // checks if it is still in the Doc!
130 // --> OD 2008-02-12 #newlistlevelattrs#
131 class SwUndoFormatResetAttr final : public SwUndo
133 public:
134 SwUndoFormatResetAttr( SwFormat& rChangedFormat,
135 const sal_uInt16 nWhichId );
136 virtual ~SwUndoFormatResetAttr() override;
138 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
139 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
141 private:
142 // format at which a certain attribute is reset.
143 SwFormat * const m_pChangedFormat;
144 // which ID of the reset attribute
145 const sal_uInt16 m_nWhichId;
146 // old attribute which has been reset - needed for undo.
147 std::unique_ptr<SfxPoolItem> m_pOldItem;
150 class SwUndoDontExpandFormat final : public SwUndo
152 const SwNodeOffset m_nNodeIndex;
153 const sal_Int32 m_nContentIndex;
155 public:
156 SwUndoDontExpandFormat( const SwPosition& rPos );
158 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
159 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
160 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
163 // helper class to receive changed attribute sets
164 class SwUndoFormatAttrHelper final : public SwClient
166 SwFormat& m_rFormat;
167 std::unique_ptr<SwUndoFormatAttr> m_pUndo;
168 const bool m_bSaveDrawPt;
170 public:
171 SwUndoFormatAttrHelper(SwFormat& rFormat, bool bSaveDrawPt = true);
173 virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
175 SwUndoFormatAttr* GetUndo() const { return m_pUndo.get(); }
176 // release the undo object (so it is not deleted here), and return it
177 std::unique_ptr<SwUndoFormatAttr> ReleaseUndo() { return std::move(m_pUndo); }
180 class SwDocModifyAndUndoGuard final
182 SwDoc* doc;
183 std::unique_ptr<SwUndoFormatAttrHelper> helper;
185 public:
186 SwDocModifyAndUndoGuard(SwFormat& format);
187 ~SwDocModifyAndUndoGuard();
190 class SwUndoMoveLeftMargin final : public SwUndo, private SwUndRng
192 const std::unique_ptr<SwHistory> m_pHistory;
193 const bool m_bModulus;
195 public:
196 SwUndoMoveLeftMargin( const SwPaM&, bool bRight, bool bModulus );
198 virtual ~SwUndoMoveLeftMargin() override;
200 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
201 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
202 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
204 SwHistory& GetHistory() { return *m_pHistory; }
208 class SwUndoDefaultAttr final : public SwUndo
210 std::optional<SfxItemSet> m_oOldSet; // the old attributes
211 std::unique_ptr<SvxTabStopItem> m_pTabStop;
213 public:
214 // registers at the format and saves old attributes
215 SwUndoDefaultAttr( const SfxItemSet& rOldSet, const SwDoc& rDoc );
217 virtual ~SwUndoDefaultAttr() override;
219 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
220 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
223 class SwUndoChangeFootNote final : public SwUndo, private SwUndRng
225 const std::unique_ptr<SwHistory> m_pHistory;
226 const OUString m_Text;
227 const bool m_bEndNote;
229 public:
230 SwUndoChangeFootNote( const SwPaM& rRange, OUString aText,
231 bool bIsEndNote );
232 virtual ~SwUndoChangeFootNote() override;
234 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
235 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
236 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
238 SwHistory& GetHistory() { return *m_pHistory; }
241 class SwUndoFootNoteInfo final : public SwUndo
243 std::unique_ptr<SwFootnoteInfo> m_pFootNoteInfo;
245 public:
246 SwUndoFootNoteInfo( const SwFootnoteInfo &rInfo, const SwDoc& rDoc );
248 virtual ~SwUndoFootNoteInfo() override;
250 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
251 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
254 class SwUndoEndNoteInfo final : public SwUndo
256 std::unique_ptr<SwEndNoteInfo> m_pEndNoteInfo;
258 public:
259 SwUndoEndNoteInfo( const SwEndNoteInfo &rInfo, const SwDoc& rDoc );
261 virtual ~SwUndoEndNoteInfo() override;
263 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
264 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
267 #endif // INCLUDED_SW_SOURCE_CORE_INC_UNDOATTRIBUTE_HXX
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */