summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2022-11-03 10:05:24 -0400
committerMiklos Vajna <vmiklos@collabora.com>2022-11-11 11:19:21 +0100
commit7444c8c87a228e4259f5dd34edfcf4c92ed02504 (patch)
treef17cf0f3bfb4a90c666585e4c7642151e0b57ad1
parent1b5c7bad0f332b6923aa820301fc1ff6d00bd0ea (diff)
tdf#151548 vba FormFields: Add basic word::XCheckBox support
make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba This now allows MS Word Basic legacy checkbox form fields to be controlled by VBA basic. -allows getting and setting the checkbox value TODO: -wire up entry and exit macros -wire up StarBASIC support (hmm, how would that be different?) -probably completely ignore this. formfields hidden from normal writer - only activeX and content controls shown. -setup tri-state for checkboxes: with a separate default value Change-Id: Ied47a507dd9acc2c8dfd1472e6704e9dd571b480 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142253 Reviewed-by: Justin Luth <jluth@mail.com> Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r--oovbaapi/ooo/vba/word/XCheckBox.idl14
-rw-r--r--sw/Library_vbaswobj.mk1
-rw-r--r--sw/qa/core/data/docm/testVBA.docmbin24218 -> 30997 bytes
-rw-r--r--sw/source/core/crsr/bookmark.cxx11
-rw-r--r--sw/source/core/inc/bookmark.hxx2
-rw-r--r--sw/source/ui/vba/vbaformfield.cxx6
-rw-r--r--sw/source/ui/vba/vbaformfieldcheckbox.cxx120
-rw-r--r--sw/source/ui/vba/vbaformfieldcheckbox.hxx56
8 files changed, 207 insertions, 3 deletions
diff --git a/oovbaapi/ooo/vba/word/XCheckBox.idl b/oovbaapi/ooo/vba/word/XCheckBox.idl
index 42b7dd8b1f60..f1eb13a19c54 100644
--- a/oovbaapi/ooo/vba/word/XCheckBox.idl
+++ b/oovbaapi/ooo/vba/word/XCheckBox.idl
@@ -22,7 +22,21 @@ module ooo { module vba { module word {
interface XCheckBox
{
interface ooo::vba::XHelperInterface;
+ interface com::sun::star::script::XDefaultProperty;
+ /// Default member: True if the specified form field object is a valid check box form field.
+ [attribute, readonly] boolean Valid;
+
+ /** AutoSize:
+ * True sizes the check box or text frame according to the font size of the surrounding text.
+ * False sizes the check box or text frame according to the Size property.
+ */
+ [attribute] boolean AutoSize;
+ /// Returns or sets the default check box value. True if the default value is checked.
+ [attribute] boolean Default;
+ /// Returns or sets the size of a check box, in points.
+ [attribute] long Size;
+ /// Returns or sets true if the check box is ticked.
[attribute] boolean Value;
};
diff --git a/sw/Library_vbaswobj.mk b/sw/Library_vbaswobj.mk
index 752f682f2461..027b67a5f12c 100644
--- a/sw/Library_vbaswobj.mk
+++ b/sw/Library_vbaswobj.mk
@@ -74,6 +74,7 @@ $(eval $(call gb_Library_add_exception_objects,vbaswobj,\
sw/source/ui/vba/vbacolumns \
sw/source/ui/vba/vbaformfield \
sw/source/ui/vba/vbaformfields \
+ sw/source/ui/vba/vbaformfieldcheckbox \
sw/source/ui/vba/vbaframe \
sw/source/ui/vba/vbaframes \
sw/source/ui/vba/vbalistformat \
diff --git a/sw/qa/core/data/docm/testVBA.docm b/sw/qa/core/data/docm/testVBA.docm
index a2609feb6cd0..58ac4e8bd3ae 100644
--- a/sw/qa/core/data/docm/testVBA.docm
+++ b/sw/qa/core/data/docm/testVBA.docm
Binary files differ
diff --git a/sw/source/core/crsr/bookmark.cxx b/sw/source/core/crsr/bookmark.cxx
index 6801dd64db14..8bc383f01b23 100644
--- a/sw/source/core/crsr/bookmark.cxx
+++ b/sw/source/core/crsr/bookmark.cxx
@@ -644,6 +644,17 @@ namespace sw::mark
return bResult;
}
+ OUString CheckboxFieldmark::GetContent() const
+ {
+ return IsChecked() ? "1" : "0";
+ }
+
+ void CheckboxFieldmark::ReplaceContent(const OUString& sNewContent)
+ {
+ SetChecked(sNewContent.toBoolean());
+ Invalidate();
+ }
+
FieldmarkWithDropDownButton::FieldmarkWithDropDownButton(const SwPaM& rPaM)
: NonTextFieldmark(rPaM)
, m_pButton(nullptr)
diff --git a/sw/source/core/inc/bookmark.hxx b/sw/source/core/inc/bookmark.hxx
index 4dbfba8391e0..94788b8dcdcf 100644
--- a/sw/source/core/inc/bookmark.hxx
+++ b/sw/source/core/inc/bookmark.hxx
@@ -262,6 +262,8 @@ namespace sw::mark {
CheckboxFieldmark(const SwPaM& rPaM, const OUString& rName);
bool IsChecked() const override;
void SetChecked(bool checked) override;
+ virtual OUString GetContent() const override;
+ virtual void ReplaceContent(const OUString& sNewContent) override;
};
/// Fieldmark with a drop down button (e.g. this button opens the date picker for a date field)
diff --git a/sw/source/ui/vba/vbaformfield.cxx b/sw/source/ui/vba/vbaformfield.cxx
index 43b9f25cf660..50008fc9c2b7 100644
--- a/sw/source/ui/vba/vbaformfield.cxx
+++ b/sw/source/ui/vba/vbaformfield.cxx
@@ -25,6 +25,7 @@
#include <docsh.hxx>
#include "vbaformfield.hxx"
+#include "vbaformfieldcheckbox.hxx"
#include "wordvbahelper.hxx"
using namespace ::ooo::vba;
@@ -53,9 +54,8 @@ SwVbaFormField::~SwVbaFormField() {}
uno::Any SAL_CALL SwVbaFormField::CheckBox()
{
- // return uno::Any(uno::Reference<word::XCheckBox>(
- // new SwVbaFormFieldCheckBox(mxParent, mxContext, m_rFormField)));
- return uno::Any();
+ return uno::Any(uno::Reference<word::XCheckBox>(
+ new SwVbaFormFieldCheckBox(mxParent, mxContext, m_rFormField)));
}
uno::Any SAL_CALL SwVbaFormField::DropDown()
diff --git a/sw/source/ui/vba/vbaformfieldcheckbox.cxx b/sw/source/ui/vba/vbaformfieldcheckbox.cxx
new file mode 100644
index 000000000000..9370d7a3df9d
--- /dev/null
+++ b/sw/source/ui/vba/vbaformfieldcheckbox.cxx
@@ -0,0 +1,120 @@
+/* -*- 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 <sal/log.hxx>
+
+#include "vbaformfieldcheckbox.hxx"
+
+using namespace ::ooo::vba;
+using namespace ::com::sun::star;
+
+/**
+ * Information about the method and properties of CheckBox was gathered from
+ * https://www.codevba.com/Word/CheckBox.htm
+ *
+ * CheckBoxes 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 Checkbox, but it might not actually be one,
+ * so make good use of getValid()
+ */
+SwVbaFormFieldCheckBox::SwVbaFormFieldCheckBox(
+ const uno::Reference<ooo::vba::XHelperInterface>& rParent,
+ const uno::Reference<uno::XComponentContext>& rContext, sw::mark::IFieldmark& rFormField)
+ : SwVbaFormFieldCheckBox_BASE(rParent, rContext)
+ , m_pCheckBox(dynamic_cast<sw::mark::ICheckboxFieldmark*>(&rFormField))
+{
+}
+
+SwVbaFormFieldCheckBox::~SwVbaFormFieldCheckBox() {}
+
+OUString SwVbaFormFieldCheckBox::getDefaultPropertyName() { return "Valid"; }
+
+sal_Bool SwVbaFormFieldCheckBox::getValid()
+{
+ return m_pCheckBox
+ && IDocumentMarkAccess::GetType(*m_pCheckBox)
+ == IDocumentMarkAccess::MarkType::CHECKBOX_FIELDMARK;
+}
+
+sal_Bool SwVbaFormFieldCheckBox::getAutoSize()
+{
+ if (!getValid())
+ return false;
+
+ SAL_INFO("sw.vba", "SwVbaFormFieldCheckBox::getAutoSize stub");
+ return true;
+}
+
+void SwVbaFormFieldCheckBox::setAutoSize(sal_Bool /*bSet*/)
+{
+ if (!getValid())
+ return;
+
+ SAL_INFO("sw.vba", "SwVbaFormFieldCheckBox::setAutoSize stub");
+}
+
+sal_Bool SwVbaFormFieldCheckBox::getDefault()
+{
+ if (!getValid())
+ return false;
+
+ return getValue();
+}
+
+void SwVbaFormFieldCheckBox::setDefault(sal_Bool bSet)
+{
+ if (!getValid())
+ return;
+
+ // Hard to know what to do here, since LO doesn't have a default property for checkboxes.
+ // Setting this really only makes sense when macro-adding a checkbox.
+ // In that case, we want it to affect the actual checkbox.
+ // However, if the checkbox has already been set by the user, then this shouldn't do anything.
+ // Assuming this is only ever called when adding a checkbox seems the sanest approach.
+ setValue(bSet);
+}
+
+// Returns the size of a check box, in points
+sal_Int32 SwVbaFormFieldCheckBox::getSize()
+{
+ if (!getValid())
+ return 0;
+
+ SAL_INFO("sw.vba", "SwVbaFormFieldCheckBox::getSize stub");
+ return 11;
+}
+
+void SwVbaFormFieldCheckBox::setSize(sal_Int32 nSet)
+{
+ if (!getValid())
+ return;
+
+ SAL_INFO("sw.vba", "SwVbaFormFieldCheckBox::setSize[" << nSet << "] stub");
+}
+
+sal_Bool SwVbaFormFieldCheckBox::getValue() { return getValid() && m_pCheckBox->IsChecked(); }
+
+void SwVbaFormFieldCheckBox::setValue(sal_Bool bSet)
+{
+ if (!getValid() || !getValue() == !bSet)
+ return;
+
+ m_pCheckBox->SetChecked(bSet);
+}
+
+OUString SwVbaFormFieldCheckBox::getServiceImplName() { return "SwVbaFormFieldCheckBox"; }
+
+uno::Sequence<OUString> SwVbaFormFieldCheckBox::getServiceNames()
+{
+ static uno::Sequence<OUString> const aServiceNames{ "ooo.vba.word.CheckBox" };
+ return aServiceNames;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/ui/vba/vbaformfieldcheckbox.hxx b/sw/source/ui/vba/vbaformfieldcheckbox.hxx
new file mode 100644
index 000000000000..8f023e539e49
--- /dev/null
+++ b/sw/source/ui/vba/vbaformfieldcheckbox.hxx
@@ -0,0 +1,56 @@
+/* -*- 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/.
+ */
+#ifndef INCLUDED_SW_SOURCE_UI_VBA_VBAFORMFIELDCHECKBOX_HXX
+#define INCLUDED_SW_SOURCE_UI_VBA_VBAFORMFIELDCHECKBOX_HXX
+
+#include <ooo/vba/word/XCheckBox.hpp>
+
+#include <vbahelper/vbahelperinterface.hxx>
+
+#include <IDocumentMarkAccess.hxx>
+
+typedef InheritedHelperInterfaceWeakImpl<ooo::vba::word::XCheckBox> SwVbaFormFieldCheckBox_BASE;
+
+class SwVbaFormFieldCheckBox : public SwVbaFormFieldCheckBox_BASE
+{
+private:
+ sw::mark::ICheckboxFieldmark* m_pCheckBox;
+
+public:
+ /// @throws css::uno::RuntimeException
+ SwVbaFormFieldCheckBox(const css::uno::Reference<ooo::vba::XHelperInterface>& rParent,
+ const css::uno::Reference<css::uno::XComponentContext>& rContext,
+ sw::mark::IFieldmark& rFormField);
+ ~SwVbaFormFieldCheckBox() override;
+
+ // XCheckBox
+ virtual OUString SAL_CALL getDefaultPropertyName() override;
+
+ // Default member: True if the specified form field object is a valid check box form field
+ virtual sal_Bool SAL_CALL getValid() override;
+
+ virtual sal_Bool SAL_CALL getAutoSize() override;
+ virtual void SAL_CALL setAutoSize(sal_Bool bSet) override;
+ // Returns the default check box value
+ virtual sal_Bool SAL_CALL getDefault() override;
+ virtual void SAL_CALL setDefault(sal_Bool bSet) override;
+ // Returns the size of a check box, in points
+ virtual sal_Int32 SAL_CALL getSize() override;
+ virtual void SAL_CALL setSize(sal_Int32 nSet) override;
+
+ virtual sal_Bool SAL_CALL getValue() override;
+ virtual void SAL_CALL setValue(sal_Bool bSet) override;
+
+ // XHelperInterface
+ OUString getServiceImplName() override;
+ css::uno::Sequence<OUString> getServiceNames() override;
+};
+#endif // INCLUDED_SW_SOURCE_UI_VBA_VBAFORMFIELDCHECKBOX_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */