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