diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-05-03 09:44:01 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-05-03 14:04:51 +0200 |
commit | 0a415b92d3c1ea2c5befd30b4ac29442f422a41d (patch) | |
tree | 0c88c08e85e875b83bf4f75f99361e4997319d96 /sw/qa | |
parent | 27588f9728eb9c6be19fcf69fd1c3a56285b4c1d (diff) |
sw content controls, drop-down: add doc model & UNO API
Add a new property, which is a list of display-text / value pairs. If
the list is non-empty, that implies that the type is a dropdown.
This should be enough for the UI to be able to provide a list of choices
& update dropdown state on click.
Note that in contrast to dropdown field-marks, here each entry has a
user-readable string and a machine-readable value. Fieldmarks only had a
single value.
Change-Id: I22b9f554e2e1a9e84cc7eb7e17772ea1a5775316
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133742
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/qa')
-rw-r--r-- | sw/qa/core/unocore/unocore.cxx | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/sw/qa/core/unocore/unocore.cxx b/sw/qa/core/unocore/unocore.cxx index 0f1b6a5e7623..f941c60c4aaf 100644 --- a/sw/qa/core/unocore/unocore.cxx +++ b/sw/qa/core/unocore/unocore.cxx @@ -456,6 +456,57 @@ CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testContentControlCheckbox) CPPUNIT_ASSERT_EQUAL(OUString(u"☐"), pContentControl->GetUncheckedState()); } +CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testContentControlDropdown) +{ + // Given an empty document: + SwDoc* pDoc = createSwDoc(); + + // When inserting a dropdown content control: + 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); + { + uno::Sequence<beans::PropertyValues> aListItems = { + { + comphelper::makePropertyValue("DisplayText", uno::makeAny(OUString("red"))), + comphelper::makePropertyValue("Value", uno::makeAny(OUString("R"))), + }, + { + comphelper::makePropertyValue("DisplayText", uno::makeAny(OUString("green"))), + comphelper::makePropertyValue("Value", uno::makeAny(OUString("G"))), + }, + { + comphelper::makePropertyValue("DisplayText", uno::makeAny(OUString("blue"))), + comphelper::makePropertyValue("Value", uno::makeAny(OUString("B"))), + }, + }; + // Without the accompanying fix in place, this test would have failed with: + // An uncaught exception of type com.sun.star.beans.UnknownPropertyException + xContentControlProps->setPropertyValue("ListItems", uno::makeAny(aListItems)); + } + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + + // Then make sure that the specified properties are set: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SwTextNode* pTextNode = pWrtShell->GetCursor()->GetNode().GetTextNode(); + SwTextAttr* pAttr = pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL); + auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr); + auto& rFormatContentControl + = static_cast<SwFormatContentControl&>(pTextContentControl->GetAttr()); + SwContentControl* pContentControl = rFormatContentControl.GetContentControl(); + std::vector<SwContentControlListItem> aListItems = pContentControl->GetListItems(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aListItems.size()); + CPPUNIT_ASSERT_EQUAL(OUString("red"), aListItems[0].m_aDisplayText); + CPPUNIT_ASSERT_EQUAL(OUString("R"), aListItems[0].m_aValue); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |