diff options
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/unofieldcoll.hxx | 5 | ||||
-rw-r--r-- | sw/source/core/unocore/unofield.cxx | 42 |
2 files changed, 47 insertions, 0 deletions
diff --git a/sw/inc/unofieldcoll.hxx b/sw/inc/unofieldcoll.hxx index efe3f814ef4a..a7bfda4bcbfe 100644 --- a/sw/inc/unofieldcoll.hxx +++ b/sw/inc/unofieldcoll.hxx @@ -23,6 +23,7 @@ #include <memory> #include <com/sun/star/util/XRefreshable.hpp> +#include <com/sun/star/container/XUniqueIDAccess.hpp> #include "unocoll.hxx" @@ -68,6 +69,7 @@ typedef ::cppu::WeakImplHelper < css::container::XEnumerationAccess , css::lang::XServiceInfo , css::util::XRefreshable +, css::container::XUniqueIDAccess > SwXTextFieldTypes_Base; class SwXTextFieldTypes final @@ -111,6 +113,9 @@ public: const css::uno::Reference< css::util::XRefreshListener>& xListener) override; + // container::XUniqueIDAccess + virtual css::uno::Any SAL_CALL getByUniqueID( const OUString& ID ) override; + virtual void SAL_CALL removeByUniqueID( const OUString& ID ) override; }; #endif diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx index 152c1aa3bc44..f0fb208aa8cf 100644 --- a/sw/source/core/unocore/unofield.cxx +++ b/sw/source/core/unocore/unofield.cxx @@ -2939,6 +2939,48 @@ void SAL_CALL SwXTextFieldTypes::removeRefreshListener( m_pImpl->m_RefreshListeners.removeInterface(aGuard, xListener); } +// This is specifically for looking up annotations, so we only need to search a couple of places +css::uno::Any SAL_CALL SwXTextFieldTypes::getByUniqueID(const OUString& ID) +{ + SolarMutexGuard aGuard; + uno::Any aRet; + auto& rDoc = GetDoc(); + + const SwFieldTypes* pFieldTypes = rDoc.getIDocumentFieldsAccess().GetFieldTypes(); + auto fieldTypeIt = std::find_if(pFieldTypes->begin(), pFieldTypes->end(), + [](const std::unique_ptr<SwFieldType>& pType) { + return pType->Which() == SwFieldIds::Postit; + }); + const SwFieldType & rCurType = **fieldTypeIt; + std::vector<SwFormatField*> vFormatFields; + rCurType.GatherFields(vFormatFields); + for (const SwFormatField* pFormatField : vFormatFields) + { + const SwPostItField* pField = static_cast<const SwPostItField*>(pFormatField->GetField()); + if (pField->GetName() == ID) + { + aRet <<= uno::Reference<beans::XPropertySet>(SwXTextField::CreateXTextField(&rDoc, pFormatField)); + return aRet; + } + } + + IDocumentMarkAccess& rMarksAccess(*rDoc.getIDocumentMarkAccess()); + auto it = rMarksAccess.findMark(ID); + if (it != rMarksAccess.getAllMarksEnd()) + { + aRet <<= uno::Reference<beans::XPropertySet>(SwXFieldmark::CreateXFieldmark(rDoc, *it)); + if (aRet.hasValue()) + return aRet; + } + + return aRet; +} + +void SAL_CALL SwXTextFieldTypes::removeByUniqueID(const OUString& /*ID*/) +{ + throw uno::RuntimeException("unsupported"); +} + class SwXFieldEnumeration::Impl : public SvtListener { |