sd/UIConfig_simpress.mk             |    1 
 sd/source/ui/inc/DrawViewShell.hxx  |   13 +++++------
 sd/source/ui/view/drviews4.cxx      |   40 ++++++++++++------------------------
 sd/uiconfig/simpress/ui/snapmenu.ui |    9 ++++++++
 4 files changed, 30 insertions(+), 33 deletions(-)

New commits:
commit 50cec31d5fa77ebc04f35e57718a02d328562417
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Sat Nov 27 21:18:56 2021 +0000
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Sun Nov 28 11:14:30 2021 +0100

    weld Snap Line context menu
    
    Change-Id: Ic4ea546f66eae7acb0427686be8981e2e8231c77
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125955
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sd/UIConfig_simpress.mk b/sd/UIConfig_simpress.mk
index 4edab7d4d5d9..3476e409a73b 100644
--- a/sd/UIConfig_simpress.mk
+++ b/sd/UIConfig_simpress.mk
@@ -161,6 +161,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/simpress,\
        sd/uiconfig/simpress/ui/slidecontextmenu \
        sd/uiconfig/simpress/ui/slidedesigndialog \
        sd/uiconfig/simpress/ui/slidetransitionspanel \
+       sd/uiconfig/simpress/ui/snapmenu \
        sd/uiconfig/simpress/ui/tabviewbar \
        sd/uiconfig/simpress/ui/tabledesignpanel \
        sd/uiconfig/simpress/ui/templatedialog \
diff --git a/sd/source/ui/inc/DrawViewShell.hxx 
b/sd/source/ui/inc/DrawViewShell.hxx
index 27b46a008fcb..44bb83d44979 100644
--- a/sd/source/ui/inc/DrawViewShell.hxx
+++ b/sd/source/ui/inc/DrawViewShell.hxx
@@ -471,19 +471,18 @@ private:
         can not be selected the index of the snap line/point for which the
         popup menu is opened has to be passed to the processing slot
         handlers.  This can be done only by manually showing the popup menu.
+        @param pParent
+            The parent for the context menu.
+        @param rRect
+            The location at which to display the context menu.
         @param rPageView
             The page view is used to access the help lines.
         @param nSnapLineIndex
             Index of the snap line or snap point for which to show the
             context menu.
-        @param rMouseLocation
-            The mouse location defines the location at which to display the
-            context menu.
     */
-    void ShowSnapLineContextMenu (
-        SdrPageView& rPageView,
-        const sal_uInt16 nSnapLineIndex,
-        const Point& rMouseLocation);
+    void ShowSnapLineContextMenu(weld::Window* pParent, const 
::tools::Rectangle& rRect,
+        SdrPageView& rPageView, const sal_uInt16 nSnapLineIndex);
 
     using ViewShell::Notify;
 
diff --git a/sd/source/ui/view/drviews4.cxx b/sd/source/ui/view/drviews4.cxx
index 8c0a9282e33a..f4114361ccb0 100644
--- a/sd/source/ui/view/drviews4.cxx
+++ b/sd/source/ui/view/drviews4.cxx
@@ -574,7 +574,9 @@ void DrawViewShell::Command(const CommandEvent& rCEvt, 
::sd::Window* pWin)
         // helper line
         if ( mpDrawView->PickHelpLine( aMPos, nHitLog, 
*GetActiveWindow()->GetOutDev(), nHelpLine, pPV) )
         {
-            ShowSnapLineContextMenu(*pPV, nHelpLine, rCEvt.GetMousePosPixel());
+            ::tools::Rectangle aRect(rCEvt.GetMousePosPixel(), Size(10, 10));
+            weld::Window* pParent = weld::GetPopupParent(*pWin, aRect);
+            ShowSnapLineContextMenu(pParent, aRect, *pPV, nHelpLine);
             return;
         }
         // is gluepoint under cursor marked?
@@ -928,41 +930,27 @@ void DrawViewShell::UnlockInput()
         mnLockCount--;
 }
 
-void DrawViewShell::ShowSnapLineContextMenu (
-    SdrPageView& rPageView,
-    const sal_uInt16 nSnapLineIndex,
-    const Point& rMouseLocation)
+void DrawViewShell::ShowSnapLineContextMenu(weld::Window* pParent, const 
::tools::Rectangle& rRect,
+                                            SdrPageView& rPageView, const 
sal_uInt16 nSnapLineIndex)
 {
     const SdrHelpLine& rHelpLine (rPageView.GetHelpLines()[nSnapLineIndex]);
-    ScopedVclPtrInstance<PopupMenu> pMenu;
+    std::unique_ptr<weld::Builder> 
xBuilder(Application::CreateBuilder(nullptr, 
"modules/simpress/ui/snapmenu.ui"));
+    std::unique_ptr<weld::Menu> xMenu(xBuilder->weld_menu("menu"));
 
     if (rHelpLine.GetKind() == SdrHelpLineKind::Point)
     {
-        pMenu->InsertItem(
-            SID_SET_SNAPITEM,
-            SdResId(STR_POPUP_EDIT_SNAPPOINT));
-        pMenu->InsertSeparator();
-        pMenu->InsertItem(
-            SID_DELETE_SNAPITEM,
-            SdResId(STR_POPUP_DELETE_SNAPPOINT));
+        xMenu->append(OUString::number(SID_SET_SNAPITEM), 
SdResId(STR_POPUP_EDIT_SNAPPOINT));
+        xMenu->append_separator("separator");
+        xMenu->append(OUString::number(SID_DELETE_SNAPITEM), 
SdResId(STR_POPUP_DELETE_SNAPPOINT));
     }
     else
     {
-        pMenu->InsertItem(
-            SID_SET_SNAPITEM,
-            SdResId(STR_POPUP_EDIT_SNAPLINE));
-        pMenu->InsertSeparator();
-        pMenu->InsertItem(
-            SID_DELETE_SNAPITEM,
-            SdResId(STR_POPUP_DELETE_SNAPLINE));
+        xMenu->append(OUString::number(SID_SET_SNAPITEM), 
SdResId(STR_POPUP_EDIT_SNAPLINE));
+        xMenu->append_separator("separator");
+        xMenu->append(OUString::number(SID_DELETE_SNAPITEM), 
SdResId(STR_POPUP_DELETE_SNAPLINE));
     }
 
-    pMenu->RemoveDisabledEntries(false);
-
-    const sal_uInt16 nResult = pMenu->Execute(
-        GetActiveWindow(),
-        ::tools::Rectangle(rMouseLocation, Size(10,10)),
-        PopupMenuFlags::ExecuteDown);
+    const int nResult = xMenu->popup_at_rect(pParent, rRect).toInt32();
     switch (nResult)
     {
         case SID_SET_SNAPITEM:
diff --git a/sd/uiconfig/simpress/ui/snapmenu.ui 
b/sd/uiconfig/simpress/ui/snapmenu.ui
new file mode 100644
index 000000000000..5bb702561dd2
--- /dev/null
+++ b/sd/uiconfig/simpress/ui/snapmenu.ui
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.38.2 -->
+<interface domain="sd">
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkMenu" id="menu">
+    <property name="visible">True</property>
+    <property name="can-focus">False</property>
+  </object>
+</interface>

Reply via email to