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