sw/qa/uibase/uno/uno.cxx | 27 +++++++++++++++++++++++++++ sw/source/uibase/uno/loktxdoc.cxx | 25 ++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-)
New commits: commit 5257a5277d6414b394aa14477a8a0dc246b303ea Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Feb 12 14:58:36 2025 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Feb 14 15:58:36 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/+/181619 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/uibase/uno/uno.cxx b/sw/qa/uibase/uno/uno.cxx index 046dd88c6861..2848c367a13b 100644 --- a/sw/qa/uibase/uno/uno.cxx +++ b/sw/qa/uibase/uno/uno.cxx @@ -369,6 +369,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 20f7cd9367ba..92108c9f6c22 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"); + auto aCommandValues = rJsonWriter.startNode("commandValues"); + auto 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(); + auto 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: */