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
32class SfxItemSet;
33class SwFormatColl;
34class SwFormatAnchor;
35class SdrMarkList;
36class SwUndoDelete;
37
38namespace sw {
39 class UndoManager;
40 class IShellCursorSupplier;
41}
42
43class SwRedlineSaveData final : public SwUndRng, public SwRedlineData, private SwUndoSaveSection
44{
45public:
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
57 const SwNodeIndex* GetMvSttIdx() const
58 {
60 }
61
62#if OSL_DEBUG_LEVEL > 0
63 sal_uInt16 m_nRedlineCount;
65#endif
66};
67
69private:
70 std::vector<std::unique_ptr<SwRedlineSaveData>> m_Data;
71
72public:
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
83namespace sw {
84class UndoRedoContext final
85 : public SfxUndoContext
86{
87public:
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
114private:
119 size_t m_nUndoOffset = 0;
120};
121
122class RepeatContext final
123 : public SfxRepeatTarget
124{
125public:
126 RepeatContext(SwDoc & rDoc, SwPaM & rPaM)
127 : m_rDoc(rDoc)
128 , m_pCurrentPaM(& rPaM)
129 , m_bDeleteRepeated(false)
130 { }
131
132 SwDoc & GetDoc() const { return m_rDoc; }
133
135 {
136 return *m_pCurrentPaM;
137 }
138
139private:
140 friend class ::sw::UndoManager;
141 friend class ::SwUndoDelete;
142
146};
147
148} // namespace sw
149
150class 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.
161
162 void DoSetFormatColl(SwDoc & rDoc, SwPaM const & rPaM);
163
164public:
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
193class SwUndoSetFlyFormat final : public SwUndo, public SwClient
194{
195 SwFrameFormat* m_pFrameFormat; // saved FlyFormat
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
208public:
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
218class SwUndoOutlineLeftRight final : public SwUndo, private SwUndRng
219{
221
222public:
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
230class SwUndoOutlineEdit final : public SwUndo, private SwUndRng
231{
234
235public:
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
243const int nUndoStringLength = 20;
244
268OUString
269ShortenString(const OUString & rStr, sal_Int32 nLength, const OUString & rFillStr);
289OUString 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: */
OUString DenoteSpecialCharacters(const OUString &rStr, bool bQuoted=true)
Denotes special characters in a string.
Definition: undel.cxx:719
const int nUndoStringLength
Definition: UndoCore.hxx:243
OUString ShortenString(const OUString &rStr, sal_Int32 nLength, const OUString &rFillStr)
Shortens a string to a maximum length.
Definition: undobj.cxx:1537
Definition: doc.hxx:192
FlyAnchors.
Definition: fmtanchr.hxx:37
Style of a layout element.
Definition: frmfmt.hxx:62
Marks a node in the document model.
Definition: ndindex.hxx:31
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:187
const SwNodeIndex * GetMvSttIdx() const
Definition: UndoCore.hxx:57
sal_uInt16 m_nRedlineCount
Definition: UndoCore.hxx:63
void RedlineToDoc(SwPaM const &rPam)
Definition: undobj.cxx:1382
SwRedlineSaveData(SwComparePosition eCmpPos, const SwPosition &rSttPos, const SwPosition &rEndPos, SwRangeRedline &rRedl, bool bCopyNext)
Definition: undobj.cxx:1325
bool empty() const
Definition: UndoCore.hxx:76
const SwRedlineSaveData & operator[](size_t const nIdx) const
Definition: UndoCore.hxx:79
void push_back(std::unique_ptr< SwRedlineSaveData > pNew)
Definition: UndoCore.hxx:78
std::vector< std::unique_ptr< SwRedlineSaveData > > m_Data
Definition: UndoCore.hxx:70
size_t size() const
Definition: UndoCore.hxx:77
SwRedlineSaveData & operator[](size_t const nIdx)
Definition: UndoCore.hxx:80
void DoSetFormatColl(SwDoc &rDoc, SwPaM const &rPaM)
Definition: unfmco.cxx:67
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unfmco.cxx:55
virtual ~SwUndoFormatColl() override
Definition: unfmco.cxx:41
const bool mbReset
Definition: UndoCore.hxx:157
std::unique_ptr< SwHistory > mpHistory
Definition: UndoCore.hxx:153
virtual SwRewriter GetRewriter() const override
Returns the rewriter for this undo object.
Definition: unfmco.cxx:78
SwHistory * GetHistory()
Definition: UndoCore.hxx:189
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unfmco.cxx:62
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unfmco.cxx:45
const bool mbResetListAttrs
Definition: UndoCore.hxx:160
SwUndoFormatColl(const SwPaM &, const SwFormatColl *, const bool bReset, const bool bResetListAttrs)
Definition: unfmco.cxx:26
OUString maFormatName
Definition: UndoCore.hxx:152
SwNumRule m_aNewNumRule
Definition: UndoCore.hxx:232
SwUndoOutlineEdit(const SwNumRule &rOldRule, const SwNumRule &rNewRule, const SwDoc &rDoc)
Definition: unoutl.cxx:50
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unoutl.cxx:63
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unoutl.cxx:68
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unoutl.cxx:58
SwNumRule m_aOldNumRule
Definition: UndoCore.hxx:233
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unoutl.cxx:38
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unoutl.cxx:32
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unoutl.cxx:44
SwUndoOutlineLeftRight(const SwPaM &rPam, short nOffset)
Definition: unoutl.cxx:26
const SwNodeIndex * GetMvSttIdx() const
Definition: undobj.hxx:209
sal_Int32 m_nNewContent
Definition: UndoCore.hxx:200
std::optional< SfxItemSet > m_oItemSet
Definition: UndoCore.hxx:198
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: undobj1.cxx:626
RndStdIds m_nOldAnchorType
Definition: UndoCore.hxx:201
sal_Int32 m_nOldContent
Definition: UndoCore.hxx:200
void GetAnchor(SwFormatAnchor &rAnhor, SwNodeOffset nNode, sal_Int32 nContent)
Definition: undobj1.cxx:509
virtual ~SwUndoSetFlyFormat() override
Definition: undobj1.cxx:505
virtual SwRewriter GetRewriter() const override
Returns the rewriter for this object.
Definition: undobj1.cxx:496
void PutAttr(sal_uInt16 nWhich, const SfxPoolItem *pItem)
Definition: undobj1.cxx:649
const OUString m_NewFormatName
Definition: UndoCore.hxx:197
SwFrameFormat * m_pFrameFormat
Definition: UndoCore.hxx:195
const OUString m_DerivedFromFormatName
Definition: UndoCore.hxx:196
SwUndoSetFlyFormat(SwFrameFormat &rFlyFormat, const SwFrameFormat &rNewFrameFormat)
Definition: undobj1.cxx:484
SwNodeOffset m_nNewNode
Definition: UndoCore.hxx:199
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: undobj1.cxx:556
RndStdIds m_nNewAnchorType
Definition: UndoCore.hxx:201
SwNodeOffset m_nOldNode
Definition: UndoCore.hxx:199
void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: undobj1.cxx:702
The Undo actions need to create new Shell cursors.
SwPaM * m_pCurrentPaM
Definition: UndoCore.hxx:144
RepeatContext(SwDoc &rDoc, SwPaM &rPaM)
Definition: UndoCore.hxx:126
SwDoc & GetDoc() const
Definition: UndoCore.hxx:132
SwPaM & GetRepeatPaM()
Definition: UndoCore.hxx:134
SwFrameFormat * m_pSelFormat
Definition: UndoCore.hxx:117
SwDoc & GetDoc() const
Definition: UndoCore.hxx:95
IShellCursorSupplier & m_rCursorSupplier
Definition: UndoCore.hxx:116
IShellCursorSupplier & GetCursorSupplier()
Definition: UndoCore.hxx:97
void GetSelections(SwFrameFormat *&o_rpSelFormat, SdrMarkList *&o_rpMarkList)
Definition: UndoCore.hxx:104
size_t GetUndoOffset() override
Definition: UndoCore.hxx:112
UndoRedoContext(SwDoc &rDoc, IShellCursorSupplier &rCursorSupplier)
Definition: UndoCore.hxx:88
void SetUndoOffset(size_t nUndoOffset)
Definition: UndoCore.hxx:110
SdrMarkList * m_pMarkList
Definition: UndoCore.hxx:118
void SetSelections(SwFrameFormat *const pSelFormat, SdrMarkList *const pMarkList)
Definition: UndoCore.hxx:99
Dialog to specify the properties of date form field.
SwComparePosition
Definition: pam.hxx:109
Marks a position in the document model.
Definition: pam.hxx:37
RndStdIds