diff options
author | Thomas Lange <tl@openoffice.org> | 2001-03-22 07:28:26 +0000 |
---|---|---|
committer | Thomas Lange <tl@openoffice.org> | 2001-03-22 07:28:26 +0000 |
commit | 6ca31a07142a7d86d7044ad4b120f306e62ae78a (patch) | |
tree | a018e8aa1c3b5a81c6e4b9de20722aeecbb4fd49 /svx/source/dialog/langbox.cxx | |
parent | dc95a50ae03cad5e2331867791975f510e6e433f (diff) |
constructors modified/added, SetLanguageList new
Diffstat (limited to 'svx/source/dialog/langbox.cxx')
-rw-r--r-- | svx/source/dialog/langbox.cxx | 240 |
1 files changed, 229 insertions, 11 deletions
diff --git a/svx/source/dialog/langbox.cxx b/svx/source/dialog/langbox.cxx index 00391c59b2f2..1183f2f13b4d 100644 --- a/svx/source/dialog/langbox.cxx +++ b/svx/source/dialog/langbox.cxx @@ -2,9 +2,9 @@ * * $RCSfile: langbox.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: pb $ $Date: 2000-11-24 10:22:55 $ + * last change: $Author: tl $ $Date: 2001-03-22 08:28:26 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -61,18 +61,114 @@ // include --------------------------------------------------------------- +#ifndef _COM_SUN_STAR_LINGUISTIC2_XLINGUSERVICEMANAGER_HDL_ +#include <com/sun/star/linguistic2/XLinguServiceManager.hdl> +#endif +#ifndef _LINGUISTIC_MISC_HXX_ +#include <linguistic/misc.hxx> +#endif +#ifndef _RTL_USTRING_HXX_ +#include<rtl/ustring.hxx> +#endif + #ifndef _SHL_HXX #include <tools/shl.hxx> #endif +#ifndef _ISOLANG_HXX +#include <tools/isolang.hxx> +#endif #pragma hdrstop +#ifndef _SVX_SCRIPTTYPEITEM_HXX +#include <scripttypeitem.hxx> +#endif +#ifndef _UNO_LINGU_HXX +#include <unolingu.hxx> +#endif +#ifndef _SVX_LANGTAB_HXX +#include <langtab.hxx> +#endif #include "langbox.hxx" #include "langtab.hxx" #include "dialmgr.hxx" #include "dialogs.hrc" #include "unolingu.hxx" +using namespace ::rtl; using namespace ::com::sun::star::util; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::linguistic2; +using namespace ::com::sun::star::uno; + +#define A2OU(x) OUString::createFromAscii( x ) + +//======================================================================== +// list of languages for forbidden chars +//======================================================================== + +static const LanguageType aForbiddenCharLang[] = +{ + LANGUAGE_CHINESE_TRADITIONAL, + LANGUAGE_CHINESE_SIMPLIFIED, + LANGUAGE_JAPANESE, + LANGUAGE_KOREAN +}; + +static const int nForbiddenCharLang = sizeof( aForbiddenCharLang ) / sizeof( aForbiddenCharLang[0] ); + + +static BOOL lcl_HasLanguage( const LanguageType *pLang, int nCount, LanguageType nLang ) +{ + int i = -1; + if (pLang && nCount > 0) + { + for (i = 0; i < nCount; ++i ) + { + if (pLang[i] == nLang) + break; + } + } + return i >= 0 && i < nCount; +} + +//======================================================================== +// misc local helper functions +//======================================================================== + + + +static Sequence< INT16 > lcl_LocaleSeqToLangSeq( Sequence< Locale > &rSeq ) +{ + const Locale *pLocale = rSeq.getConstArray(); + INT32 nCount = rSeq.getLength(); + + Sequence< INT16 > aLangs( nCount ); + INT16 *pLang = aLangs.getArray(); + for (INT32 i = 0; i < nCount; ++i) + { + pLang[i] = SvxLocaleToLanguage( pLocale[i] ); + + } + + return aLangs; +} + + +static BOOL lcl_SeqHasLang( const Sequence< INT16 > & rLangSeq, INT16 nLang ) +{ + INT32 i = -1; + INT32 nLen = rLangSeq.getLength(); + if (nLen) + { + const INT16 *pLang = rLangSeq.getConstArray(); + for (i = 0; i < nLen; ++i) + { + if (nLang == pLang[i]) + break; + } + } + return i >= 0 && i < nLen; +} //======================================================================== // class SvxLanguageBox @@ -109,26 +205,61 @@ SvxLanguageBox::SvxLanguageBox( Window* pParent, const ResId& rResId, BOOL bChec ListBox( pParent, rResId ), m_bWithCheckmark( bCheck ) - { m_pLangTable = new SvxLanguageTable; m_aNotCheckedImage = Image( SVX_RES( RID_SVXIMG_NOTCHECKED ) ); m_aCheckedImage = Image( SVX_RES( RID_SVXIMG_CHECKED ) ); + m_aAllString = String( SVX_RESSTR( RID_SVXSTR_LANGUAGE_ALL ) ); + m_nLangList = LANG_LIST_EMPTY; + m_bHasLangNone = FALSE; + m_bLangNoneIsLangAll = FALSE; + + // display entries sorted + SetStyle( GetStyle() | WB_SORT ); if ( m_bWithCheckmark ) { - const USHORT nCount = International::GetAvailableFormatCount(); + SvxLanguageTable aLangTable; + const USHORT nCount = aLangTable.GetEntryCount(); for ( USHORT i = 0; i < nCount; i++ ) { - LanguageType eLngType = International::GetAvailableFormat( i ); - if ( eLngType != LANGUAGE_SYSTEM ) - InsertLanguage( eLngType ); + LanguageType nLangType = aLangTable.GetTypeAtIndex( i ); + + BOOL bInsert = TRUE; + if ((LANGUAGE_DONTKNOW == nLangType) || + (LANGUAGE_SYSTEM == nLangType) || + (LANGUAGE_USER1 <= nLangType && nLangType <= LANGUAGE_USER9)) + { + bInsert = FALSE; + } + + if ( bInsert ) + InsertLanguage( nLangType ); } + m_nLangList = LANG_LIST_ALL; } } //------------------------------------------------------------------------ +SvxLanguageBox::SvxLanguageBox( Window* pParent, const ResId& rResId ) : + ListBox( pParent, rResId ) +{ + m_pLangTable = new SvxLanguageTable; + m_aNotCheckedImage = Image( SVX_RES( RID_SVXIMG_NOTCHECKED ) ); + m_aCheckedImage = Image( SVX_RES( RID_SVXIMG_CHECKED ) ); + m_bWithCheckmark = FALSE; + m_aAllString = String( SVX_RESSTR( RID_SVXSTR_LANGUAGE_ALL ) ); + m_nLangList = LANG_LIST_EMPTY; + m_bHasLangNone = FALSE; + m_bLangNoneIsLangAll = FALSE; + + // display entries sorted + SetStyle( GetStyle() | WB_SORT ); +} + +//------------------------------------------------------------------------ + SvxLanguageBox::~SvxLanguageBox() { delete m_pLangTable; @@ -136,9 +267,96 @@ SvxLanguageBox::~SvxLanguageBox() //------------------------------------------------------------------------ -USHORT SvxLanguageBox::InsertLanguage( const LanguageType eLangType, USHORT nPos ) +void SvxLanguageBox::SetLanguageList( INT16 nLangList, + BOOL bHasLangNone, BOOL bLangNoneIsLangAll, BOOL bCheckSpellAvail ) { - String aStrEntry = m_pLangTable->GetString( eLangType ); + Clear(); + + m_nLangList = nLangList; + m_bHasLangNone = bHasLangNone; + m_bLangNoneIsLangAll = bLangNoneIsLangAll; + m_bWithCheckmark = bCheckSpellAvail; + + if ( LANG_LIST_EMPTY != nLangList ) + { + Sequence< INT16 > aSpellAvailLang; + Sequence< INT16 > aHyphAvailLang; + Sequence< INT16 > aThesAvailLang; + if (LinguMgr::GetLngSvcMgr().is()) + { + Sequence< Locale > aTmp; + + if (LANG_LIST_SPELL_AVAIL & nLangList) + { + aTmp = LinguMgr::GetLngSvcMgr() + ->getAvailableLocales( A2OU( SN_SPELLCHECKER ) ); + aSpellAvailLang = lcl_LocaleSeqToLangSeq( aTmp ); + } + if (LANG_LIST_HYPH_AVAIL & nLangList) + { + aTmp = LinguMgr::GetLngSvcMgr() + ->getAvailableLocales( A2OU( SN_HYPHENATOR ) ); + aHyphAvailLang = lcl_LocaleSeqToLangSeq( aTmp ); + } + if (LANG_LIST_THES_AVAIL & nLangList) + { + aTmp = LinguMgr::GetLngSvcMgr() + ->getAvailableLocales( A2OU( SN_THESAURUS ) ); + aThesAvailLang = lcl_LocaleSeqToLangSeq( aTmp ); + } + } + + SvxLanguageTable aLangTable; + const USHORT nCount = aLangTable.GetEntryCount(); + for ( USHORT i = 0; i < nCount; i++ ) + { + LanguageType nLangType = aLangTable.GetTypeAtIndex( i ); + BOOL bInsert = FALSE; + if ( nLangType != LANGUAGE_SYSTEM && + nLangType != LANGUAGE_NONE ) + { + if (nLangList & LANG_LIST_ALL) + bInsert |= TRUE; + if (nLangList & LANG_LIST_WESTERN) + bInsert |= SCRIPTTYPE_LATIN == GetScriptTypeOfLanguage( nLangType ); + if (nLangList & LANG_LIST_CTL) + bInsert |= SCRIPTTYPE_COMPLEX == GetScriptTypeOfLanguage( nLangType ); + if (nLangList & LANG_LIST_CJK) + bInsert |= SCRIPTTYPE_ASIAN == GetScriptTypeOfLanguage( nLangType ); + if (nLangList & LANG_LIST_FBD_CHARS) + bInsert |= lcl_HasLanguage( aForbiddenCharLang, + nForbiddenCharLang, nLangType ); + if (nLangList & LANG_LIST_SPELL_AVAIL) + bInsert |= lcl_SeqHasLang( aSpellAvailLang, nLangType ); + if (nLangList & LANG_LIST_HYPH_AVAIL) + bInsert |= lcl_SeqHasLang( aHyphAvailLang, nLangType ); + if (nLangList & LANG_LIST_THES_AVAIL) + bInsert |= lcl_SeqHasLang( aThesAvailLang, nLangType ); + } + + if ((LANGUAGE_DONTKNOW == nLangType) || + (LANGUAGE_USER1 <= nLangType && nLangType <= LANGUAGE_USER9)) + { + bInsert = FALSE; + } + + if (bInsert) + InsertLanguage( nLangType ); + } + + if (bHasLangNone) + InsertLanguage( LANGUAGE_NONE ); + } +} + +//------------------------------------------------------------------------ + +USHORT SvxLanguageBox::InsertLanguage( const LanguageType nLangType, USHORT nPos ) +{ + String aStrEntry = m_pLangTable->GetString( nLangType ); + if (LANGUAGE_NONE == nLangType && m_bHasLangNone && m_bLangNoneIsLangAll) + aStrEntry = m_aAllString; + USHORT nAt = 0; if ( m_bWithCheckmark ) { @@ -147,7 +365,7 @@ USHORT SvxLanguageBox::InsertLanguage( const LanguageType eLangType, USHORT nPos sal_Bool bFound = sal_False; for ( USHORT i = 0; i < nLanguageCount; ++i ) { - if ( eLangType == pLangList[i] ) + if ( nLangType == pLangList[i] ) { bFound = sal_True; break; @@ -162,7 +380,7 @@ USHORT SvxLanguageBox::InsertLanguage( const LanguageType eLangType, USHORT nPos else nAt = InsertEntry( aStrEntry, nPos ); - SetEntryData( nAt, (void*)(ULONG)eLangType ); + SetEntryData( nAt, (void*)(ULONG)nLangType ); return nPos; } |