sw/source/core/inc/pagefrm.hxx    |    2 +
 sw/source/core/layout/pagechg.cxx |   58 ++++++++++++++++++++++++++++++++++++++
 sw/source/core/text/xmldump.cxx   |   41 --------------------------
 3 files changed, 60 insertions(+), 41 deletions(-)

New commits:
commit 70d0281bbd36c25b5251f4e1c99507084659db90
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Fri Mar 3 07:59:47 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Mar 3 09:54:18 2023 +0000

    sw layout xml dump: extract SwPageFrame::dumpAsXml() from SwFrame
    
    Avoids an ugly static downcast.
    
    Change-Id: I66f59409788f04e03c8c36bb12dc4ba7d3446663
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148159
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/source/core/inc/pagefrm.hxx b/sw/source/core/inc/pagefrm.hxx
index 88004bb7ccb3..cd2f14f5e885 100644
--- a/sw/source/core/inc/pagefrm.hxx
+++ b/sw/source/core/inc/pagefrm.hxx
@@ -346,6 +346,8 @@ public:
 
     const SwHeaderFrame* GetHeaderFrame() const;
     const SwFooterFrame* GetFooterFrame() const;
+
+    void dumpAsXml(xmlTextWriterPtr writer = nullptr) const override;
 };
 
 inline SwContentFrame *SwPageFrame::FindFirstBodyContent()
diff --git a/sw/source/core/layout/pagechg.cxx 
b/sw/source/core/layout/pagechg.cxx
index adbcd85f4b37..152368d9d913 100644
--- a/sw/source/core/layout/pagechg.cxx
+++ b/sw/source/core/layout/pagechg.cxx
@@ -2589,6 +2589,64 @@ const SwFooterFrame* SwPageFrame::GetFooterFrame() const
     return nullptr;
 }
 
+void SwPageFrame::dumpAsXml(xmlTextWriterPtr writer) const
+{
+    (void)xmlTextWriterStartElement(writer, reinterpret_cast<const 
xmlChar*>("page"));
+    dumpAsXmlAttributes(writer);
+
+    (void)xmlTextWriterStartElement(writer, BAD_CAST("page_status"));
+    (void)xmlTextWriterWriteAttribute(writer, BAD_CAST("ValidFlyLayout"), 
BAD_CAST(OString::boolean(!IsInvalidFlyLayout()).getStr()));
+    (void)xmlTextWriterWriteAttribute(writer, BAD_CAST("ValidFlyContent"), 
BAD_CAST(OString::boolean(!IsInvalidFlyContent()).getStr()));
+    (void)xmlTextWriterWriteAttribute(writer, BAD_CAST("ValidFlyInCnt"), 
BAD_CAST(OString::boolean(!IsInvalidFlyInCnt()).getStr()));
+    (void)xmlTextWriterWriteAttribute(writer, BAD_CAST("ValidLayout"), 
BAD_CAST(OString::boolean(!IsInvalidLayout()).getStr()));
+    (void)xmlTextWriterWriteAttribute(writer, BAD_CAST("ValidContent"), 
BAD_CAST(OString::boolean(!IsInvalidContent()).getStr()));
+    (void)xmlTextWriterEndElement(writer);
+    (void)xmlTextWriterStartElement(writer, BAD_CAST("page_info"));
+    (void)xmlTextWriterWriteFormatAttribute(writer, BAD_CAST("phyNum"), "%d", 
GetPhyPageNum());
+    (void)xmlTextWriterWriteFormatAttribute(writer, BAD_CAST("virtNum"), "%d", 
GetVirtPageNum());
+    OUString aFormatName = GetPageDesc()->GetName();
+    (void)xmlTextWriterWriteFormatAttribute( writer, BAD_CAST("pageDesc"), 
"%s", BAD_CAST(OUStringToOString(aFormatName, RTL_TEXTENCODING_UTF8).getStr()));
+    (void)xmlTextWriterEndElement(writer);
+    if (auto const* pObjs = GetSortedObjs())
+    {
+        (void)xmlTextWriterStartElement(writer, BAD_CAST("sorted_objs"));
+        for (SwAnchoredObject const*const pObj : *pObjs)
+        {   // just print pointer, full details will be printed on its anchor 
frame
+            // this nonsense is needed because of multiple inheritance
+            if (SwFlyFrame const* pFly = pObj->DynCastFlyFrame())
+            {
+                (void)xmlTextWriterStartElement(writer, BAD_CAST("fly"));
+                (void)xmlTextWriterWriteFormatAttribute(writer, 
BAD_CAST("ptr"), "%p", pFly);
+            }
+            else
+            {
+                (void)xmlTextWriterStartElement(writer, 
BAD_CAST(pObj->getElementName()));
+                (void)xmlTextWriterWriteFormatAttribute(writer, 
BAD_CAST("ptr"), "%p", pObj);
+            }
+            (void)xmlTextWriterEndElement(writer);
+        }
+        (void)xmlTextWriterEndElement(writer);
+    }
+
+    (void)xmlTextWriterStartElement(writer, BAD_CAST("infos"));
+    dumpInfosAsXml(writer);
+    (void)xmlTextWriterEndElement(writer);
+    const SwSortedObjs* pAnchored = GetDrawObjs();
+    if ( pAnchored && pAnchored->size() > 0 )
+    {
+        (void)xmlTextWriterStartElement( writer, BAD_CAST( "anchored" ) );
+
+        for (SwAnchoredObject* pObject : *pAnchored)
+        {
+            pObject->dumpAsXml( writer );
+        }
+
+        (void)xmlTextWriterEndElement( writer );
+    }
+    dumpChildrenAsXml(writer);
+    (void)xmlTextWriterEndElement(writer);
+}
+
 SwTextGridItem const* GetGridItem(SwPageFrame const*const pPage)
 {
     if (pPage && pPage->HasGrid())
diff --git a/sw/source/core/text/xmldump.cxx b/sw/source/core/text/xmldump.cxx
index f9f3f8a757eb..f204b5c6d32a 100644
--- a/sw/source/core/text/xmldump.cxx
+++ b/sw/source/core/text/xmldump.cxx
@@ -174,9 +174,6 @@ void SwFrame::dumpAsXml( xmlTextWriterPtr writer ) const
 
     switch ( GetType(  ) )
     {
-    case SwFrameType::Page:
-        name = "page";
-        break;
     case SwFrameType::Column:
         name = "column";
         break;
@@ -225,44 +222,6 @@ void SwFrame::dumpAsXml( xmlTextWriterPtr writer ) const
 
         dumpAsXmlAttributes( writer );
 
-        if (IsPageFrame())
-        {
-            const SwPageFrame* pPageFrame = static_cast<const 
SwPageFrame*>(this);
-            (void)xmlTextWriterStartElement(writer, BAD_CAST("page_status"));
-            (void)xmlTextWriterWriteAttribute(writer, 
BAD_CAST("ValidFlyLayout"), 
BAD_CAST(OString::boolean(!pPageFrame->IsInvalidFlyLayout()).getStr()));
-            (void)xmlTextWriterWriteAttribute(writer, 
BAD_CAST("ValidFlyContent"), 
BAD_CAST(OString::boolean(!pPageFrame->IsInvalidFlyContent()).getStr()));
-            (void)xmlTextWriterWriteAttribute(writer, 
BAD_CAST("ValidFlyInCnt"), 
BAD_CAST(OString::boolean(!pPageFrame->IsInvalidFlyInCnt()).getStr()));
-            (void)xmlTextWriterWriteAttribute(writer, BAD_CAST("ValidLayout"), 
BAD_CAST(OString::boolean(!pPageFrame->IsInvalidLayout()).getStr()));
-            (void)xmlTextWriterWriteAttribute(writer, 
BAD_CAST("ValidContent"), 
BAD_CAST(OString::boolean(!pPageFrame->IsInvalidContent()).getStr()));
-            (void)xmlTextWriterEndElement(writer);
-            (void)xmlTextWriterStartElement(writer, BAD_CAST("page_info"));
-            (void)xmlTextWriterWriteFormatAttribute(writer, 
BAD_CAST("phyNum"), "%d", pPageFrame->GetPhyPageNum());
-            (void)xmlTextWriterWriteFormatAttribute(writer, 
BAD_CAST("virtNum"), "%d", pPageFrame->GetVirtPageNum());
-            OUString aFormatName = pPageFrame->GetPageDesc()->GetName();
-            (void)xmlTextWriterWriteFormatAttribute( writer, 
BAD_CAST("pageDesc"), "%s", BAD_CAST(OUStringToOString(aFormatName, 
RTL_TEXTENCODING_UTF8).getStr()));
-            (void)xmlTextWriterEndElement(writer);
-            if (auto const* pObjs = pPageFrame->GetSortedObjs())
-            {
-                (void)xmlTextWriterStartElement(writer, 
BAD_CAST("sorted_objs"));
-                for (SwAnchoredObject const*const pObj : *pObjs)
-                {   // just print pointer, full details will be printed on its 
anchor frame
-                    // this nonsense is needed because of multiple inheritance
-                    if (SwFlyFrame const* pFly = pObj->DynCastFlyFrame())
-                    {
-                        (void)xmlTextWriterStartElement(writer, 
BAD_CAST("fly"));
-                        (void)xmlTextWriterWriteFormatAttribute(writer, 
BAD_CAST("ptr"), "%p", pFly);
-                    }
-                    else
-                    {
-                        (void)xmlTextWriterStartElement(writer, 
BAD_CAST(pObj->getElementName()));
-                        (void)xmlTextWriterWriteFormatAttribute(writer, 
BAD_CAST("ptr"), "%p", pObj);
-                    }
-                    (void)xmlTextWriterEndElement(writer);
-                }
-                (void)xmlTextWriterEndElement(writer);
-            }
-        }
-
         if (IsTextFrame())
         {
             const SwTextFrame *pTextFrame = static_cast<const SwTextFrame 
*>(this);

Reply via email to