Resolves: tdf#99324 let sidebar toggle auto-mnemonics on/off with alt

this returns things to passing the alt to the thing with the focus
and depends on ::Command handlers passing the alt-press/release back
up through the Command hierarchy to get to the default top-level
handler eventually

Change-Id: I869120f43810adfa2fac4670c2db143b790a1f9b
diff --git a/include/svx/sidebar/PanelLayout.hxx b/include/svx/sidebar/PanelLayout.hxx
index 22b229c..ddc2a0e 100644
--- a/include/svx/sidebar/PanelLayout.hxx
+++ b/include/svx/sidebar/PanelLayout.hxx
@@ -29,7 +29,7 @@ private:
    bool m_bInClose;
    bool hasPanelPendingLayout() const;

    DECL_DLLPRIVATE_LINK_TYPED( ImplHandlePanelLayoutTimerHdl, Idle*, void );
    DECL_DLLPRIVATE_LINK_TYPED(ImplHandlePanelLayoutTimerHdl, Idle*, void);

public:
    PanelLayout(vcl::Window* pParent, const OString& rID, const OUString& rUIXMLDescription,
@@ -40,7 +40,7 @@ public:
    virtual Size GetOptimalSize() const override;
    virtual void setPosSizePixel(long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags = PosSizeFlags::All) override;
    virtual void queue_resize(StateChangedType eReason = StateChangedType::Layout) override;

    virtual bool Notify(NotifyEvent& rNEvt) override;
};

#endif
diff --git a/sc/source/ui/app/inputwin.cxx b/sc/source/ui/app/inputwin.cxx
index 433b7ee..b37e376 100644
--- a/sc/source/ui/app/inputwin.cxx
+++ b/sc/source/ui/app/inputwin.cxx
@@ -1484,6 +1484,13 @@ void ScTextWnd::MouseButtonUp( const MouseEvent& rMEvt )

void ScTextWnd::Command( const CommandEvent& rCEvt )
{
    //pass alt press/release to parent impl
    if (rCEvt.GetCommand() == CommandEventId::ModKeyChange)
    {
        Window::Command(rCEvt);
        return;
    }

    bInputMode = true;
    CommandEventId nCommand = rCEvt.GetCommand();
    if ( pEditView /* && nCommand == CommandEventId::StartDrag */ )
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 1e7a3bd..b56aeb0 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -2842,6 +2842,12 @@ void ScGridWindow::Command( const CommandEvent& rCEvt )
    ScModule* pScMod = SC_MOD();
    OSL_ENSURE( nCmd != CommandEventId::StartDrag, "ScGridWindow::Command called with CommandEventId::StartDrag" );

    if (nCmd == CommandEventId::ModKeyChange)
    {
        Window::Command(rCEvt);
        return;
    }

    if ( nCmd == CommandEventId::StartExtTextInput ||
         nCmd == CommandEventId::EndExtTextInput ||
         nCmd == CommandEventId::ExtTextInput ||
diff --git a/sd/source/ui/view/sdwindow.cxx b/sd/source/ui/view/sdwindow.cxx
index dde0d8c..4c51a51 100644
--- a/sd/source/ui/view/sdwindow.cxx
+++ b/sd/source/ui/view/sdwindow.cxx
@@ -261,8 +261,11 @@ void Window::MouseButtonUp(const MouseEvent& rMEvt)

void Window::Command(const CommandEvent& rCEvt)
{
    if ( mpViewShell )
    if (mpViewShell)
        mpViewShell->Command(rCEvt, this);
    //pass at least alt press/release to parent impl
    if (rCEvt.GetCommand() == CommandEventId::ModKeyChange)
        vcl::Window::Command(rCEvt);
}

bool Window::Notify( NotifyEvent& rNEvt )
diff --git a/sfx2/source/dialog/backingwindow.cxx b/sfx2/source/dialog/backingwindow.cxx
index 6059ca1..2d0940a 100644
--- a/sfx2/source/dialog/backingwindow.cxx
+++ b/sfx2/source/dialog/backingwindow.cxx
@@ -163,18 +163,6 @@ BackingWindow::BackingWindow( vcl::Window* i_pParent ) :

    // init background
    SetBackground();

    GetParent()->AddEventListener(LINK(this, BackingWindow, WindowEventListener));
}

IMPL_LINK_TYPED(BackingWindow, WindowEventListener, VclWindowEvent&, rEvent, void)
{
    if (rEvent.GetId() != VCLEVENT_WINDOW_COMMAND)
        return;
    CommandEvent* pCmdEvt = static_cast<CommandEvent*>(rEvent.GetData());
    if (pCmdEvt->GetCommand() != CommandEventId::ModKeyChange)
        return;
    Accelerator::ToggleMnemonicsOnHierarchy(*pCmdEvt, this);
}

BackingWindow::~BackingWindow()
@@ -184,7 +172,6 @@ BackingWindow::~BackingWindow()

void BackingWindow::dispose()
{
    GetParent()->RemoveEventListener(LINK(this, BackingWindow, WindowEventListener));
    // deregister drag&drop helper
    if (mxDropTargetListener.is())
    {
diff --git a/sfx2/source/dialog/backingwindow.hxx b/sfx2/source/dialog/backingwindow.hxx
index 2a12b84..abb68e9 100644
--- a/sfx2/source/dialog/backingwindow.hxx
+++ b/sfx2/source/dialog/backingwindow.hxx
@@ -106,7 +106,6 @@ class BackingWindow : public vcl::Window, public VclBuilderContainer
    DECL_LINK_TYPED(CreateContextMenuHdl, ThumbnailViewItem*, void);
    DECL_LINK_TYPED(OpenTemplateHdl, ThumbnailViewItem*, void);
    DECL_LINK_TYPED(EditTemplateHdl, ThumbnailViewItem*, void);
    DECL_LINK_TYPED(WindowEventListener, VclWindowEvent&, void);

    void initControls();

diff --git a/starmath/source/edit.cxx b/starmath/source/edit.cxx
index 7809669..3cf5b16 100644
--- a/starmath/source/edit.cxx
+++ b/starmath/source/edit.cxx
@@ -335,6 +335,13 @@ void SmEditWindow::MouseButtonDown(const MouseEvent &rEvt)

void SmEditWindow::Command(const CommandEvent& rCEvt)
{
    //pass alt press/release to parent impl
    if (rCEvt.GetCommand() == CommandEventId::ModKeyChange)
    {
        Window::Command(rCEvt);
        return;
    }

    bool bForwardEvt = true;
    if (rCEvt.GetCommand() == CommandEventId::ContextMenu)
    {
diff --git a/svx/source/sidebar/PanelLayout.cxx b/svx/source/sidebar/PanelLayout.cxx
index f4ec456..9e04f33 100644
--- a/svx/source/sidebar/PanelLayout.cxx
+++ b/svx/source/sidebar/PanelLayout.cxx
@@ -110,4 +110,11 @@ void PanelLayout::setPosSizePixel(long nX, long nY, long nWidth, long nHeight, P
        VclContainer::setLayoutAllocation(*pChild, Point(0, 0), Size(nWidth, nHeight));
}

bool PanelLayout::Notify(NotifyEvent& rNEvt)
{
    if (rNEvt.GetType() == MouseNotifyEvent::COMMAND)
        Accelerator::ToggleMnemonicsOnHierarchy(*rNEvt.GetCommandEvent(), this);
    return Control::Notify( rNEvt );
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/window/syswin.cxx b/vcl/source/window/syswin.cxx
index d482cbd..1a75e4d 100644
--- a/vcl/source/window/syswin.cxx
+++ b/vcl/source/window/syswin.cxx
@@ -164,6 +164,9 @@ bool Accelerator::ToggleMnemonicsOnHierarchy(const CommandEvent& rCEvent, vcl::W

bool SystemWindow::Notify( NotifyEvent& rNEvt )
{
    if (rNEvt.GetType() == MouseNotifyEvent::COMMAND)
        Accelerator::ToggleMnemonicsOnHierarchy(*rNEvt.GetCommandEvent(), this);

    // capture KeyEvents for menu handling
    if (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT ||
        rNEvt.GetType() == MouseNotifyEvent::COMMAND)
@@ -185,11 +188,6 @@ bool SystemWindow::Notify( NotifyEvent& rNEvt )
        }
        if (bDone)
            return true;
        if (rNEvt.GetType() == MouseNotifyEvent::COMMAND)
        {
            if (Accelerator::ToggleMnemonicsOnHierarchy(*rNEvt.GetCommandEvent(), this))
                return true;
        }
    }

    return Window::Notify( rNEvt );
diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx
index 720ee3a..04dd360 100644
--- a/vcl/source/window/winproc.cxx
+++ b/vcl/source/window/winproc.cxx
@@ -2086,33 +2086,10 @@ static void ImplHandleSalKeyMod( vcl::Window* pWindow, SalKeyModEvent* pEvent )
    // #105224# send commandevent to allow special treatment of Ctrl-LeftShift/Ctrl-RightShift etc.
    // + auto-accelerator feature, tdf#92630

    vcl::Window *pChild = nullptr;

    // Alt pressed or released => give SystemWindow a chance to handle auto-accelerator
    if ( pEvent->mnCode == KEY_MOD2 || (pEvent->mnModKeyCode & MODKEY_MOD2) != 0 )
    {
        // find window - first look to see a popup is open and send it there
        pChild = pSVData->maWinData.mpFirstFloat.get();

        if (!pChild)
        {
            // find window - then look to see if the system window is available
            pChild = pWindow->ImplGetWindowImpl()->mpFirstChild;
            while ( pChild )
            {
                if ( pChild->ImplGetWindowImpl()->mbSysWin )
                    break;
                pChild = pChild->ImplGetWindowImpl()->mpNext;
            }
        }
    }

    //...if not, try to find a key input window...
    if (!pChild)
        pChild = ImplGetKeyInputWindow( pWindow );
    //...otherwise fail safe...
    if (!pChild)
        pChild = pWindow;
    // find window
    vcl::Window* pChild = ImplGetKeyInputWindow( pWindow );
    if ( !pChild )
        return;

    CommandModKeyData data( pEvent->mnModKeyCode );
    ImplCallCommand( pChild, CommandEventId::ModKeyChange, &data );