Auto spell-check is no longer done in ScDocument.
Change-Id: I7ecfd6160443299887e31d784322a00580aac067
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 9c307f5..e8aa17d 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1649,8 +1649,6 @@ public:
bool IdleCalcTextWidth();
bool IdleCheckLinks();
bool ContinueOnlineSpelling(); // TRUE = found s.th.
void RepaintRange( const ScRange& rRange );
void RepaintRange( const ScRangeList& rRange );
@@ -1662,7 +1660,6 @@ public:
void RemoveAutoSpellObj();
void SetOnlineSpellPos( const ScAddress& rPos );
SC_DLLPUBLIC bool SetVisibleSpellRange( const ScRange& rRange ); // true = changed
sal_uInt8 GetMacroCallMode() const { return nMacroCallMode; }
void SetMacroCallMode(sal_uInt8 nNew) { nMacroCallMode = nNew; }
@@ -1760,8 +1757,6 @@ private:
ScDocument& rOtherDoc, SCTAB nThisTab, SCTAB nOtherTab,
SCCOLROW nEndCol, SCCOLROW* pTranslate,
ScProgress* pProgress, sal_uLong nProAdd );
bool OnlineSpellInRange( const ScRange& rSpellRange, ScAddress& rSpellPos,
sal_uInt16 nMaxTest );
DECL_LINK(TrackTimeHdl, void *);
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 4dfd029..67fb76a 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -91,10 +91,6 @@
#include <memory>
#include <boost/scoped_ptr.hpp>
// states for online spelling in the visible range (0 is set initially)
#define VSPL_START 0
#define VSPL_DONE 1
using namespace com::sun::star;
// STATIC DATA -----------------------------------------------------------
@@ -746,225 +742,6 @@ IMPL_LINK( ScSpellStatus, EventHdl, EditStatus *, pStatus )
return 0;
}
// SPELL_MAXCELLS muss mindestens 256 sein, solange am Iterator keine
// Start-Spalte gesetzt werden kann
//! SPELL_MAXTEST fuer Timer und Idle unterschiedlich ???
// SPELL_MAXTEST now divided between visible and rest of document
#define SPELL_MAXTEST_VIS 1
#define SPELL_MAXTEST_ALL 3
#define SPELL_MAXCELLS 256
bool ScDocument::OnlineSpellInRange( const ScRange& rSpellRange, ScAddress& rSpellPos,
sal_uInt16 nMaxTest )
{
ScEditEngineDefaulter* pEngine = NULL; //! am Dokument speichern
SfxItemSet* pDefaults = NULL;
ScSpellStatus aStatus;
sal_uInt16 nCellCount = 0; // Zellen insgesamt
sal_uInt16 nTestCount = 0; // Aufrufe Spelling
bool bChanged = false; // Aenderungen?
SCCOL nCol = rSpellRange.aStart.Col(); // iterator always starts on the left edge
SCROW nRow = rSpellPos.Row();
SCTAB nTab = rSpellPos.Tab();
if ( nTab >= static_cast<SCTAB>(maTabs.size()) || !maTabs[nTab] ) // sheet deleted?
{
nTab = rSpellRange.aStart.Tab();
nRow = rSpellRange.aStart.Row();
if ( nTab >= static_cast<SCTAB>(maTabs.size()) || !maTabs[nTab] )
{
// may happen for visible range
return false;
}
}
ScRangeList aPivotRanges;
if (pDPCollection)
aPivotRanges = pDPCollection->GetAllTableRanges(nTab);
ScHorizontalCellIterator aIter( this, nTab,
rSpellRange.aStart.Col(), nRow,
rSpellRange.aEnd.Col(), rSpellRange.aEnd.Row() );
ScRefCellValue* pCell = aIter.GetNext( nCol, nRow );
// skip everything left of rSpellPos:
while ( pCell && nRow == rSpellPos.Row() && nCol < rSpellPos.Col() )
pCell = aIter.GetNext( nCol, nRow );
for (; pCell; pCell = aIter.GetNext(nCol, nRow))
{
if (!aPivotRanges.empty() && aPivotRanges.In(ScAddress(nCol, nRow, nTab)))
// Don't spell check within pivot tables.
continue;
CellType eType = pCell->meType;
if ( eType == CELLTYPE_STRING || eType == CELLTYPE_EDIT )
{
if (!pEngine)
{
// ScTabEditEngine is needed
// because MapMode must be set for some old documents
pEngine = new ScTabEditEngine( this );
pEngine->SetControlWord( pEngine->GetControlWord() |
( EE_CNTRL_ONLINESPELLING | EE_CNTRL_ALLOWBIGOBJS ) );
pEngine->SetStatusEventHdl( LINK( &aStatus, ScSpellStatus, EventHdl ) );
// Delimiters hier wie in inputhdl.cxx !!!
pEngine->SetWordDelimiters(
ScEditUtil::ModifyDelimiters( pEngine->GetWordDelimiters() ) );
pDefaults = new SfxItemSet( pEngine->GetEmptyItemSet() );
com::sun::star::uno::Reference<com::sun::star::linguistic2::XSpellChecker1> xXSpellChecker1( LinguMgr::GetSpellChecker() );
pEngine->SetSpeller( xXSpellChecker1 );
}
const ScPatternAttr* pPattern = GetPattern( nCol, nRow, nTab );
if ( ScStyleSheet* pPreviewStyle = GetPreviewCellStyle( nCol, nRow, nTab ) )
{
ScPatternAttr* pPreviewPattern = new ScPatternAttr( *pPattern );
pPreviewPattern->SetStyleSheet(pPreviewStyle);
pPreviewPattern->FillEditItemSet( pDefaults );
delete pPreviewPattern;
}
else
{
SfxItemSet* pFontSet = GetPreviewFont( nCol, nRow, nTab );
pPattern->FillEditItemSet( pDefaults, pFontSet );
}
pEngine->SetDefaults( pDefaults, false ); //! noetig ?
sal_uInt16 nCellLang = ((const SvxLanguageItem&)
pPattern->GetItem(ATTR_FONT_LANGUAGE)).GetValue();
if ( nCellLang == LANGUAGE_SYSTEM )
nCellLang = Application::GetSettings().GetLanguageTag().getLanguageType(); // never use SYSTEM for spelling
pEngine->SetDefaultLanguage( nCellLang );
if ( eType == CELLTYPE_STRING )
{
pEngine->SetText(*pCell->mpString);
}
else if (pCell->mpEditText)
pEngine->SetText(*pCell->mpEditText);
else
pEngine->SetText(EMPTY_OUSTRING);
aStatus.bModified = false;
pEngine->CompleteOnlineSpelling();
if ( aStatus.bModified ) // Fehler dazu oder weggekommen?
{
bool bNeedEdit = true; // Test auf einfachen Text
if ( !pEngine->HasOnlineSpellErrors() )
{
ScEditAttrTester aTester( pEngine );
bNeedEdit = aTester.NeedsObject();
}
if ( bNeedEdit )
{
// The cell will take ownership of pNewData.
SetEditText(ScAddress(nCol,nRow,nTab), pEngine->CreateTextObject());
aIter.RehashCol(nCol);
}
else
{
ScSetStringParam aParam;
aParam.setTextInput();
SetString(ScAddress(nCol,nRow,nTab), pEngine->GetText(), &aParam);
aIter.RehashCol(nCol);
}
// Paint
if (pShell)
{
// Seitenvorschau ist davon nicht betroffen
// (sollte jedenfalls nicht)
ScPaintHint aHint( ScRange( nCol, nRow, nTab ), PAINT_GRID );
aHint.SetPrintFlag( false );
pShell->Broadcast( aHint );
}
bChanged = true;
}
if ( ++nTestCount >= nMaxTest ) // checked enough text?
break;
}
if ( ++nCellCount >= SPELL_MAXCELLS ) // seen enough cells?
break;
}
if ( pCell )
{
++nCol; // continue after last cell
if ( nCol > rSpellRange.aEnd.Col() )
{
nCol = rSpellRange.aStart.Col();
++nRow;
if ( nRow > rSpellRange.aEnd.Row() )
pCell = NULL;
}
}
if (!pCell) // end of range reached -> next sheet
{
++nTab;
if ( nTab > rSpellRange.aEnd.Tab() || nTab >= static_cast<SCTAB>(maTabs.size()) || !maTabs[nTab] )
nTab = rSpellRange.aStart.Tab();
nCol = rSpellRange.aStart.Col();
nRow = rSpellRange.aStart.Row();
nVisSpellState = VSPL_DONE; //! only if this is for the visible range
}
rSpellPos.Set( nCol, nRow, nTab );
delete pDefaults;
delete pEngine; // bevor aStatus out of scope geht
return bChanged;
}
bool ScDocument::ContinueOnlineSpelling()
{
if (!mbIdleEnabled || !pDocOptions->IsAutoSpell() || (pShell && pShell->IsReadOnly()))
return false;
// #i48433# set bInsertingFromOtherDoc flag so there are no broadcasts when PutCell is called
// (same behavior as in RemoveAutoSpellObj: just transfer the broadcaster)
bool bOldInserting = IsInsertingFromOtherDoc();
SetInsertingFromOtherDoc( true );
//! use one EditEngine for both calls
// first check visible range
bool bResult = OnlineSpellInRange( aVisSpellRange, aVisSpellPos, SPELL_MAXTEST_VIS );
// during first pass through visible range, always continue
if ( nVisSpellState == VSPL_START )
bResult = true;
if (bResult)
{
// if errors found, continue there
OnlineSpellInRange( aVisSpellRange, aVisSpellPos, SPELL_MAXTEST_ALL );
}
else
{
// if nothing found there, continue with rest of document
ScRange aTotalRange( 0,0,0, MAXCOL,MAXROW,MAXTAB );
bResult = OnlineSpellInRange( aTotalRange, aOnlineSpellPos, SPELL_MAXTEST_ALL );
}
SetInsertingFromOtherDoc( bOldInserting );
return bResult;
}
void ScDocument::SetOnlineSpellPos( const ScAddress& rPos )
{
aOnlineSpellPos = rPos;
@@ -974,32 +751,6 @@ void ScDocument::SetOnlineSpellPos( const ScAddress& rPos )
aOnlineSpellPos = aVisSpellRange.aEnd;
}
bool ScDocument::SetVisibleSpellRange( const ScRange& rNewRange )
{
bool bChange = ( aVisSpellRange != rNewRange );
if (bChange)
{
// continue spelling through visible range when scrolling down
bool bContDown = ( nVisSpellState == VSPL_START && rNewRange.In( aVisSpellPos ) &&
rNewRange.aStart.Row() > aVisSpellRange.aStart.Row() &&
rNewRange.aStart.Col() == aVisSpellRange.aStart.Col() &&
rNewRange.aEnd.Col() == aVisSpellRange.aEnd.Col() );
aVisSpellRange = rNewRange;
if ( !bContDown )
{
aVisSpellPos = aVisSpellRange.aStart;
nVisSpellState = VSPL_START;
}
// skip visible area for aOnlineSpellPos
if ( aVisSpellRange.In( aOnlineSpellPos ) )
aOnlineSpellPos = aVisSpellRange.aEnd;
}
return bChange;
}
void ScDocument::RemoveAutoSpellObj()
{
// alle Spelling-Informationen entfernen
diff --git a/sc/source/ui/app/scmod.cxx b/sc/source/ui/app/scmod.cxx
index 74bb24a..37dee2f 100644
--- a/sc/source/ui/app/scmod.cxx
+++ b/sc/source/ui/app/scmod.cxx
@@ -1942,11 +1942,15 @@ IMPL_LINK_NOARG(ScModule, IdleHandler)
}
bool bMore = false;
bool bAutoSpell = false;
ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(SfxObjectShell::Current());
if ( pDocSh )
{
ScDocument* pDoc = pDocSh->GetDocument();
bAutoSpell = pDoc->GetDocOptions().IsAutoSpell();
if (pDocSh->IsReadOnly())
bAutoSpell = false;
sal_Bool bLinks = pDoc->IdleCheckLinks();
sal_Bool bWidth = pDoc->IdleCalcTextWidth();
@@ -1959,14 +1963,17 @@ IMPL_LINK_NOARG(ScModule, IdleHandler)
lcl_CheckNeedsRepaint( pDocSh );
}
ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
if (pViewSh)
if (bAutoSpell)
{
bool bSpell = pViewSh->ContinueOnlineSpelling();
if (bSpell)
ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
if (pViewSh)
{
aSpellTimer.Start();
bMore = true;
bool bSpell = pViewSh->ContinueOnlineSpelling();
if (bSpell)
{
aSpellTimer.Start();
bMore = true;
}
}
}