summaryrefslogtreecommitdiff
path: root/svl
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 /svl
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 'svl')
-rw-r--r--svl/inc/svl/zforlist.hxx4
-rw-r--r--svl/source/numbers/zforfind.cxx55
-rw-r--r--svl/source/numbers/zforfind.hxx2
-rw-r--r--svl/source/numbers/zforlist.cxx37
4 files changed, 77 insertions, 21 deletions
diff --git a/svl/inc/svl/zforlist.hxx b/svl/inc/svl/zforlist.hxx
index 701216468f0d..2dfa273df6da 100644
--- a/svl/inc/svl/zforlist.hxx
+++ b/svl/inc/svl/zforlist.hxx
@@ -953,6 +953,10 @@ public:
// called by SvNumberFormatterRegistry_Impl::Notify if the default system currency changes
void ResetDefaultSystemCurrency();
+ // Called by SvNumberFormatterRegistry_Impl::Notify if the system locale's
+ // date acceptence patterns change.
+ void InvalidateDateAcceptancePatterns();
+
// Replace the SYSTEM language/country format codes. Called upon change of
// the user configurable locale.
// Old compatibility codes are replaced, user defined are converted, and
diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx
index 31f9c2cb8461..eae56daf0eb5 100644
--- a/svl/source/numbers/zforfind.cxx
+++ b/svl/source/numbers/zforfind.cxx
@@ -1021,12 +1021,6 @@ bool ImpSvNumberInputScan::CanForceToIso8601( DateFormat eDateFormat )
break;
}
- if (pFormatter->GetDateSep() != '-')
- {
- nCanForceToIso8601 = 2; // date separator does not interfere
- break;
- }
-
sal_Int32 n;
switch (eDateFormat)
{
@@ -1300,6 +1294,18 @@ DateFormat ImpSvNumberInputScan::GetDateOrder()
return DMY;
}
break;
+ default:
+ case 0:
+ switch ((nOrder & 0xff))
+ {
+ case 'Y':
+ return YMD;
+ case 'M':
+ return MDY;
+ case 'D':
+ return DMY;
+ }
+ break;
}
}
SAL_WARN( "nf.date", "ImpSvNumberInputScan::GetDateOrder: undefined, falling back to locale's default");
@@ -1440,8 +1446,30 @@ input for the following reasons:
nCounter = 1;
switch (nMonthPos) // where is the month
{
- case 0: // not found => only day entered
- pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(0) );
+ case 0: // not found
+ {
+ // If input matched a date pattern, use the pattern
+ // to determine if it is a day, month or year. The
+ // pattern should have only one single value then,
+ // 'D-', 'M-' or 'Y-'. If input did not match a
+ // pattern assume the usual day of current month.
+ sal_uInt32 nDateOrder = (bFormatTurn ?
+ pFormat->GetExactDateOrder() :
+ GetDatePatternOrder());
+ switch (nDateOrder)
+ {
+ case 'Y':
+ pCal->setValue( CalendarFieldIndex::YEAR, ImplGetYear(0) );
+ break;
+ case 'M':
+ pCal->setValue( CalendarFieldIndex::MONTH, ImplGetMonth(0) );
+ break;
+ case 'D':
+ default:
+ pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(0) );
+ break;
+ }
+ }
break;
case 1: // month at the beginning (Jan 01)
pCal->setValue( CalendarFieldIndex::MONTH, Abs(nMonth)-1 );
@@ -2233,6 +2261,7 @@ bool ImpSvNumberInputScan::ScanEndString( const String& rString,
}
}
+ bool bSignDetectedHere = false;
if ( nSign == 0 // conflict - not signed
&& eScannedType != NUMBERFORMAT_DATE) // and not date
//!? catch time too?
@@ -2240,6 +2269,8 @@ bool ImpSvNumberInputScan::ScanEndString( const String& rString,
nSign = GetSign(rString, nPos); // 1- DM
if (nNegCheck) // '(' as sign
return MatchedReturn();
+ if (nSign)
+ bSignDetectedHere = true;
}
SkipBlanks(rString, nPos);
@@ -2310,6 +2341,8 @@ bool ImpSvNumberInputScan::ScanEndString( const String& rString,
const String& rDate = pFormatter->GetDateSep();
bDate = SkipString( rDate, rString, nPos); // 10. 10- 10/
}
+ if (bDate && bSignDetectedHere)
+ nSign = 0; // 'D-' takes precedence over signed date
if (bDate
|| ((MayBeIso8601() || MayBeMonthDate())
&& SkipChar( '-', rString, nPos)))
@@ -2877,6 +2910,12 @@ void ImpSvNumberInputScan::ChangeIntl()
cDecSep == pFormatter->GetDateSep().GetChar(0) );
bTextInitialized = false;
aUpperCurrSymbol.Erase();
+ InvalidateDateAcceptancePatterns();
+}
+
+
+void ImpSvNumberInputScan::InvalidateDateAcceptancePatterns()
+{
if (sDateAcceptancePatterns.getLength())
sDateAcceptancePatterns = ::com::sun::star::uno::Sequence< ::rtl::OUString >();
}
diff --git a/svl/source/numbers/zforfind.hxx b/svl/source/numbers/zforfind.hxx
index 7c2e8eb09122..233b012a4983 100644
--- a/svl/source/numbers/zforfind.hxx
+++ b/svl/source/numbers/zforfind.hxx
@@ -83,6 +83,8 @@ public:
*/
bool CanForceToIso8601( DateFormat eDateFormat );
+ void InvalidateDateAcceptancePatterns();
+
private:
SvNumberFormatter* pFormatter;
String* pUpperMonthText; // Array of month names, uppercase
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx
index 7c8a49ca727b..8cd59f850386 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -151,19 +151,24 @@ void SvNumberFormatterRegistry_Impl::ConfigurationChanged(
utl::ConfigurationBroadcaster*,
sal_uInt32 nHint)
{
- if ( nHint & SYSLOCALEOPTIONS_HINT_LOCALE )
- {
- ::osl::MutexGuard aGuard( SvNumberFormatter::GetMutex() );
- for( size_t i = 0, n = aFormatters.size(); i < n; ++i )
- aFormatters[ i ]->ReplaceSystemCL( eSysLanguage );
- eSysLanguage = MsLangId::getRealLanguage( LANGUAGE_SYSTEM );
- }
- if ( nHint & SYSLOCALEOPTIONS_HINT_CURRENCY )
- {
- ::osl::MutexGuard aGuard( SvNumberFormatter::GetMutex() );
- for( size_t i = 0, n = aFormatters.size(); i < n; ++i )
- aFormatters[ i ]->ResetDefaultSystemCurrency();
- }
+ ::osl::MutexGuard aGuard( SvNumberFormatter::GetMutex() );
+
+ if ( nHint & SYSLOCALEOPTIONS_HINT_LOCALE )
+ {
+ for( size_t i = 0, n = aFormatters.size(); i < n; ++i )
+ aFormatters[ i ]->ReplaceSystemCL( eSysLanguage );
+ eSysLanguage = MsLangId::getRealLanguage( LANGUAGE_SYSTEM );
+ }
+ if ( nHint & SYSLOCALEOPTIONS_HINT_CURRENCY )
+ {
+ for( size_t i = 0, n = aFormatters.size(); i < n; ++i )
+ aFormatters[ i ]->ResetDefaultSystemCurrency();
+ }
+ if ( nHint & SYSLOCALEOPTIONS_HINT_DATEPATTERNS )
+ {
+ for( size_t i = 0, n = aFormatters.size(); i < n; ++i )
+ aFormatters[ i ]->InvalidateDateAcceptancePatterns();
+ }
}
@@ -3183,6 +3188,12 @@ void SvNumberFormatter::ResetDefaultSystemCurrency()
}
+void SvNumberFormatter::InvalidateDateAcceptancePatterns()
+{
+ pStringScanner->InvalidateDateAcceptancePatterns();
+}
+
+
sal_uInt32 SvNumberFormatter::ImpGetDefaultSystemCurrencyFormat()
{
if ( nDefaultSystemCurrencyFormat == NUMBERFORMAT_ENTRY_NOT_FOUND )