1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "precompiled_basctl.hxx" 29 #include <ide_pch.hxx> 30 31 #include <basidesh.hxx> 32 #include <baside3.hxx> 33 #include <basobj.hxx> 34 #include <iderdll.hxx> 35 #include "dlged.hxx" 36 37 #include <localizationmgr.hxx> 38 #include <com/sun/star/resource/XStringResourceSupplier.hpp> 39 #include <com/sun/star/frame/XLayoutManager.hpp> 40 41 using namespace ::com::sun::star; 42 using namespace ::com::sun::star::uno; 43 using namespace ::com::sun::star::lang; 44 using namespace ::com::sun::star::beans; 45 using namespace ::com::sun::star::resource; 46 47 static ::rtl::OUString aDot = ::rtl::OUString::createFromAscii( "." ); 48 static ::rtl::OUString aEsc = ::rtl::OUString::createFromAscii( "&" ); 49 static ::rtl::OUString aSemi = ::rtl::OUString::createFromAscii( ";" ); 50 51 52 LocalizationMgr::LocalizationMgr( BasicIDEShell* pIDEShell, 53 const ScriptDocument& rDocument, String aLibName, 54 const Reference< XStringResourceManager >& xStringResourceManager ) 55 : m_xStringResourceManager( xStringResourceManager ) 56 , m_pIDEShell( pIDEShell ) 57 , m_aDocument( rDocument ) 58 , m_aLibName( aLibName ) 59 { 60 } 61 62 bool LocalizationMgr::isLibraryLocalized( void ) 63 { 64 bool bRet = false; 65 if( m_xStringResourceManager.is() ) 66 { 67 Sequence< Locale > aLocaleSeq = m_xStringResourceManager->getLocales(); 68 bRet = ( aLocaleSeq.getLength() > 0 ); 69 } 70 return bRet; 71 } 72 73 void LocalizationMgr::handleTranslationbar( void ) 74 { 75 static ::rtl::OUString aLayoutManagerName = ::rtl::OUString::createFromAscii( "LayoutManager" ); 76 static ::rtl::OUString aToolBarResName = 77 ::rtl::OUString::createFromAscii( "private:resource/toolbar/translationbar" ); 78 79 Reference< beans::XPropertySet > xFrameProps 80 ( m_pIDEShell->GetViewFrame()->GetFrame().GetFrameInterface(), uno::UNO_QUERY ); 81 if ( xFrameProps.is() ) 82 { 83 Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager; 84 uno::Any a = xFrameProps->getPropertyValue( aLayoutManagerName ); 85 a >>= xLayoutManager; 86 if ( xLayoutManager.is() ) 87 { 88 if ( !isLibraryLocalized() ) 89 { 90 xLayoutManager->destroyElement( aToolBarResName ); 91 } 92 else 93 { 94 xLayoutManager->createElement( aToolBarResName ); 95 xLayoutManager->requestElement( aToolBarResName ); 96 } 97 } 98 } 99 } 100 101 102 //============================================ 103 // TODO: -> export from toolkit 104 105 struct LanguageDependentProp 106 { 107 const char* pPropName; 108 sal_Int32 nPropNameLength; 109 }; 110 111 static LanguageDependentProp aLanguageDependentProp[] = 112 { 113 { "Text", 4 }, 114 { "Label", 5 }, 115 { "Title", 5 }, 116 { "HelpText", 8 }, 117 { "CurrencySymbol", 14 }, 118 { "StringItemList", 14 }, 119 { 0, 0 } 120 }; 121 122 bool isLanguageDependentProperty( ::rtl::OUString aName ) 123 { 124 bool bRet = false; 125 126 LanguageDependentProp* pLangDepProp = aLanguageDependentProp; 127 while( pLangDepProp->pPropName != 0 ) 128 { 129 if( aName.equalsAsciiL( pLangDepProp->pPropName, pLangDepProp->nPropNameLength )) 130 { 131 bRet = true; 132 break; 133 } 134 pLangDepProp++; 135 } 136 return bRet; 137 } 138 //============================================ 139 140 void LocalizationMgr::implEnableDisableResourceForAllLibraryDialogs( HandleResourceMode eMode ) 141 { 142 Sequence< ::rtl::OUString > aDlgNames = m_aDocument.getObjectNames( E_DIALOGS, m_aLibName ); 143 sal_Int32 nDlgCount = aDlgNames.getLength(); 144 const ::rtl::OUString* pDlgNames = aDlgNames.getConstArray(); 145 146 Reference< XStringResourceResolver > xDummyStringResolver; 147 for( sal_Int32 i = 0 ; i < nDlgCount ; i++ ) 148 { 149 String aDlgName = pDlgNames[ i ]; 150 DialogWindow* pWin = m_pIDEShell->FindDlgWin( m_aDocument, m_aLibName, aDlgName, sal_False ); 151 if( pWin && pWin->IsA( TYPE( DialogWindow ) ) ) 152 { 153 DialogWindow* pDialogWin = static_cast< DialogWindow* >( pWin ); 154 Reference< container::XNameContainer > xDialog = pDialogWin->GetDialog(); 155 if( xDialog.is() ) 156 { 157 // Handle dialog itself as control 158 Any aDialogCtrl; 159 aDialogCtrl <<= xDialog; 160 implHandleControlResourceProperties( aDialogCtrl, aDlgName, 161 ::rtl::OUString(), m_xStringResourceManager, xDummyStringResolver, eMode ); 162 163 // Handle all controls 164 Sequence< ::rtl::OUString > aNames = xDialog->getElementNames(); 165 const ::rtl::OUString* pNames = aNames.getConstArray(); 166 sal_Int32 nCtrls = aNames.getLength(); 167 for( sal_Int32 j = 0 ; j < nCtrls ; ++j ) 168 { 169 ::rtl::OUString aCtrlName( pNames[j] ); 170 Any aCtrl = xDialog->getByName( aCtrlName ); 171 implHandleControlResourceProperties( aCtrl, aDlgName, 172 aCtrlName, m_xStringResourceManager, xDummyStringResolver, eMode ); 173 } 174 } 175 } 176 } 177 } 178 179 180 ::rtl::OUString implCreatePureResourceId 181 ( const ::rtl::OUString& aDialogName, const ::rtl::OUString& aCtrlName, 182 const ::rtl::OUString& aPropName, 183 Reference< XStringResourceManager > xStringResourceManager ) 184 { 185 sal_Int32 nUniqueId = xStringResourceManager->getUniqueNumericId(); 186 ::rtl::OUString aPureIdStr = ::rtl::OUString::valueOf( nUniqueId ); 187 aPureIdStr += aDot; 188 aPureIdStr += aDialogName; 189 aPureIdStr += aDot; 190 if( aCtrlName.getLength() ) 191 { 192 aPureIdStr += aCtrlName; 193 aPureIdStr += aDot; 194 } 195 aPureIdStr += aPropName; 196 return aPureIdStr; 197 } 198 199 extern bool localesAreEqual( const ::com::sun::star::lang::Locale& rLocaleLeft, 200 const ::com::sun::star::lang::Locale& rLocaleRight ); 201 202 // Works on xStringResourceManager's current language for SET_IDS/RESET_IDS, 203 // anyway only one language should exist when calling this method then, 204 // either the first one for mode SET_IDS or the last one for mode RESET_IDS 205 sal_Int32 LocalizationMgr::implHandleControlResourceProperties 206 ( Any aControlAny, const ::rtl::OUString& aDialogName, const ::rtl::OUString& aCtrlName, 207 Reference< XStringResourceManager > xStringResourceManager, 208 Reference< XStringResourceResolver > xSourceStringResolver, HandleResourceMode eMode ) 209 { 210 sal_Int32 nChangedCount = 0; 211 212 Reference< XPropertySet > xPropertySet; 213 aControlAny >>= xPropertySet; 214 if( xPropertySet.is() ) 215 { 216 Sequence< Locale > aLocaleSeq = xStringResourceManager->getLocales(); 217 sal_Int32 nLocaleCount = aLocaleSeq.getLength(); 218 if( nLocaleCount == 0 ) 219 return 0; 220 221 Reference< XPropertySetInfo > xPropertySetInfo = xPropertySet->getPropertySetInfo(); 222 if( xPropertySetInfo.is() ) 223 { 224 // get sequence of control properties 225 Sequence< Property > aPropSeq = xPropertySetInfo->getProperties(); 226 const Property* pProps = aPropSeq.getConstArray(); 227 sal_Int32 nCtrlProps = aPropSeq.getLength(); 228 229 // create a map of tab indices and control names, sorted by tab index 230 for( sal_Int32 j = 0 ; j < nCtrlProps ; ++j ) 231 { 232 const Property& rProp = pProps[j]; 233 ::rtl::OUString aPropName = rProp.Name; 234 TypeClass eType = rProp.Type.getTypeClass(); 235 bool bLanguageDependentProperty = 236 (eType == TypeClass_STRING || eType == TypeClass_SEQUENCE) 237 && isLanguageDependentProperty( aPropName ); 238 if( !bLanguageDependentProperty ) 239 continue; 240 241 if( eType == TypeClass_STRING ) 242 { 243 Any aPropAny = xPropertySet->getPropertyValue( aPropName ); 244 ::rtl::OUString aPropStr; 245 aPropAny >>= aPropStr; 246 247 // Replace string by id, add id+string to StringResource 248 if( eMode == SET_IDS ) 249 { 250 bool bEscAlreadyExisting = (aPropStr.getLength() && aPropStr.getStr()[0] == '&' ); 251 if( bEscAlreadyExisting ) 252 continue; 253 254 ::rtl::OUString aPureIdStr = implCreatePureResourceId 255 ( aDialogName, aCtrlName, aPropName, xStringResourceManager ); 256 257 // Set Id for all locales 258 const Locale* pLocales = aLocaleSeq.getConstArray(); 259 for( sal_Int32 i = 0 ; i < nLocaleCount ; i++ ) 260 { 261 const Locale& rLocale = pLocales[ i ]; 262 xStringResourceManager->setStringForLocale( aPureIdStr, aPropStr, rLocale ); 263 } 264 265 ::rtl::OUString aPropIdStr = aEsc; 266 aPropIdStr += aPureIdStr; 267 // TODO?: Change here and in toolkit 268 //aPropIdStr += aSemi; 269 (void)aSemi; 270 aPropAny <<= aPropIdStr; 271 xPropertySet->setPropertyValue( aPropName, aPropAny ); 272 } 273 // Replace id by string from StringResource 274 else if( eMode == RESET_IDS ) 275 { 276 if( aPropStr.getLength() > 1 ) 277 { 278 ::rtl::OUString aPureIdStr = aPropStr.copy( 1 ); 279 ::rtl::OUString aNewPropStr = aPropStr; 280 try 281 { 282 aNewPropStr = xStringResourceManager->resolveString( aPureIdStr ); 283 } 284 catch(MissingResourceException&) 285 { 286 } 287 aPropAny <<= aNewPropStr; 288 xPropertySet->setPropertyValue( aPropName, aPropAny ); 289 } 290 } 291 // Remove Id for all locales 292 else if( eMode == REMOVE_IDS_FROM_RESOURCE ) 293 { 294 if( aPropStr.getLength() > 1 ) 295 { 296 ::rtl::OUString aPureIdStr = aPropStr.copy( 1 ); 297 298 const Locale* pLocales = aLocaleSeq.getConstArray(); 299 for( sal_Int32 i = 0 ; i < nLocaleCount ; i++ ) 300 { 301 const Locale& rLocale = pLocales[ i ]; 302 try 303 { 304 xStringResourceManager->removeIdForLocale( aPureIdStr, rLocale ); 305 } 306 catch(MissingResourceException&) 307 { 308 } 309 } 310 } 311 } 312 // Rename resource id 313 else if( eMode == RENAME_DIALOG_IDS || eMode == RENAME_CONTROL_IDS ) 314 { 315 ::rtl::OUString aSourceIdStr = aPropStr; 316 ::rtl::OUString aPureSourceIdStr = aSourceIdStr.copy( 1 ); 317 318 ::rtl::OUString aPureIdStr = implCreatePureResourceId 319 ( aDialogName, aCtrlName, aPropName, xStringResourceManager ); 320 321 // Set new Id and remove old one for all locales 322 const Locale* pLocales = aLocaleSeq.getConstArray(); 323 for( sal_Int32 i = 0 ; i < nLocaleCount ; i++ ) 324 { 325 const Locale& rLocale = pLocales[ i ]; 326 ::rtl::OUString aResStr; 327 try 328 { 329 aResStr = xStringResourceManager->resolveStringForLocale 330 ( aPureSourceIdStr, rLocale ); 331 xStringResourceManager->removeIdForLocale( aPureSourceIdStr, rLocale ); 332 xStringResourceManager->setStringForLocale( aPureIdStr, aResStr, rLocale ); 333 } 334 catch(MissingResourceException&) 335 {} 336 } 337 338 ::rtl::OUString aPropIdStr = aEsc; 339 aPropIdStr += aPureIdStr; 340 // TODO?: Change here and in toolkit 341 //aPropIdStr += aSemi; 342 (void)aSemi; 343 aPropAny <<= aPropIdStr; 344 xPropertySet->setPropertyValue( aPropName, aPropAny ); 345 } 346 // Replace string by string from source StringResourceResolver 347 else if( eMode == MOVE_RESOURCES && xSourceStringResolver.is() ) 348 { 349 ::rtl::OUString aSourceIdStr = aPropStr; 350 ::rtl::OUString aPureSourceIdStr = aSourceIdStr.copy( 1 ); 351 352 ::rtl::OUString aPureIdStr = implCreatePureResourceId 353 ( aDialogName, aCtrlName, aPropName, xStringResourceManager ); 354 355 const Locale& rDefaultLocale = xSourceStringResolver->getDefaultLocale(); 356 357 // Set Id for all locales 358 const Locale* pLocales = aLocaleSeq.getConstArray(); 359 for( sal_Int32 i = 0 ; i < nLocaleCount ; i++ ) 360 { 361 const Locale& rLocale = pLocales[ i ]; 362 ::rtl::OUString aResStr; 363 try 364 { 365 aResStr = xSourceStringResolver->resolveStringForLocale 366 ( aPureSourceIdStr, rLocale ); 367 } 368 catch(MissingResourceException&) 369 { 370 aResStr = xSourceStringResolver->resolveStringForLocale 371 ( aPureSourceIdStr, rDefaultLocale ); 372 } 373 xStringResourceManager->setStringForLocale( aPureIdStr, aResStr, rLocale ); 374 } 375 376 ::rtl::OUString aPropIdStr = aEsc; 377 aPropIdStr += aPureIdStr; 378 // TODO?: Change here and in toolkit 379 //aPropIdStr += aSemi; 380 (void)aSemi; 381 aPropAny <<= aPropIdStr; 382 xPropertySet->setPropertyValue( aPropName, aPropAny ); 383 } 384 // Copy string from source to target resource 385 else if( eMode == COPY_RESOURCES && xSourceStringResolver.is() ) 386 { 387 ::rtl::OUString aSourceIdStr = aPropStr; 388 ::rtl::OUString aPureSourceIdStr = aSourceIdStr.copy( 1 ); 389 390 const Locale& rDefaultLocale = xSourceStringResolver->getDefaultLocale(); 391 392 // Copy Id for all locales 393 const Locale* pLocales = aLocaleSeq.getConstArray(); 394 for( sal_Int32 i = 0 ; i < nLocaleCount ; i++ ) 395 { 396 const Locale& rLocale = pLocales[ i ]; 397 ::rtl::OUString aResStr; 398 try 399 { 400 aResStr = xSourceStringResolver->resolveStringForLocale 401 ( aPureSourceIdStr, rLocale ); 402 } 403 catch(MissingResourceException&) 404 { 405 aResStr = xSourceStringResolver->resolveStringForLocale 406 ( aPureSourceIdStr, rDefaultLocale ); 407 } 408 xStringResourceManager->setStringForLocale( aPureSourceIdStr, aResStr, rLocale ); 409 } 410 } 411 nChangedCount++; 412 } 413 414 // Listbox / Combobox 415 else if( eType == TypeClass_SEQUENCE ) 416 { 417 Any aPropAny = xPropertySet->getPropertyValue( aPropName ); 418 Sequence< ::rtl::OUString > aPropStrings; 419 aPropAny >>= aPropStrings; 420 421 const ::rtl::OUString* pPropStrings = aPropStrings.getConstArray(); 422 sal_Int32 nPropStringCount = aPropStrings.getLength(); 423 if( nPropStringCount == 0 ) 424 continue; 425 426 // Replace string by id, add id+string to StringResource 427 if( eMode == SET_IDS ) 428 { 429 Sequence< ::rtl::OUString > aIdStrings; 430 aIdStrings.realloc( nPropStringCount ); 431 ::rtl::OUString* pIdStrings = aIdStrings.getArray(); 432 433 ::rtl::OUString aIdStrBase = aDot; 434 aIdStrBase += aCtrlName; 435 aIdStrBase += aDot; 436 aIdStrBase += aPropName; 437 438 const Locale* pLocales = aLocaleSeq.getConstArray(); 439 sal_Int32 i; 440 for ( i = 0; i < nPropStringCount; ++i ) 441 { 442 ::rtl::OUString aPropStr = pPropStrings[i]; 443 bool bEscAlreadyExisting = (aPropStr.getLength() && aPropStr.getStr()[0] == '&' ); 444 if( bEscAlreadyExisting ) 445 { 446 pIdStrings[i] = aPropStr; 447 continue; 448 } 449 450 sal_Int32 nUniqueId = xStringResourceManager->getUniqueNumericId(); 451 ::rtl::OUString aPureIdStr = ::rtl::OUString::valueOf( nUniqueId ); 452 aPureIdStr += aIdStrBase; 453 454 // Set Id for all locales 455 for( sal_Int32 iLocale = 0 ; iLocale < nLocaleCount ; iLocale++ ) 456 { 457 const Locale& rLocale = pLocales[ iLocale ]; 458 xStringResourceManager->setStringForLocale( aPureIdStr, aPropStr, rLocale ); 459 } 460 461 ::rtl::OUString aPropIdStr = aEsc; 462 aPropIdStr += aPureIdStr; 463 pIdStrings[i] = aPropIdStr; 464 } 465 aPropAny <<= aIdStrings; 466 xPropertySet->setPropertyValue( aPropName, aPropAny ); 467 } 468 // Replace id by string from StringResource 469 else if( eMode == RESET_IDS ) 470 { 471 Sequence< ::rtl::OUString > aNewPropStrings; 472 aNewPropStrings.realloc( nPropStringCount ); 473 ::rtl::OUString* pNewPropStrings = aNewPropStrings.getArray(); 474 475 sal_Int32 i; 476 for ( i = 0; i < nPropStringCount; ++i ) 477 { 478 ::rtl::OUString aIdStr = pPropStrings[i]; 479 ::rtl::OUString aNewPropStr = aIdStr; 480 if( aIdStr.getLength() > 1 ) 481 { 482 ::rtl::OUString aPureIdStr = aIdStr.copy( 1 ); 483 try 484 { 485 aNewPropStr = xStringResourceManager->resolveString( aPureIdStr ); 486 } 487 catch(MissingResourceException&) 488 { 489 } 490 } 491 pNewPropStrings[i] = aNewPropStr; 492 } 493 aPropAny <<= aNewPropStrings; 494 xPropertySet->setPropertyValue( aPropName, aPropAny ); 495 } 496 // Remove Id for all locales 497 else if( eMode == REMOVE_IDS_FROM_RESOURCE ) 498 { 499 Sequence< ::rtl::OUString > aNewPropStrings; 500 aNewPropStrings.realloc( nPropStringCount ); 501 502 const Locale* pLocales = aLocaleSeq.getConstArray(); 503 sal_Int32 i; 504 for ( i = 0; i < nPropStringCount; ++i ) 505 { 506 ::rtl::OUString aIdStr = pPropStrings[i]; 507 if( aIdStr.getLength() > 1 ) 508 { 509 ::rtl::OUString aPureIdStr = aIdStr.copy( 1 ); 510 511 for( sal_Int32 iLocale = 0 ; iLocale < nLocaleCount ; iLocale++ ) 512 { 513 const Locale& rLocale = pLocales[iLocale]; 514 try 515 { 516 xStringResourceManager->removeIdForLocale( aPureIdStr, rLocale ); 517 } 518 catch(MissingResourceException&) 519 { 520 } 521 } 522 } 523 } 524 } 525 // Rename resource id 526 else if( eMode == RENAME_CONTROL_IDS ) 527 { 528 Sequence< ::rtl::OUString > aIdStrings; 529 aIdStrings.realloc( nPropStringCount ); 530 ::rtl::OUString* pIdStrings = aIdStrings.getArray(); 531 532 ::rtl::OUString aIdStrBase = aDot; 533 aIdStrBase += aCtrlName; 534 aIdStrBase += aDot; 535 aIdStrBase += aPropName; 536 537 const Locale* pLocales = aLocaleSeq.getConstArray(); 538 sal_Int32 i; 539 for ( i = 0; i < nPropStringCount; ++i ) 540 { 541 ::rtl::OUString aSourceIdStr = pPropStrings[i]; 542 ::rtl::OUString aPureSourceIdStr = aSourceIdStr.copy( 1 ); 543 544 sal_Int32 nUniqueId = xStringResourceManager->getUniqueNumericId(); 545 ::rtl::OUString aPureIdStr = ::rtl::OUString::valueOf( nUniqueId ); 546 aPureIdStr += aIdStrBase; 547 548 // Set Id for all locales 549 for( sal_Int32 iLocale = 0 ; iLocale < nLocaleCount ; iLocale++ ) 550 { 551 const Locale& rLocale = pLocales[ iLocale ]; 552 553 ::rtl::OUString aResStr; 554 try 555 { 556 aResStr = xStringResourceManager->resolveStringForLocale 557 ( aPureSourceIdStr, rLocale ); 558 xStringResourceManager->removeIdForLocale( aPureSourceIdStr, rLocale ); 559 xStringResourceManager->setStringForLocale( aPureIdStr, aResStr, rLocale ); 560 } 561 catch(MissingResourceException&) 562 {} 563 } 564 565 ::rtl::OUString aPropIdStr = aEsc; 566 aPropIdStr += aPureIdStr; 567 pIdStrings[i] = aPropIdStr; 568 } 569 aPropAny <<= aIdStrings; 570 xPropertySet->setPropertyValue( aPropName, aPropAny ); 571 } 572 // Replace string by string from source StringResourceResolver 573 else if( eMode == MOVE_RESOURCES && xSourceStringResolver.is() ) 574 { 575 Sequence< ::rtl::OUString > aIdStrings; 576 aIdStrings.realloc( nPropStringCount ); 577 ::rtl::OUString* pIdStrings = aIdStrings.getArray(); 578 579 ::rtl::OUString aIdStrBase = aDot; 580 aIdStrBase += aCtrlName; 581 aIdStrBase += aDot; 582 aIdStrBase += aPropName; 583 584 const Locale& rDefaultLocale = xSourceStringResolver->getDefaultLocale(); 585 586 const Locale* pLocales = aLocaleSeq.getConstArray(); 587 sal_Int32 i; 588 for ( i = 0; i < nPropStringCount; ++i ) 589 { 590 ::rtl::OUString aSourceIdStr = pPropStrings[i]; 591 ::rtl::OUString aPureSourceIdStr = aSourceIdStr.copy( 1 ); 592 593 sal_Int32 nUniqueId = xStringResourceManager->getUniqueNumericId(); 594 ::rtl::OUString aPureIdStr = ::rtl::OUString::valueOf( nUniqueId ); 595 aPureIdStr += aIdStrBase; 596 597 // Set Id for all locales 598 for( sal_Int32 iLocale = 0 ; iLocale < nLocaleCount ; iLocale++ ) 599 { 600 const Locale& rLocale = pLocales[ iLocale ]; 601 602 ::rtl::OUString aResStr; 603 try 604 { 605 aResStr = xSourceStringResolver->resolveStringForLocale 606 ( aPureSourceIdStr, rLocale ); 607 } 608 catch(MissingResourceException&) 609 { 610 aResStr = xSourceStringResolver->resolveStringForLocale 611 ( aPureSourceIdStr, rDefaultLocale ); 612 } 613 xStringResourceManager->setStringForLocale( aPureIdStr, aResStr, rLocale ); 614 } 615 616 ::rtl::OUString aPropIdStr = aEsc; 617 aPropIdStr += aPureIdStr; 618 pIdStrings[i] = aPropIdStr; 619 } 620 aPropAny <<= aIdStrings; 621 xPropertySet->setPropertyValue( aPropName, aPropAny ); 622 } 623 // Copy string from source to target resource 624 else if( eMode == COPY_RESOURCES && xSourceStringResolver.is() ) 625 { 626 const Locale& rDefaultLocale = xSourceStringResolver->getDefaultLocale(); 627 628 const Locale* pLocales = aLocaleSeq.getConstArray(); 629 sal_Int32 i; 630 for ( i = 0; i < nPropStringCount; ++i ) 631 { 632 ::rtl::OUString aSourceIdStr = pPropStrings[i]; 633 ::rtl::OUString aPureSourceIdStr = aSourceIdStr.copy( 1 ); 634 635 // Set Id for all locales 636 for( sal_Int32 iLocale = 0 ; iLocale < nLocaleCount ; iLocale++ ) 637 { 638 const Locale& rLocale = pLocales[ iLocale ]; 639 640 ::rtl::OUString aResStr; 641 try 642 { 643 aResStr = xSourceStringResolver->resolveStringForLocale 644 ( aPureSourceIdStr, rLocale ); 645 } 646 catch(MissingResourceException&) 647 { 648 aResStr = xSourceStringResolver->resolveStringForLocale 649 ( aPureSourceIdStr, rDefaultLocale ); 650 } 651 xStringResourceManager->setStringForLocale( aPureSourceIdStr, aResStr, rLocale ); 652 } 653 } 654 } 655 nChangedCount++; 656 } 657 } 658 } 659 } 660 return nChangedCount; 661 } 662 663 /* 664 void TEST_simulateDialogAddRemoveLocale( bool bAdd ) 665 { 666 Sequence< Locale > aLocaleSeq( 1 ); 667 Locale* pLocales = aLocaleSeq.getArray(); 668 669 ::com::sun::star::lang::Locale aLocale_en; 670 aLocale_en.Language = ::rtl::OUString::createFromAscii( "en" ); 671 aLocale_en.Country = ::rtl::OUString::createFromAscii( "US" ); 672 673 ::com::sun::star::lang::Locale aLocale_de; 674 aLocale_de.Language = ::rtl::OUString::createFromAscii( "de" ); 675 aLocale_de.Country = ::rtl::OUString::createFromAscii( "DE" ); 676 677 ::com::sun::star::lang::Locale aLocale_fr; 678 aLocale_fr.Language = ::rtl::OUString::createFromAscii( "fr" ); 679 aLocale_fr.Country = ::rtl::OUString::createFromAscii( "FR" ); 680 681 int n = 0; 682 if( n == 0 ) 683 pLocales[0] = aLocale_en; 684 else if( n == 1 ) 685 pLocales[0] = aLocale_de; 686 else if( n == 2 ) 687 pLocales[0] = aLocale_fr; 688 689 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 690 LocalizationMgr* pMgr = pIDEShell->GetCurLocalizationMgr(); 691 if( bAdd ) 692 pMgr->handleAddLocales( aLocaleSeq ); 693 else 694 pMgr->handleRemoveLocales( aLocaleSeq ); 695 } 696 697 void TEST_simulateDialogAddLocale( void ) 698 { 699 TEST_simulateDialogAddRemoveLocale( true ); 700 } 701 702 void TEST_simulateDialogRemoveLocale( void ) 703 { 704 TEST_simulateDialogAddRemoveLocale( false ); 705 } 706 */ 707 708 void LocalizationMgr::handleAddLocales( Sequence< Locale > aLocaleSeq ) 709 { 710 const Locale* pLocales = aLocaleSeq.getConstArray(); 711 sal_Int32 nLocaleCount = aLocaleSeq.getLength(); 712 713 if( isLibraryLocalized() ) 714 { 715 for( sal_Int32 i = 0 ; i < nLocaleCount ; i++ ) 716 { 717 const Locale& rLocale = pLocales[ i ]; 718 m_xStringResourceManager->newLocale( rLocale ); 719 } 720 } 721 else 722 { 723 DBG_ASSERT( nLocaleCount==1, "LocalizationMgr::handleAddLocales(): Only one first locale allowed" ); 724 725 const Locale& rLocale = pLocales[ 0 ]; 726 m_xStringResourceManager->newLocale( rLocale ); 727 enableResourceForAllLibraryDialogs(); 728 } 729 730 BasicIDE::MarkDocumentModified( m_aDocument ); 731 732 // update locale toolbar 733 SfxBindings* pBindings = BasicIDE::GetBindingsPtr(); 734 if ( pBindings ) 735 pBindings->Invalidate( SID_BASICIDE_CURRENT_LANG ); 736 737 handleTranslationbar(); 738 } 739 740 741 void LocalizationMgr::handleRemoveLocales( Sequence< Locale > aLocaleSeq ) 742 { 743 const Locale* pLocales = aLocaleSeq.getConstArray(); 744 sal_Int32 nLocaleCount = aLocaleSeq.getLength(); 745 bool bConsistant = true; 746 bool bModified = false; 747 748 for( sal_Int32 i = 0 ; i < nLocaleCount ; i++ ) 749 { 750 const Locale& rLocale = pLocales[ i ]; 751 bool bRemove = true; 752 753 // Check if last locale 754 Sequence< Locale > aResLocaleSeq = m_xStringResourceManager->getLocales(); 755 if( aResLocaleSeq.getLength() == 1 ) 756 { 757 const Locale& rLastResLocale = aResLocaleSeq.getConstArray()[ 0 ]; 758 if( localesAreEqual( rLocale, rLastResLocale ) ) 759 { 760 disableResourceForAllLibraryDialogs(); 761 } 762 else 763 { 764 // Inconsistancy, keep last locale 765 bConsistant = false; 766 bRemove = false; 767 } 768 } 769 770 if( bRemove ) 771 { 772 try 773 { 774 m_xStringResourceManager->removeLocale( rLocale ); 775 bModified = true; 776 } 777 catch(IllegalArgumentException&) 778 { 779 bConsistant = false; 780 } 781 } 782 } 783 if( bModified ) 784 { 785 BasicIDE::MarkDocumentModified( m_aDocument ); 786 787 // update slots 788 SfxBindings* pBindings = BasicIDE::GetBindingsPtr(); 789 if ( pBindings ) 790 { 791 pBindings->Invalidate( SID_BASICIDE_CURRENT_LANG ); 792 pBindings->Invalidate( SID_BASICIDE_MANAGE_LANG ); 793 } 794 795 handleTranslationbar(); 796 } 797 798 DBG_ASSERT( bConsistant, 799 "LocalizationMgr::handleRemoveLocales(): sequence contains unsupported locales" ); 800 } 801 802 void LocalizationMgr::handleSetDefaultLocale( Locale aLocale ) 803 { 804 if( m_xStringResourceManager.is() ) 805 { 806 try 807 { 808 m_xStringResourceManager->setDefaultLocale( aLocale ); 809 } 810 catch(IllegalArgumentException&) 811 { 812 DBG_ERROR( "LocalizationMgr::handleSetDefaultLocale: Invalid locale" ); 813 } 814 815 // update locale toolbar 816 SfxBindings* pBindings = BasicIDE::GetBindingsPtr(); 817 if ( pBindings ) 818 pBindings->Invalidate( SID_BASICIDE_CURRENT_LANG ); 819 } 820 } 821 822 void LocalizationMgr::handleSetCurrentLocale( ::com::sun::star::lang::Locale aLocale ) 823 { 824 if( m_xStringResourceManager.is() ) 825 { 826 try 827 { 828 m_xStringResourceManager->setCurrentLocale( aLocale, false ); 829 } 830 catch(IllegalArgumentException&) 831 { 832 DBG_ERROR( "LocalizationMgr::handleSetCurrentLocale: Invalid locale" ); 833 } 834 835 // update locale toolbar 836 SfxBindings* pBindings = BasicIDE::GetBindingsPtr(); 837 if ( pBindings ) 838 pBindings->Invalidate( SID_BASICIDE_CURRENT_LANG ); 839 840 IDEBaseWindow* pCurWin = m_pIDEShell->GetCurWindow(); 841 if ( pCurWin && !pCurWin->IsSuspended() && pCurWin->IsA( TYPE( DialogWindow ) ) ) 842 { 843 DialogWindow* pDlgWin = (DialogWindow*)pCurWin; 844 DlgEditor* pWinEditor = pDlgWin->GetEditor(); 845 if( pWinEditor ) 846 pWinEditor->UpdatePropertyBrowserDelayed(); 847 } 848 } 849 } 850 851 void LocalizationMgr::handleBasicStarted( void ) 852 { 853 if( m_xStringResourceManager.is() ) 854 m_aLocaleBeforeBasicStart = m_xStringResourceManager->getCurrentLocale(); 855 } 856 857 void LocalizationMgr::handleBasicStopped( void ) 858 { 859 try 860 { 861 if( m_xStringResourceManager.is() ) 862 m_xStringResourceManager->setCurrentLocale( m_aLocaleBeforeBasicStart, true ); 863 } 864 catch(IllegalArgumentException&) 865 { 866 } 867 } 868 869 870 DialogWindow* FindDialogWindowForEditor( DlgEditor* pEditor ) 871 { 872 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 873 IDEWindowTable& aIDEWindowTable = pIDEShell->GetIDEWindowTable(); 874 IDEBaseWindow* pWin = aIDEWindowTable.First(); 875 DialogWindow* pFoundDlgWin = NULL; 876 while( pWin ) 877 { 878 if ( !pWin->IsSuspended() && pWin->IsA( TYPE( DialogWindow ) ) ) 879 { 880 DialogWindow* pDlgWin = (DialogWindow*)pWin; 881 DlgEditor* pWinEditor = pDlgWin->GetEditor(); 882 if( pWinEditor == pEditor ) 883 { 884 pFoundDlgWin = pDlgWin; 885 break; 886 } 887 } 888 pWin = aIDEWindowTable.Next(); 889 } 890 return pFoundDlgWin; 891 } 892 893 894 void LocalizationMgr::setControlResourceIDsForNewEditorObject( DlgEditor* pEditor, 895 Any aControlAny, const ::rtl::OUString& aCtrlName ) 896 { 897 // Get library for DlgEditor 898 DialogWindow* pDlgWin = FindDialogWindowForEditor( pEditor ); 899 if( !pDlgWin ) 900 return; 901 ScriptDocument aDocument( pDlgWin->GetDocument() ); 902 DBG_ASSERT( aDocument.isValid(), "LocalizationMgr::setControlResourceIDsForNewEditorObject: invalid document!" ); 903 if ( !aDocument.isValid() ) 904 return; 905 const String& rLibName = pDlgWin->GetLibName(); 906 Reference< container::XNameContainer > xDialogLib( aDocument.getLibrary( E_DIALOGS, rLibName, sal_True ) ); 907 Reference< XStringResourceManager > xStringResourceManager = 908 LocalizationMgr::getStringResourceFromDialogLibrary( xDialogLib ); 909 910 // Set resource property 911 if( !xStringResourceManager.is() || xStringResourceManager->getLocales().getLength() == 0 ) 912 return; 913 914 ::rtl::OUString aDialogName = pDlgWin->GetName(); 915 Reference< XStringResourceResolver > xDummyStringResolver; 916 sal_Int32 nChangedCount = implHandleControlResourceProperties 917 ( aControlAny, aDialogName, aCtrlName, xStringResourceManager, 918 xDummyStringResolver, SET_IDS ); 919 920 if( nChangedCount ) 921 BasicIDE::MarkDocumentModified( aDocument ); 922 } 923 924 void LocalizationMgr::renameControlResourceIDsForEditorObject( DlgEditor* pEditor, 925 ::com::sun::star::uno::Any aControlAny, const ::rtl::OUString& aNewCtrlName ) 926 { 927 // Get library for DlgEditor 928 DialogWindow* pDlgWin = FindDialogWindowForEditor( pEditor ); 929 if( !pDlgWin ) 930 return; 931 ScriptDocument aDocument( pDlgWin->GetDocument() ); 932 DBG_ASSERT( aDocument.isValid(), "LocalizationMgr::renameControlResourceIDsForEditorObject: invalid document!" ); 933 if ( !aDocument.isValid() ) 934 return; 935 const String& rLibName = pDlgWin->GetLibName(); 936 Reference< container::XNameContainer > xDialogLib( aDocument.getLibrary( E_DIALOGS, rLibName, sal_True ) ); 937 Reference< XStringResourceManager > xStringResourceManager = 938 LocalizationMgr::getStringResourceFromDialogLibrary( xDialogLib ); 939 940 // Set resource property 941 if( !xStringResourceManager.is() || xStringResourceManager->getLocales().getLength() == 0 ) 942 return; 943 944 ::rtl::OUString aDialogName = pDlgWin->GetName(); 945 Reference< XStringResourceResolver > xDummyStringResolver; 946 implHandleControlResourceProperties 947 ( aControlAny, aDialogName, aNewCtrlName, xStringResourceManager, 948 xDummyStringResolver, RENAME_CONTROL_IDS ); 949 } 950 951 952 void LocalizationMgr::deleteControlResourceIDsForDeletedEditorObject( DlgEditor* pEditor, 953 Any aControlAny, const ::rtl::OUString& aCtrlName ) 954 { 955 // Get library for DlgEditor 956 DialogWindow* pDlgWin = FindDialogWindowForEditor( pEditor ); 957 if( !pDlgWin ) 958 return; 959 ScriptDocument aDocument( pDlgWin->GetDocument() ); 960 DBG_ASSERT( aDocument.isValid(), "LocalizationMgr::deleteControlResourceIDsForDeletedEditorObject: invalid document!" ); 961 if ( !aDocument.isValid() ) 962 return; 963 const String& rLibName = pDlgWin->GetLibName(); 964 Reference< container::XNameContainer > xDialogLib( aDocument.getLibrary( E_DIALOGS, rLibName, sal_True ) ); 965 Reference< XStringResourceManager > xStringResourceManager = 966 LocalizationMgr::getStringResourceFromDialogLibrary( xDialogLib ); 967 968 ::rtl::OUString aDialogName = pDlgWin->GetName(); 969 Reference< XStringResourceResolver > xDummyStringResolver; 970 sal_Int32 nChangedCount = implHandleControlResourceProperties 971 ( aControlAny, aDialogName, aCtrlName, xStringResourceManager, 972 xDummyStringResolver, REMOVE_IDS_FROM_RESOURCE ); 973 974 if( nChangedCount ) 975 BasicIDE::MarkDocumentModified( aDocument ); 976 } 977 978 void LocalizationMgr::setStringResourceAtDialog( const ScriptDocument& rDocument, const String& aLibName, 979 const String& aDlgName, Reference< container::XNameContainer > xDialogModel ) 980 { 981 static ::rtl::OUString aResourceResolverPropName = ::rtl::OUString::createFromAscii( "ResourceResolver" ); 982 983 // Get library 984 Reference< container::XNameContainer > xDialogLib( rDocument.getLibrary( E_DIALOGS, aLibName, sal_True ) ); 985 Reference< XStringResourceManager > xStringResourceManager = 986 LocalizationMgr::getStringResourceFromDialogLibrary( xDialogLib ); 987 988 // Set resource property 989 if( xStringResourceManager.is() ) 990 { 991 // Not very elegant as dialog may or may not be localized yet 992 // TODO: Find better place, where dialog is created 993 if( xStringResourceManager->getLocales().getLength() > 0 ) 994 { 995 Any aDialogCtrl; 996 aDialogCtrl <<= xDialogModel; 997 Reference< XStringResourceResolver > xDummyStringResolver; 998 implHandleControlResourceProperties( aDialogCtrl, aDlgName, 999 ::rtl::OUString(), xStringResourceManager, 1000 xDummyStringResolver, SET_IDS ); 1001 } 1002 1003 Reference< beans::XPropertySet > xDlgPSet( xDialogModel, UNO_QUERY ); 1004 Any aStringResourceManagerAny; 1005 aStringResourceManagerAny <<= xStringResourceManager; 1006 xDlgPSet->setPropertyValue( aResourceResolverPropName, aStringResourceManagerAny ); 1007 } 1008 } 1009 1010 void LocalizationMgr::renameStringResourceIDs( const ScriptDocument& rDocument, const String& aLibName, 1011 const String& aDlgName, Reference< container::XNameContainer > xDialogModel ) 1012 { 1013 // Get library 1014 Reference< container::XNameContainer > xDialogLib( rDocument.getLibrary( E_DIALOGS, aLibName, sal_True ) ); 1015 Reference< XStringResourceManager > xStringResourceManager = 1016 LocalizationMgr::getStringResourceFromDialogLibrary( xDialogLib ); 1017 if( !xStringResourceManager.is() ) 1018 return; 1019 1020 Any aDialogCtrl; 1021 aDialogCtrl <<= xDialogModel; 1022 Reference< XStringResourceResolver > xDummyStringResolver; 1023 implHandleControlResourceProperties( aDialogCtrl, aDlgName, 1024 ::rtl::OUString(), xStringResourceManager, 1025 xDummyStringResolver, RENAME_DIALOG_IDS ); 1026 1027 // Handle all controls 1028 Sequence< ::rtl::OUString > aNames = xDialogModel->getElementNames(); 1029 const ::rtl::OUString* pNames = aNames.getConstArray(); 1030 sal_Int32 nCtrls = aNames.getLength(); 1031 for( sal_Int32 i = 0 ; i < nCtrls ; ++i ) 1032 { 1033 ::rtl::OUString aCtrlName( pNames[i] ); 1034 Any aCtrl = xDialogModel->getByName( aCtrlName ); 1035 implHandleControlResourceProperties( aCtrl, aDlgName, 1036 aCtrlName, xStringResourceManager, 1037 xDummyStringResolver, RENAME_DIALOG_IDS ); 1038 } 1039 } 1040 1041 void LocalizationMgr::removeResourceForDialog( const ScriptDocument& rDocument, const String& aLibName, 1042 const String& aDlgName, Reference< container::XNameContainer > xDialogModel ) 1043 { 1044 // Get library 1045 Reference< container::XNameContainer > xDialogLib( rDocument.getLibrary( E_DIALOGS, aLibName, sal_True ) ); 1046 Reference< XStringResourceManager > xStringResourceManager = 1047 LocalizationMgr::getStringResourceFromDialogLibrary( xDialogLib ); 1048 if( !xStringResourceManager.is() ) 1049 return; 1050 1051 Any aDialogCtrl; 1052 aDialogCtrl <<= xDialogModel; 1053 Reference< XStringResourceResolver > xDummyStringResolver; 1054 implHandleControlResourceProperties( aDialogCtrl, aDlgName, 1055 ::rtl::OUString(), xStringResourceManager, 1056 xDummyStringResolver, REMOVE_IDS_FROM_RESOURCE ); 1057 1058 // Handle all controls 1059 Sequence< ::rtl::OUString > aNames = xDialogModel->getElementNames(); 1060 const ::rtl::OUString* pNames = aNames.getConstArray(); 1061 sal_Int32 nCtrls = aNames.getLength(); 1062 for( sal_Int32 i = 0 ; i < nCtrls ; ++i ) 1063 { 1064 ::rtl::OUString aCtrlName( pNames[i] ); 1065 Any aCtrl = xDialogModel->getByName( aCtrlName ); 1066 implHandleControlResourceProperties( aCtrl, aDlgName, 1067 aCtrlName, xStringResourceManager, 1068 xDummyStringResolver, REMOVE_IDS_FROM_RESOURCE ); 1069 } 1070 } 1071 1072 void LocalizationMgr::resetResourceForDialog( Reference< container::XNameContainer > xDialogModel, 1073 Reference< XStringResourceManager > xStringResourceManager ) 1074 { 1075 if( !xStringResourceManager.is() ) 1076 return; 1077 1078 // Dialog as control 1079 ::rtl::OUString aDummyName; 1080 Any aDialogCtrl; 1081 aDialogCtrl <<= xDialogModel; 1082 Reference< XStringResourceResolver > xDummyStringResolver; 1083 implHandleControlResourceProperties( aDialogCtrl, aDummyName, 1084 aDummyName, xStringResourceManager, xDummyStringResolver, RESET_IDS ); 1085 1086 // Handle all controls 1087 Sequence< ::rtl::OUString > aNames = xDialogModel->getElementNames(); 1088 const ::rtl::OUString* pNames = aNames.getConstArray(); 1089 sal_Int32 nCtrls = aNames.getLength(); 1090 for( sal_Int32 i = 0 ; i < nCtrls ; ++i ) 1091 { 1092 ::rtl::OUString aCtrlName( pNames[i] ); 1093 Any aCtrl = xDialogModel->getByName( aCtrlName ); 1094 implHandleControlResourceProperties( aCtrl, aDummyName, 1095 aCtrlName, xStringResourceManager, xDummyStringResolver, RESET_IDS ); 1096 } 1097 } 1098 1099 void LocalizationMgr::setResourceIDsForDialog( Reference< container::XNameContainer > xDialogModel, 1100 Reference< XStringResourceManager > xStringResourceManager ) 1101 { 1102 if( !xStringResourceManager.is() ) 1103 return; 1104 1105 // Dialog as control 1106 ::rtl::OUString aDummyName; 1107 Any aDialogCtrl; 1108 aDialogCtrl <<= xDialogModel; 1109 Reference< XStringResourceResolver > xDummyStringResolver; 1110 implHandleControlResourceProperties( aDialogCtrl, aDummyName, 1111 aDummyName, xStringResourceManager, xDummyStringResolver, SET_IDS ); 1112 1113 // Handle all controls 1114 Sequence< ::rtl::OUString > aNames = xDialogModel->getElementNames(); 1115 const ::rtl::OUString* pNames = aNames.getConstArray(); 1116 sal_Int32 nCtrls = aNames.getLength(); 1117 for( sal_Int32 i = 0 ; i < nCtrls ; ++i ) 1118 { 1119 ::rtl::OUString aCtrlName( pNames[i] ); 1120 Any aCtrl = xDialogModel->getByName( aCtrlName ); 1121 implHandleControlResourceProperties( aCtrl, aDummyName, 1122 aCtrlName, xStringResourceManager, xDummyStringResolver, SET_IDS ); 1123 } 1124 } 1125 1126 void LocalizationMgr::copyResourcesForPastedEditorObject( DlgEditor* pEditor, 1127 Any aControlAny, const ::rtl::OUString& aCtrlName, 1128 Reference< XStringResourceResolver > xSourceStringResolver ) 1129 { 1130 // Get library for DlgEditor 1131 DialogWindow* pDlgWin = FindDialogWindowForEditor( pEditor ); 1132 if( !pDlgWin ) 1133 return; 1134 ScriptDocument aDocument( pDlgWin->GetDocument() ); 1135 DBG_ASSERT( aDocument.isValid(), "LocalizationMgr::copyResourcesForPastedEditorObject: invalid document!" ); 1136 if ( !aDocument.isValid() ) 1137 return; 1138 const String& rLibName = pDlgWin->GetLibName(); 1139 Reference< container::XNameContainer > xDialogLib( aDocument.getLibrary( E_DIALOGS, rLibName, sal_True ) ); 1140 Reference< XStringResourceManager > xStringResourceManager = 1141 LocalizationMgr::getStringResourceFromDialogLibrary( xDialogLib ); 1142 1143 // Set resource property 1144 if( !xStringResourceManager.is() || xStringResourceManager->getLocales().getLength() == 0 ) 1145 return; 1146 1147 ::rtl::OUString aDialogName = pDlgWin->GetName(); 1148 implHandleControlResourceProperties 1149 ( aControlAny, aDialogName, aCtrlName, xStringResourceManager, 1150 xSourceStringResolver, MOVE_RESOURCES ); 1151 } 1152 1153 void LocalizationMgr::copyResourceForDroppedDialog( Reference< container::XNameContainer > xDialogModel, 1154 const ::rtl::OUString& aDialogName, Reference< XStringResourceManager > xStringResourceManager, 1155 Reference< XStringResourceResolver > xSourceStringResolver ) 1156 { 1157 if( !xStringResourceManager.is() ) 1158 return; 1159 1160 // Dialog as control 1161 ::rtl::OUString aDummyName; 1162 Any aDialogCtrl; 1163 aDialogCtrl <<= xDialogModel; 1164 implHandleControlResourceProperties( aDialogCtrl, aDialogName, 1165 aDummyName, xStringResourceManager, xSourceStringResolver, MOVE_RESOURCES ); 1166 1167 // Handle all controls 1168 Sequence< ::rtl::OUString > aNames = xDialogModel->getElementNames(); 1169 const ::rtl::OUString* pNames = aNames.getConstArray(); 1170 sal_Int32 nCtrls = aNames.getLength(); 1171 for( sal_Int32 i = 0 ; i < nCtrls ; ++i ) 1172 { 1173 ::rtl::OUString aCtrlName( pNames[i] ); 1174 Any aCtrl = xDialogModel->getByName( aCtrlName ); 1175 implHandleControlResourceProperties( aCtrl, aDialogName, 1176 aCtrlName, xStringResourceManager, xSourceStringResolver, MOVE_RESOURCES ); 1177 } 1178 } 1179 1180 void LocalizationMgr::copyResourceForDialog( 1181 const Reference< container::XNameContainer >& xDialogModel, 1182 const Reference< XStringResourceResolver >& xSourceStringResolver, 1183 const Reference< XStringResourceManager >& xTargetStringResourceManager ) 1184 { 1185 if( !xDialogModel.is() || !xSourceStringResolver.is() || !xTargetStringResourceManager.is() ) 1186 return; 1187 1188 ::rtl::OUString aDummyName; 1189 Any aDialogCtrl; 1190 aDialogCtrl <<= xDialogModel; 1191 implHandleControlResourceProperties 1192 ( aDialogCtrl, aDummyName, aDummyName, xTargetStringResourceManager, 1193 xSourceStringResolver, COPY_RESOURCES ); 1194 1195 // Handle all controls 1196 Sequence< ::rtl::OUString > aNames = xDialogModel->getElementNames(); 1197 const ::rtl::OUString* pNames = aNames.getConstArray(); 1198 sal_Int32 nCtrls = aNames.getLength(); 1199 for( sal_Int32 i = 0 ; i < nCtrls ; ++i ) 1200 { 1201 ::rtl::OUString aCtrlName( pNames[i] ); 1202 Any aCtrl = xDialogModel->getByName( aCtrlName ); 1203 implHandleControlResourceProperties( aCtrl, aDummyName, aDummyName, 1204 xTargetStringResourceManager, xSourceStringResolver, COPY_RESOURCES ); 1205 } 1206 } 1207 1208 Reference< XStringResourceManager > LocalizationMgr::getStringResourceFromDialogLibrary 1209 ( Reference< container::XNameContainer > xDialogLib ) 1210 { 1211 Reference< XStringResourceManager > xStringResourceManager; 1212 if( xDialogLib.is() ) 1213 { 1214 Reference< resource::XStringResourceSupplier > xStringResourceSupplier( xDialogLib, UNO_QUERY ); 1215 if( xStringResourceSupplier.is() ) 1216 { 1217 Reference< resource::XStringResourceResolver > 1218 xStringResourceResolver = xStringResourceSupplier->getStringResource(); 1219 1220 xStringResourceManager = 1221 Reference< resource::XStringResourceManager >( xStringResourceResolver, UNO_QUERY ); 1222 } 1223 } 1224 return xStringResourceManager; 1225 } 1226 1227