LibreOffice Module sw (master) 1
vbaformfield.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/WdFieldType.hpp>
11
12#include <sal/log.hxx>
13
14#include <doc.hxx>
15#include <docsh.hxx>
16#include <unotextrange.hxx>
17
18#include "vbaformfield.hxx"
22#include "vbarange.hxx"
23#include "wordvbahelper.hxx"
24
25using namespace ::ooo::vba;
26using namespace ::com::sun::star;
27
34SwVbaFormField::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)
41{
42}
43
45
47{
48 return uno::Any(uno::Reference<word::XCheckBox>(
50}
51
53{
54 return uno::Any(uno::Reference<word::XDropDown>(
56}
57
59{
60 return uno::Any(uno::Reference<word::XTextInput>(
62}
63
65{
67 if (!pDoc)
68 return uno::Any();
69
70 const IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
71 if (!pMarkAccess)
72 return uno::Any();
73
74 sw::mark::IFieldmark* pFieldMark = pMarkAccess->getFieldmarkBefore(m_rFormField.GetMarkPos(),
75 /*bLoop=*/false);
76
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);
79 while (pDateField)
80 {
81 pFieldMark = pMarkAccess->getFieldmarkBefore(pDateField->GetMarkPos(), /*bLoop=*/false);
82 pDateField = dynamic_cast<sw::mark::IDateFieldmark*>(pFieldMark);
83 }
84
85 if (!pFieldMark)
86 return uno::Any();
87
88 return uno::Any(uno::Reference<word::XFormField>(
90}
91
93{
95 if (!pDoc)
96 return uno::Any();
97
98 const IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
99 if (!pMarkAccess)
100 return uno::Any();
101
102 sw::mark::IFieldmark* pFieldMark = pMarkAccess->getFieldmarkAfter(m_rFormField.GetMarkPos(),
103 /*bLoop=*/false);
104
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);
107 while (pDateField)
108 {
109 pFieldMark = pMarkAccess->getFieldmarkAfter(pDateField->GetMarkPos(), /*bLoop=*/false);
110 pDateField = dynamic_cast<sw::mark::IDateFieldmark*>(pFieldMark);
111 }
112
113 if (!pFieldMark)
114 return uno::Any();
115
116 return uno::Any(uno::Reference<word::XFormField>(
117 new SwVbaFormField(mxParent, mxContext, m_xTextDocument, *pFieldMark)));
118}
119
120uno::Reference<word::XRange> SwVbaFormField::Range()
121{
122 uno::Reference<word::XRange> xRet;
124 if (pDoc)
125 {
126 uno::Reference<text::XTextRange> xText(SwXTextRange::CreateXTextRange(
127 *pDoc, m_rFormField.GetMarkStart(), &m_rFormField.GetMarkEnd()));
128 if (xText.is())
129 xRet = new SwVbaRange(mxParent, mxContext, m_xTextDocument, xText->getStart(),
130 xText->getEnd());
131 }
132 return xRet;
133}
134
135OUString SwVbaFormField::getDefaultPropertyName() { return "Type"; }
136
138{
141 return ooo::vba::word::WdFieldType::wdFieldFormCheckBox;
143 return ooo::vba::word::WdFieldType::wdFieldFormTextInput;
144 return ooo::vba::word::WdFieldType::wdFieldFormDropDown;
145}
146
148{
149 SAL_INFO("sw.vba", "SwVbaFormField::getCalculateOnExit stub");
150 return false;
151}
152
154{
155 SAL_INFO("sw.vba", "SwVbaFormField::setCalculateOnExit stub");
156}
157
159{
160 SAL_INFO("sw.vba", "SwVbaFormField::getEnabled stub");
161 return true;
162}
163
165{
166 SAL_INFO("sw.vba", "SwVbaFormField::setEnabled stub");
167}
168
170{
171 OUString sMacro;
172 (*m_rFormField.GetParameters())["EntryMacro"] >>= sMacro;
173 return sMacro;
174}
175
176void SwVbaFormField::setEntryMacro(const OUString& rSet)
177{
178 (*m_rFormField.GetParameters())["EntryMacro"] <<= rSet;
179}
180
182{
183 OUString sMacro;
184 (*m_rFormField.GetParameters())["ExitMacro"] >>= sMacro;
185 return sMacro;
186}
187
188void SwVbaFormField::setExitMacro(const OUString& rSet)
189{
190 (*m_rFormField.GetParameters())["ExitMacro"] <<= rSet;
191}
192
193OUString SwVbaFormField::getHelpText() { return m_rFormField.GetFieldHelptext(); }
194
195void SwVbaFormField::setHelpText(const OUString& rSet) { m_rFormField.SetFieldHelptext(rSet); }
196
198{
199 SAL_INFO("sw.vba", "SwVbaFormField::getOwnHelp stub");
200 return true;
201}
202
204{
205 SAL_INFO("sw.vba", "SwVbaFormField::setOwnHelp stub");
206}
207
208OUString SwVbaFormField::getName() { return m_rFormField.GetName(); }
209
210void SwVbaFormField::setName(const OUString& rSet)
211{
212 SAL_INFO("sw.vba", "SwVbaFormField::setName[" << rSet << "] stub");
213}
214
215OUString SwVbaFormField::getResult() { return m_rFormField.GetContent(); }
216
217void SwVbaFormField::setResult(const OUString& rSet)
218{
219 if (dynamic_cast<sw::mark::ICheckboxFieldmark*>(&m_rFormField))
220 m_rFormField.ReplaceContent("false");
221 else
222 m_rFormField.ReplaceContent(rSet);
223}
224
226{
227 SAL_INFO("sw.vba", "SwVbaFormField::getStatusText stub");
228 return OUString();
229}
230
231void SwVbaFormField::setStatusText(const OUString& rSet)
232{
233 SAL_INFO("sw.vba", "SwVbaFormField::setStatusText[" << rSet << "] stub");
234}
235
237{
238 SAL_INFO("sw.vba", "SwVbaFormField::getOwnStatus stub");
239 return true;
240}
241
243{
244 SAL_INFO("sw.vba", "SwVbaFormField::setOwnStatus stub");
245}
246
247OUString SwVbaFormField::getServiceImplName() { return "SwVbaFormField"; }
248
249uno::Sequence<OUString> SwVbaFormField::getServiceNames()
250{
251 static uno::Sequence<OUString> const aServiceNames{ "ooo.vba.word.FormField" };
252 return aServiceNames;
253}
254
255/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Provides access to the marks of a document.
virtual sw::mark::IFieldmark * getFieldmarkBefore(const SwPosition &pos, bool bLoop) const =0
virtual sw::mark::IFieldmark * getFieldmarkAfter(const SwPosition &pos, bool bLoop) const =0
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
css::uno::WeakReference< ov::XHelperInterface > mxParent
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:204
Definition: doc.hxx:197
IDocumentMarkAccess * getIDocumentMarkAccess()
Definition: docbm.cxx:1890
~SwVbaFormField() override
css::uno::Any SAL_CALL CheckBox() override
void SAL_CALL setEnabled(sal_Bool bSet) override
OUString SAL_CALL getEntryMacro() override
css::uno::Sequence< OUString > getServiceNames() override
sw::mark::IFieldmark & m_rFormField
OUString SAL_CALL getDefaultPropertyName() override
css::uno::Any SAL_CALL DropDown() override
OUString SAL_CALL getName() override
void SAL_CALL setCalculateOnExit(sal_Bool bSet) override
css::uno::Any SAL_CALL TextInput() override
void SAL_CALL setResult(const OUString &rSet) override
OUString SAL_CALL getResult() override
OUString getServiceImplName() override
sal_Bool SAL_CALL getOwnStatus() override
sal_Bool SAL_CALL getEnabled() override
void SAL_CALL setName(const OUString &rSet) override
OUString SAL_CALL getStatusText() override
SwVbaFormField(const css::uno::Reference< ooo::vba::XHelperInterface > &rParent, const css::uno::Reference< css::uno::XComponentContext > &rContext, const uno::Reference< text::XTextDocument > &xTextDocument, sw::mark::IFieldmark &rFormField)
FormFields are inline text objects that are only found in MS Word.
css::uno::Reference< ooo::vba::word::XRange > SAL_CALL Range() override
void SAL_CALL setHelpText(const OUString &rSet) override
void SAL_CALL setOwnHelp(sal_Bool bSet) override
OUString SAL_CALL getExitMacro() override
OUString SAL_CALL getHelpText() override
void SAL_CALL setStatusText(const OUString &rSet) override
sal_Bool SAL_CALL getCalculateOnExit() override
sal_Int32 SAL_CALL getType() override
void SAL_CALL setOwnStatus(sal_Bool bSet) override
css::uno::Reference< css::text::XTextDocument > m_xTextDocument
void SAL_CALL setExitMacro(const OUString &rSet) override
sal_Bool SAL_CALL getOwnHelp() override
css::uno::Any SAL_CALL Next() override
css::uno::Any SAL_CALL Previous() override
void SAL_CALL setEntryMacro(const OUString &rSet) override
static rtl::Reference< SwXTextRange > CreateXTextRange(SwDoc &rDoc, const SwPosition &rPos, const SwPosition *const pMark)
Definition: unoobj2.cxx:1221
Sequence< OUString > aServiceNames
#define SAL_INFO(area, stream)
SwDocShell * getDocShell(const uno::Reference< frame::XModel > &xModel)
static SfxItemSet & rSet
unsigned char sal_Bool