summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2022-11-23 20:45:09 -0500
committerJustin Luth <jluth@mail.com>2022-12-03 00:45:41 +0000
commit567c9066933b4c02377368e17a3b32f7ab7c5451 (patch)
tree6eda5a30685d73cf6a1a6821f20ad1d6c770bc84 /sw
parent8d17ad0bb36b5c330e839fdd7517b37fa72002ae (diff)
tdf#151548 ContentControls vba: allow search by name/float
This so-called modern content control is rather terrible for VBA programmers. It has no modifiable ID! Instead, there is a random _signed-integer_ as a unique id. How descriptive... Since it is an integer, it can't be passed to Item(), because then it would be an index lookup. Instead, you can pass it as a float (indicated by a #) or as a _unsigned-integer_ string. Recently the ID was preserved for content control import/export, so we can now round out our VBA to find content controls by name. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba Change-Id: I387a287505e17d3768bad5ed954136e532ca70e6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143196 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/core/data/docm/testModernVBA.docmbin31807 -> 32539 bytes
-rw-r--r--sw/source/ui/vba/vbacontentcontrol.cxx6
-rw-r--r--sw/source/ui/vba/vbacontentcontrols.cxx15
3 files changed, 11 insertions, 10 deletions
diff --git a/sw/qa/core/data/docm/testModernVBA.docm b/sw/qa/core/data/docm/testModernVBA.docm
index be7d99a24b84..49e53b615622 100644
--- a/sw/qa/core/data/docm/testModernVBA.docm
+++ b/sw/qa/core/data/docm/testModernVBA.docm
Binary files differ
diff --git a/sw/source/ui/vba/vbacontentcontrol.cxx b/sw/source/ui/vba/vbacontentcontrol.cxx
index da3f3ec6f4ee..0a156e35c96b 100644
--- a/sw/source/ui/vba/vbacontentcontrol.cxx
+++ b/sw/source/ui/vba/vbacontentcontrol.cxx
@@ -473,9 +473,9 @@ uno::Any SwVbaContentControl::getDropdownListEntries()
OUString SwVbaContentControl::getID()
{
- //const std::shared_ptr<SwContentControl>& pCC = m_rCC.GetContentControl().GetContentControl();
- //return OUString::number(static_cast<sal_uInt32>(pCC->GetId()));
- return OUString();
+ const std::shared_ptr<SwContentControl>& pCC = m_rCC.GetContentControl().GetContentControl();
+ // This signed integer is treated in VBA as if it was an unsigned int.
+ return OUString::number(static_cast<sal_uInt32>(pCC->GetId()));
}
sal_Int32 SwVbaContentControl::getLevel()
diff --git a/sw/source/ui/vba/vbacontentcontrols.cxx b/sw/source/ui/vba/vbacontentcontrols.cxx
index 4ef73f5d196e..e39094df357a 100644
--- a/sw/source/ui/vba/vbacontentcontrols.cxx
+++ b/sw/source/ui/vba/vbacontentcontrols.cxx
@@ -65,15 +65,16 @@ lcl_getContentControl(std::u16string_view sName, std::u16string_view sTag,
&& sTitle != pControl->GetContentControl().GetContentControl()->GetAlias())
continue;
- //OUString sID = OUString::number(static_cast<sal_uInt32>(
- // pControl->GetContentControl().GetContentControl()->GetId()));
- //if (!sName.empty() && sName != sID)
- // continue;
+ // When treated as a name, consider the integer ID to be unsigned
+ const OUString sID = OUString::number(static_cast<sal_uInt32>(
+ pControl->GetContentControl().GetContentControl()->GetId()));
+ if (!sName.empty() && sName != sID)
+ continue;
- //if (pElementNames)
- // vElementNames.push_back(sID);
+ if (pElementNames)
+ vElementNames.push_back(sID);
- if (rIndex == nCounter /*|| !sName.empty()*/)
+ if (rIndex == nCounter || !sName.empty())
break;
pControl = nullptr;