1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "chinese_dictionarydialog.hxx"
22 #include "chinese_dictionarydialog.hrc"
24 #include <cppuhelper/bootstrap.hxx>
25 #include <com/sun/star/i18n/TextConversionOption.hpp>
26 #include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
27 #include <com/sun/star/linguistic2/ConversionPropertyType.hpp>
28 #include <com/sun/star/linguistic2/ConversionDictionaryList.hpp>
29 #include <com/sun/star/linguistic2/XConversionPropertyType.hpp>
30 #include <com/sun/star/util/XFlushable.hpp>
31 #include <com/sun/star/lang/Locale.hpp>
32 // header for class HeaderBar
33 #include <svtools/headbar.hxx>
34 #include <svtools/svlbitm.hxx>
35 #include "svtools/treelistentry.hxx"
36 // header for define RET_OK
37 #include <vcl/msgbox.hxx>
38 // header for class SvtLinguConfigItem
39 #include <unotools/lingucfg.hxx>
40 #include <unotools/linguprops.hxx>
41 // header for class IntlWrapper
42 #include <unotools/intlwrapper.hxx>
43 #include <comphelper/processfactory.hxx>
44 // header for class Application
45 #include <vcl/svapp.hxx>
48 //disable compiler warning C4355: 'this' : used in base member initializer list
50 # pragma warning (disable : 4355)
53 //.............................................................................
54 namespace textconversiondlgs
56 //.............................................................................
58 using namespace ::com::sun::star
;
59 using namespace ::com::sun::star::uno
;
61 #define HEADER_BAR_BITS ( HIB_LEFT | HIB_VCENTER | HIB_CLICKABLE | HIB_FIXED | HIB_FIXEDPOS )
63 DictionaryList::DictionaryList( Window
* pParent
, const ResId
& rResId
)
64 : SvHeaderTabListBox( pParent
, rResId
)
67 , m_pPropertyTypeNameListBox(0)
69 , m_nSortColumnIndex(0)
73 DictionaryList::DictionaryList( Window
* pParent
)
74 : SvHeaderTabListBox( pParent
, 0 )
77 , m_pPropertyTypeNameListBox(0)
79 , m_nSortColumnIndex(0)
83 String
DictionaryList::getPropertyTypeName( sal_Int16 nConversionPropertyType
) const
85 if(!m_pPropertyTypeNameListBox
|| !m_pPropertyTypeNameListBox
->GetEntryCount())
88 sal_uInt16 nPos
= static_cast<sal_uInt16
>( nConversionPropertyType
)-1;
89 if(nPos
<m_pPropertyTypeNameListBox
->GetEntryCount())
90 return m_pPropertyTypeNameListBox
->GetEntry(nPos
);
91 return m_pPropertyTypeNameListBox
->GetEntry(0);
94 String
DictionaryList::makeTabString( const DictionaryEntry
& rEntry
) const
96 String
aStr( rEntry
.m_aTerm
);
98 aStr
+= String( rEntry
.m_aMapping
);
100 aStr
+= getPropertyTypeName( rEntry
.m_nConversionPropertyType
);
104 void DictionaryList::initDictionaryControl( const Reference
< linguistic2::XConversionDictionary
>& xDictionary
105 , ListBox
* pPropertyTypeNameListBox
)
107 SetStyle( WB_VSCROLL
| WB_TABSTOP
);
108 SetSelectionMode( SINGLE_SELECTION
);
109 SetBorderStyle( WINDOW_BORDER_MONO
);
112 if(m_xDictionary
.is())
115 m_xDictionary
= xDictionary
;
116 m_pPropertyTypeNameListBox
= pPropertyTypeNameListBox
;
119 void DictionaryList::save()
121 if( !m_xDictionary
.is() )
124 Reference
< linguistic2::XConversionPropertyType
> xPropertyType( m_xDictionary
, uno::UNO_QUERY
);
129 for( nN
= m_aToBeDeleted
.size(); nN
--; )
131 pE
= m_aToBeDeleted
[nN
];
132 m_xDictionary
->removeEntry( pE
->m_aTerm
, pE
->m_aMapping
);
134 for( nN
= GetRowCount(); nN
--; )
136 pE
= getEntryOnPos( nN
);
141 m_xDictionary
->addEntry( pE
->m_aTerm
, pE
->m_aMapping
);
142 xPropertyType
->setPropertyType( pE
->m_aTerm
, pE
->m_aMapping
, pE
->m_nConversionPropertyType
);
144 catch( uno::Exception
& )
150 Reference
< util::XFlushable
> xFlush( m_xDictionary
, uno::UNO_QUERY
);
155 void DictionaryList::deleteAll()
158 for( nN
= GetRowCount(); nN
--; )
159 deleteEntryOnPos( nN
);
160 for( nN
= m_aToBeDeleted
.size(); nN
--; )
162 DictionaryEntry
* pE
= m_aToBeDeleted
[nN
];
165 m_aToBeDeleted
.clear();
168 void DictionaryList::refillFromDictionary( sal_Int32 nTextConversionOptions
)
172 if(!m_xDictionary
.is())
175 Sequence
< OUString
> aLeftList( m_xDictionary
->getConversionEntries( linguistic2::ConversionDirection_FROM_LEFT
) );
176 sal_Int32 nCount
= aLeftList
.getLength();
178 Reference
< linguistic2::XConversionPropertyType
> xPropertyType( m_xDictionary
, uno::UNO_QUERY
);
180 OUString aLeft
, aRight
;
181 sal_Int16 nConversionPropertyType
;
183 for(sal_Int32 nN
=0; nN
<nCount
; nN
++)
185 aLeft
= aLeftList
[nN
];
186 Sequence
< OUString
> aRightList( m_xDictionary
->getConversions(
187 aLeft
, 0, aLeft
.getLength()
188 , linguistic2::ConversionDirection_FROM_LEFT
, nTextConversionOptions
) );
190 if(aRightList
.getLength()!=1)
192 OSL_FAIL("The Chinese Translation Dictionary should have exactly one Mapping for each term.");
196 aRight
= aRightList
[0];
197 nConversionPropertyType
= linguistic2::ConversionPropertyType::OTHER
;
198 if(xPropertyType
.is())
199 nConversionPropertyType
= xPropertyType
->getPropertyType(aLeft
, aRight
);
201 DictionaryEntry
* pEntry
= new DictionaryEntry( aLeft
, aRight
, nConversionPropertyType
);
202 SvTreeListEntry
* pLBEntry
= InsertEntry( makeTabString( *pEntry
) );
203 pLBEntry
->SetUserData( pEntry
);
206 if( GetEntryCount() > 0 )
210 DictionaryEntry
* DictionaryList::getFirstSelectedEntry() const
212 DictionaryEntry
* pRet
=0;
213 for( sal_Int32 nN
=GetRowCount(); nN
--; )
215 if( IsRowSelected( nN
) )
217 pRet
= getEntryOnPos( nN
);
224 DictionaryEntry
* DictionaryList::getEntryOnPos( sal_Int32 nPos
) const
226 DictionaryEntry
* pEntry
=0;
227 SvTreeListEntry
* pLBEntry
= GetEntryOnPos( nPos
);
229 pEntry
= (DictionaryEntry
*)pLBEntry
->GetUserData();
233 DictionaryEntry
* DictionaryList::getTermEntry( const OUString
& rTerm
) const
235 DictionaryEntry
* pE
= 0;
236 for( sal_Int32 nN
=GetRowCount(); nN
--; )
238 pE
= getEntryOnPos( nN
);
239 if( pE
&& rTerm
.equals( pE
->m_aTerm
) )
245 bool DictionaryList::hasTerm( const OUString
& rTerm
) const
247 return getTermEntry(rTerm
) !=0 ;
250 void DictionaryList::addEntry( const OUString
& rTerm
, const OUString
& rMapping
251 , sal_Int16 nConversionPropertyType
, sal_uIntPtr nPos
)
253 if( hasTerm( rTerm
) )
256 DictionaryEntry
* pEntry
= new DictionaryEntry( rTerm
, rMapping
, nConversionPropertyType
, true );
257 SvTreeListEntry
* pLBEntry
= InsertEntryToColumn( makeTabString( *pEntry
), nPos
);
258 pLBEntry
->SetUserData( pEntry
);
259 SelectRow( GetEntryPos( pLBEntry
) );
262 void DictionaryList::deleteEntryOnPos( sal_Int32 nPos
)
264 SvTreeListEntry
* pLBEntry
= GetEntryOnPos( nPos
);
265 DictionaryEntry
* pEntry
= getEntryOnPos( nPos
);
267 RemoveParentKeepChildren( pLBEntry
);
270 if( pEntry
->m_bNewEntry
)
273 m_aToBeDeleted
.push_back( pEntry
);
277 sal_uIntPtr
DictionaryList::deleteEntries( const OUString
& rTerm
)
279 sal_uIntPtr nPos
= LIST_APPEND
;
280 for( sal_Int32 nN
=GetRowCount(); nN
--; )
282 DictionaryEntry
* pCurEntry
= getEntryOnPos( nN
);
283 if( rTerm
.equals( pCurEntry
->m_aTerm
) )
286 SvTreeListEntry
* pCurLBEntry
= GetEntryOnPos( nN
);
287 RemoveParentKeepChildren( pCurLBEntry
);
288 if( pCurEntry
->m_bNewEntry
)
291 m_aToBeDeleted
.push_back( pCurEntry
);
297 DictionaryList::~DictionaryList()
301 void DictionaryList::activate( HeaderBar
* pHeaderBar
)
305 m_pHeaderBar
= pHeaderBar
;
307 Point aPos
= GetPosPixel();
308 Size aSize
= GetSizePixel();
309 Size aHeadSize
= pHeaderBar
->GetSizePixel();
311 aPos
.Y() += aHeadSize
.Height();
312 SetPosSizePixel( aPos
, Size( aSize
.Width(), aSize
.Height() - aHeadSize
.Height() ) );
313 InitHeaderBar( pHeaderBar
);
318 HeaderBar
* DictionaryList::createHeaderBar( const String
& rColumn1
, const String
& rColumn2
, const String
& rColumn3
319 , long nWidth1
, long nWidth2
, long nWidth3
)
321 HeaderBar
* pHeaderBar
= new HeaderBar( Control::GetParent(), WB_BUTTONSTYLE
| WB_BOTTOMBORDER
);
322 pHeaderBar
->SetPosSizePixel( GetPosPixel(), pHeaderBar
->CalcWindowSizePixel() );
324 HeaderBarItemBits nBits
= HEADER_BAR_BITS
;
325 pHeaderBar
->InsertItem( 1, rColumn1
, nWidth1
, nBits
| HIB_UPARROW
);
326 pHeaderBar
->InsertItem( 2, rColumn2
, nWidth2
, nBits
);
327 pHeaderBar
->InsertItem( 3, rColumn3
, nWidth3
, nBits
);
333 void DictionaryList::Resize()
335 SvHeaderTabListBox::Resize();
336 Size aBoxSize
= GetOutputSizePixel();
338 if ( !aBoxSize
.Width() )
341 Size aBarSize
= m_pHeaderBar
->GetSizePixel();
342 aBarSize
.Width() = GetSizePixel().Width();
343 m_pHeaderBar
->SetSizePixel( aBarSize
);
346 void DictionaryList::sortByColumn( sal_uInt16 nSortColumnIndex
, bool bSortAtoZ
)
348 m_nSortColumnIndex
=nSortColumnIndex
;
349 if( nSortColumnIndex
<3 )
352 GetModel()->SetSortMode(SortAscending
);
354 GetModel()->SetSortMode(SortDescending
);
356 GetModel()->SetCompareHdl( LINK( this, DictionaryList
, CompareHdl
));
357 GetModel()->Resort();
360 GetModel()->SetSortMode(SortNone
);
363 sal_uInt16
DictionaryList::getSortColumn() const
365 return m_nSortColumnIndex
;
368 IMPL_LINK( DictionaryList
, CompareHdl
, SvSortData
*, pData
)
370 SvTreeListEntry
* pLeft
= (SvTreeListEntry
*)(pData
->pLeft
);
371 SvTreeListEntry
* pRight
= (SvTreeListEntry
*)(pData
->pRight
);
372 return (long) ColumnCompare(pLeft
,pRight
);
375 StringCompare
DictionaryList::ColumnCompare( SvTreeListEntry
* pLeft
, SvTreeListEntry
* pRight
)
377 StringCompare eCompare
=COMPARE_EQUAL
;
379 SvLBoxItem
* pLeftItem
= getItemAtColumn( pLeft
, m_nSortColumnIndex
);
380 SvLBoxItem
* pRightItem
= getItemAtColumn( pRight
, m_nSortColumnIndex
);
382 if(pLeftItem
!= NULL
&& pRightItem
!= NULL
)
384 sal_uInt16 nLeftKind
= pLeftItem
->GetType();
385 sal_uInt16 nRightKind
= pRightItem
->GetType();
387 if(nRightKind
== SV_ITEM_ID_LBOXSTRING
&&
388 nLeftKind
== SV_ITEM_ID_LBOXSTRING
)
390 IntlWrapper
aIntlWrapper( Application::GetSettings().GetLanguageTag() );
391 const CollatorWrapper
* pCollator
= aIntlWrapper
.getCaseCollator();
393 eCompare
=(StringCompare
)pCollator
->compareString( ((SvLBoxString
*)pLeftItem
)->GetText(),
394 ((SvLBoxString
*)pRightItem
)->GetText());
396 if(eCompare
==COMPARE_EQUAL
)
397 eCompare
=COMPARE_LESS
;
403 SvLBoxItem
* DictionaryList::getItemAtColumn( SvTreeListEntry
* pEntry
, sal_uInt16 nColumn
) const
405 SvLBoxItem
* pItem
= NULL
;
408 sal_uInt16 nCount
= pEntry
->ItemCount();
410 if( nTreeFlags
& TREEFLAG_CHKBTN
)
412 if( nColumn
< nCount
)
413 pItem
= pEntry
->GetItem( nColumn
);
418 //-----------------------------------------------------------------------------
419 //-----------------------------------------------------------------------------
420 //-----------------------------------------------------------------------------
422 DictionaryEntry::DictionaryEntry( const OUString
& rTerm
, const OUString
& rMapping
423 , sal_Int16 nConversionPropertyType
426 , m_aMapping( rMapping
)
427 , m_nConversionPropertyType( nConversionPropertyType
)
428 , m_bNewEntry( bNewEntry
)
430 if( m_nConversionPropertyType
== 0 )
431 m_nConversionPropertyType
= 1;
434 DictionaryEntry::~DictionaryEntry()
438 bool DictionaryEntry::operator==( const DictionaryEntry
& rE
) const
440 return m_aTerm
== rE
.m_aTerm
441 && m_aMapping
== rE
.m_aMapping
442 && m_nConversionPropertyType
== rE
.m_nConversionPropertyType
;
445 //-----------------------------------------------------------------------------
446 //-----------------------------------------------------------------------------
447 //-----------------------------------------------------------------------------
449 ChineseDictionaryDialog::ChineseDictionaryDialog( Window
* pParent
)
450 : ModalDialog( pParent
, TextConversionDlgs_ResId( DLG_CHINESEDICTIONARY
) )
451 , m_nTextConversionOptions( i18n::TextConversionOption::NONE
)
452 , m_aRB_To_Simplified( this, TextConversionDlgs_ResId( RB_TO_SIMPLIFIED
) )
453 , m_aRB_To_Traditional( this, TextConversionDlgs_ResId( RB_TO_TRADITIONAL
) )
454 , m_aCB_Reverse( this, TextConversionDlgs_ResId( CB_REVERSE
) )
455 , m_aFT_Term( this, TextConversionDlgs_ResId( FT_TERM
) )
456 , m_aED_Term( this, TextConversionDlgs_ResId( ED_TERM
) )
457 , m_aFT_Mapping( this, TextConversionDlgs_ResId( FT_MAPPING
) )
458 , m_aED_Mapping( this, TextConversionDlgs_ResId( ED_MAPPING
) )
459 , m_aFT_Property( this, TextConversionDlgs_ResId( FT_PROPERTY
) )
460 , m_aLB_Property( this, TextConversionDlgs_ResId( LB_PROPERTY
) )
462 , m_aCT_DictionaryToSimplified( this, TextConversionDlgs_ResId( CT_MAPPINGLIST
) )
463 , m_aCT_DictionaryToTraditional( this )
464 , m_aPB_Add( this, TextConversionDlgs_ResId( PB_ADD
) )
465 , m_aPB_Modify( this, TextConversionDlgs_ResId( PB_MODIFY
) )
466 , m_aPB_Delete( this, TextConversionDlgs_ResId( PB_DELETE
) )
467 , m_aFL_Bottomline( this, TextConversionDlgs_ResId( FL_BOTTOMLINE
) )
468 , m_aBP_OK( this, TextConversionDlgs_ResId( PB_OK
) )
469 , m_aBP_Cancel( this, TextConversionDlgs_ResId( PB_CANCEL
) )
470 , m_aBP_Help( this, TextConversionDlgs_ResId( PB_HELP
) )
475 m_aRB_To_Simplified
.SetHelpId( HID_SVX_CHINESE_DICTIONARY_RB_CONVERSION_TO_SIMPLIFIED
);
476 m_aRB_To_Traditional
.SetHelpId( HID_SVX_CHINESE_DICTIONARY_RB_CONVERSION_TO_TRADITIONAL
);
478 m_aCB_Reverse
.SetHelpId( HID_SVX_CHINESE_DICTIONARY_CB_REVERSE
);
480 m_aCT_DictionaryToSimplified
.SetHelpId( HID_SVX_CHINESE_DICTIONARY_LB_TO_SIMPLIFIED
);
481 m_aCT_DictionaryToTraditional
.SetHelpId( HID_SVX_CHINESE_DICTIONARY_LB_TO_TRADITIONAL
);
483 SvtLinguConfig aLngCfg
;
484 sal_Bool bValue
= sal_Bool();
485 Any
aAny( aLngCfg
.GetProperty( OUString( UPN_IS_REVERSE_MAPPING
) ) );
486 if( aAny
>>= bValue
)
487 m_aCB_Reverse
.Check( bValue
);
489 m_aLB_Property
.SetDropDownLineCount( m_aLB_Property
.GetEntryCount() );
490 m_aLB_Property
.SelectEntryPos(0);
492 Reference
< linguistic2::XConversionDictionary
> xDictionary_To_Simplified(0);
493 Reference
< linguistic2::XConversionDictionary
> xDictionary_To_Traditional(0);
497 m_xContext
= Reference
< XComponentContext
>( ::cppu::defaultBootstrap_InitialComponentContext() );
500 Reference
< linguistic2::XConversionDictionaryList
> xDictionaryList
= linguistic2::ConversionDictionaryList::create(m_xContext
);
501 Reference
< container::XNameContainer
> xContainer( xDictionaryList
->getDictionaryContainer() );
506 OUString
aNameTo_Simplified("ChineseT2S");
507 OUString
aNameTo_Traditional("ChineseS2T");
508 lang::Locale aLocale
;
509 aLocale
.Language
= OUString("zh");
511 if( xContainer
->hasByName( aNameTo_Simplified
) )
512 xDictionary_To_Simplified
= Reference
< linguistic2::XConversionDictionary
>(
513 xContainer
->getByName( aNameTo_Simplified
), UNO_QUERY
);
516 aLocale
.Country
= OUString("TW");
517 xDictionary_To_Simplified
= Reference
< linguistic2::XConversionDictionary
>(
518 xDictionaryList
->addNewDictionary( aNameTo_Simplified
519 , aLocale
, linguistic2::ConversionDictionaryType::SCHINESE_TCHINESE
522 if (xDictionary_To_Simplified
.is())
523 xDictionary_To_Simplified
->setActive( sal_True
);
526 if( xContainer
->hasByName( aNameTo_Traditional
) )
527 xDictionary_To_Traditional
= Reference
< linguistic2::XConversionDictionary
>(
528 xContainer
->getByName( aNameTo_Traditional
), UNO_QUERY
);
531 aLocale
.Country
= OUString("CN");
532 xDictionary_To_Traditional
= Reference
< linguistic2::XConversionDictionary
>(
533 xDictionaryList
->addNewDictionary( aNameTo_Traditional
534 , aLocale
, linguistic2::ConversionDictionaryType::SCHINESE_TCHINESE
537 if (xDictionary_To_Traditional
.is())
538 xDictionary_To_Traditional
->setActive( sal_True
);
541 catch( uno::Exception
& )
548 //init HeaderBar and set tabs
550 String
aColumn1( OutputDevice::GetNonMnemonicString( m_aFT_Term
.GetText() ) );
551 String
aColumn2( OutputDevice::GetNonMnemonicString( m_aFT_Mapping
.GetText() ) );
552 String
aColumn3( OutputDevice::GetNonMnemonicString( m_aFT_Property
.GetText() ) );
554 long nWidth1
= m_aED_Mapping
.GetPosPixel().X() - m_aED_Term
.GetPosPixel().X();
555 long nWidth2
= m_aLB_Property
.GetPosPixel().X() - m_aED_Mapping
.GetPosPixel().X();
556 long nWidth3
= m_aLB_Property
.GetSizePixel().Width();
558 m_pHeaderBar
= m_aCT_DictionaryToSimplified
.createHeaderBar( aColumn1
, aColumn2
, aColumn3
, nWidth1
, nWidth2
, nWidth3
);
560 m_pHeaderBar
->SetHelpId( HID_SVX_CHINESE_DICTIONARY_LB_HEADER
);
562 long pTabs
[] = { 3, 0, nWidth1
, nWidth1
+ nWidth2
};
563 m_aCT_DictionaryToSimplified
.SetTabs( &pTabs
[0], MAP_PIXEL
);
564 m_aCT_DictionaryToTraditional
.SetTabs( &pTabs
[0], MAP_PIXEL
);
567 //init dictionary controls
568 m_aCT_DictionaryToTraditional
.SetPosPixel( m_aCT_DictionaryToSimplified
.GetPosPixel() );
569 m_aCT_DictionaryToTraditional
.SetSizePixel( m_aCT_DictionaryToSimplified
.GetSizePixel() );
571 m_aCT_DictionaryToSimplified
.initDictionaryControl( xDictionary_To_Simplified
, &m_aLB_Property
);
572 m_aCT_DictionaryToTraditional
.initDictionaryControl( xDictionary_To_Traditional
, &m_aLB_Property
);
575 updateAfterDirectionChange();
579 m_pHeaderBar
->SetSelectHdl( LINK( this, ChineseDictionaryDialog
, HeaderBarClick
) );
581 m_aED_Term
.SetModifyHdl( LINK( this, ChineseDictionaryDialog
, EditFieldsHdl
) );
582 m_aED_Mapping
.SetModifyHdl( LINK( this, ChineseDictionaryDialog
, EditFieldsHdl
) );
583 m_aLB_Property
.SetSelectHdl( LINK( this, ChineseDictionaryDialog
, EditFieldsHdl
) );
585 m_aRB_To_Simplified
.SetClickHdl( LINK( this, ChineseDictionaryDialog
, DirectionHdl
) );
586 m_aRB_To_Traditional
.SetClickHdl( LINK( this, ChineseDictionaryDialog
, DirectionHdl
) );
588 m_aCT_DictionaryToSimplified
.SetSelectHdl( LINK( this, ChineseDictionaryDialog
, MappingSelectHdl
));
589 m_aCT_DictionaryToTraditional
.SetSelectHdl( LINK( this, ChineseDictionaryDialog
, MappingSelectHdl
));
591 m_aPB_Add
.SetClickHdl( LINK( this, ChineseDictionaryDialog
, AddHdl
) );
592 m_aPB_Modify
.SetClickHdl( LINK( this, ChineseDictionaryDialog
, ModifyHdl
) );
593 m_aPB_Delete
.SetClickHdl( LINK( this, ChineseDictionaryDialog
, DeleteHdl
) );
596 ChineseDictionaryDialog::~ChineseDictionaryDialog()
602 void ChineseDictionaryDialog::setDirectionAndTextConversionOptions( bool bDirectionToSimplified
, sal_Int32 nTextConversionOptions
/*i18n::TextConversionOption*/ )
604 if( bDirectionToSimplified
== bool(m_aRB_To_Simplified
.IsChecked())
605 && nTextConversionOptions
== m_nTextConversionOptions
)
608 m_nTextConversionOptions
= nTextConversionOptions
;
610 if( bDirectionToSimplified
)
611 m_aRB_To_Simplified
.Check();
613 m_aRB_To_Traditional
.Check();
614 updateAfterDirectionChange();
617 IMPL_LINK_NOARG(ChineseDictionaryDialog
, DirectionHdl
)
619 updateAfterDirectionChange();
623 void ChineseDictionaryDialog::updateAfterDirectionChange()
625 Reference
< linguistic2::XConversionDictionary
> xDictionary(0);
627 if( m_aRB_To_Simplified
.IsChecked() )
629 m_aCT_DictionaryToSimplified
.activate( m_pHeaderBar
);
630 m_aCT_DictionaryToTraditional
.Hide();
631 xDictionary
= m_aCT_DictionaryToSimplified
.m_xDictionary
;
635 m_aCT_DictionaryToTraditional
.activate( m_pHeaderBar
);
636 m_aCT_DictionaryToSimplified
.Hide();
637 xDictionary
= m_aCT_DictionaryToTraditional
.m_xDictionary
;
643 IMPL_LINK_NOARG(ChineseDictionaryDialog
, EditFieldsHdl
)
648 IMPL_LINK_NOARG(ChineseDictionaryDialog
, MappingSelectHdl
)
650 DictionaryEntry
* pE
= getActiveDictionary().getFirstSelectedEntry();
653 m_aED_Term
.SetText( pE
->m_aTerm
);
654 m_aED_Mapping
.SetText( pE
->m_aMapping
);
655 sal_Int16 nPos
= pE
->m_nConversionPropertyType
-1;
656 if( nPos
<0 || nPos
>=m_aLB_Property
.GetEntryCount() )
658 if( m_aLB_Property
.GetEntryCount() )
659 m_aLB_Property
.SelectEntryPos(nPos
);
666 bool ChineseDictionaryDialog::isEditFieldsHaveContent() const
668 return !m_aED_Term
.GetText().isEmpty() && !m_aED_Mapping
.GetText().isEmpty();
671 bool ChineseDictionaryDialog::isEditFieldsContentEqualsSelectedListContent() const
673 DictionaryEntry
* pE
= getActiveDictionary().getFirstSelectedEntry();
676 if( pE
->m_aTerm
!= OUString( m_aED_Term
.GetText() ) )
678 if( pE
->m_aMapping
!= OUString( m_aED_Mapping
.GetText() ) )
680 if( pE
->m_nConversionPropertyType
!= m_aLB_Property
.GetSelectEntryPos()+1 )
687 const DictionaryList
& ChineseDictionaryDialog::getActiveDictionary() const
689 if( m_aRB_To_Traditional
.IsChecked() )
690 return m_aCT_DictionaryToTraditional
;
691 return m_aCT_DictionaryToSimplified
;
694 DictionaryList
& ChineseDictionaryDialog::getActiveDictionary()
696 if( m_aRB_To_Traditional
.IsChecked() )
697 return m_aCT_DictionaryToTraditional
;
698 return m_aCT_DictionaryToSimplified
;
701 const DictionaryList
& ChineseDictionaryDialog::getReverseDictionary() const
703 if( m_aRB_To_Traditional
.IsChecked() )
704 return m_aCT_DictionaryToSimplified
;
705 return m_aCT_DictionaryToTraditional
;
708 DictionaryList
& ChineseDictionaryDialog::getReverseDictionary()
710 if( m_aRB_To_Traditional
.IsChecked() )
711 return m_aCT_DictionaryToSimplified
;
712 return m_aCT_DictionaryToTraditional
;
715 void ChineseDictionaryDialog::updateButtons()
717 bool bAdd
= isEditFieldsHaveContent() && !getActiveDictionary().hasTerm( m_aED_Term
.GetText() );
718 m_aPB_Add
.Enable( bAdd
);
720 m_aPB_Delete
.Enable( !bAdd
&& getActiveDictionary().GetSelectedRowCount()>0 );
722 // DictionaryEntry* pFirstSelectedEntry = getActiveDictionary().getFirstSelectedEntry();
724 bool bModify
= false;
726 DictionaryEntry
* pFirstSelectedEntry
= getActiveDictionary().getFirstSelectedEntry();
727 bModify
= !bAdd
&& getActiveDictionary().GetSelectedRowCount()==1
728 && pFirstSelectedEntry
&& pFirstSelectedEntry
->m_aTerm
.equals( m_aED_Term
.GetText() );
729 if( bModify
&& isEditFieldsContentEqualsSelectedListContent() )
732 m_aPB_Modify
.Enable( bModify
);
735 IMPL_LINK_NOARG(ChineseDictionaryDialog
, AddHdl
)
737 if( !isEditFieldsHaveContent() )
740 sal_Int16 nConversionPropertyType
= m_aLB_Property
.GetSelectEntryPos()+1;
742 getActiveDictionary().addEntry( m_aED_Term
.GetText(), m_aED_Mapping
.GetText(), nConversionPropertyType
);
744 if( m_aCB_Reverse
.IsChecked() )
746 getReverseDictionary().deleteEntries( m_aED_Mapping
.GetText() );
747 getReverseDictionary().addEntry( m_aED_Mapping
.GetText(), m_aED_Term
.GetText(), nConversionPropertyType
);
753 IMPL_LINK_NOARG(ChineseDictionaryDialog
, ModifyHdl
)
755 OUString
aTerm( m_aED_Term
.GetText() );
756 OUString
aMapping( m_aED_Mapping
.GetText() );
757 sal_Int16 nConversionPropertyType
= m_aLB_Property
.GetSelectEntryPos()+1;
759 DictionaryList
& rActive
= getActiveDictionary();
760 DictionaryList
& rReverse
= getReverseDictionary();
762 DictionaryEntry
* pE
= rActive
.getFirstSelectedEntry();
763 if( pE
->m_aTerm
!= aTerm
)
768 if( pE
->m_aMapping
!= aMapping
|| pE
->m_nConversionPropertyType
!= nConversionPropertyType
)
770 if( m_aCB_Reverse
.IsChecked() )
772 sal_uIntPtr nPos
= rReverse
.deleteEntries( pE
->m_aMapping
);
773 nPos
= rReverse
.deleteEntries( aMapping
);
774 rReverse
.addEntry( aMapping
, aTerm
, nConversionPropertyType
, nPos
);
777 sal_uIntPtr nPos
= rActive
.deleteEntries( aTerm
);
778 rActive
.addEntry( aTerm
, aMapping
, nConversionPropertyType
, nPos
);
786 IMPL_LINK_NOARG(ChineseDictionaryDialog
, DeleteHdl
)
788 DictionaryList
& rActive
= getActiveDictionary();
789 DictionaryList
& rReverse
= getReverseDictionary();
791 if( rActive
.GetSelectedRowCount()>0)
793 DictionaryEntry
* pEntry
;
796 for( sal_Int32 nN
=rActive
.GetRowCount(); nN
--; )
798 if( rActive
.IsRowSelected( nN
) )
800 pEntry
= rActive
.getEntryOnPos( nN
);
803 aMapping
= pEntry
->m_aMapping
;
804 rActive
.deleteEntryOnPos( nN
);
805 if( m_aCB_Reverse
.IsChecked() )
806 rReverse
.deleteEntries( aMapping
);
817 short ChineseDictionaryDialog::Execute()
819 sal_Int32 nTextConversionOptions
= m_nTextConversionOptions
;
820 if(m_nTextConversionOptions
| i18n::TextConversionOption::USE_CHARACTER_VARIANTS
)
821 nTextConversionOptions
= nTextConversionOptions
^i18n::TextConversionOption::USE_CHARACTER_VARIANTS
;
823 m_aCT_DictionaryToSimplified
.refillFromDictionary( nTextConversionOptions
);
824 m_aCT_DictionaryToTraditional
.refillFromDictionary( m_nTextConversionOptions
);
826 short nRet
= ModalDialog::Execute();
830 //save settings to configuration
831 SvtLinguConfig aLngCfg
;
833 aAny
<<= sal_Bool( !!m_aCB_Reverse
.IsChecked() );
834 aLngCfg
.SetProperty( OUString( UPN_IS_REVERSE_MAPPING
), aAny
);
836 m_aCT_DictionaryToSimplified
.save();
837 m_aCT_DictionaryToTraditional
.save();
840 m_aCT_DictionaryToSimplified
.deleteAll();
841 m_aCT_DictionaryToTraditional
.deleteAll();
846 IMPL_LINK_NOARG(ChineseDictionaryDialog
, HeaderBarClick
)
850 sal_uInt16 nId
= m_pHeaderBar
->GetCurItemId();
851 HeaderBarItemBits nBits
= m_pHeaderBar
->GetItemBits(nId
);
852 if( nBits
& HIB_CLICKABLE
)
854 //set new arrow positions in headerbar
855 m_pHeaderBar
->SetItemBits( getActiveDictionary().getSortColumn()+1, HEADER_BAR_BITS
);
856 if( nBits
& HIB_UPARROW
)
857 m_pHeaderBar
->SetItemBits( nId
, HEADER_BAR_BITS
| HIB_DOWNARROW
);
859 m_pHeaderBar
->SetItemBits( nId
, HEADER_BAR_BITS
| HIB_UPARROW
);
862 nBits
= m_pHeaderBar
->GetItemBits(nId
);
863 bool bSortAtoZ
= nBits
& HIB_UPARROW
;
864 getActiveDictionary().sortByColumn(nId
-1,bSortAtoZ
);
865 getReverseDictionary().sortByColumn(nId
-1,bSortAtoZ
);
871 //.............................................................................
873 //.............................................................................
875 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */