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
42ScSpellDialogChildWindow::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
60SfxChildWinInfo 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
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 {
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( OUString() );
260 mxEngine->ClearModifyFlag();
261
262 mbNeedNextObj = true;
263}
264
266{
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: */
void SetOutputArea(const tools::Rectangle &rRect)
static css::uno::Reference< css::linguistic2::XSpellChecker1 > GetSpellChecker()
SCTAB Tab() const
Definition: address.hxx:283
SCROW Row() const
Definition: address.hxx:274
SCCOL Col() const
Definition: address.hxx:279
Parameters for conversion.
Definition: spellparam.hxx:33
void PostPaintGridAll()
Definition: docsh3.cxx:183
void SetDocumentModified()
Definition: docsh.cxx:2982
const ScDocument & GetDocument() const
Definition: docsh.hxx:219
virtual SfxUndoManager * GetUndoManager() override
Definition: docsh.cxx:2968
SC_DLLPUBLIC SfxItemPool * GetEnginePool() const
Definition: documen2.cxx:478
bool IsIdleEnabled() const
Definition: document.hxx:2207
void SetAllFormulasDirty(const sc::SetFormulaDirtyContext &rCxt)
Definition: document.cxx:3819
void EnableIdle(bool bDo)
Definition: document.hxx:2208
bool IsEditable() const
Definition: editable.hxx:84
void ResetAutoSpell()
Definition: gridwin.cxx:5938
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
void FillRangeListWithMarks(ScRangeList *pList, bool bClear, SCTAB nForTab=-1) const
Create a range list of marks.
Definition: markdata.cxx:372
SCTAB GetSelectCount() const
Definition: markdata.cxx:180
void MarkToMulti()
Definition: markdata.cxx:209
Contains all available data about any possible selection in a Calc document.
Specialized spell check dialog child window for Calc.
Definition: spelldialog.hxx:39
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
ScTabViewShell * mpViewShell
Original selection range for comparison.
Definition: spelldialog.hxx:82
ScDocumentUniquePtr mxUndoDoc
Definition: spelldialog.hxx:77
ScDocumentUniquePtr mxRedoDoc
Definition: spelldialog.hxx:78
virtual void LoseFocus() override
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
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
tools::SvRef< ScRangeList > mxOldRangeList
For cursor position in selection.
Definition: spelldialog.hxx:81
ScConvEnginePtr mxEngine
Definition: spelldialog.hxx:76
ScSelectionStatePtr mxOldSel
Definition: spelldialog.hxx:79
virtual ~ScSpellDialogChildWindow() override
Definition: spelldialog.cxx:55
virtual void GetFocus() override
Edit engine for spell checking.
Definition: spelleng.hxx:96
void UpdateInputHandler(bool bForce=false, bool bStopEditing=true)
Definition: tabvwsha.cxx:690
void MakeEditView(ScEditEngineDefaulter *pEngine, SCCOL nCol, SCROW nRow)
Definition: tabview3.cxx:2113
ScViewData & GetViewData()
Definition: tabview.hxx:344
void KillEditView(bool bNoPaint)
Definition: tabview3.cxx:2196
void SetSpellingView(EditView *pSpView)
Definition: viewdata.hxx:650
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3146
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
ScGridWindow * GetActiveWin()
Definition: viewdata.cxx:3162
ScSplitPos GetActivePart() const
Definition: viewdata.hxx:398
void GetEditView(ScSplitPos eWhich, EditView *&rViewPtr, SCCOL &rCol, SCROW &rRow)
Definition: viewdata.cxx:2284
EditView * GetSpellingView() const
Definition: viewdata.hxx:651
bool HasEditView(ScSplitPos eWhich) const
Definition: viewdata.hxx:582
SCROW GetCurY() const
Definition: viewdata.hxx:402
SCCOL GetCurX() const
Definition: viewdata.hxx:401
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
constexpr Size GetSize() const
T * get() const
::OutputDevice const * GetOutDev() const
void Init()
@ SCDOCMODE_UNDO
Definition: document.hxx:258
std::vector< SpellPortion > SpellPortions
#define SC_MOD()
Definition: scmod.hxx:247
@ SC_SELECTTYPE_SHEET
No selection, simple cell cursor.
@ SC_SELECTTYPE_NONE
@ SC_CONVERSION_SPELLCHECK
Definition: spellparam.hxx:26
SFX_IMPL_CHILDWINDOW_WITHID(SvxSearchDialogWrapper, SID_SEARCH_DLG)
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17