sfx2/source/appl/appopen.cxx | 7 ++-- sfx2/source/appl/appserv.cxx | 13 +++---- sfx2/source/notebookbar/NotebookbarTabControl.cxx | 15 ++++---- sfx2/source/notebookbar/SfxNotebookBar.cxx | 37 ++++++++++++---------- sfx2/source/sidebar/SidebarToolBox.cxx | 8 ++-- 5 files changed, 44 insertions(+), 36 deletions(-)
New commits: commit b07703963cad433e22fbe9c27f3bee5dc7a7ca63 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Thu Dec 15 19:56:30 2022 +0000 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Fri Dec 16 09:58:40 2022 +0000 sfx2: 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: I28a803be0429b97592d83d88d6c1db077fe31355 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144275 Tested-by: Caolán McNamara <caol...@redhat.com> Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/sfx2/source/appl/appopen.cxx b/sfx2/source/appl/appopen.cxx index 3d554b3cb816..4401fe396911 100644 --- a/sfx2/source/appl/appopen.cxx +++ b/sfx2/source/appl/appopen.cxx @@ -959,8 +959,11 @@ void SfxApplication::OpenDocExec_Impl( SfxRequest& rReq ) xTargetFrame = pUnoFrameItem->GetFrame(); } - if ( !pTargetFrame && !xTargetFrame.is() && SfxViewFrame::Current() ) - pTargetFrame = &SfxViewFrame::Current()->GetFrame(); + if (!pTargetFrame && !xTargetFrame.is()) + { + if (const SfxViewFrame* pViewFrame = SfxViewFrame::Current()) + pTargetFrame = &pViewFrame->GetFrame(); + } // check if caller has set a callback std::unique_ptr<SfxLinkItem> pLinkItem; diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx index 31d12cd43520..7b1b387e0f65 100644 --- a/sfx2/source/appl/appserv.cxx +++ b/sfx2/source/appl/appserv.cxx @@ -187,10 +187,11 @@ namespace SfxStringItem aURL(SID_FILE_NAME, ".component:Bibliography/View1"); SfxStringItem aRef(SID_REFERER, "private:user"); SfxStringItem aTarget(SID_TARGETNAME, "_blank"); - const SfxViewFrame* pViewFrame = SfxViewFrame::Current(); - if ( pViewFrame ) + if (const SfxViewFrame* pViewFrame = SfxViewFrame::Current()) + { pViewFrame->GetDispatcher()->ExecuteList(SID_OPENDOC, SfxCallMode::ASYNCHRON, { &aURL, &aRef, &aTarget }); + } } catch (const Exception &) { @@ -766,7 +767,7 @@ void SfxApplication::MiscExec_Impl( SfxRequest& rReq ) OUString aCurrentMode; SfxViewFrame* pViewFrame = SfxViewFrame::Current(); - if( pViewFrame ) + if (pViewFrame) { xCurrentFrame = pViewFrame->GetFrame().GetFrameInterface(); @@ -1085,8 +1086,7 @@ void SfxApplication::MiscExec_Impl( SfxRequest& rReq ) } case SID_TOOLBAR_LOCK: { - SfxViewFrame* pViewFrame = SfxViewFrame::Current(); - if (pViewFrame) + if (SfxViewFrame* pViewFrame = SfxViewFrame::Current()) { Reference<XFrame> xCurrentFrame; uno::Reference<uno::XComponentContext> xContext @@ -1571,8 +1571,7 @@ void SfxApplication::OfaExec_Impl( SfxRequest& rReq ) Reference <XFrame> xFrame(GetRequestFrame(rReq)); if ( !xFrame.is() ) { - const SfxViewFrame* pViewFrame = SfxViewFrame::Current(); - if ( pViewFrame ) + if (const SfxViewFrame* pViewFrame = SfxViewFrame::Current()) xFrame = pViewFrame->GetFrame().GetFrameInterface(); } diff --git a/sfx2/source/notebookbar/NotebookbarTabControl.cxx b/sfx2/source/notebookbar/NotebookbarTabControl.cxx index b4e7a7560efb..706add207855 100644 --- a/sfx2/source/notebookbar/NotebookbarTabControl.cxx +++ b/sfx2/source/notebookbar/NotebookbarTabControl.cxx @@ -53,11 +53,11 @@ public: { try { - if( SfxViewFrame::Current() ) + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) { Reference<XComponentContext> xContext = comphelper::getProcessComponentContext(); const Reference<XModuleManager> xModuleManager = ModuleManager::create( xContext ); - Reference<XFrame> xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface(); + Reference<XFrame> xFrame = pViewFrm->GetFrame().GetFrameInterface(); OUString aModuleName = xModuleManager->identify( xFrame ); Reference<XUIConfigurationManager> m_xConfigManager; @@ -95,11 +95,11 @@ public: { try { - if( SfxViewFrame::Current() ) + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) { Reference<XComponentContext> xContext = comphelper::getProcessComponentContext(); const Reference<XModuleManager> xModuleManager = ModuleManager::create( xContext ); - Reference<XFrame> xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface(); + Reference<XFrame> xFrame = pViewFrm->GetFrame().GetFrameInterface(); OUString aModuleName = xModuleManager->identify( xFrame ); Reference<XUIConfigurationManager> m_xConfigManager; @@ -237,7 +237,8 @@ bool NotebookbarTabControl::EventNotify( NotifyEvent& rNEvt ) void NotebookbarTabControl::StateChanged(StateChangedType nStateChange) { - if( !m_bInitialized && SfxViewFrame::Current() ) + SfxViewFrame* pViewFrm = SfxViewFrame::Current(); + if (!m_bInitialized && pViewFrm) { VclPtr<ShortcutsToolBox> pShortcuts = VclPtr<ShortcutsToolBox>::Create( this ); pShortcuts->Show(); @@ -249,7 +250,7 @@ void NotebookbarTabControl::StateChanged(StateChangedType nStateChange) m_bInitialized = true; } - if( m_bInitialized && m_bInvalidate && SfxViewFrame::Current() ) + if (m_bInitialized && m_bInvalidate && pViewFrm) { ToolBox* pToolBox = GetToolBox(); if( !pToolBox ) @@ -259,7 +260,7 @@ void NotebookbarTabControl::StateChanged(StateChangedType nStateChange) Reference<XComponentContext> xContext = comphelper::getProcessComponentContext(); const Reference<XModuleManager> xModuleManager = ModuleManager::create( xContext ); - m_xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface(); + m_xFrame = pViewFrm->GetFrame().GetFrameInterface(); OUString aModuleName = xModuleManager->identify( m_xFrame ); FillShortcutsToolBox( xContext, m_xFrame, aModuleName, pToolBox ); diff --git a/sfx2/source/notebookbar/SfxNotebookBar.cxx b/sfx2/source/notebookbar/SfxNotebookBar.cxx index ec1f5bf33c0d..80e8c896fe21 100644 --- a/sfx2/source/notebookbar/SfxNotebookBar.cxx +++ b/sfx2/source/notebookbar/SfxNotebookBar.cxx @@ -204,8 +204,8 @@ void SfxNotebookBar::CloseMethod(SystemWindow* pSysWindow) { if(pSysWindow->GetNotebookBar()) pSysWindow->CloseNotebookBar(); - if (SfxViewFrame::Current()) - SfxNotebookBar::ShowMenubar(SfxViewFrame::Current(), true); + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) + SfxNotebookBar::ShowMenubar(pViewFrm, true); } } @@ -228,9 +228,9 @@ bool SfxNotebookBar::IsActive(bool bConsiderSingleToolbar) vcl::EnumContext::Application eApp = vcl::EnumContext::Application::Any; - if (SfxViewFrame::Current()) + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) { - const Reference<frame::XFrame>& xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface(); + const Reference<frame::XFrame>& xFrame = pViewFrm->GetFrame().GetFrameInterface(); if (!xFrame.is()) return false; @@ -313,14 +313,17 @@ void SfxNotebookBar::ResetActiveToolbarModeToDefault(vcl::EnumContext::Applicati void SfxNotebookBar::ExecMethod(SfxBindings& rBindings, const OUString& rUIName) { // Save active UI file name - if ( !rUIName.isEmpty() && SfxViewFrame::Current() ) + if (!rUIName.isEmpty()) { - const Reference<frame::XFrame>& xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface(); - if (xFrame.is()) + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) { - const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( ::comphelper::getProcessComponentContext() ); - vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum(xModuleManager->identify(xFrame)); - lcl_setNotebookbarFileName( eApp, rUIName ); + const Reference<frame::XFrame>& xFrame = pViewFrm->GetFrame().GetFrameInterface(); + if (xFrame.is()) + { + const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( ::comphelper::getProcessComponentContext() ); + vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum(xModuleManager->identify(xFrame)); + lcl_setNotebookbarFileName( eApp, rUIName ); + } } } @@ -343,8 +346,9 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, { if (!pSysWindow) { - if (SfxViewFrame::Current() && SfxViewFrame::Current()->GetWindow().GetSystemWindow()) - pSysWindow = SfxViewFrame::Current()->GetWindow().GetSystemWindow(); + SfxViewFrame* pViewFrm = SfxViewFrame::Current(); + if (pViewFrm && pViewFrm->GetWindow().GetSystemWindow()) + pSysWindow = pViewFrm->GetWindow().GetSystemWindow(); else return false; } @@ -471,9 +475,9 @@ void SfxNotebookBar::ShowMenubar(bool bShow) uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext(); const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( xContext ); - if ( SfxViewFrame::Current() ) + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) { - xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface(); + xFrame = pViewFrm->GetFrame().GetFrameInterface(); eCurrentApp = vcl::EnumContext::GetApplicationEnum( xModuleManager->identify( xFrame ) ); } @@ -536,10 +540,11 @@ void SfxNotebookBar::ShowMenubar(SfxViewFrame const * pViewFrame, bool bShow) void SfxNotebookBar::ToggleMenubar() { - if (!SfxViewFrame::Current()) + SfxViewFrame* pViewFrm = SfxViewFrame::Current(); + if (!pViewFrm) return; - const Reference<frame::XFrame>& xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface(); + const Reference<frame::XFrame>& xFrame = pViewFrm->GetFrame().GetFrameInterface(); if (!xFrame.is()) return; diff --git a/sfx2/source/sidebar/SidebarToolBox.cxx b/sfx2/source/sidebar/SidebarToolBox.cxx index cc6bbec39080..8ca5ef92a1bb 100644 --- a/sfx2/source/sidebar/SidebarToolBox.cxx +++ b/sfx2/source/sidebar/SidebarToolBox.cxx @@ -67,9 +67,9 @@ SidebarToolBox::SidebarToolBox (vcl::Window* pParentWindow) SetToolboxButtonSize(GetDefaultButtonSize()); SvtMiscOptions().AddListenerLink(LINK(this, SidebarToolBox, ChangedIconSizeHandler)); - if (SfxViewFrame::Current()) + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) { - auto xFrame(SfxViewFrame::Current()->GetFrame().GetFrameInterface()); + auto xFrame(pViewFrm->GetFrame().GetFrameInterface()); auto xWidget(VCLUnoHelper::GetInterface(this)); mxImageController = sfx2::sidebar::ControllerFactory::CreateImageController(xFrame, xWidget); } @@ -253,10 +253,10 @@ IMPL_LINK_NOARG(SidebarToolBox, ChangedIconSizeHandler, LinkParamNone*, void) // dropdown. The controller should know better than us what it was. xController->updateImage(); } - else if (SfxViewFrame::Current()) + else if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) { OUString aCommandURL = GetItemCommand(it.first); - css::uno::Reference<frame::XFrame> xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface(); + css::uno::Reference<frame::XFrame> xFrame = pViewFrm->GetFrame().GetFrameInterface(); Image aImage = vcl::CommandInfoProvider::GetImageForCommand(aCommandURL, xFrame, GetImageSize()); SetItemImage(it.first, aImage); }