sw/source/ui/vba/vbacontentcontrol.cxx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
New commits: commit 9c1927df9c266834b5a2da4b7f23af0b8e8b8c6e Author: Justin Luth <justin.l...@collabora.com> AuthorDate: Tue Dec 13 15:47:18 2022 -0500 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Dec 15 08:25:15 2022 +0000 tdf#151548 vba ContentControls: implement Range This is critical for accessing content control text via VBA. Msgbox (ActiveDocument.ContentControls(1).Range.Text) Change-Id: I77885909d82e209d909e3bddff08894c1989286f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144135 Tested-by: Jenkins Reviewed-by: Justin Luth <jl...@mail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/source/ui/vba/vbacontentcontrol.cxx b/sw/source/ui/vba/vbacontentcontrol.cxx index 775e7fbbdea3..b1de99ee3388 100644 --- a/sw/source/ui/vba/vbacontentcontrol.cxx +++ b/sw/source/ui/vba/vbacontentcontrol.cxx @@ -15,9 +15,11 @@ #include <sal/log.hxx> #include <ndtxt.hxx> +#include <unotextrange.hxx> #include "vbacontentcontrol.hxx" #include "vbacontentcontrollistentries.hxx" +#include "vbarange.hxx" using namespace ::ooo::vba; using namespace ::com::sun::star; @@ -569,8 +571,21 @@ sal_Bool SwVbaContentControl::getShowingPlaceholderText() uno::Reference<word::XRange> SwVbaContentControl::getRange() { - SAL_INFO("sw.vba", "SwVbaContentControl::getRange stub"); - return uno::Reference<word::XRange>(); + uno::Reference<word::XRange> xRet; + SwTextNode* pTextNode = m_rCC.GetTextNode(); + if (pTextNode) + { + // Don't select the text attribute itself at the start. + SwPosition aStart(*pTextNode, m_rCC.GetStart() + 1); + // Don't select the CH_TXTATR_BREAKWORD itself at the end. + SwPosition aEnd(*pTextNode, *m_rCC.End() - 1); + uno::Reference<text::XTextRange> xText( + SwXTextRange::CreateXTextRange(pTextNode->GetDoc(), aStart, &aEnd)); + if (xText.is()) + xRet = new SwVbaRange(mxParent, mxContext, mxTextDocument, xText->getStart(), + xText->getEnd()); + } + return xRet; } OUString SwVbaContentControl::getRepeatingSectionItemTitle()