diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2010-09-29 16:20:12 -0400 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2010-09-29 16:23:00 -0400 |
commit | 8d56c285d42b5366d58c22dc1f1c3d1ea9cbaa77 (patch) | |
tree | 25135e6279fe9d35ec831d24ffd152fb5f83470a /editeng/source | |
parent | fc239df0fd5920f6f0136d33cf57f247332f06c6 (diff) |
Ported autocorrect-accidental-caps-lock-svx.diff from ooo-build.
Diffstat (limited to 'editeng/source')
-rw-r--r-- | editeng/source/editeng/editeng.cxx | 11 | ||||
-rwxr-xr-x | editeng/source/editeng/editview.cxx | 9 | ||||
-rwxr-xr-x | editeng/source/editeng/impedit.cxx | 4 | ||||
-rwxr-xr-x | editeng/source/editeng/impedit.hxx | 6 | ||||
-rwxr-xr-x | editeng/source/editeng/impedit2.cxx | 5 | ||||
-rw-r--r-- | editeng/source/misc/acorrcfg.cxx | 13 | ||||
-rw-r--r-- | editeng/source/misc/svxacorr.cxx | 61 | ||||
-rwxr-xr-x | editeng/source/outliner/outlvw.cxx | 4 |
8 files changed, 92 insertions, 21 deletions
diff --git a/editeng/source/editeng/editeng.cxx b/editeng/source/editeng/editeng.cxx index 8e4b2a4645a6..69a984997d1e 100644 --- a/editeng/source/editeng/editeng.cxx +++ b/editeng/source/editeng/editeng.cxx @@ -821,7 +821,7 @@ ESelection EditEngine::SelectSentence( const ESelection& rCurSel ) const return pE->pImpEditEngine->CreateESel( aSentenceSel ); } -sal_Bool EditEngine::PostKeyEvent( const KeyEvent& rKeyEvent, EditView* pEditView ) +sal_Bool EditEngine::PostKeyEvent( const KeyEvent& rKeyEvent, EditView* pEditView, Window* pFrameWin ) { DBG_CHKTHIS( EditEngine, 0 ); DBG_CHKOBJ( pEditView, EditView, 0 ); @@ -1081,7 +1081,7 @@ sal_Bool EditEngine::PostKeyEvent( const KeyEvent& rKeyEvent, EditView* pEditVie if ( bSel ) pImpEditEngine->UndoActionStart( EDITUNDO_INSERT ); if ( pImpEditEngine->GetStatus().DoAutoCorrect() ) - aCurSel = pImpEditEngine->AutoCorrect( aCurSel, 0, !pEditView->IsInsertMode() ); + aCurSel = pImpEditEngine->AutoCorrect( aCurSel, 0, !pEditView->IsInsertMode(), pFrameWin ); aCurSel = pImpEditEngine->InsertTab( aCurSel ); if ( bSel ) pImpEditEngine->UndoActionEnd( EDITUNDO_INSERT ); @@ -1102,7 +1102,7 @@ sal_Bool EditEngine::PostKeyEvent( const KeyEvent& rKeyEvent, EditView* pEditVie pImpEditEngine->UndoActionStart( EDITUNDO_INSERT ); if ( rKeyEvent.GetKeyCode().IsShift() ) { - aCurSel = pImpEditEngine->AutoCorrect( aCurSel, 0, !pEditView->IsInsertMode() ); + aCurSel = pImpEditEngine->AutoCorrect( aCurSel, 0, !pEditView->IsInsertMode(), pFrameWin ); aCurSel = pImpEditEngine->InsertLineBreak( aCurSel ); } else @@ -1110,7 +1110,7 @@ sal_Bool EditEngine::PostKeyEvent( const KeyEvent& rKeyEvent, EditView* pEditVie if ( !aAutoText.Len() ) { if ( pImpEditEngine->GetStatus().DoAutoCorrect() ) - aCurSel = pImpEditEngine->AutoCorrect( aCurSel, 0, !pEditView->IsInsertMode() ); + aCurSel = pImpEditEngine->AutoCorrect( aCurSel, 0, !pEditView->IsInsertMode(), pFrameWin ); aCurSel = pImpEditEngine->InsertParaBreak( aCurSel ); } else @@ -1158,7 +1158,8 @@ sal_Bool EditEngine::PostKeyEvent( const KeyEvent& rKeyEvent, EditView* pEditVie ( SvxAutoCorrect::IsAutoCorrectChar( nCharCode ) || pAutoCorrect->HasRunNext() ) ) { - aCurSel = pImpEditEngine->AutoCorrect( aCurSel, nCharCode, !pEditView->IsInsertMode() ); + aCurSel = pImpEditEngine->AutoCorrect( + aCurSel, nCharCode, !pEditView->IsInsertMode(), pFrameWin ); } else { diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx index 664512df414e..c9a5983edea0 100755 --- a/editeng/source/editeng/editview.cxx +++ b/editeng/source/editeng/editview.cxx @@ -60,6 +60,7 @@ #include <helpid.hrc> #include <i18npool/lang.h> #include <vcl/menu.hxx> +#include <vcl/window.hxx> #include <editeng/acorrcfg.hxx> #include <editeng/unolingu.hxx> #include <editeng/fontitem.hxx> @@ -419,11 +420,11 @@ void EditView::InsertText( const XubString& rStr, sal_Bool bSelect ) pImpEE->FormatAndUpdate( this ); } -sal_Bool EditView::PostKeyEvent( const KeyEvent& rKeyEvent ) +sal_Bool EditView::PostKeyEvent( const KeyEvent& rKeyEvent, Window* pFrameWin ) { DBG_CHKTHIS( EditView, 0 ); DBG_CHKOBJ( pImpEditView->pEditEngine, EditEngine, 0 ); - return pImpEditView->PostKeyEvent( rKeyEvent ); + return pImpEditView->PostKeyEvent( rKeyEvent, pFrameWin ); } sal_Bool EditView::MouseButtonUp( const MouseEvent& rMouseEvent ) @@ -920,7 +921,7 @@ sal_Bool EditView::MatchGroup() return sal_False; } -void EditView::CompleteAutoCorrect() +void EditView::CompleteAutoCorrect( Window* pFrameWin ) { DBG_CHKTHIS( EditView, 0 ); DBG_CHKOBJ( pImpEditView->pEditEngine, EditEngine, 0 ); @@ -930,7 +931,7 @@ void EditView::CompleteAutoCorrect() EditSelection aSel = pImpEditView->GetEditSelection(); aSel = PIMPEE->EndOfWord( aSel.Max() ); // MT 06/00: Why pass EditSelection to AutoCorrect, not EditPaM?! - aSel = PIMPEE->AutoCorrect( aSel, 0, !IsInsertMode() ); + aSel = PIMPEE->AutoCorrect( aSel, 0, !IsInsertMode(), pFrameWin ); pImpEditView->SetEditSelection( aSel ); if ( PIMPEE->IsModified() ) PIMPEE->FormatAndUpdate( this ); diff --git a/editeng/source/editeng/impedit.cxx b/editeng/source/editeng/impedit.cxx index 9ac7de8e2b7d..e0d8674da002 100755 --- a/editeng/source/editeng/impedit.cxx +++ b/editeng/source/editeng/impedit.cxx @@ -993,7 +993,7 @@ Pair ImpEditView::Scroll( long ndX, long ndY, BYTE nRangeCheck ) return Pair( nRealDiffX, nRealDiffY ); } -sal_Bool ImpEditView::PostKeyEvent( const KeyEvent& rKeyEvent ) +sal_Bool ImpEditView::PostKeyEvent( const KeyEvent& rKeyEvent, Window* pFrameWin ) { BOOL bDone = FALSE; @@ -1037,7 +1037,7 @@ sal_Bool ImpEditView::PostKeyEvent( const KeyEvent& rKeyEvent ) } if( !bDone ) - bDone = pEditEngine->PostKeyEvent( rKeyEvent, GetEditViewPtr() ); + bDone = pEditEngine->PostKeyEvent( rKeyEvent, GetEditViewPtr(), pFrameWin ); return bDone; } diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx index c8f5e2948665..77e068f8fa9a 100755 --- a/editeng/source/editeng/impedit.hxx +++ b/editeng/source/editeng/impedit.hxx @@ -92,6 +92,8 @@ class TextRanger; class SvKeyValueIterator; class SvxForbiddenCharactersTable; class SvtCTLOptions; +class Window; + #include <editeng/SpellPortions.hxx> #include <editeng/eedata.hxx> @@ -289,7 +291,7 @@ public: BOOL IsVertical() const; - BOOL PostKeyEvent( const KeyEvent& rKeyEvent ); + BOOL PostKeyEvent( const KeyEvent& rKeyEvent, Window* pFrameWin = NULL ); BOOL MouseButtonUp( const MouseEvent& rMouseEvent ); BOOL MouseButtonDown( const MouseEvent& rMouseEvent ); @@ -781,7 +783,7 @@ public: EditPaM DeleteSelected( EditSelection aEditSelection); EditPaM InsertText( const EditSelection& rCurEditSelection, sal_Unicode c, sal_Bool bOverwrite, sal_Bool bIsUserInput = sal_False ); EditPaM InsertText( EditSelection aCurEditSelection, const String& rStr ); - EditPaM AutoCorrect( const EditSelection& rCurEditSelection, sal_Unicode c, sal_Bool bOverwrite ); + EditPaM AutoCorrect( const EditSelection& rCurEditSelection, sal_Unicode c, bool bOverwrite, Window* pFrameWin = NULL ); EditPaM DeleteLeftOrRight( const EditSelection& rEditSelection, BYTE nMode, BYTE nDelMode = DELMODE_SIMPLE ); EditPaM InsertParaBreak( EditSelection aEditSelection ); EditPaM InsertLineBreak( EditSelection aEditSelection ); diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx index 148ca08816ae..56b610c14436 100755 --- a/editeng/source/editeng/impedit2.cxx +++ b/editeng/source/editeng/impedit2.cxx @@ -2576,7 +2576,8 @@ void ImpEditEngine::ImpRemoveParagraph( USHORT nPara ) } } -EditPaM ImpEditEngine::AutoCorrect( const EditSelection& rCurSel, xub_Unicode c, BOOL bOverwrite ) +EditPaM ImpEditEngine::AutoCorrect( const EditSelection& rCurSel, xub_Unicode c, + bool bOverwrite, Window* pFrameWin ) { EditSelection aSel( rCurSel ); #ifndef SVX_LIGHT @@ -2626,7 +2627,7 @@ EditPaM ImpEditEngine::AutoCorrect( const EditSelection& rCurSel, xub_Unicode c, ContentNode* pNode = aSel.Max().GetNode(); USHORT nIndex = aSel.Max().GetIndex(); EdtAutoCorrDoc aAuto( this, pNode, nIndex, c ); - pAutoCorrect->AutoCorrect( aAuto, *pNode, nIndex, c, !bOverwrite ); + pAutoCorrect->AutoCorrect( aAuto, *pNode, nIndex, c, !bOverwrite, pFrameWin ); aSel.Max().SetIndex( aAuto.GetCursor() ); // #i78661 since the SvxAutoCorrect object used here is diff --git a/editeng/source/misc/acorrcfg.cxx b/editeng/source/misc/acorrcfg.cxx index 966a0876fa30..39026344c859 100644 --- a/editeng/source/misc/acorrcfg.cxx +++ b/editeng/source/misc/acorrcfg.cxx @@ -118,9 +118,10 @@ Sequence<OUString> SvxBaseAutoCorrCfg::GetPropertyNames() "SingleQuoteAtEnd", // 13 "ReplaceDoubleQuote", // 14 "DoubleQuoteAtStart", // 15 - "DoubleQuoteAtEnd" // 16 + "DoubleQuoteAtEnd", // 16 + "CorrectAccidentalCapsLock" // 17 }; - const int nCount = 17; + const int nCount = 18; Sequence<OUString> aNames(nCount); OUString* pNames = aNames.getArray(); for(int i = 0; i < nCount; i++) @@ -220,6 +221,10 @@ void SvxBaseAutoCorrCfg::Load(sal_Bool bInit) rParent.pAutoCorrect->SetEndDoubleQuote( sal::static_int_cast< sal_Unicode >( nTemp ) ); break;//"DoubleQuoteAtEnd" + case 17: + if(*(sal_Bool*)pValues[nProp].getValue()) + nFlags |= CorrectCapsLock; + break;//"CorrectAccidentalCapsLock" } } } @@ -324,6 +329,10 @@ void SvxBaseAutoCorrCfg::Commit() case 16: pValues[nProp] <<= (sal_Int32) rParent.pAutoCorrect->GetEndDoubleQuote(); break;//"DoubleQuoteAtEnd" + case 17: + bVal = 0 != (nFlags & CorrectCapsLock); + pValues[nProp].setValue(&bVal, rType); + break;//"CorrectAccidentalCapsLock" } } PutProperties(aNames, aValues); diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx index bcb70a483abb..d9a4bac1b717 100644 --- a/editeng/source/misc/svxacorr.cxx +++ b/editeng/source/misc/svxacorr.cxx @@ -60,6 +60,7 @@ #include <editeng/escpitem.hxx> #include <editeng/svxacorr.hxx> #include <editeng/unolingu.hxx> +#include "vcl/window.hxx" #include <helpid.hrc> #include <comphelper/processfactory.hxx> #include <com/sun/star/xml/sax/InputSource.hpp> @@ -336,7 +337,8 @@ long SvxAutoCorrect::GetDefaultFlags() | SetINetAttr | ChgQuotes | SaveWordCplSttLst - | SaveWordWrdSttLst; + | SaveWordWrdSttLst + | CorrectCapsLock; LanguageType eLang = GetAppLang(); switch( eLang ) { @@ -1073,6 +1075,49 @@ BOOL SvxAutoCorrect::FnCptlSttSntnc( SvxAutoCorrDoc& rDoc, return bRet; } + +bool SvxAutoCorrect::FnCorrectCapsLock( SvxAutoCorrDoc& rDoc, const String& rTxt, + xub_StrLen nSttPos, xub_StrLen nEndPos, + LanguageType eLang ) +{ + if (nEndPos - nSttPos < 2) + // string must be at least 2-character long. + return false; + + CharClass& rCC = GetCharClass( eLang ); + + // Check the first 2 letters. + if ( !IsLowerLetter(rCC.getCharacterType(rTxt, nSttPos)) ) + return false; + + if ( !IsUpperLetter(rCC.getCharacterType(rTxt, nSttPos+1)) ) + return false; + + String aConverted; + aConverted.Append( rCC.upper(rTxt.GetChar(nSttPos)) ); + aConverted.Append( rCC.lower(rTxt.GetChar(nSttPos+1)) ); + + for (xub_StrLen i = nSttPos+2; i < nEndPos; ++i) + { + if ( IsLowerLetter(rCC.getCharacterType(rTxt, i)) ) + // A lowercase letter disqualifies the whole text. + return false; + + if ( IsUpperLetter(rCC.getCharacterType(rTxt, i)) ) + // Another uppercase letter. Convert it. + aConverted.Append( rCC.lower(rTxt.GetChar(i)) ); + else + // This is not an alphabetic letter. Leave it as-is. + aConverted.Append(rTxt.GetChar(i)); + } + + // Replace the word. + rDoc.Delete(nSttPos, nEndPos); + rDoc.Insert(nSttPos, aConverted); + + return true; +} + //The method below is renamed from _GetQuote to GetQuote by BerryJia for Bug95846 Time:2002-8-13 15:50 sal_Unicode SvxAutoCorrect::GetQuote( sal_Unicode cInsChar, BOOL bSttQuote, LanguageType eLang ) const @@ -1186,7 +1231,7 @@ String SvxAutoCorrect::GetQuote( SvxAutoCorrDoc& rDoc, xub_StrLen nInsPos, ULONG SvxAutoCorrect::AutoCorrect( SvxAutoCorrDoc& rDoc, const String& rTxt, xub_StrLen nInsPos, sal_Unicode cChar, - BOOL bInsert ) + BOOL bInsert, Window* pFrameWin ) { ULONG nRet = 0; bool bIsNextRun = bRunNext; @@ -1364,7 +1409,19 @@ ULONG SvxAutoCorrect::AutoCorrect( SvxAutoCorrDoc& rDoc, const String& rTxt, ; else { + bool bLockKeyOn = pFrameWin && (pFrameWin->GetIndicatorState() & INDICATOR_CAPSLOCK); + nRet = 0; + if ( bLockKeyOn && IsAutoCorrFlag( CorrectCapsLock ) && + FnCorrectCapsLock( rDoc, rTxt, nCapLttrPos, nInsPos, eLang ) ) + { + // Correct accidental use of cAPS LOCK key (do this only when + // the caps or shift lock key is pressed). Turn off the caps + // lock afterwords. + nRet |= CorrectCapsLock; + pFrameWin->SimulateKeyPress( KEY_CAPSLOCK ); + } + // Grossbuchstabe am Satz-Anfang ?? if( IsAutoCorrFlag( CptlSttSntnc ) && FnCptlSttSntnc( rDoc, rTxt, TRUE, nCapLttrPos, nInsPos, eLang ) ) diff --git a/editeng/source/outliner/outlvw.cxx b/editeng/source/outliner/outlvw.cxx index e2a1fabea0ba..8bc047a561a2 100755 --- a/editeng/source/outliner/outlvw.cxx +++ b/editeng/source/outliner/outlvw.cxx @@ -103,7 +103,7 @@ void OutlinerView::Paint( const Rectangle& rRect ) pEditView->Paint( rRect ); } -BOOL OutlinerView::PostKeyEvent( const KeyEvent& rKEvt ) +BOOL OutlinerView::PostKeyEvent( const KeyEvent& rKEvt, Window* pFrameWin ) { DBG_CHKTHIS( OutlinerView, 0 ); @@ -268,7 +268,7 @@ BOOL OutlinerView::PostKeyEvent( const KeyEvent& rKEvt ) } } - return bKeyProcessed ? TRUE : pEditView->PostKeyEvent( rKEvt ); + return bKeyProcessed ? TRUE : pEditView->PostKeyEvent( rKEvt, pFrameWin ); } |