sw/source/core/inc/rootfrm.hxx  |    2 +
 sw/source/core/layout/wsfrm.cxx |   48 ++++++++++++++++++++++++++++++++++++++++
 sw/source/core/text/xmldump.cxx |   48 ----------------------------------------
 3 files changed, 50 insertions(+), 48 deletions(-)

New commits:
commit 78a158211b68a020512cd63a1f357f901f879e53
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Thu Feb 23 20:01:43 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Feb 24 07:01:23 2023 +0000

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

diff --git a/sw/source/core/inc/rootfrm.hxx b/sw/source/core/inc/rootfrm.hxx
index 32344bf0d9c0..2243759d4dda 100644
--- a/sw/source/core/inc/rootfrm.hxx
+++ b/sw/source/core/inc/rootfrm.hxx
@@ -426,6 +426,8 @@ public:
     void SetFieldmarkMode(sw::FieldmarkMode, sw::ParagraphBreakMode);
     sw::ParagraphBreakMode GetParagraphBreakMode() const { return 
m_ParagraphBreakMode; }
     bool HasMergedParas() const;
+
+    void dumpAsXml(xmlTextWriterPtr writer = nullptr) const override;
 };
 
 inline tools::Long SwRootFrame::GetBrowseWidth() const
diff --git a/sw/source/core/layout/wsfrm.cxx b/sw/source/core/layout/wsfrm.cxx
index f753a993aceb..5a31c3c0a2d5 100644
--- a/sw/source/core/layout/wsfrm.cxx
+++ b/sw/source/core/layout/wsfrm.cxx
@@ -24,6 +24,7 @@
 #include <o3tl/safeint.hxx>
 #include <svl/itemiter.hxx>
 #include <editeng/brushitem.hxx>
+#include <sfx2/viewsh.hxx>
 #include <fmtornt.hxx>
 #include <pagefrm.hxx>
 #include <section.hxx>
@@ -63,6 +64,7 @@
 #include <layact.hxx>
 #include <ndtxt.hxx>
 #include <swtable.hxx>
+#include <view.hxx>
 
 // RotateFlyFrame3
 #include <basegfx/matrix/b2dhommatrixtools.hxx>
@@ -4754,4 +4756,50 @@ bool SwRootFrame::HasMergedParas() const
         || GetParagraphBreakMode() == sw::ParagraphBreakMode::Hidden;
 }
 
+namespace {
+    xmlTextWriterPtr lcl_createDefaultWriter()
+    {
+        xmlTextWriterPtr writer = xmlNewTextWriterFilename( "layout.xml", 0 );
+        xmlTextWriterSetIndent(writer,1);
+        (void)xmlTextWriterSetIndentString(writer, BAD_CAST("  "));
+        (void)xmlTextWriterStartDocument( writer, nullptr, nullptr, nullptr );
+        return writer;
+    }
+
+    void lcl_freeWriter( xmlTextWriterPtr writer )
+    {
+        (void)xmlTextWriterEndDocument( writer );
+        xmlFreeTextWriter( writer );
+    }
+}
+
+void SwRootFrame::dumpAsXml(xmlTextWriterPtr writer) const
+{
+    bool bCreateWriter = (nullptr == writer);
+    if (bCreateWriter)
+        writer = lcl_createDefaultWriter();
+
+    (void)xmlTextWriterStartElement(writer, reinterpret_cast<const 
xmlChar*>("root"));
+    dumpAsXmlAttributes(writer);
+
+    (void)xmlTextWriterStartElement(writer, BAD_CAST("sfxViewShells"));
+    SwView* pView = static_cast<SwView*>(SfxViewShell::GetFirst(true, 
checkSfxViewShell<SwView>));
+    while (pView)
+    {
+        if (GetCurrShell()->GetSfxViewShell() && pView->GetObjectShell() == 
GetCurrShell()->GetSfxViewShell()->GetObjectShell())
+            pView->dumpAsXml(writer);
+        pView = static_cast<SwView*>(SfxViewShell::GetNext(*pView, true, 
checkSfxViewShell<SwView>));
+    }
+    (void)xmlTextWriterEndElement(writer);
+
+    (void)xmlTextWriterStartElement(writer, BAD_CAST("infos"));
+    dumpInfosAsXml(writer);
+    (void)xmlTextWriterEndElement(writer);
+    dumpChildrenAsXml(writer);
+    (void)xmlTextWriterEndElement(writer);
+
+    if (bCreateWriter)
+        lcl_freeWriter(writer);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/xmldump.cxx b/sw/source/core/text/xmldump.cxx
index 3fc64f1be7a2..f9f3f8a757eb 100644
--- a/sw/source/core/text/xmldump.cxx
+++ b/sw/source/core/text/xmldump.cxx
@@ -157,23 +157,6 @@ const char* sw::PortionTypeToString(PortionType nType)
     }
 }
 
-namespace {
-    xmlTextWriterPtr lcl_createDefaultWriter()
-    {
-        xmlTextWriterPtr writer = xmlNewTextWriterFilename( "layout.xml", 0 );
-        xmlTextWriterSetIndent(writer,1);
-        (void)xmlTextWriterSetIndentString(writer, BAD_CAST("  "));
-        (void)xmlTextWriterStartDocument( writer, nullptr, nullptr, nullptr );
-        return writer;
-    }
-
-    void lcl_freeWriter( xmlTextWriterPtr writer )
-    {
-        (void)xmlTextWriterEndDocument( writer );
-        xmlFreeTextWriter( writer );
-    }
-}
-
 void SwFrame::dumpTopMostAsXml(xmlTextWriterPtr writer) const
 {
     const SwFrame* pFrame = this;
@@ -187,17 +170,10 @@ void SwFrame::dumpTopMostAsXml(xmlTextWriterPtr writer) 
const
 
 void SwFrame::dumpAsXml( xmlTextWriterPtr writer ) const
 {
-    bool bCreateWriter = ( nullptr == writer );
-    if ( bCreateWriter )
-        writer = lcl_createDefaultWriter();
-
     const char *name = nullptr;
 
     switch ( GetType(  ) )
     {
-    case SwFrameType::Root:
-        name = "root";
-        break;
     case SwFrameType::Page:
         name = "page";
         break;
@@ -249,20 +225,6 @@ void SwFrame::dumpAsXml( xmlTextWriterPtr writer ) const
 
         dumpAsXmlAttributes( writer );
 
-        if (IsRootFrame())
-        {
-            const SwRootFrame* pRootFrame = static_cast<const 
SwRootFrame*>(this);
-            (void)xmlTextWriterStartElement(writer, BAD_CAST("sfxViewShells"));
-            SwView* pView = static_cast<SwView*>(SfxViewShell::GetFirst(true, 
checkSfxViewShell<SwView>));
-            while (pView)
-            {
-                if (pRootFrame->GetCurrShell()->GetSfxViewShell() && 
pView->GetObjectShell() == 
pRootFrame->GetCurrShell()->GetSfxViewShell()->GetObjectShell())
-                    pView->dumpAsXml(writer);
-                pView = static_cast<SwView*>(SfxViewShell::GetNext(*pView, 
true, checkSfxViewShell<SwView>));
-            }
-            (void)xmlTextWriterEndElement(writer);
-        }
-
         if (IsPageFrame())
         {
             const SwPageFrame* pPageFrame = static_cast<const 
SwPageFrame*>(this);
@@ -403,9 +365,6 @@ void SwFrame::dumpAsXml( xmlTextWriterPtr writer ) const
         }
         (void)xmlTextWriterEndElement( writer );
     }
-
-    if ( bCreateWriter )
-        lcl_freeWriter( writer );
 }
 
 void SwFrame::dumpInfosAsXml( xmlTextWriterPtr writer ) const
@@ -494,10 +453,6 @@ void SwFrame::dumpChildrenAsXml( xmlTextWriterPtr writer ) 
const
 
 void SwAnchoredObject::dumpAsXml( xmlTextWriterPtr writer ) const
 {
-    bool bCreateWriter = ( nullptr == writer );
-    if ( bCreateWriter )
-        writer = lcl_createDefaultWriter();
-
     (void)xmlTextWriterStartElement( writer, BAD_CAST( getElementName() ) );
     (void)xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "ptr" ), "%p", 
this );
     (void)xmlTextWriterWriteAttribute(writer, BAD_CAST("anchor-frame"), 
BAD_CAST(OString::number(mpAnchorFrame->GetFrameId()).getStr()));
@@ -516,9 +471,6 @@ void SwAnchoredObject::dumpAsXml( xmlTextWriterPtr writer ) 
const
         pObject->dumpAsXml(writer);
 
     (void)xmlTextWriterEndElement( writer );
-
-    if ( bCreateWriter )
-        lcl_freeWriter( writer );
 }
 
 void SwFont::dumpAsXml(xmlTextWriterPtr writer) const

Reply via email to