diff options
author | Justin Luth <justin.luth@collabora.com> | 2022-12-13 18:52:09 -0500 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-12-16 07:39:43 +0000 |
commit | 88d4e7416921d4c3c71d9effa04ff56a541b169d (patch) | |
tree | e11f28e75b1350e9209b77b0d2e2d438da8418b7 | |
parent | 54599383a2f86b83c237a10f7d9fce492e798487 (diff) |
tdf#151548 vba FormFields: implement Range
Msgbox (FormFields("text1").Range.Text)
Change-Id: Iac195e09bd3f9619890b336a0cb537a1acd00049
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144136
Tested-by: Jenkins
Reviewed-by: Justin Luth <jluth@mail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r-- | oovbaapi/ooo/vba/word/XFormField.idl | 3 | ||||
-rw-r--r-- | sw/qa/core/data/docm/testVBA.docm | bin | 32952 -> 32380 bytes | |||
-rw-r--r-- | sw/source/ui/vba/vbadocument.cxx | 2 | ||||
-rw-r--r-- | sw/source/ui/vba/vbaformfield.cxx | 29 | ||||
-rw-r--r-- | sw/source/ui/vba/vbaformfield.hxx | 7 | ||||
-rw-r--r-- | sw/source/ui/vba/vbaformfields.cxx | 25 | ||||
-rw-r--r-- | sw/source/ui/vba/vbaformfields.hxx | 3 |
7 files changed, 42 insertions, 27 deletions
diff --git a/oovbaapi/ooo/vba/word/XFormField.idl b/oovbaapi/ooo/vba/word/XFormField.idl index 3d51fcd263cd..06543067c6eb 100644 --- a/oovbaapi/ooo/vba/word/XFormField.idl +++ b/oovbaapi/ooo/vba/word/XFormField.idl @@ -19,6 +19,7 @@ module ooo { module vba { module word { +interface XRange; interface XFormField { interface ooo::vba::XHelperInterface; @@ -75,7 +76,7 @@ interface XFormField * Represents a contiguous area in a document. * Each Range object is defined by a starting and ending character position. */ - any Range(); + XRange Range(); }; }; }; }; diff --git a/sw/qa/core/data/docm/testVBA.docm b/sw/qa/core/data/docm/testVBA.docm Binary files differindex 839c8dd9f73c..44e59f03a753 100644 --- a/sw/qa/core/data/docm/testVBA.docm +++ b/sw/qa/core/data/docm/testVBA.docm diff --git a/sw/source/ui/vba/vbadocument.cxx b/sw/source/ui/vba/vbadocument.cxx index c7e9731001bf..52907477dcff 100644 --- a/sw/source/ui/vba/vbadocument.cxx +++ b/sw/source/ui/vba/vbadocument.cxx @@ -327,7 +327,7 @@ SwVbaDocument::TablesOfContents( const uno::Any& index ) uno::Any SAL_CALL SwVbaDocument::FormFields(const uno::Any& index) { - uno::Reference<XCollection> xCol(new SwVbaFormFields(this, mxContext, mxModel)); + uno::Reference<XCollection> xCol(new SwVbaFormFields(this, mxContext, mxTextDocument)); if (index.hasValue()) return xCol->Item(index, uno::Any()); return uno::Any(xCol); diff --git a/sw/source/ui/vba/vbaformfield.cxx b/sw/source/ui/vba/vbaformfield.cxx index 8afaeb9d9480..0c8a8644e990 100644 --- a/sw/source/ui/vba/vbaformfield.cxx +++ b/sw/source/ui/vba/vbaformfield.cxx @@ -13,11 +13,13 @@ #include <doc.hxx> #include <docsh.hxx> +#include <unotextrange.hxx> #include "vbaformfield.hxx" #include "vbaformfieldcheckbox.hxx" #include "vbaformfielddropdown.hxx" #include "vbaformfieldtextinput.hxx" +#include "vbarange.hxx" #include "wordvbahelper.hxx" using namespace ::ooo::vba; @@ -34,10 +36,10 @@ using namespace ::com::sun::star; */ SwVbaFormField::SwVbaFormField(const uno::Reference<ooo::vba::XHelperInterface>& rParent, const uno::Reference<uno::XComponentContext>& rContext, - const uno::Reference<frame::XModel>& xModel, + const uno::Reference<text::XTextDocument>& xTextDocument, sw::mark::IFieldmark& rFormField) : SwVbaFormField_BASE(rParent, rContext) - , mxModel(xModel) + , m_xTextDocument(xTextDocument) , m_rFormField(rFormField) { } @@ -64,7 +66,7 @@ uno::Any SAL_CALL SwVbaFormField::TextInput() uno::Any SAL_CALL SwVbaFormField::Previous() { - SwDoc* pDoc = word::getDocShell(mxModel)->GetDoc(); + SwDoc* pDoc = word::getDocShell(m_xTextDocument)->GetDoc(); if (!pDoc) return uno::Any(); @@ -86,12 +88,12 @@ uno::Any SAL_CALL SwVbaFormField::Previous() return uno::Any(); return uno::Any(uno::Reference<word::XFormField>( - new SwVbaFormField(mxParent, mxContext, mxModel, *pFieldMark))); + new SwVbaFormField(mxParent, mxContext, m_xTextDocument, *pFieldMark))); } uno::Any SAL_CALL SwVbaFormField::Next() { - SwDoc* pDoc = word::getDocShell(mxModel)->GetDoc(); + SwDoc* pDoc = word::getDocShell(m_xTextDocument)->GetDoc(); if (!pDoc) return uno::Any(); @@ -113,13 +115,22 @@ uno::Any SAL_CALL SwVbaFormField::Next() return uno::Any(); return uno::Any(uno::Reference<word::XFormField>( - new SwVbaFormField(mxParent, mxContext, mxModel, *pFieldMark))); + new SwVbaFormField(mxParent, mxContext, m_xTextDocument, *pFieldMark))); } -uno::Any SAL_CALL SwVbaFormField::Range() +uno::Reference<word::XRange> SwVbaFormField::Range() { - SAL_INFO("sw.vba", "SwVbaFormField::getRange stub"); - return uno::Any(); + uno::Reference<word::XRange> xRet; + SwDoc* pDoc = word::getDocShell(m_xTextDocument)->GetDoc(); + if (pDoc) + { + uno::Reference<text::XTextRange> xText(SwXTextRange::CreateXTextRange( + *pDoc, m_rFormField.GetMarkStart(), &m_rFormField.GetMarkEnd())); + if (xText.is()) + xRet = new SwVbaRange(mxParent, mxContext, m_xTextDocument, xText->getStart(), + xText->getEnd()); + } + return xRet; } OUString SwVbaFormField::getDefaultPropertyName() { return "Type"; } diff --git a/sw/source/ui/vba/vbaformfield.hxx b/sw/source/ui/vba/vbaformfield.hxx index b004e4088cdb..260e79093589 100644 --- a/sw/source/ui/vba/vbaformfield.hxx +++ b/sw/source/ui/vba/vbaformfield.hxx @@ -8,6 +8,7 @@ */ #pragma once +#include <com/sun/star/text/XTextDocument.hpp> #include <ooo/vba/word/XFormField.hpp> #include <vbahelper/vbahelperinterface.hxx> @@ -19,14 +20,14 @@ typedef InheritedHelperInterfaceWeakImpl<ooo::vba::word::XFormField> SwVbaFormFi class SwVbaFormField : public SwVbaFormField_BASE { private: - css::uno::Reference<css::frame::XModel> mxModel; + css::uno::Reference<css::text::XTextDocument> m_xTextDocument; sw::mark::IFieldmark& m_rFormField; public: /// @throws css::uno::RuntimeException SwVbaFormField(const css::uno::Reference<ooo::vba::XHelperInterface>& rParent, const css::uno::Reference<css::uno::XComponentContext>& rContext, - const css::uno::Reference<css::frame::XModel>& xModel, + const uno::Reference<text::XTextDocument>& xTextDocument, sw::mark::IFieldmark& rFormField); ~SwVbaFormField() override; @@ -38,7 +39,7 @@ public: css::uno::Any SAL_CALL TextInput() override; css::uno::Any SAL_CALL Previous() override; css::uno::Any SAL_CALL Next() override; - css::uno::Any SAL_CALL Range() override; + css::uno::Reference<ooo::vba::word::XRange> SAL_CALL Range() override; // Indicates which of the three form fields this is: oovbaapi/ooo/vba/word/WdFieldType.idl sal_Int32 SAL_CALL getType() override; diff --git a/sw/source/ui/vba/vbaformfields.cxx b/sw/source/ui/vba/vbaformfields.cxx index 83d8af88524f..187f41f3b4f7 100644 --- a/sw/source/ui/vba/vbaformfields.cxx +++ b/sw/source/ui/vba/vbaformfields.cxx @@ -28,6 +28,7 @@ using namespace ::com::sun::star; static sw::mark::IFieldmark* lcl_getFieldmark(std::string_view rName, sal_Int32& rIndex, const uno::Reference<frame::XModel>& xModel, uno::Sequence<OUString>* pElementNames = nullptr) + { SwDoc* pDoc = word::getDocShell(xModel)->GetDoc(); if (!pDoc) @@ -104,17 +105,17 @@ class FormFieldCollectionHelper private: uno::Reference<XHelperInterface> mxParent; uno::Reference<uno::XComponentContext> mxContext; - uno::Reference<frame::XModel> mxModel; + uno::Reference<text::XTextDocument> mxTextDocument; sw::mark::IFieldmark* m_pCache; public: /// @throws css::uno::RuntimeException FormFieldCollectionHelper(uno::Reference<ov::XHelperInterface> xParent, uno::Reference<uno::XComponentContext> xContext, - uno::Reference<frame::XModel> xModel) + uno::Reference<text::XTextDocument> xTextDocument) : mxParent(std::move(xParent)) , mxContext(std::move(xContext)) - , mxModel(std::move(xModel)) + , mxTextDocument(std::move(xTextDocument)) , m_pCache(nullptr) { } @@ -123,18 +124,18 @@ public: sal_Int32 SAL_CALL getCount() override { sal_Int32 nCount = SAL_MAX_INT32; - lcl_getFieldmark("", nCount, mxModel); + lcl_getFieldmark("", nCount, mxTextDocument); return nCount == SAL_MAX_INT32 ? 0 : nCount; } uno::Any SAL_CALL getByIndex(sal_Int32 Index) override { - m_pCache = lcl_getFieldmark("", Index, mxModel); + m_pCache = lcl_getFieldmark("", Index, mxTextDocument); if (!m_pCache) throw lang::IndexOutOfBoundsException(); return uno::Any(uno::Reference<word::XFormField>( - new SwVbaFormField(mxParent, mxContext, mxModel, *m_pCache))); + new SwVbaFormField(mxParent, mxContext, mxTextDocument, *m_pCache))); } // XNameAccess @@ -142,7 +143,7 @@ public: { sal_Int32 nCount = SAL_MAX_INT32; uno::Sequence<OUString> aSeq; - lcl_getFieldmark("", nCount, mxModel, &aSeq); + lcl_getFieldmark("", nCount, mxTextDocument, &aSeq); return aSeq; } @@ -152,13 +153,13 @@ public: throw container::NoSuchElementException(); return uno::Any(uno::Reference<word::XFormField>( - new SwVbaFormField(mxParent, mxContext, mxModel, *m_pCache))); + new SwVbaFormField(mxParent, mxContext, mxTextDocument, *m_pCache))); } sal_Bool SAL_CALL hasByName(const OUString& aName) override { sal_Int32 nCount = -1; - m_pCache = lcl_getFieldmark(aName.toUtf8(), nCount, mxModel); + m_pCache = lcl_getFieldmark(aName.toUtf8(), nCount, mxTextDocument); return m_pCache != nullptr; } @@ -177,10 +178,10 @@ public: SwVbaFormFields::SwVbaFormFields(const uno::Reference<XHelperInterface>& xParent, const uno::Reference<uno::XComponentContext>& xContext, - const uno::Reference<frame::XModel>& xModel) + const uno::Reference<text::XTextDocument>& xTextDocument) : SwVbaFormFields_BASE(xParent, xContext, uno::Reference<container::XIndexAccess>( - new FormFieldCollectionHelper(xParent, xContext, xModel))) + new FormFieldCollectionHelper(xParent, xContext, xTextDocument))) { } @@ -210,7 +211,7 @@ void SwVbaFormFields::setShaded(sal_Bool /*bSet*/) // } // // return uno::Reference<ooo::vba::word::XFormField>( -// new SwVbaFormField(mxParent, mxContext, m_xModel, *pFieldmark)); +// new SwVbaFormField(mxParent, mxContext, m_xTextDocument, *pFieldmark)); // } // XEnumerationAccess diff --git a/sw/source/ui/vba/vbaformfields.hxx b/sw/source/ui/vba/vbaformfields.hxx index 865a1dab5604..2dfa9e76b0c4 100644 --- a/sw/source/ui/vba/vbaformfields.hxx +++ b/sw/source/ui/vba/vbaformfields.hxx @@ -8,6 +8,7 @@ */ #pragma once +#include <com/sun/star/text/XTextDocument.hpp> #include <ooo/vba/word/XFormFields.hpp> #include <vbahelper/vbacollectionimpl.hxx> @@ -20,7 +21,7 @@ public: /// @throws css::uno::RuntimeException SwVbaFormFields(const css::uno::Reference<ov::XHelperInterface>& xParent, const css::uno::Reference<css::uno::XComponentContext>& xContext, - const css::uno::Reference<css::frame::XModel>& xModel); + const css::uno::Reference<css::text::XTextDocument>& xTextDocument); // XFormFields sal_Bool SAL_CALL getShaded() override; |