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