nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / core / edit / edws.cxx
blobd7876e31a4fb573c92ee06870247b12941c53db8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <editsh.hxx>
22 #include <officecfg/Office/Common.hxx>
23 #include <unotools/configmgr.hxx>
24 #include <vcl/window.hxx>
26 #include <doc.hxx>
27 #include <IDocumentUndoRedo.hxx>
28 #include <IDocumentState.hxx>
29 #include <pam.hxx>
30 #include <docary.hxx>
31 #include <acorrect.hxx>
32 #include <swtable.hxx>
33 #include <ndtxt.hxx>
34 #include <txtfrm.hxx>
35 #include <swundo.hxx>
36 #include <SwRewriter.hxx>
37 #include <frameformats.hxx>
39 // masqueraded copy constructor
40 SwEditShell::SwEditShell( SwEditShell& rEdSH, vcl::Window *pWindow )
41 : SwCursorShell( rEdSH, pWindow )
42 , m_bNbspRunNext(false) // TODO: would copying that make sense? only if editing continues
43 , m_bDoParagraphSignatureValidation(true)
47 SwEditShell::SwEditShell( SwDoc& rDoc, vcl::Window *pWindow, const SwViewOption *pOptions )
48 : SwCursorShell( rDoc, pWindow, pOptions )
49 , m_bNbspRunNext(false)
50 , m_bDoParagraphSignatureValidation(true)
52 if (!utl::ConfigManager::IsFuzzing() && 0 < officecfg::Office::Common::Undo::Steps::get())
54 GetDoc()->GetIDocumentUndoRedo().DoUndo(true);
57 // Restore the paragraph metadata fields and validate signatures.
58 RestoreMetadataFieldsAndValidateParagraphSignatures();
61 SwEditShell::~SwEditShell() // USED
65 bool SwEditShell::IsModified() const
67 return GetDoc()->getIDocumentState().IsModified();
70 void SwEditShell::SetModified()
72 GetDoc()->getIDocumentState().SetModified();
75 void SwEditShell::ResetModified()
77 GetDoc()->getIDocumentState().ResetModified();
80 void SwEditShell::SetUndoNoResetModified()
82 GetDoc()->getIDocumentState().SetModified();
83 GetDoc()->GetIDocumentUndoRedo().SetUndoNoResetModified();
86 void SwEditShell::StartAllAction()
88 for(SwViewShell& rCurrentShell : GetRingContainer())
90 if (SwEditShell* pEditShell = dynamic_cast<SwEditShell*>(&rCurrentShell))
91 pEditShell->StartAction();
92 else
93 rCurrentShell.StartAction();
97 void SwEditShell::EndAllAction()
99 for(SwViewShell& rCurrentShell : GetRingContainer())
101 if( auto pEditShell = dynamic_cast<SwEditShell *>(&rCurrentShell))
102 pEditShell->EndAction();
103 else
104 rCurrentShell.EndAction();
108 void SwEditShell::CalcLayout()
110 StartAllAction();
111 SwViewShell::CalcLayout();
113 for(SwViewShell& rCurrentShell : GetRingContainer())
115 if ( rCurrentShell.GetWin() )
116 rCurrentShell.GetWin()->Invalidate();
119 EndAllAction();
122 /** Get the content type of a shell
124 * @todo Is this called for every attribute?
126 sal_uInt16 SwEditShell::GetCntType() const
128 sal_uInt16 nRet = 0;
129 if( IsTableMode() )
130 nRet = CNT_TXT;
131 else
132 switch( GetCursor()->GetNode().GetNodeType() )
134 case SwNodeType::Text: nRet = CNT_TXT; break;
135 case SwNodeType::Grf: nRet = CNT_GRF; break;
136 case SwNodeType::Ole: nRet = CNT_OLE; break;
137 default: break;
140 OSL_ASSERT( nRet );
141 return nRet;
144 bool SwEditShell::HasOtherCnt() const
147 if ( !GetDoc()->GetSpzFrameFormats()->empty() )
148 return true;
150 const SwNodes &rNds = GetDoc()->GetNodes();
151 const SwNode *pNd;
153 pNd = &rNds.GetEndOfInserts();
154 if ( 1 != (pNd->GetIndex() - pNd->StartOfSectionIndex()) )
155 return true;
157 pNd = &rNds.GetEndOfAutotext();
158 return 1 != (pNd->GetIndex() - pNd->StartOfSectionIndex());
161 SwActContext::SwActContext(SwEditShell *pShell)
162 : m_rShell(*pShell)
164 m_rShell.StartAction();
167 SwActContext::~SwActContext() COVERITY_NOEXCEPT_FALSE
169 m_rShell.EndAction();
172 SwMvContext::SwMvContext(SwEditShell *pShell)
173 : m_rShell(*pShell)
175 m_rShell.SttCursorMove();
178 SwMvContext::~SwMvContext() COVERITY_NOEXCEPT_FALSE
180 m_rShell.EndCursorMove();
183 SwFrameFormat *SwEditShell::GetTableFormat() // fastest test on a table
185 const SwTableNode* pTableNd = IsCursorInTable();
186 return pTableNd ? static_cast<SwFrameFormat*>(pTableNd->GetTable().GetFrameFormat()) : nullptr;
189 // TODO: Why is this called 3x for a new document?
190 sal_uInt16 SwEditShell::GetTOXTypeCount(TOXTypes eTyp) const
192 return mxDoc->GetTOXTypeCount(eTyp);
195 void SwEditShell::InsertTOXType(const SwTOXType& rTyp)
197 mxDoc->InsertTOXType(rTyp);
200 void SwEditShell::DoUndo( bool bOn )
201 { GetDoc()->GetIDocumentUndoRedo().DoUndo( bOn ); }
203 bool SwEditShell::DoesUndo() const
204 { return GetDoc()->GetIDocumentUndoRedo().DoesUndo(); }
206 void SwEditShell::DoGroupUndo( bool bOn )
207 { GetDoc()->GetIDocumentUndoRedo().DoGroupUndo( bOn ); }
209 bool SwEditShell::DoesGroupUndo() const
210 { return GetDoc()->GetIDocumentUndoRedo().DoesGroupUndo(); }
212 void SwEditShell::DelAllUndoObj()
214 GetDoc()->GetIDocumentUndoRedo().DelAllUndoObj();
217 // Combine continuous calls of Insert/Delete/Overwrite on characters. Default: sdbcx::Group-Undo.
219 /** open undo container
221 * @return nUndoId ID of the container
223 SwUndoId SwEditShell::StartUndo( SwUndoId eUndoId,
224 const SwRewriter *pRewriter )
225 { return GetDoc()->GetIDocumentUndoRedo().StartUndo( eUndoId, pRewriter ); }
227 /** close undo container
229 * not used by UI
231 * @param eUndoId ID of the undo container
232 * @param pRewriter ?
234 SwUndoId SwEditShell::EndUndo(SwUndoId eUndoId, const SwRewriter *pRewriter)
235 { return GetDoc()->GetIDocumentUndoRedo().EndUndo(eUndoId, pRewriter); }
237 bool SwEditShell::GetLastUndoInfo(OUString *const o_pStr,
238 SwUndoId *const o_pId,
239 const SwView* pView) const
241 return GetDoc()->GetIDocumentUndoRedo().GetLastUndoInfo(o_pStr, o_pId, pView);
244 bool SwEditShell::GetFirstRedoInfo(OUString *const o_pStr,
245 SwUndoId *const o_pId,
246 const SwView* pView) const
248 return GetDoc()->GetIDocumentUndoRedo().GetFirstRedoInfo(o_pStr, o_pId, pView);
251 SwUndoId SwEditShell::GetRepeatInfo(OUString *const o_pStr) const
252 { return GetDoc()->GetIDocumentUndoRedo().GetRepeatInfo(o_pStr); }
254 /** Auto correction */
255 void SwEditShell::AutoCorrect( SvxAutoCorrect& rACorr, bool bInsert,
256 sal_Unicode cChar )
258 CurrShell aCurr( this );
260 StartAllAction();
262 SwPaM* pCursor = getShellCursor( true );
263 SwTextNode* pTNd = pCursor->GetNode().GetTextNode();
265 SwAutoCorrDoc aSwAutoCorrDoc( *this, *pCursor, cChar );
266 // FIXME: this _must_ be called with reference to the actual node text!
267 SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(pTNd->getLayoutFrame(GetLayout())));
268 TextFrameIndex const nPos(pFrame->MapModelToViewPos(*pCursor->GetPoint()));
269 OUString const& rMergedText(pFrame->GetText());
270 rACorr.DoAutoCorrect( aSwAutoCorrDoc,
271 rMergedText, sal_Int32(nPos),
272 cChar, bInsert, m_bNbspRunNext, GetWin() );
273 if( cChar )
274 SaveTableBoxContent( pCursor->GetPoint() );
275 EndAllAction();
278 void SwEditShell::SetNewDoc()
280 GetDoc()->getIDocumentState().SetNewDoc(true);
283 OUString SwEditShell::GetPrevAutoCorrWord(SvxAutoCorrect& rACorr)
285 CurrShell aCurr( this );
287 OUString sRet;
288 SwPaM* pCursor = getShellCursor( true );
289 SwTextNode* pTNd = pCursor->GetNode().GetTextNode();
290 if (pTNd)
292 SwAutoCorrDoc aSwAutoCorrDoc( *this, *pCursor, 0 );
293 SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(pTNd->getLayoutFrame(GetLayout())));
294 TextFrameIndex const nPos(pFrame->MapModelToViewPos(*pCursor->GetPoint()));
295 sRet = rACorr.GetPrevAutoCorrWord(aSwAutoCorrDoc, pFrame->GetText(), sal_Int32(nPos));
297 return sRet;
300 std::vector<OUString> SwEditShell::GetChunkForAutoText()
302 CurrShell aCurr(this);
304 std::vector<OUString> aRet;
305 SwPaM* pCursor = getShellCursor(true);
306 SwTextNode* pTNd = pCursor->GetNode().GetTextNode();
307 if (pTNd)
309 const auto pFrame = static_cast<SwTextFrame const*>(pTNd->getLayoutFrame(GetLayout()));
310 TextFrameIndex const nPos(pFrame->MapModelToViewPos(*pCursor->GetPoint()));
311 aRet = SvxAutoCorrect::GetChunkForAutoText(pFrame->GetText(), sal_Int32(nPos));
313 return aRet;
316 SwAutoCompleteWord& SwEditShell::GetAutoCompleteWords()
318 return SwDoc::GetAutoCompleteWords();
321 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */