LCOV - code coverage report
Current view: top level - basctl/source/basicide - localizationmgr.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 586 0.0 %
Date: 2014-11-03 Functions: 0 28 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10