sc/inc/cellsuno.hxx | 15 +++++++++++---- sc/inc/docuno.hxx | 2 +- sc/source/filter/inc/workbookhelper.hxx | 4 +++- sc/source/filter/oox/defnamesbuffer.cxx | 5 +++-- sc/source/filter/oox/pivottablebuffer.cxx | 2 +- sc/source/filter/oox/scenariobuffer.cxx | 3 ++- sc/source/filter/oox/workbookhelper.cxx | 14 +++----------- sc/source/filter/oox/worksheethelper.cxx | 13 +++++-------- sc/source/ui/unoobj/cellsuno.cxx | 22 ++++++++++++++++++++-- 9 files changed, 49 insertions(+), 31 deletions(-)
New commits: commit 56da031f73f544d712b369f732f1ded1d3926fc2 Author: Noel Grandin <[email protected]> AuthorDate: Wed May 21 15:57:16 2025 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Fri May 23 15:01:28 2025 +0200 tdf#166684 strip out some unnecessary UNO work (2) to make this easier to optimise, strip out some unnecessary UNO stuff between the import filter and the underlying spreadsheet model Change-Id: I0c1e12c09842390c90a7e804dffa5fdd034f60b4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185648 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/sc/inc/cellsuno.hxx b/sc/inc/cellsuno.hxx index 959757168d28..0723ea5ca05e 100644 --- a/sc/inc/cellsuno.hxx +++ b/sc/inc/cellsuno.hxx @@ -114,6 +114,7 @@ class SfxItemPropertySet; struct SfxItemPropertyMapEntry; class ScTableRowsObj; class ScTableValidationObj; +class ScCellObj; class SolarMutexGuard; namespace editeng { class SvxBorderLine; } @@ -490,7 +491,7 @@ protected: /// @throws css::lang::IndexOutOfBoundsException /// @throws css::uno::RuntimeException - css::uno::Reference< css::table::XCell > + rtl::Reference< ScCellObj > GetCellByPosition_Impl( sal_Int32 nColumn, sal_Int32 nRow ); /// @throws css::uno::RuntimeException @@ -621,10 +622,16 @@ public: rtl::Reference< ScCellRangeObj > getScCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ); + SC_DLLPUBLIC rtl::Reference< ScCellRangeObj > + getScCellRangeByName( const OUString& aRange ); + rtl::Reference< ScCellRangeObj > + getScCellRangeByName( const OUString& aRange, const ScAddress::Details& rDetails ); rtl::Reference< ScTableRowsObj > getScRowsByPosition( SolarMutexGuard& rGuard, sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ); rtl::Reference< ScTableRowsObj > getScRows(); + SC_DLLPUBLIC rtl::Reference< ScCellObj > + getScCellByPosition( sal_Int32 nColumn, sal_Int32 nRow ); }; //! really derive cell from range? @@ -727,7 +734,7 @@ public: virtual void SAL_CALL setTokens( const css::uno::Sequence< css::sheet::FormulaToken >& aTokens ) override; // XCellAddressable - virtual css::table::CellAddress SAL_CALL getCellAddress() override; + SC_DLLPUBLIC virtual css::table::CellAddress SAL_CALL getCellAddress() override; // XSheetAnnotationAnchor virtual css::uno::Reference< css::sheet::XSheetAnnotation > SAL_CALL @@ -776,7 +783,7 @@ using ScTableSheetObj_BASE = cppu::ImplInheritanceHelper<ScCellRangeObj, css::sheet::XScenarioEnhanced, css::sheet::XExternalSheetName, css::document::XEventsSupplier>; -class SAL_DLLPUBLIC_RTTI ScTableSheetObj final : public ScTableSheetObj_BASE +class SC_DLLPUBLIC ScTableSheetObj final : public ScTableSheetObj_BASE { friend class ScTableSheetsObj; // for insertByName() @@ -857,7 +864,7 @@ public: getScenarios() override; // XSheetAnnotationsSupplier - SC_DLLPUBLIC virtual css::uno::Reference< css::sheet::XSheetAnnotations > SAL_CALL + virtual css::uno::Reference< css::sheet::XSheetAnnotations > SAL_CALL getAnnotations() override; // XDrawPageSupplier diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx index ecdca483588e..94b6044b2951 100644 --- a/sc/inc/docuno.hxx +++ b/sc/inc/docuno.hxx @@ -438,7 +438,7 @@ public: virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; }; -class ScTableSheetsObj final : public cppu::WeakImplHelper< +class SC_DLLPUBLIC ScTableSheetsObj final : public cppu::WeakImplHelper< css::sheet::XSpreadsheets2, css::sheet::XCellRangesAccess, css::container::XEnumerationAccess, diff --git a/sc/source/filter/inc/workbookhelper.hxx b/sc/source/filter/inc/workbookhelper.hxx index b6aa24f8d4a1..d445b7c9f05d 100644 --- a/sc/source/filter/inc/workbookhelper.hxx +++ b/sc/source/filter/inc/workbookhelper.hxx @@ -58,6 +58,8 @@ class ScDBData; class ScRangeData; class ScModelObj; class ScDatabaseRangeObj; +class ScTableSheetObj; + namespace oox::xls { enum class FontClassification : sal_uInt8 @@ -191,7 +193,7 @@ public: const rtl::Reference< ScModelObj >& getDocument() const; /** Returns a reference to the specified spreadsheet in the document model. */ - css::uno::Reference< css::sheet::XSpreadsheet > + rtl::Reference< ScTableSheetObj > getSheetFromDoc( sal_Int32 nSheet ) const; /** Returns a reference to the specified spreadsheet in the document model. */ css::uno::Reference< css::sheet::XSpreadsheet > diff --git a/sc/source/filter/oox/defnamesbuffer.cxx b/sc/source/filter/oox/defnamesbuffer.cxx index 78a186f46ffd..c68b8fd47346 100644 --- a/sc/source/filter/oox/defnamesbuffer.cxx +++ b/sc/source/filter/oox/defnamesbuffer.cxx @@ -37,6 +37,7 @@ #include <worksheetbuffer.hxx> #include <tokenarray.hxx> #include <tokenuno.hxx> +#include <cellsuno.hxx> #include <compiler.hxx> #include <document.hxx> @@ -317,7 +318,7 @@ void DefinedName::convertFormula( const css::uno::Sequence<css::sheet::ExternalL { case BIFF_DEFNAME_PRINTAREA: { - Reference< XPrintAreas > xPrintAreas( getSheetFromDoc( mnCalcSheet ), UNO_QUERY ); + rtl::Reference< ScTableSheetObj > xPrintAreas( getSheetFromDoc( mnCalcSheet ) ); ScRangeList aPrintRanges; getFormulaParser().extractCellRangeList( aPrintRanges, aFTokenSeq, mnCalcSheet ); if( xPrintAreas.is() && !aPrintRanges.empty() ) @@ -326,7 +327,7 @@ void DefinedName::convertFormula( const css::uno::Sequence<css::sheet::ExternalL break; case BIFF_DEFNAME_PRINTTITLES: { - Reference< XPrintAreas > xPrintAreas( getSheetFromDoc( mnCalcSheet ), UNO_QUERY ); + rtl::Reference< ScTableSheetObj > xPrintAreas( getSheetFromDoc( mnCalcSheet ) ); ScRangeList aTitleRanges; getFormulaParser().extractCellRangeList( aTitleRanges, aFTokenSeq, mnCalcSheet ); if( xPrintAreas.is() && !aTitleRanges.empty() ) diff --git a/sc/source/filter/oox/pivottablebuffer.cxx b/sc/source/filter/oox/pivottablebuffer.cxx index 995cca5d57eb..fed71de1f7cf 100644 --- a/sc/source/filter/oox/pivottablebuffer.cxx +++ b/sc/source/filter/oox/pivottablebuffer.cxx @@ -1271,7 +1271,7 @@ void PivotTable::finalizeImport() try { // create a new data pilot descriptor based on the source data - Reference< XDataPilotTablesSupplier > xDPTablesSupp( getSheetFromDoc( maLocationModel.maRange.aStart.Tab() ), UNO_QUERY_THROW ); + rtl::Reference< ScTableSheetObj > xDPTablesSupp( getSheetFromDoc( maLocationModel.maRange.aStart.Tab() ) ); Reference< XDataPilotTables > xDPTables( xDPTablesSupp->getDataPilotTables(), UNO_SET_THROW ); mxDPDescriptor = static_cast<ScDataPilotDescriptorBase*>( xDPTables->createDataPilotDescriptor().get() ); ScRange aRange = mpPivotCache->getSourceRange(); diff --git a/sc/source/filter/oox/scenariobuffer.cxx b/sc/source/filter/oox/scenariobuffer.cxx index 1fbf64cc1ff4..cb7ee37b0eae 100644 --- a/sc/source/filter/oox/scenariobuffer.cxx +++ b/sc/source/filter/oox/scenariobuffer.cxx @@ -33,6 +33,7 @@ #include <addressconverter.hxx> #include <biffhelper.hxx> #include <docuno.hxx> +#include <cellsuno.hxx> namespace oox::xls { @@ -122,7 +123,7 @@ void Scenario::finalizeImport() OUString aScenName = ContainerHelper::getUnusedName( xSheetsNA, maModel.maName, '_' ); // create the new scenario sheet - Reference< XScenariosSupplier > xScenariosSupp( getSheetFromDoc( mnSheet ), UNO_QUERY_THROW ); + rtl::Reference< ScTableSheetObj > xScenariosSupp( getSheetFromDoc( mnSheet ) ); Reference< XScenarios > xScenarios( xScenariosSupp->getScenarios(), UNO_SET_THROW ); xScenarios->addNewByName( aScenName, AddressConverter::toApiSequence(aRanges), maModel.maComment ); diff --git a/sc/source/filter/oox/workbookhelper.cxx b/sc/source/filter/oox/workbookhelper.cxx index b124763b4a4d..5f7210c86a68 100644 --- a/sc/source/filter/oox/workbookhelper.cxx +++ b/sc/source/filter/oox/workbookhelper.cxx @@ -861,18 +861,10 @@ const rtl::Reference< ScModelObj > & WorkbookHelper::getDocument() const return mrBookGlob.getDocument(); } -Reference< XSpreadsheet > WorkbookHelper::getSheetFromDoc( sal_Int32 nSheet ) const +rtl::Reference< ScTableSheetObj > WorkbookHelper::getSheetFromDoc( sal_Int32 nSheet ) const { - Reference< XSpreadsheet > xSheet; - try - { - Reference< XIndexAccess > xSheetsIA( getDocument()->getSheets(), UNO_QUERY_THROW ); - xSheet.set( xSheetsIA->getByIndex( nSheet ), UNO_QUERY_THROW ); - } - catch( Exception& ) - { - } - return xSheet; + rtl::Reference< ScTableSheetsObj > xSheetsIA( getDocument()->getScSheets() ); + return xSheetsIA->GetSheetByIndex( nSheet ); } Reference< XSpreadsheet > WorkbookHelper::getSheetFromDoc( const OUString& rSheet ) const diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx index ae1db7f75463..2dbf8e9b4653 100644 --- a/sc/source/filter/oox/worksheethelper.cxx +++ b/sc/source/filter/oox/worksheethelper.cxx @@ -1098,14 +1098,11 @@ void WorksheetGlobals::finalizeValidationRanges() const { const OUString aToken = validation.msRef.getToken( 0, ' ' ); - Reference<XSpreadsheet> xSheet = getSheetFromDoc( getCurrentSheetIndex() ); - Reference<XCellRange> xDBCellRange; - Reference<XCell> xCell; - xDBCellRange = xSheet->getCellRangeByName( aToken ); - - xCell = xDBCellRange->getCellByPosition( 0, 0 ); - Reference<XCellAddressable> xCellAddressable( xCell, UNO_QUERY_THROW ); - CellAddress aFirstCell = xCellAddressable->getCellAddress(); + rtl::Reference<ScTableSheetObj> xSheet = getSheetFromDoc( getCurrentSheetIndex() ); + rtl::Reference<ScCellRangeObj> xDBCellRange = xSheet->getScCellRangeByName( aToken ); + + rtl::Reference<ScCellObj> xCell = xDBCellRange->getScCellByPosition( 0, 0 ); + CellAddress aFirstCell = xCell->getCellAddress(); xValidation->setSourcePosition( aFirstCell ); } catch(const Exception&) diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx index 0c57107fea2c..994d5c08d752 100644 --- a/sc/source/ui/unoobj/cellsuno.cxx +++ b/sc/source/ui/unoobj/cellsuno.cxx @@ -4524,7 +4524,7 @@ void ScCellRangeObj::RefChanged() // ColumnCount / RowCount vanished //! are used in Writer for tables ??? -uno::Reference<table::XCell> ScCellRangeObj::GetCellByPosition_Impl( +rtl::Reference<ScCellObj> ScCellRangeObj::GetCellByPosition_Impl( sal_Int32 nColumn, sal_Int32 nRow ) { ScDocShell* pDocSh = GetDocShell(); @@ -4548,6 +4548,12 @@ uno::Reference<table::XCell> ScCellRangeObj::GetCellByPosition_Impl( uno::Reference<table::XCell> SAL_CALL ScCellRangeObj::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow ) +{ + return getScCellByPosition(nColumn, nRow); +} + +rtl::Reference<ScCellObj> ScCellRangeObj::getScCellByPosition( + sal_Int32 nColumn, sal_Int32 nRow ) { SolarMutexGuard aGuard; @@ -4618,11 +4624,23 @@ rtl::Reference<ScTableRowsObj> ScCellRangeObj::getScRowsByPosition(SolarMutexGua uno::Reference<table::XCellRange> SAL_CALL ScCellRangeObj::getCellRangeByName( const OUString& aName ) { - return getCellRangeByName( aName, ScAddress::detailsOOOa1 ); + return getScCellRangeByName( aName, ScAddress::detailsOOOa1 ); } uno::Reference<table::XCellRange> ScCellRangeObj::getCellRangeByName( const OUString& aName, const ScAddress::Details& rDetails ) +{ + return getScCellRangeByName( aName, rDetails ); +} + +rtl::Reference<ScCellRangeObj> ScCellRangeObj::getScCellRangeByName( + const OUString& aName ) +{ + return getScCellRangeByName( aName, ScAddress::detailsOOOa1 ); +} + +rtl::Reference<ScCellRangeObj> ScCellRangeObj::getScCellRangeByName( + const OUString& aName, const ScAddress::Details& rDetails ) { // name refers to the whole document (with the range's table as default), // valid only if the range is within this range
