ITEM: Refactor ItemType
[LibreOffice.git] / sw / source / ui / vba / vbaformfieldcheckbox.cxx
bloba6740970c1b82a259f8484a95b5f1f74b7329c36
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <sal/log.hxx>
12 #include "vbaformfieldcheckbox.hxx"
14 using namespace ::ooo::vba;
15 using namespace ::com::sun::star;
17 /**
18 * CheckBoxes are inline text objects that are only found in MS Word.
19 * They cannot be created in Excel or in Calc.
21 * Note that VBA might call this a Checkbox, but it might not actually be one,
22 * so make good use of getValid()
24 SwVbaFormFieldCheckBox::SwVbaFormFieldCheckBox(
25 const uno::Reference<ooo::vba::XHelperInterface>& rParent,
26 const uno::Reference<uno::XComponentContext>& rContext, sw::mark::Fieldmark& rFormField)
27 : SwVbaFormFieldCheckBox_BASE(rParent, rContext)
28 , m_pCheckBox(dynamic_cast<sw::mark::CheckboxFieldmark*>(&rFormField))
32 SwVbaFormFieldCheckBox::~SwVbaFormFieldCheckBox() {}
34 OUString SwVbaFormFieldCheckBox::getDefaultPropertyName() { return u"Valid"_ustr; }
36 sal_Bool SwVbaFormFieldCheckBox::getValid()
38 return m_pCheckBox
39 && IDocumentMarkAccess::GetType(*m_pCheckBox)
40 == IDocumentMarkAccess::MarkType::CHECKBOX_FIELDMARK;
43 sal_Bool SwVbaFormFieldCheckBox::getAutoSize()
45 if (!getValid())
46 return false;
48 SAL_INFO("sw.vba", "SwVbaFormFieldCheckBox::getAutoSize stub");
49 return true;
52 void SwVbaFormFieldCheckBox::setAutoSize(sal_Bool /*bSet*/)
54 if (!getValid())
55 return;
57 SAL_INFO("sw.vba", "SwVbaFormFieldCheckBox::setAutoSize stub");
60 sal_Bool SwVbaFormFieldCheckBox::getDefault()
62 if (!getValid())
63 return false;
65 return getValue();
68 void SwVbaFormFieldCheckBox::setDefault(sal_Bool bSet)
70 if (!getValid())
71 return;
73 // Hard to know what to do here, since LO doesn't have a default property for checkboxes.
74 // Setting this really only makes sense when macro-adding a checkbox.
75 // In that case, we want it to affect the actual checkbox.
76 // However, if the checkbox has already been set by the user, then this shouldn't do anything.
77 // Assuming this is only ever called when adding a checkbox seems the sanest approach.
78 setValue(bSet);
81 // Returns the size of a check box, in points
82 sal_Int32 SwVbaFormFieldCheckBox::getSize()
84 if (!getValid())
85 return 0;
87 SAL_INFO("sw.vba", "SwVbaFormFieldCheckBox::getSize stub");
88 return 11;
91 void SwVbaFormFieldCheckBox::setSize(sal_Int32 nSet)
93 if (!getValid())
94 return;
96 SAL_INFO("sw.vba", "SwVbaFormFieldCheckBox::setSize[" << nSet << "] stub");
99 sal_Bool SwVbaFormFieldCheckBox::getValue() { return getValid() && m_pCheckBox->IsChecked(); }
101 void SwVbaFormFieldCheckBox::setValue(sal_Bool bSet)
103 if (!getValid() || !getValue() == !bSet)
104 return;
106 m_pCheckBox->SetChecked(bSet);
109 OUString SwVbaFormFieldCheckBox::getServiceImplName() { return u"SwVbaFormFieldCheckBox"_ustr; }
111 uno::Sequence<OUString> SwVbaFormFieldCheckBox::getServiceNames()
113 static uno::Sequence<OUString> const aServiceNames{ u"ooo.vba.word.CheckBox"_ustr };
114 return aServiceNames;
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */