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 <set>
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;
67  std::set<sal_uInt16> m_Ids;
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 std::set<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
164 {
165  std::unique_ptr<SwUndoFormatAttr> m_pUndo;
166  const bool m_bSaveDrawPt;
167 
168 public:
169  SwUndoFormatAttrHelper( SwFormat& rFormat, bool bSaveDrawPt = true );
170 
171  virtual void Modify( const SfxPoolItem*, const SfxPoolItem* ) override;
172 
173  SwUndoFormatAttr* GetUndo() const { return m_pUndo.get(); }
174  // release the undo object (so it is not deleted here), and return it
175  std::unique_ptr<SwUndoFormatAttr> ReleaseUndo() { return std::move(m_pUndo); }
176 };
177 
178 class SwUndoMoveLeftMargin : public SwUndo, private SwUndRng
179 {
180  const std::unique_ptr<SwHistory> m_pHistory;
181  const bool m_bModulus;
182 
183 public:
184  SwUndoMoveLeftMargin( const SwPaM&, bool bRight, bool bModulus );
185 
186  virtual ~SwUndoMoveLeftMargin() override;
187 
188  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
189  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
190  virtual void RepeatImpl( ::sw::RepeatContext & ) override;
191 
193 
194 };
195 
196 class SwUndoDefaultAttr : public SwUndo
197 {
198  std::unique_ptr<SfxItemSet> m_pOldSet; // the old attributes
199  std::unique_ptr<SvxTabStopItem> m_pTabStop;
200 
201 public:
202  // registers at the format and saves old attributes
203  SwUndoDefaultAttr( const SfxItemSet& rOldSet, const SwDoc* pDoc );
204 
205  virtual ~SwUndoDefaultAttr() override;
206 
207  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
208  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
209 };
210 
211 class SwUndoChangeFootNote : public SwUndo, private SwUndRng
212 {
213  const std::unique_ptr<SwHistory> m_pHistory;
214  const OUString m_Text;
215  const bool m_bEndNote;
216 
217 public:
218  SwUndoChangeFootNote( const SwPaM& rRange, const OUString& rText,
219  bool bIsEndNote );
220  virtual ~SwUndoChangeFootNote() override;
221 
222  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
223  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
224  virtual void RepeatImpl( ::sw::RepeatContext & ) override;
225 
227 };
228 
230 {
231  std::unique_ptr<SwFootnoteInfo> m_pFootNoteInfo;
232 
233 public:
234  SwUndoFootNoteInfo( const SwFootnoteInfo &rInfo, const SwDoc* pDoc );
235 
236  virtual ~SwUndoFootNoteInfo() override;
237 
238  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
239  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
240 };
241 
242 class SwUndoEndNoteInfo : public SwUndo
243 {
244  std::unique_ptr<SwEndNoteInfo> m_pEndNoteInfo;
245 
246 public:
247  SwUndoEndNoteInfo( const SwEndNoteInfo &rInfo, const SwDoc* pDoc );
248 
249  virtual ~SwUndoEndNoteInfo() override;
250 
251  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
252  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
253 };
254 
255 #endif // INCLUDED_SW_SOURCE_CORE_INC_UNDOATTRIBUTE_HXX
256 
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwUndoResetAttr(const SwPaM &, sal_uInt16 nFormatId)
Definition: unattr.cxx:538
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:887
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:916
std::unique_ptr< SfxPoolItem > m_pOldItem
const sal_uLong m_nNodeIndex
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1031
const std::unique_ptr< SwHistory > m_pHistory
SwUndoChangeFootNote(const SwPaM &rRange, const OUString &rText, bool bIsEndNote)
Definition: unattr.cxx:932
SwHistory & GetHistory()
sal_uIntPtr sal_uLong
Definition: doc.hxx:185
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:269
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:966
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:990
std::unique_ptr< SvxTabStopItem > m_pTabStop
void SaveFlyAnchor(const SwFormat *pFormat, bool bSaveDrawPt=false)
Definition: unattr.cxx:348
virtual ~SwUndoChangeFootNote() override
Definition: unattr.cxx:942
SwHistory & GetHistory()
const SetAttrMode m_nInsertFlags
void Init(const SwFormat &rFormat)
Definition: unattr.cxx:127
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:522
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1016
SwUndoMoveLeftMargin(const SwPaM &, bool bRight, bool bModulus)
Definition: unattr.cxx:892
void PutAttr(const SfxPoolItem &rItem, const SwDoc &rDoc)
Definition: unattr.cxx:334
SwUndoFormatAttr(const SfxItemSet &rOldSet, SwFormat &rFormat, bool bSaveDrawPt)
Definition: unattr.cxx:100
std::unique_ptr< SwFootnoteInfo > m_pFootNoteInfo
virtual ~SwUndoEndNoteInfo() override
Definition: unattr.cxx:1004
SwUndoFormatAttr * GetUndo() const
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:713
Base class for various Writer styles.
Definition: format.hxx:43
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:262
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:982
bool RestoreFlyAnchor(::sw::UndoRedoContext &rContext)
Definition: unattr.cxx:387
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:925
OUString m_aChrFormatName
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:530
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:159
void SaveRedlineData(const SwPaM &rPam, bool bInsContent)
Definition: unattr.cxx:693
virtual ~SwUndoMoveLeftMargin() override
Definition: unattr.cxx:901
const OUString m_Text
SetAttrMode
Definition: swtypes.hxx:143
std::unique_ptr< SfxItemSet > m_pOldSet
virtual ~SwUndoFormatResetAttr() override
Definition: unattr.cxx:518
SwHistory & GetHistory()
const sal_uInt16 m_nWhichId
SwUndoEndNoteInfo(const SwEndNoteInfo &rInfo, const SwDoc *pDoc)
Definition: unattr.cxx:998
SwUndoAttr(const SwPaM &, const SfxItemSet &, const SetAttrMode nFlags)
Definition: unattr.cxx:671
SwUndoFormatResetAttr(SwFormat &rChangedFormat, const sal_uInt16 nWhichId)
Definition: unattr.cxx:506
const std::unique_ptr< SwHistory > m_pHistory
virtual ~SwUndoFootNoteInfo() override
Definition: unattr.cxx:978
std::unique_ptr< SwRedlineData > m_pRedlineData
SwFormat *const m_pChangedFormat
void SetAttrs(const std::set< sal_uInt16 > &rAttrs)
Definition: unattr.cxx:646
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:751
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:554
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:946
void RemoveIdx(SwDoc &rDoc)
Definition: unattr.cxx:804
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:558
sal_uLong m_nNodeIndex
virtual void Modify(const SfxPoolItem *, const SfxPoolItem *) override
Definition: unattr.cxx:68
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:577
std::unique_ptr< SwEndNoteInfo > m_pEndNoteInfo
SwUndoDontExpandFormat(const SwPosition &rPos)
Definition: unattr.cxx:1024
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:958
virtual ~SwUndoAttr() override
Definition: unattr.cxx:689
SwUndoFootNoteInfo(const SwFootnoteInfo &rInfo, const SwDoc *pDoc)
Definition: unattr.cxx:972
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:765
std::set< sal_uInt16 > m_Ids
const bool m_bSaveDrawPt
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:1053
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1008
SwFormat * GetFormat(const SwDoc &rDoc)
Definition: unattr.cxx:205
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:905
SwUndoDefaultAttr(const SfxItemSet &rOldSet, const SwDoc *pDoc)
Definition: unattr.cxx:845
virtual ~SwUndoFormatAttr() override
Definition: unattr.cxx:155
SwUndoFormatAttrHelper(SwFormat &rFormat, bool bSaveDrawPt=true)
Definition: unattr.cxx:62
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:864
const sal_Int32 m_nContentIndex
virtual SwRewriter GetRewriter() const override
Returns the rewriter for this object.
Definition: unattr.cxx:325
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1042
virtual ~SwUndoDefaultAttr() override
Definition: unattr.cxx:860
const std::unique_ptr< SwHistory > m_pHistory
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:627