desktop/qa/desktop_lib/test_desktop_lib.cxx | 4 +- sc/inc/postit.hxx | 2 + sc/qa/unit/tiledrendering/tiledrendering.cxx | 8 ++-- sc/source/ui/docshell/docsh4.cxx | 25 -------------- sc/source/ui/unoobj/docuno.cxx | 47 ++++++++++++--------------- 5 files changed, 30 insertions(+), 56 deletions(-)
New commits: commit f363777f1c518ed9633596e482d4a11eee17295d Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Mon Jul 31 11:29:05 2023 +0100 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Tue Aug 1 14:55:54 2023 +0200 cool#6911 report the position of comments as cell addresses and leave it to the client to determine the bounds of the cell Change-Id: I20a1bece5d0717c0e099b38610842d4800d6a074 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155088 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index e93cf695068f..8b21f905f71d 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -2407,14 +2407,14 @@ void DesktopLOKTest::testCommentsCalc() { CPPUNIT_ASSERT_EQUAL(std::string("4"), rComment.second.get<std::string>("tab")); CPPUNIT_ASSERT_EQUAL(std::string("Comment1"), rComment.second.get<std::string>("text")); - CPPUNIT_ASSERT_EQUAL(std::string("7650, 3570, 1274, 254"), rComment.second.get<std::string>("cellPos")); + CPPUNIT_ASSERT_EQUAL(std::string("6 14 6 14"), rComment.second.get<std::string>("cellRange")); } break; case 1: { CPPUNIT_ASSERT_EQUAL(std::string("4"), rComment.second.get<std::string>("tab")); CPPUNIT_ASSERT_EQUAL(std::string("Comment2"), rComment.second.get<std::string>("text")); - CPPUNIT_ASSERT_EQUAL(std::string("8925, 4335, 1274, 254"), rComment.second.get<std::string>("cellPos")); + CPPUNIT_ASSERT_EQUAL(std::string("7 17 7 17"), rComment.second.get<std::string>("cellRange")); } break; } diff --git a/sc/inc/postit.hxx b/sc/inc/postit.hxx index 52872b8d650e..828d094e49d1 100644 --- a/sc/inc/postit.hxx +++ b/sc/inc/postit.hxx @@ -155,6 +155,8 @@ public: /** Updates caption position according to position of the passed cell. */ void UpdateCaptionPos( const ScAddress& rPos ); + static OString NoteRangeToJsonString(const ScDocument& rDoc, const ScAddress& rPos); + private: ScPostIt( const ScPostIt& ) = delete; ScPostIt& operator=( const ScPostIt& ) = delete; diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx index 254fb5e8a042..c0fc36968c58 100644 --- a/sc/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx @@ -1110,8 +1110,8 @@ CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, testCommentCallback) CPPUNIT_ASSERT_EQUAL(std::string("LOK User1"), aView2.m_aCommentCallbackResult.get<std::string>("author")); CPPUNIT_ASSERT_EQUAL(std::string("Comment"), aView1.m_aCommentCallbackResult.get<std::string>("text")); CPPUNIT_ASSERT_EQUAL(std::string("Comment"), aView2.m_aCommentCallbackResult.get<std::string>("text")); - CPPUNIT_ASSERT_EQUAL(std::string("0, 255, 1274, 254"), aView1.m_aCommentCallbackResult.get<std::string>("cellPos")); - CPPUNIT_ASSERT_EQUAL(std::string("0, 255, 1274, 254"), aView2.m_aCommentCallbackResult.get<std::string>("cellPos")); + CPPUNIT_ASSERT_EQUAL(std::string("0 1 0 1"), aView1.m_aCommentCallbackResult.get<std::string>("cellRange")); + CPPUNIT_ASSERT_EQUAL(std::string("0 1 0 1"), aView2.m_aCommentCallbackResult.get<std::string>("cellRange")); std::string aCommentId = aView1.m_aCommentCallbackResult.get<std::string>("id"); @@ -1138,8 +1138,8 @@ CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, testCommentCallback) CPPUNIT_ASSERT_EQUAL(std::string("LOK User2"), aView2.m_aCommentCallbackResult.get<std::string>("author")); CPPUNIT_ASSERT_EQUAL(std::string("Edited comment"), aView1.m_aCommentCallbackResult.get<std::string>("text")); CPPUNIT_ASSERT_EQUAL(std::string("Edited comment"), aView2.m_aCommentCallbackResult.get<std::string>("text")); - CPPUNIT_ASSERT_EQUAL(std::string("0, 255, 1274, 254"), aView1.m_aCommentCallbackResult.get<std::string>("cellPos")); - CPPUNIT_ASSERT_EQUAL(std::string("0, 255, 1274, 254"), aView2.m_aCommentCallbackResult.get<std::string>("cellPos")); + CPPUNIT_ASSERT_EQUAL(std::string("0 1 0 1"), aView1.m_aCommentCallbackResult.get<std::string>("cellRange")); + CPPUNIT_ASSERT_EQUAL(std::string("0 1 0 1"), aView2.m_aCommentCallbackResult.get<std::string>("cellRange")); // Delete the comment if (pTabViewShell) diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx index 8c9d227a84ca..7e4370b7e6db 100644 --- a/sc/source/ui/docshell/docsh4.cxx +++ b/sc/source/ui/docshell/docsh4.cxx @@ -2561,30 +2561,7 @@ void ScDocShell::LOKCommentNotify(LOKCommentNotificationType nType, const ScDocu // Calculating the cell cursor position ScViewData* pViewData = GetViewData(); if (pViewData && pViewData->GetActiveWin()) - { - bool bInPrintTwips = comphelper::LibreOfficeKit::isCompatFlagSet( - comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs); - OString aRectString; - if (bInPrintTwips) - { - Point aTopLeft = pViewData->GetPrintTwipsPos(rPos.Col(), rPos.Row()); - tools::Long nSizeX, nSizeY; - pViewData->GetMergeSizePrintTwips(rPos.Col(), rPos.Row(), nSizeX, nSizeY); - aRectString = tools::Rectangle(aTopLeft, Size(nSizeX - 1, nSizeY - 1)).toString(); - } - else - { - Point aTopLeft = pViewData->GetScrPos(rPos.Col(), rPos.Row(), - pViewData->GetActivePart(), true); - tools::Long nSizeXPix, nSizeYPix; - pViewData->GetMergeSizePixel(rPos.Col(), rPos.Row(), nSizeXPix, nSizeYPix); - const double fPPTX = pViewData->GetPPTX(); - const double fPPTY = pViewData->GetPPTY(); - aRectString = tools::Rectangle(Point(aTopLeft.getX() / fPPTX, aTopLeft.getY() / fPPTY), - Size(nSizeXPix / fPPTX, nSizeYPix / fPPTY)).toString(); - } - aAnnotation.put("cellPos", aRectString); - } + aAnnotation.put("cellRange", ScPostIt::NoteRangeToJsonString(*pDocument, rPos)); } boost::property_tree::ptree aTree; diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index fe1cf4dbe6b3..d98731951d17 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -1185,24 +1185,31 @@ void ScModelObj::getPostIts(tools::JsonWriter& rJsonWriter) ScGridWindow* pGridWindow = pViewData->GetActiveWin(); if (pGridWindow) { - SCCOL nX = aNote.maPos.Col(); - SCROW nY = aNote.maPos.Row(); - Point aScrPos = pViewData->GetScrPos(nX, nY, pViewData->GetActivePart(), true); - tools::Long nSizeXPix; - tools::Long nSizeYPix; - pViewData->GetMergeSizePixel(nX, nY, nSizeXPix, nSizeYPix); - - double fPPTX = pViewData->GetPPTX(); - double fPPTY = pViewData->GetPPTY(); - tools::Rectangle aRect(Point(aScrPos.getX() / fPPTX, aScrPos.getY() / fPPTY), - Size(nSizeXPix / fPPTX, nSizeYPix / fPPTY)); - - rJsonWriter.put("cellPos", aRect.toString()); + rJsonWriter.put("cellRange", ScPostIt::NoteRangeToJsonString(rDoc, aNote.maPos)); } } } } +OString ScPostIt::NoteRangeToJsonString(const ScDocument& rDoc, const ScAddress& rPos) +{ + SCCOL nX(rPos.Col()); + SCROW nY(rPos.Row()); + OString aStartCellAddress(OString::number(nX) + " " + OString::number(nY)); + const ScPatternAttr* pMarkPattern = rDoc.GetPattern(nX, nY, rPos.Tab()); + if (pMarkPattern && pMarkPattern->GetItemSet().GetItemState(ATTR_MERGE, false) == SfxItemState::SET) + { + SCCOL nCol = pMarkPattern->GetItem(ATTR_MERGE).GetColMerge(); + if (nCol > 1) + nX += nCol - 1; + SCROW nRow = pMarkPattern->GetItem(ATTR_MERGE).GetRowMerge(); + if (nRow > 1) + nY += nRow - 1; + } + OString aEndCellAddress(OString::number(nX) + " " + OString::number(nY)); + return aStartCellAddress + " " + aEndCellAddress; +} + void ScModelObj::getPostItsPos(tools::JsonWriter& rJsonWriter) { if (!pDocShell) @@ -1226,19 +1233,7 @@ void ScModelObj::getPostItsPos(tools::JsonWriter& rJsonWriter) ScGridWindow* pGridWindow = pViewData->GetActiveWin(); if (pGridWindow) { - SCCOL nX = aNote.maPos.Col(); - SCROW nY = aNote.maPos.Row(); - Point aScrPos = pViewData->GetScrPos(nX, nY, pViewData->GetActivePart(), true); - tools::Long nSizeXPix; - tools::Long nSizeYPix; - pViewData->GetMergeSizePixel(nX, nY, nSizeXPix, nSizeYPix); - - double fPPTX = pViewData->GetPPTX(); - double fPPTY = pViewData->GetPPTY(); - tools::Rectangle aRect(Point(aScrPos.getX() / fPPTX, aScrPos.getY() / fPPTY), - Size(nSizeXPix / fPPTX, nSizeYPix / fPPTY)); - - rJsonWriter.put("cellPos", aRect.toString()); + rJsonWriter.put("cellRange", ScPostIt::NoteRangeToJsonString(rDoc, aNote.maPos)); } } }