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>
34#include <osl/diagnose.h>
46 , m_pED_Mapping(nullptr)
47 , m_pLB_Property(nullptr)
57 sal_uInt16
nPos =
static_cast<sal_uInt16
>( nConversionPropertyType )-1;
58 if (nPos < m_pLB_Property->get_count())
68 Reference< linguistic2::XConversionPropertyType > xPropertyType(
m_xDictionary, uno::UNO_QUERY );
79 for( nN = nRowCount; nN--; )
87 xPropertyType->setPropertyType(
pE->m_aTerm,
pE->m_aMapping,
pE->m_nConversionPropertyType );
89 catch( uno::Exception& )
95 Reference< util::XFlushable > xFlush(
m_xDictionary, uno::UNO_QUERY );
104 for( nN = nRowCount; nN--; )
121 const Sequence< OUString > aLeftList(
m_xDictionary->getConversionEntries( linguistic2::ConversionDirection_FROM_LEFT ) );
123 Reference< linguistic2::XConversionPropertyType > xPropertyType(
m_xDictionary, uno::UNO_QUERY );
126 sal_Int16 nConversionPropertyType;
128 for(
const OUString& aLeft : aLeftList)
130 Sequence< OUString > aRightList(
m_xDictionary->getConversions(
131 aLeft, 0, aLeft.getLength()
132 , linguistic2::ConversionDirection_FROM_LEFT, nTextConversionOptions ) );
134 if(aRightList.getLength()!=1)
136 OSL_FAIL(
"The Chinese Translation Dictionary should have exactly one Mapping for each term.");
140 aRight = aRightList[0];
141 nConversionPropertyType = linguistic2::ConversionPropertyType::OTHER;
142 if(xPropertyType.is())
143 nConversionPropertyType = xPropertyType->getPropertyType(aLeft, aRight);
167 return weld::fromId<DictionaryEntry*>(sLBEntry);
173 for( sal_Int32 nN = nRowCount; nN--; )
176 if(
pE && rTerm ==
pE->m_aTerm )
188 sal_Int16 nConversionPropertyType,
int nPos)
219 for (sal_Int32 nN = nRowCount; nN--;)
222 if( rTerm == pCurEntry->
m_aTerm )
236 , sal_Int16 nConversionPropertyType
238 : m_aTerm(
std::move( aTerm ))
239 , m_aMapping(
std::move( aMapping ))
240 , m_nConversionPropertyType( nConversionPropertyType )
241 , m_bNewEntry( bNewEntry )
254 m_xCT_DictionaryToTraditional.get() :
255 m_xCT_DictionaryToSimplified.get();
256 std::vector<int> aWidths;
257 int x1, x2,
y, width, height;
258 if (!m_xED_Mapping->get_extents_relative_to(pControl->
get_widget(), x1,
y, width, height))
260 aWidths.push_back(x1);
261 if (!m_xLB_Property->get_extents_relative_to(pControl->
get_widget(), x2,
y, width, height))
263 aWidths.push_back(x2 - x1);
264 m_xCT_DictionaryToTraditional->get_widget().set_column_fixed_widths(aWidths);
265 m_xCT_DictionaryToSimplified->get_widget().set_column_fixed_widths(aWidths);
283 std::vector<int> aWidths
292 const Reference< linguistic2::XConversionDictionary>& xDictionary)
295 pList->
init(xDictionary,
300 : GenericDialogController(pParent,
"svx/ui/chinesedictionary.ui",
"ChineseDictionaryDialog")
301 , m_nTextConversionOptions(i18n::TextConversionOption::
NONE)
302 , m_xRB_To_Simplified(m_xBuilder->weld_radio_button(
"tradtosimple"))
303 , m_xRB_To_Traditional(m_xBuilder->weld_radio_button(
"simpletotrad"))
304 , m_xCB_Reverse(m_xBuilder->weld_check_button(
"reverse"))
305 , m_xED_Term(m_xBuilder->weld_entry(
"term"))
306 , m_xED_Mapping(m_xBuilder->weld_entry(
"mapping"))
307 , m_xLB_Property(m_xBuilder->weld_combo_box(
"property"))
308 , m_xCT_DictionaryToSimplified(new
DictionaryList(m_xBuilder->weld_tree_view(
"tradtosimpleview")))
309 , m_xCT_DictionaryToTraditional(new
DictionaryList(m_xBuilder->weld_tree_view(
"simpletotradview")))
310 , m_xPB_Add(m_xBuilder->weld_button(
"add"))
311 , m_xPB_Modify(m_xBuilder->weld_button(
"modify"))
312 , m_xPB_Delete(m_xBuilder->weld_button(
"delete"))
320 if( aAny >>= bValue )
325 Reference< linguistic2::XConversionDictionary > xDictionary_To_Simplified;
326 Reference< linguistic2::XConversionDictionary > xDictionary_To_Traditional;
330 m_xContext.set( ::cppu::defaultBootstrap_InitialComponentContext() );
333 Reference< linguistic2::XConversionDictionaryList > xDictionaryList = linguistic2::ConversionDictionaryList::create(
m_xContext);
334 Reference< container::XNameContainer > xContainer( xDictionaryList->getDictionaryContainer() );
339 OUString aNameTo_Simplified(
"ChineseT2S");
340 OUString aNameTo_Traditional(
"ChineseS2T");
341 lang::Locale aLocale;
342 aLocale.Language =
"zh";
344 if( xContainer->hasByName( aNameTo_Simplified ) )
345 xDictionary_To_Simplified.set(
346 xContainer->getByName( aNameTo_Simplified ), UNO_QUERY );
349 aLocale.Country =
"TW";
350 xDictionary_To_Simplified =
351 xDictionaryList->addNewDictionary( aNameTo_Simplified
352 , aLocale, linguistic2::ConversionDictionaryType::SCHINESE_TCHINESE
355 if (xDictionary_To_Simplified.is())
356 xDictionary_To_Simplified->setActive(
true );
359 if( xContainer->hasByName( aNameTo_Traditional ) )
360 xDictionary_To_Traditional.set(
361 xContainer->getByName( aNameTo_Traditional ), UNO_QUERY );
364 aLocale.Country =
"CN";
365 xDictionary_To_Traditional =
366 xDictionaryList->addNewDictionary( aNameTo_Traditional
367 ,aLocale, linguistic2::ConversionDictionaryType::SCHINESE_TCHINESE);
369 if (xDictionary_To_Traditional.is())
370 xDictionary_To_Traditional->setActive(
true );
373 catch(
const uno::Exception& )
419 if (bDirectionToSimplified)
428 updateAfterDirectionChange();
433 Reference< linguistic2::XConversionDictionary > xDictionary;
466 m_xED_Term->set_text(
pE->m_aTerm );
467 m_xED_Mapping->set_text(
pE->m_aMapping );
468 sal_Int16
nPos =
pE->m_nConversionPropertyType-1;
469 if (nPos<0 || nPos>=m_xLB_Property->get_count())
471 if (m_xLB_Property->get_count())
472 m_xLB_Property->set_active(
nPos);
534 bool bModify =
false;
537 bModify = !bAdd && pFirstSelectedEntry && pFirstSelectedEntry->
m_aTerm ==
m_xED_Term->get_text();
546 if( !isEditFieldsHaveContent() )
549 sal_Int16 nConversionPropertyType = m_xLB_Property->get_active() + 1;
551 getActiveDictionary().addEntry( m_xED_Term->get_text(), m_xED_Mapping->get_text(), nConversionPropertyType );
553 if( m_xCB_Reverse->get_active() )
555 getReverseDictionary().deleteEntries( m_xED_Mapping->get_text() );
556 getReverseDictionary().addEntry( m_xED_Mapping->get_text(), m_xED_Term->get_text(), nConversionPropertyType );
564 OUString aTerm( m_xED_Term->get_text() );
565 OUString aMapping( m_xED_Mapping->get_text() );
566 sal_Int16 nConversionPropertyType = m_xLB_Property->get_active() + 1;
572 if(
pE &&
pE->m_aTerm != aTerm )
577 if(
pE->m_aMapping != aMapping ||
pE->m_nConversionPropertyType != nConversionPropertyType )
579 if( m_xCB_Reverse->get_active() )
583 rReverse.
addEntry( aMapping, aTerm, nConversionPropertyType,
nPos );
587 rActive.
addEntry( aTerm, aMapping, nConversionPropertyType,
nPos );
607 if (m_xCB_Reverse->get_active())
619 nTextConversionOptions = nTextConversionOptions^i18n::TextConversionOption::USE_CHARACTER_VARIANTS ;
624 short nRet = GenericDialogController::run();
649 bSortAtoZ = !bSortAtoZ;
664 HeaderBarClick(*m_xCT_DictionaryToSimplified, nColumn);
669 HeaderBarClick(*m_xCT_DictionaryToTraditional, nColumn);
constexpr tools::Long Width() const
css::uno::Any GetProperty(std::u16string_view rPropertyName) const
bool SetProperty(std::u16string_view rPropertyName, const css::uno::Any &rValue)
sal_Int32 m_nTextConversionOptions
bool isEditFieldsContentEqualsSelectedListContent() const
DictionaryList & getReverseDictionary()
std::unique_ptr< weld::Button > m_xPB_Delete
std::unique_ptr< weld::ComboBox > m_xLB_Property
std::unique_ptr< weld::RadioButton > m_xRB_To_Traditional
std::unique_ptr< weld::Entry > m_xED_Term
virtual short run() override
std::unique_ptr< weld::Button > m_xPB_Modify
std::unique_ptr< DictionaryList > m_xCT_DictionaryToSimplified
bool isEditFieldsHaveContent() const
std::unique_ptr< DictionaryList > m_xCT_DictionaryToTraditional
std::unique_ptr< weld::CheckButton > m_xCB_Reverse
css::uno::Reference< css::uno::XComponentContext > m_xContext
DictionaryList & getActiveDictionary()
std::unique_ptr< weld::RadioButton > m_xRB_To_Simplified
void initDictionaryControl(DictionaryList *pList, const css::uno::Reference< css::linguistic2::XConversionDictionary > &xDictionary)
std::unique_ptr< weld::Entry > m_xED_Mapping
virtual ~ChineseDictionaryDialog() override
void setDirectionAndTextConversionOptions(bool bDirectionToSimplified, sal_Int32 nTextConversionOptions)
std::unique_ptr< weld::Button > m_xPB_Add
void updateAfterDirectionChange()
ChineseDictionaryDialog(weld::Window *pParent)
static void HeaderBarClick(DictionaryList &rList, int nColumn)
bool get_sort_order() const
void addEntry(const OUString &rTerm, const OUString &rMapping, sal_Int16 nConversionPropertyType, int nPos=-1)
int deleteEntries(std::u16string_view rTerm)
void set_sort_order(bool bAscending)
DictionaryList(std::unique_ptr< weld::TreeView > xTreeView)
int get_sort_column() const
DictionaryEntry * getTermEntry(std::u16string_view rTerm) const
void set_sort_indicator(TriState eState, int nColumn)
void refillFromDictionary(sal_Int32 nTextConversionOptions)
void set_sort_column(int nColumn)
DictionaryEntry * getEntryOnPos(sal_Int32 nPos) const
void init(const css::uno::Reference< css::linguistic2::XConversionDictionary > &xDictionary, weld::Entry *pED_Term, weld::Entry *pED_Mapping, weld::ComboBox *pLB_Property)
OUString getPropertyTypeName(sal_Int16 nConversionPropertyType) const
bool hasTerm(std::u16string_view rTerm) const
DictionaryEntry * getFirstSelectedEntry() const
int get_selected_index() const
css::uno::Reference< css::linguistic2::XConversionDictionary > m_xDictionary
weld::TreeView & get_widget() const
std::unique_ptr< weld::TreeView > m_xControl
std::vector< DictionaryEntry * > m_aToBeDeleted
weld::ComboBox * m_pLB_Property
void deleteEntryOnPos(sal_Int32 nPos)
weld::Entry * m_pED_Mapping
std::unique_ptr< weld::TreeIter > m_xIter
virtual OUString get_text(int pos) const=0
virtual int get_count() const=0
constexpr OUStringLiteral UPN_IS_REVERSE_MAPPING
#define LINK(Instance, Class, Member)
IMPL_LINK(ChineseDictionaryDialog, ToSimplifiedHeaderBarClick, int, nColumn, void)
IMPL_LINK_NOARG(ChineseDictionaryDialog, SizeAllocHdl, const Size &, void)
OUString toId(const void *pValue)
DictionaryEntry(OUString rTerm, OUString aMapping, sal_Int16 nConversionPropertyType, bool bNewEntry=false)
sal_Int16 m_nConversionPropertyType