LibreOffice Module sw (master) 1
UndoAttribute.hxx
Go to the documentation of this file.
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
20#ifndef INCLUDED_SW_SOURCE_CORE_INC_UNDOATTRIBUTE_HXX
21#define INCLUDED_SW_SOURCE_CORE_INC_UNDOATTRIBUTE_HXX
22
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>
30
31class SvxTabStopItem;
32class SwFormat;
33class SwFootnoteInfo;
34class SwEndNoteInfo;
35class SwDoc;
36
37class SwUndoAttr final : public SwUndo, private SwUndRng
38{
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
46
47 void RemoveIdx( SwDoc& rDoc );
48 void redoAttribute(SwPaM& rPam, sw::UndoRedoContext& rContext);
49public:
50 SwUndoAttr( const SwPaM&, SfxItemSet, const SetAttrMode nFlags );
51 SwUndoAttr( const SwPaM&, const SfxPoolItem&, const SetAttrMode nFlags );
52
53 virtual ~SwUndoAttr() override;
54
55 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
56 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
57 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
58
59 void SaveRedlineData( const SwPaM& rPam, bool bInsContent );
60
62};
63
64class SwUndoResetAttr final : public SwUndo, private SwUndRng
65{
66 const std::unique_ptr<SwHistory> m_pHistory;
68 const sal_uInt16 m_nFormatId; // Format-Id for Redo
69
70public:
71 SwUndoResetAttr( const SwPaM&, sal_uInt16 nFormatId );
72 SwUndoResetAttr( const SwPosition&, sal_uInt16 nFormatId );
73
74 virtual ~SwUndoResetAttr() override;
75
76 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
77 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
78 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
79
81
83};
84
85class SwUndoFormatAttr final : public SwUndo
86{
87 friend class SwUndoDefaultAttr;
88 OUString m_sFormatName;
89 std::optional<SfxItemSet> m_oOldSet; // old attributes
91 const sal_uInt16 m_nFormatWhich;
92 const bool m_bSaveDrawPt;
93
94 void SaveFlyAnchor( const SwFormat * pFormat, bool bSaveDrawPt = false );
95 // #i35443# - Add return value, type <bool>.
96 // Return value indicates, if anchor attribute is restored.
97 // Notes: - If anchor attribute is restored, all other existing attributes
98 // are also restored.
99 // - Anchor attribute isn't restored successfully, if it contains
100 // an invalid anchor position and all other existing attributes
101 // aren't restored.
102 // This situation occurs for undo of styles.
104 // --> OD 2008-02-27 #refactorlists# - removed <rAffectedItemSet>
105 void Init( const SwFormat & rFormat );
106
107public:
108 // register at the Format and save old attributes
109 // --> OD 2008-02-27 #refactorlists# - removed <rNewSet>
110 SwUndoFormatAttr( SfxItemSet&& rOldSet,
111 SwFormat& rFormat,
112 bool bSaveDrawPt );
113 SwUndoFormatAttr( const SfxPoolItem& rItem,
114 SwFormat& rFormat,
115 bool bSaveDrawPt );
116
117 virtual ~SwUndoFormatAttr() override;
118
119 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
120 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
121 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
122
123 virtual SwRewriter GetRewriter() const override;
124
125 void PutAttr( const SfxPoolItem& rItem, const SwDoc& rDoc );
126 SwFormat* GetFormat( const SwDoc& rDoc ); // checks if it is still in the Doc!
127};
128
129// --> OD 2008-02-12 #newlistlevelattrs#
130class SwUndoFormatResetAttr final : public SwUndo
131{
132 public:
133 SwUndoFormatResetAttr( SwFormat& rChangedFormat,
134 const sal_uInt16 nWhichId );
135 virtual ~SwUndoFormatResetAttr() override;
136
137 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
138 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
139
140 private:
141 // format at which a certain attribute is reset.
143 // which ID of the reset attribute
144 const sal_uInt16 m_nWhichId;
145 // old attribute which has been reset - needed for undo.
146 std::unique_ptr<SfxPoolItem> m_pOldItem;
147};
148
149class SwUndoDontExpandFormat final : public SwUndo
150{
152 const sal_Int32 m_nContentIndex;
153
154public:
155 SwUndoDontExpandFormat( const SwPosition& rPos );
156
157 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
158 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
159 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
160};
161
162// helper class to receive changed attribute sets
164{
166 std::unique_ptr<SwUndoFormatAttr> m_pUndo;
167 const bool m_bSaveDrawPt;
168
169public:
170 SwUndoFormatAttrHelper(SwFormat& rFormat, bool bSaveDrawPt = true);
171
172 virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
173
174 SwUndoFormatAttr* GetUndo() const { return m_pUndo.get(); }
175 // release the undo object (so it is not deleted here), and return it
176 std::unique_ptr<SwUndoFormatAttr> ReleaseUndo() { return std::move(m_pUndo); }
177};
178
180{
182 std::unique_ptr<SwUndoFormatAttrHelper> helper;
183
184public:
187};
188
189class SwUndoMoveLeftMargin final : public SwUndo, private SwUndRng
190{
191 const std::unique_ptr<SwHistory> m_pHistory;
192 const bool m_bModulus;
193
194public:
195 SwUndoMoveLeftMargin( const SwPaM&, bool bRight, bool bModulus );
196
197 virtual ~SwUndoMoveLeftMargin() override;
198
199 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
200 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
201 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
202
204
205};
206
207class SwUndoDefaultAttr final : public SwUndo
208{
209 std::optional<SfxItemSet> m_oOldSet; // the old attributes
210 std::unique_ptr<SvxTabStopItem> m_pTabStop;
211
212public:
213 // registers at the format and saves old attributes
214 SwUndoDefaultAttr( const SfxItemSet& rOldSet, const SwDoc& rDoc );
215
216 virtual ~SwUndoDefaultAttr() override;
217
218 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
219 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
220};
221
222class SwUndoChangeFootNote final : public SwUndo, private SwUndRng
223{
224 const std::unique_ptr<SwHistory> m_pHistory;
225 const OUString m_Text;
226 const bool m_bEndNote;
227
228public:
229 SwUndoChangeFootNote( const SwPaM& rRange, OUString aText,
230 bool bIsEndNote );
231 virtual ~SwUndoChangeFootNote() override;
232
233 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
234 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
235 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
236
238};
239
240class SwUndoFootNoteInfo final : public SwUndo
241{
242 std::unique_ptr<SwFootnoteInfo> m_pFootNoteInfo;
243
244public:
245 SwUndoFootNoteInfo( const SwFootnoteInfo &rInfo, const SwDoc& rDoc );
246
247 virtual ~SwUndoFootNoteInfo() override;
248
249 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
250 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
251};
252
253class SwUndoEndNoteInfo final : public SwUndo
254{
255 std::unique_ptr<SwEndNoteInfo> m_pEndNoteInfo;
256
257public:
258 SwUndoEndNoteInfo( const SwEndNoteInfo &rInfo, const SwDoc& rDoc );
259
260 virtual ~SwUndoEndNoteInfo() override;
261
262 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
263 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
264};
265
266#endif // INCLUDED_SW_SOURCE_CORE_INC_UNDOATTRIBUTE_HXX
267
268/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< SwUndoFormatAttrHelper > helper
SwDocModifyAndUndoGuard(SwFormat &format)
Definition: unattr.cxx:98
Definition: doc.hxx:195
Base class for various Writer styles.
Definition: format.hxx:47
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:187
SfxItemSet m_AttrSet
SwNodeOffset m_nNodeIndex
void RemoveIdx(SwDoc &rDoc)
Definition: unattr.cxx:865
void redoAttribute(SwPaM &rPam, sw::UndoRedoContext &rContext)
Definition: unattr.cxx:812
const std::unique_ptr< SwHistory > m_pHistory
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:850
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:760
SwUndoAttr(const SwPaM &, SfxItemSet, const SetAttrMode nFlags)
Definition: unattr.cxx:718
void SaveRedlineData(const SwPaM &rPam, bool bInsContent)
Definition: unattr.cxx:740
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:798
OUString m_aChrFormatName
std::unique_ptr< SwRedlineSaveDatas > m_pRedlineSaveData
virtual ~SwUndoAttr() override
Definition: unattr.cxx:736
SwHistory & GetHistory()
std::unique_ptr< SwRedlineData > m_pRedlineData
const SetAttrMode m_nInsertFlags
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1009
const std::unique_ptr< SwHistory > m_pHistory
SwUndoChangeFootNote(const SwPaM &rRange, OUString aText, bool bIsEndNote)
Definition: unattr.cxx:995
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1021
virtual ~SwUndoChangeFootNote() override
Definition: unattr.cxx:1005
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:1029
SwHistory & GetHistory()
const OUString m_Text
std::optional< SfxItemSet > m_oOldSet
SwUndoDefaultAttr(const SfxItemSet &rOldSet, const SwDoc &rDoc)
Definition: unattr.cxx:906
virtual ~SwUndoDefaultAttr() override
Definition: unattr.cxx:922
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:949
std::unique_ptr< SvxTabStopItem > m_pTabStop
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:926
const sal_Int32 m_nContentIndex
const SwNodeOffset m_nNodeIndex
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1104
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1094
SwUndoDontExpandFormat(const SwPosition &rPos)
Definition: unattr.cxx:1087
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:1114
std::unique_ptr< SwEndNoteInfo > m_pEndNoteInfo
SwUndoEndNoteInfo(const SwEndNoteInfo &rInfo, const SwDoc &rDoc)
Definition: unattr.cxx:1061
virtual ~SwUndoEndNoteInfo() override
Definition: unattr.cxx:1067
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1071
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1079
std::unique_ptr< SwFootnoteInfo > m_pFootNoteInfo
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1053
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1045
virtual ~SwUndoFootNoteInfo() override
Definition: unattr.cxx:1041
SwUndoFootNoteInfo(const SwFootnoteInfo &rInfo, const SwDoc &rDoc)
Definition: unattr.cxx:1035
std::unique_ptr< SwUndoFormatAttr > m_pUndo
SwUndoFormatAttr * GetUndo() const
std::unique_ptr< SwUndoFormatAttr > ReleaseUndo()
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: unattr.cxx:69
SwUndoFormatAttrHelper(SwFormat &rFormat, bool bSaveDrawPt=true)
Definition: unattr.cxx:62
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:286
const sal_uInt16 m_nFormatWhich
SwUndoFormatAttr(SfxItemSet &&rOldSet, SwFormat &rFormat, bool bSaveDrawPt)
Definition: unattr.cxx:116
bool RestoreFlyAnchor(::sw::UndoRedoContext &rContext)
Definition: unattr.cxx:411
void SaveFlyAnchor(const SwFormat *pFormat, bool bSaveDrawPt=false)
Definition: unattr.cxx:372
void Init(const SwFormat &rFormat)
Definition: unattr.cxx:147
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:293
virtual SwRewriter GetRewriter() const override
Returns the rewriter for this object.
Definition: unattr.cxx:349
SwFormat * GetFormat(const SwDoc &rDoc)
Definition: unattr.cxx:229
SwNodeOffset m_nNodeIndex
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:180
OUString m_sFormatName
std::optional< SfxItemSet > m_oOldSet
virtual ~SwUndoFormatAttr() override
Definition: unattr.cxx:176
const bool m_bSaveDrawPt
void PutAttr(const SfxPoolItem &rItem, const SwDoc &rDoc)
Definition: unattr.cxx:358
SwUndoFormatResetAttr(SwFormat &rChangedFormat, const sal_uInt16 nWhichId)
Definition: unattr.cxx:531
std::unique_ptr< SfxPoolItem > m_pOldItem
virtual ~SwUndoFormatResetAttr() override
Definition: unattr.cxx:543
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:547
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:555
SwFormat *const m_pChangedFormat
const sal_uInt16 m_nWhichId
virtual ~SwUndoMoveLeftMargin() override
Definition: unattr.cxx:963
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:967
const std::unique_ptr< SwHistory > m_pHistory
SwUndoMoveLeftMargin(const SwPaM &, bool bRight, bool bModulus)
Definition: unattr.cxx:954
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:988
SwHistory & GetHistory()
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:978
void SetAttrs(o3tl::sorted_vector< sal_uInt16 > &&rAttrs)
Definition: unattr.cxx:693
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:583
const std::unique_ptr< SwHistory > m_pHistory
SwUndoResetAttr(const SwPaM &, sal_uInt16 nFormatId)
Definition: unattr.cxx:563
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:674
SwHistory & GetHistory()
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:604
virtual ~SwUndoResetAttr() override
Definition: unattr.cxx:579
o3tl::sorted_vector< sal_uInt16 > m_Ids
const sal_uInt16 m_nFormatId
Marks a position in the document model.
Definition: pam.hxx:37
SetAttrMode
Definition: swtypes.hxx:133