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