include/sfx2/shell.hxx                              |    4 -
 sc/source/ui/condformat/condformatdlgentry.cxx      |   66 ++++++++++---------
 sc/source/ui/drawfunc/drawsh2.cxx                   |   23 ++++--
 sd/source/ui/func/fubullet.cxx                      |    7 +-
 sd/source/ui/tools/EventMultiplexer.cxx             |    5 -
 sd/source/ui/view/outlview.cxx                      |    4 -
 sfx2/source/doc/objserv.cxx                         |   67 +++++++++++---------
 sfx2/source/view/viewsh.cxx                         |    5 +
 sw/source/core/doc/docdesc.cxx                      |   20 +++--
 sw/source/core/txtnode/OnlineAccessibilityCheck.cxx |   15 ++--
 sw/source/uibase/shells/frmsh.cxx                   |    4 -
 11 files changed, 130 insertions(+), 90 deletions(-)

New commits:
commit 587870297963b35ae8953adadbdc5ea8933004a7
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Fri May 31 12:40:45 2024 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Jun 4 09:03:31 2024 +0200

    sfx2: use SAL_RET_MAYBENULL in GetDispatcher() and GetFrame()
    
    Change-Id: Ic9876dbdd0dc0ce887a6eb135bd411f8e3dc9e12
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168288
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/include/sfx2/shell.hxx b/include/sfx2/shell.hxx
index b454547970a5..420c8d578b95 100644
--- a/include/sfx2/shell.hxx
+++ b/include/sfx2/shell.hxx
@@ -367,7 +367,7 @@ public:
         The returned pointer is only valid in the immediate context of the 
method
         call.
         */
-    SfxDispatcher*              GetDispatcher() const;
+    SAL_RET_MAYBENULL SfxDispatcher*              GetDispatcher() const;
 
     /**
         This method returns a pointer to the <SfxViewFrame> to which this 
SfxShell
@@ -388,7 +388,7 @@ public:
 
         <SfxViewShell::GetViewFrame()const>
         */
-    SfxViewFrame*               GetFrame() const;
+    SAL_RET_MAYBENULL SfxViewFrame*               GetFrame() const;
 
     virtual bool                HasUIFeature(SfxShellFeature nFeature) const;
     void                        UIFeatureChanged();
diff --git a/sc/source/ui/condformat/condformatdlgentry.cxx 
b/sc/source/ui/condformat/condformatdlgentry.cxx
index f08d23bd977b..066958daa4b8 100644
--- a/sc/source/ui/condformat/condformatdlgentry.cxx
+++ b/sc/source/ui/condformat/condformatdlgentry.cxx
@@ -448,42 +448,44 @@ void StyleSelect(weld::Window* pDialogParent, 
weld::ComboBox& rLbStyle, const Sc
         // (SetDispatcherLock would affect all Calc documents)
         if (ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell())
         {
-            SfxDispatcher* pDisp = pViewShell->GetDispatcher();
-            bool bLocked = pDisp->IsLocked();
-            if (bLocked)
-                pDisp->Lock(false);
-
-            // Execute the "new style" slot, complete with undo and all 
necessary updates.
-            // The return value (SfxUInt16Item) is ignored, look for new 
styles instead.
-            pDisp->ExecuteList(SID_STYLE_NEW,
-                SfxCallMode::SYNCHRON | SfxCallMode::RECORD,
-                { &aFamilyItem, &aRefItem }, { &aDialogParent });
-
-            if (bLocked)
-                pDisp->Lock(true);
-
-            // Find the new style and add it into the style list boxes
-            SfxStyleSheetIterator aStyleIter( pDoc->GetStyleSheetPool(), 
SfxStyleFamily::Para );
-            bool bFound = false;
-            for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle && 
!bFound; pStyle = aStyleIter.Next() )
+            if (SfxDispatcher* pDisp = pViewShell->GetDispatcher())
             {
-                const OUString& aName = pStyle->GetName();
-                if (rLbStyle.find_text(aName) == -1)    // all lists contain 
the same entries
+                bool bLocked = pDisp->IsLocked();
+                if (bLocked)
+                    pDisp->Lock(false);
+
+                // Execute the "new style" slot, complete with undo and all 
necessary updates.
+                // The return value (SfxUInt16Item) is ignored, look for new 
styles instead.
+                pDisp->ExecuteList(SID_STYLE_NEW,
+                    SfxCallMode::SYNCHRON | SfxCallMode::RECORD,
+                    { &aFamilyItem, &aRefItem }, { &aDialogParent });
+
+                if (bLocked)
+                    pDisp->Lock(true);
+
+                // Find the new style and add it into the style list boxes
+                SfxStyleSheetIterator aStyleIter( pDoc->GetStyleSheetPool(), 
SfxStyleFamily::Para );
+                bool bFound = false;
+                for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle 
&& !bFound; pStyle = aStyleIter.Next() )
                 {
-                    for( sal_Int32 i = 1, n = rLbStyle.get_count(); i <= n && 
!bFound; ++i)
+                    const OUString& aName = pStyle->GetName();
+                    if (rLbStyle.find_text(aName) == -1)    // all lists 
contain the same entries
                     {
-                        OUString aStyleName = 
ScGlobal::getCharClass().uppercase(rLbStyle.get_text(i));
-                        if( i == n )
+                        for( sal_Int32 i = 1, n = rLbStyle.get_count(); i <= n 
&& !bFound; ++i)
                         {
-                            rLbStyle.append_text(aName);
-                            rLbStyle.set_active_text(aName);
-                            bFound = true;
-                        }
-                        else if( aStyleName > 
ScGlobal::getCharClass().uppercase(aName) )
-                        {
-                            rLbStyle.insert_text(i, aName);
-                            rLbStyle.set_active_text(aName);
-                            bFound = true;
+                            OUString aStyleName = 
ScGlobal::getCharClass().uppercase(rLbStyle.get_text(i));
+                            if( i == n )
+                            {
+                                rLbStyle.append_text(aName);
+                                rLbStyle.set_active_text(aName);
+                                bFound = true;
+                            }
+                            else if( aStyleName > 
ScGlobal::getCharClass().uppercase(aName) )
+                            {
+                                rLbStyle.insert_text(i, aName);
+                                rLbStyle.set_active_text(aName);
+                                bFound = true;
+                            }
                         }
                     }
                 }
diff --git a/sc/source/ui/drawfunc/drawsh2.cxx 
b/sc/source/ui/drawfunc/drawsh2.cxx
index 418d92d00f32..04a27dbfd35c 100644
--- a/sc/source/ui/drawfunc/drawsh2.cxx
+++ b/sc/source/ui/drawfunc/drawsh2.cxx
@@ -59,12 +59,14 @@ using namespace com::sun::star;
 
 ScDrawShell::ScDrawShell( ScViewData& rData ) :
     SfxShell(rData.GetViewShell()),
-    rViewData( rData ),
-    mpSelectionChangeHandler(new svx::sidebar::SelectionChangeHandler(
-            [this] () { return this->GetSidebarContextName(); },
-            GetFrame()->GetFrame().GetController(),
-            vcl::EnumContext::Context::Cell))
+    rViewData( rData )
 {
+    SfxViewFrame* pFrame = GetFrame();
+    assert(pFrame);
+    mpSelectionChangeHandler = new svx::sidebar::SelectionChangeHandler(
+            [this] () { return this->GetSidebarContextName(); },
+            pFrame->GetFrame().GetController(),
+            vcl::EnumContext::Context::Cell);
     SetPool( &rViewData.GetScDrawView()->GetModel().GetItemPool() );
     SfxUndoManager* pMgr = rViewData.GetSfxDocShell()->GetUndoManager();
     SetUndoManager( pMgr );
@@ -548,10 +550,13 @@ void ScDrawShell::GetDrawAttrStateForIFBX( SfxItemSet& 
rSet )
 
 void ScDrawShell::Activate (const bool)
 {
-    ContextChangeEventMultiplexer::NotifyContextChange(
-        GetFrame()->GetFrame().GetController(),
-        vcl::EnumContext::GetContextEnum(
-            GetSidebarContextName()));
+    if (SfxViewFrame* pFrame = GetFrame())
+    {
+        ContextChangeEventMultiplexer::NotifyContextChange(
+            pFrame->GetFrame().GetController(),
+            vcl::EnumContext::GetContextEnum(
+                GetSidebarContextName()));
+    }
 }
 
 const OUString & ScDrawShell::GetSidebarContextName()
diff --git a/sd/source/ui/func/fubullet.cxx b/sd/source/ui/func/fubullet.cxx
index ddc8d5c972fe..a19e6ff51a3a 100644
--- a/sd/source/ui/func/fubullet.cxx
+++ b/sd/source/ui/func/fubullet.cxx
@@ -189,7 +189,12 @@ void FuBullet::InsertSpecialCharacter( SfxRequest const & 
rReq )
             aSet.Put( *pFontItem );
 
         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
-        auto xFrame = mpViewShell ? 
mpViewShell->GetFrame()->GetFrame().GetFrameInterface() : nullptr;
+        css::uno::Reference<css::frame::XFrame> xFrame;
+        if (mpViewShell)
+        {
+            if (SfxViewFrame* pFrame = mpViewShell->GetFrame())
+                xFrame = pFrame->GetFrame().GetFrameInterface();
+        }
         VclPtr<SfxAbstractDialog> pDlg( 
pFact->CreateCharMapDialog(mpView->GetViewShell()->GetFrameWeld(), aSet,
             xFrame) );
 
diff --git a/sd/source/ui/tools/EventMultiplexer.cxx 
b/sd/source/ui/tools/EventMultiplexer.cxx
index 4943787d03f2..122ac736a4e8 100644
--- a/sd/source/ui/tools/EventMultiplexer.cxx
+++ b/sd/source/ui/tools/EventMultiplexer.cxx
@@ -193,8 +193,9 @@ EventMultiplexer::Implementation::Implementation 
(ViewShellBase& rBase)
 {
     // Connect to the frame to listen for controllers being exchanged.
     // Listen to changes of certain properties.
-    Reference<frame::XFrame> xFrame =
-        mrBase.GetFrame()->GetFrame().GetFrameInterface();
+    Reference<frame::XFrame> xFrame;
+    if (SfxViewFrame* pFrame = mrBase.GetFrame())
+        xFrame = pFrame->GetFrame().GetFrameInterface();
     mxFrameWeak = xFrame;
     if (xFrame.is())
     {
diff --git a/sd/source/ui/view/outlview.cxx b/sd/source/ui/view/outlview.cxx
index 61365c8cfbf2..c781d710c877 100644
--- a/sd/source/ui/view/outlview.cxx
+++ b/sd/source/ui/view/outlview.cxx
@@ -114,7 +114,9 @@ OutlineView::OutlineView( DrawDocShell& rDocSh, 
vcl::Window* pWindow, OutlineVie
     Link<tools::EventMultiplexerEvent&,void> aLink( 
LINK(this,OutlineView,EventMultiplexerListener) );
     
mrOutlineViewShell.GetViewShellBase().GetEventMultiplexer()->AddEventListener(aLink);
 
-    Reference<XFrame> xFrame = 
mrOutlineViewShell.GetViewShellBase().GetFrame()->GetFrame().GetFrameInterface();
+    Reference<XFrame> xFrame;
+    if (SfxViewFrame* pFrame = 
mrOutlineViewShell.GetViewShellBase().GetFrame())
+        xFrame = pFrame->GetFrame().GetFrameInterface();
     maSlideImage = 
vcl::CommandInfoProvider::GetImageForCommand(u".uno:ShowSlide"_ustr, xFrame, 
vcl::ImageType::Size26);
 
     // Tell undo manager of the document about the undo manager of the
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index 21ac6c4cf664..a7863609e617 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -331,14 +331,17 @@ void SfxObjectShell::CheckOut( )
         xCmisDoc->checkOut( );
 
         // Remove the info bar
-        SfxViewFrame* pViewFrame = GetFrame();
-        pViewFrame->RemoveInfoBar( u"checkout" );
+        if (SfxViewFrame* pViewFrame = GetFrame())
+            pViewFrame->RemoveInfoBar( u"checkout" );
     }
     catch ( const uno::RuntimeException& e )
     {
-        std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(GetFrame()->GetFrameWeld(),
-                                                  VclMessageType::Warning, 
VclButtonsType::Ok, e.Message));
-        xBox->run();
+        if (SfxViewFrame* pFrame = GetFrame())
+        {
+            std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(pFrame->GetFrameWeld(),
+                                                      VclMessageType::Warning, 
VclButtonsType::Ok, e.Message));
+            xBox->run();
+        }
     }
 }
 
@@ -355,9 +358,12 @@ void SfxObjectShell::CancelCheckOut( )
     }
     catch ( const uno::RuntimeException& e )
     {
-        std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(GetFrame()->GetFrameWeld(),
-                                                  VclMessageType::Warning, 
VclButtonsType::Ok, e.Message));
-        xBox->run();
+        if (SfxViewFrame* pFrame = GetFrame())
+        {
+            std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(pFrame->GetFrameWeld(),
+                                                      VclMessageType::Warning, 
VclButtonsType::Ok, e.Message));
+            xBox->run();
+        }
     }
 }
 
@@ -367,20 +373,26 @@ void SfxObjectShell::CheckIn( )
     {
         uno::Reference< document::XCmisDocument > xCmisDoc( GetModel(), 
uno::UNO_QUERY_THROW );
         // Pop up dialog to ask for comment and major
-        SfxCheckinDialog checkinDlg(GetFrame()->GetFrameWeld());
-        if (checkinDlg.run() == RET_OK)
+        if (SfxViewFrame* pFrame = GetFrame())
         {
-            xCmisDoc->checkIn(checkinDlg.IsMajor(), checkinDlg.GetComment());
-            uno::Reference< util::XModifiable > xModifiable( GetModel( ), 
uno::UNO_QUERY );
-            if ( xModifiable.is( ) )
-                xModifiable->setModified( false );
+            SfxCheckinDialog checkinDlg(pFrame->GetFrameWeld());
+            if (checkinDlg.run() == RET_OK)
+            {
+                xCmisDoc->checkIn(checkinDlg.IsMajor(), 
checkinDlg.GetComment());
+                uno::Reference< util::XModifiable > xModifiable( GetModel( ), 
uno::UNO_QUERY );
+                if ( xModifiable.is( ) )
+                    xModifiable->setModified( false );
+            }
         }
     }
     catch ( const uno::RuntimeException& e )
     {
-        std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(GetFrame()->GetFrameWeld(),
-                                                  VclMessageType::Warning, 
VclButtonsType::Ok, e.Message));
-        xBox->run();
+        if (SfxViewFrame* pFrame = GetFrame())
+        {
+            std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(pFrame->GetFrameWeld(),
+                                                      VclMessageType::Warning, 
VclButtonsType::Ok, e.Message));
+            xBox->run();
+        }
     }
 }
 
@@ -393,9 +405,12 @@ uno::Sequence< document::CmisVersion > 
SfxObjectShell::GetCmisVersions( ) const
     }
     catch ( const uno::RuntimeException& e )
     {
-        std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(GetFrame()->GetFrameWeld(),
-                                                  VclMessageType::Warning, 
VclButtonsType::Ok, e.Message));
-        xBox->run();
+        if (SfxViewFrame* pFrame = GetFrame())
+        {
+            std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(pFrame->GetFrameWeld(),
+                                                      VclMessageType::Warning, 
VclButtonsType::Ok, e.Message));
+            xBox->run();
+        }
     }
     return uno::Sequence< document::CmisVersion > ( );
 }
@@ -552,8 +567,7 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
                 // Reload to show how the PDF actually looks like after 
signing. This also
                 // changes "finish signing" on the infobar back to "sign 
document" as a side
                 // effect.
-                SfxViewFrame* pFrame = GetFrame();
-                if (pFrame)
+                if (SfxViewFrame* pFrame = GetFrame())
                 {
                     // Store current page before reload.
                     SfxAllItemSet aSet(SfxGetpApp()->GetPool());
@@ -1244,8 +1258,7 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
                 const SfxBoolItem* saveTo = 
rReq.GetArg<SfxBoolItem>(SID_SAVETO);
                 if (saveTo == nullptr || !saveTo->GetValue())
                 {
-                    SfxViewFrame *pFrame = GetFrame();
-                    if (pFrame)
+                    if (SfxViewFrame* pFrame = GetFrame())
                         pFrame->RemoveInfoBar(u"readonly");
                     SetReadOnlyUI(false);
                 }
@@ -1356,8 +1369,7 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
                 CancelCheckOut( );
 
                 // Reload the document as we may still have local changes
-                SfxViewFrame *pFrame = GetFrame();
-                if ( pFrame )
+                if (SfxViewFrame* pFrame = GetFrame())
                     pFrame->GetDispatcher()->Execute(SID_RELOAD);
             }
             break;
@@ -2226,8 +2238,7 @@ void SfxObjectShell::SignSignatureLine(weld::Window* 
pDialogParent,
 
     // Reload the document to get the updated graphic
     // FIXME: Update just the signature line graphic instead of reloading the 
document
-    SfxViewFrame *pFrame = GetFrame();
-    if (pFrame)
+    if (SfxViewFrame* pFrame = GetFrame())
         pFrame->GetDispatcher()->Execute(SID_RELOAD);
 }
 
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index b5f010e9b0be..068648d56981 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -2437,7 +2437,10 @@ ErrCode SfxViewShell::DoVerb(sal_Int32 /*nVerb*/)
 void SfxViewShell::OutplaceActivated( bool bActive )
 {
     if ( !bActive )
-        GetFrame()->GetFrame().Appear();
+    {
+        if (SfxViewFrame* pFrame = GetFrame())
+            pFrame->GetFrame().Appear();
+    }
 }
 
 void SfxViewShell::UIActivating( SfxInPlaceClient* /*pClient*/ )
diff --git a/sw/source/core/doc/docdesc.cxx b/sw/source/core/doc/docdesc.cxx
index 0209c6af49ab..d497d4632fb4 100644
--- a/sw/source/core/doc/docdesc.cxx
+++ b/sw/source/core/doc/docdesc.cxx
@@ -655,15 +655,19 @@ void SwDoc::ChgPageDesc( size_t i, const SwPageDesc 
&rChged )
     }
     getIDocumentState().SetModified();
 
-    SfxBindings* pBindings =
-        ( GetDocShell() && GetDocShell()->GetDispatcher() ) ? 
GetDocShell()->GetDispatcher()->GetBindings() : nullptr;
-    if ( pBindings )
+    if (SwDocShell* pShell = GetDocShell())
     {
-        pBindings->Invalidate( SID_ATTR_PAGE_COLUMN );
-        pBindings->Invalidate( SID_ATTR_PAGE );
-        pBindings->Invalidate( SID_ATTR_PAGE_SIZE );
-        pBindings->Invalidate( SID_ATTR_PAGE_ULSPACE );
-        pBindings->Invalidate( SID_ATTR_PAGE_LRSPACE );
+        if (SfxDispatcher* pDispatcher = pShell->GetDispatcher())
+        {
+            if (SfxBindings* pBindings = pDispatcher->GetBindings())
+            {
+                pBindings->Invalidate( SID_ATTR_PAGE_COLUMN );
+                pBindings->Invalidate( SID_ATTR_PAGE );
+                pBindings->Invalidate( SID_ATTR_PAGE_SIZE );
+                pBindings->Invalidate( SID_ATTR_PAGE_ULSPACE );
+                pBindings->Invalidate( SID_ATTR_PAGE_LRSPACE );
+            }
+        }
     }
 
     //h/f of first-left page must not be unique but same as first master or 
left
diff --git a/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx 
b/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx
index 251efbd61b08..d861084d7018 100644
--- a/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx
+++ b/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx
@@ -120,11 +120,16 @@ void OnlineAccessibilityCheck::updateNodeStatus(SwNode* 
pNode, bool bIssueObject
 
 void OnlineAccessibilityCheck::updateStatusbar()
 {
-    SfxBindings* pBindings = m_rDocument.GetDocShell() && 
m_rDocument.GetDocShell()->GetDispatcher()
-                                 ? 
m_rDocument.GetDocShell()->GetDispatcher()->GetBindings()
-                                 : nullptr;
-    if (pBindings)
-        pBindings->Invalidate(FN_STAT_ACCESSIBILITY_CHECK);
+    if (SwDocShell* pShell = m_rDocument.GetDocShell())
+    {
+        if (SfxDispatcher* pDispatcher = pShell->GetDispatcher())
+        {
+            if (SfxBindings* pBindings = pDispatcher->GetBindings())
+            {
+                pBindings->Invalidate(FN_STAT_ACCESSIBILITY_CHECK);
+            }
+        }
+    }
 }
 
 void OnlineAccessibilityCheck::runAccessibilityCheck(SwNode* pNode)
diff --git a/sw/source/uibase/shells/frmsh.cxx 
b/sw/source/uibase/shells/frmsh.cxx
index 605475cc935e..765b4855ef8d 100644
--- a/sw/source/uibase/shells/frmsh.cxx
+++ b/sw/source/uibase/shells/frmsh.cxx
@@ -879,7 +879,9 @@ void SwFrameShell::GetState(SfxItemSet& rSet)
                                 }
                             }
                         }
-                        OUString 
aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(GetFrame()->GetFrame().GetFrameInterface()));
+                        OUString aModuleName;
+                        if (SfxViewFrame* pFrame = GetFrame())
+                            aModuleName = 
vcl::CommandInfoProvider::GetModuleIdentifier(pFrame->GetFrame().GetFrameInterface());
                         switch (nWhich)
                         {
                             case SID_OBJECT_ALIGN_UP :

Reply via email to