From e7c016e42b6c33774b28c3b10d0cc424137db9f7 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Thu, 28 Jul 2022 15:49:32 +0100 Subject: 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 Tested-by: Jenkins --- sfx2/source/dialog/recfloat.cxx | 15 ++++++++++++--- sfx2/source/inc/recfloat.hxx | 4 ++++ 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'sfx2') 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 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 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 m_xToolbar; std::unique_ptr m_xDispatcher; + ImplSVEvent *mnPostUserEventId; bool m_bFirstActivate; + + DECL_LINK(PresentParentFrame, void*, void); + public: SfxRecordingFloat_Impl(SfxBindings* pBindings, SfxChildWindow* pChildWin, -- cgit