[Libreoffice-commits] core.git: cui/source include/svl sc/source svl/source

Laurent BP (via logerrit) logerrit at kemper.freedesktop.org
Mon Jun 15 17:37:48 UTC 2020


 cui/source/tabpages/numfmt.cxx                     |   13 +++---
 include/svl/zformat.hxx                            |    4 +
 sc/source/ui/sidebar/NumberFormatPropertyPanel.cxx |   14 +++---
 sc/source/ui/view/formatsh.cxx                     |    4 +
 sc/source/ui/view/viewfunc.cxx                     |    4 -
 svl/source/numbers/zforlist.cxx                    |    8 ++-
 svl/source/numbers/zformat.cxx                     |   43 +++++++++++++++++++++
 7 files changed, 72 insertions(+), 18 deletions(-)

New commits:
commit 1861363d623963461905f42aa0b9dc2301f2eaaa
Author:     Laurent BP <laurent.balland-poirier at laposte.net>
AuthorDate: Sun May 24 22:30:41 2020 +0200
Commit:     Eike Rathke <erack at redhat.com>
CommitDate: Mon Jun 15 19:37:12 2020 +0200

    tdf#103414 Add/Delete decimal for 100th second
    
    Use Add/Delete decimal to change precision of time and duration
    Apply only to 100th second
    
    Change-Id: I2ff1b01db7ee67645511fcf7ea6bf65055e92a8c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94765
    Tested-by: Jenkins
    Reviewed-by: Eike Rathke <erack at redhat.com>

diff --git a/cui/source/tabpages/numfmt.cxx b/cui/source/tabpages/numfmt.cxx
index 109c9ef8982f..4297cd52241e 100644
--- a/cui/source/tabpages/numfmt.cxx
+++ b/cui/source/tabpages/numfmt.cxx
@@ -920,6 +920,7 @@ void SvxNumberFormatTabPage::UpdateOptions_Impl( bool bCheckCatChange /*= sal_Fa
         case CAT_PERCENT:
         case CAT_CURRENCY:
         case CAT_FRACTION:
+        case CAT_TIME:
             m_xFtOptions->set_sensitive(true);
             if ( nCategory == CAT_FRACTION )
             {
@@ -931,8 +932,8 @@ void SvxNumberFormatTabPage::UpdateOptions_Impl( bool bCheckCatChange /*= sal_Fa
                 m_xFtDecimals->set_sensitive(true);
                 m_xEdDecimals->set_sensitive(true);
             }
-            m_xFtLeadZeroes->set_sensitive(true);
-            m_xEdLeadZeroes->set_sensitive(true);
+            m_xFtLeadZeroes->set_sensitive( nCategory != CAT_TIME );
+            m_xEdLeadZeroes->set_sensitive( nCategory != CAT_TIME );
             m_xBtnNegRed->set_sensitive(true);
             if ( nCategory == CAT_NUMBER && m_xLbFormat->get_selected_index() == 0 )
                 m_xEdDecimals->set_text( "" ); //General format tdf#44399
@@ -941,12 +942,13 @@ void SvxNumberFormatTabPage::UpdateOptions_Impl( bool bCheckCatChange /*= sal_Fa
                     m_xEdDenominator->set_value( nDecimals );
                 else
                     m_xEdDecimals->set_value( nDecimals );
-            m_xEdLeadZeroes->set_value( nZeroes );
+            if ( nCategory != CAT_TIME )
+                m_xEdLeadZeroes->set_value( nZeroes );
             m_xBtnNegRed->set_active( bNegRed );
             if ( nCategory != CAT_SCIENTIFIC )
             {
-                m_xBtnThousand->set_sensitive(true);
-                m_xBtnThousand->set_active( bThousand );
+                m_xBtnThousand->set_sensitive( nCategory != CAT_TIME );
+                m_xBtnThousand->set_active( bThousand && nCategory != CAT_TIME );
             }
             break;
 
@@ -954,7 +956,6 @@ void SvxNumberFormatTabPage::UpdateOptions_Impl( bool bCheckCatChange /*= sal_Fa
         case CAT_USERDEFINED:
         case CAT_TEXT:
         case CAT_DATE:
-        case CAT_TIME:
         case CAT_BOOLEAN:
         default:
             m_xFtOptions->set_sensitive(false);
diff --git a/include/svl/zformat.hxx b/include/svl/zformat.hxx
index abd805d187e5..089a4b0e48e6 100644
--- a/include/svl/zformat.hxx
+++ b/include/svl/zformat.hxx
@@ -305,6 +305,10 @@ public:
     /// Round fNumber to its fraction representation
     double GetRoundFractionValue ( double fNumber ) const;
 
+    /// Create a format string for time with a new precision
+    OUString GetFormatStringForTimePrecision( int nPrecision ) const;
+
+
     /** If the count of string elements (substrings, ignoring [modifiers] and
         so on) in a subformat code nNumFor (0..3) is equal to the given number.
         Used by ImpSvNumberInputScan::IsNumberFormatMain() to detect a matched
diff --git a/sc/source/ui/sidebar/NumberFormatPropertyPanel.cxx b/sc/source/ui/sidebar/NumberFormatPropertyPanel.cxx
index eeb46ef316ad..324ebe8f8171 100644
--- a/sc/source/ui/sidebar/NumberFormatPropertyPanel.cxx
+++ b/sc/source/ui/sidebar/NumberFormatPropertyPanel.cxx
@@ -197,14 +197,14 @@ void NumberFormatPropertyPanel::NotifyItemUpdate(
                 sal_uInt16 nVal = pItem->GetValue();
                 mnCategorySelected = nVal;
                 mxLbCategory->set_active(nVal);
-                if( nVal < 4 ||  // General, Number, Percent and Currency
-                    nVal == 6 || // scientific also
-                    nVal == 7 )  // fraction
+                if (nVal < 8 &&  // General, Number, Percent, Currency, Time, Scientific, Fraction
+                    nVal != 4 )  // not Date
                 {
                     bool bIsScientific ( nVal == 6 );// For scientific, Thousand separator is replaced by Engineering notation
                     bool bIsFraction ( nVal == 7 );  // For fraction, Decimal places is replaced by Denominator places
-                    mxBtnThousand->set_visible(!bIsScientific);
-                    mxBtnThousand->set_sensitive(!bIsScientific);
+                    bool bIsTime ( nVal == 5 );  // For Time, Decimal places and NegRed available
+                    mxBtnThousand->set_visible( !bIsScientific );
+                    mxBtnThousand->set_sensitive( !bIsScientific && !bIsTime );
                     mxBtnThousand->set_active(false);
                     mxBtnEngineering->set_visible(bIsScientific);
                     mxBtnEngineering->set_sensitive(bIsScientific);
@@ -218,8 +218,8 @@ void NumberFormatPropertyPanel::NotifyItemUpdate(
                     mxEdDecimals->set_visible(!bIsFraction);
                     mxFtDecimals->set_sensitive(!bIsFraction);
                     mxEdDecimals->set_sensitive(!bIsFraction);
-                    mxFtLeadZeroes->set_sensitive(true);
-                    mxEdLeadZeroes->set_sensitive(true);
+                    mxFtLeadZeroes->set_sensitive( !bIsTime );
+                    mxEdLeadZeroes->set_sensitive( !bIsTime );
                 }
                 else
                     DisableControls();
diff --git a/sc/source/ui/view/formatsh.cxx b/sc/source/ui/view/formatsh.cxx
index 48ee79cafaac..dc685f4996e6 100644
--- a/sc/source/ui/view/formatsh.cxx
+++ b/sc/source/ui/view/formatsh.cxx
@@ -1165,7 +1165,7 @@ void ScFormatShell::ExecuteNumFormat( SfxRequest& rReq )
                 LanguageType eLanguage = pEntry->GetLanguage();
                 SvNumFormatType eType = pEntry->GetType();
 
-                //Just use eType to judge whether the command is fired for NUMBER/PERCENT/CURRENCY/SCIENTIFIC/FRACTION
+                //Just use eType to judge whether the command is fired for NUMBER/PERCENT/CURRENCY/SCIENTIFIC/FRACTION/TIME
                 //In sidebar, users can fire SID_NUMBER_FORMAT command by operating the related UI controls before they are disable
                 if(!(eType == SvNumFormatType::ALL
                      || eType == SvNumFormatType::NUMBER
@@ -1176,6 +1176,8 @@ void ScFormatShell::ExecuteNumFormat( SfxRequest& rReq )
                      || eType == (SvNumFormatType::CURRENCY | SvNumFormatType::DEFINED)
                      || eType == SvNumFormatType::SCIENTIFIC
                      || eType == (SvNumFormatType::SCIENTIFIC | SvNumFormatType::DEFINED)
+                     || eType == SvNumFormatType::TIME
+                     || eType == (SvNumFormatType::TIME | SvNumFormatType::DEFINED)
                      || eType == SvNumFormatType::FRACTION
                      || eType == (SvNumFormatType::FRACTION | SvNumFormatType::DEFINED)))
                     pEntry = nullptr;
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index a18986808e1c..ab700220c42a 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -2709,9 +2709,9 @@ void ScViewFunc::ChangeNumFmtDecimals( bool bIncrement )
 
     SvNumFormatType nOldType = pOldEntry->GetType();
     if ( SvNumFormatType::ALL == ( nOldType & (
-                SvNumFormatType::NUMBER |  SvNumFormatType::CURRENCY | SvNumFormatType::PERCENT | SvNumFormatType::SCIENTIFIC ) ) )
+                SvNumFormatType::NUMBER |  SvNumFormatType::CURRENCY | SvNumFormatType::PERCENT | SvNumFormatType::SCIENTIFIC | SvNumFormatType::TIME ) ) )
     {
-        //  date, time, fraction, logical, text can not be changed
+        //  date, fraction, logical, text can not be changed
         bError = true;
     }
 
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx
index fa501943c341..5a8b5c4744ce 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -3046,7 +3046,11 @@ OUString SvNumberFormatter::GenerateFormat(sal_uInt32 nIndex,
     OUStringBuffer sString;
     using comphelper::string::padToLength;
 
-    if (nLeadingZeros == 0)
+    if (eType & SvNumFormatType::TIME)
+    {
+        sString = pFormat->GetFormatStringForTimePrecision( nPrecision );
+    }
+    else if (nLeadingZeros == 0)
     {
         if (!bThousand)
             sString.append('#');
@@ -3086,7 +3090,7 @@ OUString SvNumberFormatter::GenerateFormat(sal_uInt32 nIndex,
             }
         }
     }
-    if (nPrecision > 0 && eType != SvNumFormatType::FRACTION )
+    if (nPrecision > 0 && eType != SvNumFormatType::FRACTION && !( eType & SvNumFormatType::TIME ) )
     {
         sString.append(GetNumDecimalSep());
         padToLength(sString, sString.getLength() + nPrecision, '0');
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index f683b4c62f12..33026a8508b5 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -5848,6 +5848,49 @@ bool SvNumberformat::IsMinuteSecondFormat() const
 #undef HAS_MINUTE_SECOND
 }
 
+OUString SvNumberformat::GetFormatStringForTimePrecision( int nPrecision ) const
+{
+    OUStringBuffer sString;
+    using comphelper::string::padToLength;
+
+    sal_uInt16 nNumForCnt = NumFor[0].GetCount();
+    auto const & rTypeArray = NumFor[0].Info().nTypeArray;
+    for (sal_uInt16 j=0; j < nNumForCnt; ++j)
+    {
+        switch (rTypeArray[j])
+        {
+            case NF_KEY_S :
+            case NF_KEY_SS:
+                sString.append( NumFor[0].Info().sStrArray[j] );
+                if ( j > 0 && rTypeArray[j-1] == NF_SYMBOLTYPE_DEL && j < nNumForCnt-1 )
+                {
+                    j++;
+                    sString.append( NumFor[0].Info().sStrArray[j] );
+                }
+                if (nPrecision > 0)
+                {
+                    sString.append( rLoc().getTime100SecSep() );
+                    padToLength(sString, sString.getLength() + nPrecision, '0');
+                }
+                break;
+            case NF_SYMBOLTYPE_TIME100SECSEP:
+            case NF_SYMBOLTYPE_DIGIT:
+                break;
+            case NF_SYMBOLTYPE_STRING:
+                sString.append( "\"" );
+                [[fallthrough]];
+            default:
+                sString.append( NumFor[0].Info().sStrArray[j] );
+                if (rTypeArray[j] == NF_SYMBOLTYPE_STRING)
+                {
+                    sString.append( "\"" );
+                }
+        }
+    }
+
+    return sString.makeStringAndClear();
+}
+
 const CharClass& SvNumberformat::rChrCls() const
 {
     return rScan.GetChrCls();


More information about the Libreoffice-commits mailing list