From 8169fbbe715daa801fd17dddf0b9b03f71b2217e Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Fri, 18 Dec 2020 20:56:42 +0000 Subject: weld rulermenu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I337a1b3a842fdb87cb3b8bf1a52a056e3787f477 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107983 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- include/svx/ruler.hxx | 2 +- svx/source/dialog/svxruler.cxx | 31 +++++++++++++++++-------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/include/svx/ruler.hxx b/include/svx/ruler.hxx index c0b587cdc583..4c6735490b8c 100644 --- a/include/svx/ruler.hxx +++ b/include/svx/ruler.hxx @@ -218,7 +218,7 @@ class SVX_DLLPUBLIC SvxRuler: public Ruler, public SfxListener tools::Long GetRightMax() const; DECL_LINK( TabMenuSelect, Menu *, bool ); - DECL_LINK( MenuSelect, Menu *, bool ); + void MenuSelect(std::string_view ident); void PrepareProportional_Impl(RulerType); enum class UpdateType diff --git a/svx/source/dialog/svxruler.cxx b/svx/source/dialog/svxruler.cxx index d684cd75302f..55b575d4a4ca 100644 --- a/svx/source/dialog/svxruler.cxx +++ b/svx/source/dialog/svxruler.cxx @@ -27,7 +27,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -3252,11 +3254,12 @@ void SvxRuler::Notify(SfxBroadcaster&, const SfxHint& rHint) } } -IMPL_LINK( SvxRuler, MenuSelect, Menu *, pMenu, bool ) +void SvxRuler::MenuSelect(std::string_view ident) { + if (ident.empty()) + return; /* Handler of the context menus for switching the unit of measurement */ - SetUnit(vcl::StringToMetric(OUString::fromUtf8(pMenu->GetCurItemIdent()))); - return false; + SetUnit(vcl::StringToMetric(OUString::fromUtf8(ident))); } IMPL_LINK( SvxRuler, TabMenuSelect, Menu *, pMenu, bool ) @@ -3323,19 +3326,19 @@ void SvxRuler::Command( const CommandEvent& rCommandEvent ) } else { - VclBuilder aBuilder(nullptr, AllSettings::GetUIRootDir(), "svx/ui/rulermenu.ui", ""); - VclPtr aMenu(aBuilder.get_menu("menu")); - aMenu->SetSelectHdl(LINK(this, SvxRuler, MenuSelect)); + tools::Rectangle aRect(rCommandEvent.GetMousePosPixel(), Size(1, 1)); + weld::Window* pPopupParent = weld::GetPopupParent(*this, aRect); + std::unique_ptr xBuilder(Application::CreateBuilder(pPopupParent, "svx/ui/rulermenu.ui")); + std::unique_ptr xMenu(xBuilder->weld_menu("menu")); FieldUnit eUnit = GetUnit(); - const sal_uInt16 nCount = aMenu->GetItemCount(); + const int nCount = xMenu->n_children(); bool bReduceMetric = bool(nFlags & SvxRulerSupportFlags::REDUCED_METRIC); for ( sal_uInt16 i = nCount; i; --i ) { - sal_uInt16 nId = aMenu->GetItemId(i - 1); - OString sIdent = aMenu->GetItemIdent(nId); + OString sIdent = xMenu->get_id(i - 1); FieldUnit eMenuUnit = vcl::StringToMetric(OUString::fromUtf8(sIdent)); - aMenu->CheckItem(nId, eMenuUnit == eUnit); + xMenu->set_active(sIdent, eMenuUnit == eUnit); if( bReduceMetric ) { if (eMenuUnit == FieldUnit::M || @@ -3343,19 +3346,19 @@ void SvxRuler::Command( const CommandEvent& rCommandEvent ) eMenuUnit == FieldUnit::FOOT || eMenuUnit == FieldUnit::MILE) { - aMenu->RemoveItem(i - 1); + xMenu->remove(sIdent); } else if (( eMenuUnit == FieldUnit::CHAR ) && !bHorz ) { - aMenu->RemoveItem(i - 1); + xMenu->remove(sIdent); } else if (( eMenuUnit == FieldUnit::LINE ) && bHorz ) { - aMenu->RemoveItem(i - 1); + xMenu->remove(sIdent); } } } - aMenu->Execute( this, rCommandEvent.GetMousePosPixel() ); + MenuSelect(xMenu->popup_at_rect(pPopupParent, aRect)); } } else -- cgit