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 <tools/solar.h>
27 #include "SwRewriter.hxx"
28 #include "swundo.hxx"
29 #include <o3tl/typed_flags_set.hxx>
30 #include <boost/optional.hpp>
31 
32 class SwHistory;
33 class SwPaM;
34 struct SwPosition;
35 class SwDoc;
36 class SwTextFormatColl;
37 class SwFrameFormat;
38 class SwNodeIndex;
39 class SwNodeRange;
40 class SwRedlineData;
41 class SwRedlineSaveDatas;
42 enum class RedlineFlags;
43 enum class RndStdIds;
44 
45 namespace sw {
46  class UndoRedoContext;
47  class RepeatContext;
48 }
49 
50 class SwUndo
51  : public SfxUndoAction
52 {
53  SwUndoId const m_nId;
57 
58 protected:
61 
62  static void RemoveIdxFromSection( SwDoc&, sal_uLong nSttIdx, const sal_uLong* pEndIdx = nullptr );
63  static void RemoveIdxFromRange( SwPaM& rPam, bool bMoveNext );
64  static void RemoveIdxRel( sal_uLong, const SwPosition& );
65 
66  static bool CanRedlineGroup( SwRedlineSaveDatas& rCurr,
67  const SwRedlineSaveDatas& rCheck,
68  bool bCurrIsEnd );
69 
75  virtual SwRewriter GetRewriter() const;
76 
77  // the 4 methods that derived classes have to override
78  // base implementation does nothing
79  virtual void RepeatImpl( ::sw::RepeatContext & );
80 public: // should not be public, but ran into trouble in untbl.cxx
81  virtual void UndoImpl( ::sw::UndoRedoContext & ) = 0;
82  virtual void RedoImpl( ::sw::UndoRedoContext & ) = 0;
83 
84 private:
86  static ViewShellId CreateViewShellId(const SwDoc* pDoc);
87  // SfxUndoAction
88  virtual void Undo() override;
89  virtual void Redo() override;
90  virtual void UndoWithContext(SfxUndoContext &) override;
91  virtual void RedoWithContext(SfxUndoContext &) override;
92  virtual void Repeat(SfxRepeatTarget &) override;
93  virtual bool CanRepeat(SfxRepeatTarget &) const override;
94 
95 public:
96  SwUndo(SwUndoId const nId, const SwDoc* pDoc);
97  virtual ~SwUndo() override;
98 
99  SwUndoId GetId() const { return m_nId; }
100 
110  virtual OUString GetComment() const override;
111 
113  ViewShellId GetViewShellId() const override;
114 
115  // UndoObject remembers which mode was turned on.
116  // In Undo/Redo/Repeat this remembered mode is switched on.
118  void SetRedlineFlags( RedlineFlags eMode ) { nOrigRedlineFlags = eMode; }
119 
120  bool IsDelBox() const;
121 
122  // Save and set Redline data.
123  static bool FillSaveData( const SwPaM& rRange, SwRedlineSaveDatas& rSData,
124  bool bDelRange = true, bool bCopyNext = true );
125  static bool FillSaveDataForFormat( const SwPaM& , SwRedlineSaveDatas& );
126  static void SetSaveData( SwDoc& rDoc, SwRedlineSaveDatas& rSData );
127  static bool HasHiddenRedlines( const SwRedlineSaveDatas& rSData );
128  void IgnoreRepeat() { m_isRepeatIgnored = true; }
129 };
130 
131 enum class DelContentType : sal_uInt16
132 {
133  Ftn = 0x01,
134  Fly = 0x02,
135  Bkm = 0x08,
136  AllMask = 0x0b,
137  CheckNoCntnt = 0x80,
138 };
139 namespace o3tl {
140  template<> struct typed_flags<DelContentType> : is_typed_flags<DelContentType, 0x8b> {};
141 }
142 
144 bool IsDestroyFrameAnchoredAtChar(SwPosition const & rAnchorPos,
145  SwPosition const & rStart, SwPosition const & rEnd,
146  DelContentType const nDelContentType = DelContentType::AllMask);
147 
148 // This class has to be inherited into an Undo-object if it saves content
149 // for Redo/Undo...
151 {
152 protected:
153 
154  std::unique_ptr<SwHistory> pHistory;
155 
156  // Needed for deletion of content. For Redo content is moved into the
157  // UndoNodesArray. These methods always create a new node to insert
158  // content. So the attributes do not get expanded.
159  // MoveTo: moves from the NodesArray into the UndoNodesArray.
160  // MoveFrom: moves from the UndoNodesArray into the NodesArray.
161  static void MoveToUndoNds( SwPaM& rPam,
162  SwNodeIndex* pNodeIdx,
163  sal_uLong* pEndNdIdx = nullptr );
164  static void MoveFromUndoNds( SwDoc& rDoc, sal_uLong nNodeIdx,
165  SwPosition& rInsPos,
166  const sal_uLong* pEndNdIdx = nullptr,
167  bool bForceCreateFrames = false);
168 
169  // These two methods move the SPoint back/forth from PaM. With it
170  // a range can be spanned for Undo/Redo. (In this case the SPoint
171  // is before the manipulated range!!)
172  // The flag indicates if there is content before the SPoint.
173  static bool MovePtBackward( SwPaM& rPam );
174  static void MovePtForward( SwPaM& rPam, bool bMvBkwrd );
175 
176  // Before moving stuff into UndoNodes-Array care has to be taken that
177  // the content-bearing attributes are removed from the nodes-array.
178  void DelContentIndex( const SwPosition& pMark, const SwPosition& pPoint,
179  DelContentType nDelContentType = DelContentType::AllMask );
180 
181 public:
183  ~SwUndoSaveContent() COVERITY_NOEXCEPT_FALSE;
184 };
185 
186 // Save a complete section in nodes-array.
188 {
189  std::unique_ptr<SwNodeIndex> m_pMovedStart;
190  std::unique_ptr<SwRedlineSaveDatas> pRedlSaveData;
191  sal_uLong nMvLen; // Index into UndoNodes-Array.
193 
194 protected:
195  SwNodeIndex* GetMvSttIdx() const { return m_pMovedStart.get(); }
196  sal_uLong GetMvNodeCnt() const { return nMvLen; }
197 
198 public:
201 
202  void SaveSection( const SwNodeIndex& rSttIdx );
203  void SaveSection(const SwNodeRange& rRange, bool bExpandNodes = true);
204  void RestoreSection( SwDoc* pDoc, SwNodeIndex* pIdx, sal_uInt16 nSectType );
205  void RestoreSection(SwDoc* pDoc, const SwNodeIndex& rInsPos, bool bForceCreateFrames = false);
206 
207  const SwHistory* GetHistory() const { return pHistory.get(); }
208  SwHistory* GetHistory() { return pHistory.get(); }
209 };
210 
211 // This class saves the PaM as sal_uInt16's and is able to restore it
212 // into a PaM.
213 class SwUndRng
214 {
215 public:
216  sal_uLong nSttNode, nEndNode;
217  sal_Int32 nSttContent, nEndContent;
218 
219  SwUndRng();
220  SwUndRng( const SwPaM& );
221 
222  void SetValues( const SwPaM& rPam );
223  void SetPaM( SwPaM&, bool bCorrToContent = false ) const;
224  SwPaM & AddUndoRedoPaM(
225  ::sw::UndoRedoContext &, bool const bCorrToContent = false) const;
226 };
227 
228 class SwUndoInsLayFormat;
229 
230 // base class for insertion of Document, Glossaries and Copy
231 class SwUndoInserts : public SwUndo, public SwUndRng, private SwUndoSaveContent
232 {
234  std::unique_ptr<std::vector<SwFrameFormat*>> pFrameFormats;
235  std::vector< std::shared_ptr<SwUndoInsLayFormat> > m_FlyUndos;
236  std::unique_ptr<SwRedlineData> pRedlData;
238 protected:
241  std::unique_ptr<SwNodeIndex> m_pUndoNodeIndex;
242  sal_uInt16 nSetPos; // Start in the history list.
243 
244  SwUndoInserts( SwUndoId nUndoId, const SwPaM& );
245 public:
246  virtual ~SwUndoInserts() override;
247 
248  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
249  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
250  virtual void RepeatImpl( ::sw::RepeatContext & ) override;
251 
252  // Set destination range after reading.
253  void SetInsertRange( const SwPaM&, bool bScanFlys = true,
254  bool bSttWasTextNd = true );
255 };
256 
258 {
259 public:
260  SwUndoInsDoc( const SwPaM& );
261 };
262 
264 {
265 public:
266  SwUndoCpyDoc( const SwPaM& );
267 };
268 
269 class SwUndoFlyBase : public SwUndo, private SwUndoSaveSection
270 {
271 protected:
272  SwFrameFormat* pFrameFormat; // The saved FlyFormat.
274  sal_Int32 nCntPos; // Page at/in paragraph.
276  bool bDelFormat; // Delete saved format.
277 
278  void InsFly(::sw::UndoRedoContext & rContext, bool bShowSel = true);
279  void DelFly( SwDoc* );
280 
281  SwUndoFlyBase( SwFrameFormat* pFormat, SwUndoId nUndoId );
282 
285 
286 public:
287  virtual ~SwUndoFlyBase() override;
288 
289 };
290 
292 {
293  sal_uLong mnCursorSaveIndexPara; // Cursor position
294  sal_Int32 const mnCursorSaveIndexPos; // for undo
295 public:
296  SwUndoInsLayFormat( SwFrameFormat* pFormat, sal_uLong nNodeIdx, sal_Int32 nCntIdx );
297 
298  virtual ~SwUndoInsLayFormat() override;
299 
300  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
301  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
302  virtual void RepeatImpl( ::sw::RepeatContext & ) override;
303 
304  virtual OUString GetComment() const override;
305 
306 };
307 
309 {
311 public:
312  SwUndoDelLayFormat( SwFrameFormat* pFormat );
313 
314  virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
315  virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
316 
317  void RedoForRollback();
318 
319  void ChgShowSel( bool bNew ) { bShowSelFrame = bNew; }
320 
321  virtual SwRewriter GetRewriter() const override;
322 
323 };
324 
325 #endif
326 
327 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< std::vector< SwFrameFormat * > > pFrameFormats
Definition: undobj.hxx:234
RndStdIds nRndId
Definition: undobj.hxx:275
std::vector< std::shared_ptr< SwUndoInsLayFormat > > m_FlyUndos
Definition: undobj.hxx:235
std::unique_ptr< SwHistory > pHistory
Definition: undobj.hxx:154
Represents the style of a paragraph.
Definition: fmtcol.hxx:55
Marks a position in the document model.
Definition: pam.hxx:35
sal_uLong nNdPgPos
Definition: undobj.hxx:273
sal_Int32 nSttContent
Definition: undobj.hxx:217
bool bSttWasTextNd
Definition: undobj.hxx:237
SwUndoId
Definition: swundo.hxx:29
static bool FillSaveDataForFormat(const SwPaM &, SwRedlineSaveDatas &)
Definition: undobj.cxx:1416
std::unique_ptr< SwRedlineData > pRedlData
Definition: undobj.hxx:236
virtual void Repeat(SfxRepeatTarget &) override
Definition: undobj.cxx:241
sal_uIntPtr sal_uLong
static ViewShellId CreateViewShellId(const SwDoc *pDoc)
Try to obtain the view shell ID of the current view.
Definition: undobj.cxx:167
Definition: doc.hxx:185
~SwUndoSaveContent() COVERITY_NOEXCEPT_FALSE
Definition: undobj.cxx:697
RedlineFlags nOrigRedlineFlags
Definition: undobj.hxx:54
std::unique_ptr< SwRedlineSaveDatas > pRedlSaveData
Definition: undobj.hxx:190
bool bCacheComment
Definition: undobj.hxx:59
void SetRedlineFlags(RedlineFlags eMode)
Definition: undobj.hxx:118
const SwHistory * GetHistory() const
Definition: undobj.hxx:207
Dialog to specify the properties of date form field.
Definition: accfrmobj.cxx:40
sal_Int32 const mnCursorSaveIndexPos
Definition: undobj.hxx:294
static void RemoveIdxFromSection(SwDoc &, sal_uLong nSttIdx, const sal_uLong *pEndIdx=nullptr)
Definition: undobj.cxx:114
SwTextFormatColl * pTextFormatColl
Definition: undobj.hxx:233
void ChgShowSel(bool bNew)
Definition: undobj.hxx:319
SwUndoId GetId() const
Definition: undobj.hxx:99
virtual void RepeatImpl(::sw::RepeatContext &)
Definition: undobj.cxx:261
SwUndoId const m_nId
Definition: undobj.hxx:53
sal_uInt16 nSetPos
Definition: undobj.hxx:242
bool bDelFormat
Definition: undobj.hxx:276
virtual SwRewriter GetRewriter() const
Returns the rewriter for this object.
Definition: undobj.cxx:687
static bool CanRedlineGroup(SwRedlineSaveDatas &rCurr, const SwRedlineSaveDatas &rCheck, bool bCurrIsEnd)
Definition: undobj.cxx:1473
SwHistory * GetHistory()
Definition: undobj.hxx:208
static void MoveToUndoNds(SwPaM &rPam, SwNodeIndex *pNodeIdx, sal_uLong *pEndNdIdx=nullptr)
Definition: undobj.cxx:709
static void RemoveIdxFromRange(SwPaM &rPam, bool bMoveNext)
Definition: undobj.cxx:124
virtual bool CanRepeat(SfxRepeatTarget &) const override
Definition: undobj.cxx:253
RedlineFlags GetRedlineFlags() const
Definition: undobj.hxx:117
SwNodeIndex * GetMvSttIdx() const
Definition: undobj.hxx:283
static void MovePtForward(SwPaM &rPam, bool bMvBkwrd)
Definition: undobj.cxx:821
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
virtual void UndoImpl(::sw::UndoRedoContext &)=0
sal_Int32 nCntPos
Definition: undobj.hxx:274
Style of a layout element.
Definition: frmfmt.hxx:57
static bool HasHiddenRedlines(const SwRedlineSaveDatas &rSData)
Definition: undobj.cxx:1465
sal_uLong nNdDiff
Definition: undobj.hxx:239
void DelContentIndex(const SwPosition &pMark, const SwPosition &pPoint, DelContentType nDelContentType=DelContentType::AllMask)
Definition: undobj.cxx:846
static void SetSaveData(SwDoc &rDoc, SwRedlineSaveDatas &rSData)
Definition: undobj.cxx:1446
virtual void UndoWithContext(SfxUndoContext &) override
Definition: undobj.cxx:223
boost::optional< OUString > maComment
Definition: undobj.hxx:60
sal_uLong nSttNode
Definition: undobj.hxx:216
Marks a node in the document model.
Definition: ndindex.hxx:31
static bool MovePtBackward(SwPaM &rPam)
Definition: undobj.cxx:808
virtual OUString GetComment() const override
Returns textual comment for this undo object.
Definition: undobj.cxx:653
std::unique_ptr< SwNodeIndex > m_pMovedStart
Definition: undobj.hxx:189
sal_uLong GetMvNodeCnt() const
Definition: undobj.hxx:284
sal_uLong GetMvNodeCnt() const
Definition: undobj.hxx:196
static void MoveFromUndoNds(SwDoc &rDoc, sal_uLong nNodeIdx, SwPosition &rInsPos, const sal_uLong *pEndNdIdx=nullptr, bool bForceCreateFrames=false)
Definition: undobj.cxx:746
DelContentType
Definition: undobj.hxx:131
ViewShellId const m_nViewShellId
Definition: undobj.hxx:55
virtual ~SwUndo() override
Definition: undobj.cxx:186
SwFrameFormat * pFrameFormat
Definition: undobj.hxx:272
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:1524
SwUndo(SwUndoId const nId, const SwDoc *pDoc)
Definition: undobj.cxx:159
bool m_isRepeatIgnored
for multi-selection, only repeat 1st selection
Definition: undobj.hxx:56
virtual void Redo() override
Definition: undobj.cxx:218
void IgnoreRepeat()
Definition: undobj.hxx:128
SwNodeIndex * GetMvSttIdx() const
Definition: undobj.hxx:195
virtual void RedoWithContext(SfxUndoContext &) override
Definition: undobj.cxx:232
static void RemoveIdxRel(sal_uLong, const SwPosition &)
Definition: undobj.cxx:151
virtual void RedoImpl(::sw::UndoRedoContext &)=0
virtual void Undo() override
Definition: undobj.cxx:213
RndStdIds
sal_uLong nMvLen
Definition: undobj.hxx:191
static bool FillSaveData(const SwPaM &rRange, SwRedlineSaveDatas &rSData, bool bDelRange=true, bool bCopyNext=true)
Definition: undobj.cxx:1381
ViewShellId GetViewShellId() const override
See SfxUndoAction::GetViewShellId().
Definition: undobj.cxx:682
sal_uLong nStartPos
Definition: undobj.hxx:192
bool IsDelBox() const
Definition: undobj.cxx:180
sal_uLong mnCursorSaveIndexPara
Definition: undobj.hxx:293
std::unique_ptr< SwNodeIndex > m_pUndoNodeIndex
start of Content in UndoNodes for Redo
Definition: undobj.hxx:241