sw/qa/uibase/uno/uno.cxx          |   27 +++++++++++++++++++++++++++
 sw/source/uibase/uno/loktxdoc.cxx |   25 ++++++++++++++++++++++++-
 2 files changed, 51 insertions(+), 1 deletion(-)

New commits:
commit 1dc070a7389d3a7d43c862bc7f757f0ce714fc0a
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed Feb 12 14:58:36 2025 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Thu Feb 13 13:53:29 2025 +0100

    cool#11064 sw lok: expose if layout pages have invalid content
    
    This is meant to help test writing on the LOK client side, for example
    this allows dispatching a command and once the poll callback of the LOK
    client is invoked, we can now check if the layout is fully done (slower)
    or the poll callback is invoked earlier (faster).
    
    Change-Id: I56ab4e6fe46f07a205a197c5b7aa5bb15b3ef676
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181491
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sw/qa/uibase/uno/uno.cxx b/sw/qa/uibase/uno/uno.cxx
index 3e6d9c93d51c..7b4e320d75dc 100644
--- a/sw/qa/uibase/uno/uno.cxx
+++ b/sw/qa/uibase/uno/uno.cxx
@@ -375,6 +375,33 @@ CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetFields)
                          aRef.get<std::string>("name"));
 }
 
+CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetLayout)
+{
+    // Given a document with 2 pages:
+    createSwDoc();
+    SwDoc* pDoc = getSwDoc();
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    pWrtShell->InsertPageBreak();
+
+    // When getting info about the layout:
+    tools::JsonWriter aJsonWriter;
+    std::string_view aCommand(".uno:Layout");
+    auto pXTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    pXTextDocument->getCommandValues(aJsonWriter, aCommand);
+
+    // Then make sure we get the 2 pages:
+    OString pJSON(aJsonWriter.finishAndGetAsOString());
+    std::stringstream aStream((std::string(pJSON)));
+    boost::property_tree::ptree aTree;
+    boost::property_tree::read_json(aStream, aTree);
+    auto aPages = aTree.get_child("commandValues").get_child("pages");
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aPages.count(""));
+    for (const auto& rPage : aPages)
+    {
+        CPPUNIT_ASSERT(!rPage.second.get<bool>("isInvalidContent"));
+    }
+}
+
 CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetTextFormField)
 {
     // Given a document with a fieldmark:
diff --git a/sw/source/uibase/uno/loktxdoc.cxx 
b/sw/source/uibase/uno/loktxdoc.cxx
index c19a39a81b4f..fe844e942de3 100644
--- a/sw/source/uibase/uno/loktxdoc.cxx
+++ b/sw/source/uibase/uno/loktxdoc.cxx
@@ -43,6 +43,8 @@
 #include <unoport.hxx>
 #include <unoprnms.hxx>
 #include <unocontentcontrol.hxx>
+#include <rootfrm.hxx>
+#include <pagefrm.hxx>
 #include <com/sun/star/text/XTextContent.hpp>
 
 #include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp>
@@ -344,6 +346,22 @@ void GetFields(tools::JsonWriter& rJsonWriter, SwDocShell* 
pDocShell,
     }
 }
 
+/// Implements getCommandValues(".uno:Layout").
+void GetLayout(tools::JsonWriter& rJsonWriter, SwDocShell* pDocShell)
+{
+    rJsonWriter.put("commandName", ".uno:Layout");
+    tools::ScopedJsonWriterNode aCommandValues = 
rJsonWriter.startNode("commandValues");
+    tools::ScopedJsonWriterArray aPages = rJsonWriter.startArray("pages");
+    SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+    SwRootFrame* pLayout = pWrtShell->GetLayout();
+    for (SwFrame* pFrame = pLayout->GetLower(); pFrame; pFrame = 
pFrame->GetNext())
+    {
+        auto pPage = pFrame->DynCastPageFrame();
+        tools::ScopedJsonWriterStruct aPage = rJsonWriter.startStruct();
+        rJsonWriter.put("isInvalidContent", pPage->IsInvalidContent());
+    }
+}
+
 /// Implements getCommandValues(".uno:Field").
 ///
 /// Parameters:
@@ -870,7 +888,7 @@ bool SwXTextDocument::supportsCommand(std::u16string_view 
rCommand)
     static const std::initializer_list<std::u16string_view> vForward
         = { u"TextFormFields", u"TextFormField", u"SetDocumentProperties",
             u"Bookmarks",      u"Fields",        u"Sections",
-            u"Bookmark",       u"Field" };
+            u"Bookmark",       u"Field",         u"Layout" };
 
     return std::find(vForward.begin(), vForward.end(), rCommand) != 
vForward.end();
 }
@@ -886,6 +904,7 @@ void SwXTextDocument::getCommandValues(tools::JsonWriter& 
rJsonWriter, std::stri
     static constexpr OStringLiteral aBookmark(".uno:Bookmark");
     static constexpr OStringLiteral aField(".uno:Field");
     static constexpr OStringLiteral 
aExtractDocStructure(".uno:ExtractDocumentStructure");
+    static constexpr OStringLiteral aLayout(".uno:Layout");
 
     std::map<OUString, OUString> aMap
         = SfxLokHelper::parseCommandParameters(OUString::fromUtf8(rCommand));
@@ -936,6 +955,10 @@ void SwXTextDocument::getCommandValues(tools::JsonWriter& 
rJsonWriter, std::stri
         GetDocStructure(rJsonWriter, m_pDocShell, aMap, xContentControls);
         GetDocStructureDocProps(rJsonWriter, m_pDocShell, aMap);
     }
+    else if (o3tl::starts_with(rCommand, aLayout))
+    {
+        GetLayout(rJsonWriter, m_pDocShell);
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to