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 
38 // masqueraded copy constructor
40  : SwCursorShell( rEdSH, pWindow )
41  , m_bNbspRunNext(false) // TODO: would copying that make sense? only if editing continues
42  , m_bDoParagraphSignatureValidation(true)
43 {
44 }
45 
46 SwEditShell::SwEditShell( SwDoc& rDoc, vcl::Window *pWindow, const SwViewOption *pOptions )
47  : SwCursorShell( rDoc, pWindow, pOptions )
48  , m_bNbspRunNext(false)
49  , m_bDoParagraphSignatureValidation(true)
50 {
52  {
54  }
55 
56  // Restore the paragraph metadata fields and validate signatures.
58 }
59 
61 {
62 }
63 
65 {
66  return GetDoc()->getIDocumentState().IsModified();
67 }
68 
70 {
72 }
73 
75 {
77 }
78 
80 {
83 }
84 
86 {
87  for(SwViewShell& rCurrentShell : GetRingContainer())
88  {
89  if (SwEditShell* pEditShell = dynamic_cast<SwEditShell*>(&rCurrentShell))
90  pEditShell->StartAction();
91  else
92  rCurrentShell.StartAction();
93  }
94 }
95 
97 {
98  for(SwViewShell& rCurrentShell : GetRingContainer())
99  {
100  if( dynamic_cast<const SwEditShell *>(&rCurrentShell) != nullptr )
101  static_cast<SwEditShell*>(&rCurrentShell)->EndAction();
102  else
103  rCurrentShell.EndAction();
104  }
105 }
106 
108 {
109  StartAllAction();
111 
112  for(SwViewShell& rCurrentShell : GetRingContainer())
113  {
114  if ( rCurrentShell.GetWin() )
115  rCurrentShell.GetWin()->Invalidate();
116  }
117 
118  EndAllAction();
119 }
120 
125 sal_uInt16 SwEditShell::GetCntType() const
126 {
127  sal_uInt16 nRet = 0;
128  if( IsTableMode() )
129  nRet = CNT_TXT;
130  else
131  switch( GetCursor()->GetNode().GetNodeType() )
132  {
133  case SwNodeType::Text: nRet = CNT_TXT; break;
134  case SwNodeType::Grf: nRet = CNT_GRF; break;
135  case SwNodeType::Ole: nRet = CNT_OLE; break;
136  default: break;
137  }
138 
139  OSL_ASSERT( nRet );
140  return nRet;
141 }
142 
144 
145 {
146  if ( !GetDoc()->GetSpzFrameFormats()->empty() )
147  return true;
148 
149  const SwNodes &rNds = GetDoc()->GetNodes();
150  const SwNode *pNd;
151 
152  pNd = &rNds.GetEndOfInserts();
153  if ( 1 != (pNd->GetIndex() - pNd->StartOfSectionIndex()) )
154  return true;
155 
156  pNd = &rNds.GetEndOfAutotext();
157  return 1 != (pNd->GetIndex() - pNd->StartOfSectionIndex());
158 }
159 
161  : m_rShell(*pShell)
162 {
164 }
165 
166 SwActContext::~SwActContext() COVERITY_NOEXCEPT_FALSE
167 {
169 }
170 
172  : m_rShell(*pShell)
173 {
175 }
176 
177 SwMvContext::~SwMvContext() COVERITY_NOEXCEPT_FALSE
178 {
180 }
181 
182 SwFrameFormat *SwEditShell::GetTableFormat() // fastest test on a table
183 {
184  const SwTableNode* pTableNd = IsCursorInTable();
185  return pTableNd ? static_cast<SwFrameFormat*>(pTableNd->GetTable().GetFrameFormat()) : nullptr;
186 }
187 
188 // TODO: Why is this called 3x for a new document?
190 {
191  return mxDoc->GetTOXTypeCount(eTyp);
192 }
193 
195 {
196  mxDoc->InsertTOXType(rTyp);
197 }
198 
199 void SwEditShell::DoUndo( bool bOn )
200 { GetDoc()->GetIDocumentUndoRedo().DoUndo( bOn ); }
201 
203 { return GetDoc()->GetIDocumentUndoRedo().DoesUndo(); }
204 
205 void SwEditShell::DoGroupUndo( bool bOn )
206 { GetDoc()->GetIDocumentUndoRedo().DoGroupUndo( bOn ); }
207 
209 { return GetDoc()->GetIDocumentUndoRedo().DoesGroupUndo(); }
210 
212 {
214 }
215 
216 // Combine continuous calls of Insert/Delete/Overwrite on characters. Default: sdbcx::Group-Undo.
217 
223  const SwRewriter *pRewriter )
224 { return GetDoc()->GetIDocumentUndoRedo().StartUndo( eUndoId, pRewriter ); }
225 
234 { return GetDoc()->GetIDocumentUndoRedo().EndUndo(eUndoId, pRewriter); }
235 
236 bool SwEditShell::GetLastUndoInfo(OUString *const o_pStr,
237  SwUndoId *const o_pId,
238  const SwView* pView) const
239 {
240  return GetDoc()->GetIDocumentUndoRedo().GetLastUndoInfo(o_pStr, o_pId, pView);
241 }
242 
243 bool SwEditShell::GetFirstRedoInfo(OUString *const o_pStr,
244  SwUndoId *const o_pId,
245  const SwView* pView) const
246 {
247  return GetDoc()->GetIDocumentUndoRedo().GetFirstRedoInfo(o_pStr, o_pId, pView);
248 }
249 
250 SwUndoId SwEditShell::GetRepeatInfo(OUString *const o_pStr) const
251 { return GetDoc()->GetIDocumentUndoRedo().GetRepeatInfo(o_pStr); }
252 
254 void SwEditShell::AutoCorrect( SvxAutoCorrect& rACorr, bool bInsert,
255  sal_Unicode cChar )
256 {
257  SET_CURR_SHELL( this );
258 
259  StartAllAction();
260 
261  SwPaM* pCursor = getShellCursor( true );
262  SwTextNode* pTNd = pCursor->GetNode().GetTextNode();
263 
264  SwAutoCorrDoc aSwAutoCorrDoc( *this, *pCursor, cChar );
265  // FIXME: this _must_ be called with reference to the actual node text!
266  SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(pTNd->getLayoutFrame(GetLayout())));
267  TextFrameIndex const nPos(pFrame->MapModelToViewPos(*pCursor->GetPoint()));
268  OUString const& rMergedText(pFrame->GetText());
269  rACorr.DoAutoCorrect( aSwAutoCorrDoc,
270  rMergedText, sal_Int32(nPos),
271  cChar, bInsert, m_bNbspRunNext, GetWin() );
272  if( cChar )
273  SaveTableBoxContent( pCursor->GetPoint() );
274  EndAllAction();
275 }
276 
278 {
280 }
281 
282 bool SwEditShell::GetPrevAutoCorrWord( SvxAutoCorrect const & rACorr, OUString& rWord )
283 {
284  SET_CURR_SHELL( this );
285 
286  bool bRet;
287  SwPaM* pCursor = getShellCursor( true );
288  SwTextNode* pTNd = pCursor->GetNode().GetTextNode();
289  if (pTNd)
290  {
291  SwAutoCorrDoc aSwAutoCorrDoc( *this, *pCursor, 0 );
292  SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(pTNd->getLayoutFrame(GetLayout())));
293  TextFrameIndex const nPos(pFrame->MapModelToViewPos(*pCursor->GetPoint()));
294  bRet = rACorr.GetPrevAutoCorrWord( aSwAutoCorrDoc,
295  pFrame->GetText(), sal_Int32(nPos), rWord );
296  }
297  else
298  bRet = false;
299  return bRet;
300 }
301 
303 {
305 }
306 
307 /* 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:149
TOXTypes
Definition: toxe.hxx:39
SwNode & GetEndOfInserts() const
Section fpr all footnotes.
Definition: ndarr.hxx:155
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:157
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:756
SwPaM * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:185
void SaveTableBoxContent(const SwPosition *pPos=nullptr)
Definition: trvltbl.cxx:873
sal_uLong StartOfSectionIndex() const
Definition: node.hxx:673
static SwAutoCompleteWord & GetAutoCompleteWords()
Definition: doc.hxx:1521
SwUndoId
Definition: swundo.hxx:29
virtual void CalcLayout()
Definition: viewsh.cxx:983
void SetUndoNoResetModified()
Definition: edws.cxx:79
bool IsTableMode() const
Definition: crsrsh.hxx:643
SwShellCursor * getShellCursor(bool bBlock)
Delivers the current shell cursor.
Definition: crsrsh.cxx:2921
virtual void SetModified()=0
Must be called manually at changes of format.
#define CNT_GRF
Definition: editsh.hxx:132
bool GetLastUndoInfo(OUString *const o_pStr, SwUndoId *const o_pId, const SwView *pView=nullptr) const
Definition: edws.cxx:236
bool IsModified() const
Changes in document?
Definition: edws.cxx:64
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1150
virtual SwUndoId EndUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Closes undo block.
Definition: doc.hxx:185
void AutoCorrect(SvxAutoCorrect &rACorr, bool bInsertMode, sal_Unicode cChar)
Call AutoCorrect.
Definition: edws.cxx:254
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
Definition: edws.cxx:233
SwMvContext(SwEditShell *pShell)
Definition: edws.cxx:171
void RestoreMetadataFieldsAndValidateParagraphSignatures()
Restore the metadata fields, if missing, from the RDF metadata and validate the signatures and update...
Definition: edfcol.cxx:1909
void DoUndo(bool bOn=true)
Undo.
Definition: edws.cxx:199
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:176
void SetModified()
Definition: edws.cxx:69
bool GetPrevAutoCorrWord(SvxAutoCorrDoc const &rDoc, const OUString &rTxt, sal_Int32 nPos, OUString &rWord) const
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:96
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:201
sal_uInt16 GetTOXTypeCount(TOXTypes eTyp) const
Manage types of content tables.
Definition: edws.cxx:189
sal_uInt16 sal_Unicode
void SttCursorMove()
Definition: crsrsh.cxx:291
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:174
static bool IsFuzzing()
SwEditShell & m_rShell
Definition: editsh.hxx:1017
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:284
void DoGroupUndo(bool bUn)
Definition: edws.cxx:205
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:300
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:143
const SwTableNode * IsCursorInTable() const
Definition: crsrsh.hxx:885
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.
bool GetPrevAutoCorrWord(SvxAutoCorrect const &rACorr, OUString &rWord)
Definition: edws.cxx:282
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:229
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:302
virtual bool DoesGroupUndo() const =0
Is Group Undo enabled?
bool DoesGroupUndo() const
Definition: edws.cxx:208
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
Definition: edws.cxx:222
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:426
SwEditShell & m_rShell
Definition: editsh.hxx:1025
#define SET_CURR_SHELL(shell)
Definition: swtypes.hxx:101
#define CNT_OLE
Definition: editsh.hxx:133
ring_container GetRingContainer()
#define CNT_TXT
Definition: editsh.hxx:131
SwFrameFormat * GetTableFormat()
Definition: edws.cxx:182
virtual void DoGroupUndo(bool const bDoUndo)=0
Enable/Disable Group Undo.
void StartAction()
Definition: crsrsh.cxx:212
void InsertTOXType(const SwTOXType &rTyp)
Definition: edws.cxx:194
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
~SwActContext() COVERITY_NOEXCEPT_FALSE
Definition: edws.cxx:166
~SwMvContext() COVERITY_NOEXCEPT_FALSE
Definition: edws.cxx:177
SwUndoId GetRepeatInfo(OUString *const o_pStr) const
Definition: edws.cxx:250
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:340
sal_uInt16 GetCntType() const
Determine form of content. Return Type at CurrentCursor->SPoint.
Definition: edws.cxx:125
void ResetModified()
Definition: edws.cxx:74
SwNodes & GetNodes()
Definition: doc.hxx:403
void DelAllUndoObj()
Definition: edws.cxx:211
bool GetFirstRedoInfo(OUString *const o_pStr, SwUndoId *const o_pId, const SwView *pView=nullptr) const
Definition: edws.cxx:243
virtual void CalcLayout() override
To enable set up of StartActions and EndActions.
Definition: edws.cxx:107
virtual ~SwEditShell() override
Definition: edws.cxx:60
void SetNewDoc()
Optimizing UI.
Definition: edws.cxx:277
bool m_bNbspRunNext
NO-BREAK SPACE state flag passed to and maintained by SvxAutoCorrect::DoAutoCorrect() ...
Definition: editsh.hxx:1008
SwEditShell(SwDoc &, vcl::Window *, const SwViewOption *pOpt)
Ctor/Dtor.
Definition: edws.cxx:46
bool DoesUndo() const
Definition: edws.cxx:202
void StartAllAction()
For all views of this document.
Definition: edws.cxx:85
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2072
sal_Int32 nPos
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:160
Definition: view.hxx:146
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:842
virtual void ResetModified()=0
Base class of the Writer document model elements.
Definition: node.hxx:79