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>
This commit is contained in:
Justin Luth 2022-12-13 18:52:09 -05:00 committed by Miklos Vajna
parent 54599383a2
commit 88d4e74169
7 changed files with 42 additions and 27 deletions

View file

@ -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();
};
}; }; };

Binary file not shown.

View file

@ -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);

View file

@ -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"; }

View file

@ -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;

View file

@ -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

View file

@ -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;