bump product version to 5.0.4.1
[LibreOffice.git] / cui / source / options / optgdlg.cxx
blobf2761e52005aa1dd8dfd6945fa012da5a9d2f907
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 <svl/zforlist.hxx>
21 #include <svl/currencytable.hxx>
22 #include <svtools/grfmgr.hxx>
23 #include <svl/flagitem.hxx>
24 #include <sfx2/dispatch.hxx>
25 #include <unotools/lingucfg.hxx>
26 #include <svl/szitem.hxx>
27 #include <sfx2/viewsh.hxx>
28 #include <sfx2/viewfrm.hxx>
29 #include <sfx2/imgmgr.hxx>
30 #include <vcl/configsettings.hxx>
31 #include <vcl/layout.hxx>
32 #include <vcl/mnemonic.hxx>
33 #include <i18nlangtag/mslangid.hxx>
34 #include <i18nlangtag/languagetag.hxx>
35 #include <unotools/compatibility.hxx>
36 #include <unotools/useroptions.hxx>
37 #include <unotools/fontoptions.hxx>
38 #include <svtools/menuoptions.hxx>
39 #include <svl/languageoptions.hxx>
40 #include <svtools/miscopt.hxx>
41 #include <unotools/printwarningoptions.hxx>
42 #include <unotools/syslocaleoptions.hxx>
43 #include <svtools/accessibilityoptions.hxx>
44 #include <unotools/configitem.hxx>
45 #include <sfx2/objsh.hxx>
46 #include <comphelper/string.hxx>
47 #include <comphelper/types.hxx>
48 #include <svtools/langtab.hxx>
49 #include <unotools/localfilehelper.hxx>
50 #include <unotools/configmgr.hxx>
51 #include "cuioptgenrl.hxx"
52 #include "optpath.hxx"
53 #include "optsave.hxx"
54 #include "optlingu.hxx"
55 #include <svx/xpool.hxx>
56 #include <svx/dlgutil.hxx>
57 #include "cuitabarea.hxx"
58 #include <cuires.hrc>
59 #include <editeng/unolingu.hxx>
60 #include <editeng/langitem.hxx>
61 #include <comphelper/processfactory.hxx>
62 #include <rtl/ustrbuf.hxx>
63 #include <editeng/editids.hrc>
64 #include <svx/svxids.hrc>
65 #include <svl/intitem.hxx>
66 #include <dialmgr.hxx>
67 #include <svtools/helpopt.hxx>
68 #include <unotools/saveopt.hxx>
69 #include <unotools/searchopt.hxx>
70 #include <sal/macros.h>
71 #include <officecfg/Office/Common.hxx>
72 #include <comphelper/configuration.hxx>
74 #include <com/sun/star/configuration/theDefaultProvider.hpp>
75 #include <com/sun/star/container/XNameAccess.hpp>
76 #include <com/sun/star/container/XNameReplace.hpp>
77 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
78 #include <com/sun/star/lang/XComponent.hpp>
79 #include <com/sun/star/lang/XInitialization.hpp>
80 #include <com/sun/star/beans/NamedValue.hpp>
81 #include <com/sun/star/beans/PropertyAttribute.hpp>
82 #include <com/sun/star/beans/XPropertySet.hpp>
83 #include <com/sun/star/util/XChangesBatch.hpp>
84 #include <com/sun/star/uno/Any.hxx>
85 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
86 #include <com/sun/star/container/XSet.hpp>
87 #include <com/sun/star/i18n/ScriptType.hpp>
88 #include <com/sun/star/office/Quickstart.hpp>
90 #include <vcl/svapp.hxx>
91 #include <vcl/settings.hxx>
92 #include <vcl/IconThemeInfo.hxx>
93 #include <vcl/opengl/OpenGLWrapper.hxx>
95 #include "optgdlg.hxx"
96 #include <svx/ofaitem.hxx>
97 #include <svtools/apearcfg.hxx>
98 #include <svtools/optionsdrawinglayer.hxx>
100 #include <config_vclplug.h>
102 using namespace ::com::sun::star::uno;
103 using namespace ::com::sun::star::lang;
104 using namespace ::com::sun::star::beans;
105 using namespace ::com::sun::star::container;
106 using namespace ::com::sun::star::util;
107 using namespace ::utl;
109 namespace svt {
111 class OpenGLCfg
113 private:
114 bool mbUseOpenGL;
115 bool mbForceOpenGL;
116 bool mbModified;
118 public:
119 OpenGLCfg();
120 ~OpenGLCfg();
122 bool useOpenGL() const;
123 bool forceOpenGL() const;
125 void setUseOpenGL(bool bOpenGL);
126 void setForceOpenGL(bool bOpenGL);
128 void reset();
131 OpenGLCfg::OpenGLCfg():
132 mbModified(false)
134 reset();
137 void OpenGLCfg::reset()
139 mbUseOpenGL = officecfg::Office::Common::VCL::UseOpenGL::get();
140 mbForceOpenGL = officecfg::Office::Common::VCL::ForceOpenGL::get();
141 mbModified = false;
144 OpenGLCfg::~OpenGLCfg()
146 if (mbModified)
148 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
149 if (!officecfg::Office::Common::VCL::UseOpenGL::isReadOnly())
150 officecfg::Office::Common::VCL::UseOpenGL::set(mbUseOpenGL, batch);
151 if (!officecfg::Office::Common::VCL::ForceOpenGL::isReadOnly())
152 officecfg::Office::Common::VCL::ForceOpenGL::set(mbForceOpenGL, batch);
153 batch->commit();
157 bool OpenGLCfg::useOpenGL() const
159 return mbUseOpenGL;
162 bool OpenGLCfg::forceOpenGL() const
164 return mbForceOpenGL;
167 void OpenGLCfg::setUseOpenGL(bool bOpenGL)
169 if (bOpenGL != mbUseOpenGL)
171 mbUseOpenGL = bOpenGL;
172 mbModified = true;
176 void OpenGLCfg::setForceOpenGL(bool bOpenGL)
178 if (mbForceOpenGL != bOpenGL)
180 mbForceOpenGL = bOpenGL;
181 mbModified = true;
187 // class OfaMiscTabPage --------------------------------------------------
189 SvxGeneralTabPage::sfxpg OfaMiscTabPage::DeactivatePage( SfxItemSet* pSet_ )
191 if ( pSet_ )
192 FillItemSet( pSet_ );
193 return LEAVE_PAGE;
196 namespace
198 static OUString impl_SystemFileOpenServiceName()
200 const OUString &rDesktopEnvironment = Application::GetDesktopEnvironment();
202 if ( rDesktopEnvironment.equalsIgnoreAsciiCase("kde4") )
204 #if ENABLE_KDE4
205 return OUString("com.sun.star.ui.dialogs.KDE4FilePicker" );
206 #else
207 return OUString();
208 #endif
210 else if ( rDesktopEnvironment.equalsIgnoreAsciiCase("kde") )
212 #if ENABLE_KDE
213 return OUString("com.sun.star.ui.dialogs.KDEFilePicker");
214 #else
215 return OUString();
216 #endif
218 else if ( rDesktopEnvironment.equalsIgnoreAsciiCase("tde") )
220 #if ENABLE_TDE
221 return OUString("com.sun.star.ui.dialogs.TDEFilePicker");
222 #else
223 return OUString();
224 #endif
226 #if defined WNT
227 return OUString("com.sun.star.ui.dialogs.SystemFilePicker");
228 #elif defined MACOSX
229 return OUString("com.sun.star.ui.dialogs.AquaFilePicker");
230 #else
231 return OUString();
232 #endif
235 static bool lcl_HasSystemFilePicker()
237 if( Application::hasNativeFileSelection() )
238 return true;
240 // Otherwise fall-back on querying services
241 bool bRet = false;
242 Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
244 Reference< XContentEnumerationAccess > xEnumAccess( xFactory, UNO_QUERY );
245 Reference< XSet > xSet( xFactory, UNO_QUERY );
247 if ( ! xEnumAccess.is() || ! xSet.is() )
248 return bRet;
252 OUString aFileService = impl_SystemFileOpenServiceName();
253 Reference< XEnumeration > xEnum = xEnumAccess->createContentEnumeration( aFileService );
254 if ( xEnum.is() && xEnum->hasMoreElements() )
255 bRet = true;
257 catch (const IllegalArgumentException&)
260 catch (const ElementExistException&)
263 return bRet;
267 OfaMiscTabPage::OfaMiscTabPage(vcl::Window* pParent, const SfxItemSet& rSet)
268 : SfxTabPage(pParent, "OptGeneralPage", "cui/ui/optgeneralpage.ui", &rSet)
270 get(m_pToolTipsCB, "tooltips");
271 get(m_pExtHelpCB, "exthelp");
272 if (!lcl_HasSystemFilePicker())
273 get<VclContainer>("filedlgframe")->Hide();
274 #if ! ENABLE_GTK
275 get<VclContainer>("printdlgframe")->Hide();
276 #else
277 if (!SvtMiscOptions().IsExperimentalMode())
279 get<VclContainer>("printdlgframe")->Hide();
281 #endif
282 get(m_pFileDlgCB, "filedlg");
283 get(m_pFileDlgROImage, "lockimage");
284 get(m_pPrintDlgCB, "printdlg");
285 get(m_pDocStatusCB, "docstatus");
286 get(m_pSaveAlwaysCB, "savealways");
287 get(m_pYearFrame, "yearframe");
288 get(m_pYearValueField, "year");
289 get(m_pToYearFT, "toyear");
290 get(m_pCollectUsageInfo, "collectusageinfo");
292 if (m_pFileDlgCB->IsVisible() && SvtMiscOptions().IsUseSystemFileDialogReadOnly())
294 m_pFileDlgROImage->Show();
295 m_pFileDlgCB->Disable();
298 m_aStrDateInfo = m_pToYearFT->GetText();
299 m_pYearValueField->SetModifyHdl( LINK( this, OfaMiscTabPage, TwoFigureHdl ) );
300 Link<> aLink = LINK( this, OfaMiscTabPage, TwoFigureConfigHdl );
301 m_pYearValueField->SetDownHdl( aLink );
302 m_pYearValueField->SetUpHdl( aLink );
303 m_pYearValueField->SetLoseFocusHdl( aLink );
304 m_pYearValueField->SetFirstHdl( aLink );
305 TwoFigureConfigHdl(m_pYearValueField);
307 SetExchangeSupport();
309 aLink = LINK( this, OfaMiscTabPage, HelpCheckHdl_Impl );
310 m_pToolTipsCB->SetClickHdl( aLink );
313 OfaMiscTabPage::~OfaMiscTabPage()
315 disposeOnce();
318 void OfaMiscTabPage::dispose()
320 m_pToolTipsCB.clear();
321 m_pExtHelpCB.clear();
322 m_pFileDlgROImage.clear();
323 m_pFileDlgCB.clear();
324 m_pPrintDlgCB.clear();
325 m_pDocStatusCB.clear();
326 m_pSaveAlwaysCB.clear();
327 m_pYearFrame.clear();
328 m_pYearValueField.clear();
329 m_pToYearFT.clear();
330 m_pCollectUsageInfo.clear();
331 SfxTabPage::dispose();
334 VclPtr<SfxTabPage> OfaMiscTabPage::Create( vcl::Window* pParent, const SfxItemSet* rAttrSet )
336 return VclPtr<OfaMiscTabPage>::Create( pParent, *rAttrSet );
339 bool OfaMiscTabPage::FillItemSet( SfxItemSet* rSet )
341 bool bModified = false;
342 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
344 SvtHelpOptions aHelpOptions;
345 if ( m_pToolTipsCB->IsValueChangedFromSaved() )
346 aHelpOptions.SetHelpTips( m_pToolTipsCB->IsChecked() );
347 bool bChecked = ( m_pExtHelpCB->IsChecked() && m_pToolTipsCB->IsChecked() );
348 if ( bChecked != (m_pExtHelpCB->GetSavedValue() == TRISTATE_TRUE) )
349 aHelpOptions.SetExtendedHelp( bChecked );
351 if ( m_pFileDlgCB->IsValueChangedFromSaved() )
353 SvtMiscOptions aMiscOpt;
354 aMiscOpt.SetUseSystemFileDialog( !m_pFileDlgCB->IsChecked() );
355 bModified = true;
358 if ( m_pPrintDlgCB->IsValueChangedFromSaved() )
360 SvtMiscOptions aMiscOpt;
361 aMiscOpt.SetUseSystemPrintDialog( !m_pPrintDlgCB->IsChecked() );
362 bModified = true;
365 if ( m_pDocStatusCB->IsValueChangedFromSaved() )
367 SvtPrintWarningOptions aPrintOptions;
368 aPrintOptions.SetModifyDocumentOnPrintingAllowed( m_pDocStatusCB->IsChecked() );
369 bModified = true;
372 if ( m_pSaveAlwaysCB->IsValueChangedFromSaved() )
374 SvtMiscOptions aMiscOpt;
375 aMiscOpt.SetSaveAlwaysAllowed( m_pSaveAlwaysCB->IsChecked() );
376 bModified = true;
379 const SfxUInt16Item* pUInt16Item =
380 PTR_CAST( SfxUInt16Item, GetOldItem( *rSet, SID_ATTR_YEAR2000 ) );
381 sal_uInt16 nNum = (sal_uInt16)m_pYearValueField->GetText().toInt32();
382 if ( pUInt16Item && pUInt16Item->GetValue() != nNum )
384 bModified = true;
385 rSet->Put( SfxUInt16Item( SID_ATTR_YEAR2000, nNum ) );
388 if (m_pCollectUsageInfo->IsValueChangedFromSaved())
390 officecfg::Office::Common::Misc::CollectUsageInformation::set(m_pCollectUsageInfo->IsChecked(), batch);
391 bModified = true;
394 batch->commit();
396 return bModified;
399 void OfaMiscTabPage::Reset( const SfxItemSet* rSet )
401 SvtHelpOptions aHelpOptions;
402 m_pToolTipsCB->Check( aHelpOptions.IsHelpTips() );
403 m_pExtHelpCB->Check( aHelpOptions.IsHelpTips() && aHelpOptions.IsExtendedHelp() );
405 m_pToolTipsCB->SaveValue();
406 m_pExtHelpCB->SaveValue();
408 SvtMiscOptions aMiscOpt;
409 m_pFileDlgCB->Check( !aMiscOpt.UseSystemFileDialog() );
410 m_pFileDlgCB->SaveValue();
411 m_pPrintDlgCB->Check( !aMiscOpt.UseSystemPrintDialog() );
412 m_pPrintDlgCB->SaveValue();
413 m_pSaveAlwaysCB->Check( aMiscOpt.IsSaveAlwaysAllowed() );
414 m_pSaveAlwaysCB->SaveValue();
416 SvtPrintWarningOptions aPrintOptions;
417 m_pDocStatusCB->Check(aPrintOptions.IsModifyDocumentOnPrintingAllowed());
418 m_pDocStatusCB->SaveValue();
420 const SfxPoolItem* pItem = NULL;
421 if ( SfxItemState::SET == rSet->GetItemState( SID_ATTR_YEAR2000, false, &pItem ) )
423 m_pYearValueField->SetValue( static_cast<const SfxUInt16Item*>(pItem)->GetValue() );
424 TwoFigureConfigHdl(m_pYearValueField);
426 else
428 m_pYearFrame->Enable(false);
431 m_pCollectUsageInfo->Check(officecfg::Office::Common::Misc::CollectUsageInformation::get());
432 m_pCollectUsageInfo->SaveValue();
435 IMPL_LINK( OfaMiscTabPage, TwoFigureHdl, NumericField*, pEd )
437 (void)pEd;
439 OUString aOutput( m_aStrDateInfo );
440 OUString aStr( m_pYearValueField->GetText() );
441 OUString sSep( SvtSysLocale().GetLocaleData().getNumThousandSep() );
442 sal_Int32 nIndex = 0;
443 while ((nIndex = aStr.indexOf( sSep, nIndex)) != -1)
444 aStr = aStr.replaceAt( nIndex, sSep.getLength(), "");
445 sal_Int32 nNum = aStr.toInt32();
446 if ( aStr.getLength() != 4 || nNum < m_pYearValueField->GetMin() || nNum > m_pYearValueField->GetMax() )
447 aOutput += "????";
448 else
450 nNum += 99;
451 aOutput += OUString::number( nNum );
453 m_pToYearFT->SetText( aOutput );
454 return 0;
457 IMPL_LINK( OfaMiscTabPage, TwoFigureConfigHdl, NumericField*, pEd )
459 sal_Int64 nNum = m_pYearValueField->GetValue();
460 OUString aOutput(OUString::number(nNum));
461 m_pYearValueField->SetText(aOutput);
462 m_pYearValueField->SetSelection( Selection( 0, aOutput.getLength() ) );
463 TwoFigureHdl( pEd );
464 return 0;
467 IMPL_LINK_NOARG(OfaMiscTabPage, HelpCheckHdl_Impl)
469 m_pExtHelpCB->Enable( m_pToolTipsCB->IsChecked() );
470 return 0;
473 class CanvasSettings
475 public:
476 CanvasSettings();
478 bool IsHardwareAccelerationEnabled() const;
479 bool IsHardwareAccelerationAvailable() const;
480 bool IsHardwareAccelerationRO() const;
481 void EnabledHardwareAcceleration( bool _bEnabled ) const;
483 private:
484 typedef std::vector< std::pair<OUString,Sequence<OUString> > > ServiceVector;
486 Reference<XNameAccess> mxForceFlagNameAccess;
487 ServiceVector maAvailableImplementations;
488 mutable bool mbHWAccelAvailable;
489 mutable bool mbHWAccelChecked;
492 CanvasSettings::CanvasSettings() :
493 mxForceFlagNameAccess(),
494 mbHWAccelAvailable(false),
495 mbHWAccelChecked(false)
499 Reference<XMultiServiceFactory> xConfigProvider(
500 com::sun::star::configuration::theDefaultProvider::get(
501 comphelper::getProcessComponentContext()));
503 Any propValue(
504 makeAny( NamedValue(
505 OUString("nodepath"),
506 makeAny( OUString("/org.openoffice.Office.Canvas") ) ) ) );
508 mxForceFlagNameAccess.set(
509 xConfigProvider->createInstanceWithArguments(
510 OUString("com.sun.star.configuration.ConfigurationUpdateAccess"),
511 Sequence<Any>( &propValue, 1 ) ),
512 UNO_QUERY_THROW );
514 propValue = makeAny(
515 NamedValue(
516 OUString("nodepath"),
517 makeAny( OUString("/org.openoffice.Office.Canvas/CanvasServiceList") ) ) );
519 Reference<XNameAccess> xNameAccess(
520 xConfigProvider->createInstanceWithArguments(
521 OUString("com.sun.star.configuration.ConfigurationAccess"),
522 Sequence<Any>( &propValue, 1 ) ), UNO_QUERY_THROW );
523 Reference<XHierarchicalNameAccess> xHierarchicalNameAccess(
524 xNameAccess, UNO_QUERY_THROW);
526 Sequence<OUString> serviceNames = xNameAccess->getElementNames();
527 const OUString* pCurr = serviceNames.getConstArray();
528 const OUString* const pEnd = pCurr + serviceNames.getLength();
529 while( pCurr != pEnd )
531 Reference<XNameAccess> xEntryNameAccess(
532 xHierarchicalNameAccess->getByHierarchicalName(*pCurr),
533 UNO_QUERY );
535 if( xEntryNameAccess.is() )
537 Sequence<OUString> preferredImplementations;
538 if( (xEntryNameAccess->getByName("PreferredImplementations") >>= preferredImplementations) )
539 maAvailableImplementations.push_back( std::make_pair(*pCurr,preferredImplementations) );
542 ++pCurr;
545 catch (const Exception&)
550 bool CanvasSettings::IsHardwareAccelerationAvailable() const
552 if( OpenGLWrapper::isVCLOpenGLEnabled() )
553 mbHWAccelAvailable = false;
555 else if( !mbHWAccelChecked )
557 mbHWAccelChecked = true;
559 Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
561 // check whether any of the service lists has an
562 // implementation that presents the "HardwareAcceleration" property
563 ServiceVector::const_iterator aCurr=maAvailableImplementations.begin();
564 const ServiceVector::const_iterator aEnd=maAvailableImplementations.end();
565 while( aCurr != aEnd )
567 const OUString* pCurrImpl = aCurr->second.getConstArray();
568 const OUString* const pEndImpl = pCurrImpl + aCurr->second.getLength();
570 while( pCurrImpl != pEndImpl )
574 Reference<XPropertySet> xPropSet( xFactory->createInstance(
575 pCurrImpl->trim() ),
576 UNO_QUERY_THROW );
577 bool bHasAccel(false);
578 if( (xPropSet->getPropertyValue("HardwareAcceleration") >>= bHasAccel) )
579 if( bHasAccel )
581 mbHWAccelAvailable = true;
582 return mbHWAccelAvailable;
585 catch (const Exception&)
589 ++pCurrImpl;
592 ++aCurr;
596 return mbHWAccelAvailable;
599 bool CanvasSettings::IsHardwareAccelerationEnabled() const
601 bool bForceLastEntry(false);
602 if( !mxForceFlagNameAccess.is() )
603 return true;
605 if( !(mxForceFlagNameAccess->getByName("ForceSafeServiceImpl") >>= bForceLastEntry) )
606 return true;
608 return !bForceLastEntry;
611 bool CanvasSettings::IsHardwareAccelerationRO() const
613 Reference< XPropertySet > xSet(mxForceFlagNameAccess, UNO_QUERY);
614 if (!xSet.is())
615 return true;
617 Reference< XPropertySetInfo > xInfo = xSet->getPropertySetInfo();
618 Property aProp = xInfo->getPropertyByName("ForceSafeServiceImpl");
619 return ((aProp.Attributes & css::beans::PropertyAttribute::READONLY ) == css::beans::PropertyAttribute::READONLY);
622 void CanvasSettings::EnabledHardwareAcceleration( bool _bEnabled ) const
624 Reference< XNameReplace > xNameReplace(
625 mxForceFlagNameAccess, UNO_QUERY );
627 if( !xNameReplace.is() )
628 return;
630 xNameReplace->replaceByName( OUString("ForceSafeServiceImpl"),
631 makeAny(!_bEnabled) );
633 Reference< XChangesBatch > xChangesBatch(
634 mxForceFlagNameAccess, UNO_QUERY );
636 if( !xChangesBatch.is() )
637 return;
639 xChangesBatch->commitChanges();
642 // class OfaViewTabPage --------------------------------------------------
644 OfaViewTabPage::OfaViewTabPage(vcl::Window* pParent, const SfxItemSet& rSet)
645 : SfxTabPage(pParent, "OptViewPage", "cui/ui/optviewpage.ui", &rSet)
646 , nSizeLB_InitialSelection(0)
647 , nStyleLB_InitialSelection(0)
648 , pAppearanceCfg(new SvtTabAppearanceCfg)
649 , pCanvasSettings(new CanvasSettings)
650 , mpDrawinglayerOpt(new SvtOptionsDrawinglayer)
651 , mpOpenGLConfig(new svt::OpenGLCfg)
653 get(m_pWindowSizeMF, "windowsize");
654 get(m_pIconSizeLB, "iconsize");
655 get(m_pIconStyleLB, "iconstyle");
657 get(m_pFontAntiAliasing, "aafont");
658 get(m_pAAPointLimitLabel, "aafrom");
659 get(m_pAAPointLimit, "aanf");
660 get(m_pMenuIconsLB, "menuicons");
661 get(m_pFontShowCB, "showfontpreview");
662 get(m_pFontHistoryCB, "showfonthistory");
663 get(m_pUseHardwareAccell, "useaccel");
664 get(m_pUseAntiAliase, "useaa");
665 get(m_pUseOpenGL, "useopengl");
666 get(m_pForceOpenGL, "forceopengl");
667 get(m_pMousePosLB, "mousepos");
668 get(m_pMouseMiddleLB, "mousemiddle");
669 // #i97672#
670 get(m_pSelectionCB, "trans");
671 get(m_pSelectionMF, "transmf");
673 #if defined( UNX )
674 m_pFontAntiAliasing->SetToggleHdl( LINK( this, OfaViewTabPage, OnAntialiasingToggled ) );
675 #else
676 // on this platform, we do not have the anti aliasing options
677 m_pFontAntiAliasing->Hide();
678 m_pAAPointLimitLabel->Hide();
679 m_pAAPointLimit->Hide();
681 #endif
683 // #i97672#
684 m_pSelectionCB->SetToggleHdl( LINK( this, OfaViewTabPage, OnSelectionToggled ) );
686 // Set known icon themes
687 OUString sAutoStr( m_pIconStyleLB->GetEntry( 0 ) );
688 m_pIconStyleLB->Clear();
689 StyleSettings aStyleSettings = Application::GetSettings().GetStyleSettings();
690 mInstalledIconThemes = aStyleSettings.GetInstalledIconThemes();
692 // Start with the automatically chosen icon theme
693 OUString autoThemeId = aStyleSettings.GetAutomaticallyChosenIconTheme();
694 const vcl::IconThemeInfo& autoIconTheme = vcl::IconThemeInfo::FindIconThemeById(mInstalledIconThemes, autoThemeId);
696 OUString entryForAuto = sAutoStr + " (" +
697 autoIconTheme.GetDisplayName() +
698 ")";
699 m_pIconStyleLB->InsertEntry(entryForAuto);
701 for (std::vector<vcl::IconThemeInfo>::const_iterator aI = mInstalledIconThemes.begin(); aI != mInstalledIconThemes.end(); ++aI) {
702 m_pIconStyleLB->InsertEntry(aI->GetDisplayName());
705 // separate auto and other icon themes
706 m_pIconStyleLB->SetSeparatorPos( 0 );
707 m_pIconStyleLB->SelectEntryPos(0);
709 // FIXME: should really add code to show a 'lock' icon here.
710 if (officecfg::Office::Common::VCL::UseOpenGL::isReadOnly())
711 m_pUseOpenGL->Enable(false);
712 if (officecfg::Office::Common::VCL::ForceOpenGL::isReadOnly())
713 m_pForceOpenGL->Enable(false);
716 OfaViewTabPage::~OfaViewTabPage()
718 disposeOnce();
721 void OfaViewTabPage::dispose()
723 delete mpDrawinglayerOpt;
724 mpDrawinglayerOpt = NULL;
725 delete pCanvasSettings;
726 pCanvasSettings = NULL;
727 delete pAppearanceCfg;
728 pAppearanceCfg = NULL;
729 m_pWindowSizeMF.clear();
730 m_pIconSizeLB.clear();
731 m_pIconStyleLB.clear();
732 m_pFontAntiAliasing.clear();
733 m_pAAPointLimitLabel.clear();
734 m_pAAPointLimit.clear();
735 m_pMenuIconsLB.clear();
736 m_pFontShowCB.clear();
737 m_pFontHistoryCB.clear();
738 m_pUseHardwareAccell.clear();
739 m_pUseAntiAliase.clear();
740 m_pUseOpenGL.clear();
741 m_pForceOpenGL.clear();
742 m_pMousePosLB.clear();
743 m_pMouseMiddleLB.clear();
744 m_pSelectionCB.clear();
745 m_pSelectionMF.clear();
746 SfxTabPage::dispose();
749 #if defined( UNX )
750 IMPL_LINK_NOARG( OfaViewTabPage, OnAntialiasingToggled )
752 bool bAAEnabled = m_pFontAntiAliasing->IsChecked();
754 m_pAAPointLimitLabel->Enable( bAAEnabled );
755 m_pAAPointLimit->Enable( bAAEnabled );
757 return 0L;
759 #endif
761 // #i97672#
762 IMPL_LINK_NOARG( OfaViewTabPage, OnSelectionToggled )
764 const bool bSelectionEnabled(m_pSelectionCB->IsChecked());
765 m_pSelectionMF->Enable(bSelectionEnabled);
766 return 0;
769 VclPtr<SfxTabPage> OfaViewTabPage::Create( vcl::Window* pParent, const SfxItemSet* rAttrSet )
771 return VclPtr<OfaViewTabPage>::Create(pParent, *rAttrSet);
774 bool OfaViewTabPage::FillItemSet( SfxItemSet* )
776 SvtFontOptions aFontOpt;
777 SvtMenuOptions aMenuOpt;
779 bool bModified = false;
780 bool bMenuOptModified = false;
781 bool bRepaintWindows(false);
783 SvtMiscOptions aMiscOptions;
784 sal_uInt16 nSizeLB_NewSelection = m_pIconSizeLB->GetSelectEntryPos();
785 if( nSizeLB_InitialSelection != nSizeLB_NewSelection )
787 // from now on it's modified, even if via auto setting the same size was set as now selected in the LB
788 sal_Int16 eSet = SFX_SYMBOLS_SIZE_AUTO;
789 switch( nSizeLB_NewSelection )
791 case 0: eSet = SFX_SYMBOLS_SIZE_AUTO; break;
792 case 1: eSet = SFX_SYMBOLS_SIZE_SMALL; break;
793 case 2: eSet = SFX_SYMBOLS_SIZE_LARGE; break;
794 default:
795 OSL_FAIL( "OfaViewTabPage::FillItemSet(): This state of m_pIconSizeLB should not be possible!" );
797 aMiscOptions.SetSymbolsSize( eSet );
800 sal_uInt16 nStyleLB_NewSelection = m_pIconStyleLB->GetSelectEntryPos();
801 if( nStyleLB_InitialSelection != nStyleLB_NewSelection )
803 // 0 means choose style automatically
804 if (nStyleLB_NewSelection == 0) {
805 aMiscOptions.SetIconThemeAutomatically();
807 else {
808 sal_uInt16 pos = m_pIconStyleLB->GetSelectEntryPos();
809 const vcl::IconThemeInfo& iconThemeId = mInstalledIconThemes.at(pos-1);
810 aMiscOptions.SetIconTheme(iconThemeId.GetThemeId());
812 nStyleLB_InitialSelection = nStyleLB_NewSelection;
815 bool bAppearanceChanged = false;
818 // Screen Scaling
819 sal_uInt16 nOldScale = pAppearanceCfg->GetScaleFactor();
820 sal_uInt16 nNewScale = (sal_uInt16)m_pWindowSizeMF->GetValue();
822 if ( nNewScale != nOldScale )
824 pAppearanceCfg->SetScaleFactor(nNewScale);
825 bAppearanceChanged = true;
828 // Mouse Snap Mode
829 short eOldSnap = pAppearanceCfg->GetSnapMode();
830 short eNewSnap = m_pMousePosLB->GetSelectEntryPos();
831 if(eNewSnap > 2)
832 eNewSnap = 2;
834 if ( eNewSnap != eOldSnap )
836 pAppearanceCfg->SetSnapMode(eNewSnap );
837 bAppearanceChanged = true;
840 // Middle Mouse Button
841 MouseMiddleButtonAction eOldMiddleMouse = pAppearanceCfg->GetMiddleMouseButton();
842 short eNewMiddleMouse = m_pMouseMiddleLB->GetSelectEntryPos();
843 if(eNewMiddleMouse > 2)
844 eNewMiddleMouse = 2;
846 if ( eNewMiddleMouse != static_cast<short>(eOldMiddleMouse) )
848 pAppearanceCfg->SetMiddleMouseButton( static_cast<MouseMiddleButtonAction>(eNewMiddleMouse) );
849 bAppearanceChanged = true;
852 #if defined( UNX )
853 if ( m_pFontAntiAliasing->IsValueChangedFromSaved() )
855 pAppearanceCfg->SetFontAntiAliasing( m_pFontAntiAliasing->IsChecked() );
856 bAppearanceChanged = true;
859 if ( m_pAAPointLimit->IsValueChangedFromSaved() )
861 pAppearanceCfg->SetFontAntialiasingMinPixelHeight( m_pAAPointLimit->GetValue() );
862 bAppearanceChanged = true;
864 #endif
866 if ( m_pFontShowCB->IsValueChangedFromSaved() )
868 aFontOpt.EnableFontWYSIWYG( m_pFontShowCB->IsChecked() );
869 bModified = true;
872 if(m_pMenuIconsLB->IsValueChangedFromSaved())
874 aMenuOpt.SetMenuIconsState(m_pMenuIconsLB->GetSelectEntryPos() == 0 ?
875 TRISTATE_INDET :
876 static_cast<TriState>(m_pMenuIconsLB->GetSelectEntryPos() - 1));
877 bModified = true;
878 bMenuOptModified = true;
879 bAppearanceChanged = true;
882 if ( m_pFontHistoryCB->IsValueChangedFromSaved() )
884 aFontOpt.EnableFontHistory( m_pFontHistoryCB->IsChecked() );
885 bModified = true;
888 // #i95644# if disabled, do not use value, see in ::Reset()
889 if(m_pUseHardwareAccell->IsEnabled())
891 if(m_pUseHardwareAccell->IsValueChangedFromSaved())
893 pCanvasSettings->EnabledHardwareAcceleration(m_pUseHardwareAccell->IsChecked());
894 bModified = true;
898 // #i95644# if disabled, do not use value, see in ::Reset()
899 if(m_pUseAntiAliase->IsEnabled())
901 if(m_pUseAntiAliase->IsChecked() != mpDrawinglayerOpt->IsAntiAliasing())
903 mpDrawinglayerOpt->SetAntiAliasing(m_pUseAntiAliase->IsChecked());
904 bModified = true;
905 bRepaintWindows = true;
909 mpOpenGLConfig->setUseOpenGL(m_pUseOpenGL->IsChecked());
910 mpOpenGLConfig->setForceOpenGL(m_pForceOpenGL->IsChecked());
912 // #i97672#
913 if(m_pSelectionCB->IsEnabled())
915 const bool bNewSelection(m_pSelectionCB->IsChecked());
916 const sal_uInt16 nNewTransparence((sal_uInt16)m_pSelectionMF->GetValue());
918 if(bNewSelection != (bool)mpDrawinglayerOpt->IsTransparentSelection())
920 mpDrawinglayerOpt->SetTransparentSelection(m_pSelectionCB->IsChecked());
921 bModified = true;
922 bRepaintWindows = true;
925 // #i104150# even read the value when m_pSelectionMF is disabled; it may have been
926 // modified by enabling-modify-disabling by the user
927 if(nNewTransparence != mpDrawinglayerOpt->GetTransparentSelectionPercent())
929 mpDrawinglayerOpt->SetTransparentSelectionPercent(nNewTransparence);
930 bModified = true;
931 bRepaintWindows = true;
935 SvtAccessibilityOptions aAccessibilityOptions;
937 if( bMenuOptModified )
939 // Set changed settings to the application instance
940 AllSettings aAllSettings = Application::GetSettings();
941 StyleSettings aStyleSettings = aAllSettings.GetStyleSettings();
942 aAllSettings.SetStyleSettings(aStyleSettings);
943 Application::MergeSystemSettings( aAllSettings );
944 Application::SetSettings(aAllSettings);
947 if ( bAppearanceChanged )
949 pAppearanceCfg->Commit();
950 pAppearanceCfg->SetApplicationDefaults ( GetpApp() );
953 if(bRepaintWindows)
955 vcl::Window* pAppWindow = Application::GetFirstTopLevelWindow();
957 while(pAppWindow)
959 pAppWindow->Invalidate();
960 pAppWindow = Application::GetNextTopLevelWindow(pAppWindow);
964 return bModified;
967 void OfaViewTabPage::Reset( const SfxItemSet* )
969 SvtMiscOptions aMiscOptions;
970 mpOpenGLConfig->reset();
972 if( aMiscOptions.GetSymbolsSize() != SFX_SYMBOLS_SIZE_AUTO )
973 nSizeLB_InitialSelection = ( aMiscOptions.AreCurrentSymbolsLarge() )? 2 : 1;
974 m_pIconSizeLB->SelectEntryPos( nSizeLB_InitialSelection );
975 m_pIconSizeLB->SaveValue();
977 if (aMiscOptions.IconThemeWasSetAutomatically()) {
978 nStyleLB_InitialSelection = 0;
980 else {
981 const OUString& selected = aMiscOptions.GetIconTheme();
982 const vcl::IconThemeInfo& selectedInfo =
983 vcl::IconThemeInfo::FindIconThemeById(mInstalledIconThemes, selected);
984 nStyleLB_InitialSelection = m_pIconStyleLB->GetEntryPos(selectedInfo.GetDisplayName());
987 m_pIconStyleLB->SelectEntryPos( nStyleLB_InitialSelection );
988 m_pIconStyleLB->SaveValue();
990 // Screen Scaling
991 m_pWindowSizeMF->SetValue ( pAppearanceCfg->GetScaleFactor() );
992 // Mouse Snap
993 m_pMousePosLB->SelectEntryPos(pAppearanceCfg->GetSnapMode());
994 m_pMousePosLB->SaveValue();
996 // Mouse Snap
997 m_pMouseMiddleLB->SelectEntryPos(static_cast<short>(pAppearanceCfg->GetMiddleMouseButton()));
998 m_pMouseMiddleLB->SaveValue();
1000 #if defined( UNX )
1001 m_pFontAntiAliasing->Check( pAppearanceCfg->IsFontAntiAliasing() );
1002 m_pAAPointLimit->SetValue( pAppearanceCfg->GetFontAntialiasingMinPixelHeight() );
1003 #endif
1005 // WorkingSet
1006 SvtFontOptions aFontOpt;
1007 m_pFontShowCB->Check( aFontOpt.IsFontWYSIWYGEnabled() );
1008 SvtMenuOptions aMenuOpt;
1009 m_pMenuIconsLB->SelectEntryPos(aMenuOpt.GetMenuIconsState() == 2 ? 0 : aMenuOpt.GetMenuIconsState() + 1);
1010 m_pMenuIconsLB->SaveValue();
1011 m_pFontHistoryCB->Check( aFontOpt.IsFontHistoryEnabled() );
1013 { // #i95644# HW accel (unified to disable mechanism)
1014 if(pCanvasSettings->IsHardwareAccelerationAvailable())
1016 m_pUseHardwareAccell->Check(pCanvasSettings->IsHardwareAccelerationEnabled());
1017 m_pUseHardwareAccell->Enable(!pCanvasSettings->IsHardwareAccelerationRO());
1019 else
1021 m_pUseHardwareAccell->Check(false);
1022 m_pUseHardwareAccell->Disable();
1025 m_pUseHardwareAccell->SaveValue();
1028 { // #i95644# AntiAliasing
1029 if(mpDrawinglayerOpt->IsAAPossibleOnThisSystem())
1031 m_pUseAntiAliase->Check(mpDrawinglayerOpt->IsAntiAliasing());
1033 else
1035 m_pUseAntiAliase->Check(false);
1036 m_pUseAntiAliase->Disable();
1039 m_pUseAntiAliase->SaveValue();
1041 m_pUseOpenGL->Check(mpOpenGLConfig->useOpenGL());
1042 m_pForceOpenGL->Check(mpOpenGLConfig->forceOpenGL());
1045 // #i97672# Selection
1046 // check if transparent selection is possible on this system
1047 const bool bTransparentSelectionPossible(
1048 !GetSettings().GetStyleSettings().GetHighContrastMode()
1049 && SupportsOperation(OutDevSupport_TransparentRect));
1051 // enter values
1052 if(bTransparentSelectionPossible)
1054 m_pSelectionCB->Check(mpDrawinglayerOpt->IsTransparentSelection());
1056 else
1058 m_pSelectionCB->Enable(false);
1061 m_pSelectionMF->SetValue(mpDrawinglayerOpt->GetTransparentSelectionPercent());
1062 m_pSelectionMF->Enable(mpDrawinglayerOpt->IsTransparentSelection() && bTransparentSelectionPossible);
1065 #if defined( UNX )
1066 m_pFontAntiAliasing->SaveValue();
1067 m_pAAPointLimit->SaveValue();
1068 #endif
1069 m_pFontShowCB->SaveValue();
1070 m_pFontHistoryCB->SaveValue();
1072 #if defined( UNX )
1073 LINK( this, OfaViewTabPage, OnAntialiasingToggled ).Call( NULL );
1074 #endif
1077 struct LanguageConfig_Impl
1079 SvtLanguageOptions aLanguageOptions;
1080 SvtSysLocaleOptions aSysLocaleOptions;
1081 SvtLinguConfig aLinguConfig;
1084 static bool bLanguageCurrentDoc_Impl = false;
1086 // some things we'll need...
1087 static const char sAccessSrvc[] = "com.sun.star.configuration.ConfigurationAccess";
1088 static const char sAccessUpdSrvc[] = "com.sun.star.configuration.ConfigurationUpdateAccess";
1089 static const char sInstalledLocalesPath[] = "org.openoffice.Setup/Office/InstalledLocales";
1090 static const char sUserLocalePath[] = "org.openoffice.Office.Linguistic/General";
1091 static const char sUserLocaleKey[] = "UILocale";
1092 static Sequence< OUString > seqInstalledLanguages;
1094 static OUString lcl_getDatePatternsConfigString( const LocaleDataWrapper& rLocaleWrapper )
1096 Sequence< OUString > aDateAcceptancePatterns = rLocaleWrapper.getDateAcceptancePatterns();
1097 sal_Int32 nPatterns = aDateAcceptancePatterns.getLength();
1098 OUStringBuffer aBuf( nPatterns * 6 ); // 6 := length of Y-M-D;
1099 SAL_WARN_IF( !nPatterns, "cui.options", "No date acceptance pattern");
1100 if (nPatterns)
1102 const OUString* pPatterns = aDateAcceptancePatterns.getConstArray();
1103 aBuf.append( pPatterns[0]);
1104 for (sal_Int32 i=1; i < nPatterns; ++i)
1105 aBuf.append(';').append( pPatterns[i]);
1107 return aBuf.makeStringAndClear();
1110 OfaLanguagesTabPage::OfaLanguagesTabPage(vcl::Window* pParent, const SfxItemSet& rSet)
1111 : SfxTabPage(pParent,"OptLanguagesPage","cui/ui/optlanguagespage.ui", &rSet)
1112 , pLangConfig(new LanguageConfig_Impl)
1113 , m_bDatePatternsValid(false)
1115 get(m_pUserInterfaceLB, "userinterface");
1116 m_pUserInterfaceLB->SetStyle(m_pUserInterfaceLB->GetStyle() | WB_SORT);
1117 get(m_pLocaleSettingLB, "localesetting");
1118 m_pLocaleSettingLB->SetStyle(m_pLocaleSettingLB->GetStyle() | WB_SORT);
1119 get(m_pLocaleSettingFT, "localesettingFT");
1120 get(m_pDecimalSeparatorCB, "decimalseparator");
1121 get(m_pCurrencyFT, "defaultcurrency");
1122 get(m_pCurrencyLB, "currencylb");
1123 m_pCurrencyLB->SetStyle(m_pCurrencyLB->GetStyle() | WB_SORT);
1124 get(m_pDatePatternsFT,"dataaccpatterns");
1125 get(m_pDatePatternsED, "datepatterns");
1127 get(m_pWesternLanguageLB, "westernlanguage");
1128 m_pWesternLanguageLB->SetStyle(m_pWesternLanguageLB->GetStyle() | WB_SORT);
1129 get(m_pWesternLanguageFT, "western");
1130 get(m_pAsianLanguageLB, "asianlanguage");
1131 m_pAsianLanguageLB->SetStyle(m_pAsianLanguageLB->GetStyle() | WB_SORT);
1132 get(m_pComplexLanguageLB, "complexlanguage");
1133 m_pComplexLanguageLB->SetStyle(m_pComplexLanguageLB->GetStyle() | WB_SORT);
1134 get(m_pCurrentDocCB, "currentdoc");
1135 get(m_pAsianSupportCB, "asiansupport");
1136 get(m_pCTLSupportCB, "ctlsupport");
1137 get(m_pIgnoreLanguageChangeCB, "ignorelanguagechange");
1139 // initialize user interface language selection
1140 m_sSystemDefaultString = SvtLanguageTable::GetLanguageString( LANGUAGE_SYSTEM );
1142 OUString aUILang = m_sSystemDefaultString +
1143 " - " +
1144 SvtLanguageTable::GetLanguageString( Application::GetSettings().GetUILanguageTag().getLanguageType(), true );
1146 m_pUserInterfaceLB->InsertEntry(aUILang);
1147 m_pUserInterfaceLB->SetEntryData(0, 0);
1148 m_pUserInterfaceLB->SelectEntryPos(0);
1151 Reference< XMultiServiceFactory > theConfigProvider(
1152 com::sun::star::configuration::theDefaultProvider::get(
1153 comphelper::getProcessComponentContext()));
1154 Sequence< Any > theArgs(1);
1155 Reference< XNameAccess > theNameAccess;
1157 // find out which locales are currently installed and add them to the listbox
1158 theArgs[0] = makeAny(NamedValue(OUString("nodepath"), makeAny(OUString(sInstalledLocalesPath))));
1159 theNameAccess = Reference< XNameAccess > (
1160 theConfigProvider->createInstanceWithArguments(sAccessSrvc, theArgs ), UNO_QUERY_THROW );
1161 seqInstalledLanguages = theNameAccess->getElementNames();
1162 LanguageType aLang = LANGUAGE_DONTKNOW;
1163 for (sal_IntPtr i=0; i<seqInstalledLanguages.getLength(); i++)
1165 aLang = LanguageTag::convertToLanguageTypeWithFallback(seqInstalledLanguages[i]);
1166 if (aLang != LANGUAGE_DONTKNOW)
1168 //sal_uInt16 p = m_pUserInterfaceLB->InsertLanguage(aLang);
1169 OUString aLangStr( SvtLanguageTable::GetLanguageString( aLang, true ) );
1170 sal_uInt16 p = m_pUserInterfaceLB->InsertEntry(aLangStr);
1171 m_pUserInterfaceLB->SetEntryData(p, reinterpret_cast<void*>(i+1));
1175 // find out whether the user has a specific locale specified
1176 Sequence< Any > theArgs2(1);
1177 theArgs2[0] = makeAny(NamedValue(OUString("nodepath"), makeAny(OUString(sUserLocalePath))));
1178 theNameAccess = Reference< XNameAccess > (
1179 theConfigProvider->createInstanceWithArguments(sAccessSrvc, theArgs2 ), UNO_QUERY_THROW );
1180 if (theNameAccess->hasByName(sUserLocaleKey))
1181 theNameAccess->getByName(sUserLocaleKey) >>= m_sUserLocaleValue;
1182 // select the user specified locale in the listbox
1183 if (!m_sUserLocaleValue.isEmpty())
1185 sal_Int32 d = 0;
1186 for (sal_uInt16 i=0; i < m_pUserInterfaceLB->GetEntryCount(); i++)
1188 d = (sal_Int32)reinterpret_cast<sal_IntPtr>(m_pUserInterfaceLB->GetEntryData(i));
1189 if ( d > 0 && seqInstalledLanguages.getLength() > d-1 && seqInstalledLanguages[d-1].equals(m_sUserLocaleValue))
1190 m_pUserInterfaceLB->SelectEntryPos(i);
1195 catch (const Exception &e)
1197 // we'll just leave the box in it's default setting and won't
1198 // even give it event handler...
1199 SAL_WARN("cui.options", "ignoring Exception \"" << e.Message << "\"");
1202 m_pWesternLanguageLB->SetLanguageList( SvxLanguageListFlags::WESTERN | SvxLanguageListFlags::ONLY_KNOWN, true, false, true );
1203 m_pWesternLanguageLB->InsertDefaultLanguage( ::com::sun::star::i18n::ScriptType::LATIN );
1204 m_pAsianLanguageLB->SetLanguageList( SvxLanguageListFlags::CJK | SvxLanguageListFlags::ONLY_KNOWN, true, false, true );
1205 m_pAsianLanguageLB->InsertDefaultLanguage( ::com::sun::star::i18n::ScriptType::ASIAN );
1206 m_pComplexLanguageLB->SetLanguageList( SvxLanguageListFlags::CTL | SvxLanguageListFlags::ONLY_KNOWN, true, false, true );
1207 m_pComplexLanguageLB->InsertDefaultLanguage( ::com::sun::star::i18n::ScriptType::COMPLEX );
1209 m_pLocaleSettingLB->SetLanguageList( SvxLanguageListFlags::ALL | SvxLanguageListFlags::ONLY_KNOWN, false, false, false);
1210 m_pLocaleSettingLB->InsertSystemLanguage( );
1212 const NfCurrencyTable& rCurrTab = SvNumberFormatter::GetTheCurrencyTable();
1213 const NfCurrencyEntry& rCurr = SvNumberFormatter::GetCurrencyEntry( LANGUAGE_SYSTEM );
1214 // insert SYSTEM entry
1215 OUString aDefaultCurr = m_sSystemDefaultString + " - " + rCurr.GetBankSymbol();
1216 m_pCurrencyLB->InsertEntry( aDefaultCurr );
1217 // all currencies
1218 OUString aTwoSpace( " " );
1219 sal_uInt16 nCurrCount = rCurrTab.size();
1220 // first entry is SYSTEM, skip it
1221 for ( sal_uInt16 j=1; j < nCurrCount; ++j )
1223 const NfCurrencyEntry* pCurr = &rCurrTab[j];
1224 OUString aStr_ = pCurr->GetBankSymbol() +
1225 aTwoSpace +
1226 pCurr->GetSymbol();
1227 aStr_ = ApplyLreOrRleEmbedding( aStr_ ) +
1228 aTwoSpace +
1229 ApplyLreOrRleEmbedding( SvtLanguageTable::GetLanguageString( pCurr->GetLanguage() ) );
1230 sal_uInt16 nPos = m_pCurrencyLB->InsertEntry( aStr_ );
1231 m_pCurrencyLB->SetEntryData( nPos, (void*) pCurr );
1234 m_pLocaleSettingLB->SetSelectHdl( LINK( this, OfaLanguagesTabPage, LocaleSettingHdl ) );
1235 m_pDatePatternsED->SetModifyHdl( LINK( this, OfaLanguagesTabPage, DatePatternsHdl ) );
1237 Link<> aLink( LINK( this, OfaLanguagesTabPage, SupportHdl ) );
1238 m_pAsianSupportCB->SetClickHdl( aLink );
1239 m_pCTLSupportCB->SetClickHdl( aLink );
1241 m_bOldAsian = pLangConfig->aLanguageOptions.IsAnyEnabled();
1242 m_pAsianSupportCB->Check(m_bOldAsian);
1243 m_pAsianSupportCB->SaveValue();
1244 bool bReadonly = pLangConfig->aLanguageOptions.IsReadOnly(SvtLanguageOptions::E_ALLCJK);
1245 m_pAsianSupportCB->Enable(!bReadonly);
1246 SupportHdl( m_pAsianSupportCB );
1248 m_bOldCtl = pLangConfig->aLanguageOptions.IsCTLFontEnabled();
1249 m_pCTLSupportCB->Check(m_bOldCtl);
1250 m_pCTLSupportCB->SaveValue();
1251 bReadonly = pLangConfig->aLanguageOptions.IsReadOnly(SvtLanguageOptions::E_CTLFONT);
1252 m_pCTLSupportCB->Enable(!bReadonly);
1253 SupportHdl( m_pCTLSupportCB );
1255 m_pIgnoreLanguageChangeCB->Check( pLangConfig->aSysLocaleOptions.IsIgnoreLanguageChange() );
1258 OfaLanguagesTabPage::~OfaLanguagesTabPage()
1260 disposeOnce();
1263 void OfaLanguagesTabPage::dispose()
1265 delete pLangConfig;
1266 pLangConfig = NULL;
1267 m_pUserInterfaceLB.clear();
1268 m_pLocaleSettingFT.clear();
1269 m_pLocaleSettingLB.clear();
1270 m_pDecimalSeparatorCB.clear();
1271 m_pCurrencyFT.clear();
1272 m_pCurrencyLB.clear();
1273 m_pDatePatternsFT.clear();
1274 m_pDatePatternsED.clear();
1275 m_pWesternLanguageLB.clear();
1276 m_pWesternLanguageFT.clear();
1277 m_pAsianLanguageLB.clear();
1278 m_pComplexLanguageLB.clear();
1279 m_pCurrentDocCB.clear();
1280 m_pAsianSupportCB.clear();
1281 m_pCTLSupportCB.clear();
1282 m_pIgnoreLanguageChangeCB.clear();
1283 SfxTabPage::dispose();
1286 VclPtr<SfxTabPage> OfaLanguagesTabPage::Create( vcl::Window* pParent, const SfxItemSet* rAttrSet )
1288 return VclPtr<OfaLanguagesTabPage>::Create(pParent, *rAttrSet);
1291 static void lcl_UpdateAndDelete(SfxVoidItem* pInvalidItems[], SfxBoolItem* pBoolItems[], sal_uInt16 nCount)
1293 SfxViewFrame* pCurrentFrm = SfxViewFrame::Current();
1294 SfxViewFrame* pViewFrm = SfxViewFrame::GetFirst();
1295 while(pViewFrm)
1297 SfxBindings& rBind = pViewFrm->GetBindings();
1298 for(sal_Int16 i = 0; i < nCount; i++)
1300 if(pCurrentFrm == pViewFrm)
1301 rBind.InvalidateAll(false);
1302 rBind.SetState( *pInvalidItems[i] );
1303 rBind.SetState( *pBoolItems[i] );
1305 pViewFrm = SfxViewFrame::GetNext(*pViewFrm);
1307 for(sal_Int16 i = 0; i < nCount; i++)
1309 delete pInvalidItems[i];
1310 delete pBoolItems[i] ;
1314 bool OfaLanguagesTabPage::FillItemSet( SfxItemSet* rSet )
1316 // lock configuration broadcasters so that we can coordinate the notifications
1317 pLangConfig->aSysLocaleOptions.BlockBroadcasts( true );
1318 pLangConfig->aLanguageOptions.BlockBroadcasts( true );
1319 pLangConfig->aLinguConfig.BlockBroadcasts( true );
1322 * Sequence checking only matters when CTL support is enabled.
1324 * So we only need to check for sequence checking if
1325 * a) previously it was unchecked and is now checked or
1326 * b) it was already checked but the CTL language has changed
1328 if (
1329 m_pCTLSupportCB->IsChecked() &&
1330 (m_pCTLSupportCB->GetSavedValue() != TRISTATE_TRUE ||
1331 m_pComplexLanguageLB->IsValueChangedFromSaved())
1334 //sequence checking has to be switched on depending on the selected CTL language
1335 LanguageType eCTLLang = m_pComplexLanguageLB->GetSelectLanguage();
1336 bool bOn = MsLangId::needsSequenceChecking( eCTLLang);
1337 pLangConfig->aLanguageOptions.SetCTLSequenceCheckingRestricted(bOn);
1338 pLangConfig->aLanguageOptions.SetCTLSequenceChecking(bOn);
1339 pLangConfig->aLanguageOptions.SetCTLSequenceCheckingTypeAndReplace(bOn);
1343 // handle settings for UI Language
1344 // a change of setting needs to bring up a warning message
1345 OUString aLangString;
1346 sal_Int32 d = (sal_Int32)reinterpret_cast<sal_IntPtr>(m_pUserInterfaceLB->GetSelectEntryData());
1347 if( d > 0 && seqInstalledLanguages.getLength() > d-1)
1348 aLangString = seqInstalledLanguages[d-1];
1351 if( m_pUserInterfaceLB->GetSelectEntryPos() > 0)
1352 aLangString = ConvertLanguageToIsoString(m_pUserInterfaceLB->GetSelectLanguage());
1354 Reference< XMultiServiceFactory > theConfigProvider(
1355 com::sun::star::configuration::theDefaultProvider::get(
1356 comphelper::getProcessComponentContext()));
1357 Sequence< Any > theArgs(1);
1358 theArgs[0] = makeAny(NamedValue(OUString("nodepath"), makeAny(OUString(sUserLocalePath))));
1359 Reference< XPropertySet >xProp(
1360 theConfigProvider->createInstanceWithArguments(sAccessUpdSrvc, theArgs ), UNO_QUERY_THROW );
1361 if ( !m_sUserLocaleValue.equals(aLangString))
1363 // OSL_FAIL("UserInterface language was changed, restart.");
1364 // write new value
1365 xProp->setPropertyValue(sUserLocaleKey, makeAny(aLangString));
1366 Reference< XChangesBatch >(xProp, UNO_QUERY_THROW)->commitChanges();
1367 // display info
1368 ScopedVclPtrInstance< MessageDialog > aBox(this, CUI_RES(RID_SVXSTR_LANGUAGE_RESTART), VCL_MESSAGE_INFO);
1369 aBox->Execute();
1371 // tell quickstarter to stop being a veto listener
1373 Reference< XComponentContext > xContext(
1374 comphelper::getProcessComponentContext());
1375 css::office::Quickstart::createAndSetVeto(xContext, false, false, false/*DisableVeto*/);
1378 catch (const Exception& e)
1380 // we'll just leave the box in it's default setting and won't
1381 // even give it event handler...
1382 SAL_WARN("cui.options", "ignoring Exception \"" << e.Message << "\"");
1385 OUString sLang = pLangConfig->aSysLocaleOptions.GetLocaleConfigString();
1386 LanguageType eOldLocale = (!sLang.isEmpty() ?
1387 LanguageTag::convertToLanguageTypeWithFallback( sLang ) : LANGUAGE_SYSTEM);
1388 LanguageType eNewLocale = m_pLocaleSettingLB->GetSelectLanguage();
1390 // If the "Default ..." entry was selected that means SYSTEM, the actual
1391 // eNewLocale value is temporary for the dialog only, do not resolve to
1392 // what system currently is.
1393 if (eNewLocale == LANGUAGE_USER_SYSTEM_CONFIG)
1394 eNewLocale = LANGUAGE_SYSTEM;
1396 if ( eOldLocale != eNewLocale )
1398 // an empty string denotes SYSTEM locale
1399 OUString sNewLang;
1400 if ( eNewLocale != LANGUAGE_SYSTEM )
1401 sNewLang = LanguageTag::convertToBcp47( eNewLocale);
1403 // locale nowadays get to AppSettings via notification
1404 // this will happen after releasing the lock on the ConfigurationBroadcaster at
1405 // the end of this method
1406 pLangConfig->aSysLocaleOptions.SetLocaleConfigString( sNewLang );
1407 rSet->Put( SfxBoolItem( SID_OPT_LOCALE_CHANGED, true ) );
1409 SvtScriptType nNewType = SvtLanguageOptions::GetScriptTypeOfLanguage( eNewLocale );
1410 bool bNewCJK = bool( nNewType & SvtScriptType::ASIAN );
1411 SvtCompatibilityOptions aCompatOpts;
1412 aCompatOpts.SetDefault( COMPATIBILITY_PROPERTYNAME_EXPANDWORDSPACE, !bNewCJK );
1415 if(m_pDecimalSeparatorCB->IsValueChangedFromSaved())
1416 pLangConfig->aSysLocaleOptions.SetDecimalSeparatorAsLocale(m_pDecimalSeparatorCB->IsChecked());
1418 if(m_pIgnoreLanguageChangeCB->IsValueChangedFromSaved())
1419 pLangConfig->aSysLocaleOptions.SetIgnoreLanguageChange(m_pIgnoreLanguageChangeCB->IsChecked());
1421 // Configured currency, for example, USD-en-US or EUR-de-DE, or empty for locale default.
1422 OUString sOldCurr = pLangConfig->aSysLocaleOptions.GetCurrencyConfigString();
1423 const NfCurrencyEntry* pCurr = static_cast<const NfCurrencyEntry*>(m_pCurrencyLB->GetSelectEntryData());
1424 OUString sNewCurr;
1425 if ( pCurr )
1426 sNewCurr = SvtSysLocaleOptions::CreateCurrencyConfigString(
1427 pCurr->GetBankSymbol(), pCurr->GetLanguage() );
1428 if ( sOldCurr != sNewCurr )
1429 pLangConfig->aSysLocaleOptions.SetCurrencyConfigString( sNewCurr );
1431 // Configured date acceptance patterns, for example Y-M-D;M-D or empty for
1432 // locale default.
1433 if (m_bDatePatternsValid && m_pDatePatternsED->IsValueChangedFromSaved())
1434 pLangConfig->aSysLocaleOptions.SetDatePatternsConfigString( m_pDatePatternsED->GetText());
1436 SfxObjectShell* pCurrentDocShell = SfxObjectShell::Current();
1437 Reference< css::linguistic2::XLinguProperties > xLinguProp = LinguMgr::GetLinguPropertySet();
1438 bool bCurrentDocCBChecked = m_pCurrentDocCB->IsChecked();
1439 if(m_pCurrentDocCB->IsEnabled())
1440 bLanguageCurrentDoc_Impl = bCurrentDocCBChecked;
1441 bool bCurrentDocCBChanged = m_pCurrentDocCB->IsValueChangedFromSaved();
1443 bool bValChanged = m_pWesternLanguageLB->IsValueChangedFromSaved();
1444 if( (bCurrentDocCBChanged && !bCurrentDocCBChecked) || bValChanged)
1446 LanguageType eSelectLang = m_pWesternLanguageLB->GetSelectLanguage();
1447 if(!bCurrentDocCBChecked)
1449 Any aValue;
1450 Locale aLocale = LanguageTag::convertToLocale( eSelectLang, false);
1451 aValue <<= aLocale;
1452 OUString aPropName( "DefaultLocale" );
1453 pLangConfig->aLinguConfig.SetProperty( aPropName, aValue );
1454 if (xLinguProp.is())
1455 xLinguProp->setDefaultLocale( aLocale );
1457 if(pCurrentDocShell)
1459 rSet->Put(SvxLanguageItem(MsLangId::resolveSystemLanguageByScriptType(eSelectLang, ::com::sun::star::i18n::ScriptType::LATIN),
1460 SID_ATTR_LANGUAGE));
1463 bValChanged = m_pAsianLanguageLB->IsValueChangedFromSaved();
1464 if( (bCurrentDocCBChanged && !bCurrentDocCBChecked) || bValChanged)
1466 LanguageType eSelectLang = m_pAsianLanguageLB->GetSelectLanguage();
1467 if(!bCurrentDocCBChecked)
1469 Any aValue;
1470 Locale aLocale = LanguageTag::convertToLocale( eSelectLang, false);
1471 aValue <<= aLocale;
1472 OUString aPropName( "DefaultLocale_CJK" );
1473 pLangConfig->aLinguConfig.SetProperty( aPropName, aValue );
1474 if (xLinguProp.is())
1475 xLinguProp->setDefaultLocale_CJK( aLocale );
1477 if(pCurrentDocShell)
1479 rSet->Put(SvxLanguageItem(MsLangId::resolveSystemLanguageByScriptType(eSelectLang, ::com::sun::star::i18n::ScriptType::ASIAN),
1480 SID_ATTR_CHAR_CJK_LANGUAGE));
1483 bValChanged = m_pComplexLanguageLB->IsValueChangedFromSaved();
1484 if( (bCurrentDocCBChanged && !bCurrentDocCBChecked) || bValChanged)
1486 LanguageType eSelectLang = m_pComplexLanguageLB->GetSelectLanguage();
1487 if(!bCurrentDocCBChecked)
1489 Any aValue;
1490 Locale aLocale = LanguageTag::convertToLocale( eSelectLang, false);
1491 aValue <<= aLocale;
1492 OUString aPropName( "DefaultLocale_CTL" );
1493 pLangConfig->aLinguConfig.SetProperty( aPropName, aValue );
1494 if (xLinguProp.is())
1495 xLinguProp->setDefaultLocale_CTL( aLocale );
1497 if(pCurrentDocShell)
1499 rSet->Put(SvxLanguageItem(MsLangId::resolveSystemLanguageByScriptType(eSelectLang, ::com::sun::star::i18n::ScriptType::COMPLEX),
1500 SID_ATTR_CHAR_CTL_LANGUAGE));
1504 if(m_pAsianSupportCB->IsValueChangedFromSaved() )
1506 bool bChecked = m_pAsianSupportCB->IsChecked();
1507 pLangConfig->aLanguageOptions.SetAll(bChecked);
1509 //iterate over all bindings to invalidate vertical text direction
1510 const sal_uInt16 STATE_COUNT = 2;
1512 SfxBoolItem* pBoolItems[STATE_COUNT];
1513 pBoolItems[0] = new SfxBoolItem(SID_VERTICALTEXT_STATE, false);
1514 pBoolItems[1] = new SfxBoolItem(SID_TEXT_FITTOSIZE_VERTICAL, false);
1516 SfxVoidItem* pInvalidItems[STATE_COUNT];
1517 pInvalidItems[0] = new SfxVoidItem(SID_VERTICALTEXT_STATE);
1518 pInvalidItems[1] = new SfxVoidItem(SID_TEXT_FITTOSIZE_VERTICAL);
1520 lcl_UpdateAndDelete(pInvalidItems, pBoolItems, STATE_COUNT);
1523 if ( m_pCTLSupportCB->IsValueChangedFromSaved() )
1525 SvtSearchOptions aOpt;
1526 aOpt.SetIgnoreDiacritics_CTL(true);
1527 aOpt.SetIgnoreKashida_CTL(true);
1528 aOpt.Commit();
1529 pLangConfig->aLanguageOptions.SetCTLFontEnabled( m_pCTLSupportCB->IsChecked() );
1531 const sal_uInt16 STATE_COUNT = 1;
1532 SfxBoolItem* pBoolItems[STATE_COUNT];
1533 pBoolItems[0] = new SfxBoolItem(SID_CTLFONT_STATE, false);
1534 SfxVoidItem* pInvalidItems[STATE_COUNT];
1535 pInvalidItems[0] = new SfxVoidItem(SID_CTLFONT_STATE);
1536 lcl_UpdateAndDelete(pInvalidItems, pBoolItems, STATE_COUNT);
1539 if ( pLangConfig->aSysLocaleOptions.IsModified() )
1540 pLangConfig->aSysLocaleOptions.Commit();
1542 // first release the lock on the ConfigurationBroadcaster for Locale changes
1543 // it seems that our code relies on the fact that before other changes like e.g. currency
1544 // are broadcasted locale changes have been done
1545 pLangConfig->aSysLocaleOptions.BlockBroadcasts( false );
1546 pLangConfig->aLanguageOptions.BlockBroadcasts( false );
1547 pLangConfig->aLinguConfig.BlockBroadcasts( false );
1549 return false;
1552 void OfaLanguagesTabPage::Reset( const SfxItemSet* rSet )
1554 OUString sLang = pLangConfig->aSysLocaleOptions.GetLocaleConfigString();
1555 if ( !sLang.isEmpty() )
1556 m_pLocaleSettingLB->SelectLanguage(LanguageTag::convertToLanguageTypeWithFallback(sLang));
1557 else
1558 m_pLocaleSettingLB->SelectLanguage( LANGUAGE_USER_SYSTEM_CONFIG );
1559 bool bReadonly = pLangConfig->aSysLocaleOptions.IsReadOnly(SvtSysLocaleOptions::E_LOCALE);
1560 m_pLocaleSettingLB->Enable(!bReadonly);
1561 m_pLocaleSettingFT->Enable(!bReadonly);
1564 m_pDecimalSeparatorCB->Check( pLangConfig->aSysLocaleOptions.IsDecimalSeparatorAsLocale());
1565 m_pDecimalSeparatorCB->SaveValue();
1567 m_pIgnoreLanguageChangeCB->Check( pLangConfig->aSysLocaleOptions.IsIgnoreLanguageChange());
1568 m_pIgnoreLanguageChangeCB->SaveValue();
1570 // let LocaleSettingHdl enable/disable checkboxes for CJK/CTL support
1571 // #i15812# must be done *before* the configured currency is set
1572 // and update the decimal separator used for the given locale
1573 LocaleSettingHdl(m_pLocaleSettingLB);
1575 // configured currency, for example, USD-en-US or EUR-de-DE, or empty for locale default
1576 OUString aAbbrev;
1577 LanguageType eLang;
1578 const NfCurrencyEntry* pCurr = NULL;
1579 sLang = pLangConfig->aSysLocaleOptions.GetCurrencyConfigString();
1580 if ( !sLang.isEmpty() )
1582 SvtSysLocaleOptions::GetCurrencyAbbrevAndLanguage( aAbbrev, eLang, sLang );
1583 pCurr = SvNumberFormatter::GetCurrencyEntry( aAbbrev, eLang );
1585 // if pCurr==NULL the SYSTEM entry is selected
1586 sal_uInt16 nPos = m_pCurrencyLB->GetEntryPos( (void*) pCurr );
1587 m_pCurrencyLB->SelectEntryPos( nPos );
1588 bReadonly = pLangConfig->aSysLocaleOptions.IsReadOnly(SvtSysLocaleOptions::E_CURRENCY);
1589 m_pCurrencyLB->Enable(!bReadonly);
1590 m_pCurrencyFT->Enable(!bReadonly);
1592 // date acceptance patterns
1593 OUString aDatePatternsString = pLangConfig->aSysLocaleOptions.GetDatePatternsConfigString();
1594 if (aDatePatternsString.isEmpty())
1596 const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
1597 aDatePatternsString = lcl_getDatePatternsConfigString( rLocaleWrapper);
1599 // Let's assume patterns are valid at this point.
1600 m_bDatePatternsValid = true;
1601 m_pDatePatternsED->SetText( aDatePatternsString);
1602 bReadonly = pLangConfig->aSysLocaleOptions.IsReadOnly(SvtSysLocaleOptions::E_DATEPATTERNS);
1603 m_pDatePatternsED->Enable(!bReadonly);
1604 m_pDatePatternsFT->Enable(!bReadonly);
1605 m_pDatePatternsED->SaveValue();
1607 //western/CJK/CLK language
1608 LanguageType eCurLang = LANGUAGE_NONE;
1609 LanguageType eCurLangCJK = LANGUAGE_NONE;
1610 LanguageType eCurLangCTL = LANGUAGE_NONE;
1611 SfxObjectShell* pCurrentDocShell = SfxObjectShell::Current();
1612 //collect the configuration values first
1613 m_pCurrentDocCB->Enable(false);
1615 Any aWestLang;
1616 Any aCJKLang;
1617 Any aCTLLang;
1620 aWestLang = pLangConfig->aLinguConfig.GetProperty("DefaultLocale");
1621 Locale aLocale;
1622 aWestLang >>= aLocale;
1624 eCurLang = LanguageTag::convertToLanguageType( aLocale, false);
1626 aCJKLang = pLangConfig->aLinguConfig.GetProperty("DefaultLocale_CJK");
1627 aLocale = Locale();
1628 aCJKLang >>= aLocale;
1629 eCurLangCJK = LanguageTag::convertToLanguageType( aLocale, false);
1631 aCTLLang = pLangConfig->aLinguConfig.GetProperty("DefaultLocale_CTL");
1632 aLocale = Locale();
1633 aCTLLang >>= aLocale;
1634 eCurLangCTL = LanguageTag::convertToLanguageType( aLocale, false);
1636 catch (const Exception&)
1639 //overwrite them by the values provided by the DocShell
1640 if(pCurrentDocShell)
1642 m_pCurrentDocCB->Enable(true);
1643 m_pCurrentDocCB->Check(bLanguageCurrentDoc_Impl);
1644 const SfxPoolItem* pLang;
1645 if( SfxItemState::SET == rSet->GetItemState(SID_ATTR_LANGUAGE, false, &pLang))
1647 LanguageType eTempCurLang = static_cast<const SvxLanguageItem*>(pLang)->GetValue();
1648 if (MsLangId::resolveSystemLanguageByScriptType(eCurLang, ::com::sun::star::i18n::ScriptType::LATIN) != eTempCurLang)
1649 eCurLang = eTempCurLang;
1652 if( SfxItemState::SET == rSet->GetItemState(SID_ATTR_CHAR_CJK_LANGUAGE, false, &pLang))
1654 LanguageType eTempCurLang = static_cast<const SvxLanguageItem*>(pLang)->GetValue();
1655 if (MsLangId::resolveSystemLanguageByScriptType(eCurLangCJK, ::com::sun::star::i18n::ScriptType::ASIAN) != eTempCurLang)
1656 eCurLangCJK = eTempCurLang;
1659 if( SfxItemState::SET == rSet->GetItemState(SID_ATTR_CHAR_CTL_LANGUAGE, false, &pLang))
1661 LanguageType eTempCurLang = static_cast<const SvxLanguageItem*>(pLang)->GetValue();
1662 if (MsLangId::resolveSystemLanguageByScriptType(eCurLangCTL, ::com::sun::star::i18n::ScriptType::COMPLEX) != eTempCurLang)
1663 eCurLangCTL = eTempCurLang;
1666 if(LANGUAGE_NONE == eCurLang || LANGUAGE_DONTKNOW == eCurLang)
1667 m_pWesternLanguageLB->SelectLanguage(LANGUAGE_NONE);
1668 else
1669 m_pWesternLanguageLB->SelectLanguage(eCurLang);
1671 if(LANGUAGE_NONE == eCurLangCJK || LANGUAGE_DONTKNOW == eCurLangCJK)
1672 m_pAsianLanguageLB->SelectLanguage(LANGUAGE_NONE);
1673 else
1674 m_pAsianLanguageLB->SelectLanguage(eCurLangCJK);
1676 if(LANGUAGE_NONE == eCurLangCTL || LANGUAGE_DONTKNOW == eCurLangCTL)
1677 m_pComplexLanguageLB->SelectLanguage(LANGUAGE_NONE);
1678 else
1679 m_pComplexLanguageLB->SelectLanguage(eCurLangCTL);
1681 m_pWesternLanguageLB->SaveValue();
1682 m_pAsianLanguageLB->SaveValue();
1683 m_pComplexLanguageLB->SaveValue();
1684 m_pIgnoreLanguageChangeCB->SaveValue();
1685 m_pCurrentDocCB->SaveValue();
1687 bool bEnable = !pLangConfig->aLinguConfig.IsReadOnly( "DefaultLocale" );
1688 m_pWesternLanguageFT->Enable( bEnable );
1689 m_pWesternLanguageLB->Enable( bEnable );
1693 // #i15812# controls for CJK/CTL already enabled/disabled from LocaleSettingHdl
1694 #if 0
1695 bEnable = ( !pLangConfig->aLinguConfig.IsReadOnly( "DefaultLocale_CJK" ) && m_pAsianSupportCB->IsChecked() );
1696 m_pAsianLanguageLB->Enable( bEnable );
1698 bEnable = ( !pLangConfig->aLinguConfig.IsReadOnly( "DefaultLocale_CTL" ) && m_pCTLSupportCB->IsChecked() );
1699 m_pComplexLanguageLB->Enable( bEnable );
1700 #endif
1701 // check the box "For the current document only"
1702 // set the focus to the Western Language box
1703 const SfxPoolItem* pLang = 0;
1704 if ( SfxItemState::SET == rSet->GetItemState(SID_SET_DOCUMENT_LANGUAGE, false, &pLang ) && static_cast<const SfxBoolItem*>(pLang)->GetValue() )
1706 m_pWesternLanguageLB->GrabFocus();
1707 m_pCurrentDocCB->Enable(true);
1708 m_pCurrentDocCB->Check(true);
1712 IMPL_LINK( OfaLanguagesTabPage, SupportHdl, CheckBox*, pBox )
1714 DBG_ASSERT( pBox, "OfaLanguagesTabPage::SupportHdl(): pBox invalid" );
1716 bool bCheck = pBox->IsChecked();
1717 if ( m_pAsianSupportCB == pBox )
1719 bool bReadonly = pLangConfig->aLinguConfig.IsReadOnly("DefaultLocale_CJK");
1720 bCheck = ( bCheck && !bReadonly );
1721 m_pAsianLanguageLB->Enable( bCheck );
1722 if( pBox->IsEnabled() )
1723 m_bOldAsian = bCheck;
1725 else if ( m_pCTLSupportCB == pBox )
1727 bool bReadonly = pLangConfig->aLinguConfig.IsReadOnly("DefaultLocale_CTL");
1728 bCheck = ( bCheck && !bReadonly );
1729 m_pComplexLanguageLB->Enable( bCheck );
1730 if( pBox->IsEnabled() )
1731 m_bOldCtl = bCheck;
1733 else
1734 SAL_WARN( "cui.options", "OfaLanguagesTabPage::SupportHdl(): wrong pBox" );
1736 return 0;
1739 namespace
1741 void lcl_checkLanguageCheckBox(CheckBox* _rCB,bool _bNewValue,bool _bOldValue)
1743 if ( _bNewValue )
1744 _rCB->Check(true);
1745 else
1746 _rCB->Check( _bOldValue );
1747 // #i15082# do not call SaveValue() in running dialog...
1748 // _rCB.SaveValue();
1749 _rCB->Enable( !_bNewValue );
1753 IMPL_LINK( OfaLanguagesTabPage, LocaleSettingHdl, SvxLanguageBox*, pBox )
1755 LanguageType eLang = pBox->GetSelectLanguage();
1756 SvtScriptType nType = SvtLanguageOptions::GetScriptTypeOfLanguage(eLang);
1757 // first check if CTL must be enabled
1758 // #103299# - if CTL font setting is not readonly
1759 if(!pLangConfig->aLanguageOptions.IsReadOnly(SvtLanguageOptions::E_CTLFONT))
1761 bool bIsCTLFixed = bool(nType & SvtScriptType::COMPLEX);
1762 lcl_checkLanguageCheckBox(m_pCTLSupportCB, bIsCTLFixed, m_bOldCtl);
1763 SupportHdl( m_pCTLSupportCB );
1765 // second check if CJK must be enabled
1766 // #103299# - if CJK support is not readonly
1767 if(!pLangConfig->aLanguageOptions.IsReadOnly(SvtLanguageOptions::E_ALLCJK))
1769 bool bIsCJKFixed = bool(nType & SvtScriptType::ASIAN);
1770 lcl_checkLanguageCheckBox(m_pAsianSupportCB, bIsCJKFixed, m_bOldAsian);
1771 SupportHdl( m_pAsianSupportCB );
1774 const NfCurrencyEntry* pCurr = &SvNumberFormatter::GetCurrencyEntry(
1775 ((eLang == LANGUAGE_USER_SYSTEM_CONFIG) ? MsLangId::getSystemLanguage() : eLang));
1776 sal_uInt16 nPos = m_pCurrencyLB->GetEntryPos( (void*) NULL );
1777 if (pCurr)
1779 // Update the "Default ..." currency.
1780 m_pCurrencyLB->RemoveEntry( nPos );
1781 OUString aDefaultCurr = m_sSystemDefaultString + " - " + pCurr->GetBankSymbol();
1782 nPos = m_pCurrencyLB->InsertEntry( aDefaultCurr );
1784 m_pCurrencyLB->SelectEntryPos( nPos );
1786 // obtain corresponding locale data
1787 LanguageTag aLanguageTag( eLang);
1788 LocaleDataWrapper aLocaleWrapper( aLanguageTag );
1790 // update the decimal separator key of the related CheckBox
1791 OUString sTempLabel(m_pDecimalSeparatorCB->GetText());
1792 sTempLabel = sTempLabel.replaceFirst("%1", aLocaleWrapper.getNumDecimalSep() );
1793 m_pDecimalSeparatorCB->SetText(sTempLabel);
1795 // update the date acceptance patterns
1796 OUString aDatePatternsString = lcl_getDatePatternsConfigString( aLocaleWrapper);
1797 m_bDatePatternsValid = true;
1798 m_pDatePatternsED->SetText( aDatePatternsString);
1800 return 0;
1803 IMPL_LINK( OfaLanguagesTabPage, DatePatternsHdl, Edit*, pEd )
1805 const OUString aPatterns( pEd->GetText());
1806 OUStringBuffer aBuf( aPatterns);
1807 sal_Int32 nChar = 0;
1808 bool bValid = true;
1809 bool bModified = false;
1810 if (!aPatterns.isEmpty())
1812 for (sal_Int32 nIndex=0; nIndex >= 0 && bValid; ++nChar)
1814 const OUString aPat( aPatterns.getToken( 0, ';', nIndex));
1815 if (aPat.isEmpty() && nIndex < 0)
1817 // Indicating failure when about to append a pattern is too
1818 // confusing. Empty patterns are ignored anyway when sequencing
1819 // to SvtSysLocale.
1820 continue; // for
1822 else if (aPat.getLength() < 2)
1823 bValid = false;
1824 else
1826 bool bY, bM, bD;
1827 bY = bM = bD = false;
1828 bool bSep = true;
1829 for (sal_Int32 i = 0; i < aPat.getLength() && bValid; /*nop*/)
1831 const sal_Int32 j = i;
1832 const sal_uInt32 c = aPat.iterateCodePoints( &i);
1833 // Only one Y,M,D per pattern, separated by any character(s).
1834 switch (c)
1836 case 'y':
1837 case 'Y':
1838 if (bY || !bSep)
1839 bValid = false;
1840 else if (c == 'y')
1842 aBuf[nChar] = 'Y';
1843 bModified = true;
1845 bY = true;
1846 bSep = false;
1847 break;
1848 case 'm':
1849 case 'M':
1850 if (bM || !bSep)
1851 bValid = false;
1852 else if (c == 'm')
1854 aBuf[nChar] = 'M';
1855 bModified = true;
1857 bM = true;
1858 bSep = false;
1859 break;
1860 case 'd':
1861 case 'D':
1862 if (bD || !bSep)
1863 bValid = false;
1864 else if (c == 'd')
1866 aBuf[nChar] = 'D';
1867 bModified = true;
1869 bD = true;
1870 bSep = false;
1871 break;
1872 default:
1873 // A pattern must not start with a separator (but
1874 // may end with).
1875 if (!(bY || bM || bD))
1876 bValid = false;
1877 bSep = true;
1879 nChar += i-j;
1881 // At least one of Y,M,D
1882 bValid &= (bY || bM || bD);
1886 if (bModified)
1888 // Do not use SetText(...,GetSelection()) because internally the
1889 // reference's pointer of the selection is obtained resulting in the
1890 // entire text being selected at the end.
1891 Selection aSelection( pEd->GetSelection());
1892 pEd->SetText( aBuf.makeStringAndClear(), aSelection);
1894 if (bValid)
1896 pEd->SetControlForeground();
1897 pEd->SetControlBackground();
1899 else
1901 #if 0
1902 //! Gives white on white!?! instead of white on reddish.
1903 pEd->SetControlBackground( ::Color( RGB_COLORDATA( 0xff, 0x65, 0x63)));
1904 pEd->SetControlForeground( ::Color( COL_WHITE));
1905 #else
1906 pEd->SetControlForeground( ::Color( RGB_COLORDATA( 0xf0, 0, 0)));
1907 #endif
1909 m_bDatePatternsValid = bValid;
1910 return 0;
1913 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */