summaryrefslogtreecommitdiff
path: root/cui
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2012-08-29 20:49:01 +0200
committerCaolán McNamara <caolanm@redhat.com>2012-09-07 10:27:47 +0000
commitcfbfa26deb2776e5c07463e59517eaf68c1d5d6d (patch)
tree089961fb8b4c56f68d888f5cdbe622cc799199cc /cui
parenta3044d50775afd105db322ab79a08e218ddc8ff7 (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 (cherry picked from commit bf10f4d62a5fe308ea47f9a0aac4f6f7e264ae3e) Conflicts: cui/source/options/optgdlg.hrc svl/source/numbers/zforfind.cxx unotools/source/config/syslocaleoptions.cxx Change-Id: Ic1ce91b1f9d29f1837d56b45ba0ae16f6d9cb17c Reviewed-on: https://gerrit.libreoffice.org/511 Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com> Reviewed-by: Petr Mladek <pmladek@suse.cz> Tested-by: Petr Mladek <pmladek@suse.cz> Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'cui')
-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 72e66d2b919f..8826a09d009a 100644
--- a/cui/source/options/optgdlg.cxx
+++ b/cui/source/options/optgdlg.cxx
@@ -1248,6 +1248,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();
+ rtl::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 )),
@@ -1261,6 +1277,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 )),
@@ -1383,6 +1402,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 );
@@ -1579,6 +1600,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();
@@ -1730,6 +1756,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;
@@ -1913,14 +1955,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 2ccc5037045f..59e89e40afda 100644
--- a/cui/source/options/optgdlg.hrc
+++ b/cui/source/options/optgdlg.hrc
@@ -203,6 +203,9 @@
#define FT_USERINTERFACE 30
#define LB_USERINTERFACE 31
#define STR_IB_LANGCHANGE_TITLE 32
+#define FI_DATEPATTERNS 33
+#define FT_DATEPATTERNS 34
+#define ED_DATEPATTERNS 35
#define FL_FILEDLG 53
#define FI_FILEDLG_RO 54
diff --git a/cui/source/options/optgdlg.hxx b/cui/source/options/optgdlg.hxx
index 4b7f571d503f..8b832ed717be 100644
--- a/cui/source/options/optgdlg.hxx
+++ b/cui/source/options/optgdlg.hxx
@@ -180,6 +180,9 @@ class OfaLanguagesTabPage : public SfxTabPage
CheckBox aDecimalSeparatorCB;
FixedText aCurrencyFT;
ListBox aCurrencyLB;
+ ReadOnlyImage aDatePatternsFI;
+ FixedText aDatePatternsFT;
+ Edit aDatePatternsED;
FixedLine aLinguLanguageGB;
ReadOnlyImage aWesternLanguageFI;
@@ -208,6 +211,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 75af383c6b77..6e5f3ed5a3c7 100644
--- a/cui/source/options/optgdlg.src
+++ b/cui/source/options/optgdlg.src
@@ -578,21 +578,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";
};
@@ -600,7 +620,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 ;
@@ -609,20 +629,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 ;
@@ -631,20 +651,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 ;
@@ -654,39 +674,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)";
};