Files
libreoffice/sw/source/ui/vba/vbacontentcontrols.cxx

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

269 lines
9.2 KiB
C++
Raw Normal View History

tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
/* -*- 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 <comphelper/sequence.hxx>
#include <sal/log.hxx>
#include <doc.hxx>
#include <docsh.hxx>
#include <textcontentcontrol.hxx>
#include "vbacontentcontrol.hxx"
#include "vbacontentcontrols.hxx"
#include "wordvbahelper.hxx"
using namespace ::ooo::vba;
using namespace ::com::sun::star;
// Helper function to access the content controls
// @param rIndex
// [in] negative indexes indicate the need to search by name, otherwise get by index,
// using SAL_MAX_INT32 to indicate the need to just get the total count.
// [out] rIndex indicates the found index, or the total number of content controls
static std::shared_ptr<SwContentControl>
tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
lcl_getContentControl(std::u16string_view sName, std::u16string_view sTag,
std::u16string_view sTitle, sal_Int32& rIndex,
const uno::Reference<text::XTextDocument>& xTextDocument,
uno::Sequence<OUString>* pElementNames = nullptr)
{
SwDoc* pDoc = word::getDocShell(xTextDocument)->GetDoc();
if (!pDoc)
return nullptr;
assert(sTag.empty() || sTitle.empty()); // only one grouping at a time is allowed
std::shared_ptr<SwContentControl> pControl;
tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
std::vector<OUString> vElementNames;
SwContentControlManager& rManager = pDoc->GetContentControlManager();
const size_t nLen = rManager.GetCount();
if (!pElementNames && rIndex > 0 && sName.empty() && sTag.empty() && sTitle.empty())
{
size_t i = static_cast<size_t>(rIndex);
tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
// This is the normal get-by-index/getCount mode - no need for fancy filtering.
if (i < nLen)
pControl = rManager.Get(i)->GetContentControl().GetContentControl();
tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
else
rIndex = nLen;
}
else
{
// loop through everything collecting names, filtering by Tag/Title
sal_Int32 nCounter = 0;
for (size_t i = 0; i < nLen; ++i)
tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
{
pControl = rManager.Get(i)->GetContentControl().GetContentControl();
if (!sTag.empty() && sTag != pControl->GetTag())
{
pControl = nullptr;
tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
continue;
}
if (!sTitle.empty() && sTitle != pControl->GetAlias())
{
pControl = nullptr;
tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
continue;
}
tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
// When treated as a name, consider the integer ID to be unsigned
const OUString sID = OUString::number(static_cast<sal_uInt32>(pControl->GetId()));
if (!sName.empty() && sName != sID)
{
pControl = nullptr;
continue;
}
tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
if (pElementNames)
vElementNames.push_back(sID);
tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
if (rIndex == nCounter || !sName.empty())
tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
break;
pControl = nullptr;
++nCounter;
}
rIndex = nCounter;
}
if (pElementNames)
*pElementNames = comphelper::containerToSequence(vElementNames);
return pControl;
}
namespace
{
class ContentControlsEnumWrapper : public EnumerationHelper_BASE
{
uno::Reference<container::XIndexAccess> mxIndexAccess;
sal_Int32 mnIndex;
tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
public:
explicit ContentControlsEnumWrapper(uno::Reference<container::XIndexAccess> xIndexAccess)
: mxIndexAccess(std::move(xIndexAccess))
, mnIndex(0)
tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
{
}
sal_Bool SAL_CALL hasMoreElements() override { return (mnIndex < mxIndexAccess->getCount()); }
tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
uno::Any SAL_CALL nextElement() override
{
if (mnIndex < mxIndexAccess->getCount())
tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
{
return mxIndexAccess->getByIndex(mnIndex++);
tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
}
throw container::NoSuchElementException();
}
};
class ContentControlCollectionHelper
: public ::cppu::WeakImplHelper<container::XNameAccess, container::XIndexAccess,
container::XEnumerationAccess>
{
private:
uno::Reference<XHelperInterface> mxParent;
uno::Reference<uno::XComponentContext> mxContext;
uno::Reference<text::XTextDocument> mxTextDocument;
const OUString m_sTag;
const OUString m_sTitle;
std::shared_ptr<SwContentControl> m_pCache;
tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
public:
/// @throws css::uno::RuntimeException
ContentControlCollectionHelper(uno::Reference<ov::XHelperInterface> xParent,
uno::Reference<uno::XComponentContext> xContext,
uno::Reference<text::XTextDocument> xTextDocument,
const OUString& rTag, const OUString& rTitle)
: mxParent(std::move(xParent))
, mxContext(std::move(xContext))
, mxTextDocument(std::move(xTextDocument))
, m_sTag(rTag)
, m_sTitle(rTitle)
{
}
// XIndexAccess
sal_Int32 SAL_CALL getCount() override
{
sal_Int32 nCount = SAL_MAX_INT32;
lcl_getContentControl(u"", m_sTag, m_sTitle, nCount, mxTextDocument);
return nCount == SAL_MAX_INT32 || nCount < 0 ? 0 : nCount;
}
uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
{
m_pCache = lcl_getContentControl(u"", m_sTag, m_sTitle, Index, mxTextDocument);
if (!m_pCache)
throw lang::IndexOutOfBoundsException();
return uno::Any(uno::Reference<word::XContentControl>(
new SwVbaContentControl(mxParent, mxContext, mxTextDocument, m_pCache)));
tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
}
// XNameAccess
uno::Sequence<OUString> SAL_CALL getElementNames() override
{
sal_Int32 nCount = SAL_MAX_INT32;
uno::Sequence<OUString> aSeq;
lcl_getContentControl(u"", m_sTag, m_sTitle, nCount, mxTextDocument, &aSeq);
return aSeq;
}
uno::Any SAL_CALL getByName(const OUString& aName) override
{
if (!hasByName(aName))
throw container::NoSuchElementException();
return uno::Any(uno::Reference<word::XContentControl>(
new SwVbaContentControl(mxParent, mxContext, mxTextDocument, m_pCache)));
tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
}
sal_Bool SAL_CALL hasByName(const OUString& aName) override
{
sal_Int32 nCount = -1;
m_pCache = lcl_getContentControl(aName, m_sTag, m_sTitle, nCount, mxTextDocument);
return m_pCache != nullptr;
}
// XElementAccess
uno::Type SAL_CALL getElementType() override
{
return cppu::UnoType<word::XContentControl>::get();
}
sal_Bool SAL_CALL hasElements() override { return getCount() != 0; }
// XEnumerationAccess
uno::Reference<container::XEnumeration> SAL_CALL createEnumeration() override
{
return new ContentControlsEnumWrapper(this);
}
};
}
/**
* Content Controls can be accessed and filtered in many different ways.
* Surprisingly however, there is no clear, descriptive "by name" access.
* Instead, each content control (probably) has a unique _signed-integer_ identifier,
* which can be passed to Item() as a float or _unsigned-integer_ string
* (to differentiate it from getByIndex).
*
* Index access can be filtered by Tag, Title, Range, and XML link.
* TODO: add filtering for Range, SelectLinkedControls, SelectUnlinkedControls
*/
SwVbaContentControls::SwVbaContentControls(const uno::Reference<XHelperInterface>& xParent,
const uno::Reference<uno::XComponentContext>& xContext,
const uno::Reference<text::XTextDocument>& xTextDocument,
const OUString& rTag, const OUString& rTitle)
: SwVbaContentControls_BASE(
xParent, xContext,
uno::Reference<container::XIndexAccess>(
new ContentControlCollectionHelper(xParent, xContext, xTextDocument, rTag, rTitle)))
{
}
// uno::Reference<ooo::vba::word::XContentControl> SwVbaContentControls::Add(const uno::Any& Range,
// sal_Int32 Type)
// {
// sw::mark::IFieldmark* pFieldmark = nullptr;
// switch (Type)
// {
// case ooo::vba::word::WdFieldType::wdFieldFormCheckBox:
// break;
// case ooo::vba::word::WdFieldType::wdFieldFormDropDown:
// break;
// case ooo::vba::word::WdFieldType::wdFieldFormTextInput:
// default:;
// }
//
// return uno::Reference<ooo::vba::word::XContentControl>(
// new SwVbaContentControl(mxParent, mxContext, m_xTextDocument, pFieldmark));
tdf#151548 vba ContentControls: Add basic word::XContentControl This adds basic VBA macro support for accessing the modern content controls used for creating forms. I ran out of time to make it fully functional. TODO -Invalidation: the screen isn't updating the modified results until interaction from the user (mouse click, etc.) -Unlike FormFields, content controls really depend on having Range working. I didn't have time to look into that. -I was hoping to check that my approach could accommodate the other methods that create a filtered ContentControls object: * Document.SelectLinkedControls, * Document.SelectUnlinkedControls * Range.ContentControls. I guess it will be left up to whoever needs these to add the bits that will create an appropriate collection for these limited sets. -setType: changing one type to another - both LO and Word allow limited use of this - depending on the text contents fitting the new type. What works: -getByIndex - which probably is the "normal" way to do it, since the UI doesn't provide a name/ID; just got via msgbox .ID. -full checkbox support (minus the visual invalidation) -VBA accepts almost all properties/methods that are requested. make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba If Not ActiveDocument.ContentControls(1).Checked If ActiveDocument.ContentControls(2).Checked 'If ActiveDocument.ContentControls(2).Range.Text <> "$" ActiveDocument.SelectContentControlsByTag("checkboxes").Item(1).Checked = ActiveDocument.SelectContentControlsByTag("checkboxes").Item(2).Checked ActiveDocument.SelectContentControlsByTag("checkboxes") .Item(2).SetUncheckedSymbol (8364) '€ With ActiveDocument.SelectContentControlsByTitle("listbox").Item(1) If Not .ShowingPlaceholderText 'If .Range.Text <> "Choose an item." If .Type <> wdContentControlDropdownList End With With ActiveDocument.ContentControls.Item(5) 'If Not .Temporary Then GoTo errorhandler: If .Temporary <> False Then GoTo errorhandler: If .Tag <> "" Then GoTo errorhandler: If .Title <> "" Then GoTo errorhandler: End With With ActiveDocument.ContentControls.Item(6) If .Type <> wdContentControlText If .MultiLine Then GoTo errorhandler: If ActiveDocument.ContentControls.Count <> 7 .Delete 'Doesn't actually Delete in LO yet - unsafe ' If ActiveDocument.ContentControls.Count <> 6 End With ' Change to 6 when delete is working safely With ActiveDocument.ContentControls.Item(7) If .Type <> wdContentControlDate Then GoTo errorhandler: .Color = wdColorBlueGray 'unknown to Word 2010 If .Color <> wdColorBlueGray Then GoTo errorhandler: If .DateDisplayFormat <> "mm/yy/dd" Then GoTo errorhandler: If .DateCalendarType <> wdCalendarWestern Then GoTo errorhandler: If .LockContents <> False Then GoTo errorhandler: End With Change-Id: I1c636f671de81e0283c040a578838a0433ef1f5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143080 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
2022-11-21 11:44:52 -05:00
// }
// XEnumerationAccess
uno::Type SwVbaContentControls::getElementType()
{
return cppu::UnoType<word::XContentControl>::get();
}
uno::Reference<container::XEnumeration> SwVbaContentControls::createEnumeration()
{
return new ContentControlsEnumWrapper(m_xIndexAccess);
}
uno::Any SwVbaContentControls::createCollectionObject(const uno::Any& aSource) { return aSource; }
OUString SwVbaContentControls::getServiceImplName() { return "SwVbaContentControls"; }
uno::Sequence<OUString> SwVbaContentControls::getServiceNames()
{
static uno::Sequence<OUString> const sNames{ "ooo.vba.word.ContentControls" };
return sNames;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */