Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / cui / source / options / optgdlg.cxx
blobecd671ef2c31858bd2fe61acbf90b79eea323752
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <config_features.h>
21 #include <svl/numformat.hxx>
22 #include <svl/zforlist.hxx>
23 #include <svl/currencytable.hxx>
24 #include <svtools/langhelp.hxx>
25 #include <unotools/lingucfg.hxx>
26 #if defined(_WIN32)
27 #include <unotools/resmgr.hxx>
28 #endif
29 #include <sfx2/bindings.hxx>
30 #include <sfx2/viewfrm.hxx>
31 #include <i18nlangtag/mslangid.hxx>
32 #include <i18nlangtag/languagetag.hxx>
33 #include <unotools/compatibility.hxx>
34 #include <svl/languageoptions.hxx>
35 #include <svl/cjkoptions.hxx>
36 #include <svl/ctloptions.hxx>
37 #include <svtools/miscopt.hxx>
38 #include <unotools/syslocaleoptions.hxx>
39 #include <sfx2/objsh.hxx>
40 #include <comphelper/propertysequence.hxx>
41 #include <comphelper/propertyvalue.hxx>
42 #include <svtools/langtab.hxx>
43 #include <editeng/unolingu.hxx>
44 #include <editeng/langitem.hxx>
45 #include <comphelper/processfactory.hxx>
46 #include <comphelper/string.hxx>
47 #include <rtl/ustrbuf.hxx>
48 #include <editeng/editids.hrc>
49 #include <svx/svxids.hrc>
50 #include <svl/intitem.hxx>
51 #include <GraphicsTestsDialog.hxx>
52 #include <unotools/searchopt.hxx>
53 #include <sal/log.hxx>
54 #include <officecfg/Office/Common.hxx>
55 #include <officecfg/Setup.hxx>
56 #include <comphelper/configuration.hxx>
57 #include <comphelper/diagnose_ex.hxx>
58 #if HAVE_FEATURE_BREAKPAD
59 #include <desktop/crashreport.hxx>
60 #endif
62 #include <com/sun/star/configuration/theDefaultProvider.hpp>
63 #include <com/sun/star/container/XNameAccess.hpp>
64 #include <com/sun/star/container/XNameReplace.hpp>
65 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
66 #include <com/sun/star/beans/NamedValue.hpp>
67 #include <com/sun/star/beans/PropertyAttribute.hpp>
68 #include <com/sun/star/beans/XPropertySet.hpp>
69 #include <com/sun/star/util/XChangesBatch.hpp>
70 #include <com/sun/star/uno/Any.hxx>
71 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
72 #include <com/sun/star/container/XSet.hpp>
73 #include <com/sun/star/i18n/ScriptType.hpp>
74 #include <com/sun/star/office/Quickstart.hpp>
75 #include <com/sun/star/linguistic2/XLinguProperties.hpp>
76 #include <comphelper/dispatchcommand.hxx>
78 #include <vcl/vclenum.hxx>
79 #include <vcl/svapp.hxx>
80 #include <vcl/settings.hxx>
81 #include <vcl/window.hxx>
82 #include <vcl/IconThemeInfo.hxx>
83 #include <vcl/skia/SkiaHelper.hxx>
84 #include <bitmaps.hlst>
86 #include "optgdlg.hxx"
87 #include <svtools/apearcfg.hxx>
88 #include <svtools/optionsdrawinglayer.hxx>
89 #include <svtools/restartdialog.hxx>
90 #include <svtools/imgdef.hxx>
91 #include <com/sun/star/datatransfer/clipboard/SystemClipboard.hpp>
92 #include <vcl/unohelp2.hxx>
94 #if defined(_WIN32)
95 #include <systools/win32/winstoreutil.hxx>
96 #include <vcl/fileregistration.hxx>
97 #endif
98 using namespace ::com::sun::star::uno;
99 using namespace ::com::sun::star::lang;
100 using namespace ::com::sun::star::beans;
101 using namespace ::com::sun::star::container;
102 using namespace ::com::sun::star::util;
103 using namespace ::utl;
105 // class OfaMiscTabPage --------------------------------------------------
107 DeactivateRC OfaMiscTabPage::DeactivatePage( SfxItemSet* pSet_ )
109 if ( pSet_ )
110 FillItemSet( pSet_ );
111 return DeactivateRC::LeavePage;
114 namespace
116 OUString impl_SystemFileOpenServiceName()
118 #if defined(_WIN32)
119 return "com.sun.star.ui.dialogs.SystemFilePicker";
120 #elif defined MACOSX
121 return "com.sun.star.ui.dialogs.AquaFilePicker";
122 #else
123 return OUString();
124 #endif
127 bool lcl_HasSystemFilePicker()
129 if( Application::hasNativeFileSelection() )
130 return true;
132 // Otherwise fall-back on querying services
133 bool bRet = false;
134 Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
136 Reference< XContentEnumerationAccess > xEnumAccess( xFactory, UNO_QUERY );
137 Reference< XSet > xSet( xFactory, UNO_QUERY );
139 if ( ! xEnumAccess.is() || ! xSet.is() )
140 return bRet;
144 OUString aFileService = impl_SystemFileOpenServiceName();
145 Reference< XEnumeration > xEnum = xEnumAccess->createContentEnumeration( aFileService );
146 if ( xEnum.is() && xEnum->hasMoreElements() )
147 bRet = true;
149 catch (const IllegalArgumentException&)
152 catch (const ElementExistException&)
155 return bRet;
159 OfaMiscTabPage::OfaMiscTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
160 : SfxTabPage(pPage, pController, "cui/ui/optgeneralpage.ui", "OptGeneralPage", &rSet)
161 , m_xExtHelpCB(m_xBuilder->weld_check_button("exthelp"))
162 , m_xPopUpNoHelpCB(m_xBuilder->weld_check_button("popupnohelp"))
163 , m_xShowTipOfTheDay(m_xBuilder->weld_check_button("cbShowTipOfTheDay"))
164 , m_xFileDlgFrame(m_xBuilder->weld_widget("filedlgframe"))
165 , m_xFileDlgROImage(m_xBuilder->weld_widget("lockimage"))
166 , m_xFileDlgCB(m_xBuilder->weld_check_button("filedlg"))
167 , m_xDocStatusCB(m_xBuilder->weld_check_button("docstatus"))
168 , m_xYearFrame(m_xBuilder->weld_widget("yearframe"))
169 , m_xYearValueField(m_xBuilder->weld_spin_button("year"))
170 , m_xToYearFT(m_xBuilder->weld_label("toyear"))
171 #if HAVE_FEATURE_BREAKPAD
172 , m_xPrivacyFrame(m_xBuilder->weld_widget("privacyframe"))
173 , m_xCrashReport(m_xBuilder->weld_check_button("crashreport"))
174 #endif
175 #if defined(_WIN32)
176 , m_xQuickStarterFrame(m_xBuilder->weld_widget("quickstarter"))
177 , m_xQuickLaunchCB(m_xBuilder->weld_check_button("quicklaunch"))
178 , m_xFileAssocFrame(m_xBuilder->weld_widget("fileassoc"))
179 , m_xFileAssocBtn(m_xBuilder->weld_button("assocfiles"))
180 , m_xPerformFileExtCheck(m_xBuilder->weld_check_button("cbPerformFileExtCheck"))
181 #endif
183 if (!lcl_HasSystemFilePicker())
184 m_xFileDlgFrame->hide();
185 else if (officecfg::Office::Common::Misc::UseSystemFileDialog::isReadOnly())
187 m_xFileDlgROImage->show();
188 m_xFileDlgCB->set_sensitive(false);
191 #if HAVE_FEATURE_BREAKPAD
192 m_xPrivacyFrame->show();
193 #endif
195 #if defined(_WIN32)
196 // Store-packaged apps (located under the protected Program Files\WindowsApps) can't use normal
197 // shell shortcuts to their exe. TODO: show a button to open "Startup Apps" system applet?
198 if (!sal::systools::IsStorePackagedApp())
199 m_xQuickStarterFrame->show();
201 m_xFileAssocFrame->show();
202 m_xFileAssocBtn->connect_clicked(LINK(this, OfaMiscTabPage, FileAssocClick));
203 #endif
205 m_aStrDateInfo = m_xToYearFT->get_label();
206 m_xYearValueField->connect_value_changed( LINK( this, OfaMiscTabPage, TwoFigureHdl ) );
208 SetExchangeSupport();
211 OfaMiscTabPage::~OfaMiscTabPage()
215 std::unique_ptr<SfxTabPage> OfaMiscTabPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet )
217 return std::make_unique<OfaMiscTabPage>( pPage, pController, *rAttrSet );
220 bool OfaMiscTabPage::FillItemSet( SfxItemSet* rSet )
222 bool bModified = false;
223 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
225 if ( m_xPopUpNoHelpCB->get_state_changed_from_saved() )
226 officecfg::Office::Common::Help::BuiltInHelpNotInstalledPopUp::set(m_xPopUpNoHelpCB->get_active(), batch);
228 if ( m_xExtHelpCB->get_state_changed_from_saved() )
229 officecfg::Office::Common::Help::ExtendedTip::set(m_xExtHelpCB->get_active(), batch);
231 if ( m_xShowTipOfTheDay->get_state_changed_from_saved() )
233 officecfg::Office::Common::Misc::ShowTipOfTheDay::set(m_xShowTipOfTheDay->get_active(), batch);
234 bModified = true;
237 if ( m_xFileDlgCB->get_state_changed_from_saved() )
239 officecfg::Office::Common::Misc::UseSystemFileDialog::set( !m_xFileDlgCB->get_active(), batch );
240 bModified = true;
243 if (m_xDocStatusCB->get_state_changed_from_saved())
245 officecfg::Office::Common::Print::PrintingModifiesDocument::set(m_xDocStatusCB->get_active(), batch);
246 bModified = true;
249 const SfxUInt16Item* pUInt16Item = GetOldItem( *rSet, SID_ATTR_YEAR2000 );
250 sal_uInt16 nNum = static_cast<sal_uInt16>(m_xYearValueField->get_text().toInt32());
251 if ( pUInt16Item && pUInt16Item->GetValue() != nNum )
253 bModified = true;
254 rSet->Put( SfxUInt16Item( SID_ATTR_YEAR2000, nNum ) );
257 #if HAVE_FEATURE_BREAKPAD
258 if (m_xCrashReport->get_state_changed_from_saved())
260 officecfg::Office::Common::Misc::CrashReport::set(m_xCrashReport->get_active(), batch);
261 bModified = true;
263 #endif
265 #if defined(_WIN32)
266 if (m_xPerformFileExtCheck->get_state_changed_from_saved())
268 officecfg::Office::Common::Misc::PerformFileExtCheck::set(
269 m_xPerformFileExtCheck->get_active(), batch);
270 bModified = true;
273 if( m_xQuickLaunchCB->get_state_changed_from_saved())
275 rSet->Put(SfxBoolItem(SID_ATTR_QUICKLAUNCHER, m_xQuickLaunchCB->get_active()));
276 bModified = true;
278 #endif
280 batch->commit();
282 return bModified;
285 void OfaMiscTabPage::Reset( const SfxItemSet* rSet )
287 m_xExtHelpCB->set_active( officecfg::Office::Common::Help::Tip::get() &&
288 officecfg::Office::Common::Help::ExtendedTip::get() );
289 m_xExtHelpCB->save_state();
290 m_xPopUpNoHelpCB->set_active( officecfg::Office::Common::Help::BuiltInHelpNotInstalledPopUp::get() );
291 m_xPopUpNoHelpCB->save_state();
292 m_xShowTipOfTheDay->set_active( officecfg::Office::Common::Misc::ShowTipOfTheDay::get() );
293 m_xShowTipOfTheDay->save_state();
294 m_xFileDlgCB->set_active( !officecfg::Office::Common::Misc::UseSystemFileDialog::get() );
295 m_xFileDlgCB->save_state();
297 m_xDocStatusCB->set_active(officecfg::Office::Common::Print::PrintingModifiesDocument::get());
298 m_xDocStatusCB->save_state();
300 if ( const SfxUInt16Item* pYearItem = rSet->GetItemIfSet( SID_ATTR_YEAR2000, false ) )
302 m_xYearValueField->set_value( pYearItem->GetValue() );
303 TwoFigureHdl(*m_xYearValueField);
305 else
306 m_xYearFrame->set_sensitive(false);
308 #if HAVE_FEATURE_BREAKPAD
309 m_xCrashReport->set_active(officecfg::Office::Common::Misc::CrashReport::get() && CrashReporter::IsDumpEnable());
310 m_xCrashReport->set_sensitive(!officecfg::Office::Common::Misc::CrashReport::isReadOnly() && CrashReporter::IsDumpEnable());
311 m_xCrashReport->save_state();
312 #endif
314 #if defined(_WIN32)
315 const SfxPoolItem* pItem = nullptr;
316 SfxItemState eState = rSet->GetItemState( SID_ATTR_QUICKLAUNCHER, false, &pItem );
317 if ( SfxItemState::SET == eState )
318 m_xQuickLaunchCB->set_active( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
319 else if ( SfxItemState::DISABLED == eState )
321 // quickstart not installed
322 m_xQuickStarterFrame->hide();
325 m_xQuickLaunchCB->save_state();
327 m_xPerformFileExtCheck->set_active(
328 officecfg::Office::Common::Misc::PerformFileExtCheck::get());
329 m_xPerformFileExtCheck->save_state();
330 m_xPerformFileExtCheck->set_sensitive(!officecfg::Office::Common::Misc::PerformFileExtCheck::isReadOnly());
331 #endif
334 IMPL_LINK_NOARG( OfaMiscTabPage, TwoFigureHdl, weld::SpinButton&, void )
336 OUString aOutput( m_aStrDateInfo );
337 OUString aStr( m_xYearValueField->get_text() );
338 sal_Int32 nNum = aStr.toInt32();
339 if ( aStr.getLength() != 4 || nNum < m_xYearValueField->get_min() || nNum > m_xYearValueField->get_max() )
340 aOutput += "????";
341 else
343 nNum += 99;
344 aOutput += OUString::number( nNum );
346 m_xToYearFT->set_label( aOutput );
349 #if defined(_WIN32)
350 IMPL_STATIC_LINK_NOARG(OfaMiscTabPage, FileAssocClick, weld::Button&, void)
352 vcl::fileregistration::LaunchRegistrationUI();
354 #endif
356 class CanvasSettings
358 public:
359 CanvasSettings();
361 bool IsHardwareAccelerationEnabled() const;
362 bool IsHardwareAccelerationAvailable() const;
363 bool IsHardwareAccelerationRO() const;
364 void EnabledHardwareAcceleration( bool _bEnabled ) const;
366 private:
367 typedef std::vector< std::pair<OUString,Sequence<OUString> > > ServiceVector;
369 Reference<XNameAccess> mxForceFlagNameAccess;
370 ServiceVector maAvailableImplementations;
371 mutable bool mbHWAccelAvailable;
372 mutable bool mbHWAccelChecked;
375 CanvasSettings::CanvasSettings() :
376 mbHWAccelAvailable(false),
377 mbHWAccelChecked(false)
381 Reference<XMultiServiceFactory> xConfigProvider(
382 css::configuration::theDefaultProvider::get(
383 comphelper::getProcessComponentContext()));
385 Sequence<Any> aArgs1(comphelper::InitAnyPropertySequence(
387 {"nodepath", Any(OUString("/org.openoffice.Office.Canvas"))}
388 }));
389 mxForceFlagNameAccess.set(
390 xConfigProvider->createInstanceWithArguments(
391 "com.sun.star.configuration.ConfigurationUpdateAccess",
392 aArgs1 ),
393 UNO_QUERY_THROW );
395 Sequence<Any> aArgs2(comphelper::InitAnyPropertySequence(
397 {"nodepath", Any(OUString("/org.openoffice.Office.Canvas/CanvasServiceList"))}
398 }));
399 Reference<XNameAccess> xNameAccess(
400 xConfigProvider->createInstanceWithArguments(
401 "com.sun.star.configuration.ConfigurationAccess",
402 aArgs2 ), UNO_QUERY_THROW );
403 Reference<XHierarchicalNameAccess> xHierarchicalNameAccess(
404 xNameAccess, UNO_QUERY_THROW);
406 Sequence<OUString> serviceNames = xNameAccess->getElementNames();
407 const OUString* pCurr = serviceNames.getConstArray();
408 const OUString* const pEnd = pCurr + serviceNames.getLength();
409 while( pCurr != pEnd )
411 Reference<XNameAccess> xEntryNameAccess(
412 xHierarchicalNameAccess->getByHierarchicalName(*pCurr),
413 UNO_QUERY );
415 if( xEntryNameAccess.is() )
417 Sequence<OUString> preferredImplementations;
418 if( xEntryNameAccess->getByName("PreferredImplementations") >>= preferredImplementations )
419 maAvailableImplementations.emplace_back(*pCurr,preferredImplementations );
422 ++pCurr;
425 catch (const Exception&)
430 bool CanvasSettings::IsHardwareAccelerationAvailable() const
432 if( !mbHWAccelChecked )
434 mbHWAccelChecked = true;
436 Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
438 // check whether any of the service lists has an
439 // implementation that presents the "HardwareAcceleration" property
440 for (auto const& availableImpl : maAvailableImplementations)
442 const OUString* pCurrImpl = availableImpl.second.getConstArray();
443 const OUString* const pEndImpl = pCurrImpl + availableImpl.second.getLength();
445 while( pCurrImpl != pEndImpl )
449 Reference<XPropertySet> xPropSet( xFactory->createInstance(
450 pCurrImpl->trim() ),
451 UNO_QUERY_THROW );
452 bool bHasAccel(false);
453 if( xPropSet->getPropertyValue("HardwareAcceleration") >>= bHasAccel )
454 if( bHasAccel )
456 mbHWAccelAvailable = true;
457 return mbHWAccelAvailable;
460 catch (const Exception&)
464 ++pCurrImpl;
469 return mbHWAccelAvailable;
472 bool CanvasSettings::IsHardwareAccelerationEnabled() const
474 bool bForceLastEntry(false);
475 if( !mxForceFlagNameAccess.is() )
476 return true;
478 if( !(mxForceFlagNameAccess->getByName("ForceSafeServiceImpl") >>= bForceLastEntry) )
479 return true;
481 return !bForceLastEntry;
484 bool CanvasSettings::IsHardwareAccelerationRO() const
486 Reference< XPropertySet > xSet(mxForceFlagNameAccess, UNO_QUERY);
487 if (!xSet.is())
488 return true;
490 Reference< XPropertySetInfo > xInfo = xSet->getPropertySetInfo();
491 Property aProp = xInfo->getPropertyByName("ForceSafeServiceImpl");
492 return ((aProp.Attributes & css::beans::PropertyAttribute::READONLY ) == css::beans::PropertyAttribute::READONLY);
495 void CanvasSettings::EnabledHardwareAcceleration( bool _bEnabled ) const
497 Reference< XNameReplace > xNameReplace(
498 mxForceFlagNameAccess, UNO_QUERY );
500 if( !xNameReplace.is() )
501 return;
503 xNameReplace->replaceByName( "ForceSafeServiceImpl", Any(!_bEnabled) );
505 Reference< XChangesBatch > xChangesBatch(
506 mxForceFlagNameAccess, UNO_QUERY );
508 if( !xChangesBatch.is() )
509 return;
511 xChangesBatch->commitChanges();
514 // class OfaViewTabPage --------------------------------------------------
516 static bool DisplayNameCompareLessThan(const vcl::IconThemeInfo& rInfo1, const vcl::IconThemeInfo& rInfo2)
518 return rInfo1.GetDisplayName().compareTo(rInfo2.GetDisplayName()) < 0;
521 OfaViewTabPage::OfaViewTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
522 : SfxTabPage(pPage, pController, "cui/ui/optviewpage.ui", "OptViewPage", &rSet)
523 , nSizeLB_InitialSelection(0)
524 , nSidebarSizeLB_InitialSelection(0)
525 , nNotebookbarSizeLB_InitialSelection(0)
526 , nStyleLB_InitialSelection(0)
527 , pCanvasSettings(new CanvasSettings)
528 , m_xIconSizeLB(m_xBuilder->weld_combo_box("iconsize"))
529 , m_xSidebarIconSizeLB(m_xBuilder->weld_combo_box("sidebariconsize"))
530 , m_xNotebookbarIconSizeLB(m_xBuilder->weld_combo_box("notebookbariconsize"))
531 , m_xDarkModeFrame(m_xBuilder->weld_widget("darkmode"))
532 , m_xAppearanceStyleLB(m_xBuilder->weld_combo_box("appearance"))
533 , m_xIconStyleLB(m_xBuilder->weld_combo_box("iconstyle"))
534 , m_xFontAntiAliasing(m_xBuilder->weld_check_button("aafont"))
535 , m_xAAPointLimitLabel(m_xBuilder->weld_label("aafrom"))
536 , m_xAAPointLimit(m_xBuilder->weld_metric_spin_button("aanf", FieldUnit::PIXEL))
537 , m_xFontShowCB(m_xBuilder->weld_check_button("showfontpreview"))
538 , m_xUseHardwareAccell(m_xBuilder->weld_check_button("useaccel"))
539 , m_xUseAntiAliase(m_xBuilder->weld_check_button("useaa"))
540 , m_xUseSkia(m_xBuilder->weld_check_button("useskia"))
541 , m_xForceSkiaRaster(m_xBuilder->weld_check_button("forceskiaraster"))
542 , m_xSkiaStatusEnabled(m_xBuilder->weld_label("skiaenabled"))
543 , m_xSkiaStatusDisabled(m_xBuilder->weld_label("skiadisabled"))
544 , m_xSkiaLog(m_xBuilder->weld_button("btnSkialog"))
545 , m_xMouseMiddleLB(m_xBuilder->weld_combo_box("mousemiddle"))
546 , m_xMoreIcons(m_xBuilder->weld_button("btnMoreIcons"))
547 , m_xRunGPTests(m_xBuilder->weld_button("btn_rungptest"))
548 , m_sAutoStr(m_xIconStyleLB->get_text(0))
550 OUString sToolKitName(Application::GetToolkitName());
551 const bool bHasDarkMode = sToolKitName.startsWith("gtk") || sToolKitName == "osx" || sToolKitName == "win";
552 if (!bHasDarkMode)
553 m_xDarkModeFrame->hide();
555 m_xFontAntiAliasing->connect_toggled( LINK( this, OfaViewTabPage, OnAntialiasingToggled ) );
557 m_xUseSkia->connect_toggled(LINK(this, OfaViewTabPage, OnUseSkiaToggled));
558 m_xSkiaLog->connect_clicked(LINK(this, OfaViewTabPage, OnCopySkiaLog));
560 UpdateIconThemes();
562 m_xIconStyleLB->set_active(0);
564 m_xMoreIcons->connect_clicked(LINK(this, OfaViewTabPage, OnMoreIconsClick));
565 m_xRunGPTests->connect_clicked( LINK( this, OfaViewTabPage, OnRunGPTestClick));
568 void OfaViewTabPage::UpdateIconThemes()
570 // Set known icon themes
571 m_xIconStyleLB->clear();
572 StyleSettings aStyleSettings = Application::GetSettings().GetStyleSettings();
573 mInstalledIconThemes = aStyleSettings.GetInstalledIconThemes();
574 std::sort(mInstalledIconThemes.begin(), mInstalledIconThemes.end(), DisplayNameCompareLessThan);
576 // Start with the automatically chosen icon theme
577 OUString autoThemeId = aStyleSettings.GetAutomaticallyChosenIconTheme();
578 const vcl::IconThemeInfo& autoIconTheme = vcl::IconThemeInfo::FindIconThemeById(mInstalledIconThemes, autoThemeId);
580 OUString entryForAuto = m_sAutoStr + " (" + autoIconTheme.GetDisplayName() + ")";
581 m_xIconStyleLB->append("auto", entryForAuto); // index 0 means choose style automatically
583 // separate auto and other icon themes
584 m_xIconStyleLB->append_separator("");
586 for (auto const& installIconTheme : mInstalledIconThemes)
587 m_xIconStyleLB->append(installIconTheme.GetThemeId(), installIconTheme.GetDisplayName());
590 OfaViewTabPage::~OfaViewTabPage()
594 IMPL_LINK_NOARG(OfaViewTabPage, OnRunGPTestClick, weld::Button&, void)
596 GraphicsTestsDialog m_xGraphicsTestDialog(m_xContainer.get());
597 m_xGraphicsTestDialog.run();
600 IMPL_STATIC_LINK_NOARG(OfaViewTabPage, OnMoreIconsClick, weld::Button&, void)
602 css::uno::Sequence<css::beans::PropertyValue> aArgs{ comphelper::makePropertyValue(
603 "AdditionsTag", OUString("Icons")) };
604 comphelper::dispatchCommand(".uno:AdditionsDialog", aArgs);
607 IMPL_LINK_NOARG( OfaViewTabPage, OnAntialiasingToggled, weld::Toggleable&, void )
609 bool bAAEnabled = m_xFontAntiAliasing->get_active();
611 m_xAAPointLimitLabel->set_sensitive(bAAEnabled);
612 m_xAAPointLimit->set_sensitive(bAAEnabled);
615 IMPL_LINK_NOARG(OfaViewTabPage, OnUseSkiaToggled, weld::Toggleable&, void)
617 UpdateSkiaStatus();
620 IMPL_LINK_NOARG(OfaViewTabPage, OnCopySkiaLog, weld::Button&, void)
622 #if HAVE_FEATURE_SKIA
623 css::uno::Reference<css::datatransfer::clipboard::XClipboard> xClipboard =
624 css::datatransfer::clipboard::SystemClipboard::create(
625 comphelper::getProcessComponentContext());
626 OUString sInfo = SkiaHelper::readLog();
627 vcl::unohelper::TextDataObject::CopyStringTo(sInfo, xClipboard);
628 m_xSkiaLog->set_from_icon_name(RID_SVXBMP_COPY);
629 #endif
632 void OfaViewTabPage::HideSkiaWidgets()
634 m_xUseSkia->hide();
635 m_xForceSkiaRaster->hide();
636 m_xSkiaStatusEnabled->hide();
637 m_xSkiaStatusDisabled->hide();
638 m_xSkiaLog->hide();
641 void OfaViewTabPage::UpdateSkiaStatus()
643 #if HAVE_FEATURE_SKIA
644 bool skiaHidden = true;
646 // For now Skia is used mainly on Windows, enable the controls there.
647 if (Application::GetToolkitName() == "win")
648 skiaHidden = false;
649 // It can also be used on Linux, but only with the rarely used 'gen' backend.
650 if (Application::GetToolkitName() == "x11")
651 skiaHidden = false;
652 // OSX backend has Skia support too.
653 if (Application::GetToolkitName() == "osx")
654 skiaHidden = false;
656 if (skiaHidden)
658 HideSkiaWidgets();
659 return;
662 // Easier than a custom translation string.
663 bool bEnabled = SkiaHelper::isVCLSkiaEnabled();
664 m_xSkiaStatusEnabled->set_visible(bEnabled);
665 m_xSkiaStatusDisabled->set_visible(!bEnabled);
667 // FIXME: should really add code to show a 'lock' icon here.
668 m_xUseSkia->set_sensitive(!officecfg::Office::Common::VCL::UseSkia::isReadOnly());
669 m_xForceSkiaRaster->set_sensitive(m_xUseSkia->get_active() && !officecfg::Office::Common::VCL::ForceSkiaRaster::isReadOnly());
670 m_xSkiaLog->set_sensitive(bEnabled);
672 // Technically the 'use hardware acceleration' option could be used to mean !forceSkiaRaster, but the implementation
673 // of the option is so tied to the implementation of the canvas module that it's simpler to ignore it.
674 UpdateHardwareAccelStatus();
675 #else
676 HideSkiaWidgets();
677 #endif
680 std::unique_ptr<SfxTabPage> OfaViewTabPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet )
682 return std::make_unique<OfaViewTabPage>(pPage, pController, *rAttrSet);
685 bool OfaViewTabPage::FillItemSet( SfxItemSet* )
687 bool bModified = false;
688 bool bDarkModeOptModified = false;
689 bool bRepaintWindows(false);
690 std::shared_ptr<comphelper::ConfigurationChanges> xChanges(comphelper::ConfigurationChanges::create());
692 SvtMiscOptions aMiscOptions;
693 const sal_Int32 nSizeLB_NewSelection = m_xIconSizeLB->get_active();
694 if( nSizeLB_InitialSelection != nSizeLB_NewSelection )
696 // from now on it's modified, even if via auto setting the same size was set as now selected in the LB
697 sal_Int16 eSet = SFX_SYMBOLS_SIZE_AUTO;
698 switch( nSizeLB_NewSelection )
700 case 0: eSet = SFX_SYMBOLS_SIZE_AUTO; break;
701 case 1: eSet = SFX_SYMBOLS_SIZE_SMALL; break;
702 case 2: eSet = SFX_SYMBOLS_SIZE_LARGE; break;
703 case 3: eSet = SFX_SYMBOLS_SIZE_32; break;
704 default:
705 SAL_WARN("cui.options", "OfaViewTabPage::FillItemSet(): This state of m_xIconSizeLB should not be possible!");
707 aMiscOptions.SetSymbolsSize( eSet );
710 const sal_Int32 nSidebarSizeLB_NewSelection = m_xSidebarIconSizeLB->get_active();
711 if( nSidebarSizeLB_InitialSelection != nSidebarSizeLB_NewSelection )
713 // from now on it's modified, even if via auto setting the same size was set as now selected in the LB
714 ToolBoxButtonSize eSet = ToolBoxButtonSize::DontCare;
715 switch( nSidebarSizeLB_NewSelection )
717 case 0: eSet = ToolBoxButtonSize::DontCare; break;
718 case 1: eSet = ToolBoxButtonSize::Small; break;
719 case 2: eSet = ToolBoxButtonSize::Large; break;
720 default:
721 SAL_WARN("cui.options", "OfaViewTabPage::FillItemSet(): This state of m_xSidebarIconSizeLB should not be possible!");
723 officecfg::Office::Common::Misc::SidebarIconSize::set(static_cast<sal_Int16>(eSet), xChanges);
726 const sal_Int32 nNotebookbarSizeLB_NewSelection = m_xNotebookbarIconSizeLB->get_active();
727 if( nNotebookbarSizeLB_InitialSelection != nNotebookbarSizeLB_NewSelection )
729 // from now on it's modified, even if via auto setting the same size was set as now selected in the LB
730 ToolBoxButtonSize eSet = ToolBoxButtonSize::DontCare;
731 switch( nNotebookbarSizeLB_NewSelection )
733 case 0: eSet = ToolBoxButtonSize::DontCare; break;
734 case 1: eSet = ToolBoxButtonSize::Small; break;
735 case 2: eSet = ToolBoxButtonSize::Large; break;
736 default:
737 SAL_WARN("cui.options", "OfaViewTabPage::FillItemSet(): This state of m_xNotebookbarIconSizeLB should not be possible!");
739 officecfg::Office::Common::Misc::NotebookbarIconSize::set(static_cast<sal_Int16>(eSet), xChanges);
742 const sal_Int32 nStyleLB_NewSelection = m_xIconStyleLB->get_active();
743 if( nStyleLB_InitialSelection != nStyleLB_NewSelection )
745 aMiscOptions.SetIconTheme(m_xIconStyleLB->get_active_id());
746 nStyleLB_InitialSelection = nStyleLB_NewSelection;
749 bool bAppearanceChanged = false;
750 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
752 // Middle Mouse Button
753 MouseMiddleButtonAction eOldMiddleMouse = static_cast<MouseMiddleButtonAction>(officecfg::Office::Common::View::Dialog::MiddleMouseButton::get());
754 short eNewMiddleMouse = m_xMouseMiddleLB->get_active();
755 if(eNewMiddleMouse > 2)
756 eNewMiddleMouse = 2;
758 if ( eNewMiddleMouse != static_cast<short>(eOldMiddleMouse) )
760 officecfg::Office::Common::View::Dialog::MiddleMouseButton::set(eNewMiddleMouse, batch);
761 bAppearanceChanged = true;
764 if (m_xFontAntiAliasing->get_state_changed_from_saved())
766 bool b = m_xFontAntiAliasing->get_active();
767 officecfg::Office::Common::View::FontAntiAliasing::Enabled::set(b, batch);
768 bAppearanceChanged = true;
771 if (m_xAAPointLimit->get_value_changed_from_saved())
773 sal_Int64 i = m_xAAPointLimit->get_value(FieldUnit::PIXEL);
774 officecfg::Office::Common::View::FontAntiAliasing::MinPixelHeight::set(i, batch);
775 bAppearanceChanged = true;
778 if (m_xFontShowCB->get_state_changed_from_saved())
780 officecfg::Office::Common::Font::View::ShowFontBoxWYSIWYG::set(m_xFontShowCB->get_active(), xChanges);
781 bModified = true;
784 if (m_xAppearanceStyleLB->get_value_changed_from_saved())
786 bDarkModeOptModified = true;
787 bModified = true;
790 // #i95644# if disabled, do not use value, see in ::Reset()
791 if (m_xUseHardwareAccell->get_sensitive())
793 if(m_xUseHardwareAccell->get_state_changed_from_saved())
795 pCanvasSettings->EnabledHardwareAcceleration(m_xUseHardwareAccell->get_active());
796 bModified = true;
800 // #i95644# if disabled, do not use value, see in ::Reset()
801 if (m_xUseAntiAliase->get_sensitive())
803 if (m_xUseAntiAliase->get_active() != SvtOptionsDrawinglayer::IsAntiAliasing())
805 SvtOptionsDrawinglayer::SetAntiAliasing(m_xUseAntiAliase->get_active(), /*bTemporary*/false);
806 bModified = true;
807 bRepaintWindows = true;
811 if (m_xUseSkia->get_state_changed_from_saved() ||
812 m_xForceSkiaRaster->get_state_changed_from_saved())
814 officecfg::Office::Common::VCL::UseSkia::set(m_xUseSkia->get_active(), xChanges);
815 officecfg::Office::Common::VCL::ForceSkiaRaster::set(m_xForceSkiaRaster->get_active(), xChanges);
816 bModified = true;
819 xChanges->commit();
821 if (bDarkModeOptModified)
822 MiscSettings::SetDarkMode(m_xAppearanceStyleLB->get_active());
824 if ( bAppearanceChanged )
826 batch->commit();
827 SvtTabAppearanceCfg::SetApplicationDefaults ( GetpApp() );
830 if(bRepaintWindows)
832 vcl::Window* pAppWindow = Application::GetFirstTopLevelWindow();
834 while(pAppWindow)
836 pAppWindow->Invalidate();
837 pAppWindow = Application::GetNextTopLevelWindow(pAppWindow);
841 if (m_xUseSkia->get_state_changed_from_saved() ||
842 m_xForceSkiaRaster->get_state_changed_from_saved())
844 SolarMutexGuard aGuard;
845 if( svtools::executeRestartDialog(
846 comphelper::getProcessComponentContext(), nullptr,
847 svtools::RESTART_REASON_SKIA))
848 GetDialogController()->response(RET_OK);
851 return bModified;
854 void OfaViewTabPage::Reset( const SfxItemSet* )
856 SvtMiscOptions aMiscOptions;
858 if (SvtMiscOptions::GetSymbolsSize() != SFX_SYMBOLS_SIZE_AUTO)
860 nSizeLB_InitialSelection = 1;
862 if (SvtMiscOptions::GetSymbolsSize() == SFX_SYMBOLS_SIZE_LARGE)
863 nSizeLB_InitialSelection = 2;
864 else if (SvtMiscOptions::GetSymbolsSize() == SFX_SYMBOLS_SIZE_32)
865 nSizeLB_InitialSelection = 3;
867 m_xIconSizeLB->set_active( nSizeLB_InitialSelection );
868 m_xIconSizeLB->save_value();
870 ToolBoxButtonSize eSidebarIconSize = static_cast<ToolBoxButtonSize>(officecfg::Office::Common::Misc::SidebarIconSize::get());
871 if( eSidebarIconSize == ToolBoxButtonSize::DontCare )
872 ; // do nothing
873 else if( eSidebarIconSize == ToolBoxButtonSize::Small )
874 nSidebarSizeLB_InitialSelection = 1;
875 else if( eSidebarIconSize == ToolBoxButtonSize::Large )
876 nSidebarSizeLB_InitialSelection = 2;
877 m_xSidebarIconSizeLB->set_active( nSidebarSizeLB_InitialSelection );
878 m_xSidebarIconSizeLB->save_value();
879 ToolBoxButtonSize eNotebookbarIconSize = static_cast<ToolBoxButtonSize>(officecfg::Office::Common::Misc::NotebookbarIconSize::get());
880 if( eNotebookbarIconSize == ToolBoxButtonSize::DontCare )
881 ; // do nothing
882 else if( eNotebookbarIconSize == ToolBoxButtonSize::Small )
883 nNotebookbarSizeLB_InitialSelection = 1;
884 else if( eNotebookbarIconSize == ToolBoxButtonSize::Large )
885 nNotebookbarSizeLB_InitialSelection = 2;
886 m_xNotebookbarIconSizeLB->set_active(nNotebookbarSizeLB_InitialSelection);
887 m_xNotebookbarIconSizeLB->save_value();
889 // tdf#153497 set name of automatic icon theme, it may have changed due to "Apply" while this page is visible
890 UpdateIconThemes();
892 if (aMiscOptions.IconThemeWasSetAutomatically()) {
893 nStyleLB_InitialSelection = 0;
895 else {
896 const OUString& selected = SvtMiscOptions::GetIconTheme();
897 const vcl::IconThemeInfo& selectedInfo =
898 vcl::IconThemeInfo::FindIconThemeById(mInstalledIconThemes, selected);
899 nStyleLB_InitialSelection = m_xIconStyleLB->find_text(selectedInfo.GetDisplayName());
902 m_xIconStyleLB->set_active(nStyleLB_InitialSelection);
903 m_xIconStyleLB->save_value();
905 m_xAppearanceStyleLB->set_active(officecfg::Office::Common::Misc::Appearance::get());
906 m_xAppearanceStyleLB->save_value();
908 // Middle Mouse Button
909 sal_Int16 nMiddleMouseButton = officecfg::Office::Common::View::Dialog::MiddleMouseButton::get();
910 m_xMouseMiddleLB->set_active(static_cast<short>(nMiddleMouseButton));
911 m_xMouseMiddleLB->save_value();
913 bool bFontAntiAliasing = officecfg::Office::Common::View::FontAntiAliasing::Enabled::get();
914 m_xFontAntiAliasing->set_active( bFontAntiAliasing );
915 sal_Int16 nFontAntiAliasingMinPixelHeight = officecfg::Office::Common::View::FontAntiAliasing::MinPixelHeight::get();
916 m_xAAPointLimit->set_value(nFontAntiAliasingMinPixelHeight, FieldUnit::PIXEL);
918 // WorkingSet
919 m_xFontShowCB->set_active(officecfg::Office::Common::Font::View::ShowFontBoxWYSIWYG::get());
921 UpdateHardwareAccelStatus();
922 m_xUseHardwareAccell->save_state();
924 { // #i95644# AntiAliasing
925 if(SvtOptionsDrawinglayer::IsAAPossibleOnThisSystem())
927 m_xUseAntiAliase->set_active(SvtOptionsDrawinglayer::IsAntiAliasing());
929 else
931 m_xUseAntiAliase->set_active(false);
932 m_xUseAntiAliase->set_sensitive(false);
935 m_xUseAntiAliase->save_state();
938 m_xUseSkia->set_active(officecfg::Office::Common::VCL::UseSkia::get());
939 m_xForceSkiaRaster->set_active(officecfg::Office::Common::VCL::ForceSkiaRaster::get());
940 m_xUseSkia->save_state();
941 m_xForceSkiaRaster->save_state();
943 m_xFontAntiAliasing->save_state();
944 m_xAAPointLimit->save_value();
945 m_xFontShowCB->save_state();
947 OnAntialiasingToggled(*m_xFontAntiAliasing);
948 UpdateSkiaStatus();
951 void OfaViewTabPage::UpdateHardwareAccelStatus()
953 // #i95644# HW accel (unified to disable mechanism)
954 if(pCanvasSettings->IsHardwareAccelerationAvailable())
956 m_xUseHardwareAccell->set_active(pCanvasSettings->IsHardwareAccelerationEnabled());
957 m_xUseHardwareAccell->set_sensitive(!pCanvasSettings->IsHardwareAccelerationRO());
959 else
961 m_xUseHardwareAccell->set_active(false);
962 m_xUseHardwareAccell->set_sensitive(false);
964 #if HAVE_FEATURE_SKIA
965 m_xUseHardwareAccell->set_sensitive(!m_xUseSkia->get_active());
966 #endif
969 struct LanguageConfig_Impl
971 SvtCTLOptions aCTLLanguageOptions;
972 SvtSysLocaleOptions aSysLocaleOptions;
973 SvtLinguConfig aLinguConfig;
976 static bool bLanguageCurrentDoc_Impl = false;
978 // some things we'll need...
979 constexpr OUStringLiteral sAccessSrvc = u"com.sun.star.configuration.ConfigurationAccess";
980 constexpr OUStringLiteral sAccessUpdSrvc = u"com.sun.star.configuration.ConfigurationUpdateAccess";
981 constexpr OUStringLiteral sInstalledLocalesPath = u"org.openoffice.Setup/Office/InstalledLocales";
982 constexpr OUStringLiteral sUserLocalePath = u"org.openoffice.Office.Linguistic/General";
983 constexpr OUStringLiteral sUserLocaleKey = u"UILocale";
984 static Sequence< OUString > seqInstalledLanguages;
986 static OUString lcl_getDatePatternsConfigString( const LocaleDataWrapper& rLocaleWrapper )
988 Sequence< OUString > aDateAcceptancePatterns = rLocaleWrapper.getDateAcceptancePatterns();
989 sal_Int32 nPatterns = aDateAcceptancePatterns.getLength();
990 OUStringBuffer aBuf( nPatterns * 6 ); // 6 := length of Y-M-D;
991 SAL_WARN_IF( !nPatterns, "cui.options", "No date acceptance pattern");
992 if (nPatterns)
994 const OUString* pPatterns = aDateAcceptancePatterns.getConstArray();
995 aBuf.append( pPatterns[0]);
996 for (sal_Int32 i=1; i < nPatterns; ++i)
997 aBuf.append(";" + pPatterns[i]);
999 return aBuf.makeStringAndClear();
1002 namespace
1004 //what ui language will be selected by default if the user override of General::UILocale is unset ?
1005 LanguageTag GetInstalledLocaleForSystemUILanguage()
1007 css::uno::Sequence<OUString> inst(officecfg::Setup::Office::InstalledLocales::get()->getElementNames());
1008 return LanguageTag(getInstalledLocaleForSystemUILanguage(inst, false)).makeFallback();
1012 OfaLanguagesTabPage::OfaLanguagesTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
1013 : SfxTabPage(pPage, pController, "cui/ui/optlanguagespage.ui", "OptLanguagesPage", &rSet)
1014 , pLangConfig(new LanguageConfig_Impl)
1015 , m_bDatePatternsValid(false)
1016 , m_xUserInterfaceLB(m_xBuilder->weld_combo_box("userinterface"))
1017 , m_xLocaleSettingFT(m_xBuilder->weld_label("localesettingFT"))
1018 , m_xLocaleSettingLB(new SvxLanguageBox(m_xBuilder->weld_combo_box("localesetting")))
1019 , m_xDecimalSeparatorCB(m_xBuilder->weld_check_button("decimalseparator"))
1020 , m_xCurrencyFT(m_xBuilder->weld_label("defaultcurrency"))
1021 , m_xCurrencyLB(m_xBuilder->weld_combo_box("currencylb"))
1022 , m_xDatePatternsFT(m_xBuilder->weld_label("dataaccpatterns"))
1023 , m_xDatePatternsED(m_xBuilder->weld_entry("datepatterns"))
1024 , m_xWesternLanguageLB(new SvxLanguageBox(m_xBuilder->weld_combo_box("westernlanguage")))
1025 , m_xWesternLanguageFT(m_xBuilder->weld_label("western"))
1026 , m_xAsianLanguageLB(new SvxLanguageBox(m_xBuilder->weld_combo_box("asianlanguage")))
1027 , m_xComplexLanguageLB(new SvxLanguageBox(m_xBuilder->weld_combo_box("complexlanguage")))
1028 , m_xCurrentDocCB(m_xBuilder->weld_check_button("currentdoc"))
1029 , m_xAsianSupportCB(m_xBuilder->weld_check_button("asiansupport"))
1030 , m_xCTLSupportCB(m_xBuilder->weld_check_button("ctlsupport"))
1031 , m_xIgnoreLanguageChangeCB(m_xBuilder->weld_check_button("ignorelanguagechange"))
1033 // tdf#125483 save original default label
1034 m_sDecimalSeparatorLabel = m_xDecimalSeparatorCB->get_label();
1036 // initialize user interface language selection
1037 m_sSystemDefaultString = SvtLanguageTable::GetLanguageString( LANGUAGE_SYSTEM );
1039 OUString aUILang = m_sSystemDefaultString +
1040 " - " +
1041 SvtLanguageTable::GetLanguageString(GetInstalledLocaleForSystemUILanguage().getLanguageType());
1043 m_xUserInterfaceLB->append("0", aUILang);
1044 m_xUserInterfaceLB->append_separator("");
1047 Reference< XMultiServiceFactory > theConfigProvider(
1048 css::configuration::theDefaultProvider::get(
1049 comphelper::getProcessComponentContext()));
1050 // find out which locales are currently installed and add them to the listbox
1051 Sequence< Any > theArgs{ Any(NamedValue("nodepath", Any(OUString(sInstalledLocalesPath)))) };
1052 Reference< XNameAccess > theNameAccess(
1053 theConfigProvider->createInstanceWithArguments(sAccessSrvc, theArgs ), UNO_QUERY_THROW );
1054 seqInstalledLanguages = theNameAccess->getElementNames();
1055 LanguageType aLang = LANGUAGE_DONTKNOW;
1056 std::vector< std::pair<sal_Int32, OUString> > aUILanguages;
1057 for (sal_Int32 i=0; i<seqInstalledLanguages.getLength(); i++)
1059 aLang = LanguageTag::convertToLanguageTypeWithFallback(seqInstalledLanguages[i]);
1060 if (aLang != LANGUAGE_DONTKNOW)
1062 OUString aLangStr( SvtLanguageTable::GetLanguageString( aLang ) );
1063 aUILanguages.emplace_back(i+1, aLangStr);
1067 std::sort(aUILanguages.begin(), aUILanguages.end(), [](const auto& l1, const auto& l2) {
1068 static const auto aSorter = comphelper::string::NaturalStringSorter(
1069 comphelper::getProcessComponentContext(),
1070 Application::GetSettings().GetUILanguageTag().getLocale());
1071 return aSorter.compare(l1.second, l2.second) < 0;
1074 // tdf#114694: append the sorted list after the default entry and separator.
1075 for (const auto & [ nGroupID, sGroupName ] : aUILanguages)
1077 m_xUserInterfaceLB->append(OUString::number(nGroupID), sGroupName);
1080 m_xUserInterfaceLB->set_active(0);
1082 // find out whether the user has a specific locale specified
1083 Sequence< Any > theArgs2{ Any(NamedValue("nodepath", Any(OUString(sUserLocalePath)))) };
1084 theNameAccess.set(
1085 theConfigProvider->createInstanceWithArguments(sAccessSrvc, theArgs2 ), UNO_QUERY_THROW );
1086 if (theNameAccess->hasByName(sUserLocaleKey))
1087 theNameAccess->getByName(sUserLocaleKey) >>= m_sUserLocaleValue;
1088 // select the user specified locale in the listbox
1089 if (!m_sUserLocaleValue.isEmpty())
1091 for (sal_Int32 i = 0, nEntryCount = m_xUserInterfaceLB->get_count(); i < nEntryCount; ++i)
1093 sal_Int32 d = m_xUserInterfaceLB->get_id(i).toInt32();
1094 if ( d > 0 && seqInstalledLanguages.getLength() > d-1 && seqInstalledLanguages[d-1] == m_sUserLocaleValue)
1095 m_xUserInterfaceLB->set_active(i);
1100 catch (const Exception &)
1102 // we'll just leave the box in its default setting and won't
1103 // even give it event handler...
1104 TOOLS_WARN_EXCEPTION("cui.options", "ignoring" );
1107 m_xWesternLanguageLB->SetLanguageList(
1108 SvxLanguageListFlags::WESTERN | SvxLanguageListFlags::ONLY_KNOWN, true, false, true, true,
1109 LANGUAGE_SYSTEM, css::i18n::ScriptType::LATIN);
1111 m_xAsianLanguageLB->SetLanguageList(
1112 SvxLanguageListFlags::CJK | SvxLanguageListFlags::ONLY_KNOWN, true, false, true, true,
1113 LANGUAGE_SYSTEM, css::i18n::ScriptType::ASIAN);
1115 m_xComplexLanguageLB->SetLanguageList(
1116 SvxLanguageListFlags::CTL | SvxLanguageListFlags::ONLY_KNOWN, true, false, true, true,
1117 LANGUAGE_SYSTEM, css::i18n::ScriptType::COMPLEX);
1119 m_xLocaleSettingLB->SetLanguageList(
1120 SvxLanguageListFlags::ALL | SvxLanguageListFlags::ONLY_KNOWN, false, false, false, true,
1121 LANGUAGE_USER_SYSTEM_CONFIG, css::i18n::ScriptType::WEAK);
1123 const NfCurrencyTable& rCurrTab = SvNumberFormatter::GetTheCurrencyTable();
1124 const NfCurrencyEntry& rCurr = SvNumberFormatter::GetCurrencyEntry( LANGUAGE_SYSTEM );
1125 // insert SYSTEM entry
1126 OUString aDefaultCurr = m_sSystemDefaultString + " - " + rCurr.GetBankSymbol();
1127 m_xCurrencyLB->append("default", aDefaultCurr);
1128 m_xCurrencyLB->append_separator("");
1130 assert(m_xCurrencyLB->find_id("default") != -1);
1131 // all currencies
1132 OUString aTwoSpace( " " );
1133 sal_uInt16 nCurrCount = rCurrTab.size();
1134 std::vector< const NfCurrencyEntry* > aCurrencies;
1135 // first entry is SYSTEM, skip it
1136 for ( sal_uInt16 j=1; j < nCurrCount; ++j )
1138 aCurrencies.push_back(&rCurrTab[j]);
1140 std::sort(aCurrencies.begin(), aCurrencies.end(),
1141 [](const NfCurrencyEntry* c1, const NfCurrencyEntry* c2) {
1142 return c1->GetBankSymbol().compareTo(c2->GetBankSymbol()) < 0;
1145 for (auto &v : aCurrencies)
1147 OUString aStr_ = v->GetBankSymbol() +
1148 aTwoSpace +
1149 v->GetSymbol();
1150 aStr_ = ApplyLreOrRleEmbedding( aStr_ ) +
1151 aTwoSpace +
1152 ApplyLreOrRleEmbedding( SvtLanguageTable::GetLanguageString( v->GetLanguage() ) );
1153 m_xCurrencyLB->append(weld::toId(v), aStr_);
1156 m_xCurrencyLB->set_active(0);
1158 m_xLocaleSettingLB->connect_changed( LINK( this, OfaLanguagesTabPage, LocaleSettingHdl ) );
1159 m_xDatePatternsED->connect_changed( LINK( this, OfaLanguagesTabPage, DatePatternsHdl ) );
1161 Link<weld::Toggleable&,void> aLink( LINK( this, OfaLanguagesTabPage, SupportHdl ) );
1162 m_xAsianSupportCB->connect_toggled( aLink );
1163 m_xCTLSupportCB->connect_toggled( aLink );
1165 m_bOldAsian = SvtCJKOptions::IsAnyEnabled();
1166 m_xAsianSupportCB->set_active(m_bOldAsian);
1167 m_xAsianSupportCB->save_state();
1168 bool bReadonly = SvtCJKOptions::IsReadOnly(SvtCJKOptions::E_ALL);
1169 m_xAsianSupportCB->set_sensitive(!bReadonly);
1170 SupportHdl(*m_xAsianSupportCB);
1172 m_bOldCtl = SvtCTLOptions::IsCTLFontEnabled();
1173 m_xCTLSupportCB->set_active(m_bOldCtl);
1174 m_xCTLSupportCB->save_state();
1175 bReadonly = pLangConfig->aCTLLanguageOptions.IsReadOnly(SvtCTLOptions::E_CTLFONT);
1176 m_xCTLSupportCB->set_sensitive(!bReadonly);
1177 SupportHdl(*m_xCTLSupportCB);
1179 m_xIgnoreLanguageChangeCB->set_active( pLangConfig->aSysLocaleOptions.IsIgnoreLanguageChange() );
1182 OfaLanguagesTabPage::~OfaLanguagesTabPage()
1186 std::unique_ptr<SfxTabPage> OfaLanguagesTabPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet )
1188 return std::make_unique<OfaLanguagesTabPage>(pPage, pController, *rAttrSet);
1191 static void lcl_Update(std::unique_ptr<SfxVoidItem> pInvalidItems[], std::unique_ptr<SfxBoolItem> pBoolItems[], sal_uInt16 nCount)
1193 SfxViewFrame* pCurrentFrm = SfxViewFrame::Current();
1194 SfxViewFrame* pViewFrm = SfxViewFrame::GetFirst();
1195 while(pViewFrm)
1197 SfxBindings& rBind = pViewFrm->GetBindings();
1198 for(sal_uInt16 i = 0; i < nCount; i++)
1200 if(pCurrentFrm == pViewFrm)
1201 rBind.InvalidateAll(false);
1202 rBind.SetState( *pInvalidItems[i] );
1203 rBind.SetState( *pBoolItems[i] );
1205 pViewFrm = SfxViewFrame::GetNext(*pViewFrm);
1209 bool OfaLanguagesTabPage::FillItemSet( SfxItemSet* rSet )
1211 // lock configuration broadcasters so that we can coordinate the notifications
1212 pLangConfig->aSysLocaleOptions.BlockBroadcasts( true );
1213 pLangConfig->aCTLLanguageOptions.BlockBroadcasts( true );
1214 pLangConfig->aLinguConfig.BlockBroadcasts( true );
1217 * Sequence checking only matters when CTL support is enabled.
1219 * So we only need to check for sequence checking if
1220 * a) previously it was unchecked and is now checked or
1221 * b) it was already checked but the CTL language has changed
1223 if (
1224 m_xCTLSupportCB->get_active() &&
1225 (m_xCTLSupportCB->get_saved_state() != TRISTATE_TRUE ||
1226 m_xComplexLanguageLB->get_active_id_changed_from_saved())
1229 //sequence checking has to be switched on depending on the selected CTL language
1230 LanguageType eCTLLang = m_xComplexLanguageLB->get_active_id();
1231 bool bOn = MsLangId::needsSequenceChecking( eCTLLang);
1232 pLangConfig->aCTLLanguageOptions.SetCTLSequenceCheckingRestricted(bOn);
1233 pLangConfig->aCTLLanguageOptions.SetCTLSequenceChecking(bOn);
1234 pLangConfig->aCTLLanguageOptions.SetCTLSequenceCheckingTypeAndReplace(bOn);
1238 // handle settings for UI Language
1239 // a change of setting needs to bring up a warning message
1240 OUString aLangString;
1241 sal_Int32 d = m_xUserInterfaceLB->get_active_id().toInt32();
1242 if( d > 0 && seqInstalledLanguages.getLength() > d-1)
1243 aLangString = seqInstalledLanguages[d-1];
1246 if( m_xUserInterfaceLB->GetSelectedEntryPos() > 0)
1247 aLangString = ConvertLanguageToIsoString(m_xUserInterfaceLB->get_active_id());
1249 Reference< XMultiServiceFactory > theConfigProvider(
1250 css::configuration::theDefaultProvider::get(
1251 comphelper::getProcessComponentContext()));
1252 Sequence< Any > theArgs{ Any(NamedValue("nodepath", Any(OUString(sUserLocalePath)))) };
1253 Reference< XPropertySet >xProp(
1254 theConfigProvider->createInstanceWithArguments(sAccessUpdSrvc, theArgs ), UNO_QUERY_THROW );
1255 if ( m_sUserLocaleValue != aLangString)
1257 // OSL_FAIL("UserInterface language was changed, restart.");
1258 // write new value
1259 xProp->setPropertyValue(sUserLocaleKey, Any(aLangString));
1260 Reference< XChangesBatch >(xProp, UNO_QUERY_THROW)->commitChanges();
1261 // display info
1262 SolarMutexGuard aGuard;
1263 if (svtools::executeRestartDialog(
1264 comphelper::getProcessComponentContext(), GetFrameWeld(),
1265 svtools::RESTART_REASON_LANGUAGE_CHANGE))
1266 GetDialogController()->response(RET_OK);
1268 // tell quickstarter to stop being a veto listener
1270 Reference< XComponentContext > xContext(
1271 comphelper::getProcessComponentContext());
1272 css::office::Quickstart::createAndSetVeto(xContext, false, false, false/*DisableVeto*/);
1275 catch (const Exception&)
1277 // we'll just leave the box in its default setting and won't
1278 // even give it event handler...
1279 TOOLS_WARN_EXCEPTION("cui.options", "ignoring");
1282 LanguageTag aLanguageTag( pLangConfig->aSysLocaleOptions.GetLanguageTag());
1283 LanguageType eOldLocale = (aLanguageTag.isSystemLocale() ? LANGUAGE_SYSTEM :
1284 aLanguageTag.makeFallback().getLanguageType());
1285 LanguageType eNewLocale = m_xLocaleSettingLB->get_active_id();
1287 // If the "Default ..." entry was selected that means SYSTEM, the actual
1288 // eNewLocale value is temporary for the dialog only, do not resolve to
1289 // what system currently is.
1290 if (eNewLocale == LANGUAGE_USER_SYSTEM_CONFIG)
1291 eNewLocale = LANGUAGE_SYSTEM;
1293 if ( eOldLocale != eNewLocale )
1295 // an empty string denotes SYSTEM locale
1296 OUString sNewLang;
1297 if ( eNewLocale != LANGUAGE_SYSTEM )
1298 sNewLang = LanguageTag::convertToBcp47( eNewLocale);
1300 // locale nowadays get to AppSettings via notification
1301 // this will happen after releasing the lock on the ConfigurationBroadcaster at
1302 // the end of this method
1303 pLangConfig->aSysLocaleOptions.SetLocaleConfigString( sNewLang );
1304 rSet->Put( SfxBoolItem( SID_OPT_LOCALE_CHANGED, true ) );
1306 SvtScriptType nNewType = SvtLanguageOptions::GetScriptTypeOfLanguage( eNewLocale );
1307 bool bNewCJK = bool( nNewType & SvtScriptType::ASIAN );
1308 SvtCompatibilityOptions aCompatOpts;
1309 aCompatOpts.SetDefault( SvtCompatibilityEntry::Index::ExpandWordSpace, !bNewCJK );
1312 if(m_xDecimalSeparatorCB->get_state_changed_from_saved())
1313 pLangConfig->aSysLocaleOptions.SetDecimalSeparatorAsLocale(m_xDecimalSeparatorCB->get_active());
1315 if(m_xIgnoreLanguageChangeCB->get_state_changed_from_saved())
1316 pLangConfig->aSysLocaleOptions.SetIgnoreLanguageChange(m_xIgnoreLanguageChangeCB->get_active());
1318 // Configured currency, for example, USD-en-US or EUR-de-DE, or empty for locale default.
1319 OUString sOldCurr = pLangConfig->aSysLocaleOptions.GetCurrencyConfigString();
1320 OUString sId = m_xCurrencyLB->get_active_id();
1321 const NfCurrencyEntry* pCurr = sId == "default" ? nullptr : weld::fromId<const NfCurrencyEntry*>(sId);
1322 OUString sNewCurr;
1323 if ( pCurr )
1324 sNewCurr = SvtSysLocaleOptions::CreateCurrencyConfigString(
1325 pCurr->GetBankSymbol(), pCurr->GetLanguage() );
1326 if ( sOldCurr != sNewCurr )
1327 pLangConfig->aSysLocaleOptions.SetCurrencyConfigString( sNewCurr );
1329 // Configured date acceptance patterns, for example Y-M-D;M-D or empty for
1330 // locale default.
1331 if (m_bDatePatternsValid && m_xDatePatternsED->get_value_changed_from_saved())
1332 pLangConfig->aSysLocaleOptions.SetDatePatternsConfigString( m_xDatePatternsED->get_text());
1334 SfxObjectShell* pCurrentDocShell = SfxObjectShell::Current();
1335 Reference< css::linguistic2::XLinguProperties > xLinguProp = LinguMgr::GetLinguPropertySet();
1336 bool bCurrentDocCBChecked = m_xCurrentDocCB->get_active();
1337 if (m_xCurrentDocCB->get_sensitive())
1338 bLanguageCurrentDoc_Impl = bCurrentDocCBChecked;
1339 bool bCurrentDocCBChanged = m_xCurrentDocCB->get_state_changed_from_saved();
1341 bool bValChanged = m_xWesternLanguageLB->get_active_id_changed_from_saved();
1342 if( (bCurrentDocCBChanged && !bCurrentDocCBChecked) || bValChanged)
1344 LanguageType eSelectLang = m_xWesternLanguageLB->get_active_id();
1345 if(!bCurrentDocCBChecked)
1347 Any aValue;
1348 Locale aLocale = LanguageTag::convertToLocale( eSelectLang, false);
1349 aValue <<= aLocale;
1350 pLangConfig->aLinguConfig.SetProperty( u"DefaultLocale", aValue );
1351 if (xLinguProp.is())
1352 xLinguProp->setDefaultLocale( aLocale );
1354 if(pCurrentDocShell)
1356 rSet->Put(SvxLanguageItem(MsLangId::resolveSystemLanguageByScriptType(eSelectLang, css::i18n::ScriptType::LATIN),
1357 SID_ATTR_LANGUAGE));
1360 bValChanged = m_xAsianLanguageLB->get_active_id_changed_from_saved();
1361 if( (bCurrentDocCBChanged && !bCurrentDocCBChecked) || bValChanged)
1363 LanguageType eSelectLang = m_xAsianLanguageLB->get_active_id();
1364 if(!bCurrentDocCBChecked)
1366 Any aValue;
1367 Locale aLocale = LanguageTag::convertToLocale( eSelectLang, false);
1368 aValue <<= aLocale;
1369 pLangConfig->aLinguConfig.SetProperty( u"DefaultLocale_CJK", aValue );
1370 if (xLinguProp.is())
1371 xLinguProp->setDefaultLocale_CJK( aLocale );
1373 if(pCurrentDocShell)
1375 rSet->Put(SvxLanguageItem(MsLangId::resolveSystemLanguageByScriptType(eSelectLang, css::i18n::ScriptType::ASIAN),
1376 SID_ATTR_CHAR_CJK_LANGUAGE));
1379 bValChanged = m_xComplexLanguageLB->get_active_id_changed_from_saved();
1380 if( (bCurrentDocCBChanged && !bCurrentDocCBChecked) || bValChanged)
1382 LanguageType eSelectLang = m_xComplexLanguageLB->get_active_id();
1383 if(!bCurrentDocCBChecked)
1385 Any aValue;
1386 Locale aLocale = LanguageTag::convertToLocale( eSelectLang, false);
1387 aValue <<= aLocale;
1388 pLangConfig->aLinguConfig.SetProperty( u"DefaultLocale_CTL", aValue );
1389 if (xLinguProp.is())
1390 xLinguProp->setDefaultLocale_CTL( aLocale );
1392 if(pCurrentDocShell)
1394 rSet->Put(SvxLanguageItem(MsLangId::resolveSystemLanguageByScriptType(eSelectLang, css::i18n::ScriptType::COMPLEX),
1395 SID_ATTR_CHAR_CTL_LANGUAGE));
1399 if(m_xAsianSupportCB->get_state_changed_from_saved() )
1401 bool bChecked = m_xAsianSupportCB->get_active();
1402 SvtCJKOptions::SetAll(bChecked);
1404 //iterate over all bindings to invalidate vertical text direction
1405 const sal_uInt16 STATE_COUNT = 2;
1407 std::unique_ptr<SfxBoolItem> pBoolItems[STATE_COUNT];
1408 pBoolItems[0].reset(new SfxBoolItem(SID_VERTICALTEXT_STATE, false));
1409 pBoolItems[1].reset(new SfxBoolItem(SID_TEXT_FITTOSIZE_VERTICAL, false));
1411 std::unique_ptr<SfxVoidItem> pInvalidItems[STATE_COUNT];
1412 pInvalidItems[0].reset(new SfxVoidItem(SID_VERTICALTEXT_STATE));
1413 pInvalidItems[1].reset(new SfxVoidItem(SID_TEXT_FITTOSIZE_VERTICAL));
1415 lcl_Update(pInvalidItems, pBoolItems, STATE_COUNT);
1418 if ( m_xCTLSupportCB->get_state_changed_from_saved() )
1420 SvtSearchOptions aOpt;
1421 aOpt.SetIgnoreDiacritics_CTL(true);
1422 aOpt.SetIgnoreKashida_CTL(true);
1423 aOpt.Commit();
1424 pLangConfig->aCTLLanguageOptions.SetCTLFontEnabled( m_xCTLSupportCB->get_active() );
1426 const sal_uInt16 STATE_COUNT = 1;
1427 std::unique_ptr<SfxBoolItem> pBoolItems[STATE_COUNT];
1428 pBoolItems[0].reset(new SfxBoolItem(SID_CTLFONT_STATE, false));
1429 std::unique_ptr<SfxVoidItem> pInvalidItems[STATE_COUNT];
1430 pInvalidItems[0].reset(new SfxVoidItem(SID_CTLFONT_STATE));
1431 lcl_Update(pInvalidItems, pBoolItems, STATE_COUNT);
1434 if ( pLangConfig->aSysLocaleOptions.IsModified() )
1435 pLangConfig->aSysLocaleOptions.Commit();
1437 // first release the lock on the ConfigurationBroadcaster for Locale changes
1438 // it seems that our code relies on the fact that before other changes like e.g. currency
1439 // are broadcasted locale changes have been done
1440 pLangConfig->aSysLocaleOptions.BlockBroadcasts( false );
1441 pLangConfig->aCTLLanguageOptions.BlockBroadcasts( false );
1442 pLangConfig->aLinguConfig.BlockBroadcasts( false );
1444 return false;
1447 void OfaLanguagesTabPage::Reset( const SfxItemSet* rSet )
1449 LanguageTag aLanguageTag( pLangConfig->aSysLocaleOptions.GetLanguageTag());
1450 if ( aLanguageTag.isSystemLocale() )
1451 m_xLocaleSettingLB->set_active_id( LANGUAGE_USER_SYSTEM_CONFIG );
1452 else
1453 m_xLocaleSettingLB->set_active_id( aLanguageTag.makeFallback().getLanguageType());
1454 bool bReadonly = pLangConfig->aSysLocaleOptions.IsReadOnly(SvtSysLocaleOptions::EOption::Locale);
1455 m_xLocaleSettingLB->set_sensitive(!bReadonly);
1456 m_xLocaleSettingFT->set_sensitive(!bReadonly);
1459 m_xDecimalSeparatorCB->set_active( pLangConfig->aSysLocaleOptions.IsDecimalSeparatorAsLocale());
1460 m_xDecimalSeparatorCB->save_state();
1462 m_xIgnoreLanguageChangeCB->set_active( pLangConfig->aSysLocaleOptions.IsIgnoreLanguageChange());
1463 m_xIgnoreLanguageChangeCB->save_state();
1465 // let LocaleSettingHdl enable/disable checkboxes for CJK/CTL support
1466 // #i15812# must be done *before* the configured currency is set
1467 // and update the decimal separator used for the given locale
1468 LocaleSettingHdl(*m_xLocaleSettingLB->get_widget());
1470 // configured currency, for example, USD-en-US or EUR-de-DE, or empty for locale default
1471 const NfCurrencyEntry* pCurr = nullptr;
1472 OUString sCurrency = pLangConfig->aSysLocaleOptions.GetCurrencyConfigString();
1473 if ( !sCurrency.isEmpty() )
1475 LanguageType eLang;
1476 OUString aAbbrev;
1477 SvtSysLocaleOptions::GetCurrencyAbbrevAndLanguage( aAbbrev, eLang, sCurrency );
1478 pCurr = SvNumberFormatter::GetCurrencyEntry( aAbbrev, eLang );
1480 // if pCurr==nullptr the SYSTEM entry is selected
1481 OUString sId = !pCurr ? OUString("default") : weld::toId(pCurr);
1482 m_xCurrencyLB->set_active_id(sId);
1483 bReadonly = pLangConfig->aSysLocaleOptions.IsReadOnly(SvtSysLocaleOptions::EOption::Currency);
1484 m_xCurrencyLB->set_sensitive(!bReadonly);
1485 m_xCurrencyFT->set_sensitive(!bReadonly);
1487 // date acceptance patterns
1488 OUString aDatePatternsString = pLangConfig->aSysLocaleOptions.GetDatePatternsConfigString();
1489 if (aDatePatternsString.isEmpty())
1491 const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
1492 aDatePatternsString = lcl_getDatePatternsConfigString( rLocaleWrapper);
1493 // Let's assume patterns are valid at this point.
1494 m_bDatePatternsValid = true;
1496 else
1498 bool bModified = false;
1499 m_bDatePatternsValid = validateDatePatterns( bModified, aDatePatternsString);
1501 m_xDatePatternsED->set_text(aDatePatternsString);
1502 m_xDatePatternsED->set_message_type( m_bDatePatternsValid ?
1503 weld::EntryMessageType::Normal : weld::EntryMessageType::Error);
1504 bReadonly = pLangConfig->aSysLocaleOptions.IsReadOnly(SvtSysLocaleOptions::EOption::DatePatterns);
1505 m_xDatePatternsED->set_sensitive(!bReadonly);
1506 m_xDatePatternsFT->set_sensitive(!bReadonly);
1507 m_xDatePatternsED->save_value();
1509 //western/CJK/CLK language
1510 LanguageType eCurLang = LANGUAGE_NONE;
1511 LanguageType eCurLangCJK = LANGUAGE_NONE;
1512 LanguageType eCurLangCTL = LANGUAGE_NONE;
1513 SfxObjectShell* pCurrentDocShell = SfxObjectShell::Current();
1514 //collect the configuration values first
1515 m_xCurrentDocCB->set_sensitive(false);
1517 Any aWestLang;
1518 Any aCJKLang;
1519 Any aCTLLang;
1522 aWestLang = pLangConfig->aLinguConfig.GetProperty(u"DefaultLocale");
1523 Locale aLocale;
1524 aWestLang >>= aLocale;
1526 eCurLang = LanguageTag::convertToLanguageType( aLocale, false);
1528 aCJKLang = pLangConfig->aLinguConfig.GetProperty(u"DefaultLocale_CJK");
1529 aLocale = Locale();
1530 aCJKLang >>= aLocale;
1531 eCurLangCJK = LanguageTag::convertToLanguageType( aLocale, false);
1533 aCTLLang = pLangConfig->aLinguConfig.GetProperty(u"DefaultLocale_CTL");
1534 aLocale = Locale();
1535 aCTLLang >>= aLocale;
1536 eCurLangCTL = LanguageTag::convertToLanguageType( aLocale, false);
1538 catch (const Exception&)
1541 //overwrite them by the values provided by the DocShell
1542 if(pCurrentDocShell)
1544 m_xCurrentDocCB->set_sensitive(true);
1545 m_xCurrentDocCB->set_active(bLanguageCurrentDoc_Impl);
1546 if( const SvxLanguageItem* pLangItem = rSet->GetItemIfSet(SID_ATTR_LANGUAGE, false))
1548 LanguageType eTempCurLang = pLangItem->GetValue();
1549 if (MsLangId::resolveSystemLanguageByScriptType(eCurLang, css::i18n::ScriptType::LATIN) != eTempCurLang)
1550 eCurLang = eTempCurLang;
1553 if( const SvxLanguageItem* pLang = rSet->GetItemIfSet(SID_ATTR_CHAR_CJK_LANGUAGE, false))
1555 LanguageType eTempCurLang = pLang->GetValue();
1556 if (MsLangId::resolveSystemLanguageByScriptType(eCurLangCJK, css::i18n::ScriptType::ASIAN) != eTempCurLang)
1557 eCurLangCJK = eTempCurLang;
1560 if( const SvxLanguageItem* pLang = rSet->GetItemIfSet(SID_ATTR_CHAR_CTL_LANGUAGE, false))
1562 LanguageType eTempCurLang = pLang->GetValue();
1563 if (MsLangId::resolveSystemLanguageByScriptType(eCurLangCTL, css::i18n::ScriptType::COMPLEX) != eTempCurLang)
1564 eCurLangCTL = eTempCurLang;
1567 if(LANGUAGE_NONE == eCurLang || LANGUAGE_DONTKNOW == eCurLang)
1568 m_xWesternLanguageLB->set_active_id(LANGUAGE_NONE);
1569 else
1570 m_xWesternLanguageLB->set_active_id(eCurLang);
1572 if(LANGUAGE_NONE == eCurLangCJK || LANGUAGE_DONTKNOW == eCurLangCJK)
1573 m_xAsianLanguageLB->set_active_id(LANGUAGE_NONE);
1574 else
1575 m_xAsianLanguageLB->set_active_id(eCurLangCJK);
1577 if(LANGUAGE_NONE == eCurLangCTL || LANGUAGE_DONTKNOW == eCurLangCTL)
1578 m_xComplexLanguageLB->set_active_id(LANGUAGE_NONE);
1579 else
1580 m_xComplexLanguageLB->set_active_id(eCurLangCTL);
1582 m_xWesternLanguageLB->save_active_id();
1583 m_xAsianLanguageLB->save_active_id();
1584 m_xComplexLanguageLB->save_active_id();
1585 m_xIgnoreLanguageChangeCB->save_state();
1586 m_xCurrentDocCB->save_state();
1588 bool bEnable = !pLangConfig->aLinguConfig.IsReadOnly( u"DefaultLocale" );
1589 m_xWesternLanguageFT->set_sensitive( bEnable );
1590 m_xWesternLanguageLB->set_sensitive( bEnable );
1592 // check the box "For the current document only"
1593 // set the focus to the Western Language box
1594 const SfxBoolItem* pLang = rSet->GetItemIfSet(SID_SET_DOCUMENT_LANGUAGE, false );
1595 if ( pLang && pLang->GetValue() )
1597 m_xWesternLanguageLB->grab_focus();
1598 m_xCurrentDocCB->set_sensitive(true);
1599 m_xCurrentDocCB->set_active(true);
1603 IMPL_LINK(OfaLanguagesTabPage, SupportHdl, weld::Toggleable&, rBox, void)
1605 bool bCheck = rBox.get_active();
1606 if ( m_xAsianSupportCB.get() == &rBox )
1608 bool bReadonly = pLangConfig->aLinguConfig.IsReadOnly(u"DefaultLocale_CJK");
1609 bCheck = ( bCheck && !bReadonly );
1610 m_xAsianLanguageLB->set_sensitive( bCheck );
1611 if (rBox.get_sensitive())
1612 m_bOldAsian = bCheck;
1614 else if ( m_xCTLSupportCB.get() == &rBox )
1616 bool bReadonly = pLangConfig->aLinguConfig.IsReadOnly(u"DefaultLocale_CTL");
1617 bCheck = ( bCheck && !bReadonly );
1618 m_xComplexLanguageLB->set_sensitive( bCheck );
1619 if (rBox.get_sensitive())
1620 m_bOldCtl = bCheck;
1622 else
1623 SAL_WARN( "cui.options", "OfaLanguagesTabPage::SupportHdl(): wrong rBox" );
1626 namespace
1628 void lcl_checkLanguageCheckBox(weld::CheckButton& _rCB, bool _bNewValue, bool _bOldValue)
1630 if ( _bNewValue )
1631 _rCB.set_active(true);
1632 else
1633 _rCB.set_active( _bOldValue );
1634 // #i15082# do not call save_state() in running dialog...
1635 // _rCB.save_state();
1636 _rCB.set_sensitive( !_bNewValue );
1640 IMPL_LINK_NOARG(OfaLanguagesTabPage, LocaleSettingHdl, weld::ComboBox&, void)
1642 LanguageType eLang = m_xLocaleSettingLB->get_active_id();
1643 SvtScriptType nType = SvtLanguageOptions::GetScriptTypeOfLanguage(eLang);
1644 // first check if CTL must be enabled
1645 // #103299# - if CTL font setting is not readonly
1646 if(!pLangConfig->aCTLLanguageOptions.IsReadOnly(SvtCTLOptions::E_CTLFONT))
1648 bool bIsCTLFixed = bool(nType & SvtScriptType::COMPLEX);
1649 lcl_checkLanguageCheckBox(*m_xCTLSupportCB, bIsCTLFixed, m_bOldCtl);
1650 SupportHdl(*m_xCTLSupportCB);
1652 // second check if CJK must be enabled
1653 // #103299# - if CJK support is not readonly
1654 if(!SvtCJKOptions::IsReadOnly(SvtCJKOptions::E_ALL))
1656 bool bIsCJKFixed = bool(nType & SvtScriptType::ASIAN);
1657 lcl_checkLanguageCheckBox(*m_xAsianSupportCB, bIsCJKFixed, m_bOldAsian);
1658 SupportHdl(*m_xAsianSupportCB);
1661 const NfCurrencyEntry& rCurr = SvNumberFormatter::GetCurrencyEntry(
1662 (eLang == LANGUAGE_USER_SYSTEM_CONFIG) ? MsLangId::getConfiguredSystemLanguage() : eLang);
1663 const OUString aDefaultID = "default";
1664 // Update the "Default ..." currency.
1665 m_xCurrencyLB->remove_id(aDefaultID);
1666 OUString aDefaultCurr = m_sSystemDefaultString + " - " + rCurr.GetBankSymbol();
1667 m_xCurrencyLB->insert(0, aDefaultCurr, &aDefaultID, nullptr, nullptr);
1668 assert(m_xCurrencyLB->find_id(aDefaultID) != -1);
1669 m_xCurrencyLB->set_active_text(aDefaultCurr);
1671 // obtain corresponding locale data
1672 LocaleDataWrapper aLocaleWrapper(( LanguageTag(eLang) ));
1674 // update the decimal separator key of the related CheckBox
1675 OUString sTempLabel(m_sDecimalSeparatorLabel);
1676 sTempLabel = sTempLabel.replaceFirst("%1", aLocaleWrapper.getNumDecimalSep() );
1677 m_xDecimalSeparatorCB->set_label(sTempLabel);
1679 // update the date acceptance patterns
1680 OUString aDatePatternsString = lcl_getDatePatternsConfigString( aLocaleWrapper);
1681 m_bDatePatternsValid = true;
1682 m_xDatePatternsED->set_text( aDatePatternsString);
1683 m_xDatePatternsED->set_message_type(weld::EntryMessageType::Normal);
1686 IMPL_LINK( OfaLanguagesTabPage, DatePatternsHdl, weld::Entry&, rEd, void )
1688 OUString aPatterns(rEd.get_text());
1689 bool bModified = false;
1690 const bool bValid = validateDatePatterns( bModified, aPatterns);
1691 if (bModified)
1693 // gtk3 keeps the cursor position on equal length set_text() but at
1694 // least the 'gen' backend does not and resets to 0.
1695 const int nCursorPos = rEd.get_position();
1696 rEd.set_text(aPatterns);
1697 rEd.set_position(nCursorPos);
1699 if (bValid)
1700 rEd.set_message_type(weld::EntryMessageType::Normal);
1701 else
1702 rEd.set_message_type(weld::EntryMessageType::Error);
1703 m_bDatePatternsValid = bValid;
1706 bool OfaLanguagesTabPage::validateDatePatterns( bool& rbModified, OUString& rPatterns )
1708 bool bValid = true;
1709 if (!rPatterns.isEmpty())
1711 OUStringBuffer aBuf( rPatterns);
1712 sal_Int32 nChar = 0;
1713 for (sal_Int32 nIndex=0; nIndex >= 0 && bValid; ++nChar)
1715 const OUString aPat( rPatterns.getToken( 0, ';', nIndex));
1716 if (aPat.isEmpty() && nIndex < 0)
1718 // Indicating failure when about to append a pattern is too
1719 // confusing. Empty patterns are ignored anyway when sequencing
1720 // to SvtSysLocale.
1721 continue; // for
1723 else if (aPat.getLength() < 2)
1724 bValid = false;
1725 else
1727 bool bY, bM, bD;
1728 bY = bM = bD = false;
1729 bool bSep = true;
1730 if (aPat.getLength() == 3)
1732 // Disallow a pattern that would match a numeric input with
1733 // decimal separator, like M.D
1734 const LanguageType eLang = m_xLocaleSettingLB->get_active_id();
1735 const LocaleDataWrapper aLocaleWrapper(( LanguageTag(eLang)));
1736 if ( aPat[1] == aLocaleWrapper.getNumDecimalSep().toChar()
1737 || aPat[1] == aLocaleWrapper.getNumDecimalSepAlt().toChar())
1739 bValid = false;
1742 for (sal_Int32 i = 0; i < aPat.getLength() && bValid; /*nop*/)
1744 const sal_Int32 j = i;
1745 const sal_uInt32 c = aPat.iterateCodePoints( &i);
1746 // Only one Y,M,D per pattern, separated by any character(s).
1747 switch (c)
1749 case 'y':
1750 case 'Y':
1751 if (bY || !bSep)
1752 bValid = false;
1753 else if (c == 'y')
1755 aBuf[nChar] = 'Y';
1756 rbModified = true;
1758 bY = true;
1759 bSep = false;
1760 break;
1761 case 'm':
1762 case 'M':
1763 if (bM || !bSep)
1764 bValid = false;
1765 else if (c == 'm')
1767 aBuf[nChar] = 'M';
1768 rbModified = true;
1770 bM = true;
1771 bSep = false;
1772 break;
1773 case 'd':
1774 case 'D':
1775 if (bD || !bSep)
1776 bValid = false;
1777 else if (c == 'd')
1779 aBuf[nChar] = 'D';
1780 rbModified = true;
1782 bD = true;
1783 bSep = false;
1784 break;
1785 default:
1786 // A pattern must not start with a separator (but
1787 // may end with).
1788 if (!(bY || bM || bD))
1789 bValid = false;
1790 bSep = true;
1792 nChar += i-j;
1794 // At least one of Y,M,D
1795 bValid &= (bY || bM || bD);
1798 if (rbModified)
1799 rPatterns = aBuf.makeStringAndClear();
1801 return bValid;
1804 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */