diff options
Diffstat (limited to 'cui/source')
-rw-r--r-- | cui/source/dialogs/tipofthedaydlg.cxx | 31 | ||||
-rw-r--r-- | cui/source/factory/dlgfact.cxx | 14 | ||||
-rw-r--r-- | cui/source/factory/dlgfact.hxx | 13 | ||||
-rw-r--r-- | cui/source/inc/tipofthedaydlg.hxx | 5 |
4 files changed, 61 insertions, 2 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) diff --git a/cui/source/factory/dlgfact.cxx b/cui/source/factory/dlgfact.cxx index 6d0a44086d47..6d0e9e31f77f 100644 --- a/cui/source/factory/dlgfact.cxx +++ b/cui/source/factory/dlgfact.cxx @@ -106,6 +106,16 @@ short CuiAbstractController_Impl::Execute() return m_xDlg->run(); } +short CuiAbstractTipController_Impl::Execute() +{ + return m_xDlg->run(); +} + +bool CuiAbstractTipController_Impl::StartExecuteAsync(AsyncContext& rCtx) +{ + return weld::DialogController::runAsync(m_xDlg, rCtx.maEndDialogFn); +} + short CuiAbstractSingleTabController_Impl::Execute() { return m_xDlg->run(); @@ -1682,8 +1692,8 @@ AbstractDialogFactory_Impl::CreateAboutDialog(weld::Window* pParent) VclPtr<VclAbstractDialog> AbstractDialogFactory_Impl::CreateTipOfTheDayDialog(weld::Window* pParent) { - return VclPtr<CuiAbstractController_Impl>::Create( - std::make_unique<TipOfTheDayDialog>(pParent)); + return VclPtr<CuiAbstractTipController_Impl>::Create( + std::make_shared<TipOfTheDayDialog>(pParent)); } VclPtr<VclAbstractDialog> diff --git a/cui/source/factory/dlgfact.hxx b/cui/source/factory/dlgfact.hxx index 1abf42683c95..1678d3c6349b 100644 --- a/cui/source/factory/dlgfact.hxx +++ b/cui/source/factory/dlgfact.hxx @@ -121,6 +121,19 @@ public: virtual short Execute() override; }; +class CuiAbstractTipController_Impl : public VclAbstractDialog +{ + std::shared_ptr<weld::DialogController> m_xDlg; + +public: + explicit CuiAbstractTipController_Impl(std::shared_ptr<weld::DialogController> p) + : m_xDlg(std::move(p)) + { + } + virtual short Execute() override; + virtual bool StartExecuteAsync(AsyncContext& rCtx) override; +}; + class CuiAbstractSingleTabController_Impl : public SfxAbstractDialog { std::unique_ptr<SfxSingleTabDialogController> m_xDlg; diff --git a/cui/source/inc/tipofthedaydlg.hxx b/cui/source/inc/tipofthedaydlg.hxx index 44ea0134fe01..f5f0ef999420 100644 --- a/cui/source/inc/tipofthedaydlg.hxx +++ b/cui/source/inc/tipofthedaydlg.hxx @@ -21,10 +21,13 @@ #include <vcl/weld.hxx> #include "cuigrfflt.hxx" +class VclWindowEvent; + class TipOfTheDayDialog : public weld::GenericDialogController { private: CuiGraphicPreviewWindow m_aPreview; + weld::Window* m_pParent; std::unique_ptr<weld::Label> m_pText; std::unique_ptr<weld::CheckButton> m_pShowTip; @@ -41,6 +44,8 @@ private: public: TipOfTheDayDialog(weld::Window* pWindow); virtual ~TipOfTheDayDialog() override; + + DECL_LINK(Terminated, VclWindowEvent&, void); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |