29static std::shared_ptr<SwContentControl>
31 std::u16string_view sTitle, sal_Int32& rIndex,
32 const uno::Reference<text::XTextDocument>& xTextDocument,
33 uno::Sequence<OUString>* pElementNames =
nullptr)
39 assert(sTag.empty() || sTitle.empty());
41 std::shared_ptr<SwContentControl> pControl;
42 std::vector<OUString> vElementNames;
44 const size_t nLen = rManager.
GetCount();
45 if (!pElementNames && rIndex > 0 &&
sName.empty() && sTag.empty() && sTitle.empty())
47 size_t i =
static_cast<size_t>(rIndex);
57 sal_Int32 nCounter = 0;
58 for (
size_t i = 0;
i < nLen; ++
i)
61 if (!sTag.empty() && sTag != pControl->GetTag())
66 if (!sTitle.empty() && sTitle != pControl->GetAlias())
73 const OUString sID = OUString::number(
static_cast<sal_uInt32
>(pControl->GetId()));
81 vElementNames.push_back(sID);
83 if (rIndex == nCounter || !
sName.empty())
100 uno::Reference<container::XIndexAccess> mxIndexAccess;
104 explicit ContentControlsEnumWrapper(uno::Reference<container::XIndexAccess> xIndexAccess)
105 : mxIndexAccess(
std::move(xIndexAccess))
110 sal_Bool SAL_CALL hasMoreElements()
override {
return (mnIndex < mxIndexAccess->getCount()); }
112 uno::Any SAL_CALL nextElement()
override
114 if (mnIndex < mxIndexAccess->getCount())
116 return mxIndexAccess->getByIndex(mnIndex++);
118 throw container::NoSuchElementException();
122class ContentControlCollectionHelper
123 :
public ::cppu::WeakImplHelper<container::XNameAccess, container::XIndexAccess,
124 container::XEnumerationAccess>
127 uno::Reference<XHelperInterface>
mxParent;
128 uno::Reference<uno::XComponentContext>
mxContext;
129 uno::Reference<text::XTextDocument> mxTextDocument;
130 const OUString m_sTag;
132 std::shared_ptr<SwContentControl>
m_pCache;
136 ContentControlCollectionHelper(uno::Reference<ov::XHelperInterface> xParent,
137 uno::Reference<uno::XComponentContext> xContext,
138 uno::Reference<text::XTextDocument> xTextDocument,
139 const OUString& rTag,
const OUString& rTitle)
143 , mxTextDocument(
std::move(xTextDocument))
150 sal_Int32 SAL_CALL getCount()
override
161 throw lang::IndexOutOfBoundsException();
163 return uno::Any(uno::Reference<word::XContentControl>(
168 uno::Sequence<OUString> SAL_CALL getElementNames()
override
171 uno::Sequence<OUString>
aSeq;
176 uno::Any SAL_CALL getByName(
const OUString& aName)
override
178 if (!hasByName(aName))
179 throw container::NoSuchElementException();
181 return uno::Any(uno::Reference<word::XContentControl>(
185 sal_Bool SAL_CALL hasByName(
const OUString& aName)
override
193 uno::Type SAL_CALL getElementType()
override
198 sal_Bool SAL_CALL hasElements()
override {
return getCount() != 0; }
201 uno::Reference<container::XEnumeration> SAL_CALL createEnumeration()
override
203 return new ContentControlsEnumWrapper(
this);
219 const uno::Reference<uno::XComponentContext>& xContext,
220 const uno::Reference<text::XTextDocument>& xTextDocument,
221 const OUString& rTag,
const OUString& rTitle)
225 new ContentControlCollectionHelper(xParent, xContext, xTextDocument, rTag, rTitle)))
264 static uno::Sequence<OUString>
const sNames{
"ooo.vba.word.ContentControls" };
unotools::WeakReference< AnimationNode > mxParent
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
Knows all the text content controls in the document.
SwTextContentControl * Get(size_t nIndex)
SwDoc * GetDoc()
returns Doc. But be careful!
::SwContentControlManager & GetContentControlManager()
const std::shared_ptr< SwContentControl > & GetContentControl() const
const SwFormatContentControl & GetContentControl() const
css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
css::uno::Sequence< OUString > getServiceNames() override
OUString getServiceImplName() override
css::uno::Type SAL_CALL getElementType() override
SwVbaContentControls(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::text::XTextDocument > &xTextDocument, const OUString &rTag, const OUString &rTitle)
Content Controls can be accessed and filtered in many different ways.
css::uno::Type const & get()
Sequence< sal_Int8 > aSeq
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
SwDocShell * getDocShell(const uno::Reference< frame::XModel > &xModel)
::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE
static std::shared_ptr< SwContentControl > lcl_getContentControl(std::u16string_view sName, std::u16string_view sTag, std::u16string_view sTitle, sal_Int32 &rIndex, const uno::Reference< text::XTextDocument > &xTextDocument, uno::Sequence< OUString > *pElementNames=nullptr)