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

Generated by: LCOV version 1.10