diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-02-16 12:38:55 +0100 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2023-02-19 22:48:30 +0100 |
commit | 985d534b91c9a5f4e3f616a9b4b9093908912a73 (patch) | |
tree | 7646f12a6c54b6fd688898e7a44a920f32658b00 /sw/source/ui | |
parent | 3dd417b3b0ce2295df23135077ca074291744918 (diff) |
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/+/147201
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw/source/ui')
-rw-r--r-- | sw/source/ui/config/optload.cxx | 9 | ||||
-rw-r--r-- | sw/source/ui/fldui/flddb.cxx | 25 | ||||
-rw-r--r-- | sw/source/ui/fldui/fldfunc.cxx | 2 | ||||
-rw-r--r-- | sw/source/ui/fldui/fldref.cxx | 17 | ||||
-rw-r--r-- | sw/source/ui/fmtui/tmpdlg.cxx | 34 | ||||
-rw-r--r-- | sw/source/ui/frmdlg/frmpage.cxx | 30 | ||||
-rw-r--r-- | sw/source/ui/frmdlg/wrap.cxx | 4 |
7 files changed, 69 insertions, 52 deletions
diff --git a/sw/source/ui/config/optload.cxx b/sw/source/ui/config/optload.cxx index 93d6b7e4dabe..2c3ef5adbe4e 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 = m_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 = m_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*>(m_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 d4de4413fffb..e84dcda1e780 100644 --- a/sw/source/ui/fldui/fldfunc.cxx +++ b/sw/source/ui/fldui/fldfunc.cxx @@ -312,7 +312,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 b7a30d589196..ea8e41414d4a 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 8ebf75129db7..132296f83a9b 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 == m_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 2b8b9105caab..8dff4cd41e59 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 be60343e39b4..457fa346558b 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; |