sw/source/ui/chrdlg/chardlg.cxx                    |   13 ++-
 sw/source/ui/chrdlg/drpcps.cxx                     |   64 ++++++++++------
 sw/source/ui/chrdlg/swuiccoll.cxx                  |   16 +++-
 sw/source/ui/dbui/mmresultdialogs.cxx              |   40 +++++++---
 sw/source/ui/dialog/wordcountdialog.cxx            |   25 +++---
 sw/source/ui/fldui/fldpage.cxx                     |    3 
 sw/source/ui/fldui/fldtdlg.cxx                     |    3 
 sw/source/ui/fmtui/tmpdlg.cxx                      |   27 +++----
 sw/source/ui/misc/pggrid.cxx                       |    6 -
 sw/source/ui/misc/titlepage.cxx                    |   81 ++++++++++++---------
 sw/source/uibase/app/apphdl.cxx                    |   19 +++-
 sw/source/uibase/app/swmodul1.cxx                  |    3 
 sw/source/uibase/dbui/mailmergetoolbarcontrols.cxx |   12 +--
 sw/source/uibase/envelp/syncbtn.cxx                |    3 
 sw/source/uibase/fldui/fldmgr.cxx                  |    4 -
 sw/source/uibase/fldui/xfldui.cxx                  |   12 ++-
 sw/source/uibase/inc/drpcps.hxx                    |    4 -
 sw/source/uibase/inc/swuiccoll.hxx                 |    1 
 sw/source/uibase/inc/titlepage.hxx                 |    2 
 sw/source/uibase/misc/redlndlg.cxx                 |   57 ++++++++++----
 sw/source/uibase/ribbar/inputwin.cxx               |   16 ++--
 sw/source/uibase/ribbar/workctrl.cxx               |   17 ++--
 sw/source/uibase/shells/tabsh.cxx                  |    3 
 sw/source/uibase/shells/textsh.cxx                 |   26 +++---
 sw/source/uibase/table/chartins.cxx                |   19 +++-
 sw/source/uibase/utlui/content.cxx                 |    2 
 sw/source/uibase/utlui/gloslst.cxx                 |    4 -
 sw/source/uibase/utlui/navipi.cxx                  |    7 +
 sw/source/uibase/utlui/numfmtlb.cxx                |    6 -
 29 files changed, 297 insertions(+), 198 deletions(-)

New commits:
commit 7f2155e6a20d9a3de8d3d3d53661f6891aebda67
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Tue Mar 21 16:55:59 2023 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Sat Mar 25 19:58:05 2023 +0000

    sw: check GetActiveView()
    
    See 
https://crashreport.libreoffice.org/stats/signature/SwView::GetDocShell()
    
    Change-Id: I90ebbff5082f1f9cae7fa3b940cbb9796d6c6dd3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149223
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149320
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149503

diff --git a/sw/source/ui/chrdlg/chardlg.cxx b/sw/source/ui/chrdlg/chardlg.cxx
index b7564dc414a9..b91076230e71 100644
--- a/sw/source/ui/chrdlg/chardlg.cxx
+++ b/sw/source/ui/chrdlg/chardlg.cxx
@@ -170,9 +170,11 @@ SwCharURLPage::SwCharURLPage(weld::Container* pPage, 
weld::DialogController* pCo
     m_xURLPB->connect_clicked(LINK( this, SwCharURLPage, InsertFileHdl));
     m_xEventPB->connect_clicked(LINK( this, SwCharURLPage, EventHdl));
 
-    SwView *pView = ::GetActiveView();
-    ::FillCharStyleListBox(*m_xVisitedLB, pView->GetDocShell());
-    ::FillCharStyleListBox(*m_xNotVisitedLB, pView->GetDocShell());
+    if (SwView* pView = GetActiveView())
+    {
+        ::FillCharStyleListBox(*m_xVisitedLB, pView->GetDocShell());
+        ::FillCharStyleListBox(*m_xNotVisitedLB, pView->GetDocShell());
+    }
     m_xVisitedLB->set_active_id(OUString::number(RES_POOLCHR_INET_VISIT));
     m_xVisitedLB->save_value();
     m_xNotVisitedLB->set_active_id(OUString::number(RES_POOLCHR_INET_NORMAL));
@@ -302,8 +304,9 @@ IMPL_LINK_NOARG(SwCharURLPage, InsertFileHdl, 
weld::Button&, void)
 
 IMPL_LINK_NOARG(SwCharURLPage, EventHdl, weld::Button&, void)
 {
-    bModified |= SwMacroAssignDlg::INetFormatDlg(GetFrameWeld(),
-                    ::GetActiveView()->GetWrtShell(), m_oINetMacroTable);
+    if (SwView* pView = GetActiveView())
+        bModified |= SwMacroAssignDlg::INetFormatDlg(GetFrameWeld(),
+                        pView->GetWrtShell(), m_oINetMacroTable);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/ui/chrdlg/drpcps.cxx b/sw/source/ui/chrdlg/drpcps.cxx
index 1ecb6cefeddc..32509c5018ca 100644
--- a/sw/source/ui/chrdlg/drpcps.cxx
+++ b/sw/source/ui/chrdlg/drpcps.cxx
@@ -169,10 +169,15 @@ bool SwDropCapsPict::GetNextScriptSegment(size_t &nIdx, 
sal_Int32 &start, sal_In
 #define LINES  10
 #define BORDER  2
 
-void SwDropCapsPict::GetFontSettings( const SwDropCapsPage& _rPage, vcl::Font& 
_rFont, sal_uInt16 _nWhich )
+void SwDropCapsPict::GetFontSettings( vcl::Font& _rFont, sal_uInt16 _nWhich )
 {
-    SfxItemSet aSet( _rPage.rSh.GetAttrPool(), _nWhich, _nWhich);
-    _rPage.rSh.GetCurAttr(aSet);
+    SwView* pView = GetActiveView();
+    if (!pView)
+        return;
+    SwWrtShell& rWrtShell = pView->GetWrtShell();
+    SfxItemSet aSet( rWrtShell.GetAttrPool(), _nWhich, _nWhich);
+    rWrtShell.GetCurAttr(aSet);
+
     SvxFontItem aFormatFont(static_cast<const SvxFontItem &>( 
aSet.Get(_nWhich)));
 
     _rFont.SetFamily(aFormatFont.GetFamily());
@@ -183,6 +188,11 @@ void SwDropCapsPict::GetFontSettings( const 
SwDropCapsPage& _rPage, vcl::Font& _
 
 void SwDropCapsPict::UpdatePaintSettings()
 {
+    SwView* pView = GetActiveView();
+    if (!pView)
+        return;
+    SwWrtShell& rWrtShell = pView->GetWrtShell();
+
     maBackColor = 
Application::GetSettings().GetStyleSettings().GetWindowColor();
     maTextLineColor = COL_LIGHTGRAY;
 
@@ -194,33 +204,33 @@ void SwDropCapsPict::UpdatePaintSettings()
     if (mpPage)
     {
         // tdf#135244: preview generation should not jump document view
-        auto aLock(mpPage->rSh.GetView().GetDocShell()->LockAllViews());
+        auto aLock(rWrtShell.GetView().GetDocShell()->LockAllViews());
 
         if (!mpPage->m_xTemplateBox->get_active())
         {
             // query the Font at paragraph's beginning
-            mpPage->rSh.Push();
-            mpPage->rSh.SttCursorMove();
-            mpPage->rSh.ClearMark();
+            rWrtShell.Push();
+            rWrtShell.SttCursorMove();
+            rWrtShell.ClearMark();
             SwWhichPara pSwuifnParaCurr = GoCurrPara;
             SwMoveFnCollection const & pSwuifnParaStart = fnParaStart;
-            mpPage->rSh.MovePara(pSwuifnParaCurr,pSwuifnParaStart);
+            rWrtShell.MovePara(pSwuifnParaCurr,pSwuifnParaStart);
             // normal
-            GetFontSettings( *mpPage, aFont, RES_CHRATR_FONT );
+            GetFontSettings( aFont, RES_CHRATR_FONT );
 
             // CJK
-            GetFontSettings( *mpPage, maCJKFont, RES_CHRATR_CJK_FONT );
+            GetFontSettings( maCJKFont, RES_CHRATR_CJK_FONT );
 
             // CTL
-            GetFontSettings( *mpPage, maCTLFont, RES_CHRATR_CTL_FONT );
+            GetFontSettings( maCTLFont, RES_CHRATR_CTL_FONT );
 
-            mpPage->rSh.EndCursorMove();
-            mpPage->rSh.Pop(SwCursorShell::PopMode::DeleteCurrent);
+            rWrtShell.EndCursorMove();
+            rWrtShell.Pop(SwCursorShell::PopMode::DeleteCurrent);
         }
         else
         {
             // query Font at character template
-            SwCharFormat *pFormat = mpPage->rSh.GetCharStyle(
+            SwCharFormat *pFormat = rWrtShell.GetCharStyle(
                                     mpPage->m_xTemplateBox->get_active_text(),
                                     SwWrtShell::GETSTYLE_CREATEANY );
             OSL_ENSURE(pFormat, "character style doesn't exist!");
@@ -462,7 +472,6 @@ SwDropCapsPage::SwDropCapsPage(weld::Container* pPage, 
weld::DialogController* p
     : SfxTabPage(pPage, pController, "modules/swriter/ui/dropcapspage.ui", 
"DropCapPage", &rSet)
     , bModified(false)
     , bFormat(true)
-    , rSh(::GetActiveView()->GetWrtShell())
     , m_xDropCapsBox(m_xBuilder->weld_check_button("checkCB_SWITCH"))
     , m_xWholeWordCB(m_xBuilder->weld_check_button("checkCB_WORD"))
     , m_xSwitchText(m_xBuilder->weld_label("labelFT_DROPCAPS"))
@@ -549,7 +558,9 @@ void  SwDropCapsPage::Reset(const SfxItemSet *rSet)
         m_xDistanceField->set_value(0, FieldUnit::TWIP);
     }
 
-    ::FillCharStyleListBox(*m_xTemplateBox, rSh.GetView().GetDocShell(), true);
+    SwView* pView = GetActiveView();
+    if (pView)
+        ::FillCharStyleListBox(*m_xTemplateBox, 
pView->GetWrtShell().GetView().GetDocShell(), true);
 
     m_xTemplateBox->insert_text(0, SwResId(SW_STR_NONE));
 
@@ -570,7 +581,8 @@ void  SwDropCapsPage::Reset(const SfxItemSet *rSet)
         m_xTextEdit->set_text(GetDefaultString(nVal));
     else
     {
-        m_xTextEdit->set_text(rSh.GetDropText(nVal));
+        if (pView)
+            m_xTextEdit->set_text(pView->GetWrtShell().GetDropText(nVal));
         m_xTextEdit->set_sensitive(true);
         m_xTextText->set_sensitive(true);
     }
@@ -634,12 +646,15 @@ void SwDropCapsPage::ModifyEntry(const weld::Entry& rEdit)
             : 0;
         bool bSetText = false;
 
-        if (bFormat || rSh.GetDropText(1).isEmpty())
-            sPreview = GetDefaultString(nVal);
-        else
+        if (SwView* pView = GetActiveView())
         {
-            bSetText = true;
-            sPreview = rSh.GetDropText(nVal);
+            if (bFormat || pView->GetWrtShell().GetDropText(1).isEmpty())
+                sPreview = GetDefaultString(nVal);
+            else
+            {
+                bSetText = true;
+                sPreview = pView->GetWrtShell().GetDropText(nVal);
+            }
         }
 
         OUString sEdit(m_xTextEdit->get_text());
@@ -709,8 +724,9 @@ void SwDropCapsPage::FillSet( SfxItemSet &rSet )
         aFormat.GetWholeWord() = m_xWholeWordCB->get_active();
 
         // template
-        if (m_xTemplateBox->get_active())
-            
aFormat.SetCharFormat(rSh.GetCharStyle(m_xTemplateBox->get_active_text()));
+        if (SwView* pView = GetActiveView())
+            if (m_xTemplateBox->get_active())
+                
aFormat.SetCharFormat(pView->GetWrtShell().GetCharStyle(m_xTemplateBox->get_active_text()));
     }
     else
     {
diff --git a/sw/source/ui/chrdlg/swuiccoll.cxx 
b/sw/source/ui/chrdlg/swuiccoll.cxx
index 2b1aca870165..f36c23d4db55 100644
--- a/sw/source/ui/chrdlg/swuiccoll.cxx
+++ b/sw/source/ui/chrdlg/swuiccoll.cxx
@@ -37,7 +37,6 @@ const WhichRangesContainer 
SwCondCollPage::m_aPageRg(svl::Items<FN_COND_COLL, FN
 
 SwCondCollPage::SwCondCollPage(weld::Container* pPage, weld::DialogController* 
pController, const SfxItemSet &rSet)
     : SfxTabPage(pPage, pController, "modules/swriter/ui/conditionpage.ui", 
"ConditionPage", &rSet)
-    , m_rSh(::GetActiveView()->GetWrtShell())
     , m_pCmds(SwCondCollItem::GetCmds())
     , m_pFormat(nullptr)
     , m_xTbLinks(m_xBuilder->weld_tree_view("links"))
@@ -122,9 +121,13 @@ bool SwCondCollPage::FillItemSet(SfxItemSet *rSet)
 void SwCondCollPage::Reset(const SfxItemSet *)
 {
     m_xTbLinks->clear();
-
-    SfxStyleSheetBasePool* pPool = 
m_rSh.GetView().GetDocShell()->GetStyleSheetPool();
     m_xStyleLB->clear();
+
+    SwView* pView = GetActiveView();
+    if (!pView)
+        return;
+
+    SfxStyleSheetBasePool* pPool = 
pView->GetWrtShell().GetView().GetDocShell()->GetStyleSheetPool();
     const SfxStyleSheetBase* pBase = pPool->First(SfxStyleFamily::Para);
     while (pBase)
     {
@@ -198,9 +201,14 @@ void SwCondCollPage::SelectHdl(const weld::Widget* pBox)
     if (pBox == m_xFilterLB.get())
     {
         m_xStyleLB->clear();
+
+        SwView* pView = GetActiveView();
+        if (!pView)
+            return;
+
         const sal_Int32 nSelPos = m_xFilterLB->get_active();
         const SfxStyleSearchBits nSearchFlags = 
static_cast<SfxStyleSearchBits>(m_xFilterLB->get_id(nSelPos).toInt32());
-        SfxStyleSheetBasePool* pPool = 
m_rSh.GetView().GetDocShell()->GetStyleSheetPool();
+        SfxStyleSheetBasePool* pPool = 
pView->GetWrtShell().GetView().GetDocShell()->GetStyleSheetPool();
         const SfxStyleSheetBase* pBase = pPool->First(SfxStyleFamily::Para, 
nSearchFlags);
 
         bool bEmpty = true;
diff --git a/sw/source/ui/dbui/mmresultdialogs.cxx 
b/sw/source/ui/dbui/mmresultdialogs.cxx
index 9ff6315eefb0..102920ba568a 100644
--- a/sw/source/ui/dbui/mmresultdialogs.cxx
+++ b/sw/source/ui/dbui/mmresultdialogs.cxx
@@ -264,13 +264,15 @@ SwMMResultSaveDialog::SwMMResultSaveDialog(weld::Window* 
pParent)
     m_xFromRB->connect_toggled(aLink);
     // m_pSaveAsOneRB is the default, so disable m_xFromNF and m_xToNF 
initially.
     aLink.Call(*m_xSaveAsOneRB);
-    SwView* pView = ::GetActiveView();
-    const std::shared_ptr<SwMailMergeConfigItem>& xConfigItem = 
pView->GetMailMergeConfigItem();
-    assert(xConfigItem);
-    sal_Int32 nCount = xConfigItem->GetMergedDocumentCount();
-    m_xFromNF->set_max(nCount);
-    m_xToNF->set_max(nCount);
-    m_xToNF->set_value(nCount);
+    if (SwView* pView = GetActiveView())
+    {
+        const std::shared_ptr<SwMailMergeConfigItem>& xConfigItem = 
pView->GetMailMergeConfigItem();
+        assert(xConfigItem);
+        sal_Int32 nCount = xConfigItem->GetMergedDocumentCount();
+        m_xFromNF->set_max(nCount);
+        m_xToNF->set_max(nCount);
+        m_xToNF->set_value(nCount);
+    }
 
     m_xOKButton->connect_clicked(LINK(this, SwMMResultSaveDialog, 
SaveOutputHdl_Impl));
 }
@@ -361,7 +363,9 @@ SwMMResultEmailDialog::~SwMMResultEmailDialog()
 void SwMMResultPrintDialog::FillInPrinterSettings()
 {
     //fill printer ListBox
-    SwView* pView = ::GetActiveView();
+    SwView* pView = GetActiveView();
+    if (!pView)
+        return;
     const std::shared_ptr<SwMailMergeConfigItem>& xConfigItem = 
pView->GetMailMergeConfigItem();
     const std::vector<OUString>& rPrinters = Printer::GetPrinterQueues();
     unsigned int nCount = rPrinters.size();
@@ -394,7 +398,9 @@ void SwMMResultPrintDialog::FillInPrinterSettings()
 
 void SwMMResultEmailDialog::FillInEmailSettings()
 {
-    SwView* pView = ::GetActiveView();
+    SwView* pView = GetActiveView();
+    if (!pView)
+        return;
     const std::shared_ptr<SwMailMergeConfigItem>& xConfigItem = 
pView->GetMailMergeConfigItem();
     assert(xConfigItem);
 
@@ -550,7 +556,9 @@ int documentEndPageNumber(SwMailMergeConfigItem* 
pConfigItem, int document, bool
 
 IMPL_LINK_NOARG(SwMMResultSaveDialog, SaveOutputHdl_Impl, weld::Button&, void)
 {
-    SwView* pView = ::GetActiveView();
+    SwView* pView = GetActiveView();
+    if (!pView)
+        return;
     std::shared_ptr<SwMailMergeConfigItem> xConfigItem = 
pView->GetMailMergeConfigItem();
     assert(xConfigItem);
 
@@ -746,7 +754,9 @@ IMPL_LINK_NOARG(SwMMResultSaveDialog, SaveOutputHdl_Impl, 
weld::Button&, void)
 
 IMPL_LINK(SwMMResultPrintDialog, PrinterChangeHdl_Impl, weld::ComboBox&, rBox, 
void)
 {
-    SwView* pView = ::GetActiveView();
+    SwView* pView = GetActiveView();
+    if (!pView)
+        return;
     const std::shared_ptr<SwMailMergeConfigItem>& xConfigItem = 
pView->GetMailMergeConfigItem();
     assert(xConfigItem);
     if (rBox.get_active() != -1)
@@ -782,7 +792,9 @@ IMPL_LINK(SwMMResultPrintDialog, PrinterChangeHdl_Impl, 
weld::ComboBox&, rBox, v
 
 IMPL_LINK_NOARG(SwMMResultPrintDialog, PrintHdl_Impl, weld::Button&, void)
 {
-    SwView* pView = ::GetActiveView();
+    SwView* pView = GetActiveView();
+    if (!pView)
+        return;
     std::shared_ptr<SwMailMergeConfigItem> xConfigItem = 
pView->GetMailMergeConfigItem();
     assert(xConfigItem);
 
@@ -896,7 +908,9 @@ IMPL_LINK_NOARG(SwMMResultEmailDialog, SendAsHdl_Impl, 
weld::Button&, void)
 // Send documents as e-mail
 IMPL_LINK_NOARG(SwMMResultEmailDialog, SendDocumentsHdl_Impl, weld::Button&, 
void)
 {
-    SwView* pView = ::GetActiveView();
+    SwView* pView = GetActiveView();
+    if (!pView)
+        return;
     std::shared_ptr<SwMailMergeConfigItem> xConfigItem = 
pView->GetMailMergeConfigItem();
     assert(xConfigItem);
 
diff --git a/sw/source/ui/dialog/wordcountdialog.cxx 
b/sw/source/ui/dialog/wordcountdialog.cxx
index 0bda8452a215..6dbd3c780ac4 100644
--- a/sw/source/ui/dialog/wordcountdialog.cxx
+++ b/sw/source/ui/dialog/wordcountdialog.cxx
@@ -129,19 +129,22 @@ SwWordCountFloatDlg::SwWordCountFloatDlg(SfxBindings* 
_pBindings,
 
 void SwWordCountFloatDlg::UpdateCounts()
 {
-    SwWrtShell &rSh = ::GetActiveView()->GetWrtShell();
-    SwDocStat aCurrCnt;
-    SwDocStat aDocStat;
+    if (SwView* pView = GetActiveView())
     {
-        auto& rDocShell(*GetActiveView()->GetDocShell());
-        SwWait aWait(rDocShell, true);
-        auto aLock = rDocShell.LockAllViews();
-        rSh.StartAction();
-        rSh.CountWords( aCurrCnt );
-        aDocStat = rSh.GetUpdatedDocStat();
-        rSh.EndAction();
+        SwWrtShell &rSh = pView->GetWrtShell();
+        SwDocStat aCurrCnt;
+        SwDocStat aDocStat;
+        {
+            auto& rDocShell(*pView->GetDocShell());
+            SwWait aWait(rDocShell, true);
+            auto aLock = rDocShell.LockAllViews();
+            rSh.StartAction();
+            rSh.CountWords( aCurrCnt );
+            aDocStat = rSh.GetUpdatedDocStat();
+            rSh.EndAction();
+        }
+        SetValues(aCurrCnt, aDocStat);
     }
-    SetValues(aCurrCnt, aDocStat);
 }
 
 void SwWordCountFloatDlg::SetCounts(const SwDocStat &rCurrCnt, const SwDocStat 
&rDocStat)
diff --git a/sw/source/ui/fldui/fldpage.cxx b/sw/source/ui/fldui/fldpage.cxx
index 71ff3d33246e..00c31c9bab19 100644
--- a/sw/source/ui/fldui/fldpage.cxx
+++ b/sw/source/ui/fldui/fldpage.cxx
@@ -118,6 +118,9 @@ void SwFieldPage::InsertField(SwFieldTypesEnum nTypeId, 
sal_uInt16 nSubType, con
                             sal_Unicode cSeparator, bool bIsAutomaticLanguage)
 {
     SwView* pView = GetActiveView();
+    if (!pView)
+        return;
+
     SwWrtShell *pSh = m_pWrtShell ? m_pWrtShell : pView->GetWrtShellPtr();
 
     if (!IsFieldEdit())   // insert new field
diff --git a/sw/source/ui/fldui/fldtdlg.cxx b/sw/source/ui/fldui/fldtdlg.cxx
index f2d0768d34c2..f0deba6d3108 100644
--- a/sw/source/ui/fldui/fldtdlg.cxx
+++ b/sw/source/ui/fldui/fldtdlg.cxx
@@ -220,7 +220,7 @@ void SwFieldDlg::ReInitTabPage(std::string_view rPageId, 
bool bOnlyActivate)
 // newly initialise after activation of a few TabPages
 void SwFieldDlg::Activate()
 {
-    SwView* pView = ::GetActiveView();
+    SwView* pView = GetActiveView();
     if( !pView )
         return;
 
@@ -243,7 +243,6 @@ void SwFieldDlg::EnableInsert(bool bEnable)
     if( bEnable )
     {
         SwView* pView = ::GetActiveView();
-        OSL_ENSURE(pView, "no view found");
         if( !pView ||
                 (pView->GetWrtShell().IsReadOnlyAvailable() &&
                     pView->GetWrtShell().HasReadonlySel()) )
diff --git a/sw/source/ui/fmtui/tmpdlg.cxx b/sw/source/ui/fmtui/tmpdlg.cxx
index e6fb3f00e091..c8600f5ca7e1 100644
--- a/sw/source/ui/fmtui/tmpdlg.cxx
+++ b/sw/source/ui/fmtui/tmpdlg.cxx
@@ -277,19 +277,20 @@ void SwTemplateDlgController::PageCreated(const OString& 
rId, SfxTabPage &rPage
 
     if (rId == "font")
     {
-        OSL_ENSURE(::GetActiveView(), "no active view");
-
-        SvxFontListItem aFontListItem( *static_cast<const 
SvxFontListItem*>(::GetActiveView()->
-            GetDocShell()->GetItem( SID_ATTR_CHAR_FONTLIST ) ) );
-
-        aSet.Put (SvxFontListItem( aFontListItem.GetFontList(), 
SID_ATTR_CHAR_FONTLIST));
-        sal_uInt32 nFlags = 0;
-        if(rPage.GetItemSet().GetParent() && 0 == (nHtmlMode & HTMLMODE_ON ))
-            nFlags = SVX_RELATIVE_MODE;
-        if( SfxStyleFamily::Char == nType )
-            nFlags = nFlags|SVX_PREVIEW_CHARACTER;
-        aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, nFlags));
-        rPage.PageCreated(aSet);
+        if (SwView* pView = GetActiveView())
+        {
+            SvxFontListItem aFontListItem( *static_cast<const 
SvxFontListItem*>(pView->
+                GetDocShell()->GetItem( SID_ATTR_CHAR_FONTLIST ) ) );
+
+            aSet.Put (SvxFontListItem( aFontListItem.GetFontList(), 
SID_ATTR_CHAR_FONTLIST));
+            sal_uInt32 nFlags = 0;
+            if(rPage.GetItemSet().GetParent() && 0 == (nHtmlMode & HTMLMODE_ON 
))
+                nFlags = SVX_RELATIVE_MODE;
+            if( SfxStyleFamily::Char == nType )
+                nFlags = nFlags|SVX_PREVIEW_CHARACTER;
+            aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, nFlags));
+            rPage.PageCreated(aSet);
+        }
     }
     else if (rId == "fonteffect")
     {
diff --git a/sw/source/ui/misc/pggrid.cxx b/sw/source/ui/misc/pggrid.cxx
index 18f66cc08c1a..c483c4f472b2 100644
--- a/sw/source/ui/misc/pggrid.cxx
+++ b/sw/source/ui/misc/pggrid.cxx
@@ -90,8 +90,7 @@ SwTextGridPage::SwTextGridPage(weld::Container* pPage, 
weld::DialogController* p
     m_xDisplayCB->connect_toggled(LINK(this, SwTextGridPage, DisplayGridHdl));
 
     //Get the default paper mode
-    SwView *pView   = ::GetActiveView();
-    if( pView )
+    if (SwView *pView = GetActiveView())
     {
         SwWrtShell* pSh = pView->GetWrtShellPtr();
         if( pSh )
@@ -151,8 +150,7 @@ bool SwTextGridPage::FillItemSet(SfxItemSet *rSet)
     }
 
     // draw ticks of ruler
-    SwView * pView = ::GetActiveView();
-    if (pView)
+    if (SwView * pView = GetActiveView())
     {
         if ( m_bHRulerChanged )
             pView->GetHRuler().DrawTicks();
diff --git a/sw/source/ui/misc/titlepage.cxx b/sw/source/ui/misc/titlepage.cxx
index 3d9195730598..4308c8db246d 100644
--- a/sw/source/ui/misc/titlepage.cxx
+++ b/sw/source/ui/misc/titlepage.cxx
@@ -146,7 +146,9 @@ sal_uInt16 SwTitlePageDlg::GetInsertPosition() const
 
 SwTitlePageDlg::SwTitlePageDlg(weld::Window *pParent)
     : SfxDialogController(pParent, "modules/swriter/ui/titlepage.ui", 
"DLG_TITLEPAGE")
-    , mrSh(*::GetActiveView()->GetWrtShellPtr())
+    , mpTitleDesc(nullptr)
+    , mpIndexDesc(nullptr)
+    , mpNormalDesc(nullptr)
     , 
m_xUseExistingPagesRB(m_xBuilder->weld_radio_button("RB_USE_EXISTING_PAGES"))
     , m_xPageCountNF(m_xBuilder->weld_spin_button("NF_PAGE_COUNT"))
     , m_xDocumentStartRB(m_xBuilder->weld_radio_button("RB_DOCUMENT_START"))
@@ -160,46 +162,51 @@ SwTitlePageDlg::SwTitlePageDlg(weld::Window *pParent)
     , m_xPagePropertiesPB(m_xBuilder->weld_button("PB_PAGE_PROPERTIES"))
     , m_xOkPB(m_xBuilder->weld_button("ok"))
 {
+    SwView* pView = GetActiveView();
+    if (!pView)
+        return;
+    SwWrtShell& rWrtShell = pView->GetWrtShell();
+
     m_xOkPB->connect_clicked(LINK(this, SwTitlePageDlg, OKHdl));
     m_xRestartNumberingCB->connect_toggled(LINK(this, SwTitlePageDlg, 
RestartNumberingHdl));
     m_xSetPageNumberCB->connect_toggled(LINK(this, SwTitlePageDlg, 
SetPageNumberHdl));
-    m_xPageStartNF->set_max(mrSh.GetPageCnt() + 1);
+    m_xPageStartNF->set_max(rWrtShell.GetPageCnt() + 1);
 
     sal_uInt16 nSetPage = 1;
     sal_uInt16 nResetPage = 1;
     sal_uInt16 nTitlePages = 1;
-    lcl_PushCursor(mrSh);
+    lcl_PushCursor(rWrtShell);
 
-    SwView& rView = mrSh.GetView();
+    SwView& rView = rWrtShell.GetView();
     rView.InvalidateRulerPos();
 
     bool bMaybeResetNumbering = false;
 
-    mpTitleDesc = mrSh.GetPageDescFromPool(RES_POOLPAGE_FIRST);
-    mpIndexDesc = mrSh.GetPageDescFromPool(RES_POOLPAGE_REGISTER);
-    mpNormalDesc = mrSh.GetPageDescFromPool(RES_POOLPAGE_STANDARD);
+    mpTitleDesc = rWrtShell.GetPageDescFromPool(RES_POOLPAGE_FIRST);
+    mpIndexDesc = rWrtShell.GetPageDescFromPool(RES_POOLPAGE_REGISTER);
+    mpNormalDesc = rWrtShell.GetPageDescFromPool(RES_POOLPAGE_STANDARD);
 
-    mrSh.StartOfSection();
-    if (lcl_GetPageDesc(mrSh, nSetPage, &mpPageFormatDesc))
+    rWrtShell.StartOfSection();
+    if (lcl_GetPageDesc(rWrtShell, nSetPage, &mpPageFormatDesc))
     {
         if (mpPageFormatDesc->GetPageDesc() == mpTitleDesc)
         {
-            while (mrSh.SttNxtPg())
+            while (rWrtShell.SttNxtPg())
             {
-                const size_t nCurIdx = mrSh.GetCurPageDesc();
-                const SwPageDesc& rPageDesc = mrSh.GetPageDesc(nCurIdx);
+                const size_t nCurIdx = rWrtShell.GetCurPageDesc();
+                const SwPageDesc& rPageDesc = rWrtShell.GetPageDesc(nCurIdx);
 
                 if (mpIndexDesc != &rPageDesc)
                 {
                     mpNormalDesc = &rPageDesc;
-                    bMaybeResetNumbering = lcl_GetPageDesc(mrSh, nResetPage, 
nullptr);
+                    bMaybeResetNumbering = lcl_GetPageDesc(rWrtShell, 
nResetPage, nullptr);
                     break;
                 }
                 ++nTitlePages;
             }
         }
     }
-    lcl_PopCursor(mrSh);
+    lcl_PopCursor(rWrtShell);
 
     m_xUseExistingPagesRB->set_active(true);
     m_xPageCountNF->set_value(nTitlePages);
@@ -207,7 +214,7 @@ SwTitlePageDlg::SwTitlePageDlg(weld::Window *pParent)
 
     m_xDocumentStartRB->set_active(true);
     m_xPageStartNF->set_sensitive(false);
-    m_xPageStartNF->set_value(lcl_GetCurrentPage(mrSh));
+    m_xPageStartNF->set_value(lcl_GetCurrentPage(rWrtShell));
     Link<weld::Toggleable&,void> aStartPageHdl = LINK(this, SwTitlePageDlg, 
StartPageHdl);
     m_xDocumentStartRB->connect_toggled(aStartPageHdl);
     m_xPageStartRB->connect_toggled(aStartPageHdl);
@@ -255,16 +262,24 @@ SwTitlePageDlg::~SwTitlePageDlg()
 
 IMPL_LINK_NOARG(SwTitlePageDlg, EditHdl, weld::Button&, void)
 {
-    SwView& rView = mrSh.GetView();
-    rView.GetDocShell()->FormatPage(getDialog(), 
m_xPagePropertiesLB->get_active_text(), "page", mrSh);
+    SwView* pView = GetActiveView();
+    if (!pView)
+        return;
+    SwWrtShell& rWrtShell = pView->GetWrtShell();
+    SwView& rView = rWrtShell.GetView();
+    rView.GetDocShell()->FormatPage(getDialog(), 
m_xPagePropertiesLB->get_active_text(), "page", rWrtShell);
     rView.InvalidateRulerPos();
 }
 
 IMPL_LINK_NOARG(SwTitlePageDlg, OKHdl, weld::Button&, void)
 {
-    lcl_PushCursor(mrSh);
+    SwView* pView = GetActiveView();
+    if (!pView)
+        return;
+    SwWrtShell& rWrtShell = pView->GetWrtShell();
+    lcl_PushCursor(rWrtShell);
 
-    mrSh.StartUndo();
+    rWrtShell.StartUndo();
 
     SwFormatPageDesc aTitleDesc(mpTitleDesc);
 
@@ -278,41 +293,41 @@ IMPL_LINK_NOARG(SwTitlePageDlg, OKHdl, weld::Button&, 
void)
     {
         // Assuming that a failure to GotoPage means the end of the document,
         // insert new pages after the last page.
-        if (!lcl_GotoPage(mrSh, GetInsertPosition()))
+        if (!lcl_GotoPage(rWrtShell, GetInsertPosition()))
         {
-            mrSh.EndPg();
+            rWrtShell.EndPg();
             // Add one more page as a content page to follow the new title 
pages.
-            mrSh.InsertPageBreak();
+            rWrtShell.InsertPageBreak();
         }
         for (sal_uInt16 nI = 0; nI < nNumTitlePages; ++nI)
-            mrSh.InsertPageBreak();
+            rWrtShell.InsertPageBreak();
         // In order to be able to access these new pages, the layout needs to 
be recalculated first.
-        mrSh.CalcLayout();
+        rWrtShell.CalcLayout();
     }
 
-    if (lcl_GotoPage(mrSh, GetInsertPosition()))
+    if (lcl_GotoPage(rWrtShell, GetInsertPosition()))
     {
-        mrSh.SetAttrItem(aTitleDesc);
+        rWrtShell.SetAttrItem(aTitleDesc);
         for (sal_uInt16 nI = 1; nI < nNumTitlePages; ++nI)
         {
-            if (mrSh.SttNxtPg())
-                lcl_ChangePage(mrSh, SAL_MAX_UINT16, mpIndexDesc);
+            if (rWrtShell.SttNxtPg())
+                lcl_ChangePage(rWrtShell, SAL_MAX_UINT16, mpIndexDesc);
         }
     }
 
     if ((m_xRestartNumberingCB->get_active() || nNumTitlePages > 1)
-        && lcl_GotoPage(mrSh, GetInsertPosition(), nNumTitlePages))
+        && lcl_GotoPage(rWrtShell, GetInsertPosition(), nNumTitlePages))
     {
         sal_uInt16 nPgNo
             = m_xRestartNumberingCB->get_active() ? 
m_xRestartNumberingNF->get_value() : 0;
         const SwPageDesc* pNewDesc = nNumTitlePages > 1 ? mpNormalDesc : 
nullptr;
-        lcl_ChangePage(mrSh, nPgNo, pNewDesc);
+        lcl_ChangePage(rWrtShell, nPgNo, pNewDesc);
     }
 
-    mrSh.EndUndo();
-    lcl_PopCursor(mrSh);
+    rWrtShell.EndUndo();
+    lcl_PopCursor(rWrtShell);
     if (!m_xUseExistingPagesRB->get_active())
-        lcl_GotoPage(mrSh, GetInsertPosition());
+        lcl_GotoPage(rWrtShell, GetInsertPosition());
     m_xDialog->response(RET_OK);
 }
 
diff --git a/sw/source/uibase/app/apphdl.cxx b/sw/source/uibase/app/apphdl.cxx
index 22ccceac4271..bf1d4699a62b 100644
--- a/sw/source/uibase/app/apphdl.cxx
+++ b/sw/source/uibase/app/apphdl.cxx
@@ -171,9 +171,8 @@ void SwModule::StateOther(SfxItemSet &rSet)
             case FN_MAILMERGE_NEXT_ENTRY:
             case FN_MAILMERGE_LAST_ENTRY:
             {
-                SwView* pView = ::GetActiveView();
                 std::shared_ptr<SwMailMergeConfigItem> xConfigItem;
-                if (pView)
+                if (SwView* pView = GetActiveView())
                     xConfigItem = pView->GetMailMergeConfigItem();
                 if (!xConfigItem)
                     rSet.DisableItem(nWhich);
@@ -205,9 +204,8 @@ void SwModule::StateOther(SfxItemSet &rSet)
             case FN_MAILMERGE_PRINT_DOCUMENTS:
             case FN_MAILMERGE_EMAIL_DOCUMENTS:
             {
-                SwView* pView = ::GetActiveView();
                 std::shared_ptr<SwMailMergeConfigItem> xConfigItem;
-                if (pView)
+                if (SwView* pView = GetActiveView())
                     xConfigItem = pView->EnsureMailMergeConfigItem();
 
                 // #i51949# hide e-Mail option if e-Mail is not supported
@@ -751,6 +749,9 @@ void SwModule::ExecOther(SfxRequest& rReq)
         case FN_MAILMERGE_CURRENT_ENTRY:
         {
             SwView* pView = ::GetActiveView();
+            if (!pView)
+                return;
+
             const std::shared_ptr<SwMailMergeConfigItem>& xConfigItem = 
pView->GetMailMergeConfigItem();
             if (!xConfigItem)
                 return;
@@ -812,14 +813,18 @@ void SwModule::ExecOther(SfxRequest& rReq)
         case FN_MAILMERGE_PRINT_DOCUMENTS:
         case FN_MAILMERGE_EMAIL_DOCUMENTS:
         {
-            std::shared_ptr<SwMailMergeConfigItem> xConfigItem = 
GetActiveView()->GetMailMergeConfigItem();
+            SwView* pView = ::GetActiveView();
+            if (!pView)
+                return;
+
+            std::shared_ptr<SwMailMergeConfigItem> xConfigItem = 
pView->GetMailMergeConfigItem();
             assert(xConfigItem);
             if (!xConfigItem->GetResultSet().is())
             {
                 // The connection has been attempted, but failed or no results 
found,
                 // so invalidate the toolbar buttons in case they need to be 
disabled.
                 SfxBindings& rBindings
-                    = 
GetActiveView()->GetWrtShell().GetView().GetViewFrame()->GetBindings();
+                    = 
pView->GetWrtShell().GetView().GetViewFrame()->GetBindings();
                 rBindings.Invalidate(FN_MAILMERGE_CREATE_DOCUMENTS);
                 rBindings.Invalidate(FN_MAILMERGE_SAVE_DOCUMENTS);
                 rBindings.Invalidate(FN_MAILMERGE_PRINT_DOCUMENTS);
@@ -834,7 +839,7 @@ void SwModule::ExecOther(SfxRequest& rReq)
 
             if (nWhich == FN_MAILMERGE_CREATE_DOCUMENTS)
             {
-                xConfigItem = SwDBManager::PerformMailMerge(GetActiveView());
+                xConfigItem = SwDBManager::PerformMailMerge(pView);
 
                 if (xConfigItem && xConfigItem->GetTargetView())
                     
xConfigItem->GetTargetView()->GetViewFrame()->GetFrame().Appear();
diff --git a/sw/source/uibase/app/swmodul1.cxx 
b/sw/source/uibase/app/swmodul1.cxx
index 781c30a5e74a..43dc9dd4d0af 100644
--- a/sw/source/uibase/app/swmodul1.cxx
+++ b/sw/source/uibase/app/swmodul1.cxx
@@ -107,8 +107,7 @@ static void lcl_SetUIPrefs(const SwViewOption &rPref, 
SwView* pView, SwViewShell
 
 SwWrtShell* GetActiveWrtShell()
 {
-    SwView *pActive = ::GetActiveView();
-    if( pActive )
+    if (SwView *pActive = GetActiveView())
         return &pActive->GetWrtShell();
     return nullptr;
 }
diff --git a/sw/source/uibase/dbui/mailmergetoolbarcontrols.cxx 
b/sw/source/uibase/dbui/mailmergetoolbarcontrols.cxx
index a97974f57f34..db3d38f1ee5f 100644
--- a/sw/source/uibase/dbui/mailmergetoolbarcontrols.cxx
+++ b/sw/source/uibase/dbui/mailmergetoolbarcontrols.cxx
@@ -291,9 +291,8 @@ uno::Reference<awt::XWindow> 
MMCurrentEntryController::createItemWindow(const un
 
 IMPL_LINK(MMCurrentEntryController, CurrentEditUpdatedHdl, weld::Entry&, 
rEdit, bool)
 {
-    SwView* pView = ::GetActiveView();
     std::shared_ptr<SwMailMergeConfigItem> xConfigItem;
-    if (pView)
+    if (SwView* pView = GetActiveView())
         xConfigItem = pView->GetMailMergeConfigItem();
 
     if (!xConfigItem)
@@ -315,9 +314,8 @@ void MMCurrentEntryController::statusChanged(const 
frame::FeatureStateEvent& rEv
     if (!m_xCurrentEdit)
         return;
 
-    SwView* pView = ::GetActiveView();
     std::shared_ptr<SwMailMergeConfigItem> xConfigItem;
-    if (pView)
+    if (SwView* pView = GetActiveView())
         xConfigItem = pView->GetMailMergeConfigItem();
 
     if (!xConfigItem || !rEvent.IsEnabled)
@@ -360,9 +358,8 @@ uno::Reference<awt::XWindow> 
MMExcludeEntryController::createItemWindow(const un
 
 IMPL_STATIC_LINK(MMExcludeEntryController, ExcludeHdl, weld::Toggleable&, 
rCheckbox, void)
 {
-    SwView* pView = ::GetActiveView();
     std::shared_ptr<SwMailMergeConfigItem> xConfigItem;
-    if (pView)
+    if (SwView* pView = GetActiveView())
         xConfigItem = pView->GetMailMergeConfigItem();
 
     if (xConfigItem)
@@ -374,9 +371,8 @@ void MMExcludeEntryController::statusChanged(const 
frame::FeatureStateEvent& rEv
     if (!m_xExcludeCheckbox)
         return;
 
-    SwView* pView = ::GetActiveView();
     std::shared_ptr<SwMailMergeConfigItem> xConfigItem;
-    if (pView)
+    if (SwView* pView = GetActiveView())
         xConfigItem = pView->GetMailMergeConfigItem();
 
     if (!xConfigItem || !rEvent.IsEnabled)
diff --git a/sw/source/uibase/envelp/syncbtn.cxx 
b/sw/source/uibase/envelp/syncbtn.cxx
index d00ff4913cbe..2d829a45bd46 100644
--- a/sw/source/uibase/envelp/syncbtn.cxx
+++ b/sw/source/uibase/envelp/syncbtn.cxx
@@ -44,8 +44,7 @@ SwSyncChildWin::SwSyncChildWin(vcl::Window* _pParent,
         weld::Dialog* pDlg = pBtnDlg->getDialog();
         Point aPos;
 
-        SwView* pActiveView = ::GetActiveView();
-        if (pActiveView)
+        if (SwView* pActiveView = GetActiveView())
         {
             const SwEditWin &rEditWin = pActiveView->GetEditWin();
             aPos = rEditWin.OutputToScreenPixel(Point(0, 0));
diff --git a/sw/source/uibase/fldui/fldmgr.cxx 
b/sw/source/uibase/fldui/fldmgr.cxx
index 49b0584586b0..e40b152fba23 100644
--- a/sw/source/uibase/fldui/fldmgr.cxx
+++ b/sw/source/uibase/fldui/fldmgr.cxx
@@ -355,10 +355,8 @@ const SwFieldPack aSwFields[] =
 // access to the shell
 static SwWrtShell* lcl_GetShell()
 {
-    SwView* pView = ::GetActiveView();
-    if ( nullptr != pView )
+    if (SwView* pView = GetActiveView())
         return pView->GetWrtShellPtr();
-    OSL_FAIL("no current shell found!");
     return nullptr;
 }
 
diff --git a/sw/source/uibase/fldui/xfldui.cxx 
b/sw/source/uibase/fldui/xfldui.cxx
index ca5d62a54ec4..db1ee93aedaf 100644
--- a/sw/source/uibase/fldui/xfldui.cxx
+++ b/sw/source/uibase/fldui/xfldui.cxx
@@ -51,8 +51,16 @@ bool SwFieldMgr::IsDBNumeric( const OUString& rDBName, const 
OUString& rTableQry
 {
     bool bNumeric = true;
 
-    SwDBManager* pDBManager = m_pWrtShell ? m_pWrtShell->GetDBManager() :
-                            ::GetActiveView()->GetWrtShell().GetDBManager();
+    SwDBManager* pDBManager;
+    if (m_pWrtShell)
+        pDBManager = m_pWrtShell->GetDBManager();
+    else
+    {
+        if (SwView* pView = GetActiveView())
+            pDBManager = pView->GetWrtShell().GetDBManager();
+        else
+            return bNumeric;
+    }
 
     Reference< XConnection> xConnection =
                     pDBManager->RegisterConnection(rDBName);
diff --git a/sw/source/uibase/inc/drpcps.hxx b/sw/source/uibase/inc/drpcps.hxx
index d1b0a09d082a..49da98d7f550 100644
--- a/sw/source/uibase/inc/drpcps.hxx
+++ b/sw/source/uibase/inc/drpcps.hxx
@@ -72,7 +72,7 @@ class SwDropCapsPict final : public 
weld::CustomWidgetController
     Size            CalcTextSize();
     inline void     InitPrinter();
     void            InitPrinter_();
-    static void     GetFontSettings( const SwDropCapsPage& _rPage, vcl::Font& 
_rFont, sal_uInt16 _nWhich );
+    static void     GetFontSettings( vcl::Font& _rFont, sal_uInt16 _nWhich );
     void            GetFirstScriptSegment(sal_Int32 &start, sal_Int32 &end, 
sal_uInt16 &scriptType);
     bool            GetNextScriptSegment(size_t &nIdx, sal_Int32 &start, 
sal_Int32 &end, sal_uInt16 &scriptType);
 
@@ -116,8 +116,6 @@ friend class SwDropCapsPict;
     bool          bFormat;
     bool          bHtmlMode;
 
-    SwWrtShell &rSh;
-
     std::unique_ptr<weld::CheckButton> m_xDropCapsBox;
     std::unique_ptr<weld::CheckButton> m_xWholeWordCB;
     std::unique_ptr<weld::Label> m_xSwitchText;
diff --git a/sw/source/uibase/inc/swuiccoll.hxx 
b/sw/source/uibase/inc/swuiccoll.hxx
index 4695bfe51691..8d13ba6ba28a 100644
--- a/sw/source/uibase/inc/swuiccoll.hxx
+++ b/sw/source/uibase/inc/swuiccoll.hxx
@@ -30,7 +30,6 @@ class SwCondCollPage final : public SfxTabPage
 {
     std::vector<OUString> m_aStrArr;
 
-    SwWrtShell          &m_rSh;
     const CommandStruct*m_pCmds;
     SwFormat*              m_pFormat;
 
diff --git a/sw/source/uibase/inc/titlepage.hxx 
b/sw/source/uibase/inc/titlepage.hxx
index 35a97c13041f..9e8c58984652 100644
--- a/sw/source/uibase/inc/titlepage.hxx
+++ b/sw/source/uibase/inc/titlepage.hxx
@@ -24,8 +24,6 @@ class SwPageDesc;
 class SwTitlePageDlg final : public SfxDialogController
 {
 private:
-    SwWrtShell& mrSh;
-
     std::unique_ptr<const SwFormatPageDesc> mpPageFormatDesc;
 
     SwPageDesc* mpTitleDesc;
diff --git a/sw/source/uibase/misc/redlndlg.cxx 
b/sw/source/uibase/misc/redlndlg.cxx
index a80fd90ee0f3..c889773586ed 100644
--- a/sw/source/uibase/misc/redlndlg.cxx
+++ b/sw/source/uibase/misc/redlndlg.cxx
@@ -207,8 +207,8 @@ SwRedlineAcceptDlg::~SwRedlineAcceptDlg()
 
 void SwRedlineAcceptDlg::Init(SwRedlineTable::size_type nStart)
 {
-    SwView *pView = ::GetActiveView();
-    std::unique_ptr<SwWait> xWait(pView ? new SwWait(*pView->GetDocShell(), 
false) : nullptr);
+    if (SwView *pView = GetActiveView())
+        std::unique_ptr<SwWait> xWait(pView ? new 
SwWait(*pView->GetDocShell(), false) : nullptr);
     weld::TreeView& rTreeView = m_pTable->GetWidget();
     m_aUsedSeqNo.clear();
 
@@ -240,7 +240,9 @@ void SwRedlineAcceptDlg::InitAuthors()
         return;
 
     SwView *pView = ::GetActiveView();
-    SwWrtShell* pSh = pView ? pView->GetWrtShellPtr() : nullptr;
+    if (!pView)
+        return;
+    SwWrtShell* pSh = pView->GetWrtShellPtr();
 
     SvxTPFilter *pFilterPage = m_xTabPagesCTRL->GetFilterPage();
 
@@ -483,7 +485,10 @@ SwRedlineTable::size_type 
SwRedlineAcceptDlg::CalcDiff(SwRedlineTable::size_type
 
     weld::TreeView& rTreeView = m_pTable->GetWidget();
     rTreeView.freeze();
-    SwView *pView   = ::GetActiveView();
+    SwView *pView = GetActiveView();
+    if (!pView)
+        return SwRedlineTable::npos;
+
     SwWrtShell* pSh = pView->GetWrtShellPtr();
     bool bHasRedlineAutoFormat = HasRedlineAutoFormat();
     SwRedlineDataParent *const pParent = m_RedlineParents[nStart].get();
@@ -651,7 +656,11 @@ void 
SwRedlineAcceptDlg::InsertChildren(SwRedlineDataParent *pParent, const SwRa
 
 void SwRedlineAcceptDlg::RemoveParents(SwRedlineTable::size_type nStart, 
SwRedlineTable::size_type nEnd)
 {
-    SwWrtShell* pSh = ::GetActiveView()->GetWrtShellPtr();
+    SwView *pView = ::GetActiveView();
+    if (!pView)
+        return;
+    SwWrtShell* pSh = pView->GetWrtShellPtr();
+
     SwRedlineTable::size_type nCount = pSh->GetRedlineCount();
 
     std::vector<const weld::TreeIter*> aLBoxArr;
@@ -727,7 +736,7 @@ void 
SwRedlineAcceptDlg::RemoveParents(SwRedlineTable::size_type nStart, SwRedli
 
 void SwRedlineAcceptDlg::InsertParents(SwRedlineTable::size_type nStart, 
SwRedlineTable::size_type nEnd)
 {
-    SwView *pView = ::GetActiveView();
+    SwView *pView = GetActiveView();
     if (!pView)
         return;
 
@@ -909,7 +918,11 @@ void 
SwRedlineAcceptDlg::InsertParents(SwRedlineTable::size_type nStart, SwRedli
 
 void SwRedlineAcceptDlg::CallAcceptReject( bool bSelect, bool bAccept )
 {
-    SwWrtShell* pSh = ::GetActiveView()->GetWrtShellPtr();
+    SwView *pView = GetActiveView();
+    if (!pView)
+        return;
+    SwWrtShell* pSh = pView->GetWrtShellPtr();
+
     int nPos = -1;
 
     typedef std::vector<std::unique_ptr<weld::TreeIter>> ListBoxEntries_t;
@@ -1050,7 +1063,11 @@ void SwRedlineAcceptDlg::CallAcceptReject( bool bSelect, 
bool bAccept )
 
 SwRedlineTable::size_type SwRedlineAcceptDlg::GetRedlinePos(const 
weld::TreeIter& rEntry)
 {
-    SwWrtShell* pSh = ::GetActiveView()->GetWrtShellPtr();
+    SwView *pView = GetActiveView();
+    if (!pView)
+        return SwRedlineTable::npos;
+    SwWrtShell* pSh = pView->GetWrtShellPtr();
+
     weld::TreeView& rTreeView = m_pTable->GetWidget();
     return pSh->FindRedlineOfData( 
*static_cast<SwRedlineDataParent*>(weld::fromId<RedlinData*>(
                                     rTreeView.get_id(rEntry))->pData)->pData );
@@ -1078,10 +1095,12 @@ IMPL_LINK_NOARG(SwRedlineAcceptDlg, RejectAllHdl, 
SvxTPView*, void)
 
 IMPL_LINK_NOARG(SwRedlineAcceptDlg, UndoHdl, SvxTPView*, void)
 {
-    SwView * pView = ::GetActiveView();
-    pView->GetViewFrame()->GetDispatcher()->
-                Execute(SID_UNDO, SfxCallMode::SYNCHRON);
-    m_pTPView->EnableUndo(pView->GetSlotState(SID_UNDO) != nullptr);
+    if (SwView* pView = GetActiveView())
+    {
+        pView->GetViewFrame()->GetDispatcher()->
+                    Execute(SID_UNDO, SfxCallMode::SYNCHRON);
+        m_pTPView->EnableUndo(pView->GetSlotState(SID_UNDO) != nullptr);
+    }
 
     Activate();
 }
@@ -1105,9 +1124,13 @@ IMPL_LINK_NOARG(SwRedlineAcceptDlg, SelectHdl, 
weld::TreeView&, void)
 
 IMPL_LINK_NOARG(SwRedlineAcceptDlg, GotoHdl, Timer *, void)
 {
-    SwWrtShell* pSh = ::GetActiveView()->GetWrtShellPtr();
     m_aSelectTimer.Stop();
 
+    SwView* pView = GetActiveView();
+    if (!pView)
+        return;
+    SwWrtShell* pSh = pView->GetWrtShellPtr();
+
     bool bIsNotFormated = false;
     bool bSel = false;
 
@@ -1201,7 +1224,11 @@ IMPL_LINK(SwRedlineAcceptDlg, CommandHdl, const 
CommandEvent&, rCEvt, bool)
     if (rCEvt.GetCommand() != CommandEventId::ContextMenu)
         return false;
 
-    SwWrtShell* pSh = ::GetActiveView()->GetWrtShellPtr();
+    SwView* pView = GetActiveView();
+    if (!pView)
+        return false;
+    SwWrtShell* pSh = pView->GetWrtShellPtr();
+
     const SwRangeRedline *pRed = nullptr;
 
     weld::TreeView& rTreeView = m_pTable->GetWidget();
@@ -1323,7 +1350,7 @@ IMPL_LINK(SwRedlineAcceptDlg, CommandHdl, const 
CommandEvent&, rCEvt, bool)
         if (nSortMode == 4)
             nSortMode = -1; // unsorted / sorted by position
 
-        SwWait aWait( *::GetActiveView()->GetDocShell(), false );
+        SwWait aWait( *pView->GetDocShell(), false );
         m_pTable->HeaderBarClick(nSortMode);
         if (nSortMode == -1)
             Init();             // newly fill everything
diff --git a/sw/source/uibase/ribbar/inputwin.cxx 
b/sw/source/uibase/ribbar/inputwin.cxx
index 255ae24335ab..8c0666549697 100644
--- a/sw/source/uibase/ribbar/inputwin.cxx
+++ b/sw/source/uibase/ribbar/inputwin.cxx
@@ -335,9 +335,11 @@ void  SwInputWindow::ApplyFormula()
     if (!m_pView)
     {
         // presumably there must be an active view now since the event arrived
-        SwView *const pActiveView = ::GetActiveView();
-        // this just makes the input window go away, so that the next time it 
works
-        pActiveView->GetViewFrame()->GetDispatcher()->Execute(FN_EDIT_FORMULA, 
SfxCallMode::ASYNCHRON);
+        if (SwView* pView = GetActiveView())
+        {
+            // this just makes the input window go away, so that the next time 
it works
+            pView->GetViewFrame()->GetDispatcher()->Execute(FN_EDIT_FORMULA, 
SfxCallMode::ASYNCHRON);
+        }
         return;
     }
 
@@ -368,9 +370,11 @@ void  SwInputWindow::CancelFormula()
     if (!m_pView)
     {
         // presumably there must be an active view now since the event arrived
-        SwView *const pActiveView = ::GetActiveView();
-        // this just makes the input window go away, so that the next time it 
works
-        pActiveView->GetViewFrame()->GetDispatcher()->Execute(FN_EDIT_FORMULA, 
SfxCallMode::ASYNCHRON);
+        if (SwView* pActiveView = GetActiveView())
+        {
+            // this just makes the input window go away, so that the next time 
it works
+            
pActiveView->GetViewFrame()->GetDispatcher()->Execute(FN_EDIT_FORMULA, 
SfxCallMode::ASYNCHRON);
+        }
         return;
     }
 
diff --git a/sw/source/uibase/ribbar/workctrl.cxx 
b/sw/source/uibase/ribbar/workctrl.cxx
index 8f994cf0ba8d..398913a2ac61 100644
--- a/sw/source/uibase/ribbar/workctrl.cxx
+++ b/sw/source/uibase/ribbar/workctrl.cxx
@@ -139,13 +139,16 @@ IMPL_STATIC_LINK(SwTbxAutoTextCtrl, PopupHdl, Menu*, 
pMenu, bool)
     OUString sShortName =
         pGlossaryList->GetBlockShortName(nBlock - 1, nId - (100 * nBlock) - 1);
 
-    SwGlossaryHdl* pGlosHdl = ::GetActiveView()->GetGlosHdl();
-    SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
-    ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc();
-    if ( fnSetActGroup )
-        (*fnSetActGroup)( sGroup );
-    pGlosHdl->SetCurGroup(sGroup, true);
-    pGlosHdl->InsertGlossary(sShortName);
+    if (SwView* pView = GetActiveView())
+    {
+        SwGlossaryHdl* pGlosHdl = pView->GetGlosHdl();
+        SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
+        ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc();
+        if ( fnSetActGroup )
+            (*fnSetActGroup)( sGroup );
+        pGlosHdl->SetCurGroup(sGroup, true);
+        pGlosHdl->InsertGlossary(sShortName);
+    }
 
     return false;
 }
diff --git a/sw/source/uibase/shells/tabsh.cxx 
b/sw/source/uibase/shells/tabsh.cxx
index 3cbea6b77389..1073bf9b0d00 100644
--- a/sw/source/uibase/shells/tabsh.cxx
+++ b/sw/source/uibase/shells/tabsh.cxx
@@ -687,8 +687,7 @@ void SwTableShell::Execute(SfxRequest &rReq)
             break;
         case FN_NUM_FORMAT_TABLE_DLG:
         {
-            SwView* pView = GetActiveView();
-            if(pView)
+            if (SwView* pView = GetActiveView())
             {
                 FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebView*>( 
pView) !=  nullptr );
                 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< 
sal_uInt16 >(eMetric)));
diff --git a/sw/source/uibase/shells/textsh.cxx 
b/sw/source/uibase/shells/textsh.cxx
index cb0ebc60b2ee..522b8ddbf1dd 100644
--- a/sw/source/uibase/shells/textsh.cxx
+++ b/sw/source/uibase/shells/textsh.cxx
@@ -97,19 +97,21 @@ SFX_IMPL_INTERFACE(SwTextShell, SwBaseShell)
 
 IMPL_STATIC_LINK( SwTextShell, DialogClosedHdl, 
css::ui::dialogs::DialogClosedEvent*, pEvent, void )
 {
-    SwView* pView = ::GetActiveView();
-    SwWrtShell& rWrtShell = pView->GetWrtShell();
-
-    sal_Int16 nDialogRet = pEvent->DialogResult;
-    if( nDialogRet == ui::dialogs::ExecutableDialogResults::CANCEL )
-    {
-        rWrtShell.Undo();
-        rWrtShell.GetIDocumentUndoRedo().ClearRedo();
-    }
-    else
+    if (SwView* pView = GetActiveView())
     {
-        OSL_ENSURE( nDialogRet == ui::dialogs::ExecutableDialogResults::OK,
-            "dialog execution failed" );
+        SwWrtShell& rWrtShell = pView->GetWrtShell();
+
+        sal_Int16 nDialogRet = pEvent->DialogResult;
+        if( nDialogRet == ui::dialogs::ExecutableDialogResults::CANCEL )
+        {
+            rWrtShell.Undo();
+            rWrtShell.GetIDocumentUndoRedo().ClearRedo();
+        }
+        else
+        {
+            OSL_ENSURE( nDialogRet == ui::dialogs::ExecutableDialogResults::OK,
+                "dialog execution failed" );
+        }
     }
 }
 
diff --git a/sw/source/uibase/table/chartins.cxx 
b/sw/source/uibase/table/chartins.cxx
index a1b18fedac28..a7cf76c98456 100644
--- a/sw/source/uibase/table/chartins.cxx
+++ b/sw/source/uibase/table/chartins.cxx
@@ -66,7 +66,6 @@ Point SwGetChartDialogPos( const vcl::Window *pParentWin, 
const Size& rDialogSiz
         tools::Rectangle aDesktop = pParentWin->GetDesktopRectPixel();
         Size aSpace = pParentWin->LogicToPixel(Size(8, 12), 
MapMode(MapUnit::MapAppFont));
 
-        bool bLayoutRTL = 
::GetActiveView()->GetWrtShell().IsTableRightToLeft();
         bool bCenterHor = false;
 
         if ( aDesktop.Bottom() - aObjAbs.Bottom() >= rDialogSize.Height() + 
aSpace.Height() )
@@ -88,12 +87,16 @@ Point SwGetChartDialogPos( const vcl::Window *pParentWin, 
const Size& rDialogSiz
 
             if ( bFitLeft || bFitRight )
             {
-                // if both fit, prefer right in RTL mode, left otherwise
-                bool bPutRight = bFitRight && ( bLayoutRTL || !bFitLeft );
-                if ( bPutRight )
-                    aRet.setX( aObjAbs.Right() + aSpace.Width() );
-                else
-                    aRet.setX( aObjAbs.Left() - rDialogSize.Width() - 
aSpace.Width() );
+                if (SwView* pView = GetActiveView())
+                {
+                    // if both fit, prefer right in RTL mode, left otherwise
+                    bool bLayoutRTL = 
pView->GetWrtShell().IsTableRightToLeft();
+                    bool bPutRight = bFitRight && ( bLayoutRTL || !bFitLeft );
+                    if ( bPutRight )
+                        aRet.setX( aObjAbs.Right() + aSpace.Width() );
+                    else
+                        aRet.setX( aObjAbs.Left() - rDialogSize.Width() - 
aSpace.Width() );
+                }
 
                 // center vertically
                 aRet.setY( aObjAbs.Top() + ( aObjAbs.GetHeight() - 
rDialogSize.Height() ) / 2 );
@@ -125,6 +128,8 @@ Point SwGetChartDialogPos( const vcl::Window *pParentWin, 
const Size& rDialogSiz
 SwInsertChart::SwInsertChart( const Link<css::ui::dialogs::DialogClosedEvent*, 
void>& rLink )
 {
     SwView *pView = ::GetActiveView();
+    if (!pView)
+        return;
 
     // get range string of marked data
     SwWrtShell &rWrtShell = pView->GetWrtShell();
diff --git a/sw/source/uibase/utlui/content.cxx 
b/sw/source/uibase/utlui/content.cxx
index bc920880bb3a..2c5356cd0e91 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -1672,7 +1672,7 @@ IMPL_LINK(SwContentTree, CommandHdl, const CommandEvent&, 
rCEvt, bool)
 
         // Edit only if the shown content is coming from the current view.
         if (State::HIDDEN != m_eState &&
-                (State::ACTIVE == m_eState || m_pActiveShell == 
GetActiveView()->GetWrtShellPtr())
+                (State::ACTIVE == m_eState || (GetActiveView() && 
m_pActiveShell == GetActiveView()->GetWrtShellPtr()))
                 && lcl_IsContent(*xEntry, *m_xTreeView))
         {
             const bool bReadonly = 
m_pActiveShell->GetView().GetDocShell()->IsReadOnly();
diff --git a/sw/source/uibase/utlui/gloslst.cxx 
b/sw/source/uibase/utlui/gloslst.cxx
index 3feb575e47aa..9878d0aa6716 100644
--- a/sw/source/uibase/utlui/gloslst.cxx
+++ b/sw/source/uibase/utlui/gloslst.cxx
@@ -144,7 +144,9 @@ bool SwGlossaryList::GetShortName(std::u16string_view 
rLongName,
     else if(1 < nCount)
     {
         SwView *pView  = ::GetActiveView();
-        SwGlossDecideDlg aDlg(pView ? pView->GetFrameWeld() : nullptr);
+        if (!pView)
+            return bRet;
+        SwGlossDecideDlg aDlg(pView->GetFrameWeld());
         OUString sTitle = aDlg.get_title() + " " + 
aTripleStrings.front().sBlock;
         aDlg.set_title(sTitle);
 
diff --git a/sw/source/uibase/utlui/navipi.cxx 
b/sw/source/uibase/utlui/navipi.cxx
index 669234d6bcf7..405b4442d4c2 100644
--- a/sw/source/uibase/utlui/navipi.cxx
+++ b/sw/source/uibase/utlui/navipi.cxx
@@ -1012,9 +1012,10 @@ sal_Int8 SwNavigationPI::ExecuteDrop( const 
ExecuteDropEvent& rEvt )
         SfxStringItem aOptionsItem( SID_OPTIONS, "HRC" );
         SfxLinkItem aLink( SID_DONELINK,
                             LINK( this, SwNavigationPI, DoneLink ) );
-        GetActiveView()->GetViewFrame()->GetDispatcher()->ExecuteList(
-                    SID_OPENDOC, SfxCallMode::ASYNCHRON,
-                    { &aFileItem, &aOptionsItem, &aLink });
+        if (SwView* pView = GetActiveView())
+            pView->GetViewFrame()->GetDispatcher()->ExecuteList(
+                        SID_OPENDOC, SfxCallMode::ASYNCHRON,
+                        { &aFileItem, &aOptionsItem, &aLink });
     }
     return nRet;
 }
diff --git a/sw/source/uibase/utlui/numfmtlb.cxx 
b/sw/source/uibase/utlui/numfmtlb.cxx
index 0aab232852f0..4dffed15d219 100644
--- a/sw/source/uibase/utlui/numfmtlb.cxx
+++ b/sw/source/uibase/utlui/numfmtlb.cxx
@@ -140,9 +140,7 @@ 
SwNumFormatTreeView::SwNumFormatTreeView(std::unique_ptr<weld::TreeView> xContro
 
 void SwNumFormatBase::Init()
 {
-    SwView *pView = GetActiveView();
-
-    if (pView)
+    if (SwView *pView = GetActiveView())
         m_eCurLanguage = pView->GetWrtShell().GetCurLang();
     else
         m_eCurLanguage = SvtSysLocale().GetLanguageTag().getLanguageType();
@@ -172,7 +170,6 @@ void SwNumFormatBase::SetFormatType(const SvNumFormatType 
nFormatType)
         return;
 
     SwView *pView = GetActiveView();
-    OSL_ENSURE(pView, "no view found");
     if(!pView)
         return;
     SwWrtShell &rSh = pView->GetWrtShell();
@@ -307,7 +304,6 @@ void SwNumFormatBase::SetDefFormat(const sal_uInt32 
nDefaultFormat)
     }
 
     SwView *pView = GetActiveView();
-    OSL_ENSURE(pView, "no view found");
     if(!pView)
         return;
     SwWrtShell &rSh = pView->GetWrtShell();

Reply via email to