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>
This commit is contained in:
parent
1b5c7bad0f
commit
7444c8c87a
8 changed files with 207 additions and 3 deletions
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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 \
|
||||
|
|
Binary file not shown.
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
120
sw/source/ui/vba/vbaformfieldcheckbox.cxx
Normal file
120
sw/source/ui/vba/vbaformfieldcheckbox.cxx
Normal file
|
@ -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: */
|
56
sw/source/ui/vba/vbaformfieldcheckbox.hxx
Normal file
56
sw/source/ui/vba/vbaformfieldcheckbox.hxx
Normal file
|
@ -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: */
|
Loading…
Reference in a new issue