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 Binary files a/sw/qa/core/data/docm/testVBA.docm and b/sw/qa/core/data/docm/testVBA.docm 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 #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( - // new SwVbaFormFieldCheckBox(mxParent, mxContext, m_rFormField))); - return uno::Any(); + return uno::Any(uno::Reference( + 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 + +#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& rParent, + const uno::Reference& rContext, sw::mark::IFieldmark& rFormField) + : SwVbaFormFieldCheckBox_BASE(rParent, rContext) + , m_pCheckBox(dynamic_cast(&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 SwVbaFormFieldCheckBox::getServiceNames() +{ + static uno::Sequence 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 + +#include + +#include + +typedef InheritedHelperInterfaceWeakImpl SwVbaFormFieldCheckBox_BASE; + +class SwVbaFormFieldCheckBox : public SwVbaFormFieldCheckBox_BASE +{ +private: + sw::mark::ICheckboxFieldmark* m_pCheckBox; + +public: + /// @throws css::uno::RuntimeException + SwVbaFormFieldCheckBox(const css::uno::Reference& rParent, + const css::uno::Reference& 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 getServiceNames() override; +}; +#endif // INCLUDED_SW_SOURCE_UI_VBA_VBAFORMFIELDCHECKBOX_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */