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 <cppuhelper/bootstrap.hxx>
23 #include <com/sun/star/i18n/TextConversionOption.hpp>
24 #include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
25 #include <com/sun/star/linguistic2/ConversionPropertyType.hpp>
26 #include <com/sun/star/linguistic2/ConversionDictionaryList.hpp>
27 #include <com/sun/star/linguistic2/XConversionPropertyType.hpp>
28 #include <com/sun/star/util/XFlushable.hpp>
29 #include <com/sun/star/lang/Locale.hpp>
30 #include <svtools/headbar.hxx>
31 #include <svtools/svlbitm.hxx>
32 #include "svtools/treelistentry.hxx"
33 #include <vcl/msgbox.hxx>
34 #include <vcl/settings.hxx>
35 #include <unotools/lingucfg.hxx>
36 #include <unotools/linguprops.hxx>
37 #include <unotools/intlwrapper.hxx>
38 #include <comphelper/processfactory.hxx>
39 #include <vcl/svapp.hxx>
43 namespace textconversiondlgs
47 using namespace ::com::sun::star
;
48 using namespace ::com::sun::star::uno
;
50 #define HEADER_BAR_BITS ( HeaderBarItemBits::LEFT | HeaderBarItemBits::VCENTER | HeaderBarItemBits::CLICKABLE | HeaderBarItemBits::FIXED | HeaderBarItemBits::FIXEDPOS )
52 DictionaryList::DictionaryList(SvSimpleTableContainer
& rParent
, WinBits nBits
)
53 : SvSimpleTable(rParent
, nBits
)
59 , m_nSortColumnIndex(0)
63 DictionaryList::~DictionaryList()
68 void DictionaryList::dispose()
71 m_pED_Mapping
.clear();
72 m_pLB_Property
.clear();
73 SvSimpleTable::dispose();
76 OUString
DictionaryList::getPropertyTypeName( sal_Int16 nConversionPropertyType
) const
78 if(!m_pLB_Property
|| !m_pLB_Property
->GetEntryCount())
81 sal_uInt16 nPos
= static_cast<sal_uInt16
>( nConversionPropertyType
)-1;
82 if(nPos
<m_pLB_Property
->GetEntryCount())
83 return m_pLB_Property
->GetEntry(nPos
);
84 return m_pLB_Property
->GetEntry(0);
87 OUString
DictionaryList::makeTabString( const DictionaryEntry
& rEntry
) const
89 OUString
aStr( rEntry
.m_aTerm
);
91 aStr
+= rEntry
.m_aMapping
;
93 aStr
+= getPropertyTypeName( rEntry
.m_nConversionPropertyType
);
97 void DictionaryList::save()
99 if( !m_xDictionary
.is() )
102 Reference
< linguistic2::XConversionPropertyType
> xPropertyType( m_xDictionary
, uno::UNO_QUERY
);
107 for( nN
= m_aToBeDeleted
.size(); nN
--; )
109 pE
= m_aToBeDeleted
[nN
];
110 m_xDictionary
->removeEntry( pE
->m_aTerm
, pE
->m_aMapping
);
112 for( nN
= GetRowCount(); nN
--; )
114 pE
= getEntryOnPos( nN
);
119 m_xDictionary
->addEntry( pE
->m_aTerm
, pE
->m_aMapping
);
120 xPropertyType
->setPropertyType( pE
->m_aTerm
, pE
->m_aMapping
, pE
->m_nConversionPropertyType
);
122 catch( uno::Exception
& )
128 Reference
< util::XFlushable
> xFlush( m_xDictionary
, uno::UNO_QUERY
);
133 void DictionaryList::deleteAll()
136 for( nN
= GetRowCount(); nN
--; )
137 deleteEntryOnPos( nN
);
138 for( nN
= m_aToBeDeleted
.size(); nN
--; )
140 DictionaryEntry
* pE
= m_aToBeDeleted
[nN
];
143 m_aToBeDeleted
.clear();
146 void DictionaryList::refillFromDictionary( sal_Int32 nTextConversionOptions
)
150 if(!m_xDictionary
.is())
153 Sequence
< OUString
> aLeftList( m_xDictionary
->getConversionEntries( linguistic2::ConversionDirection_FROM_LEFT
) );
154 sal_Int32 nCount
= aLeftList
.getLength();
156 Reference
< linguistic2::XConversionPropertyType
> xPropertyType( m_xDictionary
, uno::UNO_QUERY
);
158 OUString aLeft
, aRight
;
159 sal_Int16 nConversionPropertyType
;
161 for(sal_Int32 nN
=0; nN
<nCount
; nN
++)
163 aLeft
= aLeftList
[nN
];
164 Sequence
< OUString
> aRightList( m_xDictionary
->getConversions(
165 aLeft
, 0, aLeft
.getLength()
166 , linguistic2::ConversionDirection_FROM_LEFT
, nTextConversionOptions
) );
168 if(aRightList
.getLength()!=1)
170 OSL_FAIL("The Chinese Translation Dictionary should have exactly one Mapping for each term.");
174 aRight
= aRightList
[0];
175 nConversionPropertyType
= linguistic2::ConversionPropertyType::OTHER
;
176 if(xPropertyType
.is())
177 nConversionPropertyType
= xPropertyType
->getPropertyType(aLeft
, aRight
);
179 DictionaryEntry
* pEntry
= new DictionaryEntry( aLeft
, aRight
, nConversionPropertyType
);
180 SvTreeListEntry
* pLBEntry
= InsertEntry( makeTabString( *pEntry
) );
181 pLBEntry
->SetUserData( pEntry
);
184 if( GetEntryCount() > 0 )
188 DictionaryEntry
* DictionaryList::getFirstSelectedEntry() const
190 DictionaryEntry
* pRet
=0;
191 for( sal_Int32 nN
=GetRowCount(); nN
--; )
193 if( IsRowSelected( nN
) )
195 pRet
= getEntryOnPos( nN
);
202 DictionaryEntry
* DictionaryList::getEntryOnPos( sal_Int32 nPos
) const
204 DictionaryEntry
* pEntry
=0;
205 SvTreeListEntry
* pLBEntry
= GetEntryOnPos( nPos
);
207 pEntry
= static_cast<DictionaryEntry
*>(pLBEntry
->GetUserData());
211 DictionaryEntry
* DictionaryList::getTermEntry( const OUString
& rTerm
) const
213 for( sal_Int32 nN
=GetRowCount(); nN
--; )
215 DictionaryEntry
* pE
= getEntryOnPos( nN
);
216 if( pE
&& rTerm
.equals( pE
->m_aTerm
) )
222 bool DictionaryList::hasTerm( const OUString
& rTerm
) const
224 return getTermEntry(rTerm
) !=0 ;
227 void DictionaryList::addEntry( const OUString
& rTerm
, const OUString
& rMapping
228 , sal_Int16 nConversionPropertyType
, sal_uIntPtr nPos
)
230 if( hasTerm( rTerm
) )
233 DictionaryEntry
* pEntry
= new DictionaryEntry( rTerm
, rMapping
, nConversionPropertyType
, true );
234 SvTreeListEntry
* pLBEntry
= InsertEntryToColumn( makeTabString( *pEntry
), nPos
);
235 pLBEntry
->SetUserData( pEntry
);
236 SelectRow( GetEntryPos( pLBEntry
) );
239 void DictionaryList::deleteEntryOnPos( sal_Int32 nPos
)
241 SvTreeListEntry
* pLBEntry
= GetEntryOnPos( nPos
);
242 DictionaryEntry
* pEntry
= getEntryOnPos( nPos
);
244 RemoveParentKeepChildren( pLBEntry
);
247 if( pEntry
->m_bNewEntry
)
250 m_aToBeDeleted
.push_back( pEntry
);
254 sal_uIntPtr
DictionaryList::deleteEntries( const OUString
& rTerm
)
256 sal_uIntPtr nPos
= TREELIST_APPEND
;
257 for( sal_Int32 nN
=GetRowCount(); nN
--; )
259 DictionaryEntry
* pCurEntry
= getEntryOnPos( nN
);
260 if( rTerm
.equals( pCurEntry
->m_aTerm
) )
263 SvTreeListEntry
* pCurLBEntry
= GetEntryOnPos( nN
);
264 RemoveParentKeepChildren( pCurLBEntry
);
265 if( pCurEntry
->m_bNewEntry
)
268 m_aToBeDeleted
.push_back( pCurEntry
);
274 void DictionaryList::sortByColumn( sal_uInt16 nSortColumnIndex
, bool bSortAtoZ
)
276 m_nSortColumnIndex
=nSortColumnIndex
;
277 if( nSortColumnIndex
<3 )
280 GetModel()->SetSortMode(SortAscending
);
282 GetModel()->SetSortMode(SortDescending
);
284 GetModel()->SetCompareHdl( LINK( this, DictionaryList
, CompareHdl
));
285 GetModel()->Resort();
288 GetModel()->SetSortMode(SortNone
);
292 IMPL_LINK( DictionaryList
, CompareHdl
, SvSortData
*, pData
)
294 SvTreeListEntry
* pLeft
= const_cast<SvTreeListEntry
*>(pData
->pLeft
);
295 SvTreeListEntry
* pRight
= const_cast<SvTreeListEntry
*>(pData
->pRight
);
296 return (long) ColumnCompare(pLeft
,pRight
);
299 sal_Int32
DictionaryList::ColumnCompare( SvTreeListEntry
* pLeft
, SvTreeListEntry
* pRight
)
301 sal_Int32 nCompare
= 0;
303 SvLBoxItem
* pLeftItem
= getItemAtColumn( pLeft
, m_nSortColumnIndex
);
304 SvLBoxItem
* pRightItem
= getItemAtColumn( pRight
, m_nSortColumnIndex
);
306 if(pLeftItem
!= NULL
&& pRightItem
!= NULL
)
308 sal_uInt16 nLeftKind
= pLeftItem
->GetType();
309 sal_uInt16 nRightKind
= pRightItem
->GetType();
311 if(nRightKind
== SV_ITEM_ID_LBOXSTRING
&&
312 nLeftKind
== SV_ITEM_ID_LBOXSTRING
)
314 IntlWrapper
aIntlWrapper( Application::GetSettings().GetLanguageTag() );
315 const CollatorWrapper
* pCollator
= aIntlWrapper
.getCaseCollator();
317 nCompare
= pCollator
->compareString( static_cast<SvLBoxString
*>(pLeftItem
)->GetText(),
318 static_cast<SvLBoxString
*>(pRightItem
)->GetText());
327 SvLBoxItem
* DictionaryList::getItemAtColumn( SvTreeListEntry
* pEntry
, sal_uInt16 nColumn
) const
329 SvLBoxItem
* pItem
= NULL
;
332 sal_uInt16 nCount
= pEntry
->ItemCount();
334 if( nTreeFlags
& SvTreeFlags::CHKBTN
)
336 if( nColumn
< nCount
)
337 pItem
= pEntry
->GetItem( nColumn
);
346 DictionaryEntry::DictionaryEntry( const OUString
& rTerm
, const OUString
& rMapping
347 , sal_Int16 nConversionPropertyType
350 , m_aMapping( rMapping
)
351 , m_nConversionPropertyType( nConversionPropertyType
)
352 , m_bNewEntry( bNewEntry
)
354 if( m_nConversionPropertyType
== 0 )
355 m_nConversionPropertyType
= 1;
358 DictionaryEntry::~DictionaryEntry()
362 bool DictionaryEntry::operator==( const DictionaryEntry
& rE
) const
364 return m_aTerm
== rE
.m_aTerm
365 && m_aMapping
== rE
.m_aMapping
366 && m_nConversionPropertyType
== rE
.m_nConversionPropertyType
;
369 void DictionaryList::setColSizes()
371 HeaderBar
&rBar
= GetTheHeaderBar();
372 if (rBar
.GetItemCount() < 3)
375 long nWidth1
= m_pED_Term
->get_preferred_size().Width();
376 long nWidth2
= m_pED_Mapping
->get_preferred_size().Width();
377 long nWidth3
= m_pLB_Property
->get_preferred_size().Width();
379 long nWidth
= GetSizePixel().Width();
380 long nPos3
= nWidth
- nWidth3
;
381 long nRemainder
= nWidth
- (nWidth1
+ nWidth2
+ nWidth3
);
383 long aStaticTabs
[] = { 3, 0, nWidth1
+ (nRemainder
/2), nPos3
};
384 SvSimpleTable::SetTabs(aStaticTabs
, MAP_PIXEL
);
387 void DictionaryList::Resize()
389 SvSimpleTable::Resize();
393 void DictionaryList::init(const Reference
< linguistic2::XConversionDictionary
>& xDictionary
,
394 vcl::Window
*pED_Term
, vcl::Window
*pED_Mapping
, ListBox
*pLB_Property
,
395 vcl::Window
*pFT_Term
, vcl::Window
*pFT_Mapping
, vcl::Window
*pFT_Property
)
397 SetStyle( WB_VSCROLL
| WB_TABSTOP
);
398 SetSelectionMode( SINGLE_SELECTION
);
399 SetBorderStyle( WindowBorderStyle::MONO
);
402 if (m_xDictionary
.is())
405 m_xDictionary
= xDictionary
;
407 m_pED_Term
= pED_Term
;
408 m_pED_Mapping
= pED_Mapping
;
409 m_pLB_Property
= pLB_Property
;
411 HeaderBar
& rHeaderBar
= GetTheHeaderBar();
413 OUString
aColumn1( OutputDevice::GetNonMnemonicString( pFT_Term
->GetText() ) );
414 OUString
aColumn2( OutputDevice::GetNonMnemonicString( pFT_Mapping
->GetText() ) );
415 OUString
aColumn3( OutputDevice::GetNonMnemonicString( pFT_Property
->GetText() ) );
417 long nWidth1
= m_pED_Term
->get_preferred_size().Width();
418 long nWidth2
= m_pED_Mapping
->get_preferred_size().Width();
419 long nWidth3
= m_pLB_Property
->get_preferred_size().Width();
421 HeaderBarItemBits nBits
= HEADER_BAR_BITS
;
422 rHeaderBar
.InsertItem( 1, aColumn1
, nWidth1
, nBits
| HeaderBarItemBits::UPARROW
);
423 rHeaderBar
.InsertItem( 2, aColumn2
, nWidth2
, nBits
);
424 rHeaderBar
.InsertItem( 3, aColumn3
, nWidth3
, nBits
);
426 long pTabs
[] = { 3, 0, nWidth1
, nWidth1
+ nWidth2
};
427 SetTabs( &pTabs
[0], MAP_PIXEL
);
430 void ChineseDictionaryDialog::initDictionaryControl(DictionaryList
*pList
,
431 const Reference
< linguistic2::XConversionDictionary
>& xDictionary
)
433 //init HeaderBar and set tabs
434 HeaderBar
& rHeaderBar
= pList
->GetTheHeaderBar();
436 rHeaderBar
.SetSelectHdl( LINK( this, ChineseDictionaryDialog
, HeaderBarClick
) );
437 //set widgets to track the width of for columns
438 pList
->init(xDictionary
,
439 m_pED_Term
, m_pED_Mapping
, m_pLB_Property
,
440 m_pFT_Term
, m_pFT_Mapping
, m_pFT_Property
);
443 ChineseDictionaryDialog::ChineseDictionaryDialog( vcl::Window
* pParent
)
444 : ModalDialog(pParent
, "ChineseDictionaryDialog",
445 "svx/ui/chinesedictionary.ui")
446 , m_nTextConversionOptions(i18n::TextConversionOption::NONE
)
449 get(m_pRB_To_Simplified
, "tradtosimple");
450 get(m_pRB_To_Traditional
, "simpletotrad");
451 get(m_pCB_Reverse
, "reverse");
452 get(m_pFT_Term
, "termft");
453 get(m_pED_Term
, "term");
454 get(m_pFT_Mapping
, "mappingft");
455 get(m_pED_Mapping
, "mapping");
456 get(m_pFT_Property
, "propertyft");
457 get(m_pLB_Property
, "property");
459 get(m_pPB_Add
, "add");
460 get(m_pPB_Modify
, "modify");
461 get(m_pPB_Delete
, "delete");
463 get(mpToSimplifiedContainer
, "tradtosimpleview");
464 mpToSimplifiedContainer
->set_height_request(mpToSimplifiedContainer
->GetTextHeight() * 8);
465 m_pCT_DictionaryToSimplified
= VclPtr
<DictionaryList
>::Create(*mpToSimplifiedContainer
, 0);
466 get(mpToTraditionalContainer
, "simpletotradview");
467 mpToTraditionalContainer
->set_height_request(mpToTraditionalContainer
->GetTextHeight() * 8);
468 m_pCT_DictionaryToTraditional
= VclPtr
<DictionaryList
>::Create(*mpToTraditionalContainer
, 0);
470 SvtLinguConfig aLngCfg
;
472 Any
aAny( aLngCfg
.GetProperty( OUString( UPN_IS_REVERSE_MAPPING
) ) );
473 if( aAny
>>= bValue
)
474 m_pCB_Reverse
->Check( bValue
);
476 m_pLB_Property
->SetDropDownLineCount( m_pLB_Property
->GetEntryCount() );
477 m_pLB_Property
->SelectEntryPos(0);
479 Reference
< linguistic2::XConversionDictionary
> xDictionary_To_Simplified(0);
480 Reference
< linguistic2::XConversionDictionary
> xDictionary_To_Traditional(0);
484 m_xContext
= Reference
< XComponentContext
>( ::cppu::defaultBootstrap_InitialComponentContext() );
487 Reference
< linguistic2::XConversionDictionaryList
> xDictionaryList
= linguistic2::ConversionDictionaryList::create(m_xContext
);
488 Reference
< container::XNameContainer
> xContainer( xDictionaryList
->getDictionaryContainer() );
493 OUString
aNameTo_Simplified("ChineseT2S");
494 OUString
aNameTo_Traditional("ChineseS2T");
495 lang::Locale aLocale
;
496 aLocale
.Language
= "zh";
498 if( xContainer
->hasByName( aNameTo_Simplified
) )
499 xDictionary_To_Simplified
= Reference
< linguistic2::XConversionDictionary
>(
500 xContainer
->getByName( aNameTo_Simplified
), UNO_QUERY
);
503 aLocale
.Country
= "TW";
504 xDictionary_To_Simplified
= Reference
< linguistic2::XConversionDictionary
>(
505 xDictionaryList
->addNewDictionary( aNameTo_Simplified
506 , aLocale
, linguistic2::ConversionDictionaryType::SCHINESE_TCHINESE
509 if (xDictionary_To_Simplified
.is())
510 xDictionary_To_Simplified
->setActive( sal_True
);
513 if( xContainer
->hasByName( aNameTo_Traditional
) )
514 xDictionary_To_Traditional
= Reference
< linguistic2::XConversionDictionary
>(
515 xContainer
->getByName( aNameTo_Traditional
), UNO_QUERY
);
518 aLocale
.Country
= "CN";
519 xDictionary_To_Traditional
= Reference
< linguistic2::XConversionDictionary
>(
520 xDictionaryList
->addNewDictionary( aNameTo_Traditional
521 , aLocale
, linguistic2::ConversionDictionaryType::SCHINESE_TCHINESE
524 if (xDictionary_To_Traditional
.is())
525 xDictionary_To_Traditional
->setActive( sal_True
);
528 catch(const uno::Exception
& )
535 //init dictionary controls
536 initDictionaryControl(m_pCT_DictionaryToSimplified
, xDictionary_To_Simplified
);
537 initDictionaryControl(m_pCT_DictionaryToTraditional
, xDictionary_To_Traditional
);
539 updateAfterDirectionChange();
541 m_pED_Term
->SetModifyHdl( LINK( this, ChineseDictionaryDialog
, EditFieldsHdl
) );
542 m_pED_Mapping
->SetModifyHdl( LINK( this, ChineseDictionaryDialog
, EditFieldsHdl
) );
543 m_pLB_Property
->SetSelectHdl( LINK( this, ChineseDictionaryDialog
, EditFieldsHdl
) );
545 m_pRB_To_Simplified
->SetClickHdl( LINK( this, ChineseDictionaryDialog
, DirectionHdl
) );
546 m_pRB_To_Traditional
->SetClickHdl( LINK( this, ChineseDictionaryDialog
, DirectionHdl
) );
548 m_pCT_DictionaryToSimplified
->SetSelectHdl( LINK( this, ChineseDictionaryDialog
, MappingSelectHdl
));
549 m_pCT_DictionaryToTraditional
->SetSelectHdl( LINK( this, ChineseDictionaryDialog
, MappingSelectHdl
));
551 m_pPB_Add
->SetClickHdl( LINK( this, ChineseDictionaryDialog
, AddHdl
) );
552 m_pPB_Modify
->SetClickHdl( LINK( this, ChineseDictionaryDialog
, ModifyHdl
) );
553 m_pPB_Delete
->SetClickHdl( LINK( this, ChineseDictionaryDialog
, DeleteHdl
) );
556 ChineseDictionaryDialog::~ChineseDictionaryDialog()
561 void ChineseDictionaryDialog::dispose()
564 m_pCT_DictionaryToSimplified
.disposeAndClear();
565 m_pCT_DictionaryToTraditional
.disposeAndClear();
566 m_pRB_To_Simplified
.clear();
567 m_pRB_To_Traditional
.clear();
568 m_pCB_Reverse
.clear();
571 m_pFT_Mapping
.clear();
572 m_pED_Mapping
.clear();
573 m_pFT_Property
.clear();
574 m_pLB_Property
.clear();
575 mpToSimplifiedContainer
.clear();
576 mpToTraditionalContainer
.clear();
578 m_pPB_Modify
.clear();
579 m_pPB_Delete
.clear();
580 ModalDialog::dispose();
583 void ChineseDictionaryDialog::setDirectionAndTextConversionOptions( bool bDirectionToSimplified
, sal_Int32 nTextConversionOptions
/*i18n::TextConversionOption*/ )
585 if( bDirectionToSimplified
== bool(m_pRB_To_Simplified
->IsChecked())
586 && nTextConversionOptions
== m_nTextConversionOptions
)
589 m_nTextConversionOptions
= nTextConversionOptions
;
591 if( bDirectionToSimplified
)
592 m_pRB_To_Simplified
->Check();
594 m_pRB_To_Traditional
->Check();
595 updateAfterDirectionChange();
598 IMPL_LINK_NOARG(ChineseDictionaryDialog
, DirectionHdl
)
600 updateAfterDirectionChange();
604 void ChineseDictionaryDialog::updateAfterDirectionChange()
606 Reference
< linguistic2::XConversionDictionary
> xDictionary(0);
608 if( m_pRB_To_Simplified
->IsChecked() )
610 mpToTraditionalContainer
->Hide();
611 mpToSimplifiedContainer
->Show();
612 xDictionary
= m_pCT_DictionaryToSimplified
->m_xDictionary
;
616 mpToSimplifiedContainer
->Hide();
617 mpToTraditionalContainer
->Show();
618 xDictionary
= m_pCT_DictionaryToTraditional
->m_xDictionary
;
624 IMPL_LINK_NOARG(ChineseDictionaryDialog
, EditFieldsHdl
)
629 IMPL_LINK_NOARG(ChineseDictionaryDialog
, MappingSelectHdl
)
631 DictionaryEntry
* pE
= getActiveDictionary().getFirstSelectedEntry();
634 m_pED_Term
->SetText( pE
->m_aTerm
);
635 m_pED_Mapping
->SetText( pE
->m_aMapping
);
636 sal_Int16 nPos
= pE
->m_nConversionPropertyType
-1;
637 if( nPos
<0 || nPos
>=m_pLB_Property
->GetEntryCount() )
639 if( m_pLB_Property
->GetEntryCount() )
640 m_pLB_Property
->SelectEntryPos(nPos
);
647 bool ChineseDictionaryDialog::isEditFieldsHaveContent() const
649 return !m_pED_Term
->GetText().isEmpty() && !m_pED_Mapping
->GetText().isEmpty();
652 bool ChineseDictionaryDialog::isEditFieldsContentEqualsSelectedListContent() const
654 DictionaryEntry
* pE
= getActiveDictionary().getFirstSelectedEntry();
657 if( pE
->m_aTerm
!= OUString( m_pED_Term
->GetText() ) )
659 if( pE
->m_aMapping
!= OUString( m_pED_Mapping
->GetText() ) )
661 if( pE
->m_nConversionPropertyType
!= m_pLB_Property
->GetSelectEntryPos()+1 )
668 const DictionaryList
& ChineseDictionaryDialog::getActiveDictionary() const
670 if( m_pRB_To_Traditional
->IsChecked() )
671 return *m_pCT_DictionaryToTraditional
;
672 return *m_pCT_DictionaryToSimplified
;
675 DictionaryList
& ChineseDictionaryDialog::getActiveDictionary()
677 if( m_pRB_To_Traditional
->IsChecked() )
678 return *m_pCT_DictionaryToTraditional
;
679 return *m_pCT_DictionaryToSimplified
;
682 const DictionaryList
& ChineseDictionaryDialog::getReverseDictionary() const
684 if( m_pRB_To_Traditional
->IsChecked() )
685 return *m_pCT_DictionaryToSimplified
;
686 return *m_pCT_DictionaryToTraditional
;
689 DictionaryList
& ChineseDictionaryDialog::getReverseDictionary()
691 if( m_pRB_To_Traditional
->IsChecked() )
692 return *m_pCT_DictionaryToSimplified
;
693 return *m_pCT_DictionaryToTraditional
;
696 void ChineseDictionaryDialog::updateButtons()
698 bool bAdd
= isEditFieldsHaveContent() && !getActiveDictionary().hasTerm( m_pED_Term
->GetText() );
699 m_pPB_Add
->Enable( bAdd
);
701 m_pPB_Delete
->Enable( !bAdd
&& getActiveDictionary().GetSelectedRowCount()>0 );
703 // DictionaryEntry* pFirstSelectedEntry = getActiveDictionary().getFirstSelectedEntry();
705 bool bModify
= false;
707 DictionaryEntry
* pFirstSelectedEntry
= getActiveDictionary().getFirstSelectedEntry();
708 bModify
= !bAdd
&& getActiveDictionary().GetSelectedRowCount()==1
709 && pFirstSelectedEntry
&& pFirstSelectedEntry
->m_aTerm
.equals( m_pED_Term
->GetText() );
710 if( bModify
&& isEditFieldsContentEqualsSelectedListContent() )
713 m_pPB_Modify
->Enable( bModify
);
716 IMPL_LINK_NOARG(ChineseDictionaryDialog
, AddHdl
)
718 if( !isEditFieldsHaveContent() )
721 sal_Int16 nConversionPropertyType
= m_pLB_Property
->GetSelectEntryPos()+1;
723 getActiveDictionary().addEntry( m_pED_Term
->GetText(), m_pED_Mapping
->GetText(), nConversionPropertyType
);
725 if( m_pCB_Reverse
->IsChecked() )
727 getReverseDictionary().deleteEntries( m_pED_Mapping
->GetText() );
728 getReverseDictionary().addEntry( m_pED_Mapping
->GetText(), m_pED_Term
->GetText(), nConversionPropertyType
);
734 IMPL_LINK_NOARG(ChineseDictionaryDialog
, ModifyHdl
)
736 OUString
aTerm( m_pED_Term
->GetText() );
737 OUString
aMapping( m_pED_Mapping
->GetText() );
738 sal_Int16 nConversionPropertyType
= m_pLB_Property
->GetSelectEntryPos()+1;
740 DictionaryList
& rActive
= getActiveDictionary();
741 DictionaryList
& rReverse
= getReverseDictionary();
743 DictionaryEntry
* pE
= rActive
.getFirstSelectedEntry();
744 if( pE
&& pE
->m_aTerm
!= aTerm
)
749 if( pE
->m_aMapping
!= aMapping
|| pE
->m_nConversionPropertyType
!= nConversionPropertyType
)
751 if( m_pCB_Reverse
->IsChecked() )
753 sal_uIntPtr nPos
= rReverse
.deleteEntries( pE
->m_aMapping
);
754 nPos
= rReverse
.deleteEntries( aMapping
);
755 rReverse
.addEntry( aMapping
, aTerm
, nConversionPropertyType
, nPos
);
758 sal_uIntPtr nPos
= rActive
.deleteEntries( aTerm
);
759 rActive
.addEntry( aTerm
, aMapping
, nConversionPropertyType
, nPos
);
767 IMPL_LINK_NOARG(ChineseDictionaryDialog
, DeleteHdl
)
769 DictionaryList
& rActive
= getActiveDictionary();
770 DictionaryList
& rReverse
= getReverseDictionary();
772 if( rActive
.GetSelectedRowCount()>0)
774 DictionaryEntry
* pEntry
;
777 for( sal_Int32 nN
=rActive
.GetRowCount(); nN
--; )
779 if( rActive
.IsRowSelected( nN
) )
781 pEntry
= rActive
.getEntryOnPos( nN
);
784 aMapping
= pEntry
->m_aMapping
;
785 rActive
.deleteEntryOnPos( nN
);
786 if( m_pCB_Reverse
->IsChecked() )
787 rReverse
.deleteEntries( aMapping
);
798 short ChineseDictionaryDialog::Execute()
800 sal_Int32 nTextConversionOptions
= m_nTextConversionOptions
;
801 if(m_nTextConversionOptions
& i18n::TextConversionOption::USE_CHARACTER_VARIANTS
)
802 nTextConversionOptions
= nTextConversionOptions
^i18n::TextConversionOption::USE_CHARACTER_VARIANTS
;
804 m_pCT_DictionaryToSimplified
->refillFromDictionary( nTextConversionOptions
);
805 m_pCT_DictionaryToTraditional
->refillFromDictionary( m_nTextConversionOptions
);
807 short nRet
= ModalDialog::Execute();
811 //save settings to configuration
812 SvtLinguConfig aLngCfg
;
814 aAny
<<= m_pCB_Reverse
->IsChecked();
815 aLngCfg
.SetProperty( OUString( UPN_IS_REVERSE_MAPPING
), aAny
);
817 m_pCT_DictionaryToSimplified
->save();
818 m_pCT_DictionaryToTraditional
->save();
821 m_pCT_DictionaryToSimplified
->deleteAll();
822 m_pCT_DictionaryToTraditional
->deleteAll();
827 IMPL_LINK(ChineseDictionaryDialog
, HeaderBarClick
, HeaderBar
*, pHeaderBar
)
829 sal_uInt16 nId
= pHeaderBar
->GetCurItemId();
830 HeaderBarItemBits nBits
= pHeaderBar
->GetItemBits(nId
);
831 if( nBits
& HeaderBarItemBits::CLICKABLE
)
833 //set new arrow positions in headerbar
834 pHeaderBar
->SetItemBits( getActiveDictionary().getSortColumn()+1, HEADER_BAR_BITS
);
835 if( nBits
& HeaderBarItemBits::UPARROW
)
836 pHeaderBar
->SetItemBits( nId
, HEADER_BAR_BITS
| HeaderBarItemBits::DOWNARROW
);
838 pHeaderBar
->SetItemBits( nId
, HEADER_BAR_BITS
| HeaderBarItemBits::UPARROW
);
841 nBits
= pHeaderBar
->GetItemBits(nId
);
842 bool bSortAtoZ
= bool(nBits
& HeaderBarItemBits::UPARROW
);
843 getActiveDictionary().sortByColumn(nId
-1,bSortAtoZ
);
844 getReverseDictionary().sortByColumn(nId
-1,bSortAtoZ
);
854 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */