sfx2/source/dialog/recfloat.cxx |   15 ++++++++++++---
 sfx2/source/inc/recfloat.hxx    |    4 ++++
 2 files changed, 16 insertions(+), 3 deletions(-)

New commits:
commit 4285d6f64a01b26b446f387db0a309340c3a49e4
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Thu Jul 28 15:49:32 2022 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Thu Aug 4 15:40:28 2022 +0200

    Resolves: tdf#147782 restore focus to launching frame asynchronously
    
    Change-Id: I7ebde70e4e1aae861f6ac7d70a91741596cb2cc5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137526
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    Tested-by: Jenkins

diff --git a/sfx2/source/dialog/recfloat.cxx b/sfx2/source/dialog/recfloat.cxx
index 6a6fc17dbd9a..1dcbb2f7c416 100644
--- a/sfx2/source/dialog/recfloat.cxx
+++ b/sfx2/source/dialog/recfloat.cxx
@@ -102,6 +102,7 @@ SfxRecordingFloat_Impl::SfxRecordingFloat_Impl(SfxBindings* 
pBind, SfxChildWindo
                                   "FloatingRecord")
     , m_xToolbar(m_xBuilder->weld_toolbar("toolbar"))
     , m_xDispatcher(new ToolbarUnoDispatcher(*m_xToolbar, *m_xBuilder, 
pBind->GetActiveFrame()))
+    , mnPostUserEventId(nullptr)
     , m_bFirstActivate(true)
 {
     // start recording
@@ -110,6 +111,14 @@ 
SfxRecordingFloat_Impl::SfxRecordingFloat_Impl(SfxBindings* pBind, SfxChildWindo
             SfxCallMode::SYNCHRON, { &aItem });
 }
 
+IMPL_LINK_NOARG(SfxRecordingFloat_Impl, PresentParentFrame, void*, void)
+{
+    mnPostUserEventId = nullptr;
+    css::uno::Reference<css::awt::XTopWindow> 
xTopWindow(m_xDispatcher->GetFrame()->getContainerWindow(), 
css::uno::UNO_QUERY);
+    if (xTopWindow.is())
+        xTopWindow->toFront();
+}
+
 void SfxRecordingFloat_Impl::Activate()
 {
     SfxModelessDialogController::Activate();
@@ -117,13 +126,13 @@ void SfxRecordingFloat_Impl::Activate()
         return;
     // tdf#147782 retain focus in launching frame on the first activate on 
automatically gaining focus on getting launched
     m_bFirstActivate = false;
-    css::uno::Reference<css::awt::XTopWindow> 
xTopWindow(m_xDispatcher->GetFrame()->getContainerWindow(), 
css::uno::UNO_QUERY);
-    if (xTopWindow.is())
-        xTopWindow->toFront();
+    mnPostUserEventId = Application::PostUserEvent(LINK(this, 
SfxRecordingFloat_Impl, PresentParentFrame));
 }
 
 SfxRecordingFloat_Impl::~SfxRecordingFloat_Impl()
 {
+    if (mnPostUserEventId)
+        Application::RemoveUserEvent(mnPostUserEventId);
     m_xDispatcher->dispose();
 }
 
diff --git a/sfx2/source/inc/recfloat.hxx b/sfx2/source/inc/recfloat.hxx
index b7a4882cd72e..e5720e155cd6 100644
--- a/sfx2/source/inc/recfloat.hxx
+++ b/sfx2/source/inc/recfloat.hxx
@@ -42,7 +42,11 @@ class SfxRecordingFloat_Impl final : public 
SfxModelessDialogController
 {
     std::unique_ptr<weld::Toolbar> m_xToolbar;
     std::unique_ptr<ToolbarUnoDispatcher> m_xDispatcher;
+    ImplSVEvent *mnPostUserEventId;
     bool m_bFirstActivate;
+
+    DECL_LINK(PresentParentFrame, void*, void);
+
 public:
     SfxRecordingFloat_Impl(SfxBindings* pBindings,
                            SfxChildWindow* pChildWin,

Reply via email to