sw/inc/unotbl.hxx | 7 + sw/inc/unotext.hxx | 24 +++++ sw/source/core/unocore/unotbl.cxx | 30 +++++-- sw/source/core/unocore/unotext.cxx | 15 +++ sw/source/writerfilter/dmapper/DomainMapperTableHandler.cxx | 51 +++++------- sw/source/writerfilter/dmapper/DomainMapperTableHandler.hxx | 4 6 files changed, 92 insertions(+), 39 deletions(-)
New commits: commit 883febd60593e8a3c0c85c9859006cc0a35b10c2 Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Sun Aug 11 18:15:30 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Aug 12 14:22:14 2024 +0200 use more concrete UNO type in writerfilter Change-Id: I238cc9f5079dd7b3ca171b6a4b9da12534b53d23 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171734 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/inc/unotbl.hxx b/sw/inc/unotbl.hxx index f544b0ab80c8..de6a1e3d833a 100644 --- a/sw/inc/unotbl.hxx +++ b/sw/inc/unotbl.hxx @@ -47,6 +47,8 @@ class SwTableBox; class SwTableLine; class SwTableCursor; class SwUnoInternalPaM; +struct SwXParagraphEnumeration; +class SwXTableRows; class SfxItemPropertySet; typedef @@ -136,6 +138,7 @@ public: virtual css::uno::Type SAL_CALL getElementType( ) override; virtual sal_Bool SAL_CALL hasElements( ) override; + rtl::Reference< SwXParagraphEnumeration > createSwEnumeration(); SwTableBox* GetTableBox() const { return m_pBox; } static rtl::Reference<SwXCell> CreateXCell(SwFrameFormat* pTableFormat, SwTableBox* pBox, SwTable *pTable = nullptr ); SwTableBox* FindBox(SwTable* pTable, SwTableBox* pBox); @@ -343,6 +346,8 @@ public: virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + rtl::Reference< SwXTableRows > getSwRows(); + rtl::Reference< SwXCell > getSwCellByPosition( sal_Int32 nColumn, sal_Int32 nRow ); rtl::Reference< SwXCell > getSwCellByName( const OUString& aCellName ); }; @@ -434,7 +439,7 @@ public: SwXTableRows(SwFrameFormat& rFrameFormat); //XIndexAccess - virtual sal_Int32 SAL_CALL getCount() override; + SW_DLLPUBLIC virtual sal_Int32 SAL_CALL getCount() override; virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override; //XElementAccess diff --git a/sw/inc/unotext.hxx b/sw/inc/unotext.hxx index 96173ea32ba7..cff75d2738e5 100644 --- a/sw/inc/unotext.hxx +++ b/sw/inc/unotext.hxx @@ -46,6 +46,7 @@ class SwPaM; class SwXTextCursor; class SwXParagraph; class SwXTextRange; +class SwXTextTable; class SAL_DLLPUBLIC_RTTI SAL_LOPLUGIN_ANNOTATE("crosscast") SwXText : public css::lang::XTypeProvider @@ -135,7 +136,7 @@ public: SAL_CALL getText() override; SW_DLLPUBLIC virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override; virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override; - virtual OUString SAL_CALL getString() override; + SW_DLLPUBLIC virtual OUString SAL_CALL getString() override; SW_DLLPUBLIC virtual void SAL_CALL setString(const OUString& rString) override; // XSimpleText @@ -248,6 +249,27 @@ public: virtual void SAL_CALL removeTextContentAfter( const css::uno::Reference< css::text::XTextContent>& xPredecessor) override; + SW_DLLPUBLIC rtl::Reference< SwXTextTable > + convertToSwTable( + css::uno::Sequence< + css::uno::Sequence< + css::uno::Sequence< + css::uno::Reference< + css::text::XTextRange > > > > const& + rTableRanges, + css::uno::Sequence< + css::uno::Sequence< + css::uno::Sequence< + css::beans::PropertyValue > > > const& + rCellProperties, + css::uno::Sequence< + css::uno::Sequence< + css::beans::PropertyValue > > const& + rRowProperties, + css::uno::Sequence< + css::beans::PropertyValue > const& + rTableProperties); + private: rtl::Reference< SwXTextCursor > getEndImpl(SolarMutexGuard& rGuard); rtl::Reference< SwXTextRange > insertTextPortionImpl( diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx index 4878788eb606..04fa8c3a3ee8 100644 --- a/sw/source/core/unocore/unotbl.cxx +++ b/sw/source/core/unocore/unotbl.cxx @@ -1089,10 +1089,15 @@ void SwXCell::removeVetoableChangeListener(const OUString& /*rPropertyName*/, co { throw uno::RuntimeException(u"not implemented"_ustr, getXWeak()); }; uno::Reference<container::XEnumeration> SwXCell::createEnumeration() +{ + return createSwEnumeration(); +} + +rtl::Reference<SwXParagraphEnumeration> SwXCell::createSwEnumeration() { SolarMutexGuard aGuard; if(!IsValid()) - return uno::Reference<container::XEnumeration>(); + return {}; const SwStartNode* pSttNd = m_pBox->GetSttNd(); SwPosition aPos(*pSttNd); auto pUnoCursor(GetDoc()->CreateUnoCursor(aPos)); @@ -1898,7 +1903,7 @@ public: const SfxItemPropertySet * m_pPropSet; - css::uno::WeakReference<css::table::XTableRows> m_xRows; + unotools::WeakReference<SwXTableRows> m_xRows; css::uno::WeakReference<css::table::XTableColumns> m_xColumns; bool m_bFirstRowAsLabel; @@ -2000,13 +2005,21 @@ void SwXTextTable::initialize(sal_Int32 nR, sal_Int32 nC) } uno::Reference<table::XTableRows> SAL_CALL SwXTextTable::getRows() +{ + return getSwRows(); +} + +rtl::Reference<SwXTableRows> SwXTextTable::getSwRows() { SolarMutexGuard aGuard; - uno::Reference<table::XTableRows> xResult(m_pImpl->m_xRows); - if(xResult.is()) + rtl::Reference<SwXTableRows> xResult(m_pImpl->m_xRows); + if(xResult) return xResult; if(SwFrameFormat* pFormat = GetFrameFormat()) - m_pImpl->m_xRows = xResult = new SwXTableRows(*pFormat); + { + xResult = new SwXTableRows(*pFormat); + m_pImpl->m_xRows = xResult.get(); + } if(!xResult.is()) throw uno::RuntimeException(); return xResult; @@ -2170,7 +2183,12 @@ void SAL_CALL SwXTextTable::removeEventListener( m_pImpl->m_EventListeners.removeInterface(aGuard, xListener); } -uno::Reference<table::XCell> SwXTextTable::getCellByPosition(sal_Int32 nColumn, sal_Int32 nRow) +uno::Reference<table::XCell> SwXTextTable::getCellByPosition(sal_Int32 nColumn, sal_Int32 nRow) +{ + return uno::Reference<table::XCell>(getSwCellByPosition(nColumn, nRow)); +} + +rtl::Reference<SwXCell> SwXTextTable::getSwCellByPosition(sal_Int32 nColumn, sal_Int32 nRow) { SolarMutexGuard aGuard; SwFrameFormat* pFormat(GetFrameFormat()); diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx index cee7303853e1..2b4b7ad7f35a 100644 --- a/sw/source/core/unocore/unotext.cxx +++ b/sw/source/core/unocore/unotext.cxx @@ -2174,6 +2174,19 @@ SwXText::convertToTable( const uno::Sequence< uno::Sequence< beans::PropertyValue > >& rRowProperties, const uno::Sequence< beans::PropertyValue >& rTableProperties) +{ + return uno::Reference< text::XTextTable >(convertToSwTable(rTableRanges, rCellProperties, rRowProperties, rTableProperties)); +} + +rtl::Reference< SwXTextTable > +SwXText::convertToSwTable( + const uno::Sequence< uno::Sequence< uno::Sequence< + uno::Reference< text::XTextRange > > > >& rTableRanges, + const uno::Sequence< uno::Sequence< uno::Sequence< + beans::PropertyValue > > >& rCellProperties, + const uno::Sequence< uno::Sequence< beans::PropertyValue > >& + rRowProperties, + const uno::Sequence< beans::PropertyValue >& rTableProperties) { SolarMutexGuard aGuard; @@ -2226,7 +2239,7 @@ SwXText::convertToTable( SwTable const*const pTable = m_pDoc->TextToTable( aTableNodes ); if (!pTable) - return uno::Reference< text::XTextTable >(); + return {}; rtl::Reference<SwXTextTable> const xRet = SwXTextTable::CreateXTextTable(pTable->GetFrameFormat()); diff --git a/sw/source/writerfilter/dmapper/DomainMapperTableHandler.cxx b/sw/source/writerfilter/dmapper/DomainMapperTableHandler.cxx index 7bfe83fd0a37..a4a402af207e 100644 --- a/sw/source/writerfilter/dmapper/DomainMapperTableHandler.cxx +++ b/sw/source/writerfilter/dmapper/DomainMapperTableHandler.cxx @@ -56,6 +56,8 @@ #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> #include <com/sun/star/style/BreakType.hpp> #include <officecfg/Office/Writer.hxx> +#include <unotbl.hxx> +#include <unoparagraph.hxx> #ifdef DBG_UTIL #include "PropertyMapHelper.hxx" @@ -86,7 +88,7 @@ using namespace ::com::sun::star; #define MAXTABLECELLS 63 DomainMapperTableHandler::DomainMapperTableHandler( - css::uno::Reference<css::text::XTextAppendAndConvert> xText, + rtl::Reference<SwXText> xText, DomainMapper_Impl& rDMapper_Impl) : m_xText(std::move(xText)), m_rDMapper_Impl( rDMapper_Impl ) @@ -1265,10 +1267,9 @@ void DomainMapperTableHandler::ApplyParagraphPropertiesFromTableStyle(TableParag } // convert formula range identifier ABOVE, BELOW, LEFT and RIGHT -static void lcl_convertFormulaRanges(const uno::Reference<text::XTextTable> & xTable) +static void lcl_convertFormulaRanges(const rtl::Reference<SwXTextTable> & xTable) { - uno::Reference<table::XCellRange> xCellRange(xTable, uno::UNO_QUERY_THROW); - uno::Reference<container::XIndexAccess> xTableRows(xTable->getRows(), uno::UNO_QUERY_THROW); + rtl::Reference<SwXTableRows> xTableRows(xTable->getSwRows()); sal_Int32 nRows = xTableRows->getCount(); for (sal_Int32 nRow = 0; nRow < nRows; ++nRow) { @@ -1276,7 +1277,7 @@ static void lcl_convertFormulaRanges(const uno::Reference<text::XTextTable> & xT { try { - uno::Reference<beans::XPropertySet> xCellProperties(xCellRange->getCellByPosition(nCol, nRow), uno::UNO_QUERY_THROW); + rtl::Reference<SwXCell> xCellProperties = xTable->getSwCellByPosition(nCol, nRow); uno::Sequence<beans::PropertyValue> aCellGrabBag; xCellProperties->getPropertyValue(u"CellInteropGrabBag"_ustr) >>= aCellGrabBag; OUString sFormula; @@ -1315,17 +1316,15 @@ static void lcl_convertFormulaRanges(const uno::Reference<text::XTextTable> & xT sal_Int32 nCell = 0; while (++nCell) { - uno::Reference<beans::XPropertySet> xCell( - xCellRange->getCellByPosition(nCol + nCell * rRange.m_nCol, nRow + nCell * rRange.m_nRow), - uno::UNO_QUERY_THROW); + rtl::Reference<SwXCell> xCell( + xTable->getSwCellByPosition(nCol + nCell * rRange.m_nCol, nRow + nCell * rRange.m_nRow)); // empty cell or cell with text content is end of the range - uno::Reference<text::XText> xText(xCell, uno::UNO_QUERY_THROW); sLastCell = xCell->getPropertyValue(u"CellName"_ustr).get<OUString>(); if (sNextCell.isEmpty()) sNextCell = sLastCell; // accept numbers with comma and percent - OUString sCellText = xText->getString().replace(',', '.'); + OUString sCellText = xCell->getString().replace(',', '.'); if (sCellText.endsWith("%")) sCellText = sCellText.copy(0, sCellText.getLength()-1); @@ -1366,9 +1365,8 @@ static void lcl_convertFormulaRanges(const uno::Reference<text::XTextTable> & xT // update formula field if (bReplace) { - uno::Reference<text::XText> xCell(xCellRange->getCellByPosition(nCol, nRow), uno::UNO_QUERY); - uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xCell, uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration(); + rtl::Reference<SwXCell> xCell(xTable->getSwCellByPosition(nCol, nRow)); + rtl::Reference<SwXParagraphEnumeration> xParaEnum = xCell->createSwEnumeration(); uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY); uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration(); while ( xRunEnum->hasMoreElements() ) @@ -1516,12 +1514,12 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel) xEnd = rLastCell[1]; } } - uno::Reference<text::XTextTable> xTable; + rtl::Reference<SwXTextTable> xTable; try { if (m_xText.is()) { - xTable = m_xText->convertToTable(comphelper::containerToSequence(m_aTableRanges), aCellProperties, aRowProperties, aTableInfo.aTableProperties); + xTable = m_xText->convertToSwTable(comphelper::containerToSequence(m_aTableRanges), aCellProperties, aRowProperties, aTableInfo.aTableProperties); if (xTable.is()) { @@ -1533,10 +1531,8 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel) // Perform horizontal merges in reverse order, so the fact that merging changes the position of cells won't cause a problem for us. for (std::vector<HorizontallyMergedCell>::reverse_iterator it = aMerges.rbegin(); it != aMerges.rend(); ++it) { - uno::Reference<table::XCellRange> xCellRange(xTable, uno::UNO_QUERY_THROW); - uno::Reference<beans::XPropertySet> xFirstCell( - xCellRange->getCellByPosition(it->m_nFirstCol, it->m_nFirstRow), - uno::UNO_QUERY_THROW); + rtl::Reference<SwXCell> xFirstCell = + xTable->getSwCellByPosition(it->m_nFirstCol, it->m_nFirstRow); OUString aFirst = xFirstCell->getPropertyValue(u"CellName"_ustr).get<OUString>(); // tdf#105852: Only try to merge if m_nLastCol is set (i.e. there were some merge continuation cells) @@ -1550,7 +1546,7 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel) >>= aBorderValues[i]; uno::Reference<beans::XPropertySet> xLastCell( - xCellRange->getCellByPosition(it->m_nLastCol, it->m_nLastRow), + xTable->getCellByPosition(it->m_nLastCol, it->m_nLastRow), uno::UNO_QUERY_THROW); OUString aLast = xLastCell->getPropertyValue(u"CellName"_ustr).get<OUString>(); @@ -1593,37 +1589,36 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel) // If we have a table with a start and an end position, we should make it a floating one. if (xTable.is() && xStart.is() && xEnd.is()) { - uno::Reference<beans::XPropertySet> xTableProperties(xTable, uno::UNO_QUERY); bool bIsRelative = false; - xTableProperties->getPropertyValue(u"IsWidthRelative"_ustr) >>= bIsRelative; + xTable->getPropertyValue(u"IsWidthRelative"_ustr) >>= bIsRelative; if (!bIsRelative) { beans::PropertyValue aValue; aValue.Name = "Width"; - aValue.Value = xTableProperties->getPropertyValue(u"Width"_ustr); + aValue.Value = xTable->getPropertyValue(u"Width"_ustr); aFrameProperties.push_back(aValue); } else { beans::PropertyValue aValue; aValue.Name = "FrameWidthPercent"; - aValue.Value = xTableProperties->getPropertyValue(u"RelativeWidth"_ustr); + aValue.Value = xTable->getPropertyValue(u"RelativeWidth"_ustr); aFrameProperties.push_back(aValue); // Applying the relative width to the frame, needs to have the table width to be 100% of the frame width - xTableProperties->setPropertyValue(u"RelativeWidth"_ustr, uno::Any(sal_Int16(100))); + xTable->setPropertyValue(u"RelativeWidth"_ustr, uno::Any(sal_Int16(100))); } // A non-zero left margin would move the table out of the frame, move the frame itself instead. - xTableProperties->setPropertyValue(u"LeftMargin"_ustr, uno::Any(sal_Int32(0))); + xTable->setPropertyValue(u"LeftMargin"_ustr, uno::Any(sal_Int32(0))); style::BreakType eBreakType{}; - xTableProperties->getPropertyValue(u"BreakType"_ustr) >>= eBreakType; + xTable->getPropertyValue(u"BreakType"_ustr) >>= eBreakType; if (eBreakType != style::BreakType_NONE) { // A break before the table was requested. Reset that break here, since the table // will be at the start of the fly frame, not in the body frame. - xTableProperties->setPropertyValue(u"BreakType"_ustr, uno::Any(style::BreakType_NONE)); + xTable->setPropertyValue(u"BreakType"_ustr, uno::Any(style::BreakType_NONE)); } if (nestedTableLevel >= 2 || m_rDMapper_Impl.IsInHeaderFooter()) diff --git a/sw/source/writerfilter/dmapper/DomainMapperTableHandler.hxx b/sw/source/writerfilter/dmapper/DomainMapperTableHandler.hxx index 376a6d366688..39c89b7b569a 100644 --- a/sw/source/writerfilter/dmapper/DomainMapperTableHandler.hxx +++ b/sw/source/writerfilter/dmapper/DomainMapperTableHandler.hxx @@ -56,7 +56,7 @@ struct HorizontallyMergedCell /// Class to handle events generated by TableManager::resolveCurrentTable(). class DomainMapperTableHandler final : public virtual SvRefBase { - css::uno::Reference<css::text::XTextAppendAndConvert> m_xText; + rtl::Reference<SwXText> m_xText; DomainMapper_Impl& m_rDMapper_Impl; std::vector< css::uno::Reference<css::text::XTextRange> > m_aCellRange; std::vector<CellSequence_t> m_aRowRanges; @@ -76,7 +76,7 @@ class DomainMapperTableHandler final : public virtual SvRefBase public: typedef tools::SvRef<DomainMapperTableHandler> Pointer_t; - DomainMapperTableHandler(css::uno::Reference<css::text::XTextAppendAndConvert> xText, + DomainMapperTableHandler(rtl::Reference<SwXText> xText, DomainMapper_Impl& rDMapper_Impl); ~DomainMapperTableHandler() override;