xref: /aoo42x/main/cui/source/options/optdict.cxx (revision 2ee96f1c)
1*2ee96f1cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2ee96f1cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2ee96f1cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2ee96f1cSAndrew Rist  * distributed with this work for additional information
6*2ee96f1cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2ee96f1cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2ee96f1cSAndrew Rist  * "License"); you may not use this file except in compliance
9*2ee96f1cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2ee96f1cSAndrew Rist  *
11*2ee96f1cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2ee96f1cSAndrew Rist  *
13*2ee96f1cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2ee96f1cSAndrew Rist  * software distributed under the License is distributed on an
15*2ee96f1cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2ee96f1cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2ee96f1cSAndrew Rist  * specific language governing permissions and limitations
18*2ee96f1cSAndrew Rist  * under the License.
19*2ee96f1cSAndrew Rist  *
20*2ee96f1cSAndrew Rist  *************************************************************/
21*2ee96f1cSAndrew Rist 
22*2ee96f1cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_cui.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // include ---------------------------------------------------------------
28cdf0e10cSrcweir #include <tools/shl.hxx>
29cdf0e10cSrcweir #include <editeng/unolingu.hxx>
30cdf0e10cSrcweir #include <svx/dlgutil.hxx>
31cdf0e10cSrcweir #include <sfx2/sfxuno.hxx>
32cdf0e10cSrcweir #include <svl/eitem.hxx>
33cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
34cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
35cdf0e10cSrcweir #include <unotools/intlwrapper.hxx>
36cdf0e10cSrcweir #include <vcl/svapp.hxx>
37cdf0e10cSrcweir #include <vcl/msgbox.hxx>
38cdf0e10cSrcweir #include <svx/dialogs.hrc>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #define _SVX_OPTDICT_CXX
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include <linguistic/misc.hxx>
43cdf0e10cSrcweir #include <cuires.hrc>
44cdf0e10cSrcweir #include "optdict.hrc"
45cdf0e10cSrcweir #include "optdict.hxx"
46cdf0e10cSrcweir #include <dialmgr.hxx>
47cdf0e10cSrcweir #include <svx/svxerr.hxx>
48cdf0e10cSrcweir 
49cdf0e10cSrcweir using namespace ::com::sun::star;
50cdf0e10cSrcweir using namespace ::com::sun::star::uno;
51cdf0e10cSrcweir using namespace ::com::sun::star::linguistic2;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir // static ----------------------------------------------------------------
54cdf0e10cSrcweir 
55cdf0e10cSrcweir static const sal_uInt16 nNameLen    = 8;
56cdf0e10cSrcweir static const short  NOACTDICT   = -1;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir static long nStaticTabs[]=
59cdf0e10cSrcweir {
60cdf0e10cSrcweir 	2,10,71,120
61cdf0e10cSrcweir };
62cdf0e10cSrcweir 
63cdf0e10cSrcweir // static function -------------------------------------------------------
64cdf0e10cSrcweir 
65cdf0e10cSrcweir static String getNormDicEntry_Impl( const String &rText )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir 	String aTmp( rText );
68cdf0e10cSrcweir 	aTmp.EraseTrailingChars( '.' );
69cdf0e10cSrcweir 	aTmp.EraseAllChars( '=' );
70cdf0e10cSrcweir 	return aTmp;
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 
74cdf0e10cSrcweir // Compare Dictionary Entry  result
75cdf0e10cSrcweir enum CDE_RESULT { CDE_EQUAL, CDE_SIMILAR, CDE_DIFFERENT };
76cdf0e10cSrcweir 
77cdf0e10cSrcweir static CDE_RESULT cmpDicEntry_Impl( const String &rText1, const String &rText2 )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir 	CDE_RESULT eRes = CDE_DIFFERENT;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 	if (rText1 == rText2)
82cdf0e10cSrcweir 		eRes = CDE_EQUAL;
83cdf0e10cSrcweir 	else
84cdf0e10cSrcweir 	{	// similar = equal up to trailing '.' and hyphenation positions
85cdf0e10cSrcweir 		// marked with '='
86cdf0e10cSrcweir 		if (getNormDicEntry_Impl( rText1 ) == getNormDicEntry_Impl( rText2 ))
87cdf0e10cSrcweir 			eRes = CDE_SIMILAR;
88cdf0e10cSrcweir 	}
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	return eRes;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir // class SvxNewDictionaryDialog -------------------------------------------
94cdf0e10cSrcweir 
95cdf0e10cSrcweir SvxNewDictionaryDialog::SvxNewDictionaryDialog( Window* pParent,
96cdf0e10cSrcweir 		Reference< XSpellChecker1 >  &xSpl ) :
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	ModalDialog( pParent, CUI_RES( RID_SFXDLG_NEWDICT ) ),
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 	aNewDictBox		( this, CUI_RES( GB_NEWDICT ) ),
101cdf0e10cSrcweir 	aNameText		( this, CUI_RES( FT_DICTNAME ) ),
102cdf0e10cSrcweir 	aNameEdit		( this, CUI_RES( ED_DICTNAME ) ),
103cdf0e10cSrcweir 	aLanguageText	( this, CUI_RES( FT_DICTLANG ) ),
104cdf0e10cSrcweir 	aLanguageLB		( this, CUI_RES( LB_DICTLANG ) ),
105cdf0e10cSrcweir 	aExceptBtn		( this, CUI_RES( BTN_EXCEPT ) ),
106cdf0e10cSrcweir 	aOKBtn			( this, CUI_RES( BTN_NEWDICT_OK ) ),
107cdf0e10cSrcweir 	aCancelBtn		( this, CUI_RES( BTN_NEWDICT_ESC ) ),
108cdf0e10cSrcweir 	aHelpBtn		( this, CUI_RES( BTN_NEWDICT_HLP ) ),
109cdf0e10cSrcweir 	xSpell( xSpl )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir 	// Handler installieren
112cdf0e10cSrcweir 	aNameEdit.SetModifyHdl(
113cdf0e10cSrcweir 		LINK( this, SvxNewDictionaryDialog, ModifyHdl_Impl ) );
114cdf0e10cSrcweir 	aOKBtn.SetClickHdl( LINK( this, SvxNewDictionaryDialog, OKHdl_Impl ) );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 	// Sprachen anzeigen
117cdf0e10cSrcweir 	aLanguageLB.SetLanguageList( LANG_LIST_ALL, sal_True, sal_True );
118cdf0e10cSrcweir 	aLanguageLB.SelectEntryPos(0);
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	aNameText.SetAccessibleRelationMemberOf( &aNewDictBox );
121cdf0e10cSrcweir 	aNameEdit.SetAccessibleRelationMemberOf( &aNewDictBox );
122cdf0e10cSrcweir 	aLanguageText.SetAccessibleRelationMemberOf( &aNewDictBox );
123cdf0e10cSrcweir 	aLanguageLB.SetAccessibleRelationMemberOf( &aNewDictBox );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	FreeResource();
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir // -----------------------------------------------------------------------
129cdf0e10cSrcweir 
130cdf0e10cSrcweir IMPL_LINK( SvxNewDictionaryDialog, OKHdl_Impl, Button *, EMPTYARG )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir 	String sDict = aNameEdit.GetText();
133cdf0e10cSrcweir 	sDict.EraseTrailingChars();
134cdf0e10cSrcweir 	// add extension for personal dictionaries
135cdf0e10cSrcweir 	sDict.AppendAscii(".dic");
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	Reference< XDictionaryList >  xDicList( SvxGetDictionaryList() );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 	Sequence< Reference< XDictionary >  > aDics;
140cdf0e10cSrcweir 	if (xDicList.is())
141cdf0e10cSrcweir 		aDics = xDicList->getDictionaries();
142cdf0e10cSrcweir 	const Reference< XDictionary >  *pDic = aDics.getConstArray();
143cdf0e10cSrcweir 	sal_Int32 nCount = (sal_uInt16) aDics.getLength();
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 	sal_Bool bFound = sal_False;
146cdf0e10cSrcweir 	sal_uInt16 i;
147cdf0e10cSrcweir 	for (i = 0; !bFound && i < nCount; ++i )
148cdf0e10cSrcweir 		if ( sDict.EqualsIgnoreCaseAscii( String(pDic[i]->getName()) ))
149cdf0e10cSrcweir 			bFound = sal_True;
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 	if ( bFound )
152cdf0e10cSrcweir 	{
153cdf0e10cSrcweir 		// Doppelte Namen?
154cdf0e10cSrcweir 		InfoBox( this, CUI_RESSTR( RID_SVXSTR_OPT_DOUBLE_DICTS ) ).Execute();
155cdf0e10cSrcweir 		aNameEdit.GrabFocus();
156cdf0e10cSrcweir 		return 0;
157cdf0e10cSrcweir 	}
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 	// Erzeugen und hinzufuegen
160cdf0e10cSrcweir 	sal_uInt16 nLang = aLanguageLB.GetSelectLanguage();
161cdf0e10cSrcweir 	try
162cdf0e10cSrcweir 	{
163cdf0e10cSrcweir 		// create new dictionary
164cdf0e10cSrcweir 		DictionaryType eType = aExceptBtn.IsChecked() ?
165cdf0e10cSrcweir 				DictionaryType_NEGATIVE : DictionaryType_POSITIVE;
166cdf0e10cSrcweir 		if (xDicList.is())
167cdf0e10cSrcweir 		{
168cdf0e10cSrcweir 			lang::Locale aLocale( SvxCreateLocale(nLang) );
169cdf0e10cSrcweir             String aURL( linguistic::GetWritableDictionaryURL( sDict ) );
170cdf0e10cSrcweir             xNewDic = Reference< XDictionary > (
171cdf0e10cSrcweir 					xDicList->createDictionary( sDict, aLocale, eType, aURL ) , UNO_QUERY );
172cdf0e10cSrcweir             xNewDic->setActive( sal_True );
173cdf0e10cSrcweir 		}
174cdf0e10cSrcweir 		DBG_ASSERT(xNewDic.is(), "NULL pointer");
175cdf0e10cSrcweir 	}
176cdf0e10cSrcweir 	catch(...)
177cdf0e10cSrcweir 	{
178cdf0e10cSrcweir 		xNewDic = NULL;
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 		// Fehler: konnte neues W"orterbuch nicht anlegen
181cdf0e10cSrcweir 		SfxErrorContext aContext( ERRCTX_SVX_LINGU_DICTIONARY, String(),
182cdf0e10cSrcweir 			this, RID_SVXERRCTX, &CUI_MGR() );
183cdf0e10cSrcweir 		ErrorHandler::HandleError( *new StringErrorInfo(
184cdf0e10cSrcweir 				ERRCODE_SVX_LINGU_DICT_NOTWRITEABLE, sDict ) );
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 		EndDialog( RET_CANCEL );
187cdf0e10cSrcweir 	}
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 	if (xDicList.is() && xNewDic.is())
190cdf0e10cSrcweir 	{
191cdf0e10cSrcweir 		xDicList->addDictionary( Reference< XDictionary > ( xNewDic, UNO_QUERY ) );
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 		// refresh list of dictionaries
194cdf0e10cSrcweir 		//! dictionaries may have been added/removed elsewhere too.
195cdf0e10cSrcweir 		aDics = xDicList->getDictionaries();
196cdf0e10cSrcweir 	}
197cdf0e10cSrcweir 	pDic = aDics.getConstArray();
198cdf0e10cSrcweir 	nCount = (sal_uInt16) aDics.getLength();
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 	EndDialog( RET_OK );
202cdf0e10cSrcweir 	return 0;
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir // -----------------------------------------------------------------------
206cdf0e10cSrcweir 
207cdf0e10cSrcweir IMPL_LINK_INLINE_START( SvxNewDictionaryDialog, ModifyHdl_Impl, Edit *, EMPTYARG )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir 	if ( aNameEdit.GetText().Len() )
210cdf0e10cSrcweir 		aOKBtn.Enable();
211cdf0e10cSrcweir 	else
212cdf0e10cSrcweir 		aOKBtn.Disable();
213cdf0e10cSrcweir 	return 0;
214cdf0e10cSrcweir }
215cdf0e10cSrcweir IMPL_LINK_INLINE_END( SvxNewDictionaryDialog, ModifyHdl_Impl, Edit *, EMPTYARG )
216cdf0e10cSrcweir 
217cdf0e10cSrcweir //==========================================================================
218cdf0e10cSrcweir //
219cdf0e10cSrcweir // class SvxEditDictionaryDialog -------------------------------------------
220cdf0e10cSrcweir //
221cdf0e10cSrcweir //==========================================================================
222cdf0e10cSrcweir 
223cdf0e10cSrcweir SvxEditDictionaryDialog::SvxEditDictionaryDialog(
224cdf0e10cSrcweir 			Window* pParent,
225cdf0e10cSrcweir 			const String& rName,
226cdf0e10cSrcweir 			Reference< XSpellChecker1 >  &xSpl ) :
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 	ModalDialog( pParent, CUI_RES( RID_SFXDLG_EDITDICT ) ),
229cdf0e10cSrcweir 
230cdf0e10cSrcweir 	aBookFT			( this, CUI_RES( FT_BOOK ) ),
231cdf0e10cSrcweir 	aAllDictsLB		( this, CUI_RES( LB_ALLDICTS ) ),
232cdf0e10cSrcweir 	aLangFT			( this, CUI_RES( FT_DICTLANG ) ),
233cdf0e10cSrcweir 	aLangLB			( this, CUI_RES( LB_DICTLANG ) ),
234cdf0e10cSrcweir 
235cdf0e10cSrcweir 	aWordFT			( this, CUI_RES( FT_WORD ) ),
236cdf0e10cSrcweir 	aWordED			( this, CUI_RES( ED_WORD ) ),
237cdf0e10cSrcweir 	aReplaceFT		( this, CUI_RES( FT_REPLACE ) ),
238cdf0e10cSrcweir 	aReplaceED		( this, CUI_RES( ED_REPLACE ) ),
239cdf0e10cSrcweir 	aWordsLB		( this, CUI_RES( TLB_REPLACE ) ),
240cdf0e10cSrcweir 	aNewReplacePB	( this, CUI_RES( PB_NEW_REPLACE ) ),
241cdf0e10cSrcweir 	aDeletePB		( this, CUI_RES( PB_DELETE_REPLACE ) ),
242cdf0e10cSrcweir 	aEditDictsBox	( this, CUI_RES( GB_EDITDICTS ) ),
243cdf0e10cSrcweir 	aHelpBtn		( this, CUI_RES( BTN_EDITHELP ) ),
244cdf0e10cSrcweir 	aCloseBtn		( this, CUI_RES( BTN_EDITCLOSE ) ),
245cdf0e10cSrcweir 	sModify			(CUI_RES(STR_MODIFY)),
246cdf0e10cSrcweir 	sNew			(aNewReplacePB.GetText()),
247cdf0e10cSrcweir 	aDecoView		( this),
248cdf0e10cSrcweir     xSpell          ( xSpl ),
249cdf0e10cSrcweir     nOld            ( NOACTDICT ),
250cdf0e10cSrcweir     bFirstSelect    (sal_True),
251cdf0e10cSrcweir     bDoNothing      (sal_False)
252cdf0e10cSrcweir 
253cdf0e10cSrcweir {
254cdf0e10cSrcweir 	if (SvxGetDictionaryList().is())
255cdf0e10cSrcweir 		aDics = SvxGetDictionaryList()->getDictionaries();
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 	aWordsLB.SetSelectHdl(LINK(this, SvxEditDictionaryDialog, SelectHdl));
258cdf0e10cSrcweir 	aWordsLB.SetTabs(nStaticTabs);
259cdf0e10cSrcweir 
260cdf0e10cSrcweir 	//! we use an algorithm of our own to insert elements sorted
261cdf0e10cSrcweir 	aWordsLB.SetStyle(aWordsLB.GetStyle()|/*WB_SORT|*/WB_HSCROLL|WB_CLIPCHILDREN);
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 	nWidth=aWordED.GetSizePixel().Width();
265cdf0e10cSrcweir 	// Handler installieren
266cdf0e10cSrcweir 	aNewReplacePB.SetClickHdl(
267cdf0e10cSrcweir 		LINK( this, SvxEditDictionaryDialog, NewDelHdl));
268cdf0e10cSrcweir 	aDeletePB.SetClickHdl(
269cdf0e10cSrcweir 		LINK( this, SvxEditDictionaryDialog, NewDelHdl));
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 	aLangLB.SetSelectHdl(
272cdf0e10cSrcweir 		LINK( this, SvxEditDictionaryDialog, SelectLangHdl_Impl ) );
273cdf0e10cSrcweir 	aAllDictsLB.SetSelectHdl(
274cdf0e10cSrcweir 		LINK( this, SvxEditDictionaryDialog, SelectBookHdl_Impl ) );
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 	aWordED.SetModifyHdl(LINK(this, SvxEditDictionaryDialog, ModifyHdl));
277cdf0e10cSrcweir 	aReplaceED.SetModifyHdl(LINK(this, SvxEditDictionaryDialog, ModifyHdl));
278cdf0e10cSrcweir 	aWordED.SetActionHdl(LINK(this, SvxEditDictionaryDialog, NewDelHdl));
279cdf0e10cSrcweir 	aReplaceED.SetActionHdl(LINK(this, SvxEditDictionaryDialog, NewDelHdl));
280cdf0e10cSrcweir 
281cdf0e10cSrcweir 	// Listbox mit allen verfuegbaren WB's fuellen
282cdf0e10cSrcweir 	const Reference< XDictionary >  *pDic = aDics.getConstArray();
283cdf0e10cSrcweir 	sal_Int32 nCount = aDics.getLength();
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 	String aLookUpEntry;
286cdf0e10cSrcweir 	for ( sal_Int32 i = 0; i < nCount; ++i )
287cdf0e10cSrcweir 	{
288cdf0e10cSrcweir         Reference< XDictionary >  xDic( pDic[i], UNO_QUERY );
289cdf0e10cSrcweir 		if (xDic.is())
290cdf0e10cSrcweir 		{
291cdf0e10cSrcweir 			sal_Bool bNegative = xDic->getDictionaryType() == DictionaryType_NEGATIVE ?
292cdf0e10cSrcweir 								sal_True : sal_False;
293cdf0e10cSrcweir 			String aDicName( xDic->getName() );
294cdf0e10cSrcweir             const String aTxt( ::GetDicInfoStr( aDicName, SvxLocaleToLanguage( xDic->getLocale() ),
295cdf0e10cSrcweir 												 bNegative ) );
296cdf0e10cSrcweir 			aAllDictsLB.InsertEntry( aTxt );
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 			if (rName == aDicName)
299cdf0e10cSrcweir 				aLookUpEntry = aTxt;
300cdf0e10cSrcweir 		}
301cdf0e10cSrcweir 	}
302cdf0e10cSrcweir 
303cdf0e10cSrcweir 	aLangLB.SetLanguageList( LANG_LIST_ALL, sal_True, sal_True );
304cdf0e10cSrcweir 
305cdf0e10cSrcweir 	aReplaceED.SetSpaces(sal_True);
306cdf0e10cSrcweir 	aWordED.SetSpaces(sal_True);
307cdf0e10cSrcweir 
308cdf0e10cSrcweir 	if ( nCount > 0 )
309cdf0e10cSrcweir 	{
310cdf0e10cSrcweir 		aAllDictsLB.SelectEntry( aLookUpEntry );
311cdf0e10cSrcweir 		sal_uInt16 nPos = aAllDictsLB.GetSelectEntryPos();
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 		if ( nPos == LISTBOX_ENTRY_NOTFOUND )
314cdf0e10cSrcweir 		{
315cdf0e10cSrcweir 			nPos = 0;
316cdf0e10cSrcweir 			aAllDictsLB.SelectEntryPos( nPos );
317cdf0e10cSrcweir 		}
318cdf0e10cSrcweir         Reference< XDictionary >  xDic;
319cdf0e10cSrcweir 		if (nPos != LISTBOX_ENTRY_NOTFOUND)
320cdf0e10cSrcweir             xDic = Reference< XDictionary > ( aDics.getConstArray()[ nPos ], UNO_QUERY );
321cdf0e10cSrcweir 		if (xDic.is())
322cdf0e10cSrcweir             SetLanguage_Impl( SvxLocaleToLanguage( xDic->getLocale() ) );
323cdf0e10cSrcweir 
324cdf0e10cSrcweir 		// check if dictionary is read-only
325cdf0e10cSrcweir 		SetDicReadonly_Impl(xDic);
326cdf0e10cSrcweir 		sal_Bool bEnable = !IsDicReadonly_Impl();
327cdf0e10cSrcweir 		aNewReplacePB   .Enable( sal_False );
328cdf0e10cSrcweir 		aDeletePB		.Enable( sal_False );
329cdf0e10cSrcweir 		aLangFT.Enable( bEnable );
330cdf0e10cSrcweir 		aLangLB.Enable( bEnable );
331cdf0e10cSrcweir 		ShowWords_Impl( nPos );
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 	}
334cdf0e10cSrcweir 	else
335cdf0e10cSrcweir 	{
336cdf0e10cSrcweir 		aNewReplacePB.Disable();
337cdf0e10cSrcweir 		aDeletePB	 .Disable();
338cdf0e10cSrcweir 	}
339cdf0e10cSrcweir 	FreeResource();
340cdf0e10cSrcweir }
341cdf0e10cSrcweir 
342cdf0e10cSrcweir // -----------------------------------------------------------------------
343cdf0e10cSrcweir 
344cdf0e10cSrcweir SvxEditDictionaryDialog::~SvxEditDictionaryDialog()
345cdf0e10cSrcweir {
346cdf0e10cSrcweir }
347cdf0e10cSrcweir 
348cdf0e10cSrcweir // -----------------------------------------------------------------------
349cdf0e10cSrcweir 
350cdf0e10cSrcweir void SvxEditDictionaryDialog::Paint( const Rectangle& rRect )
351cdf0e10cSrcweir {
352cdf0e10cSrcweir 	ModalDialog::Paint(rRect );
353cdf0e10cSrcweir 
354cdf0e10cSrcweir 	Rectangle aRect(aEditDictsBox.GetPosPixel(),aEditDictsBox.GetSizePixel());
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 	sal_uInt16 nStyle=BUTTON_DRAW_NOFILL;
357cdf0e10cSrcweir 	aDecoView.DrawButton( aRect, nStyle);
358cdf0e10cSrcweir }
359cdf0e10cSrcweir 
360cdf0e10cSrcweir // -----------------------------------------------------------------------
361cdf0e10cSrcweir 
362cdf0e10cSrcweir void SvxEditDictionaryDialog::SetDicReadonly_Impl(
363cdf0e10cSrcweir             Reference< XDictionary >  &xDic )
364cdf0e10cSrcweir {
365cdf0e10cSrcweir 	// enable or disable new and delete button according to file attributes
366cdf0e10cSrcweir 	bDicIsReadonly = sal_True;
367cdf0e10cSrcweir 	if (xDic.is())
368cdf0e10cSrcweir 	{
369cdf0e10cSrcweir 		Reference< frame::XStorable >  xStor( xDic, UNO_QUERY );
370cdf0e10cSrcweir 		if (   !xStor.is() 				// non persistent dictionary
371cdf0e10cSrcweir 			|| !xStor->hasLocation()	// not yet persistent
372cdf0e10cSrcweir 			|| !xStor->isReadonly() )
373cdf0e10cSrcweir 		{
374cdf0e10cSrcweir 			bDicIsReadonly = sal_False;
375cdf0e10cSrcweir 		}
376cdf0e10cSrcweir 	}
377cdf0e10cSrcweir }
378cdf0e10cSrcweir 
379cdf0e10cSrcweir // -----------------------------------------------------------------------
380cdf0e10cSrcweir 
381cdf0e10cSrcweir void SvxEditDictionaryDialog::SetLanguage_Impl( util::Language nLanguage )
382cdf0e10cSrcweir {
383cdf0e10cSrcweir 	// select language
384cdf0e10cSrcweir 	aLangLB.SelectLanguage( nLanguage );
385cdf0e10cSrcweir }
386cdf0e10cSrcweir 
387cdf0e10cSrcweir sal_uInt16 SvxEditDictionaryDialog::GetLBInsertPos(const String &rDicWord)
388cdf0e10cSrcweir {
389cdf0e10cSrcweir 	sal_uInt16 nPos = USHRT_MAX;
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 	IntlWrapper aIntlWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
392cdf0e10cSrcweir 	const CollatorWrapper* pCollator = aIntlWrapper.getCollator();
393cdf0e10cSrcweir 	sal_uInt16 j;
394cdf0e10cSrcweir 	for( j = 0; j < aWordsLB.GetEntryCount(); j++ )
395cdf0e10cSrcweir 	{
396cdf0e10cSrcweir 		SvLBoxEntry* pEntry = aWordsLB.GetEntry(j);
397cdf0e10cSrcweir 		DBG_ASSERT( pEntry, "NULL pointer");
398cdf0e10cSrcweir 		String aNormEntry( getNormDicEntry_Impl( rDicWord ) );
399cdf0e10cSrcweir 		StringCompare eCmpRes = (StringCompare)pCollator->
400cdf0e10cSrcweir 			compareString( aNormEntry, getNormDicEntry_Impl( aWordsLB.GetEntryText(pEntry, 0) ) );
401cdf0e10cSrcweir 		if( COMPARE_LESS == eCmpRes )
402cdf0e10cSrcweir 			break;
403cdf0e10cSrcweir 	}
404cdf0e10cSrcweir 	if (j < aWordsLB.GetEntryCount())	// entry found?
405cdf0e10cSrcweir 		nPos = j;
406cdf0e10cSrcweir 
407cdf0e10cSrcweir 	return nPos;
408cdf0e10cSrcweir }
409cdf0e10cSrcweir 
410cdf0e10cSrcweir void SvxEditDictionaryDialog::RemoveDictEntry(SvLBoxEntry* pEntry)
411cdf0e10cSrcweir {
412cdf0e10cSrcweir 	sal_uInt16 nLBPos = aAllDictsLB.GetSelectEntryPos();
413cdf0e10cSrcweir 
414cdf0e10cSrcweir 	if ( pEntry != NULL && nLBPos != LISTBOX_ENTRY_NOTFOUND )
415cdf0e10cSrcweir 	{
416cdf0e10cSrcweir 		String sTmpShort(aWordsLB.GetEntryText(pEntry, 0));
417cdf0e10cSrcweir 
418cdf0e10cSrcweir 		Reference< XDictionary >  xDic = aDics.getConstArray()[ nLBPos ];
419cdf0e10cSrcweir 		if (xDic->remove( sTmpShort ))	// sal_True on success
420cdf0e10cSrcweir 		{
421cdf0e10cSrcweir 			aWordsLB.GetModel()->Remove(pEntry);
422cdf0e10cSrcweir 		}
423cdf0e10cSrcweir 	}
424cdf0e10cSrcweir }
425cdf0e10cSrcweir 
426cdf0e10cSrcweir // -----------------------------------------------------------------------
427cdf0e10cSrcweir 
428cdf0e10cSrcweir IMPL_LINK( SvxEditDictionaryDialog, SelectBookHdl_Impl, ListBox *, EMPTYARG )
429cdf0e10cSrcweir {
430cdf0e10cSrcweir 	sal_uInt16 nPos = aAllDictsLB.GetSelectEntryPos();
431cdf0e10cSrcweir 
432cdf0e10cSrcweir 	if ( nPos != LISTBOX_ENTRY_NOTFOUND )
433cdf0e10cSrcweir 	{
434cdf0e10cSrcweir 		aNewReplacePB.Enable( sal_False );
435cdf0e10cSrcweir 		aDeletePB	 .Enable( sal_False );
436cdf0e10cSrcweir 		// Dictionary anzeigen
437cdf0e10cSrcweir 		ShowWords_Impl( nPos );
438cdf0e10cSrcweir 		// enable or disable new and delete button according to file attributes
439cdf0e10cSrcweir         Reference< XDictionary >  xDic( aDics.getConstArray()[ nPos ], UNO_QUERY );
440cdf0e10cSrcweir 		if (xDic.is())
441cdf0e10cSrcweir             SetLanguage_Impl( SvxLocaleToLanguage( xDic->getLocale() ) );
442cdf0e10cSrcweir 
443cdf0e10cSrcweir 		SetDicReadonly_Impl(xDic);
444cdf0e10cSrcweir 		sal_Bool bEnable = !IsDicReadonly_Impl();
445cdf0e10cSrcweir 		aLangFT.Enable( bEnable );
446cdf0e10cSrcweir 		aLangLB.Enable( bEnable );
447cdf0e10cSrcweir 	}
448cdf0e10cSrcweir 	return 0;
449cdf0e10cSrcweir }
450cdf0e10cSrcweir 
451cdf0e10cSrcweir // -----------------------------------------------------------------------
452cdf0e10cSrcweir 
453cdf0e10cSrcweir IMPL_LINK( SvxEditDictionaryDialog, SelectLangHdl_Impl, ListBox *, EMPTYARG )
454cdf0e10cSrcweir {
455cdf0e10cSrcweir 	sal_uInt16 nDicPos = aAllDictsLB.GetSelectEntryPos();
456cdf0e10cSrcweir 	sal_uInt16 nLang = aLangLB.GetSelectLanguage();
457cdf0e10cSrcweir     Reference< XDictionary >  xDic( aDics.getConstArray()[ nDicPos ], UNO_QUERY );
458cdf0e10cSrcweir     sal_Int16 nOldLang = SvxLocaleToLanguage( xDic->getLocale() );
459cdf0e10cSrcweir 
460cdf0e10cSrcweir 	if ( nLang != nOldLang )
461cdf0e10cSrcweir 	{
462cdf0e10cSrcweir 		QueryBox aBox( this, CUI_RES( RID_SFXQB_SET_LANGUAGE ) );
463cdf0e10cSrcweir 		String sTxt( aBox.GetMessText() );
464cdf0e10cSrcweir 		sTxt.SearchAndReplaceAscii( "%1", aAllDictsLB.GetSelectEntry() );
465cdf0e10cSrcweir 		aBox.SetMessText( sTxt );
466cdf0e10cSrcweir 
467cdf0e10cSrcweir 		if ( aBox.Execute() == RET_YES )
468cdf0e10cSrcweir 		{
469cdf0e10cSrcweir             xDic->setLocale( SvxCreateLocale( nLang ) );
470cdf0e10cSrcweir 			sal_Bool bNegativ = xDic->getDictionaryType() == DictionaryType_NEGATIVE;
471cdf0e10cSrcweir 
472cdf0e10cSrcweir 			const String sName(
473cdf0e10cSrcweir 				::GetDicInfoStr( xDic->getName(),
474cdf0e10cSrcweir                                  SvxLocaleToLanguage( xDic->getLocale() ),
475cdf0e10cSrcweir 								 bNegativ ) );
476cdf0e10cSrcweir 			aAllDictsLB.RemoveEntry( nDicPos );
477cdf0e10cSrcweir 			aAllDictsLB.InsertEntry( sName, nDicPos );
478cdf0e10cSrcweir 			aAllDictsLB.SelectEntryPos( nDicPos );
479cdf0e10cSrcweir 		}
480cdf0e10cSrcweir 		else
481cdf0e10cSrcweir 			SetLanguage_Impl( nOldLang );
482cdf0e10cSrcweir 	}
483cdf0e10cSrcweir 	return 1;
484cdf0e10cSrcweir }
485cdf0e10cSrcweir 
486cdf0e10cSrcweir // -----------------------------------------------------------------------
487cdf0e10cSrcweir 
488cdf0e10cSrcweir void SvxEditDictionaryDialog::ShowWords_Impl( sal_uInt16 nId )
489cdf0e10cSrcweir {
490cdf0e10cSrcweir 	Reference< XDictionary >  xDic = aDics.getConstArray()[ nId ];
491cdf0e10cSrcweir 
492cdf0e10cSrcweir 	nOld = nId;
493cdf0e10cSrcweir 	EnterWait();
494cdf0e10cSrcweir 
495cdf0e10cSrcweir 	String aStr;
496cdf0e10cSrcweir 
497cdf0e10cSrcweir 	aWordED.SetText(aStr);
498cdf0e10cSrcweir 	aReplaceED.SetText(aStr);
499cdf0e10cSrcweir 
500cdf0e10cSrcweir 	if(xDic->getDictionaryType() != DictionaryType_POSITIVE)
501cdf0e10cSrcweir 	{
502cdf0e10cSrcweir 		nStaticTabs[0]=2;
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 		// make controls for replacement text active
505cdf0e10cSrcweir 		if(!aReplaceFT.IsVisible())
506cdf0e10cSrcweir 		{
507cdf0e10cSrcweir 			Size aSize=aWordED.GetSizePixel();
508cdf0e10cSrcweir 			aSize.Width()=nWidth;
509cdf0e10cSrcweir 			aWordED.SetSizePixel(aSize);
510cdf0e10cSrcweir 			aReplaceFT.Show();
511cdf0e10cSrcweir 			aReplaceED.Show();
512cdf0e10cSrcweir 		}
513cdf0e10cSrcweir 	}
514cdf0e10cSrcweir 	else
515cdf0e10cSrcweir 	{
516cdf0e10cSrcweir 		nStaticTabs[0]=1;
517cdf0e10cSrcweir 
518cdf0e10cSrcweir 		// deactivate controls for replacement text
519cdf0e10cSrcweir 		if(aReplaceFT.IsVisible())
520cdf0e10cSrcweir 		{
521cdf0e10cSrcweir 			Size aSize=aWordED.GetSizePixel();
522cdf0e10cSrcweir 			aSize.Width()=aWordsLB.GetSizePixel().Width();
523cdf0e10cSrcweir 			aWordED.SetSizePixel(aSize);
524cdf0e10cSrcweir 			aReplaceFT.Hide();
525cdf0e10cSrcweir 			aReplaceED.Hide();
526cdf0e10cSrcweir 		}
527cdf0e10cSrcweir 
528cdf0e10cSrcweir 	}
529cdf0e10cSrcweir 
530cdf0e10cSrcweir 	aWordsLB.SetTabs(nStaticTabs);
531cdf0e10cSrcweir 	aWordsLB.Clear();
532cdf0e10cSrcweir 
533cdf0e10cSrcweir 	Sequence< Reference< XDictionaryEntry >  > aEntries( xDic->getEntries() );
534cdf0e10cSrcweir 	const Reference< XDictionaryEntry >  *pEntry = aEntries.getConstArray();
535cdf0e10cSrcweir 	sal_Int32 nCount = aEntries.getLength();
536cdf0e10cSrcweir 
537cdf0e10cSrcweir 	for (sal_Int32 i = 0;  i < nCount;  i++)
538cdf0e10cSrcweir 	{
539cdf0e10cSrcweir 		aStr = String(pEntry[i]->getDictionaryWord());
540cdf0e10cSrcweir 		sal_uInt16 nPos = GetLBInsertPos( aStr );
541cdf0e10cSrcweir 		if(pEntry[i]->isNegative())
542cdf0e10cSrcweir 		{
543cdf0e10cSrcweir 			aStr += '\t';
544cdf0e10cSrcweir 			aStr += String(pEntry[i]->getReplacementText());
545cdf0e10cSrcweir 		}
546cdf0e10cSrcweir         aWordsLB.InsertEntry(aStr, 0, sal_False, nPos == USHRT_MAX ?  LIST_APPEND : nPos);
547cdf0e10cSrcweir 	}
548cdf0e10cSrcweir 
549cdf0e10cSrcweir 	if (aWordsLB.GetEntryCount())
550cdf0e10cSrcweir 	{
551cdf0e10cSrcweir 		aWordED	  .SetText( aWordsLB.GetEntryText(0LU, 0) );
552cdf0e10cSrcweir 		aReplaceED.SetText( aWordsLB.GetEntryText(0LU, 1) );
553cdf0e10cSrcweir 	}
554cdf0e10cSrcweir 
555cdf0e10cSrcweir 	LeaveWait();
556cdf0e10cSrcweir }
557cdf0e10cSrcweir 
558cdf0e10cSrcweir // -----------------------------------------------------------------------
559cdf0e10cSrcweir 
560cdf0e10cSrcweir IMPL_LINK(SvxEditDictionaryDialog, SelectHdl, SvTabListBox*, pBox)
561cdf0e10cSrcweir {
562cdf0e10cSrcweir 	if(!bDoNothing)
563cdf0e10cSrcweir 	{
564cdf0e10cSrcweir 		if(!bFirstSelect)
565cdf0e10cSrcweir 		{
566cdf0e10cSrcweir 			SvLBoxEntry* pEntry = pBox->FirstSelected();
567cdf0e10cSrcweir 			String sTmpShort(pBox->GetEntryText(pEntry, 0));
568cdf0e10cSrcweir 			// wird der Text ueber den ModifyHdl gesetzt, dann steht der Cursor
569cdf0e10cSrcweir 			//sonst immer am Wortanfang, obwohl man gerade hier editiert
570cdf0e10cSrcweir 			if(aWordED.GetText() != sTmpShort)
571cdf0e10cSrcweir 				aWordED.SetText(sTmpShort);
572cdf0e10cSrcweir 			aReplaceED.SetText(pBox->GetEntryText(pEntry, 1));
573cdf0e10cSrcweir 		}
574cdf0e10cSrcweir 		else
575cdf0e10cSrcweir 			bFirstSelect = sal_False;
576cdf0e10cSrcweir 
577cdf0e10cSrcweir 		// entries in the list box should exactly correspond to those from the
578cdf0e10cSrcweir 		// dictionary. Thus:
579cdf0e10cSrcweir 		aNewReplacePB.Enable(sal_False);
580cdf0e10cSrcweir 		aDeletePB	 .Enable( sal_True && !IsDicReadonly_Impl() );
581cdf0e10cSrcweir 	}
582cdf0e10cSrcweir 	return 0;
583cdf0e10cSrcweir };
584cdf0e10cSrcweir 
585cdf0e10cSrcweir // -----------------------------------------------------------------------
586cdf0e10cSrcweir 
587cdf0e10cSrcweir IMPL_LINK(SvxEditDictionaryDialog, NewDelHdl, PushButton*, pBtn)
588cdf0e10cSrcweir {
589cdf0e10cSrcweir 	SvLBoxEntry* pEntry = aWordsLB.FirstSelected();
590cdf0e10cSrcweir 
591cdf0e10cSrcweir 	if(pBtn == &aDeletePB)
592cdf0e10cSrcweir 	{
593cdf0e10cSrcweir 		DBG_ASSERT(pEntry, "keine Eintrag selektiert");
594cdf0e10cSrcweir 		String aStr;
595cdf0e10cSrcweir 
596cdf0e10cSrcweir 		aWordED.SetText(aStr);
597cdf0e10cSrcweir 		aReplaceED.SetText(aStr);
598cdf0e10cSrcweir 		aDeletePB.Disable();
599cdf0e10cSrcweir 
600cdf0e10cSrcweir 		RemoveDictEntry(pEntry);	// remove entry from dic and list-box
601cdf0e10cSrcweir 	}
602cdf0e10cSrcweir 	if(pBtn == &aNewReplacePB || aNewReplacePB.IsEnabled())
603cdf0e10cSrcweir 	{
604cdf0e10cSrcweir         SvLBoxEntry* _pEntry = aWordsLB.FirstSelected();
605cdf0e10cSrcweir 		XubString aNewWord(aWordED.GetText());
606cdf0e10cSrcweir 		String sEntry(aNewWord);
607cdf0e10cSrcweir 		XubString aReplaceStr(aReplaceED.GetText());
608cdf0e10cSrcweir 
609cdf0e10cSrcweir 		sal_Int16 nAddRes = DIC_ERR_UNKNOWN;
610cdf0e10cSrcweir 		sal_uInt16 nPos = aAllDictsLB.GetSelectEntryPos();
611cdf0e10cSrcweir 		if ( nPos != LISTBOX_ENTRY_NOTFOUND && aNewWord.Len() > 0)
612cdf0e10cSrcweir 		{
613cdf0e10cSrcweir 			DBG_ASSERT(nPos < aDics.getLength(), "invalid dictionary index");
614cdf0e10cSrcweir             Reference< XDictionary >  xDic( aDics.getConstArray()[ nPos ], UNO_QUERY );
615cdf0e10cSrcweir 			if (xDic.is())
616cdf0e10cSrcweir 			{
617cdf0e10cSrcweir 				// make changes in dic
618cdf0e10cSrcweir 
619cdf0e10cSrcweir 				//! ...IsVisible should reflect wether the dictionary is a negativ
620cdf0e10cSrcweir 				//! or not (hopefully...)
621cdf0e10cSrcweir 				sal_Bool bIsNegEntry = aReplaceFT.IsVisible();
622cdf0e10cSrcweir 				::rtl::OUString aRplcText;
623cdf0e10cSrcweir 				if(bIsNegEntry)
624cdf0e10cSrcweir 					aRplcText = aReplaceStr;
625cdf0e10cSrcweir 
626cdf0e10cSrcweir                 if (_pEntry) // entry selected in aWordsLB ie action = modify entry
627cdf0e10cSrcweir                     xDic->remove( aWordsLB.GetEntryText( _pEntry, 0 ) );
628cdf0e10cSrcweir 				// if remove has failed the following add should fail too
629cdf0e10cSrcweir 				// and thus a warning message should be triggered...
630cdf0e10cSrcweir 
631cdf0e10cSrcweir                 Reference<XDictionary> aXDictionary(xDic, UNO_QUERY);
632cdf0e10cSrcweir                 nAddRes = linguistic::AddEntryToDic( aXDictionary,
633cdf0e10cSrcweir 							aNewWord, bIsNegEntry,
634cdf0e10cSrcweir                             aRplcText, SvxLocaleToLanguage( xDic->getLocale() ), sal_False );
635cdf0e10cSrcweir  			}
636cdf0e10cSrcweir 		}
637cdf0e10cSrcweir 		if (DIC_ERR_NONE != nAddRes)
638cdf0e10cSrcweir 			SvxDicError( this, nAddRes );
639cdf0e10cSrcweir 
640cdf0e10cSrcweir 		if(DIC_ERR_NONE == nAddRes && sEntry.Len())
641cdf0e10cSrcweir 		{
642cdf0e10cSrcweir 			// insert new entry in list-box etc...
643cdf0e10cSrcweir 
644cdf0e10cSrcweir 			aWordsLB.SetUpdateMode(sal_False);
645cdf0e10cSrcweir             sal_uInt16 _nPos = USHRT_MAX;
646cdf0e10cSrcweir 
647cdf0e10cSrcweir 			if(aReplaceFT.IsVisible())
648cdf0e10cSrcweir 			{
649cdf0e10cSrcweir 				sEntry += '\t';
650cdf0e10cSrcweir 				sEntry += aReplaceStr;
651cdf0e10cSrcweir 			}
652cdf0e10cSrcweir 
653cdf0e10cSrcweir 			SvLBoxEntry* pNewEntry = NULL;
654cdf0e10cSrcweir             if(_pEntry) // entry selected in aWordsLB ie action = modify entry
655cdf0e10cSrcweir 			{
656cdf0e10cSrcweir                 aWordsLB.SetEntryText( sEntry, _pEntry );
657cdf0e10cSrcweir                 pNewEntry = _pEntry;
658cdf0e10cSrcweir 			}
659cdf0e10cSrcweir 			else
660cdf0e10cSrcweir 			{
661cdf0e10cSrcweir                 _nPos = GetLBInsertPos( aNewWord );
662cdf0e10cSrcweir                 SvLBoxEntry* pInsEntry = aWordsLB.InsertEntry(sEntry, 0, sal_False,
663cdf0e10cSrcweir                             _nPos == USHRT_MAX ? LIST_APPEND : (sal_uInt32)_nPos);
664cdf0e10cSrcweir 				pNewEntry = pInsEntry;
665cdf0e10cSrcweir 			}
666cdf0e10cSrcweir 
667cdf0e10cSrcweir 			aWordsLB.MakeVisible( pNewEntry );
668cdf0e10cSrcweir 			aWordsLB.SetUpdateMode(sal_True);
669cdf0e10cSrcweir 			// falls der Request aus dem ReplaceEdit kam, dann Focus in das ShortEdit setzen
670cdf0e10cSrcweir 			if(aReplaceED.HasFocus())
671cdf0e10cSrcweir 				aWordED.GrabFocus();
672cdf0e10cSrcweir 		}
673cdf0e10cSrcweir 	}
674cdf0e10cSrcweir 	else
675cdf0e10cSrcweir 	{
676cdf0e10cSrcweir 		// das kann nur ein Enter in einem der beiden Edit-Felder sein und das
677cdf0e10cSrcweir 		// bedeutet EndDialog() - muss im KeyInput ausgewertet werden
678cdf0e10cSrcweir 		return 0;
679cdf0e10cSrcweir 	}
680cdf0e10cSrcweir 	ModifyHdl(&aWordED);
681cdf0e10cSrcweir 	return 1;
682cdf0e10cSrcweir }
683cdf0e10cSrcweir 
684cdf0e10cSrcweir // -----------------------------------------------------------------------
685cdf0e10cSrcweir 
686cdf0e10cSrcweir IMPL_LINK(SvxEditDictionaryDialog, ModifyHdl, Edit*, pEdt)
687cdf0e10cSrcweir {
688cdf0e10cSrcweir 	SvLBoxEntry* pFirstSel = aWordsLB.FirstSelected();
689cdf0e10cSrcweir 	String rEntry = pEdt->GetText();
690cdf0e10cSrcweir 
691cdf0e10cSrcweir 	xub_StrLen nWordLen=rEntry.Len();
692cdf0e10cSrcweir 	const String& rRepString = aReplaceED.GetText();
693cdf0e10cSrcweir 
694cdf0e10cSrcweir 	sal_Bool bEnableNewReplace	= sal_False;
695cdf0e10cSrcweir 	sal_Bool bEnableDelete		= sal_False;
696cdf0e10cSrcweir 	String aNewReplaceText	= sNew;
697cdf0e10cSrcweir 
698cdf0e10cSrcweir 	if(pEdt == &aWordED)
699cdf0e10cSrcweir 	{
700cdf0e10cSrcweir 		if(nWordLen>0)
701cdf0e10cSrcweir 		{
702cdf0e10cSrcweir 			sal_Bool bFound = sal_False;
703cdf0e10cSrcweir 			sal_Bool bTmpSelEntry=sal_False;
704cdf0e10cSrcweir 			CDE_RESULT eCmpRes = CDE_DIFFERENT;
705cdf0e10cSrcweir 
706cdf0e10cSrcweir 			for(sal_uInt16 i = 0; i < aWordsLB.GetEntryCount(); i++)
707cdf0e10cSrcweir 			{
708cdf0e10cSrcweir 				SvLBoxEntry*  pEntry = aWordsLB.GetEntry( i );
709cdf0e10cSrcweir 				String aTestStr( aWordsLB.GetEntryText(pEntry, 0) );
710cdf0e10cSrcweir 				eCmpRes = cmpDicEntry_Impl( rEntry, aTestStr );
711cdf0e10cSrcweir 				if(CDE_DIFFERENT != eCmpRes)
712cdf0e10cSrcweir 				{
713cdf0e10cSrcweir 					if(rRepString.Len())
714cdf0e10cSrcweir 						bFirstSelect = sal_True;
715cdf0e10cSrcweir 					bDoNothing=sal_True;
716cdf0e10cSrcweir 					aWordsLB.SetCurEntry(pEntry);
717cdf0e10cSrcweir 					bDoNothing=sal_False;
718cdf0e10cSrcweir 					pFirstSel = pEntry;
719cdf0e10cSrcweir 					aReplaceED.SetText(aWordsLB.GetEntryText(pEntry, 1));
720cdf0e10cSrcweir 
721cdf0e10cSrcweir 					if (CDE_SIMILAR == eCmpRes)
722cdf0e10cSrcweir 					{
723cdf0e10cSrcweir 						aNewReplaceText = sModify;
724cdf0e10cSrcweir 						bEnableNewReplace = sal_True;
725cdf0e10cSrcweir 					}
726cdf0e10cSrcweir 					bFound= sal_True;
727cdf0e10cSrcweir 					break;
728cdf0e10cSrcweir 				}
729cdf0e10cSrcweir 				else if(getNormDicEntry_Impl(aTestStr).Search(
730cdf0e10cSrcweir 							getNormDicEntry_Impl( rEntry ) ) == 0
731cdf0e10cSrcweir 						&& !bTmpSelEntry)
732cdf0e10cSrcweir 				{
733cdf0e10cSrcweir 					bDoNothing=sal_True;
734cdf0e10cSrcweir 					aWordsLB.MakeVisible(pEntry);
735cdf0e10cSrcweir 					bDoNothing=sal_False;
736cdf0e10cSrcweir 					bTmpSelEntry=sal_True;
737cdf0e10cSrcweir 
738cdf0e10cSrcweir 					aNewReplaceText = sNew;
739cdf0e10cSrcweir 					bEnableNewReplace = sal_True;
740cdf0e10cSrcweir 				}
741cdf0e10cSrcweir 			}
742cdf0e10cSrcweir 
743cdf0e10cSrcweir 			if(!bFound)
744cdf0e10cSrcweir 			{
745cdf0e10cSrcweir 				aWordsLB.SelectAll(sal_False);
746cdf0e10cSrcweir 				pFirstSel = 0;
747cdf0e10cSrcweir 
748cdf0e10cSrcweir 				aNewReplaceText = sNew;
749cdf0e10cSrcweir 				bEnableNewReplace = sal_True;
750cdf0e10cSrcweir 			}
751cdf0e10cSrcweir 			bEnableDelete = CDE_DIFFERENT != eCmpRes;
752cdf0e10cSrcweir 		}
753cdf0e10cSrcweir 		else if(aWordsLB.GetEntryCount()>0)
754cdf0e10cSrcweir 		{
755cdf0e10cSrcweir 			SvLBoxEntry*  pEntry = aWordsLB.GetEntry( 0 );
756cdf0e10cSrcweir 			bDoNothing=sal_True;
757cdf0e10cSrcweir 			aWordsLB.MakeVisible(pEntry);
758cdf0e10cSrcweir 			bDoNothing=sal_False;
759cdf0e10cSrcweir 		}
760cdf0e10cSrcweir 	}
761cdf0e10cSrcweir 	else if(pEdt == &aReplaceED)
762cdf0e10cSrcweir 	{
763cdf0e10cSrcweir 		String aReplaceText;
764cdf0e10cSrcweir 		String aWordText;
765cdf0e10cSrcweir 		if (pFirstSel)	// a aWordsLB entry is selected
766cdf0e10cSrcweir 		{
767cdf0e10cSrcweir 			aWordText	 = aWordsLB.GetEntryText( pFirstSel, 0 );
768cdf0e10cSrcweir  			aReplaceText = aWordsLB.GetEntryText( pFirstSel, 1 );
769cdf0e10cSrcweir 
770cdf0e10cSrcweir 			aNewReplaceText = sModify;
771cdf0e10cSrcweir 			bEnableDelete = sal_True;
772cdf0e10cSrcweir 		}
773cdf0e10cSrcweir 		sal_Bool bIsChange =
774cdf0e10cSrcweir 				CDE_EQUAL != cmpDicEntry_Impl(aWordED.GetText(), aWordText)
775cdf0e10cSrcweir 			 || CDE_EQUAL != cmpDicEntry_Impl(aReplaceED.GetText(), aReplaceText);
776cdf0e10cSrcweir 		if (aWordED.GetText().Len()  &&  bIsChange)
777cdf0e10cSrcweir 			bEnableNewReplace = sal_True;
778cdf0e10cSrcweir 	}
779cdf0e10cSrcweir 
780cdf0e10cSrcweir 	aNewReplacePB.SetText( aNewReplaceText );
781cdf0e10cSrcweir 	aNewReplacePB.Enable( bEnableNewReplace && !IsDicReadonly_Impl() );
782cdf0e10cSrcweir 	aDeletePB	 .Enable( bEnableDelete     && !IsDicReadonly_Impl() );
783cdf0e10cSrcweir 
784cdf0e10cSrcweir 	return 0;
785cdf0e10cSrcweir }
786cdf0e10cSrcweir 
787cdf0e10cSrcweir //=========================================================
788cdf0e10cSrcweir //SvxDictEdit
789cdf0e10cSrcweir //=========================================================
790cdf0e10cSrcweir void SvxDictEdit::KeyInput( const KeyEvent& rKEvt )
791cdf0e10cSrcweir {
792cdf0e10cSrcweir 	const KeyCode aKeyCode = rKEvt.GetKeyCode();
793cdf0e10cSrcweir 	const sal_uInt16 nModifier = aKeyCode.GetModifier();
794cdf0e10cSrcweir 	if( aKeyCode.GetCode() == KEY_RETURN )
795cdf0e10cSrcweir 	{
796cdf0e10cSrcweir 		//wird bei Enter nichts getan, dann doch die Basisklasse rufen
797cdf0e10cSrcweir 		// um den Dialog zu schliessen
798cdf0e10cSrcweir 		if(!nModifier && !aActionLink.Call(this))
799cdf0e10cSrcweir 				 Edit::KeyInput(rKEvt);
800cdf0e10cSrcweir 	}
801cdf0e10cSrcweir 	else if(bSpaces || aKeyCode.GetCode() != KEY_SPACE)
802cdf0e10cSrcweir 		Edit::KeyInput(rKEvt);
803cdf0e10cSrcweir }
804cdf0e10cSrcweir 
805cdf0e10cSrcweir 
806