From 50cec31d5fa77ebc04f35e57718a02d328562417 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Sat, 27 Nov 2021 21:18:56 +0000 Subject: weld Snap Line context menu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ic4ea546f66eae7acb0427686be8981e2e8231c77 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125955 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- sd/source/ui/inc/DrawViewShell.hxx | 13 ++++++------- sd/source/ui/view/drviews4.cxx | 40 +++++++++++++------------------------- 2 files changed, 20 insertions(+), 33 deletions(-) (limited to 'sd/source') 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 pMenu; + std::unique_ptr xBuilder(Application::CreateBuilder(nullptr, "modules/simpress/ui/snapmenu.ui")); + std::unique_ptr 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: -- cgit