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