diff options
Diffstat (limited to 'cui/source/dialogs/tipofthedaydlg.cxx')
-rw-r--r-- | cui/source/dialogs/tipofthedaydlg.cxx | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/cui/source/dialogs/tipofthedaydlg.cxx b/cui/source/dialogs/tipofthedaydlg.cxx index 9d43fd21f4ba..8356f6f0e36f 100644 --- a/cui/source/dialogs/tipofthedaydlg.cxx +++ b/cui/source/dialogs/tipofthedaydlg.cxx @@ -25,6 +25,7 @@ #include <vcl/commandinfoprovider.hxx> #include <vcl/graphicfilter.hxx> #include <vcl/help.hxx> +#include <vcl/window.hxx> #include <com/sun/star/frame/XDesktop2.hpp> #include <com/sun/star/frame/XDispatch.hpp> @@ -38,6 +39,7 @@ #include <officecfg/Office/Common.hxx> #include <osl/file.hxx> #include <rtl/bootstrap.hxx> +#include <toolkit/helper/vclunohelper.hxx> #include <unotools/resmgr.hxx> #include <unotools/configmgr.hxx> #include <com/sun/star/beans/PropertyValue.hpp> @@ -47,6 +49,7 @@ const Size ThumbSize(150, 150); TipOfTheDayDialog::TipOfTheDayDialog(weld::Window* pParent) : GenericDialogController(pParent, "cui/ui/tipofthedaydialog.ui", "TipOfTheDayDialog") + , m_pParent(pParent) , m_pText(m_xBuilder->weld_label("lbText")) , m_pShowTip(m_xBuilder->weld_check_button("cbShowTip")) , m_pNext(m_xBuilder->weld_button("btnNext")) @@ -58,6 +61,17 @@ 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) + { + 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)); + } + } + const auto t0 = std::chrono::system_clock::now().time_since_epoch(); m_nDay = std::chrono::duration_cast<std::chrono::hours>(t0).count() / 24; if (m_nDay > officecfg::Office::Common::Misc::LastTipOfTheDayShown::get()) @@ -66,6 +80,12 @@ TipOfTheDayDialog::TipOfTheDayDialog(weld::Window* pParent) UpdateTip(); } +IMPL_LINK(TipOfTheDayDialog, Terminated, VclWindowEvent&, rEvent, void) +{ + if (rEvent.GetId() == VclEventId::ObjectDying) + TipOfTheDayDialog::response(RET_OK); +} + TipOfTheDayDialog::~TipOfTheDayDialog() { std::shared_ptr<comphelper::ConfigurationChanges> xChanges( @@ -74,6 +94,17 @@ TipOfTheDayDialog::~TipOfTheDayDialog() officecfg::Office::Common::Misc::LastTipOfTheDayID::set(m_nCurrentTip, xChanges); officecfg::Office::Common::Misc::ShowTipOfTheDay::set(m_pShowTip->get_active(), xChanges); xChanges->commit(); + + if (m_pParent != nullptr) + { + 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)); + } + } } static bool file_exists(const OUString& fileName) |