From 44009b9a9d09c2574b4740881a848556eea2859d Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 24 Feb 2015 09:03:24 +0100 Subject: Add SwPaM::dumpAsXml() To avoid code duplication in SwRangeRedline::dumpAsXml() and SwFrm::dumpAsXml(). Change-Id: Ic473cd77e960041b035b147dd31c16b141cc7cbe --- sw/inc/pam.hxx | 2 ++ sw/source/core/crsr/pam.cxx | 18 ++++++++++++++++++ sw/source/core/doc/docredln.cxx | 7 +------ sw/source/core/text/xmldump.cxx | 12 ++---------- 4 files changed, 23 insertions(+), 16 deletions(-) (limited to 'sw') diff --git a/sw/inc/pam.hxx b/sw/inc/pam.hxx index 616a45a6061a..30a19c313a10 100644 --- a/sw/inc/pam.hxx +++ b/sw/inc/pam.hxx @@ -315,6 +315,8 @@ public: { return GetPrevInRing(); } bool IsMultiSelection() const { return !unique(); } + + void dumpAsXml(struct _xmlTextWriter* pWriter) const; }; std::ostream &operator <<(std::ostream& s, const SwPaM& pam); diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx index b8dc0a6c3ee0..16f107c40ac6 100644 --- a/sw/source/core/crsr/pam.cxx +++ b/sw/source/core/crsr/pam.cxx @@ -1098,6 +1098,24 @@ void SwPaM::InvalidatePaM() } } +void SwPaM::dumpAsXml(xmlTextWriterPtr pWriter) const +{ + xmlTextWriterStartElement(pWriter, BAD_CAST("swPaM")); + + xmlTextWriterStartElement(pWriter, BAD_CAST("point")); + GetPoint()->dumpAsXml(pWriter); + xmlTextWriterEndElement(pWriter); + + if (HasMark()) + { + xmlTextWriterStartElement(pWriter, BAD_CAST("mark")); + GetMark()->dumpAsXml(pWriter); + xmlTextWriterEndElement(pWriter); + } + + xmlTextWriterEndElement(pWriter); +} + std::ostream &operator <<(std::ostream& s, const SwPaM& pam) { if( pam.HasMark()) diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx index 82ce470da54d..ba755ab43a82 100644 --- a/sw/source/core/doc/docredln.cxx +++ b/sw/source/core/doc/docredln.cxx @@ -1640,12 +1640,7 @@ void SwRangeRedline::dumpAsXml(xmlTextWriterPtr pWriter) const } xmlTextWriterWriteAttribute(pWriter, BAD_CAST("type"), BAD_CAST(sRedlineType.getStr())); - xmlTextWriterStartElement(pWriter, BAD_CAST("point")); - GetPoint()->dumpAsXml(pWriter); - xmlTextWriterEndElement(pWriter); - xmlTextWriterStartElement(pWriter, BAD_CAST("mark")); - GetMark()->dumpAsXml(pWriter); - xmlTextWriterEndElement(pWriter); + SwPaM::dumpAsXml(pWriter); const SwRedlineExtraData* pExtraRedlineData = GetExtraData(); xmlTextWriterStartElement(pWriter, BAD_CAST("swRedlineExtraData")); diff --git a/sw/source/core/text/xmldump.cxx b/sw/source/core/text/xmldump.cxx index a21f56efe93e..d32219987adc 100644 --- a/sw/source/core/text/xmldump.cxx +++ b/sw/source/core/text/xmldump.cxx @@ -299,16 +299,8 @@ void SwFrm::dumpAsXml( xmlTextWriterPtr writer ) const const SwRootFrm* const pRootFrm = static_cast(this); SwEditShell* pEditShell = pRootFrm->GetCurrShell()->GetDoc()->GetEditShell(); xmlTextWriterStartElement(writer, BAD_CAST("shellCrsr")); - for(SwPaM& rPaM : pEditShell->getShellCrsr(false)->GetRingContainer()) - { - xmlTextWriterStartElement(writer, BAD_CAST("swpam")); - xmlTextWriterWriteFormatAttribute(writer, BAD_CAST("pointNodeIndex"), "%ld", rPaM.GetPoint()->nNode.GetIndex()); - xmlTextWriterWriteFormatAttribute(writer, BAD_CAST("pointContentIndex"), "%" SAL_PRIdINT32, rPaM.GetPoint()->nContent.GetIndex()); - - xmlTextWriterWriteFormatAttribute(writer, BAD_CAST("markNodeIndex"), "%ld", rPaM.GetMark()->nNode.GetIndex()); - xmlTextWriterWriteFormatAttribute(writer, BAD_CAST("markContentIndex"), "%" SAL_PRIdINT32, rPaM.GetMark()->nContent.GetIndex()); - xmlTextWriterEndElement(writer); - } + for (SwPaM& rPaM : pEditShell->getShellCrsr(false)->GetRingContainer()) + rPaM.dumpAsXml(writer); xmlTextWriterEndElement(writer); } -- cgit