diff options
author | Troy Rollo <libreoffice@troy.rollo.name> | 2011-07-11 23:02:20 +1000 |
---|---|---|
committer | Cédric Bosdonnat <cedric.bosdonnat.ooo@free.fr> | 2011-08-10 10:18:03 +0200 |
commit | 7e631b61607ddd821d9b3a688ff769bde45a4b2c (patch) | |
tree | 9974f10be42e6288740c4a36fb8865680c7c1f99 /sw | |
parent | 6615f2f65452aa9cfe869ee09f787361a9c8fa43 (diff) |
fdo#33960, Implement new rule for xref to numbered paragraphs
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/numrule.hxx | 10 | ||||
-rw-r--r-- | sw/source/core/doc/number.cxx | 56 |
2 files changed, 61 insertions, 5 deletions
diff --git a/sw/inc/numrule.hxx b/sw/inc/numrule.hxx index 35bc16818507..4401df3647f3 100644 --- a/sw/inc/numrule.hxx +++ b/sw/inc/numrule.hxx @@ -105,6 +105,13 @@ class SW_DLLPUBLIC SwNumRule public: typedef std::vector< SwTxtNode* > tTxtNodeList; typedef std::vector< SwTxtFmtColl* > tParagraphStyleList; + + struct Extremities + { + sal_uInt16 nPrefixChars; + sal_uInt16 nSuffixChars; + }; + private: friend void _FinitCore(); @@ -171,7 +178,8 @@ public: String MakeNumString( const SwNumberTree::tNumberVector & rNumVector, const sal_Bool bInclStrings = sal_True, const sal_Bool bOnlyArabic = sal_False, - const unsigned int _nRestrictToThisLevel = MAXLEVEL ) const; + const unsigned int _nRestrictToThisLevel = MAXLEVEL, + Extremities* pExtremities = 0 ) const; String MakeRefNumString( const SwNodeNum& rNodeNum, const bool bInclSuperiorNumLabels = false, const sal_uInt8 nRestrictInclToThisLevel = 0 ) const; diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx index b9f081884807..112ffd5bfbea 100644 --- a/sw/source/core/doc/number.cxx +++ b/sw/source/core/doc/number.cxx @@ -671,12 +671,16 @@ String SwNumRule::MakeNumString( const SwNodeNum& rNum, sal_Bool bInclStrings, String SwNumRule::MakeNumString( const SwNumberTree::tNumberVector & rNumVector, const sal_Bool bInclStrings, const sal_Bool bOnlyArabic, - const unsigned int _nRestrictToThisLevel ) const + const unsigned int _nRestrictToThisLevel, + SwNumRule::Extremities* pExtremities ) const { String aStr; unsigned int nLevel = rNumVector.size() - 1; + if ( pExtremities ) + pExtremities->nPrefixChars = pExtremities->nSuffixChars = 0; + if ( nLevel > _nRestrictToThisLevel ) { nLevel = _nRestrictToThisLevel; @@ -734,8 +738,16 @@ String SwNumRule::MakeNumString( const SwNumberTree::tNumberVector & rNumVector, SVX_NUM_CHAR_SPECIAL != rMyNFmt.GetNumberingType() && SVX_NUM_BITMAP != rMyNFmt.GetNumberingType() ) { - aStr.Insert( rMyNFmt.GetPrefix(), 0 ); - aStr += rMyNFmt.GetSuffix(); + String const &rPrefix = rMyNFmt.GetPrefix(); + String const &rSuffix = rMyNFmt.GetSuffix(); + + aStr.Insert( rPrefix, 0 ); + aStr += rSuffix; + if ( pExtremities ) + { + pExtremities->nPrefixChars = rPrefix.Len(); + pExtremities->nSuffixChars = rSuffix.Len(); + } } } } @@ -752,6 +764,8 @@ String SwNumRule::MakeRefNumString( const SwNodeNum& rNodeNum, if ( rNodeNum.GetLevelInListTree() >= 0 ) { + sal_Bool bOldHadPrefix = sal_True; + const SwNodeNum* pWorkingNodeNum( &rNodeNum ); do { @@ -768,11 +782,45 @@ String SwNumRule::MakeRefNumString( const SwNodeNum& rNodeNum, pWorkingNodeNum->GetTxtNode() && pWorkingNodeNum->GetTxtNode()->HasNumber() ) ) { - aRefNumStr.Insert( MakeNumString( pWorkingNodeNum->GetNumberVector() ), 0 ); + Extremities aExtremities; + String aPrevStr = MakeNumString( pWorkingNodeNum->GetNumberVector(), + sal_True, sal_False, MAXLEVEL, + &aExtremities); + int nLen = aPrevStr.Len(); + int nStrip = 0; + sal_Unicode c; + + + while ( nStrip < aExtremities.nPrefixChars && + ( '\t' == ( c = aPrevStr.GetChar( nStrip ) ) || + ' ' == c) ) + { + ++nStrip; + } + + if (nStrip) + { + aPrevStr.Erase( 0, nStrip ); + aExtremities.nPrefixChars -= nStrip; + nLen -= nStrip; + } + + if ( bOldHadPrefix && + aExtremities.nSuffixChars && + !aExtremities.nPrefixChars + ) + { + aPrevStr.Erase( nLen - aExtremities.nSuffixChars, aExtremities.nSuffixChars ); + } + bOldHadPrefix = ( aExtremities.nPrefixChars > 0); + + aRefNumStr.Insert( aPrevStr, 0 ); + } else if ( aRefNumStr.Len() > 0 ) { aRefNumStr.Insert( String::CreateFromAscii(" "), 0 ); + bOldHadPrefix = true; } if ( bInclSuperiorNumLabels && pWorkingNodeNum->GetLevelInListTree() > 0 ) |