diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-05-18 10:51:18 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-05-19 14:38:03 +0200 |
commit | b213abcb77e19fa5d22af45c7ecd17c8a63af554 (patch) | |
tree | 3c068532a667ec0aadeddb5d523854f0fcd49c26 /sw/qa/uibase | |
parent | 85d15cfaf9b0665d907e099d6588dea0ced556ff (diff) |
sw content controls, picture: replace placeholder image on click
Previous content control types (rich text, checkbox, dropdown) had the
cursor somewhere in the content control and click selected the content
control in the placeholder case.
The picture case is somewhat different: the content control has a single
as-char image, and by the time SwWrtShell::GotoContentControl() is
invoked, the picture frame is already selected.
All we have to do here is to trigger the file picker to select a
replacement and then insert that image to replace the already selected
frame's bitmap.
Change-Id: Id3ad94ed8f7e13b0ebc2f57327bb8c0b1e374a86
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134511
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw/qa/uibase')
-rw-r--r-- | sw/qa/uibase/wrtsh/wrtsh.cxx | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/sw/qa/uibase/wrtsh/wrtsh.cxx b/sw/qa/uibase/wrtsh/wrtsh.cxx index 6faf642e10e4..297e7a2d1ebd 100644 --- a/sw/qa/uibase/wrtsh/wrtsh.cxx +++ b/sw/qa/uibase/wrtsh/wrtsh.cxx @@ -25,6 +25,7 @@ #include <wrtsh.hxx> #include <ndtxt.hxx> #include <textcontentcontrol.hxx> +#include <fmtanchr.hxx> namespace { @@ -239,6 +240,51 @@ CPPUNIT_TEST_FIXTURE(Test, testInsertDropdownContentControl) // i.e. the inserted content control was a default (rich text) one, not a dropdown. CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pContentControl->GetListItems().size()); } + +CPPUNIT_TEST_FIXTURE(Test, testReplacePictureContentControl) +{ + // Given a document with a picture content control: + SwDoc* pDoc = createSwDoc(); + uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<beans::XPropertySet> xTextGraphic( + xMSF->createInstance("com.sun.star.text.TextGraphicObject"), uno::UNO_QUERY); + xTextGraphic->setPropertyValue("AnchorType", + uno::Any(text::TextContentAnchorType_AS_CHARACTER)); + uno::Reference<text::XTextContent> xTextContent(xTextGraphic, uno::UNO_QUERY); + xText->insertTextContent(xCursor, xTextContent, false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference<text::XTextContent> xContentControl( + xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + xContentControlProps->setPropertyValue("ShowingPlaceHolder", uno::Any(true)); + xContentControlProps->setPropertyValue("Picture", uno::Any(true)); + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + + // When clicking on that content control: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->GotoObj(/*bNext=*/true, GotoObjFlags::Any); + pWrtShell->EnterSelFrameMode(); + const SwFrameFormat* pFlyFormat = pWrtShell->GetFlyFrameFormat(); + const SwFormatAnchor& rFormatAnchor = pFlyFormat->GetAnchor(); + const SwPosition* pAnchorPos = rFormatAnchor.GetContentAnchor(); + SwTextNode* pTextNode = pAnchorPos->nNode.GetNode().GetTextNode(); + SwTextAttr* pAttr = pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL); + auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr); + auto& rFormatContentControl + = static_cast<SwFormatContentControl&>(pTextContentControl->GetAttr()); + pWrtShell->GotoContentControl(rFormatContentControl); + + // Then make sure that the picture is replaced: + CPPUNIT_ASSERT(!rFormatContentControl.GetContentControl()->GetShowingPlaceHolder()); + // Without the accompanying fix in place, this test would have failed, there was no special + // handling for picture content control (how to interact with them), and the default handler + // killed the image selection. + CPPUNIT_ASSERT(pWrtShell->IsFrameSelected()); +} } CPPUNIT_PLUGIN_IMPLEMENT(); |