summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2013-01-09 01:17:26 +0100
committerMichael Stahl <mstahl@redhat.com>2013-01-09 01:24:01 +0100
commit0cb7aa288537d8740f4781e0c38e4df7394888ab (patch)
tree21af1ab4bde1cbfe1ad37b794d6228126e464596
parentca3f80193d52e058170aa91ec21b61343ac07fbe (diff)
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 (cherry picked from commit 741e8b7b9d8e1a8f758edfe1c017801aa3d51247)
-rw-r--r--sw/inc/docufld.hxx16
-rw-r--r--sw/source/core/fields/docufld.cxx51
-rw-r--r--sw/source/core/text/txtfld.cxx5
3 files changed, 48 insertions, 24 deletions
diff --git a/sw/inc/docufld.hxx b/sw/inc/docufld.hxx
index d1ae27fbd7ee..0779b256dd69 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 cc0d853e0bb7..de0d3a841611 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 aaa7fe088494..ce50b44fc3f0 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);
}
{