include/sfx2/viewsh.hxx          |    5 ++++-
 sc/source/ui/inc/hdrcont.hxx     |    2 +-
 sc/source/ui/view/hdrcont.cxx    |   13 ++++++-------
 sfx2/source/control/dispatch.cxx |   10 ++++++----
 sfx2/source/view/viewsh.cxx      |   15 +++++++++++----
 5 files changed, 28 insertions(+), 17 deletions(-)

New commits:
commit 35417853a27a53070cd5de74b41a2b8ff98b5d25
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Wed Dec 8 12:12:16 2021 +0000
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Wed Dec 8 15:30:43 2021 +0100

    keep as css::awt::XPopupMenu through another layer of api
    
    Change-Id: I750279bbfa67be442546b20e0e8315d595b6ea8c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126542
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index fc06eb9ddbe8..cfde481f5e21 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -59,6 +59,7 @@ class SfxInPlaceClient;
 class SfxLokCallbackInterface;
 namespace vcl { class PrinterController; }
 
+namespace com::sun::star::awt{ class XPopupMenu; }
 namespace com::sun::star::beans { struct PropertyValue; }
 namespace com::sun::star::datatransfer::clipboard { class XClipboardListener; }
 namespace com::sun::star::datatransfer::clipboard { class XClipboardNotifier; }
@@ -299,7 +300,9 @@ public:
     css::uno::Reference<css::frame::XController> GetController() const;
 
     bool                        TryContextMenuInterception( const Menu& rIn, 
const OUString& rMenuIdentifier, VclPtr<Menu>& rpOut, 
css::ui::ContextMenuExecuteEvent aEvent );
-    bool                        TryContextMenuInterception( Menu& rMenu, const 
OUString& rMenuIdentifier, css::ui::ContextMenuExecuteEvent aEvent );
+    bool                        TryContextMenuInterception(const 
css::uno::Reference<css::awt::XPopupMenu>&,
+                                                           const OUString& 
rMenuIdentifier,
+                                                           
css::ui::ContextMenuExecuteEvent aEvent);
 
     void                        ExecPrint( const css::uno::Sequence < 
css::beans::PropertyValue >&, bool, bool );
     // Like ExecPrint(), but only sets up for printing. Use 
Printer::ExecutePrintJob() and Printer::FinishPrintJob() afterwards.
diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx
index 6c6b3134404d..b0eee6eefb22 100644
--- a/sfx2/source/control/dispatch.cxx
+++ b/sfx2/source/control/dispatch.cxx
@@ -28,6 +28,7 @@
 
 #include <boost/property_tree/json_parser.hpp>
 
+#include <com/sun/star/awt/PopupMenuDirection.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
 #include <com/sun/star/frame/XLayoutManager.hpp>
@@ -1732,10 +1733,10 @@ void SfxDispatcher::ExecutePopup( const OUString& 
rResName, vcl::Window* pWin, c
     aEvent.ExecutePosition.Y = aPos.Y();
 
     xPopupController->setPopupMenu( xPopupMenu );
-    VCLXMenu* pAwtMenu = comphelper::getFromUnoTunnel<VCLXMenu>( xPopupMenu );
-    PopupMenu* pVCLMenu = static_cast< PopupMenu* >( pAwtMenu->GetMenu() );
     if (comphelper::LibreOfficeKit::isActive())
     {
+        VCLXMenu* pAwtMenu = comphelper::getFromUnoTunnel<VCLXMenu>( 
xPopupMenu );
+        PopupMenu* pVCLMenu = static_cast< PopupMenu* >( pAwtMenu->GetMenu() );
         boost::property_tree::ptree aMenu = fillPopupMenu(pVCLMenu);
         boost::property_tree::ptree aRoot;
         aRoot.add_child("menu", aMenu);
@@ -1748,9 +1749,10 @@ void SfxDispatcher::ExecutePopup( const OUString& 
rResName, vcl::Window* pWin, c
     else
     {
         OUString aMenuURL = "private:resource/popupmenu/" + rResName;
-        if (pVCLMenu && 
GetFrame()->GetViewShell()->TryContextMenuInterception(*pVCLMenu, aMenuURL, 
aEvent))
+        if (GetFrame()->GetViewShell()->TryContextMenuInterception(xPopupMenu, 
aMenuURL, aEvent))
         {
-            pVCLMenu->Execute(pWindow, aPos);
+            css::uno::Reference<css::awt::XWindowPeer> 
xParent(aEvent.SourceWindow, css::uno::UNO_QUERY);
+            xPopupMenu->execute(xParent, css::awt::Rectangle(aPos.X(), 
aPos.Y(), 1, 1), css::awt::PopupMenuDirection::EXECUTE_DOWN);
         }
     }
 
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 75826a28d128..e6b62ca774f9 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -24,6 +24,7 @@
 #include <svl/stritem.hxx>
 #include <svl/eitem.hxx>
 #include <svl/whiter.hxx>
+#include <toolkit/awt/vclxmenu.hxx>
 #include <vcl/menu.hxx>
 #include <vcl/svapp.hxx>
 #include <vcl/toolbox.hxx>
@@ -1954,12 +1955,18 @@ bool SfxViewShell::TryContextMenuInterception( const 
Menu& rIn, const OUString&
     return true;
 }
 
-bool SfxViewShell::TryContextMenuInterception( Menu& rMenu, const OUString& 
rMenuIdentifier, css::ui::ContextMenuExecuteEvent aEvent )
+bool SfxViewShell::TryContextMenuInterception(const 
css::uno::Reference<css::awt::XPopupMenu>& rPopupMenu,
+                                              const OUString& rMenuIdentifier, 
css::ui::ContextMenuExecuteEvent aEvent)
 {
+    VCLXMenu* pAwtMenu = comphelper::getFromUnoTunnel<VCLXMenu>(rPopupMenu);
+    PopupMenu* pVCLMenu = static_cast<PopupMenu*>(pAwtMenu->GetMenu());
+    if (!pVCLMenu)
+        return false;
+
     bool bModified = false;
 
     // create container from menu
-    aEvent.ActionTriggerContainer = 
::framework::ActionTriggerHelper::CreateActionTriggerContainerFromMenu( &rMenu, 
&rMenuIdentifier );
+    aEvent.ActionTriggerContainer = 
::framework::ActionTriggerHelper::CreateActionTriggerContainerFromMenu(pVCLMenu,
 &rMenuIdentifier);
 
     // get selection from controller
     aEvent.Selection = css::uno::Reference< css::view::XSelectionSupplier >( 
GetController(), css::uno::UNO_QUERY );
@@ -2008,8 +2015,8 @@ bool SfxViewShell::TryContextMenuInterception( Menu& 
rMenu, const OUString& rMen
 
     if ( bModified )
     {
-        rMenu.Clear();
-        
::framework::ActionTriggerHelper::CreateMenuFromActionTriggerContainer( &rMenu, 
aEvent.ActionTriggerContainer );
+        pVCLMenu->Clear();
+        
::framework::ActionTriggerHelper::CreateMenuFromActionTriggerContainer(pVCLMenu,
 aEvent.ActionTriggerContainer);
     }
 
     return true;
commit b6e08b6a02a5ec7ff711fdbb2a5a43eb8b90580f
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Wed Dec 8 11:50:26 2021 +0000
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Wed Dec 8 15:30:29 2021 +0100

    ScHeaderControl::GetMousePos only needs a Point, not a MouseEvent
    
    Change-Id: I458b3199e1d882c6cd20f5ef5a783afded626a37
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126541
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sc/source/ui/inc/hdrcont.hxx b/sc/source/ui/inc/hdrcont.hxx
index 10a795e2c2c9..149db145e2be 100644
--- a/sc/source/ui/inc/hdrcont.hxx
+++ b/sc/source/ui/inc/hdrcont.hxx
@@ -66,7 +66,7 @@ private:
     bool            bInRefMode;
 
     tools::Long            GetScrPos( SCCOLROW nEntryNo ) const;
-    SCCOLROW        GetMousePos( const MouseEvent& rMEvt, bool& rBorder ) 
const;
+    SCCOLROW        GetMousePos(const Point& rPos, bool& rBorder) const;
     bool            IsSelectionAllowed(SCCOLROW nPos) const;
     void            ShowDragHelp();
     void            HideDragHelp();
diff --git a/sc/source/ui/view/hdrcont.cxx b/sc/source/ui/view/hdrcont.cxx
index d594693813ad..b2b4263c055f 100644
--- a/sc/source/ui/view/hdrcont.cxx
+++ b/sc/source/ui/view/hdrcont.cxx
@@ -621,14 +621,14 @@ void ScHeaderControl::Paint( vcl::RenderContext& 
/*rRenderContext*/, const tools
     }
 }
 
-SCCOLROW ScHeaderControl::GetMousePos( const MouseEvent& rMEvt, bool& rBorder 
) const
+SCCOLROW ScHeaderControl::GetMousePos(const Point& rPos, bool& rBorder) const
 {
     bool        bFound = false;
     SCCOLROW    nPos = GetPos();
     SCCOLROW    nHitNo = nPos;
     SCCOLROW    nEntryNo = 1 + nPos;
     tools::Long    nScrPos;
-    tools::Long    nMousePos = bVertical ? rMEvt.GetPosPixel().Y() : 
rMEvt.GetPosPixel().X();
+    tools::Long    nMousePos = bVertical ? rPos.Y() : rPos.X();
     tools::Long    nDif;
     Size    aSize = GetOutputSizePixel();
     tools::Long    nWinSize = bVertical ? aSize.Height() : aSize.Width();
@@ -709,7 +709,7 @@ void ScHeaderControl::MouseButtonDown( const MouseEvent& 
rMEvt )
     SelectWindow();
 
     bool bIsBorder;
-    SCCOLROW nHitNo = GetMousePos( rMEvt, bIsBorder );
+    SCCOLROW nHitNo = GetMousePos(rMEvt.GetPosPixel(), bIsBorder);
     if (!IsSelectionAllowed(nHitNo))
         return;
     if ( ! rMEvt.IsLeft() )
@@ -869,7 +869,7 @@ void ScHeaderControl::MouseMove( const MouseEvent& rMEvt )
         if( !pTabView )
             return;
         bool bTmp;
-        SCCOLROW nHitNo = GetMousePos( rMEvt, bTmp );
+        SCCOLROW nHitNo = GetMousePos(rMEvt.GetPosPixel(), bTmp);
         SCTAB nTab = pTabView->GetViewData().GetTabNo();
         ScTabViewShell* pViewSh = 
dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
         ScDocument& rDoc = pViewSh->GetViewData().GetDocument();
@@ -898,7 +898,7 @@ void ScHeaderControl::MouseMove( const MouseEvent& rMEvt )
     else
     {
         bool bIsBorder;
-        (void)GetMousePos( rMEvt, bIsBorder );
+        (void)GetMousePos(rMEvt.GetPosPixel(), bIsBorder);
 
         if ( bIsBorder && rMEvt.GetButtons()==0 && ResizeAllowed() )
             SetPointer( bVertical ? PointerStyle::VSizeBar : 
PointerStyle::HSizeBar );
@@ -944,9 +944,8 @@ void ScHeaderControl::Command( const CommandEvent& rCEvt )
                 if ( rViewData.HasEditView( rViewData.GetActivePart() ) )
                     SC_MOD()->InputEnterHandler();  // always end edit mode
 
-                MouseEvent aMEvt( rCEvt.GetMousePosPixel() );
                 bool bBorder;
-                SCCOLROW nPos = GetMousePos( aMEvt, bBorder );
+                SCCOLROW nPos = GetMousePos(rCEvt.GetMousePosPixel(), bBorder 
);
                 if (!IsSelectionAllowed(nPos))
                     // Selecting this cell is not allowed, neither is context 
menu.
                     return;

Reply via email to