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 <unotools/configmgr.hxx>
24 #include <vcl/window.hxx>
25 
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>
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 
47 SwEditShell::SwEditShell( SwDoc& rDoc, vcl::Window *pWindow, const SwViewOption *pOptions )
48  : SwCursorShell( rDoc, pWindow, pOptions )
49  , m_bNbspRunNext(false)
50  , m_bDoParagraphSignatureValidation(true)
51 {
53  {
55  }
56 
57  // Restore the paragraph metadata fields and validate signatures.
59 }
60 
62 {
63 }
64 
66 {
67  return GetDoc()->getIDocumentState().IsModified();
68 }
69 
71 {
73 }
74 
76 {
78 }
79 
81 {
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( dynamic_cast<const SwEditShell *>(&rCurrentShell) != nullptr )
102  static_cast<SwEditShell*>(&rCurrentShell)->EndAction();
103  else
104  rCurrentShell.EndAction();
105  }
106 }
107 
109 {
110  StartAllAction();
112 
113  for(SwViewShell& rCurrentShell : GetRingContainer())
114  {
115  if ( rCurrentShell.GetWin() )
116  rCurrentShell.GetWin()->Invalidate();
117  }
118 
119  EndAllAction();
120 }
121 
126 sal_uInt16 SwEditShell::GetCntType() const
127 {
128  sal_uInt16 nRet = 0;
129  if( IsTableMode() )
130  nRet = CNT_TXT;
131  else
132  switch( GetCursor()->GetNode().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 ( 1 != (pNd->GetIndex() - pNd->StartOfSectionIndex()) )
155  return true;
156 
157  pNd = &rNds.GetEndOfAutotext();
158  return 1 != (pNd->GetIndex() - pNd->StartOfSectionIndex());
159 }
160 
162  : m_rShell(*pShell)
163 {
165 }
166 
167 SwActContext::~SwActContext() COVERITY_NOEXCEPT_FALSE
168 {
170 }
171 
173  : m_rShell(*pShell)
174 {
176 }
177 
178 SwMvContext::~SwMvContext() COVERITY_NOEXCEPT_FALSE
179 {
181 }
182 
183 SwFrameFormat *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 
200 void SwEditShell::DoUndo( bool bOn )
201 { GetDoc()->GetIDocumentUndoRedo().DoUndo( bOn ); }
202 
204 { return GetDoc()->GetIDocumentUndoRedo().DoesUndo(); }
205 
206 void SwEditShell::DoGroupUndo( bool bOn )
207 { GetDoc()->GetIDocumentUndoRedo().DoGroupUndo( bOn ); }
208 
210 { return GetDoc()->GetIDocumentUndoRedo().DoesGroupUndo(); }
211 
213 {
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 
237 bool 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 
244 bool 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 
251 SwUndoId SwEditShell::GetRepeatInfo(OUString *const o_pStr) const
252 { return GetDoc()->GetIDocumentUndoRedo().GetRepeatInfo(o_pStr); }
253 
255 void SwEditShell::AutoCorrect( SvxAutoCorrect& rACorr, bool bInsert,
256  sal_Unicode cChar )
257 {
258  CurrShell aCurr( this );
259 
260  StartAllAction();
261 
262  SwPaM* pCursor = getShellCursor( true );
263  SwTextNode* pTNd = pCursor->GetNode().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  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();
276 }
277 
279 {
281 }
282 
284 {
285  CurrShell aCurr( this );
286 
287  OUString sRet;
288  SwPaM* pCursor = getShellCursor( true );
289  SwTextNode* pTNd = pCursor->GetNode().GetTextNode();
290  if (pTNd)
291  {
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));
296  }
297  return sRet;
298 }
299 
300 std::vector<OUString> SwEditShell::GetChunkForAutoText()
301 {
302  CurrShell aCurr(this);
303 
304  std::vector<OUString> aRet;
305  SwPaM* pCursor = getShellCursor(true);
306  SwTextNode* pTNd = pCursor->GetNode().GetTextNode();
307  if (pTNd)
308  {
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));
312  }
313  return aRet;
314 }
315 
317 {
319 }
320 
321 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:151
TOXTypes
Definition: toxe.hxx:39
SwNode & GetEndOfInserts() const
Section for all footnotes.
Definition: ndarr.hxx:154
sal_uLong GetIndex() const
Definition: node.hxx:282
SwNode & GetNode(bool bPoint=true) const
Definition: pam.hxx:223
SwNode & GetEndOfAutotext() const
Section for all Flys/Header/Footers.
Definition: ndarr.hxx:156
SwContentNode * GetNode(SwPaM &rPam, bool &rbFirst, SwMoveFnCollection const &fnMove, bool const bInReadOnly, SwRootFrame const *const i_pLayout)
This function returns the next node in direction of search.
Definition: pam.cxx:816
SwPaM * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:189
void SaveTableBoxContent(const SwPosition *pPos=nullptr)
Definition: trvltbl.cxx:869
sal_uLong StartOfSectionIndex() const
Definition: node.hxx:673
static SwAutoCompleteWord & GetAutoCompleteWords()
Definition: doc.hxx:1528
SwUndoId
Definition: swundo.hxx:29
virtual void CalcLayout()
Definition: viewsh.cxx:973
void SetUndoNoResetModified()
Definition: edws.cxx:80
bool IsTableMode() const
Definition: crsrsh.hxx:643
SwShellCursor * getShellCursor(bool bBlock)
Delivers the current shell cursor.
Definition: crsrsh.cxx:3026
virtual void SetModified()=0
Must be called manually at changes of format.
#define CNT_GRF
Definition: editsh.hxx:130
bool GetLastUndoInfo(OUString *const o_pStr, SwUndoId *const o_pId, const SwView *pView=nullptr) const
Definition: edws.cxx:237
bool IsModified() const
Changes in document?
Definition: edws.cxx:65
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1190
virtual SwUndoId EndUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Closes undo block.
Definition: doc.hxx:184
OUString GetPrevAutoCorrWord(SvxAutoCorrect &rACorr)
Definition: edws.cxx:283
void AutoCorrect(SvxAutoCorrect &rACorr, bool bInsertMode, sal_Unicode cChar)
Call AutoCorrect.
Definition: edws.cxx:255
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
Definition: edws.cxx:234
SwMvContext(SwEditShell *pShell)
Definition: edws.cxx:172
void RestoreMetadataFieldsAndValidateParagraphSignatures()
Restore the metadata fields, if missing, from the RDF metadata and validate the signatures and update...
Definition: edfcol.cxx:1901
void DoUndo(bool bOn=true)
Undo.
Definition: edws.cxx:200
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:143
void SetModified()
Definition: edws.cxx:70
const OUString & GetText() const
Returns the text portion we want to edit (for inline see underneath)
Definition: txtfrm.cxx:1278
void EndAllAction()
Definition: edws.cxx:97
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:201
sal_uInt16 GetTOXTypeCount(TOXTypes eTyp) const
Manage types of content tables.
Definition: edws.cxx:190
OUString GetPrevAutoCorrWord(SvxAutoCorrDoc const &rDoc, const OUString &rTxt, sal_Int32 nPos)
sal_uInt16 sal_Unicode
void SttCursorMove()
Definition: crsrsh.cxx:301
virtual bool GetFirstRedoInfo(OUString *const o_pStr, SwUndoId *const o_pId, const SwView *pView=nullptr) const =0
Get Id and comment of first Redo action.
rtl::Reference< SwDoc > mxDoc
The document; never 0.
Definition: viewsh.hxx:172
static bool IsFuzzing()
SwEditShell & m_rShell
Definition: editsh.hxx:1019
virtual void DelAllUndoObj()=0
Delete all Undo actions.
virtual void DoUndo(bool const bDoUndo)=0
Enable/Disable Undo.
const SwTable & GetTable() const
Definition: node.hxx:497
SwDoc * GetDoc() const
Definition: viewsh.hxx:282
void DoGroupUndo(bool bUn)
Definition: edws.cxx:206
virtual bool DoesUndo() const =0
Is Undo enabled?
virtual void SetNewDoc(bool b)=0
virtual SwUndoId GetRepeatInfo(OUString *const o_pStr) const =0
Get Id and comment of last Undo action, if it is Repeat capable.
void EndCursorMove(const bool bIdleEnd=false)
Definition: crsrsh.cxx:310
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
bool HasOtherCnt() const
Are there frames, footnotes, etc.
Definition: edws.cxx:144
const SwTableNode * IsCursorInTable() const
Definition: crsrsh.hxx:889
Style of a layout element.
Definition: frmfmt.hxx:57
TextFrameIndex MapModelToViewPos(SwPosition const &rPos) const
Definition: txtfrm.cxx:1254
virtual SwUndoId StartUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Opens undo block.
const SwPosition * GetPoint() const
Definition: pam.hxx:207
virtual bool IsModified() const =0
Changes of document?
void EndAction(const bool bIdleEnd=false, const bool DoSetPosX=false)
Definition: crsrsh.cxx:239
virtual void SetUndoNoResetModified()=0
Disable (re)setting the document modified flag on Undo/Redo.
static SwAutoCompleteWord & GetAutoCompleteWords()
Interface for access to AutoComplete-list.
Definition: edws.cxx:316
virtual bool DoesGroupUndo() const =0
Is Group Undo enabled?
std::vector< OUString > GetChunkForAutoText()
Definition: edws.cxx:300
bool DoesGroupUndo() const
Definition: edws.cxx:209
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
Definition: edws.cxx:223
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:393
static std::vector< OUString > GetChunkForAutoText(const OUString &rTxt, sal_Int32 nPos)
SwEditShell & m_rShell
Definition: editsh.hxx:1027
#define CNT_OLE
Definition: editsh.hxx:131
ring_container GetRingContainer()
#define CNT_TXT
Definition: editsh.hxx:129
SwFrameFormat * GetTableFormat()
Definition: edws.cxx:183
virtual void DoGroupUndo(bool const bDoUndo)=0
Enable/Disable Group Undo.
void StartAction()
Definition: crsrsh.cxx:222
void InsertTOXType(const SwTOXType &rTyp)
Definition: edws.cxx:195
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
~SwActContext() COVERITY_NOEXCEPT_FALSE
Definition: edws.cxx:167
~SwMvContext() COVERITY_NOEXCEPT_FALSE
Definition: edws.cxx:178
SwUndoId GetRepeatInfo(OUString *const o_pStr) const
Definition: edws.cxx:251
virtual bool GetLastUndoInfo(OUString *const o_pStr, SwUndoId *const o_pId, const SwView *pView=nullptr) const =0
Get Id and comment of last Undo action.
vcl::Window * GetWin() const
Definition: viewsh.hxx:338
sal_uInt16 GetCntType() const
Determine form of content. Return Type at CurrentCursor->SPoint.
Definition: edws.cxx:126
void ResetModified()
Definition: edws.cxx:75
SwNodes & GetNodes()
Definition: doc.hxx:403
void DelAllUndoObj()
Definition: edws.cxx:212
bool GetFirstRedoInfo(OUString *const o_pStr, SwUndoId *const o_pId, const SwView *pView=nullptr) const
Definition: edws.cxx:244
virtual void CalcLayout() override
To enable set up of StartActions and EndActions.
Definition: edws.cxx:108
virtual ~SwEditShell() override
Definition: edws.cxx:61
void SetNewDoc()
Optimizing UI.
Definition: edws.cxx:278
bool m_bNbspRunNext
NO-BREAK SPACE state flag passed to and maintained by SvxAutoCorrect::DoAutoCorrect() ...
Definition: editsh.hxx:1010
SwEditShell(SwDoc &, vcl::Window *, const SwViewOption *pOpt)
Ctor/Dtor.
Definition: edws.cxx:47
bool DoesUndo() const
Definition: edws.cxx:203
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2069
void DoAutoCorrect(SvxAutoCorrDoc &rDoc, const OUString &rTxt, sal_Int32 nPos, sal_Unicode cInsChar, bool bInsert, bool &io_bNbspRunNext, vcl::Window const *pFrameWin=nullptr)
SwActContext(SwEditShell *pShell)
Definition: edws.cxx:161
Definition: view.hxx:144
sal_uInt16 nPos
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:836
virtual void ResetModified()=0
Base class of the Writer document model elements.
Definition: node.hxx:79