summaryrefslogtreecommitdiff
path: root/include/vbahelper
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 /include/vbahelper
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 'include/vbahelper')
-rw-r--r--include/vbahelper/vbacollectionimpl.hxx17
1 files changed, 13 insertions, 4 deletions
diff --git a/include/vbahelper/vbacollectionimpl.hxx b/include/vbahelper/vbacollectionimpl.hxx
index 90bfb51d59a5..2e5184721a83 100644
--- a/include/vbahelper/vbacollectionimpl.hxx
+++ b/include/vbahelper/vbacollectionimpl.hxx
@@ -294,19 +294,28 @@ public:
virtual css::uno::Any SAL_CALL Item(const css::uno::Any& Index1, const css::uno::Any& /*not processed in this base class*/) override
{
- if ( Index1.getValueTypeClass() != css::uno::TypeClass_STRING )
+ OUString aStringSheet;
+ if (Index1.getValueTypeClass() == css::uno::TypeClass_DOUBLE)
+ {
+ // This is needed for ContentControls, where the unique integer ID
+ // can be passed as float to simulate a "by name" lookup.
+ double fIndex = 0;
+ Index1 >>= fIndex;
+ aStringSheet = OUString::number(fIndex);
+ }
+ else if (Index1.getValueTypeClass() != css::uno::TypeClass_STRING)
{
sal_Int32 nIndex = 0;
-
if ( !( Index1 >>= nIndex ) )
{
throw css::lang::IndexOutOfBoundsException( "Couldn't convert index to Int32" );
}
+
return getItemByIntIndex( nIndex );
}
- OUString aStringSheet;
+ else
+ Index1 >>= aStringSheet;
- Index1 >>= aStringSheet;
return getItemByStringIndex( aStringSheet );
}