Update ooo320-m1
[ooovba.git] / sc / source / ui / view / spelldialog.cxx
blob0e78cc3c026600bed94f6c850d73bf2ad027beca
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: spelldialog.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
33 #include "spelldialog.hxx"
35 #include <sfx2/app.hxx>
36 #include <sfx2/bindings.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <svx/svxids.hrc>
39 #include <svx/editstat.hxx>
40 #include <svx/editview.hxx>
41 #include <svx/unolingu.hxx>
42 #include "selectionstate.hxx"
44 #include "spelleng.hxx"
45 #include "tabvwsh.hxx"
46 #include "docsh.hxx"
47 #include "scmod.hxx"
48 #include "editable.hxx"
49 #include "undoblk.hxx"
51 // ============================================================================
53 SFX_IMPL_CHILDWINDOW( ScSpellDialogChildWindow, SID_SPELL_DIALOG )
55 ScSpellDialogChildWindow::ScSpellDialogChildWindow( Window* pParentP, USHORT nId,
56 SfxBindings* pBindings, SfxChildWinInfo* pInfo ) :
57 ::svx::SpellDialogChildWindow( pParentP, nId, pBindings, pInfo ),
58 mpViewShell( 0 ),
59 mpViewData( 0 ),
60 mpDocShell( 0 ),
61 mpDoc( 0 ),
62 mbNeedNextObj( false ),
63 mbOldIdleDisabled( false )
65 Init();
68 ScSpellDialogChildWindow::~ScSpellDialogChildWindow()
70 Reset();
73 SfxChildWinInfo ScSpellDialogChildWindow::GetInfo() const
75 return ::svx::SpellDialogChildWindow::GetInfo();
78 void ScSpellDialogChildWindow::InvalidateSpellDialog()
80 ::svx::SpellDialogChildWindow::InvalidateSpellDialog();
83 // protected ------------------------------------------------------------------
85 ::svx::SpellPortions ScSpellDialogChildWindow::GetNextWrongSentence()
87 ::svx::SpellPortions aPortions;
88 if( mxEngine.get() && mpViewData )
90 if( EditView* pEditView = mpViewData->GetSpellingView() )
92 // edit engine handles cell iteration internally
95 if( mbNeedNextObj )
96 mxEngine->SpellNextDocument();
97 mbNeedNextObj = !mxEngine->IsFinished() && !mxEngine->SpellSentence( *pEditView, aPortions, false );
99 while( mbNeedNextObj );
102 // finished? - close the spelling dialog
103 if( mxEngine->IsFinished() )
104 GetBindings().GetDispatcher()->Execute( SID_SPELL_DIALOG, SFX_CALLMODE_ASYNCHRON );
106 return aPortions;
109 void ScSpellDialogChildWindow::ApplyChangedSentence( const ::svx::SpellPortions& rChanged )
111 if( mxEngine.get() && mpViewData )
112 if( EditView* pEditView = mpViewData->GetSpellingView() )
113 mxEngine->ApplyChangedSentence( *pEditView, rChanged, false );
116 void ScSpellDialogChildWindow::GetFocus()
118 if( IsSelectionChanged() )
120 Reset();
121 InvalidateSpellDialog();
122 Init();
126 void ScSpellDialogChildWindow::LoseFocus()
130 // private --------------------------------------------------------------------
132 void ScSpellDialogChildWindow::Reset()
134 if( mpViewShell && (mpViewShell == PTR_CAST( ScTabViewShell, SfxViewShell::Current() )) )
136 if( mxEngine.get() && mxEngine->IsAnyModified() )
138 const ScAddress& rCursor = mxOldSel->GetCellCursor();
139 SCTAB nTab = rCursor.Tab();
140 SCCOL nOldCol = rCursor.Col();
141 SCROW nOldRow = rCursor.Row();
142 SCCOL nNewCol = mpViewData->GetCurX();
143 SCROW nNewRow = mpViewData->GetCurY();
144 mpDocShell->GetUndoManager()->AddUndoAction( new ScUndoConversion(
145 mpDocShell, mpViewData->GetMarkData(),
146 nOldCol, nOldRow, nTab, mxUndoDoc.release(),
147 nNewCol, nNewRow, nTab, mxRedoDoc.release(),
148 ScConversionParam( SC_CONVERSION_SPELLCHECK ) ) );
149 mpDoc->SetDirty();
150 mpDocShell->SetDocumentModified();
153 mpViewData->SetSpellingView( 0 );
154 mpViewShell->KillEditView( TRUE );
155 mpDocShell->PostPaintGridAll();
156 mpViewShell->UpdateInputHandler();
157 mpDoc->DisableIdle( mbOldIdleDisabled );
159 mxEngine.reset();
160 mxUndoDoc.reset();
161 mxRedoDoc.reset();
162 mxOldSel.reset();
163 mpViewShell = 0;
164 mpViewData = 0;
165 mpDocShell = 0;
166 mpDoc = 0;
167 mbNeedNextObj = false;
168 mbOldIdleDisabled = false;
171 void ScSpellDialogChildWindow::Init()
173 if( mpViewShell )
174 return;
175 if( (mpViewShell = PTR_CAST( ScTabViewShell, SfxViewShell::Current() )) == 0 )
176 return;
178 mpViewData = mpViewShell->GetViewData();
180 // exit edit mode - TODO support spelling in edit mode
181 if( mpViewData->HasEditView( mpViewData->GetActivePart() ) )
182 SC_MOD()->InputEnterHandler();
184 mxOldSel.reset( new ScSelectionState( *mpViewData ) );
186 mpDocShell = mpViewData->GetDocShell();
187 mpDoc = mpDocShell->GetDocument();
189 const ScAddress& rCursor = mxOldSel->GetCellCursor();
190 SCCOL nCol = rCursor.Col();
191 SCROW nRow = rCursor.Row();
192 SCTAB nTab = rCursor.Tab();
194 ScMarkData& rMarkData = mpViewData->GetMarkData();
195 rMarkData.MarkToMulti();
197 switch( mxOldSel->GetSelectionType() )
199 case SC_SELECTTYPE_NONE:
200 case SC_SELECTTYPE_SHEET:
202 // test if there is something editable
203 ScEditableTester aTester( mpDoc, rMarkData );
204 if( !aTester.IsEditable() )
206 mpViewShell->ErrorMessage( aTester.GetMessageId() );
207 return;
210 break;
212 // edit mode exited, see TODO above
213 // case SC_SELECTTYPE_EDITCELL:
214 // break;
216 default:
217 DBG_ERRORFILE( "ScSpellDialogChildWindow::Init - unknown selection type" );
220 mbOldIdleDisabled = mpDoc->IsIdleDisabled();
221 mpDoc->DisableIdle( TRUE ); // #42726# stop online spelling
223 // *** create Undo/Redo documents *** -------------------------------------
225 mxUndoDoc.reset( new ScDocument( SCDOCMODE_UNDO ) );
226 mxUndoDoc->InitUndo( mpDoc, nTab, nTab );
227 mxRedoDoc.reset( new ScDocument( SCDOCMODE_UNDO ) );
228 mxRedoDoc->InitUndo( mpDoc, nTab, nTab );
230 if ( rMarkData.GetSelectCount() > 1 )
232 SCTAB nTabCount = mpDoc->GetTableCount();
233 for( SCTAB nOtherTab = 0; nOtherTab < nTabCount; ++nOtherTab )
235 if( rMarkData.GetTableSelect( nOtherTab ) && (nOtherTab != nTab) )
237 mxUndoDoc->AddUndoTab( nOtherTab, nOtherTab );
238 mxRedoDoc->AddUndoTab( nOtherTab, nOtherTab );
243 // *** create and init the edit engine *** --------------------------------
245 mxEngine.reset( new ScSpellingEngine(
246 mpDoc->GetEnginePool(), *mpViewData, mxUndoDoc.get(), mxRedoDoc.get(), LinguMgr::GetSpellChecker() ) );
247 mxEngine->SetRefDevice( mpViewData->GetActiveWin() );
249 mpViewShell->MakeEditView( mxEngine.get(), nCol, nRow );
250 EditView* pEditView = mpViewData->GetEditView( mpViewData->GetActivePart() );
251 mpViewData->SetSpellingView( pEditView );
252 Rectangle aRect( Point( 0, 0 ), Point( 0, 0 ) );
253 pEditView->SetOutputArea( aRect );
254 mxEngine->SetControlWord( EE_CNTRL_USECHARATTRIBS );
255 mxEngine->EnableUndo( FALSE );
256 mxEngine->SetPaperSize( aRect.GetSize() );
257 mxEngine->SetText( EMPTY_STRING );
258 mxEngine->ClearModifyFlag();
260 mbNeedNextObj = true;
263 bool ScSpellDialogChildWindow::IsSelectionChanged()
265 if( !mxOldSel.get() || !mpViewShell || (mpViewShell != PTR_CAST( ScTabViewShell, SfxViewShell::Current() )) )
266 return true;
268 if( EditView* pEditView = mpViewData->GetSpellingView() )
269 if( pEditView->GetEditEngine() != mxEngine.get() )
270 return true;
272 ScSelectionState aNewSel( *mpViewData );
273 return mxOldSel->GetSheetSelection() != aNewSel.GetSheetSelection();
276 // ============================================================================