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