1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <ooo/vba/word/WdFieldType.hpp>
12 #include <sal/log.hxx>
16 #include <unotextrange.hxx>
18 #include "vbaformfield.hxx"
19 #include "vbaformfieldcheckbox.hxx"
20 #include "vbaformfielddropdown.hxx"
21 #include "vbaformfieldtextinput.hxx"
22 #include "vbarange.hxx"
23 #include "wordvbahelper.hxx"
25 using namespace ::ooo::vba
;
26 using namespace ::com::sun::star
;
29 * FormFields are inline text objects that are only found in MS Word.
30 * They cannot be created in Excel or in Calc.
32 * There are three specific kinds of FormFields: CheckBox, DropDown, and TextInput.
34 SwVbaFormField::SwVbaFormField(const uno::Reference
<ooo::vba::XHelperInterface
>& rParent
,
35 const uno::Reference
<uno::XComponentContext
>& rContext
,
36 const uno::Reference
<text::XTextDocument
>& xTextDocument
,
37 sw::mark::IFieldmark
& rFormField
)
38 : SwVbaFormField_BASE(rParent
, rContext
)
39 , m_xTextDocument(xTextDocument
)
40 , m_rFormField(rFormField
)
44 SwVbaFormField::~SwVbaFormField() {}
46 uno::Any
SwVbaFormField::CheckBox()
48 return uno::Any(uno::Reference
<word::XCheckBox
>(
49 new SwVbaFormFieldCheckBox(mxParent
, mxContext
, m_rFormField
)));
52 uno::Any
SwVbaFormField::DropDown()
54 return uno::Any(uno::Reference
<word::XDropDown
>(
55 new SwVbaFormFieldDropDown(mxParent
, mxContext
, m_rFormField
)));
58 uno::Any
SwVbaFormField::TextInput()
60 return uno::Any(uno::Reference
<word::XTextInput
>(
61 new SwVbaFormFieldTextInput(mxParent
, mxContext
, m_rFormField
)));
64 uno::Any
SwVbaFormField::Previous()
66 SwDoc
* pDoc
= word::getDocShell(m_xTextDocument
)->GetDoc();
70 const IDocumentMarkAccess
* pMarkAccess
= pDoc
->getIDocumentMarkAccess();
74 sw::mark::IFieldmark
* pFieldMark
= pMarkAccess
->getFieldmarkBefore(m_rFormField
.GetMarkPos(),
77 // DateFields are a LO specialty, and do not exist natively in MS documents. Ignore if added...
78 auto pDateField
= dynamic_cast<sw::mark::IDateFieldmark
*>(pFieldMark
);
81 pFieldMark
= pMarkAccess
->getFieldmarkBefore(pDateField
->GetMarkPos(), /*bLoop=*/false);
82 pDateField
= dynamic_cast<sw::mark::IDateFieldmark
*>(pFieldMark
);
88 return uno::Any(uno::Reference
<word::XFormField
>(
89 new SwVbaFormField(mxParent
, mxContext
, m_xTextDocument
, *pFieldMark
)));
92 uno::Any
SwVbaFormField::Next()
94 SwDoc
* pDoc
= word::getDocShell(m_xTextDocument
)->GetDoc();
98 const IDocumentMarkAccess
* pMarkAccess
= pDoc
->getIDocumentMarkAccess();
102 sw::mark::IFieldmark
* pFieldMark
= pMarkAccess
->getFieldmarkAfter(m_rFormField
.GetMarkPos(),
105 // DateFields are a LO specialty, and do not exist natively in MS documents. Ignore if added...
106 auto pDateField
= dynamic_cast<sw::mark::IDateFieldmark
*>(pFieldMark
);
109 pFieldMark
= pMarkAccess
->getFieldmarkAfter(pDateField
->GetMarkPos(), /*bLoop=*/false);
110 pDateField
= dynamic_cast<sw::mark::IDateFieldmark
*>(pFieldMark
);
116 return uno::Any(uno::Reference
<word::XFormField
>(
117 new SwVbaFormField(mxParent
, mxContext
, m_xTextDocument
, *pFieldMark
)));
120 uno::Reference
<word::XRange
> SwVbaFormField::Range()
122 uno::Reference
<word::XRange
> xRet
;
123 SwDoc
* pDoc
= word::getDocShell(m_xTextDocument
)->GetDoc();
126 uno::Reference
<text::XTextRange
> xText(SwXTextRange::CreateXTextRange(
127 *pDoc
, m_rFormField
.GetMarkStart(), &m_rFormField
.GetMarkEnd()));
129 xRet
= new SwVbaRange(mxParent
, mxContext
, m_xTextDocument
, xText
->getStart(),
135 OUString
SwVbaFormField::getDefaultPropertyName() { return "Type"; }
137 sal_Int32
SwVbaFormField::getType()
139 IDocumentMarkAccess::MarkType aType
= IDocumentMarkAccess::GetType(m_rFormField
);
140 if (aType
== IDocumentMarkAccess::MarkType::CHECKBOX_FIELDMARK
)
141 return ooo::vba::word::WdFieldType::wdFieldFormCheckBox
;
142 else if (aType
== IDocumentMarkAccess::MarkType::TEXT_FIELDMARK
)
143 return ooo::vba::word::WdFieldType::wdFieldFormTextInput
;
144 return ooo::vba::word::WdFieldType::wdFieldFormDropDown
;
147 sal_Bool
SwVbaFormField::getCalculateOnExit()
149 SAL_INFO("sw.vba", "SwVbaFormField::getCalculateOnExit stub");
153 void SwVbaFormField::setCalculateOnExit(sal_Bool
/*bSet*/)
155 SAL_INFO("sw.vba", "SwVbaFormField::setCalculateOnExit stub");
158 sal_Bool
SwVbaFormField::getEnabled()
160 SAL_INFO("sw.vba", "SwVbaFormField::getEnabled stub");
164 void SwVbaFormField::setEnabled(sal_Bool
/*bSet*/)
166 SAL_INFO("sw.vba", "SwVbaFormField::setEnabled stub");
169 OUString
SwVbaFormField::getEntryMacro()
172 (*m_rFormField
.GetParameters())["EntryMacro"] >>= sMacro
;
176 void SwVbaFormField::setEntryMacro(const OUString
& rSet
)
178 (*m_rFormField
.GetParameters())["EntryMacro"] <<= rSet
;
181 OUString
SwVbaFormField::getExitMacro()
184 (*m_rFormField
.GetParameters())["ExitMacro"] >>= sMacro
;
188 void SwVbaFormField::setExitMacro(const OUString
& rSet
)
190 (*m_rFormField
.GetParameters())["ExitMacro"] <<= rSet
;
193 OUString
SwVbaFormField::getHelpText() { return m_rFormField
.GetFieldHelptext(); }
195 void SwVbaFormField::setHelpText(const OUString
& rSet
) { m_rFormField
.SetFieldHelptext(rSet
); }
197 sal_Bool
SwVbaFormField::getOwnHelp()
199 SAL_INFO("sw.vba", "SwVbaFormField::getOwnHelp stub");
203 void SwVbaFormField::setOwnHelp(sal_Bool
/*bSet*/)
205 SAL_INFO("sw.vba", "SwVbaFormField::setOwnHelp stub");
208 OUString
SwVbaFormField::getName() { return m_rFormField
.GetName(); }
210 void SwVbaFormField::setName(const OUString
& rSet
)
212 SAL_INFO("sw.vba", "SwVbaFormField::setName[" << rSet
<< "] stub");
215 OUString
SwVbaFormField::getResult() { return m_rFormField
.GetContent(); }
217 void SwVbaFormField::setResult(const OUString
& rSet
)
219 if (dynamic_cast<sw::mark::ICheckboxFieldmark
*>(&m_rFormField
))
220 m_rFormField
.ReplaceContent("false");
222 m_rFormField
.ReplaceContent(rSet
);
225 OUString
SwVbaFormField::getStatusText()
227 SAL_INFO("sw.vba", "SwVbaFormField::getStatusText stub");
231 void SwVbaFormField::setStatusText(const OUString
& rSet
)
233 SAL_INFO("sw.vba", "SwVbaFormField::setStatusText[" << rSet
<< "] stub");
236 sal_Bool
SwVbaFormField::getOwnStatus()
238 SAL_INFO("sw.vba", "SwVbaFormField::getOwnStatus stub");
242 void SwVbaFormField::setOwnStatus(sal_Bool
/*bSet*/)
244 SAL_INFO("sw.vba", "SwVbaFormField::setOwnStatus stub");
247 OUString
SwVbaFormField::getServiceImplName() { return "SwVbaFormField"; }
249 uno::Sequence
<OUString
> SwVbaFormField::getServiceNames()
251 static uno::Sequence
<OUString
> const aServiceNames
{ "ooo.vba.word.FormField" };
252 return aServiceNames
;
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */