diff options
-rw-r--r-- | sw/inc/unotxdoc.hxx | 1 | ||||
-rw-r--r-- | sw/source/uibase/uno/unotxdoc.cxx | 7 | ||||
-rw-r--r-- | sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx | 7 | ||||
-rw-r--r-- | sw/source/writerfilter/dmapper/SdtHelper.cxx | 12 |
4 files changed, 17 insertions, 10 deletions
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx index 6a9b9de6fbe6..477f2792912b 100644 --- a/sw/inc/unotxdoc.hxx +++ b/sw/inc/unotxdoc.hxx @@ -513,6 +513,7 @@ public: SW_DLLPUBLIC rtl::Reference<SwXDocumentSettings> createDocumentSettings(); SW_DLLPUBLIC rtl::Reference<SwXTextDefaults> createTextDefaults(); SW_DLLPUBLIC rtl::Reference<SwXBookmark> createBookmark(); + SW_DLLPUBLIC rtl::Reference<SwXBookmark> createFieldmark(); }; class SwXLinkTargetSupplier final : public cppu::WeakImplHelper diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index e72cf2a59ec5..400d9db8b805 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -175,6 +175,7 @@ #include <textcontentcontrol.hxx> #include <unocontentcontrol.hxx> #include <unoport.hxx> +#include <unobookmark.hxx> #include <SwXTextDefaults.hxx> using namespace ::com::sun::star; @@ -1674,6 +1675,12 @@ rtl::Reference< SwXBookmark > SwXTextDocument::createBookmark() return SwXBookmark::CreateXBookmark(GetDocOrThrow(), nullptr); } +rtl::Reference< SwXBookmark > SwXTextDocument::createFieldmark() +{ + SolarMutexGuard aGuard; + ThrowIfInvalid(); + return SwXFieldmark::CreateXFieldmark(GetDocOrThrow(), nullptr); +} Reference< XInterface > SwXTextDocument::createInstance(const OUString& rServiceName) { diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx index 103a836536bc..7f0b57ab483a 100644 --- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx +++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx @@ -7461,8 +7461,6 @@ void DomainMapper_Impl::CloseFieldCommand() try { - uno::Reference< uno::XInterface > xFieldInterface; - const auto& [sType, vArguments, vSwitches]{ splitFieldCommand(pContext->GetCommand()) }; (void)vSwitches; OUString const sFirstParam(vArguments.empty() ? OUString() : vArguments.front()); @@ -7558,6 +7556,7 @@ void DomainMapper_Impl::CloseFieldCommand() bCreateField = false; } + uno::Reference< uno::XInterface > xFieldInterface; if( bCreateField || bCreateEnhancedField ) { //add the service prefix @@ -8347,9 +8346,9 @@ void DomainMapper_Impl::CloseFieldCommand() // Don't waste resources on wrapping shapes inside a fieldmark. if (sType != "SHAPE" && m_xTextDocument && !m_aTextAppendStack.empty()) { - xFieldInterface = m_xTextDocument->createInstance("com.sun.star.text.Fieldmark"); + rtl::Reference<SwXBookmark> xFieldInterface = m_xTextDocument->createFieldmark(); - uno::Reference<text::XFormField> const xFormField(xFieldInterface, uno::UNO_QUERY); + uno::Reference<text::XFormField> const xFormField(static_cast<cppu::OWeakObject*>(xFieldInterface.get()), uno::UNO_QUERY); InsertFieldmark(m_aTextAppendStack, xFormField, pContext->GetStartRange(), pContext->GetFieldId()); xFormField->setFieldType(ODF_UNHANDLED); diff --git a/sw/source/writerfilter/dmapper/SdtHelper.cxx b/sw/source/writerfilter/dmapper/SdtHelper.cxx index 06f3262b767e..db00c79461c0 100644 --- a/sw/source/writerfilter/dmapper/SdtHelper.cxx +++ b/sw/source/writerfilter/dmapper/SdtHelper.cxx @@ -32,6 +32,7 @@ #include <com/sun/star/xml/xpath/XPathException.hpp> #include <com/sun/star/xml/dom/DocumentBuilder.hpp> #include <unotxdoc.hxx> +#include <unobookmark.hxx> namespace writerfilter::dmapper { @@ -473,14 +474,13 @@ void SdtHelper::createDateContentControl() return; } - uno::Reference<uno::XInterface> xFieldInterface - = m_rDM_Impl.GetTextDocument()->createInstance("com.sun.star.text.Fieldmark"); - uno::Reference<text::XFormField> xFormField(xFieldInterface, uno::UNO_QUERY); - uno::Reference<text::XTextContent> xToInsert(xFormField, uno::UNO_QUERY); - if (!(xFormField.is() && xToInsert.is())) + rtl::Reference<SwXBookmark> xFieldmark = m_rDM_Impl.GetTextDocument()->createFieldmark(); + uno::Reference<text::XFormField> xFormField(static_cast<cppu::OWeakObject*>(xFieldmark.get()), + uno::UNO_QUERY); + if (!xFormField) return; - xToInsert->attach(uno::Reference<text::XTextRange>(xCrsr, uno::UNO_QUERY_THROW)); + xFieldmark->attach(uno::Reference<text::XTextRange>(xCrsr, uno::UNO_QUERY_THROW)); xFormField->setFieldType(ODF_FORMDATE); uno::Reference<container::XNameContainer> xNameCont = xFormField->getParameters(); if (xNameCont.is()) |