diff options
author | Eike Rathke <erack@redhat.com> | 2021-07-03 11:46:49 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2021-07-05 10:30:01 +0200 |
commit | 96f2a6d16e6a6bf070e6875776b6153a70e75a7a (patch) | |
tree | 15d82e167aadc19f3ea71b58167307eb11fa8969 | |
parent | f9fab8cd5a7ebccc6b659dbc831385e3722d97d6 (diff) |
Resolves: tdf#125035 Use number formatter for long date in DateFormatter fields
Change-Id: Ib0cd55d9ad4e3abb4839d70c0086063a3f1a90f0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118344
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
(cherry picked from commit 2cc8ec691cc37b07e4f134bf379164f375b8a481)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118310
-rw-r--r-- | include/vcl/formatter.hxx | 4 | ||||
-rw-r--r-- | include/vcl/toolkit/field.hxx | 4 | ||||
-rw-r--r-- | vcl/source/control/field2.cxx | 24 |
3 files changed, 26 insertions, 6 deletions
diff --git a/include/vcl/formatter.hxx b/include/vcl/formatter.hxx index e2879dc36076..2049d1e12a6f 100644 --- a/include/vcl/formatter.hxx +++ b/include/vcl/formatter.hxx @@ -85,7 +85,7 @@ enum class FORMAT_CHANGE_TYPE class VCL_DLLPUBLIC Formatter { -private: +public: // A SvNumberFormatter is very expensive (regarding time and space), it is a Singleton class StaticFormatter { @@ -95,7 +95,7 @@ private: StaticFormatter(); ~StaticFormatter(); - operator SvNumberFormatter* () { return GetFormatter(); } + operator SvNumberFormatter* () const { return GetFormatter(); } UNLESS_MERGELIBS(VCL_DLLPUBLIC) static SvNumberFormatter* GetFormatter(); }; diff --git a/include/vcl/toolkit/field.hxx b/include/vcl/toolkit/field.hxx index e30d16e55edc..d6ae05f51fc5 100644 --- a/include/vcl/toolkit/field.hxx +++ b/include/vcl/toolkit/field.hxx @@ -29,6 +29,7 @@ #include <tools/time.hxx> #include <vcl/toolkit/combobox.hxx> #include <vcl/toolkit/spinfld.hxx> +#include <vcl/formatter.hxx> namespace com::sun::star::lang { struct Locale; } @@ -391,6 +392,7 @@ public: class UNLESS_MERGELIBS(VCL_DLLPUBLIC) DateFormatter : public FormatterBase { private: + Formatter::StaticFormatter maStaticFormatter; std::unique_ptr<CalendarWrapper> mxCalendarWrapper; Date maFieldDate; Date maLastDate; @@ -415,7 +417,7 @@ protected: SAL_DLLPRIVATE bool ImplAllowMalformedInput() const; public: - static OUString FormatDate(const Date& rNewDate, ExtDateFieldFormat eFormat, const LocaleDataWrapper& rLocaleData, CalendarWrapper& rCalendarWrapper); + static OUString FormatDate(const Date& rNewDate, ExtDateFieldFormat eFormat, const LocaleDataWrapper& rLocaleData, CalendarWrapper& rCalendarWrapper, const Formatter::StaticFormatter* pStaticFormatter = nullptr); static bool TextToDate(const OUString& rStr, Date& rTime, ExtDateFieldFormat eFormat, const LocaleDataWrapper& rLocaleDataWrapper, const CalendarWrapper& rCalendarWrapper); static int GetDateArea(ExtDateFieldFormat eFormat, const OUString& rText, int nCursor, const LocaleDataWrapper& rLocaleDataWrapper); diff --git a/vcl/source/control/field2.cxx b/vcl/source/control/field2.cxx index b66e226262ff..603415672f38 100644 --- a/vcl/source/control/field2.cxx +++ b/vcl/source/control/field2.cxx @@ -40,6 +40,7 @@ #include <unotools/localedatawrapper.hxx> #include <unotools/calendarwrapper.hxx> #include <unotools/charclass.hxx> +#include <svl/zforlist.hxx> using namespace ::com::sun::star; using namespace ::comphelper; @@ -1387,7 +1388,8 @@ namespace } OUString DateFormatter::FormatDate(const Date& rDate, ExtDateFieldFormat eExtFormat, - const LocaleDataWrapper& rLocaleData, CalendarWrapper& rCalendarWrapper) + const LocaleDataWrapper& rLocaleData, CalendarWrapper& rCalendarWrapper, + const Formatter::StaticFormatter* pStaticFormatter) { bool bShowCentury = false; switch (eExtFormat) @@ -1437,7 +1439,22 @@ OUString DateFormatter::FormatDate(const Date& rDate, ExtDateFieldFormat eExtFor { case ExtDateFieldFormat::SystemLong: { - return rLocaleData.getLongDate( rDate, rCalendarWrapper, !bShowCentury ); + /* TODO: adapt all callers to pass a StaticFormatter. */ + if (!pStaticFormatter) + return rLocaleData.getLongDate( rDate, rCalendarWrapper, !bShowCentury ); + else + { + SvNumberFormatter* pFormatter = *pStaticFormatter; + const LanguageTag aFormatterLang( pFormatter->GetLanguageTag()); + const sal_uInt32 nIndex = pFormatter->GetFormatIndex( NF_DATE_SYSTEM_LONG, + rLocaleData.getLanguageTag().getLanguageType(false)); + OUString aStr; + const Color* pCol; + pFormatter->GetOutputString( rDate - pFormatter->GetNullDate(), nIndex, aStr, &pCol); + // Reset to what other uses may expect. + pFormatter->ChangeIntl( aFormatterLang.getLanguageType(false)); + return aStr; + } } case ExtDateFieldFormat::ShortDDMMYY: case ExtDateFieldFormat::ShortDDMMYYYY: @@ -1482,7 +1499,8 @@ OUString DateFormatter::FormatDate(const Date& rDate, ExtDateFieldFormat eExtFor OUString DateFormatter::ImplGetDateAsText( const Date& rDate ) const { - return DateFormatter::FormatDate(rDate, GetExtDateFormat(), ImplGetLocaleDataWrapper(), GetCalendarWrapper()); + return DateFormatter::FormatDate(rDate, GetExtDateFormat(), ImplGetLocaleDataWrapper(), + GetCalendarWrapper(), &maStaticFormatter); } static void ImplDateIncrementDay( Date& rDate, bool bUp ) |