LibreOffice Module sc (master)  1
spelldialog.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 <spelldialog.hxx>
21 
22 #include <sfx2/bindings.hxx>
23 #include <svx/svxids.hrc>
24 #include <editeng/editstat.hxx>
25 #include <editeng/editview.hxx>
26 #include <editeng/unolingu.hxx>
27 #include <selectionstate.hxx>
28 #include <osl/diagnose.h>
29 
30 #include <spelleng.hxx>
31 #include <tabvwsh.hxx>
32 #include <docsh.hxx>
33 #include <scmod.hxx>
34 #include <editable.hxx>
35 #include <undoblk.hxx>
36 #include <gridwin.hxx>
37 #include <refupdatecontext.hxx>
38 #include <vcl/svapp.hxx>
39 
41 
42 ScSpellDialogChildWindow::ScSpellDialogChildWindow( vcl::Window* pParentP, sal_uInt16 nId,
43  SfxBindings* pBindings, SAL_UNUSED_PARAMETER SfxChildWinInfo* /*pInfo*/ ) :
44  svx::SpellDialogChildWindow( pParentP, nId, pBindings ),
45  mpViewShell( nullptr ),
46  mpViewData( nullptr ),
47  mpDocShell( nullptr ),
48  mpDoc( nullptr ),
49  mbNeedNextObj( false ),
50  mbOldIdleEnabled(true)
51 {
52  Init();
53 }
54 
56 {
57  Reset();
58 }
59 
60 SfxChildWinInfo ScSpellDialogChildWindow::GetInfo() const
61 {
62  return svx::SpellDialogChildWindow::GetInfo();
63 }
64 
66 {
68 }
69 
70 // protected ------------------------------------------------------------------
71 
73 {
74  svx::SpellPortions aPortions;
75  if( mxEngine && mpViewData )
76  {
77  if( EditView* pEditView = mpViewData->GetSpellingView() )
78  {
79  // edit engine handles cell iteration internally
80  do
81  {
82  if( mbNeedNextObj )
83  mxEngine->SpellNextDocument();
84  mbNeedNextObj = !mxEngine->IsFinished() && !mxEngine->SpellSentence( *pEditView, aPortions );
85  }
86  while( mbNeedNextObj );
87  }
88  }
89  return aPortions;
90 }
91 
93 {
94  if( mxEngine && mpViewData )
95  if( EditView* pEditView = mpViewData->GetSpellingView() )
96  {
97  mxEngine->ApplyChangedSentence( *pEditView, rChanged, bRecheck );
98 
99  // Reset the spell checking results to clear the markers.
101  }
102 }
103 
105 {
106  SolarMutexGuard aGuard;
107 
108  if( IsSelectionChanged() )
109  {
110  Reset();
112  Init();
113  }
114 }
115 
117 {
118 }
119 
120 // private --------------------------------------------------------------------
121 
123 {
124  if( mpViewShell && (mpViewShell == dynamic_cast<ScTabViewShell*>( SfxViewShell::Current() )) )
125  {
126  if( mxEngine && mxEngine->IsAnyModified() )
127  {
128  const ScAddress& rCursor = mxOldSel->GetCellCursor();
129  SCTAB nTab = rCursor.Tab();
130  SCCOL nOldCol = rCursor.Col();
131  SCROW nOldRow = rCursor.Row();
132  SCCOL nNewCol = mpViewData->GetCurX();
133  SCROW nNewRow = mpViewData->GetCurY();
134  mpDocShell->GetUndoManager()->AddUndoAction( std::make_unique<ScUndoConversion>(
136  nOldCol, nOldRow, nTab, std::move(mxUndoDoc),
137  nNewCol, nNewRow, nTab, std::move(mxRedoDoc),
139 
141  mpDoc->SetAllFormulasDirty(aCxt);
142 
144  }
145 
146  mpViewData->SetSpellingView( nullptr );
147  mpViewShell->KillEditView( true );
151  }
152  mxEngine.reset();
153  mxUndoDoc.reset();
154  mxRedoDoc.reset();
155  mxOldSel.reset();
157  mpViewShell = nullptr;
158  mpViewData = nullptr;
159  mpDocShell = nullptr;
160  mpDoc = nullptr;
161  mbNeedNextObj = false;
162  mbOldIdleEnabled = true;
163 }
164 
166 {
167  if( mpViewShell )
168  return;
169  if( (mpViewShell = dynamic_cast<ScTabViewShell*>( SfxViewShell::Current() )) == nullptr )
170  return;
171 
173 
174  // exit edit mode - TODO support spelling in edit mode
176  SC_MOD()->InputEnterHandler();
177 
178  mxOldSel.reset( new ScSelectionState( *mpViewData ) );
179 
182 
183  const ScAddress& rCursor = mxOldSel->GetCellCursor();
184  SCCOL nCol = rCursor.Col();
185  SCROW nRow = rCursor.Row();
186  SCTAB nTab = rCursor.Tab();
187 
188  ScMarkData& rMarkData = mpViewData->GetMarkData();
189 
191  rMarkData.FillRangeListWithMarks(mxOldRangeList.get(), true);
192 
193  rMarkData.MarkToMulti();
194 
195  switch( mxOldSel->GetSelectionType() )
196  {
197  case SC_SELECTTYPE_NONE:
198  case SC_SELECTTYPE_SHEET:
199  {
200  // test if there is something editable
201  ScEditableTester aTester( *mpDoc, rMarkData );
202  if( !aTester.IsEditable() )
203  {
204  // #i85751# Don't show an ErrorMessage here, because the vcl
205  // parent of the InfoBox is not fully initialized yet.
206  // This leads to problems in the modality behaviour of the
207  // ScSpellDialogChildWindow.
208 
209  //mpViewShell->ErrorMessage( aTester.GetMessageId() );
210  return;
211  }
212  }
213  break;
214 
215  // edit mode exited, see TODO above
216 // case SC_SELECTTYPE_EDITCELL:
217 // break;
218 
219  default:
220  OSL_FAIL( "ScSpellDialogChildWindow::Init - unknown selection type" );
221  }
222 
224  mpDoc->EnableIdle(false); // stop online spelling
225 
226  // *** create Undo/Redo documents *** -------------------------------------
227 
228  mxUndoDoc.reset( new ScDocument( SCDOCMODE_UNDO ) );
229  mxUndoDoc->InitUndo( *mpDoc, nTab, nTab );
230  mxRedoDoc.reset( new ScDocument( SCDOCMODE_UNDO ) );
231  mxRedoDoc->InitUndo( *mpDoc, nTab, nTab );
232 
233  if ( rMarkData.GetSelectCount() > 1 )
234  {
235  for (const auto& rTab : rMarkData)
236  {
237  if( rTab != nTab )
238  {
239  mxUndoDoc->AddUndoTab( rTab, rTab );
240  mxRedoDoc->AddUndoTab( rTab, rTab );
241  }
242  }
243  }
244 
245  // *** create and init the edit engine *** --------------------------------
246 
247  mxEngine.reset( new ScSpellingEngine(
249  mxEngine->SetRefDevice( mpViewData->GetActiveWin()->GetOutDev() );
250 
251  mpViewShell->MakeEditView( mxEngine.get(), nCol, nRow );
253  mpViewData->SetSpellingView( pEditView );
254  tools::Rectangle aRect( Point( 0, 0 ), Point( 0, 0 ) );
255  pEditView->SetOutputArea( aRect );
256  mxEngine->SetControlWord( EEControlBits::USECHARATTRIBS );
257  mxEngine->EnableUndo( false );
258  mxEngine->SetPaperSize( aRect.GetSize() );
259  mxEngine->SetTextCurrentDefaults( EMPTY_OUSTRING );
260  mxEngine->ClearModifyFlag();
261 
262  mbNeedNextObj = true;
263 }
264 
266 {
267  if (!mxOldRangeList || !mpViewShell
268  || (mpViewShell != dynamic_cast<ScTabViewShell*>(SfxViewShell::Current())))
269  return true;
270 
271  if( EditView* pEditView = mpViewData->GetSpellingView() )
272  if( pEditView->GetEditEngine() != mxEngine.get() )
273  return true;
274 
275  ScRangeList aCurrentRangeList;
276  mpViewData->GetMarkData().FillRangeListWithMarks(&aCurrentRangeList, true);
277 
278  return (*mxOldRangeList != aCurrentRangeList);
279 }
280 
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3108
void EnableIdle(bool bDo)
Definition: document.hxx:2131
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:353
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:42
#define EMPTY_OUSTRING
Definition: global.hxx:214
void Init()
virtual void ApplyChangedSentence(const svx::SpellPortions &rChanged, bool bRecheck) override
This method is responsible for merging corrections made in the spelling dialog back into the document...
Definition: spelldialog.cxx:92
virtual void GetFocus() override
SCROW Row() const
Definition: address.hxx:261
void PostPaintGridAll()
Definition: docsh3.cxx:183
void MarkToMulti()
Definition: markdata.cxx:223
SCROW GetCurY() const
Definition: viewdata.hxx:401
ScConvEnginePtr mxEngine
Definition: spelldialog.hxx:76
void FillRangeListWithMarks(ScRangeList *pList, bool bClear, SCTAB nForTab=-1) const
Create a range list of marks.
Definition: markdata.cxx:386
void SetDocumentModified()
Definition: docsh.cxx:2940
void SetSpellingView(EditView *pSpView)
Definition: viewdata.hxx:640
bool HasEditView(ScSplitPos eWhich) const
Definition: viewdata.hxx:572
ScSplitPos GetActivePart() const
Definition: viewdata.hxx:397
No selection, simple cell cursor.
void ResetAutoSpell()
Definition: gridwin.cxx:5689
virtual SfxUndoManager * GetUndoManager() override
Definition: docsh.cxx:2926
void KillEditView(bool bNoPaint)
Definition: tabview3.cxx:2171
ScSelectionStatePtr mxOldSel
Definition: spelldialog.hxx:79
void SetAllFormulasDirty(const sc::SetFormulaDirtyContext &rCxt)
Definition: document.cxx:3866
virtual svx::SpellPortions GetNextWrongSentence(bool bRecheck) override
Iterate over the sentences in all text shapes and stop at the next sentence with spelling errors...
Definition: spelldialog.cxx:72
SCTAB GetSelectCount() const
Definition: markdata.cxx:194
static SfxViewShell * Current()
ScTabViewShell * mpViewShell
Original selection range for comparison.
Definition: spelldialog.hxx:82
void UpdateInputHandler(bool bForce=false, bool bStopEditing=true)
Definition: tabvwsha.cxx:654
SCTAB Tab() const
Definition: address.hxx:270
ScDocumentUniquePtr mxUndoDoc
Definition: spelldialog.hxx:77
EditView * GetSpellingView() const
Definition: viewdata.hxx:641
ScViewData & GetViewData()
Definition: tabview.hxx:333
std::vector< SpellPortion > SpellPortions
tools::SvRef< ScRangeList > mxOldRangeList
For cursor position in selection.
Definition: spelldialog.hxx:81
Edit engine for spell checking.
Definition: spelleng.hxx:95
T * get() const
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
static css::uno::Reference< css::linguistic2::XSpellChecker1 > GetSpellChecker()
SFX_IMPL_CHILDWINDOW_WITHID(SvxSearchDialogWrapper, SID_SEARCH_DLG)
sal_Int16 SCCOL
Definition: types.hxx:21
#define SC_MOD()
Definition: scmod.hxx:250
Parameters for conversion.
Definition: spellparam.hxx:32
SC_DLLPUBLIC SfxItemPool * GetEnginePool() const
Definition: documen2.cxx:452
ScGridWindow * GetActiveWin()
Definition: viewdata.cxx:3124
Contains all available data about any possible selection in a Calc document.
bool IsEditable() const
Definition: editable.hxx:84
void MakeEditView(ScEditEngineDefaulter *pEngine, SCCOL nCol, SCROW nRow)
Definition: tabview3.cxx:2091
SCCOL Col() const
Definition: address.hxx:266
sal_Int32 SCROW
Definition: types.hxx:17
constexpr Size GetSize() const
ScDocumentUniquePtr mxRedoDoc
Definition: spelldialog.hxx:78
::OutputDevice const * GetOutDev() const
virtual void LoseFocus() override
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
void SetOutputArea(const tools::Rectangle &rRect)
virtual ~ScSpellDialogChildWindow() override
Definition: spelldialog.cxx:55
bool IsIdleEnabled() const
Definition: document.hxx:2130
void GetEditView(ScSplitPos eWhich, EditView *&rViewPtr, SCCOL &rCol, SCROW &rRow)
Definition: viewdata.cxx:2279
Specialized spell check dialog child window for Calc.
Definition: spelldialog.hxx:38
void InvalidateSpellDialog()
This method makes the one from the base class public so that it can be called from the view shell whe...
Definition: spelldialog.cxx:65
sal_Int16 SCTAB
Definition: types.hxx:22
SCCOL GetCurX() const
Definition: viewdata.hxx:400