diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-04-07 09:11:09 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-04-07 10:57:04 +0200 |
commit | 07a1442b2441cc032c05fd9abf5b1a8db6c7e007 (patch) | |
tree | ff55f3f4b52c2b208becaecd709af3f39595487b /sw/qa/uibase | |
parent | 9a773e8ca65ccb30cdfbf47b94aabe356df8cad2 (diff) |
sw content controls: select the content on click when showing placeholder
- teach SwCursorShell::GetContentAtPos() about a new IsAttrAtPos::ContentControl
- add a new SwCursorShell::GotoFormatContentControl() to select a
content control, and a SwWrtShell::GotoContentControl() wrapper around
it
- combine these together in SwEditWin::MouseButtonUp()
The intention is that when you open a document and you click on a
placeholder text like "Click here to enter text", then this content is
pre-selected (so typing overwrites it), but typing real content there
disables this behavior.
Change-Id: Ia539865da7b18c41cbfb398282842bdb2e25f0bc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132652
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/qa/uibase')
-rw-r--r-- | sw/qa/uibase/wrtsh/wrtsh.cxx | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/sw/qa/uibase/wrtsh/wrtsh.cxx b/sw/qa/uibase/wrtsh/wrtsh.cxx index 9f63ed2fc7e6..d73ba55ef09f 100644 --- a/sw/qa/uibase/wrtsh/wrtsh.cxx +++ b/sw/qa/uibase/wrtsh/wrtsh.cxx @@ -13,6 +13,7 @@ #include <com/sun/star/text/XTextContent.hpp> #include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/text/XTextDocument.hpp> #include <rtl/ustring.hxx> #include <sal/types.h> @@ -21,6 +22,8 @@ #include <docsh.hxx> #include <formatlinebreak.hxx> #include <wrtsh.hxx> +#include <ndtxt.hxx> +#include <textcontentcontrol.hxx> namespace { @@ -51,6 +54,42 @@ CPPUNIT_TEST_FIXTURE(Test, testInsertLineBreak) auto eClear = getProperty<sal_Int16>(xLineBreak, "Clear"); CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(SwLineBreakClear::ALL), eClear); } + +CPPUNIT_TEST_FIXTURE(Test, testGotoContentControl) +{ + // Given a document with a 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(); + xText->insertString(xCursor, "test", /*bAbsorb=*/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::makeAny(true)); + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + + // When going to that content control in placeholder mode: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SwNodeOffset nIndex = pWrtShell->GetCursor()->GetNode().GetIndex(); + SwTextNode* pTextNode = pDoc->GetNodes()[nIndex]->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 content control is selected (without the dummy character): + // Without the accompanying fix in place, this test would have failed, the user had to manually + // select the placeholder text. + sal_Int32 nStart = pWrtShell->GetCursor()->Start()->nContent.GetIndex(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), nStart); + sal_Int32 nEnd = pWrtShell->GetCursor()->End()->nContent.GetIndex(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5), nEnd); +} } CPPUNIT_PLUGIN_IMPLEMENT(); |