android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / ui / vba / vbaformfielddropdown.cxx
blobf1edc8140357ae119699c516011ac38ea9cc28d2
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 <ooo/vba/word/WdTextFormFieldType.hpp>
12 #include "vbaformfielddropdown.hxx"
13 #include "vbaformfielddropdownlistentries.hxx"
15 using namespace ::ooo::vba;
16 using namespace ::com::sun::star;
18 /**
19 * DropDown formfields are inline text objects that are only found in MS Word.
20 * They cannot be created in Excel or in Calc.
22 * Note that VBA might call this a DropDown, but it might not actually be one,
23 * so make good use of getValid()
25 SwVbaFormFieldDropDown::SwVbaFormFieldDropDown(
26 const uno::Reference<ooo::vba::XHelperInterface>& rParent,
27 const uno::Reference<uno::XComponentContext>& rContext, ::sw::mark::IFieldmark& rFormField)
28 : SwVbaFormFieldDropDown_BASE(rParent, rContext)
29 , m_pDropDown(dynamic_cast<sw::mark::IDropdownFieldmark*>(&rFormField))
33 SwVbaFormFieldDropDown::~SwVbaFormFieldDropDown() {}
35 OUString SwVbaFormFieldDropDown::getDefaultPropertyName() { return "Valid"; }
37 sal_Bool SwVbaFormFieldDropDown::getValid()
39 return m_pDropDown
40 && IDocumentMarkAccess::GetType(*m_pDropDown)
41 == IDocumentMarkAccess::MarkType::DROPDOWN_FIELDMARK;
44 sal_Int32 SwVbaFormFieldDropDown::getDefault() { return getValue(); }
46 void SwVbaFormFieldDropDown::setDefault(sal_Int32 nSet)
48 // Hard to know what to do here, since LO doesn't have a default property for DropDowns.
49 // Setting this really only makes sense when macro-adding a DropDown.
50 // In that case, we want it to affect the actual text content.
51 // However, if an item has already been selected by the user, then this shouldn't do anything.
52 // Assuming this is only ever set when adding a DropDown seems the sanest approach.
53 setValue(nSet);
56 sal_Int32 SwVbaFormFieldDropDown::getValue()
58 sal_Int32 nRet = 0;
59 if (!getValid())
60 return nRet;
62 --nRet; // send -1, which requests being changed to the selected DropDown's zero-based index
63 m_pDropDown->GetContent(&nRet);
64 return nRet + 1;
67 void SwVbaFormFieldDropDown::setValue(sal_Int32 nIndex)
69 if (!getValid() || nIndex == getValue())
70 return;
72 // switch to zero-based index for implementation
73 --nIndex;
74 m_pDropDown->ReplaceContent(/*pText=*/nullptr, &nIndex);
77 uno::Any SwVbaFormFieldDropDown::ListEntries(const uno::Any& rIndex)
79 if (!getValid())
80 return uno::Any();
82 uno::Reference<XCollection> xCol(
83 new SwVbaFormFieldDropDownListEntries(this, mxContext, *m_pDropDown));
85 if (rIndex.hasValue())
86 return xCol->Item(rIndex, uno::Any());
88 return uno::Any(xCol);
91 OUString SwVbaFormFieldDropDown::getServiceImplName() { return "SwVbaFormFieldDropDown"; }
93 uno::Sequence<OUString> SwVbaFormFieldDropDown::getServiceNames()
95 static uno::Sequence<OUString> const aServiceNames{ "ooo.vba.word.DropDown" };
96 return aServiceNames;
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */