tdf#137993 ensure the toplevel vcl::Window is activated

when the search entry gains focus so that SfxViewFrame::Current is valid

Change-Id: Ibb21db12688a7d44758cf607da618035c22a062a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105484
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/svx/source/inc/findtextfield.hxx b/svx/source/inc/findtextfield.hxx
index 1ac5519..3e5de48 100644
--- a/svx/source/inc/findtextfield.hxx
+++ b/svx/source/inc/findtextfield.hxx
@@ -63,6 +63,7 @@ private:
    DECL_LINK(ActivateHdl, weld::ComboBox&, bool);
    DECL_LINK(OnAsyncGetFocus, void*, void);

    void FocusIn();
    void ActivateFind(bool bShift);
};

diff --git a/svx/source/tbxctrls/tbunosearchcontrollers.cxx b/svx/source/tbxctrls/tbunosearchcontrollers.cxx
index 812d0be..9d38913 100644
--- a/svx/source/tbxctrls/tbunosearchcontrollers.cxx
+++ b/svx/source/tbxctrls/tbunosearchcontrollers.cxx
@@ -200,6 +200,8 @@ FindTextFieldControl::FindTextFieldControl( vcl::Window* pParent,
    m_xContext(xContext),
    m_pAcc(svt::AcceleratorExecute::createAcceleratorHelper())
{
    InitControlBase(m_xWidget.get());

    m_xWidget->set_entry_placeholder_text(SvxResId(RID_SVXSTR_FINDBAR_FIND));
    m_xWidget->set_entry_completion(true, true);
    m_pAcc->init(m_xContext, m_xFrame);
@@ -340,12 +342,20 @@ IMPL_LINK_NOARG(FindTextFieldControl, OnAsyncGetFocus, void*, void)
    m_xWidget->select_entry_region(0, -1);
}

IMPL_LINK_NOARG(FindTextFieldControl, FocusInHdl, weld::Widget&, void)
void FindTextFieldControl::FocusIn()
{
    if (m_nAsyncGetFocusId)
    if (m_nAsyncGetFocusId || !m_xWidget)
        return;

    // do it async to defeat entry in combobox having its own ideas about the focus
    m_nAsyncGetFocusId = Application::PostUserEvent(LINK(this, FindTextFieldControl, OnAsyncGetFocus));

    GrabFocus(); // tdf#137993 ensure the toplevel vcl::Window is activated so SfxViewFrame::Current is valid
}

IMPL_LINK_NOARG(FindTextFieldControl, FocusInHdl, weld::Widget&, void)
{
    FocusIn();
}

void FindTextFieldControl::dispose()
@@ -397,12 +407,8 @@ void FindTextFieldControl::set_entry_message_type(weld::EntryMessageType eType)

void FindTextFieldControl::GetFocus()
{
    if (m_xWidget)
    {
        m_xWidget->grab_focus();
        FocusInHdl(*m_xWidget);
    }
    InterimItemWindow::GetFocus();
    FocusIn();
}

namespace {