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