xref: /AOO41X/main/svx/source/unodialogs/textconversiondlgs/chinese_dictionarydialog.cxx (revision f6e50924346d0b8c0b07c91832a97665dd718b0c)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "chinese_dictionarydialog.hxx"
28cdf0e10cSrcweir #include "chinese_dictionarydialog.hrc"
29cdf0e10cSrcweir #include "resid.hxx"
30cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
31cdf0e10cSrcweir #include <com/sun/star/i18n/TextConversionOption.hpp>
32cdf0e10cSrcweir #include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
33cdf0e10cSrcweir #include <com/sun/star/linguistic2/ConversionPropertyType.hpp>
34cdf0e10cSrcweir #include <com/sun/star/linguistic2/XConversionDictionaryList.hpp>
35cdf0e10cSrcweir #include <com/sun/star/linguistic2/XConversionPropertyType.hpp>
36cdf0e10cSrcweir #include <com/sun/star/util/XFlushable.hpp>
37cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp>
38cdf0e10cSrcweir // header for class HeaderBar
39cdf0e10cSrcweir #include <svtools/headbar.hxx>
40cdf0e10cSrcweir // header for define RET_OK
41cdf0e10cSrcweir #include <vcl/msgbox.hxx>
42cdf0e10cSrcweir // header for class SvtLinguConfigItem
43cdf0e10cSrcweir #include <unotools/lingucfg.hxx>
44cdf0e10cSrcweir #include <unotools/linguprops.hxx>
45cdf0e10cSrcweir // header for class IntlWrapper
46cdf0e10cSrcweir #include <unotools/intlwrapper.hxx>
47cdf0e10cSrcweir #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
48cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
49cdf0e10cSrcweir #endif
50cdf0e10cSrcweir // header for class Application
51cdf0e10cSrcweir #include <vcl/svapp.hxx>
52cdf0e10cSrcweir #ifndef _SVX_HELPID_HRC
53cdf0e10cSrcweir #include "helpid.hrc"
54cdf0e10cSrcweir #endif
55cdf0e10cSrcweir 
56cdf0e10cSrcweir //disable compiler warning C4355: 'this' : used in base member initializer list
57cdf0e10cSrcweir #ifdef _MSC_VER
58cdf0e10cSrcweir #  pragma warning (disable : 4355)
59cdf0e10cSrcweir #endif
60cdf0e10cSrcweir 
61cdf0e10cSrcweir //.............................................................................
62cdf0e10cSrcweir namespace textconversiondlgs
63cdf0e10cSrcweir {
64cdf0e10cSrcweir //.............................................................................
65cdf0e10cSrcweir 
66cdf0e10cSrcweir using namespace ::com::sun::star;
67cdf0e10cSrcweir using namespace ::com::sun::star::uno;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir #define HEADER_BAR_BITS ( HIB_LEFT | HIB_VCENTER | HIB_CLICKABLE | HIB_FIXED | HIB_FIXEDPOS )
70cdf0e10cSrcweir 
DictionaryList(Window * pParent,const ResId & rResId)71cdf0e10cSrcweir DictionaryList::DictionaryList( Window* pParent, const ResId& rResId)
72cdf0e10cSrcweir     : SvHeaderTabListBox( pParent, rResId )
73cdf0e10cSrcweir     , m_xDictionary(0)
74cdf0e10cSrcweir     , m_pHeaderBar(0)
75cdf0e10cSrcweir     , m_pPropertyTypeNameListBox(0)
76cdf0e10cSrcweir     , m_aToBeDeleted()
77cdf0e10cSrcweir     , m_nSortColumnIndex(0)
78cdf0e10cSrcweir {
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
DictionaryList(Window * pParent)81cdf0e10cSrcweir DictionaryList::DictionaryList( Window* pParent )
82cdf0e10cSrcweir     : SvHeaderTabListBox( pParent, 0 )
83cdf0e10cSrcweir     , m_xDictionary(0)
84cdf0e10cSrcweir     , m_pHeaderBar(0)
85cdf0e10cSrcweir     , m_pPropertyTypeNameListBox(0)
86cdf0e10cSrcweir     , m_aToBeDeleted()
87cdf0e10cSrcweir     , m_nSortColumnIndex(0)
88cdf0e10cSrcweir {
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
getPropertyTypeName(sal_Int16 nConversionPropertyType) const91cdf0e10cSrcweir String DictionaryList::getPropertyTypeName( sal_Int16 nConversionPropertyType ) const
92cdf0e10cSrcweir {
93cdf0e10cSrcweir     if(!m_pPropertyTypeNameListBox || !m_pPropertyTypeNameListBox->GetEntryCount())
94cdf0e10cSrcweir         return String();
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     sal_uInt16 nPos = static_cast<sal_uInt16>( nConversionPropertyType )-1;
97cdf0e10cSrcweir     if(nPos<m_pPropertyTypeNameListBox->GetEntryCount())
98cdf0e10cSrcweir         return m_pPropertyTypeNameListBox->GetEntry(nPos);
99cdf0e10cSrcweir     return m_pPropertyTypeNameListBox->GetEntry(0);
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
makeTabString(const DictionaryEntry & rEntry) const102cdf0e10cSrcweir String DictionaryList::makeTabString( const DictionaryEntry& rEntry ) const
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     String aStr( rEntry.m_aTerm );
105cdf0e10cSrcweir     aStr += '\t';
106cdf0e10cSrcweir     aStr += String( rEntry.m_aMapping );
107cdf0e10cSrcweir     aStr += '\t';
108cdf0e10cSrcweir     aStr += getPropertyTypeName( rEntry.m_nConversionPropertyType );
109cdf0e10cSrcweir     return aStr;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
initDictionaryControl(const Reference<linguistic2::XConversionDictionary> & xDictionary,ListBox * pPropertyTypeNameListBox)112cdf0e10cSrcweir void DictionaryList::initDictionaryControl( const Reference< linguistic2::XConversionDictionary>& xDictionary
113cdf0e10cSrcweir                                            , ListBox* pPropertyTypeNameListBox )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     SetStyle( WB_VSCROLL | WB_TABSTOP );
116cdf0e10cSrcweir     SetSelectionMode( SINGLE_SELECTION );
117cdf0e10cSrcweir     SetBorderStyle( WINDOW_BORDER_MONO );
118cdf0e10cSrcweir     SetHighlightRange();
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     if(m_xDictionary.is())
121cdf0e10cSrcweir         return;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     m_xDictionary = xDictionary;
124cdf0e10cSrcweir     m_pPropertyTypeNameListBox = pPropertyTypeNameListBox;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
save()127cdf0e10cSrcweir void DictionaryList::save()
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     if( !m_xDictionary.is() )
130cdf0e10cSrcweir         return;
131cdf0e10cSrcweir 
132cdf0e10cSrcweir     Reference< linguistic2::XConversionPropertyType > xPropertyType( m_xDictionary, uno::UNO_QUERY );
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     sal_Int32 nN;
135cdf0e10cSrcweir     DictionaryEntry* pE;
136cdf0e10cSrcweir 
137cdf0e10cSrcweir     for( nN = m_aToBeDeleted.size(); nN--; )
138cdf0e10cSrcweir     {
139cdf0e10cSrcweir         pE = m_aToBeDeleted[nN];
140cdf0e10cSrcweir         m_xDictionary->removeEntry( pE->m_aTerm, pE->m_aMapping );
141cdf0e10cSrcweir     }
142cdf0e10cSrcweir     for( nN = GetRowCount(); nN--; )
143cdf0e10cSrcweir     {
144cdf0e10cSrcweir         pE = getEntryOnPos( nN );
145cdf0e10cSrcweir         if(pE->m_bNewEntry)
146cdf0e10cSrcweir         {
147cdf0e10cSrcweir             try
148cdf0e10cSrcweir             {
149cdf0e10cSrcweir                 m_xDictionary->addEntry( pE->m_aTerm, pE->m_aMapping );
150cdf0e10cSrcweir                 xPropertyType->setPropertyType( pE->m_aTerm, pE->m_aMapping, pE->m_nConversionPropertyType );
151cdf0e10cSrcweir             }
152cdf0e10cSrcweir             catch( uno::Exception& )
153cdf0e10cSrcweir             {
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 			}
156cdf0e10cSrcweir         }
157cdf0e10cSrcweir     }
158cdf0e10cSrcweir     Reference< util::XFlushable > xFlush( m_xDictionary, uno::UNO_QUERY );
159cdf0e10cSrcweir     if( xFlush.is() )
160cdf0e10cSrcweir         xFlush->flush();
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
deleteAll()163cdf0e10cSrcweir void DictionaryList::deleteAll()
164cdf0e10cSrcweir {
165cdf0e10cSrcweir     sal_Int32 nN;
166cdf0e10cSrcweir     for( nN = GetRowCount(); nN--; )
167cdf0e10cSrcweir         deleteEntryOnPos( nN  );
168cdf0e10cSrcweir     for( nN = m_aToBeDeleted.size(); nN--; )
169cdf0e10cSrcweir     {
170cdf0e10cSrcweir         DictionaryEntry* pE = m_aToBeDeleted[nN];
171cdf0e10cSrcweir         delete pE;
172cdf0e10cSrcweir     }
173cdf0e10cSrcweir     m_aToBeDeleted.clear();
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
refillFromDictionary(sal_Int32 nTextConversionOptions)176cdf0e10cSrcweir void DictionaryList::refillFromDictionary( sal_Int32 nTextConversionOptions )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir     deleteAll();
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     if(!m_xDictionary.is())
181cdf0e10cSrcweir         return;
182cdf0e10cSrcweir 
183cdf0e10cSrcweir     Sequence< rtl::OUString > aLeftList(  m_xDictionary->getConversionEntries( linguistic2::ConversionDirection_FROM_LEFT ) );
184cdf0e10cSrcweir     sal_Int32 nCount = aLeftList.getLength();
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     Reference< linguistic2::XConversionPropertyType > xPropertyType( m_xDictionary, uno::UNO_QUERY );
187cdf0e10cSrcweir 
188cdf0e10cSrcweir     rtl::OUString aLeft, aRight;
189cdf0e10cSrcweir     sal_Int16 nConversionPropertyType;
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     for(sal_Int32 nN=0; nN<nCount; nN++)
192cdf0e10cSrcweir     {
193cdf0e10cSrcweir         aLeft  = aLeftList[nN];
194cdf0e10cSrcweir         Sequence< rtl::OUString > aRightList( m_xDictionary->getConversions(
195cdf0e10cSrcweir             aLeft, 0, aLeft.getLength()
196cdf0e10cSrcweir             , linguistic2::ConversionDirection_FROM_LEFT, nTextConversionOptions ) );
197cdf0e10cSrcweir 
198cdf0e10cSrcweir         if(aRightList.getLength()!=1)
199cdf0e10cSrcweir         {
200cdf0e10cSrcweir             OSL_ASSERT("The Chinese Translation Dictionary should have exactly one Mapping for each term.");
201cdf0e10cSrcweir             continue;
202cdf0e10cSrcweir         }
203cdf0e10cSrcweir 
204cdf0e10cSrcweir         aRight = aRightList[0];
205cdf0e10cSrcweir         nConversionPropertyType = linguistic2::ConversionPropertyType::OTHER;
206cdf0e10cSrcweir         if(xPropertyType.is())
207cdf0e10cSrcweir             nConversionPropertyType = xPropertyType->getPropertyType(aLeft, aRight);
208cdf0e10cSrcweir 
209cdf0e10cSrcweir         DictionaryEntry* pEntry = new DictionaryEntry( aLeft, aRight, nConversionPropertyType );
210cdf0e10cSrcweir         SvLBoxEntry* pLBEntry = InsertEntry( makeTabString( *pEntry ) );
211cdf0e10cSrcweir 	    pLBEntry->SetUserData( pEntry );
212cdf0e10cSrcweir     }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     if( GetEntryCount() > 0 )
215cdf0e10cSrcweir         SelectRow( 0 );
216cdf0e10cSrcweir }
217cdf0e10cSrcweir 
getFirstSelectedEntry() const218cdf0e10cSrcweir DictionaryEntry* DictionaryList::getFirstSelectedEntry() const
219cdf0e10cSrcweir {
220cdf0e10cSrcweir     DictionaryEntry* pRet=0;
221cdf0e10cSrcweir     for( sal_Int32 nN=GetRowCount(); nN--; )
222cdf0e10cSrcweir     {
223cdf0e10cSrcweir         if( IsRowSelected( nN ) )
224cdf0e10cSrcweir         {
225cdf0e10cSrcweir             pRet = getEntryOnPos( nN );
226cdf0e10cSrcweir             break;
227cdf0e10cSrcweir         }
228cdf0e10cSrcweir     }
229cdf0e10cSrcweir     return pRet;
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
getEntryOnPos(sal_Int32 nPos) const232cdf0e10cSrcweir DictionaryEntry* DictionaryList::getEntryOnPos( sal_Int32 nPos ) const
233cdf0e10cSrcweir {
234cdf0e10cSrcweir     DictionaryEntry* pEntry=0;
235cdf0e10cSrcweir     SvLBoxEntry* pLBEntry = GetEntryOnPos( nPos );
236cdf0e10cSrcweir     if(pLBEntry)
237cdf0e10cSrcweir         pEntry = (DictionaryEntry*)pLBEntry->GetUserData();
238cdf0e10cSrcweir     return pEntry;
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
getTermEntry(const rtl::OUString & rTerm) const241cdf0e10cSrcweir DictionaryEntry* DictionaryList::getTermEntry( const rtl::OUString& rTerm ) const
242cdf0e10cSrcweir {
243cdf0e10cSrcweir     DictionaryEntry* pE = 0;
244cdf0e10cSrcweir     for( sal_Int32 nN=GetRowCount(); nN--; )
245cdf0e10cSrcweir     {
246cdf0e10cSrcweir         pE = getEntryOnPos( nN );
247cdf0e10cSrcweir         if( pE && rTerm.equals( pE->m_aTerm ) )
248cdf0e10cSrcweir             return pE;
249cdf0e10cSrcweir     }
250cdf0e10cSrcweir     return 0;
251cdf0e10cSrcweir }
252cdf0e10cSrcweir 
hasTerm(const rtl::OUString & rTerm) const253cdf0e10cSrcweir bool DictionaryList::hasTerm( const rtl::OUString& rTerm ) const
254cdf0e10cSrcweir {
255cdf0e10cSrcweir     return getTermEntry(rTerm) !=0 ;
256cdf0e10cSrcweir }
257cdf0e10cSrcweir 
addEntry(const rtl::OUString & rTerm,const rtl::OUString & rMapping,sal_Int16 nConversionPropertyType,sal_uIntPtr nPos)258cdf0e10cSrcweir void DictionaryList::addEntry( const rtl::OUString& rTerm, const rtl::OUString& rMapping
259cdf0e10cSrcweir                               , sal_Int16 nConversionPropertyType, sal_uIntPtr nPos )
260cdf0e10cSrcweir {
261cdf0e10cSrcweir     if( hasTerm( rTerm ) )
262cdf0e10cSrcweir         return;
263cdf0e10cSrcweir 
264cdf0e10cSrcweir     DictionaryEntry* pEntry = new DictionaryEntry( rTerm, rMapping, nConversionPropertyType, sal_True );
265cdf0e10cSrcweir     SvLBoxEntry* pLBEntry = InsertEntryToColumn( makeTabString( *pEntry ), nPos );
266cdf0e10cSrcweir 	pLBEntry->SetUserData( pEntry );
267cdf0e10cSrcweir     SelectRow( GetEntryPos( pLBEntry ) );
268cdf0e10cSrcweir }
269cdf0e10cSrcweir 
deleteEntryOnPos(sal_Int32 nPos)270cdf0e10cSrcweir void DictionaryList::deleteEntryOnPos( sal_Int32 nPos  )
271cdf0e10cSrcweir {
272cdf0e10cSrcweir     SvLBoxEntry* pLBEntry = GetEntryOnPos( nPos );
273cdf0e10cSrcweir     DictionaryEntry* pEntry = getEntryOnPos( nPos );
274cdf0e10cSrcweir     if( pLBEntry )
275cdf0e10cSrcweir         RemoveParentKeepChilds( pLBEntry );
276cdf0e10cSrcweir     if( pEntry )
277cdf0e10cSrcweir     {
278cdf0e10cSrcweir         if( pEntry->m_bNewEntry )
279cdf0e10cSrcweir             delete pEntry;
280cdf0e10cSrcweir         else
281cdf0e10cSrcweir             m_aToBeDeleted.push_back( pEntry );
282cdf0e10cSrcweir     }
283cdf0e10cSrcweir }
284cdf0e10cSrcweir 
deleteEntries(const rtl::OUString & rTerm)285cdf0e10cSrcweir sal_uIntPtr DictionaryList::deleteEntries( const rtl::OUString& rTerm )
286cdf0e10cSrcweir {
287cdf0e10cSrcweir     sal_uIntPtr nPos = LIST_APPEND;
288cdf0e10cSrcweir     for( sal_Int32 nN=GetRowCount(); nN--; )
289cdf0e10cSrcweir     {
290cdf0e10cSrcweir         DictionaryEntry* pCurEntry = getEntryOnPos( nN );
291cdf0e10cSrcweir         if( rTerm.equals( pCurEntry->m_aTerm ) )
292cdf0e10cSrcweir         {
293cdf0e10cSrcweir             nPos = nN;
294cdf0e10cSrcweir             SvLBoxEntry* pCurLBEntry = GetEntryOnPos( nN );
295cdf0e10cSrcweir             RemoveParentKeepChilds( pCurLBEntry );
296cdf0e10cSrcweir             if( pCurEntry->m_bNewEntry )
297cdf0e10cSrcweir                 delete pCurEntry;
298cdf0e10cSrcweir             else
299cdf0e10cSrcweir                 m_aToBeDeleted.push_back( pCurEntry );
300cdf0e10cSrcweir         }
301cdf0e10cSrcweir     }
302cdf0e10cSrcweir     return nPos;
303cdf0e10cSrcweir }
304cdf0e10cSrcweir 
~DictionaryList()305cdf0e10cSrcweir DictionaryList::~DictionaryList()
306cdf0e10cSrcweir {
307cdf0e10cSrcweir }
308cdf0e10cSrcweir 
activate(HeaderBar * pHeaderBar)309cdf0e10cSrcweir void DictionaryList::activate( HeaderBar* pHeaderBar )
310cdf0e10cSrcweir {
311cdf0e10cSrcweir     if(!m_pHeaderBar)
312cdf0e10cSrcweir     {
313cdf0e10cSrcweir         m_pHeaderBar = pHeaderBar;
314cdf0e10cSrcweir 
315cdf0e10cSrcweir         Point aPos = GetPosPixel();
316cdf0e10cSrcweir         Size  aSize = GetSizePixel();
317cdf0e10cSrcweir 	    Size aHeadSize = pHeaderBar->GetSizePixel();
318cdf0e10cSrcweir 
319cdf0e10cSrcweir         aPos.Y() += aHeadSize.Height();
320cdf0e10cSrcweir         SetPosSizePixel( aPos, Size( aSize.Width(), aSize.Height() - aHeadSize.Height() ) );
321cdf0e10cSrcweir 	    InitHeaderBar( pHeaderBar );
322cdf0e10cSrcweir     }
323cdf0e10cSrcweir     Show();
324cdf0e10cSrcweir }
325cdf0e10cSrcweir 
createHeaderBar(const String & rColumn1,const String & rColumn2,const String & rColumn3,long nWidth1,long nWidth2,long nWidth3)326cdf0e10cSrcweir HeaderBar* DictionaryList::createHeaderBar( const String& rColumn1, const String& rColumn2, const String& rColumn3
327cdf0e10cSrcweir                   , long nWidth1, long nWidth2, long nWidth3 )
328cdf0e10cSrcweir {
329cdf0e10cSrcweir     HeaderBar* pHeaderBar = new HeaderBar( Control::GetParent(), WB_BUTTONSTYLE | WB_BOTTOMBORDER );
330cdf0e10cSrcweir     pHeaderBar->SetPosSizePixel( GetPosPixel(), pHeaderBar->CalcWindowSizePixel() );
331cdf0e10cSrcweir 
332cdf0e10cSrcweir 	HeaderBarItemBits nBits = HEADER_BAR_BITS;
333cdf0e10cSrcweir     pHeaderBar->InsertItem( 1, rColumn1, nWidth1, nBits | HIB_UPARROW );
334cdf0e10cSrcweir 	pHeaderBar->InsertItem( 2, rColumn2, nWidth2, nBits );
335cdf0e10cSrcweir 	pHeaderBar->InsertItem( 3, rColumn3, nWidth3, nBits );
336cdf0e10cSrcweir 
337cdf0e10cSrcweir     pHeaderBar->Show();
338cdf0e10cSrcweir     return pHeaderBar;
339cdf0e10cSrcweir }
340cdf0e10cSrcweir 
Resize()341cdf0e10cSrcweir void DictionaryList::Resize()
342cdf0e10cSrcweir {
343cdf0e10cSrcweir 	SvHeaderTabListBox::Resize();
344cdf0e10cSrcweir     Size aBoxSize = GetOutputSizePixel();
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 	if ( !aBoxSize.Width() )
347cdf0e10cSrcweir 		return;
348cdf0e10cSrcweir 
349cdf0e10cSrcweir    	Size aBarSize = m_pHeaderBar->GetSizePixel();
350cdf0e10cSrcweir     aBarSize.Width() = GetSizePixel().Width();
351cdf0e10cSrcweir 	m_pHeaderBar->SetSizePixel( aBarSize );
352cdf0e10cSrcweir }
353cdf0e10cSrcweir 
sortByColumn(sal_uInt16 nSortColumnIndex,bool bSortAtoZ)354cdf0e10cSrcweir void DictionaryList::sortByColumn( sal_uInt16 nSortColumnIndex, bool bSortAtoZ )
355cdf0e10cSrcweir {
356cdf0e10cSrcweir     m_nSortColumnIndex=nSortColumnIndex;
357cdf0e10cSrcweir     if( nSortColumnIndex<3 )
358cdf0e10cSrcweir     {
359cdf0e10cSrcweir 		if(bSortAtoZ)
360cdf0e10cSrcweir 			GetModel()->SetSortMode(SortAscending);
361cdf0e10cSrcweir 		else
362cdf0e10cSrcweir 			GetModel()->SetSortMode(SortDescending);
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 		GetModel()->SetCompareHdl( LINK( this, DictionaryList, CompareHdl));
365cdf0e10cSrcweir 		GetModel()->Resort();
366cdf0e10cSrcweir 	}
367cdf0e10cSrcweir 	else
368cdf0e10cSrcweir 		GetModel()->SetSortMode(SortNone);
369cdf0e10cSrcweir }
370cdf0e10cSrcweir 
getSortColumn() const371cdf0e10cSrcweir sal_uInt16 DictionaryList::getSortColumn() const
372cdf0e10cSrcweir {
373cdf0e10cSrcweir     return m_nSortColumnIndex;
374cdf0e10cSrcweir }
375cdf0e10cSrcweir 
IMPL_LINK(DictionaryList,CompareHdl,SvSortData *,pData)376cdf0e10cSrcweir IMPL_LINK( DictionaryList, CompareHdl, SvSortData*, pData )
377cdf0e10cSrcweir {
378cdf0e10cSrcweir 	SvLBoxEntry* pLeft = (SvLBoxEntry*)(pData->pLeft );
379cdf0e10cSrcweir 	SvLBoxEntry* pRight = (SvLBoxEntry*)(pData->pRight );
380cdf0e10cSrcweir 	return (long) ColumnCompare(pLeft,pRight);
381cdf0e10cSrcweir }
382cdf0e10cSrcweir 
ColumnCompare(SvLBoxEntry * pLeft,SvLBoxEntry * pRight)383cdf0e10cSrcweir StringCompare DictionaryList::ColumnCompare( SvLBoxEntry* pLeft, SvLBoxEntry* pRight )
384cdf0e10cSrcweir {
385cdf0e10cSrcweir 	StringCompare eCompare=COMPARE_EQUAL;
386cdf0e10cSrcweir 
387cdf0e10cSrcweir 	SvLBoxItem* pLeftItem = getItemAtColumn( pLeft, m_nSortColumnIndex );
388cdf0e10cSrcweir 	SvLBoxItem* pRightItem = getItemAtColumn( pRight, m_nSortColumnIndex );
389cdf0e10cSrcweir 
390cdf0e10cSrcweir 	if(pLeftItem != NULL && pRightItem != NULL)
391cdf0e10cSrcweir 	{
392cdf0e10cSrcweir 		sal_uInt16 nLeftKind=pLeftItem->IsA();
393cdf0e10cSrcweir 		sal_uInt16 nRightKind=pRightItem->IsA();
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 		if(nRightKind == SV_ITEM_ID_LBOXSTRING &&
396cdf0e10cSrcweir 			nLeftKind == SV_ITEM_ID_LBOXSTRING )
397cdf0e10cSrcweir 		{
398cdf0e10cSrcweir 			IntlWrapper aIntlWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
399cdf0e10cSrcweir 			const CollatorWrapper* pCollator = aIntlWrapper.getCaseCollator();
400cdf0e10cSrcweir 
401cdf0e10cSrcweir 			eCompare=(StringCompare)pCollator->compareString( ((SvLBoxString*)pLeftItem)->GetText(),
402cdf0e10cSrcweir 									((SvLBoxString*)pRightItem)->GetText());
403cdf0e10cSrcweir 
404cdf0e10cSrcweir 			if(eCompare==COMPARE_EQUAL)
405cdf0e10cSrcweir                 eCompare=COMPARE_LESS;
406cdf0e10cSrcweir 		}
407cdf0e10cSrcweir 	}
408cdf0e10cSrcweir 	return eCompare;
409cdf0e10cSrcweir }
410cdf0e10cSrcweir 
getItemAtColumn(SvLBoxEntry * pEntry,sal_uInt16 nColumn) const411cdf0e10cSrcweir SvLBoxItem* DictionaryList::getItemAtColumn( SvLBoxEntry* pEntry, sal_uInt16 nColumn ) const
412cdf0e10cSrcweir {
413cdf0e10cSrcweir 	SvLBoxItem* pItem = NULL;
414cdf0e10cSrcweir     if( pEntry )
415cdf0e10cSrcweir 	{
416cdf0e10cSrcweir 		sal_uInt16 nCount = pEntry->ItemCount();
417cdf0e10cSrcweir 		nColumn++;
418cdf0e10cSrcweir 		if( nTreeFlags & TREEFLAG_CHKBTN )
419cdf0e10cSrcweir             nColumn++;
420cdf0e10cSrcweir        	if( nColumn < nCount )
421cdf0e10cSrcweir 			pItem = pEntry->GetItem( nColumn );
422cdf0e10cSrcweir 	}
423cdf0e10cSrcweir 	return pItem;
424cdf0e10cSrcweir }
425cdf0e10cSrcweir 
426cdf0e10cSrcweir //-----------------------------------------------------------------------------
427cdf0e10cSrcweir //-----------------------------------------------------------------------------
428cdf0e10cSrcweir //-----------------------------------------------------------------------------
429cdf0e10cSrcweir 
DictionaryEntry(const rtl::OUString & rTerm,const rtl::OUString & rMapping,sal_Int16 nConversionPropertyType,sal_Bool bNewEntry)430cdf0e10cSrcweir DictionaryEntry::DictionaryEntry( const rtl::OUString& rTerm, const rtl::OUString& rMapping
431cdf0e10cSrcweir                     , sal_Int16 nConversionPropertyType
432cdf0e10cSrcweir                     , sal_Bool bNewEntry )
433cdf0e10cSrcweir         : m_aTerm( rTerm )
434cdf0e10cSrcweir         , m_aMapping( rMapping )
435cdf0e10cSrcweir         , m_nConversionPropertyType( nConversionPropertyType )
436cdf0e10cSrcweir         , m_bNewEntry( bNewEntry )
437cdf0e10cSrcweir {
438cdf0e10cSrcweir     if( m_nConversionPropertyType == 0 )
439cdf0e10cSrcweir         m_nConversionPropertyType = 1;
440cdf0e10cSrcweir }
441cdf0e10cSrcweir 
~DictionaryEntry()442cdf0e10cSrcweir DictionaryEntry::~DictionaryEntry()
443cdf0e10cSrcweir {
444cdf0e10cSrcweir }
445cdf0e10cSrcweir 
operator ==(const DictionaryEntry & rE) const446cdf0e10cSrcweir bool DictionaryEntry::operator==( const DictionaryEntry& rE ) const
447cdf0e10cSrcweir {
448cdf0e10cSrcweir     return m_aTerm == rE.m_aTerm
449cdf0e10cSrcweir             && m_aMapping == rE.m_aMapping
450cdf0e10cSrcweir             && m_nConversionPropertyType == rE.m_nConversionPropertyType;
451cdf0e10cSrcweir }
452cdf0e10cSrcweir 
453cdf0e10cSrcweir //-----------------------------------------------------------------------------
454cdf0e10cSrcweir //-----------------------------------------------------------------------------
455cdf0e10cSrcweir //-----------------------------------------------------------------------------
456cdf0e10cSrcweir 
ChineseDictionaryDialog(Window * pParent)457cdf0e10cSrcweir ChineseDictionaryDialog::ChineseDictionaryDialog( Window* pParent )
458cdf0e10cSrcweir     : ModalDialog( pParent, TextConversionDlgs_ResId( DLG_CHINESEDICTIONARY ) )
459cdf0e10cSrcweir     , m_nTextConversionOptions( i18n::TextConversionOption::NONE )
460cdf0e10cSrcweir     , m_aRB_To_Simplified( this, TextConversionDlgs_ResId( RB_TO_SIMPLIFIED ) )
461cdf0e10cSrcweir     , m_aRB_To_Traditional( this, TextConversionDlgs_ResId( RB_TO_TRADITIONAL ) )
462cdf0e10cSrcweir     , m_aCB_Reverse( this, TextConversionDlgs_ResId( CB_REVERSE ) )
463cdf0e10cSrcweir     , m_aFT_Term( this, TextConversionDlgs_ResId( FT_TERM ) )
464cdf0e10cSrcweir     , m_aED_Term( this, TextConversionDlgs_ResId( ED_TERM ) )
465cdf0e10cSrcweir     , m_aFT_Mapping( this, TextConversionDlgs_ResId( FT_MAPPING ) )
466cdf0e10cSrcweir     , m_aED_Mapping( this, TextConversionDlgs_ResId( ED_MAPPING ) )
467cdf0e10cSrcweir     , m_aFT_Property( this, TextConversionDlgs_ResId( FT_PROPERTY ) )
468cdf0e10cSrcweir     , m_aLB_Property( this, TextConversionDlgs_ResId( LB_PROPERTY ) )
469cdf0e10cSrcweir     , m_pHeaderBar( 0 )
470cdf0e10cSrcweir     , m_aCT_DictionaryToSimplified( this, TextConversionDlgs_ResId( CT_MAPPINGLIST ) )
471cdf0e10cSrcweir     , m_aCT_DictionaryToTraditional( this )
472cdf0e10cSrcweir     , m_aPB_Add( this, TextConversionDlgs_ResId( PB_ADD ) )
473cdf0e10cSrcweir     , m_aPB_Modify( this, TextConversionDlgs_ResId( PB_MODIFY ) )
474cdf0e10cSrcweir     , m_aPB_Delete( this, TextConversionDlgs_ResId( PB_DELETE ) )
475cdf0e10cSrcweir     , m_aFL_Bottomline( this, TextConversionDlgs_ResId( FL_BOTTOMLINE ) )
476cdf0e10cSrcweir     , m_aBP_OK( this, TextConversionDlgs_ResId( PB_OK ) )
477cdf0e10cSrcweir     , m_aBP_Cancel( this, TextConversionDlgs_ResId( PB_CANCEL ) )
478cdf0e10cSrcweir     , m_aBP_Help( this, TextConversionDlgs_ResId( PB_HELP ) )
479cdf0e10cSrcweir     , m_xContext( 0 )
480cdf0e10cSrcweir     , m_xFactory( 0 )
481cdf0e10cSrcweir {
482cdf0e10cSrcweir     FreeResource();
483cdf0e10cSrcweir 
484cdf0e10cSrcweir     m_aRB_To_Simplified.SetHelpId( HID_SVX_CHINESE_DICTIONARY_RB_CONVERSION_TO_SIMPLIFIED );
485cdf0e10cSrcweir     m_aRB_To_Traditional.SetHelpId( HID_SVX_CHINESE_DICTIONARY_RB_CONVERSION_TO_TRADITIONAL );
486cdf0e10cSrcweir 
487cdf0e10cSrcweir     m_aCB_Reverse.SetHelpId( HID_SVX_CHINESE_DICTIONARY_CB_REVERSE );
488cdf0e10cSrcweir 
489cdf0e10cSrcweir     m_aCT_DictionaryToSimplified.SetHelpId( HID_SVX_CHINESE_DICTIONARY_LB_TO_SIMPLIFIED );
490cdf0e10cSrcweir     m_aCT_DictionaryToTraditional.SetHelpId( HID_SVX_CHINESE_DICTIONARY_LB_TO_TRADITIONAL );
491cdf0e10cSrcweir 
492cdf0e10cSrcweir     SvtLinguConfig	aLngCfg;
493cdf0e10cSrcweir     sal_Bool bValue = sal_Bool();
494cdf0e10cSrcweir     Any aAny( aLngCfg.GetProperty( rtl::OUString::createFromAscii( UPN_IS_REVERSE_MAPPING ) ) );
495cdf0e10cSrcweir 	if( aAny >>= bValue )
496cdf0e10cSrcweir 	    m_aCB_Reverse.Check( bValue );
497cdf0e10cSrcweir 
498cdf0e10cSrcweir     m_aLB_Property.SetDropDownLineCount( m_aLB_Property.GetEntryCount() );
499cdf0e10cSrcweir     m_aLB_Property.SelectEntryPos(0);
500cdf0e10cSrcweir 
501cdf0e10cSrcweir     Reference< linguistic2::XConversionDictionary > xDictionary_To_Simplified(0);
502cdf0e10cSrcweir     Reference< linguistic2::XConversionDictionary > xDictionary_To_Traditional(0);
503cdf0e10cSrcweir     //get dictionaries
504cdf0e10cSrcweir     {
505cdf0e10cSrcweir         if(!m_xContext.is())
506cdf0e10cSrcweir             m_xContext = Reference< XComponentContext >( ::cppu::defaultBootstrap_InitialComponentContext() );
507cdf0e10cSrcweir         if(m_xContext.is())
508cdf0e10cSrcweir             m_xFactory = Reference< lang::XMultiComponentFactory >( m_xContext->getServiceManager() );
509cdf0e10cSrcweir         if(m_xFactory.is())
510cdf0e10cSrcweir         {
511cdf0e10cSrcweir             Reference< linguistic2::XConversionDictionaryList > xDictionaryList(
512cdf0e10cSrcweir                                 m_xFactory->createInstanceWithContext(
513cdf0e10cSrcweir                                     rtl::OUString::createFromAscii("com.sun.star.linguistic2.ConversionDictionaryList")
514cdf0e10cSrcweir                                     , m_xContext), uno::UNO_QUERY);
515cdf0e10cSrcweir             if( xDictionaryList.is() )
516cdf0e10cSrcweir             {
517cdf0e10cSrcweir                 Reference< container::XNameContainer > xContainer( xDictionaryList->getDictionaryContainer() );
518cdf0e10cSrcweir                 if(xContainer.is())
519cdf0e10cSrcweir                 {
520cdf0e10cSrcweir                     try
521cdf0e10cSrcweir                     {
522cdf0e10cSrcweir                         rtl::OUString aNameTo_Simplified( rtl::OUString::createFromAscii("ChineseT2S") );
523cdf0e10cSrcweir                         rtl::OUString aNameTo_Traditional( rtl::OUString::createFromAscii("ChineseS2T") );
524cdf0e10cSrcweir                         lang::Locale aLocale;
525cdf0e10cSrcweir                         aLocale.Language = rtl::OUString::createFromAscii("zh");
526cdf0e10cSrcweir 
527cdf0e10cSrcweir                         if( xContainer->hasByName( aNameTo_Simplified ) )
528cdf0e10cSrcweir 	                        xDictionary_To_Simplified = Reference< linguistic2::XConversionDictionary >(
529cdf0e10cSrcweir                                     xContainer->getByName( aNameTo_Simplified ), UNO_QUERY );
530cdf0e10cSrcweir                         else
531cdf0e10cSrcweir                         {
532cdf0e10cSrcweir                             aLocale.Country = rtl::OUString::createFromAscii("TW");
533cdf0e10cSrcweir                             xDictionary_To_Simplified = Reference< linguistic2::XConversionDictionary >(
534cdf0e10cSrcweir                                     xDictionaryList->addNewDictionary( aNameTo_Simplified
535cdf0e10cSrcweir                                     , aLocale, linguistic2::ConversionDictionaryType::SCHINESE_TCHINESE
536cdf0e10cSrcweir                                         ), UNO_QUERY );
537cdf0e10cSrcweir                         }
538cdf0e10cSrcweir 						if (xDictionary_To_Simplified.is())
539cdf0e10cSrcweir 							xDictionary_To_Simplified->setActive( sal_True );
540cdf0e10cSrcweir 
541cdf0e10cSrcweir 
542cdf0e10cSrcweir                         if( xContainer->hasByName( aNameTo_Traditional ) )
543cdf0e10cSrcweir 	                        xDictionary_To_Traditional = Reference< linguistic2::XConversionDictionary >(
544cdf0e10cSrcweir                                     xContainer->getByName( aNameTo_Traditional ), UNO_QUERY );
545cdf0e10cSrcweir                         else
546cdf0e10cSrcweir                         {
547cdf0e10cSrcweir                             aLocale.Country = rtl::OUString::createFromAscii("CN");
548cdf0e10cSrcweir                             xDictionary_To_Traditional = Reference< linguistic2::XConversionDictionary >(
549cdf0e10cSrcweir                                     xDictionaryList->addNewDictionary( aNameTo_Traditional
550cdf0e10cSrcweir                                     , aLocale, linguistic2::ConversionDictionaryType::SCHINESE_TCHINESE
551cdf0e10cSrcweir                                         ), UNO_QUERY );
552cdf0e10cSrcweir                         }
553cdf0e10cSrcweir 						if (xDictionary_To_Traditional.is())
554cdf0e10cSrcweir 							xDictionary_To_Traditional->setActive( sal_True );
555cdf0e10cSrcweir 
556cdf0e10cSrcweir                     }
557cdf0e10cSrcweir                     catch( uno::Exception& )
558cdf0e10cSrcweir                     {
559cdf0e10cSrcweir                     }
560cdf0e10cSrcweir                 }
561cdf0e10cSrcweir             }
562cdf0e10cSrcweir         }
563cdf0e10cSrcweir     }
564cdf0e10cSrcweir 
565cdf0e10cSrcweir     //init HeaderBar and set tabs
566cdf0e10cSrcweir     {
567cdf0e10cSrcweir         String aColumn1( OutputDevice::GetNonMnemonicString( m_aFT_Term.GetText() ) );
568cdf0e10cSrcweir         String aColumn2( OutputDevice::GetNonMnemonicString( m_aFT_Mapping.GetText() ) );
569cdf0e10cSrcweir         String aColumn3( OutputDevice::GetNonMnemonicString( m_aFT_Property.GetText() ) );
570cdf0e10cSrcweir 
571cdf0e10cSrcweir         long nWidth1 = m_aED_Mapping.GetPosPixel().X() - m_aED_Term.GetPosPixel().X();
572cdf0e10cSrcweir         long nWidth2 = m_aLB_Property.GetPosPixel().X() - m_aED_Mapping.GetPosPixel().X();
573cdf0e10cSrcweir         long nWidth3 = m_aLB_Property.GetSizePixel().Width();
574cdf0e10cSrcweir 
575cdf0e10cSrcweir         m_pHeaderBar = m_aCT_DictionaryToSimplified.createHeaderBar( aColumn1, aColumn2, aColumn3, nWidth1, nWidth2, nWidth3 );
576cdf0e10cSrcweir         if(m_pHeaderBar)
577cdf0e10cSrcweir             m_pHeaderBar->SetHelpId( HID_SVX_CHINESE_DICTIONARY_LB_HEADER );
578cdf0e10cSrcweir 
579cdf0e10cSrcweir         long pTabs[] = { 3, 0, nWidth1, nWidth1 + nWidth2 };
580cdf0e10cSrcweir 	    m_aCT_DictionaryToSimplified.SetTabs( &pTabs[0], MAP_PIXEL );
581cdf0e10cSrcweir         m_aCT_DictionaryToTraditional.SetTabs( &pTabs[0], MAP_PIXEL );
582cdf0e10cSrcweir     }
583cdf0e10cSrcweir 
584cdf0e10cSrcweir     //init dictionary controls
585cdf0e10cSrcweir     m_aCT_DictionaryToTraditional.SetPosPixel( m_aCT_DictionaryToSimplified.GetPosPixel() );
586cdf0e10cSrcweir     m_aCT_DictionaryToTraditional.SetSizePixel( m_aCT_DictionaryToSimplified.GetSizePixel() );
587cdf0e10cSrcweir 
588cdf0e10cSrcweir     m_aCT_DictionaryToSimplified.initDictionaryControl( xDictionary_To_Simplified, &m_aLB_Property );
589cdf0e10cSrcweir     m_aCT_DictionaryToTraditional.initDictionaryControl( xDictionary_To_Traditional, &m_aLB_Property );
590cdf0e10cSrcweir 
591cdf0e10cSrcweir     //
592cdf0e10cSrcweir     updateAfterDirectionChange();
593cdf0e10cSrcweir 
594cdf0e10cSrcweir     //set hdl
595cdf0e10cSrcweir     if(m_pHeaderBar)
596cdf0e10cSrcweir         m_pHeaderBar->SetSelectHdl( LINK( this, ChineseDictionaryDialog, HeaderBarClick ) );
597cdf0e10cSrcweir 
598cdf0e10cSrcweir     m_aED_Term.SetModifyHdl( LINK( this, ChineseDictionaryDialog, EditFieldsHdl ) );
599cdf0e10cSrcweir     m_aED_Mapping.SetModifyHdl( LINK( this, ChineseDictionaryDialog, EditFieldsHdl ) );
600cdf0e10cSrcweir     m_aLB_Property.SetSelectHdl( LINK( this, ChineseDictionaryDialog, EditFieldsHdl ) );
601cdf0e10cSrcweir 
602cdf0e10cSrcweir     m_aRB_To_Simplified.SetClickHdl( LINK( this, ChineseDictionaryDialog, DirectionHdl ) );
603cdf0e10cSrcweir     m_aRB_To_Traditional.SetClickHdl( LINK( this, ChineseDictionaryDialog, DirectionHdl ) );
604cdf0e10cSrcweir 
605cdf0e10cSrcweir     m_aCT_DictionaryToSimplified.SetSelectHdl( LINK( this, ChineseDictionaryDialog, MappingSelectHdl ));
606cdf0e10cSrcweir     m_aCT_DictionaryToTraditional.SetSelectHdl( LINK( this, ChineseDictionaryDialog, MappingSelectHdl ));
607cdf0e10cSrcweir 
608cdf0e10cSrcweir     m_aPB_Add.SetClickHdl( LINK( this, ChineseDictionaryDialog, AddHdl ) );
609cdf0e10cSrcweir     m_aPB_Modify.SetClickHdl( LINK( this, ChineseDictionaryDialog, ModifyHdl ) );
610cdf0e10cSrcweir     m_aPB_Delete.SetClickHdl( LINK( this, ChineseDictionaryDialog, DeleteHdl ) );
611cdf0e10cSrcweir }
612cdf0e10cSrcweir 
~ChineseDictionaryDialog()613cdf0e10cSrcweir ChineseDictionaryDialog::~ChineseDictionaryDialog()
614cdf0e10cSrcweir {
615cdf0e10cSrcweir     m_xContext=0;
616cdf0e10cSrcweir     m_xFactory=0;
617cdf0e10cSrcweir     delete m_pHeaderBar;
618cdf0e10cSrcweir }
619cdf0e10cSrcweir 
setDirectionAndTextConversionOptions(bool bDirectionToSimplified,sal_Int32 nTextConversionOptions)620cdf0e10cSrcweir void ChineseDictionaryDialog::setDirectionAndTextConversionOptions( bool bDirectionToSimplified, sal_Int32 nTextConversionOptions /*i18n::TextConversionOption*/ )
621cdf0e10cSrcweir {
622cdf0e10cSrcweir     if( bDirectionToSimplified == bool(m_aRB_To_Simplified.IsChecked())
623cdf0e10cSrcweir         && nTextConversionOptions == m_nTextConversionOptions )
624cdf0e10cSrcweir         return;
625cdf0e10cSrcweir 
626cdf0e10cSrcweir     m_nTextConversionOptions = nTextConversionOptions;
627cdf0e10cSrcweir 
628cdf0e10cSrcweir     if( bDirectionToSimplified )
629cdf0e10cSrcweir         m_aRB_To_Simplified.Check();
630cdf0e10cSrcweir     else
631cdf0e10cSrcweir         m_aRB_To_Traditional.Check();
632cdf0e10cSrcweir     updateAfterDirectionChange();
633cdf0e10cSrcweir }
634cdf0e10cSrcweir 
IMPL_LINK(ChineseDictionaryDialog,DirectionHdl,void *,EMPTYARG)635cdf0e10cSrcweir IMPL_LINK( ChineseDictionaryDialog, DirectionHdl, void*, EMPTYARG )
636cdf0e10cSrcweir {
637cdf0e10cSrcweir     updateAfterDirectionChange();
638cdf0e10cSrcweir     return 0;
639cdf0e10cSrcweir }
640cdf0e10cSrcweir 
updateAfterDirectionChange()641cdf0e10cSrcweir void ChineseDictionaryDialog::updateAfterDirectionChange()
642cdf0e10cSrcweir {
643cdf0e10cSrcweir     Reference< linguistic2::XConversionDictionary > xDictionary(0);
644cdf0e10cSrcweir 
645cdf0e10cSrcweir     if( m_aRB_To_Simplified.IsChecked() )
646cdf0e10cSrcweir     {
647cdf0e10cSrcweir         m_aCT_DictionaryToSimplified.activate( m_pHeaderBar );
648cdf0e10cSrcweir         m_aCT_DictionaryToTraditional.Hide();
649cdf0e10cSrcweir         xDictionary = m_aCT_DictionaryToSimplified.m_xDictionary;
650cdf0e10cSrcweir     }
651cdf0e10cSrcweir     else
652cdf0e10cSrcweir     {
653cdf0e10cSrcweir         m_aCT_DictionaryToTraditional.activate( m_pHeaderBar );
654cdf0e10cSrcweir         m_aCT_DictionaryToSimplified.Hide();
655cdf0e10cSrcweir         xDictionary = m_aCT_DictionaryToTraditional.m_xDictionary;
656cdf0e10cSrcweir     }
657cdf0e10cSrcweir 
658cdf0e10cSrcweir     updateButtons();
659cdf0e10cSrcweir }
660cdf0e10cSrcweir 
IMPL_LINK(ChineseDictionaryDialog,EditFieldsHdl,Control *,EMPTYARG)661cdf0e10cSrcweir IMPL_LINK( ChineseDictionaryDialog, EditFieldsHdl, Control*, EMPTYARG )
662cdf0e10cSrcweir {
663cdf0e10cSrcweir     updateButtons();
664cdf0e10cSrcweir     return 0;
665cdf0e10cSrcweir }
IMPL_LINK(ChineseDictionaryDialog,MappingSelectHdl,void *,EMPTYARG)666cdf0e10cSrcweir IMPL_LINK( ChineseDictionaryDialog, MappingSelectHdl, void*, EMPTYARG )
667cdf0e10cSrcweir {
668cdf0e10cSrcweir     DictionaryEntry* pE = getActiveDictionary().getFirstSelectedEntry();
669cdf0e10cSrcweir     if(pE)
670cdf0e10cSrcweir     {
671cdf0e10cSrcweir         m_aED_Term.SetText( pE->m_aTerm );
672cdf0e10cSrcweir         m_aED_Mapping.SetText( pE->m_aMapping );
673cdf0e10cSrcweir         sal_Int16 nPos = pE->m_nConversionPropertyType-1;
674cdf0e10cSrcweir         if( nPos<0 || nPos>=m_aLB_Property.GetEntryCount() )
675cdf0e10cSrcweir             nPos=0;
676cdf0e10cSrcweir         if( m_aLB_Property.GetEntryCount() )
677cdf0e10cSrcweir             m_aLB_Property.SelectEntryPos(nPos);
678cdf0e10cSrcweir     }
679cdf0e10cSrcweir 
680cdf0e10cSrcweir     updateButtons();
681cdf0e10cSrcweir     return 0;
682cdf0e10cSrcweir }
683cdf0e10cSrcweir 
isEditFieldsHaveContent() const684cdf0e10cSrcweir bool ChineseDictionaryDialog::isEditFieldsHaveContent() const
685cdf0e10cSrcweir {
686cdf0e10cSrcweir     return m_aED_Term.GetText().Len() && m_aED_Mapping.GetText().Len();
687cdf0e10cSrcweir }
688cdf0e10cSrcweir 
isEditFieldsContentEqualsSelectedListContent() const689cdf0e10cSrcweir bool ChineseDictionaryDialog::isEditFieldsContentEqualsSelectedListContent() const
690cdf0e10cSrcweir {
691cdf0e10cSrcweir     DictionaryEntry* pE = getActiveDictionary().getFirstSelectedEntry();
692cdf0e10cSrcweir     if( pE )
693cdf0e10cSrcweir     {
694cdf0e10cSrcweir         if( pE->m_aTerm != rtl::OUString( m_aED_Term.GetText() ) )
695cdf0e10cSrcweir             return false;
696cdf0e10cSrcweir         if( pE->m_aMapping != rtl::OUString( m_aED_Mapping.GetText() ) )
697cdf0e10cSrcweir             return false;
698cdf0e10cSrcweir         if( pE->m_nConversionPropertyType != m_aLB_Property.GetSelectEntryPos()+1 )
699cdf0e10cSrcweir             return false;
700cdf0e10cSrcweir         return true;
701cdf0e10cSrcweir     }
702cdf0e10cSrcweir     return false;
703cdf0e10cSrcweir }
704cdf0e10cSrcweir 
getActiveDictionary() const705cdf0e10cSrcweir const DictionaryList& ChineseDictionaryDialog::getActiveDictionary() const
706cdf0e10cSrcweir {
707cdf0e10cSrcweir     if( m_aRB_To_Traditional.IsChecked() )
708cdf0e10cSrcweir         return m_aCT_DictionaryToTraditional;
709cdf0e10cSrcweir     return m_aCT_DictionaryToSimplified;
710cdf0e10cSrcweir }
711cdf0e10cSrcweir 
getActiveDictionary()712cdf0e10cSrcweir DictionaryList& ChineseDictionaryDialog::getActiveDictionary()
713cdf0e10cSrcweir {
714cdf0e10cSrcweir     if( m_aRB_To_Traditional.IsChecked() )
715cdf0e10cSrcweir         return m_aCT_DictionaryToTraditional;
716cdf0e10cSrcweir     return m_aCT_DictionaryToSimplified;
717cdf0e10cSrcweir }
718cdf0e10cSrcweir 
getReverseDictionary() const719cdf0e10cSrcweir const DictionaryList& ChineseDictionaryDialog::getReverseDictionary() const
720cdf0e10cSrcweir {
721cdf0e10cSrcweir     if( m_aRB_To_Traditional.IsChecked() )
722cdf0e10cSrcweir         return m_aCT_DictionaryToSimplified;
723cdf0e10cSrcweir     return m_aCT_DictionaryToTraditional;
724cdf0e10cSrcweir }
725cdf0e10cSrcweir 
getReverseDictionary()726cdf0e10cSrcweir DictionaryList& ChineseDictionaryDialog::getReverseDictionary()
727cdf0e10cSrcweir {
728cdf0e10cSrcweir     if( m_aRB_To_Traditional.IsChecked() )
729cdf0e10cSrcweir         return m_aCT_DictionaryToSimplified;
730cdf0e10cSrcweir     return m_aCT_DictionaryToTraditional;
731cdf0e10cSrcweir }
732cdf0e10cSrcweir 
updateButtons()733cdf0e10cSrcweir void ChineseDictionaryDialog::updateButtons()
734cdf0e10cSrcweir {
735cdf0e10cSrcweir     bool bAdd = isEditFieldsHaveContent() && !getActiveDictionary().hasTerm( m_aED_Term.GetText() );
736cdf0e10cSrcweir     m_aPB_Add.Enable( bAdd );
737cdf0e10cSrcweir 
738cdf0e10cSrcweir     m_aPB_Delete.Enable( !bAdd && getActiveDictionary().GetSelectedRowCount()>0 );
739cdf0e10cSrcweir 
740cdf0e10cSrcweir //    DictionaryEntry* pFirstSelectedEntry = getActiveDictionary().getFirstSelectedEntry();
741cdf0e10cSrcweir 
742cdf0e10cSrcweir     bool bModify = false;
743cdf0e10cSrcweir     {
744cdf0e10cSrcweir         DictionaryEntry* pFirstSelectedEntry = getActiveDictionary().getFirstSelectedEntry();
745cdf0e10cSrcweir         bModify = !bAdd && getActiveDictionary().GetSelectedRowCount()==1
746cdf0e10cSrcweir                         && pFirstSelectedEntry && pFirstSelectedEntry->m_aTerm.equals( m_aED_Term.GetText() );
747cdf0e10cSrcweir         if( bModify && isEditFieldsContentEqualsSelectedListContent() )
748cdf0e10cSrcweir             bModify = false;
749cdf0e10cSrcweir     }
750cdf0e10cSrcweir     m_aPB_Modify.Enable( bModify );
751cdf0e10cSrcweir }
752cdf0e10cSrcweir 
IMPL_LINK(ChineseDictionaryDialog,AddHdl,void *,EMPTYARG)753cdf0e10cSrcweir IMPL_LINK( ChineseDictionaryDialog, AddHdl, void*, EMPTYARG )
754cdf0e10cSrcweir {
755cdf0e10cSrcweir     if( !isEditFieldsHaveContent() )
756cdf0e10cSrcweir         return 0;
757cdf0e10cSrcweir 
758cdf0e10cSrcweir     sal_Int16 nConversionPropertyType = m_aLB_Property.GetSelectEntryPos()+1;
759cdf0e10cSrcweir 
760cdf0e10cSrcweir     getActiveDictionary().addEntry( m_aED_Term.GetText(), m_aED_Mapping.GetText(), nConversionPropertyType );
761cdf0e10cSrcweir 
762cdf0e10cSrcweir     if( m_aCB_Reverse.IsChecked() )
763cdf0e10cSrcweir     {
764cdf0e10cSrcweir         getReverseDictionary().deleteEntries( m_aED_Mapping.GetText() );
765cdf0e10cSrcweir         getReverseDictionary().addEntry( m_aED_Mapping.GetText(), m_aED_Term.GetText(), nConversionPropertyType );
766cdf0e10cSrcweir     }
767cdf0e10cSrcweir 
768cdf0e10cSrcweir     updateButtons();
769cdf0e10cSrcweir     return 0;
770cdf0e10cSrcweir }
IMPL_LINK(ChineseDictionaryDialog,ModifyHdl,void *,EMPTYARG)771cdf0e10cSrcweir IMPL_LINK( ChineseDictionaryDialog, ModifyHdl, void*, EMPTYARG )
772cdf0e10cSrcweir {
773cdf0e10cSrcweir     rtl::OUString aTerm( m_aED_Term.GetText() );
774cdf0e10cSrcweir     rtl::OUString aMapping( m_aED_Mapping.GetText() );
775cdf0e10cSrcweir     sal_Int16 nConversionPropertyType = m_aLB_Property.GetSelectEntryPos()+1;
776cdf0e10cSrcweir 
777cdf0e10cSrcweir     DictionaryList& rActive  = getActiveDictionary();
778cdf0e10cSrcweir     DictionaryList& rReverse = getReverseDictionary();
779cdf0e10cSrcweir 
780cdf0e10cSrcweir     DictionaryEntry* pE = rActive.getFirstSelectedEntry();
781cdf0e10cSrcweir     if( pE->m_aTerm != aTerm )
782cdf0e10cSrcweir         return 0;
783cdf0e10cSrcweir 
784cdf0e10cSrcweir     if( pE )
785cdf0e10cSrcweir     {
786cdf0e10cSrcweir         if( pE->m_aMapping != aMapping || pE->m_nConversionPropertyType != nConversionPropertyType )
787cdf0e10cSrcweir         {
788cdf0e10cSrcweir             if( m_aCB_Reverse.IsChecked() )
789cdf0e10cSrcweir             {
790cdf0e10cSrcweir                 sal_uIntPtr nPos = rReverse.deleteEntries( pE->m_aMapping );
791cdf0e10cSrcweir                 nPos = rReverse.deleteEntries( aMapping );
792cdf0e10cSrcweir                 rReverse.addEntry( aMapping, aTerm, nConversionPropertyType, nPos );
793cdf0e10cSrcweir             }
794cdf0e10cSrcweir 
795cdf0e10cSrcweir             sal_uIntPtr nPos = rActive.deleteEntries( aTerm );
796cdf0e10cSrcweir             rActive.addEntry( aTerm, aMapping, nConversionPropertyType, nPos );
797cdf0e10cSrcweir         }
798cdf0e10cSrcweir     }
799cdf0e10cSrcweir 
800cdf0e10cSrcweir     updateButtons();
801cdf0e10cSrcweir     return 0;
802cdf0e10cSrcweir }
803cdf0e10cSrcweir 
IMPL_LINK(ChineseDictionaryDialog,DeleteHdl,void *,EMPTYARG)804cdf0e10cSrcweir IMPL_LINK( ChineseDictionaryDialog, DeleteHdl, void*, EMPTYARG )
805cdf0e10cSrcweir {
806cdf0e10cSrcweir     DictionaryList& rActive  = getActiveDictionary();
807cdf0e10cSrcweir     DictionaryList& rReverse = getReverseDictionary();
808cdf0e10cSrcweir 
809cdf0e10cSrcweir     if( rActive.GetSelectedRowCount()>0)
810cdf0e10cSrcweir     {
811cdf0e10cSrcweir         DictionaryEntry* pEntry;
812cdf0e10cSrcweir 
813cdf0e10cSrcweir         rtl::OUString aMapping;
814cdf0e10cSrcweir         for( sal_Int32 nN=rActive.GetRowCount(); nN--; )
815cdf0e10cSrcweir         {
816cdf0e10cSrcweir             if( rActive.IsRowSelected( nN ) )
817cdf0e10cSrcweir             {
818cdf0e10cSrcweir                 pEntry = rActive.getEntryOnPos( nN );
819cdf0e10cSrcweir                 if(pEntry)
820cdf0e10cSrcweir                 {
821cdf0e10cSrcweir                     aMapping = pEntry->m_aMapping;
822cdf0e10cSrcweir                     rActive.deleteEntryOnPos( nN );
823cdf0e10cSrcweir                     if( m_aCB_Reverse.IsChecked() )
824cdf0e10cSrcweir                         rReverse.deleteEntries( aMapping  );
825cdf0e10cSrcweir                 }
826cdf0e10cSrcweir                 break;
827cdf0e10cSrcweir             }
828cdf0e10cSrcweir         }
829cdf0e10cSrcweir     }
830cdf0e10cSrcweir 
831cdf0e10cSrcweir     updateButtons();
832cdf0e10cSrcweir     return 0;
833cdf0e10cSrcweir }
834cdf0e10cSrcweir 
Execute()835cdf0e10cSrcweir short ChineseDictionaryDialog::Execute()
836cdf0e10cSrcweir {
837cdf0e10cSrcweir     sal_Int32 nTextConversionOptions = m_nTextConversionOptions;
838cdf0e10cSrcweir     if(m_nTextConversionOptions | i18n::TextConversionOption::USE_CHARACTER_VARIANTS )
839cdf0e10cSrcweir         nTextConversionOptions = nTextConversionOptions^i18n::TextConversionOption::USE_CHARACTER_VARIANTS ;
840cdf0e10cSrcweir 
841cdf0e10cSrcweir     m_aCT_DictionaryToSimplified.refillFromDictionary( nTextConversionOptions );
842cdf0e10cSrcweir     m_aCT_DictionaryToTraditional.refillFromDictionary( m_nTextConversionOptions );
843cdf0e10cSrcweir 
844cdf0e10cSrcweir     short nRet = ModalDialog::Execute();
845cdf0e10cSrcweir 
846cdf0e10cSrcweir     if( nRet == RET_OK )
847cdf0e10cSrcweir     {
848cdf0e10cSrcweir         //save settings to configuration
849cdf0e10cSrcweir         SvtLinguConfig	aLngCfg;
850cdf0e10cSrcweir         Any aAny;
851cdf0e10cSrcweir 	    aAny <<= sal_Bool( !!m_aCB_Reverse.IsChecked() );
852cdf0e10cSrcweir 	    aLngCfg.SetProperty( rtl::OUString::createFromAscii( UPN_IS_REVERSE_MAPPING ), aAny );
853cdf0e10cSrcweir 
854cdf0e10cSrcweir         m_aCT_DictionaryToSimplified.save();
855cdf0e10cSrcweir         m_aCT_DictionaryToTraditional.save();
856cdf0e10cSrcweir     }
857cdf0e10cSrcweir 
858cdf0e10cSrcweir     m_aCT_DictionaryToSimplified.deleteAll();
859cdf0e10cSrcweir     m_aCT_DictionaryToTraditional.deleteAll();
860cdf0e10cSrcweir 
861cdf0e10cSrcweir     return nRet;
862cdf0e10cSrcweir }
863cdf0e10cSrcweir 
IMPL_LINK(ChineseDictionaryDialog,HeaderBarClick,void *,EMPTYARG)864cdf0e10cSrcweir IMPL_LINK( ChineseDictionaryDialog, HeaderBarClick, void*, EMPTYARG )
865cdf0e10cSrcweir {
866cdf0e10cSrcweir 	if(m_pHeaderBar)
867cdf0e10cSrcweir     {
868cdf0e10cSrcweir 	    sal_uInt16 nId = m_pHeaderBar->GetCurItemId();
869cdf0e10cSrcweir         HeaderBarItemBits nBits = m_pHeaderBar->GetItemBits(nId);
870cdf0e10cSrcweir 	    if( nBits & HIB_CLICKABLE )
871cdf0e10cSrcweir 	    {
872cdf0e10cSrcweir             //set new arrow positions in headerbar
873cdf0e10cSrcweir             m_pHeaderBar->SetItemBits( getActiveDictionary().getSortColumn()+1, HEADER_BAR_BITS );
874cdf0e10cSrcweir             if( nBits & HIB_UPARROW )
875cdf0e10cSrcweir                 m_pHeaderBar->SetItemBits( nId, HEADER_BAR_BITS | HIB_DOWNARROW );
876cdf0e10cSrcweir             else
877cdf0e10cSrcweir                 m_pHeaderBar->SetItemBits( nId, HEADER_BAR_BITS | HIB_UPARROW );
878cdf0e10cSrcweir 
879cdf0e10cSrcweir             //sort lists
880cdf0e10cSrcweir             nBits = m_pHeaderBar->GetItemBits(nId);
881cdf0e10cSrcweir             bool bSortAtoZ = nBits & HIB_UPARROW;
882cdf0e10cSrcweir             getActiveDictionary().sortByColumn(nId-1,bSortAtoZ);
883cdf0e10cSrcweir             getReverseDictionary().sortByColumn(nId-1,bSortAtoZ);
884cdf0e10cSrcweir 	    }
885cdf0e10cSrcweir     }
886cdf0e10cSrcweir 	return 0;
887cdf0e10cSrcweir }
888cdf0e10cSrcweir 
889cdf0e10cSrcweir //.............................................................................
890cdf0e10cSrcweir } //end namespace
891cdf0e10cSrcweir //.............................................................................
892