sc/inc/cellsuno.hxx                       |   37 ++++++++++---
 sc/inc/docuno.hxx                         |    2 
 sc/inc/fmtuno.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   |   15 +----
 sc/source/filter/oox/worksheethelper.cxx  |   69 ++++++++++---------------
 sc/source/ui/unoobj/cellsuno.cxx          |   80 +++++++++++++++++++++++++++++-
 10 files changed, 149 insertions(+), 70 deletions(-)

New commits:
commit 98ebcf9e78ca92ff200a2a6456600696e98e8632
Author:     Noel Grandin <[email protected]>
AuthorDate: Wed May 21 15:57:16 2025 +0200
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Sun Jun 15 22:49: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]>
    (cherry picked from commit 56da031f73f544d712b369f732f1ded1d3926fc2)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185716
    Reviewed-by: Tomaž Vajngerl <[email protected]>
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/sc/inc/cellsuno.hxx b/sc/inc/cellsuno.hxx
index 0af278db23c7..600d90801c77 100644
--- a/sc/inc/cellsuno.hxx
+++ b/sc/inc/cellsuno.hxx
@@ -115,6 +115,7 @@ class SfxItemPropertySet;
 struct SfxItemPropertyMapEntry;
 class ScTableRowsObj;
 class ScTableValidationObj;
+class ScCellObj;
 class SolarMutexGuard;
 
 namespace editeng { class SvxBorderLine; }
@@ -496,7 +497,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
@@ -632,6 +633,20 @@ public:
                             // XTypeProvider
     virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
     virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() 
override;
+
+    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?
@@ -676,7 +691,7 @@ public:
 
     virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & 
rType ) override;
     virtual void SAL_CALL   acquire() noexcept override;
-    virtual void SAL_CALL   release() noexcept override;
+    SC_DLLPUBLIC virtual void SAL_CALL release() noexcept override;
 
     virtual void            RefChanged() override;
 
@@ -737,7 +752,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
@@ -770,7 +785,7 @@ public:
     virtual sal_Int16 SAL_CALL resetActionLocks() override;
 };
 
-class SAL_DLLPUBLIC_RTTI ScTableSheetObj final : public ScCellRangeObj,
+class SC_DLLPUBLIC ScTableSheetObj final : public ScCellRangeObj,
                         public css::sheet::XSpreadsheet,
                         public css::container::XNamed,
                         public css::sheet::XSheetPageBreak,
@@ -874,7 +889,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 c8dab9647d0c..898d96f5b140 100644
--- a/sc/inc/docuno.hxx
+++ b/sc/inc/docuno.hxx
@@ -440,7 +440,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 e76285ca37a2..cea2a1e3767e 100644
--- a/sc/source/filter/inc/workbookhelper.hxx
+++ b/sc/source/filter/inc/workbookhelper.hxx
@@ -59,6 +59,8 @@ class ScEditEngineDefaulter;
 class ScDBData;
 class ScRangeData;
 class ScModelObj;
+class ScDatabaseRangeObj;
+class ScTableSheetObj;
 
 namespace oox::xls {
 
@@ -193,7 +195,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 f128e27afd0e..15041c45343e 100644
--- a/sc/source/filter/oox/pivottablebuffer.cxx
+++ b/sc/source/filter/oox/pivottablebuffer.cxx
@@ -1267,7 +1267,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 466b9c4a0b0e..8c646ca63c9e 100644
--- a/sc/source/filter/oox/workbookhelper.cxx
+++ b/sc/source/filter/oox/workbookhelper.cxx
@@ -70,6 +70,7 @@
 #include <drwlayer.hxx>
 #include <globstr.hrc>
 #include <scresid.hxx>
+#include <cellsuno.hxx>
 
 #include <formulabuffer.hxx>
 #include <editutil.hxx>
@@ -852,18 +853,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 c85b3747be3a..0612be9807a8 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 7e34bfb2a7ce..405d2dd8399d 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -4639,7 +4639,7 @@ uno::Sequence<sal_Int8> SAL_CALL 
ScCellRangeObj::getImplementationId()
 //  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();
@@ -4663,6 +4663,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;
 
@@ -4700,11 +4706,23 @@ uno::Reference<table::XCellRange> SAL_CALL 
ScCellRangeObj::getCellRangeByPositio
 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
commit 133ffe0a37b3e8b889705a7f1fc6929ddcd49d19
Author:     Noel Grandin <[email protected]>
AuthorDate: Wed May 21 15:28:41 2025 +0200
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Sun Jun 15 22:49:21 2025 +0200

    tdf#166684 strip out some unnecessary UNO work
    
    to make this easier to optimise, strip out some unnecessary UNO stuff 
between the import filter and the underlying spreadsheet model
    
    Change-Id: I5d0ea6ffc487f089c87f17fd2eb18a30198dbacc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185647
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>
    (cherry picked from commit 79322a7025bb6fd61928204f90230560b09b4ba9)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185703
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Tomaž Vajngerl <[email protected]>

diff --git a/sc/inc/cellsuno.hxx b/sc/inc/cellsuno.hxx
index 259571901721..0af278db23c7 100644
--- a/sc/inc/cellsuno.hxx
+++ b/sc/inc/cellsuno.hxx
@@ -113,6 +113,9 @@ class SfxHint;
 class SfxItemPropertyMap;
 class SfxItemPropertySet;
 struct SfxItemPropertyMapEntry;
+class ScTableRowsObj;
+class ScTableValidationObj;
+class SolarMutexGuard;
 
 namespace editeng { class SvxBorderLine; }
 
@@ -252,6 +255,9 @@ public:
     void                    SetCursorOnly(bool bSet);
     bool                    IsCursorOnly() const            { return 
bCursorOnly; }
 
+    SC_DLLPUBLIC rtl::Reference<ScTableValidationObj> getValidation();
+    SC_DLLPUBLIC void setValidation(const 
rtl::Reference<ScTableValidationObj>&);
+
                             // XSheetOperation
     virtual double SAL_CALL computeFunction( css::sheet::GeneralFunction 
nFunction ) override;
     virtual void SAL_CALL   clearContents( sal_Int32 nContentFlags ) override;
@@ -374,7 +380,7 @@ public:
     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() 
override;
 };
 
-class UNLESS_MERGELIBS(SC_DLLPUBLIC) ScCellRangesObj final : public 
ScCellRangesBase,
+class SC_DLLPUBLIC ScCellRangesObj final : public ScCellRangesBase,
                         public css::sheet::XSheetCellRangeContainer,
                         public css::container::XNameContainer,
                         public css::container::XEnumerationAccess
@@ -393,12 +399,10 @@ private:
     rtl::Reference<ScCellRangeObj> GetObjectByIndex_Impl(sal_Int32 nIndex) 
const;
 
 public:
-    IF_MERGELIBS(SC_DLLPUBLIC)
                             ScCellRangesObj(ScDocShell* pDocSh, const 
ScRangeList& rR);
     virtual                 ~ScCellRangesObj() override;
 
     virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & 
rType ) override;
-    IF_MERGELIBS(SC_DLLPUBLIC)
     virtual void SAL_CALL   acquire() noexcept override;
     virtual void SAL_CALL   release() noexcept override;
 
@@ -455,6 +459,8 @@ public:
                             // XTypeProvider
     virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
     virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() 
override;
+
+    void addRangeAddresses( const ScRangeList& rRanges, bool bMergeRanges );
 };
 
 class SAL_DLLPUBLIC_RTTI ScCellRangeObj : public ScCellRangesBase,
diff --git a/sc/inc/fmtuno.hxx b/sc/inc/fmtuno.hxx
index 91e3b66db020..c7555bc8d5e0 100644
--- a/sc/inc/fmtuno.hxx
+++ b/sc/inc/fmtuno.hxx
@@ -147,7 +147,7 @@ public:
     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() 
override;
 };
 
-class ScTableValidationObj final : public cppu::WeakImplHelper<
+class SC_DLLPUBLIC ScTableValidationObj final : public cppu::WeakImplHelper<
                             css::sheet::XSheetCondition2,
                             css::sheet::XMultiFormulaTokens,
                             css::beans::XPropertySet,
diff --git a/sc/source/filter/oox/worksheethelper.cxx 
b/sc/source/filter/oox/worksheethelper.cxx
index 39a24a2303b3..c85b3747be3a 100644
--- a/sc/source/filter/oox/worksheethelper.cxx
+++ b/sc/source/filter/oox/worksheethelper.cxx
@@ -71,6 +71,8 @@
 #include <cellvalue.hxx>
 #include <columnspanset.hxx>
 #include <dbdata.hxx>
+#include <cellsuno.hxx>
+#include <fmtuno.hxx>
 
 #include <svl/stritem.hxx>
 #include <editeng/eeitem.hxx>
@@ -229,7 +231,7 @@ public:
     /** Returns the XCellRange interface for the passed cell range address. */
     Reference< XCellRange > getCellRange( const ScRange& rRange ) const;
     /** Returns the XSheetCellRanges interface for the passed cell range 
addresses. */
-    Reference< XSheetCellRanges > getCellRangeList( const ScRangeList& rRanges 
) const;
+    rtl::Reference<ScCellRangesObj> getCellRangeList( const ScRangeList& 
rRanges ) const;
 
     /** Returns the XCellRange interface for a column. */
     Reference< XCellRange > getColumn( sal_Int32 nCol ) const;
@@ -402,8 +404,6 @@ private:
     bool                mbHasDefWidth;      /// True = default column width is 
set from defaultColWidth attribute.
 };
 
-constexpr OUStringLiteral gaSheetCellRanges( 
u"com.sun.star.sheet.SheetCellRanges" ); /// Service name for a SheetCellRanges 
object.
-
 WorksheetGlobals::WorksheetGlobals( const WorkbookHelper& rHelper, 
ISegmentProgressBarRef xProgressBar, WorksheetType eSheetType, SCTAB nSheet ) :
     WorkbookHelper( rHelper ),
     mrMaxApiPos( rHelper.getAddressConverter().getMaxApiAddress() ),
@@ -479,17 +479,14 @@ Reference< XCellRange > WorksheetGlobals::getCellRange( 
const ScRange& rRange )
     return xRange;
 }
 
-Reference< XSheetCellRanges > WorksheetGlobals::getCellRangeList( const 
ScRangeList& rRanges ) const
+rtl::Reference<ScCellRangesObj> WorksheetGlobals::getCellRangeList( const 
ScRangeList& rRanges ) const
 {
-    Reference< XSheetCellRanges > xRanges;
-    if( mxSheet.is() && !rRanges.empty() ) try
-    {
-        xRanges.set( getBaseFilter().getModelFactory()->createInstance( 
gaSheetCellRanges ), UNO_QUERY_THROW );
-        Reference< XSheetCellRangeContainer > xRangeCont( xRanges, 
UNO_QUERY_THROW );
-        xRangeCont->addRangeAddresses( 
AddressConverter::toApiSequence(rRanges), false );
-    }
-    catch( Exception& )
+    rtl::Reference<ScCellRangesObj> xRanges;
+    if( mxSheet.is() && !rRanges.empty() )
     {
+        ScDocShell* pDocShell = getScDocument().GetDocumentShell();
+        xRanges = new ScCellRangesObj(pDocShell, ScRangeList());
+        xRanges->addRangeAddresses( rRanges, false );
     }
     return xRanges;
 }
@@ -1090,12 +1087,12 @@ void WorksheetGlobals::finalizeValidationRanges() const
 {
     for (auto const& validation : maValidations)
     {
-        PropertySet aPropSet( getCellRangeList(validation.maRanges) );
+        rtl::Reference<ScCellRangesObj> xRanges = 
getCellRangeList(validation.maRanges);
+        rtl::Reference<ScTableValidationObj> xValidation = 
xRanges->getValidation();
 
-        Reference< XPropertySet > xValidation( aPropSet.getAnyProperty( 
PROP_Validation ), UNO_QUERY );
         if( xValidation.is() )
         {
-            PropertySet aValProps( xValidation );
+            PropertySet aValProps(( Reference< XPropertySet >(xValidation) ));
 
             try
             {
@@ -1109,8 +1106,7 @@ void WorksheetGlobals::finalizeValidationRanges() const
                 xCell = xDBCellRange->getCellByPosition( 0, 0 );
                 Reference<XCellAddressable> xCellAddressable( xCell, 
UNO_QUERY_THROW );
                 CellAddress aFirstCell = xCellAddressable->getCellAddress();
-                Reference<XSheetCondition> xCondition( xValidation, 
UNO_QUERY_THROW );
-                xCondition->setSourcePosition( aFirstCell );
+                xValidation->setSourcePosition( aFirstCell );
             }
             catch(const Exception&)
             {
@@ -1158,26 +1154,18 @@ void WorksheetGlobals::finalizeValidationRanges() const
             // allow blank cells
             aValProps.setProperty( PROP_IgnoreBlankCells, 
validation.mbAllowBlank );
 
-            try
-            {
-                // condition operator
-                Reference< XSheetCondition2 > xSheetCond( xValidation, 
UNO_QUERY_THROW );
-                if( eType == ValidationType_CUSTOM )
-                    xSheetCond->setConditionOperator( 
ConditionOperator2::FORMULA );
-                else
-                    xSheetCond->setConditionOperator( 
CondFormatBuffer::convertToApiOperator( validation.mnOperator ) );
-
-                // condition formulas
-                Reference< XMultiFormulaTokens > xTokens( xValidation, 
UNO_QUERY_THROW );
-                xTokens->setTokens( 0, validation.maTokens1 );
-                xTokens->setTokens( 1, validation.maTokens2 );
-            }
-            catch( Exception& )
-            {
-            }
+            // condition operator
+            if( eType == ValidationType_CUSTOM )
+                xValidation->setConditionOperator( ConditionOperator2::FORMULA 
);
+            else
+                xValidation->setConditionOperator( 
CondFormatBuffer::convertToApiOperator( validation.mnOperator ) );
+
+            // condition formulas
+            xValidation->setTokens( 0, validation.maTokens1 );
+            xValidation->setTokens( 1, validation.maTokens2 );
 
             // write back validation settings to cell range(s)
-            aPropSet.setProperty( PROP_Validation, xValidation );
+            xRanges->setValidation( xValidation );
         }
     }
 }
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 2e5e6b60be14..7e34bfb2a7ce 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -2455,6 +2455,57 @@ void ScCellRangesBase::GetOnePropertyValue( const 
SfxItemPropertyMapEntry* pEntr
         }
 }
 
+rtl::Reference<ScTableValidationObj> ScCellRangesBase::getValidation()
+{
+    SolarMutexGuard aGuard;
+
+    const ScPatternAttr* pPattern = GetCurrentAttrsDeep();
+    if ( !pPattern )
+        return nullptr;
+
+    if ( !pDocShell || aRanges.empty() )
+        throw uno::RuntimeException();
+
+    const SfxItemPropertyMap& rPropertyMap = GetItemPropertyMap();     // from 
derived class
+    const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( 
u"Validation" );
+    assert(pEntry);
+
+    ScDocument& rDoc = pDocShell->GetDocument();
+    bool bEnglish = ( pEntry->nWID != SC_WID_UNO_VALILOC );
+    bool bXML = ( pEntry->nWID == SC_WID_UNO_VALIXML );
+    formula::FormulaGrammar::Grammar eGrammar = (bXML ?
+            rDoc.GetStorageGrammar() :
+           formula::FormulaGrammar::mapAPItoGrammar( bEnglish, bXML));
+    sal_uLong nIndex =
+            pPattern->GetItem(ATTR_VALIDDATA).GetValue();
+    return new ScTableValidationObj( rDoc, nIndex, eGrammar );
+}
+
+void ScCellRangesBase::setValidation(const 
rtl::Reference<ScTableValidationObj>& pValidObj)
+{
+    SolarMutexGuard aGuard;
+
+    const SfxItemPropertyMap& rPropertyMap = GetItemPropertyMap();     // from 
derived class
+    const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( 
u"Validation" );
+    assert(pEntry);
+
+    ScDocument& rDoc = pDocShell->GetDocument();
+    bool bEnglish = ( pEntry->nWID != SC_WID_UNO_VALILOC );
+    bool bXML = ( pEntry->nWID == SC_WID_UNO_VALIXML );
+    formula::FormulaGrammar::Grammar eGrammar = (bXML ?
+           formula::FormulaGrammar::GRAM_UNSPECIFIED :
+           formula::FormulaGrammar::mapAPItoGrammar( bEnglish, bXML));
+
+    std::unique_ptr<ScValidationData> pNewData(
+            pValidObj->CreateValidationData( rDoc, eGrammar ));
+    sal_uInt32 nIndex = rDoc.AddValidationEntry( *pNewData );
+    pNewData.reset();
+
+    ScPatternAttr aPattern(rDoc.getCellAttributeHelper());
+    aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALIDDATA, nIndex ) );
+    pDocShell->GetDocFunc().ApplyAttributes( *GetMarkData(), aPattern, true );
+}
+
 void SAL_CALL ScCellRangesBase::addPropertyChangeListener( const OUString& /* 
aPropertyName */,
                             const 
uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
 {
@@ -4127,6 +4178,13 @@ void SAL_CALL ScCellRangesObj::addRangeAddresses( const 
uno::Sequence<table::Cel
     }
 }
 
+void ScCellRangesObj::addRangeAddresses( const ScRangeList& rRanges, bool 
bMergeRanges )
+{
+    SolarMutexGuard aGuard;
+    for (const ScRange& rRange : rRanges)
+        AddRange(rRange, bMergeRanges);
+}
+
 void SAL_CALL ScCellRangesObj::removeRangeAddresses( const 
uno::Sequence<table::CellRangeAddress >& rRangeSeq )
 {
     // use sometimes a better/faster implementation

Reply via email to