cui/source/tabpages/numfmt.cxx | 3 +- include/svl/numformat.hxx | 3 ++ include/svx/numfmtsh.hxx | 27 ++++++++++++--------- sc/source/ui/sidebar/NumberFormatPropertyPanel.cxx | 26 +++++++++++++++----- sc/source/ui/view/formatsh.cxx | 3 ++ svl/source/numbers/zforlist.cxx | 7 +++++ svx/source/items/numfmtsh.cxx | 7 +++++ 7 files changed, 58 insertions(+), 18 deletions(-)
New commits: commit bbd487dc26c7e37982f64f6e6159c65ac77a89f1 Author: Laurent Balland <laurent.ball...@mailo.fr> AuthorDate: Sat Jan 14 15:48:12 2023 +0100 Commit: Eike Rathke <er...@redhat.com> CommitDate: Fri Feb 3 17:57:01 2023 +0000 tdf#153023 Disable Thousand separator for NatNum12 Add some helper to get NatNum12 state Modify both Number format dialog and Sidebar Transform CAT_ defines in enum Change-Id: Iaa3127bf07223caac60e409306a1bee2edc37428 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145513 Tested-by: Jenkins Reviewed-by: Eike Rathke <er...@redhat.com> diff --git a/cui/source/tabpages/numfmt.cxx b/cui/source/tabpages/numfmt.cxx index e6e669de6422..63f9d5ce91f7 100644 --- a/cui/source/tabpages/numfmt.cxx +++ b/cui/source/tabpages/numfmt.cxx @@ -942,7 +942,8 @@ void SvxNumberFormatTabPage::UpdateOptions_Impl( bool bCheckCatChange /*= sal_Fa m_xBtnNegRed->set_active( bNegRed ); if ( nCategory != CAT_SCIENTIFIC ) { - m_xBtnThousand->set_sensitive( nCategory != CAT_TIME ); + m_xBtnThousand->set_sensitive( nCategory != CAT_TIME + && !pNumFmtShell->IsNatNum12( theFormat ) ); m_xBtnThousand->set_active( bThousand && nCategory != CAT_TIME ); } break; diff --git a/include/svl/numformat.hxx b/include/svl/numformat.hxx index 6ff04837b0bb..0a374f3c3301 100644 --- a/include/svl/numformat.hxx +++ b/include/svl/numformat.hxx @@ -238,6 +238,9 @@ public: /// Whether format index nFIndex is of type text or not bool IsTextFormat(sal_uInt32 nFIndex) const; + /// Whether format index nFIndex has NatNum12 modifier + bool IsNatNum12(sal_uInt32 nFIndex) const; + /// Get additional info of a format index, e.g. for dialog box void GetFormatSpecialInfo(sal_uInt32 nFormat, bool& bThousand, bool& IsRed, sal_uInt16& nPrecision, sal_uInt16& nLeadingCnt); diff --git a/include/svx/numfmtsh.hxx b/include/svx/numfmtsh.hxx index 360a067e06c9..db593eb8b77d 100644 --- a/include/svx/numfmtsh.hxx +++ b/include/svx/numfmtsh.hxx @@ -38,17 +38,20 @@ enum class SvxNumberValueType }; // sort order of the category ListBox entries in the TabPage -#define CAT_ALL 0 -#define CAT_USERDEFINED 1 -#define CAT_NUMBER 2 -#define CAT_PERCENT 3 -#define CAT_CURRENCY 4 -#define CAT_DATE 5 -#define CAT_TIME 6 -#define CAT_SCIENTIFIC 7 -#define CAT_FRACTION 8 -#define CAT_BOOLEAN 9 -#define CAT_TEXT 10 +enum SvxNumberFormatCategory +{ + CAT_ALL = 0, + CAT_USERDEFINED, + CAT_NUMBER, + CAT_PERCENT, + CAT_CURRENCY, + CAT_DATE, + CAT_TIME, + CAT_SCIENTIFIC, + CAT_FRACTION, + CAT_BOOLEAN, + CAT_TEXT +}; #define SELPOS_NONE -1 @@ -130,6 +133,8 @@ public: sal_uInt16 GetFormatIntegerDigits( std::u16string_view rFormat ) const; + bool IsNatNum12( std::u16string_view rFormat ) const; + void MakePreviewString( const OUString& rFormatStr, OUString& rPreviewStr, const Color*& rpFontColor ); diff --git a/sc/source/ui/sidebar/NumberFormatPropertyPanel.cxx b/sc/source/ui/sidebar/NumberFormatPropertyPanel.cxx index c9910cc1db82..b2530df9838f 100644 --- a/sc/source/ui/sidebar/NumberFormatPropertyPanel.cxx +++ b/sc/source/ui/sidebar/NumberFormatPropertyPanel.cxx @@ -23,6 +23,7 @@ #include <sfx2/dispatch.hxx> #include <svl/intitem.hxx> #include <svl/stritem.hxx> +#include <svx/numfmtsh.hxx> #include <o3tl/string_view.hxx> #include <com/sun/star/lang/IllegalArgumentException.hpp> @@ -185,12 +186,17 @@ void NumberFormatPropertyPanel::NotifyItemUpdate( sal_uInt16 nVal = pItem->GetValue(); mnCategorySelected = nVal; mxLbCategory->set_active(nVal); - if (nVal < 8 && // General, Number, Percent, Currency, Time, Scientific, Fraction - nVal != 4 ) // not Date + // There is an offset between category list enum and listbox in side panel + SvxNumberFormatCategory nCategory = static_cast< SvxNumberFormatCategory >( nVal + 1 ); + if (nCategory <= CAT_FRACTION && // General, Number, Percent, Currency, Time, Scientific, Fraction + nCategory != CAT_DATE ) // 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 - bool bIsTime ( nVal == 5 ); // For Time, Decimal places and NegRed available + // For scientific, Thousand separator is replaced by Engineering notation + bool bIsScientific ( nCategory == CAT_SCIENTIFIC ); + // For fraction, Decimal places is replaced by Denominator places + bool bIsFraction ( nCategory == CAT_FRACTION ); + // For Time, Decimal places and NegRed available + bool bIsTime ( nCategory == CAT_TIME ); mxBtnThousand->set_visible( !bIsScientific ); mxBtnThousand->set_sensitive( !bIsScientific && !bIsTime ); mxBtnThousand->set_active(false); @@ -226,12 +232,14 @@ void NumberFormatPropertyPanel::NotifyItemUpdate( bool bNegRed = false; sal_uInt16 nPrecision = 0; sal_uInt16 nLeadZeroes = 0; + bool bNatNum12 = false; + SvxNumberFormatCategory nCategory = static_cast< SvxNumberFormatCategory >( mnCategorySelected + 1 ); if( eState >= SfxItemState::DEFAULT) { const SfxStringItem* pItem = static_cast<const SfxStringItem*>(pState); const OUString& aCode = pItem->GetValue(); sal_Int32 nIndex = 0; - sal_Int32 aFormat[4] = {0}; + sal_Int32 aFormat[5] = {0}; for (sal_Int32 & rn : aFormat) { rn = o3tl::toInt32(o3tl::getToken(aCode, 0, ',', nIndex)); @@ -242,6 +250,7 @@ void NumberFormatPropertyPanel::NotifyItemUpdate( bNegRed = static_cast<bool>(aFormat[1]); nPrecision = static_cast<sal_uInt16>(aFormat[2]); nLeadZeroes = static_cast<sal_uInt16>(aFormat[3]); + bNatNum12 = static_cast< bool >( aFormat[4] ); } else { @@ -250,6 +259,11 @@ void NumberFormatPropertyPanel::NotifyItemUpdate( nPrecision = 0; nLeadZeroes = 1; } + if ( nCategory == CAT_NUMBER || + nCategory == CAT_PERCENT || + nCategory == CAT_CURRENCY || + nCategory == CAT_FRACTION ) + mxBtnThousand->set_sensitive( !bNatNum12 ); if ( mxBtnThousand->get_visible() ) mxBtnThousand->set_active(bThousand); else if ( mxBtnEngineering->get_visible() ) diff --git a/sc/source/ui/view/formatsh.cxx b/sc/source/ui/view/formatsh.cxx index 9c35f3f1a4c3..cc3c7312942f 100644 --- a/sc/source/ui/view/formatsh.cxx +++ b/sc/source/ui/view/formatsh.cxx @@ -2519,6 +2519,7 @@ void ScFormatShell::GetNumFormatState( SfxItemSet& rSet ) const OUString sNegRed = OUString::number(static_cast<sal_Int32>(bNegRed)); const OUString sPrecision = OUString::number(nPrecision); const OUString sLeadZeroes = OUString::number(nLeadZeroes); + const OUString sNatNum12 = OUString::number( static_cast< sal_Int32 >( pFormatter->IsNatNum12( nNumberFormat ) ) ); aFormat += sThousand + sBreak + @@ -2527,6 +2528,8 @@ void ScFormatShell::GetNumFormatState( SfxItemSet& rSet ) sPrecision + sBreak + sLeadZeroes + + sBreak + + sNatNum12 + sBreak; rSet.Put(SfxStringItem(nWhich, aFormat)); diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx index ca8b6524b9e2..c85ae2ae838d 100644 --- a/svl/source/numbers/zforlist.cxx +++ b/svl/source/numbers/zforlist.cxx @@ -2257,6 +2257,13 @@ OUString SvNumberFormatter::GetLangDecimalSep( LanguageType nLang ) const return aRet; } +bool SvNumberFormatter::IsNatNum12( sal_uInt32 nFIndex ) const +{ + ::osl::MutexGuard aGuard( GetInstanceMutex() ); + const SvNumberformat* pFormat = GetFormatEntry( nFIndex ); + + return pFormat && pFormat->GetNatNumModifierString().startsWith( "[NatNum12" ); +} sal_uInt32 SvNumberFormatter::GetFormatSpecialInfo( const OUString& rFormatString, bool& bThousand, bool& IsRed, sal_uInt16& nPrecision, diff --git a/svx/source/items/numfmtsh.cxx b/svx/source/items/numfmtsh.cxx index 1aa58a32340a..8605817491ba 100644 --- a/svx/source/items/numfmtsh.cxx +++ b/svx/source/items/numfmtsh.cxx @@ -346,6 +346,13 @@ sal_uInt16 SvxNumberFormatShell::GetFormatIntegerDigits(std::u16string_view rFor return pFormatter->GetFormatIntegerDigits(nFmtKey); } +bool SvxNumberFormatShell::IsNatNum12(std::u16string_view rFormat) const +{ + sal_uInt32 nFmtKey = pFormatter->GetEntryKey(rFormat, eCurLanguage); + + return pFormatter->IsNatNum12(nFmtKey); +} + void SvxNumberFormatShell::GetOptions(const OUString& rFormat, bool& rThousand, bool& rNegRed, sal_uInt16& rPrecision, sal_uInt16& rLeadingZeroes, sal_uInt16& rCatLbPos)