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 f067ecf3d6e4bc8c506b52fa8b7555b7ab29546e Author: Caolán McNamara <[email protected]> AuthorDate: Mon Jul 31 11:29:05 2023 +0100 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Fri Aug 4 14:14:15 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/+/155044 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index fd79c43d9a1a..d20c78315a63 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -2487,14 +2487,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 36473542e1df..a7bfe873e0ed 100644 --- a/sc/inc/postit.hxx +++ b/sc/inc/postit.hxx @@ -157,6 +157,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 58cb5732ea6b..81143b845b44 100644 --- a/sc/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx @@ -1264,8 +1264,8 @@ void 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"); @@ -1293,8 +1293,8 @@ void 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 9adcb466c6bc..91ee281523f4 100644 --- a/sc/source/ui/docshell/docsh4.cxx +++ b/sc/source/ui/docshell/docsh4.cxx @@ -2549,30 +2549,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 971c75b22c22..d044e197235c 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)); } } }
