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 
29 #include <spelleng.hxx>
30 #include <tabvwsh.hxx>
31 #include <docsh.hxx>
32 #include <scmod.hxx>
33 #include <editable.hxx>
34 #include <undoblk.hxx>
35 #include <gridwin.hxx>
36 #include <refupdatecontext.hxx>
37 #include <vcl/svapp.hxx>
38 
40 
41 ScSpellDialogChildWindow::ScSpellDialogChildWindow( vcl::Window* pParentP, sal_uInt16 nId,
42  SfxBindings* pBindings, SAL_UNUSED_PARAMETER SfxChildWinInfo* /*pInfo*/ ) :
43  svx::SpellDialogChildWindow( pParentP, nId, pBindings ),
44  mpViewShell( nullptr ),
45  mpViewData( nullptr ),
46  mpDocShell( nullptr ),
47  mpDoc( nullptr ),
48  mbNeedNextObj( false ),
49  mbOldIdleEnabled(true)
50 {
51  Init();
52 }
53 
55 {
56  Reset();
57 }
58 
59 SfxChildWinInfo ScSpellDialogChildWindow::GetInfo() const
60 {
61  return svx::SpellDialogChildWindow::GetInfo();
62 }
63 
65 {
67 }
68 
69 // protected ------------------------------------------------------------------
70 
72 {
73  svx::SpellPortions aPortions;
74  if( mxEngine && mpViewData )
75  {
76  if( EditView* pEditView = mpViewData->GetSpellingView() )
77  {
78  // edit engine handles cell iteration internally
79  do
80  {
81  if( mbNeedNextObj )
82  mxEngine->SpellNextDocument();
83  mbNeedNextObj = !mxEngine->IsFinished() && !mxEngine->SpellSentence( *pEditView, aPortions );
84  }
85  while( mbNeedNextObj );
86  }
87  }
88  return aPortions;
89 }
90 
92 {
93  if( mxEngine && mpViewData )
94  if( EditView* pEditView = mpViewData->GetSpellingView() )
95  {
96  mxEngine->ApplyChangedSentence( *pEditView, rChanged, bRecheck );
97 
98  // Reset the spell checking results to clear the markers.
100  }
101 }
102 
104 {
105  SolarMutexGuard aGuard;
106 
107  if( IsSelectionChanged() )
108  {
109  Reset();
111  Init();
112  }
113 }
114 
116 {
117 }
118 
119 // private --------------------------------------------------------------------
120 
122 {
123  if( mpViewShell && (mpViewShell == dynamic_cast<ScTabViewShell*>( SfxViewShell::Current() )) )
124  {
125  if( mxEngine && mxEngine->IsAnyModified() )
126  {
127  const ScAddress& rCursor = mxOldSel->GetCellCursor();
128  SCTAB nTab = rCursor.Tab();
129  SCCOL nOldCol = rCursor.Col();
130  SCROW nOldRow = rCursor.Row();
131  SCCOL nNewCol = mpViewData->GetCurX();
132  SCROW nNewRow = mpViewData->GetCurY();
133  mpDocShell->GetUndoManager()->AddUndoAction( std::make_unique<ScUndoConversion>(
135  nOldCol, nOldRow, nTab, std::move(mxUndoDoc),
136  nNewCol, nNewRow, nTab, std::move(mxRedoDoc),
138 
140  mpDoc->SetAllFormulasDirty(aCxt);
141 
143  }
144 
145  mpViewData->SetSpellingView( nullptr );
146  mpViewShell->KillEditView( true );
150  }
151  mxEngine.reset();
152  mxUndoDoc.reset();
153  mxRedoDoc.reset();
154  mxOldSel.reset();
156  mpViewShell = nullptr;
157  mpViewData = nullptr;
158  mpDocShell = nullptr;
159  mpDoc = nullptr;
160  mbNeedNextObj = false;
161  mbOldIdleEnabled = true;
162 }
163 
165 {
166  if( mpViewShell )
167  return;
168  if( (mpViewShell = dynamic_cast<ScTabViewShell*>( SfxViewShell::Current() )) == nullptr )
169  return;
170 
172 
173  // exit edit mode - TODO support spelling in edit mode
175  SC_MOD()->InputEnterHandler();
176 
177  mxOldSel.reset( new ScSelectionState( *mpViewData ) );
178 
181 
182  const ScAddress& rCursor = mxOldSel->GetCellCursor();
183  SCCOL nCol = rCursor.Col();
184  SCROW nRow = rCursor.Row();
185  SCTAB nTab = rCursor.Tab();
186 
187  ScMarkData& rMarkData = mpViewData->GetMarkData();
188 
190  rMarkData.FillRangeListWithMarks(mxOldRangeList.get(), true);
191 
192  rMarkData.MarkToMulti();
193 
194  switch( mxOldSel->GetSelectionType() )
195  {
196  case SC_SELECTTYPE_NONE:
197  case SC_SELECTTYPE_SHEET:
198  {
199  // test if there is something editable
200  ScEditableTester aTester( mpDoc, rMarkData );
201  if( !aTester.IsEditable() )
202  {
203  // #i85751# Don't show an ErrorMessage here, because the vcl
204  // parent of the InfoBox is not fully initialized yet.
205  // This leads to problems in the modality behaviour of the
206  // ScSpellDialogChildWindow.
207 
208  //mpViewShell->ErrorMessage( aTester.GetMessageId() );
209  return;
210  }
211  }
212  break;
213 
214  // edit mode exited, see TODO above
215 // case SC_SELECTTYPE_EDITCELL:
216 // break;
217 
218  default:
219  OSL_FAIL( "ScSpellDialogChildWindow::Init - unknown selection type" );
220  }
221 
223  mpDoc->EnableIdle(false); // stop online spelling
224 
225  // *** create Undo/Redo documents *** -------------------------------------
226 
227  mxUndoDoc.reset( new ScDocument( SCDOCMODE_UNDO ) );
228  mxUndoDoc->InitUndo( mpDoc, nTab, nTab );
229  mxRedoDoc.reset( new ScDocument( SCDOCMODE_UNDO ) );
230  mxRedoDoc->InitUndo( mpDoc, nTab, nTab );
231 
232  if ( rMarkData.GetSelectCount() > 1 )
233  {
234  for (const auto& rTab : rMarkData)
235  {
236  if( rTab != nTab )
237  {
238  mxUndoDoc->AddUndoTab( rTab, rTab );
239  mxRedoDoc->AddUndoTab( rTab, rTab );
240  }
241  }
242  }
243 
244  // *** create and init the edit engine *** --------------------------------
245 
246  mxEngine.reset( new ScSpellingEngine(
248  mxEngine->SetRefDevice( mpViewData->GetActiveWin() );
249 
250  mpViewShell->MakeEditView( mxEngine.get(), nCol, nRow );
252  mpViewData->SetSpellingView( pEditView );
253  tools::Rectangle aRect( Point( 0, 0 ), Point( 0, 0 ) );
254  pEditView->SetOutputArea( aRect );
255  mxEngine->SetControlWord( EEControlBits::USECHARATTRIBS );
256  mxEngine->EnableUndo( false );
257  mxEngine->SetPaperSize( aRect.GetSize() );
258  mxEngine->SetTextCurrentDefaults( EMPTY_OUSTRING );
259  mxEngine->ClearModifyFlag();
260 
261  mbNeedNextObj = true;
262 }
263 
265 {
266  if (!mxOldRangeList || !mpViewShell
267  || (mpViewShell != dynamic_cast<ScTabViewShell*>(SfxViewShell::Current())))
268  return true;
269 
270  if( EditView* pEditView = mpViewData->GetSpellingView() )
271  if( pEditView->GetEditEngine() != mxEngine.get() )
272  return true;
273 
274  ScRangeList aCurrentRangeList;
275  mpViewData->GetMarkData().FillRangeListWithMarks(&aCurrentRangeList, true);
276 
277  return (*mxOldRangeList != aCurrentRangeList);
278 }
279 
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3053
void EnableIdle(bool bDo)
Definition: document.hxx:2121
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
#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:91
virtual void GetFocus() override
SCROW Row() const
Definition: address.hxx:262
void PostPaintGridAll()
Definition: docsh3.cxx:181
void MarkToMulti()
Definition: markdata.cxx:224
SCROW GetCurY() const
Definition: viewdata.hxx:402
ScConvEnginePtr mxEngine
Definition: spelldialog.hxx:77
void FillRangeListWithMarks(ScRangeList *pList, bool bClear, SCTAB nForTab=-1) const
Create a range list of marks.
Definition: markdata.cxx:387
void SetDocumentModified()
Definition: docsh.cxx:2819
void SetSpellingView(EditView *pSpView)
Definition: viewdata.hxx:637
bool HasEditView(ScSplitPos eWhich) const
Definition: viewdata.hxx:569
ScSplitPos GetActivePart() const
Definition: viewdata.hxx:398
No selection, simple cell cursor.
void ResetAutoSpell()
Definition: gridwin.cxx:5697
virtual SfxUndoManager * GetUndoManager() override
Definition: docsh.cxx:2805
void KillEditView(bool bNoPaint)
Definition: tabview3.cxx:2157
ScSelectionStatePtr mxOldSel
Definition: spelldialog.hxx:80
void SetAllFormulasDirty(const sc::SetFormulaDirtyContext &rCxt)
Definition: document.cxx:3837
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:71
SCTAB GetSelectCount() const
Definition: markdata.cxx:195
static SfxViewShell * Current()
ScTabViewShell * mpViewShell
Original selection range for comparison.
Definition: spelldialog.hxx:83
void UpdateInputHandler(bool bForce=false, bool bStopEditing=true)
Definition: tabvwsha.cxx:632
SCTAB Tab() const
Definition: address.hxx:271
ScDocumentUniquePtr mxUndoDoc
Definition: spelldialog.hxx:78
EditView * GetSpellingView() const
Definition: viewdata.hxx:638
ScViewData & GetViewData()
Definition: tabview.hxx:332
std::vector< SpellPortion > SpellPortions
tools::SvRef< ScRangeList > mxOldRangeList
For cursor position in selection.
Definition: spelldialog.hxx:82
Edit engine for spell checking.
Definition: spelleng.hxx:96
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:22
#define SC_MOD()
Definition: scmod.hxx:253
Parameters for conversion.
Definition: spellparam.hxx:33
SC_DLLPUBLIC SfxItemPool * GetEnginePool() const
Definition: documen2.cxx:449
ScGridWindow * GetActiveWin()
Definition: viewdata.cxx:3069
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:2077
Size GetSize() const
SCCOL Col() const
Definition: address.hxx:267
sal_Int32 SCROW
Definition: types.hxx:18
ScDocumentUniquePtr mxRedoDoc
Definition: spelldialog.hxx:79
virtual void LoseFocus() override
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
void SetOutputArea(const tools::Rectangle &rRect)
virtual ~ScSpellDialogChildWindow() override
Definition: spelldialog.cxx:54
bool IsIdleEnabled() const
Definition: document.hxx:2120
void GetEditView(ScSplitPos eWhich, EditView *&rViewPtr, SCCOL &rCol, SCROW &rRow)
Definition: viewdata.cxx:2225
Specialized spell check dialog child window for Calc.
Definition: spelldialog.hxx:39
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:64
sal_Int16 SCTAB
Definition: types.hxx:23
SCCOL GetCurX() const
Definition: viewdata.hxx:401