[Libreoffice-commits] core.git: include/vcl vcl/source

Eike Rathke (via logerrit) logerrit at kemper.freedesktop.org
Sun Jul 4 00:29:21 UTC 2021


 include/vcl/formatter.hxx     |    4 ++--
 include/vcl/toolkit/field.hxx |    4 +++-
 vcl/source/control/field2.cxx |   24 +++++++++++++++++++++---
 3 files changed, 26 insertions(+), 6 deletions(-)

New commits:
commit 2cc8ec691cc37b07e4f134bf379164f375b8a481
Author:     Eike Rathke <erack at redhat.com>
AuthorDate: Sat Jul 3 11:46:49 2021 +0200
Commit:     Eike Rathke <erack at redhat.com>
CommitDate: Sun Jul 4 02:28:48 2021 +0200

    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 at redhat.com>
    Tested-by: Jenkins

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 bf677aec692a..5217922ae20f 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 )


More information about the Libreoffice-commits mailing list