diff options
author | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-01-30 11:40:01 +0000 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-01-30 20:51:15 +0100 |
commit | b01a9f8c9da419969575d0dc20e7346306ae96d3 (patch) | |
tree | 42422e793e0ce2995c21c86dbedefaf4f7f61f85 /cui | |
parent | 84572ef8c27fc4d4a7720303972f877ed2db8f79 (diff) |
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/+/162744
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Diffstat (limited to 'cui')
-rw-r--r-- | cui/source/dialogs/tipofthedaydlg.cxx | 28 | ||||
-rw-r--r-- | cui/source/inc/tipofthedaydlg.hxx | 2 |
2 files changed, 11 insertions, 19 deletions
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; |