diff options
author | Caolán McNamara <caolanm@redhat.com> | 2022-12-15 16:40:53 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2022-12-15 21:30:31 +0000 |
commit | 54aa8993baba2a9463a5b412c6c7575efa89bb67 (patch) | |
tree | 45c5cc0151b380a21b2f684914e32eccd765952c | |
parent | 183f5e38ee775f2e8c57bd061db80baf7da3b4c7 (diff) |
sw: check SfxViewFrame::Current()
SfxViewFrame::Current() is a festering wound, these ones look like they
were safe anyway, so no need to backport. But with enough checked static
analysis will kick in to flag new unchecked ones.
Change-Id: I359d71bda2ad1f8f720fae1f87a13eae94bb763c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144244
Tested-by: Caolán McNamara <caolanm@redhat.com>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | sw/source/uibase/sidebar/PageColumnControl.cxx | 12 | ||||
-rw-r--r-- | sw/source/uibase/sidebar/PageMarginControl.cxx | 42 | ||||
-rw-r--r-- | sw/source/uibase/sidebar/PageSizeControl.cxx | 32 | ||||
-rw-r--r-- | sw/source/uibase/uiview/viewsrch.cxx | 6 | ||||
-rw-r--r-- | sw/source/uibase/utlui/bookctrl.cxx | 6 |
5 files changed, 47 insertions, 51 deletions
diff --git a/sw/source/uibase/sidebar/PageColumnControl.cxx b/sw/source/uibase/sidebar/PageColumnControl.cxx index 18d4ef4248d1..bc8d45d2e46b 100644 --- a/sw/source/uibase/sidebar/PageColumnControl.cxx +++ b/sw/source/uibase/sidebar/PageColumnControl.cxx @@ -37,10 +37,10 @@ PageColumnControl::PageColumnControl(PageColumnPopup* pControl, weld::Widget* pP , m_xControl(pControl) { bool bLandscape = false; - if ( SfxViewFrame::Current() ) + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) { const SvxPageItem *pPageItem; - SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE, pPageItem ); + pViewFrm->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE, pPageItem ); bLandscape = pPageItem->IsLandscape(); } @@ -89,8 +89,8 @@ void PageColumnControl::ExecuteColumnChange( const sal_uInt16 nColumnType ) { SfxInt16Item aPageColumnTypeItem(SID_ATTR_PAGE_COLUMN); aPageColumnTypeItem.SetValue( nColumnType ); - if ( SfxViewFrame::Current() ) - SfxViewFrame::Current()->GetBindings().GetDispatcher()->ExecuteList(SID_ATTR_PAGE_COLUMN, + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) + pViewFrm->GetBindings().GetDispatcher()->ExecuteList(SID_ATTR_PAGE_COLUMN, SfxCallMode::RECORD, { &aPageColumnTypeItem }); } @@ -112,8 +112,8 @@ IMPL_LINK( PageColumnControl, ColumnButtonClickHdl_Impl, weld::Button&, rButton, IMPL_LINK_NOARG( PageColumnControl, MoreButtonClickHdl_Impl, weld::Button&, void ) { - if ( SfxViewFrame::Current() ) - SfxViewFrame::Current()->GetBindings().GetDispatcher()->Execute( FN_FORMAT_PAGE_COLUMN_DLG, SfxCallMode::ASYNCHRON ); + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) + pViewFrm->GetBindings().GetDispatcher()->Execute( FN_FORMAT_PAGE_COLUMN_DLG, SfxCallMode::ASYNCHRON ); m_xControl->EndPopupMode(); } diff --git a/sw/source/uibase/sidebar/PageMarginControl.cxx b/sw/source/uibase/sidebar/PageMarginControl.cxx index f6e0caa727bc..217c6f7d7fa7 100644 --- a/sw/source/uibase/sidebar/PageMarginControl.cxx +++ b/sw/source/uibase/sidebar/PageMarginControl.cxx @@ -53,19 +53,14 @@ namespace { FieldUnit lcl_GetFieldUnit() { - FieldUnit eUnit = FieldUnit::INCH; - const SfxUInt16Item* pItem = nullptr; - SfxItemState eState = SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_METRIC, pItem ); - if ( pItem && eState >= SfxItemState::DEFAULT ) + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) { - eUnit = static_cast<FieldUnit>(pItem->GetValue()); + const SfxUInt16Item* pItem = nullptr; + SfxItemState eState = pViewFrm->GetBindings().GetDispatcher()->QueryState(SID_ATTR_METRIC, pItem); + if (pItem && eState >= SfxItemState::DEFAULT) + return static_cast<FieldUnit>(pItem->GetValue()); } - else - { - return SfxModule::GetCurrentFieldUnit(); - } - - return eUnit; + return SfxModule::GetCurrentFieldUnit(); } MapUnit lcl_GetUnit() @@ -130,15 +125,15 @@ PageMarginControl::PageMarginControl(PageMarginPopup* pControl, weld::Widget* pP const SvxSizeItem* pSize = nullptr; const SvxLongLRSpaceItem* pLRItem = nullptr; const SvxLongULSpaceItem* pULItem = nullptr; - if ( SfxViewFrame::Current() ) + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) { const SvxPageItem* pPageItem; - SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE, pPageItem ); + pViewFrm->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE, pPageItem ); bLandscape = pPageItem->IsLandscape(); m_bMirrored = pPageItem->GetPageUsage() == SvxPageUsage::Mirror; - SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE_SIZE, pSize ); - SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE_LRSPACE, pLRItem ); - SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE_ULSPACE, pULItem ); + pViewFrm->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE_SIZE, pSize ); + pViewFrm->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE_LRSPACE, pLRItem ); + pViewFrm->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE_ULSPACE, pULItem ); } if ( pLRItem ) @@ -398,7 +393,8 @@ IMPL_LINK( PageMarginControl, SelectMarginHdl, weld::Button&, rControl, void ) if ( !bApplyNewPageMargins ) return; - const css::uno::Reference< css::document::XUndoManager > xUndoManager( getUndoManager( SfxViewFrame::Current()->GetFrame().GetFrameInterface() ) ); + SfxViewFrame* pViewFrm = SfxViewFrame::Current(); + const css::uno::Reference<css::document::XUndoManager> xUndoManager(pViewFrm ? getUndoManager(pViewFrm->GetFrame().GetFrameInterface()) : nullptr); if ( xUndoManager.is() ) xUndoManager->enterUndoContext( "" ); @@ -421,12 +417,12 @@ void PageMarginControl::ExecuteMarginLRChange( const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin ) { - if ( SfxViewFrame::Current() ) + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) { SvxLongLRSpaceItem aPageLRMarginItem( 0, 0, SID_ATTR_PAGE_LRSPACE ); aPageLRMarginItem.SetLeft( nPageLeftMargin ); aPageLRMarginItem.SetRight( nPageRightMargin ); - SfxViewFrame::Current()->GetBindings().GetDispatcher()->ExecuteList( SID_ATTR_PAGE_LRSPACE, + pViewFrm->GetBindings().GetDispatcher()->ExecuteList( SID_ATTR_PAGE_LRSPACE, SfxCallMode::RECORD, { &aPageLRMarginItem } ); } } @@ -435,23 +431,23 @@ void PageMarginControl::ExecuteMarginULChange( const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin ) { - if ( SfxViewFrame::Current() ) + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) { SvxLongULSpaceItem aPageULMarginItem( 0, 0, SID_ATTR_PAGE_ULSPACE ); aPageULMarginItem.SetUpper( nPageTopMargin ); aPageULMarginItem.SetLower( nPageBottomMargin ); - SfxViewFrame::Current()->GetBindings().GetDispatcher()->ExecuteList( SID_ATTR_PAGE_ULSPACE, + pViewFrm->GetBindings().GetDispatcher()->ExecuteList( SID_ATTR_PAGE_ULSPACE, SfxCallMode::RECORD, { &aPageULMarginItem } ); } } void PageMarginControl::ExecutePageLayoutChange( const bool bMirrored ) { - if ( SfxViewFrame::Current() ) + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) { SvxPageItem aPageItem( SID_ATTR_PAGE ); aPageItem.SetPageUsage( bMirrored ? SvxPageUsage::Mirror : SvxPageUsage::All ); - SfxViewFrame::Current()->GetBindings().GetDispatcher()->ExecuteList( SID_ATTR_PAGE, + pViewFrm->GetBindings().GetDispatcher()->ExecuteList( SID_ATTR_PAGE, SfxCallMode::RECORD, { &aPageItem } ); } } diff --git a/sw/source/uibase/sidebar/PageSizeControl.cxx b/sw/source/uibase/sidebar/PageSizeControl.cxx index 85c41ae80689..211ebece9e5e 100644 --- a/sw/source/uibase/sidebar/PageSizeControl.cxx +++ b/sw/source/uibase/sidebar/PageSizeControl.cxx @@ -45,19 +45,14 @@ namespace { FieldUnit lcl_GetFieldUnit() { - FieldUnit eUnit = FieldUnit::INCH; const SfxUInt16Item* pItem = nullptr; - SfxItemState eState = SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_METRIC, pItem ); - if ( pItem && eState >= SfxItemState::DEFAULT ) + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) { - eUnit = static_cast<FieldUnit>(pItem->GetValue()); + SfxItemState eState = pViewFrm->GetBindings().GetDispatcher()->QueryState(SID_ATTR_METRIC, pItem); + if (pItem && eState >= SfxItemState::DEFAULT) + return static_cast<FieldUnit>(pItem->GetValue()); } - else - { - return SfxModule::GetCurrentFieldUnit(); - } - - return eUnit; + return SfxModule::GetCurrentFieldUnit(); } MapUnit lcl_GetUnit() @@ -120,12 +115,12 @@ PageSizeControl::PageSizeControl(PageSizePopup* pControl, weld::Widget* pParent) bool bLandscape = false; const SvxSizeItem* pSize = nullptr; - if ( SfxViewFrame::Current() ) + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) { const SvxPageItem* pPageItem; - SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE, pPageItem ); + pViewFrm->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE, pPageItem ); bLandscape = pPageItem->IsLandscape(); - SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE_SIZE, pSize ); + pViewFrm->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE_SIZE, pSize ); } const LocaleDataWrapper& localeDataWrapper = Application::GetSettings().GetLocaleDataWrapper(); @@ -195,10 +190,11 @@ void PageSizeControl::ExecuteSizeChange( const Paper ePaper ) bool bLandscape = false; const SvxPageItem *pItem; MapUnit eUnit = lcl_GetUnit(); - if ( !SfxViewFrame::Current() ) + SfxViewFrame* pViewFrm = SfxViewFrame::Current(); + if (!pViewFrm) return; - SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE, pItem ); + pViewFrm->GetBindings().GetDispatcher()->QueryState( SID_ATTR_PAGE, pItem ); bLandscape = pItem->IsLandscape(); SvxSizeItem aPageSizeItem(SID_ATTR_PAGE_SIZE); @@ -209,7 +205,7 @@ void PageSizeControl::ExecuteSizeChange( const Paper ePaper ) } aPageSizeItem.SetSize( aPageSize ); - SfxViewFrame::Current()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_SIZE, + pViewFrm->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_SIZE, SfxCallMode::RECORD, { &aPageSizeItem }); } @@ -226,8 +222,8 @@ IMPL_LINK_NOARG(PageSizeControl, ImplSizeHdl, ValueSet*, void) IMPL_LINK_NOARG(PageSizeControl, MoreButtonClickHdl_Impl, weld::Button&, void) { - if ( SfxViewFrame::Current() ) - SfxViewFrame::Current()->GetDispatcher()->Execute( FN_FORMAT_PAGE_SETTING_DLG, SfxCallMode::ASYNCHRON ); + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) + pViewFrm->GetDispatcher()->Execute( FN_FORMAT_PAGE_SETTING_DLG, SfxCallMode::ASYNCHRON ); mxControl->EndPopupMode(); } diff --git a/sw/source/uibase/uiview/viewsrch.cxx b/sw/source/uibase/uiview/viewsrch.cxx index 269bce441ed8..4125f1b17343 100644 --- a/sw/source/uibase/uiview/viewsrch.cxx +++ b/sw/source/uibase/uiview/viewsrch.cxx @@ -830,10 +830,10 @@ SvxSearchDialog* SwView::GetSearchDialog() { #if HAVE_FEATURE_DESKTOP const sal_uInt16 nId = SvxSearchDialogWrapper::GetChildWindowId(); - SfxViewFrame* pFrame = SfxViewFrame::Current(); - if (!pFrame) + SfxViewFrame* pViewFrm = SfxViewFrame::Current(); + if (!pViewFrm) return nullptr; - SvxSearchDialogWrapper *pWrp = static_cast<SvxSearchDialogWrapper*>(pFrame->GetChildWindow(nId)); + SvxSearchDialogWrapper *pWrp = static_cast<SvxSearchDialogWrapper*>(pViewFrm->GetChildWindow(nId)); if (!pWrp) return nullptr; return pWrp->getDialog(); diff --git a/sw/source/uibase/utlui/bookctrl.cxx b/sw/source/uibase/utlui/bookctrl.cxx index 77567198257c..4cd9029fd339 100644 --- a/sw/source/uibase/utlui/bookctrl.cxx +++ b/sw/source/uibase/utlui/bookctrl.cxx @@ -75,6 +75,10 @@ void SwBookmarkControl::Command( const CommandEvent& rCEvt ) if( !(pWrtShell && pWrtShell->getIDocumentMarkAccess()->getAllMarksCount() > 0) ) return; + SfxViewFrame* pViewFrm = SfxViewFrame::Current(); + if (!pViewFrm) + return; + std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(nullptr, "modules/swriter/ui/bookmarkmenu.ui")); std::unique_ptr<weld::Menu> xPopup(xBuilder->weld_menu("menu")); @@ -99,7 +103,7 @@ void SwBookmarkControl::Command( const CommandEvent& rCEvt ) if (!sResult.isEmpty()) { SfxUInt16Item aBookmark( FN_STAT_BOOKMARK, aBookmarkIdx[sResult.toUInt32()] ); - SfxViewFrame::Current()->GetDispatcher()->ExecuteList(FN_STAT_BOOKMARK, + pViewFrm->GetDispatcher()->ExecuteList(FN_STAT_BOOKMARK, SfxCallMode::ASYNCHRON|SfxCallMode::RECORD, { &aBookmark }); } |