xref: /aoo41x/main/cui/source/dialogs/thesdlg.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 
30 #include "precompiled_cui.hxx"
31 
32 #include "thesdlg.hrc"
33 #include "thesdlg.hxx"
34 #include "thesdlg_impl.hxx"
35 #include "cuires.hrc"
36 #include "dialmgr.hxx"
37 
38 #include <editeng/unolingu.hxx>
39 #include <tools/shl.hxx>
40 #include <svl/lngmisc.hxx>
41 #include <svtools/filter.hxx>
42 #include <svtools/svlbitm.hxx>
43 #include <svtools/svtreebx.hxx>
44 #include <vcl/wrkwin.hxx>
45 #include <vcl/msgbox.hxx>
46 #include <vcl/svapp.hxx>
47 #include <com/sun/star/linguistic2/XThesaurus.hpp>
48 #include <com/sun/star/linguistic2/XMeaning.hpp>
49 #include <thesdlg.hxx>
50 #include <svx/dlgutil.hxx>
51 #include <svx/dialmgr.hxx>
52 #include <svx/svxerr.hxx>
53 #include <editeng/unolingu.hxx>
54 #include <svx/langbox.hxx>
55 #include <svtools/langtab.hxx>
56 #include <unotools/lingucfg.hxx>
57 #include <i18npool/mslangid.hxx>
58 #include <comphelper/processfactory.hxx>
59 #include <osl/file.hxx>
60 #include <svl/lngmisc.hxx>
61 
62 
63 #include <stack>
64 #include <algorithm>
65 
66 #include <com/sun/star/linguistic2/XThesaurus.hpp>
67 #include <com/sun/star/linguistic2/XMeaning.hpp>
68 #include <com/sun/star/linguistic2/XLinguServiceManager.hpp>
69 
70 using namespace ::com::sun::star;
71 using ::rtl::OUString;
72 
73 
74 #define A2S(x)          String::CreateFromAscii( x )
75 
76 
77 // class LookUpComboBox_Impl --------------------------------------------------
78 
79 LookUpComboBox_Impl::LookUpComboBox_Impl(
80     Window *pParent, const ResId &rResId, SvxThesaurusDialog_Impl &rImpl ) :
81     ComboBox        (pParent, rResId),
82     m_rDialogImpl( rImpl )
83 {
84     m_aModifyTimer.SetTimeoutHdl( LINK( this, LookUpComboBox_Impl, ModifyTimer_Hdl ) );
85     m_aModifyTimer.SetTimeout( 500 );
86 
87     EnableAutocomplete( sal_False );
88 }
89 
90 
91 LookUpComboBox_Impl::~LookUpComboBox_Impl()
92 {
93 }
94 
95 
96 void LookUpComboBox_Impl::Modify()
97 {
98     m_aModifyTimer.Start();
99 }
100 
101 
102 IMPL_LINK( LookUpComboBox_Impl, ModifyTimer_Hdl, Timer *, EMPTYARG /*pTimer*/ )
103 {
104     m_rDialogImpl.LookUp( GetText() );
105     m_aModifyTimer.Stop();
106     return 0;
107 }
108 
109 
110 // class ReplaceEdit_Impl --------------------------------------------------
111 
112 ReplaceEdit_Impl::ReplaceEdit_Impl(
113     Window *pParent, const ResId &rResId ) :
114     Edit        (pParent, rResId)
115 {
116 }
117 
118 
119 ReplaceEdit_Impl::~ReplaceEdit_Impl()
120 {
121 }
122 
123 
124 void ReplaceEdit_Impl::Modify()
125 {
126     if (m_pBtn)
127         m_pBtn->Enable( GetText().Len() > 0 );
128 }
129 
130 void ReplaceEdit_Impl::SetText( const XubString& rStr )
131 {
132     Edit::SetText( rStr );
133     Modify();
134 }
135 
136 
137 void ReplaceEdit_Impl::SetText( const XubString& rStr, const Selection& rNewSelection )
138 {
139     Edit::SetText( rStr, rNewSelection );
140     Modify();
141 }
142 
143 
144 // class ThesaurusAlternativesCtrl_Impl ----------------------------------
145 
146 AlternativesString_Impl::AlternativesString_Impl(
147     ThesaurusAlternativesCtrl_Impl &rControl,
148     SvLBoxEntry* pEntry, sal_uInt16 nFlags, const String& rStr ) :
149     //
150     SvLBoxString( pEntry, nFlags, rStr ),
151     m_rControlImpl( rControl )
152 {
153 }
154 
155 void AlternativesString_Impl::Paint(
156     const Point& rPos,
157     SvLBox& rDev, sal_uInt16,
158 	SvLBoxEntry* pEntry )
159 {
160 	AlternativesExtraData* pData = m_rControlImpl.GetExtraData( pEntry );
161 	Point aPos( rPos );
162 	Font aOldFont( rDev.GetFont());
163 	if (pData && pData->IsHeader())
164 	{
165 		Font aFont( aOldFont );
166 		aFont.SetWeight( WEIGHT_BOLD );
167 		rDev.SetFont( aFont );
168 		aPos.X() = 0;
169 	}
170 	else
171 		aPos.X() += 5;
172 	rDev.DrawText( aPos, GetText() );
173 	rDev.SetFont( aOldFont );
174 }
175 
176 
177 ThesaurusAlternativesCtrl_Impl::ThesaurusAlternativesCtrl_Impl(
178         Window* pParent,
179         SvxThesaurusDialog_Impl &rImpl ) :
180     SvxCheckListBox( pParent, CUI_RES( CT_THES_ALTERNATIVES ) ),
181     m_rDialogImpl( rImpl )
182 {
183 	SetStyle( GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_FORCE_MAKEVISIBLE );
184 	SetHighlightRange();
185 }
186 
187 
188 ThesaurusAlternativesCtrl_Impl::~ThesaurusAlternativesCtrl_Impl()
189 {
190     ClearExtraData();
191 }
192 
193 
194 void ThesaurusAlternativesCtrl_Impl::ClearExtraData()
195 {
196     UserDataMap_t   aEmpty;
197     m_aUserData.swap( aEmpty );
198 }
199 
200 
201 void ThesaurusAlternativesCtrl_Impl::SetExtraData(
202     const SvLBoxEntry *pEntry,
203     const AlternativesExtraData &rData )
204 {
205     if (!pEntry)
206         return;
207 
208     UserDataMap_t::iterator aIt( m_aUserData.find( pEntry ) );
209     if (aIt != m_aUserData.end())
210         aIt->second = rData;
211     else
212         m_aUserData[ pEntry ] = rData;
213 }
214 
215 
216 AlternativesExtraData * ThesaurusAlternativesCtrl_Impl::GetExtraData(
217     const SvLBoxEntry *pEntry )
218 {
219     AlternativesExtraData *pRes = NULL;
220     UserDataMap_t::iterator aIt( m_aUserData.find( pEntry ) );
221     if (aIt != m_aUserData.end())
222         pRes = &aIt->second;
223     return pRes;
224 }
225 
226 
227 SvLBoxEntry * ThesaurusAlternativesCtrl_Impl::AddEntry( sal_Int32 nVal, const String &rText, bool bIsHeader )
228 {
229 	SvLBoxEntry* pEntry = new SvLBoxEntry;
230     String aText;
231     if (bIsHeader && nVal >= 0)
232     {
233         aText = String::CreateFromInt32( nVal );
234         aText += A2S( ". " );
235     }
236     pEntry->AddItem( new SvLBoxString( pEntry, 0, String() ) );	// add empty column
237     aText += rText;
238     pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0 ) );  // otherwise crash
239 	pEntry->AddItem( new AlternativesString_Impl( *this, pEntry, 0, aText ) );
240 
241 	SetExtraData( pEntry, AlternativesExtraData( rText, bIsHeader ) );
242     GetModel()->Insert( pEntry );
243 
244     if (bIsHeader)
245         GetViewDataEntry( pEntry )->SetSelectable( false );
246 
247 	return pEntry;
248 }
249 
250 
251 void ThesaurusAlternativesCtrl_Impl::KeyInput( const KeyEvent& rKEvt )
252 {
253     const KeyCode& rKey = rKEvt.GetKeyCode();
254 
255     if (rKey.GetCode() == KEY_RETURN || rKey.GetCode() == KEY_ESCAPE)
256         GetParent()->KeyInput( rKEvt ); // parent will close dialog...
257     else if (rKey.GetCode() == KEY_SPACE)
258         m_rDialogImpl.AlternativesDoubleClickHdl_Impl( this ); // look up current selected entry
259     else if (GetEntryCount())
260         SvxCheckListBox::KeyInput( rKEvt );
261 }
262 
263 
264 void ThesaurusAlternativesCtrl_Impl::Paint( const Rectangle& rRect )
265 {
266     if (!m_rDialogImpl.m_bWordFound)
267     {
268 /*        Push( PUSH_FONT );
269 
270         Font aFont( GetFont() );
271         aFont.SetHeight( 2 * aFont.GetHeight() );
272         SetFont( aFont );
273 */
274         Size aTextSize( GetTextWidth( m_rDialogImpl.aErrStr ), GetTextHeight() );
275         aTextSize  = LogicToPixel( aTextSize );
276         Point aPos;
277         aPos.X() += GetSizePixel().Width() / 2  - aTextSize.Width() / 2;
278         aPos.Y() += GetSizePixel().Height() / 2 /*- aTextSize.Height() / 2*/;
279         aPos = PixelToLogic( aPos );
280         DrawText( aPos, m_rDialogImpl.aErrStr );
281 
282 //        Pop();
283     }
284     else
285         SvxCheckListBox::Paint( rRect );
286 }
287 
288 
289 // struct SvxThesaurusDialog_Impl ----------------------------------------
290 
291 SvxThesaurusDialog_Impl::SvxThesaurusDialog_Impl( SvxThesaurusDialog * pDialog ) :
292     m_pDialog       ( pDialog ),
293     aVendorImageFI  ( pDialog, CUI_RES( IMG_VENDOR ) ),
294     aLeftBtn        ( pDialog, CUI_RES( BTN_LEFT ) ),
295     aWordText       ( pDialog, CUI_RES( FT_WORD ) ),
296     aWordCB         ( pDialog, CUI_RES( CB_WORD ), *this ),
297     m_aAlternativesText  ( pDialog, CUI_RES( FT_THES_ALTERNATIVES ) ),
298     m_pAlternativesCT    ( new ThesaurusAlternativesCtrl_Impl( pDialog, *this ) ),
299     aReplaceText    ( pDialog, CUI_RES( FT_REPL ) ),
300     aReplaceEdit    ( pDialog, CUI_RES( ED_REPL ) ),
301     aFL             ( pDialog, CUI_RES( FL_VAR ) ),
302     aHelpBtn        ( pDialog, CUI_RES( BTN_THES_HELP ) ),
303     aLangMBtn       ( pDialog, CUI_RES( MB_LANGUAGE ) ),
304     aReplaceBtn     ( pDialog, CUI_RES( BTN_THES_OK ) ),
305     aCancelBtn      ( pDialog, CUI_RES( BTN_THES_CANCEL ) ),
306     aErrStr                 ( CUI_RES( STR_ERR_TEXTNOTFOUND ) ),
307     aVendorDefaultImage     ( CUI_RES( IMG_DEFAULT_VENDOR ) ),
308     aVendorDefaultImageHC   ( CUI_RES( IMG_DEFAULT_VENDOR_HC ) ),
309     xThesaurus      ( NULL ),
310     aLookUpText     (),
311     nLookUpLanguage ( LANGUAGE_NONE ),
312     m_bWordFound( false )
313 {
314     // note: FreeResource must only be called in the c-tor of SvxThesaurusDialog
315 
316     aReplaceEdit.SetButton( &aReplaceBtn );
317 
318     aLeftBtn.SetClickHdl( LINK( this, SvxThesaurusDialog_Impl, LeftBtnHdl_Impl ) );
319     aWordCB.SetSelectHdl( LINK( this, SvxThesaurusDialog_Impl, WordSelectHdl_Impl ) );
320     aLangMBtn.SetSelectHdl( LINK( this, SvxThesaurusDialog_Impl, LanguageHdl_Impl ) );
321     m_pAlternativesCT->SetSelectHdl( LINK( this, SvxThesaurusDialog_Impl, AlternativesSelectHdl_Impl ));
322     m_pAlternativesCT->SetDoubleClickHdl( LINK( this, SvxThesaurusDialog_Impl, AlternativesDoubleClickHdl_Impl ));
323 
324     Application::PostUserEvent( STATIC_LINK( this, SvxThesaurusDialog_Impl, VendorImageInitHdl ) );
325 }
326 
327 
328 SvxThesaurusDialog_Impl::~SvxThesaurusDialog_Impl()
329 {
330     delete aLangMBtn.GetPopupMenu();
331 }
332 
333 
334 uno::Sequence< uno::Reference< linguistic2::XMeaning > > SAL_CALL SvxThesaurusDialog_Impl::queryMeanings_Impl(
335         OUString& rTerm,
336         const lang::Locale& rLocale,
337         const beans::PropertyValues& rProperties )
338     throw(lang::IllegalArgumentException, uno::RuntimeException)
339 {
340     uno::Sequence< uno::Reference< linguistic2::XMeaning > > aMeanings(
341             xThesaurus->queryMeanings( rTerm, rLocale, rProperties ) );
342 
343     // text with '.' at the end?
344     if (0 == aMeanings.getLength() && rTerm.getLength() &&
345         rTerm.getStr()[ rTerm.getLength() - 1 ] == '.')
346     {
347         // try again without trailing '.' chars. It may be a word at the
348         // end of a sentence and not an abbreviation...
349         String aTxt( rTerm );
350         aTxt.EraseTrailingChars( '.' );
351         aMeanings = xThesaurus->queryMeanings( aTxt, rLocale, rProperties );
352         if (aMeanings.getLength())
353         {
354             rTerm = aTxt;
355         }
356     }
357 
358     return aMeanings;
359 }
360 
361 
362 bool SvxThesaurusDialog_Impl::UpdateAlternativesBox_Impl()
363 {
364     lang::Locale aLocale( SvxCreateLocale( nLookUpLanguage ) );
365     uno::Sequence< uno::Reference< linguistic2::XMeaning > > aMeanings = queryMeanings_Impl(
366             aLookUpText, aLocale, uno::Sequence< beans::PropertyValue >() );
367     const sal_Int32 nMeanings = aMeanings.getLength();
368     const uno::Reference< linguistic2::XMeaning > *pMeanings = aMeanings.getConstArray();
369 
370     m_pAlternativesCT->SetUpdateMode( sal_False );
371 
372     // clear old user data of control before creating new ones via AddEntry below
373     m_pAlternativesCT->ClearExtraData();
374 
375     m_pAlternativesCT->Clear();
376     for (sal_Int32 i = 0;  i < nMeanings;  ++i)
377     {
378         OUString rMeaningTxt = pMeanings[i]->getMeaning();
379         uno::Sequence< OUString > aSynonyms( pMeanings[i]->querySynonyms() );
380         const sal_Int32 nSynonyms = aSynonyms.getLength();
381         const OUString *pSynonyms = aSynonyms.getConstArray();
382         DBG_ASSERT( rMeaningTxt.getLength() > 0, "meaning with empty text" );
383         DBG_ASSERT( nSynonyms > 0, "meaning without synonym" );
384 
385         m_pAlternativesCT->AddEntry( i + 1, rMeaningTxt, true );
386         for (sal_Int32 k = 0;  k < nSynonyms;  ++k)
387             m_pAlternativesCT->AddEntry( -1, pSynonyms[k], false );
388     }
389 
390     m_pAlternativesCT->SetUpdateMode( sal_True );
391 
392     return nMeanings > 0;
393 }
394 
395 
396 void SvxThesaurusDialog_Impl::LookUp( const String &rText )
397 {
398     if (rText != aWordCB.GetText()) // avoid moving of the cursor if the text is the same
399         aWordCB.SetText( rText );
400     LookUp_Impl();
401 }
402 
403 
404 IMPL_LINK( SvxThesaurusDialog_Impl, LeftBtnHdl_Impl, Button *, pBtn )
405 {
406     if (pBtn && aLookUpHistory.size() >= 2)
407     {
408         aLookUpHistory.pop();                       // remove current look up word from stack
409         aWordCB.SetText( aLookUpHistory.top() );    // retrieve previous look up word
410         aLookUpHistory.pop();
411         LookUp_Impl();
412     }
413     return 0;
414 }
415 
416 
417 IMPL_LINK( SvxThesaurusDialog_Impl, LanguageHdl_Impl, MenuButton *, pBtn )
418 {
419     PopupMenu *pMenu = aLangMBtn.GetPopupMenu();
420     if (pMenu && pBtn)
421     {
422         sal_uInt16 nItem = pBtn->GetCurItemId();
423         String aLangText( pMenu->GetItemText( nItem ) );
424         LanguageType nLang = SvtLanguageTable().GetType( aLangText );
425         DBG_ASSERT( nLang != LANGUAGE_NONE && nLang != LANGUAGE_DONTKNOW, "failed to get language" );
426         if (xThesaurus->hasLocale( SvxCreateLocale( nLang ) ))
427             nLookUpLanguage = nLang;
428         m_pDialog->SetWindowTitle( nLang );
429         UpdateVendorImage();
430         LookUp_Impl();
431     }
432     return 0;
433 }
434 
435 
436 void SvxThesaurusDialog_Impl::LookUp_Impl()
437 {
438     String aText( aWordCB.GetText() );
439 
440     aLookUpText = OUString( aText );
441     if (aLookUpText.getLength() > 0 &&
442             (aLookUpHistory.size() == 0 || aLookUpText != aLookUpHistory.top()))
443         aLookUpHistory.push( aLookUpText );
444 
445     m_bWordFound = UpdateAlternativesBox_Impl();
446     m_pAlternativesCT->Enable( m_bWordFound );
447 
448     if ( aWordCB.GetEntryPos( aText ) == LISTBOX_ENTRY_NOTFOUND )
449         aWordCB.InsertEntry( aText );
450 
451     aReplaceEdit.SetText( String() );
452     aLeftBtn.Enable( aLookUpHistory.size() > 1 );
453 }
454 
455 
456 IMPL_LINK( SvxThesaurusDialog_Impl, WordSelectHdl_Impl, ComboBox *, pBox )
457 {
458     if (pBox && !aWordCB.IsTravelSelect())  // act only upon return key and not when traveling with cursor keys
459     {
460         sal_uInt16 nPos = pBox->GetSelectEntryPos();
461         String aStr( pBox->GetEntry( nPos ) );
462         aStr = linguistic::GetThesaurusReplaceText( aStr );
463         aWordCB.SetText( aStr );
464         LookUp_Impl();
465     }
466 
467     return 0;
468 }
469 
470 
471 IMPL_LINK( SvxThesaurusDialog_Impl, AlternativesSelectHdl_Impl, SvxCheckListBox *, pBox )
472 {
473     SvLBoxEntry *pEntry = pBox ? pBox->GetCurEntry() : NULL;
474     if (pEntry)
475     {
476         AlternativesExtraData * pData = m_pAlternativesCT->GetExtraData( pEntry );
477         String aStr;
478         if (pData && !pData->IsHeader())
479         {
480             aStr = pData->GetText();
481             aStr = linguistic::GetThesaurusReplaceText( aStr );
482         }
483         aReplaceEdit.SetText( aStr );
484     }
485     return 0;
486 }
487 
488 
489 IMPL_LINK( SvxThesaurusDialog_Impl, AlternativesDoubleClickHdl_Impl, SvxCheckListBox *, pBox )
490 {
491     SvLBoxEntry *pEntry = pBox ? pBox->GetCurEntry() : NULL;
492     if (pEntry)
493     {
494         AlternativesExtraData * pData = m_pAlternativesCT->GetExtraData( pEntry );
495         String aStr;
496         if (pData && !pData->IsHeader())
497         {
498             aStr = pData->GetText();
499             aStr = linguistic::GetThesaurusReplaceText( aStr );
500         }
501 
502         aWordCB.SetText( aStr );
503         if (aStr.Len() > 0)
504             LookUp_Impl();
505     }
506 
507     //! workaround to set the selection since calling SelectEntryPos within
508     //! the double click handler does not work
509     Application::PostUserEvent( STATIC_LINK( this, SvxThesaurusDialog_Impl, SelectFirstHdl_Impl ), pBox );
510     return 0;
511 }
512 
513 
514 IMPL_STATIC_LINK( SvxThesaurusDialog_Impl, SelectFirstHdl_Impl, SvxCheckListBox *, pBox )
515 {
516 	(void) pThis;
517     if (pBox && pBox->GetEntryCount() >= 2)
518         pBox->SelectEntryPos( 1 );  // pos 0 is a 'header' that is not selectable
519     return 0;
520 }
521 
522 ////////////////////////////////////////////////////////////
523 
524 static Image lcl_GetImageFromPngUrl( const OUString &rFileUrl )
525 {
526     Image aRes;
527 
528     OUString aTmp;
529     osl::FileBase::getSystemPathFromFileURL( rFileUrl, aTmp );
530 
531     Graphic aGraphic;
532     const String aFilterName( RTL_CONSTASCII_USTRINGPARAM( IMP_PNG ) );
533     if( GRFILTER_OK == GraphicFilter::LoadGraphic( aTmp, aFilterName, aGraphic, NULL, NULL ) )
534     {
535         aRes = Image( aGraphic.GetBitmapEx() );
536     }
537     return aRes;
538 }
539 
540 
541 static String lcl_GetThesImplName( const lang::Locale &rLocale )
542 {
543     String aRes;
544 
545     uno::Reference< linguistic2::XLinguServiceManager >     xLngMgr;
546     try
547     {
548         uno::Reference< lang::XMultiServiceFactory >  xMSF( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
549         xLngMgr = uno::Reference< linguistic2::XLinguServiceManager >( xMSF->createInstance(
550                 OUString( RTL_CONSTASCII_USTRINGPARAM(
551                     "com.sun.star.linguistic2.LinguServiceManager" ))), uno::UNO_QUERY_THROW );
552 
553         DBG_ASSERT( xLngMgr.is(), "LinguServiceManager missing" );
554         if (xLngMgr.is())
555         {
556             uno::Sequence< OUString > aServiceNames = xLngMgr->getConfiguredServices(
557                     OUString::createFromAscii("com.sun.star.linguistic2.Thesaurus"), rLocale );
558             // there should be at most one thesaurus configured for each language
559             DBG_ASSERT( aServiceNames.getLength() <= 1, "more than one thesaurus found. Should not be possible" );
560             if (aServiceNames.getLength() == 1)
561                 aRes = aServiceNames[0];
562         }
563     }
564     catch (uno::Exception &e)
565     {
566         (void) e;
567         DBG_ASSERT( 0, "failed to get thesaurus" );
568     }
569 
570     return aRes;
571 }
572 
573 
574 void SvxThesaurusDialog_Impl::UpdateVendorImage()
575 {
576     m_pDialog->SetUpdateMode( sal_False );
577 
578     SvtLinguConfig aCfg;
579     if (aCfg.HasVendorImages( "ThesaurusDialogImage" ))
580     {
581         const bool bHC = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
582 
583         Image aImage;
584         String sThesImplName( lcl_GetThesImplName( SvxCreateLocale( nLookUpLanguage ) ) );
585         OUString aThesDialogImageUrl( aCfg.GetThesaurusDialogImage( sThesImplName, bHC ) );
586         if (sThesImplName.Len() > 0 && aThesDialogImageUrl.getLength() > 0)
587             aImage = Image( lcl_GetImageFromPngUrl( aThesDialogImageUrl ) );
588         else
589             aImage = bHC ? aVendorDefaultImageHC : aVendorDefaultImage;
590         aVendorImageFI.SetImage( aImage );
591     }
592 
593     m_pDialog->SetUpdateMode( sal_True );
594 }
595 
596 
597 IMPL_STATIC_LINK( SvxThesaurusDialog_Impl, VendorImageInitHdl, SvxThesaurusDialog_Impl *, EMPTYARG )
598 {
599     pThis->m_pDialog->SetUpdateMode( sal_False );
600 
601     SvtLinguConfig aCfg;
602     if (aCfg.HasVendorImages( "ThesaurusDialogImage" ))
603     {
604         const bool bHC = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
605         Image aImage( bHC ? pThis->aVendorDefaultImageHC : pThis->aVendorDefaultImage );
606         pThis->aVendorImageFI.SetImage( aImage );
607         pThis->aVendorImageFI.Show();
608 
609         // move down visible controls according to the vendor images height
610         Size aVendorSize = pThis->aVendorImageFI.GetSizePixel();
611         Size aImageSize  = pThis->aVendorImageFI.GetImage().GetSizePixel();
612         if (aImageSize.Height())
613         {
614             aVendorSize.Height() = aImageSize.Height();
615             if(aVendorSize.Width() < aImageSize.Width())
616                 aVendorSize.Width() = aImageSize.Width();
617             pThis->aVendorImageFI.SetSizePixel( aVendorSize );
618         }
619         const sal_Int32 nDiff = aVendorSize.Height();
620         pThis->aVendorImageFI.SetSizePixel( aVendorSize );
621         Control* aControls[] = {
622             &pThis->aLeftBtn,
623             &pThis->aWordText,
624             &pThis->aWordCB,
625             &pThis->m_aAlternativesText,
626             pThis->m_pAlternativesCT.get(),
627             &pThis->aReplaceText,
628             &pThis->aReplaceEdit,
629             &pThis->aFL,
630             &pThis->aHelpBtn,
631             &pThis->aLangMBtn,
632             &pThis->aReplaceBtn,
633             &pThis->aCancelBtn,
634             0
635         };
636         sal_Int32 nControl = 0;
637         while (aControls[nControl])
638         {
639             Point aPos = aControls[nControl]->GetPosPixel();
640             aPos.Y() += nDiff;
641             aControls[nControl]->SetPosPixel(aPos);
642             ++nControl;
643         }
644         Size aDlgSize = pThis->m_pDialog->GetSizePixel();
645         aDlgSize.Height() += nDiff;
646         pThis->m_pDialog->SetSizePixel( aDlgSize );
647         pThis->m_pDialog->Invalidate();
648     }
649 
650     pThis->UpdateVendorImage();
651     pThis->m_pDialog->SetUpdateMode( sal_True );
652 
653     return 0;
654 };
655 
656 
657 // class SvxThesaurusDialog ----------------------------------------------
658 
659 SvxThesaurusDialog::SvxThesaurusDialog(
660     Window* pParent,
661     uno::Reference< linguistic2::XThesaurus >  xThes,
662     const String &rWord,
663     LanguageType nLanguage ) :
664 
665 	SvxStandardDialog( pParent, CUI_RES( RID_SVXDLG_THESAURUS ) )
666 {
667     m_pImpl = std::auto_ptr< SvxThesaurusDialog_Impl >(new SvxThesaurusDialog_Impl( this ));
668 
669     m_pImpl->xThesaurus = xThes;
670     m_pImpl->aLookUpText = OUString( rWord );
671     m_pImpl->nLookUpLanguage = nLanguage;
672     if (rWord.Len() > 0)
673         m_pImpl->aLookUpHistory.push( rWord );
674 
675 	FreeResource();
676 
677     OUString aTmp( rWord );
678 	linguistic::RemoveHyphens( aTmp );
679     linguistic::ReplaceControlChars( aTmp );
680     String aTmp2( aTmp );
681     m_pImpl->aReplaceEdit.SetText( aTmp2 );
682     m_pImpl->aWordCB.InsertEntry( aTmp2 );
683 
684     m_pImpl->LookUp( aTmp2 );
685     m_pImpl->m_pAlternativesCT->GrabFocus();
686     m_pImpl->aLeftBtn.Enable( sal_False );
687 
688     // fill language menu button list
689     SvtLanguageTable aLangTab;
690     uno::Sequence< lang::Locale > aLocales;
691     if (m_pImpl->xThesaurus.is())
692         aLocales = m_pImpl->xThesaurus->getLocales();
693     const sal_Int32 nLocales = aLocales.getLength();
694     const lang::Locale *pLocales = aLocales.getConstArray();
695     delete m_pImpl->aLangMBtn.GetPopupMenu();
696     PopupMenu* pMenu = new PopupMenu;
697     pMenu->SetMenuFlags( MENU_FLAG_NOAUTOMNEMONICS );
698     std::vector< OUString > aLangVec;
699     for (sal_Int32 i = 0;  i < nLocales;  ++i )
700     {
701         const LanguageType nLang = SvxLocaleToLanguage( pLocales[i] );
702         DBG_ASSERT( nLang != LANGUAGE_NONE && nLang != LANGUAGE_DONTKNOW, "failed to get language" );
703         aLangVec.push_back( aLangTab.GetString( nLang ) );
704     }
705     std::sort( aLangVec.begin(), aLangVec.end() );
706     for (size_t i = 0;  i < aLangVec.size();  ++i)
707         pMenu->InsertItem( (sal_uInt16)i+1, aLangVec[i] );  // menu items should be enumerated from 1 and not 0
708     m_pImpl->aLangMBtn.SetPopupMenu( pMenu );
709 
710     SetWindowTitle( nLanguage );
711 
712 	// disable controls if service is missing
713     if (!m_pImpl->xThesaurus.is())
714 		Enable( sal_False );
715 }
716 
717 
718 SvxThesaurusDialog::~SvxThesaurusDialog()
719 {
720 }
721 
722 
723 void SvxThesaurusDialog::SetWindowTitle( LanguageType nLanguage )
724 {
725     // Sprache anpassen
726     String aStr( GetText() );
727     aStr.Erase( aStr.Search( sal_Unicode( '(' ) ) - 1 );
728     aStr.Append( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( " (" ) ) );
729     aStr += SvtLanguageTable().GetLanguageString( nLanguage );
730     aStr.Append( sal_Unicode( ')' ) );
731     SetText( aStr );    // set window title
732 }
733 
734 
735 String SvxThesaurusDialog::GetWord()
736 {
737     return m_pImpl->aReplaceEdit.GetText();
738 }
739 
740 
741 sal_uInt16 SvxThesaurusDialog::GetLanguage() const
742 {
743     return m_pImpl->nLookUpLanguage;
744 }
745 
746 
747 void SvxThesaurusDialog::Apply()
748 {
749 }
750 
751 
752