Related: tdf#128104 extend popup handler to cover all CommandEvents

Reviewed-on: https://gerrit.libreoffice.org/80021
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
(cherry picked from commit 947150821e985c255f6c802322e696eff4257a5d)

Change-Id: I26360ce5c696d0e571385d83a15876eb2286e12f
Reviewed-on: https://gerrit.libreoffice.org/82741
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/desktop/source/deployment/gui/dp_gui_dialog2.cxx b/desktop/source/deployment/gui/dp_gui_dialog2.cxx
index a3c1f55..c3dbe95 100644
--- a/desktop/source/deployment/gui/dp_gui_dialog2.cxx
+++ b/desktop/source/deployment/gui/dp_gui_dialog2.cxx
@@ -117,7 +117,7 @@ public:
    void InitFromDialog(ExtMgrDialog *pParentDialog);

    virtual bool    MouseButtonDown( const MouseEvent& rMEvt ) override;
    virtual bool    ContextMenu( const CommandEvent& rCEvt ) override;
    virtual bool    Command( const CommandEvent& rCEvt ) override;

    virtual void    RecalcAll() override;
    virtual void    selectEntry( const long nPos ) override;
@@ -214,10 +214,10 @@ void ExtBoxWithBtns_Impl::SetButtonStatus(const TEntry_Impl& rEntry)
    }
}

bool ExtBoxWithBtns_Impl::ContextMenu(const CommandEvent& rCEvt)
bool ExtBoxWithBtns_Impl::Command(const CommandEvent& rCEvt)
{
    if (rCEvt.GetCommand() != CommandEventId::ContextMenu)
        return false;
        return ExtensionBox_Impl::Command(rCEvt);

    const Point aMousePos(rCEvt.GetMousePosPixel());
    const auto nPos = PointToPos(aMousePos);
diff --git a/include/sfx2/templatelocalview.hxx b/include/sfx2/templatelocalview.hxx
index bc79b36..f5bba32 100644
--- a/include/sfx2/templatelocalview.hxx
+++ b/include/sfx2/templatelocalview.hxx
@@ -208,7 +208,7 @@ public:

    virtual bool MouseButtonDown( const MouseEvent& rMEvt ) override;

    virtual bool ContextMenu(const CommandEvent& rPos) override;
    virtual bool Command(const CommandEvent& rPos) override;

    virtual bool KeyInput( const KeyEvent& rKEvt ) override;

diff --git a/include/svx/SvxPresetListBox.hxx b/include/svx/SvxPresetListBox.hxx
index f580eba..701c259 100644
--- a/include/svx/SvxPresetListBox.hxx
+++ b/include/svx/SvxPresetListBox.hxx
@@ -44,7 +44,7 @@ public:
    SvxPresetListBox(std::unique_ptr<weld::ScrolledWindow> pWindow);

    virtual void Resize() override;
    virtual bool ContextMenu(const CommandEvent& rEvent) override;
    virtual bool Command(const CommandEvent& rEvent) override;
    static sal_uInt32 getColumnCount() { return nColCount; }
    Size const & GetIconSize() const { return aIconSize; }

diff --git a/include/vcl/customweld.hxx b/include/vcl/customweld.hxx
index c2251ef..a7c46af 100644
--- a/include/vcl/customweld.hxx
+++ b/include/vcl/customweld.hxx
@@ -33,7 +33,7 @@ public:
    virtual void GetFocus() {}
    virtual void LoseFocus() {}
    virtual void StyleUpdated() { Invalidate(); }
    virtual bool ContextMenu(const CommandEvent&) { return false; }
    virtual bool Command(const CommandEvent&) { return false; }
    virtual bool KeyInput(const KeyEvent&) { return false; }
    virtual tools::Rectangle GetFocusRect() { return tools::Rectangle(); }
    virtual FactoryFunction GetUITestFactory() const { return nullptr; }
@@ -104,7 +104,7 @@ private:
    DECL_LINK(DoLoseFocus, weld::Widget&, void);
    DECL_LINK(DoKeyPress, const KeyEvent&, bool);
    DECL_LINK(DoFocusRect, weld::Widget&, tools::Rectangle);
    DECL_LINK(DoPopupMenu, const CommandEvent&, bool);
    DECL_LINK(DoCommand, const CommandEvent&, bool);
    DECL_LINK(DoStyleUpdated, weld::Widget&, void);
    DECL_LINK(DoRequestHelp, tools::Rectangle&, OUString);

diff --git a/include/vcl/layout.hxx b/include/vcl/layout.hxx
index 0248548..e0a7ab2 100644
--- a/include/vcl/layout.hxx
+++ b/include/vcl/layout.hxx
@@ -621,7 +621,7 @@ private:
    Link<const KeyEvent&, bool> m_aKeyPressHdl;
    Link<const KeyEvent&, bool> m_aKeyReleaseHdl;
    Link<VclDrawingArea&, void> m_aStyleUpdatedHdl;
    Link<const CommandEvent&, bool> m_aPopupMenuHdl;
    Link<const CommandEvent&, bool> m_aCommandHdl;
    Link<tools::Rectangle&, OUString> m_aQueryTooltipHdl;

    virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override
@@ -678,7 +678,7 @@ private:
    }
    virtual void Command(const CommandEvent& rEvent) override
    {
        if (rEvent.GetCommand() == CommandEventId::ContextMenu && m_aPopupMenuHdl.Call(rEvent))
        if (m_aCommandHdl.Call(rEvent))
            return;
        Control::Command(rEvent);
    }
@@ -758,9 +758,9 @@ public:
    {
        m_aStyleUpdatedHdl = rLink;
    }
    void SetPopupMenuHdl(const Link<const CommandEvent&, bool>& rLink)
    void SetCommandHdl(const Link<const CommandEvent&, bool>& rLink)
    {
        m_aPopupMenuHdl = rLink;
        m_aCommandHdl = rLink;
    }
    void SetQueryTooltipHdl(const Link<tools::Rectangle&, OUString>& rLink)
    {
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 8d7f509..b6c4c22 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -1657,7 +1657,7 @@ public:
protected:
    Link<draw_args, void> m_aDrawHdl;
    Link<Widget&, void> m_aStyleUpdatedHdl;
    Link<const CommandEvent&, bool> m_aPopupMenuHdl;
    Link<const CommandEvent&, bool> m_aCommandHdl;
    Link<Widget&, tools::Rectangle> m_aGetFocusRectHdl;
    Link<tools::Rectangle&, OUString> m_aQueryTooltipHdl;

@@ -1669,10 +1669,7 @@ protected:
public:
    void connect_draw(const Link<draw_args, void>& rLink) { m_aDrawHdl = rLink; }
    void connect_style_updated(const Link<Widget&, void>& rLink) { m_aStyleUpdatedHdl = rLink; }
    void connect_popup_menu(const Link<const CommandEvent&, bool>& rLink)
    {
        m_aPopupMenuHdl = rLink;
    }
    void connect_command(const Link<const CommandEvent&, bool>& rLink) { m_aCommandHdl = rLink; }
    void connect_focus_rect(const Link<Widget&, tools::Rectangle>& rLink)
    {
        m_aGetFocusRectHdl = rLink;
diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx
index 80232e4..4c281929 100644
--- a/sfx2/source/control/templatelocalview.cxx
+++ b/sfx2/source/control/templatelocalview.cxx
@@ -1199,8 +1199,11 @@ bool SfxTemplateLocalView::MouseButtonDown( const MouseEvent& rMEvt )
    return SfxThumbnailView::MouseButtonDown(rMEvt);
}

bool SfxTemplateLocalView::ContextMenu(const CommandEvent& rCEvt)
bool SfxTemplateLocalView::Command(const CommandEvent& rCEvt)
{
    if (rCEvt.GetCommand() != CommandEventId::ContextMenu)
        return CustomWidgetController::Command(rCEvt);

    if (rCEvt.IsMouseEvent())
    {
        deselectItems();
diff --git a/sfx2/source/control/templatesearchview.cxx b/sfx2/source/control/templatesearchview.cxx
index 0203352a..759c888 100644
--- a/sfx2/source/control/templatesearchview.cxx
+++ b/sfx2/source/control/templatesearchview.cxx
@@ -83,8 +83,11 @@ bool TemplateSearchView::KeyInput( const KeyEvent& rKEvt )
    return SfxThumbnailView::KeyInput(rKEvt);
}

bool TemplateSearchView::ContextMenu(const CommandEvent& rCEvt)
bool TemplateSearchView::Command(const CommandEvent& rCEvt)
{
    if (rCEvt.GetCommand() != CommandEventId::ContextMenu)
        return CustomWidgetController::Command(rCEvt);

    if (rCEvt.IsMouseEvent())
    {
        deselectItems();
diff --git a/sfx2/source/inc/templatesearchview.hxx b/sfx2/source/inc/templatesearchview.hxx
index ae7658f..6907365 100644
--- a/sfx2/source/inc/templatesearchview.hxx
+++ b/sfx2/source/inc/templatesearchview.hxx
@@ -48,7 +48,7 @@ private:

    virtual bool MouseButtonDown( const MouseEvent& rMEvt ) override;

    virtual bool ContextMenu(const CommandEvent& rPos) override;
    virtual bool Command(const CommandEvent& rPos) override;

    virtual bool KeyInput( const KeyEvent& rKEvt ) override;

diff --git a/svx/source/dialog/imapwnd.cxx b/svx/source/dialog/imapwnd.cxx
index 38d089b..ef10b72 100644
--- a/svx/source/dialog/imapwnd.cxx
+++ b/svx/source/dialog/imapwnd.cxx
@@ -487,7 +487,7 @@ IMapObject* IMapWindow::GetIMapObj( const SdrObject* pSdrObj )
    return pIMapObj;
}

bool IMapWindow::ContextMenu(const CommandEvent& rCEvt)
bool IMapWindow::Command(const CommandEvent& rCEvt)
{
    vcl::Region  aRegion;

@@ -530,8 +530,7 @@ bool IMapWindow::ContextMenu(const CommandEvent& rCEvt)

        return true;
    }
    else
        return CustomWidgetController::ContextMenu(rCEvt);
    return CustomWidgetController::Command(rCEvt);
}

IMapDropTargetHelper::IMapDropTargetHelper(IMapWindow& rImapWindow)
diff --git a/svx/source/dialog/imapwnd.hxx b/svx/source/dialog/imapwnd.hxx
index c790c3d..ae25fa9 100644
--- a/svx/source/dialog/imapwnd.hxx
+++ b/svx/source/dialog/imapwnd.hxx
@@ -95,7 +95,7 @@ class IMapWindow final : public GraphCtrl
    // GraphCtrl
    virtual bool        MouseButtonUp(const MouseEvent& rMEvt) override;
    virtual void        SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
    virtual bool        ContextMenu(const CommandEvent& rCEvt) override;
    virtual bool        Command(const CommandEvent& rCEvt) override;
    virtual OUString    RequestHelp(tools::Rectangle& rHelpArea) override;
    virtual void        SdrObjCreated( const SdrObject& rObj ) override;
    virtual void        SdrObjChanged( const SdrObject& rObj ) override;
diff --git a/svx/source/tbxctrls/SvxPresetListBox.cxx b/svx/source/tbxctrls/SvxPresetListBox.cxx
index 87c554c..effc9fc 100644
--- a/svx/source/tbxctrls/SvxPresetListBox.cxx
+++ b/svx/source/tbxctrls/SvxPresetListBox.cxx
@@ -43,8 +43,10 @@ void SvxPresetListBox::Resize()
    SvtValueSet::Resize();
}

bool SvxPresetListBox::ContextMenu(const CommandEvent& rEvent)
bool SvxPresetListBox::Command(const CommandEvent& rEvent)
{
    if (rEvent.GetCommand() != CommandEventId::ContextMenu)
        return CustomWidgetController::Command(rEvent);
    const sal_uInt16 nIndex = GetSelectedItemId();
    if(nIndex > 0)
    {
diff --git a/sw/source/uibase/inc/unotools.hxx b/sw/source/uibase/inc/unotools.hxx
index 51931ec..8761868 100644
--- a/sw/source/uibase/inc/unotools.hxx
+++ b/sw/source/uibase/inc/unotools.hxx
@@ -71,7 +71,7 @@ public:
                    const OUString* pURL = nullptr);
    virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
    virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
    virtual bool ContextMenu(const CommandEvent& rCEvt) override;
    virtual bool Command(const CommandEvent& rCEvt) override;
    virtual ~SwOneExampleFrame() override;

    css::uno::Reference< css::frame::XModel > &       GetModel()      {return m_xModel;}
diff --git a/sw/source/uibase/utlui/unotools.cxx b/sw/source/uibase/utlui/unotools.cxx
index e406981..e080fea 100644
--- a/sw/source/uibase/utlui/unotools.cxx
+++ b/sw/source/uibase/utlui/unotools.cxx
@@ -125,7 +125,7 @@ void SwOneExampleFrame::SetDrawingArea(weld::DrawingArea* pDrawingArea)
    CreateControl();
}

bool SwOneExampleFrame::ContextMenu(const CommandEvent& rCEvt)
bool SwOneExampleFrame::Command(const CommandEvent& rCEvt)
{
    switch (rCEvt.GetCommand())
    {
@@ -139,7 +139,7 @@ bool SwOneExampleFrame::ContextMenu(const CommandEvent& rCEvt)
        default:;
        break;
    }
    return false;
    return CustomWidgetController::Command(rCEvt);
}

void SwOneExampleFrame::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
diff --git a/vcl/source/app/customweld.cxx b/vcl/source/app/customweld.cxx
index 4299bcff..d6465ff 100644
--- a/vcl/source/app/customweld.cxx
+++ b/vcl/source/app/customweld.cxx
@@ -30,7 +30,7 @@ CustomWeld::CustomWeld(weld::Builder& rBuilder, const OString& rDrawingId,
    m_xDrawingArea->connect_key_press(LINK(this, CustomWeld, DoKeyPress));
    m_xDrawingArea->connect_focus_rect(LINK(this, CustomWeld, DoFocusRect));
    m_xDrawingArea->connect_style_updated(LINK(this, CustomWeld, DoStyleUpdated));
    m_xDrawingArea->connect_popup_menu(LINK(this, CustomWeld, DoPopupMenu));
    m_xDrawingArea->connect_command(LINK(this, CustomWeld, DoCommand));
    m_xDrawingArea->connect_query_tooltip(LINK(this, CustomWeld, DoRequestHelp));
    m_rWidgetController.SetDrawingArea(m_xDrawingArea.get());
}
@@ -80,9 +80,9 @@ IMPL_LINK_NOARG(CustomWeld, DoStyleUpdated, weld::Widget&, void)
    m_rWidgetController.StyleUpdated();
}

IMPL_LINK(CustomWeld, DoPopupMenu, const CommandEvent&, rPos, bool)
IMPL_LINK(CustomWeld, DoCommand, const CommandEvent&, rPos, bool)
{
    return m_rWidgetController.ContextMenu(rPos);
    return m_rWidgetController.Command(rPos);
}

IMPL_LINK(CustomWeld, DoRequestHelp, tools::Rectangle&, rHelpArea, OUString)
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index d1fda50..8dd4d4a 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -4439,7 +4439,7 @@ private:
    DECL_LINK(KeyPressHdl, const KeyEvent&, bool);
    DECL_LINK(KeyReleaseHdl, const KeyEvent&, bool);
    DECL_LINK(StyleUpdatedHdl, VclDrawingArea&, void);
    DECL_LINK(PopupMenuHdl, const CommandEvent&, bool);
    DECL_LINK(CommandHdl, const CommandEvent&, bool);
    DECL_LINK(QueryTooltipHdl, tools::Rectangle&, OUString);

    // SalInstanceWidget has a generic listener for all these
@@ -4485,7 +4485,7 @@ public:
        m_xDrawingArea->SetKeyPressHdl(LINK(this, SalInstanceDrawingArea, KeyPressHdl));
        m_xDrawingArea->SetKeyReleaseHdl(LINK(this, SalInstanceDrawingArea, KeyReleaseHdl));
        m_xDrawingArea->SetStyleUpdatedHdl(LINK(this, SalInstanceDrawingArea, StyleUpdatedHdl));
        m_xDrawingArea->SetPopupMenuHdl(LINK(this, SalInstanceDrawingArea, PopupMenuHdl));
        m_xDrawingArea->SetCommandHdl(LINK(this, SalInstanceDrawingArea, CommandHdl));
        m_xDrawingArea->SetQueryTooltipHdl(LINK(this, SalInstanceDrawingArea, QueryTooltipHdl));
    }

@@ -4563,7 +4563,7 @@ public:
    virtual ~SalInstanceDrawingArea() override
    {
        m_xDrawingArea->SetQueryTooltipHdl(Link<tools::Rectangle&, OUString>());
        m_xDrawingArea->SetPopupMenuHdl(Link<const CommandEvent&, bool>());
        m_xDrawingArea->SetCommandHdl(Link<const CommandEvent&, bool>());
        m_xDrawingArea->SetStyleUpdatedHdl(Link<VclDrawingArea&, void>());
        m_xDrawingArea->SetMousePressHdl(Link<const MouseEvent&, bool>());
        m_xDrawingArea->SetMouseMoveHdl(Link<const MouseEvent&, bool>());
@@ -4623,9 +4623,9 @@ IMPL_LINK_NOARG(SalInstanceDrawingArea, StyleUpdatedHdl, VclDrawingArea&, void)
    m_aStyleUpdatedHdl.Call(*this);
}

IMPL_LINK(SalInstanceDrawingArea, PopupMenuHdl, const CommandEvent&, rEvent, bool)
IMPL_LINK(SalInstanceDrawingArea, CommandHdl, const CommandEvent&, rEvent, bool)
{
    return m_aPopupMenuHdl.Call(rEvent);
    return m_aCommandHdl.Call(rEvent);
}

IMPL_LINK(SalInstanceDrawingArea, QueryTooltipHdl, tools::Rectangle&, rHelpArea, OUString)
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
index 2262e52..ae958cb 100644
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
@@ -8930,7 +8930,7 @@ private:
    }
    virtual bool signal_popup_menu(const CommandEvent& rCEvt) override
    {
        return m_aPopupMenuHdl.Call(rCEvt);
        return m_aCommandHdl.Call(rCEvt);
    }
public:
    GtkInstanceDrawingArea(GtkDrawingArea* pDrawingArea, GtkInstanceBuilder* pBuilder, const a11yref& rA11y, bool bTakeOwnership)