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 
46  void RemoveIdx( SwDoc& rDoc );
47 
48 public:
49  SwUndoAttr( const SwPaM&, const SfxItemSet &, const SetAttrMode nFlags );
50  SwUndoAttr( const SwPaM&, const SfxPoolItem&, const SetAttrMode nFlags );
51 
52  virtual ~SwUndoAttr() override;
53 
54  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
55  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
56  virtual void RepeatImpl( ::sw::RepeatContext & ) override;
57 
58  void SaveRedlineData( const SwPaM& rPam, bool bInsContent );
59 
61 };
62 
63 class SwUndoResetAttr : public SwUndo, private SwUndRng
64 {
65  const std::unique_ptr<SwHistory> m_pHistory;
66  std::set<sal_uInt16> m_Ids;
67  const sal_uInt16 m_nFormatId; // Format-Id for Redo
68 
69 public:
70  SwUndoResetAttr( const SwPaM&, sal_uInt16 nFormatId );
71  SwUndoResetAttr( const SwPosition&, sal_uInt16 nFormatId );
72 
73  virtual ~SwUndoResetAttr() override;
74 
75  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
76  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
77  virtual void RepeatImpl( ::sw::RepeatContext & ) override;
78 
79  void SetAttrs( const std::set<sal_uInt16> &rAttrs );
80 
82 };
83 
84 class SwUndoFormatAttr : public SwUndo
85 {
86  friend class SwUndoDefaultAttr;
88  std::unique_ptr<SfxItemSet> m_pOldSet; // old attributes
90  const sal_uInt16 m_nFormatWhich;
91  const bool m_bSaveDrawPt;
92 
93  bool IsFormatInDoc( SwDoc* ); //is the attribute format still in the Doc?
94  void SaveFlyAnchor( 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();
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 );
126  SwFormat* GetFormat( 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:558
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:880
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:909
std::unique_ptr< SfxPoolItem > m_pOldItem
void PutAttr(const SfxPoolItem &rItem)
Definition: unattr.cxx:356
const sal_uLong m_nNodeIndex
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1024
const std::unique_ptr< SwHistory > m_pHistory
SwUndoChangeFootNote(const SwPaM &rRange, const OUString &rText, bool bIsEndNote)
Definition: unattr.cxx:925
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:293
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:959
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:983
std::unique_ptr< SvxTabStopItem > m_pTabStop
virtual ~SwUndoChangeFootNote() override
Definition: unattr.cxx:935
SwHistory & GetHistory()
const SetAttrMode m_nInsertFlags
bool IsFormatInDoc(SwDoc *)
Definition: unattr.cxx:202
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:542
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1009
SwUndoMoveLeftMargin(const SwPaM &, bool bRight, bool bModulus)
Definition: unattr.cxx:885
SwUndoFormatAttr(const SfxItemSet &rOldSet, SwFormat &rFormat, bool bSaveDrawPt)
Definition: unattr.cxx:102
std::unique_ptr< SwFootnoteInfo > m_pFootNoteInfo
virtual ~SwUndoEndNoteInfo() override
Definition: unattr.cxx:997
SwUndoFormatAttr * GetUndo() const
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:717
Base class for various Writer styles.
Definition: format.hxx:43
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:286
SwFormat * m_pFormat
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:975
bool RestoreFlyAnchor(::sw::UndoRedoContext &rContext)
Definition: unattr.cxx:407
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:918
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:550
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:161
void SaveRedlineData(const SwPaM &rPam, bool bInsContent)
Definition: unattr.cxx:697
virtual ~SwUndoMoveLeftMargin() override
Definition: unattr.cxx:894
const OUString m_Text
SetAttrMode
Definition: swtypes.hxx:143
std::unique_ptr< SfxItemSet > m_pOldSet
virtual ~SwUndoFormatResetAttr() override
Definition: unattr.cxx:538
SwHistory & GetHistory()
const sal_uInt16 m_nWhichId
SwUndoEndNoteInfo(const SwEndNoteInfo &rInfo, const SwDoc *pDoc)
Definition: unattr.cxx:991
SwUndoAttr(const SwPaM &, const SfxItemSet &, const SetAttrMode nFlags)
Definition: unattr.cxx:683
SwUndoFormatResetAttr(SwFormat &rChangedFormat, const sal_uInt16 nWhichId)
Definition: unattr.cxx:526
const std::unique_ptr< SwHistory > m_pHistory
virtual ~SwUndoFootNoteInfo() override
Definition: unattr.cxx:971
std::unique_ptr< SwRedlineData > m_pRedlineData
SwFormat *const m_pChangedFormat
void SetAttrs(const std::set< sal_uInt16 > &rAttrs)
Definition: unattr.cxx:666
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:755
std::unique_ptr< SwUndoFormatAttr > ReleaseUndo()
std::unique_ptr< SwUndoFormatAttr > m_pUndo
std::unique_ptr< SfxItemSet > m_pOldSet
virtual ~SwUndoResetAttr() override
Definition: unattr.cxx:574
SwFormat * GetFormat(SwDoc &rDoc)
Definition: unattr.cxx:281
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:939
void RemoveIdx(SwDoc &rDoc)
Definition: unattr.cxx:797
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:578
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:597
std::unique_ptr< SwEndNoteInfo > m_pEndNoteInfo
SwUndoDontExpandFormat(const SwPosition &rPos)
Definition: unattr.cxx:1017
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:951
virtual ~SwUndoAttr() override
Definition: unattr.cxx:693
SwUndoFootNoteInfo(const SwFootnoteInfo &rInfo, const SwDoc *pDoc)
Definition: unattr.cxx:965
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:769
std::set< sal_uInt16 > m_Ids
const bool m_bSaveDrawPt
void SaveFlyAnchor(bool bSaveDrawPt=false)
Definition: unattr.cxx:368
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:1046
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1001
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:898
SwUndoDefaultAttr(const SfxItemSet &rOldSet, const SwDoc *pDoc)
Definition: unattr.cxx:838
virtual ~SwUndoFormatAttr() override
Definition: unattr.cxx:157
SwUndoFormatAttrHelper(SwFormat &rFormat, bool bSaveDrawPt=true)
Definition: unattr.cxx:62
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:857
const sal_Int32 m_nContentIndex
virtual SwRewriter GetRewriter() const override
Returns the rewriter for this object.
Definition: unattr.cxx:345
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unattr.cxx:1035
virtual ~SwUndoDefaultAttr() override
Definition: unattr.cxx:853
const std::unique_ptr< SwHistory > m_pHistory
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unattr.cxx:647