1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: optdict.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
38 // include ---------------------------------------------------------------
39 #include <tools/shl.hxx>
42 #include <unolingu.hxx>
43 #include <dlgutil.hxx>
44 #include <sfx2/sfxuno.hxx>
45 #include <svtools/eitem.hxx>
46 #include <com/sun/star/frame/XStorable.hpp>
47 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
48 #include <comphelper/processfactory.hxx>
50 #include <unotools/intlwrapper.hxx>
51 #include <vcl/svapp.hxx>
52 #include <vcl/msgbox.hxx>
54 #define _SVX_OPTDICT_CXX
56 #ifndef _LINGUISTIC_MISC_HHX_
57 #include <linguistic/misc.hxx>
59 #include <svx/dialogs.hrc>
60 #include "optdict.hrc"
64 #include "optdict.hxx"
65 #include <svx/dialmgr.hxx>
68 using namespace ::com::sun::star
;
69 using namespace ::com::sun::star::uno
;
70 using namespace ::com::sun::star::linguistic2
;
72 // static ----------------------------------------------------------------
74 static const sal_uInt16 nNameLen
= 8;
75 static const short NOACTDICT
= -1;
77 static long nStaticTabs
[]=
82 // static function -------------------------------------------------------
84 static String
getNormDicEntry_Impl( const String
&rText
)
87 aTmp
.EraseTrailingChars( '.' );
88 aTmp
.EraseAllChars( '=' );
93 // Compare Dictionary Entry result
94 enum CDE_RESULT
{ CDE_EQUAL
, CDE_SIMILAR
, CDE_DIFFERENT
};
96 static CDE_RESULT
cmpDicEntry_Impl( const String
&rText1
, const String
&rText2
)
98 CDE_RESULT eRes
= CDE_DIFFERENT
;
100 if (rText1
== rText2
)
103 { // similar = equal up to trailing '.' and hyphenation positions
105 if (getNormDicEntry_Impl( rText1
) == getNormDicEntry_Impl( rText2
))
112 // class SvxNewDictionaryDialog -------------------------------------------
114 SvxNewDictionaryDialog::SvxNewDictionaryDialog( Window
* pParent
,
115 Reference
< XSpellChecker1
> &xSpl
) :
117 ModalDialog( pParent
, SVX_RES( RID_SFXDLG_NEWDICT
) ),
119 aNameText ( this, SVX_RES( FT_DICTNAME
) ),
120 aNameEdit ( this, SVX_RES( ED_DICTNAME
) ),
121 aLanguageText ( this, SVX_RES( FT_DICTLANG
) ),
122 aLanguageLB ( this, SVX_RES( LB_DICTLANG
) ),
123 aExceptBtn ( this, SVX_RES( BTN_EXCEPT
) ),
124 aNewDictBox ( this, SVX_RES( GB_NEWDICT
) ),
125 aOKBtn ( this, SVX_RES( BTN_NEWDICT_OK
) ),
126 aCancelBtn ( this, SVX_RES( BTN_NEWDICT_ESC
) ),
127 aHelpBtn ( this, SVX_RES( BTN_NEWDICT_HLP
) ),
130 // Handler installieren
131 aNameEdit
.SetModifyHdl(
132 LINK( this, SvxNewDictionaryDialog
, ModifyHdl_Impl
) );
133 aOKBtn
.SetClickHdl( LINK( this, SvxNewDictionaryDialog
, OKHdl_Impl
) );
136 aLanguageLB
.SetLanguageList( LANG_LIST_ALL
, TRUE
, TRUE
);
137 aLanguageLB
.SelectEntryPos(0);
142 // -----------------------------------------------------------------------
144 IMPL_LINK( SvxNewDictionaryDialog
, OKHdl_Impl
, Button
*, EMPTYARG
)
146 String sDict
= aNameEdit
.GetText();
147 sDict
.EraseTrailingChars();
148 // add extension for personal dictionaries
149 sDict
.AppendAscii(".dic");
151 Reference
< XDictionaryList
> xDicList( SvxGetDictionaryList() );
153 Sequence
< Reference
< XDictionary
> > aDics
;
155 aDics
= xDicList
->getDictionaries();
156 const Reference
< XDictionary
> *pDic
= aDics
.getConstArray();
157 sal_Int32 nCount
= (sal_uInt16
) aDics
.getLength();
159 sal_Bool bFound
= sal_False
;
161 for (i
= 0; !bFound
&& i
< nCount
; ++i
)
162 if ( sDict
.EqualsIgnoreCaseAscii( String(pDic
[i
]->getName()) ))
168 InfoBox( this, SVX_RESSTR( RID_SVXSTR_OPT_DOUBLE_DICTS
) ).Execute();
169 aNameEdit
.GrabFocus();
173 // Erzeugen und hinzufuegen
174 sal_uInt16 nLang
= aLanguageLB
.GetSelectLanguage();
177 // create new dictionary
178 DictionaryType eType
= aExceptBtn
.IsChecked() ?
179 DictionaryType_NEGATIVE
: DictionaryType_POSITIVE
;
182 lang::Locale
aLocale( SvxCreateLocale(nLang
) );
183 String
aURL( linguistic::GetWritableDictionaryURL( sDict
) );
184 xNewDic
= Reference
< XDictionary
> (
185 xDicList
->createDictionary( sDict
, aLocale
, eType
, aURL
) , UNO_QUERY
);
187 DBG_ASSERT(xNewDic
.is(), "NULL pointer");
193 // Fehler: konnte neues W"orterbuch nicht anlegen
194 SfxErrorContext
aContext( ERRCTX_SVX_LINGU_DICTIONARY
, String(),
195 this, RID_SVXERRCTX
, &DIALOG_MGR() );
196 ErrorHandler::HandleError( *new StringErrorInfo(
197 ERRCODE_SVX_LINGU_DICT_NOTWRITEABLE
, sDict
) );
199 EndDialog( RET_CANCEL
);
202 if (xDicList
.is() && xNewDic
.is())
204 xDicList
->addDictionary( Reference
< XDictionary
> ( xNewDic
, UNO_QUERY
) );
206 // refresh list of dictionaries
207 //! dictionaries may have been added/removed elsewhere too.
208 aDics
= xDicList
->getDictionaries();
210 pDic
= aDics
.getConstArray();
211 nCount
= (sal_uInt16
) aDics
.getLength();
218 // -----------------------------------------------------------------------
220 IMPL_LINK_INLINE_START( SvxNewDictionaryDialog
, ModifyHdl_Impl
, Edit
*, EMPTYARG
)
222 if ( aNameEdit
.GetText().Len() )
228 IMPL_LINK_INLINE_END( SvxNewDictionaryDialog
, ModifyHdl_Impl
, Edit
*, EMPTYARG
)
230 //==========================================================================
232 // class SvxEditDictionaryDialog -------------------------------------------
234 //==========================================================================
236 SvxEditDictionaryDialog::SvxEditDictionaryDialog(
239 Reference
< XSpellChecker1
> &xSpl
) :
241 ModalDialog( pParent
, SVX_RES( RID_SFXDLG_EDITDICT
) ),
243 aBookFT ( this, SVX_RES( FT_BOOK
) ),
244 aAllDictsLB ( this, SVX_RES( LB_ALLDICTS
) ),
245 aLangFT ( this, SVX_RES( FT_DICTLANG
) ),
246 aLangLB ( this, SVX_RES( LB_DICTLANG
) ),
247 aWordFT ( this, SVX_RES( FT_WORD
) ),
248 aWordED ( this, SVX_RES( ED_WORD
) ),
249 aReplaceFT ( this, SVX_RES( FT_REPLACE
) ),
250 aReplaceED ( this, SVX_RES( ED_REPLACE
) ),
251 aWordsLB ( this, SVX_RES( TLB_REPLACE
) ),
252 aNewReplacePB ( this, SVX_RES( PB_NEW_REPLACE
) ),
253 aDeletePB ( this, SVX_RES( PB_DELETE_REPLACE
) ),
254 aEditDictsBox ( this, SVX_RES( GB_EDITDICTS
) ),
255 aCloseBtn ( this, SVX_RES( BTN_EDITCLOSE
) ),
256 aHelpBtn ( this, SVX_RES( BTN_EDITHELP
) ),
257 sModify (SVX_RES(STR_MODIFY
)),
258 sNew (aNewReplacePB
.GetText()),
262 bFirstSelect (sal_True
),
263 bDoNothing (sal_False
)
266 if (SvxGetDictionaryList().is())
267 aDics
= SvxGetDictionaryList()->getDictionaries();
269 aWordsLB
.SetSelectHdl(LINK(this, SvxEditDictionaryDialog
, SelectHdl
));
270 aWordsLB
.SetTabs(nStaticTabs
);
272 //! we use an algorithm of our own to insert elements sorted
273 aWordsLB
.SetWindowBits(/*WB_SORT|*/WB_HSCROLL
|WB_CLIPCHILDREN
);
276 nWidth
=aWordED
.GetSizePixel().Width();
277 // Handler installieren
278 aNewReplacePB
.SetClickHdl(
279 LINK( this, SvxEditDictionaryDialog
, NewDelHdl
));
280 aDeletePB
.SetClickHdl(
281 LINK( this, SvxEditDictionaryDialog
, NewDelHdl
));
283 aLangLB
.SetSelectHdl(
284 LINK( this, SvxEditDictionaryDialog
, SelectLangHdl_Impl
) );
285 aAllDictsLB
.SetSelectHdl(
286 LINK( this, SvxEditDictionaryDialog
, SelectBookHdl_Impl
) );
288 aWordED
.SetModifyHdl(LINK(this, SvxEditDictionaryDialog
, ModifyHdl
));
289 aReplaceED
.SetModifyHdl(LINK(this, SvxEditDictionaryDialog
, ModifyHdl
));
290 aWordED
.SetActionHdl(LINK(this, SvxEditDictionaryDialog
, NewDelHdl
));
291 aReplaceED
.SetActionHdl(LINK(this, SvxEditDictionaryDialog
, NewDelHdl
));
293 // Listbox mit allen verfuegbaren WB's fuellen
294 const Reference
< XDictionary
> *pDic
= aDics
.getConstArray();
295 sal_Int32 nCount
= aDics
.getLength();
298 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
300 Reference
< XDictionary
> xDic( pDic
[i
], UNO_QUERY
);
303 sal_Bool bNegative
= xDic
->getDictionaryType() == DictionaryType_NEGATIVE
?
304 sal_True
: sal_False
;
305 String
aDicName( xDic
->getName() );
306 const String
aTxt( ::GetDicInfoStr( aDicName
, SvxLocaleToLanguage( xDic
->getLocale() ),
308 aAllDictsLB
.InsertEntry( aTxt
);
310 if (rName
== aDicName
)
315 aLangLB
.SetLanguageList( LANG_LIST_ALL
, TRUE
, TRUE
);
317 aReplaceED
.SetSpaces(sal_True
);
318 aWordED
.SetSpaces(sal_True
);
322 aAllDictsLB
.SelectEntry( aLookUpEntry
);
323 sal_uInt16 nPos
= aAllDictsLB
.GetSelectEntryPos();
325 if ( nPos
== LISTBOX_ENTRY_NOTFOUND
)
328 aAllDictsLB
.SelectEntryPos( nPos
);
330 Reference
< XDictionary
> xDic
;
331 if (nPos
!= LISTBOX_ENTRY_NOTFOUND
)
332 xDic
= Reference
< XDictionary
> ( aDics
.getConstArray()[ nPos
], UNO_QUERY
);
334 SetLanguage_Impl( SvxLocaleToLanguage( xDic
->getLocale() ) );
336 // check if dictionary is read-only
337 SetDicReadonly_Impl(xDic
);
338 sal_Bool bEnable
= !IsDicReadonly_Impl();
339 aNewReplacePB
.Enable( sal_False
);
340 aDeletePB
.Enable( sal_False
);
341 aLangFT
.Enable( bEnable
);
342 aLangLB
.Enable( bEnable
);
343 ShowWords_Impl( nPos
);
348 aNewReplacePB
.Disable();
349 aDeletePB
.Disable();
354 // -----------------------------------------------------------------------
356 SvxEditDictionaryDialog::~SvxEditDictionaryDialog()
360 // -----------------------------------------------------------------------
362 void SvxEditDictionaryDialog::Paint( const Rectangle
& rRect
)
364 ModalDialog::Paint(rRect
);
366 Rectangle
aRect(aEditDictsBox
.GetPosPixel(),aEditDictsBox
.GetSizePixel());
368 sal_uInt16 nStyle
=BUTTON_DRAW_NOFILL
;
369 aDecoView
.DrawButton( aRect
, nStyle
);
372 // -----------------------------------------------------------------------
374 void SvxEditDictionaryDialog::SetDicReadonly_Impl(
375 Reference
< XDictionary
> &xDic
)
377 // enable or disable new and delete button according to file attributes
378 bDicIsReadonly
= sal_True
;
381 Reference
< frame::XStorable
> xStor( xDic
, UNO_QUERY
);
382 if ( !xStor
.is() // non persistent dictionary
383 || !xStor
->hasLocation() // not yet persistent
384 || !xStor
->isReadonly() )
386 bDicIsReadonly
= sal_False
;
391 // -----------------------------------------------------------------------
393 void SvxEditDictionaryDialog::SetLanguage_Impl( util::Language nLanguage
)
396 aLangLB
.SelectLanguage( nLanguage
);
399 USHORT
SvxEditDictionaryDialog::GetLBInsertPos(const String
&rDicWord
)
401 USHORT nPos
= USHRT_MAX
;
403 IntlWrapper
aIntlWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
404 const CollatorWrapper
* pCollator
= aIntlWrapper
.getCollator();
406 for( j
= 0; j
< aWordsLB
.GetEntryCount(); j
++ )
408 SvLBoxEntry
* pEntry
= aWordsLB
.GetEntry(j
);
409 DBG_ASSERT( pEntry
, "NULL pointer");
410 String
aNormEntry( getNormDicEntry_Impl( rDicWord
) );
411 StringCompare eCmpRes
= (StringCompare
)pCollator
->
412 compareString( aNormEntry
, getNormDicEntry_Impl( aWordsLB
.GetEntryText(pEntry
, 0) ) );
413 if( COMPARE_LESS
== eCmpRes
)
416 if (j
< aWordsLB
.GetEntryCount()) // entry found?
422 void SvxEditDictionaryDialog::RemoveDictEntry(SvLBoxEntry
* pEntry
)
424 sal_uInt16 nLBPos
= aAllDictsLB
.GetSelectEntryPos();
426 if ( pEntry
!= NULL
&& nLBPos
!= LISTBOX_ENTRY_NOTFOUND
)
428 String
sTmpShort(aWordsLB
.GetEntryText(pEntry
, 0));
430 Reference
< XDictionary
> xDic
= aDics
.getConstArray()[ nLBPos
];
431 if (xDic
->remove( sTmpShort
)) // sal_True on success
433 aWordsLB
.GetModel()->Remove(pEntry
);
438 // -----------------------------------------------------------------------
440 IMPL_LINK( SvxEditDictionaryDialog
, SelectBookHdl_Impl
, ListBox
*, EMPTYARG
)
442 sal_uInt16 nPos
= aAllDictsLB
.GetSelectEntryPos();
444 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
446 aNewReplacePB
.Enable( sal_False
);
447 aDeletePB
.Enable( sal_False
);
448 // Dictionary anzeigen
449 ShowWords_Impl( nPos
);
450 // enable or disable new and delete button according to file attributes
451 Reference
< XDictionary
> xDic( aDics
.getConstArray()[ nPos
], UNO_QUERY
);
453 SetLanguage_Impl( SvxLocaleToLanguage( xDic
->getLocale() ) );
455 SetDicReadonly_Impl(xDic
);
456 sal_Bool bEnable
= !IsDicReadonly_Impl();
457 aLangFT
.Enable( bEnable
);
458 aLangLB
.Enable( bEnable
);
463 // -----------------------------------------------------------------------
465 IMPL_LINK( SvxEditDictionaryDialog
, SelectLangHdl_Impl
, ListBox
*, EMPTYARG
)
467 sal_uInt16 nDicPos
= aAllDictsLB
.GetSelectEntryPos();
468 sal_uInt16 nLang
= aLangLB
.GetSelectLanguage();
469 Reference
< XDictionary
> xDic( aDics
.getConstArray()[ nDicPos
], UNO_QUERY
);
470 INT16 nOldLang
= SvxLocaleToLanguage( xDic
->getLocale() );
472 if ( nLang
!= nOldLang
)
474 QueryBox
aBox( this, SVX_RES( RID_SFXQB_SET_LANGUAGE
) );
475 String
sTxt( aBox
.GetMessText() );
476 sTxt
.SearchAndReplaceAscii( "%1", aAllDictsLB
.GetSelectEntry() );
477 aBox
.SetMessText( sTxt
);
479 if ( aBox
.Execute() == RET_YES
)
481 xDic
->setLocale( SvxCreateLocale( nLang
) );
482 sal_Bool bNegativ
= xDic
->getDictionaryType() == DictionaryType_NEGATIVE
;
485 ::GetDicInfoStr( xDic
->getName(),
486 SvxLocaleToLanguage( xDic
->getLocale() ),
488 aAllDictsLB
.RemoveEntry( nDicPos
);
489 aAllDictsLB
.InsertEntry( sName
, nDicPos
);
490 aAllDictsLB
.SelectEntryPos( nDicPos
);
493 SetLanguage_Impl( nOldLang
);
498 // -----------------------------------------------------------------------
500 void SvxEditDictionaryDialog::ShowWords_Impl( sal_uInt16 nId
)
502 Reference
< XDictionary
> xDic
= aDics
.getConstArray()[ nId
];
509 aWordED
.SetText(aStr
);
510 aReplaceED
.SetText(aStr
);
512 if(xDic
->getDictionaryType() != DictionaryType_POSITIVE
)
516 // make controls for replacement text active
517 if(!aReplaceFT
.IsVisible())
519 Size aSize
=aWordED
.GetSizePixel();
520 aSize
.Width()=nWidth
;
521 aWordED
.SetSizePixel(aSize
);
530 // deactivate controls for replacement text
531 if(aReplaceFT
.IsVisible())
533 Size aSize
=aWordED
.GetSizePixel();
534 aSize
.Width()=aWordsLB
.GetSizePixel().Width();
535 aWordED
.SetSizePixel(aSize
);
542 aWordsLB
.SetTabs(nStaticTabs
);
545 Sequence
< Reference
< XDictionaryEntry
> > aEntries( xDic
->getEntries() );
546 const Reference
< XDictionaryEntry
> *pEntry
= aEntries
.getConstArray();
547 sal_Int32 nCount
= aEntries
.getLength();
549 for (sal_Int32 i
= 0; i
< nCount
; i
++)
551 aStr
= String(pEntry
[i
]->getDictionaryWord());
552 USHORT nPos
= GetLBInsertPos( aStr
);
553 if(pEntry
[i
]->isNegative())
556 aStr
+= String(pEntry
[i
]->getReplacementText());
558 aWordsLB
.InsertEntry(aStr
, 0, sal_False
, nPos
== USHRT_MAX
? LIST_APPEND
: nPos
);
561 if (aWordsLB
.GetEntryCount())
563 aWordED
.SetText( aWordsLB
.GetEntryText(0LU, 0) );
564 aReplaceED
.SetText( aWordsLB
.GetEntryText(0LU, 1) );
570 // -----------------------------------------------------------------------
572 IMPL_LINK(SvxEditDictionaryDialog
, SelectHdl
, SvTabListBox
*, pBox
)
578 SvLBoxEntry
* pEntry
= pBox
->FirstSelected();
579 String
sTmpShort(pBox
->GetEntryText(pEntry
, 0));
580 // wird der Text ueber den ModifyHdl gesetzt, dann steht der Cursor
581 //sonst immer am Wortanfang, obwohl man gerade hier editiert
582 if(aWordED
.GetText() != sTmpShort
)
583 aWordED
.SetText(sTmpShort
);
584 aReplaceED
.SetText(pBox
->GetEntryText(pEntry
, 1));
587 bFirstSelect
= sal_False
;
589 // entries in the list box should exactly correspond to those from the
591 aNewReplacePB
.Enable(sal_False
);
592 aDeletePB
.Enable( sal_True
&& !IsDicReadonly_Impl() );
597 // -----------------------------------------------------------------------
599 IMPL_LINK(SvxEditDictionaryDialog
, NewDelHdl
, PushButton
*, pBtn
)
601 SvLBoxEntry
* pEntry
= aWordsLB
.FirstSelected();
603 if(pBtn
== &aDeletePB
)
605 DBG_ASSERT(pEntry
, "keine Eintrag selektiert");
608 aWordED
.SetText(aStr
);
609 aReplaceED
.SetText(aStr
);
612 RemoveDictEntry(pEntry
); // remove entry from dic and list-box
614 if(pBtn
== &aNewReplacePB
|| aNewReplacePB
.IsEnabled())
616 SvLBoxEntry
* _pEntry
= aWordsLB
.FirstSelected();
617 XubString
aNewWord(aWordED
.GetText());
618 String
sEntry(aNewWord
);
619 XubString
aReplaceStr(aReplaceED
.GetText());
621 sal_Int16 nAddRes
= DIC_ERR_UNKNOWN
;
622 sal_uInt16 nPos
= aAllDictsLB
.GetSelectEntryPos();
623 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
&& aNewWord
.Len() > 0)
625 DBG_ASSERT(nPos
< aDics
.getLength(), "invalid dictionary index");
626 Reference
< XDictionary
> xDic( aDics
.getConstArray()[ nPos
], UNO_QUERY
);
629 // make changes in dic
631 //! ...IsVisible should reflect wether the dictionary is a negativ
632 //! or not (hopefully...)
633 sal_Bool bIsNegEntry
= aReplaceFT
.IsVisible();
634 ::rtl::OUString aRplcText
;
636 aRplcText
= aReplaceStr
;
638 if (_pEntry
) // entry selected in aWordsLB ie action = modify entry
639 xDic
->remove( aWordsLB
.GetEntryText( _pEntry
, 0 ) );
640 // if remove has failed the following add should fail too
641 // and thus a warning message should be triggered...
643 Reference
<XDictionary
> aXDictionary(xDic
, UNO_QUERY
);
644 nAddRes
= linguistic::AddEntryToDic( aXDictionary
,
645 aNewWord
, bIsNegEntry
,
646 aRplcText
, SvxLocaleToLanguage( xDic
->getLocale() ), sal_False
);
649 if (DIC_ERR_NONE
!= nAddRes
)
650 SvxDicError( this, nAddRes
);
652 if(DIC_ERR_NONE
== nAddRes
&& sEntry
.Len())
654 // insert new entry in list-box etc...
656 aWordsLB
.SetUpdateMode(sal_False
);
657 sal_uInt16 _nPos
= USHRT_MAX
;
659 if(aReplaceFT
.IsVisible())
662 sEntry
+= aReplaceStr
;
665 SvLBoxEntry
* pNewEntry
= NULL
;
666 if(_pEntry
) // entry selected in aWordsLB ie action = modify entry
668 aWordsLB
.SetEntryText( sEntry
, _pEntry
);
673 _nPos
= GetLBInsertPos( aNewWord
);
674 SvLBoxEntry
* pInsEntry
= aWordsLB
.InsertEntry(sEntry
, 0, sal_False
,
675 _nPos
== USHRT_MAX
? LIST_APPEND
: (sal_uInt32
)_nPos
);
676 pNewEntry
= pInsEntry
;
679 aWordsLB
.MakeVisible( pNewEntry
);
680 aWordsLB
.SetUpdateMode(sal_True
);
681 // falls der Request aus dem ReplaceEdit kam, dann Focus in das ShortEdit setzen
682 if(aReplaceED
.HasFocus())
688 // das kann nur ein Enter in einem der beiden Edit-Felder sein und das
689 // bedeutet EndDialog() - muss im KeyInput ausgewertet werden
696 // -----------------------------------------------------------------------
698 IMPL_LINK(SvxEditDictionaryDialog
, ModifyHdl
, Edit
*, pEdt
)
700 SvLBoxEntry
* pFirstSel
= aWordsLB
.FirstSelected();
701 String rEntry
= pEdt
->GetText();
703 xub_StrLen nWordLen
=rEntry
.Len();
704 const String
& rRepString
= aReplaceED
.GetText();
706 BOOL bEnableNewReplace
= FALSE
;
707 BOOL bEnableDelete
= FALSE
;
708 String aNewReplaceText
= sNew
;
714 sal_Bool bFound
= sal_False
;
715 sal_Bool bTmpSelEntry
=sal_False
;
716 CDE_RESULT eCmpRes
= CDE_DIFFERENT
;
718 for(sal_uInt16 i
= 0; i
< aWordsLB
.GetEntryCount(); i
++)
720 SvLBoxEntry
* pEntry
= aWordsLB
.GetEntry( i
);
721 String
aTestStr( aWordsLB
.GetEntryText(pEntry
, 0) );
722 eCmpRes
= cmpDicEntry_Impl( rEntry
, aTestStr
);
723 if(CDE_DIFFERENT
!= eCmpRes
)
726 bFirstSelect
= sal_True
;
728 aWordsLB
.SetCurEntry(pEntry
);
729 bDoNothing
=sal_False
;
731 aReplaceED
.SetText(aWordsLB
.GetEntryText(pEntry
, 1));
733 if (CDE_SIMILAR
== eCmpRes
)
735 aNewReplaceText
= sModify
;
736 bEnableNewReplace
= TRUE
;
741 else if(getNormDicEntry_Impl(aTestStr
).Search(
742 getNormDicEntry_Impl( rEntry
) ) == 0
746 aWordsLB
.MakeVisible(pEntry
);
747 bDoNothing
=sal_False
;
748 bTmpSelEntry
=sal_True
;
750 aNewReplaceText
= sNew
;
751 bEnableNewReplace
= TRUE
;
757 aWordsLB
.SelectAll(sal_False
);
760 aNewReplaceText
= sNew
;
761 bEnableNewReplace
= TRUE
;
763 bEnableDelete
= CDE_DIFFERENT
!= eCmpRes
;
765 else if(aWordsLB
.GetEntryCount()>0)
767 SvLBoxEntry
* pEntry
= aWordsLB
.GetEntry( 0 );
769 aWordsLB
.MakeVisible(pEntry
);
770 bDoNothing
=sal_False
;
773 else if(pEdt
== &aReplaceED
)
777 if (pFirstSel
) // a aWordsLB entry is selected
779 aWordText
= aWordsLB
.GetEntryText( pFirstSel
, 0 );
780 aReplaceText
= aWordsLB
.GetEntryText( pFirstSel
, 1 );
782 aNewReplaceText
= sModify
;
783 bEnableDelete
= TRUE
;
786 CDE_EQUAL
!= cmpDicEntry_Impl(aWordED
.GetText(), aWordText
)
787 || CDE_EQUAL
!= cmpDicEntry_Impl(aReplaceED
.GetText(), aReplaceText
);
788 if (aWordED
.GetText().Len() && bIsChange
)
789 bEnableNewReplace
= TRUE
;
792 aNewReplacePB
.SetText( aNewReplaceText
);
793 aNewReplacePB
.Enable( bEnableNewReplace
&& !IsDicReadonly_Impl() );
794 aDeletePB
.Enable( bEnableDelete
&& !IsDicReadonly_Impl() );
799 //=========================================================
801 //=========================================================
802 void SvxDictEdit::KeyInput( const KeyEvent
& rKEvt
)
804 const KeyCode aKeyCode
= rKEvt
.GetKeyCode();
805 const sal_uInt16 nModifier
= aKeyCode
.GetModifier();
806 if( aKeyCode
.GetCode() == KEY_RETURN
)
808 //wird bei Enter nichts getan, dann doch die Basisklasse rufen
809 // um den Dialog zu schliessen
810 if(!nModifier
&& !aActionLink
.Call(this))
811 Edit::KeyInput(rKEvt
);
813 else if(bSpaces
|| aKeyCode
.GetCode() != KEY_SPACE
)
814 Edit::KeyInput(rKEvt
);