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;
65 #endif
66 };
67 
69 private:
70  std::vector<std::unique_ptr<SwRedlineSaveData, o3tl::default_delete<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, o3tl::default_delete<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 private:
115 };
116 
117 class RepeatContext final
118  : public SfxRepeatTarget
119 {
120 public:
121  RepeatContext(SwDoc & rDoc, SwPaM & rPaM)
122  : m_rDoc(rDoc)
123  , m_pCurrentPaM(& rPaM)
124  , m_bDeleteRepeated(false)
125  { }
126 
127  SwDoc & GetDoc() const { return m_rDoc; }
128 
130  {
131  return *m_pCurrentPaM;
132  }
133 
134 private:
135  friend class ::sw::UndoManager;
136  friend class ::SwUndoDelete;
137 
141 };
142 
143 } // namespace sw
144 
145 class SwUndoFormatColl final : public SwUndo, private SwUndRng
146 {
147  OUString maFormatName;
148  std::unique_ptr<SwHistory> mpHistory;
149  // for correct <ReDo(..)> and <Repeat(..)>
150  // boolean, which indicates that the attributes are reset at the nodes
151  // before the format has been applied.
152  const bool mbReset;
153  // boolean, which indicates that the list attributes had been reset at
154  // the nodes before the format has been applied.
155  const bool mbResetListAttrs;
156 
157  void DoSetFormatColl(SwDoc & rDoc, SwPaM const & rPaM);
158 
159 public:
160  SwUndoFormatColl( const SwPaM&, const SwFormatColl*,
161  const bool bReset,
162  const bool bResetListAttrs );
163  virtual ~SwUndoFormatColl() override;
164 
165  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
166  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
167  virtual void RepeatImpl( ::sw::RepeatContext & ) override;
168 
182  virtual SwRewriter GetRewriter() const override;
183 
184  SwHistory* GetHistory() { return mpHistory.get(); }
185 
186 };
187 
188 class SwUndoSetFlyFormat final : public SwUndo, public SwClient
189 {
190  SwFrameFormat* m_pFrameFormat; // saved FlyFormat
191  const OUString m_DerivedFromFormatName;
192  const OUString m_NewFormatName;
193  std::optional<SfxItemSet> m_oItemSet; // the re-/ set attributes
198 
199  void PutAttr( sal_uInt16 nWhich, const SfxPoolItem* pItem );
200  void SwClientNotify(const SwModify&, const SfxHint&) override;
201  void GetAnchor( SwFormatAnchor& rAnhor, sal_uLong nNode, sal_Int32 nContent );
202 
203 public:
204  SwUndoSetFlyFormat( SwFrameFormat& rFlyFormat, const SwFrameFormat& rNewFrameFormat );
205  virtual ~SwUndoSetFlyFormat() override;
206 
207  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
208  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
209 
210  virtual SwRewriter GetRewriter() const override;
211 };
212 
213 class SwUndoOutlineLeftRight final : public SwUndo, private SwUndRng
214 {
215  short m_nOffset;
216 
217 public:
218  SwUndoOutlineLeftRight( const SwPaM& rPam, short nOffset );
219 
220  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
221  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
222  virtual void RepeatImpl( ::sw::RepeatContext & ) override;
223 };
224 
225 class SwUndoOutlineEdit final : public SwUndo, private SwUndRng
226 {
229 
230 public:
231  SwUndoOutlineEdit(const SwNumRule& rOldRule, const SwNumRule& rNewRule, const SwDoc& rDoc);
232 
233  virtual void UndoImpl(::sw::UndoRedoContext&) override;
234  virtual void RedoImpl(::sw::UndoRedoContext&) override;
235  virtual void RepeatImpl(::sw::RepeatContext&) override;
236 };
237 
238 const int nUndoStringLength = 20;
239 
263 OUString
264 ShortenString(const OUString & rStr, sal_Int32 nLength, const OUString & rFillStr);
284 OUString DenoteSpecialCharacters(const OUString & rStr, bool bQuoted = true);
285 
286 #endif // INCLUDED_SW_SOURCE_CORE_INC_UNDOCORE_HXX
287 
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwNumRule m_aOldNumRule
Definition: UndoCore.hxx:228
void SetSelections(SwFrameFormat *const pSelFormat, SdrMarkList *const pMarkList)
Definition: UndoCore.hxx:99
Marks a position in the document model.
Definition: pam.hxx:35
RndStdIds m_nOldAnchorType
Definition: UndoCore.hxx:196
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:195
sal_uIntPtr sal_uLong
SwPaM & GetRepeatPaM()
Definition: UndoCore.hxx:129
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:1323
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:195
IShellCursorSupplier & GetCursorSupplier()
Definition: UndoCore.hxx:97
void push_back(std::unique_ptr< SwRedlineSaveData, o3tl::default_delete< SwRedlineSaveData >> pNew)
Definition: UndoCore.hxx:78
const OUString m_DerivedFromFormatName
Definition: UndoCore.hxx:191
sal_uInt16 m_nRedlineCount
Definition: UndoCore.hxx:64
SwHistory * GetHistory()
Definition: UndoCore.hxx:184
SwNodeIndex * GetMvSttIdx() const
Definition: UndoCore.hxx:58
SwDoc & GetDoc() const
Definition: UndoCore.hxx:127
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:629
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unoutl.cxx:68
sal_uLong m_nOldNode
Definition: UndoCore.hxx:194
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
const bool mbReset
Definition: UndoCore.hxx:152
Style of a layout element.
Definition: frmfmt.hxx:59
std::optional< SfxItemSet > m_oItemSet
Definition: UndoCore.hxx:193
virtual SwRewriter GetRewriter() const override
Returns the rewriter for this object.
Definition: undobj1.cxx:499
const bool mbResetListAttrs
Definition: UndoCore.hxx:155
OUString DenoteSpecialCharacters(const OUString &rStr, bool bQuoted=true)
Denotes special characters in a string.
Definition: undel.cxx:718
sal_uLong m_nNewNode
Definition: UndoCore.hxx:194
SwFrameFormat * m_pSelFormat
Definition: UndoCore.hxx:113
std::vector< std::unique_ptr< SwRedlineSaveData, o3tl::default_delete< SwRedlineSaveData > > > m_Data
Definition: UndoCore.hxx:70
FlyAnchors.
Definition: fmtanchr.hxx:34
SdrMarkList * m_pMarkList
Definition: UndoCore.hxx:114
Marks a node in the document model.
Definition: ndindex.hxx:31
void GetAnchor(SwFormatAnchor &rAnhor, sal_uLong nNode, sal_Int32 nContent)
Definition: undobj1.cxx:512
void RedlineToDoc(SwPaM const &rPam)
Definition: undobj.cxx:1379
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:112
void PutAttr(sal_uInt16 nWhich, const SfxPoolItem *pItem)
Definition: undobj1.cxx:652
SwUndoFormatColl(const SwPaM &, const SwFormatColl *, const bool bReset, const bool bResetListAttrs)
Definition: unfmco.cxx:26
OUString maFormatName
Definition: UndoCore.hxx:147
SwNumRule m_aNewNumRule
Definition: UndoCore.hxx:227
SwFrameFormat * m_pFrameFormat
Definition: UndoCore.hxx:190
virtual ~SwUndoSetFlyFormat() override
Definition: undobj1.cxx:508
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: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:196
SwNodeIndex * GetMvSttIdx() const
Definition: undobj.hxx:208
bool empty() const
Definition: UndoCore.hxx:76
SwUndoSetFlyFormat(SwFrameFormat &rFlyFormat, const SwFrameFormat &rNewFrameFormat)
Definition: undobj1.cxx:487
RepeatContext(SwDoc &rDoc, SwPaM &rPaM)
Definition: UndoCore.hxx:121
std::unique_ptr< SwHistory > mpHistory
Definition: UndoCore.hxx:148
RndStdIds
SwPaM * m_pCurrentPaM
Definition: UndoCore.hxx:139
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unoutl.cxx:38
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:238
SwComparePosition
Definition: pam.hxx:64
const OUString m_NewFormatName
Definition: UndoCore.hxx:192