sw/source/ui/fldui/fldpage.cxx            |    3 +
 sw/source/ui/misc/pggrid.cxx              |    3 -
 sw/source/uibase/app/appenv.cxx           |    3 +
 sw/source/uibase/app/applab.cxx           |    1 
 sw/source/uibase/dbui/dbmgr.cxx           |   84 ++++++++++++++++--------------
 sw/source/uibase/docvw/AnnotationWin.cxx  |   14 +++--
 sw/source/uibase/docvw/AnnotationWin2.cxx |   82 +++++++++++++++++++----------
 sw/source/uibase/docvw/edtwin2.cxx        |    6 --
 sw/source/uibase/misc/redlndlg.cxx        |   37 +++++++++++--
 sw/source/uibase/ribbar/inputwin.cxx      |   13 ++--
 sw/source/uibase/shells/langhelper.cxx    |   31 ++++++-----
 sw/source/uibase/uiview/view.cxx          |   19 +++---
 sw/source/uibase/uno/unomailmerge.cxx     |    2 
 sw/source/uibase/uno/unotxdoc.cxx         |   29 +++++-----
 sw/source/uibase/uno/unotxvw.cxx          |   25 ++++----
 sw/source/uibase/utlui/content.cxx        |   12 ++--
 sw/source/uibase/utlui/navipi.cxx         |    5 +
 17 files changed, 224 insertions(+), 145 deletions(-)

New commits:
commit 59cfe55463526332e0ae91882cd8ccd187aa91e2
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Mon Feb 20 16:29:19 2023 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Feb 22 08:11:44 2023 +0000

    sw: check GetWrtShellPtr()
    
    Change-Id: I8d99e9108f6163eafb7576603826f8d02a0ff416
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147336
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    (cherry picked from commit 6cb076f6b08668cf2a0490fe17ce34e74969702a)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147362
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/source/ui/fldui/fldpage.cxx b/sw/source/ui/fldui/fldpage.cxx
index 71ff3d33246e..0ba0d536a78d 100644
--- a/sw/source/ui/fldui/fldpage.cxx
+++ b/sw/source/ui/fldui/fldpage.cxx
@@ -120,6 +120,9 @@ void SwFieldPage::InsertField(SwFieldTypesEnum nTypeId, 
sal_uInt16 nSubType, con
     SwView* pView = GetActiveView();
     SwWrtShell *pSh = m_pWrtShell ? m_pWrtShell : pView->GetWrtShellPtr();
 
+    if (!pSh)
+        return;
+
     if (!IsFieldEdit())   // insert new field
     {
         SwInsertField_Data aData(nTypeId, nSubType, rPar1, rPar2, nFormatId, 
nullptr, cSeparator, bIsAutomaticLanguage );
diff --git a/sw/source/ui/misc/pggrid.cxx b/sw/source/ui/misc/pggrid.cxx
index 4d26eead12d9..1e5f11332e67 100644
--- a/sw/source/ui/misc/pggrid.cxx
+++ b/sw/source/ui/misc/pggrid.cxx
@@ -93,8 +93,7 @@ SwTextGridPage::SwTextGridPage(weld::Container* pPage, 
weld::DialogController* p
     SwView *pView   = ::GetActiveView();
     if( pView )
     {
-        SwWrtShell* pSh = pView->GetWrtShellPtr();
-        if( pSh )
+        if (SwWrtShell* pSh = pView->GetWrtShellPtr())
         {
             m_bSquaredMode = pSh->GetDoc()->IsSquaredPageMode();
         }
diff --git a/sw/source/uibase/app/appenv.cxx b/sw/source/uibase/app/appenv.cxx
index 86b92c8aabf7..6c744867ada1 100644
--- a/sw/source/uibase/app/appenv.cxx
+++ b/sw/source/uibase/app/appenv.cxx
@@ -150,6 +150,9 @@ void SwModule::InsertEnv( SfxRequest& rReq )
     pNewView->AttrChangedNotify(nullptr); // so that SelectShell is being 
called
     pSh = pNewView->GetWrtShellPtr();
 
+    if (!pSh)
+        return;
+
     OUString aTmp = SwResId(STR_ENV_TITLE) + OUString::number( ++nTitleNo );
     xDocSh->SetTitle( aTmp );
 
diff --git a/sw/source/uibase/app/applab.cxx b/sw/source/uibase/app/applab.cxx
index 7ee421ed5ee7..ac6d69ca2849 100644
--- a/sw/source/uibase/app/applab.cxx
+++ b/sw/source/uibase/app/applab.cxx
@@ -207,6 +207,7 @@ void SwModule::InsertLab(SfxRequest& rReq, bool bLabel)
     SwWrtShell *pSh = pNewView->GetWrtShellPtr();
     OSL_ENSURE( pSh, "missing WrtShell" );
 
+    if (pSh)
     {   // block for locks the dispatcher!!
 
         SwWait aWait( static_cast<SwDocShell&>(*xDocSh), true );
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index a62bd62b869b..defeec646801 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -919,49 +919,52 @@ static SfxObjectShell* lcl_CreateWorkingDocument(
     }
 
     SwView* pWorkView = static_cast< SwView* >( pWorkFrame->GetViewShell() );
-    SwWrtShell* pWorkWrtShell = pWorkView->GetWrtShellPtr();
-    pWorkWrtShell->GetViewOptions()->SetIdle( false );
-    pWorkView->AttrChangedNotify(nullptr);// in order for SelectShell to be 
called
-    SwDoc* pWorkDoc = pWorkWrtShell->GetDoc();
-    pWorkDoc->GetIDocumentUndoRedo().DoUndo( false );
-    pWorkDoc->ReplaceDocumentProperties( *pSourceDoc );
-
-    // import print settings
-    const SwPrintData &rPrintData = 
pSourceDoc->getIDocumentDeviceAccess().getPrintData();
-    pWorkDoc->getIDocumentDeviceAccess().setPrintData(rPrintData);
-    const JobSetup *pJobSetup = 
pSourceDoc->getIDocumentDeviceAccess().getJobsetup();
-    if (pJobSetup)
-        pWorkDoc->getIDocumentDeviceAccess().setJobsetup(*pJobSetup);
-
-    if( aType == WorkingDocType::TARGET )
-    {
-        assert( !ppDBManager );
-        pWorkDoc->SetInMailMerge( true );
-        pWorkWrtShell->SetLabelDoc( false );
-    }
-    else
+
+    if (SwWrtShell* pWorkWrtShell = pWorkView->GetWrtShellPtr())
     {
-        // We have to swap the DBmanager of the new doc, so we also need input
-        assert(ppDBManager && *ppDBManager);
-        SwDBManager *pWorkDBManager = pWorkDoc->GetDBManager();
-        pWorkDoc->SetDBManager( *ppDBManager );
-        *ppDBManager = pWorkDBManager;
+        pWorkWrtShell->GetViewOptions()->SetIdle( false );
+        pWorkView->AttrChangedNotify(nullptr);// in order for SelectShell to 
be called
+        SwDoc* pWorkDoc = pWorkWrtShell->GetDoc();
+        pWorkDoc->GetIDocumentUndoRedo().DoUndo( false );
+        pWorkDoc->ReplaceDocumentProperties( *pSourceDoc );
+
+        // import print settings
+        const SwPrintData &rPrintData = 
pSourceDoc->getIDocumentDeviceAccess().getPrintData();
+        pWorkDoc->getIDocumentDeviceAccess().setPrintData(rPrintData);
+        const JobSetup *pJobSetup = 
pSourceDoc->getIDocumentDeviceAccess().getJobsetup();
+        if (pJobSetup)
+            pWorkDoc->getIDocumentDeviceAccess().setJobsetup(*pJobSetup);
 
-        if( aType == WorkingDocType::SOURCE )
+        if( aType == WorkingDocType::TARGET )
         {
-            // the GetDBData call constructs the data, if it's missing - kind 
of const...
-            pWorkWrtShell->ChgDBData( 
const_cast<SwDoc*>(pSourceDoc)->GetDBData() );
-            // some DocumentSettings are currently not copied by 
SwDoc::CreateCopy
-            pWorkWrtShell->SetLabelDoc( rSourceWrtShell.IsLabelDoc() );
-            pWorkDoc->getIDocumentState().ResetModified();
+            assert( !ppDBManager );
+            pWorkDoc->SetInMailMerge( true );
+            pWorkWrtShell->SetLabelDoc( false );
         }
         else
-            pWorkDoc->getIDocumentLinksAdministration().EmbedAllLinks();
-    }
+        {
+            // We have to swap the DBmanager of the new doc, so we also need 
input
+            assert(ppDBManager && *ppDBManager);
+            SwDBManager *pWorkDBManager = pWorkDoc->GetDBManager();
+            pWorkDoc->SetDBManager( *ppDBManager );
+            *ppDBManager = pWorkDBManager;
+
+            if( aType == WorkingDocType::SOURCE )
+            {
+                // the GetDBData call constructs the data, if it's missing - 
kind of const...
+                pWorkWrtShell->ChgDBData( 
const_cast<SwDoc*>(pSourceDoc)->GetDBData() );
+                // some DocumentSettings are currently not copied by 
SwDoc::CreateCopy
+                pWorkWrtShell->SetLabelDoc( rSourceWrtShell.IsLabelDoc() );
+                pWorkDoc->getIDocumentState().ResetModified();
+            }
+            else
+                pWorkDoc->getIDocumentLinksAdministration().EmbedAllLinks();
+        }
 
-    if( pView )     *pView     = pWorkView;
-    if( pWrtShell ) *pWrtShell = pWorkWrtShell;
-    if( pDoc )      *pDoc      = pWorkDoc;
+        if( pView )     *pView     = pWorkView;
+        if( pWrtShell ) *pWrtShell = pWorkWrtShell;
+        if( pDoc )      *pDoc      = pWorkDoc;
+    }
 
     return xWorkObjectShell.get();
 }
@@ -1223,8 +1226,11 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* 
pSourceShell,
         else if( pTargetView )
         {
             pTargetShell = pTargetView->GetWrtShellPtr();
-            pTargetDoc = pTargetShell->GetDoc();
-            xTargetDocShell = pTargetView->GetDocShell();
+            if (pTargetShell)
+            {
+                pTargetDoc = pTargetShell->GetDoc();
+                xTargetDocShell = pTargetView->GetDocShell();
+            }
         }
 
         if( bCreateSingleFile )
diff --git a/sw/source/uibase/docvw/AnnotationWin.cxx 
b/sw/source/uibase/docvw/AnnotationWin.cxx
index 685dcbb5ce94..5e93aeb2c8e5 100644
--- a/sw/source/uibase/docvw/AnnotationWin.cxx
+++ b/sw/source/uibase/docvw/AnnotationWin.cxx
@@ -207,8 +207,11 @@ void SwAnnotationWin::SetResolved(bool resolved)
 {
     bool oldState = IsResolved();
     
static_cast<SwPostItField*>(mpFormatField->GetField())->SetResolved(resolved);
-    const SwViewOption* pVOpt = mrView.GetWrtShellPtr()->GetViewOptions();
-    mrSidebarItem.mbShow = !IsResolved() || (pVOpt->IsResolvedPostIts());
+    if (SwWrtShell* pWrtShell = mrView.GetWrtShellPtr())
+    {
+        const SwViewOption* pVOpt = pWrtShell->GetViewOptions();
+        mrSidebarItem.mbShow = !IsResolved() || (pVOpt->IsResolvedPostIts());
+    }
 
     mpTextRangeOverlay.reset();
 
@@ -315,7 +318,8 @@ void SwAnnotationWin::UpdateData()
 void SwAnnotationWin::Delete()
 {
     collectUIInformation("DELETE",get_id());
-    if (!mrView.GetWrtShellPtr()->GotoField(*mpFormatField))
+    SwWrtShell* pWrtShell = mrView.GetWrtShellPtr();
+    if (!(pWrtShell && pWrtShell->GotoField(*mpFormatField)))
         return;
 
     if ( mrMgr.GetActiveSidebarWin() == this)
@@ -330,8 +334,8 @@ void SwAnnotationWin::Delete()
     }
     // we delete the field directly, the Mgr cleans up the PostIt by listening
     GrabFocusToDocument();
-    mrView.GetWrtShellPtr()->ClearMark();
-    mrView.GetWrtShellPtr()->DelRight();
+    pWrtShell->ClearMark();
+    pWrtShell->DelRight();
 }
 
 void SwAnnotationWin::GotoPos()
diff --git a/sw/source/uibase/docvw/AnnotationWin2.cxx 
b/sw/source/uibase/docvw/AnnotationWin2.cxx
index 087759047a81..5f4bdc1415a9 100644
--- a/sw/source/uibase/docvw/AnnotationWin2.cxx
+++ b/sw/source/uibase/docvw/AnnotationWin2.cxx
@@ -348,7 +348,6 @@ void SwAnnotationWin::InitControls()
     mxVScrollbar->connect_vadjustment_changed(LINK(this, SwAnnotationWin, 
ScrollHdl));
     mxVScrollbar->connect_mouse_move(LINK(this, SwAnnotationWin, 
MouseMoveHdl));
 
-    const SwViewOption* pVOpt = mrView.GetWrtShellPtr()->GetViewOptions();
     EEControlBits nCntrl = mpOutliner->GetControlWord();
     // TODO: crash when AUTOCOMPLETE enabled
     nCntrl |= EEControlBits::MARKFIELDS | EEControlBits::PASTESPECIAL | 
EEControlBits::AUTOCORRECT | EEControlBits::USECHARATTRIBS; // | 
EEControlBits::AUTOCOMPLETE;
@@ -356,10 +355,15 @@ void SwAnnotationWin::InitControls()
         nCntrl |= EEControlBits::MARKFIELDS;
     else
         nCntrl &= ~EEControlBits::MARKFIELDS;
-    if (pVOpt->IsOnlineSpell())
-        nCntrl |= EEControlBits::ONLINESPELLING;
-    else
-        nCntrl &= ~EEControlBits::ONLINESPELLING;
+
+    if (SwWrtShell* pWrtShell = mrView.GetWrtShellPtr())
+    {
+        const SwViewOption* pVOpt = pWrtShell->GetViewOptions();
+        if (pVOpt->IsOnlineSpell())
+            nCntrl |= EEControlBits::ONLINESPELLING;
+        else
+            nCntrl &= ~EEControlBits::ONLINESPELLING;
+    }
     mpOutliner->SetControlWord(nCntrl);
 
     std::size_t aIndex = SW_MOD()->InsertRedlineAuthor(GetAuthor());
@@ -453,7 +457,10 @@ void SwAnnotationWin::SetMenuButtonColors()
 
     mxMenuButton->set_background(mColorDark);
 
-    const Fraction& rFraction = 
mrView.GetWrtShellPtr()->GetOut()->GetMapMode().GetScaleY();
+    SwWrtShell* pWrtShell = mrView.GetWrtShellPtr();
+    if (!pWrtShell)
+        return;
+    const Fraction& rFraction = pWrtShell->GetOut()->GetMapMode().GetScaleY();
 
     ScopedVclPtrInstance<VirtualDevice> xVirDev;
     Size aSize(tools::Long(METABUTTON_WIDTH * rFraction),
@@ -503,7 +510,11 @@ void SwAnnotationWin::Rescale()
     aMode.SetOrigin( Point() );
     SetMapMode( aMode );
     mxSidebarTextControl->SetMapMode( aMode );
-    const Fraction& rFraction = 
mrView.GetWrtShellPtr()->GetOut()->GetMapMode().GetScaleY();
+
+    SwWrtShell* pWrtShell = mrView.GetWrtShellPtr();
+    if (!pWrtShell)
+        return;
+    const Fraction& rFraction = pWrtShell->GetOut()->GetMapMode().GetScaleY();
 
     vcl::Font aFont = maLabelFont;
     sal_Int32 nHeight = tools::Long(aFont.GetFontHeight() * rFraction);
@@ -930,17 +941,20 @@ void SwAnnotationWin::SetLanguage(const SvxLanguageItem& 
rNewItem)
     GetOutlinerView()->SetSelection(aOld);
     mpOutliner->SetModifyHdl( aLink );
 
-    const SwViewOption* pVOpt = mrView.GetWrtShellPtr()->GetViewOptions();
     EEControlBits nCntrl = mpOutliner->GetControlWord();
     // turn off
     nCntrl &= ~EEControlBits::ONLINESPELLING;
     mpOutliner->SetControlWord(nCntrl);
 
-    //turn back on
-    if (pVOpt->IsOnlineSpell())
-        nCntrl |= EEControlBits::ONLINESPELLING;
-    else
-        nCntrl &= ~EEControlBits::ONLINESPELLING;
+    if (SwWrtShell* pWrtShell = mrView.GetWrtShellPtr())
+    {
+        const SwViewOption* pVOpt = pWrtShell->GetViewOptions();
+        //turn back on
+        if (pVOpt->IsOnlineSpell())
+            nCntrl |= EEControlBits::ONLINESPELLING;
+        else
+            nCntrl &= ~EEControlBits::ONLINESPELLING;
+    }
     mpOutliner->SetControlWord(nCntrl);
 
     mpOutliner->CompleteOnlineSpelling();
@@ -1009,7 +1023,8 @@ void SwAnnotationWin::ActivatePostIt()
     // when cursor out of visible area
     GetOutlinerView()->ShowCursor(false);
 
-    
mpOutlinerView->GetEditView().SetInsertMode(mrView.GetWrtShellPtr()->IsInsMode());
+    if (SwWrtShell* pWrtShell = mrView.GetWrtShellPtr())
+        mpOutlinerView->GetEditView().SetInsertMode(pWrtShell->IsInsMode());
 
     if ( !Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
         GetOutlinerView()->SetBackgroundColor(mColorDark);
@@ -1228,8 +1243,13 @@ void SwAnnotationWin::ResetAttributes()
 
 int SwAnnotationWin::GetPrefScrollbarWidth() const
 {
-    const Fraction& 
f(mrView.GetWrtShellPtr()->GetOut()->GetMapMode().GetScaleY());
-    return 
tools::Long(Application::GetSettings().GetStyleSettings().GetScrollBarSize() * 
f);
+    if (SwWrtShell* pWrtShell = mrView.GetWrtShellPtr())
+    {
+        const Fraction& f(pWrtShell->GetOut()->GetMapMode().GetScaleY());
+        return 
tools::Long(Application::GetSettings().GetStyleSettings().GetScrollBarSize() * 
f);
+    }
+    else
+        return 
tools::Long(Application::GetSettings().GetStyleSettings().GetScrollBarSize());
 }
 
 sal_Int32 SwAnnotationWin::GetMetaHeight() const
@@ -1256,22 +1276,30 @@ sal_Int32 SwAnnotationWin::GetMinimumSizeWithMeta() 
const
 
 sal_Int32 SwAnnotationWin::GetMinimumSizeWithoutMeta() const
 {
-    const Fraction& 
f(mrView.GetWrtShellPtr()->GetOut()->GetMapMode().GetScaleY());
-    return tools::Long(POSTIT_MINIMUMSIZE_WITHOUT_META * f);
+    if (SwWrtShell* pWrtShell = mrView.GetWrtShellPtr())
+    {
+        const Fraction& f(pWrtShell->GetOut()->GetMapMode().GetScaleY());
+        return tools::Long(POSTIT_MINIMUMSIZE_WITHOUT_META * f);
+    }
+    else
+        return tools::Long(POSTIT_MINIMUMSIZE_WITHOUT_META);
 }
 
 void SwAnnotationWin::SetSpellChecking()
 {
-    const SwViewOption* pVOpt = mrView.GetWrtShellPtr()->GetViewOptions();
-    EEControlBits nCntrl = mpOutliner->GetControlWord();
-    if (pVOpt->IsOnlineSpell())
-        nCntrl |= EEControlBits::ONLINESPELLING;
-    else
-        nCntrl &= ~EEControlBits::ONLINESPELLING;
-    mpOutliner->SetControlWord(nCntrl);
+    if (SwWrtShell* pWrtShell = mrView.GetWrtShellPtr())
+    {
+        const SwViewOption* pVOpt = pWrtShell->GetViewOptions();
+        EEControlBits nCntrl = mpOutliner->GetControlWord();
+        if (pVOpt->IsOnlineSpell())
+            nCntrl |= EEControlBits::ONLINESPELLING;
+        else
+            nCntrl &= ~EEControlBits::ONLINESPELLING;
+        mpOutliner->SetControlWord(nCntrl);
 
-    mpOutliner->CompleteOnlineSpelling();
-    Invalidate();
+        mpOutliner->CompleteOnlineSpelling();
+        Invalidate();
+    }
 }
 
 void SwAnnotationWin::SetViewState(ViewState bViewState)
diff --git a/sw/source/uibase/docvw/edtwin2.cxx 
b/sw/source/uibase/docvw/edtwin2.cxx
index 3c4802b84f79..04a51cfbc7b2 100644
--- a/sw/source/uibase/docvw/edtwin2.cxx
+++ b/sw/source/uibase/docvw/edtwin2.cxx
@@ -441,12 +441,8 @@ void SwEditWin::RequestHelp(const HelpEvent &rEvt)
 
 void SwEditWin::PrePaint(vcl::RenderContext& /*rRenderContext*/)
 {
-    SwWrtShell* pWrtShell = GetView().GetWrtShellPtr();
-
-    if(pWrtShell)
-    {
+    if (SwWrtShell* pWrtShell = GetView().GetWrtShellPtr())
         pWrtShell->PrePaint();
-    }
 }
 
 void SwEditWin::Paint(vcl::RenderContext& rRenderContext, const 
tools::Rectangle& rRect)
diff --git a/sw/source/uibase/misc/redlndlg.cxx 
b/sw/source/uibase/misc/redlndlg.cxx
index 7f61f8a7863f..85ab6d718479 100644
--- a/sw/source/uibase/misc/redlndlg.cxx
+++ b/sw/source/uibase/misc/redlndlg.cxx
@@ -100,6 +100,8 @@ void SwModelessRedlineAcceptDlg::Activate()
     {   // doc-switch
         SwWait aWait( *pDocSh, false );
         SwWrtShell* pSh = pView->GetWrtShellPtr();
+        if (!pSh)
+            return;
 
         m_pChildWin->SetOldDocShell(pDocSh);  // avoid recursion (using 
modified-Hdl)
 
@@ -244,6 +246,8 @@ void SwRedlineAcceptDlg::InitAuthors()
 
     SwView *pView = ::GetActiveView();
     SwWrtShell* pSh = pView ? pView->GetWrtShellPtr() : nullptr;
+    if (!pSh)
+        return;
 
     SvxTPFilter *pFilterPage = m_xTabPagesCTRL->GetFilterPage();
 
@@ -389,6 +393,9 @@ void SwRedlineAcceptDlg::Activate()
 
     // did something change?
     SwWrtShell* pSh = pView->GetWrtShellPtr();
+    if (!pSh)
+        return;
+
     SwRedlineTable::size_type nCount = pSh->GetRedlineCount();
 
     // check the number of pointers
@@ -488,6 +495,9 @@ SwRedlineTable::size_type 
SwRedlineAcceptDlg::CalcDiff(SwRedlineTable::size_type
     rTreeView.freeze();
     SwView *pView   = ::GetActiveView();
     SwWrtShell* pSh = pView->GetWrtShellPtr();
+    if (!pSh)
+        return SwRedlineTable::npos;
+
     bool bHasRedlineAutoFormat = HasRedlineAutoFormat();
     SwRedlineDataParent *const pParent = m_RedlineParents[nStart].get();
     const SwRangeRedline& rRedln = pSh->GetRedline(nStart);
@@ -655,6 +665,9 @@ void SwRedlineAcceptDlg::InsertChildren(SwRedlineDataParent 
*pParent, const SwRa
 void SwRedlineAcceptDlg::RemoveParents(SwRedlineTable::size_type nStart, 
SwRedlineTable::size_type nEnd)
 {
     SwWrtShell* pSh = ::GetActiveView()->GetWrtShellPtr();
+    if (!pSh)
+        return;
+
     SwRedlineTable::size_type nCount = pSh->GetRedlineCount();
 
     std::vector<const weld::TreeIter*> aLBoxArr;
@@ -735,6 +748,9 @@ void 
SwRedlineAcceptDlg::InsertParents(SwRedlineTable::size_type nStart, SwRedli
         return;
 
     SwWrtShell* pSh = pView->GetWrtShellPtr();
+    if (!pSh)
+        return;
+
     bool bHasRedlineAutoFormat = HasRedlineAutoFormat();
 
     SwRedlineTable::size_type nCount = pSh->GetRedlineCount();
@@ -913,6 +929,9 @@ void 
SwRedlineAcceptDlg::InsertParents(SwRedlineTable::size_type nStart, SwRedli
 void SwRedlineAcceptDlg::CallAcceptReject( bool bSelect, bool bAccept )
 {
     SwWrtShell* pSh = ::GetActiveView()->GetWrtShellPtr();
+    if (!pSh)
+        return;
+
     int nPos = -1;
 
     typedef std::vector<std::unique_ptr<weld::TreeIter>> ListBoxEntries_t;
@@ -1053,10 +1072,14 @@ void SwRedlineAcceptDlg::CallAcceptReject( bool 
bSelect, bool bAccept )
 
 SwRedlineTable::size_type SwRedlineAcceptDlg::GetRedlinePos(const 
weld::TreeIter& rEntry)
 {
-    SwWrtShell* pSh = ::GetActiveView()->GetWrtShellPtr();
-    weld::TreeView& rTreeView = m_pTable->GetWidget();
-    return pSh->FindRedlineOfData( 
*static_cast<SwRedlineDataParent*>(weld::fromId<RedlinData*>(
-                                    rTreeView.get_id(rEntry))->pData)->pData );
+    if (SwWrtShell* pSh = ::GetActiveView()->GetWrtShellPtr())
+    {
+        weld::TreeView& rTreeView = m_pTable->GetWidget();
+        return pSh->FindRedlineOfData( 
*static_cast<SwRedlineDataParent*>(weld::fromId<RedlinData*>(
+                                        
rTreeView.get_id(rEntry))->pData)->pData );
+    }
+    else
+        return SwRedlineTable::npos;
 }
 
 IMPL_LINK_NOARG(SwRedlineAcceptDlg, AcceptHdl, SvxTPView*, void)
@@ -1109,6 +1132,9 @@ IMPL_LINK_NOARG(SwRedlineAcceptDlg, SelectHdl, 
weld::TreeView&, void)
 IMPL_LINK_NOARG(SwRedlineAcceptDlg, GotoHdl, Timer *, void)
 {
     SwWrtShell* pSh = ::GetActiveView()->GetWrtShellPtr();
+    if (!pSh)
+        return;
+
     m_aSelectTimer.Stop();
 
     bool bIsNotFormated = false;
@@ -1205,6 +1231,9 @@ IMPL_LINK(SwRedlineAcceptDlg, CommandHdl, const 
CommandEvent&, rCEvt, bool)
         return false;
 
     SwWrtShell* pSh = ::GetActiveView()->GetWrtShellPtr();
+    if (!pSh)
+        return false;
+
     const SwRangeRedline *pRed = nullptr;
 
     weld::TreeView& rTreeView = m_pTable->GetWidget();
diff --git a/sw/source/uibase/ribbar/inputwin.cxx 
b/sw/source/uibase/ribbar/inputwin.cxx
index 255ae24335ab..3cabc8a9c73a 100644
--- a/sw/source/uibase/ribbar/inputwin.cxx
+++ b/sw/source/uibase/ribbar/inputwin.cxx
@@ -191,12 +191,11 @@ void SwInputWindow::ShowWin()
 {
     m_bIsTable = false;
     // stop rulers
-    if (m_pView)
+    if (m_pView && m_pWrtShell)
     {
         m_pView->GetHRuler().SetActive( false );
         m_pView->GetVRuler().SetActive( false );
 
-        OSL_ENSURE(m_pWrtShell, "no WrtShell!");
         // Cursor in table
         m_bIsTable = m_pWrtShell->IsCursorInTable();
 
@@ -332,7 +331,7 @@ void  SwInputWindow::ApplyFormula()
     // in case it was created while loading the document, the active view
     // wasn't initialised at that time, so ShowWin() didn't initialise anything
     // either - nothing to do
-    if (!m_pView)
+    if (!m_pView || !m_pWrtShell)
     {
         // presumably there must be an active view now since the event arrived
         SwView *const pActiveView = ::GetActiveView();
@@ -365,7 +364,7 @@ void  SwInputWindow::CancelFormula()
     // in case it was created while loading the document, the active view
     // wasn't initialised at that time, so ShowWin() didn't initialise anything
     // either - nothing to do
-    if (!m_pView)
+    if (!m_pView || !m_pWrtShell)
     {
         // presumably there must be an active view now since the event arrived
         SwView *const pActiveView = ::GetActiveView();
@@ -394,7 +393,7 @@ const sal_Unicode CH_PDF = 0x202c;
 
 IMPL_LINK( SwInputWindow, SelTableCellsNotify, SwWrtShell&, rCaller, void )
 {
-    if(m_bIsTable)
+    if(m_pWrtShell && m_bIsTable)
     {
         SwFrameFormat* pTableFormat = rCaller.GetTableFormat();
         OUString sBoxNms( rCaller.GetBoxNms() );
@@ -447,7 +446,7 @@ void SwInputWindow::SetFormula( const OUString& rFormula )
 
 IMPL_LINK_NOARG(SwInputWindow, ModifyHdl, weld::Entry&, void)
 {
-    if (m_bIsTable && m_bResetUndo)
+    if (m_pWrtShell && m_bIsTable && m_bResetUndo)
     {
         m_pWrtShell->StartAllAction();
         DelBoxContent();
@@ -461,7 +460,7 @@ IMPL_LINK_NOARG(SwInputWindow, ModifyHdl, weld::Entry&, 
void)
 
 void SwInputWindow::DelBoxContent()
 {
-    if( m_bIsTable )
+    if( m_pWrtShell && m_bIsTable )
     {
         m_pWrtShell->StartAllAction();
         m_pWrtShell->ClearMark();
diff --git a/sw/source/uibase/shells/langhelper.cxx 
b/sw/source/uibase/shells/langhelper.cxx
index 097a8b0d8408..cf9497b43e27 100644
--- a/sw/source/uibase/shells/langhelper.cxx
+++ b/sw/source/uibase/shells/langhelper.cxx
@@ -177,21 +177,24 @@ namespace SwLangHelper
                 // when setting a new language attribute
                 if (bForSelection)
                 {
-                    const SwViewOption* pVOpt = 
rView.GetWrtShellPtr()->GetViewOptions();
-                    EEControlBits nCntrl = pEditEngine->GetControlWord();
-                    // turn off
-                    nCntrl &= ~EEControlBits::ONLINESPELLING;
-                    pEditEngine->SetControlWord(nCntrl);
-
-                    //turn back on
-                    if (pVOpt->IsOnlineSpell())
-                        nCntrl |= EEControlBits::ONLINESPELLING;
-                    else
+                    if (SwWrtShell* pWrtShell = rView.GetWrtShellPtr())
+                    {
+                        const SwViewOption* pVOpt = 
pWrtShell->GetViewOptions();
+                        EEControlBits nCntrl = pEditEngine->GetControlWord();
+                        // turn off
                         nCntrl &= ~EEControlBits::ONLINESPELLING;
-                    pEditEngine->SetControlWord(nCntrl);
-
-                    pEditEngine->CompleteOnlineSpelling();
-                    rEditView.Invalidate();
+                        pEditEngine->SetControlWord(nCntrl);
+
+                        //turn back on
+                        if (pVOpt->IsOnlineSpell())
+                            nCntrl |= EEControlBits::ONLINESPELLING;
+                        else
+                            nCntrl &= ~EEControlBits::ONLINESPELLING;
+                        pEditEngine->SetControlWord(nCntrl);
+
+                        pEditEngine->CompleteOnlineSpelling();
+                        rEditView.Invalidate();
+                    }
                 }
 
                 if (!bForSelection)
diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx
index 8c3ffcde2322..8e8858213f05 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -185,10 +185,10 @@ void SwView::GotFocus() const
             const_cast< SwView* >( this )->AttrChangedNotify(nullptr);
         }
     }
-    if( GetWrtShellPtr() )
+    if (SwWrtShell* pWrtShell = GetWrtShellPtr())
     {
         SwWrtShell& rWrtShell = GetWrtShell();
-        rWrtShell.GetDoc()->getIDocumentLayoutAccess().SetCurrentViewShell( 
GetWrtShellPtr() );
+        rWrtShell.GetDoc()->getIDocumentLayoutAccess().SetCurrentViewShell( 
pWrtShell );
         rWrtShell.GetDoc()->getIDocumentSettingAccess().set( 
DocumentSettingId::BROWSE_MODE,
                                  rWrtShell.GetViewOptions()->getBrowseMode() );
     }
@@ -1936,8 +1936,7 @@ void SwView::AddTransferable(SwTransferable& 
rTransferable)
 
 tools::Rectangle SwView::getLOKVisibleArea() const
 {
-    SwViewShell* pVwSh = GetWrtShellPtr();
-    if (pVwSh)
+    if (SwViewShell* pVwSh = GetWrtShellPtr())
         return pVwSh->getLOKVisibleArea();
     else
         return tools::Rectangle();
@@ -1945,16 +1944,16 @@ tools::Rectangle SwView::getLOKVisibleArea() const
 
 void SwView::flushPendingLOKInvalidateTiles()
 {
-    SwWrtShell* pSh = GetWrtShellPtr();
-    assert(pSh);
-    pSh->FlushPendingLOKInvalidateTiles();
+    if (SwWrtShell* pSh = GetWrtShellPtr())
+        pSh->FlushPendingLOKInvalidateTiles();
 }
 
 std::optional<OString> SwView::getLOKPayload(int nType, int nViewId) const
 {
-    SwWrtShell* pSh = GetWrtShellPtr();
-    assert(pSh);
-    return pSh->getLOKPayload(nType, nViewId);
+    if (SwWrtShell* pSh = GetWrtShellPtr())
+        return pSh->getLOKPayload(nType, nViewId);
+    else
+        return std::nullopt;
 }
 
 OUString SwView::GetDataSourceName() const
diff --git a/sw/source/uibase/uno/unomailmerge.cxx 
b/sw/source/uibase/uno/unomailmerge.cxx
index 83c37bc9d338..7399f71f5c44 100644
--- a/sw/source/uibase/uno/unomailmerge.cxx
+++ b/sw/source/uibase/uno/unomailmerge.cxx
@@ -591,7 +591,6 @@ uno::Any SAL_CALL SwXMailMerge::execute(
     SwView *pView = pFrame ? dynamic_cast<SwView*>( pFrame->GetViewShell()  ) 
: nullptr;
     if (!pView)
         throw RuntimeException();
-    SwWrtShell &rSh = *pView->GetWrtShellPtr();
 
     // avoid assertion in 'Update' from Sfx by supplying a shell
     // and thus avoiding the SelectShell call in Writers GetState function
@@ -662,6 +661,7 @@ uno::Any SAL_CALL SwXMailMerge::execute(
             throw IllegalArgumentException("Invalid value of property: 
OutputType", static_cast < cppu::OWeakObject * > ( this ), 0 );
     }
 
+    SwWrtShell &rSh = pView->GetWrtShell();
     SwDBManager* pMgr = rSh.GetDBManager();
     //force layout creation
     rSh.CalcLayout();
diff --git a/sw/source/uibase/uno/unotxdoc.cxx 
b/sw/source/uibase/uno/unotxdoc.cxx
index 9cd00ead1c9e..cad1dc446f16 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -2653,14 +2653,6 @@ uno::Sequence< beans::PropertyValue > SAL_CALL 
SwXTextDocument::getRenderer(
     if (0 > nRenderer)
         throw IllegalArgumentException();
 
-    // TODO/mba: we really need a generic way to get the SwViewShell!
-    SwViewShell* pVwSh = nullptr;
-    SwView* pSwView = dynamic_cast<SwView*>( pView );
-    if ( pSwView )
-        pVwSh = pSwView->GetWrtShellPtr();
-    else
-        pVwSh = static_cast<SwPagePreview*>(pView)->GetViewShell();
-
     sal_Int32 nMaxRenderer = 0;
     if (!bIsSwSrcView && m_pRenderData)
     {
@@ -2751,11 +2743,22 @@ uno::Sequence< beans::PropertyValue > SAL_CALL 
SwXTextDocument::getRenderer(
         }
         else
         {
-            aTmpSize = pVwSh->GetPageSize( nPage, bIsSkipEmptyPages );
-            aPageSize = awt::Size ( convertTwipToMm100( aTmpSize.Width() ),
-                                    convertTwipToMm100( aTmpSize.Height() ));
-            Point aPoint = pVwSh->GetPagePos(nPage);
-            aPagePos = awt::Point(convertTwipToMm100(aPoint.X()), 
convertTwipToMm100(aPoint.Y()));
+            // TODO/mba: we really need a generic way to get the SwViewShell!
+            SwViewShell* pVwSh = nullptr;
+            SwView* pSwView = dynamic_cast<SwView*>( pView );
+            if ( pSwView )
+                pVwSh = pSwView->GetWrtShellPtr();
+            else
+                pVwSh = static_cast<SwPagePreview*>(pView)->GetViewShell();
+
+            if (pVwSh)
+            {
+                aTmpSize = pVwSh->GetPageSize( nPage, bIsSkipEmptyPages );
+                aPageSize = awt::Size ( convertTwipToMm100( aTmpSize.Width() ),
+                                        convertTwipToMm100( aTmpSize.Height() 
));
+                Point aPoint = pVwSh->GetPagePos(nPage);
+                aPagePos = awt::Point(convertTwipToMm100(aPoint.X()), 
convertTwipToMm100(aPoint.Y()));
+            }
         }
 
         sal_Int32 nLen = 3;
diff --git a/sw/source/uibase/uno/unotxvw.cxx b/sw/source/uibase/uno/unotxvw.cxx
index 16804f83f753..7bb391586e5a 100644
--- a/sw/source/uibase/uno/unotxvw.cxx
+++ b/sw/source/uibase/uno/unotxvw.cxx
@@ -710,24 +710,25 @@ SfxObjectShellLock SwXTextView::BuildTmpSelectionDoc()
     SfxViewFrame* pDocFrame = SfxViewFrame::LoadHiddenDocument( *xDocSh, 
SFX_INTERFACE_NONE );
     SwView* pDocView = static_cast<SwView*>( pDocFrame->GetViewShell() );
     pDocView->AttrChangedNotify(nullptr);//So that SelectShell is called.
-    SwWrtShell* pSh = pDocView->GetWrtShellPtr();
+    if (SwWrtShell* pSh = pDocView->GetWrtShellPtr())
+    {
+        IDocumentDeviceAccess& rIDDA = pSh->getIDocumentDeviceAccess();
+        SfxPrinter* pTempPrinter = rIDDA.getPrinter( true );
 
-    IDocumentDeviceAccess& rIDDA = pSh->getIDocumentDeviceAccess();
-    SfxPrinter* pTempPrinter = rIDDA.getPrinter( true );
+        const SwPageDesc& rCurPageDesc = 
rOldSh.GetPageDesc(rOldSh.GetCurPageDesc());
 
-    const SwPageDesc& rCurPageDesc = 
rOldSh.GetPageDesc(rOldSh.GetCurPageDesc());
+        IDocumentDeviceAccess& rIDDA_old = rOldSh.getIDocumentDeviceAccess();
 
-    IDocumentDeviceAccess& rIDDA_old = rOldSh.getIDocumentDeviceAccess();
+        if( rIDDA_old.getPrinter( false ) )
+        {
+            rIDDA.setJobsetup( *rIDDA_old.getJobsetup() );
+            //#69563# if it isn't the same printer then the pointer has been 
invalidated!
+            pTempPrinter = rIDDA.getPrinter( true );
+        }
 
-    if( rIDDA_old.getPrinter( false ) )
-    {
-        rIDDA.setJobsetup( *rIDDA_old.getJobsetup() );
-        //#69563# if it isn't the same printer then the pointer has been 
invalidated!
-        pTempPrinter = rIDDA.getPrinter( true );
+        
pTempPrinter->SetPaperBin(rCurPageDesc.GetMaster().GetPaperBin().GetValue());
     }
 
-    
pTempPrinter->SetPaperBin(rCurPageDesc.GetMaster().GetPaperBin().GetValue());
-
     return xDocSh;
 }
 
diff --git a/sw/source/uibase/utlui/content.cxx 
b/sw/source/uibase/utlui/content.cxx
index 900662990d09..48be29d67b08 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -3722,13 +3722,17 @@ IMPL_LINK_NOARG(SwContentTree, TimerUpdate, Timer *, 
void)
     // No update while drag and drop.
     // Query view because the Navigator is cleared too late.
     SwView* pView = GetParentWindow()->GetCreateView();
-    if(pView && pView->GetWrtShellPtr() && pView->GetWrtShellPtr()->GetWin() &&
-        (pView->GetWrtShellPtr()->GetWin()->HasFocus() || m_bDocHasChanged || 
m_bViewHasChanged) &&
-        !IsInDrag() && !pView->GetWrtShellPtr()->ActionPend())
+
+    if (!pView)
+        return;
+
+    SwWrtShell* pActShell = pView->GetWrtShellPtr();
+    if(pActShell && pActShell->GetWin() &&
+        (pActShell->GetWin()->HasFocus() || m_bDocHasChanged || 
m_bViewHasChanged) &&
+        !IsInDrag() && !pActShell->ActionPend())
     {
         if (m_bDocHasChanged || m_bViewHasChanged)
         {
-            SwWrtShell* pActShell = pView->GetWrtShellPtr();
             if (State::CONSTANT == m_eState && !lcl_FindShell(m_pActiveShell))
             {
                 SetActiveShell(pActShell);
diff --git a/sw/source/uibase/utlui/navipi.cxx 
b/sw/source/uibase/utlui/navipi.cxx
index 773e40baa0c1..31cb7d6b74e0 100644
--- a/sw/source/uibase/utlui/navipi.cxx
+++ b/sw/source/uibase/utlui/navipi.cxx
@@ -663,8 +663,9 @@ SwNavigationPI::SwNavigationPI(weld::Widget* pParent,
     if(IsGlobalDoc())
     {
         SwView *pActView = GetCreateView();
-        m_xGlobalToolBox->set_item_active("save",
-                    pActView->GetWrtShellPtr()->IsGlblDocSaveLinks());
+        if (pActView && pActView->GetWrtShellPtr())
+            m_xGlobalToolBox->set_item_active("save",
+                        pActView->GetWrtShellPtr()->IsGlblDocSaveLinks());
         if (m_pConfig->IsGlobalActive())
             ToggleTree();
         if (bFloatingNavigator)

Reply via email to