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
92 const sal_uInt16 m_nFormatWhich;
93 const bool m_bSaveDrawPt;
94
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.
105 // --> OD 2008-02-27 #refactorlists# - removed <rAffectedItemSet>
106 void Init( const SwFormat & rFormat );
107
108public:
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 );
117
118 virtual ~SwUndoFormatAttr() override;
119
120 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
121 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
122 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
123
124 virtual SwRewriter GetRewriter() const override;
125
126 void PutAttr( const SfxPoolItem& rItem, const SwDoc& rDoc );
127 SwFormat* GetFormat( const SwDoc& rDoc ); // checks if it is still in the Doc!
128};
129
130// --> OD 2008-02-12 #newlistlevelattrs#
131class SwUndoFormatResetAttr final : public SwUndo
132{
133 public:
134 SwUndoFormatResetAttr( SwFormat& rChangedFormat,
135 const std::vector<sal_uInt16>& rIds );
136 virtual ~SwUndoFormatResetAttr() override;
137
138 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
139 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
140
141 private:
142 // format at which a certain attribute is reset.
144 // old attribute which has been reset - needed for undo.
146
148};
149
150class SwUndoDontExpandFormat final : public SwUndo
151{
153 const sal_Int32 m_nContentIndex;
154
155public:
156 SwUndoDontExpandFormat( const SwPosition& rPos );
157
158 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
159 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
160 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
161};
162
163// helper class to receive changed attribute sets
165{
167 std::unique_ptr<SwUndoFormatAttr> m_pUndo;
168 const bool m_bSaveDrawPt;
169
170public:
171 SwUndoFormatAttrHelper(SwFormat& rFormat, bool bSaveDrawPt = true);
172
173 virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
174
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); }
178};
179
181{
183 std::unique_ptr<SwUndoFormatAttrHelper> helper;
184
185public:
188};
189
190class SwUndoMoveLeftMargin final : public SwUndo, private SwUndRng
191{
192 const std::unique_ptr<SwHistory> m_pHistory;
193 const bool m_bModulus;
194
195public:
196 SwUndoMoveLeftMargin( const SwPaM&, bool bRight, bool bModulus );
197
198 virtual ~SwUndoMoveLeftMargin() override;
199
200 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
201 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
202 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
203
205
206};
207
208class SwUndoDefaultAttr final : public SwUndo
209{
210 std::optional<SfxItemSet> m_oOldSet; // the old attributes
211 std::unique_ptr<SvxTabStopItem> m_pTabStop;
212
213public:
214 // registers at the format and saves old attributes
215 SwUndoDefaultAttr( const SfxItemSet& rOldSet, const SwDoc& rDoc );
216
217 virtual ~SwUndoDefaultAttr() override;
218
219 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
220 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
221};
222
223class SwUndoChangeFootNote final : public SwUndo, private SwUndRng
224{
225 const std::unique_ptr<SwHistory> m_pHistory;
226 const OUString m_Text;
227 const bool m_bEndNote;
228
229public:
230 SwUndoChangeFootNote( const SwPaM& rRange, OUString aText,
231 bool bIsEndNote );
232 virtual ~SwUndoChangeFootNote() override;
233
234 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
235 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
236 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
237
239};
240
241class SwUndoFootNoteInfo final : public SwUndo
242{
243 std::unique_ptr<SwFootnoteInfo> m_pFootNoteInfo;
244
245public:
246 SwUndoFootNoteInfo( const SwFootnoteInfo &rInfo, const SwDoc& rDoc );
247
248 virtual ~SwUndoFootNoteInfo() override;
249
250 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
251 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
252};
253
254class SwUndoEndNoteInfo final : public SwUndo
255{
256 std::unique_ptr<SwEndNoteInfo> m_pEndNoteInfo;
257
258public:
259 SwUndoEndNoteInfo( const SwEndNoteInfo &rInfo, const SwDoc& rDoc );
260
261 virtual ~SwUndoEndNoteInfo() override;
262
263 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
264 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
265};
266
267#endif // INCLUDED_SW_SOURCE_CORE_INC_UNDOATTRIBUTE_HXX
268
269/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< SwUndoFormatAttrHelper > helper
SwDocModifyAndUndoGuard(SwFormat &format)
Definition: unattr.cxx:98
Definition: doc.hxx:197
Base class for various Writer styles.
Definition: format.hxx:47
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:188
SfxItemSet m_AttrSet
SwNodeOffset m_nNodeIndex
void RemoveIdx(SwDoc &rDoc)
Definition: unattr.cxx:899
void redoAttribute(SwPaM &rPam, sw::UndoRedoContext &rContext)
Definition: unattr.cxx:846
const std::unique_ptr< SwHistory > m_pHistory
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:884
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:794
SwUndoAttr(const SwPaM &, SfxItemSet, const SetAttrMode nFlags)
Definition: unattr.cxx:752
void SaveRedlineData(const SwPaM &rPam, bool bInsContent)
Definition: unattr.cxx:774
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:832
OUString m_aChrFormatName
std::unique_ptr< SwRedlineSaveDatas > m_pRedlineSaveData
virtual ~SwUndoAttr() override
Definition: unattr.cxx:770
SwHistory & GetHistory()
std::unique_ptr< SwRedlineData > m_pRedlineData
const SetAttrMode m_nInsertFlags
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1043
const std::unique_ptr< SwHistory > m_pHistory
SwUndoChangeFootNote(const SwPaM &rRange, OUString aText, bool bIsEndNote)
Definition: unattr.cxx:1029
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1055
virtual ~SwUndoChangeFootNote() override
Definition: unattr.cxx:1039
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:1063
SwHistory & GetHistory()
const OUString m_Text
std::optional< SfxItemSet > m_oOldSet
SwUndoDefaultAttr(const SfxItemSet &rOldSet, const SwDoc &rDoc)
Definition: unattr.cxx:940
virtual ~SwUndoDefaultAttr() override
Definition: unattr.cxx:956
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:983
std::unique_ptr< SvxTabStopItem > m_pTabStop
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:960
const sal_Int32 m_nContentIndex
const SwNodeOffset m_nNodeIndex
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1138
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1128
SwUndoDontExpandFormat(const SwPosition &rPos)
Definition: unattr.cxx:1121
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:1148
std::unique_ptr< SwEndNoteInfo > m_pEndNoteInfo
SwUndoEndNoteInfo(const SwEndNoteInfo &rInfo, const SwDoc &rDoc)
Definition: unattr.cxx:1095
virtual ~SwUndoEndNoteInfo() override
Definition: unattr.cxx:1101
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1105
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1113
std::unique_ptr< SwFootnoteInfo > m_pFootNoteInfo
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1087
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1079
virtual ~SwUndoFootNoteInfo() override
Definition: unattr.cxx:1075
SwUndoFootNoteInfo(const SwFootnoteInfo &rInfo, const SwDoc &rDoc)
Definition: unattr.cxx:1069
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
sal_Int32 m_nAnchorContentOffset
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:298
const sal_uInt16 m_nFormatWhich
SwUndoFormatAttr(SfxItemSet &&rOldSet, SwFormat &rFormat, bool bSaveDrawPt)
Definition: unattr.cxx:116
bool RestoreFlyAnchor(::sw::UndoRedoContext &rContext)
Definition: unattr.cxx:422
void SaveFlyAnchor(const SwFormat *pFormat, bool bSaveDrawPt=false)
Definition: unattr.cxx:384
void Init(const SwFormat &rFormat)
Definition: unattr.cxx:149
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:305
virtual SwRewriter GetRewriter() const override
Returns the rewriter for this object.
Definition: unattr.cxx:361
SwFormat * GetFormat(const SwDoc &rDoc)
Definition: unattr.cxx:241
SwNodeOffset m_nNodeIndex
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:183
OUString m_sFormatName
std::optional< SfxItemSet > m_oOldSet
virtual ~SwUndoFormatAttr() override
Definition: unattr.cxx:179
const bool m_bSaveDrawPt
void PutAttr(const SfxPoolItem &rItem, const SwDoc &rDoc)
Definition: unattr.cxx:370
void BroadcastStyleChange()
Definition: unattr.cxx:583
SwUndoFormatResetAttr(SwFormat &rChangedFormat, const std::vector< sal_uInt16 > &rIds)
Definition: unattr.cxx:551
virtual ~SwUndoFormatResetAttr() override
Definition: unattr.cxx:565
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:569
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:575
SwFormat *const m_pChangedFormat
virtual ~SwUndoMoveLeftMargin() override
Definition: unattr.cxx:997
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1001
const std::unique_ptr< SwHistory > m_pHistory
SwUndoMoveLeftMargin(const SwPaM &, bool bRight, bool bModulus)
Definition: unattr.cxx:988
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:1022
SwHistory & GetHistory()
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1012
void SetAttrs(o3tl::sorted_vector< sal_uInt16 > &&rAttrs)
Definition: unattr.cxx:727
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:617
const std::unique_ptr< SwHistory > m_pHistory
SwUndoResetAttr(const SwPaM &, sal_uInt16 nFormatId)
Definition: unattr.cxx:597
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:708
SwHistory & GetHistory()
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:638
virtual ~SwUndoResetAttr() override
Definition: unattr.cxx:613
o3tl::sorted_vector< sal_uInt16 > m_Ids
const sal_uInt16 m_nFormatId
Marks a position in the document model.
Definition: pam.hxx:38
SetAttrMode
Definition: swtypes.hxx:133