diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
commit | 267c6f2ac71f92999e969232431ba04678e7437e (patch) | |
tree | 358c9467650e1d0a1d7227a21dac2e3d08b622b2 /sw/source/ui/vba/vbaformfieldtextinput.cxx | |
parent | Initial commit. (diff) | |
download | libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.tar.xz libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.zip |
Adding upstream version 4:24.2.0.upstream/4%24.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sw/source/ui/vba/vbaformfieldtextinput.cxx')
-rw-r--r-- | sw/source/ui/vba/vbaformfieldtextinput.cxx | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/sw/source/ui/vba/vbaformfieldtextinput.cxx b/sw/source/ui/vba/vbaformfieldtextinput.cxx new file mode 100644 index 0000000000..4f78761f4e --- /dev/null +++ b/sw/source/ui/vba/vbaformfieldtextinput.cxx @@ -0,0 +1,130 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <ooo/vba/word/WdTextFormFieldType.hpp> + +#include <sal/log.hxx> + +#include "vbaformfieldtextinput.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +/** + * TextInput formfields are inline text objects that are only found in MS Word. + * They cannot be created in Excel or in Calc. + * + * Note that VBA might call this a TextInput, but it might not actually be one, + * so make good use of getValid() + */ +SwVbaFormFieldTextInput::SwVbaFormFieldTextInput( + const uno::Reference<ooo::vba::XHelperInterface>& rParent, + const uno::Reference<uno::XComponentContext>& rContext, sw::mark::IFieldmark& rFormField) + : SwVbaFormFieldTextInput_BASE(rParent, rContext) + , m_rTextInput(rFormField) +{ +} + +SwVbaFormFieldTextInput::~SwVbaFormFieldTextInput() {} + +OUString SwVbaFormFieldTextInput::getDefaultPropertyName() { return "Valid"; } + +sal_Bool SwVbaFormFieldTextInput::getValid() +{ + return IDocumentMarkAccess::GetType(m_rTextInput) + == IDocumentMarkAccess::MarkType::TEXT_FIELDMARK; +} + +OUString SwVbaFormFieldTextInput::getDefault() +{ + if (!getValid()) + return OUString(); + + return m_rTextInput.GetContent(); +} + +void SwVbaFormFieldTextInput::setDefault(const OUString& sSet) +{ + // Hard to know what to do here, since LO doesn't have a default property for text input. + // This really only makes sense when macro-adding a text input. + // In that case, we want it to affect the actual text content. + // However, if the text has already been set by the user, then this shouldn't do anything. + // Assuming this is only ever set when adding a text input seems the sanest approach. + if (!getValid() || getDefault() == sSet) + return; + + m_rTextInput.ReplaceContent(sSet); +} + +OUString SwVbaFormFieldTextInput::getFormat() +{ + if (!getValid()) + return OUString(); + + SAL_INFO("sw.vba", "SwVbaFormFieldTextInput::getFormat stub"); + return OUString(); +} + +sal_Int32 SwVbaFormFieldTextInput::getType() +{ + if (!getValid()) + return word::WdTextFormFieldType::wdRegularText; + + SAL_INFO("sw.vba", "SwVbaFormFieldTextInput::getType stub"); + return word::WdTextFormFieldType::wdRegularText; +} + +sal_Int32 SwVbaFormFieldTextInput::getWidth() +{ + if (!getValid()) + return 0; + + SAL_INFO("sw.vba", "SwVbaFormFieldTextInput::getWidth stub"); + return 11 * 50; +} + +void SwVbaFormFieldTextInput::setWidth(sal_Int32 nWidth) +{ + if (!getValid()) + return; + + SAL_INFO("sw.vba", "SwVbaFormFieldTextInput::setWidth[" << nWidth << "] stub"); +} + +void SwVbaFormFieldTextInput::Clear() +{ + if (!getValid() || m_rTextInput.GetContent().isEmpty()) + return; + + m_rTextInput.ReplaceContent(""); +} + +void SwVbaFormFieldTextInput::EditType(sal_Int32 nType, const uno::Any& rDefault, + const uno::Any& rFormat, const uno::Any& rEnabled) +{ + OUString sDefault; + OUString sFormat; + bool bEnabled = true; + rDefault >>= sDefault; + rFormat >>= sFormat; + rEnabled >>= bEnabled; + SAL_INFO("sw.vba", "SwVbaFormFieldTextInput::EditType[" + << nType << "] sDefault[" << sDefault << "] sFormat[" << sFormat + << "] bEnabled[" << bEnabled << "] stub"); +} + +OUString SwVbaFormFieldTextInput::getServiceImplName() { return "SwVbaFormFieldTextInput"; } + +uno::Sequence<OUString> SwVbaFormFieldTextInput::getServiceNames() +{ + static uno::Sequence<OUString> const aServiceNames{ "ooo.vba.word.TextInput" }; + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |