xref: /aoo41x/main/svx/source/dialog/langbox.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // include ---------------------------------------------------------------
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <com/sun/star/linguistic2/XLinguServiceManager.hdl>
34*cdf0e10cSrcweir #include <com/sun/star/linguistic2/XAvailableLocales.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/i18n/ScriptType.hpp>
36*cdf0e10cSrcweir #include <linguistic/misc.hxx>
37*cdf0e10cSrcweir #include <rtl/ustring.hxx>
38*cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx>
39*cdf0e10cSrcweir #include <tools/urlobj.hxx>
40*cdf0e10cSrcweir #include <svtools/langtab.hxx>
41*cdf0e10cSrcweir #include <tools/shl.hxx>
42*cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
43*cdf0e10cSrcweir #include <i18npool/lang.h>
44*cdf0e10cSrcweir #include <editeng/scripttypeitem.hxx>
45*cdf0e10cSrcweir #include <editeng/unolingu.hxx>
46*cdf0e10cSrcweir #include <svx/langbox.hxx>
47*cdf0e10cSrcweir #include <svx/dialmgr.hxx>
48*cdf0e10cSrcweir #include <svx/dialogs.hrc>
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir using namespace ::com::sun::star::util;
51*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
52*cdf0e10cSrcweir using namespace ::com::sun::star::linguistic2;
53*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir // -----------------------------------------------------------------------
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir String GetDicInfoStr( const String& rName, const sal_uInt16 nLang, sal_Bool bNeg )
58*cdf0e10cSrcweir {
59*cdf0e10cSrcweir 	INetURLObject aURLObj;
60*cdf0e10cSrcweir 	aURLObj.SetSmartProtocol( INET_PROT_FILE );
61*cdf0e10cSrcweir 	aURLObj.SetSmartURL( rName, INetURLObject::ENCODE_ALL );
62*cdf0e10cSrcweir 	String aTmp( aURLObj.GetBase() );
63*cdf0e10cSrcweir 	aTmp += sal_Unicode( ' ' );
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir 	if ( bNeg )
66*cdf0e10cSrcweir 	{
67*cdf0e10cSrcweir 		sal_Char const sTmp[] = " (-) ";
68*cdf0e10cSrcweir 		aTmp.AppendAscii( sTmp );
69*cdf0e10cSrcweir 	}
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 	if ( LANGUAGE_NONE == nLang )
72*cdf0e10cSrcweir 		aTmp += String( ResId( RID_SVXSTR_LANGUAGE_ALL, DIALOG_MGR() ) );
73*cdf0e10cSrcweir 	else
74*cdf0e10cSrcweir 	{
75*cdf0e10cSrcweir 		aTmp += sal_Unicode( '[' );
76*cdf0e10cSrcweir 		aTmp += SvtLanguageTable::GetLanguageString( (LanguageType)nLang );
77*cdf0e10cSrcweir 		aTmp += sal_Unicode( ']' );
78*cdf0e10cSrcweir 	}
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 	return aTmp;
81*cdf0e10cSrcweir }
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir //========================================================================
84*cdf0e10cSrcweir //	misc local helper functions
85*cdf0e10cSrcweir //========================================================================
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir static Sequence< sal_Int16 > lcl_LocaleSeqToLangSeq( Sequence< Locale > &rSeq )
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir 	const Locale *pLocale = rSeq.getConstArray();
90*cdf0e10cSrcweir 	sal_Int32 nCount = rSeq.getLength();
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 	Sequence< sal_Int16 >	aLangs( nCount );
93*cdf0e10cSrcweir 	sal_Int16 *pLang = aLangs.getArray();
94*cdf0e10cSrcweir 	for (sal_Int32 i = 0;  i < nCount;  ++i)
95*cdf0e10cSrcweir 	{
96*cdf0e10cSrcweir 		pLang[i] = SvxLocaleToLanguage( pLocale[i] );
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 	}
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 	return aLangs;
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir static sal_Bool lcl_SeqHasLang( const Sequence< sal_Int16 > & rLangSeq, sal_Int16 nLang )
105*cdf0e10cSrcweir {
106*cdf0e10cSrcweir 	sal_Int32 i = -1;
107*cdf0e10cSrcweir 	sal_Int32 nLen = rLangSeq.getLength();
108*cdf0e10cSrcweir 	if (nLen)
109*cdf0e10cSrcweir 	{
110*cdf0e10cSrcweir 		const sal_Int16 *pLang = rLangSeq.getConstArray();
111*cdf0e10cSrcweir 		for (i = 0;  i < nLen;  ++i)
112*cdf0e10cSrcweir 		{
113*cdf0e10cSrcweir 			if (nLang == pLang[i])
114*cdf0e10cSrcweir 				break;
115*cdf0e10cSrcweir 		}
116*cdf0e10cSrcweir 	}
117*cdf0e10cSrcweir 	return i >= 0  &&  i < nLen;
118*cdf0e10cSrcweir }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir //========================================================================
121*cdf0e10cSrcweir //	class SvxLanguageBox
122*cdf0e10cSrcweir //========================================================================
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir sal_uInt16 TypeToPos_Impl( LanguageType eType, const ListBox& rLb )
125*cdf0e10cSrcweir {
126*cdf0e10cSrcweir 	sal_uInt16	nPos   = LISTBOX_ENTRY_NOTFOUND;
127*cdf0e10cSrcweir 	sal_uInt16	nCount = rLb.GetEntryCount();
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 	for ( sal_uInt16 i=0; nPos == LISTBOX_ENTRY_NOTFOUND && i<nCount; i++ )
130*cdf0e10cSrcweir 		if ( eType == LanguageType((sal_uIntPtr)rLb.GetEntryData(i)) )
131*cdf0e10cSrcweir 			nPos = i;
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 	return nPos;
134*cdf0e10cSrcweir }
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir //-----------------------------------------------------------------------
137*cdf0e10cSrcweir SvxLanguageBox::SvxLanguageBox( Window* pParent, WinBits nWinStyle, sal_Bool bCheck ) :
138*cdf0e10cSrcweir     ListBox( pParent, nWinStyle ),
139*cdf0e10cSrcweir     m_pSpellUsedLang( NULL ),
140*cdf0e10cSrcweir     m_bWithCheckmark( bCheck )
141*cdf0e10cSrcweir {
142*cdf0e10cSrcweir     Init();
143*cdf0e10cSrcweir }
144*cdf0e10cSrcweir //------------------------------------------------------------------------
145*cdf0e10cSrcweir SvxLanguageBox::SvxLanguageBox( Window* pParent, const ResId& rResId, sal_Bool bCheck ) :
146*cdf0e10cSrcweir 	ListBox( pParent, rResId ),
147*cdf0e10cSrcweir     m_pSpellUsedLang( NULL ),
148*cdf0e10cSrcweir 	m_bWithCheckmark( bCheck )
149*cdf0e10cSrcweir {
150*cdf0e10cSrcweir     Init();
151*cdf0e10cSrcweir }
152*cdf0e10cSrcweir //------------------------------------------------------------------------
153*cdf0e10cSrcweir void SvxLanguageBox::Init()
154*cdf0e10cSrcweir {
155*cdf0e10cSrcweir     m_pLangTable = new SvtLanguageTable;
156*cdf0e10cSrcweir 	m_aNotCheckedImage = Image( SVX_RES( RID_SVXIMG_NOTCHECKED ) );
157*cdf0e10cSrcweir     m_aCheckedImage = Image( SVX_RES( RID_SVXIMG_CHECKED ) );
158*cdf0e10cSrcweir     m_aCheckedImageHC = Image( SVX_RES( RID_SVXIMG_CHECKED_H ) );
159*cdf0e10cSrcweir 	m_aAllString			= String( SVX_RESSTR( RID_SVXSTR_LANGUAGE_ALL ) );
160*cdf0e10cSrcweir 	m_nLangList				= LANG_LIST_EMPTY;
161*cdf0e10cSrcweir 	m_bHasLangNone			= sal_False;
162*cdf0e10cSrcweir 	m_bLangNoneIsLangAll	= sal_False;
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 	// display entries sorted
165*cdf0e10cSrcweir 	SetStyle( GetStyle() | WB_SORT );
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 	if ( m_bWithCheckmark )
168*cdf0e10cSrcweir 	{
169*cdf0e10cSrcweir         SvtLanguageTable aLangTable;
170*cdf0e10cSrcweir 		sal_uInt32 nCount = aLangTable.GetEntryCount();
171*cdf0e10cSrcweir 		for ( sal_uInt32 i = 0; i < nCount; i++ )
172*cdf0e10cSrcweir 		{
173*cdf0e10cSrcweir 			LanguageType nLangType = aLangTable.GetTypeAtIndex( i );
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 			sal_Bool bInsert = sal_True;
176*cdf0e10cSrcweir 			if ((LANGUAGE_DONTKNOW == nLangType)  ||
177*cdf0e10cSrcweir 				(LANGUAGE_SYSTEM   == nLangType)  ||
178*cdf0e10cSrcweir 				(LANGUAGE_USER1 <= nLangType  &&  nLangType <= LANGUAGE_USER9))
179*cdf0e10cSrcweir 			{
180*cdf0e10cSrcweir 				bInsert = sal_False;
181*cdf0e10cSrcweir 			}
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir 			if ( bInsert )
184*cdf0e10cSrcweir 				InsertLanguage( nLangType );
185*cdf0e10cSrcweir 		}
186*cdf0e10cSrcweir 		m_nLangList	= LANG_LIST_ALL;
187*cdf0e10cSrcweir 	}
188*cdf0e10cSrcweir }
189*cdf0e10cSrcweir //------------------------------------------------------------------------
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir SvxLanguageBox::~SvxLanguageBox()
192*cdf0e10cSrcweir {
193*cdf0e10cSrcweir     delete m_pSpellUsedLang;
194*cdf0e10cSrcweir 	delete m_pLangTable;
195*cdf0e10cSrcweir }
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir //------------------------------------------------------------------------
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir sal_uInt16 SvxLanguageBox::ImplInsertImgEntry( const String& rEntry, sal_uInt16 nPos, bool bChecked )
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir     sal_uInt16 nRet = 0;
202*cdf0e10cSrcweir     if( !bChecked )
203*cdf0e10cSrcweir         nRet = InsertEntry( rEntry, m_aNotCheckedImage, nPos );
204*cdf0e10cSrcweir     else if( GetSettings().GetStyleSettings().GetHighContrastMode() )
205*cdf0e10cSrcweir         nRet = InsertEntry( rEntry, m_aCheckedImageHC, nPos );
206*cdf0e10cSrcweir     else
207*cdf0e10cSrcweir         nRet = InsertEntry( rEntry, m_aCheckedImage, nPos );
208*cdf0e10cSrcweir     return nRet;
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir //------------------------------------------------------------------------
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir void SvxLanguageBox::SetLanguageList( sal_Int16 nLangList,
214*cdf0e10cSrcweir 		sal_Bool bHasLangNone, sal_Bool bLangNoneIsLangAll, sal_Bool bCheckSpellAvail )
215*cdf0e10cSrcweir {
216*cdf0e10cSrcweir 	Clear();
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir 	m_nLangList				= nLangList;
219*cdf0e10cSrcweir 	m_bHasLangNone			= bHasLangNone;
220*cdf0e10cSrcweir 	m_bLangNoneIsLangAll	= bLangNoneIsLangAll;
221*cdf0e10cSrcweir 	m_bWithCheckmark		= bCheckSpellAvail;
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 	if ( LANG_LIST_EMPTY != nLangList )
224*cdf0e10cSrcweir 	{
225*cdf0e10cSrcweir 		Sequence< sal_Int16 > aSpellAvailLang;
226*cdf0e10cSrcweir 		Sequence< sal_Int16 > aHyphAvailLang;
227*cdf0e10cSrcweir 		Sequence< sal_Int16 > aThesAvailLang;
228*cdf0e10cSrcweir         Sequence< sal_Int16 > aSpellUsedLang;
229*cdf0e10cSrcweir         Sequence< sal_Int16 > aHyphUsedLang;
230*cdf0e10cSrcweir         Sequence< sal_Int16 > aThesUsedLang;
231*cdf0e10cSrcweir 		Reference< XAvailableLocales > xAvail( LinguMgr::GetLngSvcMgr(), UNO_QUERY );
232*cdf0e10cSrcweir 		if (xAvail.is())
233*cdf0e10cSrcweir 		{
234*cdf0e10cSrcweir 			Sequence< Locale > aTmp;
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir 			if (LANG_LIST_SPELL_AVAIL & nLangList)
237*cdf0e10cSrcweir 			{
238*cdf0e10cSrcweir 				aTmp = xAvail->getAvailableLocales( A2OU( SN_SPELLCHECKER ) );
239*cdf0e10cSrcweir 				aSpellAvailLang = lcl_LocaleSeqToLangSeq( aTmp );
240*cdf0e10cSrcweir 			}
241*cdf0e10cSrcweir 			if (LANG_LIST_HYPH_AVAIL  & nLangList)
242*cdf0e10cSrcweir 			{
243*cdf0e10cSrcweir 				aTmp = xAvail->getAvailableLocales( A2OU( SN_HYPHENATOR ) );
244*cdf0e10cSrcweir 				aHyphAvailLang = lcl_LocaleSeqToLangSeq( aTmp );
245*cdf0e10cSrcweir 			}
246*cdf0e10cSrcweir 			if (LANG_LIST_THES_AVAIL  & nLangList)
247*cdf0e10cSrcweir 			{
248*cdf0e10cSrcweir 				aTmp = xAvail->getAvailableLocales( A2OU( SN_THESAURUS ) );
249*cdf0e10cSrcweir 				aThesAvailLang = lcl_LocaleSeqToLangSeq( aTmp );
250*cdf0e10cSrcweir 			}
251*cdf0e10cSrcweir 		}
252*cdf0e10cSrcweir         if (LANG_LIST_SPELL_USED & nLangList)
253*cdf0e10cSrcweir         {
254*cdf0e10cSrcweir             Reference< XSpellChecker1 > xTmp1( SvxGetSpellChecker(), UNO_QUERY );
255*cdf0e10cSrcweir             if (xTmp1.is())
256*cdf0e10cSrcweir                 aSpellUsedLang = xTmp1->getLanguages();
257*cdf0e10cSrcweir         }
258*cdf0e10cSrcweir         if (LANG_LIST_HYPH_USED  & nLangList)
259*cdf0e10cSrcweir         {
260*cdf0e10cSrcweir             Reference< XHyphenator > xTmp( SvxGetHyphenator() );
261*cdf0e10cSrcweir             if (xTmp.is()) {
262*cdf0e10cSrcweir                 Sequence < Locale > aLocaleSequence( xTmp->getLocales() );
263*cdf0e10cSrcweir                 aHyphUsedLang = lcl_LocaleSeqToLangSeq( aLocaleSequence );
264*cdf0e10cSrcweir             }
265*cdf0e10cSrcweir         }
266*cdf0e10cSrcweir         if (LANG_LIST_THES_USED  & nLangList)
267*cdf0e10cSrcweir         {
268*cdf0e10cSrcweir             Reference< XThesaurus > xTmp( SvxGetThesaurus() );
269*cdf0e10cSrcweir             if (xTmp.is()) {
270*cdf0e10cSrcweir                 Sequence < Locale > aLocaleSequence( xTmp->getLocales() );
271*cdf0e10cSrcweir                 aThesUsedLang = lcl_LocaleSeqToLangSeq( aLocaleSequence );
272*cdf0e10cSrcweir             }
273*cdf0e10cSrcweir         }
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir         SvtLanguageTable aLangTable;
276*cdf0e10cSrcweir         ::com::sun::star::uno::Sequence< sal_uInt16 > xKnown;
277*cdf0e10cSrcweir         const sal_uInt16* pKnown;
278*cdf0e10cSrcweir         sal_uInt32 nCount;
279*cdf0e10cSrcweir         if ( nLangList & LANG_LIST_ONLY_KNOWN )
280*cdf0e10cSrcweir         {
281*cdf0e10cSrcweir             xKnown = LocaleDataWrapper::getInstalledLanguageTypes();
282*cdf0e10cSrcweir             pKnown = xKnown.getConstArray();
283*cdf0e10cSrcweir             nCount = xKnown.getLength();
284*cdf0e10cSrcweir         }
285*cdf0e10cSrcweir         else
286*cdf0e10cSrcweir         {
287*cdf0e10cSrcweir             nCount = aLangTable.GetEntryCount();
288*cdf0e10cSrcweir             pKnown = NULL;
289*cdf0e10cSrcweir         }
290*cdf0e10cSrcweir 		for ( sal_uInt32 i = 0; i < nCount; i++ )
291*cdf0e10cSrcweir 		{
292*cdf0e10cSrcweir             LanguageType nLangType;
293*cdf0e10cSrcweir             if ( nLangList & LANG_LIST_ONLY_KNOWN )
294*cdf0e10cSrcweir                 nLangType = pKnown[i];
295*cdf0e10cSrcweir             else
296*cdf0e10cSrcweir                 nLangType = aLangTable.GetTypeAtIndex( i );
297*cdf0e10cSrcweir 			if ( nLangType != LANGUAGE_DONTKNOW &&
298*cdf0e10cSrcweir 				 nLangType != LANGUAGE_SYSTEM &&
299*cdf0e10cSrcweir 			     nLangType != LANGUAGE_NONE &&
300*cdf0e10cSrcweir                  (nLangType < LANGUAGE_USER1 || nLangType > LANGUAGE_USER9) &&
301*cdf0e10cSrcweir                  (MsLangId::getSubLanguage( nLangType) != 0 ||
302*cdf0e10cSrcweir                   (nLangList & LANG_LIST_ALSO_PRIMARY_ONLY)) &&
303*cdf0e10cSrcweir                  ((nLangList & LANG_LIST_ALL) != 0 ||
304*cdf0e10cSrcweir                   ((nLangList & LANG_LIST_WESTERN) != 0 &&
305*cdf0e10cSrcweir                    (SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType) ==
306*cdf0e10cSrcweir                     SCRIPTTYPE_LATIN)) ||
307*cdf0e10cSrcweir                   ((nLangList & LANG_LIST_CTL) != 0 &&
308*cdf0e10cSrcweir                    (SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType) ==
309*cdf0e10cSrcweir                     SCRIPTTYPE_COMPLEX)) ||
310*cdf0e10cSrcweir                   ((nLangList & LANG_LIST_CJK) != 0 &&
311*cdf0e10cSrcweir                    (SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType) ==
312*cdf0e10cSrcweir                     SCRIPTTYPE_ASIAN)) ||
313*cdf0e10cSrcweir                   ((nLangList & LANG_LIST_FBD_CHARS) != 0 &&
314*cdf0e10cSrcweir                    MsLangId::hasForbiddenCharacters(nLangType)) ||
315*cdf0e10cSrcweir                   ((nLangList & LANG_LIST_SPELL_AVAIL) != 0 &&
316*cdf0e10cSrcweir                    lcl_SeqHasLang(aSpellAvailLang, nLangType)) ||
317*cdf0e10cSrcweir                   ((nLangList & LANG_LIST_HYPH_AVAIL) != 0 &&
318*cdf0e10cSrcweir                    lcl_SeqHasLang(aHyphAvailLang, nLangType)) ||
319*cdf0e10cSrcweir                   ((nLangList & LANG_LIST_THES_AVAIL) != 0 &&
320*cdf0e10cSrcweir                    lcl_SeqHasLang(aThesAvailLang, nLangType)) ||
321*cdf0e10cSrcweir                   ((nLangList & LANG_LIST_SPELL_USED) != 0 &&
322*cdf0e10cSrcweir                    lcl_SeqHasLang(aSpellUsedLang, nLangType)) ||
323*cdf0e10cSrcweir                   ((nLangList & LANG_LIST_HYPH_USED) != 0 &&
324*cdf0e10cSrcweir                    lcl_SeqHasLang(aHyphUsedLang, nLangType)) ||
325*cdf0e10cSrcweir                   ((nLangList & LANG_LIST_THES_USED) != 0 &&
326*cdf0e10cSrcweir                    lcl_SeqHasLang(aThesUsedLang, nLangType))) )
327*cdf0e10cSrcweir 				InsertLanguage( nLangType );
328*cdf0e10cSrcweir 		}
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir 		if (bHasLangNone)
331*cdf0e10cSrcweir 			InsertLanguage( LANGUAGE_NONE );
332*cdf0e10cSrcweir 	}
333*cdf0e10cSrcweir }
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir //------------------------------------------------------------------------
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir sal_uInt16 SvxLanguageBox::InsertLanguage( const LanguageType nLangType, sal_uInt16 nPos )
338*cdf0e10cSrcweir {
339*cdf0e10cSrcweir     return ImplInsertLanguage( nLangType, nPos, ::com::sun::star::i18n::ScriptType::WEAK );
340*cdf0e10cSrcweir }
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir //------------------------------------------------------------------------
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir sal_uInt16 SvxLanguageBox::ImplInsertLanguage( const LanguageType nLangType, sal_uInt16 nPos, sal_Int16 nType )
345*cdf0e10cSrcweir {
346*cdf0e10cSrcweir     LanguageType nLang = MsLangId::getReplacementForObsoleteLanguage( nLangType);
347*cdf0e10cSrcweir     // For obsolete and to be replaced languages check whether an entry of the
348*cdf0e10cSrcweir     // replacement already exists and if so don't add an entry with identical
349*cdf0e10cSrcweir     // string as would be returned by SvtLanguageTable::GetString().
350*cdf0e10cSrcweir     if (nLang != nLangType)
351*cdf0e10cSrcweir     {
352*cdf0e10cSrcweir         sal_uInt16 nAt = TypeToPos_Impl( nLang, *this );
353*cdf0e10cSrcweir         if ( nAt != LISTBOX_ENTRY_NOTFOUND )
354*cdf0e10cSrcweir             return nAt;
355*cdf0e10cSrcweir     }
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir     String aStrEntry = m_pLangTable->GetString( nLang );
358*cdf0e10cSrcweir     if (LANGUAGE_NONE == nLang && m_bHasLangNone && m_bLangNoneIsLangAll)
359*cdf0e10cSrcweir         aStrEntry = m_aAllString;
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir     LanguageType nRealLang = nLang;
362*cdf0e10cSrcweir     if (nRealLang == LANGUAGE_SYSTEM)
363*cdf0e10cSrcweir     {
364*cdf0e10cSrcweir         nRealLang = MsLangId::resolveSystemLanguageByScriptType(nRealLang, nType);
365*cdf0e10cSrcweir         aStrEntry.AppendAscii(" - ");
366*cdf0e10cSrcweir         aStrEntry.Append(m_pLangTable->GetString( nRealLang ));
367*cdf0e10cSrcweir     }
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir     aStrEntry = ApplyLreOrRleEmbedding( aStrEntry );
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir     sal_uInt16 nAt = 0;
372*cdf0e10cSrcweir     if ( m_bWithCheckmark )
373*cdf0e10cSrcweir     {
374*cdf0e10cSrcweir         sal_Bool bFound = sal_False;
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir         if (!m_pSpellUsedLang)
377*cdf0e10cSrcweir         {
378*cdf0e10cSrcweir             Reference< XSpellChecker1 > xSpell( SvxGetSpellChecker(), UNO_QUERY );
379*cdf0e10cSrcweir             if ( xSpell.is() )
380*cdf0e10cSrcweir                 m_pSpellUsedLang = new Sequence< sal_Int16 >( xSpell->getLanguages() );
381*cdf0e10cSrcweir         }
382*cdf0e10cSrcweir         bFound = m_pSpellUsedLang ?
383*cdf0e10cSrcweir             lcl_SeqHasLang( *m_pSpellUsedLang, nRealLang ) : sal_False;
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir         nAt = ImplInsertImgEntry( aStrEntry, nPos, bFound );
386*cdf0e10cSrcweir     }
387*cdf0e10cSrcweir     else
388*cdf0e10cSrcweir         nAt = InsertEntry( aStrEntry, nPos );
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir     SetEntryData( nAt, (void*)(sal_uIntPtr)nLangType );
391*cdf0e10cSrcweir     return nAt;
392*cdf0e10cSrcweir }
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir //------------------------------------------------------------------------
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir sal_uInt16 SvxLanguageBox::InsertDefaultLanguage( sal_Int16 nType, sal_uInt16 nPos )
397*cdf0e10cSrcweir {
398*cdf0e10cSrcweir     return ImplInsertLanguage( LANGUAGE_SYSTEM, nPos, nType );
399*cdf0e10cSrcweir }
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir //------------------------------------------------------------------------
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir sal_uInt16 SvxLanguageBox::InsertLanguage( const LanguageType nLangType,
404*cdf0e10cSrcweir         sal_Bool bCheckEntry, sal_uInt16 nPos )
405*cdf0e10cSrcweir {
406*cdf0e10cSrcweir     LanguageType nLang = MsLangId::getReplacementForObsoleteLanguage( nLangType);
407*cdf0e10cSrcweir     // For obsolete and to be replaced languages check whether an entry of the
408*cdf0e10cSrcweir     // replacement already exists and if so don't add an entry with identical
409*cdf0e10cSrcweir     // string as would be returned by SvtLanguageTable::GetString().
410*cdf0e10cSrcweir     if (nLang != nLangType)
411*cdf0e10cSrcweir     {
412*cdf0e10cSrcweir         sal_uInt16 nAt = TypeToPos_Impl( nLang, *this );
413*cdf0e10cSrcweir         if ( nAt != LISTBOX_ENTRY_NOTFOUND )
414*cdf0e10cSrcweir             return nAt;
415*cdf0e10cSrcweir     }
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir 	String aStrEntry = m_pLangTable->GetString( nLang );
418*cdf0e10cSrcweir 	if (LANGUAGE_NONE == nLang && m_bHasLangNone && m_bLangNoneIsLangAll)
419*cdf0e10cSrcweir 		aStrEntry = m_aAllString;
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir     sal_uInt16 nAt = ImplInsertImgEntry( aStrEntry, nPos, bCheckEntry );
422*cdf0e10cSrcweir 	SetEntryData( nAt, (void*)(sal_uIntPtr)nLang );
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir     return nAt;
425*cdf0e10cSrcweir }
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir //------------------------------------------------------------------------
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir void SvxLanguageBox::RemoveLanguage( const LanguageType eLangType )
430*cdf0e10cSrcweir {
431*cdf0e10cSrcweir 	sal_uInt16 nAt = TypeToPos_Impl( eLangType, *this );
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir 	if ( nAt != LISTBOX_ENTRY_NOTFOUND )
434*cdf0e10cSrcweir 		RemoveEntry( nAt );
435*cdf0e10cSrcweir }
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir //------------------------------------------------------------------------
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir LanguageType SvxLanguageBox::GetSelectLanguage() const
440*cdf0e10cSrcweir {
441*cdf0e10cSrcweir 	sal_uInt16 		 nPos	= GetSelectEntryPos();
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir 	if ( nPos != LISTBOX_ENTRY_NOTFOUND )
444*cdf0e10cSrcweir 		return LanguageType( (sal_uIntPtr)GetEntryData(nPos) );
445*cdf0e10cSrcweir 	else
446*cdf0e10cSrcweir 		return LanguageType( LANGUAGE_DONTKNOW );
447*cdf0e10cSrcweir }
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir //------------------------------------------------------------------------
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir void SvxLanguageBox::SelectLanguage( const LanguageType eLangType, sal_Bool bSelect )
452*cdf0e10cSrcweir {
453*cdf0e10cSrcweir     // If the core uses a LangID of an imported MS document and wants to select
454*cdf0e10cSrcweir     // a language that is replaced, we need to select the replacement instead.
455*cdf0e10cSrcweir     LanguageType nLang = MsLangId::getReplacementForObsoleteLanguage( eLangType);
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir 	sal_uInt16 nAt = TypeToPos_Impl( nLang, *this );
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir 	if ( nAt != LISTBOX_ENTRY_NOTFOUND )
460*cdf0e10cSrcweir 		SelectEntryPos( nAt, bSelect );
461*cdf0e10cSrcweir }
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir //------------------------------------------------------------------------
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir sal_Bool SvxLanguageBox::IsLanguageSelected( const LanguageType eLangType ) const
466*cdf0e10cSrcweir {
467*cdf0e10cSrcweir     // Same here, work on the replacement if applicable.
468*cdf0e10cSrcweir     LanguageType nLang = MsLangId::getReplacementForObsoleteLanguage( eLangType);
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir 	sal_uInt16 nAt = TypeToPos_Impl( nLang, *this );
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir 	if ( nAt != LISTBOX_ENTRY_NOTFOUND )
473*cdf0e10cSrcweir 		return IsEntryPosSelected( nAt );
474*cdf0e10cSrcweir 	else
475*cdf0e10cSrcweir 		return sal_False;
476*cdf0e10cSrcweir }
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir #if ENABLE_LAYOUT
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir namespace layout
481*cdf0e10cSrcweir {
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir SvxLanguageBox::~SvxLanguageBox ()
484*cdf0e10cSrcweir {
485*cdf0e10cSrcweir }
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir SvxLanguageBox::SvxLanguageBox( Context* pParent, const char* pFile, sal_Bool bCheck )
488*cdf0e10cSrcweir : ListBox ( pParent, pFile, bCheck )
489*cdf0e10cSrcweir {
490*cdf0e10cSrcweir }
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir void SvxLanguageBox::SetLanguageList( sal_Int16/*list*/, bool/*hasLangNone*/, bool /*langNoneIsLangAll*/, bool /*checkSpellAvail*/)
493*cdf0e10cSrcweir {
494*cdf0e10cSrcweir }
495*cdf0e10cSrcweir 
496*cdf0e10cSrcweir sal_uInt16 SvxLanguageBox::InsertLanguage( const LanguageType/*type*/, sal_uInt16/*pos*/)
497*cdf0e10cSrcweir {
498*cdf0e10cSrcweir     return 0;
499*cdf0e10cSrcweir }
500*cdf0e10cSrcweir sal_uInt16 SvxLanguageBox::InsertLanguage( const LanguageType/*type*/, bool/*checkEntry*/, sal_uInt16 /*pos*/)
501*cdf0e10cSrcweir {
502*cdf0e10cSrcweir     return 0;
503*cdf0e10cSrcweir }
504*cdf0e10cSrcweir void SvxLanguageBox::RemoveLanguage( const LanguageType/*type*/)
505*cdf0e10cSrcweir {
506*cdf0e10cSrcweir }
507*cdf0e10cSrcweir void SvxLanguageBox::SelectLanguage( const LanguageType/*type*/, bool/*select*/)
508*cdf0e10cSrcweir {
509*cdf0e10cSrcweir }
510*cdf0e10cSrcweir LanguageType SvxLanguageBox::GetSelectLanguage() const
511*cdf0e10cSrcweir {
512*cdf0e10cSrcweir     return 0;
513*cdf0e10cSrcweir }
514*cdf0e10cSrcweir bool SvxLanguageBox::IsLanguageSelected( const LanguageType/*type*/) const
515*cdf0e10cSrcweir {
516*cdf0e10cSrcweir     return true;
517*cdf0e10cSrcweir }
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir /*IMPL_IMPL (SvxLanguageBox, ListBox);
520*cdf0e10cSrcweir IMPL_CONSTRUCTORS ( SvxLanguageBox, ListBox, "svxlanguagebox" );
521*cdf0e10cSrcweir IMPL_GET_IMPL( SvxLanguageBox );
522*cdf0e10cSrcweir IMPL_GET_WINDOW (SvxLanguageBox);*/
523*cdf0e10cSrcweir };
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir #endif
526*cdf0e10cSrcweir 
527