diff options
author | Michael Stahl <Michael.Stahl@cib.de> | 2018-11-07 16:14:19 +0100 |
---|---|---|
committer | Michael Stahl <Michael.Stahl@cib.de> | 2018-11-15 15:10:06 +0100 |
commit | 43a7231c96b5d132e8cc349553ff6efaba9d5ed0 (patch) | |
tree | 0c276f06148863cc9a0d894e287bb2ab65802fd0 /sw | |
parent | a25e7ac89e456f57f2b9701b04b7a4733aaf6f57 (diff) |
sw_redlinehide_3: add second result to SwChapterField
Now it can store both the result for Show as well as for Hide mode.
Change-Id: I15a14b76a96ef77683cd63039b1a8f5e1e94e4c9
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/chpfld.hxx | 31 | ||||
-rw-r--r-- | sw/qa/core/test_ToxTextGenerator.cxx | 16 | ||||
-rw-r--r-- | sw/source/core/fields/chpfld.cxx | 90 | ||||
-rw-r--r-- | sw/source/ui/fldui/flddok.cxx | 2 |
4 files changed, 85 insertions, 54 deletions
diff --git a/sw/inc/chpfld.hxx b/sw/inc/chpfld.hxx index 1b85246fba11..85b896f0c042 100644 --- a/sw/inc/chpfld.hxx +++ b/sw/inc/chpfld.hxx @@ -49,11 +49,18 @@ class SW_DLLPUBLIC SwChapterField : public SwField { friend class SwChapterFieldType; friend class ToxTextGeneratorTest; // the unittest needs to mock the chapter fields. - sal_uInt8 m_nLevel; - OUString m_sTitle; - OUString m_sNumber; - OUString m_sPre; - OUString m_sPost; + + struct State + { + sal_uInt8 nLevel; + OUString sTitle; + OUString sNumber; + OUString sPre; + OUString sPost; + State() : nLevel(0) {} + }; + State m_State; + State m_StateRLHidden; virtual OUString Expand() const override; virtual std::unique_ptr<SwField> Copy() const override; @@ -67,20 +74,16 @@ public: bool bSrchNum = false); void ChangeExpansion(const SwTextNode &rNd, bool bSrchNum, SwRootFrame const* pLayout = nullptr); - inline sal_uInt8 GetLevel() const; - inline void SetLevel(sal_uInt8); + sal_uInt8 GetLevel(SwRootFrame const* pLayout = nullptr) const; + void SetLevel(sal_uInt8); + + const OUString& GetNumber(SwRootFrame const* pLayout = nullptr) const; + const OUString& GetTitle(SwRootFrame const* pLayout = nullptr) const; - inline const OUString& GetNumber() const; - inline const OUString& GetTitle() const; virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override; virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override; }; -inline sal_uInt8 SwChapterField::GetLevel() const { return m_nLevel; } -inline void SwChapterField::SetLevel(sal_uInt8 nLev) { m_nLevel = nLev; } -inline const OUString& SwChapterField::GetNumber() const { return m_sNumber; } -inline const OUString& SwChapterField::GetTitle() const { return m_sTitle; } - #endif // INCLUDED_SW_INC_CHPFLD_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/core/test_ToxTextGenerator.cxx b/sw/qa/core/test_ToxTextGenerator.cxx index 5bd25a844665..3ddc9fef6f80 100644 --- a/sw/qa/core/test_ToxTextGenerator.cxx +++ b/sw/qa/core/test_ToxTextGenerator.cxx @@ -141,10 +141,10 @@ ToxTextGeneratorTest::ChapterNumberWithoutTextIsGeneratedForNoprepstTitle() SwForm form; ToxTextGeneratorWithMockedChapterField ttg(form); // set all values to make sure they are not used - ttg.GetChapterField().sNumber = "1"; - ttg.GetChapterField().sPre = "PRE"; - ttg.GetChapterField().sPost = "POST"; - ttg.GetChapterField().sTitle = "TITLE"; + ttg.GetChapterField().m_State.sNumber = "1"; + ttg.GetChapterField().m_State.sPre = "PRE"; + ttg.GetChapterField().m_State.sPost = "POST"; + ttg.GetChapterField().m_State.sTitle = "TITLE"; SwFormToken token(TOKEN_CHAPTER_INFO); token.nChapterFormat = CF_NUM_NOPREPST_TITLE; @@ -167,10 +167,10 @@ ToxTextGeneratorTest::ChapterNumberWithTitleIsGeneratedForNumberNoPrepst() SwForm form; ToxTextGeneratorWithMockedChapterField ttg(form); // set all values to make sure they are not used - ttg.GetChapterField().sNumber = "5"; - ttg.GetChapterField().sPre = "PRE"; - ttg.GetChapterField().sPost = "POST"; - ttg.GetChapterField().sTitle = "myTitle"; + ttg.GetChapterField().m_State.sNumber = "5"; + ttg.GetChapterField().m_State.sPre = "PRE"; + ttg.GetChapterField().m_State.sPost = "POST"; + ttg.GetChapterField().m_State.sTitle = "myTitle"; SwFormToken token(TOKEN_CHAPTER_INFO); token.nChapterFormat = CF_NUMBER_NOPREPST; diff --git a/sw/source/core/fields/chpfld.cxx b/sw/source/core/fields/chpfld.cxx index 0702ca92d379..4502f783d179 100644 --- a/sw/source/core/fields/chpfld.cxx +++ b/sw/source/core/fields/chpfld.cxx @@ -20,6 +20,7 @@ #include <com/sun/star/text/ChapterFormat.hpp> #include <doc.hxx> #include <frame.hxx> +#include <rootfrm.hxx> #include <txtfrm.hxx> #include <pam.hxx> #include <ndtxt.hxx> @@ -66,35 +67,58 @@ SwFieldType* SwChapterFieldType::Copy() const SwChapterField::SwChapterField(SwChapterFieldType* pTyp, sal_uInt32 nFormat) : SwField(pTyp, nFormat) - , m_nLevel(0) -{} +{ +} + +sal_uInt8 SwChapterField::GetLevel(SwRootFrame const*const pLayout) const +{ + State const& rState(pLayout && pLayout->IsHideRedlines() ? m_StateRLHidden : m_State); + return rState.nLevel; +} + +// this is called from UI or from import filters, so override both states +void SwChapterField::SetLevel(sal_uInt8 nLev) +{ + m_State.nLevel = nLev; + m_StateRLHidden.nLevel = nLev; +} + +const OUString& SwChapterField::GetNumber(SwRootFrame const*const pLayout) const +{ + State const& rState(pLayout && pLayout->IsHideRedlines() ? m_StateRLHidden : m_State); + return rState.sNumber; +} + +const OUString& SwChapterField::GetTitle(SwRootFrame const*const pLayout) const +{ + State const& rState(pLayout && pLayout->IsHideRedlines() ? m_StateRLHidden : m_State); + return rState.sTitle; +} OUString SwChapterField::Expand() const { + State const& rState(m_State); switch( GetFormat() ) { case CF_TITLE: - return m_sTitle; + return rState.sTitle; case CF_NUMBER: - return m_sPre + m_sNumber + m_sPost; + return rState.sPre + rState.sNumber + rState.sPost; case CF_NUM_TITLE: - return m_sPre + m_sNumber + m_sPost + m_sTitle; + return rState.sPre + rState.sNumber + rState.sPost + rState.sTitle; case CF_NUM_NOPREPST_TITLE: - return m_sNumber + m_sTitle; + return rState.sNumber + rState.sTitle; } // CF_NUMBER_NOPREPST - return m_sNumber; + return rState.sNumber; } std::unique_ptr<SwField> SwChapterField::Copy() const { std::unique_ptr<SwChapterField> pTmp( new SwChapterField(static_cast<SwChapterFieldType*>(GetTyp()), GetFormat())); - pTmp->m_nLevel = m_nLevel; - pTmp->m_sTitle = m_sTitle; - pTmp->m_sNumber = m_sNumber; - pTmp->m_sPost = m_sPost; - pTmp->m_sPre = m_sPre; + pTmp->m_State = m_State; + pTmp->m_StateRLHidden = m_StateRLHidden; return std::unique_ptr<SwField>(pTmp.release()); } @@ -122,13 +146,14 @@ void SwChapterField::ChangeExpansion(const SwFrame & rFrame, void SwChapterField::ChangeExpansion(const SwTextNode &rTextNd, bool bSrchNum, SwRootFrame const*const pLayout) { - m_sNumber.clear(); - m_sTitle.clear(); - m_sPost.clear(); - m_sPre.clear(); + State & rState(pLayout && pLayout->IsHideRedlines() ? m_StateRLHidden : m_State); + rState.sNumber.clear(); + rState.sTitle.clear(); + rState.sPost.clear(); + rState.sPre.clear(); SwDoc* pDoc = const_cast<SwDoc*>(rTextNd.GetDoc()); - const SwTextNode *pTextNd = rTextNd.FindOutlineNodeOfLevel(m_nLevel, pLayout); + const SwTextNode *pTextNd = rTextNd.FindOutlineNodeOfLevel(rState.nLevel, pLayout); if( pTextNd ) { if( bSrchNum ) @@ -137,24 +162,24 @@ void SwChapterField::ChangeExpansion(const SwTextNode &rTextNd, bool bSrchNum, do { if( pONd && pONd->GetTextColl() ) { - sal_uInt8 nPrevLvl = m_nLevel; + sal_uInt8 nPrevLvl = rState.nLevel; OSL_ENSURE( pONd->GetAttrOutlineLevel() >= 0 && pONd->GetAttrOutlineLevel() <= MAXLEVEL, "<SwChapterField::ChangeExpansion(..)> - outline node with inconsistent outline level. Serious defect." ); - m_nLevel = static_cast<sal_uInt8>(pONd->GetAttrOutlineLevel()); + rState.nLevel = static_cast<sal_uInt8>(pONd->GetAttrOutlineLevel()); - if (nPrevLvl < m_nLevel) - m_nLevel = nPrevLvl; + if (nPrevLvl < rState.nLevel) + rState.nLevel = nPrevLvl; else if( SVX_NUM_NUMBER_NONE != pDoc->GetOutlineNumRule() - ->Get( m_nLevel ).GetNumberingType() ) + ->Get( rState.nLevel ).GetNumberingType() ) { pTextNd = pONd; break; } - if (!m_nLevel--) + if (!rState.nLevel--) break; - pONd = pTextNd->FindOutlineNodeOfLevel(m_nLevel, pLayout); + pONd = pTextNd->FindOutlineNodeOfLevel(rState.nLevel, pLayout); } else break; @@ -168,7 +193,7 @@ void SwChapterField::ChangeExpansion(const SwTextNode &rTextNd, bool bSrchNum, // correction of refactoring done by cws swnumtree: // retrieve numbering string without prefix and suffix strings // as stated in the above german comment. - m_sNumber = pTextNd->GetNumString(false, MAXLEVEL, pLayout); + rState.sNumber = pTextNd->GetNumString(false, MAXLEVEL, pLayout); SwNumRule* pRule( pTextNd->GetNumRule() ); if ( pTextNd->IsCountedInList() && pRule ) @@ -180,16 +205,16 @@ void SwChapterField::ChangeExpansion(const SwTextNode &rTextNd, bool bSrchNum, nListLevel = MAXLEVEL - 1; const SwNumFormat& rNFormat = pRule->Get(nListLevel); - m_sPost = rNFormat.GetSuffix(); - m_sPre = rNFormat.GetPrefix(); + rState.sPost = rNFormat.GetSuffix(); + rState.sPre = rNFormat.GetPrefix(); } } else { - m_sNumber = "??"; + rState.sNumber = "??"; } - m_sTitle = removeControlChars(sw::GetExpandTextMerged(pLayout, + rState.sTitle = removeControlChars(sw::GetExpandTextMerged(pLayout, *pTextNd, false, false, ExpandMode(0))); } } @@ -199,7 +224,7 @@ bool SwChapterField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const switch( nWhichId ) { case FIELD_PROP_BYTE1: - rAny <<= static_cast<sal_Int8>(m_nLevel); + rAny <<= static_cast<sal_Int8>(m_State.nLevel); break; case FIELD_PROP_USHORT1: @@ -238,7 +263,10 @@ bool SwChapterField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) sal_Int8 nTmp = 0; rAny >>= nTmp; if(nTmp >= 0 && nTmp < MAXLEVEL) - m_nLevel = nTmp; + { + m_State.nLevel = nTmp; + m_StateRLHidden.nLevel = nTmp; + } else bRet = false; break; diff --git a/sw/source/ui/fldui/flddok.cxx b/sw/source/ui/fldui/flddok.cxx index 66a6684f8341..3b756a692136 100644 --- a/sw/source/ui/fldui/flddok.cxx +++ b/sw/source/ui/fldui/flddok.cxx @@ -385,7 +385,7 @@ IMPL_LINK_NOARG(SwFieldDokPage, TypeHdl, ListBox&, void) case TYP_CHAPTERFLD: m_pValueFT->SetText(SwResId(STR_LEVEL)); if (IsFieldEdit()) - m_pLevelED->SetText(OUString::number(static_cast<SwChapterField*>(GetCurField())->GetLevel() + 1)); + m_pLevelED->SetText(OUString::number(static_cast<SwChapterField*>(GetCurField())->GetLevel(GetWrtShell()->GetLayout()) + 1)); bLevel = true; break; |