summaryrefslogtreecommitdiff
path: root/oovbaapi
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2022-11-21 11:44:52 -0500
committerJustin Luth <jluth@mail.com>2022-11-24 23:24:49 +0100
commit24d7431876e87eba700a9f141dc8e030143a92ad (patch)
tree894e49e8e764a69849c86dddd51742ba3ab2caf2 /oovbaapi
parentb789f54cb0bb2ae2f1d2cba3b3e5920085c8696d (diff)
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>
Diffstat (limited to 'oovbaapi')
-rw-r--r--oovbaapi/UnoApi_oovbaapi.mk3
-rw-r--r--oovbaapi/ooo/vba/word/WdContentControlType.idl25
-rw-r--r--oovbaapi/ooo/vba/word/XContentControl.idl103
-rw-r--r--oovbaapi/ooo/vba/word/XContentControls.idl23
-rw-r--r--oovbaapi/ooo/vba/word/XDocument.idl3
5 files changed, 157 insertions, 0 deletions
diff --git a/oovbaapi/UnoApi_oovbaapi.mk b/oovbaapi/UnoApi_oovbaapi.mk
index 331cf4937e32..063700762e46 100644
--- a/oovbaapi/UnoApi_oovbaapi.mk
+++ b/oovbaapi/UnoApi_oovbaapi.mk
@@ -833,6 +833,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,oovbaapi,ooo/vba/word,\
WdFarEastLineBreakLevel \
WdFieldKind \
WdFieldShading \
+ WdContentControlType \
WdFieldType \
WdFindMatch \
WdFindWrap \
@@ -1057,6 +1058,8 @@ $(eval $(call gb_UnoApi_add_idlfiles,oovbaapi,ooo/vba/word,\
XFields \
XFind \
XFont \
+ XContentControl \
+ XContentControls \
XFormField \
XFormFields \
XFrame \
diff --git a/oovbaapi/ooo/vba/word/WdContentControlType.idl b/oovbaapi/ooo/vba/word/WdContentControlType.idl
new file mode 100644
index 000000000000..d93159a07b66
--- /dev/null
+++ b/oovbaapi/ooo/vba/word/WdContentControlType.idl
@@ -0,0 +1,25 @@
+/* -*- 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/.
+ */
+
+module ooo { module vba { module word {
+ constants WdContentControlType {
+ const long wdContentControlRichText = 0;
+ const long wdContentControlText = 1;
+ const long wdContentControlPicture = 2;
+ const long wdContentControlComboBox = 3;
+ const long wdContentControlDropdownList = 4;
+ const long wdContentControlBuildingBlockGallery = 5;
+ const long wdContentControlDate = 6;
+ const long wdContentControlGroup = 7;
+ const long wdContentControlCheckbox = 8;
+ const long wdContentControlRepeatingSection = 9;
+ };
+}; }; };
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oovbaapi/ooo/vba/word/XContentControl.idl b/oovbaapi/ooo/vba/word/XContentControl.idl
new file mode 100644
index 000000000000..e53846022786
--- /dev/null
+++ b/oovbaapi/ooo/vba/word/XContentControl.idl
@@ -0,0 +1,103 @@
+/* -*- 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/.
+ */
+
+module ooo { module vba { module word {
+
+interface XRange;
+interface XContentControlListEntries;
+interface XContentControl
+{
+ interface ooo::vba::XHelperInterface;
+
+ /// returns or sets whether users can add/remove sections from the specified repeating section
+ /// content control by using the user interface.
+ /// Use only with repeating section content controls.
+ [attribute] boolean AllowInsertDeleteSection;
+ /// returns or sets the appearance of the content control.
+ /// (wdContentControlBoundingBox/wdContentControlHidden/wdContentControlTags)
+ [attribute] long Appearance;
+ /// returns or sets a String that represents the category for a building block content control.
+ [attribute] string BuildingBlockCategory;
+ /// returns or sets a WdBuildingBlockTypes constant that represents the type of building block
+ /// for a building block content control.
+ [attribute] long BuildingBlockType;
+ /// returns or sets a Boolean that represents a check box's current state (checked/unchecked).
+ [attribute] boolean Checked;
+ /// returns or sets the color of the content control.
+ [attribute] long Color;
+ /// returns or sets a WdCalendarType constant that represents the calendar type.
+ [attribute] long DateCalendarType;
+ /// returns or sets a String that represents the format in which dates are displayed.
+ [attribute] string DateDisplayFormat;
+ /// returns a WdLanguageID that represents the language format for the date displayed.
+ [attribute, readonly] long DateDisplayLocale;
+ /// returns or sets a WdContentControlDateStorageFormat that represents the format for storage
+ /// and retrieval of dates when a date content control is bound to the XML data store.
+ [attribute] long DateStorageFormat;
+ /// returns or sets a Variant that represents the name of the character style to use to format text in a text content control.
+ //[attribute] string DefaultTextStyle;
+ /// returns a ContentControlListEntries collection that represents the items
+ /// in a drop-down list content control or in a combo box content control.
+ [attribute, readonly] any DropdownListEntries;
+ /// returns a String that represents the identification for a content control.
+ [attribute, readonly] string ID;
+ /// returns the level of the content control—whether the content control surrounds text, paragraphs, table cells, or table rows; or if it is inline.
+ /// (wdContentControlLevelCell/wdContentControlLevelInline/wdContentControlLevelParagraph/wdContentControlLevelRow)
+ [attribute, readonly] long Level;
+ /// returns or sets whether the user can delete a content control from the active document.
+ [attribute] boolean LockContentControl;
+ /// returns or sets whether the user can edit the contents of a content control.
+ [attribute] boolean LockContents;
+ /// returns or sets whether a text content control allows multiple lines of text.
+ [attribute] boolean MultiLine;
+ /// returns a ContentControl that represents the parent content control for a content control that is nested inside a rich-text control or group control.
+ //[attribute, readonly] XContentControl ParentContentControl;
+ /// returns a BuildingBlock object that represents the placeholder text for a content control.
+ [attribute, readonly] /*WRONG - should be XBuildingBlock*/ string PlaceholderText;
+ /// returns a Range that represents the contents of the content control in the active document.
+ [attribute, readonly] XRange Range;
+ /// returns the collection of repeating section items in the specified repeating section content control.
+ //[attribute, readonly] RepeatingSectionItems;
+ /// returns or sets the name of the repeating section items used in the context menu associated
+ /// with the specified repeating section content control.
+ [attribute] string RepeatingSectionItemTitle;
+ /// returns whether the placeholder text for the content control is displayed.
+ [attribute, readonly] boolean ShowingPlaceholderText;
+ /// returns or sets a String that represents a value to identify a content control.
+ [attribute] string Tag;
+ /// returns or sets whether to remove a content control from the active document
+ /// when the user edits the contents of the control.
+ [attribute] boolean Temporary;
+ /// returns or sets a String that represents the title for a content control.
+ [attribute] string Title;
+ /// returns or sets a WdContentControlType that represents the type for a content control.
+ [attribute] long Type;
+ /// returns an XMLMapping object that represents the mapping of a content control to XML data in the data store of a document.
+ //[attribute, readonly] XMLMapping;
+
+ /// Copies the content control from the active document to the Clipboard.
+ void Copy();
+ /// Removes the content control from the active document and moves it to the Clipboard.
+ void Cut();
+ /// Deletes the specified content control and the contents of the content control.
+ void Delete( [in] /*optional*/ any bDeleteContents );
+ /// Sets the symbol used to represent the checked state of a check box content control.
+ void SetCheckedSymbol( [in] long Character, [in] /*optional*/ any sFont );
+ /// Sets the symbol used to represent the unchecked state of a check box content control.
+ void SetUnCheckedSymbol( [in] long Character, [in] /*optional*/ any sFont );
+ /// Sets the placeholder text that displays until a user enters their own text.
+ void SetPlaceholderText( [in] /*optional*/ any BuildingBlock, [in] /*optional*/ any Range, [in] /*optional*/ any sFont );
+ /// Removes a group content control. Its children are no longer nested and can be freely edited.
+ void Ungroup();
+
+};
+
+}; }; };
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oovbaapi/ooo/vba/word/XContentControls.idl b/oovbaapi/ooo/vba/word/XContentControls.idl
new file mode 100644
index 000000000000..49facea70b40
--- /dev/null
+++ b/oovbaapi/ooo/vba/word/XContentControls.idl
@@ -0,0 +1,23 @@
+/* -*- 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/.
+ */
+
+module ooo { module vba { module word {
+
+interface XContentControl;
+interface XContentControls
+{
+ interface ::ooo::vba::XCollection;
+
+ /// Returns a ContentControl object that represents a new WdContentControlType added at a range
+ //XContentControl Add( [in] /*optional*/ any Type, [in] /*optional*/ any Range ) raises ( com::sun::star::script::BasicErrorException );
+};
+
+}; }; };
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oovbaapi/ooo/vba/word/XDocument.idl b/oovbaapi/ooo/vba/word/XDocument.idl
index 0f7b5f994aa1..354cac11b2ed 100644
--- a/oovbaapi/ooo/vba/word/XDocument.idl
+++ b/oovbaapi/ooo/vba/word/XDocument.idl
@@ -37,6 +37,9 @@ interface XDocument
any BuiltInDocumentProperties( [in] any Index );
any CustomDocumentProperties( [in] any Index );
any Bookmarks( [in] any Index );
+ any ContentControls( [in] any Index );
+ any SelectContentControlsByTag( [in] any Index );
+ any SelectContentControlsByTitle( [in] any Index );
any Variables( [in] any Index );
any Paragraphs( [in] any Index );
any Styles( [in] any Index ) raises (com::sun::star::script::BasicErrorException);