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