Bump version to 4.3-4
[LibreOffice.git] / cui / source / options / optgdlg.cxx
blob7b6f9478fa7ae0eee03db3f9818fefe03b3bdc3a
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 <svtools/grfmgr.hxx>
22 #include <svl/flagitem.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <unotools/lingucfg.hxx>
25 #include <svl/szitem.hxx>
26 #include <sfx2/viewsh.hxx>
27 #include <sfx2/viewfrm.hxx>
28 #include <sfx2/imgmgr.hxx>
29 #include <vcl/configsettings.hxx>
30 #include <vcl/msgbox.hxx>
31 #include <vcl/mnemonic.hxx>
32 #include <i18nlangtag/mslangid.hxx>
33 #include <i18nlangtag/languagetag.hxx>
34 #include <unotools/compatibility.hxx>
35 #include <unotools/useroptions.hxx>
36 #include <unotools/fontoptions.hxx>
37 #include <svtools/menuoptions.hxx>
38 #include <svl/languageoptions.hxx>
39 #include <svtools/miscopt.hxx>
40 #include <unotools/printwarningoptions.hxx>
41 #include <unotools/syslocaleoptions.hxx>
42 #include <svtools/accessibilityoptions.hxx>
43 #include <unotools/configitem.hxx>
44 #include <sfx2/objsh.hxx>
45 #include <comphelper/string.hxx>
46 #include <comphelper/types.hxx>
47 #include <svtools/langtab.hxx>
48 #include <unotools/localfilehelper.hxx>
49 #include <unotools/configmgr.hxx>
50 #include "cuioptgenrl.hxx"
51 #include "optpath.hxx"
52 #include "optsave.hxx"
53 #include "optlingu.hxx"
54 #include <svx/xpool.hxx>
55 #include <svx/dlgutil.hxx>
56 #include "cuitabarea.hxx"
57 #include <cuires.hrc>
58 #include <editeng/unolingu.hxx>
59 #include <editeng/langitem.hxx>
60 #include <comphelper/processfactory.hxx>
61 #include <rtl/ustrbuf.hxx>
62 #include <editeng/editids.hrc>
63 #include <svx/svxids.hrc>
64 #include <svl/intitem.hxx>
65 #include <dialmgr.hxx>
66 #include <svtools/helpopt.hxx>
67 #include <unotools/saveopt.hxx>
68 #include <unotools/searchopt.hxx>
69 #include <sal/macros.h>
71 #include <com/sun/star/configuration/theDefaultProvider.hpp>
72 #include <com/sun/star/container/XNameAccess.hpp>
73 #include <com/sun/star/container/XNameReplace.hpp>
74 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
75 #include <com/sun/star/lang/XComponent.hpp>
76 #include <com/sun/star/lang/XInitialization.hpp>
77 #include <com/sun/star/beans/NamedValue.hpp>
78 #include <com/sun/star/beans/XPropertySet.hpp>
79 #include <com/sun/star/util/XChangesBatch.hpp>
80 #include <com/sun/star/uno/Any.hxx>
81 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
82 #include <com/sun/star/container/XSet.hpp>
83 #include <com/sun/star/i18n/ScriptType.hpp>
84 #include <com/sun/star/office/Quickstart.hpp>
86 #include <vcl/svapp.hxx>
87 #include <vcl/settings.hxx>
88 #include <vcl/IconThemeInfo.hxx>
90 #include "optgdlg.hxx"
91 #include <svx/ofaitem.hxx>
92 #include <svtools/apearcfg.hxx>
93 #include <svtools/optionsdrawinglayer.hxx>
95 #include <config_vclplug.h>
97 using namespace ::com::sun::star::uno;
98 using namespace ::com::sun::star::lang;
99 using namespace ::com::sun::star::beans;
100 using namespace ::com::sun::star::container;
101 using namespace ::com::sun::star::util;
102 using namespace ::utl;
104 // class OfaMiscTabPage --------------------------------------------------
106 int OfaMiscTabPage::DeactivatePage( SfxItemSet* pSet_ )
108 if ( pSet_ )
109 FillItemSet( *pSet_ );
110 return LEAVE_PAGE;
113 namespace
115 static OUString impl_SystemFileOpenServiceName()
117 const OUString &rDesktopEnvironment = Application::GetDesktopEnvironment();
119 if ( rDesktopEnvironment.equalsIgnoreAsciiCase("kde4") )
121 #if ENABLE_KDE4
122 return OUString("com.sun.star.ui.dialogs.KDE4FilePicker" );
123 #else
124 return OUString();
125 #endif
127 else if ( rDesktopEnvironment.equalsIgnoreAsciiCase("kde") )
129 #if ENABLE_KDE
130 return OUString("com.sun.star.ui.dialogs.KDEFilePicker");
131 #else
132 return OUString();
133 #endif
135 else if ( rDesktopEnvironment.equalsIgnoreAsciiCase("tde") )
137 #if ENABLE_TDE
138 return OUString("com.sun.star.ui.dialogs.TDEFilePicker");
139 #else
140 return OUString();
141 #endif
143 #if defined WNT
144 return OUString("com.sun.star.ui.dialogs.SystemFilePicker");
145 #elif defined MACOSX
146 return OUString("com.sun.star.ui.dialogs.AquaFilePicker");
147 #else
148 return OUString();
149 #endif
152 static bool lcl_HasSystemFilePicker()
154 if( Application::hasNativeFileSelection() )
155 return true;
157 // Otherwise fall-back on querying services
158 bool bRet = false;
159 Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
161 Reference< XContentEnumerationAccess > xEnumAccess( xFactory, UNO_QUERY );
162 Reference< XSet > xSet( xFactory, UNO_QUERY );
164 if ( ! xEnumAccess.is() || ! xSet.is() )
165 return bRet;
169 OUString aFileService = impl_SystemFileOpenServiceName();
170 Reference< XEnumeration > xEnum = xEnumAccess->createContentEnumeration( aFileService );
171 if ( xEnum.is() && xEnum->hasMoreElements() )
172 bRet = true;
174 catch (const IllegalArgumentException&)
177 catch (const ElementExistException&)
180 return bRet;
186 OfaMiscTabPage::OfaMiscTabPage(Window* pParent, const SfxItemSet& rSet)
187 : SfxTabPage(pParent, "OptGeneralPage", "cui/ui/optgeneralpage.ui", rSet)
189 get(m_pToolTipsCB, "tooltips");
190 get(m_pExtHelpCB, "exthelp");
191 if (!lcl_HasSystemFilePicker())
192 get<VclContainer>("filedlgframe")->Hide();
193 #if ! ENABLE_GTK
194 get<VclContainer>("printdlgframe")->Hide();
195 #else
196 if (!SvtMiscOptions().IsExperimentalMode())
198 get<VclContainer>("printdlgframe")->Hide();
200 #endif
201 get(m_pFileDlgCB, "filedlg");
202 get(m_pFileDlgROImage, "lockimage");
203 get(m_pPrintDlgCB, "printdlg");
204 get(m_pDocStatusCB, "docstatus");
205 get(m_pSaveAlwaysCB, "savealways");
206 get(m_pYearFrame, "yearframe");
207 get(m_pYearValueField, "year");
208 get(m_pToYearFT, "toyear");
210 if (m_pFileDlgCB->IsVisible() && SvtMiscOptions().IsUseSystemFileDialogReadOnly())
212 m_pFileDlgROImage->Show();
213 m_pFileDlgCB->Disable();
216 m_aStrDateInfo = m_pToYearFT->GetText();
217 m_pYearValueField->SetModifyHdl( LINK( this, OfaMiscTabPage, TwoFigureHdl ) );
218 Link aLink = LINK( this, OfaMiscTabPage, TwoFigureConfigHdl );
219 m_pYearValueField->SetDownHdl( aLink );
220 m_pYearValueField->SetUpHdl( aLink );
221 m_pYearValueField->SetLoseFocusHdl( aLink );
222 m_pYearValueField->SetFirstHdl( aLink );
223 TwoFigureConfigHdl(m_pYearValueField);
225 SetExchangeSupport();
227 aLink = LINK( this, OfaMiscTabPage, HelpCheckHdl_Impl );
228 m_pToolTipsCB->SetClickHdl( aLink );
233 OfaMiscTabPage::~OfaMiscTabPage()
239 SfxTabPage* OfaMiscTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
241 return new OfaMiscTabPage( pParent, rAttrSet );
246 bool OfaMiscTabPage::FillItemSet( SfxItemSet& rSet )
248 bool bModified = false;
250 SvtHelpOptions aHelpOptions;
251 if ( m_pToolTipsCB->IsValueChangedFromSaved() )
252 aHelpOptions.SetHelpTips( m_pToolTipsCB->IsChecked() );
253 bool bChecked = ( m_pExtHelpCB->IsChecked() && m_pToolTipsCB->IsChecked() );
254 if ( bChecked != (m_pExtHelpCB->GetSavedValue() == TRISTATE_TRUE) )
255 aHelpOptions.SetExtendedHelp( bChecked );
257 if ( m_pFileDlgCB->IsValueChangedFromSaved() )
259 SvtMiscOptions aMiscOpt;
260 aMiscOpt.SetUseSystemFileDialog( !m_pFileDlgCB->IsChecked() );
261 bModified = true;
264 if ( m_pPrintDlgCB->IsValueChangedFromSaved() )
266 SvtMiscOptions aMiscOpt;
267 aMiscOpt.SetUseSystemPrintDialog( !m_pPrintDlgCB->IsChecked() );
268 bModified = true;
271 if ( m_pDocStatusCB->IsValueChangedFromSaved() )
273 SvtPrintWarningOptions aPrintOptions;
274 aPrintOptions.SetModifyDocumentOnPrintingAllowed( m_pDocStatusCB->IsChecked() );
275 bModified = true;
278 if ( m_pSaveAlwaysCB->IsValueChangedFromSaved() )
280 SvtMiscOptions aMiscOpt;
281 aMiscOpt.SetSaveAlwaysAllowed( m_pSaveAlwaysCB->IsChecked() );
282 bModified = true;
285 const SfxUInt16Item* pUInt16Item =
286 PTR_CAST( SfxUInt16Item, GetOldItem( rSet, SID_ATTR_YEAR2000 ) );
287 sal_uInt16 nNum = (sal_uInt16)m_pYearValueField->GetText().toInt32();
288 if ( pUInt16Item && pUInt16Item->GetValue() != nNum )
290 bModified = true;
291 rSet.Put( SfxUInt16Item( SID_ATTR_YEAR2000, nNum ) );
294 return bModified;
299 void OfaMiscTabPage::Reset( const SfxItemSet& rSet )
301 SvtHelpOptions aHelpOptions;
302 m_pToolTipsCB->Check( aHelpOptions.IsHelpTips() );
303 m_pExtHelpCB->Check( aHelpOptions.IsHelpTips() && aHelpOptions.IsExtendedHelp() );
305 m_pToolTipsCB->SaveValue();
306 m_pExtHelpCB->SaveValue();
308 SvtMiscOptions aMiscOpt;
309 m_pFileDlgCB->Check( !aMiscOpt.UseSystemFileDialog() );
310 m_pFileDlgCB->SaveValue();
311 m_pPrintDlgCB->Check( !aMiscOpt.UseSystemPrintDialog() );
312 m_pPrintDlgCB->SaveValue();
313 m_pSaveAlwaysCB->Check( aMiscOpt.IsSaveAlwaysAllowed() );
314 m_pSaveAlwaysCB->SaveValue();
316 SvtPrintWarningOptions aPrintOptions;
317 m_pDocStatusCB->Check(aPrintOptions.IsModifyDocumentOnPrintingAllowed());
318 m_pDocStatusCB->SaveValue();
320 const SfxPoolItem* pItem = NULL;
321 if ( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_YEAR2000, false, &pItem ) )
323 m_pYearValueField->SetValue( ((SfxUInt16Item*)pItem)->GetValue() );
324 TwoFigureConfigHdl(m_pYearValueField);
326 else
328 m_pYearFrame->Enable(false);
334 IMPL_LINK( OfaMiscTabPage, TwoFigureHdl, NumericField*, pEd )
336 (void)pEd;
338 OUString aOutput( m_aStrDateInfo );
339 OUString aStr( m_pYearValueField->GetText() );
340 OUString sSep( SvtSysLocale().GetLocaleData().getNumThousandSep() );
341 sal_Int32 nIndex = 0;
342 while ((nIndex = aStr.indexOf( sSep, nIndex)) != -1)
343 aStr = aStr.replaceAt( nIndex, sSep.getLength(), "");
344 sal_Int32 nNum = aStr.toInt32();
345 if ( aStr.getLength() != 4 || nNum < m_pYearValueField->GetMin() || nNum > m_pYearValueField->GetMax() )
346 aOutput += "????";
347 else
349 nNum += 99;
350 aOutput += OUString::number( nNum );
352 m_pToYearFT->SetText( aOutput );
353 return 0;
358 IMPL_LINK( OfaMiscTabPage, TwoFigureConfigHdl, NumericField*, pEd )
360 sal_Int64 nNum = m_pYearValueField->GetValue();
361 OUString aOutput(OUString::number(nNum));
362 m_pYearValueField->SetText(aOutput);
363 m_pYearValueField->SetSelection( Selection( 0, aOutput.getLength() ) );
364 TwoFigureHdl( pEd );
365 return 0;
370 IMPL_LINK_NOARG(OfaMiscTabPage, HelpCheckHdl_Impl)
372 m_pExtHelpCB->Enable( m_pToolTipsCB->IsChecked() );
373 return 0;
378 class CanvasSettings
380 public:
381 CanvasSettings();
383 bool IsHardwareAccelerationEnabled() const;
384 bool IsHardwareAccelerationAvailable() const;
385 void EnabledHardwareAcceleration( bool _bEnabled ) const;
387 private:
388 typedef std::vector< std::pair<OUString,Sequence<OUString> > > ServiceVector;
390 Reference<XNameAccess> mxForceFlagNameAccess;
391 ServiceVector maAvailableImplementations;
392 mutable bool mbHWAccelAvailable;
393 mutable bool mbHWAccelChecked;
397 CanvasSettings::CanvasSettings() :
398 mxForceFlagNameAccess(),
399 mbHWAccelAvailable(false),
400 mbHWAccelChecked(false)
404 Reference<XMultiServiceFactory> xConfigProvider(
405 com::sun::star::configuration::theDefaultProvider::get(
406 comphelper::getProcessComponentContext()));
408 Any propValue(
409 makeAny( NamedValue(
410 OUString("nodepath"),
411 makeAny( OUString("/org.openoffice.Office.Canvas") ) ) ) );
413 mxForceFlagNameAccess.set(
414 xConfigProvider->createInstanceWithArguments(
415 OUString("com.sun.star.configuration.ConfigurationUpdateAccess"),
416 Sequence<Any>( &propValue, 1 ) ),
417 UNO_QUERY_THROW );
419 propValue = makeAny(
420 NamedValue(
421 OUString("nodepath"),
422 makeAny( OUString("/org.openoffice.Office.Canvas/CanvasServiceList") ) ) );
424 Reference<XNameAccess> xNameAccess(
425 xConfigProvider->createInstanceWithArguments(
426 OUString("com.sun.star.configuration.ConfigurationAccess"),
427 Sequence<Any>( &propValue, 1 ) ), UNO_QUERY_THROW );
428 Reference<XHierarchicalNameAccess> xHierarchicalNameAccess(
429 xNameAccess, UNO_QUERY_THROW);
431 Sequence<OUString> serviceNames = xNameAccess->getElementNames();
432 const OUString* pCurr = serviceNames.getConstArray();
433 const OUString* const pEnd = pCurr + serviceNames.getLength();
434 while( pCurr != pEnd )
436 Reference<XNameAccess> xEntryNameAccess(
437 xHierarchicalNameAccess->getByHierarchicalName(*pCurr),
438 UNO_QUERY );
440 if( xEntryNameAccess.is() )
442 Sequence<OUString> preferredImplementations;
443 if( (xEntryNameAccess->getByName("PreferredImplementations") >>= preferredImplementations) )
444 maAvailableImplementations.push_back( std::make_pair(*pCurr,preferredImplementations) );
447 ++pCurr;
450 catch (const Exception&)
456 bool CanvasSettings::IsHardwareAccelerationAvailable() const
458 if( !mbHWAccelChecked )
460 mbHWAccelChecked = true;
462 Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
464 // check whether any of the service lists has an
465 // implementation that presents the "HardwareAcceleration" property
466 ServiceVector::const_iterator aCurr=maAvailableImplementations.begin();
467 const ServiceVector::const_iterator aEnd=maAvailableImplementations.end();
468 while( aCurr != aEnd )
470 const OUString* pCurrImpl = aCurr->second.getConstArray();
471 const OUString* const pEndImpl = pCurrImpl + aCurr->second.getLength();
473 while( pCurrImpl != pEndImpl )
477 Reference<XPropertySet> xPropSet( xFactory->createInstance(
478 pCurrImpl->trim() ),
479 UNO_QUERY_THROW );
480 bool bHasAccel(false);
481 if( (xPropSet->getPropertyValue("HardwareAcceleration") >>= bHasAccel) )
482 if( bHasAccel )
484 mbHWAccelAvailable = true;
485 return mbHWAccelAvailable;
488 catch (const Exception&)
492 ++pCurrImpl;
495 ++aCurr;
499 return mbHWAccelAvailable;
503 bool CanvasSettings::IsHardwareAccelerationEnabled() const
505 bool bForceLastEntry(false);
506 if( !mxForceFlagNameAccess.is() )
507 return true;
509 if( !(mxForceFlagNameAccess->getByName("ForceSafeServiceImpl") >>= bForceLastEntry) )
510 return true;
512 return !bForceLastEntry;
516 void CanvasSettings::EnabledHardwareAcceleration( bool _bEnabled ) const
518 Reference< XNameReplace > xNameReplace(
519 mxForceFlagNameAccess, UNO_QUERY );
521 if( !xNameReplace.is() )
522 return;
524 xNameReplace->replaceByName( OUString("ForceSafeServiceImpl"),
525 makeAny(!_bEnabled) );
527 Reference< XChangesBatch > xChangesBatch(
528 mxForceFlagNameAccess, UNO_QUERY );
530 if( !xChangesBatch.is() )
531 return;
533 xChangesBatch->commitChanges();
536 // class OfaViewTabPage --------------------------------------------------
538 OfaViewTabPage::OfaViewTabPage(Window* pParent, const SfxItemSet& rSet)
539 : SfxTabPage(pParent, "OptViewPage", "cui/ui/optviewpage.ui", rSet)
540 , nSizeLB_InitialSelection(0)
541 , nStyleLB_InitialSelection(0)
542 , pAppearanceCfg(new SvtTabAppearanceCfg)
543 , pCanvasSettings(new CanvasSettings)
544 , mpDrawinglayerOpt(new SvtOptionsDrawinglayer)
546 get(m_pWindowSizeMF, "windowsize");
547 get(m_pIconSizeLB, "iconsize");
548 get(m_pIconStyleLB, "iconstyle");
549 get(m_pSystemFont, "systemfont");
551 VclContainer *pRef = get<VclContainer>("refgrid");
552 //fdo#65595, we need height-for-width support here, but for now we can
553 //bodge it
554 Size aPrefSize(m_pSystemFont->get_preferred_size());
555 Size aSize(pRef->get_preferred_size());
556 if (aPrefSize.Width() > aSize.Width())
558 aSize = m_pSystemFont->CalcMinimumSize(aSize.Width());
559 m_pSystemFont->set_width_request(aSize.Width());
560 m_pSystemFont->set_height_request(aSize.Height());
563 get(m_pFontAntiAliasing, "aafont");
564 get(m_pAAPointLimitLabel, "aafrom");
565 get(m_pAAPointLimit, "aanf");
566 get(m_pMenuIconsLB, "menuicons");
567 get(m_pFontShowCB, "showfontpreview");
568 get(m_pFontHistoryCB, "showfonthistory");
569 get(m_pUseHardwareAccell, "useaccel");
570 get(m_pUseAntiAliase, "useaa");
571 get(m_pMousePosLB, "mousepos");
572 get(m_pMouseMiddleLB, "mousemiddle");
573 // #i97672#
574 get(m_pSelectionCB, "trans");
575 get(m_pSelectionMF, "transmf");
577 #if defined( UNX )
578 m_pFontAntiAliasing->SetToggleHdl( LINK( this, OfaViewTabPage, OnAntialiasingToggled ) );
579 #else
580 // on this platform, we do not have the anti aliasing options
581 m_pFontAntiAliasing->Hide();
582 m_pAAPointLimitLabel->Hide();
583 m_pAAPointLimit->Hide();
585 #endif
587 // #i97672#
588 m_pSelectionCB->SetToggleHdl( LINK( this, OfaViewTabPage, OnSelectionToggled ) );
590 if( ! Application::ValidateSystemFont() )
592 m_pSystemFont->Check(false);
593 m_pSystemFont->Enable(false);
596 // Set known icon themes
597 OUString sAutoStr( m_pIconStyleLB->GetEntry( 0 ) );
598 m_pIconStyleLB->Clear();
599 StyleSettings aStyleSettings = Application::GetSettings().GetStyleSettings();
600 mInstalledIconThemes = aStyleSettings.GetInstalledIconThemes();
602 // Start with the automatically chosen icon theme
603 OUString autoThemeId = aStyleSettings.GetAutomaticallyChosenIconTheme();
604 const vcl::IconThemeInfo& autoIconTheme = vcl::IconThemeInfo::FindIconThemeById(mInstalledIconThemes, autoThemeId);
606 OUString entryForAuto = sAutoStr + OUString(" (") +
607 autoIconTheme.GetDisplayName() +
608 OUString(")");
609 m_pIconStyleLB->InsertEntry(entryForAuto);
611 for (std::vector<vcl::IconThemeInfo>::const_iterator aI = mInstalledIconThemes.begin(); aI != mInstalledIconThemes.end(); ++aI) {
612 m_pIconStyleLB->InsertEntry(aI->GetDisplayName());
615 // separate auto and other icon themes
616 m_pIconStyleLB->SetSeparatorPos( 0 );
617 m_pIconStyleLB->SelectEntryPos(0);
620 OfaViewTabPage::~OfaViewTabPage()
622 delete mpDrawinglayerOpt;
623 delete pCanvasSettings;
624 delete pAppearanceCfg;
627 #if defined( UNX )
628 IMPL_LINK( OfaViewTabPage, OnAntialiasingToggled, void*, NOTINTERESTEDIN )
630 (void)NOTINTERESTEDIN;
632 bool bAAEnabled = m_pFontAntiAliasing->IsChecked();
634 m_pAAPointLimitLabel->Enable( bAAEnabled );
635 m_pAAPointLimit->Enable( bAAEnabled );
637 return 0L;
639 #endif
641 // #i97672#
642 IMPL_LINK( OfaViewTabPage, OnSelectionToggled, void*, NOTINTERESTEDIN )
644 (void)NOTINTERESTEDIN;
645 const bool bSelectionEnabled(m_pSelectionCB->IsChecked());
646 m_pSelectionMF->Enable(bSelectionEnabled);
647 return 0;
650 SfxTabPage* OfaViewTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
652 return new OfaViewTabPage(pParent, rAttrSet);
655 bool OfaViewTabPage::FillItemSet( SfxItemSet& )
657 SvtFontOptions aFontOpt;
658 SvtMenuOptions aMenuOpt;
660 bool bModified = false;
661 bool bMenuOptModified = false;
662 bool bRepaintWindows(false);
664 SvtMiscOptions aMiscOptions;
665 sal_uInt16 nSizeLB_NewSelection = m_pIconSizeLB->GetSelectEntryPos();
666 if( nSizeLB_InitialSelection != nSizeLB_NewSelection )
668 // from now on it's modified, even if via auto setting the same size was set as now selected in the LB
669 sal_Int16 eSet = SFX_SYMBOLS_SIZE_AUTO;
670 switch( nSizeLB_NewSelection )
672 case 0: eSet = SFX_SYMBOLS_SIZE_AUTO; break;
673 case 1: eSet = SFX_SYMBOLS_SIZE_SMALL; break;
674 case 2: eSet = SFX_SYMBOLS_SIZE_LARGE; break;
675 default:
676 OSL_FAIL( "OfaViewTabPage::FillItemSet(): This state of m_pIconSizeLB should not be possible!" );
678 aMiscOptions.SetSymbolsSize( eSet );
681 sal_uInt16 nStyleLB_NewSelection = m_pIconStyleLB->GetSelectEntryPos();
682 if( nStyleLB_InitialSelection != nStyleLB_NewSelection )
684 // 0 means choose style automatically
685 if (nStyleLB_NewSelection == 0) {
686 aMiscOptions.SetIconThemeAutomatically();
688 else {
689 sal_uInt16 pos = m_pIconStyleLB->GetSelectEntryPos();
690 const vcl::IconThemeInfo& iconThemeId = mInstalledIconThemes.at(pos-1);
691 aMiscOptions.SetIconTheme(iconThemeId.GetThemeId());
693 nStyleLB_InitialSelection = nStyleLB_NewSelection;
696 bool bAppearanceChanged = false;
699 // Screen Scaling
700 sal_uInt16 nOldScale = pAppearanceCfg->GetScaleFactor();
701 sal_uInt16 nNewScale = (sal_uInt16)m_pWindowSizeMF->GetValue();
703 if ( nNewScale != nOldScale )
705 pAppearanceCfg->SetScaleFactor(nNewScale);
706 bAppearanceChanged = true;
709 // Mouse Snap Mode
710 short eOldSnap = pAppearanceCfg->GetSnapMode();
711 short eNewSnap = m_pMousePosLB->GetSelectEntryPos();
712 if(eNewSnap > 2)
713 eNewSnap = 2;
715 if ( eNewSnap != eOldSnap )
717 pAppearanceCfg->SetSnapMode(eNewSnap );
718 bAppearanceChanged = true;
721 // Middle Mouse Button
722 short eOldMiddleMouse = pAppearanceCfg->GetMiddleMouseButton();
723 short eNewMiddleMouse = m_pMouseMiddleLB->GetSelectEntryPos();
724 if(eNewMiddleMouse > 2)
725 eNewMiddleMouse = 2;
727 if ( eNewMiddleMouse != eOldMiddleMouse )
729 pAppearanceCfg->SetMiddleMouseButton( eNewMiddleMouse );
730 bAppearanceChanged = true;
733 #if defined( UNX )
734 if ( m_pFontAntiAliasing->IsValueChangedFromSaved() )
736 pAppearanceCfg->SetFontAntiAliasing( m_pFontAntiAliasing->IsChecked() );
737 bAppearanceChanged = true;
740 if ( m_pAAPointLimit->IsValueChangedFromSaved() )
742 pAppearanceCfg->SetFontAntialiasingMinPixelHeight( m_pAAPointLimit->GetValue() );
743 bAppearanceChanged = true;
745 #endif
747 if ( m_pFontShowCB->IsValueChangedFromSaved() )
749 aFontOpt.EnableFontWYSIWYG( m_pFontShowCB->IsChecked() );
750 bModified = true;
753 if(m_pMenuIconsLB->IsValueChangedFromSaved())
755 aMenuOpt.SetMenuIconsState(m_pMenuIconsLB->GetSelectEntryPos() == 0 ?
756 TRISTATE_INDET :
757 static_cast<TriState>(m_pMenuIconsLB->GetSelectEntryPos() - 1));
758 bModified = true;
759 bMenuOptModified = true;
760 bAppearanceChanged = true;
763 if ( m_pFontHistoryCB->IsValueChangedFromSaved() )
765 aFontOpt.EnableFontHistory( m_pFontHistoryCB->IsChecked() );
766 bModified = true;
769 // #i95644# if disabled, do not use value, see in ::Reset()
770 if(m_pUseHardwareAccell->IsEnabled())
772 if(m_pUseHardwareAccell->IsValueChangedFromSaved())
774 pCanvasSettings->EnabledHardwareAcceleration(m_pUseHardwareAccell->IsChecked());
775 bModified = true;
779 // #i95644# if disabled, do not use value, see in ::Reset()
780 if(m_pUseAntiAliase->IsEnabled())
782 if(m_pUseAntiAliase->IsChecked() != mpDrawinglayerOpt->IsAntiAliasing())
784 mpDrawinglayerOpt->SetAntiAliasing(m_pUseAntiAliase->IsChecked());
785 bModified = true;
786 bRepaintWindows = true;
790 // #i97672#
791 if(m_pSelectionCB->IsEnabled())
793 const bool bNewSelection(m_pSelectionCB->IsChecked());
794 const sal_uInt16 nNewTransparence((sal_uInt16)m_pSelectionMF->GetValue());
796 if(bNewSelection != (bool)mpDrawinglayerOpt->IsTransparentSelection())
798 mpDrawinglayerOpt->SetTransparentSelection(m_pSelectionCB->IsChecked());
799 bModified = true;
800 bRepaintWindows = true;
803 // #i104150# even read the value when m_pSelectionMF is disabled; it may have been
804 // modified by enabling-modify-disabling by the user
805 if(nNewTransparence != mpDrawinglayerOpt->GetTransparentSelectionPercent())
807 mpDrawinglayerOpt->SetTransparentSelectionPercent(nNewTransparence);
808 bModified = true;
809 bRepaintWindows = true;
813 SvtAccessibilityOptions aAccessibilityOptions;
814 if( aAccessibilityOptions.GetIsSystemFont() != m_pSystemFont->IsChecked() &&
815 m_pSystemFont->IsEnabled() )
817 aAccessibilityOptions.SetIsSystemFont( m_pSystemFont->IsChecked() );
818 bModified = true;
819 bMenuOptModified = true;
822 if( bMenuOptModified )
824 // Set changed settings to the application instance
825 AllSettings aAllSettings = Application::GetSettings();
826 StyleSettings aStyleSettings = aAllSettings.GetStyleSettings();
827 if( m_pSystemFont->IsEnabled() )
828 aStyleSettings.SetUseSystemUIFonts( m_pSystemFont->IsChecked() );
829 aAllSettings.SetStyleSettings(aStyleSettings);
830 Application::MergeSystemSettings( aAllSettings );
831 Application::SetSettings(aAllSettings);
834 if ( bAppearanceChanged )
836 pAppearanceCfg->Commit();
837 pAppearanceCfg->SetApplicationDefaults ( GetpApp() );
840 if(bRepaintWindows)
842 Window* pAppWindow = Application::GetFirstTopLevelWindow();
844 while(pAppWindow)
846 pAppWindow->Invalidate();
847 pAppWindow = Application::GetNextTopLevelWindow(pAppWindow);
851 return bModified;
854 void OfaViewTabPage::Reset( const SfxItemSet& )
856 SvtMiscOptions aMiscOptions;
858 if( aMiscOptions.GetSymbolsSize() != SFX_SYMBOLS_SIZE_AUTO )
859 nSizeLB_InitialSelection = ( aMiscOptions.AreCurrentSymbolsLarge() )? 2 : 1;
860 m_pIconSizeLB->SelectEntryPos( nSizeLB_InitialSelection );
861 m_pIconSizeLB->SaveValue();
863 if (aMiscOptions.IconThemeWasSetAutomatically()) {
864 nStyleLB_InitialSelection = 0;
866 else {
867 const OUString& selected = aMiscOptions.GetIconTheme();
868 const vcl::IconThemeInfo& selectedInfo =
869 vcl::IconThemeInfo::FindIconThemeById(mInstalledIconThemes, selected);
870 nStyleLB_InitialSelection = m_pIconStyleLB->GetEntryPos(selectedInfo.GetDisplayName());
873 m_pIconStyleLB->SelectEntryPos( nStyleLB_InitialSelection );
874 m_pIconStyleLB->SaveValue();
876 if( m_pSystemFont->IsEnabled() )
878 SvtAccessibilityOptions aAccessibilityOptions;
879 m_pSystemFont->Check( aAccessibilityOptions.GetIsSystemFont() );
882 // Screen Scaling
883 m_pWindowSizeMF->SetValue ( pAppearanceCfg->GetScaleFactor() );
884 // Mouse Snap
885 m_pMousePosLB->SelectEntryPos(pAppearanceCfg->GetSnapMode());
886 m_pMousePosLB->SaveValue();
888 // Mouse Snap
889 m_pMouseMiddleLB->SelectEntryPos(pAppearanceCfg->GetMiddleMouseButton());
890 m_pMouseMiddleLB->SaveValue();
892 #if defined( UNX )
893 m_pFontAntiAliasing->Check( pAppearanceCfg->IsFontAntiAliasing() );
894 m_pAAPointLimit->SetValue( pAppearanceCfg->GetFontAntialiasingMinPixelHeight() );
895 #endif
897 // WorkingSet
898 SvtFontOptions aFontOpt;
899 m_pFontShowCB->Check( aFontOpt.IsFontWYSIWYGEnabled() );
900 SvtMenuOptions aMenuOpt;
901 m_pMenuIconsLB->SelectEntryPos(aMenuOpt.GetMenuIconsState() == 2 ? 0 : aMenuOpt.GetMenuIconsState() + 1);
902 m_pMenuIconsLB->SaveValue();
903 m_pFontHistoryCB->Check( aFontOpt.IsFontHistoryEnabled() );
905 { // #i95644# HW accel (unified to disable mechanism)
906 if(pCanvasSettings->IsHardwareAccelerationAvailable())
908 m_pUseHardwareAccell->Check(pCanvasSettings->IsHardwareAccelerationEnabled());
910 else
912 m_pUseHardwareAccell->Check(false);
913 m_pUseHardwareAccell->Disable();
916 m_pUseHardwareAccell->SaveValue();
919 { // #i95644# AntiAliasing
920 if(mpDrawinglayerOpt->IsAAPossibleOnThisSystem())
922 m_pUseAntiAliase->Check(mpDrawinglayerOpt->IsAntiAliasing());
924 else
926 m_pUseAntiAliase->Check(false);
927 m_pUseAntiAliase->Disable();
930 m_pUseAntiAliase->SaveValue();
934 // #i97672# Selection
935 // check if transparent selection is possible on this system
936 const bool bTransparentSelectionPossible(
937 !GetSettings().GetStyleSettings().GetHighContrastMode()
938 && SupportsOperation(OutDevSupport_TransparentRect));
940 // enter values
941 if(bTransparentSelectionPossible)
943 m_pSelectionCB->Check(mpDrawinglayerOpt->IsTransparentSelection());
945 else
947 m_pSelectionCB->Enable(false);
950 m_pSelectionMF->SetValue(mpDrawinglayerOpt->GetTransparentSelectionPercent());
951 m_pSelectionMF->Enable(mpDrawinglayerOpt->IsTransparentSelection() && bTransparentSelectionPossible);
954 #if defined( UNX )
955 m_pFontAntiAliasing->SaveValue();
956 m_pAAPointLimit->SaveValue();
957 #endif
958 m_pFontShowCB->SaveValue();
959 m_pFontHistoryCB->SaveValue();
961 #if defined( UNX )
962 LINK( this, OfaViewTabPage, OnAntialiasingToggled ).Call( NULL );
963 #endif
966 struct LanguageConfig_Impl
968 SvtLanguageOptions aLanguageOptions;
969 SvtSysLocaleOptions aSysLocaleOptions;
970 SvtLinguConfig aLinguConfig;
973 static bool bLanguageCurrentDoc_Impl = false;
975 // some things we'll need...
976 static const OUString sAccessSrvc("com.sun.star.configuration.ConfigurationAccess");
977 static const OUString sAccessUpdSrvc("com.sun.star.configuration.ConfigurationUpdateAccess");
978 static const OUString sInstalledLocalesPath("org.openoffice.Setup/Office/InstalledLocales");
979 static OUString sUserLocalePath("org.openoffice.Office.Linguistic/General");
980 //static const OUString sUserLocalePath("org.openoffice.Office/Linguistic");
981 static const OUString sUserLocaleKey("UILocale");
982 static Sequence< OUString > seqInstalledLanguages;
984 static OUString lcl_getDatePatternsConfigString( const LocaleDataWrapper& rLocaleWrapper )
986 Sequence< OUString > aDateAcceptancePatterns = rLocaleWrapper.getDateAcceptancePatterns();
987 sal_Int32 nPatterns = aDateAcceptancePatterns.getLength();
988 OUStringBuffer aBuf( nPatterns * 6 ); // 6 := length of Y-M-D;
989 SAL_WARN_IF( !nPatterns, "cui.options", "No date acceptance pattern");
990 if (nPatterns)
992 const OUString* pPatterns = aDateAcceptancePatterns.getConstArray();
993 aBuf.append( pPatterns[0]);
994 for (sal_Int32 i=1; i < nPatterns; ++i)
995 aBuf.append(';').append( pPatterns[i]);
997 return aBuf.makeStringAndClear();
1000 OfaLanguagesTabPage::OfaLanguagesTabPage( Window* pParent, const SfxItemSet& rSet ) :
1001 SfxTabPage( pParent,"OptLanguagesPage","cui/ui/optlanguagespage.ui", rSet ),
1002 pLangConfig(new LanguageConfig_Impl)
1004 get(m_pUserInterfaceLB, "userinterface");
1005 m_pUserInterfaceLB->SetStyle(m_pUserInterfaceLB->GetStyle() | WB_SORT);
1006 get(m_pLocaleSettingLB, "localesetting");
1007 m_pLocaleSettingLB->SetStyle(m_pLocaleSettingLB->GetStyle() | WB_SORT);
1008 get(m_pLocaleSettingFT, "localesettingFT");
1009 get(m_pDecimalSeparatorCB, "decimalseparator");
1010 get(m_pCurrencyFT, "defaultcurrency");
1011 get(m_pCurrencyLB, "currencylb");
1012 m_pCurrencyLB->SetStyle(m_pCurrencyLB->GetStyle() | WB_SORT);
1013 get(m_pDatePatternsFT,"dataaccpatterns");
1014 get(m_pDatePatternsED, "datepatterns");
1016 get(m_pWesternLanguageLB, "westernlanguage");
1017 m_pWesternLanguageLB->SetStyle(m_pWesternLanguageLB->GetStyle() | WB_SORT);
1018 get(m_pWesternLanguageFT, "western");
1019 get(m_pAsianLanguageLB, "asianlanguage");
1020 m_pAsianLanguageLB->SetStyle(m_pAsianLanguageLB->GetStyle() | WB_SORT);
1021 get(m_pComplexLanguageLB, "complexlanguage");
1022 m_pComplexLanguageLB->SetStyle(m_pComplexLanguageLB->GetStyle() | WB_SORT);
1023 get(m_pCurrentDocCB, "currentdoc");
1024 get(m_pAsianSupportCB, "asiansupport");
1025 get(m_pCTLSupportCB, "ctlsupport");
1026 get(m_pIgnoreLanguageChangeCB, "ignorelanguagechange");
1028 // initialize user interface language selection
1029 m_sSystemDefaultString = SvtLanguageTable::GetLanguageString( LANGUAGE_SYSTEM );
1031 OUString aUILang = m_sSystemDefaultString +
1032 " - " +
1033 SvtLanguageTable::GetLanguageString( Application::GetSettings().GetUILanguageTag().getLanguageType(), true );
1035 m_pUserInterfaceLB->InsertEntry(aUILang);
1036 m_pUserInterfaceLB->SetEntryData(0, 0);
1037 m_pUserInterfaceLB->SelectEntryPos(0);
1040 Reference< XMultiServiceFactory > theConfigProvider(
1041 com::sun::star::configuration::theDefaultProvider::get(
1042 comphelper::getProcessComponentContext()));
1043 Sequence< Any > theArgs(1);
1044 Reference< XNameAccess > theNameAccess;
1046 // find out which locales are currently installed and add them to the listbox
1047 theArgs[0] = makeAny(NamedValue(OUString("nodepath"), makeAny(sInstalledLocalesPath)));
1048 theNameAccess = Reference< XNameAccess > (
1049 theConfigProvider->createInstanceWithArguments(sAccessSrvc, theArgs ), UNO_QUERY_THROW );
1050 seqInstalledLanguages = theNameAccess->getElementNames();
1051 LanguageType aLang = LANGUAGE_DONTKNOW;
1052 for (sal_IntPtr i=0; i<seqInstalledLanguages.getLength(); i++)
1054 aLang = LanguageTag::convertToLanguageTypeWithFallback(seqInstalledLanguages[i]);
1055 if (aLang != LANGUAGE_DONTKNOW)
1057 //sal_uInt16 p = m_pUserInterfaceLB->InsertLanguage(aLang);
1058 OUString aLangStr( SvtLanguageTable::GetLanguageString( aLang, true ) );
1059 sal_uInt16 p = m_pUserInterfaceLB->InsertEntry(aLangStr);
1060 m_pUserInterfaceLB->SetEntryData(p, (void*)(i+1));
1064 // find out whether the user has a specific locale specified
1065 Sequence< Any > theArgs2(1);
1066 theArgs2[0] = makeAny(NamedValue(OUString("nodepath"), makeAny(sUserLocalePath)));
1067 theNameAccess = Reference< XNameAccess > (
1068 theConfigProvider->createInstanceWithArguments(sAccessSrvc, theArgs2 ), UNO_QUERY_THROW );
1069 if (theNameAccess->hasByName(sUserLocaleKey))
1070 theNameAccess->getByName(sUserLocaleKey) >>= m_sUserLocaleValue;
1071 // select the user specified locale in the listbox
1072 if (!m_sUserLocaleValue.isEmpty())
1074 sal_Int32 d = 0;
1075 for (sal_uInt16 i=0; i < m_pUserInterfaceLB->GetEntryCount(); i++)
1077 d = (sal_Int32)(sal_IntPtr)m_pUserInterfaceLB->GetEntryData(i);
1078 if ( d > 0 && seqInstalledLanguages.getLength() > d-1 && seqInstalledLanguages[d-1].equals(m_sUserLocaleValue))
1079 m_pUserInterfaceLB->SelectEntryPos(i);
1084 catch (const Exception &e)
1086 // we'll just leave the box in it's default setting and won't
1087 // even give it event handler...
1088 SAL_WARN("cui.options", "ignoring Exception \"" << e.Message << "\"");
1091 m_pWesternLanguageLB->SetLanguageList( LANG_LIST_WESTERN | LANG_LIST_ONLY_KNOWN, true, false, true );
1092 m_pWesternLanguageLB->InsertDefaultLanguage( ::com::sun::star::i18n::ScriptType::LATIN );
1093 m_pAsianLanguageLB->SetLanguageList( LANG_LIST_CJK | LANG_LIST_ONLY_KNOWN, true, false, true );
1094 m_pAsianLanguageLB->InsertDefaultLanguage( ::com::sun::star::i18n::ScriptType::ASIAN );
1095 m_pComplexLanguageLB->SetLanguageList( LANG_LIST_CTL | LANG_LIST_ONLY_KNOWN, true, false, true );
1096 m_pComplexLanguageLB->InsertDefaultLanguage( ::com::sun::star::i18n::ScriptType::COMPLEX );
1098 m_pLocaleSettingLB->SetLanguageList( LANG_LIST_ALL | LANG_LIST_ONLY_KNOWN, false, false, false);
1099 m_pLocaleSettingLB->InsertSystemLanguage( );
1101 const NfCurrencyTable& rCurrTab = SvNumberFormatter::GetTheCurrencyTable();
1102 const NfCurrencyEntry& rCurr = SvNumberFormatter::GetCurrencyEntry( LANGUAGE_SYSTEM );
1103 // insert SYSTEM entry
1104 OUString aDefaultCurr = m_sSystemDefaultString + " - " + rCurr.GetBankSymbol();
1105 m_pCurrencyLB->InsertEntry( aDefaultCurr );
1106 // all currencies
1107 OUString aTwoSpace( " " );
1108 sal_uInt16 nCurrCount = rCurrTab.size();
1109 // first entry is SYSTEM, skip it
1110 for ( sal_uInt16 j=1; j < nCurrCount; ++j )
1112 const NfCurrencyEntry* pCurr = &rCurrTab[j];
1113 OUString aStr_ = pCurr->GetBankSymbol() +
1114 aTwoSpace +
1115 pCurr->GetSymbol();
1116 aStr_ = ApplyLreOrRleEmbedding( aStr_ ) +
1117 aTwoSpace +
1118 ApplyLreOrRleEmbedding( SvtLanguageTable::GetLanguageString( pCurr->GetLanguage() ) );
1119 sal_uInt16 nPos = m_pCurrencyLB->InsertEntry( aStr_ );
1120 m_pCurrencyLB->SetEntryData( nPos, (void*) pCurr );
1123 m_pLocaleSettingLB->SetSelectHdl( LINK( this, OfaLanguagesTabPage, LocaleSettingHdl ) );
1124 m_pDatePatternsED->SetModifyHdl( LINK( this, OfaLanguagesTabPage, DatePatternsHdl ) );
1126 Link aLink( LINK( this, OfaLanguagesTabPage, SupportHdl ) );
1127 m_pAsianSupportCB->SetClickHdl( aLink );
1128 m_pCTLSupportCB->SetClickHdl( aLink );
1130 m_bOldAsian = pLangConfig->aLanguageOptions.IsAnyEnabled();
1131 m_pAsianSupportCB->Check(m_bOldAsian);
1132 m_pAsianSupportCB->SaveValue();
1133 bool bReadonly = pLangConfig->aLanguageOptions.IsReadOnly(SvtLanguageOptions::E_ALLCJK);
1134 m_pAsianSupportCB->Enable(!bReadonly);
1135 SupportHdl( m_pAsianSupportCB );
1137 m_bOldCtl = pLangConfig->aLanguageOptions.IsCTLFontEnabled();
1138 m_pCTLSupportCB->Check(m_bOldCtl);
1139 m_pCTLSupportCB->SaveValue();
1140 bReadonly = pLangConfig->aLanguageOptions.IsReadOnly(SvtLanguageOptions::E_CTLFONT);
1141 m_pCTLSupportCB->Enable(!bReadonly);
1142 SupportHdl( m_pCTLSupportCB );
1144 m_pIgnoreLanguageChangeCB->Check( pLangConfig->aSysLocaleOptions.IsIgnoreLanguageChange() );
1147 OfaLanguagesTabPage::~OfaLanguagesTabPage()
1149 delete pLangConfig;
1152 SfxTabPage* OfaLanguagesTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
1154 return new OfaLanguagesTabPage(pParent, rAttrSet);
1157 static void lcl_UpdateAndDelete(SfxVoidItem* pInvalidItems[], SfxBoolItem* pBoolItems[], sal_uInt16 nCount)
1159 SfxViewFrame* pCurrentFrm = SfxViewFrame::Current();
1160 SfxViewFrame* pViewFrm = SfxViewFrame::GetFirst();
1161 while(pViewFrm)
1163 SfxBindings& rBind = pViewFrm->GetBindings();
1164 for(sal_Int16 i = 0; i < nCount; i++)
1166 if(pCurrentFrm == pViewFrm)
1167 rBind.InvalidateAll(false);
1168 rBind.SetState( *pInvalidItems[i] );
1169 rBind.SetState( *pBoolItems[i] );
1171 pViewFrm = SfxViewFrame::GetNext(*pViewFrm);
1173 for(sal_Int16 i = 0; i < nCount; i++)
1175 delete pInvalidItems[i];
1176 delete pBoolItems[i] ;
1180 bool OfaLanguagesTabPage::FillItemSet( SfxItemSet& rSet )
1182 // lock configuration broadcasters so that we can coordinate the notifications
1183 pLangConfig->aSysLocaleOptions.BlockBroadcasts( true );
1184 pLangConfig->aLanguageOptions.BlockBroadcasts( true );
1185 pLangConfig->aLinguConfig.BlockBroadcasts( true );
1188 * Sequence checking only matters when CTL support is enabled.
1190 * So we only need to check for sequence checking if
1191 * a) previously it was unchecked and is now checked or
1192 * b) it was already checked but the CTL language has changed
1194 if (
1195 m_pCTLSupportCB->IsChecked() &&
1196 (m_pCTLSupportCB->GetSavedValue() != TRISTATE_TRUE ||
1197 m_pComplexLanguageLB->IsValueChangedFromSaved())
1200 //sequence checking has to be switched on depending on the selected CTL language
1201 LanguageType eCTLLang = m_pComplexLanguageLB->GetSelectLanguage();
1202 bool bOn = MsLangId::needsSequenceChecking( eCTLLang);
1203 pLangConfig->aLanguageOptions.SetCTLSequenceCheckingRestricted(bOn);
1204 pLangConfig->aLanguageOptions.SetCTLSequenceChecking(bOn);
1205 pLangConfig->aLanguageOptions.SetCTLSequenceCheckingTypeAndReplace(bOn);
1209 // handle settings for UI Language
1210 // a change of setting needs to bring up a warning message
1211 OUString aLangString;
1212 sal_Int32 d = (sal_Int32)(sal_IntPtr)m_pUserInterfaceLB->GetEntryData(m_pUserInterfaceLB->GetSelectEntryPos());
1213 if( d > 0 && seqInstalledLanguages.getLength() > d-1)
1214 aLangString = seqInstalledLanguages[d-1];
1217 if( m_pUserInterfaceLB->GetSelectEntryPos() > 0)
1218 aLangString = ConvertLanguageToIsoString(m_pUserInterfaceLB->GetSelectLanguage());
1220 Reference< XMultiServiceFactory > theConfigProvider(
1221 com::sun::star::configuration::theDefaultProvider::get(
1222 comphelper::getProcessComponentContext()));
1223 Sequence< Any > theArgs(1);
1224 theArgs[0] = makeAny(NamedValue(OUString("nodepath"), makeAny(sUserLocalePath)));
1225 Reference< XPropertySet >xProp(
1226 theConfigProvider->createInstanceWithArguments(sAccessUpdSrvc, theArgs ), UNO_QUERY_THROW );
1227 if ( !m_sUserLocaleValue.equals(aLangString))
1229 // OSL_FAIL("UserInterface language was changed, restart.");
1230 // write new value
1231 xProp->setPropertyValue(sUserLocaleKey, makeAny(aLangString));
1232 Reference< XChangesBatch >(xProp, UNO_QUERY_THROW)->commitChanges();
1233 // display info
1234 InfoBox aBox(this, CUI_RES(RID_SVX_MSGBOX_LANGUAGE_RESTART));
1235 aBox.Execute();
1237 // tell quickstarter to stop being a veto listener
1239 Reference< XComponentContext > xContext(
1240 comphelper::getProcessComponentContext());
1241 css::office::Quickstart::createAndSetVeto(xContext, false, false, false/*DisableVeto*/);
1244 catch (const Exception& e)
1246 // we'll just leave the box in it's default setting and won't
1247 // even give it event handler...
1248 SAL_WARN("cui.options", "ignoring Exception \"" << e.Message << "\"");
1251 OUString sLang = pLangConfig->aSysLocaleOptions.GetLocaleConfigString();
1252 LanguageType eOldLocale = (!sLang.isEmpty() ?
1253 LanguageTag::convertToLanguageTypeWithFallback( sLang ) : LANGUAGE_SYSTEM);
1254 LanguageType eNewLocale = m_pLocaleSettingLB->GetSelectLanguage();
1256 // If the "Default ..." entry was selected that means SYSTEM, the actual
1257 // eNewLocale value is temporary for the dialog only, do not resolve to
1258 // what system currently is.
1259 if (eNewLocale == LANGUAGE_USER_SYSTEM_CONFIG)
1260 eNewLocale = LANGUAGE_SYSTEM;
1262 if ( eOldLocale != eNewLocale )
1264 // an empty string denotes SYSTEM locale
1265 OUString sNewLang;
1266 if ( eNewLocale != LANGUAGE_SYSTEM )
1267 sNewLang = LanguageTag::convertToBcp47( eNewLocale);
1269 // locale nowadays get to AppSettings via notification
1270 // this will happen after releasing the lock on the ConfigurationBroadcaster at
1271 // the end of this method
1272 pLangConfig->aSysLocaleOptions.SetLocaleConfigString( sNewLang );
1273 rSet.Put( SfxBoolItem( SID_OPT_LOCALE_CHANGED, true ) );
1275 sal_uInt16 nNewType = SvtLanguageOptions::GetScriptTypeOfLanguage( eNewLocale );
1276 bool bNewCJK = ( nNewType & SCRIPTTYPE_ASIAN ) != 0;
1277 SvtCompatibilityOptions aCompatOpts;
1278 aCompatOpts.SetDefault( COMPATIBILITY_PROPERTYNAME_EXPANDWORDSPACE, !bNewCJK );
1281 if(m_pDecimalSeparatorCB->IsValueChangedFromSaved())
1282 pLangConfig->aSysLocaleOptions.SetDecimalSeparatorAsLocale(m_pDecimalSeparatorCB->IsChecked());
1284 if(m_pIgnoreLanguageChangeCB->IsValueChangedFromSaved())
1285 pLangConfig->aSysLocaleOptions.SetIgnoreLanguageChange(m_pIgnoreLanguageChangeCB->IsChecked());
1287 // Configured currency, for example, USD-en-US or EUR-de-DE, or empty for locale default.
1288 OUString sOldCurr = pLangConfig->aSysLocaleOptions.GetCurrencyConfigString();
1289 sal_Int32 nCurrPos = m_pCurrencyLB->GetSelectEntryPos();
1290 const NfCurrencyEntry* pCurr = (const NfCurrencyEntry*)
1291 m_pCurrencyLB->GetEntryData( nCurrPos );
1292 OUString sNewCurr;
1293 if ( pCurr )
1294 sNewCurr = SvtSysLocaleOptions::CreateCurrencyConfigString(
1295 pCurr->GetBankSymbol(), pCurr->GetLanguage() );
1296 if ( sOldCurr != sNewCurr )
1297 pLangConfig->aSysLocaleOptions.SetCurrencyConfigString( sNewCurr );
1299 // Configured date acceptance patterns, for example Y-M-D;M-D or empty for
1300 // locale default.
1301 if (m_bDatePatternsValid && m_pDatePatternsED->IsValueChangedFromSaved())
1302 pLangConfig->aSysLocaleOptions.SetDatePatternsConfigString( m_pDatePatternsED->GetText());
1304 SfxObjectShell* pCurrentDocShell = SfxObjectShell::Current();
1305 Reference< css::linguistic2::XLinguProperties > xLinguProp = LinguMgr::GetLinguPropertySet();
1306 bool bCurrentDocCBChecked = m_pCurrentDocCB->IsChecked();
1307 if(m_pCurrentDocCB->IsEnabled())
1308 bLanguageCurrentDoc_Impl = bCurrentDocCBChecked;
1309 bool bCurrentDocCBChanged = m_pCurrentDocCB->IsValueChangedFromSaved();
1311 bool bValChanged = m_pWesternLanguageLB->IsValueChangedFromSaved();
1312 if( (bCurrentDocCBChanged && !bCurrentDocCBChecked) || bValChanged)
1314 LanguageType eSelectLang = m_pWesternLanguageLB->GetSelectLanguage();
1315 if(!bCurrentDocCBChecked)
1317 Any aValue;
1318 Locale aLocale = LanguageTag::convertToLocale( eSelectLang, false);
1319 aValue <<= aLocale;
1320 OUString aPropName( "DefaultLocale" );
1321 pLangConfig->aLinguConfig.SetProperty( aPropName, aValue );
1322 if (xLinguProp.is())
1323 xLinguProp->setDefaultLocale( aLocale );
1325 if(pCurrentDocShell)
1327 rSet.Put(SvxLanguageItem(MsLangId::resolveSystemLanguageByScriptType(eSelectLang, ::com::sun::star::i18n::ScriptType::LATIN),
1328 SID_ATTR_LANGUAGE));
1331 bValChanged = m_pAsianLanguageLB->IsValueChangedFromSaved();
1332 if( (bCurrentDocCBChanged && !bCurrentDocCBChecked) || bValChanged)
1334 LanguageType eSelectLang = m_pAsianLanguageLB->GetSelectLanguage();
1335 if(!bCurrentDocCBChecked)
1337 Any aValue;
1338 Locale aLocale = LanguageTag::convertToLocale( eSelectLang, false);
1339 aValue <<= aLocale;
1340 OUString aPropName( "DefaultLocale_CJK" );
1341 pLangConfig->aLinguConfig.SetProperty( aPropName, aValue );
1342 if (xLinguProp.is())
1343 xLinguProp->setDefaultLocale_CJK( aLocale );
1345 if(pCurrentDocShell)
1347 rSet.Put(SvxLanguageItem(MsLangId::resolveSystemLanguageByScriptType(eSelectLang, ::com::sun::star::i18n::ScriptType::ASIAN),
1348 SID_ATTR_CHAR_CJK_LANGUAGE));
1351 bValChanged = m_pComplexLanguageLB->IsValueChangedFromSaved();
1352 if( (bCurrentDocCBChanged && !bCurrentDocCBChecked) || bValChanged)
1354 LanguageType eSelectLang = m_pComplexLanguageLB->GetSelectLanguage();
1355 if(!bCurrentDocCBChecked)
1357 Any aValue;
1358 Locale aLocale = LanguageTag::convertToLocale( eSelectLang, false);
1359 aValue <<= aLocale;
1360 OUString aPropName( "DefaultLocale_CTL" );
1361 pLangConfig->aLinguConfig.SetProperty( aPropName, aValue );
1362 if (xLinguProp.is())
1363 xLinguProp->setDefaultLocale_CTL( aLocale );
1365 if(pCurrentDocShell)
1367 rSet.Put(SvxLanguageItem(MsLangId::resolveSystemLanguageByScriptType(eSelectLang, ::com::sun::star::i18n::ScriptType::COMPLEX),
1368 SID_ATTR_CHAR_CTL_LANGUAGE));
1372 if(m_pAsianSupportCB->IsValueChangedFromSaved() )
1374 bool bChecked = m_pAsianSupportCB->IsChecked();
1375 pLangConfig->aLanguageOptions.SetAll(bChecked);
1377 //iterate over all bindings to invalidate vertical text direction
1378 const sal_uInt16 STATE_COUNT = 2;
1380 SfxBoolItem* pBoolItems[STATE_COUNT];
1381 pBoolItems[0] = new SfxBoolItem(SID_VERTICALTEXT_STATE, false);
1382 pBoolItems[1] = new SfxBoolItem(SID_TEXT_FITTOSIZE_VERTICAL, false);
1384 SfxVoidItem* pInvalidItems[STATE_COUNT];
1385 pInvalidItems[0] = new SfxVoidItem(SID_VERTICALTEXT_STATE);
1386 pInvalidItems[1] = new SfxVoidItem(SID_TEXT_FITTOSIZE_VERTICAL);
1388 lcl_UpdateAndDelete(pInvalidItems, pBoolItems, STATE_COUNT);
1391 if ( m_pCTLSupportCB->IsValueChangedFromSaved() )
1393 SvtSearchOptions aOpt;
1394 aOpt.SetIgnoreDiacritics_CTL (true);
1395 aOpt.SetIgnoreKashida_CTL (true);
1396 pLangConfig->aLanguageOptions.SetCTLFontEnabled( m_pCTLSupportCB->IsChecked() );
1398 const sal_uInt16 STATE_COUNT = 1;
1399 SfxBoolItem* pBoolItems[STATE_COUNT];
1400 pBoolItems[0] = new SfxBoolItem(SID_CTLFONT_STATE, false);
1401 SfxVoidItem* pInvalidItems[STATE_COUNT];
1402 pInvalidItems[0] = new SfxVoidItem(SID_CTLFONT_STATE);
1403 lcl_UpdateAndDelete(pInvalidItems, pBoolItems, STATE_COUNT);
1406 if ( pLangConfig->aSysLocaleOptions.IsModified() )
1407 pLangConfig->aSysLocaleOptions.Commit();
1409 // first release the lock on the ConfigurationBroadcaster for Locale changes
1410 // it seems that our code relies on the fact that before other changes like e.g. currency
1411 // are broadcasted locale changes have been done
1412 pLangConfig->aSysLocaleOptions.BlockBroadcasts( false );
1413 pLangConfig->aLanguageOptions.BlockBroadcasts( false );
1414 pLangConfig->aLinguConfig.BlockBroadcasts( false );
1416 return false;
1419 void OfaLanguagesTabPage::Reset( const SfxItemSet& rSet )
1421 OUString sLang = pLangConfig->aSysLocaleOptions.GetLocaleConfigString();
1422 if ( !sLang.isEmpty() )
1423 m_pLocaleSettingLB->SelectLanguage(LanguageTag::convertToLanguageTypeWithFallback(sLang));
1424 else
1425 m_pLocaleSettingLB->SelectLanguage( LANGUAGE_USER_SYSTEM_CONFIG );
1426 bool bReadonly = pLangConfig->aSysLocaleOptions.IsReadOnly(SvtSysLocaleOptions::E_LOCALE);
1427 m_pLocaleSettingLB->Enable(!bReadonly);
1428 m_pLocaleSettingFT->Enable(!bReadonly);
1431 m_pDecimalSeparatorCB->Check( pLangConfig->aSysLocaleOptions.IsDecimalSeparatorAsLocale());
1432 m_pDecimalSeparatorCB->SaveValue();
1434 m_pIgnoreLanguageChangeCB->Check( pLangConfig->aSysLocaleOptions.IsIgnoreLanguageChange());
1435 m_pIgnoreLanguageChangeCB->SaveValue();
1437 // let LocaleSettingHdl enable/disable checkboxes for CJK/CTL support
1438 // #i15812# must be done *before* the configured currency is set
1439 // and update the decimal separator used for the given locale
1440 LocaleSettingHdl(m_pLocaleSettingLB);
1442 // configured currency, for example, USD-en-US or EUR-de-DE, or empty for locale default
1443 OUString aAbbrev;
1444 LanguageType eLang;
1445 const NfCurrencyEntry* pCurr = NULL;
1446 sLang = pLangConfig->aSysLocaleOptions.GetCurrencyConfigString();
1447 if ( !sLang.isEmpty() )
1449 SvtSysLocaleOptions::GetCurrencyAbbrevAndLanguage( aAbbrev, eLang, sLang );
1450 pCurr = SvNumberFormatter::GetCurrencyEntry( aAbbrev, eLang );
1452 // if pCurr==NULL the SYSTEM entry is selected
1453 sal_uInt16 nPos = m_pCurrencyLB->GetEntryPos( (void*) pCurr );
1454 m_pCurrencyLB->SelectEntryPos( nPos );
1455 bReadonly = pLangConfig->aSysLocaleOptions.IsReadOnly(SvtSysLocaleOptions::E_CURRENCY);
1456 m_pCurrencyLB->Enable(!bReadonly);
1457 m_pCurrencyFT->Enable(!bReadonly);
1459 // date acceptance patterns
1460 OUString aDatePatternsString = pLangConfig->aSysLocaleOptions.GetDatePatternsConfigString();
1461 if (aDatePatternsString.isEmpty())
1463 const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
1464 aDatePatternsString = lcl_getDatePatternsConfigString( rLocaleWrapper);
1466 // Let's assume patterns are valid at this point.
1467 m_bDatePatternsValid = true;
1468 m_pDatePatternsED->SetText( aDatePatternsString);
1469 bReadonly = pLangConfig->aSysLocaleOptions.IsReadOnly(SvtSysLocaleOptions::E_DATEPATTERNS);
1470 m_pDatePatternsED->Enable(!bReadonly);
1471 m_pDatePatternsFT->Enable(!bReadonly);
1472 m_pDatePatternsED->SaveValue();
1474 //western/CJK/CLK language
1475 LanguageType eCurLang = LANGUAGE_NONE;
1476 LanguageType eCurLangCJK = LANGUAGE_NONE;
1477 LanguageType eCurLangCTL = LANGUAGE_NONE;
1478 SfxObjectShell* pCurrentDocShell = SfxObjectShell::Current();
1479 //collect the configuration values first
1480 m_pCurrentDocCB->Enable(false);
1482 Any aWestLang;
1483 Any aCJKLang;
1484 Any aCTLLang;
1487 aWestLang = pLangConfig->aLinguConfig.GetProperty("DefaultLocale");
1488 Locale aLocale;
1489 aWestLang >>= aLocale;
1491 eCurLang = LanguageTag::convertToLanguageType( aLocale, false);
1493 aCJKLang = pLangConfig->aLinguConfig.GetProperty("DefaultLocale_CJK");
1494 aLocale = Locale();
1495 aCJKLang >>= aLocale;
1496 eCurLangCJK = LanguageTag::convertToLanguageType( aLocale, false);
1498 aCTLLang = pLangConfig->aLinguConfig.GetProperty("DefaultLocale_CTL");
1499 aLocale = Locale();
1500 aCTLLang >>= aLocale;
1501 eCurLangCTL = LanguageTag::convertToLanguageType( aLocale, false);
1503 catch (const Exception&)
1506 //overwrite them by the values provided by the DocShell
1507 if(pCurrentDocShell)
1509 m_pCurrentDocCB->Enable(true);
1510 m_pCurrentDocCB->Check(bLanguageCurrentDoc_Impl);
1511 const SfxPoolItem* pLang;
1512 if( SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_LANGUAGE, false, &pLang))
1514 LanguageType eTempCurLang = ((const SvxLanguageItem*)pLang)->GetValue();
1515 if (MsLangId::resolveSystemLanguageByScriptType(eCurLang, ::com::sun::star::i18n::ScriptType::LATIN) != eTempCurLang)
1516 eCurLang = eTempCurLang;
1519 if( SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_CHAR_CJK_LANGUAGE, false, &pLang))
1521 LanguageType eTempCurLang = ((const SvxLanguageItem*)pLang)->GetValue();
1522 if (MsLangId::resolveSystemLanguageByScriptType(eCurLangCJK, ::com::sun::star::i18n::ScriptType::ASIAN) != eTempCurLang)
1523 eCurLangCJK = eTempCurLang;
1526 if( SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_CHAR_CTL_LANGUAGE, false, &pLang))
1528 LanguageType eTempCurLang = ((const SvxLanguageItem*)pLang)->GetValue();
1529 if (MsLangId::resolveSystemLanguageByScriptType(eCurLangCTL, ::com::sun::star::i18n::ScriptType::COMPLEX) != eTempCurLang)
1530 eCurLangCTL = eTempCurLang;
1533 if(LANGUAGE_NONE == eCurLang || LANGUAGE_DONTKNOW == eCurLang)
1534 m_pWesternLanguageLB->SelectLanguage(LANGUAGE_NONE);
1535 else
1536 m_pWesternLanguageLB->SelectLanguage(eCurLang);
1538 if(LANGUAGE_NONE == eCurLangCJK || LANGUAGE_DONTKNOW == eCurLangCJK)
1539 m_pAsianLanguageLB->SelectLanguage(LANGUAGE_NONE);
1540 else
1541 m_pAsianLanguageLB->SelectLanguage(eCurLangCJK);
1543 if(LANGUAGE_NONE == eCurLangCTL || LANGUAGE_DONTKNOW == eCurLangCTL)
1544 m_pComplexLanguageLB->SelectLanguage(LANGUAGE_NONE);
1545 else
1546 m_pComplexLanguageLB->SelectLanguage(eCurLangCTL);
1548 m_pWesternLanguageLB->SaveValue();
1549 m_pAsianLanguageLB->SaveValue();
1550 m_pComplexLanguageLB->SaveValue();
1551 m_pIgnoreLanguageChangeCB->SaveValue();
1552 m_pCurrentDocCB->SaveValue();
1554 bool bEnable = !pLangConfig->aLinguConfig.IsReadOnly( "DefaultLocale" );
1555 m_pWesternLanguageFT->Enable( bEnable );
1556 m_pWesternLanguageLB->Enable( bEnable );
1560 // #i15812# controls for CJK/CTL already enabled/disabled from LocaleSettingHdl
1561 #if 0
1562 bEnable = ( !pLangConfig->aLinguConfig.IsReadOnly( "DefaultLocale_CJK" ) && m_pAsianSupportCB->IsChecked() );
1563 m_pAsianLanguageLB->Enable( bEnable );
1565 bEnable = ( !pLangConfig->aLinguConfig.IsReadOnly( "DefaultLocale_CTL" ) && m_pCTLSupportCB->IsChecked() );
1566 m_pComplexLanguageLB->Enable( bEnable );
1567 #endif
1568 // check the box "For the current document only"
1569 // set the focus to the Western Language box
1570 const SfxPoolItem* pLang = 0;
1571 if ( SFX_ITEM_SET == rSet.GetItemState(SID_SET_DOCUMENT_LANGUAGE, false, &pLang ) && ((const SfxBoolItem*)pLang)->GetValue() )
1573 m_pWesternLanguageLB->GrabFocus();
1574 m_pCurrentDocCB->Enable(true);
1575 m_pCurrentDocCB->Check(true);
1579 IMPL_LINK( OfaLanguagesTabPage, SupportHdl, CheckBox*, pBox )
1581 DBG_ASSERT( pBox, "OfaLanguagesTabPage::SupportHdl(): pBox invalid" );
1583 bool bCheck = pBox->IsChecked();
1584 if ( m_pAsianSupportCB == pBox )
1586 bool bReadonly = pLangConfig->aLinguConfig.IsReadOnly("DefaultLocale_CJK");
1587 bCheck = ( bCheck && !bReadonly );
1588 m_pAsianLanguageLB->Enable( bCheck );
1589 if( pBox->IsEnabled() )
1590 m_bOldAsian = bCheck;
1592 else if ( m_pCTLSupportCB == pBox )
1594 bool bReadonly = pLangConfig->aLinguConfig.IsReadOnly("DefaultLocale_CTL");
1595 bCheck = ( bCheck && !bReadonly );
1596 m_pComplexLanguageLB->Enable( bCheck );
1597 if( pBox->IsEnabled() )
1598 m_bOldCtl = bCheck;
1600 else
1601 SAL_WARN( "cui.options", "OfaLanguagesTabPage::SupportHdl(): wrong pBox" );
1603 return 0;
1606 namespace
1608 void lcl_checkLanguageCheckBox(CheckBox* _rCB,bool _bNewValue,bool _bOldValue)
1610 if ( _bNewValue )
1611 _rCB->Check(true);
1612 else
1613 _rCB->Check( _bOldValue );
1614 // #i15082# do not call SaveValue() in running dialog...
1615 // _rCB.SaveValue();
1616 _rCB->Enable( !_bNewValue );
1620 IMPL_LINK( OfaLanguagesTabPage, LocaleSettingHdl, SvxLanguageBox*, pBox )
1622 LanguageType eLang = pBox->GetSelectLanguage();
1623 sal_uInt16 nType = SvtLanguageOptions::GetScriptTypeOfLanguage(eLang);
1624 // first check if CTL must be enabled
1625 // #103299# - if CTL font setting is not readonly
1626 if(!pLangConfig->aLanguageOptions.IsReadOnly(SvtLanguageOptions::E_CTLFONT))
1628 bool bIsCTLFixed = (nType & SCRIPTTYPE_COMPLEX) != 0;
1629 lcl_checkLanguageCheckBox(m_pCTLSupportCB, bIsCTLFixed, m_bOldCtl);
1630 SupportHdl( m_pCTLSupportCB );
1632 // second check if CJK must be enabled
1633 // #103299# - if CJK support is not readonly
1634 if(!pLangConfig->aLanguageOptions.IsReadOnly(SvtLanguageOptions::E_ALLCJK))
1636 bool bIsCJKFixed = (nType & SCRIPTTYPE_ASIAN) != 0;
1637 lcl_checkLanguageCheckBox(m_pAsianSupportCB, bIsCJKFixed, m_bOldAsian);
1638 SupportHdl( m_pAsianSupportCB );
1641 const NfCurrencyEntry* pCurr = &SvNumberFormatter::GetCurrencyEntry(
1642 ((eLang == LANGUAGE_USER_SYSTEM_CONFIG) ? MsLangId::getSystemLanguage() : eLang));
1643 sal_uInt16 nPos = m_pCurrencyLB->GetEntryPos( (void*) NULL );
1644 if (pCurr)
1646 // Update the "Default ..." currency.
1647 m_pCurrencyLB->RemoveEntry( nPos );
1648 OUString aDefaultCurr = m_sSystemDefaultString + " - " + pCurr->GetBankSymbol();
1649 nPos = m_pCurrencyLB->InsertEntry( aDefaultCurr );
1651 m_pCurrencyLB->SelectEntryPos( nPos );
1653 // obtain corresponding locale data
1654 LanguageTag aLanguageTag( eLang);
1655 LocaleDataWrapper aLocaleWrapper( aLanguageTag );
1657 // update the decimal separator key of the related CheckBox
1658 OUString sTempLabel(m_pDecimalSeparatorCB->GetText());
1659 sTempLabel = sTempLabel.replaceFirst("%1", aLocaleWrapper.getNumDecimalSep() );
1660 m_pDecimalSeparatorCB->SetText(sTempLabel);
1662 // update the date acceptance patterns
1663 OUString aDatePatternsString = lcl_getDatePatternsConfigString( aLocaleWrapper);
1664 m_bDatePatternsValid = true;
1665 m_pDatePatternsED->SetText( aDatePatternsString);
1667 return 0;
1670 IMPL_LINK( OfaLanguagesTabPage, DatePatternsHdl, Edit*, pEd )
1672 const OUString aPatterns( pEd->GetText());
1673 OUStringBuffer aBuf( aPatterns);
1674 sal_Int32 nChar = 0;
1675 bool bValid = true;
1676 bool bModified = false;
1677 if (!aPatterns.isEmpty())
1679 for (sal_Int32 nIndex=0; nIndex >= 0 && bValid; ++nChar)
1681 const OUString aPat( aPatterns.getToken( 0, ';', nIndex));
1682 if (aPat.isEmpty() && nIndex < 0)
1684 // Indicating failure when about to append a pattern is too
1685 // confusing. Empty patterns are ignored anyway when sequencing
1686 // to SvtSysLocale.
1687 continue; // for
1689 else if (aPat.getLength() < 2)
1690 bValid = false;
1691 else
1693 bool bY, bM, bD;
1694 bY = bM = bD = false;
1695 bool bSep = true;
1696 for (sal_Int32 i = 0; i < aPat.getLength() && bValid; /*nop*/)
1698 const sal_Int32 j = i;
1699 const sal_uInt32 c = aPat.iterateCodePoints( &i);
1700 // Only one Y,M,D per pattern, separated by any character(s).
1701 switch (c)
1703 case 'y':
1704 case 'Y':
1705 if (bY || !bSep)
1706 bValid = false;
1707 else if (c == 'y')
1709 aBuf[nChar] = 'Y';
1710 bModified = true;
1712 bY = true;
1713 bSep = false;
1714 break;
1715 case 'm':
1716 case 'M':
1717 if (bM || !bSep)
1718 bValid = false;
1719 else if (c == 'm')
1721 aBuf[nChar] = 'M';
1722 bModified = true;
1724 bM = true;
1725 bSep = false;
1726 break;
1727 case 'd':
1728 case 'D':
1729 if (bD || !bSep)
1730 bValid = false;
1731 else if (c == 'd')
1733 aBuf[nChar] = 'D';
1734 bModified = true;
1736 bD = true;
1737 bSep = false;
1738 break;
1739 default:
1740 // A pattern must not start with a separator (but
1741 // may end with).
1742 if (!(bY || bM || bD))
1743 bValid = false;
1744 bSep = true;
1746 nChar += i-j;
1748 // At least one of Y,M,D
1749 bValid &= (bY || bM || bD);
1753 if (bModified)
1755 // Do not use SetText(...,GetSelection()) because internally the
1756 // reference's pointer of the selection is obtained resulting in the
1757 // entire text being selected at the end.
1758 Selection aSelection( pEd->GetSelection());
1759 pEd->SetText( aBuf.makeStringAndClear(), aSelection);
1761 if (bValid)
1763 pEd->SetControlForeground();
1764 pEd->SetControlBackground();
1766 else
1768 #if 0
1769 //! Gives white on white!?! instead of white on reddish.
1770 pEd->SetControlBackground( ::Color( RGB_COLORDATA( 0xff, 0x65, 0x63)));
1771 pEd->SetControlForeground( ::Color( COL_WHITE));
1772 #else
1773 pEd->SetControlForeground( ::Color( RGB_COLORDATA( 0xf0, 0, 0)));
1774 #endif
1776 m_bDatePatternsValid = bValid;
1777 return 0;
1780 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */