cui/source/dialogs/tipofthedaydlg.cxx |   31 +++++++++++++++++++++++++++++++
 cui/source/factory/dlgfact.cxx        |   14 ++++++++++++--
 cui/source/factory/dlgfact.hxx        |   13 +++++++++++++
 cui/source/inc/tipofthedaydlg.hxx     |    5 +++++
 cui/uiconfig/ui/tipofthedaydialog.ui  |    4 ++--
 sfx2/source/appl/appserv.cxx          |    2 +-
 6 files changed, 64 insertions(+), 5 deletions(-)

New commits:
commit 9be322687ab09f61439da0c6d4934dbae08cbcc4
Author:     Matt K <matt...@gmail.com>
AuthorDate: Sat Apr 3 01:24:30 2021 -0500
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Thu Jun 17 09:28:01 2021 +0200

    tdf#127533 Make Tip-of-the-Day dialog non-modal and allow multiple tips to 
open
    
    The Tip-of-the-Day dialog is made non-modal and stays on-top of the main 
window
    while allowing the user to interact with the rest of application.
    
    Change-Id: I51e1a3488ab74d8371b71a8585d1512ce051f637
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113782
    Reviewed-by: Matt K <matt...@gmail.com>
    Reviewed-by: Heiko Tietze <heiko.tie...@documentfoundation.org>
    Tested-by: Jenkins
    Signed-off-by: Michael Meeks <michael.me...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117341
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Andras Timar <andras.ti...@collabora.com>

diff --git a/cui/source/dialogs/tipofthedaydlg.cxx 
b/cui/source/dialogs/tipofthedaydlg.cxx
index 2404052271e6..42f0a331fbfa 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,12 +39,14 @@
 #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>
 
 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"))
@@ -55,6 +58,17 @@ TipOfTheDayDialog::TipOfTheDayDialog(weld::Window* pParent)
 
     m_nCurrentTip = officecfg::Office::Common::Misc::LastTipOfTheDayID::get();
 
+    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())
@@ -63,6 +77,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(
@@ -71,6 +91,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 e731ae7fe3d9..7ee30c9b621a 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();
@@ -1686,8 +1696,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 7d97167193b8..b39e29efe821 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: */
diff --git a/cui/uiconfig/ui/tipofthedaydialog.ui 
b/cui/uiconfig/ui/tipofthedaydialog.ui
index 13e0452187c3..d389c554f300 100644
--- a/cui/uiconfig/ui/tipofthedaydialog.ui
+++ b/cui/uiconfig/ui/tipofthedaydialog.ui
@@ -7,7 +7,7 @@
     <property name="border-width">6</property>
     <property name="title" translatable="yes" 
context="TipOfTheDayDialog|Name">Tip of the day</property>
     <property name="resizable">False</property>
-    <property name="modal">True</property>
+    <property name="modal">False</property>
     <property name="window-position">center-on-parent</property>
     <property name="type-hint">dialog</property>
     <child internal-child="vbox">
@@ -26,7 +26,7 @@
                 <property name="visible">True</property>
                 <property name="can-focus">True</property>
                 <property name="receives-default">False</property>
-                <property name="tooltip-text" translatable="yes" 
context="TipOfTheDay|Checkbox_Tooltip">Enable the dialog again at Tools &gt; 
Options &gt; General</property>
+                <property name="tooltip-text" translatable="yes" 
context="TipOfTheDay|Checkbox_Tooltip">Enable the dialog again at Tools &gt; 
Options &gt; General, or Help &gt; Show Tip of the Day</property>
                 <property name="use-underline">True</property>
                 <property name="active">True</property>
                 <property name="draw-indicator">True</property>
diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx
index 78e23aeb372a..42cd0825e747 100644
--- a/sfx2/source/appl/appserv.cxx
+++ b/sfx2/source/appl/appserv.cxx
@@ -666,7 +666,7 @@ void SfxApplication::MiscExec_Impl( SfxRequest& rReq )
         {
             SfxAbstractDialogFactory* pFact = 
SfxAbstractDialogFactory::Create();
             ScopedVclPtr<VclAbstractDialog> 
pDlg(pFact->CreateTipOfTheDayDialog(rReq.GetFrameWeld()));
-            pDlg->Execute();
+            pDlg->StartExecuteAsync(nullptr);
             bDone = true;
             break;
         }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to