forms/source/xforms/model.cxx            |    2 +-
 forms/source/xforms/model_helper.hxx     |    4 ++--
 forms/source/xforms/submission.cxx       |   21 ++++++++-------------
 forms/source/xforms/submission.hxx       |   11 +++++------
 sc/source/ui/docshell/docsh.cxx          |    6 ++----
 sc/source/ui/docshell/docsh3.cxx         |    6 ++----
 sc/source/ui/docshell/docsh4.cxx         |    4 +---
 sc/source/ui/drawfunc/fuins2.cxx         |    2 +-
 sc/source/ui/drawfunc/fusel.cxx          |    2 +-
 sc/source/ui/inc/docsh.hxx               |    9 +++------
 sc/source/ui/miscdlgs/optsolver.cxx      |    2 +-
 sc/source/ui/miscdlgs/sharedocdlg.cxx    |    3 +--
 sc/source/ui/undo/undocell.cxx           |    2 +-
 sc/source/ui/unoobj/TablePivotCharts.cxx |    2 +-
 sc/source/ui/unoobj/chartuno.cxx         |    2 +-
 sc/source/ui/unoobj/servuno.cxx          |   10 ++++------
 sc/source/ui/vba/excelvbahelper.cxx      |    3 +--
 sc/source/ui/vba/vbachartobjects.cxx     |    3 +--
 sc/source/ui/vba/vbarange.cxx            |    6 ++----
 sc/source/ui/view/formatsh.cxx           |    3 +--
 sc/source/ui/view/tabview.cxx            |    3 +--
 sc/source/ui/view/tabview3.cxx           |    2 +-
 sc/source/ui/view/tabview5.cxx           |    2 +-
 sc/source/ui/view/viewfun2.cxx           |    2 +-
 sc/source/ui/view/viewfun3.cxx           |    4 ++--
 sc/source/ui/view/viewfun7.cxx           |    4 ++--
 sc/source/ui/view/viewfunc.cxx           |    8 ++++----
 27 files changed, 52 insertions(+), 76 deletions(-)

New commits:
commit 0ef626f2ff72c62ee42e74e2b58174c047e384cd
Author:     Noel Grandin <[email protected]>
AuthorDate: Thu Jan 12 10:19:24 2023 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Thu Jan 12 14:46:29 2023 +0000

    override GetModel in ScDocShell
    
    so we can avoid dynamic_cast and XUnoTunnel in various places
    
    Change-Id: I1f524270a8030106a2058691c3d89b90d46ed26f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145391
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 2f2f3521ae4e..071c2530f61b 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -503,8 +503,7 @@ bool ScDocShell::LoadXML( SfxMedium* pLoadMedium, const 
css::uno::Reference< css
     //if the document was not generated by LibreOffice, do hard recalc in case 
some other document
     //generator saved cached formula results that differ from LibreOffice's 
calculated results or
     //did not use cached formula results.
-    uno::Reference<document::XDocumentPropertiesSupplier> xDPS(GetModel(), 
uno::UNO_QUERY_THROW);
-    uno::Reference<document::XDocumentProperties> xDocProps = 
xDPS->getDocumentProperties();
+    uno::Reference<document::XDocumentProperties> xDocProps = 
GetModel()->getDocumentProperties();
 
     ScRecalcOptions nRecalcMode =
         
static_cast<ScRecalcOptions>(officecfg::Office::Calc::Formula::Load::ODFRecalcMode::get());
@@ -896,7 +895,6 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& 
rHint )
                                                 bChangedViewSettings = true;
                                             }
 
-                                            uno::Reference< frame::XStorable > 
xStor( GetModel(), uno::UNO_QUERY_THROW );
                                             // TODO/LATER: More entries from 
the MediaDescriptor might be interesting for the merge
                                             uno::Sequence< 
beans::PropertyValue > aValues{
                                                 comphelper::makePropertyValue(
@@ -922,7 +920,7 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& 
rHint )
                                             }
 
                                             SC_MOD()->SetInSharedDocSaving( 
true );
-                                            xStor->storeToURL( 
GetSharedFileURL(), aValues );
+                                            GetModel()->storeToURL( 
GetSharedFileURL(), aValues );
                                             SC_MOD()->SetInSharedDocSaving( 
false );
 
                                             if ( bChangedViewSettings )
diff --git a/sc/source/ui/docshell/docsh3.cxx b/sc/source/ui/docshell/docsh3.cxx
index 803ba61f8a7a..5d3cd076f623 100644
--- a/sc/source/ui/docshell/docsh3.cxx
+++ b/sc/source/ui/docshell/docsh3.cxx
@@ -175,7 +175,7 @@ void ScDocShell::PostPaint( const ScRangeList& rRanges, 
PaintPartFlags nPart, sa
     // the document size too - cell size affects that, obviously)
     if ((nPart & (PaintPartFlags::Top | PaintPartFlags::Left)) && 
comphelper::LibreOfficeKit::isActive())
     {
-        ScModelObj* pModel = 
comphelper::getFromUnoTunnel<ScModelObj>(this->GetModel());
+        ScModelObj* pModel = GetModel();
         SfxLokHelper::notifyDocumentSizeChangedAllViews(pModel);
     }
 }
@@ -696,10 +696,8 @@ void ScDocShell::CompareDocument( ScDocument& rOtherDoc )
             //  (only if comparing different documents)
 
             using namespace ::com::sun::star;
-            uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
-                GetModel(), uno::UNO_QUERY_THROW);
             uno::Reference<document::XDocumentProperties> xDocProps(
-                xDPS->getDocumentProperties());
+                GetModel()->getDocumentProperties());
             OSL_ENSURE(xDocProps.is(), "no DocumentProperties");
             OUString aDocUser = xDocProps->getModifiedBy();
 
diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx
index 494057b12087..a57a40e9be8b 100644
--- a/sc/source/ui/docshell/docsh4.cxx
+++ b/sc/source/ui/docshell/docsh4.cxx
@@ -1132,9 +1132,7 @@ void ScDocShell::Execute( SfxRequest& rReq )
                                             EnableSharedSettings( false );
 
                                             // Do *not* use dispatch mechanism 
in this place - we don't want others (extensions etc.) to intercept this.
-                                            uno::Reference<frame::XStorable> 
xStorable2(
-                                                GetModel(), 
uno::UNO_QUERY_THROW);
-                                            xStorable2->store();
+                                            GetModel()->store();
 
                                             ScTabView* pTabView = 
pViewData->GetView();
                                             if ( pTabView )
diff --git a/sc/source/ui/drawfunc/fuins2.cxx b/sc/source/ui/drawfunc/fuins2.cxx
index ba7c2cba3573..e753e63214a6 100644
--- a/sc/source/ui/drawfunc/fuins2.cxx
+++ b/sc/source/ui/drawfunc/fuins2.cxx
@@ -139,7 +139,7 @@ void lcl_ChartInit(const uno::Reference 
<embed::XEmbeddedObject>& xObj, ScViewDa
 
     xReceiver->attachDataProvider(xDataProvider);
 
-    uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( 
pDocShell->GetModel(), uno::UNO_QUERY );
+    uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( 
static_cast<cppu::OWeakObject*>(pDocShell->GetModel()), uno::UNO_QUERY );
     xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
 
     // Same behavior as with old chart: Always assume data series in columns
diff --git a/sc/source/ui/drawfunc/fusel.cxx b/sc/source/ui/drawfunc/fusel.cxx
index 2b051bb3bf11..9695702c55e3 100644
--- a/sc/source/ui/drawfunc/fusel.cxx
+++ b/sc/source/ui/drawfunc/fusel.cxx
@@ -531,7 +531,7 @@ bool FuSelection::MouseButtonUp(const MouseEvent& rMEvt)
     if ( bCopy && pPage )
     {
         ScDocShell* pDocShell = rViewData.GetDocShell();
-        ScModelObj* pModelObj = ( pDocShell ? 
comphelper::getFromUnoTunnel<ScModelObj>( pDocShell->GetModel() ) : nullptr );
+        ScModelObj* pModelObj = ( pDocShell ? pDocShell->GetModel() : nullptr 
);
         if ( pModelObj )
         {
             SCTAB nTab = rViewData.GetTabNo();
diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx
index 8fac5cf6ed5a..edf0cbc1c1b0 100644
--- a/sc/source/ui/inc/docsh.hxx
+++ b/sc/source/ui/inc/docsh.hxx
@@ -430,6 +430,8 @@ public:
     void SnapVisArea( tools::Rectangle& rRect ) const;
 
     void RegisterAutomationWorkbookObject(css::uno::Reference< 
ooo::vba::excel::XWorkbook > const& xWorkbook);
+
+    ScModelObj* GetModel() const { return 
static_cast<ScModelObj*>(SfxObjectShell::GetModel().get()); }
 };
 
 void UpdateAcceptChangesDialog();
@@ -490,11 +492,6 @@ namespace HelperNotifyChanges
         return false;
     }
 
-    inline ScModelObj* getModel(const ScDocShell &rDocShell)
-    {
-        return comphelper::getFromUnoTunnel<ScModelObj>(rDocShell.GetModel());
-    }
-
     inline bool getMustPropagateChangesModel(ScModelObj* pModelObj)
     {
         return pModelObj && pModelObj->HasChangesListeners();
@@ -511,7 +508,7 @@ namespace HelperNotifyChanges
     inline void NotifyIfChangesListeners(const ScDocShell &rDocShell, const 
ScRange &rRange,
         const OUString &rType = OUString("cell-change"))
     {
-        ScModelObj* pModelObj = getModel(rDocShell);
+        ScModelObj* pModelObj = rDocShell.GetModel();
         ScRangeList aChangeRanges(rRange);
 
         if (getMustPropagateChangesModel(pModelObj))
diff --git a/sc/source/ui/miscdlgs/optsolver.cxx 
b/sc/source/ui/miscdlgs/optsolver.cxx
index 5f4270b559c5..42fdf95ae1a7 100644
--- a/sc/source/ui/miscdlgs/optsolver.cxx
+++ b/sc/source/ui/miscdlgs/optsolver.cxx
@@ -830,7 +830,7 @@ bool ScOptSolverDlg::CallSolver()       // return true -> 
close dialog after cal
 
     ReadConditions();
 
-    uno::Reference<sheet::XSpreadsheetDocument> xDocument( 
mpDocShell->GetModel(), uno::UNO_QUERY );
+    rtl::Reference<ScModelObj> xDocument( mpDocShell->GetModel() );
 
     ScRange aObjRange;
     if ( !ParseRef( aObjRange, m_xEdObjectiveCell->GetText(), false ) )
diff --git a/sc/source/ui/miscdlgs/sharedocdlg.cxx 
b/sc/source/ui/miscdlgs/sharedocdlg.cxx
index bb02a2e7d385..5ebe52a8e677 100644
--- a/sc/source/ui/miscdlgs/sharedocdlg.cxx
+++ b/sc/source/ui/miscdlgs/sharedocdlg.cxx
@@ -196,8 +196,7 @@ void ScShareDocumentDlg::UpdateView()
         }
         aUser += " " + m_aStrExclusiveAccess;
 
-        uno::Reference<document::XDocumentPropertiesSupplier> 
xDPS(mpDocShell->GetModel(), uno::UNO_QUERY_THROW);
-        uno::Reference<document::XDocumentProperties> xDocProps = 
xDPS->getDocumentProperties();
+        uno::Reference<document::XDocumentProperties> xDocProps = 
mpDocShell->GetModel()->getDocumentProperties();
 
         util::DateTime uDT(xDocProps->getModificationDate());
         DateTime aDateTime(uDT);
diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx
index c51110402b1e..16c79ea457f5 100644
--- a/sc/source/ui/undo/undocell.cxx
+++ b/sc/source/ui/undo/undocell.cxx
@@ -50,7 +50,7 @@ namespace HelperNotifyChanges
     static void NotifyIfChangesListeners(const ScDocShell& rDocShell, const 
ScAddress &rPos,
         const ScUndoEnterData::ValuesType &rOldValues, const OUString& rType = 
OUString("cell-change"))
     {
-        ScModelObj* pModelObj = getModel(rDocShell);
+        ScModelObj* pModelObj = rDocShell.GetModel();
         if (pModelObj)
         {
             ScRangeList aChangeRanges;
diff --git a/sc/source/ui/unoobj/TablePivotCharts.cxx 
b/sc/source/ui/unoobj/TablePivotCharts.cxx
index da5fc9f2f19d..7bc7731cd1b0 100644
--- a/sc/source/ui/unoobj/TablePivotCharts.cxx
+++ b/sc/source/ui/unoobj/TablePivotCharts.cxx
@@ -139,7 +139,7 @@ void SAL_CALL TablePivotCharts::addNewByName(OUString const 
& rName,
     {
         xReceiver->attachDataProvider(xDataProvider);
 
-        uno::Reference<util::XNumberFormatsSupplier> 
xNumberFormatsSupplier(m_pDocShell->GetModel(), uno::UNO_QUERY);
+        uno::Reference<util::XNumberFormatsSupplier> 
xNumberFormatsSupplier(static_cast<cppu::OWeakObject*>(m_pDocShell->GetModel()),
 uno::UNO_QUERY);
         xReceiver->attachNumberFormatsSupplier(xNumberFormatsSupplier);
 
         uno::Sequence<beans::PropertyValue> aArgs( 
comphelper::InitPropertySequence({
diff --git a/sc/source/ui/unoobj/chartuno.cxx b/sc/source/ui/unoobj/chartuno.cxx
index 4d4ea02c3e24..25f356eed2e7 100644
--- a/sc/source/ui/unoobj/chartuno.cxx
+++ b/sc/source/ui/unoobj/chartuno.cxx
@@ -222,7 +222,7 @@ void SAL_CALL ScChartsObj::addNewByName( const OUString& 
rName,
         else
             sRangeStr = "all";
 
-        uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( 
pDocShell->GetModel(), uno::UNO_QUERY );
+        uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( 
static_cast<cppu::OWeakObject*>(pDocShell->GetModel()), uno::UNO_QUERY );
         xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
 
         // set arguments
diff --git a/sc/source/ui/unoobj/servuno.cxx b/sc/source/ui/unoobj/servuno.cxx
index f2713d26bfac..073a57119bb4 100644
--- a/sc/source/ui/unoobj/servuno.cxx
+++ b/sc/source/ui/unoobj/servuno.cxx
@@ -95,7 +95,7 @@ public:
         uno::Sequence< uno::Any > aArgs{
             // access the application object ( parent for workbook )
             uno::Any(ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, 
"ooo.vba.Application", {} )),
-            uno::Any(mpDocShell->GetModel())
+            
uno::Any(uno::Reference(static_cast<css::sheet::XSpreadsheetDocument*>(mpDocShell->GetModel())))
         };
         maWorkbook <<= ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, 
"ooo.vba.excel.Workbook", aArgs );
     }
@@ -182,8 +182,7 @@ public:
         OUString sCodeName;
 
         // need to find the page ( and index )  for this control
-        uno::Reference< drawing::XDrawPagesSupplier > xSupplier( 
mrDocShell.GetModel(), uno::UNO_QUERY_THROW );
-        uno::Reference< container::XIndexAccess > xIndex( 
xSupplier->getDrawPages(), uno::UNO_QUERY_THROW );
+        uno::Reference< container::XIndexAccess > xIndex(  
mrDocShell.GetModel()->getDrawPages(), uno::UNO_QUERY_THROW );
         sal_Int32 nLen = xIndex->getCount();
         bool bMatched = false;
         for ( sal_Int32 index = 0; index < nLen; ++index )
@@ -218,8 +217,7 @@ public:
     OUString SAL_CALL getCodeNameForContainer( const 
uno::Reference<uno::XInterface>& xContainer ) override
     {
         SolarMutexGuard aGuard;
-        uno::Reference<drawing::XDrawPagesSupplier> 
xSupplier(mrDocShell.GetModel(), uno::UNO_QUERY_THROW);
-        uno::Reference<container::XIndexAccess> 
xIndex(xSupplier->getDrawPages(), uno::UNO_QUERY_THROW);
+        uno::Reference<container::XIndexAccess> 
xIndex(mrDocShell.GetModel()->getDrawPages(), uno::UNO_QUERY_THROW);
 
         for (sal_Int32 i = 0, n = xIndex->getCount(); i < n; ++i)
         {
@@ -583,7 +581,7 @@ uno::Reference<uno::XInterface> 
ScServiceProvider::MakeInstance(
                 uno::Any aGlobs;
                 if ( !pDocShell->GetBasicManager()->GetGlobalUNOConstant( 
"VBAGlobals", aGlobs ) )
                 {
-                    uno::Sequence< uno::Any > aArgs{ 
uno::Any(pDocShell->GetModel()) };
+                    uno::Sequence< uno::Any > aArgs{ 
uno::Any(uno::Reference(static_cast<css::sheet::XSpreadsheetDocument*>(pDocShell->GetModel())))
 };
                     xRet = 
::comphelper::getProcessServiceFactory()->createInstanceWithArguments( 
"ooo.vba.excel.Globals", aArgs );
                     pDocShell->GetBasicManager()->SetGlobalUNOConstant( 
"VBAGlobals", uno::Any( xRet ) );
                     BasicManager* pAppMgr = SfxApplication::GetBasicManager();
diff --git a/sc/source/ui/vba/excelvbahelper.cxx 
b/sc/source/ui/vba/excelvbahelper.cxx
index 1c1824d89533..f752234943c5 100644
--- a/sc/source/ui/vba/excelvbahelper.cxx
+++ b/sc/source/ui/vba/excelvbahelper.cxx
@@ -339,8 +339,7 @@ void setUpDocumentModules( const uno::Reference< 
sheet::XSpreadsheetDocument >&
         if( xLib.is()  )
         {
             uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( 
xLib, uno::UNO_QUERY_THROW );
-            uno::Reference< lang::XMultiServiceFactory> xSF( 
pShell->GetModel(), uno::UNO_QUERY_THROW);
-            uno::Reference< container::XNameAccess > 
xVBACodeNamedObjectAccess( 
xSF->createInstance("ooo.vba.VBAObjectModuleObjectProvider"), 
uno::UNO_QUERY_THROW );
+            uno::Reference< container::XNameAccess > 
xVBACodeNamedObjectAccess( 
pShell->GetModel()->createInstance("ooo.vba.VBAObjectModuleObjectProvider"), 
uno::UNO_QUERY_THROW );
             // set up the module info for the workbook and sheets in the newly 
created
             // spreadsheet
             ScDocument& rDoc = pShell->GetDocument();
diff --git a/sc/source/ui/vba/vbachartobjects.cxx 
b/sc/source/ui/vba/vbachartobjects.cxx
index 5cc12080c1e4..cdc1d3d48362 100644
--- a/sc/source/ui/vba/vbachartobjects.cxx
+++ b/sc/source/ui/vba/vbachartobjects.cxx
@@ -111,8 +111,7 @@ ScVbaChartObjects::getChartObjectNames() const
         if ( !pDocShell )
             throw uno::RuntimeException("Failed to obtain the docshell 
implclass" );
 
-        uno::Reference< sheet::XSpreadsheetDocument > xSpreadsheetDocument( 
pDocShell->GetModel(), uno::UNO_QUERY_THROW );
-        uno::Reference< sheet::XSpreadsheets > xSpreadsheets = 
xSpreadsheetDocument->getSheets();
+        uno::Reference< sheet::XSpreadsheets > xSpreadsheets = 
pDocShell->GetModel()->getSheets();
         std::vector< OUString > aChartNamesVector;
 
         const uno::Sequence< OUString > sSheetNames = 
xSpreadsheets->getElementNames();
diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx
index 15a04d480f9e..4998942084ce 100644
--- a/sc/source/ui/vba/vbarange.cxx
+++ b/sc/source/ui/vba/vbarange.cxx
@@ -1173,8 +1173,7 @@ ScVbaRange::getCellRangesForAddress( ScRefFlags& 
rResFlags, std::u16string_view
 bool getScRangeListForAddress( const OUString& sName, ScDocShell* pDocSh, 
const ScRange& refRange, ScRangeList& aCellRanges, 
formula::FormulaGrammar::AddressConvention aConv )
 {
     // see if there is a match with a named range
-    uno::Reference< beans::XPropertySet > xProps( pDocSh->GetModel(), 
uno::UNO_QUERY_THROW );
-    uno::Reference< container::XNameAccess > xNameAccess( 
xProps->getPropertyValue( "NamedRanges" ), uno::UNO_QUERY_THROW );
+    uno::Reference< container::XNameAccess > xNameAccess( 
pDocSh->GetModel()->getPropertyValue( "NamedRanges" ), uno::UNO_QUERY_THROW );
     // Strange enough you can have Range( "namedRange1, namedRange2, etc," )
     // loop around each ',' separated name
     std::vector< OUString > vNames;
@@ -5213,7 +5212,6 @@ ScVbaRange::GoalSeek( const uno::Any& Goal, const 
uno::Reference< excel::XRange
     ScVbaRange* pRange = static_cast< ScVbaRange* >( ChangingCell.get() );
     if ( pDocShell && pRange )
     {
-        uno::Reference< sheet::XGoalSeek > xGoalSeek(  pDocShell->GetModel(), 
uno::UNO_QUERY_THROW );
         RangeHelper thisRange( mxRange );
         table::CellRangeAddress thisAddress = 
thisRange.getCellRangeAddressable()->getRangeAddress();
         RangeHelper changingCellRange( pRange->mxRange );
@@ -5221,7 +5219,7 @@ ScVbaRange::GoalSeek( const uno::Any& Goal, const 
uno::Reference< excel::XRange
         OUString sGoal = getAnyAsString( Goal );
         table::CellAddress thisCell( thisAddress.Sheet, 
thisAddress.StartColumn, thisAddress.StartRow );
         table::CellAddress changingCell( changingCellAddr.Sheet, 
changingCellAddr.StartColumn, changingCellAddr.StartRow );
-        sheet::GoalResult res = xGoalSeek->seekGoal( thisCell, changingCell, 
sGoal );
+        sheet::GoalResult res = pDocShell->GetModel()->seekGoal( thisCell, 
changingCell, sGoal );
         ChangingCell->setValue( uno::Any( res.Result ) );
 
         // openoffice behaves differently, result is 0 if the divergence is 
too great
diff --git a/sc/source/ui/view/formatsh.cxx b/sc/source/ui/view/formatsh.cxx
index 3c823fad2fa1..9c35f3f1a4c3 100644
--- a/sc/source/ui/view/formatsh.cxx
+++ b/sc/source/ui/view/formatsh.cxx
@@ -398,11 +398,10 @@ void ScFormatShell::ExecuteStyle( SfxRequest& rReq )
                 const SfxStringItem* pFamilyItem = 
rReq.GetArg<SfxStringItem>(SID_STYLE_FAMILYNAME);
                 if ( pFamilyItem && pNameItem )
                 {
-                    css::uno::Reference< css::style::XStyleFamiliesSupplier > 
xModel(pDocSh->GetModel(), css::uno::UNO_QUERY);
                     try
                     {
                         css::uno::Reference< css::container::XNameAccess > 
xStyles;
-                        css::uno::Reference< css::container::XNameAccess > 
xCont = xModel->getStyleFamilies();
+                        css::uno::Reference< css::container::XNameAccess > 
xCont = pDocSh->GetModel()->getStyleFamilies();
                         xCont->getByName(pFamilyItem->GetValue()) >>= xStyles;
                         css::uno::Reference< css::beans::XPropertySet > xInfo;
                         xStyles->getByName( pNameItem->GetValue() ) >>= xInfo;
diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx
index 5b2c44ee4875..4248fdd08526 100644
--- a/sc/source/ui/view/tabview.cxx
+++ b/sc/source/ui/view/tabview.cxx
@@ -2631,8 +2631,7 @@ void lcl_ExtendTiledDimension(bool bColumn, const 
SCCOLROW nEnd, const SCCOLROW
         return;
 
     ScDocShell* pDocSh = rViewData.GetDocShell();
-    ScModelObj* pModelObj = pDocSh ?
-        comphelper::getFromUnoTunnel<ScModelObj>( pDocSh->GetModel() ) : 
nullptr;
+    ScModelObj* pModelObj = pDocSh ? pDocSh->GetModel() : nullptr;
     Size aOldSize(0, 0);
     if (pModelObj)
         aOldSize = pModelObj->getDocumentSize();
diff --git a/sc/source/ui/view/tabview3.cxx b/sc/source/ui/view/tabview3.cxx
index feab66cbd411..fdf3a3d517dc 100644
--- a/sc/source/ui/view/tabview3.cxx
+++ b/sc/source/ui/view/tabview3.cxx
@@ -403,7 +403,7 @@ void ScTabView::SetCursor( SCCOL nPosX, SCROW nPosY, bool 
bNew )
 
     ScDocument& rDoc = aViewData.GetDocument();
     ScDocShell* pDocSh = aViewData.GetDocShell();
-    ScModelObj* pModelObj = pDocSh ? comphelper::getFromUnoTunnel<ScModelObj>( 
pDocSh->GetModel() ) : nullptr;
+    ScModelObj* pModelObj = pDocSh ? pDocSh->GetModel() : nullptr;
     Size aOldSize(0, 0);
     if (pModelObj)
         aOldSize = pModelObj->getDocumentSize();
diff --git a/sc/source/ui/view/tabview5.cxx b/sc/source/ui/view/tabview5.cxx
index dd3e057ada21..f3569ac9497f 100644
--- a/sc/source/ui/view/tabview5.cxx
+++ b/sc/source/ui/view/tabview5.cxx
@@ -332,7 +332,7 @@ void ScTabView::TabChanged( bool bSameTabButMoved )
         return;
 
     ScDocShell* pDocSh = GetViewData().GetDocShell();
-    ScModelObj* pModelObj = pDocSh ? comphelper::getFromUnoTunnel<ScModelObj>( 
pDocSh->GetModel()) : nullptr;
+    ScModelObj* pModelObj = pDocSh ? pDocSh->GetModel() : nullptr;
 
     if (!pModelObj)
         return;
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index 884722204f0a..8be670e2834f 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -1487,7 +1487,7 @@ void ScViewFunc::FillAuto( FillDir eDir, SCCOL nStartCol, 
SCROW nStartRow,
     if ( bDoAutoSpell )
         CopyAutoSpellData(eDir, nStartCol, nStartRow, nEndCol, nEndRow, 
nCount);
 
-    ScModelObj* pModelObj = HelperNotifyChanges::getModel(*pDocSh);
+    ScModelObj* pModelObj = pDocSh->GetModel();
 
     ScRangeList aChangeRanges;
     ScRange aChangeRange( aRange );
diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx
index 9dd9b810273a..a19484aa9007 100644
--- a/sc/source/ui/view/viewfun3.cxx
+++ b/sc/source/ui/view/viewfun3.cxx
@@ -1448,7 +1448,7 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, 
ScDocument* pClipDoc,
 
     if ( nFlags & InsertDeleteFlags::OBJECTS )
     {
-        ScModelObj* pModelObj = comphelper::getFromUnoTunnel<ScModelObj>( 
pDocSh->GetModel() );
+        ScModelObj* pModelObj = pDocSh->GetModel();
         if ( pPage && pModelObj )
         {
             bool bSameDoc = ( rClipParam.getSourceDocID() == 
rDoc.GetDocumentID() );
@@ -1803,7 +1803,7 @@ void ScViewFunc::PostPasteFromClip(const ScRangeList& 
rPasteRanges, const ScMark
 
     SelectionChanged(true);
 
-    ScModelObj* pModelObj = HelperNotifyChanges::getModel(*pDocSh);
+    ScModelObj* pModelObj = pDocSh->GetModel();
 
     ScRangeList aChangeRanges;
     for (size_t i = 0, n = rPasteRanges.size(); i < n; ++i)
diff --git a/sc/source/ui/view/viewfun7.cxx b/sc/source/ui/view/viewfun7.cxx
index d42860dad5fc..0b55f4eff0e2 100644
--- a/sc/source/ui/view/viewfun7.cxx
+++ b/sc/source/ui/view/viewfun7.cxx
@@ -178,7 +178,7 @@ void ScViewFunc::PasteDraw( const Point& rLogicPos, 
SdrModel* pModel,
 
             ScDocument& rDocument = GetViewData().GetDocument();
             ScDocShell* pDocShell = GetViewData().GetDocShell();
-            ScModelObj* pModelObj = ( pDocShell ? 
comphelper::getFromUnoTunnel<ScModelObj>( pDocShell->GetModel() ) : nullptr );
+            ScModelObj* pModelObj = ( pDocShell ? pDocShell->GetModel() : 
nullptr );
             if ( pDestPage && pModelObj && pDrawTrans )
             {
                 const ScRangeListVector& rProtectedChartRangesVector( 
pDrawTrans->GetProtectedChartRangesVector() );
@@ -247,7 +247,7 @@ void ScViewFunc::PasteDraw( const Point& rLogicPos, 
SdrModel* pModel,
 
         ScDocument& rDocument = GetViewData().GetDocument();
         ScDocShell* pDocShell = GetViewData().GetDocShell();
-        ScModelObj* pModelObj = ( pDocShell ? 
comphelper::getFromUnoTunnel<ScModelObj>( pDocShell->GetModel() ) : nullptr );
+        ScModelObj* pModelObj = ( pDocShell ? pDocShell->GetModel() : nullptr 
);
         const ScDrawTransferObj* pTransferObj = 
ScDrawTransferObj::GetOwnClipboard(ScTabViewShell::GetClipData(GetViewData().GetActiveWin()));
         if ( pPage && pModelObj && ( pTransferObj || pDrawTrans ) )
         {
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index 6e15f9b3e0f8..4924e0c8c64f 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -340,7 +340,7 @@ namespace HelperNotifyChanges
     static void NotifyIfChangesListeners(const ScDocShell &rDocShell, 
ScMarkData& rMark,
                                          SCCOL nCol, SCROW nRow, const 
OUString& rType = "cell-change")
     {
-        ScModelObj* pModelObj = getModel(rDocShell);
+        ScModelObj* pModelObj = rDocShell.GetModel();
 
         ScRangeList aChangeRanges;
         for (const auto& rTab : rMark)
@@ -1347,7 +1347,7 @@ void ScViewFunc::ApplySelectionPattern( const 
ScPatternAttr& rAttr, bool bCursor
         CellContentChanged();
     }
 
-    ScModelObj* pModelObj = HelperNotifyChanges::getModel(*pDocSh);
+    ScModelObj* pModelObj = pDocSh->GetModel();
 
     if (HelperNotifyChanges::getMustPropagateChangesModel(pModelObj))
     {
@@ -2108,7 +2108,7 @@ void ScViewFunc::DeleteContents( InsertDeleteFlags nFlags 
)
 
     pDocSh->UpdateOle(GetViewData());
 
-    if (ScModelObj* pModelObj = HelperNotifyChanges::getModel(*pDocSh))
+    if (ScModelObj* pModelObj = pDocSh->GetModel())
     {
         ScRangeList aChangeRanges;
         if ( bSimple )
@@ -2443,7 +2443,7 @@ void ScViewFunc::SetWidthOrHeight(
     if ( !bWidth )
         return;
 
-    ScModelObj* pModelObj = HelperNotifyChanges::getModel(*pDocSh);
+    ScModelObj* pModelObj = pDocSh->GetModel();
 
     if (!HelperNotifyChanges::getMustPropagateChangesModel(pModelObj))
         return;
commit 5fd2f0b93bd7d38a277823bfc251c71da7a6f490
Author:     Noel Grandin <[email protected]>
AuthorDate: Thu Jan 12 09:19:03 2023 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Thu Jan 12 14:46:19 2023 +0000

    use concrete class in Submission
    
    the code already relies on the underlying type of mxModel being Model
    rather than XModel
    
    Change-Id: I5b78482d37024a5bc274b0208fa56e4328f3f5f2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145390
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/forms/source/xforms/model.cxx b/forms/source/xforms/model.cxx
index 7001f4aaa8e8..d4eeb0e57980 100644
--- a/forms/source/xforms/model.cxx
+++ b/forms/source/xforms/model.cxx
@@ -436,7 +436,7 @@ void SAL_CALL Model::submitWithInteraction(
         Submission* pSubmission =
             comphelper::getFromUnoTunnel<Submission>( mxSubmissions->getItem( 
sID ) );
         OSL_ENSURE( pSubmission != nullptr, "no submission?" );
-        OSL_ENSURE( pSubmission->getModel() == Reference<XModel>( this ),
+        OSL_ENSURE( pSubmission->getModelImpl() == this,
                     "wrong model" );
 
         // submit. All exceptions are allowed to leave.
diff --git a/forms/source/xforms/model_helper.hxx 
b/forms/source/xforms/model_helper.hxx
index d8e98c98ec26..fbb563a1300b 100644
--- a/forms/source/xforms/model_helper.hxx
+++ b/forms/source/xforms/model_helper.hxx
@@ -92,14 +92,14 @@ protected:
     {
         auto pSubmission = comphelper::getFromUnoTunnel<Submission>( t );
         OSL_ENSURE( pSubmission != nullptr, "invalid item?" );
-        pSubmission->setModel( css::uno::Reference<css::xforms::XModel>( 
mpModel ) );
+        pSubmission->setModel( mpModel );
     }
 
     virtual void _remove( const T& t ) override
     {
         auto pSubmission = comphelper::getFromUnoTunnel<Submission>( t );
         OSL_ENSURE( pSubmission != nullptr, "invalid item?" );
-        pSubmission->setModel( css::uno::Reference<css::xforms::XModel>( ) );
+        pSubmission->setModel( nullptr );
     }
 };
 
diff --git a/forms/source/xforms/submission.cxx 
b/forms/source/xforms/submission.cxx
index d8d81abd5b23..8260095102b3 100644
--- a/forms/source/xforms/submission.cxx
+++ b/forms/source/xforms/submission.cxx
@@ -85,7 +85,8 @@ Submission::~Submission() noexcept
 
 void Submission::setModel( const Reference<XModel>& xModel )
 {
-    mxModel = xModel;
+    mxModel = dynamic_cast<Model*>(xModel.get());
+    assert((!mxModel || !xModel) && "we only support an instance of Model 
here");
 }
 
 
@@ -202,12 +203,12 @@ bool Submission::doSubmit( const Reference< 
XInteractionHandler >& xHandler )
     else if( !maRef.getExpression().isEmpty() )
     {
         aExpression.setExpression( maRef.getExpression() );
-        aEvalContext = comphelper::getFromUnoTunnel<Model>( mxModel 
)->getEvaluationContext();
+        aEvalContext = mxModel->getEvaluationContext();
     }
     else
     {
         aExpression.setExpression( "/" );
-        aEvalContext = comphelper::getFromUnoTunnel<Model>( mxModel 
)->getEvaluationContext();
+        aEvalContext = mxModel->getEvaluationContext();
     }
     aExpression.evaluate( aEvalContext );
     Reference<XXPathObject> xResult = aExpression.getXPath();
@@ -268,12 +269,9 @@ void Submission::liveCheck()
         throw RuntimeException();
 }
 
-Model* Submission::getModelImpl() const
+css::uno::Reference<XModel> Submission::getModel() const
 {
-    Model* pModel = nullptr;
-    if( mxModel.is() )
-        pModel = comphelper::getFromUnoTunnel<Model>( mxModel );
-    return pModel;
+    return mxModel;
 }
 
 
@@ -404,7 +402,7 @@ void SAL_CALL Submission::submitWithInteraction(
 {
     // as long as this class is not really threadsafe, we need to copy
     // the members we're interested in
-    Reference< XModel > xModel( mxModel );
+    rtl::Reference< Model > xModel( mxModel );
     OUString sID( msID );
 
     if ( !xModel.is() || msID.isEmpty() )
@@ -413,12 +411,9 @@ void SAL_CALL Submission::submitWithInteraction(
                 *this
               );
 
-    Model* pModel = comphelper::getFromUnoTunnel<Model>( xModel );
-    OSL_ENSURE( pModel != nullptr, "illegal model?" );
-
     // #i36765# #i47248# warning on submission of illegal data
     // check for validity (and query user if invalid)
-    bool bValid = pModel->isValid();
+    bool bValid = xModel->isValid();
     if( ! bValid )
     {
         InvalidDataOnSubmitException aInvalidDataException(
diff --git a/forms/source/xforms/submission.hxx 
b/forms/source/xforms/submission.hxx
index 1e7f17e4cfc7..31c5b9af07b9 100644
--- a/forms/source/xforms/submission.hxx
+++ b/forms/source/xforms/submission.hxx
@@ -78,7 +78,7 @@ class Submission : public Submission_t
 private:
 
     /// the Model to which this Submission belongs; may be NULL
-    css::uno::Reference<css::xforms::XModel> mxModel;
+    rtl::Reference<Model> mxModel;
 
     // this will extract the document from the model that will be submitted
     css::uno::Reference< css::xml::dom::XDocumentFragment >
@@ -96,8 +96,10 @@ public:
 
 
     /// get XForms model
-    css::uno::Reference<css::xforms::XModel>
-        getModel() const { return mxModel;}
+    css::uno::Reference<css::xforms::XModel> getModel() const;
+
+    /// get the model implementation
+    xforms::Model* getModelImpl() const { return mxModel.get(); }
 
     /// set XForms model
     void setModel(
@@ -163,9 +165,6 @@ private:
     /// @throws css::uno::RuntimeException
     void liveCheck();
 
-    /// get the model implementation
-    xforms::Model* getModelImpl() const;
-
 protected:
 
 

Reply via email to