[Libreoffice-commits] core.git: 4 commits - editeng/inc editeng/source sw/source
Eike Rathke
erack at redhat.com
Fri Apr 12 11:45:22 PDT 2013
editeng/inc/editeng/editview.hxx | 27 ++++++++++
editeng/source/editeng/editview.cxx | 56 ++++++++++------------
sw/source/ui/lingu/olmenu.cxx | 91 +-----------------------------------
3 files changed, 57 insertions(+), 117 deletions(-)
New commits:
commit b88e5350ebbe5365cfd768aba0f42bc439d60898
Author: Eike Rathke <erack at redhat.com>
Date: Fri Apr 12 20:40:05 2013 +0200
use EditView::CheckLanguage() instead of duplicated code
Change-Id: I0ff75f1dc084f426846ac4f67db85a5d932d7bee
diff --git a/sw/source/ui/lingu/olmenu.cxx b/sw/source/ui/lingu/olmenu.cxx
index 4cd00b2..a444910 100644
--- a/sw/source/ui/lingu/olmenu.cxx
+++ b/sw/source/ui/lingu/olmenu.cxx
@@ -51,6 +51,7 @@
#include <editeng/splwrap.hxx>
#include <editeng/brushitem.hxx>
#include <editeng/unolingu.hxx>
+#include <editeng/editview.hxx>
#include <i18nlangtag/mslangid.hxx>
#include <i18nlangtag/languagetag.hxx>
#include <linguistic/lngprops.hxx>
@@ -98,90 +99,6 @@ using namespace ::com::sun::star;
extern void sw_CharDialog( SwWrtShell &rWrtSh, bool bUseDialog, sal_uInt16 nSlot,const SfxItemSet *pArgs, SfxRequest *pReq );
-
-
-// tries to determine the language of 'rText'
-//
-static LanguageType lcl_CheckLanguage(
- const OUString &rText,
- uno::Reference< linguistic2::XSpellChecker1 > xSpell,
- uno::Reference< linguistic2::XLanguageGuessing > xLangGuess,
- bool bIsParaText )
-{
- LanguageType nLang = LANGUAGE_NONE;
- if (bIsParaText) // check longer texts with language-guessing...
- {
- if (!xLangGuess.is())
- return nLang;
-
- lang::Locale aLocale( xLangGuess->guessPrimaryLanguage( rText, 0, rText.getLength()) );
-
- // get language as from "Tools/Options - Language Settings - Languages: Locale setting"
- LanguageType nTmpLang = Application::GetSettings().GetLanguageTag().getLanguageType();
-
- // if the result from language guessing does not provide a 'Country' part
- // try to get it by looking up the locale setting of the office.
- /* FIXME-BCP47: handle language tags */
- if (aLocale.Country.isEmpty())
- {
- lang::Locale aTmpLocale = LanguageTag( nTmpLang ).getLocale();
- if (aTmpLocale.Language == aLocale.Language)
- nLang = nTmpLang;
- }
- if (nLang == LANGUAGE_NONE) // language not found by looking up the system language...
- nLang = LanguageTag( aLocale ).makeFallback().getLanguageType();
- if (nLang == LANGUAGE_SYSTEM)
- nLang = nTmpLang;
- if (nLang == LANGUAGE_DONTKNOW)
- nLang = LANGUAGE_NONE;
- }
- else // check single word
- {
- if (!xSpell.is())
- return nLang;
-
- //
- // build list of languages to check
- //
- LanguageType aLangList[4];
- const AllSettings& rSettings = Application::GetSettings();
- SvtLinguOptions aLinguOpt;
- SvtLinguConfig().GetOptions( aLinguOpt );
- // The default document language from "Tools/Options - Language Settings - Languages: Western"
- aLangList[0] = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN);
- // The one from "Tools/Options - Language Settings - Languages: User interface"
- aLangList[1] = rSettings.GetUILanguageTag().getLanguageType();
- // The one from "Tools/Options - Language Settings - Languages: Locale setting"
- aLangList[2] = rSettings.GetLanguageTag().getLanguageType();
- // en-US
- aLangList[3] = LANGUAGE_ENGLISH_US;
-#if OSL_DEBUG_LEVEL > 1
- lang::Locale a0( LanguageTag( aLangList[0] ).getLocale() );
- lang::Locale a1( LanguageTag( aLangList[1] ).getLocale() );
- lang::Locale a2( LanguageTag( aLangList[2] ).getLocale() );
- lang::Locale a3( LanguageTag( aLangList[3] ).getLocale() );
-#endif
-
- sal_Int32 nCount = SAL_N_ELEMENTS(aLangList);
- for (sal_Int32 i = 0; i < nCount; i++)
- {
- sal_Int16 nTmpLang = aLangList[i];
- if (nTmpLang != LANGUAGE_NONE && nTmpLang != LANGUAGE_DONTKNOW)
- {
- if (xSpell->hasLanguage( nTmpLang ) &&
- xSpell->isValid( rText, nTmpLang, uno::Sequence< beans::PropertyValue >() ))
- {
- nLang = nTmpLang;
- break;
- }
- }
- }
- }
-
- return nLang;
-}
-
-
/// @returns : the language for the selected text that is set for the
/// specified attribute (script type).
/// If there are more than one languages used LANGUAGE_DONTKNOW will be returned.
@@ -443,8 +360,8 @@ SwSpellPopup::SwSpellPopup(
nGuessLangPara = LANGUAGE_NONE;
if (xSpellAlt.is() && xLG.is())
{
- nGuessLangWord = lcl_CheckLanguage( xSpellAlt->getWord(), ::GetSpellChecker(), xLG, false );
- nGuessLangPara = lcl_CheckLanguage( rParaText, ::GetSpellChecker(), xLG, true );
+ nGuessLangWord = EditView::CheckLanguage( xSpellAlt->getWord(), ::GetSpellChecker(), xLG, false );
+ nGuessLangPara = EditView::CheckLanguage( rParaText, ::GetSpellChecker(), xLG, true );
}
if (nGuessLangWord != LANGUAGE_NONE || nGuessLangPara != LANGUAGE_NONE)
{
@@ -652,7 +569,7 @@ aInfo16( SW_RES(IMG_INFO_16) )
nGuessLangPara = LANGUAGE_NONE;
if (xLG.is())
{
- nGuessLangPara = lcl_CheckLanguage( rParaText, ::GetSpellChecker(), xLG, true );
+ nGuessLangPara = EditView::CheckLanguage( rParaText, ::GetSpellChecker(), xLG, true );
}
if (nGuessLangWord != LANGUAGE_NONE || nGuessLangPara != LANGUAGE_NONE)
{
commit a324ad1ab6bb3b8cd36a0b8f4f6c372cd3ca74af
Author: Eike Rathke <erack at redhat.com>
Date: Fri Apr 12 20:39:07 2013 +0200
resolveSystemLanguageByScriptType in case not set
Change-Id: I45582ba27579413140d536fdf0106edbef8dc4a7
diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx
index f243354..4bc4b7b 100644
--- a/editeng/source/editeng/editview.cxx
+++ b/editeng/source/editeng/editview.cxx
@@ -118,7 +118,8 @@ LanguageType EditView::CheckLanguage(
SvtLinguOptions aLinguOpt;
SvtLinguConfig().GetOptions( aLinguOpt );
// The default document language from "Tools/Options - Language Settings - Languages: Western"
- aLangList[0] = aLinguOpt.nDefaultLanguage;
+ aLangList[0] = MsLangId::resolveSystemLanguageByScriptType( aLinguOpt.nDefaultLanguage,
+ ::com::sun::star::i18n::ScriptType::LATIN);
// The one from "Tools/Options - Language Settings - Languages: User interface"
aLangList[1] = rSettings.GetUILanguageTag().getLanguageType();
// The one from "Tools/Options - Language Settings - Languages: Locale setting"
commit f3e70f0f9ced15917bb3d91f0653952031e250ba
Author: Eike Rathke <erack at redhat.com>
Date: Fri Apr 12 20:01:06 2013 +0200
make that a proper static method EditView::CheckLanguage()
Change-Id: I08c1af6813314b4881aafdd7f3f98a7629d5cf76
diff --git a/editeng/inc/editeng/editview.hxx b/editeng/inc/editeng/editview.hxx
index f3cad0e..a2f5ce8 100644
--- a/editeng/inc/editeng/editview.hxx
+++ b/editeng/inc/editeng/editview.hxx
@@ -60,7 +60,12 @@ namespace sun {
namespace star {
namespace datatransfer {
class XTransferable;
-}}}}
+}
+namespace linguistic2 {
+ class XSpellChecker1;
+ class XLanguageGuessing;
+}
+}}}
class EDITENG_DLLPUBLIC EditView
{
@@ -215,6 +220,26 @@ public:
String GetSurroundingText() 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
diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx
index b4d6652..f243354 100644
--- a/editeng/source/editeng/editview.cxx
+++ b/editeng/source/editeng/editview.cxx
@@ -68,18 +68,17 @@
using namespace com::sun::star;
using namespace com::sun::star::uno;
using namespace com::sun::star::beans;
-using namespace com::sun::star::linguistic2;
DBG_NAME( EditView )
-// From SW => Create common method
-static LanguageType lcl_CheckLanguage(
- const OUString &rText,
- Reference< XSpellChecker1 > xSpell,
- Reference< linguistic2::XLanguageGuessing > xLangGuess,
- sal_Bool bIsParaText )
+// static
+LanguageType EditView::CheckLanguage(
+ const OUString &rText,
+ Reference< linguistic2::XSpellChecker1 > xSpell,
+ Reference< linguistic2::XLanguageGuessing > xLangGuess,
+ bool bIsParaText )
{
LanguageType nLang = LANGUAGE_NONE;
if (bIsParaText) // check longer texts with language-guessing...
@@ -889,7 +888,7 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link* pCallBack )
Point aPos ( pImpEditView->GetWindow()->PixelToLogic( rPosPixel ) );
aPos = pImpEditView->GetDocPos( aPos );
EditPaM aPaM = pImpEditView->pEditEngine->GetPaM(aPos, false);
- Reference< XSpellChecker1 > xSpeller( PIMPEE->GetSpeller() );
+ Reference< linguistic2::XSpellChecker1 > xSpeller( PIMPEE->GetSpeller() );
ESelection aOldSel = GetSelection();
if ( xSpeller.is() && pImpEditView->IsWrongSpelledWord( aPaM, sal_True ) )
{
@@ -920,10 +919,10 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link* pCallBack )
rVal.Value <<= (sal_Int16) 7;
//
// Are there any replace suggestions?
- Reference< XSpellAlternatives > xSpellAlt =
+ Reference< linguistic2::XSpellAlternatives > xSpellAlt =
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...
LanguageType nGuessLangWord = LANGUAGE_NONE;
@@ -941,8 +940,8 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link* pCallBack )
OSL_FAIL( "content node is NULL" );
}
- nGuessLangWord = lcl_CheckLanguage( xSpellAlt->getWord(), xSpeller, xLangGuesser, sal_False );
- nGuessLangPara = lcl_CheckLanguage( aParaText, xSpeller, xLangGuesser, sal_True );
+ nGuessLangWord = CheckLanguage( xSpellAlt->getWord(), xSpeller, xLangGuesser, false );
+ nGuessLangPara = CheckLanguage( aParaText, xSpeller, xLangGuesser, true );
}
if (nGuessLangWord != LANGUAGE_NONE || nGuessLangPara != LANGUAGE_NONE)
{
@@ -993,11 +992,11 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link* pCallBack )
SvtLinguConfig aCfg;
- Reference< XSearchableDictionaryList > xDicList( SvxGetDictionaryList() );
- Sequence< Reference< XDictionary > > aDics;
+ Reference< linguistic2::XSearchableDictionaryList > xDicList( SvxGetDictionaryList() );
+ Sequence< Reference< linguistic2::XDictionary > > aDics;
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).
// This is to ensure that there is at least one dictionary to which
// words could be added.
commit cabde84509d0644258b3d5ccb8c7022e28f505bf
Author: Eike Rathke <erack at redhat.com>
Date: Fri Apr 12 19:41:14 2013 +0200
use proper language tag fallback for language guesser result
Change-Id: Icd912361ebca0e618bc76fa7017039cc116bef40
diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx
index 8e10abb..b4d6652 100644
--- a/editeng/source/editeng/editview.cxx
+++ b/editeng/source/editeng/editview.cxx
@@ -87,24 +87,22 @@ static LanguageType lcl_CheckLanguage(
if (!xLangGuess.is())
return nLang;
- lang::Locale aLocale( xLangGuess->guessPrimaryLanguage( rText, 0, rText.getLength()) );
+ LanguageTag aGuessTag( xLangGuess->guessPrimaryLanguage( rText, 0, rText.getLength()) );
- // get language as from "Tools/Options - Language Settings - Languages: Locale setting"
- LanguageType nTmpLang = Application::GetSettings().GetLanguageTag().getLanguageType();
-
- // if the result from language guessing does not provide a 'Country' part
- // try to get it by looking up the locale setting of the office.
- /* FIXME-BCP47: handle language tags */
- if ( aLocale.Country.isEmpty( ) )
+ // If the result from language guessing does not provide a 'Country'
+ // part, try to get it by looking up the locale setting of the office,
+ // "Tools/Options - Language Settings - Languages: Locale setting", if
+ // the language matches.
+ if ( aGuessTag.getCountry().isEmpty() )
{
- lang::Locale aTmpLocale = LanguageTag( nTmpLang ).getLocale();
- if (aTmpLocale.Language == aLocale.Language)
- nLang = nTmpLang;
+ const LanguageTag& rAppLocaleTag = Application::GetSettings().GetLanguageTag();
+ if (rAppLocaleTag.getLanguage() == aGuessTag.getLanguage())
+ nLang = rAppLocaleTag.getLanguageType();
}
if (nLang == LANGUAGE_NONE) // language not found by looking up the sytem language...
- nLang = LanguageTag( aLocale ).makeFallback().getLanguageType();
+ nLang = aGuessTag.makeFallback().getLanguageType(); // best known locale match
if (nLang == LANGUAGE_SYSTEM)
- nLang = nTmpLang;
+ nLang = Application::GetSettings().GetLanguageTag().getLanguageType();
if (nLang == LANGUAGE_DONTKNOW)
nLang = LANGUAGE_NONE;
}
More information about the Libreoffice-commits
mailing list