/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// Helper function to access the content controls // @param rIndex // [in] negative indexes indicate the need to search by name, otherwise get by index, // using SAL_MAX_INT32 to indicate the need to just get the total count. // [out] rIndex indicates the found index, or the total number of content controls static std::shared_ptr<SwContentControl>
lcl_getContentControl(std::u16string_view sName, std::u16string_view sTag,
std::u16string_view sTitle, sal_Int32& rIndex, const rtl::Reference<SwXTextDocument>& xTextDocument,
uno::Sequence<OUString>* pElementNames = nullptr)
{
SwDoc* pDoc = xTextDocument->GetDocShell()->GetDoc(); if (!pDoc) return nullptr;
assert(sTag.empty() || sTitle.empty()); // only one grouping at a time is allowed
std::shared_ptr<SwContentControl> pControl;
std::vector<OUString> vElementNames;
SwContentControlManager& rManager = pDoc->GetContentControlManager(); const size_t nLen = rManager.GetCount(); if (!pElementNames && rIndex > 0 && sName.empty() && sTag.empty() && sTitle.empty())
{
size_t i = static_cast<size_t>(rIndex); // This is the normal get-by-index/getCount mode - no need for fancy filtering. if (i < nLen)
pControl = rManager.Get(i)->GetContentControl().GetContentControl(); else
rIndex = nLen;
} else
{ // loop through everything collecting names, filtering by Tag/Title
sal_Int32 nCounter = 0; for (size_t i = 0; i < nLen; ++i)
{
pControl = rManager.Get(i)->GetContentControl().GetContentControl(); if (!sTag.empty() && sTag != pControl->GetTag())
{
pControl = nullptr; continue;
} if (!sTitle.empty() && sTitle != pControl->GetAlias())
{
pControl = nullptr; continue;
}
// When treated as a name, consider the integer ID to be unsigned const OUString sID = OUString::number(static_cast<sal_uInt32>(pControl->GetId())); if (!sName.empty() && sName != sID)
{
pControl = nullptr; continue;
}
/** * Content Controls can be accessed and filtered in many different ways. * Surprisingly however, there is no clear, descriptive "by name" access. * Instead, each content control (probably) has a unique _signed-integer_ identifier, * which can be passed to Item() as a float or _unsigned-integer_ string * (to differentiate it from getByIndex). * * Index access can be filtered by Tag, Title, Range, and XML link. * TODO: add filtering for Range, SelectLinkedControls, SelectUnlinkedControls
*/
SwVbaContentControls::SwVbaContentControls(const uno::Reference<XHelperInterface>& xParent, const uno::Reference<uno::XComponentContext>& xContext, const rtl::Reference<SwXTextDocument>& xTextDocument, const OUString& rTag, const OUString& rTitle)
: SwVbaContentControls_BASE(
xParent, xContext,
uno::Reference<container::XIndexAccess>( new ContentControlCollectionHelper(xParent, xContext, xTextDocument, rTag, rTitle)))
{
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.