diff options
-rw-r--r-- | include/svl/zforlist.hxx | 4 | ||||
-rw-r--r-- | svl/source/numbers/zforlist.cxx | 2 | ||||
-rw-r--r-- | sw/inc/cellatr.hxx | 8 | ||||
-rw-r--r-- | sw/source/core/attr/cellatr.cxx | 11 | ||||
-rw-r--r-- | sw/source/core/doc/docsort.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/edit/edtab.cxx | 3 | ||||
-rw-r--r-- | sw/source/core/fields/cellfml.cxx | 5 | ||||
-rw-r--r-- | sw/source/core/table/swtable.cxx | 17 | ||||
-rw-r--r-- | sw/source/core/undo/untbl.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/unocore/unotbl.cxx | 6 | ||||
-rw-r--r-- | sw/source/filter/xml/xmlfmte.cxx | 2 | ||||
-rw-r--r-- | sw/source/filter/xml/xmltble.cxx | 2 |
12 files changed, 42 insertions, 24 deletions
diff --git a/include/svl/zforlist.hxx b/include/svl/zforlist.hxx index 3e59064281c2..5b84d0078408 100644 --- a/include/svl/zforlist.hxx +++ b/include/svl/zforlist.hxx @@ -54,6 +54,10 @@ namespace com { namespace sun { namespace star { #define SV_COUNTRY_LANGUAGE_OFFSET 10000 // Max count of formats per country/language #define SV_MAX_COUNT_STANDARD_FORMATS 100 // Max count of builtin default formats per CL +/// The built-in @ Text format, offset within a locale, key in the locale the +/// number formatter was constructed with. +constexpr sal_uInt32 NF_STANDARD_FORMAT_TEXT = SV_MAX_COUNT_STANDARD_FORMATS; + #define NUMBERFORMAT_ENTRY_NOT_FOUND (sal_uInt32)(0xffffffff) /// MAX_ULONG diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx index a6e7af89562f..bfa23d2f5f58 100644 --- a/svl/source/numbers/zforlist.cxx +++ b/svl/source/numbers/zforlist.cxx @@ -86,6 +86,8 @@ using namespace ::std; #define ZF_STANDARD_LOGICAL SV_MAX_COUNT_STANDARD_FORMATS-1 // 99 #define ZF_STANDARD_TEXT SV_MAX_COUNT_STANDARD_FORMATS // 100 +static_assert( ZF_STANDARD_TEXT == NF_STANDARD_FORMAT_TEXT, "definition mismatch" ); + /* Locale that is set if an unknown locale (from another system) is loaded of * legacy documents. Can not be SYSTEM because else, for example, a German "DM" * (old currency) is recognized as a date (#53155#). */ diff --git a/sw/inc/cellatr.hxx b/sw/inc/cellatr.hxx index 2dfb8c193b87..30027fc64c77 100644 --- a/sw/inc/cellatr.hxx +++ b/sw/inc/cellatr.hxx @@ -28,11 +28,17 @@ namespace rtl { class OUString; } +/** The number formatter's default locale's @ Text format. + Not necessarily system locale, but the locale the formatter was constructed + with. For this SvNumberFormatter::IsTextFormat() always returns true. + */ +constexpr sal_uInt32 getSwDefaultTextFormat() { return NF_STANDARD_FORMAT_TEXT; } + class SW_DLLPUBLIC SwTableBoxNumFormat : public SfxUInt32Item { bool m_bAuto; ///< automatically given flag public: - SwTableBoxNumFormat( sal_uInt32 nFormat = css::util::NumberFormat::TEXT, + SwTableBoxNumFormat( sal_uInt32 nFormat = getSwDefaultTextFormat(), bool bAuto = false ); // "pure virtual methods" of SfxPoolItem diff --git a/sw/source/core/attr/cellatr.cxx b/sw/source/core/attr/cellatr.cxx index e8ec2c59a049..abc80746442d 100644 --- a/sw/source/core/attr/cellatr.cxx +++ b/sw/source/core/attr/cellatr.cxx @@ -31,8 +31,17 @@ #include <calbck.hxx> #include <swtable.hxx> +// The % SV_COUNTRY_LANGUAGE_OFFSET result checks if nFormat is a mere built-in +// @ Text format of *any* locale and if so uses the default text format. Text +// is text, the locale doesn't matter for Writer's number formatting purposes. +// The advantage is that this is the pool's default item value and some places +// benefit from this special treatment in that they don't have to handle/store +// attribute specifics, especially when writing a document. SwTableBoxNumFormat::SwTableBoxNumFormat( sal_uInt32 nFormat, bool bFlag ) - : SfxUInt32Item( RES_BOXATR_FORMAT, nFormat ), m_bAuto( bFlag ) + : SfxUInt32Item( RES_BOXATR_FORMAT, + (((nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == getSwDefaultTextFormat()) ? + getSwDefaultTextFormat() : nFormat)) + , m_bAuto( bFlag ) { } diff --git a/sw/source/core/doc/docsort.cxx b/sw/source/core/doc/docsort.cxx index cd146f81dc61..3aa5fa635e20 100644 --- a/sw/source/core/doc/docsort.cxx +++ b/sw/source/core/doc/docsort.cxx @@ -277,7 +277,7 @@ double SwSortBoxElement::GetValue( sal_uInt16 nKey ) const if( pFndBox ) { const SwFormat *pFormat = pFndBox->GetBox()->GetFrameFormat(); - if (pFormat->GetTableBoxNumFormat().GetValue() & css::util::NumberFormat::TEXT) + if (pDoc->GetNumberFormatter()->IsTextFormat( pFormat->GetTableBoxNumFormat().GetValue())) nVal = SwSortElement::GetValue( nKey ); else nVal = pFormat->GetTableBoxValue().GetValue(); diff --git a/sw/source/core/edit/edtab.cxx b/sw/source/core/edit/edtab.cxx index af961388cba9..83f91423c1e0 100644 --- a/sw/source/core/edit/edtab.cxx +++ b/sw/source/core/edit/edtab.cxx @@ -387,8 +387,7 @@ bool SwEditShell::IsTableBoxTextFormat() const RES_BOXATR_FORMAT, true, &pItem )) { nFormat = static_cast<const SwTableBoxNumFormat*>(pItem)->GetValue(); - return GetDoc()->GetNumberFormatter()->IsTextFormat( nFormat ) || - static_cast<sal_uInt32>(css::util::NumberFormat::TEXT) == nFormat; + return GetDoc()->GetNumberFormatter()->IsTextFormat( nFormat ); } sal_uLong nNd = pBox->IsValidNumTextNd(); diff --git a/sw/source/core/fields/cellfml.cxx b/sw/source/core/fields/cellfml.cxx index 87d757cd6f69..6582cd77e2de 100644 --- a/sw/source/core/fields/cellfml.cxx +++ b/sw/source/core/fields/cellfml.cxx @@ -217,11 +217,12 @@ double SwTableBox::GetValue( SwTableCalcPara& rCalcPara ) const SvNumberFormatter* pNumFormatr = pDoc->GetNumberFormatter(); - if( static_cast<sal_uInt32>(css::util::NumberFormat::TEXT) == nFormatIndex ) + const sal_Int16 nFormatType = pNumFormatr->GetType( nFormatIndex ); + if( nFormatType == css::util::NumberFormat::TEXT ) nFormatIndex = 0; // JP 22.04.98: Bug 49659 - special treatment for percentages else if( !sText.isEmpty() && - css::util::NumberFormat::PERCENT == pNumFormatr->GetType( nFormatIndex )) + css::util::NumberFormat::PERCENT == nFormatType) { sal_uInt32 nTmpFormat = 0; if( pDoc->IsNumberFormat( sText, nTmpFormat, aNum ) && diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx index dc3c749fd802..00702490bc31 100644 --- a/sw/source/core/table/swtable.cxx +++ b/sw/source/core/table/swtable.cxx @@ -2091,7 +2091,7 @@ void ChgNumToText( SwTableBox& rBox, sal_uLong nFormat ) const SfxPoolItem* pItem; Color* pCol = nullptr; - if( css::util::NumberFormat::TEXT != static_cast<sal_Int16>(nFormat) ) + if( getSwDefaultTextFormat() != nFormat ) { // special text format: OUString sTmp; @@ -2175,7 +2175,7 @@ void SwTableBoxFormat::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew const SwTableBoxNumFormat *pNewFormat = nullptr; const SwTableBoxFormula *pNewFormula = nullptr; const SwTableBoxValue *pNewVal = nullptr; - sal_uLong nOldFormat = css::util::NumberFormat::TEXT; + sal_uLong nOldFormat = getSwDefaultTextFormat(); switch( pNew ? pNew->Which() : 0 ) { @@ -2241,15 +2241,15 @@ void SwTableBoxFormat::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew // is it newer or has the current been removed? if( pNewVal ) { - if( css::util::NumberFormat::TEXT != static_cast<sal_Int16>(nNewFormat) ) + if( GetDoc()->GetNumberFormatter()->IsTextFormat(nNewFormat) ) + nOldFormat = 0; + else { if( SfxItemState::SET == GetItemState( RES_BOXATR_VALUE, false )) - nOldFormat = css::util::NumberFormat::TEXT; + nOldFormat = getSwDefaultTextFormat(); else - nNewFormat = css::util::NumberFormat::TEXT; + nNewFormat = getSwDefaultTextFormat(); } - else if( css::util::NumberFormat::TEXT == static_cast<sal_Int16>(nNewFormat) ) - nOldFormat = 0; } // Logic: @@ -2263,8 +2263,7 @@ void SwTableBoxFormat::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew // - align left for horizontal alignment, if RIGHT // - align top for vertical alignment, if BOTTOM is set SvNumberFormatter* pNumFormatr = GetDoc()->GetNumberFormatter(); - bool bNewIsTextFormat = pNumFormatr->IsTextFormat( nNewFormat ) || - css::util::NumberFormat::TEXT == static_cast<sal_Int16>(nNewFormat); + bool bNewIsTextFormat = pNumFormatr->IsTextFormat( nNewFormat ); if( (!bNewIsTextFormat && nOldFormat != nNewFormat) || pNewFormula ) { diff --git a/sw/source/core/undo/untbl.cxx b/sw/source/core/undo/untbl.cxx index 250dde4d6c03..6cd5e2bb3b67 100644 --- a/sw/source/core/undo/untbl.cxx +++ b/sw/source/core/undo/untbl.cxx @@ -2143,7 +2143,7 @@ SwUndoTableNumFormat::SwUndoTableNumFormat( const SwTableBox& rBox, : SwUndo(SwUndoId::TBLNUMFMT, rBox.GetFrameFormat()->GetDoc()) , m_pBoxSet(nullptr) , m_pHistory(nullptr) - , m_nFormatIdx(css::util::NumberFormat::TEXT) + , m_nFormatIdx(getSwDefaultTextFormat()) , m_nNewFormatIdx(0) , m_fNum(0.0) , m_fNewNum(0.0) @@ -2352,7 +2352,7 @@ void SwUndoTableNumFormat::RedoImpl(::sw::UndoRedoContext & rContext) RedlineFlagsInternGuard aGuard( rDoc, RedlineFlags::NONE, RedlineFlags::Ignore ); pBoxFormat->SetFormatAttr( aBoxSet ); } - else if( css::util::NumberFormat::TEXT != static_cast<sal_Int16>(m_nFormatIdx) ) + else if( getSwDefaultTextFormat() != m_nFormatIdx ) { SfxItemSet aBoxSet( rDoc.GetAttrPool(), svl::Items<RES_BOXATR_FORMAT, RES_BOXATR_VALUE>{} ); diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx index de6adc6a2130..cd722ea0f880 100644 --- a/sw/source/core/unocore/unotbl.cxx +++ b/sw/source/core/unocore/unotbl.cxx @@ -711,7 +711,7 @@ void sw_setString( SwXCell &rCell, const OUString &rText, pBoxFormat->ResetFormatAttr( RES_BOXATR_FORMULA ); pBoxFormat->ResetFormatAttr( RES_BOXATR_VALUE ); if (!bKeepNumberFormat) - pBoxFormat->SetFormatAttr( SwTableBoxNumFormat(css::util::NumberFormat::TEXT) ); + pBoxFormat->SetFormatAttr( SwTableBoxNumFormat(/*default Text*/) ); pBoxFormat->UnlockModify(); } rCell.SwXText::setString(rText); @@ -736,10 +736,8 @@ void sw_setValue( SwXCell &rCell, double nVal ) //!! do we need to set a new number format? Yes, if // - there is no current number format // - the current number format is not a number format according to the number formatter, but rather a text format - // - the current number format is not even a valid number formatter number format, but rather Writer's own 'special' text number format if(SfxItemState::SET != pBoxFormat->GetAttrSet().GetItemState(RES_BOXATR_FORMAT, true, &pItem) - || pDoc->GetNumberFormatter()->IsTextFormat(static_cast<const SwTableBoxNumFormat*>(pItem)->GetValue()) - || static_cast<sal_Int16>(static_cast<const SwTableBoxNumFormat*>(pItem)->GetValue()) == css::util::NumberFormat::TEXT) + || pDoc->GetNumberFormatter()->IsTextFormat(static_cast<const SwTableBoxNumFormat*>(pItem)->GetValue())) { aSet.Put(SwTableBoxNumFormat(0)); } diff --git a/sw/source/filter/xml/xmlfmte.cxx b/sw/source/filter/xml/xmlfmte.cxx index deb42e5cdcc5..ec079e903807 100644 --- a/sw/source/filter/xml/xmlfmte.cxx +++ b/sw/source/filter/xml/xmlfmte.cxx @@ -109,7 +109,7 @@ void SwXMLExport::ExportFormat( const SwFormat& rFormat, enum XMLTokenEnum eFami sal_Int32 nFormat = (sal_Int32) static_cast<const SwTableBoxNumFormat *>(pItem)->GetValue(); - if ( (nFormat != -1) && (nFormat != css::util::NumberFormat::TEXT) ) + if ( (nFormat != -1) && (nFormat != static_cast<sal_Int32>(getSwDefaultTextFormat())) ) { // if we have a format, register and then export // (Careful: here we assume that data styles will be diff --git a/sw/source/filter/xml/xmltble.cxx b/sw/source/filter/xml/xmltble.cxx index 775bc175eaab..d68d5e06148a 100644 --- a/sw/source/filter/xml/xmltble.cxx +++ b/sw/source/filter/xml/xmltble.cxx @@ -822,7 +822,7 @@ void SwXMLExport::ExportTableBox( const SwTableBox& rBox, Any aAny = xCellPropertySet->getPropertyValue("NumberFormat"); aAny >>= nNumberFormat; - if (css::util::NumberFormat::TEXT == nNumberFormat) + if (static_cast<sal_Int32>(getSwDefaultTextFormat()) == nNumberFormat) { // text format AddAttribute( XML_NAMESPACE_OFFICE, |