android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / ui / vba / vbacontentcontrollistentries.cxx
blob552397e156b7bbd2d1786a5eb90d5febf5721f05
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include "vbacontentcontrollistentries.hxx"
12 using namespace ::ooo::vba;
13 using namespace ::com::sun::star;
15 namespace
17 class ContentControlListEntriesEnumWrapper : public EnumerationHelper_BASE
19 uno::Reference<container::XIndexAccess> mxIndexAccess;
20 sal_Int32 mnIndex;
22 public:
23 explicit ContentControlListEntriesEnumWrapper(
24 uno::Reference<container::XIndexAccess> xIndexAccess)
25 : mxIndexAccess(xIndexAccess)
26 , mnIndex(0)
30 virtual sal_Bool SAL_CALL hasMoreElements() override
32 return (mnIndex < mxIndexAccess->getCount());
35 virtual uno::Any SAL_CALL nextElement() override
37 if (mnIndex < mxIndexAccess->getCount())
39 return mxIndexAccess->getByIndex(mnIndex++);
41 throw container::NoSuchElementException();
45 class ContentControlListEntryCollectionHelper
46 : public ::cppu::WeakImplHelper<container::XIndexAccess, container::XEnumerationAccess>
48 private:
49 uno::Reference<XHelperInterface> mxParent;
50 uno::Reference<uno::XComponentContext> mxContext;
51 std::shared_ptr<SwContentControl> m_pCC;
53 public:
54 /// @throws css::uno::RuntimeException
55 ContentControlListEntryCollectionHelper(uno::Reference<ov::XHelperInterface> xParent,
56 uno::Reference<uno::XComponentContext> xContext,
57 std::shared_ptr<SwContentControl> pCC)
58 : mxParent(xParent)
59 , mxContext(xContext)
60 , m_pCC(pCC)
64 sal_Int32 SAL_CALL getCount() override { return m_pCC->GetListItems().size(); }
66 uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
68 if (Index < 0 || Index >= getCount())
69 throw lang::IndexOutOfBoundsException();
71 return uno::Any(uno::Reference<word::XContentControlListEntry>(
72 new SwVbaContentControlListEntry(mxParent, mxContext, m_pCC, Index)));
75 uno::Type SAL_CALL getElementType() override
77 return cppu::UnoType<word::XContentControlListEntry>::get();
80 sal_Bool SAL_CALL hasElements() override { return getCount() != 0; }
82 // XEnumerationAccess
83 uno::Reference<container::XEnumeration> SAL_CALL createEnumeration() override
85 return new ContentControlListEntriesEnumWrapper(this);
90 /**
91 * DropDownLists and ComboBoxes contain a list of name/value pairs to choose from.
92 * Use of DropDownListEntries from any other control is invalid.
94 SwVbaContentControlListEntries::SwVbaContentControlListEntries(
95 const uno::Reference<XHelperInterface>& xParent,
96 const uno::Reference<uno::XComponentContext>& xContext, std::shared_ptr<SwContentControl> pCC)
97 : SwVbaContentControlListEntries_BASE(
98 xParent, xContext,
99 uno::Reference<container::XIndexAccess>(
100 new ContentControlListEntryCollectionHelper(xParent, xContext, pCC)))
101 , m_pCC(pCC)
105 uno::Reference<word::XContentControlListEntry>
106 SwVbaContentControlListEntries::Add(const OUString& rName, const uno::Any& rValue,
107 const uno::Any& rIndex)
109 // No duplicate Names allowed in VBA
110 for (auto& rListItem : m_pCC->GetListItems())
112 if (rListItem.ToString() == rName)
113 return uno::Reference<word::XContentControlListEntry>();
116 sal_Int32 nZIndex = SAL_MAX_INT32;
117 rIndex >>= nZIndex;
118 // rIndex is 1-based, nZIndex is 0-based. If rIndex is not given, then add as the last choice.
119 assert(nZIndex > 0);
120 --nZIndex;
121 nZIndex = std::min(static_cast<size_t>(nZIndex), m_pCC->GetListItems().size());
123 OUString sValue;
124 rValue >>= sValue;
125 if (m_pCC->AddListItem(nZIndex, rName, sValue))
127 return uno::Reference<word::XContentControlListEntry>(
128 new SwVbaContentControlListEntry(mxParent, mxContext, m_pCC, nZIndex));
131 return uno::Reference<word::XContentControlListEntry>();
134 void SwVbaContentControlListEntries::Clear() { m_pCC->ClearListItems(); }
136 sal_Int32 SwVbaContentControlListEntries::getCount() { return m_pCC->GetListItems().size(); }
138 // XEnumerationAccess
139 uno::Type SwVbaContentControlListEntries::getElementType()
141 return cppu::UnoType<word::XContentControlListEntry>::get();
144 uno::Reference<container::XEnumeration> SwVbaContentControlListEntries::createEnumeration()
146 return new ContentControlListEntriesEnumWrapper(m_xIndexAccess);
149 // SwVbaContentControlListEntries_BASE
150 uno::Any SwVbaContentControlListEntries::createCollectionObject(const uno::Any& aSource)
152 return aSource;
155 OUString SwVbaContentControlListEntries::getServiceImplName()
157 return "SwVbaContentControlListEntries";
160 uno::Sequence<OUString> SwVbaContentControlListEntries::getServiceNames()
162 static uno::Sequence<OUString> const sNames{ "ooo.vba.word.ContentControlListEntries" };
163 return sNames;
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */