sw/source/ui/chrdlg/chardlg.cxx | 13 ++- sw/source/ui/chrdlg/drpcps.cxx | 66 +++++++++++------ 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 | 4 - 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 | 78 ++++++++++++--------- 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 | 65 ++++++++++++----- sw/source/uibase/ribbar/inputwin.cxx | 16 ++-- sw/source/uibase/ribbar/workctrl.cxx | 20 ++--- 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, 299 insertions(+), 207 deletions(-)
New commits: commit 74f398bb58510087cc4a11bb2253715771a2c6b2 Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Tue Mar 21 16:55:59 2023 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed Mar 22 12:03:50 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> diff --git a/sw/source/ui/chrdlg/chardlg.cxx b/sw/source/ui/chrdlg/chardlg.cxx index efa16ce22797..cd62cef9e81e 100644 --- a/sw/source/ui/chrdlg/chardlg.cxx +++ b/sw/source/ui/chrdlg/chardlg.cxx @@ -174,9 +174,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)); @@ -306,8 +308,9 @@ IMPL_LINK_NOARG(SwCharURLPage, InsertFileHdl, weld::Button&, void) IMPL_LINK_NOARG(SwCharURLPage, EventHdl, weld::Button&, void) { - m_bModified |= SwMacroAssignDlg::INetFormatDlg(GetFrameWeld(), - ::GetActiveView()->GetWrtShell(), m_oINetMacroTable); + if (SwView* pView = GetActiveView()) + m_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 b3778c861479..15bdd270a0ef 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.m_rSh.GetAttrPool(), _nWhich, _nWhich); - _rPage.m_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->m_rSh.GetView().GetDocShell()->LockAllViews()); + auto aLock(rWrtShell.GetView().GetDocShell()->LockAllViews()); if (!mpPage->m_xTemplateBox->get_active()) { // query the Font at paragraph's beginning - mpPage->m_rSh.Push(); - mpPage->m_rSh.SttCursorMove(); - mpPage->m_rSh.ClearMark(); + rWrtShell.Push(); + rWrtShell.SttCursorMove(); + rWrtShell.ClearMark(); SwWhichPara pSwuifnParaCurr = GoCurrPara; SwMoveFnCollection const & pSwuifnParaStart = fnParaStart; - mpPage->m_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->m_rSh.EndCursorMove(); - mpPage->m_rSh.Pop(SwCursorShell::PopMode::DeleteCurrent); + rWrtShell.EndCursorMove(); + rWrtShell.Pop(SwCursorShell::PopMode::DeleteCurrent); } else { // query Font at character template - SwCharFormat *pFormat = mpPage->m_rSh.GetCharStyle( + SwCharFormat *pFormat = rWrtShell.GetCharStyle( mpPage->m_xTemplateBox->get_active_text(), SwWrtShell::GETSTYLE_CREATEANY ); OSL_ENSURE(pFormat, "character style doesn't exist!"); @@ -232,7 +242,7 @@ void SwDropCapsPict::UpdatePaintSettings() aFont.SetCharSet(rFormatFont.GetCharSet()); } - const Color& rFontColor = mpPage->m_rSh.GetViewOptions()->GetFontColor(); + const Color& rFontColor = rWrtShell.GetViewOptions()->GetFontColor(); aFont.SetColor( rFontColor ); maCJKFont.SetColor( rFontColor ); maCTLFont.SetColor( rFontColor ); @@ -463,7 +473,6 @@ SwDropCapsPage::SwDropCapsPage(weld::Container* pPage, weld::DialogController* p : SfxTabPage(pPage, pController, "modules/swriter/ui/dropcapspage.ui", "DropCapPage", &rSet) , m_bModified(false) , m_bFormat(true) - , m_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")) @@ -550,7 +559,9 @@ void SwDropCapsPage::Reset(const SfxItemSet *rSet) m_xDistanceField->set_value(0, FieldUnit::TWIP); } - ::FillCharStyleListBox(*m_xTemplateBox, m_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)); @@ -571,7 +582,8 @@ void SwDropCapsPage::Reset(const SfxItemSet *rSet) m_xTextEdit->set_text(GetDefaultString(nVal)); else { - m_xTextEdit->set_text(m_rSh.GetDropText(nVal)); + if (pView) + m_xTextEdit->set_text(pView->GetWrtShell().GetDropText(nVal)); m_xTextEdit->set_sensitive(true); m_xTextText->set_sensitive(true); } @@ -635,12 +647,15 @@ void SwDropCapsPage::ModifyEntry(const weld::Entry& rEdit) : 0; bool bSetText = false; - if (m_bFormat || m_rSh.GetDropText(1).isEmpty()) - sPreview = GetDefaultString(nVal); - else + if (SwView* pView = GetActiveView()) { - bSetText = true; - sPreview = m_rSh.GetDropText(nVal); + if (m_bFormat || pView->GetWrtShell().GetDropText(1).isEmpty()) + sPreview = GetDefaultString(nVal); + else + { + bSetText = true; + sPreview = pView->GetWrtShell().GetDropText(nVal); + } } OUString sEdit(m_xTextEdit->get_text()); @@ -710,8 +725,9 @@ void SwDropCapsPage::FillSet( SfxItemSet &rSet ) aFormat.GetWholeWord() = m_xWholeWordCB->get_active(); // template - if (m_xTemplateBox->get_active()) - aFormat.SetCharFormat(m_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 2a478a5c9111..8dddc8a41002 100644 --- a/sw/source/ui/chrdlg/swuiccoll.cxx +++ b/sw/source/ui/chrdlg/swuiccoll.cxx @@ -37,7 +37,6 @@ const WhichRangesContainer SwCondCollPage::s_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 93667179a21d..0476b1894138 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)); } @@ -357,7 +359,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(); @@ -390,7 +394,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); @@ -546,7 +552,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); @@ -742,7 +750,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) @@ -778,7 +788,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); @@ -892,7 +904,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 f83c9b75e69a..dfdd77f5db66 100644 --- a/sw/source/ui/fldui/fldpage.cxx +++ b/sw/source/ui/fldui/fldpage.cxx @@ -118,8 +118,10 @@ void SwFieldPage::InsertField(SwFieldTypesEnum nTypeId, sal_uInt16 nSubType, con sal_Unicode cSeparator, bool bIsAutomaticLanguage) { SwView* pView = GetActiveView(); - SwWrtShell *pSh = m_pWrtShell ? m_pWrtShell : pView->GetWrtShellPtr(); + if (!pView) + return; + SwWrtShell *pSh = m_pWrtShell ? m_pWrtShell : pView->GetWrtShellPtr(); if (!pSh) return; diff --git a/sw/source/ui/fldui/fldtdlg.cxx b/sw/source/ui/fldui/fldtdlg.cxx index 9f81d6841ef4..487bfa8cc0c2 100644 --- a/sw/source/ui/fldui/fldtdlg.cxx +++ b/sw/source/ui/fldui/fldtdlg.cxx @@ -221,7 +221,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; @@ -246,7 +246,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 8267cc4c10b5..4f64f86de238 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 == (m_nHtmlMode & HTMLMODE_ON )) - nFlags = SVX_RELATIVE_MODE; - if( SfxStyleFamily::Char == m_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 == (m_nHtmlMode & HTMLMODE_ON )) + nFlags = SVX_RELATIVE_MODE; + if( SfxStyleFamily::Char == m_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 1e5f11332e67..a3de6219f96d 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()) { if (SwWrtShell* pSh = pView->GetWrtShellPtr()) { @@ -150,8 +149,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..8ce59993f26c 100644 --- a/sw/source/ui/misc/titlepage.cxx +++ b/sw/source/ui/misc/titlepage.cxx @@ -146,7 +146,6 @@ sal_uInt16 SwTitlePageDlg::GetInsertPosition() const SwTitlePageDlg::SwTitlePageDlg(weld::Window *pParent) : SfxDialogController(pParent, "modules/swriter/ui/titlepage.ui", "DLG_TITLEPAGE") - , mrSh(*::GetActiveView()->GetWrtShellPtr()) , 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 +159,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 +211,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 +259,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 +290,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 bbc2ada8e165..546fd6902276 100644 --- a/sw/source/uibase/app/apphdl.cxx +++ b/sw/source/uibase/app/apphdl.cxx @@ -172,9 +172,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); @@ -206,9 +205,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 @@ -752,6 +750,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; @@ -813,14 +814,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); @@ -835,7 +840,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 a74b43821643..64bd38f44458 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 1603d11b2608..a6496a12c16b 100644 --- a/sw/source/uibase/dbui/mailmergetoolbarcontrols.cxx +++ b/sw/source/uibase/dbui/mailmergetoolbarcontrols.cxx @@ -253,9 +253,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) @@ -277,9 +276,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) @@ -322,9 +320,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) @@ -336,9 +333,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 0b30c494b044..715d769633f0 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 a556ffa23e9b..efc5f916f178 100644 --- a/sw/source/uibase/fldui/fldmgr.cxx +++ b/sw/source/uibase/fldui/fldmgr.cxx @@ -357,10 +357,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 2be2a93f1918..e5532f89454b 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 8d5a5fb6dd6e..afc7c6482253 100644 --- a/sw/source/uibase/inc/drpcps.hxx +++ b/sw/source/uibase/inc/drpcps.hxx @@ -74,7 +74,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); @@ -118,8 +118,6 @@ friend class SwDropCapsPict; bool m_bFormat; bool m_bHtmlMode; - SwWrtShell &m_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 aff7f533ab11..74e6920b0275 100644 --- a/sw/source/uibase/inc/swuiccoll.hxx +++ b/sw/source/uibase/inc/swuiccoll.hxx @@ -31,7 +31,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 304c4d4a3a50..3b587ec2d9a0 100644 --- a/sw/source/uibase/misc/redlndlg.cxx +++ b/sw/source/uibase/misc/redlndlg.cxx @@ -210,9 +210,8 @@ SwRedlineAcceptDlg::~SwRedlineAcceptDlg() void SwRedlineAcceptDlg::Init(SwRedlineTable::size_type nStart) { - SwView *pView = ::GetActiveView(); std::optional<SwWait> oWait; - if (pView) + if (SwView *pView = GetActiveView()) oWait.emplace(*pView->GetDocShell(), false); weld::TreeView& rTreeView = m_pTable->GetWidget(); m_aUsedSeqNo.clear(); @@ -245,7 +244,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(); @@ -491,7 +492,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(); if (!pSh) return SwRedlineTable::npos; @@ -662,7 +666,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(); if (!pSh) return; @@ -926,7 +934,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(); if (!pSh) return; @@ -1070,14 +1082,17 @@ void SwRedlineAcceptDlg::CallAcceptReject( bool bSelect, bool bAccept ) SwRedlineTable::size_type SwRedlineAcceptDlg::GetRedlinePos(const weld::TreeIter& rEntry) { - 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 + SwView* pView = GetActiveView(); + if (!pView) + return SwRedlineTable::npos; + + SwWrtShell* pSh = pView->GetWrtShellPtr(); + if (!pSh) return SwRedlineTable::npos; + + weld::TreeView& rTreeView = m_pTable->GetWidget(); + return pSh->FindRedlineOfData( *static_cast<SwRedlineDataParent*>(weld::fromId<RedlinData*>( + rTreeView.get_id(rEntry))->pData)->pData ); } IMPL_LINK_NOARG(SwRedlineAcceptDlg, AcceptHdl, SvxTPView*, void) @@ -1102,10 +1117,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(); } @@ -1131,7 +1148,11 @@ IMPL_LINK_NOARG(SwRedlineAcceptDlg, GotoHdl, Timer *, void) { m_aSelectTimer.Stop(); - SwWrtShell* pSh = ::GetActiveView()->GetWrtShellPtr(); + SwView* pView = GetActiveView(); + if (!pView) + return; + + SwWrtShell* pSh = pView->GetWrtShellPtr(); if (!pSh) return; @@ -1228,7 +1249,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(); if (!pSh) return false; @@ -1353,7 +1378,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 675390d4e9ac..9a5c12707991 100644 --- a/sw/source/uibase/ribbar/inputwin.cxx +++ b/sw/source/uibase/ribbar/inputwin.cxx @@ -334,9 +334,11 @@ void SwInputWindow::ApplyFormula() if (!m_pView || !m_pWrtShell) { // 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; } @@ -367,9 +369,11 @@ void SwInputWindow::CancelFormula() if (!m_pView || !m_pWrtShell) { // 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; } diff --git a/sw/source/uibase/ribbar/workctrl.cxx b/sw/source/uibase/ribbar/workctrl.cxx index fb38977c3ea4..840b94b73442 100644 --- a/sw/source/uibase/ribbar/workctrl.cxx +++ b/sw/source/uibase/ribbar/workctrl.cxx @@ -140,13 +140,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; } @@ -719,8 +722,7 @@ void SAL_CALL NavElementToolBoxControl::statusChanged( const frame::FeatureState else m_pBox->set_sensitive(true); - SwView* pView = GetActiveView(); - if (pView) + if (SwView* pView = GetActiveView()) { pView->GetViewFrame().GetBindings().Invalidate(FN_SCROLL_NEXT); pView->GetViewFrame().GetBindings().Invalidate(FN_SCROLL_PREV); diff --git a/sw/source/uibase/shells/tabsh.cxx b/sw/source/uibase/shells/tabsh.cxx index 3fc8dcd56bc1..4090a89bcaa5 100644 --- a/sw/source/uibase/shells/tabsh.cxx +++ b/sw/source/uibase/shells/tabsh.cxx @@ -689,8 +689,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 f93bfe4e40b5..8ecd18555c0e 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 f08b03dfe210..58df4037b236 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 57b9bffab834..5e7149c72a4b 100644 --- a/sw/source/uibase/utlui/content.cxx +++ b/sw/source/uibase/utlui/content.cxx @@ -1741,7 +1741,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 a0a00fe073e0..c09fd2dce2b6 100644 --- a/sw/source/uibase/utlui/navipi.cxx +++ b/sw/source/uibase/utlui/navipi.cxx @@ -1014,9 +1014,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();