Files
libreoffice/sw/source/ui/vba/vbacontentcontrol.hxx

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

143 lines
5.8 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/.
*/
#pragma once
#include <com/sun/star/text/XTextDocument.hpp>
#include <ooo/vba/word/XContentControl.hpp>
#include <vbahelper/vbahelperinterface.hxx>
#include <textcontentcontrol.hxx>
typedef InheritedHelperInterfaceWeakImpl<ooo::vba::word::XContentControl> SwVbaContentControl_BASE;
class SwVbaContentControl : public SwVbaContentControl_BASE
{
private:
css::uno::Reference<css::text::XTextDocument> mxTextDocument;
std::shared_ptr<SwContentControl> m_pCC;
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
SwVbaContentControl(const css::uno::Reference<ooo::vba::XHelperInterface>& rParent,
const css::uno::Reference<css::uno::XComponentContext>& rContext,
const css::uno::Reference<css::text::XTextDocument>& xTextDocument,
std::shared_ptr<SwContentControl> pContentControl);
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
~SwVbaContentControl() override;
// XContentControl Properties
sal_Bool SAL_CALL getAllowInsertDeleteSection() override;
void SAL_CALL setAllowInsertDeleteSection(sal_Bool bSet) override;
sal_Int32 SAL_CALL getAppearance() override;
void SAL_CALL setAppearance(sal_Int32 nSet) override;
OUString SAL_CALL getBuildingBlockCategory() override;
void SAL_CALL setBuildingBlockCategory(const OUString& sSet) override;
sal_Int32 SAL_CALL getBuildingBlockType() override;
void SAL_CALL setBuildingBlockType(sal_Int32 nSet) override;
sal_Bool SAL_CALL getChecked() override;
void SAL_CALL setChecked(sal_Bool bSet) override;
// returns or sets a WdColor (@since after 2010 I assume)
sal_Int32 SAL_CALL getColor() override;
void SAL_CALL setColor(sal_Int32 nSet) override;
sal_Int32 SAL_CALL getDateCalendarType() override;
void SAL_CALL setDateCalendarType(sal_Int32 nSet) override;
OUString SAL_CALL getDateDisplayFormat() override;
void SAL_CALL setDateDisplayFormat(const OUString& sSet) override;
sal_Int32 SAL_CALL getDateDisplayLocale() override;
sal_Int32 SAL_CALL getDateStorageFormat() override;
void SAL_CALL setDateStorageFormat(sal_Int32 nSet) override;
css::uno::Any SAL_CALL getDropdownListEntries() override;
// This is an integer used as a unique identifier string
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
OUString SAL_CALL getID() override;
sal_Int32 SAL_CALL getLevel() override;
// returns or sets if the user can delete the control
sal_Bool SAL_CALL getLockContentControl() override;
void SAL_CALL setLockContentControl(sal_Bool bSet) override;
// returns or sets if the user can edit the contents (i.e. read-only flag)
sal_Bool SAL_CALL getLockContents() override;
void SAL_CALL setLockContents(sal_Bool bSet) override;
sal_Bool SAL_CALL getMultiLine() override;
void SAL_CALL setMultiLine(sal_Bool bSet) override;
// WRONG- THIS SHOULD RETURN XBUILDINGBLOCK
OUString SAL_CALL getPlaceholderText() override;
sal_Bool SAL_CALL getShowingPlaceholderText() override;
OUString SAL_CALL getRepeatingSectionItemTitle() override;
void SAL_CALL setRepeatingSectionItemTitle(const OUString& rSet) override;
css::uno::Reference<ooo::vba::word::XRange> SAL_CALL getRange() override;
OUString SAL_CALL getTag() override;
void SAL_CALL setTag(const OUString& rSet) override;
// returns or sets if the control is removed after accepting user change (i.e. control -> text)
sal_Bool SAL_CALL getTemporary() override;
void SAL_CALL setTemporary(sal_Bool bSet) override;
OUString SAL_CALL getTitle() override;
void SAL_CALL setTitle(const OUString& rSet) override;
// returns or sets a WdContentControlType that represents the type for a content control.
sal_Int32 SAL_CALL getType() override;
void SAL_CALL setType(sal_Int32 nSet) override;
// XContentControl Methods
// Copies the content control from the active document to the Clipboard.
// Retrieve from the clipboard using the Paste method of the Selection object
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
// or of the Range object, or use the Paste function from within Microsoft Word.
void SAL_CALL Copy() override;
// Removes the control from the active document and moves it to the Clipboard.
void SAL_CALL Cut() override;
// Specifies whether to delete the contents of the content control. The default value is False.
// True removes both the content control and its contents.
// False removes the control but leaves the contents of the content control in the document.
void SAL_CALL Delete(const css::uno::Any& bDeleteContents) override;
// Set the Unicode character used to display the checked state.
void SAL_CALL SetCheckedSymbol(sal_Int32 Character, const css::uno::Any& sFont) override;
// Set the Unicode character used to display the unchecked state.
void SAL_CALL SetUnCheckedSymbol(sal_Int32 Character, const css::uno::Any& sFont) override;
// Sets the placeholder text that displays until a user enters their own text.
// Only one of the parameters is used when specifying placeholder text.
// If more than one parameter is provided, use the text specified in the first parameter.
// If all parameters are omitted, the placeholder text is blank.
void SAL_CALL SetPlaceholderText(const css::uno::Any& BuildingBlock, const css::uno::Any& Range,
const css::uno::Any& sText) override;
void SAL_CALL Ungroup() override;
// XHelperInterface
OUString getServiceImplName() override;
css::uno::Sequence<OUString> getServiceNames() override;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */