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