LCOV - code coverage report
Current view: top level - libreoffice/svx/source/unodialogs/textconversiondlgs - chinese_dictionarydialog.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 446 0.0 %
Date: 2012-12-27 Functions: 0 57 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/XConversionDictionaryList.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< rtl::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 :     rtl::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< rtl::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 rtl::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 rtl::OUString& rTerm ) const
     246             : {
     247           0 :     return getTermEntry(rTerm) !=0 ;
     248             : }
     249             : 
     250           0 : void DictionaryList::addEntry( const rtl::OUString& rTerm, const rtl::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, sal_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 rtl::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 rtl::OUString& rTerm, const rtl::OUString& rMapping
     423             :                     , sal_Int16 nConversionPropertyType
     424             :                     , sal_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             :     , m_xContext( 0 )
     472           0 :     , m_xFactory( 0 )
     473             : {
     474           0 :     FreeResource();
     475             : 
     476           0 :     m_aRB_To_Simplified.SetHelpId( HID_SVX_CHINESE_DICTIONARY_RB_CONVERSION_TO_SIMPLIFIED );
     477           0 :     m_aRB_To_Traditional.SetHelpId( HID_SVX_CHINESE_DICTIONARY_RB_CONVERSION_TO_TRADITIONAL );
     478             : 
     479           0 :     m_aCB_Reverse.SetHelpId( HID_SVX_CHINESE_DICTIONARY_CB_REVERSE );
     480             : 
     481           0 :     m_aCT_DictionaryToSimplified.SetHelpId( HID_SVX_CHINESE_DICTIONARY_LB_TO_SIMPLIFIED );
     482           0 :     m_aCT_DictionaryToTraditional.SetHelpId( HID_SVX_CHINESE_DICTIONARY_LB_TO_TRADITIONAL );
     483             : 
     484           0 :     SvtLinguConfig  aLngCfg;
     485           0 :     sal_Bool bValue = sal_Bool();
     486           0 :     Any aAny( aLngCfg.GetProperty( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( UPN_IS_REVERSE_MAPPING )) ) );
     487           0 :     if( aAny >>= bValue )
     488           0 :         m_aCB_Reverse.Check( bValue );
     489             : 
     490           0 :     m_aLB_Property.SetDropDownLineCount( m_aLB_Property.GetEntryCount() );
     491           0 :     m_aLB_Property.SelectEntryPos(0);
     492             : 
     493           0 :     Reference< linguistic2::XConversionDictionary > xDictionary_To_Simplified(0);
     494           0 :     Reference< linguistic2::XConversionDictionary > xDictionary_To_Traditional(0);
     495             :     //get dictionaries
     496             :     {
     497           0 :         if(!m_xContext.is())
     498           0 :             m_xContext = Reference< XComponentContext >( ::cppu::defaultBootstrap_InitialComponentContext() );
     499           0 :         if(m_xContext.is())
     500           0 :             m_xFactory = Reference< lang::XMultiComponentFactory >( m_xContext->getServiceManager() );
     501           0 :         if(m_xFactory.is())
     502             :         {
     503             :             Reference< linguistic2::XConversionDictionaryList > xDictionaryList(
     504           0 :                                 m_xFactory->createInstanceWithContext(
     505             :                                     rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.linguistic2.ConversionDictionaryList"))
     506           0 :                                     , m_xContext), uno::UNO_QUERY);
     507           0 :             if( xDictionaryList.is() )
     508             :             {
     509           0 :                 Reference< container::XNameContainer > xContainer( xDictionaryList->getDictionaryContainer() );
     510           0 :                 if(xContainer.is())
     511             :                 {
     512             :                     try
     513             :                     {
     514           0 :                         rtl::OUString aNameTo_Simplified( RTL_CONSTASCII_USTRINGPARAM("ChineseT2S") );
     515           0 :                         rtl::OUString aNameTo_Traditional( RTL_CONSTASCII_USTRINGPARAM("ChineseS2T") );
     516           0 :                         lang::Locale aLocale;
     517           0 :                         aLocale.Language = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("zh") );
     518             : 
     519           0 :                         if( xContainer->hasByName( aNameTo_Simplified ) )
     520             :                             xDictionary_To_Simplified = Reference< linguistic2::XConversionDictionary >(
     521           0 :                                     xContainer->getByName( aNameTo_Simplified ), UNO_QUERY );
     522             :                         else
     523             :                         {
     524           0 :                             aLocale.Country = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TW") );
     525             :                             xDictionary_To_Simplified = Reference< linguistic2::XConversionDictionary >(
     526           0 :                                     xDictionaryList->addNewDictionary( aNameTo_Simplified
     527             :                                     , aLocale, linguistic2::ConversionDictionaryType::SCHINESE_TCHINESE
     528           0 :                                         ), UNO_QUERY );
     529             :                         }
     530           0 :                         if (xDictionary_To_Simplified.is())
     531           0 :                             xDictionary_To_Simplified->setActive( sal_True );
     532             : 
     533             : 
     534           0 :                         if( xContainer->hasByName( aNameTo_Traditional ) )
     535             :                             xDictionary_To_Traditional = Reference< linguistic2::XConversionDictionary >(
     536           0 :                                     xContainer->getByName( aNameTo_Traditional ), UNO_QUERY );
     537             :                         else
     538             :                         {
     539           0 :                             aLocale.Country = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CN") );
     540             :                             xDictionary_To_Traditional = Reference< linguistic2::XConversionDictionary >(
     541           0 :                                     xDictionaryList->addNewDictionary( aNameTo_Traditional
     542             :                                     , aLocale, linguistic2::ConversionDictionaryType::SCHINESE_TCHINESE
     543           0 :                                         ), UNO_QUERY );
     544             :                         }
     545           0 :                         if (xDictionary_To_Traditional.is())
     546           0 :                             xDictionary_To_Traditional->setActive( sal_True );
     547             : 
     548             :                     }
     549           0 :                     catch( uno::Exception& )
     550             :                     {
     551             :                     }
     552           0 :                 }
     553           0 :             }
     554             :         }
     555             :     }
     556             : 
     557             :     //init HeaderBar and set tabs
     558             :     {
     559           0 :         String aColumn1( OutputDevice::GetNonMnemonicString( m_aFT_Term.GetText() ) );
     560           0 :         String aColumn2( OutputDevice::GetNonMnemonicString( m_aFT_Mapping.GetText() ) );
     561           0 :         String aColumn3( OutputDevice::GetNonMnemonicString( m_aFT_Property.GetText() ) );
     562             : 
     563           0 :         long nWidth1 = m_aED_Mapping.GetPosPixel().X() - m_aED_Term.GetPosPixel().X();
     564           0 :         long nWidth2 = m_aLB_Property.GetPosPixel().X() - m_aED_Mapping.GetPosPixel().X();
     565           0 :         long nWidth3 = m_aLB_Property.GetSizePixel().Width();
     566             : 
     567           0 :         m_pHeaderBar = m_aCT_DictionaryToSimplified.createHeaderBar( aColumn1, aColumn2, aColumn3, nWidth1, nWidth2, nWidth3 );
     568           0 :         if(m_pHeaderBar)
     569           0 :             m_pHeaderBar->SetHelpId( HID_SVX_CHINESE_DICTIONARY_LB_HEADER );
     570             : 
     571           0 :         long pTabs[] = { 3, 0, nWidth1, nWidth1 + nWidth2 };
     572           0 :         m_aCT_DictionaryToSimplified.SetTabs( &pTabs[0], MAP_PIXEL );
     573           0 :         m_aCT_DictionaryToTraditional.SetTabs( &pTabs[0], MAP_PIXEL );
     574             :     }
     575             : 
     576             :     //init dictionary controls
     577           0 :     m_aCT_DictionaryToTraditional.SetPosPixel( m_aCT_DictionaryToSimplified.GetPosPixel() );
     578           0 :     m_aCT_DictionaryToTraditional.SetSizePixel( m_aCT_DictionaryToSimplified.GetSizePixel() );
     579             : 
     580           0 :     m_aCT_DictionaryToSimplified.initDictionaryControl( xDictionary_To_Simplified, &m_aLB_Property );
     581           0 :     m_aCT_DictionaryToTraditional.initDictionaryControl( xDictionary_To_Traditional, &m_aLB_Property );
     582             : 
     583             :     //
     584           0 :     updateAfterDirectionChange();
     585             : 
     586             :     //set hdl
     587           0 :     if(m_pHeaderBar)
     588           0 :         m_pHeaderBar->SetSelectHdl( LINK( this, ChineseDictionaryDialog, HeaderBarClick ) );
     589             : 
     590           0 :     m_aED_Term.SetModifyHdl( LINK( this, ChineseDictionaryDialog, EditFieldsHdl ) );
     591           0 :     m_aED_Mapping.SetModifyHdl( LINK( this, ChineseDictionaryDialog, EditFieldsHdl ) );
     592           0 :     m_aLB_Property.SetSelectHdl( LINK( this, ChineseDictionaryDialog, EditFieldsHdl ) );
     593             : 
     594           0 :     m_aRB_To_Simplified.SetClickHdl( LINK( this, ChineseDictionaryDialog, DirectionHdl ) );
     595           0 :     m_aRB_To_Traditional.SetClickHdl( LINK( this, ChineseDictionaryDialog, DirectionHdl ) );
     596             : 
     597           0 :     m_aCT_DictionaryToSimplified.SetSelectHdl( LINK( this, ChineseDictionaryDialog, MappingSelectHdl ));
     598           0 :     m_aCT_DictionaryToTraditional.SetSelectHdl( LINK( this, ChineseDictionaryDialog, MappingSelectHdl ));
     599             : 
     600           0 :     m_aPB_Add.SetClickHdl( LINK( this, ChineseDictionaryDialog, AddHdl ) );
     601           0 :     m_aPB_Modify.SetClickHdl( LINK( this, ChineseDictionaryDialog, ModifyHdl ) );
     602           0 :     m_aPB_Delete.SetClickHdl( LINK( this, ChineseDictionaryDialog, DeleteHdl ) );
     603           0 : }
     604             : 
     605           0 : ChineseDictionaryDialog::~ChineseDictionaryDialog()
     606             : {
     607           0 :     m_xContext=0;
     608           0 :     m_xFactory=0;
     609           0 :     delete m_pHeaderBar;
     610           0 : }
     611             : 
     612           0 : void ChineseDictionaryDialog::setDirectionAndTextConversionOptions( bool bDirectionToSimplified, sal_Int32 nTextConversionOptions /*i18n::TextConversionOption*/ )
     613             : {
     614           0 :     if( bDirectionToSimplified == bool(m_aRB_To_Simplified.IsChecked())
     615             :         && nTextConversionOptions == m_nTextConversionOptions )
     616           0 :         return;
     617             : 
     618           0 :     m_nTextConversionOptions = nTextConversionOptions;
     619             : 
     620           0 :     if( bDirectionToSimplified )
     621           0 :         m_aRB_To_Simplified.Check();
     622             :     else
     623           0 :         m_aRB_To_Traditional.Check();
     624           0 :     updateAfterDirectionChange();
     625             : }
     626             : 
     627           0 : IMPL_LINK_NOARG(ChineseDictionaryDialog, DirectionHdl)
     628             : {
     629           0 :     updateAfterDirectionChange();
     630           0 :     return 0;
     631             : }
     632             : 
     633           0 : void ChineseDictionaryDialog::updateAfterDirectionChange()
     634             : {
     635           0 :     Reference< linguistic2::XConversionDictionary > xDictionary(0);
     636             : 
     637           0 :     if( m_aRB_To_Simplified.IsChecked() )
     638             :     {
     639           0 :         m_aCT_DictionaryToSimplified.activate( m_pHeaderBar );
     640           0 :         m_aCT_DictionaryToTraditional.Hide();
     641           0 :         xDictionary = m_aCT_DictionaryToSimplified.m_xDictionary;
     642             :     }
     643             :     else
     644             :     {
     645           0 :         m_aCT_DictionaryToTraditional.activate( m_pHeaderBar );
     646           0 :         m_aCT_DictionaryToSimplified.Hide();
     647           0 :         xDictionary = m_aCT_DictionaryToTraditional.m_xDictionary;
     648             :     }
     649             : 
     650           0 :     updateButtons();
     651           0 : }
     652             : 
     653           0 : IMPL_LINK_NOARG(ChineseDictionaryDialog, EditFieldsHdl)
     654             : {
     655           0 :     updateButtons();
     656           0 :     return 0;
     657             : }
     658           0 : IMPL_LINK_NOARG(ChineseDictionaryDialog, MappingSelectHdl)
     659             : {
     660           0 :     DictionaryEntry* pE = getActiveDictionary().getFirstSelectedEntry();
     661           0 :     if(pE)
     662             :     {
     663           0 :         m_aED_Term.SetText( pE->m_aTerm );
     664           0 :         m_aED_Mapping.SetText( pE->m_aMapping );
     665           0 :         sal_Int16 nPos = pE->m_nConversionPropertyType-1;
     666           0 :         if( nPos<0 || nPos>=m_aLB_Property.GetEntryCount() )
     667           0 :             nPos=0;
     668           0 :         if( m_aLB_Property.GetEntryCount() )
     669           0 :             m_aLB_Property.SelectEntryPos(nPos);
     670             :     }
     671             : 
     672           0 :     updateButtons();
     673           0 :     return 0;
     674             : }
     675             : 
     676           0 : bool ChineseDictionaryDialog::isEditFieldsHaveContent() const
     677             : {
     678           0 :     return m_aED_Term.GetText().Len() && m_aED_Mapping.GetText().Len();
     679             : }
     680             : 
     681           0 : bool ChineseDictionaryDialog::isEditFieldsContentEqualsSelectedListContent() const
     682             : {
     683           0 :     DictionaryEntry* pE = getActiveDictionary().getFirstSelectedEntry();
     684           0 :     if( pE )
     685             :     {
     686           0 :         if( pE->m_aTerm != rtl::OUString( m_aED_Term.GetText() ) )
     687           0 :             return false;
     688           0 :         if( pE->m_aMapping != rtl::OUString( m_aED_Mapping.GetText() ) )
     689           0 :             return false;
     690           0 :         if( pE->m_nConversionPropertyType != m_aLB_Property.GetSelectEntryPos()+1 )
     691           0 :             return false;
     692           0 :         return true;
     693             :     }
     694           0 :     return false;
     695             : }
     696             : 
     697           0 : const DictionaryList& ChineseDictionaryDialog::getActiveDictionary() const
     698             : {
     699           0 :     if( m_aRB_To_Traditional.IsChecked() )
     700           0 :         return m_aCT_DictionaryToTraditional;
     701           0 :     return m_aCT_DictionaryToSimplified;
     702             : }
     703             : 
     704           0 : DictionaryList& ChineseDictionaryDialog::getActiveDictionary()
     705             : {
     706           0 :     if( m_aRB_To_Traditional.IsChecked() )
     707           0 :         return m_aCT_DictionaryToTraditional;
     708           0 :     return m_aCT_DictionaryToSimplified;
     709             : }
     710             : 
     711           0 : const DictionaryList& ChineseDictionaryDialog::getReverseDictionary() const
     712             : {
     713           0 :     if( m_aRB_To_Traditional.IsChecked() )
     714           0 :         return m_aCT_DictionaryToSimplified;
     715           0 :     return m_aCT_DictionaryToTraditional;
     716             : }
     717             : 
     718           0 : DictionaryList& ChineseDictionaryDialog::getReverseDictionary()
     719             : {
     720           0 :     if( m_aRB_To_Traditional.IsChecked() )
     721           0 :         return m_aCT_DictionaryToSimplified;
     722           0 :     return m_aCT_DictionaryToTraditional;
     723             : }
     724             : 
     725           0 : void ChineseDictionaryDialog::updateButtons()
     726             : {
     727           0 :     bool bAdd = isEditFieldsHaveContent() && !getActiveDictionary().hasTerm( m_aED_Term.GetText() );
     728           0 :     m_aPB_Add.Enable( bAdd );
     729             : 
     730           0 :     m_aPB_Delete.Enable( !bAdd && getActiveDictionary().GetSelectedRowCount()>0 );
     731             : 
     732             : //    DictionaryEntry* pFirstSelectedEntry = getActiveDictionary().getFirstSelectedEntry();
     733             : 
     734           0 :     bool bModify = false;
     735             :     {
     736           0 :         DictionaryEntry* pFirstSelectedEntry = getActiveDictionary().getFirstSelectedEntry();
     737           0 :         bModify = !bAdd && getActiveDictionary().GetSelectedRowCount()==1
     738           0 :                         && pFirstSelectedEntry && pFirstSelectedEntry->m_aTerm.equals( m_aED_Term.GetText() );
     739           0 :         if( bModify && isEditFieldsContentEqualsSelectedListContent() )
     740           0 :             bModify = false;
     741             :     }
     742           0 :     m_aPB_Modify.Enable( bModify );
     743           0 : }
     744             : 
     745           0 : IMPL_LINK_NOARG(ChineseDictionaryDialog, AddHdl)
     746             : {
     747           0 :     if( !isEditFieldsHaveContent() )
     748           0 :         return 0;
     749             : 
     750           0 :     sal_Int16 nConversionPropertyType = m_aLB_Property.GetSelectEntryPos()+1;
     751             : 
     752           0 :     getActiveDictionary().addEntry( m_aED_Term.GetText(), m_aED_Mapping.GetText(), nConversionPropertyType );
     753             : 
     754           0 :     if( m_aCB_Reverse.IsChecked() )
     755             :     {
     756           0 :         getReverseDictionary().deleteEntries( m_aED_Mapping.GetText() );
     757           0 :         getReverseDictionary().addEntry( m_aED_Mapping.GetText(), m_aED_Term.GetText(), nConversionPropertyType );
     758             :     }
     759             : 
     760           0 :     updateButtons();
     761           0 :     return 0;
     762             : }
     763           0 : IMPL_LINK_NOARG(ChineseDictionaryDialog, ModifyHdl)
     764             : {
     765           0 :     rtl::OUString aTerm( m_aED_Term.GetText() );
     766           0 :     rtl::OUString aMapping( m_aED_Mapping.GetText() );
     767           0 :     sal_Int16 nConversionPropertyType = m_aLB_Property.GetSelectEntryPos()+1;
     768             : 
     769           0 :     DictionaryList& rActive  = getActiveDictionary();
     770           0 :     DictionaryList& rReverse = getReverseDictionary();
     771             : 
     772           0 :     DictionaryEntry* pE = rActive.getFirstSelectedEntry();
     773           0 :     if( pE->m_aTerm != aTerm )
     774           0 :         return 0;
     775             : 
     776           0 :     if( pE )
     777             :     {
     778           0 :         if( pE->m_aMapping != aMapping || pE->m_nConversionPropertyType != nConversionPropertyType )
     779             :         {
     780           0 :             if( m_aCB_Reverse.IsChecked() )
     781             :             {
     782           0 :                 sal_uIntPtr nPos = rReverse.deleteEntries( pE->m_aMapping );
     783           0 :                 nPos = rReverse.deleteEntries( aMapping );
     784           0 :                 rReverse.addEntry( aMapping, aTerm, nConversionPropertyType, nPos );
     785             :             }
     786             : 
     787           0 :             sal_uIntPtr nPos = rActive.deleteEntries( aTerm );
     788           0 :             rActive.addEntry( aTerm, aMapping, nConversionPropertyType, nPos );
     789             :         }
     790             :     }
     791             : 
     792           0 :     updateButtons();
     793           0 :     return 0;
     794             : }
     795             : 
     796           0 : IMPL_LINK_NOARG(ChineseDictionaryDialog, DeleteHdl)
     797             : {
     798           0 :     DictionaryList& rActive  = getActiveDictionary();
     799           0 :     DictionaryList& rReverse = getReverseDictionary();
     800             : 
     801           0 :     if( rActive.GetSelectedRowCount()>0)
     802             :     {
     803             :         DictionaryEntry* pEntry;
     804             : 
     805           0 :         rtl::OUString aMapping;
     806           0 :         for( sal_Int32 nN=rActive.GetRowCount(); nN--; )
     807             :         {
     808           0 :             if( rActive.IsRowSelected( nN ) )
     809             :             {
     810           0 :                 pEntry = rActive.getEntryOnPos( nN );
     811           0 :                 if(pEntry)
     812             :                 {
     813           0 :                     aMapping = pEntry->m_aMapping;
     814           0 :                     rActive.deleteEntryOnPos( nN );
     815           0 :                     if( m_aCB_Reverse.IsChecked() )
     816           0 :                         rReverse.deleteEntries( aMapping  );
     817             :                 }
     818           0 :                 break;
     819             :             }
     820           0 :         }
     821             :     }
     822             : 
     823           0 :     updateButtons();
     824           0 :     return 0;
     825             : }
     826             : 
     827           0 : short ChineseDictionaryDialog::Execute()
     828             : {
     829           0 :     sal_Int32 nTextConversionOptions = m_nTextConversionOptions;
     830             :     if(m_nTextConversionOptions | i18n::TextConversionOption::USE_CHARACTER_VARIANTS )
     831           0 :         nTextConversionOptions = nTextConversionOptions^i18n::TextConversionOption::USE_CHARACTER_VARIANTS ;
     832             : 
     833           0 :     m_aCT_DictionaryToSimplified.refillFromDictionary( nTextConversionOptions );
     834           0 :     m_aCT_DictionaryToTraditional.refillFromDictionary( m_nTextConversionOptions );
     835             : 
     836           0 :     short nRet = ModalDialog::Execute();
     837             : 
     838           0 :     if( nRet == RET_OK )
     839             :     {
     840             :         //save settings to configuration
     841           0 :         SvtLinguConfig  aLngCfg;
     842           0 :         Any aAny;
     843           0 :         aAny <<= sal_Bool( !!m_aCB_Reverse.IsChecked() );
     844           0 :         aLngCfg.SetProperty( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( UPN_IS_REVERSE_MAPPING )), aAny );
     845             : 
     846           0 :         m_aCT_DictionaryToSimplified.save();
     847           0 :         m_aCT_DictionaryToTraditional.save();
     848             :     }
     849             : 
     850           0 :     m_aCT_DictionaryToSimplified.deleteAll();
     851           0 :     m_aCT_DictionaryToTraditional.deleteAll();
     852             : 
     853           0 :     return nRet;
     854             : }
     855             : 
     856           0 : IMPL_LINK_NOARG(ChineseDictionaryDialog, HeaderBarClick)
     857             : {
     858           0 :     if(m_pHeaderBar)
     859             :     {
     860           0 :         sal_uInt16 nId = m_pHeaderBar->GetCurItemId();
     861           0 :         HeaderBarItemBits nBits = m_pHeaderBar->GetItemBits(nId);
     862           0 :         if( nBits & HIB_CLICKABLE )
     863             :         {
     864             :             //set new arrow positions in headerbar
     865           0 :             m_pHeaderBar->SetItemBits( getActiveDictionary().getSortColumn()+1, HEADER_BAR_BITS );
     866           0 :             if( nBits & HIB_UPARROW )
     867           0 :                 m_pHeaderBar->SetItemBits( nId, HEADER_BAR_BITS | HIB_DOWNARROW );
     868             :             else
     869           0 :                 m_pHeaderBar->SetItemBits( nId, HEADER_BAR_BITS | HIB_UPARROW );
     870             : 
     871             :             //sort lists
     872           0 :             nBits = m_pHeaderBar->GetItemBits(nId);
     873           0 :             bool bSortAtoZ = nBits & HIB_UPARROW;
     874           0 :             getActiveDictionary().sortByColumn(nId-1,bSortAtoZ);
     875           0 :             getReverseDictionary().sortByColumn(nId-1,bSortAtoZ);
     876             :         }
     877             :     }
     878           0 :     return 0;
     879             : }
     880             : 
     881             : //.............................................................................
     882             : } //end namespace
     883             : //.............................................................................
     884             : 
     885             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10