sd: support changing position with .uno:EditAnnotation

Change-Id: Ie5c683c06079e4d77d42b242c60cf67257db5c16
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97421
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
This commit is contained in:
Tomaž Vajngerl
2020-06-29 14:26:26 +02:00
committed by Tomaž Vajngerl
parent 0760b11c59
commit affe8a36c9
4 changed files with 83 additions and 5 deletions

View File

@@ -221,6 +221,9 @@ class SvxSetItem;
// CAUTION! Range <64 .. 67> used by EditEngine (!)
#define SID_ATTR_POSTIT_POSITION_X TypedWhichId<SfxInt32Item>( SID_SVX_START + 68 )
#define SID_ATTR_POSTIT_POSITION_Y TypedWhichId<SfxInt32Item>( SID_SVX_START + 69 )
#define SID_RULER_CHANGE_STATE ( SID_SVX_START + 78 )
#define SID_RULER_NULL_OFFSET TypedWhichId<SfxPointItem>( SID_SVX_START + 79 )
#define SID_RULER_BORDERS TypedWhichId<SvxRulerItem>( SID_SVX_START + 80 )

View File

@@ -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<beans::PropertyValue> 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<std::string>("action"));
int nComment1 = aView1.m_aCommentCallbackResult.get<int>("id");
CPPUNIT_ASSERT(!aView1.m_aCommentCallbackResult.get<std::string>("parthash").empty());
CPPUNIT_ASSERT_EQUAL(std::string("Comment"), aView1.m_aCommentCallbackResult.get<std::string>("text"));
CPPUNIT_ASSERT_EQUAL(std::string("0, 0, 0, 0"), aView1.m_aCommentCallbackResult.get<std::string>("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<std::string>("action"));
CPPUNIT_ASSERT_EQUAL(std::string("Comment"), aView1.m_aCommentCallbackResult.get<std::string>("text"));
CPPUNIT_ASSERT_EQUAL(std::string("10, 20, 0, 0"), aView1.m_aCommentCallbackResult.get<std::string>("rectangle"));
comphelper::LibreOfficeKit::setTiledAnnotations(true);
}
void SdTiledRenderingTest::testMultiViewInsertDeletePage()
{
// Load the document.

View File

@@ -33,6 +33,7 @@
#include <sal/macros.h>
#include <svl/itempool.hxx>
#include <svl/intitem.hxx>
#include <unotools/localedatawrapper.hxx>
#include <unotools/useroptions.hxx>
#include <unotools/syslocale.hxx>
@@ -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<const SfxStringItem*>(pPoolItem)->GetValue();
if (xAnnotation.is() && !sText.isEmpty())
if (SfxItemState::SET == pArgs->GetItemState(SID_ATTR_POSTIT_POSITION_X, true, &pPoolItem))
nPositionX = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
if (SfxItemState::SET == pArgs->GetItemState(SID_ATTR_POSTIT_POSITION_Y, true, &pPoolItem))
nPositionY = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
if (xAnnotation.is())
{
CreateChangeUndo(xAnnotation);
// TODO: Not allow other authors to change others' comments ?
Reference<XText> 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> xText(xAnnotation->getTextRange());
xText->setString(sText);
}
LOKCommentNotifyAll(CommentNotificationType::Modify, xAnnotation);
}

View File

@@ -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,