summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2023-02-16 12:38:55 +0100
committerCaolán McNamara <caolanm@redhat.com>2023-02-17 16:03:11 +0000
commit25b38765d6e500af196ce312a3e1d819c6a7d09c (patch)
tree2ebeaa7c9870b18876752bbb316a491e78e0682a
parent08b0443e0f50f79ee26fad4eada0190623b9b30a (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/+/147155 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sw/source/ui/config/optload.cxx9
-rw-r--r--sw/source/ui/fldui/flddb.cxx25
-rw-r--r--sw/source/ui/fldui/fldfunc.cxx2
-rw-r--r--sw/source/ui/fldui/fldref.cxx17
-rw-r--r--sw/source/ui/fmtui/tmpdlg.cxx34
-rw-r--r--sw/source/ui/frmdlg/frmpage.cxx30
-rw-r--r--sw/source/ui/frmdlg/wrap.cxx4
-rw-r--r--sw/source/uibase/app/appopt.cxx47
-rw-r--r--sw/source/uibase/utlui/content.cxx11
-rw-r--r--sw/source/uibase/utlui/glbltree.cxx17
10 files changed, 112 insertions, 84 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 656600c6b52e..8267cc4c10b5 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;
diff --git a/sw/source/uibase/app/appopt.cxx b/sw/source/uibase/app/appopt.cxx
index 4f06d121ff78..e6923fe9aee1 100644
--- a/sw/source/uibase/app/appopt.cxx
+++ b/sw/source/uibase/app/appopt.cxx
@@ -263,26 +263,28 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet )
pElemItem->FillViewOptions( aViewOpt );
// Outline-folding options
- SwWrtShell* pWrtShell = GetActiveWrtShell();
- bool bIsOutlineFoldingOn = pWrtShell->GetViewOptions()->IsShowOutlineContentVisibilityButton();
- bool bTreatSubsChanged = aViewOpt.IsTreatSubOutlineLevelsAsContent()
- != pWrtShell->GetViewOptions()->IsTreatSubOutlineLevelsAsContent();
- if (bIsOutlineFoldingOn &&
- (!aViewOpt.IsShowOutlineContentVisibilityButton() || bTreatSubsChanged))
+ if (SwWrtShell* pWrtShell = GetActiveWrtShell())
{
- // Outline-folding options have change which require to show all content.
- // Either outline-folding is being switched off or outline-folding is currently on
- // and the treat subs option has changed.
- pWrtShell->GetView().GetViewFrame().GetDispatcher()->Execute(FN_SHOW_OUTLINECONTENTVISIBILITYBUTTON);
- if (bTreatSubsChanged)
- bReFoldOutlineFolding = true; // folding method changed, set flag to refold below
- }
- else
- {
- // Refold needs to be done when outline-folding is being turned on or off
- bReFoldOutlineFolding =
- pWrtShell->GetViewOptions()->IsShowOutlineContentVisibilityButton() !=
- aViewOpt.IsShowOutlineContentVisibilityButton();
+ bool bIsOutlineFoldingOn = pWrtShell->GetViewOptions()->IsShowOutlineContentVisibilityButton();
+ bool bTreatSubsChanged = aViewOpt.IsTreatSubOutlineLevelsAsContent()
+ != pWrtShell->GetViewOptions()->IsTreatSubOutlineLevelsAsContent();
+ if (bIsOutlineFoldingOn &&
+ (!aViewOpt.IsShowOutlineContentVisibilityButton() || bTreatSubsChanged))
+ {
+ // Outline-folding options have change which require to show all content.
+ // Either outline-folding is being switched off or outline-folding is currently on
+ // and the treat subs option has changed.
+ pWrtShell->GetView().GetViewFrame().GetDispatcher()->Execute(FN_SHOW_OUTLINECONTENTVISIBILITYBUTTON);
+ if (bTreatSubsChanged)
+ bReFoldOutlineFolding = true; // folding method changed, set flag to refold below
+ }
+ else
+ {
+ // Refold needs to be done when outline-folding is being turned on or off
+ bReFoldOutlineFolding =
+ pWrtShell->GetViewOptions()->IsShowOutlineContentVisibilityButton() !=
+ aViewOpt.IsShowOutlineContentVisibilityButton();
+ }
}
}
@@ -400,8 +402,11 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet )
if (bReFoldOutlineFolding)
{
- GetActiveWrtShell()->GetView().GetViewFrame().GetDispatcher()->Execute(FN_SHOW_OUTLINECONTENTVISIBILITYBUTTON);
- GetActiveWrtShell()->GetView().GetViewFrame().GetDispatcher()->Execute(FN_SHOW_OUTLINECONTENTVISIBILITYBUTTON);
+ if (SwWrtShell* pWrtShell = GetActiveWrtShell())
+ {
+ pWrtShell->GetView().GetViewFrame().GetDispatcher()->Execute(FN_SHOW_OUTLINECONTENTVISIBILITYBUTTON);
+ pWrtShell->GetView().GetViewFrame().GetDispatcher()->Execute(FN_SHOW_OUTLINECONTENTVISIBILITYBUTTON);
+ }
}
}
diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx
index 254ee4fcec9f..e299438634f5 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -1418,11 +1418,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 fac264f2bbf1..22559a3f709e 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();
+ }
}
}
}