LibreOffice Module sw (master)  1
UndoCore.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_UNDOCORE_HXX
21 #define INCLUDED_SW_SOURCE_CORE_INC_UNDOCORE_HXX
22 
23 #include <undobj.hxx>
24 #include <calbck.hxx>
25 #include <o3tl/deleter.hxx>
26 #include <rtl/ustring.hxx>
27 #include <redline.hxx>
28 #include <numrule.hxx>
29 
30 #include <memory>
31 #include <vector>
32 
33 class SfxItemSet;
34 class SwFormatColl;
35 class SwFormatAnchor;
36 class SdrMarkList;
37 class SwUndoDelete;
38 
39 namespace sw {
40  class UndoManager;
41  class IShellCursorSupplier;
42 }
43 
44 class SwRedlineSaveData final : public SwUndRng, public SwRedlineData, private SwUndoSaveSection
45 {
46 public:
48  SwComparePosition eCmpPos,
49  const SwPosition& rSttPos,
50  const SwPosition& rEndPos,
51  SwRangeRedline& rRedl,
52  bool bCopyNext );
53 
55 
56  void RedlineToDoc( SwPaM const & rPam );
57 
59  {
61  }
62 
63 #if OSL_DEBUG_LEVEL > 0
64  sal_uInt16 m_nRedlineCount;
66 #endif
67 };
68 
70 private:
71  std::vector<std::unique_ptr<SwRedlineSaveData>> m_Data;
72 
73 public:
74  SwRedlineSaveDatas() : m_Data() {}
75 
76  void clear() { m_Data.clear(); }
77  bool empty() const { return m_Data.empty(); }
78  size_t size() const { return m_Data.size(); }
79  void push_back(std::unique_ptr<SwRedlineSaveData> pNew) { m_Data.push_back(std::move(pNew)); }
80  const SwRedlineSaveData& operator[](size_t const nIdx) const { return *m_Data[ nIdx ]; }
81  SwRedlineSaveData& operator[](size_t const nIdx) { return *m_Data[ nIdx ]; }
82 };
83 
84 namespace sw {
85 class UndoRedoContext final
86  : public SfxUndoContext
87 {
88 public:
89  UndoRedoContext(SwDoc & rDoc, IShellCursorSupplier & rCursorSupplier)
90  : m_rDoc(rDoc)
91  , m_rCursorSupplier(rCursorSupplier)
92  , m_pSelFormat(nullptr)
93  , m_pMarkList(nullptr)
94  { }
95 
96  SwDoc & GetDoc() const { return m_rDoc; }
97 
99 
100  void SetSelections(SwFrameFormat *const pSelFormat, SdrMarkList *const pMarkList)
101  {
102  m_pSelFormat = pSelFormat;
103  m_pMarkList = pMarkList;
104  }
105  void GetSelections(SwFrameFormat *& o_rpSelFormat, SdrMarkList *& o_rpMarkList)
106  {
107  o_rpSelFormat = m_pSelFormat;
108  o_rpMarkList = m_pMarkList;
109  }
110 
111  void SetUndoOffset(size_t nUndoOffset) { m_nUndoOffset = nUndoOffset; }
112 
113  size_t GetUndoOffset() override { return m_nUndoOffset; }
114 
115 private:
120  size_t m_nUndoOffset = 0;
121 };
122 
123 class RepeatContext final
124  : public SfxRepeatTarget
125 {
126 public:
127  RepeatContext(SwDoc & rDoc, SwPaM & rPaM)
128  : m_rDoc(rDoc)
129  , m_pCurrentPaM(& rPaM)
130  , m_bDeleteRepeated(false)
131  { }
132 
133  SwDoc & GetDoc() const { return m_rDoc; }
134 
136  {
137  return *m_pCurrentPaM;
138  }
139 
140 private:
141  friend class ::sw::UndoManager;
142  friend class ::SwUndoDelete;
143 
147 };
148 
149 } // namespace sw
150 
151 class SwUndoFormatColl final : public SwUndo, private SwUndRng
152 {
153  OUString maFormatName;
154  std::unique_ptr<SwHistory> mpHistory;
155  // for correct <ReDo(..)> and <Repeat(..)>
156  // boolean, which indicates that the attributes are reset at the nodes
157  // before the format has been applied.
158  const bool mbReset;
159  // boolean, which indicates that the list attributes had been reset at
160  // the nodes before the format has been applied.
161  const bool mbResetListAttrs;
162 
163  void DoSetFormatColl(SwDoc & rDoc, SwPaM const & rPaM);
164 
165 public:
166  SwUndoFormatColl( const SwPaM&, const SwFormatColl*,
167  const bool bReset,
168  const bool bResetListAttrs );
169  virtual ~SwUndoFormatColl() override;
170 
171  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
172  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
173  virtual void RepeatImpl( ::sw::RepeatContext & ) override;
174 
188  virtual SwRewriter GetRewriter() const override;
189 
190  SwHistory* GetHistory() { return mpHistory.get(); }
191 
192 };
193 
194 class SwUndoSetFlyFormat final : public SwUndo, public SwClient
195 {
196  SwFrameFormat* m_pFrameFormat; // saved FlyFormat
197  const OUString m_DerivedFromFormatName;
198  const OUString m_NewFormatName;
199  std::optional<SfxItemSet> m_oItemSet; // the re-/ set attributes
204 
205  void PutAttr( sal_uInt16 nWhich, const SfxPoolItem* pItem );
206  void SwClientNotify(const SwModify&, const SfxHint&) override;
207  void GetAnchor( SwFormatAnchor& rAnhor, SwNodeOffset nNode, sal_Int32 nContent );
208 
209 public:
210  SwUndoSetFlyFormat( SwFrameFormat& rFlyFormat, const SwFrameFormat& rNewFrameFormat );
211  virtual ~SwUndoSetFlyFormat() override;
212 
213  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
214  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
215 
216  virtual SwRewriter GetRewriter() const override;
217 };
218 
219 class SwUndoOutlineLeftRight final : public SwUndo, private SwUndRng
220 {
221  short m_nOffset;
222 
223 public:
224  SwUndoOutlineLeftRight( const SwPaM& rPam, short nOffset );
225 
226  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
227  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
228  virtual void RepeatImpl( ::sw::RepeatContext & ) override;
229 };
230 
231 class SwUndoOutlineEdit final : public SwUndo, private SwUndRng
232 {
235 
236 public:
237  SwUndoOutlineEdit(const SwNumRule& rOldRule, const SwNumRule& rNewRule, const SwDoc& rDoc);
238 
239  virtual void UndoImpl(::sw::UndoRedoContext&) override;
240  virtual void RedoImpl(::sw::UndoRedoContext&) override;
241  virtual void RepeatImpl(::sw::RepeatContext&) override;
242 };
243 
244 const int nUndoStringLength = 20;
245 
269 OUString
270 ShortenString(const OUString & rStr, sal_Int32 nLength, const OUString & rFillStr);
290 OUString DenoteSpecialCharacters(const OUString & rStr, bool bQuoted = true);
291 
292 #endif // INCLUDED_SW_SOURCE_CORE_INC_UNDOCORE_HXX
293 
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwNumRule m_aOldNumRule
Definition: UndoCore.hxx:234
void SetSelections(SwFrameFormat *const pSelFormat, SdrMarkList *const pMarkList)
Definition: UndoCore.hxx:100
Marks a position in the document model.
Definition: pam.hxx:36
RndStdIds m_nOldAnchorType
Definition: UndoCore.hxx:202
UndoRedoContext(SwDoc &rDoc, IShellCursorSupplier &rCursorSupplier)
Definition: UndoCore.hxx:89
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unfmco.cxx:55
size_t size() const
Definition: UndoCore.hxx:78
sal_Int32 m_nNewContent
Definition: UndoCore.hxx:201
SwPaM & GetRepeatPaM()
Definition: UndoCore.hxx:135
Definition: doc.hxx:188
SwUndoOutlineLeftRight(const SwPaM &rPam, short nOffset)
Definition: unoutl.cxx:26
SwRedlineSaveData(SwComparePosition eCmpPos, const SwPosition &rSttPos, const SwPosition &rEndPos, SwRangeRedline &rRedl, bool bCopyNext)
Definition: undobj.cxx:1321
Dialog to specify the properties of date form field.
virtual ~SwUndoFormatColl() override
Definition: unfmco.cxx:41
SwRedlineSaveData & operator[](size_t const nIdx)
Definition: UndoCore.hxx:81
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unoutl.cxx:32
SwUndoOutlineEdit(const SwNumRule &rOldRule, const SwNumRule &rNewRule, const SwDoc &rDoc)
Definition: unoutl.cxx:50
const SwRedlineSaveData & operator[](size_t const nIdx) const
Definition: UndoCore.hxx:80
sal_Int32 m_nOldContent
Definition: UndoCore.hxx:201
IShellCursorSupplier & GetCursorSupplier()
Definition: UndoCore.hxx:98
const OUString m_DerivedFromFormatName
Definition: UndoCore.hxx:197
sal_uInt16 m_nRedlineCount
Definition: UndoCore.hxx:64
SwHistory * GetHistory()
Definition: UndoCore.hxx:190
SwNodeIndex * GetMvSttIdx() const
Definition: UndoCore.hxx:58
SwDoc & GetDoc() const
Definition: UndoCore.hxx:133
SwDoc & GetDoc() const
Definition: UndoCore.hxx:96
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unoutl.cxx:58
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: undobj1.cxx:629
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unoutl.cxx:68
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:137
const bool mbReset
Definition: UndoCore.hxx:158
Style of a layout element.
Definition: frmfmt.hxx:59
std::optional< SfxItemSet > m_oItemSet
Definition: UndoCore.hxx:199
virtual SwRewriter GetRewriter() const override
Returns the rewriter for this object.
Definition: undobj1.cxx:499
const bool mbResetListAttrs
Definition: UndoCore.hxx:161
size_t GetUndoOffset() override
Definition: UndoCore.hxx:113
OUString DenoteSpecialCharacters(const OUString &rStr, bool bQuoted=true)
Denotes special characters in a string.
Definition: undel.cxx:715
SwFrameFormat * m_pSelFormat
Definition: UndoCore.hxx:118
FlyAnchors.
Definition: fmtanchr.hxx:34
SdrMarkList * m_pMarkList
Definition: UndoCore.hxx:119
Marks a node in the document model.
Definition: ndindex.hxx:32
SwNodeOffset m_nNewNode
Definition: UndoCore.hxx:200
void push_back(std::unique_ptr< SwRedlineSaveData > pNew)
Definition: UndoCore.hxx:79
void RedlineToDoc(SwPaM const &rPam)
Definition: undobj.cxx:1378
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unoutl.cxx:63
The Undo actions need to create new Shell cursors.
IShellCursorSupplier & m_rCursorSupplier
Definition: UndoCore.hxx:117
void PutAttr(sal_uInt16 nWhich, const SfxPoolItem *pItem)
Definition: undobj1.cxx:652
void GetAnchor(SwFormatAnchor &rAnhor, SwNodeOffset nNode, sal_Int32 nContent)
Definition: undobj1.cxx:512
SwUndoFormatColl(const SwPaM &, const SwFormatColl *, const bool bReset, const bool bResetListAttrs)
Definition: unfmco.cxx:26
OUString maFormatName
Definition: UndoCore.hxx:153
std::vector< std::unique_ptr< SwRedlineSaveData > > m_Data
Definition: UndoCore.hxx:71
SwNumRule m_aNewNumRule
Definition: UndoCore.hxx:233
SwFrameFormat * m_pFrameFormat
Definition: UndoCore.hxx:196
virtual ~SwUndoSetFlyFormat() override
Definition: undobj1.cxx:508
void GetSelections(SwFrameFormat *&o_rpSelFormat, SdrMarkList *&o_rpMarkList)
Definition: UndoCore.hxx:105
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unfmco.cxx:45
void DoSetFormatColl(SwDoc &rDoc, SwPaM const &rPaM)
Definition: unfmco.cxx:67
OUString ShortenString(const OUString &rStr, sal_Int32 nLength, const OUString &rFillStr)
Shortens a string to a maximum length.
Definition: undobj.cxx:1534
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unoutl.cxx:44
void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: undobj1.cxx:705
RndStdIds m_nNewAnchorType
Definition: UndoCore.hxx:202
SwNodeIndex * GetMvSttIdx() const
Definition: undobj.hxx:209
bool empty() const
Definition: UndoCore.hxx:77
SwUndoSetFlyFormat(SwFrameFormat &rFlyFormat, const SwFrameFormat &rNewFrameFormat)
Definition: undobj1.cxx:487
RepeatContext(SwDoc &rDoc, SwPaM &rPaM)
Definition: UndoCore.hxx:127
std::unique_ptr< SwHistory > mpHistory
Definition: UndoCore.hxx:154
RndStdIds
SwPaM * m_pCurrentPaM
Definition: UndoCore.hxx:145
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unoutl.cxx:38
void SetUndoOffset(size_t nUndoOffset)
Definition: UndoCore.hxx:111
SwNodeOffset m_nOldNode
Definition: UndoCore.hxx:200
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unfmco.cxx:62
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: undobj1.cxx:559
virtual SwRewriter GetRewriter() const override
Returns the rewriter for this undo object.
Definition: unfmco.cxx:78
const int nUndoStringLength
Definition: UndoCore.hxx:244
SwComparePosition
Definition: pam.hxx:65
const OUString m_NewFormatName
Definition: UndoCore.hxx:198