LibreOffice Module sw (master) 1
vbaformfielddropdown.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
10#include <ooo/vba/word/WdTextFormFieldType.hpp>
11
14
15using namespace ::ooo::vba;
16using namespace ::com::sun::star;
17
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))
30{
31}
32
34
36
38{
39 return m_pDropDown
42}
43
45
47{
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);
54}
55
57{
58 sal_Int32 nRet = 0;
59 if (!getValid())
60 return nRet;
61
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;
65}
66
68{
69 if (!getValid() || nIndex == getValue())
70 return;
71
72 // switch to zero-based index for implementation
73 --nIndex;
74 m_pDropDown->ReplaceContent(/*pText=*/nullptr, &nIndex);
75}
76
78{
79 if (!getValid())
80 return uno::Any();
81
82 uno::Reference<XCollection> xCol(
84
85 if (rIndex.hasValue())
86 return xCol->Item(rIndex, uno::Any());
87
88 return uno::Any(xCol);
89}
90
91OUString SwVbaFormFieldDropDown::getServiceImplName() { return "SwVbaFormFieldDropDown"; }
92
94{
95 static uno::Sequence<OUString> const aServiceNames{ "ooo.vba.word.DropDown" };
96 return aServiceNames;
97}
98
99/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static SW_DLLPUBLIC MarkType GetType(const ::sw::mark::IMark &rMark)
Returns the MarkType used to create the mark.
Definition: docbm.cxx:502
css::uno::Reference< css::uno::XComponentContext > mxContext
sal_Int32 SAL_CALL getDefault() override
OUString getServiceImplName() override
OUString SAL_CALL getDefaultPropertyName() override
sal_Bool SAL_CALL getValid() override
sw::mark::IDropdownFieldmark * m_pDropDown
css::uno::Any SAL_CALL ListEntries(const css::uno::Any &rIndex) override
void SAL_CALL setDefault(sal_Int32 nSet) override
css::uno::Sequence< OUString > getServiceNames() override
sal_Int32 SAL_CALL getValue() override
SwVbaFormFieldDropDown(const css::uno::Reference< ooo::vba::XHelperInterface > &rParent, const css::uno::Reference< css::uno::XComponentContext > &rContext, sw::mark::IFieldmark &rFormField)
DropDown formfields are inline text objects that are only found in MS Word.
void SAL_CALL setValue(sal_Int32 nIndex) override
virtual OUString GetContent(sal_Int32 *pIndex) const =0
virtual void ReplaceContent(const OUString *pText, sal_Int32 *pIndex)=0
Sequence< OUString > aServiceNames
sal_Int32 nIndex
Dialog to specify the properties of date form field.
bool hasValue()
unsigned char sal_Bool