sw/source/ui/config/optload.cxx | 9 ++++----- sw/source/ui/fldui/flddb.cxx | 25 ++++++++++++------------- sw/source/ui/fldui/fldfunc.cxx | 2 +- sw/source/ui/fldui/fldref.cxx | 17 +++++++++-------- sw/source/ui/fmtui/tmpdlg.cxx | 34 ++++++++++++++++++++-------------- sw/source/ui/frmdlg/frmpage.cxx | 30 +++++++++++++++++++++--------- sw/source/ui/frmdlg/wrap.cxx | 4 ++-- sw/source/uibase/app/appopt.cxx | 25 +++++++++++++++---------- sw/source/uibase/utlui/content.cxx | 11 +++++++---- sw/source/uibase/utlui/glbltree.cxx | 17 ++++++++++------- 10 files changed, 101 insertions(+), 73 deletions(-)
New commits: commit e790bcace8109cbcce618f92e12afcb7dbc629f9 Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Thu Feb 16 12:38:55 2023 +0100 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Fri Feb 17 12:10:21 2023 +0000 check GetActiveWrtShell() and CheckAndGetWrtShell() See https://crashreport.libreoffice.org/stats/signature/SwModule::ApplyItemSet(unsigned%20short,SfxItemSet%20const%20&) Change-Id: I7c719c5fe4cda9f6571592c30f39bd440053dbe9 Change-Id: Iaa4448dccd1a0ec1aefa539e476b5046ed50f7b7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147203 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/sw/source/ui/config/optload.cxx b/sw/source/ui/config/optload.cxx index 1885c06ecf9d..af62e10f7fdf 100644 --- a/sw/source/ui/config/optload.cxx +++ b/sw/source/ui/config/optload.cxx @@ -464,10 +464,11 @@ SwCaptionOptPage::SwCaptionOptPage(weld::Container* pPage, weld::DialogControlle SwStyleNameMapper::FillUIName(RES_POOLCOLL_LABEL_FRAME, m_sText); SwStyleNameMapper::FillUIName(RES_POOLCOLL_LABEL_DRAWING, m_sDrawing); - SwWrtShell* pSh = ::GetActiveWrtShell(); // m_xFormatBox sal_uInt16 nSelFormat = SVX_NUM_ARABIC; + SwWrtShell* pSh = ::GetActiveWrtShell(); + if (pSh) { for ( auto i = pMgr->GetFieldTypeCount(); i; ) @@ -663,13 +664,12 @@ void SwCaptionOptPage::UpdateEntry(int nSelEntry) m_xCategory->set_sensitive(bChecked); m_xPreview->set_sensitive(bChecked); - SwWrtShell *pSh = ::GetActiveWrtShell(); InsCaptionOpt* pOpt = weld::fromId<InsCaptionOpt*>(m_xCheckLB->get_id(nSelEntry)); m_xCategoryBox->clear(); m_xCategoryBox->append_text(m_sNone); - if (pSh) + if (::GetActiveWrtShell()) { const size_t nCount = pMgr->GetFieldTypeCount(); @@ -867,8 +867,7 @@ void SwCaptionOptPage::InvalidatePreview() aStr += m_xCategoryBox->get_active_text() + " "; } - SwWrtShell *pSh = ::GetActiveWrtShell(); - if (pSh) + if (SwWrtShell *pSh = ::GetActiveWrtShell()) { SwSetExpFieldType* pFieldType = static_cast<SwSetExpFieldType*>(pMgr->GetFieldType( SwFieldIds::SetExp, m_xCategoryBox->get_active_text() )); diff --git a/sw/source/ui/fldui/flddb.cxx b/sw/source/ui/fldui/flddb.cxx index 3293a6bc670d..62dd538f01e0 100644 --- a/sw/source/ui/fldui/flddb.cxx +++ b/sw/source/ui/fldui/flddb.cxx @@ -73,7 +73,7 @@ SwFieldDBPage::SwFieldDBPage(weld::Container* pPage, weld::DialogController* pCo SwFieldDBPage::~SwFieldDBPage() { // If we have no stored SwWrtShell, it means we didn't do anything useful - no need to revoke. - if (SwWrtShell* pSh = GetWrtShell()) + if (SwWrtShell* pSh = CheckAndGetWrtShell()) { // This would cleanup in the case of cancelled dialog SwDBManager* pDbManager = pSh->GetDoc()->GetDBManager(); @@ -140,8 +140,7 @@ void SwFieldDBPage::Reset(const SfxItemSet*) } else { - SwWrtShell *pSh = CheckAndGetWrtShell(); - if(pSh) + if (SwWrtShell *pSh = CheckAndGetWrtShell()) { SwDBData aTmp(pSh->GetDBData()); m_xDatabaseTLB->Select(aTmp.sDataSource, aTmp.sCommand, u""); @@ -197,15 +196,16 @@ bool SwFieldDBPage::FillItemSet(SfxItemSet* ) aData.sDataSource = m_xDatabaseTLB->GetDBName(sTableName, sColumnName, &bIsTable); aData.sCommand = sTableName; aData.nCommandType = bIsTable ? 0 : 1; - SwWrtShell *pSh = CheckAndGetWrtShell(); - assert(pSh); - SwDBManager* pDbManager = pSh->GetDoc()->GetDBManager(); - if (pDbManager) - pDbManager->CommitLastRegistrations(); + if (SwWrtShell *pSh = CheckAndGetWrtShell()) + { + SwDBManager* pDbManager = pSh->GetDoc()->GetDBManager(); + if (pDbManager) + pDbManager->CommitLastRegistrations(); - if (aData.sDataSource.isEmpty()) - aData = pSh->GetDBData(); + if (aData.sDataSource.isEmpty()) + aData = pSh->GetDBData(); + } if(!aData.sDataSource.isEmpty()) // without database no new field command { @@ -292,8 +292,6 @@ void SwFieldDBPage::TypeHdl(const weld::TreeView* pBox) if (nOld == GetTypeSel()) return; - SwWrtShell *pSh = CheckAndGetWrtShell(); - assert(pSh); bool bCond = false, bSetNo = false, bFormat = false, bDBFormat = false; const SwFieldTypesEnum nTypeId = static_cast<SwFieldTypesEnum>(m_xTypeLB->get_id(GetTypeSel()).toUInt32()); @@ -315,7 +313,8 @@ void SwFieldDBPage::TypeHdl(const weld::TreeView* pBox) { if (auto *const pField = dynamic_cast<SwDBNameInfField*>(GetCurField())) { - aData = pField->GetDBData(pSh->GetDoc()); + if(SwWrtShell *pSh = CheckAndGetWrtShell()) + aData = pField->GetDBData(pSh->GetDoc()); } } m_xDatabaseTLB->Select(aData.sDataSource, aData.sCommand, sColumnName); diff --git a/sw/source/ui/fldui/fldfunc.cxx b/sw/source/ui/fldui/fldfunc.cxx index 017a4d19c6aa..a129f7413287 100644 --- a/sw/source/ui/fldui/fldfunc.cxx +++ b/sw/source/ui/fldui/fldfunc.cxx @@ -315,7 +315,7 @@ IMPL_LINK_NOARG(SwFieldFuncPage, TypeHdl, weld::TreeView&, void) m_xNameED->SetDropEnable(true); m_xValueFT->set_label(SwResId(STR_INSTEXT)); SwWrtShell* pSh = GetActiveWrtShell(); - if (!IsFieldEdit() && pSh ) + if (!IsFieldEdit() && pSh) m_xValueED->set_text(pSh->GetSelText()); bName = bValue = true; m_xNameED->set_accessible_name(m_xNameFT->get_label()); diff --git a/sw/source/ui/fldui/fldref.cxx b/sw/source/ui/fldui/fldref.cxx index bae2557f173d..08a44c5c85fd 100644 --- a/sw/source/ui/fldui/fldref.cxx +++ b/sw/source/ui/fldui/fldref.cxx @@ -198,7 +198,6 @@ void SwFieldRefPage::Reset(const SfxItemSet* ) SwWrtShell *pSh = GetWrtShell(); if (!pSh) pSh = ::GetActiveWrtShell(); - if (!pSh) return; @@ -490,8 +489,11 @@ void SwFieldRefPage::SubTypeHdl() void SwFieldRefPage::UpdateSubType(const OUString& filterString) { SwWrtShell *pSh = GetWrtShell(); - if(!pSh) + if (!pSh) pSh = ::GetActiveWrtShell(); + if (!pSh) + return; + SwGetRefField const*const pRefField(dynamic_cast<SwGetRefField*>(GetCurField())); const sal_uInt16 nTypeId = m_xTypeLB->get_id(GetTypeSel()).toUInt32(); @@ -980,13 +982,12 @@ bool SwFieldRefPage::FillItemSet(SfxItemSet* ) SwGetRefField const*const pRefField(dynamic_cast<SwGetRefField*>(GetCurField())); - if (REFFLDFLAG & nTypeId) + SwWrtShell *pSh = GetWrtShell(); + if(!pSh) + pSh = ::GetActiveWrtShell(); + + if (pSh && REFFLDFLAG & nTypeId) { - SwWrtShell *pSh = GetWrtShell(); - if(!pSh) - { - pSh = ::GetActiveWrtShell(); - } if (nTypeId == REFFLDFLAG_BOOKMARK) // text marks! { aName = m_xNameED->get_text(); diff --git a/sw/source/ui/fmtui/tmpdlg.cxx b/sw/source/ui/fmtui/tmpdlg.cxx index aa3c9e5eacf6..e6fb3f00e091 100644 --- a/sw/source/ui/fmtui/tmpdlg.cxx +++ b/sw/source/ui/fmtui/tmpdlg.cxx @@ -308,11 +308,14 @@ void SwTemplateDlgController::PageCreated(const OString& rId, SfxTabPage &rPage } else if (SfxStyleFamily::Pseudo == nType) { - SwDocShell* pDocShell = ::GetActiveWrtShell()->GetView().GetDocShell(); - FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebDocShell*>( pDocShell) != nullptr ); + if (SwWrtShell* pSh = ::GetActiveWrtShell()) + { + SwDocShell* pDocShell = pSh->GetView().GetDocShell(); + FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebDocShell*>( pDocShell) != nullptr ); - aSet.Put ( SfxUInt16Item(SID_METRIC_ITEM, static_cast< sal_uInt16 >(eMetric))); - rPage.PageCreated(aSet); + aSet.Put ( SfxUInt16Item(SID_METRIC_ITEM, static_cast< sal_uInt16 >(eMetric))); + rPage.PageCreated(aSet); + } } } else if (rId == "columns") @@ -472,18 +475,21 @@ void SwTemplateDlgController::PageCreated(const OString& rId, SfxTabPage &rPage std::unique_ptr<weld::ComboBox> xCharFormatLB(xBuilder->weld_combo_box("combobox")); xCharFormatLB->clear(); xCharFormatLB->append_text(SwViewShell::GetShellRes()->aStrNone); - SwDocShell* pDocShell = ::GetActiveWrtShell()->GetView().GetDocShell(); - ::FillCharStyleListBox(*xCharFormatLB, pDocShell); + if (SwWrtShell* pSh = ::GetActiveWrtShell()) + { + SwDocShell* pDocShell = pSh->GetView().GetDocShell(); + ::FillCharStyleListBox(*xCharFormatLB, pDocShell); - std::vector<OUString> aList; - aList.reserve(xCharFormatLB->get_count()); - for (sal_Int32 j = 0; j < xCharFormatLB->get_count(); j++) - aList.push_back(xCharFormatLB->get_text(j)); + std::vector<OUString> aList; + aList.reserve(xCharFormatLB->get_count()); + for (sal_Int32 j = 0; j < xCharFormatLB->get_count(); j++) + aList.push_back(xCharFormatLB->get_text(j)); - aSet.Put( SfxStringListItem( SID_CHAR_FMT_LIST_BOX,&aList ) ) ; - FieldUnit eMetric = ::GetDfltMetric(dynamic_cast< const SwWebDocShell *>( pDocShell ) != nullptr); - aSet.Put ( SfxUInt16Item(SID_METRIC_ITEM, static_cast< sal_uInt16 >(eMetric))); - rPage.PageCreated(aSet); + aSet.Put( SfxStringListItem( SID_CHAR_FMT_LIST_BOX,&aList ) ) ; + FieldUnit eMetric = ::GetDfltMetric(dynamic_cast< const SwWebDocShell *>( pDocShell ) != nullptr); + aSet.Put ( SfxUInt16Item(SID_METRIC_ITEM, static_cast< sal_uInt16 >(eMetric))); + rPage.PageCreated(aSet); + } } else if (rId == "indents") { diff --git a/sw/source/ui/frmdlg/frmpage.cxx b/sw/source/ui/frmdlg/frmpage.cxx index 11955b5beb42..dede6dec1830 100644 --- a/sw/source/ui/frmdlg/frmpage.cxx +++ b/sw/source/ui/frmdlg/frmpage.cxx @@ -859,6 +859,9 @@ void SwFramePage::Reset( const SfxItemSet *rSet ) { SwWrtShell* pSh = m_bFormat ? ::GetActiveWrtShell() : getFrameDlgParentShell(); + OSL_ENSURE(pSh , "shell not found"); + if (!pSh) + return; m_nHtmlMode = ::GetHtmlMode(pSh->GetView().GetDocShell()); m_bHtmlMode = (m_nHtmlMode & HTMLMODE_ON) != 0; @@ -902,7 +905,6 @@ void SwFramePage::Reset( const SfxItemSet *rSet ) if ( m_sDlgType == "PictureDialog" || m_sDlgType == "ObjectDialog" ) { - OSL_ENSURE(pSh , "shell not found"); pSh->GetGrfSize( m_aGrfSize ); if ( !m_bNew ) @@ -1031,9 +1033,7 @@ void SwFramePage::Reset( const SfxItemSet *rSet ) bool SwFramePage::FillItemSet(SfxItemSet *rSet) { bool bRet = false; - SwWrtShell* pSh = m_bFormat ? ::GetActiveWrtShell() - : getFrameDlgParentShell(); - OSL_ENSURE( pSh , "shell not found"); + const SfxItemSet& rOldSet = GetItemSet(); const SfxPoolItem* pOldItem = nullptr; @@ -1044,8 +1044,14 @@ bool SwFramePage::FillItemSet(SfxItemSet *rSet) pOldItem = GetOldItem(*rSet, RES_ANCHOR); if (m_bNew || !pOldItem || eAnchorId != static_cast<const SwFormatAnchor*>(pOldItem)->GetAnchorId()) { - SwFormatAnchor aAnc( eAnchorId, pSh->GetPhyPageNum() ); - bRet = nullptr != rSet->Put( aAnc ); + SwWrtShell* pSh = m_bFormat ? ::GetActiveWrtShell() + : getFrameDlgParentShell(); + OSL_ENSURE( pSh , "shell not found"); + if (pSh) + { + SwFormatAnchor aAnc( eAnchorId, pSh->GetPhyPageNum() ); + bRet = nullptr != rSet->Put( aAnc ); + } } } @@ -1703,9 +1709,12 @@ DeactivateRC SwFramePage::DeactivatePage(SfxItemSet * _pSet) //the original. But for the other pages we need the current anchor. SwWrtShell* pSh = m_bFormat ? ::GetActiveWrtShell() : getFrameDlgParentShell(); - RndStdIds eAnchorId = GetAnchor(); - SwFormatAnchor aAnc( eAnchorId, pSh->GetPhyPageNum() ); - _pSet->Put( aAnc ); + if (pSh) + { + RndStdIds eAnchorId = GetAnchor(); + SwFormatAnchor aAnc( eAnchorId, pSh->GetPhyPageNum() ); + _pSet->Put( aAnc ); + } } } @@ -1758,6 +1767,9 @@ void SwFramePage::RangeModifyHdl() SwWrtShell* pSh = m_bFormat ? ::GetActiveWrtShell() : getFrameDlgParentShell(); OSL_ENSURE(pSh , "shell not found"); + if (!pSh) + return; + SwFlyFrameAttrMgr aMgr( m_bNew, pSh, GetItemSet() ); SvxSwFrameValidation aVal; diff --git a/sw/source/ui/frmdlg/wrap.cxx b/sw/source/ui/frmdlg/wrap.cxx index a03ddff953be..4db38e12f772 100644 --- a/sw/source/ui/frmdlg/wrap.cxx +++ b/sw/source/ui/frmdlg/wrap.cxx @@ -379,9 +379,9 @@ void SwWrapTabPage::ActivatePage(const SfxItemSet& rSet) m_nAnchorId = rAnch.GetAnchorId(); bool bEnable = (m_nAnchorId != RndStdIds::FLY_AS_CHAR); - if (!m_bDrawMode) + SwWrtShell* pSh = m_bFormat ? ::GetActiveWrtShell() : m_pWrtSh; + if (pSh && !m_bDrawMode) { - SwWrtShell* pSh = m_bFormat ? ::GetActiveWrtShell() : m_pWrtSh; SwFlyFrameAttrMgr aMgr( m_bNew, pSh, GetItemSet() ); SvxSwFrameValidation aVal; diff --git a/sw/source/uibase/app/appopt.cxx b/sw/source/uibase/app/appopt.cxx index 86343d2e6651..064bf31f47c2 100644 --- a/sw/source/uibase/app/appopt.cxx +++ b/sw/source/uibase/app/appopt.cxx @@ -260,17 +260,19 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) { pElemItem->FillViewOptions( aViewOpt ); - SwWrtShell* pWrtShell = GetActiveWrtShell(); - bFlag = pWrtShell->GetViewOptions()->IsShowOutlineContentVisibilityButton(); - bool bTreatSubsChanged = aViewOpt.IsTreatSubOutlineLevelsAsContent() - != pWrtShell->GetViewOptions()->IsTreatSubOutlineLevelsAsContent(); - if (bFlag && (!aViewOpt.IsShowOutlineContentVisibilityButton() || bTreatSubsChanged)) + if (SwWrtShell* pWrtShell = GetActiveWrtShell()) { - // outline mode options have change which require to show all content - pWrtShell->MakeAllFoldedOutlineContentVisible(); + bFlag = pWrtShell->GetViewOptions()->IsShowOutlineContentVisibilityButton(); + bool bTreatSubsChanged = aViewOpt.IsTreatSubOutlineLevelsAsContent() + != pWrtShell->GetViewOptions()->IsTreatSubOutlineLevelsAsContent(); + if (bFlag && (!aViewOpt.IsShowOutlineContentVisibilityButton() || bTreatSubsChanged)) + { + // outline mode options have change which require to show all content + pWrtShell->MakeAllFoldedOutlineContentVisible(); - if (bTreatSubsChanged) - bFlag = false; // folding method changed, set bFlag false to refold below + if (bTreatSubsChanged) + bFlag = false; // folding method changed, set bFlag false to refold below + } } } @@ -387,7 +389,10 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) return; if (!bFlag) - GetActiveWrtShell()->MakeAllFoldedOutlineContentVisible(false); + { + if (SwWrtShell* pWrtShell = GetActiveWrtShell()) + pWrtShell->MakeAllFoldedOutlineContentVisible(false); + } } std::unique_ptr<SfxTabPage> SwModule::CreateTabPage( sal_uInt16 nId, weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet ) diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx index 851eb0f75dd0..bc920880bb3a 100644 --- a/sw/source/uibase/utlui/content.cxx +++ b/sw/source/uibase/utlui/content.cxx @@ -1360,11 +1360,14 @@ static void lcl_SetOutlineContentEntriesSensitivities(SwContentTree* pThis, cons bool bIsRoot = lcl_IsContentType(rEntry, rContentTree); - if (pThis->GetActiveWrtShell()->GetViewOptions()->IsTreatSubOutlineLevelsAsContent()) + if (const SwWrtShell* pSh = pThis->GetActiveWrtShell()) { - if (!bIsRoot) - rPop.set_sensitive(OString::number(TOGGLE_OUTLINE_CONTENT_VISIBILITY), true); - return; + if (pSh->GetViewOptions()->IsTreatSubOutlineLevelsAsContent()) + { + if (!bIsRoot) + rPop.set_sensitive(OString::number(TOGGLE_OUTLINE_CONTENT_VISIBILITY), true); + return; + } } const SwNodes& rNodes = pThis->GetWrtShell()->GetNodes(); diff --git a/sw/source/uibase/utlui/glbltree.cxx b/sw/source/uibase/utlui/glbltree.cxx index 4e64540c4a90..a336cbec7925 100644 --- a/sw/source/uibase/utlui/glbltree.cxx +++ b/sw/source/uibase/utlui/glbltree.cxx @@ -205,14 +205,17 @@ sal_Int8 SwGlobalTreeDropTarget::ExecuteDrop( const ExecuteDropEvent& rEvt ) // to not work on an old content. if(n) { - m_rTreeView.GetActiveWrtShell()->GetGlobalDocContent(aTempContents); - // If the file was successfully inserted, - // then the next content must also be fetched. - if(nEntryCount < aTempContents.size()) + if (const SwWrtShell* pSh = m_rTreeView.GetActiveWrtShell()) { - nEntryCount++; - nAbsContPos++; - pCnt = aTempContents[ nAbsContPos ].get(); + pSh->GetGlobalDocContent(aTempContents); + // If the file was successfully inserted, + // then the next content must also be fetched. + if(nEntryCount < aTempContents.size()) + { + nEntryCount++; + nAbsContPos++; + pCnt = aTempContents[ nAbsContPos ].get(); + } } } }