summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2022-11-11 13:51:59 +0000
committerMiklos Vajna <vmiklos@collabora.com>2022-12-20 08:07:01 +0000
commit61d0f5b8425b74c86c696a7934a6b6eb090ffec1 (patch)
tree183063bd9c6bd5aecfafce788e55204296ba373a
parente5622668c244358c7a5db3b4434ae2391e5a6749 (diff)
tdf#151548 vba FormFields: implement Range
This squashed commit includes cid#1516788 Uninitialized pointer field Change-Id: I9565a995aa400fd391de70606b59c16e68a042c3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142584 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> 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> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144551 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
-rw-r--r--oovbaapi/ooo/vba/word/XFormField.idl3
-rw-r--r--sw/qa/core/data/docm/testVBA.docmbin32952 -> 32380 bytes
-rw-r--r--sw/source/ui/vba/vbadocument.cxx2
-rw-r--r--sw/source/ui/vba/vbaformfield.cxx29
-rw-r--r--sw/source/ui/vba/vbaformfield.hxx7
-rw-r--r--sw/source/ui/vba/vbaformfields.cxx26
-rw-r--r--sw/source/ui/vba/vbaformfields.hxx3
7 files changed, 43 insertions, 27 deletions
diff --git a/oovbaapi/ooo/vba/word/XFormField.idl b/oovbaapi/ooo/vba/word/XFormField.idl
index 2b879fb6c652..54d432e64cdc 100644
--- a/oovbaapi/ooo/vba/word/XFormField.idl
+++ b/oovbaapi/ooo/vba/word/XFormField.idl
@@ -24,6 +24,7 @@
module ooo { module vba { module word {
+interface XRange;
interface XFormField
{
interface ooo::vba::XHelperInterface;
@@ -80,7 +81,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
index 839c8dd9f73c..44e59f03a753 100644
--- a/sw/qa/core/data/docm/testVBA.docm
+++ b/sw/qa/core/data/docm/testVBA.docm
Binary files differ
diff --git a/sw/source/ui/vba/vbadocument.cxx b/sw/source/ui/vba/vbadocument.cxx
index e72fee6d478c..502636b33530 100644
--- a/sw/source/ui/vba/vbadocument.cxx
+++ b/sw/source/ui/vba/vbadocument.cxx
@@ -303,7 +303,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 008c7e87d547..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,18 @@ 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)
{
}
@@ -122,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
@@ -141,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;
}
@@ -151,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;
}
@@ -176,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)))
{
}
@@ -209,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;