summaryrefslogtreecommitdiff
path: root/cui/source/options
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2012-08-29 20:49:01 +0200
committerEike Rathke <erack@redhat.com>2012-08-29 21:17:46 +0200
commitcda156257003df673fa853a0a5ffcd1cb4848d43 (patch)
tree5fcd7aa0c1c8e5de2da387e069423530500b15b4 /cui/source/options
parent332451bea5ebe08136de2d51e0e29cac88f89e8c (diff)
resolved fdo#52240 fdo#52137 fdo#52288 user editable date patterns
Implemented user editable date acceptance patterns. The introduction of strict date parsing using locale dependent date acceptance patterns in 3.6.0 wasn't always welcomed. Besides that not every locale had patterns for incomplete (only day and month) date input, users also complained about not being able to key in dates on numeric keypads if the locale's date separator wasn't '/' or '-' This commit implements a "Date acceptance patterns" edit field under Tools->Options->LanguageSettings->Languages that follows the selected locale and enables the user to add patterns. Example de-DE locale: * default patterns: D.M.Y;D.M. * to enable additional input on numeric keypad: D.M.Y;D.M.;D-M-Y;D-M * if 3-4 shall not result in a date, D-M- could be used instead of D-M * note that to enter an ISO 8601 Y-M-D date with a D-M-Y pattern active one needs to enter a year >31 or with at least 3 digits, e.g. 011 Change-Id: I9e20fcb168578b02d0f0248a0e209942e0f27113
Diffstat (limited to 'cui/source/options')
-rw-r--r--cui/source/options/optgdlg.cxx128
-rw-r--r--cui/source/options/optgdlg.hrc3
-rw-r--r--cui/source/options/optgdlg.hxx4
-rw-r--r--cui/source/options/optgdlg.src52
4 files changed, 170 insertions, 17 deletions
diff --git a/cui/source/options/optgdlg.cxx b/cui/source/options/optgdlg.cxx
index 4f8336822446..5f7015bdbd37 100644
--- a/cui/source/options/optgdlg.cxx
+++ b/cui/source/options/optgdlg.cxx
@@ -1206,6 +1206,22 @@ static OUString sUserLocalePath(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Offi
static const OUString sUserLocaleKey(RTL_CONSTASCII_USTRINGPARAM("UILocale"));
static Sequence< OUString > seqInstalledLanguages;
+static OUString lcl_getDatePatternsConfigString( const LocaleDataWrapper& rLocaleWrapper )
+{
+ Sequence< OUString > aDateAcceptancePatterns = rLocaleWrapper.getDateAcceptancePatterns();
+ sal_Int32 nPatterns = aDateAcceptancePatterns.getLength();
+ OUStringBuffer aBuf( nPatterns * 6 ); // 6 := length of Y-M-D;
+ SAL_WARN_IF( !nPatterns, "cui.options", "No date acceptance pattern");
+ if (nPatterns)
+ {
+ const OUString* pPatterns = aDateAcceptancePatterns.getConstArray();
+ aBuf.append( pPatterns[0]);
+ for (sal_Int32 i=1; i < nPatterns; ++i)
+ aBuf.append(';').append( pPatterns[i]);
+ }
+ return aBuf.makeStringAndClear();
+}
+
OfaLanguagesTabPage::OfaLanguagesTabPage( Window* pParent, const SfxItemSet& rSet ) :
SfxTabPage( pParent, CUI_RES( OFA_TP_LANGUAGES ), rSet ),
aUILanguageGB(this, CUI_RES(FL_UI_LANG )),
@@ -1219,6 +1235,9 @@ OfaLanguagesTabPage::OfaLanguagesTabPage( Window* pParent, const SfxItemSet& rSe
aDecimalSeparatorCB(this, CUI_RES(CB_DECIMALSEPARATOR)),
aCurrencyFT( this, CUI_RES(FT_CURRENCY )),
aCurrencyLB( this, CUI_RES(LB_CURRENCY )),
+ aDatePatternsFI( this, CUI_RES(FI_DATEPATTERNS )),
+ aDatePatternsFT( this, CUI_RES(FT_DATEPATTERNS )),
+ aDatePatternsED( this, CUI_RES(ED_DATEPATTERNS )),
aLinguLanguageGB(this, CUI_RES(FL_LINGU_LANG )),
aWesternLanguageFI(this, CUI_RES(FI_WEST_LANG )),
aWesternLanguageFT(this, CUI_RES(FT_WEST_LANG )),
@@ -1341,6 +1360,8 @@ OfaLanguagesTabPage::OfaLanguagesTabPage( Window* pParent, const SfxItemSet& rSe
delete pLanguageTable;
aLocaleSettingLB.SetSelectHdl( LINK( this, OfaLanguagesTabPage, LocaleSettingHdl ) );
+ aDatePatternsED.SetModifyHdl( LINK( this, OfaLanguagesTabPage, DatePatternsHdl ) );
+
Link aLink( LINK( this, OfaLanguagesTabPage, SupportHdl ) );
aAsianSupportCB.SetClickHdl( aLink );
aCTLSupportCB.SetClickHdl( aLink );
@@ -1537,6 +1558,11 @@ sal_Bool OfaLanguagesTabPage::FillItemSet( SfxItemSet& rSet )
if ( sOldCurr != sNewCurr )
pLangConfig->aSysLocaleOptions.SetCurrencyConfigString( sNewCurr );
+ // Configured date acceptance patterns, for example Y-M-D;M-D or empty for
+ // locale default.
+ if (aDatePatternsED.GetText() != aDatePatternsED.GetSavedValue())
+ pLangConfig->aSysLocaleOptions.SetDatePatternsConfigString( aDatePatternsED.GetText());
+
SfxObjectShell* pCurrentDocShell = SfxObjectShell::Current();
Reference< XPropertySet > xLinguProp( LinguMgr::GetLinguPropertySet(), UNO_QUERY );
sal_Bool bCurrentDocCBChecked = aCurrentDocCB.IsChecked();
@@ -1688,6 +1714,22 @@ void OfaLanguagesTabPage::Reset( const SfxItemSet& rSet )
aCurrencyFT.Enable(!bReadonly);
aCurrencyFI.Show(bReadonly);
+ // date acceptance patterns
+ OUString aDatePatternsString = pLangConfig->aSysLocaleOptions.GetDatePatternsConfigString();
+ if (aDatePatternsString.isEmpty())
+ {
+ Locale aTempLocale;
+ SvxLanguageToLocale( aTempLocale, Application::GetSettings().GetLanguage());
+ LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), aTempLocale );
+ aDatePatternsString = lcl_getDatePatternsConfigString( aLocaleWrapper);
+ }
+ aDatePatternsED.SetText( aDatePatternsString);
+ bReadonly = pLangConfig->aSysLocaleOptions.IsReadOnly(SvtSysLocaleOptions::E_DATEPATTERNS);
+ aDatePatternsED.Enable(!bReadonly);
+ aDatePatternsFT.Enable(!bReadonly);
+ aDatePatternsFI.Show(bReadonly);
+ aDatePatternsED.SaveValue();
+
//western/CJK/CLK language
LanguageType eCurLang = LANGUAGE_NONE;
LanguageType eCurLangCJK = LANGUAGE_NONE;
@@ -1871,14 +1913,98 @@ IMPL_LINK( OfaLanguagesTabPage, LocaleSettingHdl, SvxLanguageBox*, pBox )
}
aCurrencyLB.SelectEntryPos( nPos );
- //update the decimal separator key of the related CheckBox
+ // obtain corresponding locale data
Locale aTempLocale;
SvxLanguageToLocale( aTempLocale, eLang );
LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), aTempLocale );
+
+ // update the decimal separator key of the related CheckBox
String sTempLabel(sDecimalSeparatorLabel);
sTempLabel.SearchAndReplaceAscii("%1", aLocaleWrapper.getNumDecimalSep() );
aDecimalSeparatorCB.SetText(sTempLabel);
+ // update the date acceptance patterns
+ OUString aDatePatternsString = lcl_getDatePatternsConfigString( aLocaleWrapper);
+ aDatePatternsED.SetText( aDatePatternsString);
+
+ return 0;
+}
+
+IMPL_LINK( OfaLanguagesTabPage, DatePatternsHdl, Edit*, pEd )
+{
+ OUString aPatterns( pEd->GetText());
+ bool bValid = true;
+ if (!aPatterns.isEmpty())
+ {
+ for (sal_Int32 nIndex=0; nIndex >= 0 && bValid; /*nop*/)
+ {
+ OUString aPat( aPatterns.getToken( 0, ';', nIndex));
+ if (aPat.isEmpty() && nIndex < 0)
+ {
+ // Indicating failure when about to append a pattern is too
+ // confusing. Empty patterns are ignored anyway when sequencing
+ // to SvtSysLocale.
+ continue; // for
+ }
+ else if (aPat.getLength() < 2)
+ bValid = false;
+ else
+ {
+ bool bY, bM, bD;
+ bY = bM = bD = false;
+ bool bSep = true;
+ for (sal_Int32 i = 0; i < aPat.getLength() && bValid; /*nop*/)
+ {
+ sal_uInt32 c = aPat.iterateCodePoints( &i);
+ // Only one Y,M,D per pattern, separated by any character(s).
+ switch (c)
+ {
+ case 'Y':
+ if (bY || !bSep)
+ bValid = false;
+ bY = true;
+ bSep = false;
+ break;
+ case 'M':
+ if (bM || !bSep)
+ bValid = false;
+ bM = true;
+ bSep = false;
+ break;
+ case 'D':
+ if (bD || !bSep)
+ bValid = false;
+ bD = true;
+ bSep = false;
+ break;
+ default:
+ bSep = true;
+ }
+ }
+ // At least one of Y,M,D
+ bValid &= (bY || bM || bD);
+ }
+ }
+ }
+ if (bValid)
+ {
+ pEd->SetControlForeground();
+ pEd->SetControlBackground();
+ }
+ else
+ {
+ // color to use as foreground for an invalid pattern
+ #define INVALID_PATTERN_FOREGROUND_COLOR Color(COL_WHITE)
+ // color to use as background for an invalid pattern
+ #define INVALID_PATTERN_BACKGROUND_COLOR Color(0xff6563)
+#if 0
+ //! Gives white on white!?!
+ pEd->SetControlBackground( INVALID_PATTERN_BACKGROUND_COLOR);
+ pEd->SetControlForeground( INVALID_PATTERN_FOREGROUND_COLOR);
+#else
+ pEd->SetControlForeground( INVALID_PATTERN_BACKGROUND_COLOR);
+#endif
+ }
return 0;
}
diff --git a/cui/source/options/optgdlg.hrc b/cui/source/options/optgdlg.hrc
index aaa966660faf..59293806fb49 100644
--- a/cui/source/options/optgdlg.hrc
+++ b/cui/source/options/optgdlg.hrc
@@ -176,6 +176,9 @@
#define FI_USERINTERFACE 29
#define FT_USERINTERFACE 30
#define LB_USERINTERFACE 31
+#define FI_DATEPATTERNS 32
+#define FT_DATEPATTERNS 33
+#define ED_DATEPATTERNS 34
#define FL_FILEDLG 53
#define FI_FILEDLG_RO 54
diff --git a/cui/source/options/optgdlg.hxx b/cui/source/options/optgdlg.hxx
index e38c48c90db3..b58868866e75 100644
--- a/cui/source/options/optgdlg.hxx
+++ b/cui/source/options/optgdlg.hxx
@@ -179,6 +179,9 @@ class OfaLanguagesTabPage : public SfxTabPage
CheckBox aDecimalSeparatorCB;
FixedText aCurrencyFT;
ListBox aCurrencyLB;
+ ReadOnlyImage aDatePatternsFI;
+ FixedText aDatePatternsFT;
+ Edit aDatePatternsED;
FixedLine aLinguLanguageGB;
ReadOnlyImage aWesternLanguageFI;
@@ -207,6 +210,7 @@ class OfaLanguagesTabPage : public SfxTabPage
DECL_LINK( SupportHdl, CheckBox* ) ;
DECL_LINK( LocaleSettingHdl, SvxLanguageBox* ) ;
+ DECL_LINK( DatePatternsHdl, Edit* ) ;
public:
OfaLanguagesTabPage( Window* pParent, const SfxItemSet& rSet );
diff --git a/cui/source/options/optgdlg.src b/cui/source/options/optgdlg.src
index 272874429302..67abcf0aa2d2 100644
--- a/cui/source/options/optgdlg.src
+++ b/cui/source/options/optgdlg.src
@@ -558,21 +558,41 @@ TabPage OFA_TP_LANGUAGES
TabStop = TRUE ;
Sort = TRUE;
};
+ FixedImage FI_DATEPATTERNS
+ {
+ Pos = MAP_APPFONT ( 5 , 78 ) ;
+ Size = MAP_APPFONT ( 6 , 6 ) ;
+ Hide = TRUE;
+ };
+ FixedText FT_DATEPATTERNS
+ {
+ Pos = MAP_APPFONT ( 12 , 76 ) ;
+ Size = MAP_APPFONT ( 108 , 8 ) ;
+ Text [ en-US ] = "Date acceptance ~patterns";
+ };
+ Edit ED_DATEPATTERNS
+ {
+ HelpID = "cui:Edit:OFA_TP_LANGUAGES:ED_DATEPATTERNS";
+ Pos = MAP_APPFONT ( 123 , 74 ) ;
+ Size = MAP_APPFONT ( 125 , 12 ) ;
+ Border = TRUE ;
+ TabStop = TRUE ;
+ };
FixedLine FL_LINGU_LANG
{
- Pos = MAP_APPFONT ( 6 , 77 ) ;
+ Pos = MAP_APPFONT ( 6 , 92 ) ;
Size = MAP_APPFONT ( 248 , 8 ) ;
Text [ en-US ] = "Default languages for documents";
};
FixedImage FI_WEST_LANG
{
- Pos = MAP_APPFONT ( 5 , 92 ) ;
+ Pos = MAP_APPFONT ( 5 , 107 ) ;
Size = MAP_APPFONT ( 6 , 6 ) ;
Hide = TRUE;
};
FixedText FT_WEST_LANG
{
- Pos = MAP_APPFONT ( 12 , 90 ) ;
+ Pos = MAP_APPFONT ( 12 , 105 ) ;
Size = MAP_APPFONT ( 108 , 8 ) ;
Text [ en-US ] = "Western";
};
@@ -580,7 +600,7 @@ TabPage OFA_TP_LANGUAGES
ListBox LB_WEST_LANG
{
HelpID = "cui:ListBox:OFA_TP_LANGUAGES:LB_WEST_LANG";
- Pos = MAP_APPFONT ( 123 , 88 ) ;
+ Pos = MAP_APPFONT ( 123 , 103 ) ;
Size = MAP_APPFONT ( 125 , 60 ) ;
DropDown = TRUE ;
Border = TRUE ;
@@ -589,20 +609,20 @@ TabPage OFA_TP_LANGUAGES
};
FixedImage FI_ASIAN_LANG
{
- Pos = MAP_APPFONT ( 5 , 108 ) ;
+ Pos = MAP_APPFONT ( 5 , 123 ) ;
Size = MAP_APPFONT ( 6 , 6 ) ;
Hide = TRUE;
};
FixedText FT_ASIAN_LANG
{
- Pos = MAP_APPFONT ( 12 , 106 ) ;
+ Pos = MAP_APPFONT ( 12 , 121 ) ;
Size = MAP_APPFONT ( 108 , 8 ) ;
Text [ en-US ] = "Asian";
};
ListBox LB_ASIAN_LANG
{
HelpID = "cui:ListBox:OFA_TP_LANGUAGES:LB_ASIAN_LANG";
- Pos = MAP_APPFONT ( 123 , 104 ) ;
+ Pos = MAP_APPFONT ( 123 , 119 ) ;
Size = MAP_APPFONT ( 125 , 60 ) ;
DropDown = TRUE ;
Border = TRUE ;
@@ -611,20 +631,20 @@ TabPage OFA_TP_LANGUAGES
};
FixedImage FI_COMPLEX_LANG
{
- Pos = MAP_APPFONT ( 5 , 124 ) ;
+ Pos = MAP_APPFONT ( 5 , 139 ) ;
Size = MAP_APPFONT ( 6 , 6 ) ;
Hide = TRUE;
};
FixedText FT_COMPLEX_LANG
{
- Pos = MAP_APPFONT ( 12 , 122 ) ;
+ Pos = MAP_APPFONT ( 12 , 137 ) ;
Size = MAP_APPFONT ( 108 , 8 ) ;
Text [ en-US ] = "C~TL";
};
ListBox LB_COMPLEX_LANG
{
HelpID = "cui:ListBox:OFA_TP_LANGUAGES:LB_COMPLEX_LANG";
- Pos = MAP_APPFONT ( 123 , 120 ) ;
+ Pos = MAP_APPFONT ( 123 , 135 ) ;
Size = MAP_APPFONT ( 125 , 60 ) ;
DropDown = TRUE ;
Border = TRUE ;
@@ -634,39 +654,39 @@ TabPage OFA_TP_LANGUAGES
CheckBox CB_CURRENT_DOC
{
HelpID = "cui:CheckBox:OFA_TP_LANGUAGES:CB_CURRENT_DOC";
- Pos = MAP_APPFONT ( 123 , 135 ) ;
+ Pos = MAP_APPFONT ( 123 , 150 ) ;
Size = MAP_APPFONT ( 125 , RSC_CD_CHECKBOX_HEIGHT ) ;
Text [ en-US ] = "For the current document only";
};
FixedLine FL_ENHANCED
{
- Pos = MAP_APPFONT ( 6 , 145 ) ;
+ Pos = MAP_APPFONT ( 6 , 160 ) ;
Size = MAP_APPFONT ( 248 , 8 ) ;
Text [ en-US ] = "Enhanced language support";
};
FixedImage FI_ASIANSUPPORT
{
- Pos = MAP_APPFONT ( 5 , 160 ) ;
+ Pos = MAP_APPFONT ( 5 , 175 ) ;
Size = MAP_APPFONT ( 6 , 6 ) ;
Hide = TRUE;
};
CheckBox CB_ASIANSUPPORT
{
HelpID = "cui:CheckBox:OFA_TP_LANGUAGES:CB_ASIANSUPPORT";
- Pos = MAP_APPFONT ( 12 , 158 ) ;
+ Pos = MAP_APPFONT ( 12 , 173 ) ;
Size = MAP_APPFONT ( 236 ,RSC_CD_CHECKBOX_HEIGHT ) ;
Text [ en-US ] = "E~nabled for Asian languages";
};
FixedImage FI_CTLSUPPORT
{
- Pos = MAP_APPFONT ( 5 , 175 ) ;
+ Pos = MAP_APPFONT ( 5 , 190 ) ;
Size = MAP_APPFONT ( 6 , 6 ) ;
Hide = TRUE;
};
CheckBox CB_CTLSUPPORT
{
HelpID = "cui:CheckBox:OFA_TP_LANGUAGES:CB_CTLSUPPORT";
- Pos = MAP_APPFONT ( 12 , 173 ) ;
+ Pos = MAP_APPFONT ( 12 , 188 ) ;
Size = MAP_APPFONT ( 236 , RSC_CD_CHECKBOX_HEIGHT ) ;
Text [ en-US ] = "Ena~bled for complex text layout (CTL)";
};