desktop/source/deployment/gui/dp_gui_theextmgr.cxx | 6 - sc/source/ui/vba/vbaapplication.cxx | 13 ++ sc/source/ui/vba/vbapagesetup.cxx | 7 + sc/source/ui/vba/vbaworkbook.cxx | 26 +++-- sc/source/ui/vba/vbaworksheet.cxx | 102 +++++++++++---------- 5 files changed, 89 insertions(+), 65 deletions(-)
New commits: commit 2e86a482da67bd6ad5791f6fd82be13b75dc04bd Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Thu May 18 13:31:14 2023 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Tue May 30 16:52:15 2023 +0200 sc: check excel::getDocShell There seems to be some crashes related. See https://crashreport.libreoffice.org/stats/signature/ScDocShell::GetDocument() or https://crashreport.libreoffice.org/stats/signature/ScDocShell::RegisterAutomationWorkbookObject(com::sun::star::uno::Reference%3Cooo::vba::excel::XWorkbook%3E%20const%20&) Change-Id: I9affce5a28cb1198eb472d369debf83fd7dd8c0e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151924 Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> (cherry picked from commit c0e96f302c04597bc49d55e262b069f1eb170e45) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151925 Reviewed-by: Michael Stahl <michael.st...@allotropia.de> Reviewed-by: Eike Rathke <er...@redhat.com> Reviewed-by: Ilmari Lauhakangas <ilmari.lauhakan...@libreoffice.org> Tested-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sc/source/ui/vba/vbaapplication.cxx b/sc/source/ui/vba/vbaapplication.cxx index 98c7cf7708a5..6676b4bb5eaa 100644 --- a/sc/source/ui/vba/vbaapplication.cxx +++ b/sc/source/ui/vba/vbaapplication.cxx @@ -1203,7 +1203,8 @@ uno::Reference< excel::XRange > lclCreateVbaRange( const ListOfScRange& rList ) { ScDocShell* pDocShell = excel::getDocShell( rxModel ); - if( !pDocShell ) throw uno::RuntimeException(); + if( !pDocShell ) + throw uno::RuntimeException(); ScRangeList aCellRanges; for( const auto& rItem : rList ) @@ -1345,8 +1346,11 @@ ScVbaApplication::Volatile( const uno::Any& aVolatile ) if ( pMeth ) { uno::Reference< frame::XModel > xModel( getCurrentDocument() ); - ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument(); - rDoc.GetMacroManager()->SetUserFuncVolatile( pMeth->GetName(), bVolatile); + if ( ScDocShell* pShell = excel::getDocShell( xModel )) + { + ScDocument& rDoc = pShell->GetDocument(); + rDoc.GetMacroManager()->SetUserFuncVolatile( pMeth->GetName(), bVolatile); + } } // this is bound to break when loading the document @@ -1446,7 +1450,10 @@ void SAL_CALL ScVbaApplication::setScreenUpdating(sal_Bool bUpdate) VbaApplicationBase::setScreenUpdating( bUpdate ); uno::Reference< frame::XModel > xModel( getCurrentExcelDoc( mxContext ), uno::UNO_SET_THROW ); + ScDocShell* pDocShell = excel::getDocShell( xModel ); + if (!pDocShell) + return; ScDocument& rDoc = pDocShell->GetDocument(); if( bUpdate ) diff --git a/sc/source/ui/vba/vbapagesetup.cxx b/sc/source/ui/vba/vbapagesetup.cxx index f487b74e0c7b..f945802e1082 100644 --- a/sc/source/ui/vba/vbapagesetup.cxx +++ b/sc/source/ui/vba/vbapagesetup.cxx @@ -77,8 +77,11 @@ OUString SAL_CALL ScVbaPageSetup::getPrintArea() ScUnoConversion::FillScRange( aRange, rRange ); aRangeList.push_back( aRange ); } - ScDocument& rDoc = excel::getDocShell( mxModel )->GetDocument(); - aRangeList.Format( aPrintArea, ScRefFlags::RANGE_ABS, rDoc, formula::FormulaGrammar::CONV_XL_A1, ',' ); + if ( ScDocShell* pShell = excel::getDocShell( mxModel )) + { + ScDocument& rDoc = pShell->GetDocument(); + aRangeList.Format( aPrintArea, ScRefFlags::RANGE_ABS, rDoc, formula::FormulaGrammar::CONV_XL_A1, ',' ); + } } return aPrintArea; diff --git a/sc/source/ui/vba/vbaworkbook.cxx b/sc/source/ui/vba/vbaworkbook.cxx index 23cc523a1aa8..0604d9686b61 100644 --- a/sc/source/ui/vba/vbaworkbook.cxx +++ b/sc/source/ui/vba/vbaworkbook.cxx @@ -184,9 +184,8 @@ ScVbaWorkbook::init() { if ( !ColorData.hasElements() ) ResetColors(); - uno::Reference< frame::XModel > xModel = getModel(); - if ( xModel.is() ) - excel::getDocShell( xModel )->RegisterAutomationWorkbookObject( this ); + if ( ScDocShell* pShell = excel::getDocShell( getModel() )) + pShell->RegisterAutomationWorkbookObject( this ); } 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 ) : ScVbaWorkbook_BASE( xParent, xContext, xModel ) @@ -264,18 +263,23 @@ ScVbaWorkbook::getProtectStructure() sal_Bool SAL_CALL ScVbaWorkbook::getPrecisionAsDisplayed() { - uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_SET_THROW ); - ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument(); - return rDoc.GetDocOptions().IsCalcAsShown(); + if ( ScDocShell* pShell = excel::getDocShell( getModel() )) + { + ScDocument& rDoc = pShell->GetDocument(); + return rDoc.GetDocOptions().IsCalcAsShown(); + } + return false; } void SAL_CALL ScVbaWorkbook::setPrecisionAsDisplayed( sal_Bool _precisionAsDisplayed ) { - uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_SET_THROW ); - ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument(); - ScDocOptions aOpt = rDoc.GetDocOptions(); - aOpt.SetCalcAsShown( _precisionAsDisplayed ); - rDoc.SetDocOptions( aOpt ); + if ( ScDocShell* pShell = excel::getDocShell( getModel() )) + { + ScDocument& rDoc = pShell->GetDocument(); + ScDocOptions aOpt = rDoc.GetDocOptions(); + aOpt.SetCalcAsShown( _precisionAsDisplayed ); + rDoc.SetDocOptions( aOpt ); + } } OUString SAL_CALL ScVbaWorkbook::getAuthor() diff --git a/sc/source/ui/vba/vbaworksheet.cxx b/sc/source/ui/vba/vbaworksheet.cxx index cfc84537da62..abd76c6023c6 100644 --- a/sc/source/ui/vba/vbaworksheet.cxx +++ b/sc/source/ui/vba/vbaworksheet.cxx @@ -199,7 +199,8 @@ ScVbaWorksheet::createSheetCopyInNewDoc(const OUString& aCurrSheetName) ScDocShell* pShell = excel::getDocShell( xModel ); OUString aCodeName; - pShell->GetDocument().GetCodeName( 0, aCodeName ); + if (pShell) + pShell->GetDocument().GetCodeName( 0, aCodeName ); return uno::Reference< excel::XWorksheet >( getUnoDocModule( aCodeName, pShell ), uno::UNO_QUERY_THROW ); } @@ -309,20 +310,22 @@ ScVbaWorksheet::getEnableSelection() if ( !ScVbaWorksheets::nameExists(xSpreadDoc, getName(), nTab) ) throw uno::RuntimeException("Sheet Name does not exist." ); - uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_SET_THROW ); - ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument(); - const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); - bool bLockedCells = false; - bool bUnlockedCells = false; - if( pProtect ) + if ( ScDocShell* pShell = excel::getDocShell( getModel() )) { - bLockedCells = pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS); - bUnlockedCells = pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS); + ScDocument& rDoc = pShell->GetDocument(); + const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); + bool bLockedCells = false; + bool bUnlockedCells = false; + if( pProtect ) + { + bLockedCells = pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS); + bUnlockedCells = pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS); + } + if( bLockedCells ) + return excel::XlEnableSelection::xlNoRestrictions; + if( bUnlockedCells ) + return excel::XlEnableSelection::xlUnlockedCells; } - if( bLockedCells ) - return excel::XlEnableSelection::xlNoRestrictions; - if( bUnlockedCells ) - return excel::XlEnableSelection::xlUnlockedCells; return excel::XlEnableSelection::xlNoSelection; } @@ -342,46 +345,49 @@ ScVbaWorksheet::setEnableSelection( sal_Int32 nSelection ) if ( !ScVbaWorksheets::nameExists(xSpreadDoc, getName(), nTab) ) throw uno::RuntimeException("Sheet Name does not exist." ); - uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_SET_THROW ); - ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument(); - const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); - // default is xlNoSelection - bool bLockedCells = false; - bool bUnlockedCells = false; - if( nSelection == excel::XlEnableSelection::xlNoRestrictions ) + if ( ScDocShell* pShell = excel::getDocShell( getModel() )) { - bLockedCells = true; - bUnlockedCells = true; - } - else if( nSelection == excel::XlEnableSelection::xlUnlockedCells ) - { - bUnlockedCells = true; - } - if( pProtect ) - { - ScTableProtection aNewProtect(*pProtect); - aNewProtect.setOption(ScTableProtection::SELECT_LOCKED_CELLS, bLockedCells); - aNewProtect.setOption(ScTableProtection::SELECT_UNLOCKED_CELLS, bUnlockedCells); - rDoc.SetTabProtection(nTab, &aNewProtect); + ScDocument& rDoc = pShell->GetDocument(); + const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); + // default is xlNoSelection + bool bLockedCells = false; + bool bUnlockedCells = false; + if( nSelection == excel::XlEnableSelection::xlNoRestrictions ) + { + bLockedCells = true; + bUnlockedCells = true; + } + else if( nSelection == excel::XlEnableSelection::xlUnlockedCells ) + { + bUnlockedCells = true; + } + if( pProtect ) + { + ScTableProtection aNewProtect(*pProtect); + aNewProtect.setOption(ScTableProtection::SELECT_LOCKED_CELLS, bLockedCells); + aNewProtect.setOption(ScTableProtection::SELECT_UNLOCKED_CELLS, bUnlockedCells); + rDoc.SetTabProtection(nTab, &aNewProtect); + } } - - } sal_Bool SAL_CALL ScVbaWorksheet::getAutoFilterMode() { - uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_SET_THROW ); - ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument(); - ScDBData* pDBData = rDoc.GetAnonymousDBData(getSheetID()); - if (pDBData) - return pDBData->HasAutoFilter(); + if ( ScDocShell* pShell = excel::getDocShell( getModel() )) + { + ScDocument& rDoc = pShell->GetDocument(); + ScDBData* pDBData = rDoc.GetAnonymousDBData(getSheetID()); + if (pDBData) + return pDBData->HasAutoFilter(); + } return false; } void SAL_CALL ScVbaWorksheet::setAutoFilterMode( sal_Bool bAutoFilterMode ) { - uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_SET_THROW ); - ScDocShell* pDocShell = excel::getDocShell( xModel ); + ScDocShell* pDocShell = excel::getDocShell( getModel() ); + if (!pDocShell) + return; ScDocument& rDoc = pDocShell->GetDocument(); ScDBData* pDBData = rDoc.GetAnonymousDBData(getSheetID()); if (!pDBData) @@ -481,11 +487,13 @@ ScVbaWorksheet::getProtectDrawingObjects() bool bSheetExists = ScVbaWorksheets::nameExists (xSpreadDoc, aSheetName, nTab); if ( bSheetExists ) { - uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_SET_THROW ); - ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument(); - const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); - if ( pProtect ) - return pProtect->isOptionEnabled( ScTableProtection::OBJECTS ); + if ( ScDocShell* pShell = excel::getDocShell( getModel() )) + { + ScDocument& rDoc = pShell->GetDocument(); + const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); + if ( pProtect ) + return pProtect->isOptionEnabled( ScTableProtection::OBJECTS ); + } } return false; } commit a570896b5aa1bfc019d529d788276dbcc260cd55 Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Thu May 25 11:15:37 2023 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Tue May 30 16:52:04 2023 +0200 desktop: check getDialog() it might return nullptr See https://crashreport.libreoffice.org/stats/signature/dp_gui::TheExtensionManager::ToTop() Change-Id: I4023529aec0ba2c72b4e7db5449d235c208ee30b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152223 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> (cherry picked from commit 8ce5696c3cf9d7a95da581ebe4b7ebd0d7a114ca) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152226 Reviewed-by: Michael Stahl <michael.st...@allotropia.de> Reviewed-by: Eike Rathke <er...@redhat.com> Reviewed-by: Ilmari Lauhakangas <ilmari.lauhakan...@libreoffice.org> Tested-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/desktop/source/deployment/gui/dp_gui_theextmgr.cxx b/desktop/source/deployment/gui/dp_gui_theextmgr.cxx index 10a2cfb1f136..e844f09c1b85 100644 --- a/desktop/source/deployment/gui/dp_gui_theextmgr.cxx +++ b/desktop/source/deployment/gui/dp_gui_theextmgr.cxx @@ -158,7 +158,8 @@ void TheExtensionManager::SetText( const OUString &rTitle ) { const SolarMutexGuard guard; - getDialog()->set_title( rTitle ); + if (weld::Window* pDialog = getDialog()) + pDialog->set_title( rTitle ); } @@ -166,7 +167,8 @@ void TheExtensionManager::ToTop() { const SolarMutexGuard guard; - getDialog()->present(); + if (weld::Window* pDialog = getDialog()) + pDialog->present(); } void TheExtensionManager::Close()