LibreOffice Module sw (master)  1
edglbldc.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 <doc.hxx>
21 #include <IDocumentUndoRedo.hxx>
23 #include <IDocumentState.hxx>
24 #include <editsh.hxx>
25 #include <pam.hxx>
26 #include <ndtxt.hxx>
27 #include <docary.hxx>
28 #include <swundo.hxx>
29 #include <section.hxx>
30 #include <doctxm.hxx>
31 #include <edglbldc.hxx>
32 
34 {
36 }
37 
39 {
41  if( !GetDoc()->getIDocumentState().IsModified() ) // Bug 57028
42  {
44  }
46 }
47 
49 {
51 }
52 
54 {
55  rArr.clear();
56 
58  return;
59 
60  // then all linked areas on the topmost level
61  SwDoc* pMyDoc = GetDoc();
62  const SwSectionFormats& rSectFormats = pMyDoc->GetSections();
63 
64  for( auto n = rSectFormats.size(); n; )
65  {
66  const SwSection* pSect = rSectFormats[ --n ]->GetGlobalDocSection();
67  if( pSect )
68  {
69  std::unique_ptr<SwGlblDocContent> pNew;
70  switch( pSect->GetType() )
71  {
73  break; // ignore
75  assert( dynamic_cast<const SwTOXBaseSection*>( pSect) && "no TOXBaseSection!" );
76  pNew.reset(new SwGlblDocContent( static_cast<const SwTOXBaseSection*>(pSect) ));
77  break;
78 
79  default:
80  pNew.reset(new SwGlblDocContent( pSect ));
81  break;
82  }
83  rArr.insert( std::move(pNew) );
84  }
85  }
86 
87  // and finally add the dummies (other text)
88  SwNode* pNd;
89  SwNodeOffset nSttIdx = pMyDoc->GetNodes().GetEndOfExtras().GetIndex() + 2;
90  for( SwGlblDocContents::size_type n = 0; n < rArr.size(); ++n )
91  {
92  const SwGlblDocContent& rNew = *rArr[ n ];
93  // Search from StartPos until rNew.DocPos for a content node.
94  // If one exists then a dummy entry is needed.
95  for( ; nSttIdx < rNew.GetDocPos(); ++nSttIdx )
96  if( ( pNd = pMyDoc->GetNodes()[ nSttIdx ])->IsContentNode()
97  || pNd->IsSectionNode() || pNd->IsTableNode() )
98  {
99  std::unique_ptr<SwGlblDocContent> pNew(new SwGlblDocContent( nSttIdx ));
100  if( rArr.insert( std::move(pNew) ).second )
101  ++n; // to the next position
102  break;
103  }
104 
105  // set StartPosition to the end
106  nSttIdx = pMyDoc->GetNodes()[ rNew.GetDocPos() ]->EndOfSectionIndex();
107  ++nSttIdx;
108  }
109 
110  // Should the end also be set?
111  if( !rArr.empty() )
112  {
113  SwNodeOffset nNdEnd = pMyDoc->GetNodes().GetEndOfContent().GetIndex();
114  for( ; nSttIdx < nNdEnd; ++nSttIdx )
115  if( ( pNd = pMyDoc->GetNodes()[ nSttIdx ])->IsContentNode()
116  || pNd->IsSectionNode() || pNd->IsTableNode() )
117  {
118  rArr.insert( std::make_unique<SwGlblDocContent>( nSttIdx ) );
119  break;
120  }
121  }
122  else
123  {
124  std::unique_ptr<SwGlblDocContent> pNew(new SwGlblDocContent(
125  pMyDoc->GetNodes().GetEndOfExtras().GetIndex() + 2 ));
126  rArr.insert( std::move(pNew) );
127  }
128 }
129 
131  SwSectionData & rNew)
132 {
134  return;
135 
136  CurrShell aCurr( this );
137  StartAllAction();
138 
139  SwPaM* pCursor = GetCursor();
140  if( pCursor->GetNext() != pCursor || IsTableMode() )
141  ClearMark();
142 
143  SwPosition& rPos = *pCursor->GetPoint();
144  rPos.nNode = rInsPos.GetDocPos();
145 
146  bool bEndUndo = false;
147  SwDoc* pMyDoc = GetDoc();
148  SwTextNode *const pTextNd = rPos.nNode.GetNode().GetTextNode();
149  if( pTextNd )
150  rPos.nContent.Assign( pTextNd, 0 );
151  else
152  {
153  bEndUndo = true;
154  pMyDoc->GetIDocumentUndoRedo().StartUndo( SwUndoId::START, nullptr );
155  --rPos.nNode;
157  pCursor->SetMark();
158  }
159 
160  InsertSection( rNew );
161 
162  if( bEndUndo )
163  {
164  pMyDoc->GetIDocumentUndoRedo().EndUndo( SwUndoId::END, nullptr );
165  }
166  EndAllAction();
167 }
168 
170  const SwTOXBase& rTOX )
171 {
173  return false;
174 
175  CurrShell aCurr( this );
176  StartAllAction();
177 
178  SwPaM* pCursor = GetCursor();
179  if( pCursor->GetNext() != pCursor || IsTableMode() )
180  ClearMark();
181 
182  SwPosition& rPos = *pCursor->GetPoint();
183  rPos.nNode = rInsPos.GetDocPos();
184 
185  bool bEndUndo = false;
186  SwDoc* pMyDoc = GetDoc();
187  SwTextNode* pTextNd = rPos.nNode.GetNode().GetTextNode();
188  if (pTextNd && pTextNd->GetText().getLength() && rPos.nNode.GetIndex() + 1 !=
189  pMyDoc->GetNodes().GetEndOfContent().GetIndex() )
190  rPos.nContent.Assign( pTextNd, 0 );
191  else
192  {
193  bEndUndo = true;
194  pMyDoc->GetIDocumentUndoRedo().StartUndo( SwUndoId::START, nullptr );
195  --rPos.nNode;
197  }
198 
199  InsertTableOf( rTOX );
200 
201  if( bEndUndo )
202  {
203  pMyDoc->GetIDocumentUndoRedo().EndUndo( SwUndoId::END, nullptr );
204  }
205  EndAllAction();
206 
207  return true;
208 }
209 
211 {
213  return false;
214 
215  CurrShell aCurr( this );
216  StartAllAction();
217 
218  SwPaM* pCursor = GetCursor();
219  if( pCursor->GetNext() != pCursor || IsTableMode() )
220  ClearMark();
221 
222  SwPosition& rPos = *pCursor->GetPoint();
223  rPos.nNode = rInsPos.GetDocPos() - 1;
224  rPos.nContent.Assign( nullptr, 0 );
225 
226  SwDoc* pMyDoc = GetDoc();
228  EndAllAction();
229  return true;
230 }
231 
233  size_t nDelPos )
234 {
236  return;
237 
238  CurrShell aCurr( this );
239  StartAllAction();
241 
242  SwPaM* pCursor = GetCursor();
243  if( pCursor->GetNext() != pCursor || IsTableMode() )
244  ClearMark();
245 
246  SwPosition& rPos = *pCursor->GetPoint();
247 
248  SwDoc* pMyDoc = GetDoc();
249  const SwGlblDocContent& rDelPos = *rArr[ nDelPos ];
250  SwNodeOffset nDelIdx = rDelPos.GetDocPos();
251  if( 1 == rArr.size() )
252  {
253  // we need at least one node!
254  rPos.nNode = nDelIdx - 1;
255  rPos.nContent.Assign( nullptr, 0 );
256 
258  ++nDelIdx;
259  }
260 
261  switch( rDelPos.GetType() )
262  {
263  case GLBLDOC_UNKNOWN:
264  {
265  rPos.nNode = nDelIdx;
266  pCursor->SetMark();
267  if( ++nDelPos < rArr.size() )
268  rPos.nNode = rArr[ nDelPos ]->GetDocPos();
269  else
270  rPos.nNode = pMyDoc->GetNodes().GetEndOfContent();
271  --rPos.nNode;
272  if( !pMyDoc->getIDocumentContentOperations().DelFullPara( *pCursor ) )
273  Delete();
274  }
275  break;
276 
277  case GLBLDOC_TOXBASE:
278  {
279  const SwTOXBaseSection* pTOX = static_cast<const SwTOXBaseSection*>(rDelPos.GetTOX());
280  pMyDoc->DeleteTOX( *pTOX, true );
281  }
282  break;
283 
284  case GLBLDOC_SECTION:
285  {
286  SwSectionFormat* pSectFormat = const_cast<SwSectionFormat*>(rDelPos.GetSection()->GetFormat());
287  pMyDoc->DelSectionFormat( pSectFormat, true );
288  }
289  break;
290  }
291 
293  EndAllAction();
294 }
295 
297  size_t nFromPos, size_t nToPos,
298  size_t nInsPos )
299 {
301  nFromPos >= rArr.size() || nToPos > rArr.size() ||
302  nInsPos > rArr.size() || nFromPos >= nToPos ||
303  ( nFromPos <= nInsPos && nInsPos <= nToPos ) )
304  return false;
305 
306  CurrShell aCurr( this );
307  StartAllAction();
308 
309  SwPaM* pCursor = GetCursor();
310  if( pCursor->GetNext() != pCursor || IsTableMode() )
311  ClearMark();
312 
313  SwDoc* pMyDoc = GetDoc();
314  SwNodeRange aRg( pMyDoc->GetNodes(), rArr[ nFromPos ]->GetDocPos() );
315  if( nToPos < rArr.size() )
316  aRg.aEnd = rArr[ nToPos ]->GetDocPos();
317  else
318  aRg.aEnd = pMyDoc->GetNodes().GetEndOfContent();
319 
320  SwNodeIndex aInsPos( pMyDoc->GetNodes() );
321  if( nInsPos < rArr.size() )
322  aInsPos = rArr[ nInsPos ]->GetDocPos();
323  else
324  aInsPos = pMyDoc->GetNodes().GetEndOfContent();
325 
326  bool bRet = pMyDoc->getIDocumentContentOperations().MoveNodeRange( aRg, aInsPos,
328 
329  EndAllAction();
330  return bRet;
331 }
332 
334 {
336  return;
337 
338  CurrShell aCurr( this );
339  SttCursorMove();
340 
341  SwPaM* pCursor = GetCursor();
342  if( pCursor->GetNext() != pCursor || IsTableMode() )
343  ClearMark();
344 
345  SwPosition& rCursorPos = *pCursor->GetPoint();
346  rCursorPos.nNode = rPos.GetDocPos();
347 
348  SwDoc* pMyDoc = GetDoc();
349  SwContentNode * pCNd = rCursorPos.nNode.GetNode().GetContentNode();
350  if( !pCNd )
351  pCNd = pMyDoc->GetNodes().GoNext( &rCursorPos.nNode );
352 
353  rCursorPos.nContent.Assign( pCNd, 0 );
354 
355  EndCursorMove();
356 }
357 
359 {
361  m_PTR.pTOX = nullptr;
362  m_nDocPos = nPos;
363 }
364 
366 {
368  m_PTR.pTOX = pTOX;
369 
370  const SwSectionNode* pSectNd = pTOX->GetFormat()->GetSectionNode();
371  m_nDocPos = pSectNd ? pSectNd->GetIndex() : SwNodeOffset(0);
372 }
373 
375 {
377  m_PTR.pSect = pSect;
378 
379  const SwSectionNode* pSectNd = pSect->GetFormat()->GetSectionNode();
380  m_nDocPos = pSectNd ? pSectNd->GetIndex() : SwNodeOffset(0);
381 }
382 
383 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Marks a position in the document model.
Definition: pam.hxx:36
bool IsSectionNode() const
Definition: node.hxx:654
bool MoveGlobalDocContent(const SwGlblDocContents &rArr, size_t nFromPos, size_t nToPos, size_t nNewPos)
Definition: edglbldc.cxx:296
const OUString & GetText() const
Definition: ndtxt.hxx:218
void DelSectionFormat(SwSectionFormat *pFormat, bool bDelNodes=false)
Definition: ndsect.cxx:521
void InsertTableOf(const SwTOXBase &rTOX, const SfxItemSet *pSet=nullptr)
Insert content table. Renew if required.
Definition: edtox.cxx:123
SwNodeIndex nNode
Definition: pam.hxx:38
bool IsTableMode() const
Definition: crsrsh.hxx:648
virtual void SetModified()=0
Must be called manually at changes of format.
bool IsModified() const
Changes in document?
Definition: edws.cxx:65
sal_Int64 n
virtual SwUndoId EndUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Closes undo block.
SwSection const * InsertSection(SwSectionData &rNewData, SfxItemSet const *const =nullptr)
Definition: edsect.cxx:35
Definition: doc.hxx:187
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
Definition: edws.cxx:234
const IDocumentSettingAccess & getIDocumentSettingAccess() const
Provides access to the document setting interface.
Definition: viewsh.cxx:2777
SwNode & GetNode() const
Definition: ndindex.hxx:119
SwNodeOffset m_nDocPos
Definition: edglbldc.hxx:39
SwSectionFormat * GetFormat()
Definition: section.hxx:336
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:144
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:315
const SwSection * pSect
Definition: edglbldc.hxx:42
void EndAllAction()
Definition: edws.cxx:97
Array of Undo-history.
Definition: docary.hxx:191
virtual void set(DocumentSettingId id, bool value)=0
Set the specified document setting.
void SttCursorMove()
Definition: crsrsh.cxx:302
SwIndex nContent
Definition: pam.hxx:39
SwSectionNode * GetSectionNode()
Definition: section.cxx:922
bool IsGlblDocSaveLinks() const
Definition: edglbldc.cxx:48
bool DeleteTOX(const SwTOXBase &rTOXBase, bool bDelNodes)
Delete table of contents.
Definition: doctxm.cxx:524
SwDoc * GetDoc() const
Definition: viewsh.hxx:282
SwNodeOffset GetIndex() const
Definition: ndindex.hxx:152
size_type size() const
SwPaM * GetNext()
Definition: pam.hxx:265
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:162
void EndCursorMove(const bool bIdleEnd=false)
Definition: crsrsh.cxx:311
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:137
virtual SwUndoId StartUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Opens undo block.
GlobalDocContentType m_eType
Definition: edglbldc.hxx:38
SwGlblDocContent(SwNodeOffset nPos)
Definition: edglbldc.cxx:358
const SwPosition * GetPoint() const
Definition: pam.hxx:208
void DeleteGlobalDocContent(const SwGlblDocContents &rArr, size_t nPos)
Definition: edglbldc.cxx:232
virtual void SetUndoNoResetModified()=0
Disable (re)setting the document modified flag on Undo/Redo.
SwIndex & Assign(SwIndexReg *, sal_Int32)
Definition: index.cxx:206
SwContentNode * GetContentNode()
Definition: node.hxx:625
SwNodeOffset GetIndex() const
Definition: node.hxx:292
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
Definition: edws.cxx:223
size_t size() const
Definition: docary.hxx:87
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:394
Marks a node in the document model.
Definition: ndindex.hxx:30
bool empty() const
const SwTOXBase * pTOX
Definition: edglbldc.hxx:41
virtual bool MoveNodeRange(SwNodeRange &, SwNodeIndex &, SwMoveFlags)=0
void GetGlobalDocContent(SwGlblDocContents &rArr) const
Definition: edglbldc.cxx:53
void GotoGlobalDocContent(const SwGlblDocContent &rPos)
Definition: edglbldc.cxx:333
bool Delete()
Delete content of all ranges.
Definition: eddel.cxx:125
const SwTOXBase * GetTOX() const
Definition: edglbldc.hxx:54
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
void InsertGlobalDocContent(const SwGlblDocContent &rPos, SwSectionData &rNew)
Definition: edglbldc.cxx:130
SwCursor * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:195
GlobalDocContentType GetType() const
Query contents.
Definition: edglbldc.hxx:51
virtual bool DelFullPara(SwPaM &)=0
Delete full paragraphs.
SwNodes & GetNodes()
Definition: doc.hxx:408
const SwSection * GetSection() const
Definition: edglbldc.hxx:52
SwNodeIndex aEnd
Definition: ndindex.hxx:133
o3tl::strong_int< sal_Int32, struct Tag_SwNodeOffset > SwNodeOffset
Definition: nodeoffset.hxx:16
virtual bool get(DocumentSettingId id) const =0
Return the specified document setting.
void ClearMark()
Definition: crsrsh.cxx:939
virtual bool AppendTextNode(SwPosition &rPos)=0
SwNodeOffset GetDocPos() const
Definition: edglbldc.hxx:56
bool IsTableNode() const
Definition: node.hxx:650
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:476
SectionType GetType() const
Definition: section.hxx:169
std::pair< const_iterator, bool > insert(Value &&x)
SwNode & GetEndOfExtras() const
This is the last EndNode of a special section.
Definition: ndarr.hxx:160
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
union SwGlblDocContent::@25 m_PTR
SwSectionFormats & GetSections()
Definition: doc.hxx:1337
SwContentNode * GoNext(SwNodeIndex *) const
Definition: nodes.cxx:1300
void SetGlblDocSaveLinks(bool bFlag)
Definition: edglbldc.cxx:38
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:864
bool IsGlobalDoc() const
Interfaces for GlobalDocument.
Definition: edglbldc.cxx:33
Base class of the Writer document model elements.
Definition: node.hxx:81