Kaydet (Commit) 43a7231c authored tarafından Michael Stahl's avatar Michael Stahl

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
üst a25e7ac8
...@@ -49,11 +49,18 @@ class SW_DLLPUBLIC SwChapterField : public SwField ...@@ -49,11 +49,18 @@ class SW_DLLPUBLIC SwChapterField : public SwField
{ {
friend class SwChapterFieldType; friend class SwChapterFieldType;
friend class ToxTextGeneratorTest; // the unittest needs to mock the chapter fields. friend class ToxTextGeneratorTest; // the unittest needs to mock the chapter fields.
sal_uInt8 m_nLevel;
OUString m_sTitle; struct State
OUString m_sNumber; {
OUString m_sPre; sal_uInt8 nLevel;
OUString m_sPost; OUString sTitle;
OUString sNumber;
OUString sPre;
OUString sPost;
State() : nLevel(0) {}
};
State m_State;
State m_StateRLHidden;
virtual OUString Expand() const override; virtual OUString Expand() const override;
virtual std::unique_ptr<SwField> Copy() const override; virtual std::unique_ptr<SwField> Copy() const override;
...@@ -67,20 +74,16 @@ public: ...@@ -67,20 +74,16 @@ public:
bool bSrchNum = false); bool bSrchNum = false);
void ChangeExpansion(const SwTextNode &rNd, bool bSrchNum, SwRootFrame const* pLayout = nullptr); void ChangeExpansion(const SwTextNode &rNd, bool bSrchNum, SwRootFrame const* pLayout = nullptr);
inline sal_uInt8 GetLevel() const; sal_uInt8 GetLevel(SwRootFrame const* pLayout = nullptr) const;
inline void SetLevel(sal_uInt8); 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 QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override;
virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) 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 #endif // INCLUDED_SW_INC_CHPFLD_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -141,10 +141,10 @@ ToxTextGeneratorTest::ChapterNumberWithoutTextIsGeneratedForNoprepstTitle() ...@@ -141,10 +141,10 @@ ToxTextGeneratorTest::ChapterNumberWithoutTextIsGeneratedForNoprepstTitle()
SwForm form; SwForm form;
ToxTextGeneratorWithMockedChapterField ttg(form); ToxTextGeneratorWithMockedChapterField ttg(form);
// set all values to make sure they are not used // set all values to make sure they are not used
ttg.GetChapterField().sNumber = "1"; ttg.GetChapterField().m_State.sNumber = "1";
ttg.GetChapterField().sPre = "PRE"; ttg.GetChapterField().m_State.sPre = "PRE";
ttg.GetChapterField().sPost = "POST"; ttg.GetChapterField().m_State.sPost = "POST";
ttg.GetChapterField().sTitle = "TITLE"; ttg.GetChapterField().m_State.sTitle = "TITLE";
SwFormToken token(TOKEN_CHAPTER_INFO); SwFormToken token(TOKEN_CHAPTER_INFO);
token.nChapterFormat = CF_NUM_NOPREPST_TITLE; token.nChapterFormat = CF_NUM_NOPREPST_TITLE;
...@@ -167,10 +167,10 @@ ToxTextGeneratorTest::ChapterNumberWithTitleIsGeneratedForNumberNoPrepst() ...@@ -167,10 +167,10 @@ ToxTextGeneratorTest::ChapterNumberWithTitleIsGeneratedForNumberNoPrepst()
SwForm form; SwForm form;
ToxTextGeneratorWithMockedChapterField ttg(form); ToxTextGeneratorWithMockedChapterField ttg(form);
// set all values to make sure they are not used // set all values to make sure they are not used
ttg.GetChapterField().sNumber = "5"; ttg.GetChapterField().m_State.sNumber = "5";
ttg.GetChapterField().sPre = "PRE"; ttg.GetChapterField().m_State.sPre = "PRE";
ttg.GetChapterField().sPost = "POST"; ttg.GetChapterField().m_State.sPost = "POST";
ttg.GetChapterField().sTitle = "myTitle"; ttg.GetChapterField().m_State.sTitle = "myTitle";
SwFormToken token(TOKEN_CHAPTER_INFO); SwFormToken token(TOKEN_CHAPTER_INFO);
token.nChapterFormat = CF_NUMBER_NOPREPST; token.nChapterFormat = CF_NUMBER_NOPREPST;
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <com/sun/star/text/ChapterFormat.hpp> #include <com/sun/star/text/ChapterFormat.hpp>
#include <doc.hxx> #include <doc.hxx>
#include <frame.hxx> #include <frame.hxx>
#include <rootfrm.hxx>
#include <txtfrm.hxx> #include <txtfrm.hxx>
#include <pam.hxx> #include <pam.hxx>
#include <ndtxt.hxx> #include <ndtxt.hxx>
...@@ -66,35 +67,58 @@ SwFieldType* SwChapterFieldType::Copy() const ...@@ -66,35 +67,58 @@ SwFieldType* SwChapterFieldType::Copy() const
SwChapterField::SwChapterField(SwChapterFieldType* pTyp, sal_uInt32 nFormat) SwChapterField::SwChapterField(SwChapterFieldType* pTyp, sal_uInt32 nFormat)
: SwField(pTyp, 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 OUString SwChapterField::Expand() const
{ {
State const& rState(m_State);
switch( GetFormat() ) switch( GetFormat() )
{ {
case CF_TITLE: case CF_TITLE:
return m_sTitle; return rState.sTitle;
case CF_NUMBER: case CF_NUMBER:
return m_sPre + m_sNumber + m_sPost; return rState.sPre + rState.sNumber + rState.sPost;
case CF_NUM_TITLE: 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: case CF_NUM_NOPREPST_TITLE:
return m_sNumber + m_sTitle; return rState.sNumber + rState.sTitle;
} }
// CF_NUMBER_NOPREPST // CF_NUMBER_NOPREPST
return m_sNumber; return rState.sNumber;
} }
std::unique_ptr<SwField> SwChapterField::Copy() const std::unique_ptr<SwField> SwChapterField::Copy() const
{ {
std::unique_ptr<SwChapterField> pTmp( std::unique_ptr<SwChapterField> pTmp(
new SwChapterField(static_cast<SwChapterFieldType*>(GetTyp()), GetFormat())); new SwChapterField(static_cast<SwChapterFieldType*>(GetTyp()), GetFormat()));
pTmp->m_nLevel = m_nLevel; pTmp->m_State = m_State;
pTmp->m_sTitle = m_sTitle; pTmp->m_StateRLHidden = m_StateRLHidden;
pTmp->m_sNumber = m_sNumber;
pTmp->m_sPost = m_sPost;
pTmp->m_sPre = m_sPre;
return std::unique_ptr<SwField>(pTmp.release()); return std::unique_ptr<SwField>(pTmp.release());
} }
...@@ -122,13 +146,14 @@ void SwChapterField::ChangeExpansion(const SwFrame & rFrame, ...@@ -122,13 +146,14 @@ void SwChapterField::ChangeExpansion(const SwFrame & rFrame,
void SwChapterField::ChangeExpansion(const SwTextNode &rTextNd, bool bSrchNum, void SwChapterField::ChangeExpansion(const SwTextNode &rTextNd, bool bSrchNum,
SwRootFrame const*const pLayout) SwRootFrame const*const pLayout)
{ {
m_sNumber.clear(); State & rState(pLayout && pLayout->IsHideRedlines() ? m_StateRLHidden : m_State);
m_sTitle.clear(); rState.sNumber.clear();
m_sPost.clear(); rState.sTitle.clear();
m_sPre.clear(); rState.sPost.clear();
rState.sPre.clear();
SwDoc* pDoc = const_cast<SwDoc*>(rTextNd.GetDoc()); 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( pTextNd )
{ {
if( bSrchNum ) if( bSrchNum )
...@@ -137,24 +162,24 @@ void SwChapterField::ChangeExpansion(const SwTextNode &rTextNd, bool bSrchNum, ...@@ -137,24 +162,24 @@ void SwChapterField::ChangeExpansion(const SwTextNode &rTextNd, bool bSrchNum,
do { do {
if( pONd && pONd->GetTextColl() ) if( pONd && pONd->GetTextColl() )
{ {
sal_uInt8 nPrevLvl = m_nLevel; sal_uInt8 nPrevLvl = rState.nLevel;
OSL_ENSURE( pONd->GetAttrOutlineLevel() >= 0 && pONd->GetAttrOutlineLevel() <= MAXLEVEL, OSL_ENSURE( pONd->GetAttrOutlineLevel() >= 0 && pONd->GetAttrOutlineLevel() <= MAXLEVEL,
"<SwChapterField::ChangeExpansion(..)> - outline node with inconsistent outline level. Serious defect." ); "<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) if (nPrevLvl < rState.nLevel)
m_nLevel = nPrevLvl; rState.nLevel = nPrevLvl;
else if( SVX_NUM_NUMBER_NONE != pDoc->GetOutlineNumRule() else if( SVX_NUM_NUMBER_NONE != pDoc->GetOutlineNumRule()
->Get( m_nLevel ).GetNumberingType() ) ->Get( rState.nLevel ).GetNumberingType() )
{ {
pTextNd = pONd; pTextNd = pONd;
break; break;
} }
if (!m_nLevel--) if (!rState.nLevel--)
break; break;
pONd = pTextNd->FindOutlineNodeOfLevel(m_nLevel, pLayout); pONd = pTextNd->FindOutlineNodeOfLevel(rState.nLevel, pLayout);
} }
else else
break; break;
...@@ -168,7 +193,7 @@ void SwChapterField::ChangeExpansion(const SwTextNode &rTextNd, bool bSrchNum, ...@@ -168,7 +193,7 @@ void SwChapterField::ChangeExpansion(const SwTextNode &rTextNd, bool bSrchNum,
// correction of refactoring done by cws swnumtree: // correction of refactoring done by cws swnumtree:
// retrieve numbering string without prefix and suffix strings // retrieve numbering string without prefix and suffix strings
// as stated in the above german comment. // 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() ); SwNumRule* pRule( pTextNd->GetNumRule() );
if ( pTextNd->IsCountedInList() && pRule ) if ( pTextNd->IsCountedInList() && pRule )
...@@ -180,16 +205,16 @@ void SwChapterField::ChangeExpansion(const SwTextNode &rTextNd, bool bSrchNum, ...@@ -180,16 +205,16 @@ void SwChapterField::ChangeExpansion(const SwTextNode &rTextNd, bool bSrchNum,
nListLevel = MAXLEVEL - 1; nListLevel = MAXLEVEL - 1;
const SwNumFormat& rNFormat = pRule->Get(nListLevel); const SwNumFormat& rNFormat = pRule->Get(nListLevel);
m_sPost = rNFormat.GetSuffix(); rState.sPost = rNFormat.GetSuffix();
m_sPre = rNFormat.GetPrefix(); rState.sPre = rNFormat.GetPrefix();
} }
} }
else else
{ {
m_sNumber = "??"; rState.sNumber = "??";
} }
m_sTitle = removeControlChars(sw::GetExpandTextMerged(pLayout, rState.sTitle = removeControlChars(sw::GetExpandTextMerged(pLayout,
*pTextNd, false, false, ExpandMode(0))); *pTextNd, false, false, ExpandMode(0)));
} }
} }
...@@ -199,7 +224,7 @@ bool SwChapterField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const ...@@ -199,7 +224,7 @@ bool SwChapterField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
switch( nWhichId ) switch( nWhichId )
{ {
case FIELD_PROP_BYTE1: case FIELD_PROP_BYTE1:
rAny <<= static_cast<sal_Int8>(m_nLevel); rAny <<= static_cast<sal_Int8>(m_State.nLevel);
break; break;
case FIELD_PROP_USHORT1: case FIELD_PROP_USHORT1:
...@@ -238,7 +263,10 @@ bool SwChapterField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) ...@@ -238,7 +263,10 @@ bool SwChapterField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
sal_Int8 nTmp = 0; sal_Int8 nTmp = 0;
rAny >>= nTmp; rAny >>= nTmp;
if(nTmp >= 0 && nTmp < MAXLEVEL) if(nTmp >= 0 && nTmp < MAXLEVEL)
m_nLevel = nTmp; {
m_State.nLevel = nTmp;
m_StateRLHidden.nLevel = nTmp;
}
else else
bRet = false; bRet = false;
break; break;
......
...@@ -385,7 +385,7 @@ IMPL_LINK_NOARG(SwFieldDokPage, TypeHdl, ListBox&, void) ...@@ -385,7 +385,7 @@ IMPL_LINK_NOARG(SwFieldDokPage, TypeHdl, ListBox&, void)
case TYP_CHAPTERFLD: case TYP_CHAPTERFLD:
m_pValueFT->SetText(SwResId(STR_LEVEL)); m_pValueFT->SetText(SwResId(STR_LEVEL));
if (IsFieldEdit()) 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; bLevel = true;
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment