diff --git a/include/vbahelper/vbaapplicationbase.hxx b/include/vbahelper/vbaapplicationbase.hxx index f580fb3402f1..15296aaef050 100644 --- a/include/vbahelper/vbaapplicationbase.hxx +++ b/include/vbahelper/vbaapplicationbase.hxx @@ -47,7 +47,7 @@ protected: virtual ~VbaApplicationBase() override; /// @throws css::uno::RuntimeException - virtual css::uno::Reference< css::frame::XModel > getCurrentDocument() = 0; + virtual css::frame::XModel* getCurrentDocument() = 0; public: // XHelperInterface ( parent is itself ) virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent( ) override { return this; } diff --git a/include/vbahelper/vbadocumentbase.hxx b/include/vbahelper/vbadocumentbase.hxx index f69d6de46b40..09d987bd1a8b 100644 --- a/include/vbahelper/vbadocumentbase.hxx +++ b/include/vbahelper/vbadocumentbase.hxx @@ -47,7 +47,7 @@ class VBAHELPER_DLLPUBLIC VbaDocumentBase : public VbaDocumentBase_BASE protected: css::uno::Reference< css::uno::XInterface > mxVBProject; protected: - virtual css::uno::Reference< css::frame::XModel > getModel() const = 0; + virtual css::frame::XModel* getModel() const = 0; public: VbaDocumentBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ); VbaDocumentBase( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext >const& xContext ); diff --git a/sc/source/core/tool/address.cxx b/sc/source/core/tool/address.cxx index 8e30a93823f7..3e4487facecc 100644 --- a/sc/source/core/tool/address.cxx +++ b/sc/source/core/tool/address.cxx @@ -2036,12 +2036,12 @@ static OUString getFileNameFromDoc( const ScDocument* pDoc ) // TODO : er points at ScGlobal::GetAbsDocName() // as a better template. Look into it OUString sFileName; - SfxObjectShell* pShell; + ScDocShell* pShell; if( nullptr != pDoc && nullptr != (pShell = pDoc->GetDocumentShell() ) ) { - uno::Reference< frame::XModel > xModel = pShell->GetModel(); + rtl::Reference< ScModelObj > xModel = pShell->GetModel(); if( xModel.is() ) { if( !xModel->getURL().isEmpty() ) diff --git a/sc/source/filter/excel/xeroot.cxx b/sc/source/filter/excel/xeroot.cxx index d162b9e419f1..5dbe4c9b38ff 100644 --- a/sc/source/filter/excel/xeroot.cxx +++ b/sc/source/filter/excel/xeroot.cxx @@ -244,14 +244,13 @@ void XclExpRoot::InitializeGlobals() SAL_WARN( "sc", "XclExpRoot::InitializeGlobals - no object shell"); break; } - uno::Reference< lang::XComponent > xComponent = pShell->GetModel(); - if (!xComponent.is()) + rtl::Reference< ScModelObj > xModel = pShell->GetModel(); + if (!xModel.is()) { SAL_WARN( "sc", "XclExpRoot::InitializeGlobals - no component"); break; } - uno::Reference< lang::XMultiServiceFactory > xModelFactory( xComponent, uno::UNO_QUERY); - oox::xls::OpCodeProvider aOpCodeProvider(xModelFactory, false); + oox::xls::OpCodeProvider aOpCodeProvider(xModel, false); // Compiler mocks about non-matching ctor or conversion from // Sequence<...> to Sequence if directly created or passed, // conversion through Any works around. diff --git a/sc/source/filter/xcl97/xcl97esc.cxx b/sc/source/filter/xcl97/xcl97esc.cxx index d6bc672a174a..696595cae826 100644 --- a/sc/source/filter/xcl97/xcl97esc.cxx +++ b/sc/source/filter/xcl97/xcl97esc.cxx @@ -414,7 +414,7 @@ std::unique_ptr XclEscherEx::CreateOCXCtrlObj( Reference< X // writes from xCtrlModel into mxCtlsStrm, raw class name returned in aClassName Reference< XOutputStream > xOut( new utl::OSeekableOutputStreamWrapper( *mxCtlsStrm ) ); - Reference< css::frame::XModel > xModel( GetDocShell() ? GetDocShell()->GetModel() : nullptr ); + rtl::Reference< ScModelObj > xModel( GetDocShell() ? GetDocShell()->GetModel() : nullptr ); if( xModel.is() && xOut.is() && oox::ole::MSConvertOCXControls::WriteOCXExcelKludgeStream( xModel, xOut, xCtrlModel, xShape->getSize(), aClassName ) ) { sal_uInt32 nStrmSize = static_cast< sal_uInt32 >( mxCtlsStrm->Tell() - nStrmStart ); diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx index 56a33bf86840..15d47f96180d 100644 --- a/sc/source/filter/xml/xmlimprt.cxx +++ b/sc/source/filter/xml/xmlimprt.cxx @@ -1687,9 +1687,10 @@ extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportFODS(SvStream &rStream) { ScDLL::Init(); - SfxObjectShellLock xDocSh(new ScDocShell); + rtl::Reference xDocSh(new ScDocShell); + SfxObjectShellLock xLock(xDocSh.get()); xDocSh->DoInitNew(); - uno::Reference xModel(xDocSh->GetModel()); + rtl::Reference xModel(xDocSh->GetModel()); uno::Reference xMultiServiceFactory(comphelper::getProcessServiceFactory()); uno::Reference xStream(new ::utl::OSeekableInputStreamWrapper(rStream)); @@ -1740,9 +1741,10 @@ extern "C" SAL_DLLPUBLIC_EXPORT bool TestFODSExportXLS(SvStream &rStream) { ScDLL::Init(); - SfxObjectShellLock xDocSh(new ScDocShell); + rtl::Reference xDocSh(new ScDocShell); + SfxObjectShellLock xLock(xDocSh.get()); xDocSh->DoInitNew(); - uno::Reference xModel(xDocSh->GetModel()); + rtl::Reference xModel(xDocSh->GetModel()); uno::Reference xMultiServiceFactory(comphelper::getProcessServiceFactory()); uno::Reference xStream(new ::utl::OSeekableInputStreamWrapper(rStream)); @@ -1814,9 +1816,10 @@ extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportXLSX(SvStream &rStream) { ScDLL::Init(); - SfxObjectShellLock xDocSh(new ScDocShell); + rtl::Reference xDocSh(new ScDocShell); + SfxObjectShellLock xLock(xDocSh.get()); xDocSh->DoInitNew(); - uno::Reference xModel(xDocSh->GetModel()); + rtl::Reference xModel(xDocSh->GetModel()); uno::Reference xMultiServiceFactory(comphelper::getProcessServiceFactory()); uno::Reference xStream(new utl::OSeekableInputStreamWrapper(rStream)); diff --git a/sc/source/filter/xml/xmlwrap.cxx b/sc/source/filter/xml/xmlwrap.cxx index e7c2f7fbd4d7..d0f36de5eca0 100644 --- a/sc/source/filter/xml/xmlwrap.cxx +++ b/sc/source/filter/xml/xmlwrap.cxx @@ -290,7 +290,7 @@ bool ScXMLImportWrapper::Import( ImportFlags nMode, ErrCodeMsg& rError ) xStorage = pMedium->GetStorage(); // get filter - uno::Reference xModel = mrDocShell.GetModel(); + rtl::Reference xModel = mrDocShell.GetModel(); /** property map for export info set */ static comphelper::PropertyMapEntry const aImportInfoMap[] = @@ -318,10 +318,9 @@ bool ScXMLImportWrapper::Import( ImportFlags nMode, ErrCodeMsg& rError ) // ---- get BuildId from parent container if available - uno::Reference< container::XChild > xChild( xModel, uno::UNO_QUERY ); - if( xChild.is() ) + if( xModel.is() ) { - uno::Reference< beans::XPropertySet > xParentSet( xChild->getParent(), uno::UNO_QUERY ); + uno::Reference< beans::XPropertySet > xParentSet( xModel->getParent(), uno::UNO_QUERY ); if( xParentSet.is() ) { uno::Reference< beans::XPropertySetInfo > xPropSetInfo( xParentSet->getPropertySetInfo() ); @@ -382,13 +381,11 @@ bool ScXMLImportWrapper::Import( ImportFlags nMode, ErrCodeMsg& rError ) // RDF metadata: ODF >= 1.2 try { - const uno::Reference< rdf::XDocumentMetadataAccess > xDMA( - xModel, uno::UNO_QUERY_THROW ); const uno::Reference< rdf::XURI > xBaseURI( ::sfx2::createBaseURI( xContext, xModel, aBaseURL, aName ) ); uno::Reference xHandler = mrDocShell.GetMedium()->GetInteractionHandler(); - xDMA->loadMetadataFromStorage( xStorage, xBaseURI, xHandler ); + xModel->loadMetadataFromStorage( xStorage, xBaseURI, xHandler ); } catch ( const lang::WrappedTargetException & e) { @@ -534,19 +531,18 @@ bool ScXMLImportWrapper::Import( ImportFlags nMode, ErrCodeMsg& rError ) bool bRet = !rError.IsError(); - ::svx::DropUnusedNamedItems(xModel); + ::svx::DropUnusedNamedItems(cppu::getXWeak(xModel.get())); // set BuildId on XModel for later OLE object loading if( xInfoSet.is() ) { - uno::Reference< beans::XPropertySet > xModelSet( xModel, uno::UNO_QUERY ); - if( xModelSet.is() ) + if( xModel.is() ) { - uno::Reference< beans::XPropertySetInfo > xModelSetInfo( xModelSet->getPropertySetInfo() ); + uno::Reference< beans::XPropertySetInfo > xModelSetInfo( xModel->getPropertySetInfo() ); OUString sBuildPropName(u"BuildId"_ustr ); if( xModelSetInfo.is() && xModelSetInfo->hasPropertyByName(sBuildPropName) ) { - xModelSet->setPropertyValue( sBuildPropName, xInfoSet->getPropertyValue(sBuildPropName) ); + xModel->setPropertyValue( sBuildPropName, xInfoSet->getPropertyValue(sBuildPropName) ); } } @@ -563,9 +559,9 @@ bool ScXMLImportWrapper::Import( ImportFlags nMode, ErrCodeMsg& rError ) /* Set library container to VBA compatibility mode, this forces loading the Basic project, which in turn creates the VBA Globals object and does all related initialization. */ - if ( xModelSet.is() ) try + if ( xModel.is() ) try { - uno::Reference< script::vba::XVBACompatibility > xVBACompat( xModelSet->getPropertyValue( + uno::Reference< script::vba::XVBACompatibility > xVBACompat( xModel->getPropertyValue( u"BasicLibraries"_ustr ), uno::UNO_QUERY_THROW ); xVBACompat->setVBACompatibilityMode( true ); } @@ -763,11 +759,10 @@ bool ScXMLImportWrapper::Export(bool bStylesOnly) if ( pObjSh && xStorage.is() ) { - uno::Reference xModel(pObjSh->GetModel()); + rtl::Reference xModel(pObjSh->GetModel()); // sorting wants to create undo actions assert(SfxObjectCreateMode::STANDARD != pObjSh->GetCreateMode() || rDoc.GetDrawLayer()->IsUndoEnabled()); - uno::Reference const xDPS(xModel, uno::UNO_QUERY); - uno::Reference const xDPs(xDPS->getDrawPages()); + uno::Reference const xDPs(xModel->getDrawPages()); assert(xDPs.is()); for (auto i = xDPs->getCount(); 0 < i; ) { @@ -852,9 +847,7 @@ bool ScXMLImportWrapper::Export(bool bStylesOnly) && aVersion != ODFVER_010_TEXT && aVersion != ODFVER_011_TEXT ) { - const uno::Reference< rdf::XDocumentMetadataAccess > xDMA( - xModel, uno::UNO_QUERY_THROW ); - xDMA->storeMetadataToStorage( xStorage ); + xModel->storeMetadataToStorage( xStorage ); } } catch ( const beans::UnknownPropertyException &) diff --git a/sc/source/ui/vba/vbaapplication.cxx b/sc/source/ui/vba/vbaapplication.cxx index 914f6aaab16e..e108dda59182 100644 --- a/sc/source/ui/vba/vbaapplication.cxx +++ b/sc/source/ui/vba/vbaapplication.cxx @@ -256,7 +256,7 @@ ScVbaApplication::hasProperty( const OUString& Name ) uno::Reference< excel::XWorkbook > ScVbaApplication::getActiveWorkbook() { - uno::Reference< frame::XModel > xModel( getCurrentExcelDoc( mxContext ), uno::UNO_SET_THROW ); + rtl::Reference< ScModelObj > xModel( dynamic_cast(getCurrentExcelDoc( mxContext ).get()) ); uno::Reference< excel::XWorkbook > xWorkbook( getVBADocument( xModel ), uno::UNO_QUERY ); if( xWorkbook.is() ) return xWorkbook; // #i116936# getVBADocument() may return null in documents without global VBA mode enabled @@ -266,7 +266,7 @@ ScVbaApplication::getActiveWorkbook() uno::Reference< excel::XWorkbook > SAL_CALL ScVbaApplication::getThisWorkbook() { - uno::Reference< frame::XModel > xModel( getThisExcelDoc( mxContext ), uno::UNO_SET_THROW ); + rtl::Reference< ScModelObj > xModel( dynamic_cast(getThisExcelDoc( mxContext ).get()) ); uno::Reference< excel::XWorkbook > xWorkbook( getVBADocument( xModel ), uno::UNO_QUERY ); if( xWorkbook.is() ) return xWorkbook; // #i116936# getVBADocument() may return null in documents without global VBA mode enabled @@ -481,7 +481,7 @@ ScVbaApplication::Dialogs( const uno::Any &aIndex ) uno::Reference< excel::XWindow > SAL_CALL ScVbaApplication::getActiveWindow() { - uno::Reference< frame::XModel > xModel = getCurrentDocument(); + rtl::Reference< ScModelObj > xModel = getCurrentDocument(); uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW ); uno::Reference< XHelperInterface > xParent( getActiveWorkbook(), uno::UNO_QUERY_THROW ); uno::Reference< excel::XWindow > xWin( new ScVbaWindow( xParent, mxContext, xModel, xController ) ); @@ -551,7 +551,7 @@ ScVbaApplication::setStatusBar( const uno::Any& _statusbar ) ScVbaApplication::getCalculation() { // TODO: in Excel, this is an application-wide setting - uno::Reference xCalc(getCurrentDocument(), uno::UNO_QUERY_THROW); + rtl::Reference xCalc(getCurrentDocument()); if(xCalc->isAutomaticCalculationEnabled()) return excel::XlCalculation::xlCalculationAutomatic; else @@ -562,7 +562,7 @@ void SAL_CALL ScVbaApplication::setCalculation( ::sal_Int32 _calculation ) { // TODO: in Excel, this is an application-wide setting - uno::Reference< sheet::XCalculatable > xCalc(getCurrentDocument(), uno::UNO_QUERY_THROW); + rtl::Reference< ScModelObj > xCalc(getCurrentDocument()); switch(_calculation) { case excel::XlCalculation::xlCalculationManual: @@ -978,9 +978,8 @@ ScVbaApplication::setIteration( sal_Bool bSet ) void SAL_CALL ScVbaApplication::Calculate() { - uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_SET_THROW ); - uno::Reference< sheet::XCalculatable > xCalculatable( getCurrentDocument(), uno::UNO_QUERY_THROW ); - xCalculatable->calculateAll(); + rtl::Reference< ScModelObj > xModel( getCurrentDocument() ); + xModel->calculateAll(); } /// @throws uno::RuntimeException @@ -1429,10 +1428,10 @@ ScVbaApplication::Caller( const uno::Any& /*aIndex*/ ) return aRet; } -uno::Reference< frame::XModel > +ScModelObj* ScVbaApplication::getCurrentDocument() { - return getCurrentExcelDoc(mxContext); + return dynamic_cast(getCurrentExcelDoc(mxContext).get()); } uno::Any SAL_CALL diff --git a/sc/source/ui/vba/vbaapplication.hxx b/sc/source/ui/vba/vbaapplication.hxx index e2bbc49cf60c..05e2501f6c08 100644 --- a/sc/source/ui/vba/vbaapplication.hxx +++ b/sc/source/ui/vba/vbaapplication.hxx @@ -26,6 +26,7 @@ #include #include #include +#include namespace com::sun::star::uno { class XComponentContext; } namespace ooo::vba { class XSink; } @@ -53,7 +54,7 @@ private: comphelper::InvocationHelper m_aInvocationHelper; protected: - virtual css::uno::Reference< css::frame::XModel > getCurrentDocument() override; + virtual ScModelObj* getCurrentDocument() override; public: explicit ScVbaApplication( const css::uno::Reference< css::uno::XComponentContext >& m_xContext ); diff --git a/sc/source/ui/vba/vbaformat.cxx b/sc/source/ui/vba/vbaformat.cxx index a866b7c6105e..20b442857490 100644 --- a/sc/source/ui/vba/vbaformat.cxx +++ b/sc/source/ui/vba/vbaformat.cxx @@ -61,12 +61,12 @@ template< typename... Ifc > ScVbaFormat< Ifc... >::ScVbaFormat( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, uno::Reference< beans::XPropertySet > _xPropertySet, - uno::Reference< frame::XModel > xModel, + const rtl::Reference< ScModelObj >& xModel, bool bCheckAmbiguoity ) : ScVbaFormat_BASE( xParent, xContext ), m_aDefaultLocale( u"en"_ustr, u"US"_ustr, OUString() ), mxPropertySet(std::move( _xPropertySet )), - mxModel(std::move( xModel )), + mxModel( xModel ), mbCheckAmbiguoity( bCheckAmbiguoity ), mbAddIndent( false ) { @@ -773,7 +773,7 @@ ScVbaFormat< Ifc... >::initializeNumberFormats() { if ( !xNumberFormats.is() ) { - mxNumberFormatsSupplier.set( mxModel, uno::UNO_QUERY_THROW ); + mxNumberFormatsSupplier.set( cppu::getXWeak(mxModel.get()), uno::UNO_QUERY_THROW ); xNumberFormats = mxNumberFormatsSupplier->getNumberFormats(); xNumberFormatTypes.set( xNumberFormats, uno::UNO_QUERY ); // _THROW? } diff --git a/sc/source/ui/vba/vbaformat.hxx b/sc/source/ui/vba/vbaformat.hxx index a85818ddd214..696e01286580 100644 --- a/sc/source/ui/vba/vbaformat.hxx +++ b/sc/source/ui/vba/vbaformat.hxx @@ -20,6 +20,7 @@ #include #include +#include namespace com::sun::star::beans { class XPropertySet; } namespace com::sun::star::beans { class XPropertyState; } @@ -31,6 +32,7 @@ namespace ooo::vba::excel { class XFont; } namespace ooo::vba::excel { class XInterior; } class ScCellRangesBase; +class ScModelObj; class SfxItemSet; template< typename... Ifc > @@ -43,7 +45,7 @@ protected: css::uno::Reference< css::util::XNumberFormatsSupplier > mxNumberFormatsSupplier; css::uno::Reference< css::util::XNumberFormats > xNumberFormats; css::uno::Reference< css::util::XNumberFormatTypes > xNumberFormatTypes; - css::uno::Reference< css::frame::XModel > mxModel; + rtl::Reference< ScModelObj > mxModel; css::uno::Reference< css::beans::XPropertyState > xPropertyState; bool mbCheckAmbiguoity; bool mbAddIndent; @@ -61,7 +63,7 @@ protected: virtual ScCellRangesBase* getCellRangesBase(); public: /// @throws css::script::BasicErrorException - ScVbaFormat( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, css::uno::Reference< css::beans::XPropertySet > _xPropertySet, css::uno::Reference< css::frame::XModel > xModel, bool bCheckAmbiguoity ); + ScVbaFormat( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, css::uno::Reference< css::beans::XPropertySet > _xPropertySet, const rtl::Reference& xModel, bool bCheckAmbiguoity ); virtual css::uno::Reference< ov::XHelperInterface > thisHelperIface() = 0; /// @throws css::uno::RuntimeException void SAL_CALL setAddIndent( const css::uno::Any& BAddIndent) { BAddIndent >>= mbAddIndent; } diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index 77ccc0129e87..1aedfe261fad 100644 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -388,14 +388,14 @@ getDocShellFromRanges( const uno::Reference< sheet::XSheetCellRangeContainer >& } /// @throws uno::RuntimeException -static uno::Reference< frame::XModel > getModelFromXIf( const uno::Reference< uno::XInterface >& xIf ) +static rtl::Reference< ScModelObj > getModelFromXIf( const uno::Reference< uno::XInterface >& xIf ) { ScDocShell* pDocShell = getDocShellFromIf(xIf ); return pDocShell->GetModel(); } /// @throws uno::RuntimeException -static uno::Reference< frame::XModel > getModelFromRange( const uno::Reference< table::XCellRange >& xRange ) +static rtl::Reference< ScModelObj > getModelFromRange( const uno::Reference< table::XCellRange >& xRange ) { // the XInterface for getImplementation can be any derived interface, no need for queryInterface uno::Reference< uno::XInterface > xIf( xRange ); @@ -480,7 +480,7 @@ class NumFormatHelper public: explicit NumFormatHelper( const uno::Reference< table::XCellRange >& xRange ) { - mxSupplier.set( getModelFromRange( xRange ), uno::UNO_QUERY_THROW ); + mxSupplier.set( cppu::getXWeak(getModelFromRange( xRange ).get()), uno::UNO_QUERY_THROW ); mxRangeProps.set( xRange, uno::UNO_QUERY_THROW); mxFormats = mxSupplier->getNumberFormats(); } @@ -1418,7 +1418,14 @@ lcl_setupBorders( const uno::Reference< excel::XRange >& xParentRange, const uno } ScVbaRange::ScVbaRange( uno::Sequence< uno::Any> const & args, - uno::Reference< uno::XComponentContext> const & xContext ) : ScVbaRange_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext, getXSomethingFromArgs< beans::XPropertySet >( args, 1, false ), getModelFromXIf( getXSomethingFromArgs< uno::XInterface >( args, 1 ) ), true ), mbIsRows( false ), mbIsColumns( false ) + uno::Reference< uno::XComponentContext> const & xContext ) + : ScVbaRange_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), + xContext, + getXSomethingFromArgs< beans::XPropertySet >( args, 1, false ), + getModelFromXIf( getXSomethingFromArgs< uno::XInterface >( args, 1 ) ), + true ), + mbIsRows( false ), + mbIsColumns( false ) { mxRange.set( mxPropertySet, uno::UNO_QUERY ); mxRanges.set( mxPropertySet, uno::UNO_QUERY ); @@ -5374,8 +5381,8 @@ ScVbaRange::getStyle() OUString sStyleName; xProps->getPropertyValue( CELLSTYLE ) >>= sStyleName; ScDocShell* pShell = getScDocShell(); - uno::Reference< frame::XModel > xModel( pShell->GetModel() ); - uno::Reference< excel::XStyle > xStyle = new ScVbaStyle( this, mxContext, sStyleName, xModel ); + ScModelObj* pModel( pShell->GetModel() ); + uno::Reference< excel::XStyle > xStyle = new ScVbaStyle( this, mxContext, sStyleName, pModel ); return uno::Any( xStyle ); } void SAL_CALL diff --git a/sc/source/ui/vba/vbastyle.cxx b/sc/source/ui/vba/vbastyle.cxx index 86eedeac344d..92e435e63a73 100644 --- a/sc/source/ui/vba/vbastyle.cxx +++ b/sc/source/ui/vba/vbastyle.cxx @@ -21,6 +21,7 @@ #include #include #include +#include using namespace ::ooo::vba; using namespace ::com::sun::star; @@ -28,17 +29,18 @@ using namespace ::com::sun::star; constexpr OUString DISPLAYNAME = u"DisplayName"_ustr; uno::Reference< container::XNameAccess > -ScVbaStyle::getStylesNameContainer( const uno::Reference< frame::XModel >& xModel ) +ScVbaStyle::getStylesNameContainer( const rtl::Reference& xModel ) { - uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( xModel, uno::UNO_QUERY_THROW); - uno::Reference< container::XNameAccess > xStylesAccess( xStyleSupplier->getStyleFamilies()->getByName(u"CellStyles"_ustr), uno::UNO_QUERY_THROW ); + if (!xModel) + throw uno::RuntimeException(); + uno::Reference< container::XNameAccess > xStylesAccess( xModel->getStyleFamilies()->getByName(u"CellStyles"_ustr), uno::UNO_QUERY_THROW ); return xStylesAccess; } /// @throws script::BasicErrorException /// @throws uno::RuntimeException static uno::Reference< beans::XPropertySet > -lcl_getStyleProps( const OUString& sStyleName, const uno::Reference< frame::XModel >& xModel ) +lcl_getStyleProps( const OUString& sStyleName, const rtl::Reference& xModel ) { uno::Reference< beans::XPropertySet > xStyleProps( ScVbaStyle::getStylesNameContainer( xModel )->getByName( sStyleName ), uno::UNO_QUERY_THROW ); @@ -56,14 +58,12 @@ void ScVbaStyle::initialise() } mxStyle.set( mxPropertySet, uno::UNO_QUERY_THROW ); - uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( mxModel, uno::UNO_QUERY_THROW ); mxStyleFamilyNameContainer.set( ScVbaStyle::getStylesNameContainer( mxModel ), uno::UNO_QUERY_THROW ); - } ScVbaStyle::ScVbaStyle( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, - const OUString& sStyleName, const uno::Reference< frame::XModel >& _xModel ) + const OUString& sStyleName, const rtl::Reference& _xModel ) : ScVbaStyle_BASE( xParent, xContext, lcl_getStyleProps( sStyleName, _xModel ), _xModel, false ) { try @@ -79,7 +79,7 @@ ScVbaStyle::ScVbaStyle( const uno::Reference< ov::XHelperInterface >& xParent, ScVbaStyle::ScVbaStyle( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< beans::XPropertySet >& _xPropertySet, - const uno::Reference< frame::XModel >& _xModel ) + const rtl::Reference& _xModel ) : ScVbaStyle_BASE( xParent, xContext, _xPropertySet, _xModel, false ) { try diff --git a/sc/source/ui/vba/vbastyle.hxx b/sc/source/ui/vba/vbastyle.hxx index cc002ce6ff64..df565e75fc18 100644 --- a/sc/source/ui/vba/vbastyle.hxx +++ b/sc/source/ui/vba/vbastyle.hxx @@ -25,6 +25,8 @@ #include #include "vbaformat.hxx" +class ScModelObj; + typedef ScVbaFormat< ov::excel::XStyle > ScVbaStyle_BASE; class ScVbaStyle final : public ScVbaStyle_BASE @@ -37,12 +39,12 @@ class ScVbaStyle final : public ScVbaStyle_BASE public: /// @throws css::script::BasicErrorException /// @throws css::uno::RuntimeException - ScVbaStyle( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const OUString& sStyleName, const css::uno::Reference< css::frame::XModel >& _xModel ); + ScVbaStyle( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const OUString& sStyleName, const rtl::Reference& _xModel ); /// @throws css::script::BasicErrorException /// @throws css::uno::RuntimeException - ScVbaStyle( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::beans::XPropertySet >& _xPropertySet, const css::uno::Reference< css::frame::XModel >& _xModel ); + ScVbaStyle( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::beans::XPropertySet >& _xPropertySet, const rtl::Reference& _cModel ); /// @throws css::uno::RuntimeException - static css::uno::Reference< css::container::XNameAccess > getStylesNameContainer( const css::uno::Reference< css::frame::XModel >& xModel ); + static css::uno::Reference< css::container::XNameAccess > getStylesNameContainer( const rtl::Reference& xModel ); virtual css::uno::Reference< ov::XHelperInterface > thisHelperIface() override { return this; }; // XStyle Methods virtual sal_Bool SAL_CALL BuiltIn() override; diff --git a/sc/source/ui/vba/vbastyles.cxx b/sc/source/ui/vba/vbastyles.cxx index 8e1aa8cb2ca4..829f420e767d 100644 --- a/sc/source/ui/vba/vbastyles.cxx +++ b/sc/source/ui/vba/vbastyles.cxx @@ -24,12 +24,13 @@ #include #include #include +#include using namespace ::ooo::vba; using namespace ::com::sun::star; static css::uno::Any -lcl_createAPIStyleToVBAObject( const css::uno::Any& aObject, const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) +lcl_createAPIStyleToVBAObject( const css::uno::Any& aObject, const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const rtl::Reference& xModel ) { uno::Reference< beans::XPropertySet > xStyleProps( aObject, uno::UNO_QUERY_THROW ); uno::Reference< excel::XStyle > xStyle( new ScVbaStyle( xParent, xContext, xStyleProps, xModel ) ); @@ -38,15 +39,15 @@ lcl_createAPIStyleToVBAObject( const css::uno::Any& aObject, const uno::Referenc ScVbaStyles::ScVbaStyles( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< css::uno::XComponentContext > & xContext, - const uno::Reference< frame::XModel >& xModel ) + ScModelObj* pModel ) : ScVbaStyles_BASE( xParent, xContext, - uno::Reference< container::XIndexAccess >( ScVbaStyle::getStylesNameContainer( xModel ), uno::UNO_QUERY_THROW ) ), - mxModel( xModel ) + uno::Reference< container::XIndexAccess >( ScVbaStyle::getStylesNameContainer( pModel ), uno::UNO_QUERY_THROW ) ), + mxModel( pModel ) { try { - mxMSF.set( mxModel, uno::UNO_QUERY_THROW ); + mxMSF = mxModel; mxNameContainerCellStyles.set( m_xNameAccess, uno::UNO_QUERY_THROW ); } catch (uno::Exception& ) @@ -80,11 +81,11 @@ class EnumWrapper : public EnumerationHelper_BASE uno::Reference m_xIndexAccess; uno::Reference m_xParent; uno::Reference m_xContext; - uno::Reference m_xModel; + rtl::Reference m_xModel; sal_Int32 nIndex; public: - EnumWrapper( uno::Reference< container::XIndexAccess > xIndexAccess, uno::Reference xParent, uno::Reference xContext, uno::Reference xModel ) : m_xIndexAccess(std::move( xIndexAccess )), m_xParent(std::move( xParent )), m_xContext(std::move( xContext )), m_xModel(std::move( xModel )), nIndex( 0 ) {} + EnumWrapper( uno::Reference< container::XIndexAccess > xIndexAccess, uno::Reference xParent, uno::Reference xContext, rtl::Reference xModel ) : m_xIndexAccess(std::move( xIndexAccess )), m_xParent(std::move( xParent )), m_xContext(std::move( xContext )), m_xModel(std::move( xModel )), nIndex( 0 ) {} virtual sal_Bool SAL_CALL hasMoreElements( ) override { return ( nIndex < m_xIndexAccess->getCount() ); diff --git a/sc/source/ui/vba/vbastyles.hxx b/sc/source/ui/vba/vbastyles.hxx index 78990bca969c..fad786e948c4 100644 --- a/sc/source/ui/vba/vbastyles.hxx +++ b/sc/source/ui/vba/vbastyles.hxx @@ -19,19 +19,21 @@ #pragma once #include #include +#include namespace com::sun::star::lang { class XMultiServiceFactory; } namespace com::sun::star::container { class XNameContainer; } +class ScModelObj; typedef CollTestImplHelper< ov::excel::XStyles > ScVbaStyles_BASE; class ScVbaStyles: public ScVbaStyles_BASE { - css::uno::Reference< css::frame::XModel > mxModel; + rtl::Reference< ScModelObj > mxModel; css::uno::Reference< css::lang::XMultiServiceFactory > mxMSF; css::uno::Reference< css::container::XNameContainer > mxNameContainerCellStyles; public: /// @throws css::script::BasicErrorException - ScVbaStyles( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::frame::XModel >& xModel ); + ScVbaStyles( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, ScModelObj* pModel ); /// @throws css::uno::RuntimeException css::uno::Sequence< OUString > getStyleNames(); /// @throws css::script::BasicErrorException diff --git a/sc/source/ui/vba/vbawindow.cxx b/sc/source/ui/vba/vbawindow.cxx index c9847e6d523d..4ee3a1cc5949 100644 --- a/sc/source/ui/vba/vbawindow.cxx +++ b/sc/source/ui/vba/vbawindow.cxx @@ -190,7 +190,7 @@ public: ScVbaWindow::ScVbaWindow( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, - const uno::Reference< frame::XModel >& xModel, + const rtl::Reference< ScModelObj >& xModel, const uno::Reference< frame::XController >& xController ) : WindowImpl_BASE( xParent, xContext, xController ), m_xModel(xModel) @@ -202,7 +202,7 @@ ScVbaWindow::ScVbaWindow( const uno::Sequence< uno::Any >& args, const uno::Reference< uno::XComponentContext >& xContext ) : WindowImpl_BASE( args, xContext ), - m_xModel(getXSomethingFromArgs< frame::XModel >( args, 1, false )) + m_xModel(dynamic_cast(getXSomethingFromArgs< frame::XModel >( args, 1, false ).get())) { init(); } @@ -729,7 +729,7 @@ void SAL_CALL ScVbaWindow::setZoom(const uno::Any& _zoom) { sal_Int16 nZoom = 100; _zoom >>= nZoom; - uno::Reference xSpreadDoc( m_xModel, uno::UNO_QUERY_THROW ); + uno::Reference xSpreadDoc( m_xModel ); uno::Reference< excel::XWorksheet > xActiveSheet = ActiveSheet(); SCTAB nTab = 0; if ( !ScVbaWorksheets::nameExists (xSpreadDoc, xActiveSheet->getName(), nTab) ) diff --git a/sc/source/ui/vba/vbawindow.hxx b/sc/source/ui/vba/vbawindow.hxx index bb84719a6be3..0a6e0cf1b205 100644 --- a/sc/source/ui/vba/vbawindow.hxx +++ b/sc/source/ui/vba/vbawindow.hxx @@ -27,12 +27,14 @@ #include +class ScModelObj; + typedef cppu::ImplInheritanceHelper< VbaWindowBase, ov::excel::XWindow > WindowImpl_BASE; class ScVbaWindow : public WindowImpl_BASE { private: - css::uno::Reference m_xModel; + rtl::Reference m_xModel; css::uno::Reference< ov::excel::XPane > m_xPane; void init(); @@ -55,7 +57,7 @@ public: ScVbaWindow( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, - const css::uno::Reference< css::frame::XModel >& xModel, + const rtl::Reference< ScModelObj >& xModel, const css::uno::Reference< css::frame::XController >& xController ); /// @throws css::uno::RuntimeException ScVbaWindow( diff --git a/sc/source/ui/vba/vbawindows.cxx b/sc/source/ui/vba/vbawindows.cxx index 4b36116c6c4e..9807be7ce626 100644 --- a/sc/source/ui/vba/vbawindows.cxx +++ b/sc/source/ui/vba/vbawindows.cxx @@ -41,7 +41,7 @@ using namespace ::ooo::vba; typedef std::unordered_map< OUString, sal_Int32 > NameIndexHash; -static uno::Reference< XHelperInterface > lcl_createWorkbookHIParent( const uno::Reference< frame::XModel >& xModel, const uno::Reference< uno::XComponentContext >& xContext, const uno::Any& aApplication ) +static uno::Reference< XHelperInterface > lcl_createWorkbookHIParent( const rtl::Reference< ScModelObj >& xModel, const uno::Reference< uno::XComponentContext >& xContext, const uno::Any& aApplication ) { return new ScVbaWorkbook( uno::Reference< XHelperInterface >( aApplication, uno::UNO_QUERY_THROW ), xContext, xModel ); } @@ -49,9 +49,10 @@ static uno::Reference< XHelperInterface > lcl_createWorkbookHIParent( const uno: static uno::Any ComponentToWindow( const uno::Any& aSource, const uno::Reference< uno::XComponentContext > & xContext, const uno::Any& aApplication ) { uno::Reference< frame::XModel > xModel( aSource, uno::UNO_QUERY_THROW ); + ScModelObj* pModel = dynamic_cast(xModel.get()); // !! TODO !! iterate over all controllers - uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW ); - uno::Reference< excel::XWindow > xWin( new ScVbaWindow( lcl_createWorkbookHIParent( xModel, xContext, aApplication ), xContext, xModel, xController ) ); + uno::Reference< frame::XController > xController( pModel->getCurrentController(), uno::UNO_SET_THROW ); + uno::Reference< excel::XWindow > xWin( new ScVbaWindow( lcl_createWorkbookHIParent( pModel, xContext, aApplication ), xContext, pModel, xController ) ); return uno::Any( xWin ); } @@ -144,7 +145,10 @@ public: if ( xNext.is() ) { m_windows.push_back( xNext ); - uno::Reference< frame::XModel > xModel( xNext, uno::UNO_QUERY_THROW ); // that the spreadsheetdocument is a xmodel is a given + // that the spreadsheetdocument is a xmodel is a given + rtl::Reference xModel = dynamic_cast(xNext.get()); + if (!xModel) + throw uno::RuntimeException(); // tdf#126457 - add workbook name to window titles rtl::Reference workbook(new ScVbaWorkbook( diff --git a/sc/source/ui/vba/vbaworkbook.cxx b/sc/source/ui/vba/vbaworkbook.cxx index 7abf25406248..8c58603e00d7 100644 --- a/sc/source/ui/vba/vbaworkbook.cxx +++ b/sc/source/ui/vba/vbaworkbook.cxx @@ -190,7 +190,7 @@ ScVbaWorkbook::init() ScVbaWorkbook::ScVbaWorkbook( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, - css::uno::Reference< css::frame::XModel > const & xModel ) + rtl::Reference< ScModelObj > const & xModel ) : ScVbaWorkbook_BASE( xParent, xContext ), mxModel(xModel) { @@ -200,7 +200,7 @@ ScVbaWorkbook::ScVbaWorkbook( const css::uno::Reference< ov::XHelperInterface >& ScVbaWorkbook::ScVbaWorkbook( uno::Sequence< uno::Any> const & args, uno::Reference< uno::XComponentContext> const & xContext ) : ScVbaWorkbook_BASE( args, xContext ), - mxModel(getXSomethingFromArgs< frame::XModel >( args, 1 )) + mxModel(dynamic_cast(getXSomethingFromArgs< frame::XModel >( args, 1 ).get())) { init(); } @@ -263,8 +263,7 @@ ScVbaWorkbook::Protect( const uno::Any &aPassword ) sal_Bool ScVbaWorkbook::getProtectStructure() { - uno::Reference< util::XProtectable > xProt( getModel(), uno::UNO_QUERY_THROW ); - return xProt->isProtected(); + return getModel()->isProtected(); } sal_Bool SAL_CALL ScVbaWorkbook::getPrecisionAsDisplayed() @@ -290,7 +289,7 @@ void SAL_CALL ScVbaWorkbook::setPrecisionAsDisplayed( sal_Bool _precisionAsDispl OUString SAL_CALL ScVbaWorkbook::getAuthor() { - uno::Reference xDPS( getModel(), uno::UNO_QUERY ); + rtl::Reference xDPS( getModel() ); if (!xDPS.is()) return u"?"_ustr; uno::Reference xDocProps = xDPS->getDocumentProperties(); @@ -299,7 +298,7 @@ OUString SAL_CALL ScVbaWorkbook::getAuthor() void SAL_CALL ScVbaWorkbook::setAuthor( const OUString& _author ) { - uno::Reference xDPS( getModel(), uno::UNO_QUERY ); + rtl::Reference xDPS( getModel() ); if (!xDPS.is()) return; uno::Reference xDocProps = xDPS->getDocumentProperties(); @@ -311,7 +310,7 @@ ScVbaWorkbook::SaveCopyAs( const OUString& sFileName ) { OUString aURL; osl::FileBase::getFileURLFromSystemPath( sFileName, aURL ); - uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW ); + rtl::Reference< ScModelObj > xStor( getModel() ); uno::Sequence< beans::PropertyValue > storeProps{ comphelper::makePropertyValue( u"FilterName"_ustr, SC_XL97_FILTER_NAME) }; xStor->storeToURL( aURL, storeProps ); @@ -358,7 +357,7 @@ ScVbaWorkbook::SaveAs( const uno::Any& FileName, const uno::Any& FileFormat, con uno::Sequence storeProps{ comphelper::makePropertyValue(u"FilterName"_ustr, uno::Any()) }; setFilterPropsFromFormat( nFileFormat, storeProps ); - uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW ); + rtl::Reference< ScModelObj > xStor( getModel() ); xStor->storeAsURL( sURL, storeProps ); } @@ -417,7 +416,7 @@ ScVbaWorkbook::getServiceNames() OUString SAL_CALL ScVbaWorkbook::getCodeName() { - uno::Reference< beans::XPropertySet > xModelProp( getModel(), uno::UNO_QUERY_THROW ); + rtl::Reference< ScModelObj > xModelProp( getModel() ); return xModelProp->getPropertyValue(u"CodeName"_ustr).get< OUString >(); } diff --git a/sc/source/ui/vba/vbaworkbook.hxx b/sc/source/ui/vba/vbaworkbook.hxx index d6ee4b016779..af0dddc523b8 100644 --- a/sc/source/ui/vba/vbaworkbook.hxx +++ b/sc/source/ui/vba/vbaworkbook.hxx @@ -22,6 +22,7 @@ #include #include #include +#include typedef cppu::ImplInheritanceHelper< VbaDocumentBase, ov::excel::XWorkbook > ScVbaWorkbook_BASE; @@ -31,14 +32,14 @@ class ScVbaWorkbook : public ScVbaWorkbook_BASE static bool setFilterPropsFromFormat( sal_Int32 nFormat, css::uno::Sequence< css::beans::PropertyValue >& rProps ); void init(); - css::uno::Reference< css::frame::XModel > mxModel; + rtl::Reference< ScModelObj > mxModel; protected: - virtual css::uno::Reference< css::frame::XModel > getModel() const override { return mxModel; } + virtual ScModelObj* getModel() const override { return mxModel.get(); } public: ScVbaWorkbook( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, - css::uno::Reference< css::frame::XModel > const & xModel ); + rtl::Reference< ScModelObj > const & xModel ); ScVbaWorkbook( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext >const& xContext ); // Attributes diff --git a/sc/source/ui/vba/vbaworkbooks.cxx b/sc/source/ui/vba/vbaworkbooks.cxx index 468124764bdf..d1982e70d885 100644 --- a/sc/source/ui/vba/vbaworkbooks.cxx +++ b/sc/source/ui/vba/vbaworkbooks.cxx @@ -42,11 +42,10 @@ const sal_Int16 CUSTOM_CHAR = 5; static uno::Any getWorkbook( const uno::Reference< uno::XComponentContext >& xContext, - const uno::Reference< sheet::XSpreadsheetDocument > &xDoc, + const rtl::Reference< ScModelObj > &xModel, const uno::Reference< XHelperInterface >& xParent ) { // FIXME: fine as long as ScVbaWorkbook is stateless ... - uno::Reference< frame::XModel > xModel( xDoc, uno::UNO_QUERY ); if( !xModel.is() ) return uno::Any(); @@ -71,7 +70,7 @@ public: virtual uno::Any SAL_CALL nextElement( ) override { uno::Reference< sheet::XSpreadsheetDocument > xDoc( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW ); - return getWorkbook( m_xContext, xDoc, m_xParent ); + return getWorkbook( m_xContext, static_cast(xDoc.get()), m_xParent ); } }; @@ -102,7 +101,7 @@ uno::Any ScVbaWorkbooks::createCollectionObject( const css::uno::Any& aSource ) { uno::Reference< sheet::XSpreadsheetDocument > xDoc( aSource, uno::UNO_QUERY_THROW ); - return getWorkbook( mxContext, xDoc, mxParent ); + return getWorkbook( mxContext, dynamic_cast(xDoc.get()), mxParent ); } uno::Any SAL_CALL @@ -147,7 +146,7 @@ ScVbaWorkbooks::Add( const uno::Any& Template ) if (!xSpreadDoc.is()) return uno::Any(); - uno::Any aRet = getWorkbook( mxContext, xSpreadDoc, mxParent ); + uno::Any aRet = getWorkbook( mxContext, dynamic_cast(xSpreadDoc.get()), mxParent ); uno::Reference< excel::XWorkbook > xWBook( aRet, uno::UNO_QUERY ); if (xWBook.is()) xWBook->Activate(); @@ -266,7 +265,7 @@ ScVbaWorkbooks::Open( const OUString& rFileName, const uno::Any& /*UpdateLinks*/ throw uno::RuntimeException(u"Bad Format"_ustr ); uno::Reference xSpreadDoc( openDocument( rFileName, ReadOnly, sProps ), uno::UNO_QUERY_THROW ); - uno::Any aRet = getWorkbook( mxContext, xSpreadDoc, mxParent ); + uno::Any aRet = getWorkbook( mxContext, dynamic_cast(xSpreadDoc.get()), mxParent ); uno::Reference< excel::XWorkbook > xWBook( aRet, uno::UNO_QUERY ); if ( xWBook.is() ) xWBook->Activate(); diff --git a/sc/source/ui/view/tabvwsh4.cxx b/sc/source/ui/view/tabvwsh4.cxx index 04f8cc346f60..0a9aa6970899 100644 --- a/sc/source/ui/view/tabvwsh4.cxx +++ b/sc/source/ui/view/tabvwsh4.cxx @@ -1881,8 +1881,8 @@ static bool lcl_CheckInArrayCols(std::vector>& nUniqueRe rtl::Reference ScTabViewShell::GetRangeWithSheet(css::table::CellRangeAddress& rRangeData, bool& bHasData, bool bHasUnoArguments) { // get spreadsheet document model & controller - uno::Reference xModel(GetViewData().GetDocShell()->GetModel()); - uno::Reference xController(xModel->getCurrentController()); + ScModelObj* pModel(GetViewData().GetDocShell()->GetModel()); + uno::Reference xController(pModel->getCurrentController()); // spreadsheet's extension of com.sun.star.frame.Controller service ScTabViewObj* pSpreadsheetDocument = dynamic_cast(xController.get()); @@ -1952,30 +1952,27 @@ void ScTabViewShell::HandleDuplicateRecordsHighlight(const rtl::Reference xModel(GetViewData().GetDocShell()->GetModel()); + ScModelObj* pModel(GetViewData().GetDocShell()->GetModel()); rtl::Reference xSheetRange( ActiveSheet->getScCellRangeByPosition(aRange.StartColumn, aRange.StartRow, aRange.EndColumn, aRange.EndRow)); uno::Sequence> aDataArray = xSheetRange->getDataArray(); - uno::Reference< document::XUndoManagerSupplier > xUndoManager( xModel, uno::UNO_QUERY ); - uno::Reference xLockable(xModel, uno::UNO_QUERY); - ScDocument& rDoc = GetViewData().GetDocShell()->GetDocument(); comphelper::ScopeGuard aUndoContextGuard( - [&xUndoManager, &xLockable, &xModel, &rDoc] { - xUndoManager->getUndoManager()->leaveUndoContext(); - xLockable->removeActionLock(); - if (xModel->hasControllersLocked()) - xModel->unlockControllers(); + [pModel, &rDoc] { + pModel->getUndoManager()->leaveUndoContext(); + pModel->removeActionLock(); + if (pModel->hasControllersLocked()) + pModel->unlockControllers(); rDoc.UnlockAdjustHeight(); }); rDoc.LockAdjustHeight(); - xModel->lockControllers(); - xLockable->addActionLock(); - xUndoManager->getUndoManager()->enterUndoContext("HandleDuplicateRecords"); + pModel->lockControllers(); + pModel->addActionLock(); + pModel->getUndoManager()->enterUndoContext("HandleDuplicateRecords"); bool nModifier = false; // modifier key pressed? bool bNoDuplicatesForSelection = true; @@ -2052,34 +2049,30 @@ void ScTabViewShell::HandleDuplicateRecordsRemove(const rtl::Reference xModel(GetViewData().GetDocShell()->GetModel()); + ScModelObj* pModel(GetViewData().GetDocShell()->GetModel()); rtl::Reference xSheetRange( ActiveSheet->getScCellRangeByPosition(aRange.StartColumn, aRange.StartRow, aRange.EndColumn, aRange.EndRow)); uno::Sequence> aDataArray = xSheetRange->getDataArray(); - uno::Reference< document::XUndoManagerSupplier > xUndoManager( xModel, uno::UNO_QUERY ); - uno::Reference xLockable(xModel, uno::UNO_QUERY); - - uno::Reference xCalculatable(xModel, uno::UNO_QUERY); - bool bAutoCalc = xCalculatable->isAutomaticCalculationEnabled(); + bool bAutoCalc = pModel->isAutomaticCalculationEnabled(); ScDocument& rDoc = GetViewData().GetDocShell()->GetDocument(); comphelper::ScopeGuard aUndoContextGuard( - [&xUndoManager, &xLockable, &xModel, &xCalculatable, &bAutoCalc, &rDoc] { - xUndoManager->getUndoManager()->leaveUndoContext(); - xCalculatable->enableAutomaticCalculation(bAutoCalc); - xLockable->removeActionLock(); - if (xModel->hasControllersLocked()) - xModel->unlockControllers(); + [pModel, &bAutoCalc, &rDoc] { + pModel->getUndoManager()->leaveUndoContext(); + pModel->enableAutomaticCalculation(bAutoCalc); + pModel->removeActionLock(); + if (pModel->hasControllersLocked()) + pModel->unlockControllers(); rDoc.UnlockAdjustHeight(); }); rDoc.LockAdjustHeight(); - xModel->lockControllers(); - xLockable->addActionLock(); - xCalculatable->enableAutomaticCalculation(true); - xUndoManager->getUndoManager()->enterUndoContext("HandleDuplicateRecords"); + pModel->lockControllers(); + pModel->addActionLock(); + pModel->enableAutomaticCalculation(true); + pModel->getUndoManager()->enterUndoContext("HandleDuplicateRecords"); if (bDuplicateRows) { diff --git a/sw/source/ui/vba/vbaapplication.cxx b/sw/source/ui/vba/vbaapplication.cxx index 3310f8688a05..67c44e717df6 100644 --- a/sw/source/ui/vba/vbaapplication.cxx +++ b/sw/source/ui/vba/vbaapplication.cxx @@ -490,10 +490,10 @@ SwVbaApplication::getServiceNames() return aServiceNames; } -uno::Reference< frame::XModel > +SfxBaseModel* SwVbaApplication::getCurrentDocument() { - return static_cast(getCurrentWordDoc( mxContext ).get()); + return getCurrentWordDoc( mxContext ).get(); } rtl::Reference< SwXTextDocument > diff --git a/sw/source/ui/vba/vbaapplication.hxx b/sw/source/ui/vba/vbaapplication.hxx index cf2e79ab414d..ac573e3a4f80 100644 --- a/sw/source/ui/vba/vbaapplication.hxx +++ b/sw/source/ui/vba/vbaapplication.hxx @@ -32,6 +32,7 @@ #include #include #include +#include #include "vbawindow.hxx" @@ -124,7 +125,8 @@ public: // XSinkCaller virtual void SAL_CALL CallSinks( const OUString& Method, css::uno::Sequence< css::uno::Any >& Arguments ) override; - virtual css::uno::Reference< css::frame::XModel > getCurrentDocument() override; + // this should be SwXTextDocument, but the inheritance hierarchy makes that impossoble + virtual SfxBaseModel* getCurrentDocument() override; rtl::Reference getCurrentSwDocument(); }; diff --git a/sw/source/ui/vba/vbadocument.cxx b/sw/source/ui/vba/vbadocument.cxx index b742f6f843e1..049cd2a81aa1 100644 --- a/sw/source/ui/vba/vbadocument.cxx +++ b/sw/source/ui/vba/vbadocument.cxx @@ -221,8 +221,7 @@ SwVbaDocument::CustomDocumentProperties( const uno::Any& index ) uno::Any SAL_CALL SwVbaDocument::Bookmarks( const uno::Any& rIndex ) { - uno::Reference< text::XBookmarksSupplier > xBookmarksSupplier( getModel(),uno::UNO_QUERY_THROW ); - uno::Reference xBookmarks( xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY_THROW ); + uno::Reference xBookmarks( mxTextDocument->getBookmarks(), uno::UNO_QUERY_THROW ); uno::Reference< XCollection > xBookmarksVba( new SwVbaBookmarks( this, mxContext, xBookmarks, mxTextDocument ) ); if ( rIndex.getValueTypeClass() == uno::TypeClass_VOID ) return uno::Any( xBookmarksVba ); @@ -230,7 +229,7 @@ SwVbaDocument::Bookmarks( const uno::Any& rIndex ) return xBookmarksVba->Item( rIndex, uno::Any() ); } -uno::Reference< frame::XModel > SwVbaDocument::getModel() const +SfxBaseModel* SwVbaDocument::getModel() const { return static_cast(mxTextDocument.get()); } uno::Any SwVbaDocument::ContentControls(const uno::Any& index) @@ -286,8 +285,7 @@ uno::Reference SwVbaDocument::getActiveWindow() uno::Any SAL_CALL SwVbaDocument::Variables( const uno::Any& rIndex ) { - uno::Reference< css::document::XDocumentPropertiesSupplier > xDocumentPropertiesSupplier( getModel(),uno::UNO_QUERY_THROW ); - uno::Reference< css::document::XDocumentProperties > xDocumentProperties = xDocumentPropertiesSupplier->getDocumentProperties(); + uno::Reference< css::document::XDocumentProperties > xDocumentProperties = mxTextDocument->getDocumentProperties(); uno::Reference< beans::XPropertyAccess > xUserDefined( xDocumentProperties->getUserDefinedProperties(), uno::UNO_QUERY_THROW ); uno::Reference< XCollection > xVariables( new SwVbaVariables( this, mxContext, xUserDefined ) ); @@ -386,9 +384,7 @@ uno::Any SAL_CALL SwVbaDocument::getAttachedTemplate() { uno::Reference< word::XTemplate > xTemplate; - uno::Reference const xDocPropSupp( - getModel(), uno::UNO_QUERY_THROW); - uno::Reference< css::document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_SET_THROW ); + uno::Reference< css::document::XDocumentProperties > xDocProps( mxTextDocument->getDocumentProperties(), uno::UNO_SET_THROW ); xTemplate = new SwVbaTemplate( this, mxContext, xDocProps->getTemplateURL() ); return uno::Any( xTemplate ); @@ -411,9 +407,7 @@ SwVbaDocument::setAttachedTemplate( const css::uno::Any& _attachedtemplate ) else osl::FileBase::getFileURLFromSystemPath( sTemplate, aURL ); - uno::Reference const xDocPropSupp( - getModel(), uno::UNO_QUERY_THROW ); - uno::Reference< css::document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_SET_THROW ); + uno::Reference< css::document::XDocumentProperties > xDocProps( mxTextDocument->getDocumentProperties(), uno::UNO_SET_THROW ); xDocProps->setTemplateURL( aURL ); } @@ -595,8 +589,7 @@ SwVbaDocument::SaveAs2000( const uno::Any& FileName, const uno::Any& FileFormat, setFilterPropsFromFormat( nFileFormat, storeProps ); - uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW ); - xStor->storeAsURL( sURL, storeProps ); + mxTextDocument->storeAsURL( sURL, storeProps ); } void SAL_CALL @@ -622,8 +615,7 @@ SwVbaDocument::SavePreviewPngAs( const uno::Any& FileName ) uno::Sequence storeProps{ comphelper::makePropertyValue(u"FilterName"_ustr, u"writer_png_Export"_ustr) }; - uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW ); - xStor->storeToURL( sURL, storeProps ); + mxTextDocument->storeToURL( sURL, storeProps ); } uno::Any diff --git a/sw/source/ui/vba/vbadocument.hxx b/sw/source/ui/vba/vbadocument.hxx index aeaedecedd1d..7abc36547770 100644 --- a/sw/source/ui/vba/vbadocument.hxx +++ b/sw/source/ui/vba/vbadocument.hxx @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -45,7 +46,8 @@ private: css::uno::Reference< css::container::XNameAccess > getFormControls() const; protected: - virtual css::uno::Reference< css::frame::XModel > getModel() const override; + // this should be SwXTextDocument, but the inheritance hierarchy makes that impossoble + virtual SfxBaseModel* getModel() const override; public: SwVbaDocument( const css::uno::Reference< ooo::vba::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& m_xContext, rtl::Reference< SwXTextDocument > const & xModel ); diff --git a/vbahelper/source/vbahelper/vbaapplicationbase.cxx b/vbahelper/source/vbahelper/vbaapplicationbase.cxx index c4f91f01044a..0ed0b2d7bc4e 100644 --- a/vbahelper/source/vbahelper/vbaapplicationbase.cxx +++ b/vbahelper/source/vbahelper/vbaapplicationbase.cxx @@ -419,7 +419,7 @@ uno::Any SAL_CALL VbaApplicationBase::getVBE() try // return empty object on error { // "VBE" object does not have a parent, but pass document model to be able to determine application type - uno::Sequence< uno::Any > aArgs{ uno::Any(getCurrentDocument()) }; + uno::Sequence< uno::Any > aArgs{ uno::Any(uno::Reference(getCurrentDocument())) }; uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW ); uno::Reference< uno::XInterface > xVBE = xServiceManager->createInstanceWithArgumentsAndContext( u"ooo.vba.vbide.VBE"_ustr , aArgs, mxContext ); diff --git a/vbahelper/source/vbahelper/vbadocumentbase.cxx b/vbahelper/source/vbahelper/vbadocumentbase.cxx index 7db25a6bbba5..6665378e5b40 100644 --- a/vbahelper/source/vbahelper/vbadocumentbase.cxx +++ b/vbahelper/source/vbahelper/vbadocumentbase.cxx @@ -290,7 +290,7 @@ VbaDocumentBase::getVBProject() if (xVBE) { uno::Sequence< uno::Any > aArgs{ uno::Any(xVBE), // the VBE - uno::Any(getModel()) }; // document model for script container access + uno::Any(uno::Reference(getModel())) }; // document model for script container access uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager() ); if (xServiceManager) mxVBProject = xServiceManager->createInstanceWithArgumentsAndContext(