From cb95276e6e6bf12a1c06d5c252551e55c788fcb2 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 18 Jun 2020 21:39:30 +0200 Subject: use JsonWriter for the rest of ITiledRenderable and fix bug in buffer reallacotion where mPos pointing at the beginning of the new buffer instead of at the correct index inside it. Change-Id: Ie1ffaa176f6165e2cec85c93adc945312eff38e4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96650 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sw/inc/swmodule.hxx | 3 +- sw/inc/unotxdoc.hxx | 6 ++-- sw/qa/extras/tiledrendering/tiledrendering.cxx | 6 ++-- sw/qa/extras/uiwriter/uiwriter2.cxx | 8 +++-- sw/qa/extras/uiwriter/uiwriter3.cxx | 8 +++-- sw/source/uibase/app/swmodul1.cxx | 26 ++++---------- sw/source/uibase/inc/swruler.hxx | 3 +- sw/source/uibase/misc/swruler.cxx | 47 ++++++++++++-------------- sw/source/uibase/uno/unotxdoc.cxx | 39 ++++++++------------- 9 files changed, 66 insertions(+), 80 deletions(-) (limited to 'sw') diff --git a/sw/inc/swmodule.hxx b/sw/inc/swmodule.hxx index a8c07038b6b7..c4a53dcc3771 100644 --- a/sw/inc/swmodule.hxx +++ b/sw/inc/swmodule.hxx @@ -57,6 +57,7 @@ class SvtCTLOptions; class SvtUserOptions; enum class SwCompareMode; struct SwDBData; +namespace tools { class JsonWriter; } enum class SvViewOpt { DestView, @@ -198,7 +199,7 @@ public: std::size_t GetRedlineAuthor(); OUString const & GetRedlineAuthor(std::size_t nPos); /// See SwXTextDocument::getTrackedChangeAuthors(). - OUString GetRedlineAuthorInfo(); + void GetRedlineAuthorInfo(tools::JsonWriter& rJsonWriter); std::size_t InsertRedlineAuthor(const OUString& rAuthor); void SetRedlineAuthor(const OUString& rAuthor); // for unit tests diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx index 16780ce2edeb..cf950c259c22 100644 --- a/sw/inc/unotxdoc.hxx +++ b/sw/inc/unotxdoc.hxx @@ -438,11 +438,11 @@ public: /// @see vcl::ITiledRenderable::getTrackedChanges(). void getTrackedChanges(tools::JsonWriter&) override; /// @see vcl::ITiledRenderable::getTrackedChangeAuthors(). - OUString getTrackedChangeAuthors() override; + void getTrackedChangeAuthors(tools::JsonWriter& rJsonWriter) override; - OUString getRulerState() override; + void getRulerState(tools::JsonWriter& rJsonWriter) override; /// @see vcl::ITiledRenderable::getPostIts(). - OUString getPostIts() override; + void getPostIts(tools::JsonWriter& rJsonWriter) override; /// @see vcl::ITiledRenderable::executeFromFieldEvent(). virtual void executeFromFieldEvent(const StringMap& aArguments) override; diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 487def29974b..69560ae2bd15 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -49,6 +49,7 @@ #include #include #include +#include static char const DATA_DIRECTORY[] = "/sw/qa/extras/tiledrendering/data/"; @@ -1619,8 +1620,9 @@ void SwTiledRenderingTest::testRedlineColors() pWrtShell->Insert("zzz"); // Assert that info about exactly one author is returned. - OUString aInfo = pXTextDocument->getTrackedChangeAuthors(); - std::stringstream aStream(aInfo.toUtf8().getStr()); + tools::JsonWriter aJsonWriter; + pXTextDocument->getTrackedChangeAuthors(aJsonWriter); + std::stringstream aStream(aJsonWriter.extractAsOString().getStr()); boost::property_tree::ptree aTree; boost::property_tree::read_json(aStream, aTree); CPPUNIT_ASSERT_EQUAL(static_cast(1), aTree.get_child("authors").size()); diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 01d05d963b3c..64e82663bdaf 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -49,6 +49,7 @@ #include #include #include +#include namespace { @@ -2261,8 +2262,11 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testImageComment) // rendering and on the desktop. SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); CPPUNIT_ASSERT(pTextDoc); - OUString aPostits = pTextDoc->getPostIts(); - std::stringstream aStream(aPostits.toUtf8().getStr()); + tools::JsonWriter aJsonWriter; + pTextDoc->getPostIts(aJsonWriter); + char* pChar = aJsonWriter.extractData(); + std::stringstream aStream(pChar); + free(pChar); boost::property_tree::ptree aTree; boost::property_tree::read_json(aStream, aTree); for (const boost::property_tree::ptree::value_type& rValue : aTree.get_child("comments")) diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx index dda897ee2ee3..0f9f3255f990 100644 --- a/sw/qa/extras/uiwriter/uiwriter3.cxx +++ b/sw/qa/extras/uiwriter/uiwriter3.cxx @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -855,8 +856,11 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf132603) dispatchCommand(mxComponent, ".uno:Copy", {}); Scheduler::ProcessEventsToIdle(); - OUString aPostits = pTextDoc->getPostIts(); - std::stringstream aStream(aPostits.toUtf8().getStr()); + tools::JsonWriter aJsonWriter; + pTextDoc->getPostIts(aJsonWriter); + char* pChar = aJsonWriter.extractData(); + std::stringstream aStream(pChar); + free(pChar); boost::property_tree::ptree aTree; boost::property_tree::read_json(aStream, aTree); for (const boost::property_tree::ptree::value_type& rValue : aTree.get_child("comments")) diff --git a/sw/source/uibase/app/swmodul1.cxx b/sw/source/uibase/app/swmodul1.cxx index b6cfe847a59b..cbaf3bdc2d90 100644 --- a/sw/source/uibase/app/swmodul1.cxx +++ b/sw/source/uibase/app/swmodul1.cxx @@ -56,6 +56,7 @@ #include #include +#include #include using namespace ::svx; @@ -433,29 +434,16 @@ static Color lcl_GetAuthorColor(std::size_t nPos) } /// Returns a JSON representation of a redline author. -static boost::property_tree::ptree lcl_AuthorToJson(const OUString& rAuthor, std::size_t nIndex) +void SwModule::GetRedlineAuthorInfo(tools::JsonWriter& rJsonWriter) { - boost::property_tree::ptree aRet; - aRet.put("index", nIndex); - aRet.put("name", rAuthor.toUtf8().getStr()); - aRet.put("color", sal_uInt32(lcl_GetAuthorColor(nIndex))); - return aRet; -} - -OUString SwModule::GetRedlineAuthorInfo() -{ - boost::property_tree::ptree aTable; + auto authorsNode = rJsonWriter.startNode("authors"); for (std::size_t nAuthor = 0; nAuthor < m_pAuthorNames.size(); ++nAuthor) { - boost::property_tree::ptree aAuthor = lcl_AuthorToJson(m_pAuthorNames[nAuthor], nAuthor); - aTable.push_back(std::make_pair("", aAuthor)); + auto authorNode = rJsonWriter.startNode(""); + rJsonWriter.put("index", nAuthor); + rJsonWriter.put("name", m_pAuthorNames[nAuthor]); + rJsonWriter.put("color", sal_uInt32(lcl_GetAuthorColor(nAuthor))); } - - boost::property_tree::ptree aTree; - aTree.add_child("authors", aTable); - std::stringstream aStream; - boost::property_tree::write_json(aStream, aTree); - return OUString::fromUtf8(aStream.str().c_str()); } std::size_t SwModule::InsertRedlineAuthor(const OUString& rAuthor) diff --git a/sw/source/uibase/inc/swruler.hxx b/sw/source/uibase/inc/swruler.hxx index 2dac3e6c7926..6c903f9ca9a5 100644 --- a/sw/source/uibase/inc/swruler.hxx +++ b/sw/source/uibase/inc/swruler.hxx @@ -18,6 +18,7 @@ class SwViewShell; class View; namespace vcl { class Window; } class SwEditWin; +namespace tools { class JsonWriter; } /** * An horizontal ruler with a control for comment panel visibility for Writer. @@ -42,7 +43,7 @@ public: * \param rRect ignored */ virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; - std::string CreateJsonNotification(); + void CreateJsonNotification(tools::JsonWriter& rJsonWriter); private: SwViewShell * mpViewShell; //< Shell to check if there is any comments on doc and their visibility diff --git a/sw/source/uibase/misc/swruler.cxx b/sw/source/uibase/misc/swruler.cxx index 680031a264b8..effe189148dc 100644 --- a/sw/source/uibase/misc/swruler.cxx +++ b/sw/source/uibase/misc/swruler.cxx @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -232,10 +233,8 @@ void SwCommentRuler::MouseButtonDown(const MouseEvent& rMEvt) Invalidate(); } -std::string SwCommentRuler::CreateJsonNotification() +void SwCommentRuler::CreateJsonNotification(tools::JsonWriter& rJsonWriter) { - boost::property_tree::ptree jsonNotif; - // Note that GetMargin1(), GetMargin2(), GetNullOffset(), and GetPageOffset() return values in // pixels. Not twips. So "converting" the returned values with convertTwipToMm100() is quite // wrong. (Also, even if the return values actually were in twips, it is questionable why we @@ -252,35 +251,30 @@ std::string SwCommentRuler::CreateJsonNotification() // without LibreOfficeKit::isActive().) But in both web-based Online and in the iOS app, the // zoom level from the point of view of this code here apparently does not change even if one // zooms from the Online code's point of view. - jsonNotif.put("margin1", convertTwipToMm100(GetMargin1())); - jsonNotif.put("margin2", convertTwipToMm100(GetMargin2())); - jsonNotif.put("leftOffset", convertTwipToMm100(GetNullOffset())); - jsonNotif.put("pageOffset", convertTwipToMm100(GetPageOffset())); + rJsonWriter.put("margin1", convertTwipToMm100(GetMargin1())); + rJsonWriter.put("margin2", convertTwipToMm100(GetMargin2())); + rJsonWriter.put("leftOffset", convertTwipToMm100(GetNullOffset())); + rJsonWriter.put("pageOffset", convertTwipToMm100(GetPageOffset())); // GetPageWidth() on the other hand does return a value in twips. // So here convertTwipToMm100() really does produce actual mm100. Fun. - jsonNotif.put("pageWidth", convertTwipToMm100(GetPageWidth())); - - boost::property_tree::ptree tabs; + rJsonWriter.put("pageWidth", convertTwipToMm100(GetPageWidth())); - // The RulerTab array elements that GetTabs() returns have their nPos field in twips. So these - // too are actual mm100. - for (auto const& tab : GetTabs()) { - boost::property_tree::ptree element; - element.put("position", convertTwipToMm100(tab.nPos)); - element.put("style", tab.nStyle); - tabs.push_back(std::make_pair("", element)); - } + auto tabsNode = rJsonWriter.startNode("tabs"); - jsonNotif.add_child("tabs", tabs); + // The RulerTab array elements that GetTabs() returns have their nPos field in twips. So these + // too are actual mm100. + for (auto const& tab : GetTabs()) + { + auto tabNode = rJsonWriter.startNode(""); + rJsonWriter.put("position", convertTwipToMm100(tab.nPos)); + rJsonWriter.put("style", tab.nStyle); + } + } RulerUnitData aUnitData = GetCurrentRulerUnit(); - jsonNotif.put("unit", aUnitData.aUnitStr); - - std::stringstream aStream; - boost::property_tree::write_json(aStream, jsonNotif); - return aStream.str(); + rJsonWriter.put("unit", aUnitData.aUnitStr); } void SwCommentRuler::NotifyKit() @@ -288,9 +282,10 @@ void SwCommentRuler::NotifyKit() if (!comphelper::LibreOfficeKit::isActive()) return; - const std::string test = CreateJsonNotification(); + tools::JsonWriter aJsonWriter; + CreateJsonNotification(aJsonWriter); mpViewShell->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_RULER_UPDATE, - test.c_str()); + aJsonWriter.extractData()); } void SwCommentRuler::Update() diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 0d934c32f39c..08baf270baff 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -3304,21 +3304,21 @@ void SwXTextDocument::getTrackedChanges(tools::JsonWriter& rJson) } } -OUString SwXTextDocument::getTrackedChangeAuthors() +void SwXTextDocument::getTrackedChangeAuthors(tools::JsonWriter& rJsonWriter) { - return SW_MOD()->GetRedlineAuthorInfo(); + SW_MOD()->GetRedlineAuthorInfo(rJsonWriter); } -OUString SwXTextDocument::getRulerState() +void SwXTextDocument::getRulerState(tools::JsonWriter& rJsonWriter) { SwView* pView = pDocShell->GetView(); - return OUString::fromUtf8(dynamic_cast(pView->GetHRuler()).CreateJsonNotification().c_str()); + dynamic_cast(pView->GetHRuler()).CreateJsonNotification(rJsonWriter); } -OUString SwXTextDocument::getPostIts() +void SwXTextDocument::getPostIts(tools::JsonWriter& rJsonWriter) { SolarMutexGuard aGuard; - boost::property_tree::ptree aAnnotations; + auto commentsNode = rJsonWriter.startNode("comments"); for (auto const& sidebarItem : *pDocShell->GetView()->GetPostItMgr()) { sw::annotation::SwAnnotationWin* pWin = sidebarItem->pPostIt.get(); @@ -3344,25 +3344,16 @@ OUString SwXTextDocument::getPostIts() } const OString sRects = comphelper::string::join("; ", aRects); - boost::property_tree::ptree aAnnotation; - aAnnotation.put("id", pField->GetPostItId()); - aAnnotation.put("parent", pWin->CalcParent()); - aAnnotation.put("author", pField->GetPar1().toUtf8().getStr()); - aAnnotation.put("text", pField->GetPar2().toUtf8().getStr()); - aAnnotation.put("resolved", pField->GetResolved() ? "true" : "false"); - aAnnotation.put("dateTime", utl::toISO8601(pField->GetDateTime().GetUNODateTime())); - aAnnotation.put("anchorPos", aSVRect.toString()); - aAnnotation.put("textRange", sRects.getStr()); - - aAnnotations.push_back(std::make_pair("", aAnnotation)); + auto commentNode = rJsonWriter.startNode(""); + rJsonWriter.put("id", pField->GetPostItId()); + rJsonWriter.put("parent", pWin->CalcParent()); + rJsonWriter.put("author", pField->GetPar1()); + rJsonWriter.put("text", pField->GetPar2()); + rJsonWriter.put("resolved", pField->GetResolved() ? "true" : "false"); + rJsonWriter.put("dateTime", utl::toISO8601(pField->GetDateTime().GetUNODateTime())); + rJsonWriter.put("anchorPos", aSVRect.toString()); + rJsonWriter.put("textRange", sRects); } - - boost::property_tree::ptree aTree; - aTree.add_child("comments", aAnnotations); - std::stringstream aStream; - boost::property_tree::write_json(aStream, aTree); - - return OUString::fromUtf8(aStream.str().c_str()); } void SwXTextDocument::executeFromFieldEvent(const StringMap& aArguments) -- cgit v1.2.3