TSCP: refactor paragraph metadata field check
This moves the logic into SwEditShell next to
the exiting paragraph metadata infrastructure.
Change-Id: I6c12bfca3d2e1b2bc8697f03f4de1b7c3e14b95a
Reviewed-on: https://gerrit.libreoffice.org/42742
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx
index 50c5bf7..7a8164c 100644
--- a/sw/inc/editsh.hxx
+++ b/sw/inc/editsh.hxx
@@ -380,6 +380,10 @@ public:
/// Validate paragraph signatures, if any, at the cursor.
void ValidateParagraphSignatures(bool updateDontRemove);
/// Returns true iff the cursor is within a paragraph metadata field.
/// Currently there are two variants: signature and classification.
bool IsCursorInParagraphMetadataField() const;
void Insert2(SwField const &, const bool bForceExpandHints);
void UpdateFields( SwField & ); ///< One single field.
diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx
index dc7314e..2afae84 100644
--- a/sw/source/core/crsr/pam.cxx
+++ b/sw/source/core/crsr/pam.cxx
@@ -43,9 +43,7 @@
#include <hints.hxx>
#include <xmloff/odffields.hxx>
#include <rdfhelper.hxx>
#include <txtatr.hxx>
#include <docsh.hxx>
#include <editsh.hxx>
// for the dump "MSC-" compiler
inline sal_Int32 GetSttOrEnd( bool bCondition, const SwContentNode& rNd )
@@ -715,30 +713,10 @@ bool SwPaM::HasReadonlySel( bool bFormView ) const
bRet = !( pA == pB && pA != nullptr );
}
// Paragraph Signatures are read-only.
if (!bRet)
{
SwTextNode* pNode = Start()->nNode.GetNode().GetTextNode();
if (pNode != nullptr)
{
SwTextAttr* pAttr = pNode->GetTextAttrAt(Start()->nContent.GetIndex(), RES_TXTATR_METAFIELD);
SwTextMeta* pTextMeta = static_txtattr_cast<SwTextMeta*>(pAttr);
if (pTextMeta)
{
SwFormatMeta& rFormatMeta(static_cast<SwFormatMeta&>(pTextMeta->GetAttr()));
if (::sw::Meta* pMeta = rFormatMeta.GetMeta())
{
if (const SwDocShell* pDocSh = pDoc->GetDocShell())
{
static const OUString metaNS("urn:bails");
const css::uno::Reference<css::rdf::XResource> xSubject(pMeta->MakeUnoObject(), uno::UNO_QUERY);
uno::Reference<frame::XModel> xModel = pDocSh->GetBaseModel();
const std::map<OUString, OUString> aStatements = SwRDFHelper::getStatements(xModel, metaNS, xSubject);
bRet = (aStatements.find("loext:paragraph:signature") != aStatements.end());
}
}
}
}
// Paragraph Signatures and Classification fields are read-only.
bRet = pDoc->GetEditShell()->IsCursorInParagraphMetadataField();
}
return bRet;
diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx
index 1346826..d696fe0 100644
--- a/sw/source/core/edit/edfcol.cxx
+++ b/sw/source/core/edit/edfcol.cxx
@@ -79,6 +79,7 @@
#include <strings.hrc>
#include <undobj.hxx>
#include <UndoParagraphSignature.hxx>
#include <txtatr.hxx>
#include <officecfg/Office/Common.hxx>
#include <com/sun/star/beans/PropertyAttribute.hpp>
@@ -1155,6 +1156,32 @@ void SwEditShell::ValidateParagraphSignatures(bool updateDontRemove)
}
}
bool SwEditShell::IsCursorInParagraphMetadataField() const
{
SwTextNode* pNode = GetCursor()->Start()->nNode.GetNode().GetTextNode();
if (pNode != nullptr)
{
SwTextAttr* pAttr = pNode->GetTextAttrAt(GetCursor()->Start()->nContent.GetIndex(), RES_TXTATR_METAFIELD);
SwTextMeta* pTextMeta = static_txtattr_cast<SwTextMeta*>(pAttr);
if (pTextMeta != nullptr)
{
SwFormatMeta& rFormatMeta(static_cast<SwFormatMeta&>(pTextMeta->GetAttr()));
if (::sw::Meta* pMeta = rFormatMeta.GetMeta())
{
if (const SwDocShell* pDocSh = GetDoc()->GetDocShell())
{
const css::uno::Reference<css::rdf::XResource> xSubject(pMeta->MakeUnoObject(), uno::UNO_QUERY);
uno::Reference<frame::XModel> xModel = pDocSh->GetBaseModel();
const std::map<OUString, OUString> aStatements = SwRDFHelper::getStatements(xModel, MetaNS, xSubject);
return (aStatements.find(ParagraphSignatureRDFName) != aStatements.end());
}
}
}
}
return false;
}
// #i62675#
void SwEditShell::SetTextFormatColl(SwTextFormatColl *pFormat,
const bool bResetListAttrs)