1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: chinese_dictionarydialog.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include "chinese_dictionarydialog.hxx"
35 #include "chinese_dictionarydialog.hrc"
37 #include <cppuhelper/bootstrap.hxx>
38 #include <com/sun/star/i18n/TextConversionOption.hpp>
39 #include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
40 #include <com/sun/star/linguistic2/ConversionPropertyType.hpp>
41 #include <com/sun/star/linguistic2/XConversionDictionaryList.hpp>
42 #include <com/sun/star/linguistic2/XConversionPropertyType.hpp>
43 #include <com/sun/star/util/XFlushable.hpp>
44 #include <com/sun/star/lang/Locale.hpp>
45 // header for class HeaderBar
46 #include <svtools/headbar.hxx>
47 // header for define RET_OK
48 #include <vcl/msgbox.hxx>
49 // header for class SvtLinguConfigItem
50 #include <svtools/lingucfg.hxx>
51 #include <svtools/linguprops.hxx>
52 // header for class IntlWrapper
53 #include <unotools/intlwrapper.hxx>
54 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
55 #include <comphelper/processfactory.hxx>
57 // header for class Application
58 #include <vcl/svapp.hxx>
59 #ifndef _SVX_HELPID_HRC
63 //disable compiler warning C4355: 'this' : used in base member initializer list
65 # pragma warning (disable : 4355)
68 //.............................................................................
69 namespace textconversiondlgs
71 //.............................................................................
73 using namespace ::com::sun::star
;
74 using namespace ::com::sun::star::uno
;
76 #define HEADER_BAR_BITS ( HIB_LEFT | HIB_VCENTER | HIB_CLICKABLE | HIB_FIXED | HIB_FIXEDPOS )
78 DictionaryList::DictionaryList( Window
* pParent
, const ResId
& rResId
)
79 : SvHeaderTabListBox( pParent
, rResId
)
82 , m_pPropertyTypeNameListBox(0)
84 , m_nSortColumnIndex(0)
88 DictionaryList::DictionaryList( Window
* pParent
)
89 : SvHeaderTabListBox( pParent
, 0 )
92 , m_pPropertyTypeNameListBox(0)
94 , m_nSortColumnIndex(0)
98 String
DictionaryList::getPropertyTypeName( sal_Int16 nConversionPropertyType
) const
100 if(!m_pPropertyTypeNameListBox
|| !m_pPropertyTypeNameListBox
->GetEntryCount())
103 USHORT nPos
= static_cast<USHORT
>( nConversionPropertyType
)-1;
104 if(nPos
<m_pPropertyTypeNameListBox
->GetEntryCount())
105 return m_pPropertyTypeNameListBox
->GetEntry(nPos
);
106 return m_pPropertyTypeNameListBox
->GetEntry(0);
109 String
DictionaryList::makeTabString( const DictionaryEntry
& rEntry
) const
111 String
aStr( rEntry
.m_aTerm
);
113 aStr
+= String( rEntry
.m_aMapping
);
115 aStr
+= getPropertyTypeName( rEntry
.m_nConversionPropertyType
);
119 void DictionaryList::initDictionaryControl( const Reference
< linguistic2::XConversionDictionary
>& xDictionary
120 , ListBox
* pPropertyTypeNameListBox
)
122 SetWindowBits( WB_VSCROLL
);
123 SetSelectionMode( SINGLE_SELECTION
);
124 SetBorderStyle( WINDOW_BORDER_MONO
);
127 if(m_xDictionary
.is())
130 m_xDictionary
= xDictionary
;
131 m_pPropertyTypeNameListBox
= pPropertyTypeNameListBox
;
134 void DictionaryList::save()
136 if( !m_xDictionary
.is() )
139 Reference
< linguistic2::XConversionPropertyType
> xPropertyType( m_xDictionary
, uno::UNO_QUERY
);
144 for( nN
= m_aToBeDeleted
.size(); nN
--; )
146 pE
= m_aToBeDeleted
[nN
];
147 m_xDictionary
->removeEntry( pE
->m_aTerm
, pE
->m_aMapping
);
149 for( nN
= GetRowCount(); nN
--; )
151 pE
= getEntryOnPos( nN
);
156 m_xDictionary
->addEntry( pE
->m_aTerm
, pE
->m_aMapping
);
157 xPropertyType
->setPropertyType( pE
->m_aTerm
, pE
->m_aMapping
, pE
->m_nConversionPropertyType
);
159 catch( uno::Exception
& )
165 Reference
< util::XFlushable
> xFlush( m_xDictionary
, uno::UNO_QUERY
);
170 void DictionaryList::deleteAll()
173 for( nN
= GetRowCount(); nN
--; )
174 deleteEntryOnPos( nN
);
175 for( nN
= m_aToBeDeleted
.size(); nN
--; )
177 DictionaryEntry
* pE
= m_aToBeDeleted
[nN
];
180 m_aToBeDeleted
.clear();
183 void DictionaryList::refillFromDictionary( sal_Int32 nTextConversionOptions
)
187 if(!m_xDictionary
.is())
190 Sequence
< rtl::OUString
> aLeftList( m_xDictionary
->getConversionEntries( linguistic2::ConversionDirection_FROM_LEFT
) );
191 sal_Int32 nCount
= aLeftList
.getLength();
193 Reference
< linguistic2::XConversionPropertyType
> xPropertyType( m_xDictionary
, uno::UNO_QUERY
);
195 rtl::OUString aLeft
, aRight
;
196 sal_Int16 nConversionPropertyType
;
198 for(sal_Int32 nN
=0; nN
<nCount
; nN
++)
200 aLeft
= aLeftList
[nN
];
201 Sequence
< rtl::OUString
> aRightList( m_xDictionary
->getConversions(
202 aLeft
, 0, aLeft
.getLength()
203 , linguistic2::ConversionDirection_FROM_LEFT
, nTextConversionOptions
) );
205 if(aRightList
.getLength()!=1)
207 OSL_ASSERT("The Chinese Translation Dictionary should have exactly one Mapping for each term.");
211 aRight
= aRightList
[0];
212 nConversionPropertyType
= linguistic2::ConversionPropertyType::OTHER
;
213 if(xPropertyType
.is())
214 nConversionPropertyType
= xPropertyType
->getPropertyType(aLeft
, aRight
);
216 DictionaryEntry
* pEntry
= new DictionaryEntry( aLeft
, aRight
, nConversionPropertyType
);
217 SvLBoxEntry
* pLBEntry
= InsertEntry( makeTabString( *pEntry
) );
218 pLBEntry
->SetUserData( pEntry
);
221 if( GetEntryCount() > 0 )
225 DictionaryEntry
* DictionaryList::getFirstSelectedEntry() const
227 DictionaryEntry
* pRet
=0;
228 for( sal_Int32 nN
=GetRowCount(); nN
--; )
230 if( IsRowSelected( nN
) )
232 pRet
= getEntryOnPos( nN
);
239 DictionaryEntry
* DictionaryList::getEntryOnPos( sal_Int32 nPos
) const
241 DictionaryEntry
* pEntry
=0;
242 SvLBoxEntry
* pLBEntry
= GetEntryOnPos( nPos
);
244 pEntry
= (DictionaryEntry
*)pLBEntry
->GetUserData();
248 DictionaryEntry
* DictionaryList::getTermEntry( const rtl::OUString
& rTerm
) const
250 DictionaryEntry
* pE
= 0;
251 for( sal_Int32 nN
=GetRowCount(); nN
--; )
253 pE
= getEntryOnPos( nN
);
254 if( pE
&& rTerm
.equals( pE
->m_aTerm
) )
260 bool DictionaryList::hasTerm( const rtl::OUString
& rTerm
) const
262 return getTermEntry(rTerm
) !=0 ;
265 void DictionaryList::addEntry( const rtl::OUString
& rTerm
, const rtl::OUString
& rMapping
266 , sal_Int16 nConversionPropertyType
, ULONG nPos
)
268 if( hasTerm( rTerm
) )
271 DictionaryEntry
* pEntry
= new DictionaryEntry( rTerm
, rMapping
, nConversionPropertyType
, sal_True
);
272 SvLBoxEntry
* pLBEntry
= InsertEntryToColumn( makeTabString( *pEntry
), nPos
);
273 pLBEntry
->SetUserData( pEntry
);
274 SelectRow( GetEntryPos( pLBEntry
) );
277 void DictionaryList::deleteEntryOnPos( sal_Int32 nPos
)
279 SvLBoxEntry
* pLBEntry
= GetEntryOnPos( nPos
);
280 DictionaryEntry
* pEntry
= getEntryOnPos( nPos
);
282 RemoveParentKeepChilds( pLBEntry
);
285 if( pEntry
->m_bNewEntry
)
288 m_aToBeDeleted
.push_back( pEntry
);
292 ULONG
DictionaryList::deleteEntries( const rtl::OUString
& rTerm
)
294 ULONG nPos
= LIST_APPEND
;
295 for( sal_Int32 nN
=GetRowCount(); nN
--; )
297 DictionaryEntry
* pCurEntry
= getEntryOnPos( nN
);
298 if( rTerm
.equals( pCurEntry
->m_aTerm
) )
301 SvLBoxEntry
* pCurLBEntry
= GetEntryOnPos( nN
);
302 RemoveParentKeepChilds( pCurLBEntry
);
303 if( pCurEntry
->m_bNewEntry
)
306 m_aToBeDeleted
.push_back( pCurEntry
);
312 DictionaryList::~DictionaryList()
316 void DictionaryList::activate( HeaderBar
* pHeaderBar
)
320 m_pHeaderBar
= pHeaderBar
;
322 Point aPos
= GetPosPixel();
323 Size aSize
= GetSizePixel();
324 Size aHeadSize
= pHeaderBar
->GetSizePixel();
326 aPos
.Y() += aHeadSize
.Height();
327 SetPosSizePixel( aPos
, Size( aSize
.Width(), aSize
.Height() - aHeadSize
.Height() ) );
328 InitHeaderBar( pHeaderBar
);
333 HeaderBar
* DictionaryList::createHeaderBar( const String
& rColumn1
, const String
& rColumn2
, const String
& rColumn3
334 , long nWidth1
, long nWidth2
, long nWidth3
)
336 HeaderBar
* pHeaderBar
= new HeaderBar( Control::GetParent(), WB_BUTTONSTYLE
| WB_BOTTOMBORDER
);
337 pHeaderBar
->SetPosSizePixel( GetPosPixel(), pHeaderBar
->CalcWindowSizePixel() );
339 HeaderBarItemBits nBits
= HEADER_BAR_BITS
;
340 pHeaderBar
->InsertItem( 1, rColumn1
, nWidth1
, nBits
| HIB_UPARROW
);
341 pHeaderBar
->InsertItem( 2, rColumn2
, nWidth2
, nBits
);
342 pHeaderBar
->InsertItem( 3, rColumn3
, nWidth3
, nBits
);
348 void DictionaryList::Resize()
350 SvHeaderTabListBox::Resize();
351 Size aBoxSize
= GetOutputSizePixel();
353 if ( !aBoxSize
.Width() )
356 Size aBarSize
= m_pHeaderBar
->GetSizePixel();
357 aBarSize
.Width() = GetSizePixel().Width();
358 m_pHeaderBar
->SetSizePixel( aBarSize
);
361 void DictionaryList::sortByColumn( USHORT nSortColumnIndex
, bool bSortAtoZ
)
363 m_nSortColumnIndex
=nSortColumnIndex
;
364 if( nSortColumnIndex
<3 )
367 GetModel()->SetSortMode(SortAscending
);
369 GetModel()->SetSortMode(SortDescending
);
371 GetModel()->SetCompareHdl( LINK( this, DictionaryList
, CompareHdl
));
372 GetModel()->Resort();
375 GetModel()->SetSortMode(SortNone
);
378 USHORT
DictionaryList::getSortColumn() const
380 return m_nSortColumnIndex
;
383 IMPL_LINK( DictionaryList
, CompareHdl
, SvSortData
*, pData
)
385 SvLBoxEntry
* pLeft
= (SvLBoxEntry
*)(pData
->pLeft
);
386 SvLBoxEntry
* pRight
= (SvLBoxEntry
*)(pData
->pRight
);
387 return (long) ColumnCompare(pLeft
,pRight
);
390 StringCompare
DictionaryList::ColumnCompare( SvLBoxEntry
* pLeft
, SvLBoxEntry
* pRight
)
392 StringCompare eCompare
=COMPARE_EQUAL
;
394 SvLBoxItem
* pLeftItem
= getItemAtColumn( pLeft
, m_nSortColumnIndex
);
395 SvLBoxItem
* pRightItem
= getItemAtColumn( pRight
, m_nSortColumnIndex
);
397 if(pLeftItem
!= NULL
&& pRightItem
!= NULL
)
399 USHORT nLeftKind
=pLeftItem
->IsA();
400 USHORT nRightKind
=pRightItem
->IsA();
402 if(nRightKind
== SV_ITEM_ID_LBOXSTRING
&&
403 nLeftKind
== SV_ITEM_ID_LBOXSTRING
)
405 IntlWrapper
aIntlWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
406 const CollatorWrapper
* pCollator
= aIntlWrapper
.getCaseCollator();
408 eCompare
=(StringCompare
)pCollator
->compareString( ((SvLBoxString
*)pLeftItem
)->GetText(),
409 ((SvLBoxString
*)pRightItem
)->GetText());
411 if(eCompare
==COMPARE_EQUAL
)
412 eCompare
=COMPARE_LESS
;
418 SvLBoxItem
* DictionaryList::getItemAtColumn( SvLBoxEntry
* pEntry
, USHORT nColumn
) const
420 SvLBoxItem
* pItem
= NULL
;
423 USHORT nCount
= pEntry
->ItemCount();
425 if( nTreeFlags
& TREEFLAG_CHKBTN
)
427 if( nColumn
< nCount
)
428 pItem
= pEntry
->GetItem( nColumn
);
433 //-----------------------------------------------------------------------------
434 //-----------------------------------------------------------------------------
435 //-----------------------------------------------------------------------------
437 DictionaryEntry::DictionaryEntry( const rtl::OUString
& rTerm
, const rtl::OUString
& rMapping
438 , sal_Int16 nConversionPropertyType
439 , sal_Bool bNewEntry
)
441 , m_aMapping( rMapping
)
442 , m_nConversionPropertyType( nConversionPropertyType
)
443 , m_bNewEntry( bNewEntry
)
445 if( m_nConversionPropertyType
== 0 )
446 m_nConversionPropertyType
= 1;
449 DictionaryEntry::DictionaryEntry()
452 , m_nConversionPropertyType( linguistic2::ConversionPropertyType::OTHER
)
453 , m_bNewEntry( sal_True
)
457 DictionaryEntry::~DictionaryEntry()
461 bool DictionaryEntry::operator==( const DictionaryEntry
& rE
) const
463 return m_aTerm
== rE
.m_aTerm
464 && m_aMapping
== rE
.m_aMapping
465 && m_nConversionPropertyType
== rE
.m_nConversionPropertyType
;
468 //-----------------------------------------------------------------------------
469 //-----------------------------------------------------------------------------
470 //-----------------------------------------------------------------------------
472 ChineseDictionaryDialog::ChineseDictionaryDialog( Window
* pParent
)
473 : ModalDialog( pParent
, TextConversionDlgs_ResId( DLG_CHINESEDICTIONARY
) )
474 , m_nTextConversionOptions( i18n::TextConversionOption::NONE
)
475 , m_aRB_To_Simplified( this, TextConversionDlgs_ResId( RB_TO_SIMPLIFIED
) )
476 , m_aRB_To_Traditional( this, TextConversionDlgs_ResId( RB_TO_TRADITIONAL
) )
477 , m_aCB_Reverse( this, TextConversionDlgs_ResId( CB_REVERSE
) )
478 , m_aFT_Term( this, TextConversionDlgs_ResId( FT_TERM
) )
479 , m_aED_Term( this, TextConversionDlgs_ResId( ED_TERM
) )
480 , m_aFT_Mapping( this, TextConversionDlgs_ResId( FT_MAPPING
) )
481 , m_aED_Mapping( this, TextConversionDlgs_ResId( ED_MAPPING
) )
482 , m_aFT_Property( this, TextConversionDlgs_ResId( FT_PROPERTY
) )
483 , m_aLB_Property( this, TextConversionDlgs_ResId( LB_PROPERTY
) )
485 , m_aCT_DictionaryToSimplified( this, TextConversionDlgs_ResId( CT_MAPPINGLIST
) )
486 , m_aCT_DictionaryToTraditional( this )
487 , m_aPB_Add( this, TextConversionDlgs_ResId( PB_ADD
) )
488 , m_aPB_Modify( this, TextConversionDlgs_ResId( PB_MODIFY
) )
489 , m_aPB_Delete( this, TextConversionDlgs_ResId( PB_DELETE
) )
490 , m_aFL_Bottomline( this, TextConversionDlgs_ResId( FL_BOTTOMLINE
) )
491 , m_aBP_OK( this, TextConversionDlgs_ResId( PB_OK
) )
492 , m_aBP_Cancel( this, TextConversionDlgs_ResId( PB_CANCEL
) )
493 , m_aBP_Help( this, TextConversionDlgs_ResId( PB_HELP
) )
499 m_aRB_To_Simplified
.SetHelpId( HID_SVX_CHINESE_DICTIONARY_RB_CONVERSION_TO_SIMPLIFIED
);
500 m_aRB_To_Traditional
.SetHelpId( HID_SVX_CHINESE_DICTIONARY_RB_CONVERSION_TO_TRADITIONAL
);
502 m_aCB_Reverse
.SetHelpId( HID_SVX_CHINESE_DICTIONARY_CB_REVERSE
);
504 m_aCT_DictionaryToSimplified
.SetHelpId( HID_SVX_CHINESE_DICTIONARY_LB_TO_SIMPLIFIED
);
505 m_aCT_DictionaryToTraditional
.SetHelpId( HID_SVX_CHINESE_DICTIONARY_LB_TO_TRADITIONAL
);
507 SvtLinguConfig aLngCfg
;
508 sal_Bool bValue
= sal_Bool();
509 Any
aAny( aLngCfg
.GetProperty( rtl::OUString::createFromAscii( UPN_IS_REVERSE_MAPPING
) ) );
510 if( aAny
>>= bValue
)
511 m_aCB_Reverse
.Check( bValue
);
513 m_aLB_Property
.SetDropDownLineCount( m_aLB_Property
.GetEntryCount() );
514 m_aLB_Property
.SelectEntryPos(0);
516 Reference
< linguistic2::XConversionDictionary
> xDictionary_To_Simplified(0);
517 Reference
< linguistic2::XConversionDictionary
> xDictionary_To_Traditional(0);
521 m_xContext
= Reference
< XComponentContext
>( ::cppu::defaultBootstrap_InitialComponentContext() );
523 m_xFactory
= Reference
< lang::XMultiComponentFactory
>( m_xContext
->getServiceManager() );
526 Reference
< linguistic2::XConversionDictionaryList
> xDictionaryList(
527 m_xFactory
->createInstanceWithContext(
528 rtl::OUString::createFromAscii("com.sun.star.linguistic2.ConversionDictionaryList")
529 , m_xContext
), uno::UNO_QUERY
);
530 if( xDictionaryList
.is() )
532 Reference
< container::XNameContainer
> xContainer( xDictionaryList
->getDictionaryContainer() );
537 rtl::OUString
aNameTo_Simplified( rtl::OUString::createFromAscii("ChineseT2S") );
538 rtl::OUString
aNameTo_Traditional( rtl::OUString::createFromAscii("ChineseS2T") );
539 lang::Locale aLocale
;
540 aLocale
.Language
= rtl::OUString::createFromAscii("zh");
542 if( xContainer
->hasByName( aNameTo_Simplified
) )
543 xDictionary_To_Simplified
= Reference
< linguistic2::XConversionDictionary
>(
544 xContainer
->getByName( aNameTo_Simplified
), UNO_QUERY
);
547 aLocale
.Country
= rtl::OUString::createFromAscii("TW");
548 xDictionary_To_Simplified
= Reference
< linguistic2::XConversionDictionary
>(
549 xDictionaryList
->addNewDictionary( aNameTo_Simplified
550 , aLocale
, linguistic2::ConversionDictionaryType::SCHINESE_TCHINESE
553 if (xDictionary_To_Simplified
.is())
554 xDictionary_To_Simplified
->setActive( sal_True
);
557 if( xContainer
->hasByName( aNameTo_Traditional
) )
558 xDictionary_To_Traditional
= Reference
< linguistic2::XConversionDictionary
>(
559 xContainer
->getByName( aNameTo_Traditional
), UNO_QUERY
);
562 aLocale
.Country
= rtl::OUString::createFromAscii("CN");
563 xDictionary_To_Traditional
= Reference
< linguistic2::XConversionDictionary
>(
564 xDictionaryList
->addNewDictionary( aNameTo_Traditional
565 , aLocale
, linguistic2::ConversionDictionaryType::SCHINESE_TCHINESE
568 if (xDictionary_To_Traditional
.is())
569 xDictionary_To_Traditional
->setActive( sal_True
);
572 catch( uno::Exception
& )
580 //init HeaderBar and set tabs
582 String
aColumn1( OutputDevice::GetNonMnemonicString( m_aFT_Term
.GetText() ) );
583 String
aColumn2( OutputDevice::GetNonMnemonicString( m_aFT_Mapping
.GetText() ) );
584 String
aColumn3( OutputDevice::GetNonMnemonicString( m_aFT_Property
.GetText() ) );
586 long nWidth1
= m_aED_Mapping
.GetPosPixel().X() - m_aED_Term
.GetPosPixel().X();
587 long nWidth2
= m_aLB_Property
.GetPosPixel().X() - m_aED_Mapping
.GetPosPixel().X();
588 long nWidth3
= m_aLB_Property
.GetSizePixel().Width();
590 m_pHeaderBar
= m_aCT_DictionaryToSimplified
.createHeaderBar( aColumn1
, aColumn2
, aColumn3
, nWidth1
, nWidth2
, nWidth3
);
592 m_pHeaderBar
->SetHelpId( HID_SVX_CHINESE_DICTIONARY_LB_HEADER
);
594 long pTabs
[] = { 3, 0, nWidth1
, nWidth1
+ nWidth2
};
595 m_aCT_DictionaryToSimplified
.SetTabs( &pTabs
[0], MAP_PIXEL
);
596 m_aCT_DictionaryToTraditional
.SetTabs( &pTabs
[0], MAP_PIXEL
);
599 //init dictionary controls
600 m_aCT_DictionaryToTraditional
.SetPosPixel( m_aCT_DictionaryToSimplified
.GetPosPixel() );
601 m_aCT_DictionaryToTraditional
.SetSizePixel( m_aCT_DictionaryToSimplified
.GetSizePixel() );
603 m_aCT_DictionaryToSimplified
.initDictionaryControl( xDictionary_To_Simplified
, &m_aLB_Property
);
604 m_aCT_DictionaryToTraditional
.initDictionaryControl( xDictionary_To_Traditional
, &m_aLB_Property
);
607 updateAfterDirectionChange();
611 m_pHeaderBar
->SetSelectHdl( LINK( this, ChineseDictionaryDialog
, HeaderBarClick
) );
613 m_aED_Term
.SetModifyHdl( LINK( this, ChineseDictionaryDialog
, EditFieldsHdl
) );
614 m_aED_Mapping
.SetModifyHdl( LINK( this, ChineseDictionaryDialog
, EditFieldsHdl
) );
615 m_aLB_Property
.SetSelectHdl( LINK( this, ChineseDictionaryDialog
, EditFieldsHdl
) );
617 m_aRB_To_Simplified
.SetClickHdl( LINK( this, ChineseDictionaryDialog
, DirectionHdl
) );
618 m_aRB_To_Traditional
.SetClickHdl( LINK( this, ChineseDictionaryDialog
, DirectionHdl
) );
620 m_aCT_DictionaryToSimplified
.SetSelectHdl( LINK( this, ChineseDictionaryDialog
, MappingSelectHdl
));
621 m_aCT_DictionaryToTraditional
.SetSelectHdl( LINK( this, ChineseDictionaryDialog
, MappingSelectHdl
));
623 m_aPB_Add
.SetClickHdl( LINK( this, ChineseDictionaryDialog
, AddHdl
) );
624 m_aPB_Modify
.SetClickHdl( LINK( this, ChineseDictionaryDialog
, ModifyHdl
) );
625 m_aPB_Delete
.SetClickHdl( LINK( this, ChineseDictionaryDialog
, DeleteHdl
) );
628 ChineseDictionaryDialog::~ChineseDictionaryDialog()
635 void ChineseDictionaryDialog::setDirectionAndTextConversionOptions( bool bDirectionToSimplified
, sal_Int32 nTextConversionOptions
/*i18n::TextConversionOption*/ )
637 if( bDirectionToSimplified
== bool(m_aRB_To_Simplified
.IsChecked())
638 && nTextConversionOptions
== m_nTextConversionOptions
)
641 m_nTextConversionOptions
= nTextConversionOptions
;
643 if( bDirectionToSimplified
)
644 m_aRB_To_Simplified
.Check();
646 m_aRB_To_Traditional
.Check();
647 updateAfterDirectionChange();
650 IMPL_LINK( ChineseDictionaryDialog
, DirectionHdl
, void*, EMPTYARG
)
652 updateAfterDirectionChange();
656 void ChineseDictionaryDialog::updateAfterDirectionChange()
658 Reference
< linguistic2::XConversionDictionary
> xDictionary(0);
660 if( m_aRB_To_Simplified
.IsChecked() )
662 m_aCT_DictionaryToSimplified
.activate( m_pHeaderBar
);
663 m_aCT_DictionaryToTraditional
.Hide();
664 xDictionary
= m_aCT_DictionaryToSimplified
.m_xDictionary
;
668 m_aCT_DictionaryToTraditional
.activate( m_pHeaderBar
);
669 m_aCT_DictionaryToSimplified
.Hide();
670 xDictionary
= m_aCT_DictionaryToTraditional
.m_xDictionary
;
676 IMPL_LINK( ChineseDictionaryDialog
, EditFieldsHdl
, Control
*, EMPTYARG
)
681 IMPL_LINK( ChineseDictionaryDialog
, MappingSelectHdl
, void*, EMPTYARG
)
683 DictionaryEntry
* pE
= getActiveDictionary().getFirstSelectedEntry();
686 m_aED_Term
.SetText( pE
->m_aTerm
);
687 m_aED_Mapping
.SetText( pE
->m_aMapping
);
688 sal_Int16 nPos
= pE
->m_nConversionPropertyType
-1;
689 if( nPos
<0 || nPos
>=m_aLB_Property
.GetEntryCount() )
691 if( m_aLB_Property
.GetEntryCount() )
692 m_aLB_Property
.SelectEntryPos(nPos
);
699 bool ChineseDictionaryDialog::isEditFieldsHaveContent() const
701 return m_aED_Term
.GetText().Len() && m_aED_Mapping
.GetText().Len();
704 bool ChineseDictionaryDialog::isEditFieldsContentEqualsSelectedListContent() const
706 DictionaryEntry
* pE
= getActiveDictionary().getFirstSelectedEntry();
709 if( pE
->m_aTerm
!= rtl::OUString( m_aED_Term
.GetText() ) )
711 if( pE
->m_aMapping
!= rtl::OUString( m_aED_Mapping
.GetText() ) )
713 if( pE
->m_nConversionPropertyType
!= m_aLB_Property
.GetSelectEntryPos()+1 )
720 const DictionaryList
& ChineseDictionaryDialog::getActiveDictionary() const
722 if( m_aRB_To_Traditional
.IsChecked() )
723 return m_aCT_DictionaryToTraditional
;
724 return m_aCT_DictionaryToSimplified
;
727 DictionaryList
& ChineseDictionaryDialog::getActiveDictionary()
729 if( m_aRB_To_Traditional
.IsChecked() )
730 return m_aCT_DictionaryToTraditional
;
731 return m_aCT_DictionaryToSimplified
;
734 const DictionaryList
& ChineseDictionaryDialog::getReverseDictionary() const
736 if( m_aRB_To_Traditional
.IsChecked() )
737 return m_aCT_DictionaryToSimplified
;
738 return m_aCT_DictionaryToTraditional
;
741 DictionaryList
& ChineseDictionaryDialog::getReverseDictionary()
743 if( m_aRB_To_Traditional
.IsChecked() )
744 return m_aCT_DictionaryToSimplified
;
745 return m_aCT_DictionaryToTraditional
;
748 void ChineseDictionaryDialog::updateButtons()
750 bool bAdd
= isEditFieldsHaveContent() && !getActiveDictionary().hasTerm( m_aED_Term
.GetText() );
751 m_aPB_Add
.Enable( bAdd
);
753 m_aPB_Delete
.Enable( !bAdd
&& getActiveDictionary().GetSelectedRowCount()>0 );
755 // DictionaryEntry* pFirstSelectedEntry = getActiveDictionary().getFirstSelectedEntry();
757 bool bModify
= false;
759 DictionaryEntry
* pFirstSelectedEntry
= getActiveDictionary().getFirstSelectedEntry();
760 bModify
= !bAdd
&& getActiveDictionary().GetSelectedRowCount()==1
761 && pFirstSelectedEntry
&& pFirstSelectedEntry
->m_aTerm
.equals( m_aED_Term
.GetText() );
762 if( bModify
&& isEditFieldsContentEqualsSelectedListContent() )
765 m_aPB_Modify
.Enable( bModify
);
768 IMPL_LINK( ChineseDictionaryDialog
, AddHdl
, void*, EMPTYARG
)
770 if( !isEditFieldsHaveContent() )
773 sal_Int16 nConversionPropertyType
= m_aLB_Property
.GetSelectEntryPos()+1;
775 getActiveDictionary().addEntry( m_aED_Term
.GetText(), m_aED_Mapping
.GetText(), nConversionPropertyType
);
777 if( m_aCB_Reverse
.IsChecked() )
779 getReverseDictionary().deleteEntries( m_aED_Mapping
.GetText() );
780 getReverseDictionary().addEntry( m_aED_Mapping
.GetText(), m_aED_Term
.GetText(), nConversionPropertyType
);
786 IMPL_LINK( ChineseDictionaryDialog
, ModifyHdl
, void*, EMPTYARG
)
788 rtl::OUString
aTerm( m_aED_Term
.GetText() );
789 rtl::OUString
aMapping( m_aED_Mapping
.GetText() );
790 sal_Int16 nConversionPropertyType
= m_aLB_Property
.GetSelectEntryPos()+1;
792 DictionaryList
& rActive
= getActiveDictionary();
793 DictionaryList
& rReverse
= getReverseDictionary();
795 DictionaryEntry
* pE
= rActive
.getFirstSelectedEntry();
796 if( pE
->m_aTerm
!= aTerm
)
801 if( pE
->m_aMapping
!= aMapping
|| pE
->m_nConversionPropertyType
!= nConversionPropertyType
)
803 if( m_aCB_Reverse
.IsChecked() )
805 ULONG nPos
= rReverse
.deleteEntries( pE
->m_aMapping
);
806 nPos
= rReverse
.deleteEntries( aMapping
);
807 rReverse
.addEntry( aMapping
, aTerm
, nConversionPropertyType
, nPos
);
810 ULONG nPos
= rActive
.deleteEntries( aTerm
);
811 rActive
.addEntry( aTerm
, aMapping
, nConversionPropertyType
, nPos
);
819 IMPL_LINK( ChineseDictionaryDialog
, DeleteHdl
, void*, EMPTYARG
)
821 DictionaryList
& rActive
= getActiveDictionary();
822 DictionaryList
& rReverse
= getReverseDictionary();
824 if( rActive
.GetSelectedRowCount()>0)
826 DictionaryEntry
* pEntry
;
828 rtl::OUString aMapping
;
829 for( sal_Int32 nN
=rActive
.GetRowCount(); nN
--; )
831 if( rActive
.IsRowSelected( nN
) )
833 pEntry
= rActive
.getEntryOnPos( nN
);
836 aMapping
= pEntry
->m_aMapping
;
837 rActive
.deleteEntryOnPos( nN
);
838 if( m_aCB_Reverse
.IsChecked() )
839 rReverse
.deleteEntries( aMapping
);
850 short ChineseDictionaryDialog::Execute()
852 sal_Int32 nTextConversionOptions
= m_nTextConversionOptions
;
853 if(m_nTextConversionOptions
| i18n::TextConversionOption::USE_CHARACTER_VARIANTS
)
854 nTextConversionOptions
= nTextConversionOptions
^i18n::TextConversionOption::USE_CHARACTER_VARIANTS
;
856 m_aCT_DictionaryToSimplified
.refillFromDictionary( nTextConversionOptions
);
857 m_aCT_DictionaryToTraditional
.refillFromDictionary( m_nTextConversionOptions
);
859 short nRet
= ModalDialog::Execute();
863 //save settings to configuration
864 SvtLinguConfig aLngCfg
;
866 aAny
<<= sal_Bool( !!m_aCB_Reverse
.IsChecked() );
867 aLngCfg
.SetProperty( rtl::OUString::createFromAscii( UPN_IS_REVERSE_MAPPING
), aAny
);
869 m_aCT_DictionaryToSimplified
.save();
870 m_aCT_DictionaryToTraditional
.save();
873 m_aCT_DictionaryToSimplified
.deleteAll();
874 m_aCT_DictionaryToTraditional
.deleteAll();
879 IMPL_LINK( ChineseDictionaryDialog
, HeaderBarClick
, void*, EMPTYARG
)
883 USHORT nId
= m_pHeaderBar
->GetCurItemId();
884 HeaderBarItemBits nBits
= m_pHeaderBar
->GetItemBits(nId
);
885 if( nBits
& HIB_CLICKABLE
)
887 //set new arrow positions in headerbar
888 m_pHeaderBar
->SetItemBits( getActiveDictionary().getSortColumn()+1, HEADER_BAR_BITS
);
889 if( nBits
& HIB_UPARROW
)
890 m_pHeaderBar
->SetItemBits( nId
, HEADER_BAR_BITS
| HIB_DOWNARROW
);
892 m_pHeaderBar
->SetItemBits( nId
, HEADER_BAR_BITS
| HIB_UPARROW
);
895 nBits
= m_pHeaderBar
->GetItemBits(nId
);
896 bool bSortAtoZ
= nBits
& HIB_UPARROW
;
897 getActiveDictionary().sortByColumn(nId
-1,bSortAtoZ
);
898 getReverseDictionary().sortByColumn(nId
-1,bSortAtoZ
);
904 //.............................................................................
906 //.............................................................................