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

Generated by: LCOV version 1.10