cui/source/dialogs/tipofthedaydlg.cxx | 28 ++++++++++------------------ cui/source/inc/tipofthedaydlg.hxx | 2 +- 2 files changed, 11 insertions(+), 19 deletions(-)
New commits: commit 6c24cdd5098c5021da53ee96b07bd90bada0f049 Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Tue Jan 30 11:40:01 2024 +0000 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Wed Jan 31 10:59:13 2024 +0100 tdf#151352 keep a reference to the parent and use that in the dtor instead of a pointer. FWIW the XWindow isn't actually a vcl::Window in the Gtk case, so VCLUnoHelper::GetWindow doesn't do anything there. But using an XWindow gives a safe view wrt life cycle. Change-Id: I4d0fd707ea931a76d6f87f434f7ece8df066785c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162720 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/cui/source/dialogs/tipofthedaydlg.cxx b/cui/source/dialogs/tipofthedaydlg.cxx index f1cb7afc2c1f..bbb26a054be9 100644 --- a/cui/source/dialogs/tipofthedaydlg.cxx +++ b/cui/source/dialogs/tipofthedaydlg.cxx @@ -50,7 +50,7 @@ const Size ThumbSize(150, 150); TipOfTheDayDialog::TipOfTheDayDialog(weld::Window* pParent) : GenericDialogController(pParent, "cui/ui/tipofthedaydialog.ui", "TipOfTheDayDialog") - , m_pParent(pParent) + , m_xParent(pParent ? pParent->GetXWindow() : nullptr) , m_pText(m_xBuilder->weld_label("lbText")) , m_pShowTip(m_xBuilder->weld_check_button("cbShowTip")) , m_pNext(m_xBuilder->weld_button("btnNext")) @@ -62,15 +62,11 @@ TipOfTheDayDialog::TipOfTheDayDialog(weld::Window* pParent) m_nCurrentTip = officecfg::Office::Common::Misc::LastTipOfTheDayID::get(); m_pPreview->set_size_request(ThumbSize.Width(), ThumbSize.Height()); - if (pParent != nullptr) + if (m_xParent.is()) { - css::uno::Reference<css::awt::XWindow> xWindow = pParent->GetXWindow(); - if (xWindow.is()) - { - VclPtr<vcl::Window> xVclWin(VCLUnoHelper::GetWindow(xWindow)); - if (xVclWin != nullptr) - xVclWin->AddEventListener(LINK(this, TipOfTheDayDialog, Terminated)); - } + VclPtr<vcl::Window> xVclWin(VCLUnoHelper::GetWindow(m_xParent)); + if (xVclWin != nullptr) + xVclWin->AddEventListener(LINK(this, TipOfTheDayDialog, Terminated)); } const auto t0 = std::chrono::system_clock::now().time_since_epoch(); @@ -94,7 +90,7 @@ IMPL_LINK(TipOfTheDayDialog, Terminated, VclWindowEvent&, rEvent, void) { if (rEvent.GetId() == VclEventId::ObjectDying) { - m_pParent = nullptr; + m_xParent.clear(); TipOfTheDayDialog::response(RET_OK); } } @@ -107,15 +103,11 @@ TipOfTheDayDialog::~TipOfTheDayDialog() officecfg::Office::Common::Misc::ShowTipOfTheDay::set(m_pShowTip->get_active(), xChanges); xChanges->commit(); - if (m_pParent != nullptr) + if (m_xParent.is()) { - css::uno::Reference<css::awt::XWindow> xWindow = m_pParent->GetXWindow(); - if (xWindow.is()) - { - VclPtr<vcl::Window> xVclWin(VCLUnoHelper::GetWindow(xWindow)); - if (xVclWin != nullptr) - xVclWin->RemoveEventListener(LINK(this, TipOfTheDayDialog, Terminated)); - } + VclPtr<vcl::Window> xVclWin(VCLUnoHelper::GetWindow(m_xParent)); + if (xVclWin != nullptr) + xVclWin->RemoveEventListener(LINK(this, TipOfTheDayDialog, Terminated)); } } diff --git a/cui/source/inc/tipofthedaydlg.hxx b/cui/source/inc/tipofthedaydlg.hxx index 69af1996e454..1f86d1bf238c 100644 --- a/cui/source/inc/tipofthedaydlg.hxx +++ b/cui/source/inc/tipofthedaydlg.hxx @@ -27,7 +27,7 @@ class TipOfTheDayDialog : public weld::GenericDialogController { private: CuiGraphicPreviewWindow m_aPreview; - weld::Window* m_pParent; + css::uno::Reference<css::awt::XWindow> m_xParent; std::unique_ptr<weld::Label> m_pText; std::unique_ptr<weld::CheckButton> m_pShowTip;