LCOV - code coverage report
Current view: top level - svx/source/unodialogs/textconversiondlgs - chinese_dictionarydialog.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 443 0.0 %
Date: 2014-11-03 Functions: 0 55 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      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>
      40             : #include "helpid.hrc"
      41             : 
      42             : 
      43             : namespace textconversiondlgs
      44             : {
      45             : 
      46             : 
      47             : using namespace ::com::sun::star;
      48             : using namespace ::com::sun::star::uno;
      49             : 
      50             : #define HEADER_BAR_BITS ( HIB_LEFT | HIB_VCENTER | HIB_CLICKABLE | HIB_FIXED | HIB_FIXEDPOS )
      51             : 
      52           0 : DictionaryList::DictionaryList(SvSimpleTableContainer& rParent, WinBits nBits)
      53             :     : SvSimpleTable(rParent, nBits)
      54             :     , m_xDictionary(0)
      55             :     , m_pED_Term(0)
      56             :     , m_pED_Mapping(0)
      57             :     , m_pLB_Property(0)
      58             :     , m_aToBeDeleted()
      59           0 :     , m_nSortColumnIndex(0)
      60             : {
      61           0 : }
      62             : 
      63           0 : OUString DictionaryList::getPropertyTypeName( sal_Int16 nConversionPropertyType ) const
      64             : {
      65           0 :     if(!m_pLB_Property || !m_pLB_Property->GetEntryCount())
      66           0 :         return OUString();
      67             : 
      68           0 :     sal_uInt16 nPos = static_cast<sal_uInt16>( nConversionPropertyType )-1;
      69           0 :     if(nPos<m_pLB_Property->GetEntryCount())
      70           0 :         return m_pLB_Property->GetEntry(nPos);
      71           0 :     return m_pLB_Property->GetEntry(0);
      72             : }
      73             : 
      74           0 : OUString DictionaryList::makeTabString( const DictionaryEntry& rEntry ) const
      75             : {
      76           0 :     OUString aStr( rEntry.m_aTerm );
      77           0 :     aStr += "\t";
      78           0 :     aStr += rEntry.m_aMapping;
      79           0 :     aStr += "\t";
      80           0 :     aStr += getPropertyTypeName( rEntry.m_nConversionPropertyType );
      81           0 :     return aStr;
      82             : }
      83             : 
      84           0 : void DictionaryList::save()
      85             : {
      86           0 :     if( !m_xDictionary.is() )
      87           0 :         return;
      88             : 
      89           0 :     Reference< linguistic2::XConversionPropertyType > xPropertyType( m_xDictionary, uno::UNO_QUERY );
      90             : 
      91             :     sal_Int32 nN;
      92             :     DictionaryEntry* pE;
      93             : 
      94           0 :     for( nN = m_aToBeDeleted.size(); nN--; )
      95             :     {
      96           0 :         pE = m_aToBeDeleted[nN];
      97           0 :         m_xDictionary->removeEntry( pE->m_aTerm, pE->m_aMapping );
      98             :     }
      99           0 :     for( nN = GetRowCount(); nN--; )
     100             :     {
     101           0 :         pE = getEntryOnPos( nN );
     102           0 :         if(pE->m_bNewEntry)
     103             :         {
     104             :             try
     105             :             {
     106           0 :                 m_xDictionary->addEntry( pE->m_aTerm, pE->m_aMapping );
     107           0 :                 xPropertyType->setPropertyType( pE->m_aTerm, pE->m_aMapping, pE->m_nConversionPropertyType );
     108             :             }
     109           0 :             catch( uno::Exception& )
     110             :             {
     111             : 
     112             :             }
     113             :         }
     114             :     }
     115           0 :     Reference< util::XFlushable > xFlush( m_xDictionary, uno::UNO_QUERY );
     116           0 :     if( xFlush.is() )
     117           0 :         xFlush->flush();
     118             : }
     119             : 
     120           0 : void DictionaryList::deleteAll()
     121             : {
     122             :     sal_Int32 nN;
     123           0 :     for( nN = GetRowCount(); nN--; )
     124           0 :         deleteEntryOnPos( nN  );
     125           0 :     for( nN = m_aToBeDeleted.size(); nN--; )
     126             :     {
     127           0 :         DictionaryEntry* pE = m_aToBeDeleted[nN];
     128           0 :         delete pE;
     129             :     }
     130           0 :     m_aToBeDeleted.clear();
     131           0 : }
     132             : 
     133           0 : void DictionaryList::refillFromDictionary( sal_Int32 nTextConversionOptions )
     134             : {
     135           0 :     deleteAll();
     136             : 
     137           0 :     if(!m_xDictionary.is())
     138           0 :         return;
     139             : 
     140           0 :     Sequence< OUString > aLeftList(  m_xDictionary->getConversionEntries( linguistic2::ConversionDirection_FROM_LEFT ) );
     141           0 :     sal_Int32 nCount = aLeftList.getLength();
     142             : 
     143           0 :     Reference< linguistic2::XConversionPropertyType > xPropertyType( m_xDictionary, uno::UNO_QUERY );
     144             : 
     145           0 :     OUString aLeft, aRight;
     146             :     sal_Int16 nConversionPropertyType;
     147             : 
     148           0 :     for(sal_Int32 nN=0; nN<nCount; nN++)
     149             :     {
     150           0 :         aLeft  = aLeftList[nN];
     151           0 :         Sequence< OUString > aRightList( m_xDictionary->getConversions(
     152             :             aLeft, 0, aLeft.getLength()
     153           0 :             , linguistic2::ConversionDirection_FROM_LEFT, nTextConversionOptions ) );
     154             : 
     155           0 :         if(aRightList.getLength()!=1)
     156             :         {
     157             :             OSL_FAIL("The Chinese Translation Dictionary should have exactly one Mapping for each term.");
     158           0 :             continue;
     159             :         }
     160             : 
     161           0 :         aRight = aRightList[0];
     162           0 :         nConversionPropertyType = linguistic2::ConversionPropertyType::OTHER;
     163           0 :         if(xPropertyType.is())
     164           0 :             nConversionPropertyType = xPropertyType->getPropertyType(aLeft, aRight);
     165             : 
     166           0 :         DictionaryEntry* pEntry = new DictionaryEntry( aLeft, aRight, nConversionPropertyType );
     167           0 :         SvTreeListEntry* pLBEntry = InsertEntry( makeTabString( *pEntry ) );
     168           0 :         pLBEntry->SetUserData( pEntry );
     169           0 :     }
     170             : 
     171           0 :     if( GetEntryCount() > 0 )
     172           0 :         SelectRow( 0 );
     173             : }
     174             : 
     175           0 : DictionaryEntry* DictionaryList::getFirstSelectedEntry() const
     176             : {
     177           0 :     DictionaryEntry* pRet=0;
     178           0 :     for( sal_Int32 nN=GetRowCount(); nN--; )
     179             :     {
     180           0 :         if( IsRowSelected( nN ) )
     181             :         {
     182           0 :             pRet = getEntryOnPos( nN );
     183           0 :             break;
     184             :         }
     185             :     }
     186           0 :     return pRet;
     187             : }
     188             : 
     189           0 : DictionaryEntry* DictionaryList::getEntryOnPos( sal_Int32 nPos ) const
     190             : {
     191           0 :     DictionaryEntry* pEntry=0;
     192           0 :     SvTreeListEntry* pLBEntry = GetEntryOnPos( nPos );
     193           0 :     if(pLBEntry)
     194           0 :         pEntry = (DictionaryEntry*)pLBEntry->GetUserData();
     195           0 :     return pEntry;
     196             : }
     197             : 
     198           0 : DictionaryEntry* DictionaryList::getTermEntry( const OUString& rTerm ) const
     199             : {
     200           0 :     DictionaryEntry* pE = 0;
     201           0 :     for( sal_Int32 nN=GetRowCount(); nN--; )
     202             :     {
     203           0 :         pE = getEntryOnPos( nN );
     204           0 :         if( pE && rTerm.equals( pE->m_aTerm ) )
     205           0 :             return pE;
     206             :     }
     207           0 :     return 0;
     208             : }
     209             : 
     210           0 : bool DictionaryList::hasTerm( const OUString& rTerm ) const
     211             : {
     212           0 :     return getTermEntry(rTerm) !=0 ;
     213             : }
     214             : 
     215           0 : void DictionaryList::addEntry( const OUString& rTerm, const OUString& rMapping
     216             :                               , sal_Int16 nConversionPropertyType, sal_uIntPtr nPos )
     217             : {
     218           0 :     if( hasTerm( rTerm ) )
     219           0 :         return;
     220             : 
     221           0 :     DictionaryEntry* pEntry = new DictionaryEntry( rTerm, rMapping, nConversionPropertyType, true );
     222           0 :     SvTreeListEntry* pLBEntry = InsertEntryToColumn( makeTabString( *pEntry ), nPos );
     223           0 :     pLBEntry->SetUserData( pEntry );
     224           0 :     SelectRow( GetEntryPos( pLBEntry ) );
     225             : }
     226             : 
     227           0 : void DictionaryList::deleteEntryOnPos( sal_Int32 nPos  )
     228             : {
     229           0 :     SvTreeListEntry* pLBEntry = GetEntryOnPos( nPos );
     230           0 :     DictionaryEntry* pEntry = getEntryOnPos( nPos );
     231           0 :     if( pLBEntry )
     232           0 :         RemoveParentKeepChildren( pLBEntry );
     233           0 :     if( pEntry )
     234             :     {
     235           0 :         if( pEntry->m_bNewEntry )
     236           0 :             delete pEntry;
     237             :         else
     238           0 :             m_aToBeDeleted.push_back( pEntry );
     239             :     }
     240           0 : }
     241             : 
     242           0 : sal_uIntPtr DictionaryList::deleteEntries( const OUString& rTerm )
     243             : {
     244           0 :     sal_uIntPtr nPos = TREELIST_APPEND;
     245           0 :     for( sal_Int32 nN=GetRowCount(); nN--; )
     246             :     {
     247           0 :         DictionaryEntry* pCurEntry = getEntryOnPos( nN );
     248           0 :         if( rTerm.equals( pCurEntry->m_aTerm ) )
     249             :         {
     250           0 :             nPos = nN;
     251           0 :             SvTreeListEntry* pCurLBEntry = GetEntryOnPos( nN );
     252           0 :             RemoveParentKeepChildren( pCurLBEntry );
     253           0 :             if( pCurEntry->m_bNewEntry )
     254           0 :                 delete pCurEntry;
     255             :             else
     256           0 :                 m_aToBeDeleted.push_back( pCurEntry );
     257             :         }
     258             :     }
     259           0 :     return nPos;
     260             : }
     261             : 
     262           0 : void DictionaryList::sortByColumn( sal_uInt16 nSortColumnIndex, bool bSortAtoZ )
     263             : {
     264           0 :     m_nSortColumnIndex=nSortColumnIndex;
     265           0 :     if( nSortColumnIndex<3 )
     266             :     {
     267           0 :         if(bSortAtoZ)
     268           0 :             GetModel()->SetSortMode(SortAscending);
     269             :         else
     270           0 :             GetModel()->SetSortMode(SortDescending);
     271             : 
     272           0 :         GetModel()->SetCompareHdl( LINK( this, DictionaryList, CompareHdl));
     273           0 :         GetModel()->Resort();
     274             :     }
     275             :     else
     276           0 :         GetModel()->SetSortMode(SortNone);
     277           0 : }
     278             : 
     279             : 
     280           0 : IMPL_LINK( DictionaryList, CompareHdl, SvSortData*, pData )
     281             : {
     282           0 :     SvTreeListEntry* pLeft = (SvTreeListEntry*)(pData->pLeft );
     283           0 :     SvTreeListEntry* pRight = (SvTreeListEntry*)(pData->pRight );
     284           0 :     return (long) ColumnCompare(pLeft,pRight);
     285             : }
     286             : 
     287           0 : sal_Int32 DictionaryList::ColumnCompare( SvTreeListEntry* pLeft, SvTreeListEntry* pRight )
     288             : {
     289           0 :     sal_Int32 nCompare = 0;
     290             : 
     291           0 :     SvLBoxItem* pLeftItem = getItemAtColumn( pLeft, m_nSortColumnIndex );
     292           0 :     SvLBoxItem* pRightItem = getItemAtColumn( pRight, m_nSortColumnIndex );
     293             : 
     294           0 :     if(pLeftItem != NULL && pRightItem != NULL)
     295             :     {
     296           0 :         sal_uInt16 nLeftKind = pLeftItem->GetType();
     297           0 :         sal_uInt16 nRightKind = pRightItem->GetType();
     298             : 
     299           0 :         if(nRightKind == SV_ITEM_ID_LBOXSTRING &&
     300             :             nLeftKind == SV_ITEM_ID_LBOXSTRING )
     301             :         {
     302           0 :             IntlWrapper aIntlWrapper( Application::GetSettings().GetLanguageTag() );
     303           0 :             const CollatorWrapper* pCollator = aIntlWrapper.getCaseCollator();
     304             : 
     305             :             nCompare = pCollator->compareString( static_cast<SvLBoxString*>(pLeftItem)->GetText(),
     306           0 :                                     static_cast<SvLBoxString*>(pRightItem)->GetText());
     307             : 
     308           0 :             if (nCompare == 0)
     309           0 :                 nCompare = -1;
     310             :         }
     311             :     }
     312           0 :     return nCompare;
     313             : }
     314             : 
     315           0 : SvLBoxItem* DictionaryList::getItemAtColumn( SvTreeListEntry* pEntry, sal_uInt16 nColumn ) const
     316             : {
     317           0 :     SvLBoxItem* pItem = NULL;
     318           0 :     if( pEntry )
     319             :     {
     320           0 :         sal_uInt16 nCount = pEntry->ItemCount();
     321           0 :         nColumn++;
     322           0 :         if( nTreeFlags & TREEFLAG_CHKBTN )
     323           0 :             nColumn++;
     324           0 :            if( nColumn < nCount )
     325           0 :             pItem = pEntry->GetItem( nColumn );
     326             :     }
     327           0 :     return pItem;
     328             : }
     329             : 
     330             : 
     331             : 
     332             : 
     333             : 
     334           0 : DictionaryEntry::DictionaryEntry( const OUString& rTerm, const OUString& rMapping
     335             :                     , sal_Int16 nConversionPropertyType
     336             :                     , bool bNewEntry )
     337             :         : m_aTerm( rTerm )
     338             :         , m_aMapping( rMapping )
     339             :         , m_nConversionPropertyType( nConversionPropertyType )
     340           0 :         , m_bNewEntry( bNewEntry )
     341             : {
     342           0 :     if( m_nConversionPropertyType == 0 )
     343           0 :         m_nConversionPropertyType = 1;
     344           0 : }
     345             : 
     346           0 : DictionaryEntry::~DictionaryEntry()
     347             : {
     348           0 : }
     349             : 
     350           0 : bool DictionaryEntry::operator==( const DictionaryEntry& rE ) const
     351             : {
     352           0 :     return m_aTerm == rE.m_aTerm
     353           0 :             && m_aMapping == rE.m_aMapping
     354           0 :             && m_nConversionPropertyType == rE.m_nConversionPropertyType;
     355             : }
     356             : 
     357           0 : void DictionaryList::setColSizes()
     358             : {
     359           0 :     HeaderBar &rBar = GetTheHeaderBar();
     360           0 :     if (rBar.GetItemCount() < 3)
     361           0 :         return;
     362             : 
     363           0 :     long nWidth1 = m_pED_Term->get_preferred_size().Width();
     364           0 :     long nWidth2 = m_pED_Mapping->get_preferred_size().Width();
     365           0 :     long nWidth3 = m_pLB_Property->get_preferred_size().Width();
     366             : 
     367           0 :     long nWidth = GetSizePixel().Width();
     368           0 :     long nPos3 = nWidth - nWidth3;
     369           0 :     long nRemainder = nWidth - (nWidth1 + nWidth2 + nWidth3);
     370             : 
     371           0 :     long aStaticTabs[] = { 3, 0, nWidth1 + (nRemainder/2), nPos3 };
     372           0 :     SvSimpleTable::SetTabs(aStaticTabs, MAP_PIXEL);
     373             : }
     374             : 
     375           0 : void DictionaryList::Resize()
     376             : {
     377           0 :     SvSimpleTable::Resize();
     378           0 :     setColSizes();
     379           0 : }
     380             : 
     381           0 : void DictionaryList::init(const Reference< linguistic2::XConversionDictionary>& xDictionary,
     382             :     vcl::Window *pED_Term, vcl::Window *pED_Mapping, ListBox *pLB_Property,
     383             :     vcl::Window *pFT_Term, vcl::Window *pFT_Mapping, vcl::Window *pFT_Property)
     384             : {
     385           0 :     SetStyle( WB_VSCROLL | WB_TABSTOP );
     386           0 :     SetSelectionMode( SINGLE_SELECTION );
     387           0 :     SetBorderStyle( WindowBorderStyle::MONO );
     388           0 :     SetHighlightRange();
     389             : 
     390           0 :     if (m_xDictionary.is())
     391           0 :         return;
     392             : 
     393           0 :     m_xDictionary = xDictionary;
     394             : 
     395           0 :     m_pED_Term = pED_Term;
     396           0 :     m_pED_Mapping = pED_Mapping;
     397           0 :     m_pLB_Property = pLB_Property;
     398             : 
     399           0 :     HeaderBar& rHeaderBar = GetTheHeaderBar();
     400             : 
     401           0 :     OUString aColumn1( OutputDevice::GetNonMnemonicString( pFT_Term->GetText() ) );
     402           0 :     OUString aColumn2( OutputDevice::GetNonMnemonicString( pFT_Mapping->GetText() ) );
     403           0 :     OUString aColumn3( OutputDevice::GetNonMnemonicString( pFT_Property->GetText() ) );
     404             : 
     405           0 :     long nWidth1 = m_pED_Term->get_preferred_size().Width();
     406           0 :     long nWidth2 = m_pED_Mapping->get_preferred_size().Width();
     407           0 :     long nWidth3 = m_pLB_Property->get_preferred_size().Width();
     408             : 
     409           0 :     HeaderBarItemBits nBits = HEADER_BAR_BITS;
     410           0 :     rHeaderBar.InsertItem( 1, aColumn1, nWidth1, nBits | HIB_UPARROW );
     411           0 :     rHeaderBar.InsertItem( 2, aColumn2, nWidth2, nBits );
     412           0 :     rHeaderBar.InsertItem( 3, aColumn3, nWidth3, nBits );
     413             : 
     414           0 :     long pTabs[] = { 3, 0, nWidth1, nWidth1 + nWidth2 };
     415           0 :     SetTabs( &pTabs[0], MAP_PIXEL );
     416             : }
     417             : 
     418           0 : void ChineseDictionaryDialog::initDictionaryControl(DictionaryList *pList,
     419             :     const Reference< linguistic2::XConversionDictionary>& xDictionary)
     420             : {
     421             :     //init HeaderBar and set tabs
     422           0 :     HeaderBar& rHeaderBar = pList->GetTheHeaderBar();
     423             :     //set hdl
     424           0 :     rHeaderBar.SetSelectHdl( LINK( this, ChineseDictionaryDialog, HeaderBarClick ) );
     425             :     //set widgets to track the width of for columns
     426             :     pList->init(xDictionary,
     427             :         m_pED_Term, m_pED_Mapping, m_pLB_Property,
     428           0 :         m_pFT_Term, m_pFT_Mapping, m_pFT_Property);
     429           0 : }
     430             : 
     431           0 : ChineseDictionaryDialog::ChineseDictionaryDialog( vcl::Window* pParent )
     432             :     : ModalDialog(pParent, "ChineseDictionaryDialog",
     433             :          "svx/ui/chinesedictionary.ui")
     434             :     , m_nTextConversionOptions(i18n::TextConversionOption::NONE)
     435           0 :     , m_xContext(0)
     436             : {
     437           0 :     get(m_pRB_To_Simplified, "tradtosimple");
     438           0 :     get(m_pRB_To_Traditional, "simpletotrad");
     439           0 :     get(m_pCB_Reverse, "reverse");
     440           0 :     get(m_pFT_Term, "termft");
     441           0 :     get(m_pED_Term, "term");
     442           0 :     get(m_pFT_Mapping, "mappingft");
     443           0 :     get(m_pED_Mapping, "mapping");
     444           0 :     get(m_pFT_Property, "propertyft");
     445           0 :     get(m_pLB_Property, "property");
     446             : 
     447           0 :     get(m_pPB_Add, "add");
     448           0 :     get(m_pPB_Modify, "modify");
     449           0 :     get(m_pPB_Delete, "delete");
     450             : 
     451           0 :     get(mpToSimplifiedContainer, "tradtosimpleview");
     452           0 :     mpToSimplifiedContainer->set_height_request(mpToSimplifiedContainer->GetTextHeight() * 8);
     453           0 :     m_pCT_DictionaryToSimplified = new DictionaryList(*mpToSimplifiedContainer, 0);
     454           0 :     get(mpToTraditionalContainer, "simpletotradview");
     455           0 :     mpToTraditionalContainer->set_height_request(mpToTraditionalContainer->GetTextHeight() * 8);
     456           0 :     m_pCT_DictionaryToTraditional = new DictionaryList(*mpToTraditionalContainer, 0);
     457             : 
     458           0 :     SvtLinguConfig  aLngCfg;
     459             :     bool bValue;
     460           0 :     Any aAny( aLngCfg.GetProperty( OUString( UPN_IS_REVERSE_MAPPING ) ) );
     461           0 :     if( aAny >>= bValue )
     462           0 :         m_pCB_Reverse->Check( bValue );
     463             : 
     464           0 :     m_pLB_Property->SetDropDownLineCount( m_pLB_Property->GetEntryCount() );
     465           0 :     m_pLB_Property->SelectEntryPos(0);
     466             : 
     467           0 :     Reference< linguistic2::XConversionDictionary > xDictionary_To_Simplified(0);
     468           0 :     Reference< linguistic2::XConversionDictionary > xDictionary_To_Traditional(0);
     469             :     //get dictionaries
     470             :     {
     471           0 :         if(!m_xContext.is())
     472           0 :             m_xContext = Reference< XComponentContext >( ::cppu::defaultBootstrap_InitialComponentContext() );
     473           0 :         if(m_xContext.is())
     474             :         {
     475           0 :             Reference< linguistic2::XConversionDictionaryList > xDictionaryList = linguistic2::ConversionDictionaryList::create(m_xContext);
     476           0 :             Reference< container::XNameContainer > xContainer( xDictionaryList->getDictionaryContainer() );
     477           0 :             if(xContainer.is())
     478             :             {
     479             :                 try
     480             :                 {
     481           0 :                     OUString aNameTo_Simplified("ChineseT2S");
     482           0 :                     OUString aNameTo_Traditional("ChineseS2T");
     483           0 :                     lang::Locale aLocale;
     484           0 :                     aLocale.Language = "zh";
     485             : 
     486           0 :                     if( xContainer->hasByName( aNameTo_Simplified ) )
     487           0 :                         xDictionary_To_Simplified = Reference< linguistic2::XConversionDictionary >(
     488           0 :                                 xContainer->getByName( aNameTo_Simplified ), UNO_QUERY );
     489             :                     else
     490             :                     {
     491           0 :                         aLocale.Country = "TW";
     492           0 :                         xDictionary_To_Simplified = Reference< linguistic2::XConversionDictionary >(
     493           0 :                                 xDictionaryList->addNewDictionary( aNameTo_Simplified
     494             :                                 , aLocale, linguistic2::ConversionDictionaryType::SCHINESE_TCHINESE
     495           0 :                                     ), UNO_QUERY );
     496             :                     }
     497           0 :                     if (xDictionary_To_Simplified.is())
     498           0 :                         xDictionary_To_Simplified->setActive( sal_True );
     499             : 
     500             : 
     501           0 :                     if( xContainer->hasByName( aNameTo_Traditional ) )
     502           0 :                         xDictionary_To_Traditional = Reference< linguistic2::XConversionDictionary >(
     503           0 :                                 xContainer->getByName( aNameTo_Traditional ), UNO_QUERY );
     504             :                     else
     505             :                     {
     506           0 :                         aLocale.Country = "CN";
     507           0 :                         xDictionary_To_Traditional = Reference< linguistic2::XConversionDictionary >(
     508           0 :                                 xDictionaryList->addNewDictionary( aNameTo_Traditional
     509             :                                 , aLocale, linguistic2::ConversionDictionaryType::SCHINESE_TCHINESE
     510           0 :                                     ), UNO_QUERY );
     511             :                     }
     512           0 :                     if (xDictionary_To_Traditional.is())
     513           0 :                         xDictionary_To_Traditional->setActive( sal_True );
     514             : 
     515             :                 }
     516           0 :                 catch(const uno::Exception& )
     517             :                 {
     518             :                 }
     519           0 :             }
     520             :         }
     521             :     }
     522             : 
     523             :     //init dictionary controls
     524           0 :     initDictionaryControl(m_pCT_DictionaryToSimplified, xDictionary_To_Simplified);
     525           0 :     initDictionaryControl(m_pCT_DictionaryToTraditional, xDictionary_To_Traditional);
     526             : 
     527           0 :     updateAfterDirectionChange();
     528             : 
     529           0 :     m_pED_Term->SetModifyHdl( LINK( this, ChineseDictionaryDialog, EditFieldsHdl ) );
     530           0 :     m_pED_Mapping->SetModifyHdl( LINK( this, ChineseDictionaryDialog, EditFieldsHdl ) );
     531           0 :     m_pLB_Property->SetSelectHdl( LINK( this, ChineseDictionaryDialog, EditFieldsHdl ) );
     532             : 
     533           0 :     m_pRB_To_Simplified->SetClickHdl( LINK( this, ChineseDictionaryDialog, DirectionHdl ) );
     534           0 :     m_pRB_To_Traditional->SetClickHdl( LINK( this, ChineseDictionaryDialog, DirectionHdl ) );
     535             : 
     536           0 :     m_pCT_DictionaryToSimplified->SetSelectHdl( LINK( this, ChineseDictionaryDialog, MappingSelectHdl ));
     537           0 :     m_pCT_DictionaryToTraditional->SetSelectHdl( LINK( this, ChineseDictionaryDialog, MappingSelectHdl ));
     538             : 
     539           0 :     m_pPB_Add->SetClickHdl( LINK( this, ChineseDictionaryDialog, AddHdl ) );
     540           0 :     m_pPB_Modify->SetClickHdl( LINK( this, ChineseDictionaryDialog, ModifyHdl ) );
     541           0 :     m_pPB_Delete->SetClickHdl( LINK( this, ChineseDictionaryDialog, DeleteHdl ) );
     542           0 : }
     543             : 
     544           0 : ChineseDictionaryDialog::~ChineseDictionaryDialog()
     545             : {
     546           0 :     m_xContext=0;
     547           0 :     delete m_pCT_DictionaryToSimplified;
     548           0 :     delete m_pCT_DictionaryToTraditional;
     549           0 : }
     550             : 
     551           0 : void ChineseDictionaryDialog::setDirectionAndTextConversionOptions( bool bDirectionToSimplified, sal_Int32 nTextConversionOptions /*i18n::TextConversionOption*/ )
     552             : {
     553           0 :     if( bDirectionToSimplified == bool(m_pRB_To_Simplified->IsChecked())
     554           0 :         && nTextConversionOptions == m_nTextConversionOptions )
     555           0 :         return;
     556             : 
     557           0 :     m_nTextConversionOptions = nTextConversionOptions;
     558             : 
     559           0 :     if( bDirectionToSimplified )
     560           0 :         m_pRB_To_Simplified->Check();
     561             :     else
     562           0 :         m_pRB_To_Traditional->Check();
     563           0 :     updateAfterDirectionChange();
     564             : }
     565             : 
     566           0 : IMPL_LINK_NOARG(ChineseDictionaryDialog, DirectionHdl)
     567             : {
     568           0 :     updateAfterDirectionChange();
     569           0 :     return 0;
     570             : }
     571             : 
     572           0 : void ChineseDictionaryDialog::updateAfterDirectionChange()
     573             : {
     574           0 :     Reference< linguistic2::XConversionDictionary > xDictionary(0);
     575             : 
     576           0 :     if( m_pRB_To_Simplified->IsChecked() )
     577             :     {
     578           0 :         mpToTraditionalContainer->Hide();
     579           0 :         mpToSimplifiedContainer->Show();
     580           0 :         xDictionary = m_pCT_DictionaryToSimplified->m_xDictionary;
     581             :     }
     582             :     else
     583             :     {
     584           0 :         mpToSimplifiedContainer->Hide();
     585           0 :         mpToTraditionalContainer->Show();
     586           0 :         xDictionary = m_pCT_DictionaryToTraditional->m_xDictionary;
     587             :     }
     588             : 
     589           0 :     updateButtons();
     590           0 : }
     591             : 
     592           0 : IMPL_LINK_NOARG(ChineseDictionaryDialog, EditFieldsHdl)
     593             : {
     594           0 :     updateButtons();
     595           0 :     return 0;
     596             : }
     597           0 : IMPL_LINK_NOARG(ChineseDictionaryDialog, MappingSelectHdl)
     598             : {
     599           0 :     DictionaryEntry* pE = getActiveDictionary().getFirstSelectedEntry();
     600           0 :     if(pE)
     601             :     {
     602           0 :         m_pED_Term->SetText( pE->m_aTerm );
     603           0 :         m_pED_Mapping->SetText( pE->m_aMapping );
     604           0 :         sal_Int16 nPos = pE->m_nConversionPropertyType-1;
     605           0 :         if( nPos<0 || nPos>=m_pLB_Property->GetEntryCount() )
     606           0 :             nPos=0;
     607           0 :         if( m_pLB_Property->GetEntryCount() )
     608           0 :             m_pLB_Property->SelectEntryPos(nPos);
     609             :     }
     610             : 
     611           0 :     updateButtons();
     612           0 :     return 0;
     613             : }
     614             : 
     615           0 : bool ChineseDictionaryDialog::isEditFieldsHaveContent() const
     616             : {
     617           0 :     return !m_pED_Term->GetText().isEmpty() && !m_pED_Mapping->GetText().isEmpty();
     618             : }
     619             : 
     620           0 : bool ChineseDictionaryDialog::isEditFieldsContentEqualsSelectedListContent() const
     621             : {
     622           0 :     DictionaryEntry* pE = getActiveDictionary().getFirstSelectedEntry();
     623           0 :     if( pE )
     624             :     {
     625           0 :         if( pE->m_aTerm != OUString( m_pED_Term->GetText() ) )
     626           0 :             return false;
     627           0 :         if( pE->m_aMapping != OUString( m_pED_Mapping->GetText() ) )
     628           0 :             return false;
     629           0 :         if( pE->m_nConversionPropertyType != m_pLB_Property->GetSelectEntryPos()+1 )
     630           0 :             return false;
     631           0 :         return true;
     632             :     }
     633           0 :     return false;
     634             : }
     635             : 
     636           0 : const DictionaryList& ChineseDictionaryDialog::getActiveDictionary() const
     637             : {
     638           0 :     if( m_pRB_To_Traditional->IsChecked() )
     639           0 :         return *m_pCT_DictionaryToTraditional;
     640           0 :     return *m_pCT_DictionaryToSimplified;
     641             : }
     642             : 
     643           0 : DictionaryList& ChineseDictionaryDialog::getActiveDictionary()
     644             : {
     645           0 :     if( m_pRB_To_Traditional->IsChecked() )
     646           0 :         return *m_pCT_DictionaryToTraditional;
     647           0 :     return *m_pCT_DictionaryToSimplified;
     648             : }
     649             : 
     650           0 : const DictionaryList& ChineseDictionaryDialog::getReverseDictionary() const
     651             : {
     652           0 :     if( m_pRB_To_Traditional->IsChecked() )
     653           0 :         return *m_pCT_DictionaryToSimplified;
     654           0 :     return *m_pCT_DictionaryToTraditional;
     655             : }
     656             : 
     657           0 : DictionaryList& ChineseDictionaryDialog::getReverseDictionary()
     658             : {
     659           0 :     if( m_pRB_To_Traditional->IsChecked() )
     660           0 :         return *m_pCT_DictionaryToSimplified;
     661           0 :     return *m_pCT_DictionaryToTraditional;
     662             : }
     663             : 
     664           0 : void ChineseDictionaryDialog::updateButtons()
     665             : {
     666           0 :     bool bAdd = isEditFieldsHaveContent() && !getActiveDictionary().hasTerm( m_pED_Term->GetText() );
     667           0 :     m_pPB_Add->Enable( bAdd );
     668             : 
     669           0 :     m_pPB_Delete->Enable( !bAdd && getActiveDictionary().GetSelectedRowCount()>0 );
     670             : 
     671             : //    DictionaryEntry* pFirstSelectedEntry = getActiveDictionary().getFirstSelectedEntry();
     672             : 
     673           0 :     bool bModify = false;
     674             :     {
     675           0 :         DictionaryEntry* pFirstSelectedEntry = getActiveDictionary().getFirstSelectedEntry();
     676           0 :         bModify = !bAdd && getActiveDictionary().GetSelectedRowCount()==1
     677           0 :                         && pFirstSelectedEntry && pFirstSelectedEntry->m_aTerm.equals( m_pED_Term->GetText() );
     678           0 :         if( bModify && isEditFieldsContentEqualsSelectedListContent() )
     679           0 :             bModify = false;
     680             :     }
     681           0 :     m_pPB_Modify->Enable( bModify );
     682           0 : }
     683             : 
     684           0 : IMPL_LINK_NOARG(ChineseDictionaryDialog, AddHdl)
     685             : {
     686           0 :     if( !isEditFieldsHaveContent() )
     687           0 :         return 0;
     688             : 
     689           0 :     sal_Int16 nConversionPropertyType = m_pLB_Property->GetSelectEntryPos()+1;
     690             : 
     691           0 :     getActiveDictionary().addEntry( m_pED_Term->GetText(), m_pED_Mapping->GetText(), nConversionPropertyType );
     692             : 
     693           0 :     if( m_pCB_Reverse->IsChecked() )
     694             :     {
     695           0 :         getReverseDictionary().deleteEntries( m_pED_Mapping->GetText() );
     696           0 :         getReverseDictionary().addEntry( m_pED_Mapping->GetText(), m_pED_Term->GetText(), nConversionPropertyType );
     697             :     }
     698             : 
     699           0 :     updateButtons();
     700           0 :     return 0;
     701             : }
     702           0 : IMPL_LINK_NOARG(ChineseDictionaryDialog, ModifyHdl)
     703             : {
     704           0 :     OUString aTerm( m_pED_Term->GetText() );
     705           0 :     OUString aMapping( m_pED_Mapping->GetText() );
     706           0 :     sal_Int16 nConversionPropertyType = m_pLB_Property->GetSelectEntryPos()+1;
     707             : 
     708           0 :     DictionaryList& rActive  = getActiveDictionary();
     709           0 :     DictionaryList& rReverse = getReverseDictionary();
     710             : 
     711           0 :     DictionaryEntry* pE = rActive.getFirstSelectedEntry();
     712           0 :     if( pE && pE->m_aTerm != aTerm )
     713           0 :         return 0;
     714             : 
     715           0 :     if( pE )
     716             :     {
     717           0 :         if( pE->m_aMapping != aMapping || pE->m_nConversionPropertyType != nConversionPropertyType )
     718             :         {
     719           0 :             if( m_pCB_Reverse->IsChecked() )
     720             :             {
     721           0 :                 sal_uIntPtr nPos = rReverse.deleteEntries( pE->m_aMapping );
     722           0 :                 nPos = rReverse.deleteEntries( aMapping );
     723           0 :                 rReverse.addEntry( aMapping, aTerm, nConversionPropertyType, nPos );
     724             :             }
     725             : 
     726           0 :             sal_uIntPtr nPos = rActive.deleteEntries( aTerm );
     727           0 :             rActive.addEntry( aTerm, aMapping, nConversionPropertyType, nPos );
     728             :         }
     729             :     }
     730             : 
     731           0 :     updateButtons();
     732           0 :     return 0;
     733             : }
     734             : 
     735           0 : IMPL_LINK_NOARG(ChineseDictionaryDialog, DeleteHdl)
     736             : {
     737           0 :     DictionaryList& rActive  = getActiveDictionary();
     738           0 :     DictionaryList& rReverse = getReverseDictionary();
     739             : 
     740           0 :     if( rActive.GetSelectedRowCount()>0)
     741             :     {
     742             :         DictionaryEntry* pEntry;
     743             : 
     744           0 :         OUString aMapping;
     745           0 :         for( sal_Int32 nN=rActive.GetRowCount(); nN--; )
     746             :         {
     747           0 :             if( rActive.IsRowSelected( nN ) )
     748             :             {
     749           0 :                 pEntry = rActive.getEntryOnPos( nN );
     750           0 :                 if(pEntry)
     751             :                 {
     752           0 :                     aMapping = pEntry->m_aMapping;
     753           0 :                     rActive.deleteEntryOnPos( nN );
     754           0 :                     if( m_pCB_Reverse->IsChecked() )
     755           0 :                         rReverse.deleteEntries( aMapping  );
     756             :                 }
     757           0 :                 break;
     758             :             }
     759           0 :         }
     760             :     }
     761             : 
     762           0 :     updateButtons();
     763           0 :     return 0;
     764             : }
     765             : 
     766           0 : short ChineseDictionaryDialog::Execute()
     767             : {
     768           0 :     sal_Int32 nTextConversionOptions = m_nTextConversionOptions;
     769           0 :     if(m_nTextConversionOptions & i18n::TextConversionOption::USE_CHARACTER_VARIANTS )
     770           0 :         nTextConversionOptions = nTextConversionOptions^i18n::TextConversionOption::USE_CHARACTER_VARIANTS ;
     771             : 
     772           0 :     m_pCT_DictionaryToSimplified->refillFromDictionary( nTextConversionOptions );
     773           0 :     m_pCT_DictionaryToTraditional->refillFromDictionary( m_nTextConversionOptions );
     774             : 
     775           0 :     short nRet = ModalDialog::Execute();
     776             : 
     777           0 :     if( nRet == RET_OK )
     778             :     {
     779             :         //save settings to configuration
     780           0 :         SvtLinguConfig  aLngCfg;
     781           0 :         Any aAny;
     782           0 :         aAny <<= m_pCB_Reverse->IsChecked();
     783           0 :         aLngCfg.SetProperty( OUString( UPN_IS_REVERSE_MAPPING ), aAny );
     784             : 
     785           0 :         m_pCT_DictionaryToSimplified->save();
     786           0 :         m_pCT_DictionaryToTraditional->save();
     787             :     }
     788             : 
     789           0 :     m_pCT_DictionaryToSimplified->deleteAll();
     790           0 :     m_pCT_DictionaryToTraditional->deleteAll();
     791             : 
     792           0 :     return nRet;
     793             : }
     794             : 
     795           0 : IMPL_LINK(ChineseDictionaryDialog, HeaderBarClick, HeaderBar*, pHeaderBar)
     796             : {
     797           0 :     sal_uInt16 nId = pHeaderBar->GetCurItemId();
     798           0 :     HeaderBarItemBits nBits = pHeaderBar->GetItemBits(nId);
     799           0 :     if( nBits & HIB_CLICKABLE )
     800             :     {
     801             :         //set new arrow positions in headerbar
     802           0 :         pHeaderBar->SetItemBits( getActiveDictionary().getSortColumn()+1, HEADER_BAR_BITS );
     803           0 :         if( nBits & HIB_UPARROW )
     804           0 :             pHeaderBar->SetItemBits( nId, HEADER_BAR_BITS | HIB_DOWNARROW );
     805             :         else
     806           0 :             pHeaderBar->SetItemBits( nId, HEADER_BAR_BITS | HIB_UPARROW );
     807             : 
     808             :         //sort lists
     809           0 :         nBits = pHeaderBar->GetItemBits(nId);
     810           0 :         bool bSortAtoZ = nBits & HIB_UPARROW;
     811           0 :         getActiveDictionary().sortByColumn(nId-1,bSortAtoZ);
     812           0 :         getReverseDictionary().sortByColumn(nId-1,bSortAtoZ);
     813             :     }
     814             : 
     815           0 :     return 0;
     816             : }
     817             : 
     818             : 
     819           0 : } //end namespace
     820             : 
     821             : 
     822             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10