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