tdf#123793 Add kb tab navigation to special chars popup window

...and keep the 'More Characters...' button as first focused

Change-Id: Iab4cb00aaed9250f0cc7f35f27af48eb326f2a48
Reviewed-on: https://gerrit.libreoffice.org/71834
Tested-by: Jenkins
Reviewed-by: Jim Raykowski <raykowj@gmail.com>
(cherry picked from commit caa6de6c97b0c2fc82c6a2699a1e84b9d2eb9dbd)
Reviewed-on: https://gerrit.libreoffice.org/72772
Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
diff --git a/include/sfx2/charmapcontrol.hxx b/include/sfx2/charmapcontrol.hxx
index 970e3fa..5b0dbcc 100644
--- a/include/sfx2/charmapcontrol.hxx
+++ b/include/sfx2/charmapcontrol.hxx
@@ -40,6 +40,8 @@ public:

    virtual void dispose() override;

    virtual bool EventNotify( NotifyEvent& rNEvt ) override;

private:
    VclPtr<SvxCharViewControl> m_pRecentCharView[16];
    VclPtr<SvxCharViewControl> m_pFavCharView[16];
@@ -50,7 +52,7 @@ private:
    VclPtr<Button>         maDlgBtn;

    DECL_LINK(CharClickHdl, SvxCharViewControl*, void);
    DECL_STATIC_LINK(SfxCharmapCtrl, LoseFocusHdl, Control&, void);
    DECL_STATIC_LINK(SfxCharmapCtrl, FocusHdl, Control&, void);
    DECL_LINK(OpenDlgHdl, Button*, void);

    void            getFavCharacterList();
diff --git a/sfx2/source/control/charmapcontrol.cxx b/sfx2/source/control/charmapcontrol.cxx
index 8bb684b..7f757a7e 100644
--- a/sfx2/source/control/charmapcontrol.cxx
+++ b/sfx2/source/control/charmapcontrol.cxx
@@ -20,6 +20,7 @@
#include <comphelper/dispatchcommand.hxx>
#include <officecfg/Office/Common.hxx>
#include <sfx2/charmapcontrol.hxx>
#include <vcl/event.hxx>

using namespace css;

@@ -64,10 +65,14 @@ SfxCharmapCtrl::SfxCharmapCtrl(sal_uInt16 nId, vcl::Window* pParent, const css::

    for(int i = 0; i < 16; i++)
    {
        m_pRecentCharView[i]->SetStyle(m_pRecentCharView[i]->GetStyle() | WB_GROUP);
        m_pRecentCharView[i]->setMouseClickHdl(LINK(this,SfxCharmapCtrl, CharClickHdl));
        m_pRecentCharView[i]->SetLoseFocusHdl(LINK(this,SfxCharmapCtrl, LoseFocusHdl));
        m_pRecentCharView[i]->SetGetFocusHdl(LINK(this,SfxCharmapCtrl, FocusHdl));
        m_pRecentCharView[i]->SetLoseFocusHdl(LINK(this,SfxCharmapCtrl, FocusHdl));
        m_pFavCharView[i]->SetStyle(m_pFavCharView[i]->GetStyle() | WB_GROUP);
        m_pFavCharView[i]->setMouseClickHdl(LINK(this,SfxCharmapCtrl, CharClickHdl));
        m_pFavCharView[i]->SetLoseFocusHdl(LINK(this,SfxCharmapCtrl, LoseFocusHdl));
        m_pFavCharView[i]->SetGetFocusHdl(LINK(this,SfxCharmapCtrl, FocusHdl));
        m_pFavCharView[i]->SetLoseFocusHdl(LINK(this,SfxCharmapCtrl, FocusHdl));
    }

    maDlgBtn->SetClickHdl(LINK(this, SfxCharmapCtrl, OpenDlgHdl));
@@ -177,7 +182,32 @@ void SfxCharmapCtrl::updateRecentCharControl()
}


IMPL_STATIC_LINK(SfxCharmapCtrl, LoseFocusHdl, Control&, pItem, void)
bool SfxCharmapCtrl::EventNotify( NotifyEvent& rNEvt )
{
    static bool bNeedsInit = true;
    if ( maDlgBtn->HasFocus() && rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
    {
        const vcl::KeyCode& rKey = rNEvt.GetKeyEvent()->GetKeyCode();
        const sal_uInt16 nCode = rKey.GetCode();
        if ( nCode != KEY_TAB && nCode != KEY_RETURN && nCode != KEY_SPACE && nCode != KEY_ESCAPE )
        {
            return true;
        }
        if ( bNeedsInit && nCode == KEY_TAB )
        {
            for(int i = 0; i < 16; i++)
            {
                m_pRecentCharView[i]->set_property( "can-focus", "true" );
                m_pFavCharView[i]->set_property( "can-focus", "true" );
            }
            bNeedsInit = false;
        }
    }
    return SfxPopupWindow::EventNotify( rNEvt );
}


IMPL_STATIC_LINK(SfxCharmapCtrl, FocusHdl, Control&, pItem, void)
{
    pItem.Invalidate();
}
@@ -185,10 +215,8 @@ IMPL_STATIC_LINK(SfxCharmapCtrl, LoseFocusHdl, Control&, pItem, void)

IMPL_LINK(SfxCharmapCtrl, CharClickHdl, SvxCharViewControl*, rView, void)
{
    rView->GrabFocus();
    rView->Invalidate();
    rView->InsertCharToDoc();

    GrabFocusToDocument();
    Close();
}