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>
29 #include <o3tl/sorted_vector.hxx>
30 
31 class SvxTabStopItem;
32 class SwFormat;
33 class SwFootnoteInfo;
34 class SwEndNoteInfo;
35 class SwDoc;
36 
37 class SwUndoAttr : 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  sal_uLong m_nNodeIndex; // Offset: for Redlining
44  const SetAttrMode m_nInsertFlags; // insert flags
45  OUString m_aChrFormatName;
46 
47  void RemoveIdx( SwDoc& rDoc );
48 
49 public:
50  SwUndoAttr( const SwPaM&, const 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 
64 class SwUndoResetAttr : public SwUndo, private SwUndRng
65 {
66  const std::unique_ptr<SwHistory> m_pHistory;
68  const sal_uInt16 m_nFormatId; // Format-Id for Redo
69 
70 public:
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 
80  void SetAttrs( const o3tl::sorted_vector<sal_uInt16> &rAttrs );
81 
83 };
84 
85 class SwUndoFormatAttr : public SwUndo
86 {
87  friend class SwUndoDefaultAttr;
88  OUString m_sFormatName;
89  std::unique_ptr<SfxItemSet> m_pOldSet; // 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.
103  bool RestoreFlyAnchor(::sw::UndoRedoContext & rContext);
104  // --> OD 2008-02-27 #refactorlists# - removed <rAffectedItemSet>
105  void Init( const SwFormat & rFormat );
106 
107 public:
108  // register at the Format and save old attributes
109  // --> OD 2008-02-27 #refactorlists# - removed <rNewSet>
110  SwUndoFormatAttr( const 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#
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 
150 {
152  const sal_Int32 m_nContentIndex;
153 
154 public:
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
163 class SwUndoFormatAttrHelper final : public SwClient
164 {
166  std::unique_ptr<SwUndoFormatAttr> m_pUndo;
167  const bool m_bSaveDrawPt;
168 
169 public:
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 
179 class SwUndoMoveLeftMargin : public SwUndo, private SwUndRng
180 {
181  const std::unique_ptr<SwHistory> m_pHistory;
182  const bool m_bModulus;
183 
184 public:
185  SwUndoMoveLeftMargin( const SwPaM&, bool bRight, bool bModulus );
186 
187  virtual ~SwUndoMoveLeftMargin() override;
188 
189  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
190  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
191  virtual void RepeatImpl( ::sw::RepeatContext & ) override;
192 
194 
195 };
196 
197 class SwUndoDefaultAttr : public SwUndo
198 {
199  std::unique_ptr<SfxItemSet> m_pOldSet; // the old attributes
200  std::unique_ptr<SvxTabStopItem> m_pTabStop;
201 
202 public:
203  // registers at the format and saves old attributes
204  SwUndoDefaultAttr( const SfxItemSet& rOldSet, const SwDoc& rDoc );
205 
206  virtual ~SwUndoDefaultAttr() override;
207 
208  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
209  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
210 };
211 
212 class SwUndoChangeFootNote : public SwUndo, private SwUndRng
213 {
214  const std::unique_ptr<SwHistory> m_pHistory;
215  const OUString m_Text;
216  const bool m_bEndNote;
217 
218 public:
219  SwUndoChangeFootNote( const SwPaM& rRange, const OUString& rText,
220  bool bIsEndNote );
221  virtual ~SwUndoChangeFootNote() override;
222 
223  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
224  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
225  virtual void RepeatImpl( ::sw::RepeatContext & ) override;
226 
228 };
229 
231 {
232  std::unique_ptr<SwFootnoteInfo> m_pFootNoteInfo;
233 
234 public:
235  SwUndoFootNoteInfo( const SwFootnoteInfo &rInfo, const SwDoc& rDoc );
236 
237  virtual ~SwUndoFootNoteInfo() override;
238 
239  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
240  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
241 };
242 
243 class SwUndoEndNoteInfo : public SwUndo
244 {
245  std::unique_ptr<SwEndNoteInfo> m_pEndNoteInfo;
246 
247 public:
248  SwUndoEndNoteInfo( const SwEndNoteInfo &rInfo, const SwDoc& rDoc );
249 
250  virtual ~SwUndoEndNoteInfo() override;
251 
252  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
253  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
254 };
255 
256 #endif // INCLUDED_SW_SOURCE_CORE_INC_UNDOATTRIBUTE_HXX
257 
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwUndoResetAttr(const SwPaM &, sal_uInt16 nFormatId)
Definition: unattr.cxx:533
const sal_uInt16 m_nFormatWhich
SwHistory & GetHistory()
sal_uLong m_nNodeIndex
Marks a position in the document model.
Definition: pam.hxx:35
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:881
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:910
std::unique_ptr< SfxPoolItem > m_pOldItem
const sal_uLong m_nNodeIndex
SwUndoFootNoteInfo(const SwFootnoteInfo &rInfo, const SwDoc &rDoc)
Definition: unattr.cxx:967
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1026
o3tl::sorted_vector< sal_uInt16 > m_Ids
const std::unique_ptr< SwHistory > m_pHistory
SwUndoChangeFootNote(const SwPaM &rRange, const OUString &rText, bool bIsEndNote)
Definition: unattr.cxx:927
SwHistory & GetHistory()
sal_uIntPtr sal_uLong
Definition: doc.hxx:187
const std::unique_ptr< SwHistory > m_pHistory
const sal_uInt16 m_nFormatId
std::unique_ptr< SwRedlineSaveDatas > m_pRedlineSaveData
SfxItemSet m_AttrSet
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:264
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:961
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:985
std::unique_ptr< SvxTabStopItem > m_pTabStop
void SaveFlyAnchor(const SwFormat *pFormat, bool bSaveDrawPt=false)
Definition: unattr.cxx:343
virtual ~SwUndoChangeFootNote() override
Definition: unattr.cxx:937
SwHistory & GetHistory()
const SetAttrMode m_nInsertFlags
void Init(const SwFormat &rFormat)
Definition: unattr.cxx:122
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:517
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1011
SwUndoMoveLeftMargin(const SwPaM &, bool bRight, bool bModulus)
Definition: unattr.cxx:886
void PutAttr(const SfxPoolItem &rItem, const SwDoc &rDoc)
Definition: unattr.cxx:329
SwUndoEndNoteInfo(const SwEndNoteInfo &rInfo, const SwDoc &rDoc)
Definition: unattr.cxx:993
SwUndoFormatAttr(const SfxItemSet &rOldSet, SwFormat &rFormat, bool bSaveDrawPt)
Definition: unattr.cxx:91
std::unique_ptr< SwFootnoteInfo > m_pFootNoteInfo
virtual ~SwUndoEndNoteInfo() override
Definition: unattr.cxx:999
SwUndoFormatAttr * GetUndo() const
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:708
Base class for various Writer styles.
Definition: format.hxx:46
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:257
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
SwUndoDefaultAttr(const SfxItemSet &rOldSet, const SwDoc &rDoc)
Definition: unattr.cxx:840
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:977
bool RestoreFlyAnchor(::sw::UndoRedoContext &rContext)
Definition: unattr.cxx:382
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:920
OUString m_aChrFormatName
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: unattr.cxx:64
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:525
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:154
void SaveRedlineData(const SwPaM &rPam, bool bInsContent)
Definition: unattr.cxx:688
virtual ~SwUndoMoveLeftMargin() override
Definition: unattr.cxx:895
const OUString m_Text
SetAttrMode
Definition: swtypes.hxx:137
std::unique_ptr< SfxItemSet > m_pOldSet
virtual ~SwUndoFormatResetAttr() override
Definition: unattr.cxx:513
SwHistory & GetHistory()
const sal_uInt16 m_nWhichId
SwUndoAttr(const SwPaM &, const SfxItemSet &, const SetAttrMode nFlags)
Definition: unattr.cxx:666
SwUndoFormatResetAttr(SwFormat &rChangedFormat, const sal_uInt16 nWhichId)
Definition: unattr.cxx:501
const std::unique_ptr< SwHistory > m_pHistory
virtual ~SwUndoFootNoteInfo() override
Definition: unattr.cxx:973
std::unique_ptr< SwRedlineData > m_pRedlineData
SwFormat *const m_pChangedFormat
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:746
std::unique_ptr< SwUndoFormatAttr > ReleaseUndo()
std::unique_ptr< SwUndoFormatAttr > m_pUndo
OUString m_sFormatName
std::unique_ptr< SfxItemSet > m_pOldSet
virtual ~SwUndoResetAttr() override
Definition: unattr.cxx:549
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:941
void RemoveIdx(SwDoc &rDoc)
Definition: unattr.cxx:799
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:553
sal_uLong m_nNodeIndex
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:572
std::unique_ptr< SwEndNoteInfo > m_pEndNoteInfo
SwUndoDontExpandFormat(const SwPosition &rPos)
Definition: unattr.cxx:1019
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:953
virtual ~SwUndoAttr() override
Definition: unattr.cxx:684
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:760
const bool m_bSaveDrawPt
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:1048
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1003
SwFormat * GetFormat(const SwDoc &rDoc)
Definition: unattr.cxx:200
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:899
void SetAttrs(const o3tl::sorted_vector< sal_uInt16 > &rAttrs)
Definition: unattr.cxx:641
virtual ~SwUndoFormatAttr() override
Definition: unattr.cxx:150
SwUndoFormatAttrHelper(SwFormat &rFormat, bool bSaveDrawPt=true)
Definition: unattr.cxx:57
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:859
const sal_Int32 m_nContentIndex
virtual SwRewriter GetRewriter() const override
Returns the rewriter for this object.
Definition: unattr.cxx:320
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1037
virtual ~SwUndoDefaultAttr() override
Definition: unattr.cxx:855
const std::unique_ptr< SwHistory > m_pHistory
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:622