diff options
author | Justin Luth <jluth@mail.com> | 2023-06-26 20:14:17 -0400 |
---|---|---|
committer | Justin Luth <jluth@mail.com> | 2023-06-27 04:06:26 +0200 |
commit | 609a1567d0e60ca11800df56059b97b6a61ad117 (patch) | |
tree | 37ff252f7f95e6d84cb70fbf686fbc781ca33f5d | |
parent | tdf#123026 sc xlsx: provide per-sheet optimal row height setting (diff) | |
download | core-609a1567d0e60ca11800df56059b97b6a61ad117.tar.gz core-609a1567d0e60ca11800df56059b97b6a61ad117.zip |
tdf#151548 ContentControls vba: allow search by float #2
I don't know how to figure out where the basic parsing
is mishandling the double-specifier of "#",
so just hack in a re-attempt to find a control with the
name of an unfound index.
This should be fine. If it really was specifying an index,
then it won't get to this code.
If the number is larger than the index and a control exists
with that id, then it almost certainly was intended as a name.
If by some chance it wasn't, then instead of the code failing,
it will actually go ahead with the operation.
Since in practical terms this won't happen,
just go ahead and fix the likely case of a
positive-number-as-a-name control not being found.
Change-Id: I2a34184d86b99a50fdc6b806264f1d5e7794ad48
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153630
Tested-by: Jenkins
Reviewed-by: Justin Luth <jluth@mail.com>
-rw-r--r-- | sw/source/ui/vba/vbadocument.cxx | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/sw/source/ui/vba/vbadocument.cxx b/sw/source/ui/vba/vbadocument.cxx index 4f20311879ad..c8985464501d 100644 --- a/sw/source/ui/vba/vbadocument.cxx +++ b/sw/source/ui/vba/vbadocument.cxx @@ -225,7 +225,24 @@ uno::Any SwVbaDocument::ContentControls(const uno::Any& index) uno::Reference<XCollection> xContentControls( new SwVbaContentControls(this, mxContext, mxTextDocument, "", "")); if (index.hasValue()) - return xContentControls->Item(index, uno::Any()); + { + try + { + return xContentControls->Item(index, uno::Any()); + } + catch (lang::IndexOutOfBoundsException&) + { + // Hack: Instead of an index, it might be a float that was mistakenly treated as a long, + // which can happen with any valid positive integer when specified as a double like + // ActiveDocument.ContentControls(1841581653#). + if (index.getValueTypeClass() == css::uno::TypeClass_LONG) + { + sal_Int32 nLong(0); + index >>= nLong; + return xContentControls->Item(uno::Any(static_cast<double>(nLong)), uno::Any()); + } + } + } return uno::Any(xContentControls); } |