Kaydet (Commit) f3e70f0f authored tarafından Eike Rathke's avatar Eike Rathke

make that a proper static method EditView::CheckLanguage()

Change-Id: I08c1af6813314b4881aafdd7f3f98a7629d5cf76
üst cabde845
...@@ -60,7 +60,12 @@ namespace sun { ...@@ -60,7 +60,12 @@ namespace sun {
namespace star { namespace star {
namespace datatransfer { namespace datatransfer {
class XTransferable; class XTransferable;
}}}} }
namespace linguistic2 {
class XSpellChecker1;
class XLanguageGuessing;
}
}}}
class EDITENG_DLLPUBLIC EditView class EDITENG_DLLPUBLIC EditView
{ {
...@@ -215,6 +220,26 @@ public: ...@@ -215,6 +220,26 @@ public:
String GetSurroundingText() const; String GetSurroundingText() const;
Selection GetSurroundingTextSelection() const; Selection GetSurroundingTextSelection() const;
/** Tries to determine the language of 'rText', returning a matching known
locale if possible, or a fallback, or LANGUAGE_NONE if nothing found or
matched.
@param bIsParaText
If TRUE, rText is a paragraph and the language is obtained by
passing the text to xLangGuess.
IF FALSE, a language match is tried for, in order,
1. the default document language (non-CTL, non-CJK, aka LATIN)
2. the UI language (Tools->Options->LanguageSettings->Languages User Interface)
3. the locale (Tools->Options->LanguageSettings->Languages Locale)
4. en-US
If nothing matched, LANGUAGE_NONE is returned.
*/
static LanguageType CheckLanguage(
const OUString &rText,
com::sun::star::uno::Reference< com::sun::star::linguistic2::XSpellChecker1 > xSpell,
com::sun::star::uno::Reference< com::sun::star::linguistic2::XLanguageGuessing > xLangGuess,
bool bIsParaText );
}; };
#endif // _MyEDITVIEW_HXX #endif // _MyEDITVIEW_HXX
......
...@@ -68,18 +68,17 @@ ...@@ -68,18 +68,17 @@
using namespace com::sun::star; using namespace com::sun::star;
using namespace com::sun::star::uno; using namespace com::sun::star::uno;
using namespace com::sun::star::beans; using namespace com::sun::star::beans;
using namespace com::sun::star::linguistic2;
DBG_NAME( EditView ) DBG_NAME( EditView )
// From SW => Create common method // static
static LanguageType lcl_CheckLanguage( LanguageType EditView::CheckLanguage(
const OUString &rText, const OUString &rText,
Reference< XSpellChecker1 > xSpell, Reference< linguistic2::XSpellChecker1 > xSpell,
Reference< linguistic2::XLanguageGuessing > xLangGuess, Reference< linguistic2::XLanguageGuessing > xLangGuess,
sal_Bool bIsParaText ) bool bIsParaText )
{ {
LanguageType nLang = LANGUAGE_NONE; LanguageType nLang = LANGUAGE_NONE;
if (bIsParaText) // check longer texts with language-guessing... if (bIsParaText) // check longer texts with language-guessing...
...@@ -889,7 +888,7 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link* pCallBack ) ...@@ -889,7 +888,7 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link* pCallBack )
Point aPos ( pImpEditView->GetWindow()->PixelToLogic( rPosPixel ) ); Point aPos ( pImpEditView->GetWindow()->PixelToLogic( rPosPixel ) );
aPos = pImpEditView->GetDocPos( aPos ); aPos = pImpEditView->GetDocPos( aPos );
EditPaM aPaM = pImpEditView->pEditEngine->GetPaM(aPos, false); EditPaM aPaM = pImpEditView->pEditEngine->GetPaM(aPos, false);
Reference< XSpellChecker1 > xSpeller( PIMPEE->GetSpeller() ); Reference< linguistic2::XSpellChecker1 > xSpeller( PIMPEE->GetSpeller() );
ESelection aOldSel = GetSelection(); ESelection aOldSel = GetSelection();
if ( xSpeller.is() && pImpEditView->IsWrongSpelledWord( aPaM, sal_True ) ) if ( xSpeller.is() && pImpEditView->IsWrongSpelledWord( aPaM, sal_True ) )
{ {
...@@ -920,10 +919,10 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link* pCallBack ) ...@@ -920,10 +919,10 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link* pCallBack )
rVal.Value <<= (sal_Int16) 7; rVal.Value <<= (sal_Int16) 7;
// //
// Are there any replace suggestions? // Are there any replace suggestions?
Reference< XSpellAlternatives > xSpellAlt = Reference< linguistic2::XSpellAlternatives > xSpellAlt =
xSpeller->spell( aSelected, PIMPEE->GetLanguage( aPaM2 ), aPropVals ); xSpeller->spell( aSelected, PIMPEE->GetLanguage( aPaM2 ), aPropVals );
Reference< XLanguageGuessing > xLangGuesser( EE_DLL().GetGlobalData()->GetLanguageGuesser() ); Reference< linguistic2::XLanguageGuessing > xLangGuesser( EE_DLL().GetGlobalData()->GetLanguageGuesser() );
// check if text might belong to a different language... // check if text might belong to a different language...
LanguageType nGuessLangWord = LANGUAGE_NONE; LanguageType nGuessLangWord = LANGUAGE_NONE;
...@@ -941,8 +940,8 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link* pCallBack ) ...@@ -941,8 +940,8 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link* pCallBack )
OSL_FAIL( "content node is NULL" ); OSL_FAIL( "content node is NULL" );
} }
nGuessLangWord = lcl_CheckLanguage( xSpellAlt->getWord(), xSpeller, xLangGuesser, sal_False ); nGuessLangWord = CheckLanguage( xSpellAlt->getWord(), xSpeller, xLangGuesser, false );
nGuessLangPara = lcl_CheckLanguage( aParaText, xSpeller, xLangGuesser, sal_True ); nGuessLangPara = CheckLanguage( aParaText, xSpeller, xLangGuesser, true );
} }
if (nGuessLangWord != LANGUAGE_NONE || nGuessLangPara != LANGUAGE_NONE) if (nGuessLangWord != LANGUAGE_NONE || nGuessLangPara != LANGUAGE_NONE)
{ {
...@@ -993,11 +992,11 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link* pCallBack ) ...@@ -993,11 +992,11 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link* pCallBack )
SvtLinguConfig aCfg; SvtLinguConfig aCfg;
Reference< XSearchableDictionaryList > xDicList( SvxGetDictionaryList() ); Reference< linguistic2::XSearchableDictionaryList > xDicList( SvxGetDictionaryList() );
Sequence< Reference< XDictionary > > aDics; Sequence< Reference< linguistic2::XDictionary > > aDics;
if (xDicList.is()) if (xDicList.is())
{ {
const Reference< XDictionary > *pDic = NULL; const Reference< linguistic2::XDictionary > *pDic = NULL;
// add the default positive dictionary to dic-list (if not already done). // add the default positive dictionary to dic-list (if not already done).
// This is to ensure that there is at least one dictionary to which // This is to ensure that there is at least one dictionary to which
// words could be added. // words could be added.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment