diff options
author | Thomas Lange [tl] <tl@openoffice.org> | 2010-04-22 13:08:19 +0200 |
---|---|---|
committer | Thomas Lange [tl] <tl@openoffice.org> | 2010-04-22 13:08:19 +0200 |
commit | dcee57dba3d6bb88dcdc9f36ac4c6dd0dca699b9 (patch) | |
tree | 17bd0c9a9438a9e579c9b939120cc4671e6b300f /editeng | |
parent | 8d8c715352d37c28e0e4987a29dbdb3e3db50ac8 (diff) |
cws tl80: #i110341# problems with spell check dialog fixed
Diffstat (limited to 'editeng')
-rwxr-xr-x[-rw-r--r--] | editeng/inc/editeng/editeng.hxx | 3 | ||||
-rw-r--r-- | editeng/inc/editeng/outliner.hxx | 2 | ||||
-rw-r--r-- | editeng/source/editeng/editeng.cxx | 14 | ||||
-rwxr-xr-x[-rw-r--r--] | editeng/source/editeng/impedit.hxx | 5 | ||||
-rwxr-xr-x[-rw-r--r--] | editeng/source/editeng/impedit4.cxx | 67 | ||||
-rw-r--r-- | editeng/source/outliner/outlin2.cxx | 4 |
6 files changed, 70 insertions, 25 deletions
diff --git a/editeng/inc/editeng/editeng.hxx b/editeng/inc/editeng/editeng.hxx index 3d9afded321f..84f4802e7b44 100644..100755 --- a/editeng/inc/editeng/editeng.hxx +++ b/editeng/inc/editeng/editeng.hxx @@ -232,6 +232,7 @@ public: ESelection WordRight( const ESelection& rSelection, USHORT nWordType ) const; ESelection CursorLeft( const ESelection& rSelection, USHORT nCharacterIteratorMode ) const; ESelection CursorRight( const ESelection& rSelection, USHORT nCharacterIteratorMode ) const; + ESelection SelectSentence( const ESelection& rCurSel ) const; void Clear(); void SetText( const String& rStr ); @@ -396,7 +397,7 @@ public: // put spell position to start of current sentence void PutSpellingToSentenceStart( EditView& rEditView ); //applies a changed sentence - void ApplyChangedSentence(EditView& rEditView, const ::svx::SpellPortions& rNewPortions, bool bIsGrammarChecking ); + void ApplyChangedSentence(EditView& rEditView, const ::svx::SpellPortions& rNewPortions, bool bRecheck ); //deinitialize sentence spelling void EndSpelling(); diff --git a/editeng/inc/editeng/outliner.hxx b/editeng/inc/editeng/outliner.hxx index 2d7afdb8a68c..09de5859db99 100644 --- a/editeng/inc/editeng/outliner.hxx +++ b/editeng/inc/editeng/outliner.hxx @@ -1017,7 +1017,7 @@ public: // put spell position to start of current sentence void PutSpellingToSentenceStart( EditView& rEditView ); //applies a changed sentence - void ApplyChangedSentence(EditView& rEditView, const ::svx::SpellPortions& rNewPortions, bool bIsGrammarChecking ); + void ApplyChangedSentence(EditView& rEditView, const ::svx::SpellPortions& rNewPortions, bool bRecheck ); void EndSpelling(); /** sets a link that is called at the beginning of a drag operation at an edit view */ diff --git a/editeng/source/editeng/editeng.cxx b/editeng/source/editeng/editeng.cxx index 212fb8ff9446..e22f2dacad47 100644 --- a/editeng/source/editeng/editeng.cxx +++ b/editeng/source/editeng/editeng.cxx @@ -812,6 +812,14 @@ ESelection EditEngine::CursorRight( const ESelection& rSelection, USHORT nCharac return pE->pImpEditEngine->CreateESel( aSel ); } +ESelection EditEngine::SelectSentence( const ESelection& rCurSel ) const +{ + EditEngine* pE = (EditEngine*)this; + EditSelection aCurSel( pE->pImpEditEngine->CreateSel( rCurSel ) ); + EditSelection aSentenceSel( pE->pImpEditEngine->SelectSentence( aCurSel ) ); + return pE->pImpEditEngine->CreateESel( aSentenceSel ); +} + sal_Bool EditEngine::PostKeyEvent( const KeyEvent& rKeyEvent, EditView* pEditView ) { DBG_CHKTHIS( EditEngine, 0 ); @@ -2195,7 +2203,7 @@ void EditEngine::EndSpelling() bool EditEngine::SpellSentence(EditView& rView, ::svx::SpellPortions& rToFill, bool bIsGrammarChecking ) { DBG_CHKTHIS( EditEngine, 0 ); - return pImpEditEngine->SpellSentence( rView, rToFill, bIsGrammarChecking ); + return pImpEditEngine->SpellSentence( rView, rToFill, bIsGrammarChecking ); } /*-- 08.09.2008 11:38:32--------------------------------------------------- @@ -2208,10 +2216,10 @@ void EditEngine::PutSpellingToSentenceStart( EditView& rEditView ) /*-- 13.10.2003 16:43:27--------------------------------------------------- -----------------------------------------------------------------------*/ -void EditEngine::ApplyChangedSentence(EditView& rEditView, const ::svx::SpellPortions& rNewPortions, bool bIsGrammarChecking ) +void EditEngine::ApplyChangedSentence(EditView& rEditView, const ::svx::SpellPortions& rNewPortions, bool bRecheck ) { DBG_CHKTHIS( EditEngine, 0 ); - pImpEditEngine->ApplyChangedSentence( rEditView, rNewPortions, bIsGrammarChecking ); + pImpEditEngine->ApplyChangedSentence( rEditView, rNewPortions, bRecheck ); } sal_Bool EditEngine::HasConvertibleTextPortion( LanguageType nLang ) diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx index 3bacfc949e3b..ede5acacc698 100644..100755 --- a/editeng/source/editeng/impedit.hxx +++ b/editeng/source/editeng/impedit.hxx @@ -164,6 +164,7 @@ struct SpellInfo EESpellState eState; EPaM aSpellStart; EPaM aSpellTo; + EditPaM aCurSentenceStart; sal_Bool bSpellToEnd; sal_Bool bMultipleDoc; ::svx::SpellPortions aLastSpellPortions; @@ -697,6 +698,8 @@ private: */ void ImplFillTextMarkingVector(const ::com::sun::star::lang::Locale& rLocale, EEngineData::TextMarkingVector& rTextMarkingVector, const String& rTxt, const USHORT nIdx, const USHORT nLen) const; + SpellInfo * CreateSpellInfo( const EditSelection &rSel, bool bMultipleDocs ); + protected: virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); @@ -953,7 +956,7 @@ public: //put spelling back to start of current sentence - needed after switch of grammar support void PutSpellingToSentenceStart( EditView& rEditView ); //applies a changed sentence - void ApplyChangedSentence(EditView& rEditView, const ::svx::SpellPortions& rNewPortions, bool bIsGrammarChecking ); + void ApplyChangedSentence(EditView& rEditView, const ::svx::SpellPortions& rNewPortions, bool bRecheck ); //deinitialize sentence spelling void EndSpelling(); //adds one or more portions of text to the SpellPortions depending on language changes diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx index c45c6faf2b6a..4f56faae8548 100644..100755 --- a/editeng/source/editeng/impedit4.cxx +++ b/editeng/source/editeng/impedit4.cxx @@ -1455,6 +1455,23 @@ Reference< XSpellChecker1 > ImpEditEngine::GetSpeller() return xSpeller; } + +SpellInfo * ImpEditEngine::CreateSpellInfo( const EditSelection &rSel, bool bMultipleDocs ) +{ + pSpellInfo = new SpellInfo; + pSpellInfo->bMultipleDoc = bMultipleDocs; + EditSelection aSentenceSel( SelectSentence( rSel ) ); +// pSpellInfo->aSpellStart = CreateEPaM( aSentenceSel.Min() ); +// pSpellInfo->aSpellTo = CreateEPaM( rSel.HasRange()? aSentenceSel.Max() : aSentenceSel.Min() ); + // always spell draw objects completely, startting at the top. + // (spelling in only a selection or not starting with the top requires + // further changes elsewehe to work properly) + pSpellInfo->aSpellStart = EPaM(); + pSpellInfo->aSpellTo = EPaM( EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND ); + return pSpellInfo; +} + + EESpellState ImpEditEngine::Spell( EditView* pEditView, sal_Bool bMultipleDoc ) { #ifdef SVX_LIGHT @@ -1475,9 +1492,7 @@ EESpellState ImpEditEngine::Spell( EditView* pEditView, sal_Bool bMultipleDoc ) } EditSelection aCurSel( pEditView->pImpEditView->GetEditSelection() ); - pSpellInfo = new SpellInfo; - pSpellInfo->bMultipleDoc = bMultipleDoc; - pSpellInfo->aSpellStart = CreateEPaM( SelectWord( aCurSel, ::com::sun::star::i18n::WordType::DICTIONARY_WORD ).Min() ); + pSpellInfo = CreateSpellInfo( aCurSel, bMultipleDoc ); sal_Bool bIsStart = sal_False; if ( bMultipleDoc ) @@ -1945,11 +1960,9 @@ void ImpEditEngine::EndSpelling() void ImpEditEngine::StartSpelling(EditView& rEditView, sal_Bool bMultipleDoc) { DBG_ASSERT(!pSpellInfo, "pSpellInfo already set?"); - pSpellInfo = new SpellInfo; - pSpellInfo->bMultipleDoc = bMultipleDoc; rEditView.pImpEditView->SetEditSelection( aEditDoc.GetStartPaM() ); EditSelection aCurSel( rEditView.pImpEditView->GetEditSelection() ); - pSpellInfo->aSpellStart = CreateEPaM( SelectWord( aCurSel, ::com::sun::star::i18n::WordType::DICTIONARY_WORD ).Min() ); + pSpellInfo = CreateSpellInfo( aCurSel, bMultipleDoc ); } /*-- 13.10.2003 16:43:27--------------------------------------------------- Search for the next wrong word within the given selection @@ -2002,33 +2015,31 @@ Reference< XSpellAlternatives > ImpEditEngine::ImpFindNextError(EditSelection& r /*-- 13.10.2003 16:43:27--------------------------------------------------- -----------------------------------------------------------------------*/ -bool ImpEditEngine::SpellSentence(EditView& rEditView, ::svx::SpellPortions& rToFill, bool /*bIsGrammarChecking*/ ) +bool ImpEditEngine::SpellSentence(EditView& rEditView, + ::svx::SpellPortions& rToFill, + bool /*bIsGrammarChecking*/ ) { #ifdef SVX_LIGHT #else bool bRet = false; + EditSelection aCurSel( rEditView.pImpEditView->GetEditSelection() ); //the pSpellInfo has to be created on demand if(!pSpellInfo) - { - pSpellInfo = new SpellInfo; - pSpellInfo->bMultipleDoc = sal_True; - rEditView.pImpEditView->SetEditSelection( aEditDoc.GetStartPaM() ); - EditSelection aCurSel( rEditView.pImpEditView->GetEditSelection() ); - pSpellInfo->aSpellStart = CreateEPaM( SelectWord( aCurSel, ::com::sun::star::i18n::WordType::DICTIONARY_WORD ).Min() ); - } + pSpellInfo = CreateSpellInfo( aCurSel, true ); + pSpellInfo->aCurSentenceStart = aCurSel.Min(); DBG_ASSERT( xSpeller.is(), "Kein Speller gesetzt!" ); pSpellInfo->aLastSpellPortions.clear(); pSpellInfo->aLastSpellContentSelections.clear(); rToFill.clear(); - EditSelection aCurSel( rEditView.pImpEditView->GetEditSelection() ); //if no selection previously exists the range is extended to the end of the object if(aCurSel.Min() == aCurSel.Max()) { ContentNode* pLastNode = aEditDoc.SaveGetObject( aEditDoc.Count()-1); aCurSel.Max() = EditPaM(pLastNode, pLastNode->Len()); } + // check for next error in aCurSel and set aCurSel to that one if any was found Reference< XSpellAlternatives > xAlt = ImpFindNextError(aCurSel); - if(xAlt.is()) + if (xAlt.is()) { bRet = true; //find the sentence boundaries @@ -2060,6 +2071,7 @@ bool ImpEditEngine::SpellSentence(EditView& rEditView, ::svx::SpellPortions& rTo aCurSel = aNextSel; } while( xAlt.is() ); + //set the selection to the end of the current sentence rEditView.pImpEditView->SetEditSelection(aSentencePaM.Max()); } @@ -2173,13 +2185,20 @@ void ImpEditEngine::AddPortionIterated( /*-- 13.10.2003 16:43:33--------------------------------------------------- -----------------------------------------------------------------------*/ -void ImpEditEngine::ApplyChangedSentence(EditView& rEditView, const ::svx::SpellPortions& rNewPortions, bool /*bIsGrammarChecking*/ ) +void ImpEditEngine::ApplyChangedSentence(EditView& rEditView, + const ::svx::SpellPortions& rNewPortions, + bool bRecheck ) { #ifdef SVX_LIGHT #else DBG_ASSERT(pSpellInfo, "pSpellInfo not initialized"); if(pSpellInfo) { + // get current paragraph length to calculate later on how the sentence length changed, + // in order to place the cursor at the end of the sentence again + EditSelection aOldSel( rEditView.pImpEditView->GetEditSelection() ); + xub_StrLen nOldLen = aOldSel.Max().GetNode()->Len(); + UndoActionStart( EDITUNDO_INSERT ); if(pSpellInfo->aLastSpellPortions.size() == rNewPortions.size()) { @@ -2266,6 +2285,20 @@ void ImpEditEngine::ApplyChangedSentence(EditView& rEditView, const ::svx::Spell } } UndoActionEnd( EDITUNDO_INSERT ); + + EditPaM aNext; + if (bRecheck) + aNext = pSpellInfo->aCurSentenceStart; + else + { + // restore cursor position to the end of the modified sentence. + // (This will define the continuation position for spell/grammar checking) + // First: check if the sentence/para length changed + sal_Int32 nDelta = rEditView.pImpEditView->GetEditSelection().Max().GetNode()->Len() - nOldLen; + xub_StrLen nEndOfSentence = aOldSel.Max().GetIndex() + nDelta; + aNext = EditPaM( aOldSel.Max().GetNode(), nEndOfSentence ); + } + rEditView.pImpEditView->SetEditSelection( aNext ); } FormatAndUpdate(); aEditDoc.SetModified(TRUE); diff --git a/editeng/source/outliner/outlin2.cxx b/editeng/source/outliner/outlin2.cxx index 1a49c087265a..81db53b3d474 100644 --- a/editeng/source/outliner/outlin2.cxx +++ b/editeng/source/outliner/outlin2.cxx @@ -807,7 +807,7 @@ void Outliner::PutSpellingToSentenceStart( EditView& rEditView ) /*-- 13.10.2003 16:56:25--------------------------------------------------- -----------------------------------------------------------------------*/ -void Outliner::ApplyChangedSentence(EditView& rEditView, const ::svx::SpellPortions& rNewPortions, bool bIsGrammarChecking ) +void Outliner::ApplyChangedSentence(EditView& rEditView, const ::svx::SpellPortions& rNewPortions, bool bRecheck ) { - pEditEngine->ApplyChangedSentence( rEditView, rNewPortions, bIsGrammarChecking ); + pEditEngine->ApplyChangedSentence( rEditView, rNewPortions, bRecheck ); } |