From affe8a36c977d396e1e229b0d656cc8c2c062132 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Mon, 29 Jun 2020 14:26:26 +0200 Subject: sd: support changing position with .uno:EditAnnotation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ie5c683c06079e4d77d42b242c60cf67257db5c16 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97421 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- include/svx/svxids.hrc | 3 ++ sd/qa/unit/tiledrendering/tiledrendering.cxx | 50 ++++++++++++++++++++++++++ sd/source/ui/annotations/annotationmanager.cxx | 28 ++++++++++++--- svx/sdi/svx.sdi | 7 +++- 4 files changed, 83 insertions(+), 5 deletions(-) diff --git a/include/svx/svxids.hrc b/include/svx/svxids.hrc index be93603f8444..9081fe0f36f6 100644 --- a/include/svx/svxids.hrc +++ b/include/svx/svxids.hrc @@ -221,6 +221,9 @@ class SvxSetItem; // CAUTION! Range <64 .. 67> used by EditEngine (!) +#define SID_ATTR_POSTIT_POSITION_X TypedWhichId( SID_SVX_START + 68 ) +#define SID_ATTR_POSTIT_POSITION_Y TypedWhichId( SID_SVX_START + 69 ) + #define SID_RULER_CHANGE_STATE ( SID_SVX_START + 78 ) #define SID_RULER_NULL_OFFSET TypedWhichId( SID_SVX_START + 79 ) #define SID_RULER_BORDERS TypedWhichId( SID_SVX_START + 80 ) diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index 8eef1f6733dd..647d01dbe2b1 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -111,6 +111,7 @@ public: void testTdf81754(); void testTdf105502(); void testCommentCallbacks(); + void testCommentChange(); void testMultiViewInsertDeletePage(); void testDisableUndoRepair(); void testDocumentRepair(); @@ -161,6 +162,7 @@ public: CPPUNIT_TEST(testTdf81754); CPPUNIT_TEST(testTdf105502); CPPUNIT_TEST(testCommentCallbacks); + CPPUNIT_TEST(testCommentChange); CPPUNIT_TEST(testMultiViewInsertDeletePage); CPPUNIT_TEST(testDisableUndoRepair); CPPUNIT_TEST(testDocumentRepair); @@ -1807,6 +1809,54 @@ void SdTiledRenderingTest::testCommentCallbacks() comphelper::LibreOfficeKit::setTiledAnnotations(true); } +void SdTiledRenderingTest::testCommentChange() +{ + uno::Sequence aArgs; + + // Load the document. + // Set the tiled annotations off + comphelper::LibreOfficeKit::setTiledAnnotations(false); + + createDoc("dummy.odp", comphelper::InitPropertySequence( + { + {".uno:Author", uno::makeAny(OUString("LOK User1"))}, + })); + + ViewCallback aView1; + + // Add a new comment + aArgs = comphelper::InitPropertySequence( + { + {"Text", uno::makeAny(OUString("Comment"))}, + }); + comphelper::dispatchCommand(".uno:InsertAnnotation", aArgs); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(std::string("Add"), aView1.m_aCommentCallbackResult.get("action")); + + int nComment1 = aView1.m_aCommentCallbackResult.get("id"); + + CPPUNIT_ASSERT(!aView1.m_aCommentCallbackResult.get("parthash").empty()); + CPPUNIT_ASSERT_EQUAL(std::string("Comment"), aView1.m_aCommentCallbackResult.get("text")); + CPPUNIT_ASSERT_EQUAL(std::string("0, 0, 0, 0"), aView1.m_aCommentCallbackResult.get("rectangle")); + + // Edit this annotation now + aArgs = comphelper::InitPropertySequence( + { + {"Id", uno::makeAny(OUString::number(nComment1))}, + {"PositionX", uno::makeAny(sal_Int32(10))}, + {"PositionY", uno::makeAny(sal_Int32(20))} + }); + comphelper::dispatchCommand(".uno:EditAnnotation", aArgs); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(std::string("Modify"), aView1.m_aCommentCallbackResult.get("action")); + CPPUNIT_ASSERT_EQUAL(std::string("Comment"), aView1.m_aCommentCallbackResult.get("text")); + CPPUNIT_ASSERT_EQUAL(std::string("10, 20, 0, 0"), aView1.m_aCommentCallbackResult.get("rectangle")); + + comphelper::LibreOfficeKit::setTiledAnnotations(true); +} + void SdTiledRenderingTest::testMultiViewInsertDeletePage() { // Load the document. diff --git a/sd/source/ui/annotations/annotationmanager.cxx b/sd/source/ui/annotations/annotationmanager.cxx index 512ed85a786d..4edab188efab 100644 --- a/sd/source/ui/annotations/annotationmanager.cxx +++ b/sd/source/ui/annotations/annotationmanager.cxx @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -389,6 +390,9 @@ void AnnotationManagerImpl::ExecuteEditAnnotation(SfxRequest const & rReq) Reference< XAnnotation > xAnnotation; sal_uInt32 nId = 0; OUString sText; + sal_Int32 nPositionX = -1; + sal_Int32 nPositionY = -1; + if (!pArgs) return; @@ -404,13 +408,29 @@ void AnnotationManagerImpl::ExecuteEditAnnotation(SfxRequest const & rReq) if (SfxItemState::SET == pArgs->GetItemState(SID_ATTR_POSTIT_TEXT, true, &pPoolItem)) sText = static_cast(pPoolItem)->GetValue(); - if (xAnnotation.is() && !sText.isEmpty()) + if (SfxItemState::SET == pArgs->GetItemState(SID_ATTR_POSTIT_POSITION_X, true, &pPoolItem)) + nPositionX = static_cast(pPoolItem)->GetValue(); + + if (SfxItemState::SET == pArgs->GetItemState(SID_ATTR_POSTIT_POSITION_Y, true, &pPoolItem)) + nPositionY = static_cast(pPoolItem)->GetValue(); + + if (xAnnotation.is()) { CreateChangeUndo(xAnnotation); - // TODO: Not allow other authors to change others' comments ? - Reference xText(xAnnotation->getTextRange()); - xText->setString(sText); + if (nPositionX >= 0 && nPositionY >= 0) + { + double fX = convertTwipToMm100(nPositionX) / 100.0; + double fY = convertTwipToMm100(nPositionY) / 100.0; + xAnnotation->setPosition({fX, fY}); + } + + if (!sText.isEmpty()) + { + // TODO: Not allow other authors to change others' comments ? + Reference xText(xAnnotation->getTextRange()); + xText->setString(sText); + } LOKCommentNotifyAll(CommentNotificationType::Modify, xAnnotation); } diff --git a/svx/sdi/svx.sdi b/svx/sdi/svx.sdi index fcf88f0f0659..738d3bc671fb 100644 --- a/svx/sdi/svx.sdi +++ b/svx/sdi/svx.sdi @@ -4501,7 +4501,12 @@ SfxVoidItem InsertAnnotation SID_INSERT_POSTIT ] SfxVoidItem EditAnnotation SID_EDIT_POSTIT -(SvxPostItIdItem Id SID_ATTR_POSTIT_ID,SvxPostItAuthorItem Author SID_ATTR_POSTIT_AUTHOR,SvxPostItDateItem Date SID_ATTR_POSTIT_DATE,SvxPostItTextItem Text SID_ATTR_POSTIT_TEXT) +(SvxPostItIdItem Id SID_ATTR_POSTIT_ID, + SvxPostItAuthorItem Author SID_ATTR_POSTIT_AUTHOR, + SvxPostItDateItem Date SID_ATTR_POSTIT_DATE, + SvxPostItTextItem Text SID_ATTR_POSTIT_TEXT, + SfxInt32Item PositionX SID_ATTR_POSTIT_POSITION_X + SfxInt32Item PositionY SID_ATTR_POSTIT_POSITION_Y) [ AutoUpdate = FALSE, FastCall = FALSE, -- cgit