LibreOffice Module sw (master) 1
edws.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 <editsh.hxx>
21
22#include <officecfg/Office/Common.hxx>
23#include <osl/diagnose.h>
25#include <vcl/window.hxx>
26
27#include <doc.hxx>
28#include <IDocumentUndoRedo.hxx>
29#include <IDocumentState.hxx>
30#include <pam.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>
38
39// masqueraded copy constructor
41 : SwCursorShell( rEdSH, pWindow )
42 , m_bNbspRunNext(false) // TODO: would copying that make sense? only if editing continues
43 , m_bDoParagraphSignatureValidation(true)
44{
45}
46
47SwEditShell::SwEditShell( SwDoc& rDoc, vcl::Window *pWindow, const SwViewOption *pOptions )
48 : SwCursorShell( rDoc, pWindow, pOptions )
49 , m_bNbspRunNext(false)
50 , m_bDoParagraphSignatureValidation(true)
51{
53 {
54 GetDoc()->GetIDocumentUndoRedo().DoUndo(true);
55 }
56
57 // Restore the paragraph metadata fields and validate signatures.
59}
60
62{
63}
64
66{
68}
69
71{
73}
74
76{
78}
79
81{
83 GetDoc()->GetIDocumentUndoRedo().SetUndoNoResetModified();
84}
85
87{
88 for(SwViewShell& rCurrentShell : GetRingContainer())
89 {
90 if (SwEditShell* pEditShell = dynamic_cast<SwEditShell*>(&rCurrentShell))
91 pEditShell->StartAction();
92 else
93 rCurrentShell.StartAction();
94 }
95}
96
98{
99 for(SwViewShell& rCurrentShell : GetRingContainer())
100 {
101 if( auto pEditShell = dynamic_cast<SwEditShell *>(&rCurrentShell))
102 pEditShell->EndAction();
103 else
104 rCurrentShell.EndAction();
105 }
106}
107
109{
112
113 for(SwViewShell& rCurrentShell : GetRingContainer())
114 {
115 if ( rCurrentShell.GetWin() )
116 rCurrentShell.GetWin()->Invalidate();
117 }
118
119 EndAllAction();
120}
121
126sal_uInt16 SwEditShell::GetCntType() const
127{
128 sal_uInt16 nRet = 0;
129 if( IsTableMode() )
130 nRet = CNT_TXT;
131 else
132 switch( GetCursor()->GetPointNode().GetNodeType() )
133 {
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;
138 }
139
140 OSL_ASSERT( nRet );
141 return nRet;
142}
143
145
146{
147 if ( !GetDoc()->GetSpzFrameFormats()->empty() )
148 return true;
149
150 const SwNodes &rNds = GetDoc()->GetNodes();
151 const SwNode *pNd;
152
153 pNd = &rNds.GetEndOfInserts();
154 if ( SwNodeOffset(1) != (pNd->GetIndex() - pNd->StartOfSectionIndex()) )
155 return true;
156
157 pNd = &rNds.GetEndOfAutotext();
158 return SwNodeOffset(1) != (pNd->GetIndex() - pNd->StartOfSectionIndex());
159}
160
162 : m_rShell(*pShell)
163{
165}
166
167SwActContext::~SwActContext() COVERITY_NOEXCEPT_FALSE
168{
170}
171
173 : m_rShell(*pShell)
174{
176}
177
178SwMvContext::~SwMvContext() COVERITY_NOEXCEPT_FALSE
179{
181}
182
183SwFrameFormat *SwEditShell::GetTableFormat() // fastest test on a table
184{
185 const SwTableNode* pTableNd = IsCursorInTable();
186 return pTableNd ? static_cast<SwFrameFormat*>(pTableNd->GetTable().GetFrameFormat()) : nullptr;
187}
188
189// TODO: Why is this called 3x for a new document?
191{
192 return mxDoc->GetTOXTypeCount(eTyp);
193}
194
196{
197 mxDoc->InsertTOXType(rTyp);
198}
199
200void SwEditShell::DoUndo( bool bOn )
201{ GetDoc()->GetIDocumentUndoRedo().DoUndo( bOn ); }
202
204{ return GetDoc()->GetIDocumentUndoRedo().DoesUndo(); }
205
207{ GetDoc()->GetIDocumentUndoRedo().DoGroupUndo( bOn ); }
208
210{ return GetDoc()->GetIDocumentUndoRedo().DoesGroupUndo(); }
211
213{
214 GetDoc()->GetIDocumentUndoRedo().DelAllUndoObj();
215}
216
217// Combine continuous calls of Insert/Delete/Overwrite on characters. Default: sdbcx::Group-Undo.
218
224 const SwRewriter *pRewriter )
225{ return GetDoc()->GetIDocumentUndoRedo().StartUndo( eUndoId, pRewriter ); }
226
235{ return GetDoc()->GetIDocumentUndoRedo().EndUndo(eUndoId, pRewriter); }
236
237bool SwEditShell::GetLastUndoInfo(OUString *const o_pStr,
238 SwUndoId *const o_pId,
239 const SwView* pView) const
240{
241 return GetDoc()->GetIDocumentUndoRedo().GetLastUndoInfo(o_pStr, o_pId, pView);
242}
243
244bool SwEditShell::GetFirstRedoInfo(OUString *const o_pStr,
245 SwUndoId *const o_pId,
246 const SwView* pView) const
247{
248 return GetDoc()->GetIDocumentUndoRedo().GetFirstRedoInfo(o_pStr, o_pId, pView);
249}
250
251SwUndoId SwEditShell::GetRepeatInfo(OUString *const o_pStr) const
252{ return GetDoc()->GetIDocumentUndoRedo().GetRepeatInfo(o_pStr); }
253
255void SwEditShell::AutoCorrect( SvxAutoCorrect& rACorr, bool bInsert,
256 sal_Unicode cChar )
257{
258 CurrShell aCurr( this );
259
261
262 SwPaM* pCursor = getShellCursor( true );
263 SwTextNode* pTNd = pCursor->GetPointNode().GetTextNode();
264
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 // tdf#147414 sw_redlinehide: if cursor moved backward, it may be at the
270 // start of a delete redline - but MapViewToModelPos() always returns end
271 // of redline and it will be called when AutoCorrect actually inserts
272 // something - so first normalize cursor point to end of redline so that
273 // point will then be moved forward when something is inserted.
274 *pCursor->GetPoint() = pFrame->MapViewToModelPos(nPos);
275 OUString const& rMergedText(pFrame->GetText());
276 rACorr.DoAutoCorrect( aSwAutoCorrDoc,
277 rMergedText, sal_Int32(nPos),
278 cChar, bInsert, m_bNbspRunNext, GetWin() );
279 if( cChar )
280 SaveTableBoxContent( pCursor->GetPoint() );
281 EndAllAction();
282}
283
285{
287}
288
290{
291 CurrShell aCurr( this );
292
293 OUString sRet;
294 SwPaM* pCursor = getShellCursor( true );
295 SwTextNode* pTNd = pCursor->GetPointNode().GetTextNode();
296 if (pTNd)
297 {
298 SwAutoCorrDoc aSwAutoCorrDoc( *this, *pCursor, 0 );
299 SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(pTNd->getLayoutFrame(GetLayout())));
300 TextFrameIndex const nPos(pFrame->MapModelToViewPos(*pCursor->GetPoint()));
301 sRet = rACorr.GetPrevAutoCorrWord(aSwAutoCorrDoc, pFrame->GetText(), sal_Int32(nPos));
302 }
303 return sRet;
304}
305
306std::vector<OUString> SwEditShell::GetChunkForAutoText()
307{
308 CurrShell aCurr(this);
309
310 std::vector<OUString> aRet;
311 SwPaM* pCursor = getShellCursor(true);
312 SwTextNode* pTNd = pCursor->GetPointNode().GetTextNode();
313 if (pTNd)
314 {
315 const auto pFrame = static_cast<SwTextFrame const*>(pTNd->getLayoutFrame(GetLayout()));
316 TextFrameIndex const nPos(pFrame->MapModelToViewPos(*pCursor->GetPoint()));
317 aRet = SvxAutoCorrect::GetChunkForAutoText(pFrame->GetText(), sal_Int32(nPos));
318 }
319 return aRet;
320}
321
323{
325}
326
327/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SetNewDoc(bool b)=0
virtual void ResetModified()=0
virtual void SetModified()=0
Must be called manually at changes of format.
virtual bool IsModified() const =0
Changes of document?
void DoAutoCorrect(SvxAutoCorrDoc &rDoc, const OUString &rTxt, sal_Int32 nPos, sal_Unicode cInsChar, bool bInsert, bool &io_bNbspRunNext, vcl::Window const *pFrameWin=nullptr)
static std::vector< OUString > GetChunkForAutoText(std::u16string_view rTxt, sal_Int32 nPos)
OUString GetPrevAutoCorrWord(SvxAutoCorrDoc const &rDoc, const OUString &rTxt, sal_Int32 nPos)
SwActContext(SwEditShell *pShell)
Definition: edws.cxx:161
~SwActContext() COVERITY_NOEXCEPT_FALSE
Definition: edws.cxx:167
SwEditShell & m_rShell
Definition: editsh.hxx:1020
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1225
void StartAction()
Definition: crsrsh.cxx:226
const SwTableNode * IsCursorInTable() const
Definition: crsrsh.hxx:914
void SttCursorMove()
Definition: crsrsh.cxx:301
SwCursor * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:194
void EndAction(const bool bIdleEnd=false)
Definition: crsrsh.cxx:243
SwShellCursor * getShellCursor(bool bBlock)
Delivers the current shell cursor.
Definition: crsrsh.cxx:3082
bool IsTableMode() const
Definition: crsrsh.hxx:662
void EndCursorMove(const bool bIdleEnd=false)
Definition: crsrsh.cxx:310
void SaveTableBoxContent(const SwPosition *pPos=nullptr)
Definition: trvltbl.cxx:867
Definition: doc.hxx:195
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:402
static SwAutoCompleteWord & GetAutoCompleteWords()
Definition: doc.hxx:1552
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:152
SwNodes & GetNodes()
Definition: doc.hxx:420
sal_uInt16 GetCntType() const
Determine form of content. Return Type at CurrentCursor->SPoint.
Definition: edws.cxx:126
virtual void CalcLayout() override
To enable set up of StartActions and EndActions.
Definition: edws.cxx:108
bool DoesGroupUndo() const
Definition: edws.cxx:209
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
bool IsModified() const
Changes in document?
Definition: edws.cxx:65
void SetUndoNoResetModified()
Definition: edws.cxx:80
void InsertTOXType(const SwTOXType &rTyp)
Definition: edws.cxx:195
void SetNewDoc()
Optimizing UI.
Definition: edws.cxx:284
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
Definition: edws.cxx:223
static SwAutoCompleteWord & GetAutoCompleteWords()
Interface for access to AutoComplete-list.
Definition: edws.cxx:322
bool m_bNbspRunNext
NO-BREAK SPACE state flag passed to and maintained by SvxAutoCorrect::DoAutoCorrect()
Definition: editsh.hxx:1011
SwFrameFormat * GetTableFormat()
Definition: edws.cxx:183
bool GetFirstRedoInfo(OUString *const o_pStr, SwUndoId *const o_pId, const SwView *pView=nullptr) const
Definition: edws.cxx:244
void RestoreMetadataFieldsAndValidateParagraphSignatures()
Restore the metadata fields, if missing, from the RDF metadata and validate the signatures and update...
Definition: edfcol.cxx:1920
bool GetLastUndoInfo(OUString *const o_pStr, SwUndoId *const o_pId, const SwView *pView=nullptr) const
Definition: edws.cxx:237
sal_uInt16 GetTOXTypeCount(TOXTypes eTyp) const
Manage types of content tables.
Definition: edws.cxx:190
virtual ~SwEditShell() override
Definition: edws.cxx:61
SwEditShell(SwDoc &, vcl::Window *, const SwViewOption *pOpt)
Ctor/Dtor.
Definition: edws.cxx:47
void ResetModified()
Definition: edws.cxx:75
std::vector< OUString > GetChunkForAutoText()
Definition: edws.cxx:306
void SetModified()
Definition: edws.cxx:70
void DoGroupUndo(bool bUn)
Definition: edws.cxx:206
bool DoesUndo() const
Definition: edws.cxx:203
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
Definition: edws.cxx:234
void AutoCorrect(SvxAutoCorrect &rACorr, bool bInsertMode, sal_Unicode cChar)
Call AutoCorrect.
Definition: edws.cxx:255
void DoUndo(bool bOn=true)
Undo.
Definition: edws.cxx:200
void DelAllUndoObj()
Definition: edws.cxx:212
bool HasOtherCnt() const
Are there frames, footnotes, etc.
Definition: edws.cxx:144
void EndAllAction()
Definition: edws.cxx:97
SwUndoId GetRepeatInfo(OUString *const o_pStr) const
Definition: edws.cxx:251
OUString GetPrevAutoCorrWord(SvxAutoCorrect &rACorr)
Definition: edws.cxx:289
Style of a layout element.
Definition: frmfmt.hxx:62
SwMvContext(SwEditShell *pShell)
Definition: edws.cxx:172
~SwMvContext() COVERITY_NOEXCEPT_FALSE
Definition: edws.cxx:178
SwEditShell & m_rShell
Definition: editsh.hxx:1028
Base class of the Writer document model elements.
Definition: node.hxx:98
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:903
SwNodeOffset GetIndex() const
Definition: node.hxx:312
SwNodeOffset StartOfSectionIndex() const
Definition: node.hxx:724
SwNode & GetEndOfAutotext() const
Section for all Flys/Header/Footers.
Definition: ndarr.hxx:158
SwNode & GetEndOfInserts() const
Section for all footnotes.
Definition: ndarr.hxx:156
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:187
SwNode & GetPointNode() const
Definition: pam.hxx:283
const SwPosition * GetPoint() const
Definition: pam.hxx:261
const SwTable & GetTable() const
Definition: node.hxx:542
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:209
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:166
SwPosition MapViewToModelPos(TextFrameIndex nIndex) const
Definition: txtfrm.cxx:1246
TextFrameIndex MapModelToViewPos(SwPosition const &rPos) const
Definition: txtfrm.cxx:1267
const OUString & GetText() const
Returns the text portion we want to edit (for inline see underneath)
Definition: txtfrm.cxx:1293
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:112
rtl::Reference< SwDoc > mxDoc
The document; never 0.
Definition: viewsh.hxx:179
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2159
vcl::Window * GetWin() const
Definition: viewsh.hxx:346
SwDoc * GetDoc() const
Definition: viewsh.hxx:290
virtual void CalcLayout()
Definition: viewsh.cxx:1070
Definition: view.hxx:146
ring_container GetRingContainer()
Definition: ring.hxx:240
static bool IsFuzzing()
#define CNT_OLE
Definition: editsh.hxx:132
#define CNT_TXT
Definition: editsh.hxx:130
#define CNT_GRF
Definition: editsh.hxx:131
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
SwUndoId
Definition: swundo.hxx:30
TOXTypes
Definition: toxe.hxx:40
sal_uInt16 sal_Unicode