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