LibreOffice Module sw (master)  1
undel.cxx
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 #include <UndoDelete.hxx>
21 
22 #include <libxml/xmlwriter.h>
23 
24 #include <hintids.hxx>
25 #include <rtl/ustrbuf.hxx>
26 #include <unotools/charclass.hxx>
27 #include <frmfmt.hxx>
28 #include <fmtanchr.hxx>
29 #include <doc.hxx>
30 #include <UndoManager.hxx>
33 #include <swtable.hxx>
34 #include <swundo.hxx>
35 #include <pam.hxx>
36 #include <ndtxt.hxx>
37 #include <UndoCore.hxx>
38 #include <rolbck.hxx>
39 #include <poolfmt.hxx>
40 #include <mvsave.hxx>
41 #include <docary.hxx>
42 #include <frmtool.hxx>
43 #include <txtfrm.hxx>
44 #include <rootfrm.hxx>
45 #include <strings.hrc>
46 #include <frameformats.hxx>
47 #include <vector>
48 
49 // DELETE
50 /* lcl_MakeAutoFrames has to call MakeFrames for objects bounded "AtChar"
51  ( == AUTO ), if the anchor frame has be moved via MoveNodes(..) and
52  DelFrames(..)
53 */
54 static void lcl_MakeAutoFrames( const SwFrameFormats& rSpzArr, sal_uLong nMovedIndex )
55 {
56  for( size_t n = 0; n < rSpzArr.size(); ++n )
57  {
58  SwFrameFormat * pFormat = rSpzArr[n];
59  const SwFormatAnchor* pAnchor = &pFormat->GetAnchor();
60  if (pAnchor->GetAnchorId() == RndStdIds::FLY_AT_CHAR)
61  {
62  const SwPosition* pAPos = pAnchor->GetContentAnchor();
63  if( pAPos && nMovedIndex == pAPos->nNode.GetIndex() )
64  pFormat->MakeFrames();
65  }
66  }
67 }
68 
69 static SwTextNode * FindFirstAndNextNode(SwDoc & rDoc, SwUndRng const& rRange,
70  SwRedlineSaveDatas const& rRedlineSaveData,
71  SwTextNode *& o_rpFirstMergedDeletedTextNode)
72 {
73  // redlines are corrected now to exclude the deleted node
74  assert(rRange.m_nEndContent == 0);
75  sal_uLong nEndOfRedline = 0;
76  for (size_t i = 0; i < rRedlineSaveData.size(); ++i)
77  {
78  auto const& rRedline(rRedlineSaveData[i]);
79  if (rRedline.m_nSttNode <= rRange.m_nSttNode
80  && rRedline.m_nSttNode < rRange.m_nEndNode
81  && rRange.m_nEndNode <= rRedline.m_nEndNode
82  && rRedline.GetType() == RedlineType::Delete)
83  {
84  nEndOfRedline = rRedline.m_nEndNode;
85  o_rpFirstMergedDeletedTextNode = rDoc.GetNodes()[rRedline.m_nSttNode]->GetTextNode();
86  assert(rRange.m_nSttNode == rRange.m_nEndNode - 1); // otherwise this needs to iterate more RL to find the first node?
87  break;
88  }
89  }
90  if (nEndOfRedline)
91  {
92  assert(o_rpFirstMergedDeletedTextNode);
93  SwTextNode * pNextNode(nullptr);
94  for (sal_uLong i = rRange.m_nEndNode; /* i <= nEndOfRedline */; ++i)
95  {
96  SwNode *const pNode(rDoc.GetNodes()[i]);
97  assert(!pNode->IsEndNode()); // cannot be both leaving section here *and* overlapping redline
98  if (pNode->IsStartNode())
99  {
100  i = pNode->EndOfSectionIndex(); // will be incremented again
101  }
102  else if (pNode->IsTextNode())
103  {
104  pNextNode = pNode->GetTextNode();
105  break;
106  }
107  }
108  assert(pNextNode);
109  return pNextNode;
110  }
111  else
112  {
113  return nullptr;
114  }
115 }
116 
117 static void DelFullParaMoveFrames(SwDoc & rDoc, SwUndRng const& rRange,
118  SwRedlineSaveDatas const& rRedlineSaveData)
119 {
120  SwTextNode * pFirstMergedDeletedTextNode(nullptr);
121  SwTextNode *const pNextNode = FindFirstAndNextNode(rDoc, rRange,
122  rRedlineSaveData, pFirstMergedDeletedTextNode);
123  if (pNextNode)
124  {
125  std::vector<SwTextFrame*> frames;
126  SwIterator<SwTextFrame, SwTextNode, sw::IteratorMode::UnwrapMulti> aIter(*pFirstMergedDeletedTextNode);
127  for (SwTextFrame* pFrame = aIter.First(); pFrame; pFrame = aIter.Next())
128  {
129  if (pFrame->getRootFrame()->IsHideRedlines())
130  {
131  assert(pFrame->GetMergedPara());
132  assert(pFrame->GetMergedPara()->pFirstNode == pFirstMergedDeletedTextNode);
133  assert(pNextNode->GetIndex() <= pFrame->GetMergedPara()->pLastNode->GetIndex());
134  frames.push_back(pFrame);
135  }
136  }
137  for (SwTextFrame *const pFrame : frames)
138  {
139  // sw_redlinehide: don't need FrameMode::Existing here
140  // because everything from pNextNode onwards is already
141  // correctly hidden
142  pFrame->RegisterToNode(*pNextNode, true);
143  }
144  }
145 }
146 
147 // SwUndoDelete has to perform a deletion and to record anything that is needed
148 // to restore the situation before the deletion. Unfortunately a part of the
149 // deletion will be done after calling this Ctor, this has to be kept in mind!
150 // In this Ctor only the complete paragraphs will be deleted, the joining of
151 // the first and last paragraph of the selection will be handled outside this
152 // function.
153 // Here are the main steps of the function:
154 // 1. Deletion/recording of content indices of the selection: footnotes, fly
155 // frames and bookmarks
156 // Step 1 could shift all nodes by deletion of footnotes => nNdDiff will be set.
157 // 2. If the paragraph where the selection ends, is the last content of a
158 // section so that this section becomes empty when the paragraphs will be
159 // joined we have to do some smart actions ;-) The paragraph will be moved
160 // outside the section and replaced by a dummy text node, the complete
161 // section will be deleted in step 3. The difference between replacement
162 // dummy and original is nReplacementDummy.
163 // 3. Moving complete selected nodes into the UndoArray. Before this happens the
164 // selection has to be extended if there are sections which would become
165 // empty otherwise. BTW: sections will be moved into the UndoArray if they
166 // are complete part of the selection. Sections starting or ending outside
167 // of the selection will not be removed from the DocNodeArray even they got
168 // a "dummy"-copy in the UndoArray.
169 // 4. We have to anticipate the joining of the two paragraphs if the start
170 // paragraph is inside a section and the end paragraph not. Then we have to
171 // move the paragraph into this section and to record this in nSectDiff.
173  SwPaM& rPam,
174  bool bFullPara,
175  bool bCalledByTableCpy )
176  : SwUndo(SwUndoId::DELETE, rPam.GetDoc()),
177  SwUndRng( rPam ),
178  m_nNode(0),
179  m_nNdDiff(0),
180  m_nSectDiff(0),
181  m_nReplaceDummy(0),
182  m_nSetPos(0),
183  m_bGroup( false ),
184  m_bBackSp( false ),
185  m_bJoinNext( false ),
186  m_bTableDelLastNd( false ),
187  // bFullPara is set e.g. if an empty paragraph before a table is deleted
188  m_bDelFullPara( bFullPara ),
189  m_bResetPgDesc( false ),
190  m_bResetPgBrk( false ),
191  m_bFromTableCopy( bCalledByTableCpy )
192  , m_bDisableMakeFrames(false)
193 {
194 
195  m_bCacheComment = false;
196 
197  SwDoc * pDoc = rPam.GetDoc();
198 
200  {
202  if( !FillSaveData( rPam, *m_pRedlSaveData ))
203  {
204  m_pRedlSaveData.reset();
205  }
206  }
207 
208  if( !m_pHistory )
209  m_pHistory.reset( new SwHistory );
210 
211  // delete all footnotes for now
212  const SwPosition *pStt = rPam.Start(),
213  *pEnd = rPam.GetPoint() == pStt
214  ? rPam.GetMark()
215  : rPam.GetPoint();
216 
217  // Step 1. deletion/record of content indices
218  if( m_bDelFullPara )
219  {
220  OSL_ENSURE( rPam.HasMark(), "PaM without Mark" );
221  DelContentIndex( *rPam.GetMark(), *rPam.GetPoint(),
223 
224  ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
225  DelBookmarks(pStt->nNode, pEnd->nNode);
226  }
227  else
228  {
229  DelContentIndex( *rPam.GetMark(), *rPam.GetPoint() );
230  ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
231  if (m_nEndNode - m_nSttNode > 1) // check for fully selected nodes
232  {
233  SwNodeIndex const start(pStt->nNode, +1);
234  DelBookmarks(start, pEnd->nNode);
235  }
236  }
237 
238  m_nSetPos = m_pHistory ? m_pHistory->Count() : 0;
239 
240  // Is already anything deleted?
241  m_nNdDiff = m_nSttNode - pStt->nNode.GetIndex();
242 
243  m_bJoinNext = !bFullPara && pEnd == rPam.GetPoint();
244  m_bBackSp = !bFullPara && !m_bJoinNext;
245 
246  SwTextNode *pSttTextNd = nullptr, *pEndTextNd = nullptr;
247  if( !bFullPara )
248  {
249  pSttTextNd = pStt->nNode.GetNode().GetTextNode();
250  pEndTextNd = m_nSttNode == m_nEndNode
251  ? pSttTextNd
252  : pEnd->nNode.GetNode().GetTextNode();
253  }
254  else if (m_pRedlSaveData)
255  {
256  DelFullParaMoveFrames(*pDoc, *this, *m_pRedlSaveData);
257  }
258 
259  bool bMoveNds = *pStt != *pEnd // any area still existent?
260  && ( SaveContent( pStt, pEnd, pSttTextNd, pEndTextNd ) || m_bFromTableCopy );
261 
262  if( pSttTextNd && pEndTextNd && pSttTextNd != pEndTextNd )
263  {
264  // two different TextNodes, thus save also the TextFormatCollection
265  m_pHistory->Add( pSttTextNd->GetTextColl(),pStt->nNode.GetIndex(), SwNodeType::Text );
266  m_pHistory->Add( pEndTextNd->GetTextColl(),pEnd->nNode.GetIndex(), SwNodeType::Text );
267 
268  if( !m_bJoinNext ) // Selection from bottom to top
269  {
270  // When using JoinPrev() all AUTO-PageBreak's will be copied
271  // correctly. To restore them with UNDO, Auto-PageBreak of the
272  // EndNode needs to be reset. Same for PageDesc and ColBreak.
273  if( pEndTextNd->HasSwAttrSet() )
274  {
275  SwRegHistory aRegHist( *pEndTextNd, m_pHistory.get() );
276  if( SfxItemState::SET == pEndTextNd->GetpSwAttrSet()->GetItemState(
277  RES_BREAK, false ) )
278  pEndTextNd->ResetAttr( RES_BREAK );
279  if( pEndTextNd->HasSwAttrSet() &&
280  SfxItemState::SET == pEndTextNd->GetpSwAttrSet()->GetItemState(
281  RES_PAGEDESC, false ) )
282  pEndTextNd->ResetAttr( RES_PAGEDESC );
283  }
284  }
285  }
286 
287  // Move now also the PaM. The SPoint is at the beginning of a SSelection.
288  if( pEnd == rPam.GetPoint() && ( !bFullPara || pSttTextNd || pEndTextNd ) )
289  rPam.Exchange();
290 
291  if( !pSttTextNd && !pEndTextNd )
292  --rPam.GetPoint()->nNode;
293  rPam.DeleteMark(); // the SPoint is in the selection
294 
295  if( !pEndTextNd )
296  m_nEndContent = 0;
297  if( !pSttTextNd )
298  m_nSttContent = 0;
299 
300  if( bMoveNds ) // Do Nodes exist that need to be moved?
301  {
302  SwNodes& rNds = pDoc->GetUndoManager().GetUndoNodes();
303  SwNodes& rDocNds = pDoc->GetNodes();
304  SwNodeRange aRg( rDocNds, m_nSttNode - m_nNdDiff,
305  rDocNds, m_nEndNode - m_nNdDiff );
306  if( !bFullPara && !pEndTextNd &&
307  &aRg.aEnd.GetNode() != &pDoc->GetNodes().GetEndOfContent() )
308  {
309  SwNode* pNode = aRg.aEnd.GetNode().StartOfSectionNode();
310  if( pNode->GetIndex() >= m_nSttNode - m_nNdDiff )
311  ++aRg.aEnd; // Deletion of a complete table
312  }
313  SwNode* pTmpNd;
314  // Step 2: Expand selection if necessary
315  if( m_bJoinNext || bFullPara )
316  {
317  // If all content of a section will be moved into Undo, the section
318  // itself should be moved completely.
319  while( aRg.aEnd.GetIndex() + 2 < rDocNds.Count() &&
320  ( (pTmpNd = rDocNds[ aRg.aEnd.GetIndex()+1 ])->IsEndNode() &&
321  pTmpNd->StartOfSectionNode()->IsSectionNode() &&
322  pTmpNd->StartOfSectionNode()->GetIndex() >= aRg.aStart.GetIndex() ) )
323  ++aRg.aEnd;
325  if( m_nReplaceDummy )
326  { // The selection has been expanded, because
327  ++aRg.aEnd;
328  if( pEndTextNd )
329  {
330  // The end text node has to leave the (expanded) selection
331  // The dummy is needed because MoveNodes deletes empty
332  // sections
333  ++m_nReplaceDummy;
334  SwNodeRange aMvRg( *pEndTextNd, 0, *pEndTextNd, 1 );
335  SwPosition aSplitPos( *pEndTextNd );
336  ::sw::UndoGuard const ug(pDoc->GetIDocumentUndoRedo());
337  pDoc->getIDocumentContentOperations().SplitNode( aSplitPos, false );
338  rDocNds.MoveNodes( aMvRg, rDocNds, aRg.aEnd );
339  --aRg.aEnd;
340  }
341  else
342  m_nReplaceDummy = 0;
343  }
344  }
345  if( m_bBackSp || bFullPara )
346  {
347  // See above, the selection has to be expanded if there are "nearly
348  // empty" sections and a replacement dummy has to be set if needed.
349  while( 1 < aRg.aStart.GetIndex() &&
350  ( (pTmpNd = rDocNds[ aRg.aStart.GetIndex()-1 ])->IsSectionNode() &&
351  pTmpNd->EndOfSectionIndex() < aRg.aEnd.GetIndex() ) )
352  --aRg.aStart;
353  if( pSttTextNd )
354  {
356  if( m_nReplaceDummy )
357  {
358  SwNodeRange aMvRg( *pSttTextNd, 0, *pSttTextNd, 1 );
359  SwPosition aSplitPos( *pSttTextNd );
360  ::sw::UndoGuard const ug(pDoc->GetIDocumentUndoRedo());
361  pDoc->getIDocumentContentOperations().SplitNode( aSplitPos, false );
362  rDocNds.MoveNodes( aMvRg, rDocNds, aRg.aStart );
363  --aRg.aStart;
364  }
365  }
366  }
367 
368  if( m_bFromTableCopy )
369  {
370  if( !pEndTextNd )
371  {
372  if( pSttTextNd )
373  ++aRg.aStart;
374  else if( !bFullPara && !aRg.aEnd.GetNode().IsContentNode() )
375  --aRg.aEnd;
376  }
377  }
378  else if (pSttTextNd && (pEndTextNd || pSttTextNd->GetText().getLength()))
379  ++aRg.aStart;
380 
381  // Step 3: Moving into UndoArray...
382  m_nNode = rNds.GetEndOfContent().GetIndex();
383  rDocNds.MoveNodes( aRg, rNds, SwNodeIndex( rNds.GetEndOfContent() ));
384  m_pMvStt.reset( new SwNodeIndex( rNds, m_nNode ) );
385  // remember difference!
387 
388  if( pSttTextNd && pEndTextNd )
389  {
390  //Step 4: Moving around sections
391  m_nSectDiff = aRg.aEnd.GetIndex() - aRg.aStart.GetIndex();
392  // nSect is the number of sections which starts(ends) between start
393  // and end node of the selection. The "loser" paragraph has to be
394  // moved into the section(s) of the "winner" paragraph
395  if( m_nSectDiff )
396  {
397  if( m_bJoinNext )
398  {
399  SwNodeRange aMvRg( *pEndTextNd, 0, *pEndTextNd, 1 );
400  rDocNds.MoveNodes( aMvRg, rDocNds, aRg.aStart );
401  }
402  else
403  {
404  SwNodeRange aMvRg( *pSttTextNd, 0, *pSttTextNd, 1 );
405  rDocNds.MoveNodes( aMvRg, rDocNds, aRg.aEnd );
406  }
407  }
408  }
411  m_bJoinNext ? pEndTextNd->GetIndex() : pSttTextNd->GetIndex() );
412  }
413  else
414  m_nNode = 0; // moved no node -> no difference at the end
415 
416  // Are there any Nodes that got deleted before that (FootNotes
417  // have ContentNodes)?
418  if( !pSttTextNd && !pEndTextNd )
419  {
420  m_nNdDiff = m_nSttNode - rPam.GetPoint()->nNode.GetIndex() - (bFullPara ? 0 : 1);
421  rPam.Move( fnMoveForward, GoInNode );
422  }
423  else
424  {
426  if( m_nSectDiff && m_bBackSp )
428  m_nNdDiff -= rPam.GetPoint()->nNode.GetIndex();
429  }
430 
431  if( !rPam.GetNode().IsContentNode() )
432  rPam.GetPoint()->nContent.Assign( nullptr, 0 );
433 
434  // is a history necessary here at all?
435  if( m_pHistory && !m_pHistory->Count() )
436  m_pHistory.reset();
437 }
438 
439 bool SwUndoDelete::SaveContent( const SwPosition* pStt, const SwPosition* pEnd,
440  SwTextNode* pSttTextNd, SwTextNode* pEndTextNd )
441 {
442  sal_uLong nNdIdx = pStt->nNode.GetIndex();
443  // 1 - copy start in Start-String
444  if( pSttTextNd )
445  {
446  bool bOneNode = m_nSttNode == m_nEndNode;
447  SwRegHistory aRHst( *pSttTextNd, m_pHistory.get() );
448  // always save all text atttibutes because of possibly overlapping
449  // areas of on/off
450  m_pHistory->CopyAttr( pSttTextNd->GetpSwpHints(), nNdIdx,
451  0, pSttTextNd->GetText().getLength(), true );
452  if( !bOneNode && pSttTextNd->HasSwAttrSet() )
453  m_pHistory->CopyFormatAttr( *pSttTextNd->GetpSwAttrSet(), nNdIdx );
454 
455  // the length might have changed (!!Fields!!)
456  sal_Int32 nLen = (bOneNode
457  ? pEnd->nContent.GetIndex()
458  : pSttTextNd->GetText().getLength())
459  - pStt->nContent.GetIndex();
460 
461  // delete now also the text (all attribute changes are added to
462  // UNDO history)
463  m_aSttStr = pSttTextNd->GetText().copy(m_nSttContent, nLen);
464  pSttTextNd->EraseText( pStt->nContent, nLen );
465  if( pSttTextNd->GetpSwpHints() )
466  pSttTextNd->GetpSwpHints()->DeRegister();
467 
468  // METADATA: store
469  bool emptied( !m_aSttStr->isEmpty() && !pSttTextNd->Len() );
470  if (!bOneNode || emptied) // merging may overwrite xmlids...
471  {
472  m_pMetadataUndoStart = emptied
473  ? pSttTextNd->CreateUndoForDelete()
474  : pSttTextNd->CreateUndo();
475  }
476 
477  if( bOneNode )
478  return false; // stop moving more nodes
479  }
480 
481  // 2 - copy end into End-String
482  if( pEndTextNd )
483  {
484  SwIndex aEndIdx( pEndTextNd );
485  nNdIdx = pEnd->nNode.GetIndex();
486  SwRegHistory aRHst( *pEndTextNd, m_pHistory.get() );
487 
488  // always save all text atttibutes because of possibly overlapping
489  // areas of on/off
490  m_pHistory->CopyAttr( pEndTextNd->GetpSwpHints(), nNdIdx, 0,
491  pEndTextNd->GetText().getLength(), true );
492 
493  if( pEndTextNd->HasSwAttrSet() )
494  m_pHistory->CopyFormatAttr( *pEndTextNd->GetpSwAttrSet(), nNdIdx );
495 
496  // delete now also the text (all attribute changes are added to
497  // UNDO history)
498  m_aEndStr = pEndTextNd->GetText().copy( 0, pEnd->nContent.GetIndex() );
499  pEndTextNd->EraseText( aEndIdx, pEnd->nContent.GetIndex() );
500  if( pEndTextNd->GetpSwpHints() )
501  pEndTextNd->GetpSwpHints()->DeRegister();
502 
503  // METADATA: store
504  bool emptied = !m_aEndStr->isEmpty() && !pEndTextNd->Len();
505 
506  m_pMetadataUndoEnd = emptied
507  ? pEndTextNd->CreateUndoForDelete()
508  : pEndTextNd->CreateUndo();
509  }
510 
511  // if there are only two Nodes then we're done
512  if( ( pSttTextNd || pEndTextNd ) && m_nSttNode + 1 == m_nEndNode )
513  return false; // do not move any Node
514 
515  return true; // move Nodes lying in between
516 }
517 
518 bool SwUndoDelete::CanGrouping( SwDoc* pDoc, const SwPaM& rDelPam )
519 {
520  // Is Undo greater than one Node (that is Start and EndString)?
521  if( !m_aSttStr || m_aSttStr->isEmpty() || m_aEndStr )
522  return false;
523 
524  // only the deletion of single char's can be condensed
526  return false;
527 
528  const SwPosition *pStt = rDelPam.Start(),
529  *pEnd = rDelPam.GetPoint() == pStt
530  ? rDelPam.GetMark()
531  : rDelPam.GetPoint();
532 
533  if( pStt->nNode != pEnd->nNode ||
534  pStt->nContent.GetIndex()+1 != pEnd->nContent.GetIndex() ||
535  pEnd->nNode != m_nSttNode )
536  return false;
537 
538  // Distinguish between BackSpace and Delete because the Undo array needs to
539  // be constructed differently!
540  if( pEnd->nContent == m_nSttContent )
541  {
542  if( m_bGroup && !m_bBackSp ) return false;
543  m_bBackSp = true;
544  }
545  else if( pStt->nContent == m_nSttContent )
546  {
547  if( m_bGroup && m_bBackSp ) return false;
548  m_bBackSp = false;
549  }
550  else
551  return false;
552 
553  // are both Nodes (Node/Undo array) TextNodes at all?
554  SwTextNode * pDelTextNd = pStt->nNode.GetNode().GetTextNode();
555  if( !pDelTextNd ) return false;
556 
557  sal_Int32 nUChrPos = m_bBackSp ? 0 : m_aSttStr->getLength()-1;
558  sal_Unicode cDelChar = pDelTextNd->GetText()[ pStt->nContent.GetIndex() ];
559  CharClass& rCC = GetAppCharClass();
560  if( ( CH_TXTATR_BREAKWORD == cDelChar || CH_TXTATR_INWORD == cDelChar ) ||
561  rCC.isLetterNumeric( OUString( cDelChar ), 0 ) !=
562  rCC.isLetterNumeric( *m_aSttStr, nUChrPos ) )
563  return false;
564 
565  // tdf#132725 - if at-char/at-para flys would be deleted, don't group!
566  // DelContentIndex() would be called at the wrong time here, the indexes
567  // in the stored SwHistoryTextFlyCnt would be wrong when Undo is invoked
568  if (IsFlySelectedByCursor(*pDoc, *pStt, *pEnd))
569  {
570  return false;
571  }
572 
573  {
574  SwRedlineSaveDatas aTmpSav;
575  const bool bSaved = FillSaveData( rDelPam, aTmpSav, false );
576 
577  bool bOk = ( !m_pRedlSaveData && !bSaved ) ||
578  ( m_pRedlSaveData && bSaved &&
580  // aTmpSav.DeleteAndDestroyAll();
581  if( !bOk )
582  return false;
583 
584  pDoc->getIDocumentRedlineAccess().DeleteRedline( rDelPam, false, RedlineType::Any );
585  }
586 
587  // Both 'deletes' can be consolidated, so 'move' the related character
588  if( m_bBackSp )
589  m_nSttContent--; // BackSpace: add char to array!
590  else
591  {
592  m_nEndContent++; // Delete: attach char at the end
593  nUChrPos++;
594  }
595  m_aSttStr = m_aSttStr->replaceAt( nUChrPos, 0, OUString(cDelChar) );
596  pDelTextNd->EraseText( pStt->nContent, 1 );
597 
598  m_bGroup = true;
599  return true;
600 }
601 
603 {
604  if( m_pMvStt ) // Delete also the selection from UndoNodes array
605  {
606  // Insert saves content in IconSection
607  m_pMvStt->GetNode().GetNodes().Delete( *m_pMvStt, m_nNode );
608  m_pMvStt.reset();
609  }
610  m_pRedlSaveData.reset();
611 }
612 
614 {
615  SwRewriter aRewriter;
616 
617  bool bDone = false;
618 
619  for ( sal_uInt16 n = 0; n < rHistory.Count(); n++)
620  {
621  OUString aDescr = rHistory[n]->GetDescription();
622 
623  if (!aDescr.isEmpty())
624  {
625  aRewriter.AddRule(UndoArg2, aDescr);
626 
627  bDone = true;
628  break;
629  }
630  }
631 
632  if (! bDone)
633  {
634  aRewriter.AddRule(UndoArg2, SwResId(STR_FIELD));
635  }
636 
637  return aRewriter;
638 }
639 
641 {
642  switch (nChar)
643  {
644  case CH_TXTATR_BREAKWORD:
645  case CH_TXTATR_INWORD:
646  case CH_TXTATR_TAB:
647  case CH_TXTATR_NEWLINE:
652  case CH_TXT_ATR_FIELDSEP:
653  case CH_TXT_ATR_FIELDEND:
654  return true;
655 
656  default:
657  break;
658  }
659 
660  return false;
661 }
662 
663 static OUString lcl_DenotedPortion(const OUString& rStr, sal_Int32 nStart, sal_Int32 nEnd)
664 {
665  OUString aResult;
666 
667  auto nCount = nEnd - nStart;
668  if (nCount > 0)
669  {
670  sal_Unicode cLast = rStr[nEnd - 1];
671  if (lcl_IsSpecialCharacter(cLast))
672  {
673  switch(cLast)
674  {
675  case CH_TXTATR_TAB:
676  aResult = SwResId(STR_UNDO_TABS, nCount);
677 
678  break;
679  case CH_TXTATR_NEWLINE:
680  aResult = SwResId(STR_UNDO_NLS, nCount);
681 
682  break;
683 
684  case CH_TXTATR_INWORD:
685  case CH_TXTATR_BREAKWORD:
687  break;
688 
693  case CH_TXT_ATR_FIELDSEP:
694  case CH_TXT_ATR_FIELDEND:
695  break; // nothing?
696 
697  default:
698  assert(!"unexpected special character");
699  break;
700  }
701  SwRewriter aRewriter;
702  aRewriter.AddRule(UndoArg1, OUString::number(nCount));
703  aResult = aRewriter.Apply(aResult);
704  }
705  else
706  {
707  aResult = SwResId(STR_START_QUOTE) +
708  rStr.copy(nStart, nCount) +
709  SwResId(STR_END_QUOTE);
710  }
711  }
712 
713  return aResult;
714 }
715 
716 OUString DenoteSpecialCharacters(const OUString & rStr)
717 {
718  OUStringBuffer aResult;
719 
720  if (!rStr.isEmpty())
721  {
722  bool bStart = false;
723  sal_Int32 nStart = 0;
724  sal_Unicode cLast = 0;
725 
726  for( sal_Int32 i = 0; i < rStr.getLength(); i++)
727  {
728  if (lcl_IsSpecialCharacter(rStr[i]))
729  {
730  if (cLast != rStr[i])
731  bStart = true;
732 
733  }
734  else
735  {
736  if (lcl_IsSpecialCharacter(cLast))
737  bStart = true;
738  }
739 
740  if (bStart)
741  {
742  aResult.append(lcl_DenotedPortion(rStr, nStart, i));
743 
744  nStart = i;
745  bStart = false;
746  }
747 
748  cLast = rStr[i];
749  }
750 
751  aResult.append(lcl_DenotedPortion(rStr, nStart, rStr.getLength()));
752  }
753  else
755 
756  return aResult.makeStringAndClear();
757 }
758 
760 {
761  SwRewriter aResult;
762 
763  if (m_nNode != 0)
764  {
765  if (!m_sTableName.isEmpty())
766  {
767 
768  SwRewriter aRewriter;
769  aRewriter.AddRule(UndoArg1, SwResId(STR_START_QUOTE));
770  aRewriter.AddRule(UndoArg2, m_sTableName);
771  aRewriter.AddRule(UndoArg3, SwResId(STR_END_QUOTE));
772 
773  OUString sTmp = aRewriter.Apply(SwResId(STR_TABLE_NAME));
774  aResult.AddRule(UndoArg1, sTmp);
775  }
776  else
777  aResult.AddRule(UndoArg1, SwResId(STR_PARAGRAPHS));
778  }
779  else
780  {
781  OUString aStr;
782 
783  if (m_aSttStr && m_aEndStr && m_aSttStr->isEmpty() &&
784  m_aEndStr->isEmpty())
785  {
786  aStr = SwResId(STR_PARAGRAPH_UNDO);
787  }
788  else
789  {
790  std::optional<OUString> aTmpStr;
791  if (m_aSttStr)
792  aTmpStr = m_aSttStr;
793  else if (m_aEndStr)
794  aTmpStr = m_aEndStr;
795 
796  if (aTmpStr)
797  {
798  aStr = DenoteSpecialCharacters(*aTmpStr);
799  }
800  else
801  {
803  }
804  }
805 
806  aStr = ShortenString(aStr, nUndoStringLength, SwResId(STR_LDOTS));
807  if (m_pHistory)
808  {
810  aStr = aRewriter.Apply(aStr);
811  }
812 
813  aResult.AddRule(UndoArg1, aStr);
814  }
815 
816  return aResult;
817 }
818 
819 // Every object, anchored "AtContent" will be reanchored at rPos
820 static void lcl_ReAnchorAtContentFlyFrames( const SwFrameFormats& rSpzArr, SwPosition &rPos, sal_uLong nOldIdx )
821 {
822  if( !rSpzArr.empty() )
823  {
824  SwFlyFrameFormat* pFormat;
825  const SwFormatAnchor* pAnchor;
826  const SwPosition* pAPos;
827  for( size_t n = 0; n < rSpzArr.size(); ++n )
828  {
829  pFormat = static_cast<SwFlyFrameFormat*>(rSpzArr[n]);
830  pAnchor = &pFormat->GetAnchor();
831  if (pAnchor->GetAnchorId() == RndStdIds::FLY_AT_PARA)
832  {
833  pAPos = pAnchor->GetContentAnchor();
834  if( pAPos && nOldIdx == pAPos->nNode.GetIndex() )
835  {
836  SwFormatAnchor aAnch( *pAnchor );
837  aAnch.SetAnchor( &rPos );
838  pFormat->SetFormatAttr( aAnch );
839  }
840  }
841  }
842  }
843 }
844 
846 {
847  SwDoc& rDoc = rContext.GetDoc();
848 
849  sal_uLong nCalcStt = m_nSttNode - m_nNdDiff;
850 
851  if( m_nSectDiff && m_bBackSp )
852  nCalcStt += m_nSectDiff;
853 
854  SwNodeIndex aIdx(rDoc.GetNodes(), nCalcStt);
855  SwNode* pInsNd = &aIdx.GetNode();
856  SwNode* pMovedNode = nullptr;
857 
858  { // code block so that SwPosition is detached when deleting a Node
859  SwPosition aPos( aIdx );
860  if( !m_bDelFullPara )
861  {
862  assert(!m_bTableDelLastNd || pInsNd->IsTextNode());
863  if( pInsNd->IsTableNode() )
864  {
865  pInsNd = rDoc.GetNodes().MakeTextNode( aIdx,
866  rDoc.GetDfltTextFormatColl() );
867  --aIdx;
868  aPos.nNode = aIdx;
869  aPos.nContent.Assign( pInsNd->GetContentNode(), m_nSttContent );
870  }
871  else
872  {
873  if( pInsNd->IsContentNode() )
874  aPos.nContent.Assign( static_cast<SwContentNode*>(pInsNd), m_nSttContent );
875  if( !m_bTableDelLastNd )
876  pInsNd = nullptr; // do not delete Node!
877  }
878  }
879  else
880  pInsNd = nullptr; // do not delete Node!
881 
882  bool bNodeMove = 0 != m_nNode;
883 
884  if( m_aEndStr )
885  {
886  // discard attributes since they all saved!
887  SwTextNode* pTextNd = aPos.nNode.GetNode().GetTextNode();
888 
889  if( pTextNd && pTextNd->HasSwAttrSet() )
890  pTextNd->ResetAllAttr();
891 
892  if( pTextNd && pTextNd->GetpSwpHints() )
893  pTextNd->ClearSwpHintsArr( true );
894 
895  if( m_aSttStr && !m_bFromTableCopy )
896  {
897  sal_uLong nOldIdx = aPos.nNode.GetIndex();
898  rDoc.getIDocumentContentOperations().SplitNode( aPos, false );
899  // After the split all objects are anchored at the first
900  // paragraph, but the pHistory of the fly frame formats relies
901  // on anchoring at the start of the selection
902  // => selection backwards needs a correction.
903  if( m_bBackSp )
904  lcl_ReAnchorAtContentFlyFrames(*rDoc.GetSpzFrameFormats(), aPos, nOldIdx);
905  pTextNd = aPos.nNode.GetNode().GetTextNode();
906  }
907  if( pTextNd )
908  {
909  OUString const ins( pTextNd->InsertText(*m_aEndStr, aPos.nContent,
911  assert(ins.getLength() == m_aEndStr->getLength()); // must succeed
912  (void) ins;
913  // METADATA: restore
915  }
916  }
917  else if (m_aSttStr && bNodeMove && pInsNd == nullptr)
918  {
919  SwTextNode * pNd = aPos.nNode.GetNode().GetTextNode();
920  if( pNd )
921  {
922  if (m_nSttContent < pNd->GetText().getLength())
923  {
924  sal_uLong nOldIdx = aPos.nNode.GetIndex();
925  rDoc.getIDocumentContentOperations().SplitNode( aPos, false );
926  if( m_bBackSp )
927  lcl_ReAnchorAtContentFlyFrames(*rDoc.GetSpzFrameFormats(), aPos, nOldIdx);
928  }
929  else
930  ++aPos.nNode;
931  }
932  }
933  if( m_nSectDiff )
934  {
935  sal_uLong nMoveIndex = aPos.nNode.GetIndex();
936  int nDiff = 0;
937  if( m_bJoinNext )
938  {
939  nMoveIndex += m_nSectDiff + 1;
940  pMovedNode = &aPos.nNode.GetNode();
941  }
942  else
943  {
944  nMoveIndex -= m_nSectDiff + 1;
945  ++nDiff;
946  }
947  SwNodeIndex aMvIdx(rDoc.GetNodes(), nMoveIndex);
948  SwNodeRange aRg( aPos.nNode, 0 - nDiff, aPos.nNode, 1 - nDiff );
949  --aPos.nNode;
950  if( !m_bJoinNext )
951  pMovedNode = &aPos.nNode.GetNode();
952  rDoc.GetNodes().MoveNodes(aRg, rDoc.GetNodes(), aMvIdx);
953  ++aPos.nNode;
954  }
955 
956  if( bNodeMove )
957  {
958  SwNodeRange aRange( *m_pMvStt, 0, *m_pMvStt, m_nNode );
959  SwNodeIndex aCopyIndex( aPos.nNode, -1 );
960  rDoc.GetUndoManager().GetUndoNodes().Copy_(aRange, aPos.nNode,
961  // sw_redlinehide: delay creating frames: the flags on the
962  // nodes aren't necessarily up-to-date, and the redlines
963  // from m_pRedlSaveData aren't applied yet...
964  false);
965 
966  if( m_nReplaceDummy )
967  {
968  sal_uLong nMoveIndex;
969  if( m_bJoinNext )
970  {
971  nMoveIndex = m_nEndNode - m_nNdDiff;
972  aPos.nNode = nMoveIndex + m_nReplaceDummy;
973  }
974  else
975  {
976  aPos = SwPosition( aCopyIndex );
977  nMoveIndex = aPos.nNode.GetIndex() + m_nReplaceDummy + 1;
978  }
979  SwNodeIndex aMvIdx(rDoc.GetNodes(), nMoveIndex);
980  SwNodeRange aRg( aPos.nNode, 0, aPos.nNode, 1 );
981  pMovedNode = &aPos.nNode.GetNode();
982  // tdf#131684 without deleting frames
983  rDoc.GetNodes().MoveNodes(aRg, rDoc.GetNodes(), aMvIdx, false);
984  rDoc.GetNodes().Delete( aMvIdx);
985  }
986  }
987 
988  if( m_aSttStr )
989  {
990  aPos.nNode = m_nSttNode - m_nNdDiff + ( m_bJoinNext ? 0 : m_nReplaceDummy );
991  SwTextNode * pTextNd = aPos.nNode.GetNode().GetTextNode();
992  // If more than a single Node got deleted, also all "Node"
993  // attributes were saved
994  if (pTextNd != nullptr)
995  {
996  if( pTextNd->HasSwAttrSet() && bNodeMove && !m_aEndStr )
997  pTextNd->ResetAllAttr();
998 
999  if( pTextNd->GetpSwpHints() )
1000  pTextNd->ClearSwpHintsArr( true );
1001 
1002  // SectionNode mode and selection from top to bottom:
1003  // -> in StartNode is still the rest of the Join => delete
1004  aPos.nContent.Assign( pTextNd, m_nSttContent );
1005  OUString const ins( pTextNd->InsertText(*m_aSttStr, aPos.nContent,
1007  assert(ins.getLength() == m_aSttStr->getLength()); // must succeed
1008  (void) ins;
1009  // METADATA: restore
1010  pTextNd->RestoreMetadata(m_pMetadataUndoStart);
1011  }
1012  }
1013 
1014  if( m_pHistory )
1015  {
1016  m_pHistory->TmpRollback(&rDoc, m_nSetPos, false);
1017  if( m_nSetPos ) // there were Footnodes/FlyFrames
1018  {
1019  // are there others than these ones?
1020  if( m_nSetPos < m_pHistory->Count() )
1021  {
1022  // if so save the attributes of the others
1023  SwHistory aHstr;
1024  aHstr.Move( 0, m_pHistory.get(), m_nSetPos );
1025  m_pHistory->Rollback(&rDoc);
1026  m_pHistory->Move( 0, &aHstr );
1027  }
1028  else
1029  {
1030  m_pHistory->Rollback(&rDoc);
1031  m_pHistory.reset();
1032  }
1033  }
1034  }
1035 
1036  if( m_bResetPgDesc || m_bResetPgBrk )
1037  {
1038  sal_uInt16 nStt = m_bResetPgDesc ? sal_uInt16(RES_PAGEDESC) : sal_uInt16(RES_BREAK);
1039  sal_uInt16 nEnd = m_bResetPgBrk ? sal_uInt16(RES_BREAK) : sal_uInt16(RES_PAGEDESC);
1040 
1041  SwNode* pNode = rDoc.GetNodes()[ m_nEndNode + 1 ];
1042  if( pNode->IsContentNode() )
1043  static_cast<SwContentNode*>(pNode)->ResetAttr( nStt, nEnd );
1044  else if( pNode->IsTableNode() )
1045  static_cast<SwTableNode*>(pNode)->GetTable().GetFrameFormat()->ResetFormatAttr( nStt, nEnd );
1046  }
1047  }
1048  // delete the temporarily added Node
1049  if (pInsNd && !m_bTableDelLastNd)
1050  {
1051  assert(&aIdx.GetNode() == pInsNd);
1052  rDoc.GetNodes().Delete( aIdx );
1053  }
1054  if( m_pRedlSaveData )
1055  SetSaveData(rDoc, *m_pRedlSaveData);
1056 
1057  sal_uLong delFullParaEndNode(m_nEndNode);
1058  if (m_bDisableMakeFrames) // tdf#132944
1059  {
1061  SwTextNode *const pEndNode(aIdx.GetNodes()[m_nEndNode]->GetTextNode());
1063  for (SwTextFrame* pFrame = aIter.First(); pFrame; pFrame = aIter.Next())
1064  {
1066  if (pFrame->getRootFrame()->IsHideRedlines())
1067  {
1068  assert(pFrame->GetTextNodeFirst() == pEndNode); // can't be merged with previous
1069  layouts.insert(pFrame->getRootFrame());
1070  }
1071  for (SwRootFrame const*const pLayout : layouts)
1072  {
1073  pEndNode->DelFrames(pLayout); // SwUndoRedlineDelete will create it
1074  }
1075  }
1076  }
1077  else if (m_bDelFullPara && m_pRedlSaveData)
1078  {
1079  SwTextNode * pFirstMergedDeletedTextNode(nullptr);
1080  SwTextNode *const pNextNode = FindFirstAndNextNode(rDoc, *this,
1081  *m_pRedlSaveData, pFirstMergedDeletedTextNode);
1082  if (pNextNode)
1083  {
1084  bool bNonMerged(false);
1085  std::vector<SwTextFrame*> frames;
1087  for (SwTextFrame* pFrame = aIter.First(); pFrame; pFrame = aIter.Next())
1088  {
1089  if (pFrame->getRootFrame()->IsHideRedlines())
1090  {
1091  frames.push_back(pFrame);
1092  }
1093  else
1094  {
1095  bNonMerged = true;
1096  }
1097  }
1098  for (SwTextFrame *const pFrame : frames)
1099  {
1100  // could either destroy the text frames, or move them...
1101  // destroying them would have the advantage that we don't
1102  // need special code to *exclude* pFirstMergedDeletedTextNode
1103  // from MakeFrames for the layouts in Hide mode but not
1104  // layouts in Show mode ...
1105  // ... except that MakeFrames won't create them then :(
1106  pFrame->RegisterToNode(*pFirstMergedDeletedTextNode);
1107  assert(pFrame->GetMergedPara());
1108  assert(!bNonMerged); // delFullParaEndNode is such an awful hack
1109  (void) bNonMerged;
1110  delFullParaEndNode = pFirstMergedDeletedTextNode->GetIndex();
1111  }
1112  }
1113  }
1114  else if (m_aSttStr && (!m_bFromTableCopy || 0 != m_nNode))
1115  {
1116  // only now do we have redlines in the document again; fix up the split
1117  // frames
1118  SwTextNode *const pStartNode(aIdx.GetNodes()[m_nSttNode]->GetTextNode());
1119  assert(pStartNode);
1120  sw::RecreateStartTextFrames(*pStartNode);
1121  }
1122 
1123  // create frames after SetSaveData has recreated redlines
1124  if (0 != m_nNode && !m_bDisableMakeFrames)
1125  {
1126  // tdf#121031 if the start node is a text node, it already has a frame;
1127  // if it's a table, it does not
1128  // tdf#109376 exception: end on non-text-node -> start node was inserted
1129  assert(!m_bDelFullPara || (m_nSectDiff == 0));
1130  SwNodeIndex const start(rDoc.GetNodes(), m_nSttNode +
1131  ((m_bDelFullPara || !rDoc.GetNodes()[m_nSttNode]->IsTextNode() || pInsNd)
1132  ? 0 : 1));
1133  // don't include end node in the range: it may have been merged already
1134  // by the start node, or it may be merged by one of the moved nodes,
1135  // but if it isn't merged, its current frame(s) should be good...
1136  SwNodeIndex const end(rDoc.GetNodes(), m_bDelFullPara ? delFullParaEndNode : m_nEndNode);
1137  ::MakeFrames(&rDoc, start, end);
1138  }
1139 
1140  if (pMovedNode && !m_bDisableMakeFrames)
1141  { // probably better do this after creating all frames
1142  lcl_MakeAutoFrames(*rDoc.GetSpzFrameFormats(), pMovedNode->GetIndex());
1143  }
1144 
1145  // tdf#134021 only after MakeFrames(), because it may be the only node
1146  // that has layout frames
1147  if (pInsNd && m_bTableDelLastNd)
1148  {
1149  assert(&aIdx.GetNode() == pInsNd);
1150  SwPaM tmp(aIdx, aIdx);
1152  }
1153 
1154  AddUndoRedoPaM(rContext, true);
1155 }
1156 
1158 {
1159  SwPaM & rPam = AddUndoRedoPaM(rContext);
1160  SwDoc& rDoc = *rPam.GetDoc();
1161 
1162  if( m_pRedlSaveData )
1163  {
1164  const bool bSuccess = FillSaveData(rPam, *m_pRedlSaveData);
1165  OSL_ENSURE(bSuccess,
1166  "SwUndoDelete::Redo: used to have redline data, but now none?");
1167  if (!bSuccess)
1168  {
1169  m_pRedlSaveData.reset();
1170  }
1171  }
1172 
1173  if( !m_bDelFullPara )
1174  {
1175  // tdf#128739 correct cursors but do not delete bookmarks yet
1176  ::PaMCorrAbs(rPam, *rPam.End());
1177  SetPaM(rPam);
1178 
1179  if( !m_bJoinNext ) // then restore selection from bottom to top
1180  rPam.Exchange();
1181  }
1182 
1183  if( m_pHistory ) // are the attributes saved?
1184  {
1185  m_pHistory->SetTmpEnd( m_pHistory->Count() );
1186  SwHistory aHstr;
1187  aHstr.Move( 0, m_pHistory.get() );
1188 
1189  if( m_bDelFullPara )
1190  {
1191  OSL_ENSURE( rPam.HasMark(), "PaM without Mark" );
1192  DelContentIndex( *rPam.GetMark(), *rPam.GetPoint(),
1194 
1195  DelBookmarks(rPam.GetMark()->nNode, rPam.GetPoint()->nNode);
1196  }
1197  else
1198  DelContentIndex( *rPam.GetMark(), *rPam.GetPoint() );
1199  m_nSetPos = m_pHistory ? m_pHistory->Count() : 0;
1200 
1201  m_pHistory->Move( m_nSetPos, &aHstr );
1202  }
1203  else
1204  {
1205  if( m_bDelFullPara )
1206  {
1207  OSL_ENSURE( rPam.HasMark(), "PaM without Mark" );
1208  DelContentIndex( *rPam.GetMark(), *rPam.GetPoint(),
1210 
1211  DelBookmarks( rPam.GetMark()->nNode, rPam.GetPoint()->nNode );
1212  }
1213  else
1214  DelContentIndex( *rPam.GetMark(), *rPam.GetPoint() );
1215  m_nSetPos = m_pHistory ? m_pHistory->Count() : 0;
1216  }
1217 
1218  if( !m_aSttStr && !m_aEndStr )
1219  {
1221  {
1222  DelFullParaMoveFrames(rDoc, *this, *m_pRedlSaveData);
1223  }
1224 
1225  SwNodeIndex aSttIdx = ( m_bDelFullPara || m_bJoinNext )
1226  ? rPam.GetMark()->nNode
1227  : rPam.GetPoint()->nNode;
1228  SwTableNode* pTableNd = aSttIdx.GetNode().GetTableNode();
1229  if( pTableNd )
1230  {
1231  if( m_bTableDelLastNd )
1232  {
1233  // than add again a Node at the end
1234  const SwNodeIndex aTmpIdx( *pTableNd->EndOfSectionNode(), 1 );
1235  rDoc.GetNodes().MakeTextNode( aTmpIdx,
1237  }
1238 
1239  SwContentNode* pNextNd = rDoc.GetNodes()[
1240  pTableNd->EndOfSectionIndex()+1 ]->GetContentNode();
1241  if( pNextNd )
1242  {
1243  SwFrameFormat* pTableFormat = pTableNd->GetTable().GetFrameFormat();
1244 
1245  const SfxPoolItem *pItem;
1246  if( SfxItemState::SET == pTableFormat->GetItemState( RES_PAGEDESC,
1247  false, &pItem ) )
1248  pNextNd->SetAttr( *pItem );
1249 
1250  if( SfxItemState::SET == pTableFormat->GetItemState( RES_BREAK,
1251  false, &pItem ) )
1252  pNextNd->SetAttr( *pItem );
1253  }
1254  pTableNd->DelFrames();
1255  }
1256  else if (*rPam.GetMark() == *rPam.GetPoint())
1257  { // paragraph with only footnote or as-char fly, delete that
1258  // => DelContentIndex has already deleted it! nothing to do here
1260  return;
1261  }
1262 
1263  // avoid asserts from ~SwIndexReg for deleted nodes
1264  SwPaM aTmp(*rPam.End());
1265  if (!aTmp.Move(fnMoveForward, GoInNode))
1266  {
1267  *aTmp.GetPoint() = *rPam.Start();
1268  aTmp.Move(fnMoveBackward, GoInNode);
1269  }
1270  assert(aTmp.GetPoint()->nNode != rPam.GetPoint()->nNode
1271  && aTmp.GetPoint()->nNode != rPam.GetMark()->nNode);
1272  ::PaMCorrAbs(rPam, *aTmp.GetPoint());
1273 
1274  rPam.DeleteMark();
1275 
1276  rDoc.GetNodes().Delete( aSttIdx, m_nEndNode - m_nSttNode );
1277  }
1278  else if( m_bDelFullPara )
1279  {
1280  assert(!"dead code");
1281  // The Pam was incremented by one at Point (== end) to provide space
1282  // for UNDO. This now needs to be reverted!
1283  --rPam.End()->nNode;
1284  if( rPam.GetPoint()->nNode == rPam.GetMark()->nNode )
1285  *rPam.GetMark() = *rPam.GetPoint();
1287  }
1288  else
1290 }
1291 
1293 {
1294  // this action does not seem idempotent,
1295  // so make sure it is only executed once on repeat
1296  if (rContext.m_bDeleteRepeated)
1297  return;
1298 
1299  SwPaM & rPam = rContext.GetRepeatPaM();
1300  SwDoc& rDoc = *rPam.GetDoc();
1301  ::sw::GroupUndoGuard const undoGuard(rDoc.GetIDocumentUndoRedo());
1302  if( !rPam.HasMark() )
1303  {
1304  rPam.SetMark();
1305  rPam.Move( fnMoveForward, GoInContent );
1306  }
1307  if( m_bDelFullPara )
1309  else
1311  rContext.m_bDeleteRepeated = true;
1312 }
1313 
1314 void SwUndoDelete::SetTableName(const OUString & rName)
1315 {
1316  m_sTableName = rName;
1317 }
1318 
1320 {
1321  xmlTextWriterStartElement(pWriter, BAD_CAST("SwUndoDelete"));
1322  xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
1323  SwUndo::dumpAsXml(pWriter);
1325  xmlTextWriterEndElement(pWriter);
1326 }
1327 
1328 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uLong m_nNdDiff
Definition: UndoDelete.hxx:50
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:682
SwPaM & AddUndoRedoPaM(::sw::UndoRedoContext &, bool const bCorrToContent=false) const
Definition: undobj.cxx:108
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:151
constexpr TypedWhichId< SwFormatPageDesc > RES_PAGEDESC(93)
void DeleteMark()
Definition: pam.hxx:177
sal_uLong GetIndex() const
Definition: node.hxx:282
SwNode & GetNode(bool bPoint=true) const
Definition: pam.hxx:223
bool GoInContent(SwPaM &rPam, SwMoveFnCollection const &fnMove)
Definition: pam.cxx:963
sal_uLong Count() const
Definition: ndarr.hxx:142
static OUString GetPlaceHolder(SwUndoArg eId)
Definition: SwRewriter.cxx:55
Marks a position in the document model.
Definition: pam.hxx:35
void DelBookmarks(const SwNodeIndex &rStt, const SwNodeIndex &rEnd, std::vector< SaveBookmark > *pSaveBkmk, const SwIndex *pSttIdx, const SwIndex *pEndIdx)
Definition: docbm.cxx:1791
bool IsSectionNode() const
Definition: node.hxx:644
std::unique_ptr< SwHistory > m_pHistory
Definition: undobj.hxx:166
SwNodes const & GetUndoNodes() const
Definition: docundo.cxx:73
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: undel.cxx:1157
void DelFrames(SwRootFrame const *pLayout=nullptr)
Method deletes all views of document for the node.
Definition: ndtbl.cxx:2427
const OUString & GetText() const
Definition: ndtxt.hxx:211
SwUndoId
Definition: swundo.hxx:29
virtual sal_uInt16 ResetAllAttr() override
Definition: ndtxt.cxx:5142
SwpHints * GetpSwpHints()
Definition: ndtxt.hxx:219
std::unique_ptr< SwNodeIndex > m_pMvStt
Definition: UndoDelete.hxx:41
size_t size() const
Definition: UndoCore.hxx:76
SwNodeIndex nNode
Definition: pam.hxx:37
sal_uLong m_nNode
Definition: UndoDelete.hxx:49
virtual sal_Int32 Len() const override
Definition: ndtxt.cxx:274
sal_uIntPtr sal_uLong
SwPaM & GetRepeatPaM()
Definition: UndoCore.hxx:128
const SwPosition * GetMark() const
Definition: pam.hxx:209
sal_uLong m_nEndNode
Definition: undobj.hxx:229
sal_Int64 n
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: undel.cxx:1319
bool SaveContent(const SwPosition *pStt, const SwPosition *pEnd, SwTextNode *pSttTextNd, SwTextNode *pEndTextNd)
Definition: undel.cxx:439
Definition: doc.hxx:184
TElementType * Next()
Definition: calbck.hxx:351
sal_uInt16 m_nSetPos
Definition: UndoDelete.hxx:53
constexpr TypedWhichId< SvxFormatBreakItem > RES_BREAK(94)
bool m_bJoinNext
Definition: UndoDelete.hxx:57
SwNode & GetNode() const
Definition: ndindex.hxx:119
#define CH_TXTATR_NEWLINE
Definition: hintids.hxx:173
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:143
virtual bool DeleteAndJoin(SwPaM &, const bool bForceJoinNext=false)=0
complete delete of a given PaM
std::optional< OUString > m_aEndStr
Definition: UndoDelete.hxx:42
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:314
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
#define CH_TXT_ATR_FORMELEMENT
Definition: hintids.hxx:177
void Copy_(const SwNodeRange &rRg, const SwNodeIndex &rInsPos, bool bNewFrames=true) const
Definition: ndarr.hxx:176
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:201
const SwFrameFormats * GetSpzFrameFormats() const
Definition: doc.hxx:739
static SwTextNode * FindFirstAndNextNode(SwDoc &rDoc, SwUndRng const &rRange, SwRedlineSaveDatas const &rRedlineSaveData, SwTextNode *&o_rpFirstMergedDeletedTextNode)
Definition: undel.cxx:69
virtual SwRewriter GetRewriter() const override
Returns rewriter for this undo object.
Definition: undel.cxx:759
bool CanGrouping(SwDoc *, const SwPaM &)
Definition: undel.cxx:518
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: undobj.cxx:707
std::shared_ptr< MetadatableUndo > CreateUndoForDelete()
#define CH_TXTATR_BREAKWORD
Definition: hintids.hxx:170
void Delete(const SwNodeIndex &rPos, sal_uLong nNodes=1)
delete nodes
Definition: nodes.cxx:1069
bool isLetterNumeric(const OUString &rStr, sal_Int32 nPos) const
sal_uInt16 sal_Unicode
bool m_bResetPgBrk
Definition: UndoDelete.hxx:61
#define CH_TXTATR_INWORD
Definition: hintids.hxx:171
SwTableNode * GetTableNode()
Definition: node.hxx:599
SwUndoDelete(SwPaM &, bool bFullPara=false, bool bCalledByTableCpy=false)
Definition: undel.cxx:172
SwIndex nContent
Definition: pam.hxx:38
bool empty() const
Definition: docary.hxx:265
sal_uLong m_nReplaceDummy
Definition: UndoDelete.hxx:52
SwNodeIndex aStart
Definition: ndindex.hxx:132
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
Definition: doc.cxx:425
const SwTextFormatColl * GetDfltTextFormatColl() const
Definition: doc.hxx:773
#define CH_TXT_ATR_INPUTFIELDSTART
Definition: hintids.hxx:174
int nCount
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
const SwTable & GetTable() const
Definition: node.hxx:497
static bool CanRedlineGroup(SwRedlineSaveDatas &rCurr, const SwRedlineSaveDatas &rCheck, bool bCurrIsEnd)
Definition: undobj.cxx:1485
bool empty() const
bool m_bFromTableCopy
Definition: UndoDelete.hxx:62
SwDoc & GetDoc() const
Definition: UndoCore.hxx:94
static OUString lcl_DenotedPortion(const OUString &rStr, sal_Int32 nStart, sal_Int32 nEnd)
Definition: undel.cxx:663
virtual ~SwUndoDelete() override
Definition: undel.cxx:602
void MakeFrames(SwDoc *pDoc, const SwNodeIndex &rSttIdx, const SwNodeIndex &rEndIdx)
Definition: frmtool.cxx:1912
Specific frame formats (frames, DrawObjects).
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:163
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: undel.cxx:1292
void SetTableName(const OUString &rName)
Definition: undel.cxx:1314
bool IsContentNode() const
Definition: node.hxx:628
bool m_bDisableMakeFrames
Definition: UndoDelete.hxx:63
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
struct _xmlTextWriter * xmlTextWriterPtr
const SwAttrSet * GetpSwAttrSet() const
Definition: node.hxx:443
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:501
Style of a layout element.
Definition: frmfmt.hxx:57
::sw::UndoManager & GetUndoManager()
Definition: doc.cxx:132
void DeRegister()
deregister the currently registered History
Definition: ndhints.hxx:197
std::shared_ptr< ::sfx2::MetadatableUndo > m_pMetadataUndoEnd
Definition: UndoDelete.hxx:45
const SwFormatAnchor & GetAnchor(bool=true) const
Definition: fmtanchr.hxx:81
bool m_bDelFullPara
Definition: UndoDelete.hxx:59
int i
bool GoInNode(SwPaM &rPam, SwMoveFnCollection const &fnMove)
Definition: pam.cxx:954
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:131
const SwPosition * GetPoint() const
Definition: pam.hxx:207
void DelContentIndex(const SwPosition &pMark, const SwPosition &pPoint, DelContentType nDelContentType=DelContentType::AllMask)
Definition: undobj.cxx:862
SwIndex & Assign(SwIndexReg *, sal_Int32)
Definition: index.cxx:206
RndStdIds GetAnchorId() const
Definition: fmtanchr.hxx:65
OUString Apply(const OUString &rStr) const
Definition: SwRewriter.cxx:43
const SwPosition * GetContentAnchor() const
Definition: fmtanchr.hxx:67
Count
static void SetSaveData(SwDoc &rDoc, SwRedlineSaveDatas &rSData)
Definition: undobj.cxx:1458
static SwRewriter lcl_RewriterFromHistory(SwHistory &rHistory)
Definition: undel.cxx:613
void Exchange()
Definition: pam.cxx:489
TElementType * First()
Definition: calbck.hxx:343
virtual bool DeleteRedline(const SwPaM &rPam, bool bSaveInUndo, RedlineType nDelType)=0
bool m_bTableDelLastNd
Definition: UndoDelete.hxx:58
FlyAnchors.
Definition: fmtanchr.hxx:34
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
Definition: pam.hxx:205
sal_Int32 m_nEndContent
Definition: undobj.hxx:230
SwDoc * GetDoc() const
Definition: pam.hxx:243
sal_uLong m_nSectDiff
Definition: UndoDelete.hxx:51
static void DelFullParaMoveFrames(SwDoc &rDoc, SwUndRng const &rRange, SwRedlineSaveDatas const &rRedlineSaveData)
Definition: undel.cxx:117
Marks a character position inside a document model node.
Definition: index.hxx:37
#define CH_TXT_ATR_FIELDSTART
Definition: hintids.hxx:179
void AddRule(SwUndoArg eWhat, const OUString &rWith)
Definition: SwRewriter.cxx:29
std::shared_ptr< MetadatableUndo > CreateUndo() const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
Definition: format.cxx:396
Marks a node in the document model.
Definition: ndindex.hxx:31
bool m_bCacheComment
Definition: undobj.hxx:61
bool HasSwAttrSet() const
Definition: node.hxx:444
OUString SwResId(const char *pId)
Definition: swmodule.cxx:178
enumrange< T >::Iterator end(enumrange< T >)
const SwPosition * Start() const
Definition: pam.hxx:212
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
virtual bool IsIgnoreRedline() const =0
static void lcl_MakeAutoFrames(const SwFrameFormats &rSpzArr, sal_uLong nMovedIndex)
Definition: undel.cxx:54
sal_uInt16 Count() const
Definition: rolbck.hxx:378
sal_uLong m_nSttNode
Definition: undobj.hxx:229
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:458
void EraseText(const SwIndex &rIdx, const sal_Int32 nCount=SAL_MAX_INT32, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
delete text content ATTENTION: must not be called with a range that overlaps the start of an attribut...
Definition: ndtxt.cxx:2660
OUString InsertText(const OUString &rStr, const SwIndex &rIdx, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
insert text content
Definition: ndtxt.cxx:2277
void ClearSwpHintsArr(bool bDelFields)
Definition: thints.cxx:3365
sal_uLong EndOfSectionIndex() const
Definition: node.hxx:677
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
#define CH_TXT_ATR_INPUTFIELDEND
Definition: hintids.hxx:175
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:334
bool m_bResetPgDesc
Definition: UndoDelete.hxx:60
virtual bool SetAttr(const SfxPoolItem &)
made virtual
Definition: node.cxx:1540
void SetPaM(SwPaM &, bool bCorrToContent=false) const
Definition: undobj.cxx:80
DelContentType
Definition: undobj.hxx:133
void RecreateStartTextFrames(SwTextNode &rNode)
Definition: frmtool.cxx:1361
OUString ShortenString(const OUString &rStr, sal_Int32 nLength, const OUString &rFillStr)
Shortens a string to a maximum length.
Definition: undobj.cxx:1517
static void lcl_ReAnchorAtContentFlyFrames(const SwFrameFormats &rSpzArr, SwPosition &rPos, sal_uLong nOldIdx)
Definition: undel.cxx:820
SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:59
virtual bool DelFullPara(SwPaM &)=0
Delete full paragraphs.
OUString DenoteSpecialCharacters(const OUString &rStr)
Denotes special characters in a string.
Definition: undel.cxx:716
sal_Int32 GetIndex() const
Definition: index.hxx:95
virtual void MakeFrames()
Creates the views.
Definition: atrfrm.cxx:2648
SwNodes & GetNodes()
Definition: doc.hxx:403
virtual SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId, bool bRegardLanguage=true)=0
Return "Auto-Collection with ID.
const SwPosition * End() const
Definition: pam.hxx:217
SwNodeIndex aEnd
Definition: ndindex.hxx:133
#define CH_TXTATR_TAB
Definition: hintids.hxx:172
void PaMCorrAbs(const SwPaM &rRange, const SwPosition &rNewPos)
Function declarations so that everything below the CursorShell can move the Cursor once in a while...
Definition: doccorr.cxx:85
double getLength(const B2DPolygon &rCandidate)
static bool lcl_IsSpecialCharacter(sal_Unicode nChar)
Definition: undel.cxx:640
#define CH_TXT_ATR_FIELDEND
Definition: hintids.hxx:181
SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:58
virtual bool SplitNode(const SwPosition &rPos, bool bChkTableStart)=0
Split a node at rPos (implemented only for TextNode).
bool IsTableNode() const
Definition: node.hxx:640
size_t size() const
bool IsFlySelectedByCursor(SwDoc const &rDoc, SwPosition const &rStart, SwPosition const &rEnd)
check at-char and at-para flys in rDoc
Definition: undobj.cxx:1663
std::unique_ptr< SwRedlineSaveDatas > m_pRedlSaveData
Definition: UndoDelete.hxx:43
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:475
static bool FillSaveData(const SwPaM &rRange, SwRedlineSaveDatas &rSData, bool bDelRange=true, bool bCopyNext=true)
Definition: undobj.cxx:1393
virtual const SwRedlineTable & GetRedlineTable() const =0
std::pair< const_iterator, bool > insert(Value &&x)
std::shared_ptr< ::sfx2::MetadatableUndo > m_pMetadataUndoStart
Definition: UndoDelete.hxx:44
#define CH_TXT_ATR_FIELDSEP
Definition: hintids.hxx:180
std::optional< OUString > m_aSttStr
Definition: UndoDelete.hxx:42
CharClass & GetAppCharClass()
Definition: init.cxx:709
void Move(sal_uInt16 nPos, SwHistory *pIns, sal_uInt16 const nStart=0)
Definition: rolbck.hxx:386
OUString m_sTableName
Definition: UndoDelete.hxx:47
aStr
void RestoreMetadata(std::shared_ptr< MetadatableUndo > const &i_pUndo)
sal_Int32 m_nSttContent
Definition: undobj.hxx:230
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: undel.cxx:845
const int nUndoStringLength
Definition: UndoCore.hxx:224
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:836
SwTextNode * MakeTextNode(const SwNodeIndex &rWhere, SwTextFormatColl *pColl, bool bNewFrames=true)
Implementations of "Make...Node" are in the given .cxx-files.
Definition: ndtxt.cxx:104
void SetAnchor(const SwPosition *pPos)
Definition: atrfrm.cxx:1483
bool MoveNodes(const SwNodeRange &, SwNodes &rNodes, const SwNodeIndex &, bool bNewFrames=true)
move the node pointer
Definition: nodes.cxx:394
Base class of the Writer document model elements.
Definition: node.hxx:79
SwTextFormatColl * GetTextColl() const
Definition: ndtxt.hxx:830
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo