sw/inc/docufld.hxx | 16 ++++++++--- sw/source/core/fields/docufld.cxx | 51 +++++++++++++++++++++++-------------- sw/source/core/text/txtfld.cxx | 5 ++- sw/source/filter/ww8/rtfexport.cxx | 2 - 4 files changed, 49 insertions(+), 25 deletions(-)
New commits: commit 741e8b7b9d8e1a8f758edfe1c017801aa3d51247 Author: Michael Stahl <mst...@redhat.com> Date: Wed Jan 9 01:17:26 2013 +0100 fdo#58074: store page number in SwPageNumberField Should hopefully fix the problem, which is essentially that all SwPageNumberFields share a single SwPageNumberFieldType, which is only updated properly in SwTxtFormatter::NewFldPortion, hence all expansions of a SwPageNumberField other than that return wrong values. Does not fix the problem for fields in headers though, which appears much harder... Change-Id: Iecf363c8acbc2aaa418cc0c980e0b62c8e0e7d14 diff --git a/sw/inc/docufld.hxx b/sw/inc/docufld.hxx index d1ae27f..0779b25 100644 --- a/sw/inc/docufld.hxx +++ b/sw/inc/docufld.hxx @@ -142,14 +142,14 @@ enum SwJumpEditFormat class SwPageNumberFieldType : public SwFieldType { sal_Int16 nNumberingType; - sal_uInt16 nNum, nMax; bool bVirtuell; public: SwPageNumberFieldType(); - String& Expand( sal_uInt32 nFmt, short nOff, const String&, String& rRet ) const; - void ChangeExpansion( SwDoc* pDoc, sal_uInt16 nNum, sal_uInt16 nMax, + String& Expand( sal_uInt32 nFmt, short nOff, sal_uInt16 const nPageNumber, + sal_uInt16 const nMaxPage, const String&, String& rRet ) const; + void ChangeExpansion( SwDoc* pDoc, sal_Bool bVirtPageNum, const sal_Int16* pNumFmt = 0 ); virtual SwFieldType* Copy() const; }; @@ -163,10 +163,18 @@ class SW_DLLPUBLIC SwPageNumberField : public SwField String sUserStr; sal_uInt16 nSubType; short nOffset; + // fdo#58074 store page number in SwField, not SwFieldType + sal_uInt16 m_nPageNumber; + sal_uInt16 m_nMaxPage; public: SwPageNumberField(SwPageNumberFieldType*, sal_uInt16 nSub = PG_RANDOM, - sal_uInt32 nFmt = 0, short nOff = 0); + sal_uInt32 nFmt = 0, short nOff = 0, + sal_uInt16 const nPageNumber = 0, + sal_uInt16 const nMaxPage = 0); + + void ChangeExpansion(sal_uInt16 const nPageNumber, + sal_uInt16 const nMaxPage); virtual String Expand() const; virtual SwField* Copy() const; diff --git a/sw/source/core/fields/docufld.cxx b/sw/source/core/fields/docufld.cxx index cc0d853..de0d3a8 100644 --- a/sw/source/core/fields/docufld.cxx +++ b/sw/source/core/fields/docufld.cxx @@ -107,19 +107,18 @@ using namespace nsSwDocInfoSubType; SwPageNumberFieldType::SwPageNumberFieldType() : SwFieldType( RES_PAGENUMBERFLD ), nNumberingType( SVX_NUM_ARABIC ), - nNum( 0 ), - nMax( USHRT_MAX ), bVirtuell( false ) { } String& SwPageNumberFieldType::Expand( sal_uInt32 nFmt, short nOff, + sal_uInt16 const nPageNumber, sal_uInt16 const nMaxPage, const String& rUserStr, String& rRet ) const { sal_uInt32 nTmpFmt = (SVX_NUM_PAGEDESC == nFmt) ? (sal_uInt32)nNumberingType : nFmt; - long nTmp = nNum + nOff; + int const nTmp = nPageNumber + nOff; - if( 0 >= nTmp || SVX_NUM_NUMBER_NONE == nTmpFmt || (!bVirtuell && nTmp > nMax) ) + if (0 >= nTmp || SVX_NUM_NUMBER_NONE == nTmpFmt || (!bVirtuell && nTmp > nMaxPage)) rRet = aEmptyStr; else if( SVX_NUM_CHAR_SPECIAL == nTmpFmt ) rRet = rUserStr; @@ -132,8 +131,6 @@ SwFieldType* SwPageNumberFieldType::Copy() const { SwPageNumberFieldType *pTmp = new SwPageNumberFieldType(); - pTmp->nNum = nNum; - pTmp->nMax = nMax; pTmp->nNumberingType = nNumberingType; pTmp->bVirtuell = bVirtuell; @@ -144,12 +141,10 @@ SwFieldType* SwPageNumberFieldType::Copy() const Beschreibung: Verschiedene Expandierung --------------------------------------------------------------------*/ -void SwPageNumberFieldType::ChangeExpansion( SwDoc* pDoc, sal_uInt16 nPage, - sal_uInt16 nNumPages, sal_Bool bVirt, +void SwPageNumberFieldType::ChangeExpansion( SwDoc* pDoc, + sal_Bool bVirt, const sal_Int16* pNumFmt ) { - nNum = nPage; - nMax = nNumPages; if( pNumFmt ) nNumberingType = *pNumFmt; @@ -186,11 +181,21 @@ void SwPageNumberFieldType::ChangeExpansion( SwDoc* pDoc, sal_uInt16 nPage, --------------------------------------------------------------------*/ SwPageNumberField::SwPageNumberField(SwPageNumberFieldType* pTyp, - sal_uInt16 nSub, sal_uInt32 nFmt, short nOff) + sal_uInt16 nSub, sal_uInt32 nFmt, short nOff, + sal_uInt16 const nPageNumber, sal_uInt16 const nMaxPage) : SwField(pTyp, nFmt), nSubType(nSub), nOffset(nOff) + , m_nPageNumber(nPageNumber) + , m_nMaxPage(nMaxPage) { } +void SwPageNumberField::ChangeExpansion(sal_uInt16 const nPageNumber, + sal_uInt16 const nMaxPage) +{ + m_nPageNumber = nPageNumber; + m_nMaxPage = nMaxPage; +} + String SwPageNumberField::Expand() const { String sRet; @@ -198,23 +203,33 @@ String SwPageNumberField::Expand() const if( PG_NEXT == nSubType && 1 != nOffset ) { - if( pFldType->Expand( GetFormat(), 1, sUserStr, sRet ).Len() ) - pFldType->Expand( GetFormat(), nOffset, sUserStr, sRet ); + if (pFldType->Expand(GetFormat(), 1, m_nPageNumber, m_nMaxPage, + sUserStr, sRet).Len()) + { + pFldType->Expand(GetFormat(), nOffset, m_nPageNumber, m_nMaxPage, + sUserStr, sRet); + } } else if( PG_PREV == nSubType && -1 != nOffset ) { - if( pFldType->Expand( GetFormat(), -1, sUserStr, sRet ).Len() ) - pFldType->Expand( GetFormat(), nOffset, sUserStr, sRet ); + if (pFldType->Expand(GetFormat(), -1, m_nPageNumber, m_nMaxPage, + sUserStr, sRet).Len()) + { + pFldType->Expand(GetFormat(), nOffset, m_nPageNumber, m_nMaxPage, + sUserStr, sRet); + } } else - pFldType->Expand( GetFormat(), nOffset, sUserStr, sRet ); + pFldType->Expand(GetFormat(), nOffset, m_nPageNumber, m_nMaxPage, + sUserStr, sRet); return sRet; } SwField* SwPageNumberField::Copy() const { - SwPageNumberField *pTmp = - new SwPageNumberField((SwPageNumberFieldType*)GetTyp(), nSubType, GetFormat(), nOffset); + SwPageNumberField *pTmp = new SwPageNumberField( + static_cast<SwPageNumberFieldType*>(GetTyp()), nSubType, + GetFormat(), nOffset, m_nPageNumber, m_nMaxPage); pTmp->SetLanguage( GetLanguage() ); pTmp->SetUserString( sUserStr ); return pTmp; diff --git a/sw/source/core/text/txtfld.cxx b/sw/source/core/text/txtfld.cxx index aaa7fe0..ce50b44 100644 --- a/sw/source/core/text/txtfld.cxx +++ b/sw/source/core/text/txtfld.cxx @@ -169,8 +169,9 @@ SwExpandPortion *SwTxtFormatter::NewFldPortion( SwTxtFormatInfo &rInf, sal_Int16 nNumFmt = -1; if(SVX_NUM_PAGEDESC == pFld->GetFormat()) nNumFmt = pFrame->FindPageFrm()->GetPageDesc()->GetNumType().GetNumberingType(); - - pPageNr->ChangeExpansion( pDoc, nVirtNum, nNumPages, + static_cast<SwPageNumberField*>(pFld) + ->ChangeExpansion(nVirtNum, nNumPages); + pPageNr->ChangeExpansion(pDoc, bVirt, nNumFmt > -1 ? &nNumFmt : 0); } { commit 9669d2bdea00b86874831d0c2555e7f85f2ca209 Author: Michael Stahl <mst...@redhat.com> Date: Wed Jan 9 01:12:46 2013 +0100 that ExpandField looks like it wants cache only Change-Id: I3991d2f40fab9795d7f1754665f2ebfa165c310c diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx index a9e6c5d..9b01126 100644 --- a/sw/source/filter/ww8/rtfexport.cxx +++ b/sw/source/filter/ww8/rtfexport.cxx @@ -325,7 +325,7 @@ void RtfExport::DoFormText(const SwInputField* pFld ) { SAL_INFO("sw.rtf", OSL_THIS_FUNC); - ::rtl::OUString sResult = pFld->ExpandField(pDoc->IsClipBoard()); + ::rtl::OUString sResult = pFld->ExpandField(true); ::rtl::OUString sHelp( pFld->GetHelp() ); ::rtl::OUString sName = pFld->GetPar2(); ::rtl::OUString sStatus = pFld->GetToolTip(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits