summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2018-11-07 14:16:28 +0100
committerMichael Stahl <Michael.Stahl@cib.de>2018-11-10 19:49:27 +0100
commit0a258ae8698639b6fd62dcea3663d7ce510bc3c2 (patch)
tree4703cbdde986f4cf4904314fb1d18a863b1c3dd0
parent3ff9c3bc23c2d45798a4d970ffd8d2e1e182db49 (diff)
sw_redlinehide_3: add second result to SwGetRefField
... and init it in SwGetRefField::UpdateField(). Change-Id: I69af00678e84214d4a122d8b2d940fcdda5f4ccf
-rw-r--r--sw/inc/reffld.hxx11
-rw-r--r--sw/source/core/fields/reffld.cxx207
2 files changed, 158 insertions, 60 deletions
diff --git a/sw/inc/reffld.hxx b/sw/inc/reffld.hxx
index a3764451f5a4..7e02260d5ba6 100644
--- a/sw/inc/reffld.hxx
+++ b/sw/inc/reffld.hxx
@@ -83,18 +83,15 @@ class SW_DLLPUBLIC SwGetRefField : public SwField
private:
OUString m_sSetRefName;
OUString m_sSetReferenceLanguage;
- OUString m_sText;
+ OUString m_sText; ///< result
+ OUString m_sTextRLHidden; ///< result for layout with redlines hidden
sal_uInt16 m_nSubType;
+ /// reference to either a SwTextFootnote::m_nSeqNo or a SwSetExpField::mnSeqNo
sal_uInt16 m_nSeqNo;
virtual OUString Expand() const override;
virtual std::unique_ptr<SwField> Copy() const override;
- // #i81002#
- static OUString MakeRefNumStr( const SwTextNode& rTextNodeOfField,
- const SwTextNode& rTextNodeOfReferencedItem,
- const sal_uInt32 nRefNumFormat );
-
public:
SwGetRefField( SwGetRefFieldType*, const OUString& rSetRef, const OUString& rReferenceLanguage,
sal_uInt16 nSubType, sal_uInt16 nSeqNo, sal_uLong nFormat );
@@ -114,7 +111,7 @@ public:
no update for these reference format types. */
void UpdateField( const SwTextField* pFieldTextAttr );
- void SetExpand( const OUString& rStr ) { m_sText = rStr; }
+ void SetExpand( const OUString& rStr );
/// Get/set sub type.
virtual sal_uInt16 GetSubType() const override;
diff --git a/sw/source/core/fields/reffld.cxx b/sw/source/core/fields/reffld.cxx
index 9dbc51f1d733..c44d2f450348 100644
--- a/sw/source/core/fields/reffld.cxx
+++ b/sw/source/core/fields/reffld.cxx
@@ -29,6 +29,8 @@
#include <pam.hxx>
#include <cntfrm.hxx>
#include <pagefrm.hxx>
+#include <rootfrm.hxx>
+#include <modeltoviewhelper.hxx>
#include <docary.hxx>
#include <fmtfld.hxx>
#include <txtfld.hxx>
@@ -69,6 +71,11 @@ using namespace ::com::sun::star;
using namespace ::com::sun::star::text;
using namespace ::com::sun::star::lang;
+static std::pair<OUString, bool> MakeRefNumStr(SwRootFrame const* pLayout,
+ const SwTextNode& rTextNodeOfField,
+ const SwTextNode& rTextNodeOfReferencedItem,
+ sal_uInt32 nRefNumFormat);
+
static void lcl_GetLayTree( const SwFrame* pFrame, std::vector<const SwFrame*>& rArr )
{
while( pFrame )
@@ -402,6 +409,12 @@ OUString SwGetRefField::GetExpandedTextOfReferencedTextNode() const
: OUString();
}
+void SwGetRefField::SetExpand( const OUString& rStr )
+{
+ m_sText = rStr;
+ m_sTextRLHidden = rStr;
+}
+
OUString SwGetRefField::Expand() const
{
return m_sText;
@@ -417,10 +430,40 @@ OUString SwGetRefField::GetFieldName() const
return Expand();
}
+
+static void FilterText(OUString & rText, LanguageType const eLang,
+ OUString const& rSetReferenceLanguage)
+{
+ // remove all special characters (replace them with blanks)
+ if (!rText.isEmpty())
+ {
+ rText = rText.replaceAll(OUStringLiteral1(0xad), "");
+ OUStringBuffer aBuf(rText);
+ const sal_Int32 l = aBuf.getLength();
+ for (sal_Int32 i = 0; i < l; ++i)
+ {
+ if (aBuf[i] < ' ')
+ {
+ aBuf[i] = ' ';
+ }
+ else if (aBuf[i] == 0x2011)
+ {
+ aBuf[i] = '-';
+ }
+ }
+ rText = aBuf.makeStringAndClear();
+ if (!rSetReferenceLanguage.isEmpty())
+ {
+ lcl_formatReferenceLanguage(rText, false, eLang, rSetReferenceLanguage);
+ }
+ }
+}
+
// #i81002# - parameter <pFieldTextAttr> added
void SwGetRefField::UpdateField( const SwTextField* pFieldTextAttr )
{
m_sText.clear();
+ m_sTextRLHidden.clear();
SwDoc* pDoc = static_cast<SwGetRefFieldType*>(GetTyp())->GetDoc();
// finding the reference target (the number)
@@ -433,8 +476,24 @@ void SwGetRefField::UpdateField( const SwTextField* pFieldTextAttr )
if ( !pTextNd )
{
m_sText = SwViewShell::GetShellRes()->aGetRefField_RefItemNotFound;
+ m_sTextRLHidden = m_sText;
return ;
}
+
+ SwRootFrame const* pLayout(nullptr);
+ SwRootFrame const* pLayoutRLHidden(nullptr);
+ for (SwRootFrame const*const pLay : pDoc->GetAllLayouts())
+ {
+ if (pLay->IsHideRedlines())
+ {
+ pLayoutRLHidden = pLay;
+ }
+ else
+ {
+ pLayout = pLay;
+ }
+ }
+
// where is the category name (e.g. "Illustration")?
const OUString aText = pTextNd->GetText();
const sal_Int32 nCatStart = aText.indexOf(m_sSetRefName);
@@ -497,8 +556,10 @@ void SwGetRefField::UpdateField( const SwTextField* pFieldTextAttr )
nEnd = std::min(nStart + 1, nLen);
break;
- // "Reference" (whole Text)
default:
+ assert(false); // fall through to appease MSVC C4701
+ // "Reference" (whole Text)
+ case REF_CONTENT:
nStart = 0;
nEnd = nLen;
break;
@@ -524,15 +585,21 @@ void SwGetRefField::UpdateField( const SwTextField* pFieldTextAttr )
SwTextFootnote* const pFootnoteIdx = pDoc->GetFootnoteIdxs()[i];
if( m_nSeqNo == pFootnoteIdx->GetSeqRefNo() )
{
- m_sText = pFootnoteIdx->GetFootnote().GetViewNumStr(*pDoc, nullptr/*TODO?*/);
+ m_sText = pFootnoteIdx->GetFootnote().GetViewNumStr(*pDoc, nullptr);
+ m_sTextRLHidden = pFootnoteIdx->GetFootnote().GetViewNumStr(*pDoc, pLayoutRLHidden);
if (!m_sSetReferenceLanguage.isEmpty())
+ {
lcl_formatReferenceLanguage(m_sText, false, GetLanguage(), m_sSetReferenceLanguage);
+ lcl_formatReferenceLanguage(m_sTextRLHidden, false, GetLanguage(), m_sSetReferenceLanguage);
+ }
break;
}
}
return;
default:
+ assert(false); // fall through to appease MSVC C4701
+ case REF_SETREFATTR:
nStart = nNumStart;
nEnd = nNumEnd;
break;
@@ -541,28 +608,19 @@ void SwGetRefField::UpdateField( const SwTextField* pFieldTextAttr )
if( nStart != nEnd ) // a section?
{
m_sText = pTextNd->GetExpandText(nStart, nEnd - nStart, false, false, false);
-
- // remove all special characters (replace them with blanks)
- if( !m_sText.isEmpty() )
+ if (m_nSubType == REF_OUTLINE
+ || (m_nSubType == REF_SEQUENCEFLD && REF_CONTENT == GetFormat()))
{
- m_sText = m_sText.replaceAll(OUStringLiteral1(0xad), "");
- OUStringBuffer aBuf(m_sText);
- const sal_Int32 l = aBuf.getLength();
- for (sal_Int32 i=0; i<l; ++i)
- {
- if (aBuf[i]<' ')
- {
- aBuf[i]=' ';
- }
- else if (aBuf[i]==0x2011)
- {
- aBuf[i]='-';
- }
- }
- m_sText = aBuf.makeStringAndClear();
- if (!m_sSetReferenceLanguage.isEmpty())
- lcl_formatReferenceLanguage(m_sText, false, GetLanguage(), m_sSetReferenceLanguage);
+ m_sTextRLHidden = sw::GetExpandTextMerged(
+ pLayoutRLHidden, *pTextNd, false, false, ExpandMode(0));
+ }
+ else
+ {
+ m_sTextRLHidden = pTextNd->GetExpandText(
+ nStart, nEnd - nStart, false, false, false, ExpandMode::HideDeletions);
}
+ FilterText(m_sText, GetLanguage(), m_sSetReferenceLanguage);
+ FilterText(m_sTextRLHidden, GetLanguage(), m_sSetReferenceLanguage);
}
}
break;
@@ -570,8 +628,11 @@ void SwGetRefField::UpdateField( const SwTextField* pFieldTextAttr )
case REF_PAGE:
case REF_PAGE_PGDESC:
{
- const SwTextFrame* pFrame = static_cast<SwTextFrame*>(pTextNd->getLayoutFrame( pDoc->getIDocumentLayoutAccess().GetCurrentLayout(), nullptr, nullptr)),
- *pSave = pFrame;
+ auto const func =
+ [this, pTextNd, nNumStart](OUString & rText, SwRootFrame const*const pLay)
+ {
+ SwTextFrame const* pFrame = static_cast<SwTextFrame*>(pTextNd->getLayoutFrame(pLay, nullptr, nullptr));
+ SwTextFrame const*const pSave = pFrame;
if (pFrame)
{
TextFrameIndex const nNumStartIndex(pFrame->MapModelToView(pTextNd, nNumStart));
@@ -586,31 +647,46 @@ void SwGetRefField::UpdateField( const SwTextField* pFieldTextAttr )
if( REF_PAGE_PGDESC == GetFormat() &&
nullptr != ( pPage = pFrame->FindPageFrame() ) &&
pPage->GetPageDesc() )
- m_sText = pPage->GetPageDesc()->GetNumType().GetNumStr( nPageNo );
+ {
+ rText = pPage->GetPageDesc()->GetNumType().GetNumStr(nPageNo);
+ }
else
- m_sText = OUString::number(nPageNo);
+ {
+ rText = OUString::number(nPageNo);
+ }
if (!m_sSetReferenceLanguage.isEmpty())
- lcl_formatReferenceLanguage(m_sText, false, GetLanguage(), m_sSetReferenceLanguage);
+ lcl_formatReferenceLanguage(rText, false, GetLanguage(), m_sSetReferenceLanguage);
}
+ };
+ // sw_redlinehide: currently only one of these layouts will exist,
+ // so the getLayoutFrame will use the same frame in both cases
+ func(m_sText, pLayout);
+ func(m_sTextRLHidden, pLayoutRLHidden);
}
break;
case REF_CHAPTER:
{
+ auto const func =
+ [this, pTextNd](OUString & rText, SwRootFrame const*const pLay)
+ {
// a bit tricky: search any frame
- const SwFrame* pFrame = pTextNd->getLayoutFrame( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() );
+ SwFrame const*const pFrame = pTextNd->getLayoutFrame(pLay);
if( pFrame )
{
SwChapterFieldType aFieldTyp;
SwChapterField aField( &aFieldTyp, 0 );
aField.SetLevel( MAXLEVEL - 1 );
aField.ChangeExpansion( *pFrame, pTextNd, true );
- m_sText = aField.GetNumber();
+ rText = aField.GetNumber(pLay);
if (!m_sSetReferenceLanguage.isEmpty())
- lcl_formatReferenceLanguage(m_sText, false, GetLanguage(), m_sSetReferenceLanguage);
+ lcl_formatReferenceLanguage(rText, false, GetLanguage(), m_sSetReferenceLanguage);
}
+ };
+ func(m_sText, pLayout);
+ func(m_sTextRLHidden, pLayoutRLHidden);
}
break;
@@ -630,6 +706,7 @@ void SwGetRefField::UpdateField( const SwTextField* pFieldTextAttr )
m_sText = nNumStart < pFieldTextAttr->GetStart()
? aLocaleData.getAboveWord()
: aLocaleData.getBelowWord();
+ m_sTextRLHidden = m_sText;
break;
}
@@ -640,6 +717,8 @@ void SwGetRefField::UpdateField( const SwTextField* pFieldTextAttr )
if (!m_sSetReferenceLanguage.isEmpty())
lcl_formatReferenceLanguage(m_sText, false, GetLanguage(), m_sSetReferenceLanguage);
+
+ m_sTextRLHidden = m_sText;
}
break;
// #i81002#
@@ -647,19 +726,26 @@ void SwGetRefField::UpdateField( const SwTextField* pFieldTextAttr )
case REF_NUMBER_NO_CONTEXT:
case REF_NUMBER_FULL_CONTEXT:
{
- // for differentiation of Roman numbers and letters in Hungarian article handling
- bool bClosingParenthesis = false;
-
if ( pFieldTextAttr && pFieldTextAttr->GetpTextNode() )
{
- m_sText = MakeRefNumStr( pFieldTextAttr->GetTextNode(), *pTextNd, GetFormat() );
- if ( !m_sText.isEmpty() && !m_sSetReferenceLanguage.isEmpty() )
- bClosingParenthesis = pTextNd->GetNumRule()->MakeNumString( *(pTextNd->GetNum()), true).endsWith(")");
+ auto result =
+ MakeRefNumStr(pLayout, pFieldTextAttr->GetTextNode(), *pTextNd, GetFormat());
+ m_sText = result.first;
+ // for differentiation of Roman numbers and letters in Hungarian article handling
+ bool bClosingParenthesis = result.second;
+ if (!m_sSetReferenceLanguage.isEmpty())
+ {
+ lcl_formatReferenceLanguage(m_sText, bClosingParenthesis, GetLanguage(), m_sSetReferenceLanguage);
+ }
+ result =
+ MakeRefNumStr(pLayoutRLHidden, pFieldTextAttr->GetTextNode(), *pTextNd, GetFormat());
+ m_sTextRLHidden = result.first;
+ bClosingParenthesis = result.second;
+ if (!m_sSetReferenceLanguage.isEmpty())
+ {
+ lcl_formatReferenceLanguage(m_sTextRLHidden, bClosingParenthesis, GetLanguage(), m_sSetReferenceLanguage);
+ }
}
-
- if (!m_sSetReferenceLanguage.isEmpty())
- lcl_formatReferenceLanguage(m_sText, bClosingParenthesis, GetLanguage(), m_sSetReferenceLanguage);
-
}
break;
@@ -669,14 +755,22 @@ void SwGetRefField::UpdateField( const SwTextField* pFieldTextAttr )
}
// #i81002#
-OUString SwGetRefField::MakeRefNumStr( const SwTextNode& rTextNodeOfField,
- const SwTextNode& rTextNodeOfReferencedItem,
- const sal_uInt32 nRefNumFormat )
+static std::pair<OUString, bool> MakeRefNumStr(
+ SwRootFrame const*const pLayout,
+ const SwTextNode& i_rTextNodeOfField,
+ const SwTextNode& i_rTextNodeOfReferencedItem,
+ const sal_uInt32 nRefNumFormat)
{
+ SwTextNode const& rTextNodeOfField(pLayout
+ ? *sw::GetParaPropsNode(*pLayout, i_rTextNodeOfField)
+ : i_rTextNodeOfField);
+ SwTextNode const& rTextNodeOfReferencedItem(pLayout
+ ? *sw::GetParaPropsNode(*pLayout, i_rTextNodeOfReferencedItem)
+ : i_rTextNodeOfReferencedItem);
if ( rTextNodeOfReferencedItem.HasNumber() &&
rTextNodeOfReferencedItem.IsCountedInList() )
{
- OSL_ENSURE( rTextNodeOfReferencedItem.GetNum(),
+ OSL_ENSURE( rTextNodeOfReferencedItem.GetNum(pLayout),
"<SwGetRefField::MakeRefNumStr(..)> - referenced paragraph has number, but no <SwNodeNum> instance!" );
// Determine, up to which level the superior list labels have to be
@@ -700,17 +794,19 @@ OUString SwGetRefField::MakeRefNumStr( const SwTextNode& rTextNodeOfField,
if ( rTextNodeOfField.HasNumber() &&
rTextNodeOfField.GetNumRule() == rTextNodeOfReferencedItem.GetNumRule() )
{
- pNodeNumForTextNodeOfField = rTextNodeOfField.GetNum();
+ pNodeNumForTextNodeOfField = rTextNodeOfField.GetNum(pLayout);
}
else
{
pNodeNumForTextNodeOfField =
- rTextNodeOfReferencedItem.GetNum()->GetPrecedingNodeNumOf( rTextNodeOfField );
+ rTextNodeOfReferencedItem.GetNum(pLayout)->GetPrecedingNodeNumOf(rTextNodeOfField);
}
if ( pNodeNumForTextNodeOfField )
{
- const SwNumberTree::tNumberVector rFieldNumVec = pNodeNumForTextNodeOfField->GetNumberVector();
- const SwNumberTree::tNumberVector rRefItemNumVec = rTextNodeOfReferencedItem.GetNum()->GetNumberVector();
+ const SwNumberTree::tNumberVector rFieldNumVec =
+ pNodeNumForTextNodeOfField->GetNumberVector();
+ const SwNumberTree::tNumberVector rRefItemNumVec =
+ rTextNodeOfReferencedItem.GetNum()->GetNumberVector();
std::size_t nLevel( 0 );
while ( nLevel < rFieldNumVec.size() && nLevel < rRefItemNumVec.size() )
{
@@ -734,13 +830,17 @@ OUString SwGetRefField::MakeRefNumStr( const SwTextNode& rTextNodeOfField,
OSL_ENSURE( rTextNodeOfReferencedItem.GetNumRule(),
"<SwGetRefField::MakeRefNumStr(..)> - referenced numbered paragraph has no numbering rule set!" );
- return rTextNodeOfReferencedItem.GetNumRule()->MakeRefNumString(
- *(rTextNodeOfReferencedItem.GetNum()),
- bInclSuperiorNumLabels,
- nRestrictInclToThisLevel );
+ return std::make_pair(
+ rTextNodeOfReferencedItem.GetNumRule()->MakeRefNumString(
+ *(rTextNodeOfReferencedItem.GetNum(pLayout)),
+ bInclSuperiorNumLabels,
+ nRestrictInclToThisLevel ),
+ rTextNodeOfReferencedItem.GetNumRule()->MakeNumString(
+ *(rTextNodeOfReferencedItem.GetNum(pLayout)),
+ true).endsWith(")") );
}
- return OUString();
+ return std::make_pair(OUString(), false);
}
std::unique_ptr<SwField> SwGetRefField::Copy() const
@@ -749,6 +849,7 @@ std::unique_ptr<SwField> SwGetRefField::Copy() const
m_sSetRefName, m_sSetReferenceLanguage, m_nSubType,
m_nSeqNo, GetFormat() ) );
pField->m_sText = m_sText;
+ pField->m_sTextRLHidden = m_sTextRLHidden;
return std::unique_ptr<SwField>(pField.release());
}