LibreOffice Module sw (master) 1
undobj.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#ifndef INCLUDED_SW_INC_UNDOBJ_HXX
20#define INCLUDED_SW_INC_UNDOBJ_HXX
21
22#include <vector>
23#include <memory>
24
25#include <svl/undo.hxx>
26#include "SwRewriter.hxx"
27#include "swundo.hxx"
28#include "nodeoffset.hxx"
29#include "ndindex.hxx"
31#include <optional>
32
33class SwHistory;
34class SwPaM;
35struct SwPosition;
36class SwDoc;
38class SwFrameFormat;
39class SwFormatAnchor;
40class SwNode;
41class SwNodeRange;
42class SwRedlineData;
44enum class RedlineFlags;
45enum class RndStdIds;
46typedef struct _xmlTextWriter* xmlTextWriterPtr;
47
48namespace sw {
49 class UndoRedoContext;
50 class RepeatContext;
51}
52
53class SwUndo
54 : public SfxUndoAction
55{
60
61protected:
63 mutable std::optional<OUString> maComment;
64
65 static void RemoveIdxFromSection( SwDoc&, SwNodeOffset nSttIdx, const SwNodeOffset* pEndIdx = nullptr );
66 static void RemoveIdxFromRange( SwPaM& rPam, bool bMoveNext );
67 static void RemoveIdxRel( SwNodeOffset, const SwPosition& );
68
69 static bool CanRedlineGroup( SwRedlineSaveDatas& rCurr,
70 const SwRedlineSaveDatas& rCheck,
71 bool bCurrIsEnd );
72
78 virtual SwRewriter GetRewriter() const;
79
80 // the 4 methods that derived classes have to override
81 // base implementation does nothing
82 virtual void RepeatImpl( ::sw::RepeatContext & );
83public: // should not be public, but ran into trouble in untbl.cxx
84 virtual void UndoImpl( ::sw::UndoRedoContext & ) = 0;
85 virtual void RedoImpl( ::sw::UndoRedoContext & ) = 0;
86
87private:
89 static ViewShellId CreateViewShellId(const SwDoc* pDoc);
90 // SfxUndoAction
91 virtual void Undo() override;
92 virtual void Redo() override;
93 virtual void UndoWithContext(SfxUndoContext &) override;
94 virtual void RedoWithContext(SfxUndoContext &) override;
95 virtual void Repeat(SfxRepeatTarget &) override;
96 virtual bool CanRepeat(SfxRepeatTarget &) const override;
97
98public:
99 SwUndo(SwUndoId const nId, const SwDoc* pDoc);
100 virtual ~SwUndo() override;
101
102 SwUndoId GetId() const { return m_nId; }
103
113 virtual OUString GetComment() const override;
114
116 ViewShellId GetViewShellId() const override;
117
118 // UndoObject remembers which mode was turned on.
119 // In Undo/Redo/Repeat this remembered mode is switched on.
122
123 bool IsDelBox() const;
124
125 // Save and set Redline data.
126 static bool FillSaveData( const SwPaM& rRange, SwRedlineSaveDatas& rSData,
127 bool bDelRange = true, bool bCopyNext = true );
128 static bool FillSaveDataForFormat( const SwPaM& , SwRedlineSaveDatas& );
129 static void SetSaveData( SwDoc& rDoc, SwRedlineSaveDatas& rSData );
130 static bool HasHiddenRedlines( const SwRedlineSaveDatas& rSData );
132};
133
134enum class DelContentType : sal_uInt16
135{
136 Ftn = 0x01,
137 Fly = 0x02,
138 Bkm = 0x08,
139 AllMask = 0x0b,
140 Replace = 0x10,
141 WriterfilterHack = 0x20,
143 CheckNoCntnt = 0x80,
144};
145namespace o3tl {
146 template<> struct typed_flags<DelContentType> : is_typed_flags<DelContentType, 0xfb> {};
147}
148
150bool IsDestroyFrameAnchoredAtChar(SwPosition const & rAnchorPos,
151 SwPosition const & rStart, SwPosition const & rEnd,
152 DelContentType const nDelContentType = DelContentType::AllMask);
154bool IsSelectFrameAnchoredAtPara(SwPosition const & rAnchorPos,
155 SwPosition const & rStart, SwPosition const & rEnd,
156 DelContentType const nDelContentType = DelContentType::AllMask);
158bool IsFlySelectedByCursor(SwDoc const & rDoc,
159 SwPosition const & rStart, SwPosition const & rEnd);
160
161// This class has to be inherited into an Undo-object if it saves content
162// for Redo/Undo...
164{
165protected:
166
167 std::unique_ptr<SwHistory> m_pHistory;
168
169 // Needed for deletion of content. For Redo content is moved into the
170 // UndoNodesArray. These methods always create a new node to insert
171 // content. So the attributes do not get expanded.
172 // MoveTo: moves from the NodesArray into the UndoNodesArray.
173 // MoveFrom: moves from the UndoNodesArray into the NodesArray.
174 static void MoveToUndoNds( SwPaM& rPam,
175 SwNodeIndex* pNodeIdx,
176 SwNodeOffset* pEndNdIdx = nullptr );
177 static void MoveFromUndoNds( SwDoc& rDoc, SwNodeOffset nNodeIdx,
178 SwPosition& rInsPos,
179 const SwNodeOffset* pEndNdIdx = nullptr,
180 bool bForceCreateFrames = false);
181
182 // These two methods move the SPoint back/forth from PaM. With it
183 // a range can be spanned for Undo/Redo. (In this case the SPoint
184 // is before the manipulated range!!)
185 // The flag indicates if there is content before the SPoint.
186 static bool MovePtBackward( SwPaM& rPam );
187 static void MovePtForward( SwPaM& rPam, bool bMvBkwrd );
188
189 // Before moving stuff into UndoNodes-Array care has to be taken that
190 // the content-bearing attributes are removed from the nodes-array.
191 void DelContentIndex( const SwPosition& pMark, const SwPosition& pPoint,
192 DelContentType nDelContentType = DelContentType::AllMask );
193
194public:
196 virtual ~SwUndoSaveContent() COVERITY_NOEXCEPT_FALSE;
197 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
198};
199
200// Save a complete section in nodes-array.
202{
203 std::optional<SwNodeIndex> m_oMovedStart;
204 std::unique_ptr<SwRedlineSaveDatas> m_pRedlineSaveData;
205 SwNodeOffset m_nMoveLen; // Index into UndoNodes-Array.
207
208protected:
209 const SwNodeIndex* GetMvSttIdx() const { return m_oMovedStart ? &*m_oMovedStart : nullptr; }
210 SwNodeOffset GetMvNodeCnt() const { return m_nMoveLen; }
211
212public:
215
216 void SaveSection( const SwNodeIndex& rSttIdx );
217 void SaveSection(const SwNodeRange& rRange, bool bExpandNodes = true);
218 void RestoreSection( SwDoc* pDoc, SwNodeIndex* pIdx, sal_uInt16 nSectType );
219 void RestoreSection(SwDoc* pDoc, const SwNode& rInsPos, bool bForceCreateFrames = false);
220
221 const SwHistory* GetHistory() const { return m_pHistory.get(); }
222 SwHistory* GetHistory() { return m_pHistory.get(); }
223 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
224};
225
226// This class saves the PaM as sal_uInt16's and is able to restore it
227// into a PaM.
229{
230public:
232 sal_Int32 m_nSttContent, m_nEndContent;
233
234 SwUndRng();
235 SwUndRng( const SwPaM& );
236
237 void SetValues( const SwPaM& rPam );
238 void SetPaM( SwPaM&, bool bCorrToContent = false ) const;
239 SwPaM & AddUndoRedoPaM(
240 ::sw::UndoRedoContext &, bool const bCorrToContent = false) const;
241};
242
244
245namespace sw {
246
247std::optional<std::vector<SwFrameFormat*>>
248GetFlysAnchoredAt(SwDoc & rDoc, SwNodeOffset nSttNode);
249
250}
251
252// base class for insertion of Document, Glossaries and Copy
253class SwUndoInserts : public SwUndo, public SwUndRng, private SwUndoSaveContent
254{
255 SwTextFormatColl *m_pTextFormatColl, *m_pLastNodeColl;
256 std::optional<std::vector<SwFrameFormat*>> m_pFrameFormats;
257 std::vector< std::shared_ptr<SwUndoInsLayFormat> > m_FlyUndos;
258 std::unique_ptr<SwRedlineData> m_pRedlineData;
262 std::optional<SwNodeIndex> m_oUndoNodeIndex;
263 sal_uInt16 m_nSetPos; // Start in the history list.
264
265protected:
266 SwUndoInserts( SwUndoId nUndoId, const SwPaM& );
267public:
268 virtual ~SwUndoInserts() override;
269
270 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
271 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
272 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
273
274 // Set destination range after reading.
275 void SetInsertRange( const SwPaM&, bool bScanFlys = true,
276 SwNodeOffset nDeleteTextNodes = SwNodeOffset(1));
277
278 static bool IsCreateUndoForNewFly(SwFormatAnchor const& rAnchor,
279 SwNodeOffset const nStartNode, SwNodeOffset const nEndNode);
280 std::vector<SwFrameFormat*> * GetFlysAnchoredAt() { return m_pFrameFormats ? &*m_pFrameFormats : nullptr; }
281
282 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
283};
284
286class SwUndoInsDoc final : public SwUndoInserts
287{
288public:
289 SwUndoInsDoc( const SwPaM& );
290};
291
292class SwUndoCpyDoc final : public SwUndoInserts
293{
294public:
295 SwUndoCpyDoc( const SwPaM& );
296};
297
299{
300protected:
301 SwFrameFormat* m_pFrameFormat; // The saved FlyFormat.
303 sal_Int32 m_nContentPos; // Page at/in paragraph.
305 bool m_bDelFormat; // Delete saved format.
306
307 void InsFly(::sw::UndoRedoContext & rContext, bool bShowSel = true);
308 void DelFly( SwDoc* );
309
310 SwUndoFlyBase( SwFrameFormat* pFormat, SwUndoId nUndoId );
311
314
315public:
316 virtual ~SwUndoFlyBase() override;
317 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
318
319};
320
322{
324 sal_Int32 mnCursorSaveIndexPos; // for undo
325public:
326 SwUndoInsLayFormat( SwFrameFormat* pFormat, SwNodeOffset nNodeIdx, sal_Int32 nCntIdx );
327
328 virtual ~SwUndoInsLayFormat() override;
329
330 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
331 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
332 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
333
334 virtual OUString GetComment() const override;
335
336};
337
339{
341public:
343
344 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
345 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
346
347 void RedoForRollback();
348
349 void ChgShowSel( bool bNew ) { m_bShowSelFrame = bNew; }
350
351 virtual SwRewriter GetRewriter() const override;
352
353};
354
355#endif
356
357/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: doc.hxx:197
FlyAnchors.
Definition: fmtanchr.hxx:37
Style of a layout element.
Definition: frmfmt.hxx:72
Marks a node in the document model.
Definition: ndindex.hxx:31
Base class of the Writer document model elements.
Definition: node.hxx:98
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:188
Represents the style of a paragraph.
Definition: fmtcol.hxx:61
SwNodeOffset m_nEndNode
Definition: undobj.hxx:231
sal_Int32 m_nEndContent
Definition: undobj.hxx:232
void ChgShowSel(bool bNew)
Definition: undobj.hxx:349
RndStdIds m_nRndId
Definition: undobj.hxx:304
SwNodeOffset m_nNodePagePos
Definition: undobj.hxx:302
SwFrameFormat * m_pFrameFormat
Definition: undobj.hxx:301
bool m_bDelFormat
Definition: undobj.hxx:305
SwNodeOffset GetMvNodeCnt() const
Definition: undobj.hxx:313
sal_Int32 m_nContentPos
Definition: undobj.hxx:303
const SwNodeIndex * GetMvSttIdx() const
Definition: undobj.hxx:312
Undo for Insert -> Text from file.
Definition: undobj.hxx:287
SwNodeOffset mnCursorSaveIndexPara
Definition: undobj.hxx:323
sal_Int32 mnCursorSaveIndexPos
Definition: undobj.hxx:324
std::vector< std::shared_ptr< SwUndoInsLayFormat > > m_FlyUndos
Definition: undobj.hxx:257
SwNodeOffset m_nDeleteTextNodes
Definition: undobj.hxx:259
std::optional< SwNodeIndex > m_oUndoNodeIndex
start of Content in UndoNodes for Redo
Definition: undobj.hxx:262
sal_uInt16 m_nSetPos
Definition: undobj.hxx:263
SwNodeOffset m_nNodeDiff
Definition: undobj.hxx:260
SwTextFormatColl * m_pLastNodeColl
Definition: undobj.hxx:255
std::vector< SwFrameFormat * > * GetFlysAnchoredAt()
Definition: undobj.hxx:280
std::unique_ptr< SwRedlineData > m_pRedlineData
Definition: undobj.hxx:258
std::optional< std::vector< SwFrameFormat * > > m_pFrameFormats
Definition: undobj.hxx:256
static void MoveFromUndoNds(SwDoc &rDoc, SwNodeOffset nNodeIdx, SwPosition &rInsPos, const SwNodeOffset *pEndNdIdx=nullptr, bool bForceCreateFrames=false)
Definition: undobj.cxx:799
virtual ~SwUndoSaveContent() COVERITY_NOEXCEPT_FALSE
Definition: undobj.cxx:738
void DelContentIndex(const SwPosition &pMark, const SwPosition &pPoint, DelContentType nDelContentType=DelContentType::AllMask)
Definition: undobj.cxx:902
static void MoveToUndoNds(SwPaM &rPam, SwNodeIndex *pNodeIdx, SwNodeOffset *pEndNdIdx=nullptr)
Definition: undobj.cxx:763
std::unique_ptr< SwHistory > m_pHistory
Definition: undobj.hxx:167
static bool MovePtBackward(SwPaM &rPam)
Definition: undobj.cxx:867
static void MovePtForward(SwPaM &rPam, bool bMvBkwrd)
Definition: undobj.cxx:879
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: undobj.cxx:742
const SwHistory * GetHistory() const
Definition: undobj.hxx:221
std::unique_ptr< SwRedlineSaveDatas > m_pRedlineSaveData
Definition: undobj.hxx:204
const SwNodeIndex * GetMvSttIdx() const
Definition: undobj.hxx:209
SwNodeOffset m_nStartPos
Definition: undobj.hxx:206
std::optional< SwNodeIndex > m_oMovedStart
Definition: undobj.hxx:203
SwNodeOffset m_nMoveLen
Definition: undobj.hxx:205
SwHistory * GetHistory()
Definition: undobj.hxx:222
SwNodeOffset GetMvNodeCnt() const
Definition: undobj.hxx:210
virtual SwRewriter GetRewriter() const
Returns the rewriter for this object.
Definition: undobj.cxx:728
std::optional< OUString > maComment
Definition: undobj.hxx:63
virtual void UndoImpl(::sw::UndoRedoContext &)=0
SwUndo(SwUndoId const nId, const SwDoc *pDoc)
Definition: undobj.cxx:151
void IgnoreRepeat()
Definition: undobj.hxx:131
void SetRedlineFlags(RedlineFlags eMode)
Definition: undobj.hxx:121
virtual void Repeat(SfxRepeatTarget &) override
Definition: undobj.cxx:237
virtual void Redo() override
Definition: undobj.cxx:214
RedlineFlags m_nOrigRedlineFlags
Definition: undobj.hxx:57
RedlineFlags GetRedlineFlags() const
Definition: undobj.hxx:120
ViewShellId GetViewShellId() const override
See SfxUndoAction::GetViewShellId().
Definition: undobj.cxx:723
virtual bool CanRepeat(SfxRepeatTarget &) const override
Definition: undobj.cxx:249
static bool FillSaveData(const SwPaM &rRange, SwRedlineSaveDatas &rSData, bool bDelRange=true, bool bCopyNext=true)
Definition: undobj.cxx:1455
virtual OUString GetComment() const override
Returns textual comment for this undo object.
Definition: undobj.cxx:694
static void RemoveIdxRel(SwNodeOffset, const SwPosition &)
Definition: undobj.cxx:144
static void RemoveIdxFromRange(SwPaM &rPam, bool bMoveNext)
Definition: undobj.cxx:118
virtual void UndoWithContext(SfxUndoContext &) override
Definition: undobj.cxx:219
bool IsDelBox() const
Definition: undobj.cxx:172
static bool HasHiddenRedlines(const SwRedlineSaveDatas &rSData)
Definition: undobj.cxx:1539
static void SetSaveData(SwDoc &rDoc, SwRedlineSaveDatas &rSData)
Definition: undobj.cxx:1519
static bool CanRedlineGroup(SwRedlineSaveDatas &rCurr, const SwRedlineSaveDatas &rCheck, bool bCurrIsEnd)
Definition: undobj.cxx:1547
SwUndoId GetId() const
Definition: undobj.hxx:102
virtual void RepeatImpl(::sw::RepeatContext &)
Definition: undobj.cxx:257
bool m_bCacheComment
Definition: undobj.hxx:62
static ViewShellId CreateViewShellId(const SwDoc *pDoc)
Try to obtain the view shell ID of the current view.
Definition: undobj.cxx:159
static bool FillSaveDataForFormat(const SwPaM &, SwRedlineSaveDatas &)
Definition: undobj.cxx:1489
virtual void RedoImpl(::sw::UndoRedoContext &)=0
static void RemoveIdxFromSection(SwDoc &, SwNodeOffset nSttIdx, const SwNodeOffset *pEndIdx=nullptr)
Definition: undobj.cxx:108
virtual void Undo() override
Definition: undobj.cxx:209
bool m_isRepeatIgnored
for multi-selection, only repeat 1st selection
Definition: undobj.hxx:59
ViewShellId m_nViewShellId
Definition: undobj.hxx:58
virtual void RedoWithContext(SfxUndoContext &) override
Definition: undobj.cxx:228
virtual ~SwUndo() override
Definition: undobj.cxx:178
SwUndoId const m_nId
Definition: undobj.hxx:56
struct _xmlTextWriter * xmlTextWriterPtr
Mode eMode
Dialog to specify the properties of date form field.
std::optional< std::vector< SwFrameFormat * > > GetFlysAnchoredAt(SwDoc &rDoc, SwNodeOffset const nSttNode)
Definition: untblk.cxx:41
o3tl::strong_int< sal_Int32, struct Tag_SwNodeOffset > SwNodeOffset
Definition: nodeoffset.hxx:16
Marks a position in the document model.
Definition: pam.hxx:38
RndStdIds
SwUndoId
Definition: swundo.hxx:30
bool IsFlySelectedByCursor(SwDoc const &rDoc, SwPosition const &rStart, SwPosition const &rEnd)
check at-char and at-para flys in rDoc
Definition: undobj.cxx:1730
struct _xmlTextWriter * xmlTextWriterPtr
Definition: undobj.hxx:46
bool IsSelectFrameAnchoredAtPara(SwPosition const &rAnchorPos, SwPosition const &rStart, SwPosition const &rEnd, DelContentType const nDelContentType=DelContentType::AllMask)
is a fly anchored at paragraph at rAnchorPos selected?
Definition: undobj.cxx:1688
bool IsDestroyFrameAnchoredAtChar(SwPosition const &rAnchorPos, SwPosition const &rStart, SwPosition const &rEnd, DelContentType const nDelContentType=DelContentType::AllMask)
will DelContentIndex destroy a frame anchored at character at rAnchorPos?
Definition: undobj.cxx:1647
DelContentType
Definition: undobj.hxx:135