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